Search in sources :

Example 11 with AssociationRef

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

the class UIAssociationEditor method renderReadOnlyAssociations.

/**
 * @see org.alfresco.web.ui.repo.component.property.BaseAssociationEditor#renderReadOnlyAssociations(javax.faces.context.FacesContext, javax.faces.context.ResponseWriter, org.alfresco.service.cmr.repository.NodeService)
 */
protected void renderReadOnlyAssociations(FacesContext context, ResponseWriter out, NodeService nodeService) throws IOException {
    if (this.originalAssocs.size() > 0) {
        out.write("<table cellspacing='0' cellpadding='2' border='0'>");
        Iterator iter = this.originalAssocs.values().iterator();
        while (iter.hasNext()) {
            out.write("<tr><td>");
            AssociationRef assoc = (AssociationRef) iter.next();
            NodeRef targetNode = assoc.getTargetRef();
            if (nodeService.exists(targetNode)) {
                if (ContentModel.TYPE_PERSON.equals(nodeService.getType(targetNode))) {
                    // if the node represents a person, show the username instead of the name
                    out.write(Utils.encode(User.getFullNameAndUserId(nodeService, targetNode)));
                } else if (ContentModel.TYPE_AUTHORITY_CONTAINER.equals(nodeService.getType(targetNode))) {
                    // if the node represents a group, show the group display name instead of the name
                    String groupDisplayName = (String) nodeService.getProperty(targetNode, ContentModel.PROP_AUTHORITY_DISPLAY_NAME);
                    if (groupDisplayName == null || groupDisplayName.length() == 0) {
                        String group = (String) nodeService.getProperty(targetNode, ContentModel.PROP_AUTHORITY_NAME);
                        groupDisplayName = group.substring(PermissionService.GROUP_PREFIX.length());
                    }
                    out.write(Utils.encode(groupDisplayName));
                } else {
                    // use the standard cm:name property
                    // Fix AWC-1301
                    String displayString = null;
                    try {
                        displayString = Repository.getDisplayPath(nodeService.getPath(targetNode)) + "/" + Repository.getNameForNode(nodeService, targetNode);
                    } catch (AccessDeniedException ade) {
                        displayString = Application.getMessage(context, MSG_WARN_CANNOT_VIEW_TARGET_DETAILS);
                    }
                    out.write(Utils.encode(displayString));
                }
            } else {
                String message = Application.getMessage(context, MSG_WARN_USER_WAS_DELETED);
                out.write(message);
            }
            out.write("</td></tr>");
        }
        out.write("</table>");
    }
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) AccessDeniedException(org.alfresco.repo.security.permissions.AccessDeniedException) Iterator(java.util.Iterator) AssociationRef(org.alfresco.service.cmr.repository.AssociationRef)

Example 12 with AssociationRef

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

the class UIAssociationEditor method addTarget.

/**
 * Updates the component and node state to reflect an association being added
 *
 * @param node The node we are dealing with
 * @param toAdd The noderefs of the children to add
 */
protected void addTarget(Node node, String[] toAdd) {
    if (node != null && toAdd != null && toAdd.length > 0) {
        for (int x = 0; x < toAdd.length; x++) {
            String targetRef = toAdd[x];
            // update the node so it knows to add the association (if it wasn't there originally)
            if (this.originalAssocs.containsKey(targetRef) == false) {
                QName assocQName = Repository.resolveToQName(this.associationName);
                AssociationRef newAssoc = new AssociationRef(null, node.getNodeRef(), assocQName, new NodeRef(targetRef));
                Map<String, AssociationRef> added = node.getAddedAssociations().get(this.associationName);
                added.put(targetRef, newAssoc);
                if (logger.isDebugEnabled())
                    logger.debug("Added association to " + targetRef + " to the added list");
            }
            // if the association was previously removed and has now been re-added it
            // will still be in the "to be removed" list so remove it if it is
            Map<String, AssociationRef> removed = node.getRemovedAssociations().get(this.associationName);
            if (removed.containsKey(targetRef)) {
                removed.remove(targetRef);
                if (logger.isDebugEnabled())
                    logger.debug("Removed association to " + targetRef + " from the removed list");
            }
        }
    }
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) QName(org.alfresco.service.namespace.QName) AssociationRef(org.alfresco.service.cmr.repository.AssociationRef)

Example 13 with AssociationRef

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

the class UIAssociationEditor method populateAssocationMaps.

/**
 * @see org.alfresco.web.ui.repo.component.property.BaseAssociationEditor#populateAssocationMaps(org.alfresco.web.bean.repository.Node, org.alfresco.service.cmr.repository.NodeService)
 */
@SuppressWarnings("unchecked")
protected void populateAssocationMaps(Node node, NodeService nodeService) {
    // and place them in a map keyed by the noderef of the child node
    if (this.originalAssocs == null) {
        this.originalAssocs = new LinkedHashMap<String, Object>();
        List assocs = (List) node.getAssociations().get(this.associationName);
        if (assocs != null) {
            Iterator iter = assocs.iterator();
            while (iter.hasNext()) {
                AssociationRef assoc = (AssociationRef) iter.next();
                if (nodeService.exists(assoc.getTargetRef())) {
                    // add the association to the map
                    this.originalAssocs.put(assoc.getTargetRef().toString(), assoc);
                }
            }
        }
    }
    // get the map of added associations for this node and association type
    this.added = (Map) node.getAddedAssociations().get(this.associationName);
    if (added == null) {
        // if there aren't any added associations for 'associationName' create a map and add it
        added = new LinkedHashMap<String, Object>();
        node.getAddedAssociations().put(this.associationName, (Map) added);
    }
    // get the map of removed associations for this node and association type
    this.removed = (Map) node.getRemovedAssociations().get(this.associationName);
    if (removed == null) {
        // if there aren't any added associations for 'associationName' create a map and add it
        removed = new LinkedHashMap<String, Object>();
        node.getRemovedAssociations().put(this.associationName, (Map) removed);
    }
}
Also used : Iterator(java.util.Iterator) List(java.util.List) AssociationRef(org.alfresco.service.cmr.repository.AssociationRef)

Example 14 with AssociationRef

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

the class UIAssociationEditor method renderExistingAssociations.

/**
 * @see org.alfresco.web.ui.repo.component.property.BaseAssociationEditor#renderExistingAssociations(javax.faces.context.FacesContext, javax.faces.context.ResponseWriter, org.alfresco.service.cmr.repository.NodeService, boolean)
 */
protected void renderExistingAssociations(FacesContext context, ResponseWriter out, NodeService nodeService, boolean allowManyChildren) throws IOException {
    boolean itemsRendered = false;
    // show the associations from the original list if they are not in the removed list
    Iterator iter = this.originalAssocs.values().iterator();
    while (iter.hasNext()) {
        AssociationRef assoc = (AssociationRef) iter.next();
        if (removed.containsKey(assoc.getTargetRef().toString()) == false) {
            renderExistingAssociation(context, out, nodeService, assoc.getTargetRef(), allowManyChildren);
            itemsRendered = true;
        }
    }
    // also show any associations added in this session
    iter = this.added.values().iterator();
    while (iter.hasNext()) {
        AssociationRef assoc = (AssociationRef) iter.next();
        renderExistingAssociation(context, out, nodeService, assoc.getTargetRef(), allowManyChildren);
        itemsRendered = true;
    }
    // show the none selected message if no items were rendered
    if (itemsRendered == false && allowManyChildren == true) {
        renderNone(context, out);
    }
}
Also used : Iterator(java.util.Iterator) AssociationRef(org.alfresco.service.cmr.repository.AssociationRef)

Example 15 with AssociationRef

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

the class TransientNode method initNode.

/**
 * Initialises the node.
 *
 * @param data The properties and associations to initialise the node with
 */
protected void initNode(Map<QName, Serializable> data) {
    if (logger.isDebugEnabled())
        logger.debug("Initialising transient node with data: " + data);
    DictionaryService ddService = this.getServiceRegistry().getDictionaryService();
    // marshall the given properties and associations into the internal maps
    this.associations = new QNameNodeMap(this, this);
    this.childAssociations = new QNameNodeMap(this, this);
    if (data != null) {
        // go through all data items and allocate to the correct internal list
        for (QName item : data.keySet()) {
            PropertyDefinition propDef = ddService.getProperty(item);
            if (propDef != null) {
                this.properties.put(item, data.get(item));
            } else {
                // see if the item is either type of association
                AssociationDefinition assocDef = ddService.getAssociation(item);
                if (assocDef != null) {
                    if (assocDef.isChild()) {
                        Object obj = data.get(item);
                        if (obj instanceof NodeRef) {
                            NodeRef child = (NodeRef) obj;
                            // create a child association reference, add it to a list and add the list
                            // to the list of child associations for this node
                            List<ChildAssociationRef> assocs = new ArrayList<ChildAssociationRef>(1);
                            ChildAssociationRef childRef = new ChildAssociationRef(assocDef.getName(), this.nodeRef, null, child);
                            assocs.add(childRef);
                            this.childAssociations.put(item, assocs);
                        } else if (obj instanceof List) {
                            List targets = (List) obj;
                            List<ChildAssociationRef> assocs = new ArrayList<ChildAssociationRef>(targets.size());
                            for (Object target : targets) {
                                if (target instanceof NodeRef) {
                                    NodeRef currentChild = (NodeRef) target;
                                    ChildAssociationRef childRef = new ChildAssociationRef(assocDef.getName(), this.nodeRef, null, currentChild);
                                    assocs.add(childRef);
                                }
                            }
                            if (assocs.size() > 0) {
                                this.childAssociations.put(item, assocs);
                            }
                        }
                    } else {
                        Object obj = data.get(item);
                        if (obj instanceof NodeRef) {
                            NodeRef target = (NodeRef) obj;
                            // create a association reference, add it to a list and add the list
                            // to the list of associations for this node
                            List<AssociationRef> assocs = new ArrayList<AssociationRef>(1);
                            AssociationRef assocRef = new AssociationRef(null, this.nodeRef, assocDef.getName(), target);
                            assocs.add(assocRef);
                            this.associations.put(item, assocs);
                        } else if (obj instanceof List) {
                            List targets = (List) obj;
                            List<AssociationRef> assocs = new ArrayList<AssociationRef>(targets.size());
                            for (Object target : targets) {
                                if (target instanceof NodeRef) {
                                    NodeRef currentTarget = (NodeRef) target;
                                    AssociationRef assocRef = new AssociationRef(null, this.nodeRef, assocDef.getName(), currentTarget);
                                    assocs.add(assocRef);
                                }
                            }
                            if (assocs.size() > 0) {
                                this.associations.put(item, assocs);
                            }
                        }
                    }
                }
            }
        }
    }
    // show that the maps have been initialised
    this.propsRetrieved = true;
    this.assocsRetrieved = true;
    this.childAssocsRetrieved = true;
    // setup the list of aspects the node would have
    TypeDefinition typeDef = ddService.getType(this.type);
    if (typeDef == null) {
        throw new AlfrescoRuntimeException("Failed to find type definition: " + this.type);
    }
    // get flat list of all aspects for the type
    List<QName> defaultAspects = new ArrayList<QName>(16);
    getMandatoryAspects(typeDef, defaultAspects);
    this.aspects = new HashSet<QName>(defaultAspects);
    // setup remaining variables
    this.path = null;
    this.locked = Boolean.FALSE;
    this.workingCopyOwner = Boolean.FALSE;
}
Also used : QName(org.alfresco.service.namespace.QName) ArrayList(java.util.ArrayList) 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) TypeDefinition(org.alfresco.service.cmr.dictionary.TypeDefinition) NodeRef(org.alfresco.service.cmr.repository.NodeRef) DictionaryService(org.alfresco.service.cmr.dictionary.DictionaryService) AssociationDefinition(org.alfresco.service.cmr.dictionary.AssociationDefinition) AlfrescoRuntimeException(org.alfresco.error.AlfrescoRuntimeException) ArrayList(java.util.ArrayList) List(java.util.List)

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