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;
import java.io.Serializable;
import java.text.MessageFormat;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
@@ -91,7 +91,7 @@ public class DeclareRecordAction extends RMActionExecuterAbstractBase
{
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
if (!checkMandatoryPropertiesEnabled ||
mandatoryPropertiesSet(actionedUponNodeRef, missingProperties))
@@ -100,7 +100,7 @@ public class DeclareRecordAction extends RMActionExecuterAbstractBase
try
{
// 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_BY, AuthenticationUtil.getRunAsUser());
this.getNodeService().addAspect(actionedUponNodeRef, ASPECT_DECLARED_RECORD, declaredProps);
@@ -195,13 +195,25 @@ public class DeclareRecordAction extends RMActionExecuterAbstractBase
}
// check for missing mandatory metadata from custom aspect definitions
// TODO should not apply record custom metadata for non-electronic and vice versa
if (result)
{
Collection<QName> aspects = this.getDictionaryService().getAspects(RM_CUSTOM_MODEL);
for (QName aspect : aspects)
QName aspect;
if (nodeRefType.equals(TYPE_NON_ELECTRONIC_DOCUMENT))
//if (nodeRefType.getLocalName()))
{
AspectDefinition aspectDef = this.getDictionaryService().getAspect(aspect);
aspect = TYPE_NON_ELECTRONIC_DOCUMENT;
}
else
{
aspect = ASPECT_RECORD;
}
// get customAspectImpl
String localName = aspect.toPrefixString(getNamespaceService()).replace(":", "");
localName = MessageFormat.format("{0}CustomProperties", localName);
QName customAspect = QName.createQName(RM_CUSTOM_URI, localName);
AspectDefinition aspectDef = this.getDictionaryService().getAspect(customAspect);
for (PropertyDefinition propDef : aspectDef.getProperties().values())
{
if (propDef.isMandatory() && nodeRefProps.get(propDef.getName()) == null)
@@ -213,7 +225,6 @@ public class DeclareRecordAction extends RMActionExecuterAbstractBase
}
}
}
}
return result;
}

View File

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