Search in sources :

Example 1 with TypeDefinition

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

the class BrowseBean method queryBrowseNodes.

// ------------------------------------------------------------------------------
// Helper methods
/**
 * Query a list of nodes for the specified parent node Id
 *
 * @param parentNodeId     Id of the parent node or null for the root node
 */
private void queryBrowseNodes(String parentNodeId) {
    long startTime = 0;
    if (logger.isDebugEnabled())
        startTime = System.currentTimeMillis();
    UserTransaction tx = null;
    try {
        FacesContext context = FacesContext.getCurrentInstance();
        tx = Repository.getUserTransaction(context, true);
        tx.begin();
        NodeRef parentRef;
        if (parentNodeId == null) {
            // no specific parent node specified - use the root node
            parentRef = this.getNodeService().getRootNode(Repository.getStoreRef());
        } else {
            // build a NodeRef for the specified Id and our store
            parentRef = new NodeRef(Repository.getStoreRef(), parentNodeId);
        }
        List<FileInfo> children = null;
        FileFilterMode.setClient(Client.webclient);
        try {
            children = this.getFileFolderService().list(parentRef);
        } finally {
            FileFilterMode.clearClient();
        }
        this.containerNodes = new ArrayList<Node>(children.size());
        this.contentNodes = new ArrayList<Node>(children.size());
        // in case of dynamic config, only lookup once
        Set<NodeEventListener> nodeEventListeners = getNodeEventListeners();
        for (FileInfo fileInfo : children) {
            // create our Node representation from the NodeRef
            NodeRef nodeRef = fileInfo.getNodeRef();
            // find it's type so we can see if it's a node we are interested in
            QName type = this.getNodeService().getType(nodeRef);
            // make sure the type is defined in the data dictionary
            TypeDefinition typeDef = this.getDictionaryService().getType(type);
            if (typeDef != null) {
                MapNode node = null;
                // look for File content node
                if (this.getDictionaryService().isSubClass(type, ContentModel.TYPE_CONTENT)) {
                    // create our Node representation
                    node = new MapNode(nodeRef, this.getNodeService(), fileInfo.getProperties());
                    setupCommonBindingProperties(node);
                    this.contentNodes.add(node);
                } else // look for Space folder node
                if (this.getDictionaryService().isSubClass(type, ContentModel.TYPE_FOLDER) == true && this.getDictionaryService().isSubClass(type, ContentModel.TYPE_SYSTEM_FOLDER) == false) {
                    // create our Node representation
                    node = new MapNode(nodeRef, this.getNodeService(), fileInfo.getProperties());
                    node.addPropertyResolver("icon", this.resolverSpaceIcon);
                    node.addPropertyResolver("smallIcon", this.resolverSmallIcon);
                    this.containerNodes.add(node);
                } else // look for File Link object node
                if (ApplicationModel.TYPE_FILELINK.equals(type)) {
                    // create our File Link Node representation
                    node = new MapNode(nodeRef, this.getNodeService(), fileInfo.getProperties());
                    // only display the user has the permissions to navigate to the target of the link
                    NodeRef destRef = (NodeRef) node.getProperties().get(ContentModel.PROP_LINK_DESTINATION);
                    if (destRef != null && new Node(destRef).hasPermission(PermissionService.READ) == true) {
                        node.addPropertyResolver("url", this.resolverLinkUrl);
                        node.addPropertyResolver("downloadUrl", this.resolverLinkDownload);
                        node.addPropertyResolver("webdavUrl", this.resolverLinkWebdavUrl);
                        node.addPropertyResolver("cifsPath", this.resolverLinkCifsPath);
                        node.addPropertyResolver("fileType16", this.resolverFileType16);
                        node.addPropertyResolver("fileType32", this.resolverFileType32);
                        node.addPropertyResolver("lang", this.resolverLang);
                        this.contentNodes.add(node);
                    }
                } else if (ApplicationModel.TYPE_FOLDERLINK.equals(type)) {
                    // create our Folder Link Node representation
                    node = new MapNode(nodeRef, this.getNodeService(), fileInfo.getProperties());
                    // only display the user has the permissions to navigate to the target of the link
                    NodeRef destRef = (NodeRef) node.getProperties().get(ContentModel.PROP_LINK_DESTINATION);
                    if (destRef != null && new Node(destRef).hasPermission(PermissionService.READ) == true) {
                        node.addPropertyResolver("icon", this.resolverSpaceIcon);
                        node.addPropertyResolver("smallIcon", this.resolverSmallIcon);
                        this.containerNodes.add(node);
                    }
                }
                // inform any listeners that a Node wrapper has been created
                if (node != null) {
                    for (NodeEventListener listener : nodeEventListeners) {
                        listener.created(node, type);
                    }
                }
            } else {
                if (logger.isWarnEnabled())
                    logger.warn("Found invalid object in database: id = " + nodeRef + ", type = " + type);
            }
        }
        // commit the transaction
        tx.commit();
    } catch (InvalidNodeRefException refErr) {
        Utils.addErrorMessage(MessageFormat.format(Application.getMessage(FacesContext.getCurrentInstance(), Repository.ERROR_NODEREF), new Object[] { refErr.getNodeRef() }), refErr);
        this.containerNodes = Collections.<Node>emptyList();
        this.contentNodes = Collections.<Node>emptyList();
        try {
            if (tx != null) {
                tx.rollback();
            }
        } catch (Exception tex) {
        }
    } catch (Throwable err) {
        Utils.addErrorMessage(MessageFormat.format(Application.getMessage(FacesContext.getCurrentInstance(), Repository.ERROR_GENERIC), err.getMessage()), err);
        this.containerNodes = Collections.<Node>emptyList();
        this.contentNodes = Collections.<Node>emptyList();
        try {
            if (tx != null) {
                tx.rollback();
            }
        } catch (Exception tex) {
        }
    }
    if (logger.isDebugEnabled()) {
        long endTime = System.currentTimeMillis();
        logger.debug("Time to query and build map nodes: " + (endTime - startTime) + "ms");
    }
}
Also used : UserTransaction(javax.transaction.UserTransaction) FacesContext(javax.faces.context.FacesContext) QName(org.alfresco.service.namespace.QName) Node(org.alfresco.web.bean.repository.Node) MapNode(org.alfresco.web.bean.repository.MapNode) MapNode(org.alfresco.web.bean.repository.MapNode) SearcherException(org.alfresco.repo.search.SearcherException) InvalidNodeRefException(org.alfresco.service.cmr.repository.InvalidNodeRefException) AbortProcessingException(javax.faces.event.AbortProcessingException) IOException(java.io.IOException) TypeDefinition(org.alfresco.service.cmr.dictionary.TypeDefinition) NodeRef(org.alfresco.service.cmr.repository.NodeRef) FileInfo(org.alfresco.service.cmr.model.FileInfo) InvalidNodeRefException(org.alfresco.service.cmr.repository.InvalidNodeRefException)

Example 2 with TypeDefinition

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

the class NavigatorPluginBean method isAddableChild.

/**
 * Determines whether the given NodeRef can be added to the tree as
 * a child for example, if it's a folder.
 *
 * @param nodeRef The NodeRef to check
 * @return true if the node should be added to the tree
 */
protected boolean isAddableChild(NodeRef nodeRef) {
    boolean addable = false;
    if (this.getNodeService().exists(nodeRef)) {
        // find it's type so we can see if it's a node we are interested in
        QName type = this.getNodeService().getType(nodeRef);
        // make sure the type is defined in the data dictionary
        TypeDefinition typeDef = this.getDictionaryService().getType(type);
        if (typeDef != null) {
            // look for folder node types
            if (this.getDictionaryService().isSubClass(type, ContentModel.TYPE_FOLDER) == true && this.getDictionaryService().isSubClass(type, ContentModel.TYPE_SYSTEM_FOLDER) == false) {
                addable = true;
            }
        }
    }
    return addable;
}
Also used : QName(org.alfresco.service.namespace.QName) TypeDefinition(org.alfresco.service.cmr.dictionary.TypeDefinition)

Example 3 with TypeDefinition

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

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

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

TypeDefinition (org.alfresco.service.cmr.dictionary.TypeDefinition)44 QName (org.alfresco.service.namespace.QName)31 DataTypeDefinition (org.alfresco.service.cmr.dictionary.DataTypeDefinition)19 NodeRef (org.alfresco.service.cmr.repository.NodeRef)13 FacesContext (javax.faces.context.FacesContext)10 ArrayList (java.util.ArrayList)8 HashMap (java.util.HashMap)8 StartFormData (org.activiti.engine.form.StartFormData)8 IOException (java.io.IOException)7 PropertyDefinition (org.alfresco.service.cmr.dictionary.PropertyDefinition)7 Node (org.alfresco.web.bean.repository.Node)7 UserTransaction (javax.transaction.UserTransaction)6 InvalidArgumentException (org.alfresco.rest.framework.core.exceptions.InvalidArgumentException)6 DictionaryService (org.alfresco.service.cmr.dictionary.DictionaryService)6 ChildAssociationRef (org.alfresco.service.cmr.repository.ChildAssociationRef)6 Date (java.util.Date)5 SelectItem (javax.faces.model.SelectItem)5 MapNode (org.alfresco.web.bean.repository.MapNode)5 Serializable (java.io.Serializable)4 List (java.util.List)4