Search in sources :

Example 41 with TypeDefinition

use of org.alfresco.service.cmr.dictionary.TypeDefinition in project alfresco-remote-api by Alfresco.

the class AbstractWorkflowRestApiTest method checkWorkflowTaskDefinition.

private void checkWorkflowTaskDefinition(WorkflowTaskDefinition wfDefinition, JSONObject definition) throws Exception {
    assertNotNull(definition);
    assertEquals(wfDefinition.getId(), definition.getString("id"));
    assertTrue(definition.has("url"));
    JSONObject type = definition.getJSONObject("type");
    TypeDefinition startType = (wfDefinition).getMetadata();
    assertNotNull(type);
    assertEquals(startType.getName().toPrefixString(), type.getString("name"));
    assertEquals(startType.getTitle(this.dictionaryService), type.getString("title"));
    assertEquals(startType.getDescription(this.dictionaryService), type.getString("description"));
    assertTrue(type.has("url"));
    JSONObject node = definition.getJSONObject("node");
    WorkflowNode startNode = wfDefinition.getNode();
    assertNotNull(node);
    assertEquals(startNode.getName(), node.getString("name"));
    assertEquals(startNode.getTitle(), node.getString("title"));
    assertEquals(startNode.getDescription(), node.getString("description"));
    assertEquals(startNode.isTaskNode(), node.getBoolean("isTaskNode"));
    JSONArray transitions = node.getJSONArray("transitions");
    WorkflowTransition[] startTransitions = startNode.getTransitions();
    assertNotNull(transitions);
    assertEquals(startTransitions.length, transitions.length());
    for (int i = 0; i < transitions.length(); i++) {
        JSONObject transition = transitions.getJSONObject(i);
        WorkflowTransition startTransition = startTransitions[i];
        assertNotNull(transition);
        if (startTransition.getId() == null) {
            assertEquals("", transition.getString("id"));
        } else {
            assertEquals(startTransition.getId(), transition.getString("id"));
        }
        assertEquals(startTransition.getTitle(), transition.getString("title"));
        assertEquals(startTransition.getDescription(), transition.getString("description"));
        assertEquals(startTransition.isDefault(), transition.getBoolean("isDefault"));
        assertTrue(transition.has("isHidden"));
    }
}
Also used : JSONObject(org.json.JSONObject) JSONArray(org.json.JSONArray) WorkflowTransition(org.alfresco.service.cmr.workflow.WorkflowTransition) WorkflowNode(org.alfresco.service.cmr.workflow.WorkflowNode) TypeDefinition(org.alfresco.service.cmr.dictionary.TypeDefinition)

Example 42 with TypeDefinition

use of org.alfresco.service.cmr.dictionary.TypeDefinition in project records-management by Alfresco.

the class RecordsManagementAdminServiceImpl method getCustomisable.

/**
 * @see org.alfresco.module.org_alfresco_module_rm.RecordsManagementAdminService#getCustomisable(org.alfresco.service.cmr.repository.NodeRef)
 */
@Override
public Set<QName> getCustomisable(NodeRef nodeRef) {
    mandatory("nodeRef", nodeRef);
    Set<QName> result = new HashSet<QName>(5);
    // Check the nodes hierarchy for customisable types
    QName type = getNodeService().getType(nodeRef);
    while (type != null && !ContentModel.TYPE_CMOBJECT.equals(type)) {
        // Add to the list if the type is customisable
        if (isCustomisable(type)) {
            result.add(type);
        }
        // Type and get the types parent
        TypeDefinition def = getDictionaryService().getType(type);
        if (def != null) {
            type = def.getParentName();
        } else {
            type = null;
        }
    }
    // Get all the nodes aspects
    Set<QName> aspects = getNodeService().getAspects(nodeRef);
    for (QName aspect : aspects) {
        QName tempAspect = QName.createQName(aspect.toString());
        while (tempAspect != null) {
            // Add to the list if the aspect is customisable
            if (isCustomisable(tempAspect)) {
                result.add(tempAspect);
            }
            // Try and get the parent aspect
            AspectDefinition aspectDef = getDictionaryService().getAspect(tempAspect);
            if (aspectDef != null) {
                tempAspect = aspectDef.getParentName();
            } else {
                tempAspect = null;
            }
        }
    }
    return result;
}
Also used : QName(org.alfresco.service.namespace.QName) AspectDefinition(org.alfresco.service.cmr.dictionary.AspectDefinition) HashSet(java.util.HashSet) TypeDefinition(org.alfresco.service.cmr.dictionary.TypeDefinition) DataTypeDefinition(org.alfresco.service.cmr.dictionary.DataTypeDefinition)

Example 43 with TypeDefinition

use of org.alfresco.service.cmr.dictionary.TypeDefinition in project records-management by Alfresco.

the class RecordServiceImpl method validateForCompletion.

/**
 * Helper method to validate whether the node is in a state suitable for completion
 *
 * @param nodeRef node reference
 * @throws Exception if node not valid for completion
 */
private void validateForCompletion(NodeRef nodeRef) {
    if (!nodeService.exists(nodeRef)) {
        LOGGER.warn(I18NUtil.getMessage(MSG_UNDECLARED_ONLY_RECORDS, nodeRef.toString()));
        throw new IntegrityException("The record does not exist.", null);
    }
    if (!isRecord(nodeRef)) {
        LOGGER.warn(I18NUtil.getMessage(MSG_UNDECLARED_ONLY_RECORDS, nodeRef.toString()));
        throw new IntegrityException("The node is not a record.", null);
    }
    if (freezeService.isFrozen(nodeRef)) {
        LOGGER.warn(I18NUtil.getMessage(MSG_UNDECLARED_ONLY_RECORDS, nodeRef.toString()));
        throw new IntegrityException("The record is frozen.", null);
    }
    if (isDeclared(nodeRef)) {
        throw new IntegrityException("The record is already completed.", null);
    }
    // if the record is newly created make sure the record identifier is set before completing the record
    Set<NodeRef> newRecords = transactionalResourceHelper.getSet(RecordServiceImpl.KEY_NEW_RECORDS);
    if (newRecords.contains(nodeRef)) {
        generateRecordIdentifier(nodeService, identifierService, nodeRef);
    }
    // Validate that all mandatory properties, if any, are present
    List<String> missingProperties = new ArrayList<>(5);
    // Aspect not already defined - check mandatory properties then add
    if (checkMandatoryPropertiesEnabled) {
        Map<QName, Serializable> nodeRefProps = nodeService.getProperties(nodeRef);
        QName nodeRefType = nodeService.getType(nodeRef);
        // check for missing mandatory metadata from type definitions
        TypeDefinition typeDef = dictionaryService.getType(nodeRefType);
        checkDefinitionMandatoryPropsSet(typeDef, nodeRefProps, missingProperties);
        // check for missing mandatory metadata from aspect definitions
        Set<QName> aspects = nodeService.getAspects(nodeRef);
        for (QName aspect : aspects) {
            AspectDefinition aspectDef = dictionaryService.getAspect(aspect);
            checkDefinitionMandatoryPropsSet(aspectDef, nodeRefProps, missingProperties);
        }
        // check for missing mandatory metadata from custom aspect definitions
        QName customAspect = getCustomAspectImpl(nodeRefType);
        AspectDefinition aspectDef = dictionaryService.getAspect(customAspect);
        checkDefinitionMandatoryPropsSet(aspectDef, nodeRefProps, missingProperties);
        if (!missingProperties.isEmpty()) {
            LOGGER.debug(buildMissingPropertiesErrorString(missingProperties));
            throw new RecordMissingMetadataException("The record has missing mandatory properties.");
        }
    }
}
Also used : Serializable(java.io.Serializable) QName(org.alfresco.service.namespace.QName) ArrayList(java.util.ArrayList) IntegrityException(org.alfresco.repo.node.integrity.IntegrityException) AspectDefinition(org.alfresco.service.cmr.dictionary.AspectDefinition) TypeDefinition(org.alfresco.service.cmr.dictionary.TypeDefinition) NodeRef(org.alfresco.service.cmr.repository.NodeRef)

Aggregations

TypeDefinition (org.alfresco.service.cmr.dictionary.TypeDefinition)43 QName (org.alfresco.service.namespace.QName)30 DataTypeDefinition (org.alfresco.service.cmr.dictionary.DataTypeDefinition)18 NodeRef (org.alfresco.service.cmr.repository.NodeRef)13 FacesContext (javax.faces.context.FacesContext)10 ArrayList (java.util.ArrayList)8 HashMap (java.util.HashMap)8 StartFormData (org.activiti.engine.form.StartFormData)8 IOException (java.io.IOException)7 PropertyDefinition (org.alfresco.service.cmr.dictionary.PropertyDefinition)7 Node (org.alfresco.web.bean.repository.Node)7 UserTransaction (javax.transaction.UserTransaction)6 InvalidArgumentException (org.alfresco.rest.framework.core.exceptions.InvalidArgumentException)6 DictionaryService (org.alfresco.service.cmr.dictionary.DictionaryService)6 ChildAssociationRef (org.alfresco.service.cmr.repository.ChildAssociationRef)6 Date (java.util.Date)5 SelectItem (javax.faces.model.SelectItem)5 MapNode (org.alfresco.web.bean.repository.MapNode)5 Serializable (java.io.Serializable)4 List (java.util.List)4