Search in sources :

Example 21 with AssociationRef

use of org.alfresco.service.cmr.repository.AssociationRef in project acs-community-packaging by Alfresco.

the class UIAssociationEditor method removeTarget.

/**
 * Updates the component and node state to reflect an association being removed
 *
 * @param node The node we are dealing with
 * @param targetRef The noderef of the child to remove
 */
protected void removeTarget(Node node, String targetRef) {
    if (node != null && targetRef != null) {
        QName assocQName = Repository.resolveToQName(this.associationName);
        AssociationRef newAssoc = new AssociationRef(null, node.getNodeRef(), assocQName, new NodeRef(targetRef));
        // was one of the original ones
        if (this.originalAssocs.containsKey(targetRef)) {
            Map<String, AssociationRef> removed = node.getRemovedAssociations().get(this.associationName);
            removed.put(targetRef, newAssoc);
            if (logger.isDebugEnabled())
                logger.debug("Added association to " + targetRef + " to the removed list");
        }
        // if this association was previously added in this session it will still be
        // in the added list so remove it if it is
        Map<String, AssociationRef> added = node.getAddedAssociations().get(this.associationName);
        if (added.containsKey(targetRef)) {
            added.remove(targetRef);
            if (logger.isDebugEnabled())
                logger.debug("Removed association to " + targetRef + " from the added list");
        }
    }
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) QName(org.alfresco.service.namespace.QName) AssociationRef(org.alfresco.service.cmr.repository.AssociationRef)

Example 22 with AssociationRef

use of org.alfresco.service.cmr.repository.AssociationRef in project acs-community-packaging by Alfresco.

the class EditSpaceDialog method finishImpl.

@Override
protected String finishImpl(FacesContext context, String outcome) throws Exception {
    // update the existing node in the repository
    NodeRef nodeRef = this.editableNode.getNodeRef();
    Map<String, Object> editedProps = this.editableNode.getProperties();
    // handle the name property separately, perform a rename in case it changed
    String name = (String) editedProps.get(ContentModel.PROP_NAME);
    if (name != null) {
        this.getFileFolderService().rename(nodeRef, name);
    }
    // build the properties to add to the repository
    Map<QName, Serializable> repoProps = new HashMap<QName, Serializable>(7);
    // overwrite the current properties with the edited ones
    Iterator<String> iterProps = editedProps.keySet().iterator();
    while (iterProps.hasNext()) {
        String propName = iterProps.next();
        QName qname = QName.createQName(propName);
        // make sure the property is represented correctly
        Serializable propValue = (Serializable) editedProps.get(propName);
        // check for empty strings when using number types, set to null in this case
        if ((propValue != null) && (propValue instanceof String) && (propValue.toString().length() == 0)) {
            PropertyDefinition propDef = this.getDictionaryService().getProperty(qname);
            if (propDef != null) {
                if (propDef.getDataType().getName().equals(DataTypeDefinition.DOUBLE) || propDef.getDataType().getName().equals(DataTypeDefinition.FLOAT) || propDef.getDataType().getName().equals(DataTypeDefinition.INT) || propDef.getDataType().getName().equals(DataTypeDefinition.LONG)) {
                    propValue = null;
                }
            }
        }
        repoProps.put(qname, propValue);
    }
    // add the new properties back to the repository
    this.getNodeService().addProperties(nodeRef, repoProps);
    // we also need to persist any association changes that may have been made
    // add any associations added in the UI
    Map<String, Map<String, AssociationRef>> addedAssocs = this.editableNode.getAddedAssociations();
    for (Map<String, AssociationRef> typedAssoc : addedAssocs.values()) {
        for (AssociationRef assoc : typedAssoc.values()) {
            this.getNodeService().createAssociation(assoc.getSourceRef(), assoc.getTargetRef(), assoc.getTypeQName());
        }
    }
    // remove any association removed in the UI
    Map<String, Map<String, AssociationRef>> removedAssocs = this.editableNode.getRemovedAssociations();
    for (Map<String, AssociationRef> typedAssoc : removedAssocs.values()) {
        for (AssociationRef assoc : typedAssoc.values()) {
            this.getNodeService().removeAssociation(assoc.getSourceRef(), assoc.getTargetRef(), assoc.getTypeQName());
        }
    }
    // add any child associations added in the UI
    Map<String, Map<String, ChildAssociationRef>> addedChildAssocs = this.editableNode.getAddedChildAssociations();
    for (Map<String, ChildAssociationRef> typedAssoc : addedChildAssocs.values()) {
        for (ChildAssociationRef assoc : typedAssoc.values()) {
            this.getNodeService().addChild(assoc.getParentRef(), assoc.getChildRef(), assoc.getTypeQName(), assoc.getTypeQName());
        }
    }
    // remove any child association removed in the UI
    Map<String, Map<String, ChildAssociationRef>> removedChildAssocs = this.editableNode.getRemovedChildAssociations();
    for (Map<String, ChildAssociationRef> typedAssoc : removedChildAssocs.values()) {
        for (ChildAssociationRef assoc : typedAssoc.values()) {
            this.getNodeService().removeChild(assoc.getParentRef(), assoc.getChildRef());
        }
    }
    // do nothing by default, subclasses can override if necessary
    return AlfrescoNavigationHandler.CLOSE_DIALOG_OUTCOME;
}
Also used : Serializable(java.io.Serializable) HashMap(java.util.HashMap) QName(org.alfresco.service.namespace.QName) ChildAssociationRef(org.alfresco.service.cmr.repository.ChildAssociationRef) PropertyDefinition(org.alfresco.service.cmr.dictionary.PropertyDefinition) AssociationRef(org.alfresco.service.cmr.repository.AssociationRef) ChildAssociationRef(org.alfresco.service.cmr.repository.ChildAssociationRef) NodeRef(org.alfresco.service.cmr.repository.NodeRef) HashMap(java.util.HashMap) Map(java.util.Map)

Example 23 with AssociationRef

use of org.alfresco.service.cmr.repository.AssociationRef in project acs-community-packaging by Alfresco.

the class UsersBeanProperties method getAvatarUrl.

public String getAvatarUrl() {
    String avatarUrl = null;
    List<AssociationRef> refs = getNodeService().getTargetAssocs(this.person.getNodeRef(), ContentModel.ASSOC_AVATAR);
    if (refs.size() == 1) {
        NodeRef photoRef = refs.get(0).getTargetRef();
        String name = (String) getNodeService().getProperty(photoRef, ContentModel.PROP_NAME);
        avatarUrl = DownloadContentServlet.generateBrowserURL(photoRef, name);
    }
    return avatarUrl;
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) AssociationRef(org.alfresco.service.cmr.repository.AssociationRef)

Example 24 with AssociationRef

use of org.alfresco.service.cmr.repository.AssociationRef in project acs-community-packaging by Alfresco.

the class EditContentPropertiesDialog method finishImpl.

@Override
protected String finishImpl(FacesContext context, String outcome) throws Exception {
    NodeRef nodeRef = this.editableNode.getNodeRef();
    Map<String, Object> editedProps = this.editableNode.getProperties();
    // get the name and move the node as necessary
    String name = (String) editedProps.get(ContentModel.PROP_NAME);
    if (name != null) {
        getFileFolderService().rename(nodeRef, name);
    }
    // we need to put all the properties from the editable bag back into
    // the format expected by the repository
    Map<QName, Serializable> repoProps = this.getNodeService().getProperties(nodeRef);
    // Extract and deal with the special mimetype property for ContentData
    String mimetype = (String) editedProps.get(TEMP_PROP_MIMETYPE);
    if (mimetype != null) {
        // remove temporary prop from list so it isn't saved with the others
        editedProps.remove(TEMP_PROP_MIMETYPE);
        ContentData contentData = (ContentData) editedProps.get(ContentModel.PROP_CONTENT);
        if (contentData != null) {
            contentData = ContentData.setMimetype(contentData, mimetype);
            editedProps.put(ContentModel.PROP_CONTENT.toString(), contentData);
        }
    }
    // Extract and deal with the special encoding property for ContentData
    String encoding = (String) editedProps.get(TEMP_PROP_ENCODING);
    if (encoding != null) {
        // remove temporary prop from list so it isn't saved with the others
        editedProps.remove(TEMP_PROP_ENCODING);
        ContentData contentData = (ContentData) editedProps.get(ContentModel.PROP_CONTENT);
        if (contentData != null) {
            contentData = ContentData.setEncoding(contentData, encoding);
            editedProps.put(ContentModel.PROP_CONTENT.toString(), contentData);
        }
    }
    // add the "author" aspect if required, properties will get set below
    if (this.getNodeService().hasAspect(nodeRef, ContentModel.ASPECT_AUTHOR) == false) {
        this.getNodeService().addAspect(nodeRef, ContentModel.ASPECT_AUTHOR, null);
    }
    // add the "titled" aspect if required, properties will get set below
    if (this.getNodeService().hasAspect(nodeRef, ContentModel.ASPECT_TITLED) == false) {
        getNodeService().addAspect(nodeRef, ContentModel.ASPECT_TITLED, null);
    }
    // add the remaining properties
    Iterator<String> iterProps = editedProps.keySet().iterator();
    while (iterProps.hasNext()) {
        String propName = iterProps.next();
        QName qname = QName.createQName(propName);
        // make sure the property is represented correctly
        Serializable propValue = (Serializable) editedProps.get(propName);
        // check for empty strings when using number types, set to null in this case
        if (propValue instanceof String) {
            PropertyDefinition propDef = this.getDictionaryService().getProperty(qname);
            if (((String) propValue).length() == 0) {
                if (propDef != null) {
                    if (propDef.getDataType().getName().equals(DataTypeDefinition.DOUBLE) || propDef.getDataType().getName().equals(DataTypeDefinition.FLOAT) || propDef.getDataType().getName().equals(DataTypeDefinition.INT) || propDef.getDataType().getName().equals(DataTypeDefinition.LONG)) {
                        propValue = null;
                    }
                }
            } else // handle locale strings to Locale objects
            if (propDef != null && propDef.getDataType().getName().equals(DataTypeDefinition.LOCALE)) {
                propValue = I18NUtil.parseLocale((String) propValue);
            }
        }
        repoProps.put(qname, propValue);
    }
    // send the properties back to the repository
    this.getNodeService().setProperties(nodeRef, repoProps);
    // we also need to persist any association changes that may have been made
    // add any associations added in the UI
    Map<String, Map<String, AssociationRef>> addedAssocs = this.editableNode.getAddedAssociations();
    for (Map<String, AssociationRef> typedAssoc : addedAssocs.values()) {
        for (AssociationRef assoc : typedAssoc.values()) {
            this.getNodeService().createAssociation(assoc.getSourceRef(), assoc.getTargetRef(), assoc.getTypeQName());
        }
    }
    // remove any association removed in the UI
    Map<String, Map<String, AssociationRef>> removedAssocs = this.editableNode.getRemovedAssociations();
    for (Map<String, AssociationRef> typedAssoc : removedAssocs.values()) {
        for (AssociationRef assoc : typedAssoc.values()) {
            this.getNodeService().removeAssociation(assoc.getSourceRef(), assoc.getTargetRef(), assoc.getTypeQName());
        }
    }
    // add any child associations added in the UI
    Map<String, Map<String, ChildAssociationRef>> addedChildAssocs = this.editableNode.getAddedChildAssociations();
    for (Map<String, ChildAssociationRef> typedAssoc : addedChildAssocs.values()) {
        for (ChildAssociationRef assoc : typedAssoc.values()) {
            this.getNodeService().addChild(assoc.getParentRef(), assoc.getChildRef(), assoc.getTypeQName(), assoc.getTypeQName());
        }
    }
    // remove any child association removed in the UI
    Map<String, Map<String, ChildAssociationRef>> removedChildAssocs = this.editableNode.getRemovedChildAssociations();
    for (Map<String, ChildAssociationRef> typedAssoc : removedChildAssocs.values()) {
        for (ChildAssociationRef assoc : typedAssoc.values()) {
            this.getNodeService().removeChild(assoc.getParentRef(), assoc.getChildRef());
        }
    }
    return outcome;
}
Also used : Serializable(java.io.Serializable) QName(org.alfresco.service.namespace.QName) ChildAssociationRef(org.alfresco.service.cmr.repository.ChildAssociationRef) PropertyDefinition(org.alfresco.service.cmr.dictionary.PropertyDefinition) AssociationRef(org.alfresco.service.cmr.repository.AssociationRef) ChildAssociationRef(org.alfresco.service.cmr.repository.ChildAssociationRef) NodeRef(org.alfresco.service.cmr.repository.NodeRef) ContentData(org.alfresco.service.cmr.repository.ContentData) Map(java.util.Map)

Example 25 with AssociationRef

use of org.alfresco.service.cmr.repository.AssociationRef in project acs-community-packaging by Alfresco.

the class Node method getAssociations.

/**
 * @return All the associations this node has as a Map, using the association
 *         type as the key
 */
public final Map getAssociations() {
    if (this.assocsRetrieved == false) {
        this.associations = new QNameNodeMap(this, this);
        List<AssociationRef> assocs = getServiceRegistry().getNodeService().getTargetAssocs(this.nodeRef, RegexQNamePattern.MATCH_ALL);
        for (AssociationRef assocRef : assocs) {
            String assocName = assocRef.getTypeQName().toString();
            List<AssociationRef> list = (List<AssociationRef>) this.associations.get(assocName);
            // create the list if this is first association with 'assocName'
            if (list == null) {
                list = new ArrayList<AssociationRef>();
                this.associations.put(assocName, list);
            }
            // add the association to the list
            list.add(assocRef);
        }
        this.assocsRetrieved = true;
    }
    return this.associations;
}
Also used : ArrayList(java.util.ArrayList) List(java.util.List) AssociationRef(org.alfresco.service.cmr.repository.AssociationRef) ChildAssociationRef(org.alfresco.service.cmr.repository.ChildAssociationRef)

Aggregations

AssociationRef (org.alfresco.service.cmr.repository.AssociationRef)35 NodeRef (org.alfresco.service.cmr.repository.NodeRef)26 ChildAssociationRef (org.alfresco.service.cmr.repository.ChildAssociationRef)22 QName (org.alfresco.service.namespace.QName)13 ArrayList (java.util.ArrayList)9 Serializable (java.io.Serializable)8 HashMap (java.util.HashMap)7 List (java.util.List)6 Map (java.util.Map)6 Iterator (java.util.Iterator)4 PropertyDefinition (org.alfresco.service.cmr.dictionary.PropertyDefinition)4 WebApiDescription (org.alfresco.rest.framework.WebApiDescription)3 QNamePattern (org.alfresco.service.namespace.QNamePattern)3 IOException (java.io.IOException)2 Date (java.util.Date)2 ListDataModel (javax.faces.model.ListDataModel)2 MimeMessage (javax.mail.internet.MimeMessage)2 AlfrescoRuntimeException (org.alfresco.error.AlfrescoRuntimeException)2 DictionaryService (org.alfresco.service.cmr.dictionary.DictionaryService)2 ContentData (org.alfresco.service.cmr.repository.ContentData)2