RM-5175_Complete_record_with_missing_metadata

This commit is contained in:
Sara Aspery
2017-06-10 23:50:15 +01:00
parent 658f064a8d
commit bc0a9431ce
2 changed files with 33 additions and 22 deletions

View File

@@ -28,8 +28,8 @@
package org.alfresco.module.org_alfresco_module_rm.action.impl; package org.alfresco.module.org_alfresco_module_rm.action.impl;
import java.io.Serializable; import java.io.Serializable;
import java.text.MessageFormat;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection;
import java.util.Date; import java.util.Date;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
@@ -91,7 +91,7 @@ public class DeclareRecordAction extends RMActionExecuterAbstractBase
{ {
if (!getRecordService().isDeclared(actionedUponNodeRef)) if (!getRecordService().isDeclared(actionedUponNodeRef))
{ {
List<String> missingProperties = new ArrayList<String>(5); List<String> missingProperties = new ArrayList<>(5);
// Aspect not already defined - check mandatory properties then add // Aspect not already defined - check mandatory properties then add
if (!checkMandatoryPropertiesEnabled || if (!checkMandatoryPropertiesEnabled ||
mandatoryPropertiesSet(actionedUponNodeRef, missingProperties)) mandatoryPropertiesSet(actionedUponNodeRef, missingProperties))
@@ -100,7 +100,7 @@ public class DeclareRecordAction extends RMActionExecuterAbstractBase
try try
{ {
// Add the declared aspect // Add the declared aspect
Map<QName, Serializable> declaredProps = new HashMap<QName, Serializable>(2); Map<QName, Serializable> declaredProps = new HashMap<>(2);
declaredProps.put(PROP_DECLARED_AT, new Date()); declaredProps.put(PROP_DECLARED_AT, new Date());
declaredProps.put(PROP_DECLARED_BY, AuthenticationUtil.getRunAsUser()); declaredProps.put(PROP_DECLARED_BY, AuthenticationUtil.getRunAsUser());
this.getNodeService().addAspect(actionedUponNodeRef, ASPECT_DECLARED_RECORD, declaredProps); this.getNodeService().addAspect(actionedUponNodeRef, ASPECT_DECLARED_RECORD, declaredProps);
@@ -195,22 +195,33 @@ public class DeclareRecordAction extends RMActionExecuterAbstractBase
} }
// check for missing mandatory metadata from custom aspect definitions // check for missing mandatory metadata from custom aspect definitions
// TODO should not apply record custom metadata for non-electronic and vice versa
if (result) if (result)
{ {
Collection<QName> aspects = this.getDictionaryService().getAspects(RM_CUSTOM_MODEL); QName aspect;
for (QName aspect : aspects) if (nodeRefType.equals(TYPE_NON_ELECTRONIC_DOCUMENT))
//if (nodeRefType.getLocalName()))
{ {
AspectDefinition aspectDef = this.getDictionaryService().getAspect(aspect); aspect = TYPE_NON_ELECTRONIC_DOCUMENT;
for (PropertyDefinition propDef : aspectDef.getProperties().values()) }
{ else
if (propDef.isMandatory() && nodeRefProps.get(propDef.getName()) == null) {
{ aspect = ASPECT_RECORD;
logMissingProperty(propDef, missingProperties); }
// get customAspectImpl
String localName = aspect.toPrefixString(getNamespaceService()).replace(":", "");
localName = MessageFormat.format("{0}CustomProperties", localName);
QName customAspect = QName.createQName(RM_CUSTOM_URI, localName);
result = false; AspectDefinition aspectDef = this.getDictionaryService().getAspect(customAspect);
break;
} for (PropertyDefinition propDef : aspectDef.getProperties().values())
{
if (propDef.isMandatory() && nodeRefProps.get(propDef.getName()) == null)
{
logMissingProperty(propDef, missingProperties);
result = false;
break;
} }
} }
} }

View File

@@ -285,7 +285,7 @@ public class CompleteRecordTest extends BaseRMTestCase
defineCustomMetadata(CUSTOM_NON_ELECTRONIC_TEST, TYPE_NON_ELECTRONIC_DOCUMENT, MANDATORY_METADATA); defineCustomMetadata(CUSTOM_NON_ELECTRONIC_TEST, TYPE_NON_ELECTRONIC_DOCUMENT, MANDATORY_METADATA);
// create a non-electronic record // create a non-electronic record
nonElectronicRecord = utils.createRecord(rmFolder, "non-electronicRecord.txt", "title"); nonElectronicRecord = utils.createNonElectronicRecord(rmFolder, "non-electronicRecord.txt", "title");
} }
public void when() public void when()
@@ -329,10 +329,10 @@ public class CompleteRecordTest extends BaseRMTestCase
action.setCheckMandatoryPropertiesEnabled(true); action.setCheckMandatoryPropertiesEnabled(true);
// create the custom metadata definition (that has a mandatory property) // create the custom metadata definition (that has a mandatory property)
defineCustomMetadata(CUSTOM_NON_ELECTRONIC_TEST, ASPECT_RECORD, MANDATORY_METADATA); defineCustomMetadata(CUSTOM_NON_ELECTRONIC_TEST, TYPE_NON_ELECTRONIC_DOCUMENT, MANDATORY_METADATA);
// create a non-electronic record // create a non-electronic record
nonElectronicRecord = utils.createRecord(rmFolder, "non-electronicRecord.txt", "title"); nonElectronicRecord = utils.createNonElectronicRecord(rmFolder, "non-electronicRecord.txt", "title");
// populate the custom metadata mandatory property for the record // populate the custom metadata mandatory property for the record
populateCustomMetadata(nonElectronicRecord, CUSTOM_NON_ELECTRONIC_TEST); populateCustomMetadata(nonElectronicRecord, CUSTOM_NON_ELECTRONIC_TEST);
@@ -424,11 +424,11 @@ public class CompleteRecordTest extends BaseRMTestCase
// enable mandatory parameter check // enable mandatory parameter check
action.setCheckMandatoryPropertiesEnabled(true); action.setCheckMandatoryPropertiesEnabled(true);
// create the custom metadata definition (that has a mandatory property) // create the record custom metadata definition (that has a mandatory property)
defineCustomMetadata(CUSTOM_ELECTRONIC_TEST, ASPECT_RECORD, MANDATORY_METADATA); defineCustomMetadata(CUSTOM_ELECTRONIC_TEST, ASPECT_RECORD, MANDATORY_METADATA);
// create a non-electronic record // create a non-electronic record
nonElectronicRecord = utils.createRecord(rmFolder, "non-electronicRecord.txt", "title"); nonElectronicRecord = utils.createNonElectronicRecord(rmFolder, "non-electronicRecord.txt", "title");
} }
public void when() public void when()
@@ -471,8 +471,8 @@ public class CompleteRecordTest extends BaseRMTestCase
// enable mandatory parameter check // enable mandatory parameter check
action.setCheckMandatoryPropertiesEnabled(true); action.setCheckMandatoryPropertiesEnabled(true);
// create the custom metadata definition (that has a mandatory property) // create the non-electronic record custom metadata definition (that has a mandatory property)
defineCustomMetadata(CUSTOM_NON_ELECTRONIC_TEST, ASPECT_RECORD, MANDATORY_METADATA); defineCustomMetadata(CUSTOM_NON_ELECTRONIC_TEST, TYPE_NON_ELECTRONIC_DOCUMENT, MANDATORY_METADATA);
// create a electronic record // create a electronic record
record = utils.createRecord(rmFolder, "electronicRecord.txt", "title"); record = utils.createRecord(rmFolder, "electronicRecord.txt", "title");