Search in sources :

Example 36 with ChildAssociationRef

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

the class AdvancedSearchDialog method getSavedSearches.

/**
 * @return list of saved searches as SelectItem objects
 */
public List<SelectItem> getSavedSearches() {
    List<SelectItem> savedSearches = properties.getCachedSavedSearches().get();
    if (savedSearches == null) {
        FacesContext fc = FacesContext.getCurrentInstance();
        ServiceRegistry services = Repository.getServiceRegistry(fc);
        // get the searches list from the current user or global searches location
        NodeRef searchesRef = null;
        if (SAVED_SEARCHES_USER.equals(properties.getSavedSearchMode()) == true) {
            searchesRef = getUserSearchesRef();
        } else if (SAVED_SEARCHES_GLOBAL.equals(properties.getSavedSearchMode()) == true) {
            searchesRef = getGlobalSearchesRef();
        }
        // read the content nodes under the folder
        if (searchesRef != null) {
            DictionaryService dd = services.getDictionaryService();
            List<ChildAssociationRef> childRefs = getNodeService().getChildAssocs(searchesRef, ContentModel.ASSOC_CONTAINS, RegexQNamePattern.MATCH_ALL);
            savedSearches = new ArrayList<SelectItem>(childRefs.size() + 1);
            if (childRefs.size() != 0) {
                for (ChildAssociationRef ref : childRefs) {
                    Node childNode = new Node(ref.getChildRef());
                    if (dd.isSubClass(childNode.getType(), ContentModel.TYPE_CONTENT)) {
                        savedSearches.add(new SelectItem(childNode.getId(), childNode.getName()));
                    }
                }
                // make sure the list is sorted by the label
                QuickSort sorter = new QuickSort(savedSearches, "label", true, IDataContainer.SORT_CASEINSENSITIVE);
                sorter.sort();
            }
        } else {
            // handle missing/access denied folder case
            savedSearches = new ArrayList<SelectItem>(1);
        }
        // add an entry (at the start) to instruct the user to select a saved search
        savedSearches.add(0, new SelectItem(NO_SELECTION, Application.getMessage(FacesContext.getCurrentInstance(), MSG_SELECT_SAVED_SEARCH)));
        // store in the cache (will auto-expire)
        properties.getCachedSavedSearches().put(savedSearches);
    }
    return savedSearches;
}
Also used : FacesContext(javax.faces.context.FacesContext) NodeRef(org.alfresco.service.cmr.repository.NodeRef) DictionaryService(org.alfresco.service.cmr.dictionary.DictionaryService) QuickSort(org.alfresco.web.data.QuickSort) SelectItem(javax.faces.model.SelectItem) Node(org.alfresco.web.bean.repository.Node) MapNode(org.alfresco.web.bean.repository.MapNode) ServiceRegistry(org.alfresco.service.ServiceRegistry) ChildAssociationRef(org.alfresco.service.cmr.repository.ChildAssociationRef)

Example 37 with ChildAssociationRef

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

the class SearchContext method getPathFromSpaceRef.

/**
 * Generate a search XPATH pointing to the specified node, optionally return an XPATH
 * that includes the child nodes.
 *
 * @param ref         Of the node to generate path too
 * @param children   Whether to include children of the node
 *
 * @return the path
 */
public static String getPathFromSpaceRef(NodeRef ref, boolean children) {
    FacesContext context = FacesContext.getCurrentInstance();
    Path path = Repository.getServiceRegistry(context).getNodeService().getPath(ref);
    NamespaceService ns = Repository.getServiceRegistry(context).getNamespaceService();
    StringBuilder buf = new StringBuilder(64);
    for (int i = 0; i < path.size(); i++) {
        String elementString = "";
        Path.Element element = path.get(i);
        if (element instanceof Path.ChildAssocElement) {
            ChildAssociationRef elementRef = ((Path.ChildAssocElement) element).getRef();
            if (elementRef.getParentRef() != null) {
                Collection<String> prefixes = ns.getPrefixes(elementRef.getQName().getNamespaceURI());
                if (prefixes.size() > 0) {
                    elementString = '/' + (String) prefixes.iterator().next() + ':' + ISO9075.encode(elementRef.getQName().getLocalName());
                }
            }
        }
        buf.append(elementString);
    }
    if (children == true) {
        // append syntax to get all children of the path
        buf.append("//*");
    } else {
        // append syntax to just represent the path, not the children
        buf.append("/*");
    }
    return buf.toString();
}
Also used : Path(org.alfresco.service.cmr.repository.Path) FacesContext(javax.faces.context.FacesContext) NamespaceService(org.alfresco.service.namespace.NamespaceService) ChildAssociationRef(org.alfresco.service.cmr.repository.ChildAssociationRef)

Example 38 with ChildAssociationRef

use of org.alfresco.service.cmr.repository.ChildAssociationRef 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)

Example 39 with ChildAssociationRef

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

the class CreateUserWizard method createHomeSpace.

/**
 * Create the specified home space if it does not exist, and return the ID
 *
 * @param locationId Parent location
 * @param spaceName Home space to create, can be null to simply return the parent
 * @param oldHomeFolderRef the previous home space, for the case where the the user is being updated.
 *        It may not have changed.
 * @param error True to throw an error if the space already exists, else ignore and return
 * @return ID of the home space
 */
protected NodeRef createHomeSpace(String locationId, String spaceName, NodeRef oldHomeFolderRef, boolean error) {
    NodeRef homeSpaceNodeRef = null;
    if (spaceName != null && spaceName.length() != 0) {
        NodeRef parentRef = new NodeRef(Repository.getStoreRef(), locationId);
        // check for existence of home space with same name - return immediately
        // if it exists or throw an exception an give user chance to enter another name
        NodeRef childRef = this.getNodeService().getChildByName(parentRef, ContentModel.ASSOC_CONTAINS, spaceName);
        if (childRef != null) {
            if (childRef.equals(oldHomeFolderRef)) {
                return oldHomeFolderRef;
            }
            if (error) {
                throw new AlfrescoRuntimeException("A Home Space with the same name already exists.");
            } else {
                return childRef;
            }
        }
        // space does not exist already, create a new Space under it with
        // the specified name
        String qname = QName.createValidLocalName(spaceName);
        ChildAssociationRef assocRef = this.getNodeService().createNode(parentRef, ContentModel.ASSOC_CONTAINS, QName.createQName(NamespaceService.SYSTEM_MODEL_1_0_URI, qname), ContentModel.TYPE_FOLDER);
        NodeRef nodeRef = assocRef.getChildRef();
        // set the name property on the node
        this.getNodeService().setProperty(nodeRef, ContentModel.PROP_NAME, spaceName);
        if (logger.isDebugEnabled())
            logger.debug("Created Home Space for with name: " + spaceName);
        // apply the uifacets aspect - icon, title and description props
        Map<QName, Serializable> uiFacetsProps = new HashMap<QName, Serializable>(3);
        uiFacetsProps.put(ApplicationModel.PROP_ICON, CreateSpaceWizard.DEFAULT_SPACE_ICON_NAME);
        uiFacetsProps.put(ContentModel.PROP_TITLE, spaceName);
        this.getNodeService().addAspect(nodeRef, ApplicationModel.ASPECT_UIFACETS, uiFacetsProps);
        setupHomeSpacePermissions(nodeRef);
        // return the ID of the created space
        homeSpaceNodeRef = nodeRef;
    }
    return homeSpaceNodeRef;
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) Serializable(java.io.Serializable) HashMap(java.util.HashMap) QName(org.alfresco.service.namespace.QName) AlfrescoRuntimeException(org.alfresco.error.AlfrescoRuntimeException) ChildAssociationRef(org.alfresco.service.cmr.repository.ChildAssociationRef)

Example 40 with ChildAssociationRef

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

the class NewUserWizard method createHomeSpace.

/**
 * Create the specified home space if it does not exist, and return the ID
 *
 * @param locationId
 *            Parent location
 * @param spaceName
 *            Home space to create, can be null to simply return the parent
 * @param error
 *            True to throw an error if the space already exists, else
 *            ignore and return
 *
 * @return ID of the home space
 */
private NodeRef createHomeSpace(String locationId, String spaceName, boolean error) {
    NodeRef homeSpaceNodeRef = null;
    if (spaceName != null && spaceName.length() != 0) {
        NodeRef parentRef = new NodeRef(Repository.getStoreRef(), locationId);
        // check for existance of home space with same name - return immediately
        // if it exists or throw an exception an give user chance to enter another name
        // TODO: this might be better replaced with an XPath query!
        List<ChildAssociationRef> children = this.getNodeService().getChildAssocs(parentRef);
        for (ChildAssociationRef ref : children) {
            String childNodeName = (String) this.getNodeService().getProperty(ref.getChildRef(), ContentModel.PROP_NAME);
            if (spaceName.equals(childNodeName)) {
                if (error) {
                    throw new AlfrescoRuntimeException("A Home Space with the same name already exists.");
                } else {
                    return ref.getChildRef();
                }
            }
        }
        // space does not exist already, create a new Space under it with
        // the specified name
        String qname = QName.createValidLocalName(spaceName);
        ChildAssociationRef assocRef = this.getNodeService().createNode(parentRef, ContentModel.ASSOC_CONTAINS, QName.createQName(NamespaceService.SYSTEM_MODEL_1_0_URI, qname), ContentModel.TYPE_FOLDER);
        NodeRef nodeRef = assocRef.getChildRef();
        // set the name property on the node
        this.getNodeService().setProperty(nodeRef, ContentModel.PROP_NAME, spaceName);
        if (logger.isDebugEnabled())
            logger.debug("Created Home Space for with name: " + spaceName);
        // apply the uifacets aspect - icon, title and description props
        Map<QName, Serializable> uiFacetsProps = new HashMap<QName, Serializable>(3);
        uiFacetsProps.put(ApplicationModel.PROP_ICON, CreateSpaceWizard.DEFAULT_SPACE_ICON_NAME);
        uiFacetsProps.put(ContentModel.PROP_TITLE, spaceName);
        this.getNodeService().addAspect(nodeRef, ApplicationModel.ASPECT_UIFACETS, uiFacetsProps);
        setupHomeSpacePermissions(nodeRef);
        // return the ID of the created space
        homeSpaceNodeRef = nodeRef;
    }
    return homeSpaceNodeRef;
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) Serializable(java.io.Serializable) HashMap(java.util.HashMap) QName(org.alfresco.service.namespace.QName) AlfrescoRuntimeException(org.alfresco.error.AlfrescoRuntimeException) ChildAssociationRef(org.alfresco.service.cmr.repository.ChildAssociationRef)

Aggregations

ChildAssociationRef (org.alfresco.service.cmr.repository.ChildAssociationRef)258 NodeRef (org.alfresco.service.cmr.repository.NodeRef)202 QName (org.alfresco.service.namespace.QName)109 Test (org.junit.Test)56 HashMap (java.util.HashMap)54 BaseUnitTest (org.alfresco.module.org_alfresco_module_rm.test.util.BaseUnitTest)53 ArrayList (java.util.ArrayList)52 Serializable (java.io.Serializable)42 AlfrescoRuntimeException (org.alfresco.error.AlfrescoRuntimeException)25 FacesContext (javax.faces.context.FacesContext)22 Map (java.util.Map)19 UserTransaction (javax.transaction.UserTransaction)18 Node (org.alfresco.web.bean.repository.Node)17 Date (java.util.Date)15 StoreRef (org.alfresco.service.cmr.repository.StoreRef)13 NodeService (org.alfresco.service.cmr.repository.NodeService)12 SiteInfo (org.alfresco.service.cmr.site.SiteInfo)12 List (java.util.List)11 StringPropertyValue (org.alfresco.solr.client.StringPropertyValue)11 IOException (java.io.IOException)10