use of org.alfresco.service.cmr.dictionary.TypeDefinition in project alfresco-remote-api by Alfresco.
the class AbstractWorkflowRestApiTest method checkWorkflowTaskDefinition.
private void checkWorkflowTaskDefinition(WorkflowTaskDefinition wfDefinition, JSONObject definition) throws Exception {
assertNotNull(definition);
assertEquals(wfDefinition.getId(), definition.getString("id"));
assertTrue(definition.has("url"));
JSONObject type = definition.getJSONObject("type");
TypeDefinition startType = (wfDefinition).getMetadata();
assertNotNull(type);
assertEquals(startType.getName().toPrefixString(), type.getString("name"));
assertEquals(startType.getTitle(this.dictionaryService), type.getString("title"));
assertEquals(startType.getDescription(this.dictionaryService), type.getString("description"));
assertTrue(type.has("url"));
JSONObject node = definition.getJSONObject("node");
WorkflowNode startNode = wfDefinition.getNode();
assertNotNull(node);
assertEquals(startNode.getName(), node.getString("name"));
assertEquals(startNode.getTitle(), node.getString("title"));
assertEquals(startNode.getDescription(), node.getString("description"));
assertEquals(startNode.isTaskNode(), node.getBoolean("isTaskNode"));
JSONArray transitions = node.getJSONArray("transitions");
WorkflowTransition[] startTransitions = startNode.getTransitions();
assertNotNull(transitions);
assertEquals(startTransitions.length, transitions.length());
for (int i = 0; i < transitions.length(); i++) {
JSONObject transition = transitions.getJSONObject(i);
WorkflowTransition startTransition = startTransitions[i];
assertNotNull(transition);
if (startTransition.getId() == null) {
assertEquals("", transition.getString("id"));
} else {
assertEquals(startTransition.getId(), transition.getString("id"));
}
assertEquals(startTransition.getTitle(), transition.getString("title"));
assertEquals(startTransition.getDescription(), transition.getString("description"));
assertEquals(startTransition.isDefault(), transition.getBoolean("isDefault"));
assertTrue(transition.has("isHidden"));
}
}
use of org.alfresco.service.cmr.dictionary.TypeDefinition in project records-management by Alfresco.
the class RecordsManagementAdminServiceImpl method getCustomisable.
/**
* @see org.alfresco.module.org_alfresco_module_rm.RecordsManagementAdminService#getCustomisable(org.alfresco.service.cmr.repository.NodeRef)
*/
@Override
public Set<QName> getCustomisable(NodeRef nodeRef) {
mandatory("nodeRef", nodeRef);
Set<QName> result = new HashSet<QName>(5);
// Check the nodes hierarchy for customisable types
QName type = getNodeService().getType(nodeRef);
while (type != null && !ContentModel.TYPE_CMOBJECT.equals(type)) {
// Add to the list if the type is customisable
if (isCustomisable(type)) {
result.add(type);
}
// Type and get the types parent
TypeDefinition def = getDictionaryService().getType(type);
if (def != null) {
type = def.getParentName();
} else {
type = null;
}
}
// Get all the nodes aspects
Set<QName> aspects = getNodeService().getAspects(nodeRef);
for (QName aspect : aspects) {
QName tempAspect = QName.createQName(aspect.toString());
while (tempAspect != null) {
// Add to the list if the aspect is customisable
if (isCustomisable(tempAspect)) {
result.add(tempAspect);
}
// Try and get the parent aspect
AspectDefinition aspectDef = getDictionaryService().getAspect(tempAspect);
if (aspectDef != null) {
tempAspect = aspectDef.getParentName();
} else {
tempAspect = null;
}
}
}
return result;
}
use of org.alfresco.service.cmr.dictionary.TypeDefinition in project records-management by Alfresco.
the class RecordServiceImpl method validateForCompletion.
/**
* Helper method to validate whether the node is in a state suitable for completion
*
* @param nodeRef node reference
* @throws Exception if node not valid for completion
*/
private void validateForCompletion(NodeRef nodeRef) {
if (!nodeService.exists(nodeRef)) {
LOGGER.warn(I18NUtil.getMessage(MSG_UNDECLARED_ONLY_RECORDS, nodeRef.toString()));
throw new IntegrityException("The record does not exist.", null);
}
if (!isRecord(nodeRef)) {
LOGGER.warn(I18NUtil.getMessage(MSG_UNDECLARED_ONLY_RECORDS, nodeRef.toString()));
throw new IntegrityException("The node is not a record.", null);
}
if (freezeService.isFrozen(nodeRef)) {
LOGGER.warn(I18NUtil.getMessage(MSG_UNDECLARED_ONLY_RECORDS, nodeRef.toString()));
throw new IntegrityException("The record is frozen.", null);
}
if (isDeclared(nodeRef)) {
throw new IntegrityException("The record is already completed.", null);
}
// if the record is newly created make sure the record identifier is set before completing the record
Set<NodeRef> newRecords = transactionalResourceHelper.getSet(RecordServiceImpl.KEY_NEW_RECORDS);
if (newRecords.contains(nodeRef)) {
generateRecordIdentifier(nodeService, identifierService, nodeRef);
}
// Validate that all mandatory properties, if any, are present
List<String> missingProperties = new ArrayList<>(5);
// Aspect not already defined - check mandatory properties then add
if (checkMandatoryPropertiesEnabled) {
Map<QName, Serializable> nodeRefProps = nodeService.getProperties(nodeRef);
QName nodeRefType = nodeService.getType(nodeRef);
// check for missing mandatory metadata from type definitions
TypeDefinition typeDef = dictionaryService.getType(nodeRefType);
checkDefinitionMandatoryPropsSet(typeDef, nodeRefProps, missingProperties);
// check for missing mandatory metadata from aspect definitions
Set<QName> aspects = nodeService.getAspects(nodeRef);
for (QName aspect : aspects) {
AspectDefinition aspectDef = dictionaryService.getAspect(aspect);
checkDefinitionMandatoryPropsSet(aspectDef, nodeRefProps, missingProperties);
}
// check for missing mandatory metadata from custom aspect definitions
QName customAspect = getCustomAspectImpl(nodeRefType);
AspectDefinition aspectDef = dictionaryService.getAspect(customAspect);
checkDefinitionMandatoryPropsSet(aspectDef, nodeRefProps, missingProperties);
if (!missingProperties.isEmpty()) {
LOGGER.debug(buildMissingPropertiesErrorString(missingProperties));
throw new RecordMissingMetadataException("The record has missing mandatory properties.");
}
}
}
Aggregations