Search in sources :

Example 6 with DictionaryService

use of org.alfresco.service.cmr.dictionary.DictionaryService 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 7 with DictionaryService

use of org.alfresco.service.cmr.dictionary.DictionaryService in project acs-community-packaging by Alfresco.

the class AdvancedSearchDialog method getCustomPropertyLookup.

/**
 * Helper map to lookup custom property QName strings against a DataTypeDefinition
 *
 * @return custom property lookup Map
 */
private Map<String, DataTypeDefinition> getCustomPropertyLookup() {
    if ((properties.getCustomPropertyLookup() == null) || (Application.isDynamicConfig(FacesContext.getCurrentInstance()))) {
        properties.setCustomPropertyLookup(new HashMap<String, DataTypeDefinition>(7, 1.0f));
        List<CustomProperty> customProps = getSearchConfig().getCustomProperties();
        if (customProps != null) {
            DictionaryService dd = Repository.getServiceRegistry(FacesContext.getCurrentInstance()).getDictionaryService();
            for (CustomProperty customProp : customProps) {
                PropertyDefinition propDef = null;
                QName propQName = Repository.resolveToQName(customProp.Property);
                if (customProp.Type != null) {
                    QName type = Repository.resolveToQName(customProp.Type);
                    TypeDefinition typeDef = dd.getType(type);
                    propDef = typeDef.getProperties().get(propQName);
                } else if (customProp.Aspect != null) {
                    QName aspect = Repository.resolveToQName(customProp.Aspect);
                    AspectDefinition aspectDef = dd.getAspect(aspect);
                    propDef = aspectDef.getProperties().get(propQName);
                }
                if (propQName != null && propDef != null) {
                    properties.getCustomPropertyLookup().put(propQName.toString(), propDef.getDataType());
                }
            }
        }
    }
    return properties.getCustomPropertyLookup();
}
Also used : DictionaryService(org.alfresco.service.cmr.dictionary.DictionaryService) QName(org.alfresco.service.namespace.QName) CustomProperty(org.alfresco.web.config.AdvancedSearchConfigElement.CustomProperty) AspectDefinition(org.alfresco.service.cmr.dictionary.AspectDefinition) DataTypeDefinition(org.alfresco.service.cmr.dictionary.DataTypeDefinition) PropertyDefinition(org.alfresco.service.cmr.dictionary.PropertyDefinition) TypeDefinition(org.alfresco.service.cmr.dictionary.TypeDefinition) DataTypeDefinition(org.alfresco.service.cmr.dictionary.DataTypeDefinition)

Example 8 with DictionaryService

use of org.alfresco.service.cmr.dictionary.DictionaryService in project acs-community-packaging by Alfresco.

the class AdvancedSearchDialog method getContentTypes.

/**
 * @return Returns a list of content object types to allow the user to select from
 */
public List<SelectItem> getContentTypes() {
    if ((properties.getContentTypes() == null) || (Application.isDynamicConfig(FacesContext.getCurrentInstance()))) {
        FacesContext context = FacesContext.getCurrentInstance();
        DictionaryService dictionaryService = Repository.getServiceRegistry(context).getDictionaryService();
        // add the well known cm:content object type by default
        properties.setContentTypes(new ArrayList<SelectItem>(5));
        properties.getContentTypes().add(new SelectItem(ContentModel.TYPE_CONTENT.toString(), dictionaryService.getType(ContentModel.TYPE_CONTENT).getTitle(dictionaryService)));
        // add any configured content sub-types to the list
        List<String> types = getSearchConfig().getContentTypes();
        if (types != null) {
            for (String type : types) {
                QName idQName = Repository.resolveToQName(type);
                if (idQName != null) {
                    TypeDefinition typeDef = dictionaryService.getType(idQName);
                    if (typeDef != null && dictionaryService.isSubClass(typeDef.getName(), ContentModel.TYPE_CONTENT)) {
                        // try and get label from the dictionary
                        String label = typeDef.getTitle(dictionaryService);
                        // else just use the localname
                        if (label == null) {
                            label = idQName.getLocalName();
                        }
                        properties.getContentTypes().add(new SelectItem(idQName.toString(), label));
                    }
                }
            }
        }
    }
    return properties.getContentTypes();
}
Also used : FacesContext(javax.faces.context.FacesContext) DictionaryService(org.alfresco.service.cmr.dictionary.DictionaryService) SelectItem(javax.faces.model.SelectItem) QName(org.alfresco.service.namespace.QName) TypeDefinition(org.alfresco.service.cmr.dictionary.TypeDefinition) DataTypeDefinition(org.alfresco.service.cmr.dictionary.DataTypeDefinition)

Example 9 with DictionaryService

use of org.alfresco.service.cmr.dictionary.DictionaryService in project acs-community-packaging by Alfresco.

the class Repository method setupBreadcrumbLocation.

/**
 * Sets up the breadcrumb location representation for the given node in
 * the given list.
 *
 * @param context FacesContext
 * @param navBean NavigationBean instance
 * @param location The location list to setup
 * @param node The Node being navigated to
 */
public static void setupBreadcrumbLocation(FacesContext context, NavigationBean navBean, List<IBreadcrumbHandler> location, NodeRef node) {
    // make the sure the given list is empty
    location.clear();
    // get required services
    NodeService nodeService = Repository.getServiceRegistry(context).getNodeService();
    DictionaryService dictionaryService = Repository.getServiceRegistry(context).getDictionaryService();
    PermissionService permsService = Repository.getServiceRegistry(context).getPermissionService();
    // add the given node to start
    String nodeName = Repository.getNameForNode(nodeService, node);
    location.add(navBean.new NavigationBreadcrumbHandler(node, nodeName));
    // get the given node's parent node
    NodeRef parent = nodeService.getPrimaryParent(node).getParentRef();
    while (parent != null) {
        // check the user can read the parent node
        if (permsService.hasPermission(parent, PermissionService.READ) == AccessStatus.ALLOWED) {
            // get the grand parent so we can check for the root node
            NodeRef grandParent = nodeService.getPrimaryParent(parent).getParentRef();
            if (grandParent != null) {
                // check that the node is actually a folder type, content can have children!
                QName parentType = nodeService.getType(parent);
                if (dictionaryService.isSubClass(parentType, ContentModel.TYPE_FOLDER)) {
                    // if it's a folder add the location to the breadcrumb
                    String parentName = Repository.getNameForNode(nodeService, parent);
                    location.add(0, navBean.new NavigationBreadcrumbHandler(parent, parentName));
                }
            }
            parent = grandParent;
        } else {
            // the user does not have Read permission above this point so stop!
            break;
        }
    }
}
Also used : PermissionService(org.alfresco.service.cmr.security.PermissionService) NodeRef(org.alfresco.service.cmr.repository.NodeRef) DictionaryService(org.alfresco.service.cmr.dictionary.DictionaryService) QName(org.alfresco.service.namespace.QName) NodeService(org.alfresco.service.cmr.repository.NodeService)

Example 10 with DictionaryService

use of org.alfresco.service.cmr.dictionary.DictionaryService 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

DictionaryService (org.alfresco.service.cmr.dictionary.DictionaryService)29 FacesContext (javax.faces.context.FacesContext)12 NodeRef (org.alfresco.service.cmr.repository.NodeRef)11 QName (org.alfresco.service.namespace.QName)11 NodeService (org.alfresco.service.cmr.repository.NodeService)8 Node (org.alfresco.web.bean.repository.Node)8 ChildAssociationRef (org.alfresco.service.cmr.repository.ChildAssociationRef)7 TypeDefinition (org.alfresco.service.cmr.dictionary.TypeDefinition)6 SelectItem (javax.faces.model.SelectItem)5 PropertyDefinition (org.alfresco.service.cmr.dictionary.PropertyDefinition)5 Serializable (java.io.Serializable)4 ArrayList (java.util.ArrayList)4 DataTypeDefinition (org.alfresco.service.cmr.dictionary.DataTypeDefinition)4 QuickSort (org.alfresco.web.data.QuickSort)4 HashMap (java.util.HashMap)3 List (java.util.List)3 Map (java.util.Map)3 ResponseWriter (javax.faces.context.ResponseWriter)3 UserTransaction (javax.transaction.UserTransaction)3 AccessDeniedException (org.alfresco.repo.security.permissions.AccessDeniedException)3