use of org.alfresco.rest.workflow.api.model.Item in project alfresco-remote-api by Alfresco.
the class WorkflowRestImpl method getItemFromProcess.
/**
* Get an item from the process package variable
*/
public Item getItemFromProcess(String itemId, String processId) {
NodeRef nodeRef = getNodeRef(itemId);
ActivitiScriptNode packageScriptNode = null;
try {
HistoricVariableInstance variableInstance = activitiProcessEngine.getHistoryService().createHistoricVariableInstanceQuery().processInstanceId(processId).variableName(BPM_PACKAGE).singleResult();
if (variableInstance != null) {
packageScriptNode = (ActivitiScriptNode) variableInstance.getValue();
} else {
throw new EntityNotFoundException(processId);
}
} catch (ActivitiObjectNotFoundException e) {
throw new EntityNotFoundException(processId);
}
Item item = null;
if (packageScriptNode != null) {
List<ChildAssociationRef> documentList = nodeService.getChildAssocs(packageScriptNode.getNodeRef());
for (ChildAssociationRef childAssociationRef : documentList) {
if (childAssociationRef.getChildRef().equals(nodeRef)) {
item = createItemForNodeRef(childAssociationRef.getChildRef());
break;
}
}
}
if (item == null) {
throw new EntityNotFoundException(itemId);
}
return item;
}
use of org.alfresco.rest.workflow.api.model.Item in project alfresco-remote-api by Alfresco.
the class WorkflowRestImpl method getItemsFromProcess.
/**
* Get all items from the process package variable
*/
public CollectionWithPagingInfo<Item> getItemsFromProcess(String processId, Paging paging) {
ActivitiScriptNode packageScriptNode = null;
try {
HistoricVariableInstance variableInstance = activitiProcessEngine.getHistoryService().createHistoricVariableInstanceQuery().processInstanceId(processId).variableName(BPM_PACKAGE).singleResult();
if (variableInstance != null) {
packageScriptNode = (ActivitiScriptNode) variableInstance.getValue();
} else {
throw new EntityNotFoundException(processId);
}
} catch (ActivitiObjectNotFoundException e) {
throw new EntityNotFoundException(processId);
}
List<Item> page = new ArrayList<Item>();
if (packageScriptNode != null) {
List<ChildAssociationRef> documentList = nodeService.getChildAssocs(packageScriptNode.getNodeRef());
for (ChildAssociationRef childAssociationRef : documentList) {
Item item = createItemForNodeRef(childAssociationRef.getChildRef());
page.add(item);
}
}
return CollectionWithPagingInfo.asPaged(paging, page, false, page.size());
}
use of org.alfresco.rest.workflow.api.model.Item in project alfresco-remote-api by Alfresco.
the class WorkflowRestImpl method createItemForNodeRef.
protected Item createItemForNodeRef(NodeRef nodeRef) {
Map<QName, Serializable> properties = nodeService.getProperties(nodeRef);
Item item = new Item();
String name = (String) properties.get(ContentModel.PROP_NAME);
String title = (String) properties.get(ContentModel.PROP_TITLE);
String description = (String) properties.get(ContentModel.PROP_DESCRIPTION);
Date createdAt = (Date) properties.get(ContentModel.PROP_CREATED);
String createdBy = (String) properties.get(ContentModel.PROP_CREATOR);
Date modifiedAt = (Date) properties.get(ContentModel.PROP_MODIFIED);
String modifiedBy = (String) properties.get(ContentModel.PROP_MODIFIER);
ContentData contentData = (ContentData) nodeService.getProperty(nodeRef, ContentModel.PROP_CONTENT);
item.setId(nodeRef.getId());
item.setName(name);
item.setTitle(title);
item.setDescription(description);
item.setCreatedAt(createdAt);
item.setCreatedBy(createdBy);
item.setModifiedAt(modifiedAt);
item.setModifiedBy(modifiedBy);
if (contentData != null) {
item.setMimeType(contentData.getMimetype());
item.setSize(contentData.getSize());
}
return item;
}
use of org.alfresco.rest.workflow.api.model.Item in project alfresco-remote-api by Alfresco.
the class WorkflowRestImpl method createItemInProcess.
/**
* Create a new item in the process package variable
*/
public Item createItemInProcess(String itemId, String processId) {
NodeRef nodeRef = getNodeRef(itemId);
ActivitiScriptNode packageScriptNode = null;
try {
packageScriptNode = (ActivitiScriptNode) activitiProcessEngine.getRuntimeService().getVariable(processId, BPM_PACKAGE);
} catch (ActivitiObjectNotFoundException e) {
throw new EntityNotFoundException(processId);
}
if (packageScriptNode == null) {
throw new InvalidArgumentException("process doesn't contain a workflow package variable");
}
// check if noderef exists
try {
nodeService.getProperties(nodeRef);
} catch (Exception e) {
throw new EntityNotFoundException("item with id " + nodeRef.toString() + " not found");
}
try {
QName workflowPackageItemId = QName.createQName("wpi", nodeRef.toString());
nodeService.addChild(packageScriptNode.getNodeRef(), nodeRef, WorkflowModel.ASSOC_PACKAGE_CONTAINS, workflowPackageItemId);
} catch (Exception e) {
throw new ApiException("could not add item to process " + e.getMessage(), e);
}
Item responseItem = createItemForNodeRef(nodeRef);
activitiWorkflowEngine.dispatchPackageUpdatedEvent(packageScriptNode, null, null, processId, null);
return responseItem;
}
Aggregations