Search in sources :

Example 6 with TypeDefinition

use of org.alfresco.service.cmr.dictionary.TypeDefinition in project alfresco-remote-api by Alfresco.

the class ProcessesImpl method getVariables.

@Override
public CollectionWithPagingInfo<Variable> getVariables(String processId, Paging paging) {
    CollectionWithPagingInfo<Variable> result = null;
    // Check if user is allowed to get variables
    List<HistoricVariableInstance> variableInstances = validateIfUserAllowedToWorkWithProcess(processId);
    Map<String, Object> variables = new HashMap<String, Object>();
    for (HistoricVariableInstance variable : variableInstances) {
        variables.put(variable.getVariableName(), variable.getValue());
    }
    ProcessInstance processInstance = activitiProcessEngine.getRuntimeService().createProcessInstanceQuery().processInstanceId(processId).singleResult();
    String processDefinitionId = null;
    if (processInstance != null) {
        processDefinitionId = processInstance.getProcessDefinitionId();
    } else {
        // Completed process instance
        HistoricProcessInstance historicInstance = activitiProcessEngine.getHistoryService().createHistoricProcessInstanceQuery().processInstanceId(processId).singleResult();
        if (historicInstance == null) {
            throw new EntityNotFoundException(processId);
        }
        processDefinitionId = historicInstance.getProcessDefinitionId();
    }
    // Get start-task definition for explicit typing of variables submitted at the start
    String formKey = null;
    StartFormData startFormData = activitiProcessEngine.getFormService().getStartFormData(processDefinitionId);
    if (startFormData != null) {
        formKey = startFormData.getFormKey();
    }
    TypeDefinition startTaskTypeDefinition = getWorkflowFactory().getTaskFullTypeDefinition(formKey, true);
    // Convert raw variables to Variable objects
    List<Variable> resultingVariables = restVariableHelper.getVariables(variables, startTaskTypeDefinition);
    result = CollectionWithPagingInfo.asPaged(paging, resultingVariables);
    return result;
}
Also used : Variable(org.alfresco.rest.workflow.api.model.Variable) HashMap(java.util.HashMap) HistoricProcessInstance(org.activiti.engine.history.HistoricProcessInstance) EntityNotFoundException(org.alfresco.rest.framework.core.exceptions.EntityNotFoundException) TypeDefinition(org.alfresco.service.cmr.dictionary.TypeDefinition) DataTypeDefinition(org.alfresco.service.cmr.dictionary.DataTypeDefinition) StartFormData(org.activiti.engine.form.StartFormData) HistoricVariableInstance(org.activiti.engine.history.HistoricVariableInstance) ProcessInstance(org.activiti.engine.runtime.ProcessInstance) HistoricProcessInstance(org.activiti.engine.history.HistoricProcessInstance)

Example 7 with TypeDefinition

use of org.alfresco.service.cmr.dictionary.TypeDefinition in project alfresco-remote-api by Alfresco.

the class WorkflowModelBuilder method buildPropertyLabels.

private Map<String, String> buildPropertyLabels(WorkflowTask task, Map<String, Object> properties) {
    TypeDefinition taskType = task.getDefinition().getMetadata();
    final Map<QName, PropertyDefinition> propDefs = taskType.getProperties();
    return CollectionUtils.transform(properties, new Function<Entry<String, Object>, Pair<String, String>>() {

        @Override
        public Pair<String, String> apply(Entry<String, Object> entry) {
            String propName = entry.getKey();
            PropertyDefinition propDef = propDefs.get(qNameConverter.mapNameToQName(propName));
            if (propDef != null) {
                List<ConstraintDefinition> constraints = propDef.getConstraints();
                for (ConstraintDefinition constraintDef : constraints) {
                    Constraint constraint = constraintDef.getConstraint();
                    if (constraint instanceof ListOfValuesConstraint) {
                        ListOfValuesConstraint listConstraint = (ListOfValuesConstraint) constraint;
                        String label = listConstraint.getDisplayLabel(String.valueOf(entry.getValue()), dictionaryService);
                        return new Pair<String, String>(propName, label);
                    }
                }
            }
            return null;
        }
    });
}
Also used : Constraint(org.alfresco.service.cmr.dictionary.Constraint) ListOfValuesConstraint(org.alfresco.repo.dictionary.constraint.ListOfValuesConstraint) QName(org.alfresco.service.namespace.QName) PropertyDefinition(org.alfresco.service.cmr.dictionary.PropertyDefinition) TypeDefinition(org.alfresco.service.cmr.dictionary.TypeDefinition) ConstraintDefinition(org.alfresco.service.cmr.dictionary.ConstraintDefinition) Entry(java.util.Map.Entry) ListOfValuesConstraint(org.alfresco.repo.dictionary.constraint.ListOfValuesConstraint) ArrayList(java.util.ArrayList) List(java.util.List) Pair(org.alfresco.util.Pair)

Example 8 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 9 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 10 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)

Aggregations

TypeDefinition (org.alfresco.service.cmr.dictionary.TypeDefinition)43 QName (org.alfresco.service.namespace.QName)30 DataTypeDefinition (org.alfresco.service.cmr.dictionary.DataTypeDefinition)18 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