changes following review

This commit is contained in:
Sara Aspery
2017-06-26 12:41:02 +01:00
parent 5d02384f24
commit 7269b33c65
3 changed files with 68 additions and 54 deletions

View File

@@ -61,7 +61,7 @@ public class CompleteRecordTests extends BaseRMRestTest
{
private static final Boolean COMPLETE = true;
private static final Boolean INCOMPLETE = false;
private static final String parameters = "include=isCompleted";
private static final String PARAMETERS = "include=isCompleted";
/**
* Incomplete records with mandatory meta-data missing
@@ -106,7 +106,7 @@ public class CompleteRecordTests extends BaseRMRestTest
/**
* <pre>
* Given the repository is configured to check mandatory data before completing a record
* And an incomplete record with missing mandatory meta-data
* And an incomplete record with its mandatory meta-data missing
* When I complete the record
* Then I receive an error indicating that I can't complete the operation,
* because some of the mandatory meta-data of the record is missing
@@ -183,7 +183,7 @@ public class CompleteRecordTests extends BaseRMRestTest
{
// Get the recordsAPI
RecordsAPI recordsAPI = getRestAPIFactory().getRecordsAPI();
recordsAPI.completeRecord(nonRecordId, parameters);
recordsAPI.completeRecord(nonRecordId, PARAMETERS);
assertStatusCode(BAD_REQUEST);
}
@@ -277,7 +277,7 @@ public class CompleteRecordTests extends BaseRMRestTest
private void verifyRecordCompletionStatus(Record record, Boolean completionStatus)
{
RecordsAPI recordsAPI = getRestAPIFactory().getRecordsAPI();
Record recordModel = recordsAPI.getRecord(record.getId(), parameters);
Record recordModel = recordsAPI.getRecord(record.getId(), PARAMETERS);
assertEquals(recordModel.getIsCompleted(), completionStatus);
}
@@ -287,6 +287,6 @@ public class CompleteRecordTests extends BaseRMRestTest
private void completeRecord(Record record) throws Exception
{
RecordsAPI recordsAPI = getRestAPIFactory().getRecordsAPI();
recordsAPI.completeRecord(record.getId(), parameters);
recordsAPI.completeRecord(record.getId(), PARAMETERS);
}
}

View File

@@ -27,6 +27,9 @@
package org.alfresco.module.org_alfresco_module_rm.action.impl;
import java.util.HashMap;
import java.util.Map;
import org.alfresco.module.org_alfresco_module_rm.action.RMActionExecuterAbstractBase;
import org.alfresco.module.org_alfresco_module_rm.record.RecordService;
import org.alfresco.repo.action.executer.ActionExecuterAbstractBase;
@@ -42,6 +45,8 @@ import org.alfresco.util.ParameterCheck;
*/
public class DeclareRecordAction extends RMActionExecuterAbstractBase
{
private static final String MISSING_PROPERTIES = "missingProperties";
/** action name */
public static final String NAME = "declareRecord";
@@ -71,11 +76,25 @@ public class DeclareRecordAction extends RMActionExecuterAbstractBase
}
catch (IntegrityException e)
{
if (e.getMessage().contains("missing"))
Map<String, String> errorMap = getErrorMessageMap();
if (e.getMsgId().equals(errorMap.get(MISSING_PROPERTIES)))
{
action.setParameterValue(ActionExecuterAbstractBase.PARAM_RESULT, "missingProperties");
action.setParameterValue(ActionExecuterAbstractBase.PARAM_RESULT, MISSING_PROPERTIES);
}
}
}
/**
* TODO: needs to be properties file
* Temporary Helper method to get the map of complete record error message keys with associated message text
* @return errorMap
*/
private Map<String, String> getErrorMessageMap() {
Map<String, String> errorMap = new HashMap<>();
errorMap.put("missingProperties", "The record has missing mandatory properties.");
errorMap.put("alreadyCompleted", "The record is already completed.");
errorMap.put("unsuitableNode", "The node is not a record or the record does not exist or is frozen.");
return errorMap;
}
}

View File

@@ -1972,21 +1972,7 @@ public class RecordServiceImpl extends BaseBehaviourBean
@Override
public void complete(NodeRef nodeRef)
{
if (nodeService.exists(nodeRef) && isRecord(nodeRef) && !freezeService.isFrozen(nodeRef))
{
if (!isDeclared(nodeRef))
{
// 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);
}
List<String> missingProperties = new ArrayList<>(5);
// Aspect not already defined - check mandatory properties then add
if (!checkMandatoryPropertiesEnabled || mandatoryPropertiesSet(nodeRef, missingProperties))
{
validateForCompletion(nodeRef);
disablePropertyEditableCheck();
try
{
@@ -2010,7 +1996,29 @@ public class RecordServiceImpl extends BaseBehaviourBean
{
enablePropertyEditableCheck();
}
} else
}
/**
* 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) && isRecord(nodeRef) && !freezeService.isFrozen(nodeRef))
{
if (!isDeclared(nodeRef))
{
// 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);
}
List<String> missingProperties = new ArrayList<>(5);
// Aspect not already defined - check mandatory properties then add
if (checkMandatoryPropertiesEnabled && !mandatoryPropertiesSet(nodeRef, missingProperties))
{
LOGGER.debug(buildMissingPropertiesErrorString(missingProperties));
throw new IntegrityException("The record has missing mandatory properties.", null);
@@ -2025,10 +2033,9 @@ public class RecordServiceImpl extends BaseBehaviourBean
{
LOGGER.warn(I18NUtil.getMessage(MSG_UNDECLARED_ONLY_RECORDS, nodeRef.toString()));
}
throw new IntegrityException("The record does not exist or is frozen.", null);
throw new IntegrityException("The node is not a record or the record does not exist or is frozen.", null);
}
}
private String buildMissingPropertiesErrorString(List<String> missingProperties)
{
StringBuilder builder = new StringBuilder(255);
@@ -2086,20 +2093,6 @@ public class RecordServiceImpl extends BaseBehaviourBean
for (PropertyDefinition propDef : classDef.getProperties().values())
{
if (propDef.isMandatory() && nodeRefProps.get(propDef.getName()) == null)
{
logMissingProperty(propDef, missingProperties);
;
}
}
}
/**
* Log information about missing properties.
*
* @param propDef property definition
* @param missingProperties missing properties
*/
private void logMissingProperty(PropertyDefinition propDef, List<String> missingProperties)
{
if (LOGGER.isWarnEnabled())
{
@@ -2109,6 +2102,8 @@ public class RecordServiceImpl extends BaseBehaviourBean
}
missingProperties.add(propDef.getName().toString());
}
}
}
/**
* Helper method to get the custom aspect for a given nodeRef type