use of org.alfresco.service.cmr.dictionary.AspectDefinition in project records-management by Alfresco.
the class RecordsManagementAdminServiceImpl method initCustomMap.
/**
* Initialise custom type map
*/
private void initCustomMap() {
customisableTypes = new HashMap<QName, QName>(7);
Collection<QName> aspects = getDictionaryService().getAspects(RM_CUSTOM_MODEL);
for (QName aspect : aspects) {
AspectDefinition aspectDef = getDictionaryService().getAspect(aspect);
String name = aspectDef.getName().getLocalName();
if (name.endsWith("Properties")) {
QName type = null;
String prefixString = aspectDef.getDescription(getDictionaryService());
if (prefixString == null) {
// Backward compatibility from previous RM V1.0 custom models
if (CompatibilityModel.NAME_CUSTOM_RECORD_PROPERTIES.equals(name)) {
type = RecordsManagementModel.ASPECT_RECORD;
} else if (CompatibilityModel.NAME_CUSTOM_RECORD_FOLDER_PROPERTIES.equals(name)) {
type = RecordsManagementModel.TYPE_RECORD_FOLDER;
} else if (CompatibilityModel.NAME_CUSTOM_RECORD_CATEGORY_PROPERTIES.equals(name)) {
type = RecordsManagementModel.TYPE_RECORD_CATEGORY;
} else if (CompatibilityModel.NAME_CUSTOM_RECORD_SERIES_PROPERTIES.equals(name) && // a v1.0 installation has added custom properties
aspectDef.getProperties().size() != 0) {
type = CompatibilityModel.TYPE_RECORD_SERIES;
}
} else {
type = QName.createQName(prefixString, getNamespaceService());
}
// Add the customisable type to the map
if (type != null) {
customisableTypes.put(type, aspect);
// Remove customisable type from the pending list
if (pendingCustomisableTypes != null && pendingCustomisableTypes.contains(type)) {
pendingCustomisableTypes.remove(type);
}
}
}
}
// Deal with any pending types left over
if (pendingCustomisableTypes != null && pendingCustomisableTypes.size() != 0) {
NodeRef modelRef = getCustomModelRef(RecordsManagementModel.RM_CUSTOM_URI);
M2Model model = readCustomContentModel(modelRef);
try {
for (QName customisableType : pendingCustomisableTypes) {
QName customAspect = getCustomAspectImpl(customisableType);
// Create the new aspect to hold the custom properties
M2Aspect aspect = model.createAspect(customAspect.toPrefixString(getNamespaceService()));
aspect.setDescription(customisableType.toPrefixString(getNamespaceService()));
// Make a record of the customisable type
customisableTypes.put(customisableType, customAspect);
}
} finally {
writeCustomContentModel(modelRef, model);
}
}
// indicate map is initialised
isCustomMapInit = true;
}
use of org.alfresco.service.cmr.dictionary.AspectDefinition 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.AspectDefinition in project records-management by Alfresco.
the class RecordsManagementNodeFormFilter method addRecordMetadataPropertyFieldsToGroup.
/**
* @param form
* @param nodeRef
*/
protected void addRecordMetadataPropertyFieldsToGroup(Form form, NodeRef nodeRef) {
Set<QName> aspects = recordService.getRecordMetadataAspects(nodeRef);
for (QName aspect : aspects) {
if (nodeService.hasAspect(nodeRef, aspect)) {
String aspectName = aspect.getPrefixedQName(namespaceService).toPrefixString().replace(":", "-");
String setId = RM_METADATA_PREFIX + aspectName;
String setLabel = null;
AspectDefinition aspectDefinition = dictionaryService.getAspect(aspect);
if (aspectDefinition != null) {
setLabel = aspectDefinition.getTitle(new StaticMessageLookup());
}
addPropertyFieldsToGroup(form, dictionaryService.getPropertyDefs(aspect), setId, setLabel);
}
}
}
use of org.alfresco.service.cmr.dictionary.AspectDefinition in project records-management by Alfresco.
the class ApplyCustomTypeAction method getParameterDefintions.
@Override
protected synchronized List<ParameterDefinition> getParameterDefintions() {
// We can take these parameter definitions from the properties defined in the dod model.
if (this.parameterDefinitions == null) {
AspectDefinition aspectDefinition = getDictionaryService().getAspect(customTypeAspect);
if (aspectDefinition == null) {
throw new AlfrescoRuntimeException(I18NUtil.getMessage(MSG_CUSTOM_ASPECT_NOT_RECOGNISED, customTypeAspect));
}
Map<QName, PropertyDefinition> props = aspectDefinition.getProperties();
this.parameterDefinitions = new ArrayList<ParameterDefinition>(props.size());
for (Map.Entry<QName, PropertyDefinition> entry : props.entrySet()) {
String paramName = entry.getKey().toPrefixString(getNamespaceService());
PropertyDefinition value = entry.getValue();
QName paramType = value.getDataType().getName();
boolean paramIsMandatory = value.isMandatory();
parameterDefinitions.add(new ParameterDefinitionImpl(paramName, paramType, paramIsMandatory, null));
}
}
return parameterDefinitions;
}
use of org.alfresco.service.cmr.dictionary.AspectDefinition 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