Search in sources :

Example 31 with M2Model

use of org.alfresco.repo.dictionary.M2Model in project records-management by Alfresco.

the class RelationshipServiceImpl method persistUpdatedAssocTitle.

/**
 * This method writes the specified String into the association's title property.
 * For RM custom properties and references, Title is used to store the identifier.
 *
 * NOTE: Currently RMC custom associations only
 * @param associationDefinitionQName Qualified name for the association definition
 * @param newTitle The new title
 * @return Qualified name for the association definition
 */
private QName persistUpdatedAssocTitle(QName associationDefinitionQName, String newTitle) {
    mandatory("associationDefinitionQName", associationDefinitionQName);
    AssociationDefinition assocDefn = getDictionaryService().getAssociation(associationDefinitionQName);
    if (assocDefn == null) {
        StringBuilder sb = new StringBuilder();
        sb.append("Cannot find the association definiton for '").append(associationDefinitionQName.getLocalName()).append("'.");
        throw new AlfrescoRuntimeException(sb.toString());
    }
    // defaults to RM_CUSTOM_URI
    NodeRef modelRef = getCustomModelRef("");
    M2Model deserializedModel = readCustomContentModel(modelRef);
    String customAspectName = ASPECT_CUSTOM_ASSOCIATIONS.toPrefixString(getNamespaceService());
    M2Aspect customAssocsAspect = deserializedModel.getAspect(customAspectName);
    for (M2ClassAssociation assoc : customAssocsAspect.getAssociations()) {
        if (associationDefinitionQName.toPrefixString(getNamespaceService()).equals(assoc.getName()) && newTitle != null) {
            assoc.setTitle(newTitle);
        }
    }
    writeCustomContentModel(modelRef, deserializedModel);
    if (logger.isInfoEnabled()) {
        logger.info("persistUpdatedAssocTitle: " + associationDefinitionQName + "=" + newTitle + " to aspect: " + customAspectName);
    }
    return associationDefinitionQName;
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) AssociationDefinition(org.alfresco.service.cmr.dictionary.AssociationDefinition) ChildAssociationDefinition(org.alfresco.service.cmr.dictionary.ChildAssociationDefinition) M2Model(org.alfresco.repo.dictionary.M2Model) AlfrescoRuntimeException(org.alfresco.error.AlfrescoRuntimeException) ParameterCheck.mandatoryString(org.alfresco.util.ParameterCheck.mandatoryString) M2Aspect(org.alfresco.repo.dictionary.M2Aspect) M2ClassAssociation(org.alfresco.repo.dictionary.M2ClassAssociation)

Example 32 with M2Model

use of org.alfresco.repo.dictionary.M2Model in project records-management by Alfresco.

the class RelationshipServiceImpl method createRelationshipDefinition.

/**
 * @see org.alfresco.module.org_alfresco_module_rm.relationship.RelationshipService#createRelationshipDefinition(org.alfresco.module.org_alfresco_module_rm.relationship.RelationshipDisplayName)
 */
@Override
public RelationshipDefinition createRelationshipDefinition(RelationshipDisplayName displayName) {
    mandatory("displayName", displayName);
    String title;
    RelationshipType type = determineRelationshipTypeFromDisplayName(displayName);
    switch(type) {
        case BIDIRECTIONAL:
            title = displayName.getSourceText();
            break;
        case PARENTCHILD:
            String sourceText = displayName.getSourceText();
            String targetText = displayName.getTargetText();
            title = composeAssociationDefinitionTitle(sourceText, targetText);
            break;
        default:
            StringBuilder sb = new StringBuilder();
            sb.append("Unsupported relationship type: '").append(type.toString()).append("'.");
            throw new AlfrescoRuntimeException(sb.toString());
    }
    // If this title is already taken...
    if (existsTitle(title)) {
        StringBuilder sb = new StringBuilder();
        sb.append("Cannot create a relationship definition for the display name: '").append(displayName.toString()).append("' as there is already a relationship definition with this display name.");
        throw new AlfrescoRuntimeException(sb.toString());
    }
    // Defaults to RM_CUSTOM_URI
    NodeRef modelRef = getCustomModelRef("");
    M2Model deserializedModel = readCustomContentModel(modelRef);
    String customAspectName = ASPECT_CUSTOM_ASSOCIATIONS.toPrefixString(getNamespaceService());
    M2Aspect customAssocsAspect = deserializedModel.getAspect(customAspectName);
    if (customAssocsAspect == null) {
        StringBuilder sb = new StringBuilder();
        sb.append("The aspect: '").append(customAspectName).append("' is undefined.");
        throw new AlfrescoRuntimeException(sb.toString());
    }
    QName relationshipDefinitionQName = generateRelationshipDefinitionQNameFor(title);
    String generatedShortQName = relationshipDefinitionQName.toPrefixString(getNamespaceService());
    M2ClassAssociation customAssoc = customAssocsAspect.getAssociation(generatedShortQName);
    if (customAssoc != null) {
        StringBuilder sb = new StringBuilder();
        sb.append("The association: '").append(customAssoc.getName()).append("' already exists.");
        throw new AlfrescoRuntimeException(sb.toString());
    }
    M2ClassAssociation newAssoc;
    switch(type) {
        case BIDIRECTIONAL:
            newAssoc = customAssocsAspect.createAssociation(generatedShortQName);
            break;
        case PARENTCHILD:
            newAssoc = customAssocsAspect.createChildAssociation(generatedShortQName);
            break;
        default:
            StringBuilder sb = new StringBuilder();
            sb.append("Unsupported relationship type: '").append(type.toString()).append("'.");
            throw new AlfrescoRuntimeException(sb.toString());
    }
    newAssoc.setSourceMandatory(false);
    newAssoc.setTargetMandatory(false);
    // MOB-1573
    newAssoc.setSourceMany(true);
    newAssoc.setTargetMany(true);
    newAssoc.setTitle(title);
    newAssoc.setTargetClassName(RecordsManagementModel.ASPECT_RECORD.toPrefixString(getNamespaceService()));
    writeCustomContentModel(modelRef, deserializedModel);
    return new RelationshipDefinitionImpl(relationshipDefinitionQName.getLocalName(), type, displayName);
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) QName(org.alfresco.service.namespace.QName) M2Model(org.alfresco.repo.dictionary.M2Model) AlfrescoRuntimeException(org.alfresco.error.AlfrescoRuntimeException) ParameterCheck.mandatoryString(org.alfresco.util.ParameterCheck.mandatoryString) M2Aspect(org.alfresco.repo.dictionary.M2Aspect) M2ClassAssociation(org.alfresco.repo.dictionary.M2ClassAssociation)

Aggregations

M2Model (org.alfresco.repo.dictionary.M2Model)32 AlfrescoRuntimeException (org.alfresco.error.AlfrescoRuntimeException)18 NodeRef (org.alfresco.service.cmr.repository.NodeRef)15 M2Aspect (org.alfresco.repo.dictionary.M2Aspect)10 QName (org.alfresco.service.namespace.QName)10 ParameterCheck.mandatoryString (org.springframework.extensions.surf.util.ParameterCheck.mandatoryString)10 M2Property (org.alfresco.repo.dictionary.M2Property)8 InputStream (java.io.InputStream)6 M2Constraint (org.alfresco.repo.dictionary.M2Constraint)6 File (java.io.File)5 IOException (java.io.IOException)4 HashMap (java.util.HashMap)4 M2ClassAssociation (org.alfresco.repo.dictionary.M2ClassAssociation)4 PropertyDefinition (org.alfresco.service.cmr.dictionary.PropertyDefinition)4 ByteArrayOutputStream (java.io.ByteArrayOutputStream)3 ArrayList (java.util.ArrayList)3 ZipFile (java.util.zip.ZipFile)3 AlfrescoModel (org.alfresco.solr.client.AlfrescoModel)3 HashSet (java.util.HashSet)2 M2Namespace (org.alfresco.repo.dictionary.M2Namespace)2