Merge branch 'feature-2.5/RM-5175_Complete_record_missing_metadata' into merge/RM_25

Conflicts:
	rm-community/rm-community-repo/source/java/org/alfresco/module/org_alfresco_module_rm/action/impl/DeclareRecordAction.java
This commit is contained in:
Tuna Aksoy
2017-06-12 20:42:51 +01:00
3 changed files with 587 additions and 154 deletions

View File

@@ -27,7 +27,10 @@
package org.alfresco.module.org_alfresco_module_rm.action.impl; package org.alfresco.module.org_alfresco_module_rm.action.impl;
import static org.alfresco.module.org_alfresco_module_rm.record.RecordUtils.generateRecordIdentifier;
import java.io.Serializable; import java.io.Serializable;
import java.text.MessageFormat;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Date; import java.util.Date;
import java.util.HashMap; import java.util.HashMap;
@@ -35,8 +38,6 @@ import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
import static org.alfresco.module.org_alfresco_module_rm.record.RecordUtils.generateRecordIdentifier;
import org.alfresco.module.org_alfresco_module_rm.action.RMActionExecuterAbstractBase; import org.alfresco.module.org_alfresco_module_rm.action.RMActionExecuterAbstractBase;
import org.alfresco.module.org_alfresco_module_rm.record.RecordServiceImpl; import org.alfresco.module.org_alfresco_module_rm.record.RecordServiceImpl;
import org.alfresco.module.org_alfresco_module_rm.util.TransactionalResourceHelper; import org.alfresco.module.org_alfresco_module_rm.util.TransactionalResourceHelper;
@@ -63,24 +64,24 @@ public class DeclareRecordAction extends RMActionExecuterAbstractBase
{ {
/** action name */ /** action name */
public static final String NAME = "declareRecord"; public static final String NAME = "declareRecord";
/** I18N */ /** I18N */
private static final String MSG_UNDECLARED_ONLY_RECORDS = "rm.action.undeclared-only-records"; private static final String MSG_UNDECLARED_ONLY_RECORDS = "rm.action.undeclared-only-records";
private static final String MSG_NO_DECLARE_MAND_PROP = "rm.action.no-declare-mand-prop"; private static final String MSG_NO_DECLARE_MAND_PROP = "rm.action.no-declare-mand-prop";
/** Logger */ /** Logger */
private static Log logger = LogFactory.getLog(DeclareRecordAction.class); private static Log logger = LogFactory.getLog(DeclareRecordAction.class);
/** check mandatory properties */ /** check mandatory properties */
private boolean checkMandatoryPropertiesEnabled = true; private boolean checkMandatoryPropertiesEnabled = true;
/** transactional resource helper */ /** transactional resource helper */
private TransactionalResourceHelper transactionalResourceHelper; private TransactionalResourceHelper transactionalResourceHelper;
/** /**
* @param checkMandatoryPropertiesEnabled true if check mandatory properties is enabled, false otherwise * @param checkMandatoryPropertiesEnabled true if check mandatory properties is enabled, false otherwise
*/ */
public void setCheckMandatoryPropertiesEnabled(boolean checkMandatoryPropertiesEnabled) public void setCheckMandatoryPropertiesEnabled(boolean checkMandatoryPropertiesEnabled)
{ {
this.checkMandatoryPropertiesEnabled = checkMandatoryPropertiesEnabled; this.checkMandatoryPropertiesEnabled = checkMandatoryPropertiesEnabled;
} }
@@ -112,16 +113,16 @@ public class DeclareRecordAction extends RMActionExecuterAbstractBase
generateRecordIdentifier(getNodeService(), getIdentifierService(), actionedUponNodeRef); generateRecordIdentifier(getNodeService(), getIdentifierService(), 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))
{ {
getRecordService().disablePropertyEditableCheck(); getRecordService().disablePropertyEditableCheck();
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);
@@ -215,6 +216,34 @@ public class DeclareRecordAction extends RMActionExecuterAbstractBase
} }
} }
// check for missing mandatory metadata from custom aspect definitions
if (result)
{
QName aspect = ASPECT_RECORD;
if (nodeRefType.equals(TYPE_NON_ELECTRONIC_DOCUMENT))
{
aspect = TYPE_NON_ELECTRONIC_DOCUMENT;
}
// 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)
{
logMissingProperty(propDef, missingProperties);
result = false;
break;
}
}
}
return result; return result;
} }

View File

@@ -33,210 +33,591 @@ import java.util.Map;
import org.alfresco.module.org_alfresco_module_rm.action.RecordsManagementActionResult; import org.alfresco.module.org_alfresco_module_rm.action.RecordsManagementActionResult;
import org.alfresco.module.org_alfresco_module_rm.action.impl.DeclareRecordAction; import org.alfresco.module.org_alfresco_module_rm.action.impl.DeclareRecordAction;
import org.alfresco.module.org_alfresco_module_rm.model.RecordsManagementCustomModel;
import org.alfresco.module.org_alfresco_module_rm.test.util.BaseRMTestCase; import org.alfresco.module.org_alfresco_module_rm.test.util.BaseRMTestCase;
import org.alfresco.service.cmr.dictionary.DataTypeDefinition;
import org.alfresco.service.cmr.repository.NodeRef; import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.namespace.QName; import org.alfresco.service.namespace.QName;
/** /**
* Complete record tests. * Complete record tests.
* *
* @author Roy Wetherall * @author Roy Wetherall
* @since 2.2.1 * @since 2.2.1
*/ */
public class CompleteRecordTest extends BaseRMTestCase public class CompleteRecordTest extends BaseRMTestCase
{ {
private static final QName ASPECT_TEST = QName.createQName("http://www.alfresco.org/model/rmtest/1.0", "recordMetaDataWithProperty"); private static final QName ASPECT_TEST = QName.createQName("http://www.alfresco.org/model/rmtest/1.0", "recordMetaDataWithProperty");
private static final QName PROP_TEST = QName.createQName("http://www.alfresco.org/model/rmtest/1.0", "customMandatoryProperty"); private static final QName PROP_TEST = QName.createQName("http://www.alfresco.org/model/rmtest/1.0", "customMandatoryProperty");
private static final QName CUSTOM_ELECTRONIC_TEST = QName.createQName(RecordsManagementCustomModel.RM_CUSTOM_URI, "rmarecordCustomProperties");
/** complete record action */ private static final QName CUSTOM_NON_ELECTRONIC_TEST = QName.createQName(RecordsManagementCustomModel.RM_CUSTOM_URI, "rmanonElectronicDocumentCustomProperties");
private DeclareRecordAction action; private static final boolean MANDATORY_METADATA = true;
private static final boolean OPTIONAL_METADATA = false;
/**
* @see org.alfresco.module.org_alfresco_module_rm.test.util.BaseRMTestCase#initServices() /**
*/ * complete record action
@Override */
protected void initServices() private DeclareRecordAction action;
{
super.initServices(); /**
* @see org.alfresco.module.org_alfresco_module_rm.test.util.BaseRMTestCase#initServices()
// get the action */
action = (DeclareRecordAction)applicationContext.getBean("declareRecord"); @Override
} protected void initServices()
{
/** super.initServices();
* @see org.alfresco.module.org_alfresco_module_rm.test.util.BaseRMTestCase#tearDownImpl()
*/ // get the action
@Override action = (DeclareRecordAction) applicationContext.getBean("declareRecord");
protected void tearDownImpl() }
{
super.tearDownImpl(); /**
* @see org.alfresco.module.org_alfresco_module_rm.test.util.BaseRMTestCase#tearDownImpl()
// ensure action is returned to original state */
action.setCheckMandatoryPropertiesEnabled(true); @Override
} protected void tearDownImpl()
{
/** super.tearDownImpl();
* Given the the application is configured to check for mandatory values before complete
* And a filed record is missing mandatory values // ensure action is returned to original state
* When I try to complete the record action.setCheckMandatoryPropertiesEnabled(true);
* Then the missing properties parameter of the action will be populated }
* And the record will not be complete
*/ /**
* Given the the application is configured to check for mandatory values before complete
* And a filed record is missing mandatory values
* When I try to complete the record
* Then the missing properties parameter of the action will be populated
* And the record will not be complete
*/
public void testCheckForMandatoryValuesMissing() throws Exception public void testCheckForMandatoryValuesMissing() throws Exception
{ {
doBehaviourDrivenTest(new BehaviourDrivenTest() doBehaviourDrivenTest(new BehaviourDrivenTest()
{ {
private NodeRef record; private NodeRef record;
private RecordsManagementActionResult result; private RecordsManagementActionResult result;
public void given() public void given()
{ {
// enable mandatory parameter check // enable mandatory parameter check
action.setCheckMandatoryPropertiesEnabled(true); action.setCheckMandatoryPropertiesEnabled(true);
// create a record // create a record
record = utils.createRecord(rmFolder, "record.txt", "title"); record = utils.createRecord(rmFolder, "record.txt", "title");
// add the record aspect (that has a mandatory property) // add the record aspect (that has a mandatory property)
nodeService.addAspect(record, ASPECT_TEST, null); nodeService.addAspect(record, ASPECT_TEST, null);
} }
public void when() public void when()
{ {
// complete record // complete record
result = rmActionService.executeRecordsManagementAction(record, "declareRecord"); result = rmActionService.executeRecordsManagementAction(record, "declareRecord");
} }
public void then() public void then()
{ {
assertNotNull(result); assertNotNull(result);
assertNotNull(result.getValue()); assertNotNull(result.getValue());
assertFalse(nodeService.hasAspect(record, ASPECT_DECLARED_RECORD)); assertFalse(nodeService.hasAspect(record, ASPECT_DECLARED_RECORD));
} }
}); });
} }
/** /**
* Given the the application is configured to check for mandatory values before complete * Given the the application is configured to check for mandatory values before complete
* And a filed record has all mandatory values * And a filed record has all mandatory values
* When I try to complete the record * When I try to complete the record
* Then the record is completed * Then the record is completed
*/ */
public void testCheckForMandatoryValuePresent() throws Exception public void testCheckForMandatoryValuePresent() throws Exception
{ {
doBehaviourDrivenTest(new BehaviourDrivenTest() doBehaviourDrivenTest(new BehaviourDrivenTest()
{ {
private NodeRef record; private NodeRef record;
private RecordsManagementActionResult result; private RecordsManagementActionResult result;
public void given() public void given()
{ {
// enable mandatory parameter check // enable mandatory parameter check
action.setCheckMandatoryPropertiesEnabled(true); action.setCheckMandatoryPropertiesEnabled(true);
// create a record // create a record
record = utils.createRecord(rmFolder, "record.txt", "title"); record = utils.createRecord(rmFolder, "record.txt", "title");
// add the record aspect (that has a mandatory property) // add the record aspect (that has a mandatory property)
Map<QName, Serializable> properties = new HashMap<QName, Serializable>(1); Map<QName, Serializable> properties = new HashMap<>(1);
properties.put(PROP_TEST, "something"); properties.put(PROP_TEST, "something");
nodeService.addAspect(record, ASPECT_TEST, properties); nodeService.addAspect(record, ASPECT_TEST, properties);
} }
public void when() public void when()
{ {
// complete record // complete record
result = rmActionService.executeRecordsManagementAction(record, "declareRecord"); result = rmActionService.executeRecordsManagementAction(record, "declareRecord");
} }
public void then() public void then()
{ {
assertNotNull(result); assertNotNull(result);
assertNull(result.getValue()); assertNull(result.getValue());
assertTrue(nodeService.hasAspect(record, ASPECT_DECLARED_RECORD)); assertTrue(nodeService.hasAspect(record, ASPECT_DECLARED_RECORD));
} }
}); });
} }
/** /**
* Given the the application is configured not to check for mandatory values before complete * Given the the application is configured to check for mandatory values before complete
* And a filed record is missing mandatory values * And a filed record is missing custom mandatory values
* When I try to complete the record * When I try to complete the record
* Then the record is completed * Then the missing properties parameter of the action will be populated
*/ * And the record will not be complete
*/
public void testCheckForCustomMandatoryValuesMissing() throws Exception
{
doBehaviourDrivenTest(new BehaviourDrivenTest()
{
private NodeRef record;
private RecordsManagementActionResult result;
public void given() throws Exception
{
// enable mandatory parameter check
action.setCheckMandatoryPropertiesEnabled(true);
// create the custom metadata definition (that has a mandatory property) for electronic records
defineCustomMetadata(CUSTOM_ELECTRONIC_TEST, ASPECT_RECORD, MANDATORY_METADATA);
// create an electronic record
record = utils.createRecord(rmFolder, "electronicRecord.txt", "title");
}
public void when()
{
// complete record
result = rmActionService.executeRecordsManagementAction(record, "declareRecord");
}
public void then()
{
assertNotNull(result);
assertNotNull(result.getValue());
assertFalse(nodeService.hasAspect(record, ASPECT_DECLARED_RECORD));
}
public void after()
{
// remove the custom metadata definition
removeCustomMetadata(CUSTOM_ELECTRONIC_TEST);
}
});
}
/**
* Given the the application is configured to check for mandatory values before complete
* And a filed record has all custom mandatory values
* When I try to complete the record
* Then the record is completed
*/
public void testCheckForCustomMandatoryValuePresent() throws Exception
{
doBehaviourDrivenTest(new BehaviourDrivenTest()
{
private NodeRef record;
private RecordsManagementActionResult result;
public void given() throws Exception
{
// enable mandatory parameter check
action.setCheckMandatoryPropertiesEnabled(true);
// define the custom metadata definition (that has a mandatory property)
defineCustomMetadata(CUSTOM_ELECTRONIC_TEST, ASPECT_RECORD, MANDATORY_METADATA);
// create a record
record = utils.createRecord(rmFolder, "customrecord.txt", "title");
// populate the custom metadata mandatory property for the record
populateCustomMetadata(record, CUSTOM_ELECTRONIC_TEST);
}
public void when()
{
// complete record
result = rmActionService.executeRecordsManagementAction(record, "declareRecord");
}
public void then()
{
assertNotNull(result);
assertNull(result.getValue());
assertTrue(nodeService.hasAspect(record, ASPECT_DECLARED_RECORD));
}
public void after()
{
// remove the custom metadata definition
removeCustomMetadata(CUSTOM_ELECTRONIC_TEST);
}
});
}
/**
* Given the the application is configured to check for mandatory values before complete
* And a non-electronic record is missing custom mandatory values
* When I try to complete the record
* Then the missing properties parameter of the action will be populated
* And the record will not be complete
*/
public void testCheckForCustomMandatoryValuesMissingInNonElectronicRecord() throws Exception
{
doBehaviourDrivenTest(new BehaviourDrivenTest()
{
private NodeRef nonElectronicRecord;
private RecordsManagementActionResult result;
public void given() throws Exception
{
// enable mandatory parameter check
action.setCheckMandatoryPropertiesEnabled(true);
// create the custom metadata definition (that has a mandatory property) for non-electronic records
defineCustomMetadata(CUSTOM_NON_ELECTRONIC_TEST, TYPE_NON_ELECTRONIC_DOCUMENT, MANDATORY_METADATA);
// create a non-electronic record
nonElectronicRecord = utils.createNonElectronicRecord(rmFolder, "non-electronicRecord.txt", "title");
}
public void when()
{
// complete non-electronic record
result = rmActionService.executeRecordsManagementAction(nonElectronicRecord,
"declareRecord");
}
public void then()
{
assertNotNull(result);
assertNotNull(result.getValue());
assertFalse(nodeService.hasAspect(nonElectronicRecord, ASPECT_DECLARED_RECORD));
}
public void after()
{
// remove the custom metadata definition
removeCustomMetadata(CUSTOM_NON_ELECTRONIC_TEST);
}
});
}
/**
* Given the the application is configured to check for mandatory values before complete
* And a non-electronic record has all custom mandatory values
* When I try to complete the record
* Then the record is completed
*/
public void testCheckForCustomMandatoryValuePresentInNonElectronicRecord() throws Exception
{
doBehaviourDrivenTest(new BehaviourDrivenTest()
{
private NodeRef nonElectronicRecord;
private RecordsManagementActionResult result;
public void given() throws Exception
{
// enable mandatory parameter check
action.setCheckMandatoryPropertiesEnabled(true);
// create the custom metadata definition (that has a mandatory property)
defineCustomMetadata(CUSTOM_NON_ELECTRONIC_TEST, TYPE_NON_ELECTRONIC_DOCUMENT, MANDATORY_METADATA);
// create a non-electronic record
nonElectronicRecord = utils.createNonElectronicRecord(rmFolder, "non-electronicRecord.txt", "title");
// populate the custom metadata mandatory property for the record
populateCustomMetadata(nonElectronicRecord, CUSTOM_NON_ELECTRONIC_TEST);
}
public void when()
{
// complete record
result = rmActionService.executeRecordsManagementAction(nonElectronicRecord, "declareRecord");
}
public void then()
{
assertNotNull(result);
assertNull(result.getValue());
assertTrue(nodeService.hasAspect(nonElectronicRecord, ASPECT_DECLARED_RECORD));
}
public void after()
{
// remove the custom metadata definition
removeCustomMetadata(CUSTOM_NON_ELECTRONIC_TEST);
}
});
}
/**
* Given the the application is configured to check for mandatory values before complete
* And a filed record is missing custom non-mandatory values
* When I try to complete the record
* Then the record is completed
*/
public void testCheckForCustomOptionalValuesMissing() throws Exception
{
doBehaviourDrivenTest(new BehaviourDrivenTest()
{
private NodeRef record;
private RecordsManagementActionResult result;
public void given() throws Exception
{
// enable mandatory parameter check
action.setCheckMandatoryPropertiesEnabled(true);
// create the custom metadata definition (that does not have a mandatory property)
defineCustomMetadata(CUSTOM_ELECTRONIC_TEST, ASPECT_RECORD, OPTIONAL_METADATA);
// create a record
record = utils.createRecord(rmFolder, "customrecord.txt", "title");
}
public void when()
{
// complete record
result = rmActionService.executeRecordsManagementAction(record, "declareRecord");
}
public void then()
{
assertNotNull(result);
assertNull(result.getValue());
assertTrue(nodeService.hasAspect(record, ASPECT_DECLARED_RECORD));
}
public void after()
{
// remove the custom metadata definition
removeCustomMetadata(CUSTOM_ELECTRONIC_TEST);
}
});
}
/**
* Given the the application is configured to check for mandatory values before complete
* And custom mandatory metadata is required for electronic records
* And a non-electronic record has no custom mandatory values
* When I try to complete the non-electronic record
* Then the record is completed
*/
public void testElectronicRecordCustomMandatoryNotAppliedToNonElectronicRecord() throws Exception
{
doBehaviourDrivenTest(new BehaviourDrivenTest()
{
private NodeRef nonElectronicRecord;
private RecordsManagementActionResult result;
public void given() throws Exception
{
// enable mandatory parameter check
action.setCheckMandatoryPropertiesEnabled(true);
// 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.createNonElectronicRecord(rmFolder, "non-electronicRecord.txt", "title");
}
public void when()
{
// complete record
result = rmActionService.executeRecordsManagementAction(nonElectronicRecord, "declareRecord");
}
public void then()
{
assertNotNull(result);
assertNull(result.getValue());
assertTrue(nodeService.hasAspect(nonElectronicRecord, ASPECT_DECLARED_RECORD));
}
public void after()
{
// remove the custom metadata definition
removeCustomMetadata(CUSTOM_ELECTRONIC_TEST);
}
});
}
/**
* Given the the application is configured to check for mandatory values before complete
* And custom mandatory metadata is required for non-electronic records
* And an electronic record has no custom mandatory values
* When I try to complete the electronic record
* Then the record is completed
*/
public void testNonElectronicRecordCustomMandatoryNotAppliedToElectronicRecord() throws Exception
{
doBehaviourDrivenTest(new BehaviourDrivenTest()
{
private NodeRef record;
private RecordsManagementActionResult result;
public void given() throws Exception
{
// enable mandatory parameter check
action.setCheckMandatoryPropertiesEnabled(true);
// 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");
}
public void when()
{
// complete record
result = rmActionService.executeRecordsManagementAction(record, "declareRecord");
}
public void then()
{
assertNotNull(result);
assertNull(result.getValue());
assertTrue(nodeService.hasAspect(record, ASPECT_DECLARED_RECORD));
}
public void after()
{
// remove the custom metadata definition
removeCustomMetadata(CUSTOM_NON_ELECTRONIC_TEST);
}
});
}
/**
* Given the the application is configured not to check for mandatory values before complete
* And a filed record is missing mandatory values
* When I try to complete the record
* Then the record is completed
*/
public void testDontCheckForMandatoryValuesMissing() throws Exception public void testDontCheckForMandatoryValuesMissing() throws Exception
{ {
doBehaviourDrivenTest(new BehaviourDrivenTest() doBehaviourDrivenTest(new BehaviourDrivenTest()
{ {
private NodeRef record; private NodeRef record;
private RecordsManagementActionResult result; private RecordsManagementActionResult result;
public void given() public void given()
{ {
// disable mandatory parameter check // disable mandatory parameter check
action.setCheckMandatoryPropertiesEnabled(false); action.setCheckMandatoryPropertiesEnabled(false);
// create a record // create a record
record = utils.createRecord(rmFolder, "record.txt", "title"); record = utils.createRecord(rmFolder, "record.txt", "title");
// add the record aspect (that has a mandatory property) // add the record aspect (that has a mandatory property)
nodeService.addAspect(record, ASPECT_TEST, null); nodeService.addAspect(record, ASPECT_TEST, null);
} }
public void when() public void when()
{ {
// complete record // complete record
result = rmActionService.executeRecordsManagementAction(record, "declareRecord"); result = rmActionService.executeRecordsManagementAction(record, "declareRecord");
} }
public void then() public void then()
{ {
assertNotNull(result); assertNotNull(result);
assertNull(result.getValue()); assertNull(result.getValue());
assertTrue(nodeService.hasAspect(record, ASPECT_DECLARED_RECORD)); assertTrue(nodeService.hasAspect(record, ASPECT_DECLARED_RECORD));
} }
}); });
} }
/** /**
* Given the the application is configured to not to check for mandatory values before complete * Given the the application is configured to not to check for mandatory values before complete
* And a filed record has all mandatory values * And a filed record has all mandatory values
* When I try to complete the record * When I try to complete the record
* Then the record is completed * Then the record is completed
*/ */
public void testDontCheckForMandatoryValuePresent() throws Exception public void testDontCheckForMandatoryValuePresent() throws Exception
{ {
doBehaviourDrivenTest(new BehaviourDrivenTest() doBehaviourDrivenTest(new BehaviourDrivenTest()
{ {
private NodeRef record; private NodeRef record;
private RecordsManagementActionResult result; private RecordsManagementActionResult result;
public void given() public void given()
{ {
// enable mandatory parameter check // enable mandatory parameter check
action.setCheckMandatoryPropertiesEnabled(false); action.setCheckMandatoryPropertiesEnabled(false);
// create a record // create a record
record = utils.createRecord(rmFolder, "record.txt", "title"); record = utils.createRecord(rmFolder, "record.txt", "title");
// add the record aspect (that has a mandatory property) // add the record aspect (that has a mandatory property)
Map<QName, Serializable> properties = new HashMap<QName, Serializable>(1); Map<QName, Serializable> properties = new HashMap<>(1);
properties.put(PROP_TEST, "something"); properties.put(PROP_TEST, "something");
nodeService.addAspect(record, ASPECT_TEST, properties); nodeService.addAspect(record, ASPECT_TEST, properties);
} }
public void when() public void when()
{ {
// complete record // complete record
result = rmActionService.executeRecordsManagementAction(record, "declareRecord"); result = rmActionService.executeRecordsManagementAction(record, "declareRecord");
} }
public void then() public void then()
{ {
assertNotNull(result); assertNotNull(result);
assertNull(result.getValue()); assertNull(result.getValue());
assertTrue(nodeService.hasAspect(record, ASPECT_DECLARED_RECORD)); assertTrue(nodeService.hasAspect(record, ASPECT_DECLARED_RECORD));
} }
}); });
}
/**
* Helper method to create a Custom Metadata definition in the RM custom model
*
* @param mandatory specifies if metadata is mandatory
*/
private void defineCustomMetadata(QName propId, QName typeName, boolean mandatory) throws Exception
{
rmAdminService.addCustomPropertyDefinition(
propId,
typeName,
"SomeCustomDefLabel",
DataTypeDefinition.TEXT,
null,
null,
null,
false,
mandatory,
false,
null
);
}
/**
* Helper method to populate the Custom Metadata for the record
*/
private void populateCustomMetadata(NodeRef record, QName propId)
{
Map<QName, Serializable> properties = new HashMap<>(1);
properties.put(propId, "SomeCustomValue");
nodeService.addAspect(record, propId, properties);
}
/**
* Helper method to remove the Custom Metadata definition in the RM custom model
*/
private void removeCustomMetadata(QName propId)
{
rmAdminService.removeCustomPropertyDefinition(propId);
} }
} }

View File

@@ -301,6 +301,29 @@ public class CommonRMTestUtils implements RecordsManagementModel
return record; return record;
} }
/**
* Helper method to create a non-electronic record in a record folder.
*
* @param recordFolder record folder
* @param name name of the non-electronic record
* @param title title of the non-electronic record
* @return {@link NodeRef} non-electronic record node reference
*/
public NodeRef createNonElectronicRecord(NodeRef recordFolder, String name, String title)
{
Map<QName, Serializable> props = new HashMap<QName, Serializable>(1);
props.put(ContentModel.PROP_TITLE, title);
props.put(ContentModel.PROP_NAME, name);
// Create the document
NodeRef record = nodeService.createNode(recordFolder,
ContentModel.ASSOC_CONTAINS,
QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, name),
RecordsManagementModel.TYPE_NON_ELECTRONIC_DOCUMENT,
props).getChildRef();
return record;
}
/** /**
* Helper method to complete record. * Helper method to complete record.
*/ */