Search in sources :

Example 16 with AssociationDefinition

use of org.alfresco.service.cmr.dictionary.AssociationDefinition in project alfresco-repository by Alfresco.

the class RemoveChildAssocCommand method persistNode.

/**
 * Persists the given FormData on the given NodeRef
 *
 * @param nodeRef The NodeRef to persist the form data on
 * @param data The FormData to persist
 */
protected void persistNode(NodeRef nodeRef, FormData data) {
    // get the property definitions for the type of node being persisted
    QName type = this.nodeService.getType(nodeRef);
    TypeDefinition typeDef = this.dictionaryService.getAnonymousType(type, this.nodeService.getAspects(nodeRef));
    Map<QName, AssociationDefinition> assocDefs = typeDef.getAssociations();
    Map<QName, ChildAssociationDefinition> childAssocDefs = typeDef.getChildAssociations();
    Map<QName, PropertyDefinition> propDefs = typeDef.getProperties();
    Map<QName, Serializable> propsToPersist = new HashMap<QName, Serializable>(data.getNumberOfFields());
    List<AbstractAssocCommand> assocsToPersist = new ArrayList<AbstractAssocCommand>();
    for (FieldData fieldData : data) {
        // NOTE: ignore file fields for now, not supported yet!
        if (fieldData.isFile() == false) {
            String fieldName = fieldData.getName();
            if (fieldName.startsWith(PROP_DATA_PREFIX)) {
                processPropertyPersist(nodeRef, propDefs, fieldData, propsToPersist, data);
            } else if (fieldName.startsWith(ASSOC_DATA_PREFIX)) {
                processAssociationPersist(nodeRef, assocDefs, childAssocDefs, fieldData, assocsToPersist);
            } else if (getLogger().isWarnEnabled()) {
                getLogger().warn("Ignoring unrecognised field '" + fieldName + "'");
            }
        }
    }
    // persist the properties using addProperties as this changes the repo
    // values of
    // those properties included in the Map, but leaves any other property
    // values unchanged,
    // whereas setProperties causes the deletion of properties that are not
    // included in the Map.
    this.nodeService.addProperties(nodeRef, propsToPersist);
    for (AbstractAssocCommand cmd : assocsToPersist) {
        // TODO If there is an attempt to add and remove the same assoc in
        // one request,
        // we could drop each request and do nothing.
        cmd.updateAssociations(nodeService);
    }
}
Also used : Serializable(java.io.Serializable) HashMap(java.util.HashMap) QName(org.alfresco.service.namespace.QName) ArrayList(java.util.ArrayList) PropertyDefinition(org.alfresco.service.cmr.dictionary.PropertyDefinition) TypeDefinition(org.alfresco.service.cmr.dictionary.TypeDefinition) DataTypeDefinition(org.alfresco.service.cmr.dictionary.DataTypeDefinition) FieldData(org.alfresco.repo.forms.FormData.FieldData) ChildAssociationDefinition(org.alfresco.service.cmr.dictionary.ChildAssociationDefinition) AssociationDefinition(org.alfresco.service.cmr.dictionary.AssociationDefinition) ChildAssociationDefinition(org.alfresco.service.cmr.dictionary.ChildAssociationDefinition)

Example 17 with AssociationDefinition

use of org.alfresco.service.cmr.dictionary.AssociationDefinition in project alfresco-repository by Alfresco.

the class ActivitiPropertyConverter method getTaskProperties.

public Map<QName, Serializable> getTaskProperties(Task task) {
    // retrieve type definition for task
    TypeDefinition taskDef = typeManager.getFullTaskDefinition(task);
    Map<QName, PropertyDefinition> taskProperties = taskDef.getProperties();
    Map<QName, AssociationDefinition> taskAssociations = taskDef.getAssociations();
    TaskService taskService = activitiUtil.getTaskService();
    // Get all task variables including execution vars.
    Map<String, Object> variables = taskService.getVariables(task.getId());
    Map<String, Object> localVariables = taskService.getVariablesLocal(task.getId());
    // Map the arbitrary properties
    Map<QName, Serializable> properties = mapArbitraryProperties(variables, localVariables, taskProperties, taskAssociations);
    // Map activiti task instance fields to properties
    properties.put(WorkflowModel.PROP_TASK_ID, task.getId());
    properties.put(WorkflowModel.PROP_DESCRIPTION, task.getDescription());
    // Since the task is never started explicitally, we use the create time
    properties.put(WorkflowModel.PROP_START_DATE, task.getCreateTime());
    // Due date is present on the task
    properties.put(WorkflowModel.PROP_DUE_DATE, task.getDueDate());
    // Since this is a runtime-task, it's not completed yet
    properties.put(WorkflowModel.PROP_COMPLETION_DATE, null);
    properties.put(WorkflowModel.PROP_PRIORITY, task.getPriority());
    properties.put(ContentModel.PROP_CREATED, task.getCreateTime());
    properties.put(ContentModel.PROP_OWNER, task.getAssignee());
    // Be sure to fetch the outcome
    String outcomeVarName = factory.mapQNameToName(WorkflowModel.PROP_OUTCOME);
    if (variables.get(outcomeVarName) != null) {
        properties.put(WorkflowModel.PROP_OUTCOME, (Serializable) variables.get(outcomeVarName));
    }
    List<IdentityLink> links = taskService.getIdentityLinksForTask(task.getId());
    mapPooledActors(links, properties);
    return filterTaskProperties(properties);
}
Also used : Serializable(java.io.Serializable) QName(org.alfresco.service.namespace.QName) TaskService(org.activiti.engine.TaskService) PropertyDefinition(org.alfresco.service.cmr.dictionary.PropertyDefinition) IdentityLink(org.activiti.engine.task.IdentityLink) TypeDefinition(org.alfresco.service.cmr.dictionary.TypeDefinition) AssociationDefinition(org.alfresco.service.cmr.dictionary.AssociationDefinition)

Example 18 with AssociationDefinition

use of org.alfresco.service.cmr.dictionary.AssociationDefinition in project alfresco-repository by Alfresco.

the class ActivitiPropertyConverter method getTaskProperties.

@SuppressWarnings("unchecked")
public Map<QName, Serializable> getTaskProperties(HistoricTaskInstance historicTask, Map<String, Object> localVariables) {
    // Retrieve type definition for task, based on taskFormKey variable
    String formKey = (String) localVariables.get(ActivitiConstants.PROP_TASK_FORM_KEY);
    TypeDefinition taskDef = typeManager.getFullTaskDefinition(formKey);
    Map<QName, PropertyDefinition> taskProperties = taskDef.getProperties();
    Map<QName, AssociationDefinition> taskAssociations = taskDef.getAssociations();
    Map<String, Object> allVariables = getHistoricProcessVariables(historicTask.getProcessInstanceId());
    allVariables.putAll(localVariables);
    // Map the arbitrary properties
    Map<QName, Serializable> properties = mapArbitraryProperties(allVariables, localVariables, taskProperties, taskAssociations);
    // Map activiti task instance fields to properties
    properties.put(WorkflowModel.PROP_TASK_ID, historicTask.getId());
    properties.put(WorkflowModel.PROP_DESCRIPTION, historicTask.getDescription());
    // Since the task is never started explicitly, we use the create time
    properties.put(WorkflowModel.PROP_START_DATE, historicTask.getStartTime());
    properties.put(WorkflowModel.PROP_DUE_DATE, historicTask.getDueDate());
    properties.put(WorkflowModel.PROP_COMPLETION_DATE, historicTask.getEndTime());
    properties.put(WorkflowModel.PROP_PRIORITY, historicTask.getPriority());
    properties.put(ContentModel.PROP_CREATED, historicTask.getStartTime());
    properties.put(ContentModel.PROP_OWNER, historicTask.getAssignee());
    // Be sure to fetch the outcome
    String outcomeVarName = factory.mapQNameToName(WorkflowModel.PROP_OUTCOME);
    if (localVariables.get(outcomeVarName) != null) {
        properties.put(WorkflowModel.PROP_OUTCOME, (Serializable) localVariables.get(outcomeVarName));
    }
    // History of pooled actors is stored in task variable
    List<NodeRef> pooledActors = new ArrayList<NodeRef>();
    List<String> pooledActorRefIds = (List<String>) localVariables.get(ActivitiConstants.PROP_POOLED_ACTORS_HISTORY);
    if (pooledActorRefIds != null) {
        for (String nodeId : pooledActorRefIds) {
            pooledActors.add(new NodeRef(nodeId));
        }
    }
    // Add pooled actors. When no actors are found, set empty list
    properties.put(WorkflowModel.ASSOC_POOLED_ACTORS, (Serializable) pooledActors);
    return filterTaskProperties(properties);
}
Also used : Serializable(java.io.Serializable) QName(org.alfresco.service.namespace.QName) ArrayList(java.util.ArrayList) PropertyDefinition(org.alfresco.service.cmr.dictionary.PropertyDefinition) TypeDefinition(org.alfresco.service.cmr.dictionary.TypeDefinition) NodeRef(org.alfresco.service.cmr.repository.NodeRef) AssociationDefinition(org.alfresco.service.cmr.dictionary.AssociationDefinition) List(java.util.List) ArrayList(java.util.ArrayList)

Example 19 with AssociationDefinition

use of org.alfresco.service.cmr.dictionary.AssociationDefinition in project alfresco-repository by Alfresco.

the class ActivitiPropertyConverter method getMissingMandatoryTaskProperties.

/**
 * Get missing mandatory properties on Task
 *
 * @param task
 *            task instance
 * @return array of missing property names (or null, if none)
 */
private List<QName> getMissingMandatoryTaskProperties(DelegateTask task) {
    TypeDefinition typeDefinition = typeManager.getFullTaskDefinition(task);
    // retrieve properties of task
    Map<QName, Serializable> existingValues = getTaskProperties(task, typeDefinition, false);
    Map<QName, PropertyDefinition> propertyDefs = typeDefinition.getProperties();
    Map<QName, AssociationDefinition> assocDefs = typeDefinition.getAssociations();
    List<QName> missingProps = findMissingProperties(existingValues, propertyDefs);
    List<QName> missingAssocs = findMissingProperties(existingValues, assocDefs);
    missingProps.addAll(missingAssocs);
    return missingProps;
}
Also used : Serializable(java.io.Serializable) AssociationDefinition(org.alfresco.service.cmr.dictionary.AssociationDefinition) QName(org.alfresco.service.namespace.QName) PropertyDefinition(org.alfresco.service.cmr.dictionary.PropertyDefinition) TypeDefinition(org.alfresco.service.cmr.dictionary.TypeDefinition)

Example 20 with AssociationDefinition

use of org.alfresco.service.cmr.dictionary.AssociationDefinition in project alfresco-repository by Alfresco.

the class ChildAssociatedNodeFinder method init.

public void init() {
    super.init();
    // Quickly scan the supplied association types and remove any that either
    // do not exist or are not child association types.
    DictionaryService dictionaryService = serviceRegistry.getDictionaryService();
    childAssociationTypes.clear();
    for (QName associationType : suppliedAssociationTypes) {
        AssociationDefinition assocDef = dictionaryService.getAssociation(associationType);
        if (assocDef != null && assocDef.isChild()) {
            childAssociationTypes.add(associationType);
        }
    }
    initialised = true;
}
Also used : DictionaryService(org.alfresco.service.cmr.dictionary.DictionaryService) AssociationDefinition(org.alfresco.service.cmr.dictionary.AssociationDefinition) QName(org.alfresco.service.namespace.QName)

Aggregations

AssociationDefinition (org.alfresco.service.cmr.dictionary.AssociationDefinition)60 QName (org.alfresco.service.namespace.QName)46 PropertyDefinition (org.alfresco.service.cmr.dictionary.PropertyDefinition)24 ChildAssociationDefinition (org.alfresco.service.cmr.dictionary.ChildAssociationDefinition)19 NodeRef (org.alfresco.service.cmr.repository.NodeRef)17 TypeDefinition (org.alfresco.service.cmr.dictionary.TypeDefinition)15 HashMap (java.util.HashMap)13 Serializable (java.io.Serializable)11 ArrayList (java.util.ArrayList)11 ClassDefinition (org.alfresco.service.cmr.dictionary.ClassDefinition)9 DataTypeDefinition (org.alfresco.service.cmr.dictionary.DataTypeDefinition)7 AlfrescoRuntimeException (org.alfresco.error.AlfrescoRuntimeException)6 AspectDefinition (org.alfresco.service.cmr.dictionary.AspectDefinition)6 ChildAssociationRef (org.alfresco.service.cmr.repository.ChildAssociationRef)6 Collection (java.util.Collection)5 AssociationRef (org.alfresco.service.cmr.repository.AssociationRef)5 HashSet (java.util.HashSet)4 List (java.util.List)4 Map (java.util.Map)4 Pair (org.alfresco.util.Pair)3