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;
}
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;
}
});
}
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");
}
}
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;
}
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();
}
Aggregations