Java源码示例:org.alfresco.service.cmr.dictionary.TypeDefinition

示例1
/**
 * @param variables raw variables
 * @param typeDefinition the typê definition for the start-task of the process, used to extract types.
 * @return list of {@link Variable}, representing the given raw variables
 */
public List<Variable> getVariables(Map<String, Object> variables, TypeDefinition typeDefinition)
{
    List<Variable> result = new ArrayList<Variable>();
    TypeDefinitionContext context = new TypeDefinitionContext(typeDefinition, getQNameConverter());
    
    Variable variable = null;
    for(Entry<String, Object> entry : variables.entrySet()) 
    {
        if(!INTERNAL_PROPERTIES.contains(entry.getKey()))
        {
            variable = new Variable();
            variable.setName(entry.getKey());
            
            // Set value and type
            setVariableValueAndType(variable, entry.getValue(), context);
            result.add(variable);
        }
    }
    return result;
}
 
示例2
/**
 * Actually tests if the priority is the default value.  This is based on the assumption that custom
 * tasks are defaulted to a priority of 50 (which is invalid).  I'm testing that the code I wrote decides this is an
 * invalid number and sets it to the default value (2).
 */
@Test
public void testPriorityIsValid()
{
    WorkflowDefinition definition = deployDefinition("activiti/testCustomActiviti.bpmn20.xml");
    
    personManager.setUser(USER1);
    
    // Start the Workflow
    WorkflowPath path = workflowService.startWorkflow(definition.getId(), null);
    String instanceId = path.getInstance().getId();

    // Check the Start Task is completed.
    WorkflowTask startTask = workflowService.getStartTask(instanceId);
    assertEquals(WorkflowTaskState.COMPLETED, startTask.getState());
    
    List<WorkflowTask> tasks = workflowService.getTasksForWorkflowPath(path.getId());
    for (WorkflowTask workflowTask : tasks)
    {
        Map<QName, Serializable> props = workflowTask.getProperties();
        TypeDefinition typeDefinition = workflowTask.getDefinition().getMetadata();
        Map<QName, PropertyDefinition> propertyDefs = typeDefinition.getProperties();        
        PropertyDefinition priorDef =  propertyDefs.get(WorkflowModel.PROP_PRIORITY);
        assertEquals(props.get(WorkflowModel.PROP_PRIORITY),Integer.valueOf(priorDef.getDefaultValue()));        
    }
}
 
示例3
public void testPropertyOverride()
{
    TypeDefinition type1 = service.getType(QName.createQName(TEST_URL, "overridetype1"));
    Map<QName, PropertyDefinition> props1 = type1.getProperties();
    PropertyDefinition prop1 = props1.get(QName.createQName(TEST_URL, "propoverride"));
    String def1 = prop1.getDefaultValue();
    assertEquals("one", def1);
    
    TypeDefinition type2 = service.getType(QName.createQName(TEST_URL, "overridetype2"));
    Map<QName, PropertyDefinition> props2 = type2.getProperties();
    PropertyDefinition prop2 = props2.get(QName.createQName(TEST_URL, "propoverride"));
    String def2 = prop2.getDefaultValue();
    assertEquals("two", def2);

    TypeDefinition type3 = service.getType(QName.createQName(TEST_URL, "overridetype3"));
    Map<QName, PropertyDefinition> props3 = type3.getProperties();
    PropertyDefinition prop3 = props3.get(QName.createQName(TEST_URL, "propoverride"));
    String def3 = prop3.getDefaultValue();
    assertEquals("three", def3);
}
 
示例4
@Override
public void updateDefinition(DictionaryService dictionaryService)
{
    TypeDefinition typeDef = dictionaryService.getType(alfrescoName);

    if (typeDef != null)
    {
        setTypeDefDisplayName(typeDef.getTitle(dictionaryService));
        setTypeDefDescription(typeDef.getDescription(dictionaryService));
    }
    else
    {
        super.updateDefinition(dictionaryService);
    }
    
    updateTypeDefInclProperties();
}
 
示例5
/**
 * Gets the Task {@link TypeDefinition} for the given name.
 * 
 * @param name the name of the task definition.
 * @param isStart is theis a start task?
 * @return  the task {@link TypeDefinition}.
 */
public TypeDefinition getTaskTypeDefinition(String name, boolean isStart)
{
    TypeDefinition typeDef = null;
    if(name!=null)
    {
        QName typeName = qNameConverter.mapNameToQName(name);
        typeDef = dictionaryService.getType(typeName);
    }
    if (typeDef == null)
    {
        QName defaultTypeName = isStart? defaultStartTaskType : WorkflowModel.TYPE_WORKFLOW_TASK;
        typeDef = dictionaryService.getType(defaultTypeName);
        if (typeDef == null)
        {
            String msg = messageService.getMessage("workflow.get.task.definition.metadata.error", name);
            throw new WorkflowException( msg);
        }
    }
    return typeDef;
}
 
示例6
private void afterPropertiesSet_validateSelectors()
{
    PropertyCheck.mandatory(this, "storeByTypeName", this.storeByTypeName);
    if (this.storeByTypeName.isEmpty())
    {
        throw new IllegalStateException("No stores have been defined for node types");
    }

    this.storeByTypeQName = new HashMap<>();
    this.storeByTypeName.forEach((typeName, store) -> {
        final QName typeQName = QName.resolveToQName(this.namespaceService, typeName);
        if (typeQName == null)
        {
            throw new IllegalStateException(typeQName + " cannot be resolved to a qualified name");
        }
        final TypeDefinition type = this.dictionaryService.getType(typeQName);
        if (type == null)
        {
            throw new IllegalStateException(typeQName + " cannot be resolved to a registered node type");
        }

        this.storeByTypeQName.put(typeQName, store);
    });
}
 
示例7
/**
 * @param taskType type of the task
 * @return all types (and aspects) which properties should not be used for form-model elements
 */
protected Set<QName> getTypesToExclude(TypeDefinition taskType)
{
    HashSet<QName> typesToExclude = new HashSet<QName>();
    
    ClassDefinition parentClassDefinition = taskType.getParentClassDefinition();
    boolean contentClassFound = false;
    while(parentClassDefinition != null) 
    {
        if(contentClassFound)
        {
            typesToExclude.add(parentClassDefinition.getName());
        }
        else if(ContentModel.TYPE_CONTENT.equals(parentClassDefinition.getName()))
        {
            // All parents of "cm:content" should be ignored as well for fetching start-properties 
            typesToExclude.add(ContentModel.TYPE_CONTENT);
            typesToExclude.addAll(parentClassDefinition.getDefaultAspectNames());
            contentClassFound = true;
        }
        parentClassDefinition = parentClassDefinition.getParentClassDefinition();
    }
    return typesToExclude;
}
 
示例8
@Override
public void updateDefinition(DictionaryService dictionaryService)
{
    TypeDefinition typeDef = dictionaryService.getType(alfrescoName);

    if (typeDef != null)
    {
        setTypeDefDisplayName(typeDef.getTitle(dictionaryService));
        setTypeDefDescription(typeDef.getDescription(dictionaryService));
    }
    else
    {
        super.updateDefinition(dictionaryService);
    }
    
    updateTypeDefInclProperties();
}
 
示例9
protected Object handleDefaultProperty(Object task, TypeDefinition type, QName key, Serializable value)
{
    PropertyDefinition propDef = type.getProperties().get(key);
    if (propDef != null)
    {
        return handleProperty(value, propDef);
    }
    else
    {
        AssociationDefinition assocDef = type.getAssociations().get(key);
        if (assocDef != null)
        {
            return handleAssociation(value, assocDef);
        }
        else if (value instanceof NodeRef)
        {
            return nodeConverter.convertNode((NodeRef)value, false);
        }
    }
    return value;
}
 
示例10
public Map<String, Object> handleVariablesToSet(Map<QName, Serializable> properties, 
            TypeDefinition type,
            Object object, Class<?> objectType)
{
    Map<String, Object> variablesToSet = new HashMap<String, Object>();
    for (Entry<QName, Serializable> entry : properties.entrySet())
    {
        QName key = entry.getKey();
        Serializable value = entry.getValue();
        WorkflowPropertyHandler handler = handlers.get(key);
        if (handler == null)
        {
            handler = defaultHandler;
        }
        Object result = handler.handleProperty(key, value, type, object, objectType);
        if (WorkflowPropertyHandler.DO_NOT_ADD.equals(result)==false) 
        {
            String keyStr = qNameConverter.mapQNameToName(key);
            variablesToSet.put(keyStr, result);
        }
    }
    return variablesToSet;
}
 
示例11
private WorkflowTaskDefinition makeTaskDefinition(WorkflowTransition... transitions)
{
    String id = "DefinitionId";
    TypeDefinition metadata = makeTypeDef();
    WorkflowNode node = new WorkflowNode("", "", "", "", true, transitions);
    return new WorkflowTaskDefinition(id,
                node, metadata);
}
 
示例12
@Override
public void deactivateCustomModel(final String modelName)
{
    CustomModelDefinition customModelDefinition = getCustomModel(modelName);
    if (customModelDefinition == null)
    {
        throw new CustomModelException.ModelDoesNotExistException(MSG_MODEL_NOT_EXISTS, new Object[] { modelName });
    }

    Collection<TypeDefinition> modelTypes = customModelDefinition.getTypeDefinitions();
    Collection<AspectDefinition> modelAspects = customModelDefinition.getAspectDefinitions();

    for (CompiledModel cm : getAllCustomM2Models(false))
    {
        // Ignore type/aspect dependency check within the model itself
        if (!customModelDefinition.getName().equals(cm.getModelDefinition().getName()))
        {
            // Check if the type of the model being deactivated is the parent of another model's type
            validateTypeAspectDependency(modelTypes, cm.getTypes());

            // Check if the aspect of the model being deactivated is the parent of another model's aspect
            validateTypeAspectDependency(modelAspects, cm.getAspects());
        }
    }

    // requiresNewTx = true, in order to catch any exception thrown within
    // "DictionaryModelType$DictionaryModelTypeTransactionListener" model validation.
    doInTransaction(MSG_UNABLE_MODEL_DEACTIVATE, true, new RetryingTransactionCallback<Void>()
    {
        public Void execute() throws Exception
        {
            repoAdminService.deactivateModel(modelName);
            return null;
        }
    });
}
 
示例13
private Map<String, String> buildPropertyLabels(WorkflowTask task, Map<String, Object> properties)
{
    TypeDefinition taskType = task.getDefinition().getMetadata();
    final Map<QName, PropertyDefinition> propDefs = taskType.getProperties();
    return CollectionUtils.transform(properties, new Function<Entry<String, Object>, Pair<String, String>>()
    {
        @Override
        public Pair<String, String> apply(Entry<String, Object> entry)
        {
            String propName = entry.getKey();
            PropertyDefinition propDef = propDefs.get(qNameConverter.mapNameToQName(propName));
            if(propDef != null )
            {
                List<ConstraintDefinition> constraints = propDef.getConstraints();
                for (ConstraintDefinition constraintDef : constraints)
                {
                    Constraint constraint = constraintDef.getConstraint();
                    if (constraint instanceof ListOfValuesConstraint)
                    {
                        ListOfValuesConstraint listConstraint = (ListOfValuesConstraint) constraint;
                        String label = listConstraint.getDisplayLabel(String.valueOf(entry.getValue()), dictionaryService);
                        return new Pair<String, String>(propName, label);
                    }
                }
            }
            return null;
        }
    });
}
 
示例14
/**
 * @param typeQName             a node type
 * @return                      <tt>true</tt> if the type given has the <b>cm:auditable</b> aspect by default
 */
public static boolean hasAuditableAspect(QName typeQName, DictionaryService dictionaryService)
{
    TypeDefinition typeDef = dictionaryService.getType(typeQName);
    if (typeDef == null)
    {
        return false;
    }
    return typeDef.getDefaultAspectNames().contains(ContentModel.ASPECT_AUDITABLE);
}
 
示例15
/**
 * {@inheritDoc}
  */
@Override
protected String getItemType(WorkflowTask item)
{
    TypeDefinition typeDef = item.getDefinition().getMetadata();
    return typeDef.getName().toPrefixString(namespaceService);
}
 
示例16
private WorkflowTaskDefinition makeTaskDefinition()
{
    String id = "foo$startTaskDefId";
    TypeDefinition metadata = makeTypeDef();
    WorkflowNode node = new WorkflowNode("", "", "", "", false);
    return new WorkflowTaskDefinition(id,
                node, metadata);
}
 
示例17
@Override
public NodeDefinition fromTypeDefinition(TypeDefinition typeDefinition,
        MessageLookup messageLookup) 
{
    
    if (typeDefinition == null)
    {
        throw new AlfrescoRuntimeException("Undefined definition for the node");
    }
    NodeDefinition nodeDefinition = new NodeDefinition();
    nodeDefinition.setProperties(getProperties(typeDefinition.getProperties(), messageLookup));
    
    return nodeDefinition;
}
 
示例18
private Map<String, Object> buildProperties(WorkflowTask task, Collection<String> propertyFilters)
{
    Map<QName, Serializable> properties = task.getProperties();
    Collection<QName> keys;
    if (propertyFilters == null || propertyFilters.size() == 0)
    {
        TypeDefinition taskType = task.getDefinition().getMetadata();
        Map<QName, PropertyDefinition> propDefs = taskType.getProperties();
        Map<QName, AssociationDefinition> assocDefs = taskType.getAssociations();
        Set<QName> propKeys = properties.keySet();
        keys = new HashSet<QName>(propDefs.size() + assocDefs.size() + propKeys.size());
        keys.addAll(propDefs.keySet());
        keys.addAll(assocDefs.keySet());
        keys.addAll(propKeys);
        keys.add(WorkflowModel.PROP_HIDDEN_TRANSITIONS);
    }
    else
    {
        keys = buildQNameKeys(propertyFilters);
    }
    
    Map<String, Object> result = buildQNameProperties(properties, keys, task);
    
    // ALF-18092: Special handling for the "hiddenTransitions" property, as it can be an empty string
    if (keys.contains(WorkflowModel.PROP_HIDDEN_TRANSITIONS))
    {
        List<?> hiddenTransitions = getHiddenTransitions(properties);
        if (hiddenTransitions != null)
        {
            result.put(qNameConverter.mapQNameToName(WorkflowModel.PROP_HIDDEN_TRANSITIONS), hiddenTransitions);
        }
    }
    return result;
}
 
示例19
public static TypeDefinition matchTypeDefinition(String string, NamespacePrefixResolver namespacePrefixResolver, DictionaryService dictionaryService)
{
    QName search = QName.createQName(expandQName(string, namespacePrefixResolver));
    TypeDefinition typeDefinition = dictionaryService.getType(search);
    QName match = null;
    if (typeDefinition == null)
    {
        for (QName definition : dictionaryService.getAllTypes())
        {
            if (definition.getNamespaceURI().equalsIgnoreCase(search.getNamespaceURI()))
            {
                if (definition.getLocalName().equalsIgnoreCase(search.getLocalName()))
                {
                    if (match == null)
                    {
                        match = definition;
                    }
                    else
                    {
                        throw new QueryModelException("Ambiguous data datype " + string);
                    }
                }
            }
        }
    }
    else
    {
        return typeDefinition;
    }
    if (match == null)
    {
        return null;
    }
    else
    {
        return dictionaryService.getType(match);
    }
}
 
示例20
@Override
public CollectionWithPagingInfo<CustomType> getCustomTypes(String modelName, Parameters parameters)
{
    CustomModelDefinition modelDef = getCustomModelImpl(modelName);
    Collection<TypeDefinition> typeDefinitions = modelDef.getTypeDefinitions();
    // TODO Should we support paging?
    Paging paging = Paging.DEFAULT;

    List<CustomType> customTypes = convertToCustomTypes(typeDefinitions, false);

    return CollectionWithPagingInfo.asPaged(paging, customTypes, false, typeDefinitions.size());

}
 
示例21
public WorkflowTaskDefinition createTaskDefinition(String id, WorkflowNode node, String typeName, boolean isStart)
{
    TypeDefinition metaData = getTaskTypeDefinition(typeName, isStart);
    if(id == null)
    {
        id = qNameConverter.mapQNameToName(metaData.getName());
    }
    return new WorkflowTaskDefinition(id, node, metaData);
}
 
示例22
@Test
public void testGetDefinitionById() throws Exception
{
    WorkflowDefinition definition = deployTestTaskDefinition();
    WorkflowDefinition result = workflowEngine.getDefinitionById(definition.getId());

    assertNotNull("The workflow definition was not found!", result);
    
    assertEquals(definition.getId(), result.getId());
    assertEquals(definition.getDescription(), result.getDescription());
    assertEquals(definition.getName(), result.getName());
    assertEquals(definition.getTitle(), result.getTitle());
    assertEquals(definition.getVersion(), result.getVersion());

    WorkflowTaskDefinition resultStartDef = result.getStartTaskDefinition();
    assertNotNull("Start task is null!", resultStartDef);

    WorkflowTaskDefinition originalStartDef = definition.getStartTaskDefinition();
    assertEquals("Start task Id does not match!", originalStartDef.getId(), resultStartDef.getId());
    
    WorkflowNode resultNode = resultStartDef.getNode();
    assertNotNull("Start Task Node is null!", resultNode);
    assertEquals("Start Task Node Name does not match!", originalStartDef.getNode().getName(), resultNode.getName());
    
    TypeDefinition metaData = resultStartDef.getMetadata();
    assertNotNull("Start Task Metadata is null!", metaData);
    assertEquals("Start Task Metadata name does not match!", originalStartDef.getMetadata().getName(), metaData.getName());
    
    workflowEngine.undeployDefinition(definition.getId());
    WorkflowDefinition nullResult = workflowEngine.getDefinitionById(definition.getId());
    assertNull("The workflow definition was found but should be null!", nullResult);
}
 
示例23
/**
* {@inheritDoc}
*/
public Object handleProperty(QName key, Serializable value, TypeDefinition type, Object object, Class<?> objectType)
{
    if (DelegateTask.class.equals(objectType))
    {
        return handleDelegateTaskProperty((DelegateTask)object, type, key, value);
    }
    else if (Task.class.equals(objectType))
    {
        return handleTaskProperty((Task)object, type, key, value);
    }
    return handleProcessPropert(null, type, key, value);
}
 
示例24
public TypeDefinition getFullTaskDefinition(DelegateTask delegateTask)
{
    FormData formData = null;
    TaskEntity taskEntity = (TaskEntity) delegateTask;
    TaskFormHandler taskFormHandler = taskEntity.getTaskDefinition().getTaskFormHandler();
    if (taskFormHandler != null)
    {
        formData = taskFormHandler.createTaskForm(taskEntity);
    }
    return getFullTaskDefinition(delegateTask.getId(), formData);
}
 
示例25
/**
 * @param path WorkflowPath
 * @param instance ProcessInstance
 */
private void endStartTaskAutomatically(WorkflowPath path, ProcessInstance instance)
{
    // Check if StartTask Needs to be ended automatically
    WorkflowDefinition definition = path.getInstance().getDefinition();
    TypeDefinition metadata = definition.getStartTaskDefinition().getMetadata();
    Set<QName> aspects = metadata.getDefaultAspectNames();
    if(aspects.contains(WorkflowModel.ASPECT_END_AUTOMATICALLY))
    {
        String taskId = ActivitiConstants.START_TASK_PREFIX + instance.getId();
        endStartTask(taskId);
    }
}
 
示例26
private Map<String, Object> buildTypeDefinition(TypeDefinition typeDefinition)
{
    Map<String, Object> model = new HashMap<String, Object>();

    model.put(TYPE_DEFINITION_NAME, typeDefinition.getName());
    model.put(TYPE_DEFINITION_TITLE, typeDefinition.getTitle(dictionaryService));
    model.put(TYPE_DEFINITION_DESCRIPTION, typeDefinition.getDescription(dictionaryService));
    model.put(TYPE_DEFINITION_URL, getUrl(typeDefinition));

    return model;
}
 
示例27
/**
* {@inheritDoc}
*/
@Override
protected Object handleDelegateTaskProperty(DelegateTask task, TypeDefinition type, QName key, Serializable value)
{
    checkType(key, value, Date.class);
    task.setDueDate((Date) value);
    return DO_NOT_ADD;
}
 
示例28
/**
* {@inheritDoc}
*/

@Override
protected Object handleTaskProperty(Task task, TypeDefinition type, QName key, Serializable value)
{
    int priority;
    // ACE-3121: Workflow Admin Console: Cannot change priority for activiti
    // It could be a String that converts to an int, like when coming from WorkflowInterpreter.java
    if (value instanceof String)
    {
        try
        {
            priority = Integer.parseInt((String) value);
        }
        catch (NumberFormatException e)
        {
            throw getInvalidPropertyValueException(key, value);
        }
    }
    else
    {
        checkType(key, value, Integer.class);
        priority = (Integer) value;
    }

    // Priority value validation not performed to allow for future model changes
    task.setPriority(priority);

    return DO_NOT_ADD;
}
 
示例29
/**
* {@inheritDoc}
*/

@Override
protected Object handleDelegateTaskProperty(DelegateTask task, TypeDefinition type, QName key, Serializable value)
{
    checkType(key, value, Integer.class);
    task.setPriority((Integer) value);
    return DO_NOT_ADD;
}
 
示例30
/**
* {@inheritDoc}
*/
@Override
protected Object handleTaskProperty(Task task, TypeDefinition type, QName key, Serializable value)
{
    //Task assignment needs to be done after setting all properties
    // so it is handled in ActivitiPropertyConverter.
    return DO_NOT_ADD;
}