include_declare_record_refactoring_in_Rest

This commit is contained in:
Sara Aspery
2017-06-20 11:12:22 +01:00
parent 15b1bc41cd
commit 57b3460b58
6 changed files with 1669 additions and 1675 deletions

View File

@@ -388,8 +388,7 @@
<bean id="declareRecord" class="org.alfresco.module.org_alfresco_module_rm.action.impl.DeclareRecordAction" parent="rmAction"> <bean id="declareRecord" class="org.alfresco.module.org_alfresco_module_rm.action.impl.DeclareRecordAction" parent="rmAction">
<property name="publicAction" value="true"/> <property name="publicAction" value="true"/>
<property name="checkMandatoryPropertiesEnabled" value="${rm.completerecord.mandatorypropertiescheck.enabled}"/> <property name="recordService" ref="RecordService" />
<property name="transactionalResourceHelper" ref="rm.transactionalResourceHelper" />
</bean> </bean>
<!-- undeclare record --> <!-- undeclare record -->

View File

@@ -27,33 +27,13 @@
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.text.MessageFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
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.RecordService;
import org.alfresco.module.org_alfresco_module_rm.util.TransactionalResourceHelper;
import org.alfresco.repo.action.executer.ActionExecuterAbstractBase; import org.alfresco.repo.action.executer.ActionExecuterAbstractBase;
import org.alfresco.repo.security.authentication.AuthenticationUtil; import org.alfresco.repo.node.integrity.IntegrityException;
import org.alfresco.repo.security.authentication.AuthenticationUtil.RunAsWork;
import org.alfresco.service.cmr.action.Action; import org.alfresco.service.cmr.action.Action;
import org.alfresco.service.cmr.dictionary.AspectDefinition;
import org.alfresco.service.cmr.dictionary.PropertyDefinition;
import org.alfresco.service.cmr.dictionary.TypeDefinition;
import org.alfresco.service.cmr.repository.NodeRef; import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.cmr.security.OwnableService; import org.alfresco.util.ParameterCheck;
import org.alfresco.service.namespace.QName;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.extensions.surf.util.I18NUtil;
/** /**
* Declare record action * Declare record action
@@ -62,36 +42,24 @@ import org.springframework.extensions.surf.util.I18NUtil;
*/ */
public class DeclareRecordAction extends RMActionExecuterAbstractBase public class DeclareRecordAction extends RMActionExecuterAbstractBase
{ {
/** action name */ /**
* action name
*/
public static final String NAME = "declareRecord"; public static final String NAME = "declareRecord";
/** I18N */ /**
private static final String MSG_UNDECLARED_ONLY_RECORDS = "rm.action.undeclared-only-records"; * Record service
private static final String MSG_NO_DECLARE_MAND_PROP = "rm.action.no-declare-mand-prop"; */
private RecordService recordService;
/** Logger */
private static Log logger = LogFactory.getLog(DeclareRecordAction.class);
/** check mandatory properties */
private boolean checkMandatoryPropertiesEnabled = true;
/** transactional resource helper */
private TransactionalResourceHelper transactionalResourceHelper;
/** /**
* @param checkMandatoryPropertiesEnabled true if check mandatory properties is enabled, false otherwise * Sets the record service
*
* @param recordService record service
*/ */
public void setCheckMandatoryPropertiesEnabled(boolean checkMandatoryPropertiesEnabled) public void setRecordService(RecordService recordService)
{ {
this.checkMandatoryPropertiesEnabled = checkMandatoryPropertiesEnabled; this.recordService = recordService;
}
/**
* @param transactionalResourceHelper
*/
public void setTransactionalResourceHelper(TransactionalResourceHelper transactionalResourceHelper)
{
this.transactionalResourceHelper = transactionalResourceHelper;
} }
/** /**
@@ -100,167 +68,14 @@ public class DeclareRecordAction extends RMActionExecuterAbstractBase
@Override @Override
protected void executeImpl(final Action action, final NodeRef actionedUponNodeRef) protected void executeImpl(final Action action, final NodeRef actionedUponNodeRef)
{ {
if (getNodeService().exists(actionedUponNodeRef) && ParameterCheck.mandatory("actionedUponNodeRef", actionedUponNodeRef);
getRecordService().isRecord(actionedUponNodeRef) &&
!getFreezeService().isFrozen(actionedUponNodeRef))
{
if (!getRecordService().isDeclared(actionedUponNodeRef))
{
// 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(actionedUponNodeRef))
{
generateRecordIdentifier(getNodeService(), getIdentifierService(), actionedUponNodeRef);
}
List<String> missingProperties = new ArrayList<>(5);
// Aspect not already defined - check mandatory properties then add
if (!checkMandatoryPropertiesEnabled ||
mandatoryPropertiesSet(actionedUponNodeRef, missingProperties))
{
getRecordService().disablePropertyEditableCheck();
try try
{ {
// Add the declared aspect recordService.complete(actionedUponNodeRef);
Map<QName, Serializable> declaredProps = new HashMap<>(2); } catch (IntegrityException e)
declaredProps.put(PROP_DECLARED_AT, new Date());
declaredProps.put(PROP_DECLARED_BY, AuthenticationUtil.getRunAsUser());
this.getNodeService().addAspect(actionedUponNodeRef, ASPECT_DECLARED_RECORD, declaredProps);
AuthenticationUtil.runAsSystem(new RunAsWork<Void>()
{ {
@Override action.setParameterValue(ActionExecuterAbstractBase.PARAM_RESULT, e.getMessage());
public Void doWork()
{
// remove all owner related rights
getOwnableService().setOwner(actionedUponNodeRef, OwnableService.NO_OWNER);
return null;
}
});
}
finally
{
getRecordService().enablePropertyEditableCheck();
}
}
else
{
logger.debug(buildMissingPropertiesErrorString(missingProperties));
action.setParameterValue(ActionExecuterAbstractBase.PARAM_RESULT, "missingProperties");
}
}
}
else
{
if (logger.isWarnEnabled())
{
logger.warn(I18NUtil.getMessage(MSG_UNDECLARED_ONLY_RECORDS, actionedUponNodeRef.toString()));
}
}
} }
private String buildMissingPropertiesErrorString(List<String> missingProperties)
{
StringBuilder builder = new StringBuilder(255);
builder.append(I18NUtil.getMessage(MSG_NO_DECLARE_MAND_PROP));
builder.append(" ");
for (String missingProperty : missingProperties)
{
builder.append(missingProperty).append(", ");
}
return builder.toString();
}
/**
* Helper method to check whether all the mandatory properties of the node have been set
*
* @param nodeRef node reference
* @return boolean true if all mandatory properties are set, false otherwise
*/
private boolean mandatoryPropertiesSet(NodeRef nodeRef, List<String> missingProperties)
{
boolean result = true;
Map<QName, Serializable> nodeRefProps = this.getNodeService().getProperties(nodeRef);
QName nodeRefType = this.getNodeService().getType(nodeRef);
TypeDefinition typeDef = this.getDictionaryService().getType(nodeRefType);
for (PropertyDefinition propDef : typeDef.getProperties().values())
{
if (propDef.isMandatory() && nodeRefProps.get(propDef.getName()) == null)
{
logMissingProperty(propDef, missingProperties);
result = false;
break;
}
}
if (result)
{
Set<QName> aspects = this.getNodeService().getAspects(nodeRef);
for (QName aspect : aspects)
{
AspectDefinition aspectDef = this.getDictionaryService().getAspect(aspect);
for (PropertyDefinition propDef : aspectDef.getProperties().values())
{
if (propDef.isMandatory() && nodeRefProps.get(propDef.getName()) == null)
{
logMissingProperty(propDef, missingProperties);
result = false;
break;
}
}
}
}
// 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;
}
/**
* Log information about missing properties.
*
* @param propDef property definition
* @param missingProperties missing properties
*/
private void logMissingProperty(PropertyDefinition propDef, List<String> missingProperties)
{
if (logger.isWarnEnabled())
{
StringBuilder msg = new StringBuilder();
msg.append("Mandatory property missing: ").append(propDef.getName());
logger.warn(msg.toString());
}
missingProperties.add(propDef.getName().toString());
} }
} }

View File

@@ -57,7 +57,6 @@ public interface RecordService
* *
* @param recordMetadataAspect record metadata aspect qualified name * @param recordMetadataAspect record metadata aspect qualified name
* @param filePlanType file plan type * @param filePlanType file plan type
*
* @since 2.2 * @since 2.2
*/ */
void registerRecordMetadataAspect(QName recordMetadataAspect, QName filePlanType); void registerRecordMetadataAspect(QName recordMetadataAspect, QName filePlanType);
@@ -73,7 +72,6 @@ public interface RecordService
* Disables the property editable check for a given node in this transaction only. * Disables the property editable check for a given node in this transaction only.
* *
* @param nodeRef node reference * @param nodeRef node reference
*
* @since 2.2 * @since 2.2
*/ */
void disablePropertyEditableCheck(NodeRef nodeRef); void disablePropertyEditableCheck(NodeRef nodeRef);
@@ -87,7 +85,6 @@ public interface RecordService
* Gets a list of all the record meta-data aspects * Gets a list of all the record meta-data aspects
* *
* @return {@link Set}<{@link QName}> list of record meta-data aspects * @return {@link Set}<{@link QName}> list of record meta-data aspects
*
* @deprecated since 2.2, file plan component required to provide context * @deprecated since 2.2, file plan component required to provide context
*/ */
@Deprecated @Deprecated
@@ -99,7 +96,6 @@ public interface RecordService
* *
* @param aspect aspect {@link QName} * @param aspect aspect {@link QName}
* @return boolean true if the aspect is a registered record meta-data aspect, false otherwise * @return boolean true if the aspect is a registered record meta-data aspect, false otherwise
*
* @since 2.3 * @since 2.3
*/ */
boolean isRecordMetadataAspect(QName aspect); boolean isRecordMetadataAspect(QName aspect);
@@ -111,7 +107,6 @@ public interface RecordService
* @param property property {@link QName} * @param property property {@link QName}
* @return boolean true if the property is declared on a registered record meta-data aspect, * @return boolean true if the property is declared on a registered record meta-data aspect,
* false otherwise * false otherwise
*
* @since 2.3 * @since 2.3
*/ */
boolean isRecordMetadataProperty(QName property); boolean isRecordMetadataProperty(QName property);
@@ -125,7 +120,6 @@ public interface RecordService
* *
* @param nodeRef node reference to file plan component providing context * @param nodeRef node reference to file plan component providing context
* @return {@link Set}<{@link QName}> list of record meta-data aspects * @return {@link Set}<{@link QName}> list of record meta-data aspects
*
* @since 2.2 * @since 2.2
*/ */
Set<QName> getRecordMetadataAspects(NodeRef nodeRef); Set<QName> getRecordMetadataAspects(NodeRef nodeRef);
@@ -138,7 +132,6 @@ public interface RecordService
* *
* @param filePlanType file plan type * @param filePlanType file plan type
* @return{@link Set}<{@link QName}> list of record meta-data aspects * @return{@link Set}<{@link QName}> list of record meta-data aspects
*
* @since 2.2 * @since 2.2
*/ */
Set<QName> getRecordMetadataAspects(QName filePlanType); Set<QName> getRecordMetadataAspects(QName filePlanType);
@@ -201,7 +194,7 @@ public interface RecordService
/** /**
* Indicates whether the record is filed or not * Indicates whether the record is filed or not
* *
* @param nodeRef record * @param record Record node reference
* @return boolean true if filed, false otherwise * @return boolean true if filed, false otherwise
*/ */
boolean isFiled(NodeRef record); boolean isFiled(NodeRef record);
@@ -209,25 +202,10 @@ public interface RecordService
/** /**
* 'File' a new document that arrived in the file plan structure. * 'File' a new document that arrived in the file plan structure.
* *
* @param nodeRef record * @param record Record node reference
*/ */
void file(NodeRef record); void file(NodeRef record);
/**
* Indicates whether all the mandatory metadata for the record is populated or not
*
* @param record record for which to check if all mandatory metadata is populated
* @return boolean true if all mandatory metadata is populated, false otherwise
*/
boolean isMandatoryPropertiesPopulated(NodeRef record);
/**
* Completes a record.
*
* @param record record to be completed
*/
void complete(NodeRef record);
/** /**
* Rejects a record with the provided reason * Rejects a record with the provided reason
* *
@@ -289,8 +267,14 @@ public interface RecordService
* *
* @param record the record to unlink * @param record the record to unlink
* @param recordFolder the record folder to unlink it from * @param recordFolder the record folder to unlink it from
*
* @since 2.3 * @since 2.3
*/ */
void unlink(NodeRef record, NodeRef recordFolder); void unlink(NodeRef record, NodeRef recordFolder);
/**
* Completes a record
*
* @param nodeRef Record node reference
*/
void complete(NodeRef nodeRef);
} }

View File

@@ -34,6 +34,7 @@ import static org.alfresco.repo.policy.Behaviour.NotificationFrequency.TRANSACTI
import static org.alfresco.repo.policy.annotation.BehaviourKind.ASSOCIATION; import static org.alfresco.repo.policy.annotation.BehaviourKind.ASSOCIATION;
import java.io.Serializable; import java.io.Serializable;
import java.text.MessageFormat;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.Calendar; import java.util.Calendar;
@@ -62,6 +63,7 @@ import org.alfresco.module.org_alfresco_module_rm.disposition.DispositionSchedul
import org.alfresco.module.org_alfresco_module_rm.disposition.DispositionService; import org.alfresco.module.org_alfresco_module_rm.disposition.DispositionService;
import org.alfresco.module.org_alfresco_module_rm.dod5015.DOD5015Model; import org.alfresco.module.org_alfresco_module_rm.dod5015.DOD5015Model;
import org.alfresco.module.org_alfresco_module_rm.fileplan.FilePlanService; import org.alfresco.module.org_alfresco_module_rm.fileplan.FilePlanService;
import org.alfresco.module.org_alfresco_module_rm.freeze.FreezeService;
import org.alfresco.module.org_alfresco_module_rm.identifier.IdentifierService; import org.alfresco.module.org_alfresco_module_rm.identifier.IdentifierService;
import org.alfresco.module.org_alfresco_module_rm.model.BaseBehaviourBean; import org.alfresco.module.org_alfresco_module_rm.model.BaseBehaviourBean;
import org.alfresco.module.org_alfresco_module_rm.model.RecordsManagementCustomModel; import org.alfresco.module.org_alfresco_module_rm.model.RecordsManagementCustomModel;
@@ -82,9 +84,9 @@ import org.alfresco.repo.content.ContentServicePolicies;
import org.alfresco.repo.node.NodeServicePolicies; import org.alfresco.repo.node.NodeServicePolicies;
import org.alfresco.repo.node.integrity.IncompleteNodeTagger; import org.alfresco.repo.node.integrity.IncompleteNodeTagger;
import org.alfresco.repo.node.integrity.IntegrityException; import org.alfresco.repo.node.integrity.IntegrityException;
import org.alfresco.repo.policy.Behaviour.NotificationFrequency;
import org.alfresco.repo.policy.ClassPolicyDelegate; import org.alfresco.repo.policy.ClassPolicyDelegate;
import org.alfresco.repo.policy.PolicyComponent; import org.alfresco.repo.policy.PolicyComponent;
import org.alfresco.repo.policy.Behaviour.NotificationFrequency;
import org.alfresco.repo.policy.annotation.Behaviour; import org.alfresco.repo.policy.annotation.Behaviour;
import org.alfresco.repo.policy.annotation.BehaviourBean; import org.alfresco.repo.policy.annotation.BehaviourBean;
import org.alfresco.repo.policy.annotation.BehaviourKind; import org.alfresco.repo.policy.annotation.BehaviourKind;
@@ -143,33 +145,54 @@ public class RecordServiceImpl extends BaseBehaviourBean
NodeServicePolicies.OnUpdatePropertiesPolicy, NodeServicePolicies.OnUpdatePropertiesPolicy,
ContentServicePolicies.OnContentUpdatePolicy ContentServicePolicies.OnContentUpdatePolicy
{ {
/** Logger */ /**
* Logger
*/
private static final Logger LOGGER = LoggerFactory.getLogger(RecordServiceImpl.class); private static final Logger LOGGER = LoggerFactory.getLogger(RecordServiceImpl.class);
/** Sync Model URI */ /**
* Sync Model URI
*/
private static final String SYNC_MODEL_1_0_URI = "http://www.alfresco.org/model/sync/1.0"; private static final String SYNC_MODEL_1_0_URI = "http://www.alfresco.org/model/sync/1.0";
/** Synced aspect */ /**
* Synced aspect
*/
private static final QName ASPECT_SYNCED = QName.createQName(SYNC_MODEL_1_0_URI, "synced"); private static final QName ASPECT_SYNCED = QName.createQName(SYNC_MODEL_1_0_URI, "synced");
/** transation data key */ /**
* transation data key
*/
private static final String KEY_IGNORE_ON_UPDATE = "ignoreOnUpdate"; private static final String KEY_IGNORE_ON_UPDATE = "ignoreOnUpdate";
public static final String KEY_NEW_RECORDS = "newRecords"; public static final String KEY_NEW_RECORDS = "newRecords";
/** I18N */ /**
* I18N
*/
private static final String MSG_NODE_HAS_ASPECT = "rm.service.node-has-aspect"; private static final String MSG_NODE_HAS_ASPECT = "rm.service.node-has-aspect";
private static final String FINAL_VERSION = "rm.service.final-version"; private static final String FINAL_VERSION = "rm.service.final-version";
private static final String FINAL_DESCRIPTION = "rm.service.final-version-description"; private static final String FINAL_DESCRIPTION = "rm.service.final-version-description";
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";
/** Always edit property array */ /**
* Always edit property array
*/
private static final QName[] ALWAYS_EDIT_PROPERTIES = new QName[] private static final QName[] ALWAYS_EDIT_PROPERTIES = new QName[]
{ {
ContentModel.PROP_LAST_THUMBNAIL_MODIFICATION_DATA ContentModel.PROP_LAST_THUMBNAIL_MODIFICATION_DATA
}; };
/** always edit model URI's */ /**
* always edit model URI's
*/
private List<String> alwaysEditURIs; private List<String> alwaysEditURIs;
/**
* check mandatory properties
*/
private boolean checkMandatoryPropertiesEnabled = true;
/** /**
* @param alwaysEditURIs the alwaysEditURIs to set * @param alwaysEditURIs the alwaysEditURIs to set
*/ */
@@ -186,7 +209,9 @@ public class RecordServiceImpl extends BaseBehaviourBean
return this.alwaysEditURIs; return this.alwaysEditURIs;
} }
/** record model URI's */ /**
* record model URI's
*/
public static final List<String> RECORD_MODEL_URIS = Collections.unmodifiableList( public static final List<String> RECORD_MODEL_URIS = Collections.unmodifiableList(
Arrays.asList( Arrays.asList(
RM_URI, RM_URI,
@@ -196,7 +221,9 @@ public class RecordServiceImpl extends BaseBehaviourBean
DOD5015Model.DOD_URI DOD5015Model.DOD_URI
)); ));
/** non-record model URI's */ /**
* non-record model URI's
*/
private static final String[] NON_RECORD_MODEL_URIS = new String[] private static final String[] NON_RECORD_MODEL_URIS = new String[]
{ {
NamespaceService.AUDIO_MODEL_1_0_URI, NamespaceService.AUDIO_MODEL_1_0_URI,
@@ -208,64 +235,114 @@ public class RecordServiceImpl extends BaseBehaviourBean
NamespaceService.REPOSITORY_VIEW_1_0_URI NamespaceService.REPOSITORY_VIEW_1_0_URI
}; };
/** Indentity service */ /**
* Indentity service
*/
private IdentifierService identifierService; private IdentifierService identifierService;
/** Extended permission service */ /**
* Extended permission service
*/
private ExtendedPermissionService extendedPermissionService; private ExtendedPermissionService extendedPermissionService;
/** Extended security service */ /**
* Extended security service
*/
private ExtendedSecurityService extendedSecurityService; private ExtendedSecurityService extendedSecurityService;
/** File plan service */ /**
* File plan service
*/
private FilePlanService filePlanService; private FilePlanService filePlanService;
/** Records management notification helper */ /**
* Records management notification helper
*/
private RecordsManagementNotificationHelper notificationHelper; private RecordsManagementNotificationHelper notificationHelper;
/** Policy component */ /**
* Policy component
*/
private PolicyComponent policyComponent; private PolicyComponent policyComponent;
/** Ownable service */ /**
* Ownable service
*/
private OwnableService ownableService; private OwnableService ownableService;
/** Capability service */ /**
* Capability service
*/
private CapabilityService capabilityService; private CapabilityService capabilityService;
/** Rule service */ /**
* Rule service
*/
private RuleService ruleService; private RuleService ruleService;
/** File folder service */ /**
* File folder service
*/
private FileFolderService fileFolderService; private FileFolderService fileFolderService;
/** Record folder service */ /**
* Record folder service
*/
private RecordFolderService recordFolderService; private RecordFolderService recordFolderService;
/** File plan role service */ /**
* File plan role service
*/
private FilePlanRoleService filePlanRoleService; private FilePlanRoleService filePlanRoleService;
/** Permission service */ /**
* Permission service
*/
private PermissionService permissionService; private PermissionService permissionService;
/** Version service */ /**
* Version service
*/
private VersionService versionService; private VersionService versionService;
/** Relationship service */ /**
* Relationship service
*/
private RelationshipService relationshipService; private RelationshipService relationshipService;
/** Disposition service */ /**
* Disposition service
*/
private DispositionService dispositionService; private DispositionService dispositionService;
/** records management container type */ /**
* records management container type
*/
private RecordsManagementContainerType recordsManagementContainerType; private RecordsManagementContainerType recordsManagementContainerType;
/** recordable version service */ /**
* recordable version service
*/
private RecordableVersionService recordableVersionService; private RecordableVersionService recordableVersionService;
/** list of available record meta-data aspects and the file plan types the are applicable to */ /**
* list of available record meta-data aspects and the file plan types the are applicable to
*/
private Map<QName, Set<QName>> recordMetaDataAspects; private Map<QName, Set<QName>> recordMetaDataAspects;
/** policies */ /**
* Freeze service
*/
private FreezeService freezeService;
/**
* Namespace service
*/
private NamespaceService namespaceService;
/**
* policies
*/
private ClassPolicyDelegate<BeforeFileRecord> beforeFileRecord; private ClassPolicyDelegate<BeforeFileRecord> beforeFileRecord;
private ClassPolicyDelegate<OnFileRecord> onFileRecord; private ClassPolicyDelegate<OnFileRecord> onFileRecord;
private ClassPolicyDelegate<BeforeRecordDeclaration> beforeRecordDeclarationDelegate; private ClassPolicyDelegate<BeforeRecordDeclaration> beforeRecordDeclarationDelegate;
@@ -424,6 +501,30 @@ public class RecordServiceImpl extends BaseBehaviourBean
this.incompleteNodeTagger = incompleteNodeTagger; this.incompleteNodeTagger = incompleteNodeTagger;
} }
/**
* @param freezeService freeze service
*/
public void setFreezeService(FreezeService freezeService)
{
this.freezeService = freezeService;
}
/**
* @param namespaceService namespace service
*/
public void setNamespaceService(NamespaceService namespaceService)
{
this.namespaceService = namespaceService;
}
/**
* @param checkMandatoryPropertiesEnabled true if check mandatory properties is enabled, false otherwise
*/
public void setCheckMandatoryPropertiesEnabled(boolean checkMandatoryPropertiesEnabled)
{
this.checkMandatoryPropertiesEnabled = checkMandatoryPropertiesEnabled;
}
/** /**
* Init method * Init method
*/ */
@@ -521,8 +622,7 @@ public class RecordServiceImpl extends BaseBehaviourBean
{ {
Set<NodeRef> newRecords = transactionalResourceHelper.getSet(KEY_NEW_RECORDS); Set<NodeRef> newRecords = transactionalResourceHelper.getSet(KEY_NEW_RECORDS);
newRecords.add(nodeRef); newRecords.add(nodeRef);
} } else
else
{ {
// if we are linking a record // if we are linking a record
NodeRef parentNodeRef = childAssocRef.getParentRef(); NodeRef parentNodeRef = childAssocRef.getParentRef();
@@ -538,13 +638,11 @@ public class RecordServiceImpl extends BaseBehaviourBean
// recalculate disposition schedule for the record when linking it // recalculate disposition schedule for the record when linking it
dispositionService.recalculateNextDispositionStep(nodeRef); dispositionService.recalculateNextDispositionStep(nodeRef);
} }
} } catch (RecordLinkRuntimeException e)
catch (RecordLinkRuntimeException e)
{ {
// rethrow exception // rethrow exception
throw e; throw e;
} } catch (AlfrescoRuntimeException e)
catch (AlfrescoRuntimeException e)
{ {
// do nothing but log error // do nothing but log error
LOGGER.warn("Unable to file pending record.", e); LOGGER.warn("Unable to file pending record.", e);
@@ -600,7 +698,7 @@ public class RecordServiceImpl extends BaseBehaviourBean
( (
name = "onUpdateProperties", name = "onUpdateProperties",
kind = BehaviourKind.CLASS, kind = BehaviourKind.CLASS,
type= "rma:record" type = "rma:record"
) )
public void onUpdateProperties(final NodeRef nodeRef, final Map<QName, Serializable> before, final Map<QName, Serializable> after) public void onUpdateProperties(final NodeRef nodeRef, final Map<QName, Serializable> before, final Map<QName, Serializable> after)
{ {
@@ -626,20 +724,18 @@ public class RecordServiceImpl extends BaseBehaviourBean
// deal with date values, remove the seconds and milliseconds for the // deal with date values, remove the seconds and milliseconds for the
// comparison as they are removed from the submitted for data // comparison as they are removed from the submitted for data
Calendar beforeCal = Calendar.getInstance(); Calendar beforeCal = Calendar.getInstance();
beforeCal.setTime((Date)beforeValue); beforeCal.setTime((Date) beforeValue);
Calendar afterCal = Calendar.getInstance(); Calendar afterCal = Calendar.getInstance();
afterCal.setTime((Date)afterValue); afterCal.setTime((Date) afterValue);
beforeCal.set(Calendar.SECOND, 0); beforeCal.set(Calendar.SECOND, 0);
beforeCal.set(Calendar.MILLISECOND, 0); beforeCal.set(Calendar.MILLISECOND, 0);
afterCal.set(Calendar.SECOND, 0); afterCal.set(Calendar.SECOND, 0);
afterCal.set(Calendar.MILLISECOND, 0); afterCal.set(Calendar.MILLISECOND, 0);
propertyUnchanged = (beforeCal.compareTo(afterCal) == 0); propertyUnchanged = (beforeCal.compareTo(afterCal) == 0);
} } else if ((afterValue instanceof Boolean) && (beforeValue == null) && (afterValue.equals(Boolean.FALSE)))
else if ((afterValue instanceof Boolean) && (beforeValue == null) && (afterValue.equals(Boolean.FALSE)))
{ {
propertyUnchanged = true; propertyUnchanged = true;
} } else
else
{ {
// otherwise // otherwise
propertyUnchanged = EqualsHelper.nullSafeEquals(beforeValue, afterValue); propertyUnchanged = EqualsHelper.nullSafeEquals(beforeValue, afterValue);
@@ -663,7 +759,6 @@ public class RecordServiceImpl extends BaseBehaviourBean
* Get map containing record metadata aspects. * Get map containing record metadata aspects.
* *
* @return {@link Map}<{@link QName}, {@link Set}<{@link QName}>> map containing record metadata aspects * @return {@link Map}<{@link QName}, {@link Set}<{@link QName}>> map containing record metadata aspects
*
* @since 2.2 * @since 2.2
*/ */
protected Map<QName, Set<QName>> getRecordMetadataAspectsMap() protected Map<QName, Set<QName>> getRecordMetadataAspectsMap()
@@ -721,8 +816,7 @@ public class RecordServiceImpl extends BaseBehaviourBean
{ {
// get the current set of file plan types for this aspect // get the current set of file plan types for this aspect
filePlanTypes = getRecordMetadataAspectsMap().get(recordMetadataAspect); filePlanTypes = getRecordMetadataAspectsMap().get(recordMetadataAspect);
} } else
else
{ {
// create a new set for the file plan type // create a new set for the file plan type
filePlanTypes = new HashSet<QName>(1); filePlanTypes = new HashSet<QName>(1);
@@ -867,8 +961,7 @@ public class RecordServiceImpl extends BaseBehaviourBean
{ {
// move the document into the file plan // move the document into the file plan
nodeService.moveNode(nodeRef, newRecordContainer, ContentModel.ASSOC_CONTAINS, parentAssoc.getQName()); nodeService.moveNode(nodeRef, newRecordContainer, ContentModel.ASSOC_CONTAINS, parentAssoc.getQName());
} } finally
finally
{ {
behaviourFilter.enableBehaviour(); behaviourFilter.enableBehaviour();
} }
@@ -907,14 +1000,12 @@ public class RecordServiceImpl extends BaseBehaviourBean
// set the extended security // set the extended security
extendedSecurityService.set(nodeRef, readersAndWriters); extendedSecurityService.set(nodeRef, readersAndWriters);
} } finally
finally
{ {
ruleService.enableRules(); ruleService.enableRules();
} }
} }
} } finally
finally
{ {
ruleService.enableRuleType("outbound"); ruleService.enableRuleType("outbound");
} }
@@ -955,8 +1046,7 @@ public class RecordServiceImpl extends BaseBehaviourBean
LOGGER.debug(msg); LOGGER.debug(msg);
throw new RecordCreationException(msg); throw new RecordCreationException(msg);
} }
} } else
else
{ {
// verify that the provided file plan is actually a file plan // verify that the provided file plan is actually a file plan
if (!filePlanService.isFilePlan(filePlan)) if (!filePlanService.isFilePlan(filePlan))
@@ -1072,8 +1162,7 @@ public class RecordServiceImpl extends BaseBehaviourBean
// create a copy of the original state and add it to the unfiled record container // create a copy of the original state and add it to the unfiled record container
FileInfo recordInfo = fileFolderService.copy(nodeRef, unfiledRecordFolder, null); FileInfo recordInfo = fileFolderService.copy(nodeRef, unfiledRecordFolder, null);
record = recordInfo.getNodeRef(); record = recordInfo.getNodeRef();
} } finally
finally
{ {
recordsManagementContainerType.enable(); recordsManagementContainerType.enable();
} }
@@ -1084,8 +1173,7 @@ public class RecordServiceImpl extends BaseBehaviourBean
try try
{ {
nodeService.removeAspect(record, ContentModel.ASPECT_VERSIONABLE); nodeService.removeAspect(record, ContentModel.ASPECT_VERSIONABLE);
} } finally
finally
{ {
behaviourFilter.enableBehaviour(ContentModel.ASPECT_VERSIONABLE); behaviourFilter.enableBehaviour(ContentModel.ASPECT_VERSIONABLE);
} }
@@ -1108,16 +1196,14 @@ public class RecordServiceImpl extends BaseBehaviourBean
if (originalAssocs == null) if (originalAssocs == null)
{ {
nodeService.removeAspect(record, ContentModel.ASPECT_COPIEDFROM); nodeService.removeAspect(record, ContentModel.ASPECT_COPIEDFROM);
} } else
else
{ {
for (AssociationRef originalAssoc : originalAssocs) for (AssociationRef originalAssoc : originalAssocs)
{ {
nodeService.createAssociation(record, originalAssoc.getTargetRef(), ContentModel.ASSOC_ORIGINAL); nodeService.createAssociation(record, originalAssoc.getTargetRef(), ContentModel.ASSOC_ORIGINAL);
} }
} }
} } catch (FileNotFoundException e)
catch (FileNotFoundException e)
{ {
throw new AlfrescoRuntimeException("Can't create recorded version, because copy fails.", e); throw new AlfrescoRuntimeException("Can't create recorded version, because copy fails.", e);
} }
@@ -1188,8 +1274,7 @@ public class RecordServiceImpl extends BaseBehaviourBean
if (type == null) if (type == null)
{ {
type = ContentModel.TYPE_CONTENT; type = ContentModel.TYPE_CONTENT;
} } else if (!dictionaryService.isSubClass(type, ContentModel.TYPE_CONTENT))
else if (!dictionaryService.isSubClass(type, ContentModel.TYPE_CONTENT))
{ {
throw new AlfrescoRuntimeException("Record can only be created from a sub-type of cm:content."); throw new AlfrescoRuntimeException("Record can only be created from a sub-type of cm:content.");
} }
@@ -1234,8 +1319,7 @@ public class RecordServiceImpl extends BaseBehaviourBean
} }
}); });
} } finally
finally
{ {
enablePropertyEditableCheck(); enablePropertyEditableCheck();
} }
@@ -1273,8 +1357,7 @@ public class RecordServiceImpl extends BaseBehaviourBean
return null; return null;
} }
}); });
} } finally
finally
{ {
ruleService.enableRules(); ruleService.enableRules();
enablePropertyEditableCheck(); enablePropertyEditableCheck();
@@ -1308,7 +1391,7 @@ public class RecordServiceImpl extends BaseBehaviourBean
/** /**
* Helper method to 'file' a new document that arrived in the file plan structure. * Helper method to 'file' a new document that arrived in the file plan structure.
* * <p>
* TODO atm we only 'file' content as a record .. may need to consider other types if we * TODO atm we only 'file' content as a record .. may need to consider other types if we
* are to support the notion of composite records. * are to support the notion of composite records.
* *
@@ -1347,94 +1430,6 @@ public class RecordServiceImpl extends BaseBehaviourBean
} }
} }
/**
* Helper method to 'complete' a record.
*
* @param record node reference to record
*/
public void complete(NodeRef record)
{
ParameterCheck.mandatory("item", record);
// TODO get this from config
boolean checkMandatoryPropertiesEnabled = true;
if (!checkMandatoryPropertiesEnabled || (isMandatoryPropertiesPopulated(record)))
{
disablePropertyEditableCheck();
// Add the declared aspect
Map<QName, Serializable> declaredProps = new HashMap<>(2);
declaredProps.put(RecordsManagementModel.PROP_DECLARED_AT, new Date());
declaredProps.put(RecordsManagementModel.PROP_DECLARED_BY, AuthenticationUtil.getRunAsUser());
nodeService.addAspect(record, RecordsManagementModel.ASPECT_DECLARED_RECORD, declaredProps);
enablePropertyEditableCheck();
}
}
/**
* Helper method to determine whether a record's mandatory properties are set.
*
* @param nodeRef node reference to record
* @return boolean true if all mandatory metadata properties are set, false otherwise
*/
public boolean isMandatoryPropertiesPopulated(NodeRef nodeRef)
{
boolean result = true;
// check for missing mandatory metadata from type definitions
Map<QName, Serializable> nodeRefProps = nodeService.getProperties(nodeRef);
QName nodeRefType = nodeService.getType(nodeRef);
TypeDefinition typeDef = dictionaryService.getType(nodeRefType);
for (PropertyDefinition propDef : typeDef.getProperties().values())
{
if (propDef.isMandatory() && nodeRefProps.get(propDef.getName()) == null)
{
result = false;
break;
}
}
// check for missing mandatory metadata from aspect definitions
if (result)
{
// TODO change to aspects = getAspects(nodeRef) ?
Set<QName> aspects = nodeService.getAspects(nodeRef);
for (QName aspect : aspects)
{
AspectDefinition aspectDef = dictionaryService.getAspect(aspect);
for (PropertyDefinition propDef : aspectDef.getProperties().values())
{
if (propDef.isMandatory() && nodeRefProps.get(propDef.getName()) == null)
{
result = false;
break;
}
}
}
}
// check for missing mandatory metadata from custom aspect definitions
if (result)
{
Collection<QName> aspects = dictionaryService.getAspects(RM_CUSTOM_MODEL);
for (QName aspect : aspects)
{
AspectDefinition aspectDef = dictionaryService.getAspect(aspect);
for (PropertyDefinition propDef : aspectDef.getProperties().values())
{
if (propDef.isMandatory() && nodeRefProps.get(propDef.getName()) == null)
{
result = false;
break;
}
}
}
}
return result;
}
/** /**
* @see org.alfresco.module.org_alfresco_module_rm.record.RecordService#rejectRecord(org.alfresco.service.cmr.repository.NodeRef, java.lang.String) * @see org.alfresco.module.org_alfresco_module_rm.record.RecordService#rejectRecord(org.alfresco.service.cmr.repository.NodeRef, java.lang.String)
*/ */
@@ -1469,10 +1464,10 @@ public class RecordServiceImpl extends BaseBehaviourBean
// get record property values // get record property values
final Map<QName, Serializable> properties = nodeService.getProperties(nodeRef); final Map<QName, Serializable> properties = nodeService.getProperties(nodeRef);
final String recordId = (String)properties.get(PROP_IDENTIFIER); final String recordId = (String) properties.get(PROP_IDENTIFIER);
final String documentOwner = (String)properties.get(PROP_RECORD_ORIGINATING_USER_ID); final String documentOwner = (String) properties.get(PROP_RECORD_ORIGINATING_USER_ID);
final String originalName = (String)properties.get(PROP_ORIGIONAL_NAME); final String originalName = (String) properties.get(PROP_ORIGIONAL_NAME);
final NodeRef originatingLocation = (NodeRef)properties.get(PROP_RECORD_ORIGINATING_LOCATION); final NodeRef originatingLocation = (NodeRef) properties.get(PROP_RECORD_ORIGINATING_LOCATION);
// we can only reject if the originating location is present // we can only reject if the originating location is present
if (originatingLocation != null) if (originatingLocation != null)
@@ -1501,7 +1496,7 @@ public class RecordServiceImpl extends BaseBehaviourBean
{ {
fileFolderService.rename(nodeRef, originalName); fileFolderService.rename(nodeRef, originalName);
String name = (String)nodeService.getProperty(nodeRef, ContentModel.PROP_NAME); String name = (String) nodeService.getProperty(nodeRef, ContentModel.PROP_NAME);
LOGGER.debug("Rename {} to {}", name, originalName); LOGGER.debug("Rename {} to {}", name, originalName);
} }
@@ -1528,8 +1523,7 @@ public class RecordServiceImpl extends BaseBehaviourBean
// send an email to the record creator // send an email to the record creator
notificationHelper.recordRejectedEmailNotification(nodeRef, recordId, documentOwner); notificationHelper.recordRejectedEmailNotification(nodeRef, recordId, documentOwner);
} }
} } finally
finally
{ {
ruleService.enableRules(); ruleService.enableRules();
} }
@@ -1630,8 +1624,7 @@ public class RecordServiceImpl extends BaseBehaviourBean
if (result) if (result)
{ {
LOGGER.debug(" ... property marked as always editable."); LOGGER.debug(" ... property marked as always editable.");
} } else
else
{ {
boolean allowRecordEdit = false; boolean allowRecordEdit = false;
boolean allowNonRecordEdit = false; boolean allowNonRecordEdit = false;
@@ -1657,29 +1650,25 @@ public class RecordServiceImpl extends BaseBehaviourBean
{ {
LOGGER.debug(" ... so all properties can be edited."); LOGGER.debug(" ... so all properties can be edited.");
result = true; result = true;
} } else if (allowNonRecordEdit && !allowRecordEdit)
else if (allowNonRecordEdit && !allowRecordEdit)
{ {
// can only edit non record properties // can only edit non record properties
if (!isRecordMetadata(filePlan, property)) if (!isRecordMetadata(filePlan, property))
{ {
LOGGER.debug(" ... property is not considered record metadata so editable."); LOGGER.debug(" ... property is not considered record metadata so editable.");
result = true; result = true;
} } else
else
{ {
LOGGER.debug(" ... property is considered record metadata so not editable."); LOGGER.debug(" ... property is considered record metadata so not editable.");
} }
} } else if (!allowNonRecordEdit && allowRecordEdit)
else if (!allowNonRecordEdit && allowRecordEdit)
{ {
// can only edit record properties // can only edit record properties
if (isRecordMetadata(filePlan, property)) if (isRecordMetadata(filePlan, property))
{ {
LOGGER.debug(" ... property is considered record metadata so editable."); LOGGER.debug(" ... property is considered record metadata so editable.");
result = true; result = true;
} } else
else
{ {
LOGGER.debug(" ... property is not considered record metadata so not editable."); LOGGER.debug(" ... property is not considered record metadata so not editable.");
} }
@@ -1712,8 +1701,7 @@ public class RecordServiceImpl extends BaseBehaviourBean
if (parent != null && TYPE_NON_ELECTRONIC_DOCUMENT.equals(parent.getName())) if (parent != null && TYPE_NON_ELECTRONIC_DOCUMENT.equals(parent.getName()))
{ {
result = false; result = false;
} } else
else
{ {
// check the URI's // check the URI's
result = RECORD_MODEL_URIS.contains(property.getNamespaceURI()); result = RECORD_MODEL_URIS.contains(property.getNamespaceURI());
@@ -1808,8 +1796,7 @@ public class RecordServiceImpl extends BaseBehaviourBean
if (!nodeService.hasAspect(nodeRef, typeQName)) if (!nodeService.hasAspect(nodeRef, typeQName))
{ {
nodeService.addAspect(nodeRef, typeQName, null); nodeService.addAspect(nodeRef, typeQName, null);
} } else
else
{ {
LOGGER.info(I18NUtil.getMessage(MSG_NODE_HAS_ASPECT, nodeRef.toString(), typeQName.toString())); LOGGER.info(I18NUtil.getMessage(MSG_NODE_HAS_ASPECT, nodeRef.toString(), typeQName.toString()));
} }
@@ -1825,7 +1812,7 @@ public class RecordServiceImpl extends BaseBehaviourBean
ParameterCheck.mandatory("recordFolder", recordFolder); ParameterCheck.mandatory("recordFolder", recordFolder);
// ensure we are linking a record to a record folder // ensure we are linking a record to a record folder
if(isRecord(record) && isRecordFolder(recordFolder)) if (isRecord(record) && isRecordFolder(recordFolder))
{ {
// ensure that we are not linking a record to an existing location // ensure that we are not linking a record to an existing location
List<ChildAssociationRef> parents = nodeService.getParentAssocs(record); List<ChildAssociationRef> parents = nodeService.getParentAssocs(record);
@@ -1853,8 +1840,7 @@ public class RecordServiceImpl extends BaseBehaviourBean
// recalculate disposition schedule for the record when linking it // recalculate disposition schedule for the record when linking it
dispositionService.recalculateNextDispositionStep(record); dispositionService.recalculateNextDispositionStep(record);
} } else
else
{ {
// can only link a record to a record folder // can only link a record to a record folder
throw new RecordLinkRuntimeException("Can only link a record to a record folder."); throw new RecordLinkRuntimeException("Can only link a record to a record folder.");
@@ -1862,7 +1848,6 @@ public class RecordServiceImpl extends BaseBehaviourBean
} }
/** /**
*
* @param record * @param record
* @param recordFolder * @param recordFolder
*/ */
@@ -1898,7 +1883,7 @@ public class RecordServiceImpl extends BaseBehaviourBean
ParameterCheck.mandatory("recordFolder", recordFolder); ParameterCheck.mandatory("recordFolder", recordFolder);
// ensure we are unlinking a record from a record folder // ensure we are unlinking a record from a record folder
if(isRecord(record) && isRecordFolder(recordFolder)) if (isRecord(record) && isRecordFolder(recordFolder))
{ {
// check that we are not trying to unlink the primary parent // check that we are not trying to unlink the primary parent
NodeRef primaryParent = nodeService.getPrimaryParent(record).getParentRef(); NodeRef primaryParent = nodeService.getPrimaryParent(record).getParentRef();
@@ -1912,8 +1897,7 @@ public class RecordServiceImpl extends BaseBehaviourBean
// recalculate disposition schedule for record after unlinking it // recalculate disposition schedule for record after unlinking it
dispositionService.recalculateNextDispositionStep(record); dispositionService.recalculateNextDispositionStep(record);
} } else
else
{ {
// can only unlink a record from a record folder // can only unlink a record from a record folder
throw new RecordLinkRuntimeException("Can only unlink a record from a record folder."); throw new RecordLinkRuntimeException("Can only unlink a record from a record folder.");
@@ -2007,9 +1991,175 @@ public class RecordServiceImpl extends BaseBehaviourBean
* If the node doesn't have the aspect it means IncompleteNodeTagger didn't load before TransactionBehaviourQueue * If the node doesn't have the aspect it means IncompleteNodeTagger didn't load before TransactionBehaviourQueue
* and we don't need to reevaluate. * and we don't need to reevaluate.
*/ */
if(nodeService.hasAspect(nodeRef, ContentModel.ASPECT_INCOMPLETE)) if (nodeService.hasAspect(nodeRef, ContentModel.ASPECT_INCOMPLETE))
{ {
incompleteNodeTagger.beforeCommit(false); incompleteNodeTagger.beforeCommit(false);
} }
} }
/**
* Completes a record
*
* @param nodeRef Record node reference
*/
@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))
{
disablePropertyEditableCheck();
try
{
// Add the declared aspect
Map<QName, Serializable> declaredProps = new HashMap<>(2);
declaredProps.put(PROP_DECLARED_AT, new Date());
declaredProps.put(PROP_DECLARED_BY, AuthenticationUtil.getRunAsUser());
nodeService.addAspect(nodeRef, ASPECT_DECLARED_RECORD, declaredProps);
AuthenticationUtil.runAsSystem(new RunAsWork<Void>()
{
@Override
public Void doWork()
{
// remove all owner related rights
ownableService.setOwner(nodeRef, OwnableService.NO_OWNER);
return null;
}
});
} finally
{
enablePropertyEditableCheck();
}
} else
{
LOGGER.debug(buildMissingPropertiesErrorString(missingProperties));
throw new IntegrityException("The record has missing mandatory properties.", null);
}
} else
{
throw new IntegrityException("The record is already completed.", null);
}
} else
{
if (LOGGER.isWarnEnabled())
{
LOGGER.warn(I18NUtil.getMessage(MSG_UNDECLARED_ONLY_RECORDS, nodeRef.toString()));
}
throw new IntegrityException("The record does not exist or is frozen.", null);
}
}
private String buildMissingPropertiesErrorString(List<String> missingProperties)
{
StringBuilder builder = new StringBuilder(255);
builder.append(I18NUtil.getMessage(MSG_NO_DECLARE_MAND_PROP));
builder.append(" ");
for (String missingProperty : missingProperties)
{
builder.append(missingProperty).append(", ");
}
return builder.toString();
}
/**
* Helper method to check whether all the mandatory properties of the node have been set
*
* @param nodeRef node reference
* @return boolean true if all mandatory properties are set, false otherwise
*/
private boolean mandatoryPropertiesSet(final NodeRef nodeRef, final List<String> missingProperties)
{
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);
return missingProperties.isEmpty();
}
/**
* Helper method to check whether all the definition mandatory properties of the node have been set
*
* @param classDef the ClassDefinition defining the properties to be checked
* @param nodeRefProps the properties of the node to be checked
* @param missingProperties the list of mandatory properties found to be missing (currently only the first one)
* @return boolean true if all mandatory properties are set, false otherwise
*/
private void checkDefinitionMandatoryPropsSet(final ClassDefinition classDef, final Map<QName, Serializable> nodeRefProps,
final List<String> missingProperties)
{
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())
{
StringBuilder msg = new StringBuilder();
msg.append("Mandatory property missing: ").append(propDef.getName());
LOGGER.warn(msg.toString());
}
missingProperties.add(propDef.getName().toString());
}
/**
* Helper method to get the custom aspect for a given nodeRef type
*
* @param nodeRefType the node type for which to return custom aspect QName
* @return QName custom aspect
*/
private QName getCustomAspectImpl(QName nodeRefType)
{
QName aspect = ASPECT_RECORD;
if (nodeRefType.equals(TYPE_NON_ELECTRONIC_DOCUMENT))
{
aspect = TYPE_NON_ELECTRONIC_DOCUMENT;
}
// get customAspectImpl
String localName = aspect.toPrefixString(namespaceService).replace(":", "");
localName = MessageFormat.format("{0}CustomProperties", localName);
return QName.createQName(RM_CUSTOM_URI, localName);
}
} }

View File

@@ -32,8 +32,8 @@ import java.util.HashMap;
import java.util.Map; 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.model.RecordsManagementCustomModel; import org.alfresco.module.org_alfresco_module_rm.model.RecordsManagementCustomModel;
import org.alfresco.module.org_alfresco_module_rm.record.RecordServiceImpl;
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.dictionary.DataTypeDefinition;
import org.alfresco.service.cmr.repository.NodeRef; import org.alfresco.service.cmr.repository.NodeRef;
@@ -55,9 +55,9 @@ public class CompleteRecordTest extends BaseRMTestCase
private static final boolean OPTIONAL_METADATA = false; private static final boolean OPTIONAL_METADATA = false;
/** /**
* complete record action * Record service impl
*/ */
private DeclareRecordAction action; private RecordServiceImpl recordServiceImpl;
/** /**
* @see org.alfresco.module.org_alfresco_module_rm.test.util.BaseRMTestCase#initServices() * @see org.alfresco.module.org_alfresco_module_rm.test.util.BaseRMTestCase#initServices()
@@ -67,8 +67,8 @@ public class CompleteRecordTest extends BaseRMTestCase
{ {
super.initServices(); super.initServices();
// get the action // get the record service
action = (DeclareRecordAction) applicationContext.getBean("declareRecord"); recordServiceImpl = (RecordServiceImpl) applicationContext.getBean("recordService");
} }
/** /**
@@ -80,7 +80,7 @@ public class CompleteRecordTest extends BaseRMTestCase
super.tearDownImpl(); super.tearDownImpl();
// ensure action is returned to original state // ensure action is returned to original state
action.setCheckMandatoryPropertiesEnabled(true); recordServiceImpl.setCheckMandatoryPropertiesEnabled(true);
} }
/** /**
@@ -100,7 +100,7 @@ public class CompleteRecordTest extends BaseRMTestCase
public void given() public void given()
{ {
// enable mandatory parameter check // enable mandatory parameter check
action.setCheckMandatoryPropertiesEnabled(true); recordServiceImpl.setCheckMandatoryPropertiesEnabled(true);
// create a record // create a record
record = utils.createRecord(rmFolder, "record.txt", "title"); record = utils.createRecord(rmFolder, "record.txt", "title");
@@ -140,7 +140,7 @@ public class CompleteRecordTest extends BaseRMTestCase
public void given() public void given()
{ {
// enable mandatory parameter check // enable mandatory parameter check
action.setCheckMandatoryPropertiesEnabled(true); recordServiceImpl.setCheckMandatoryPropertiesEnabled(true);
// create a record // create a record
record = utils.createRecord(rmFolder, "record.txt", "title"); record = utils.createRecord(rmFolder, "record.txt", "title");
@@ -183,7 +183,7 @@ public class CompleteRecordTest extends BaseRMTestCase
public void given() throws Exception public void given() throws Exception
{ {
// enable mandatory parameter check // enable mandatory parameter check
action.setCheckMandatoryPropertiesEnabled(true); recordServiceImpl.setCheckMandatoryPropertiesEnabled(true);
// create the custom metadata definition (that has a mandatory property) for electronic records // create the custom metadata definition (that has a mandatory property) for electronic records
defineCustomMetadata(CUSTOM_ELECTRONIC_TEST, ASPECT_RECORD, MANDATORY_METADATA); defineCustomMetadata(CUSTOM_ELECTRONIC_TEST, ASPECT_RECORD, MANDATORY_METADATA);
@@ -229,7 +229,7 @@ public class CompleteRecordTest extends BaseRMTestCase
public void given() throws Exception public void given() throws Exception
{ {
// enable mandatory parameter check // enable mandatory parameter check
action.setCheckMandatoryPropertiesEnabled(true); recordServiceImpl.setCheckMandatoryPropertiesEnabled(true);
// define the custom metadata definition (that has a mandatory property) // define the custom metadata definition (that has a mandatory property)
defineCustomMetadata(CUSTOM_ELECTRONIC_TEST, ASPECT_RECORD, MANDATORY_METADATA); defineCustomMetadata(CUSTOM_ELECTRONIC_TEST, ASPECT_RECORD, MANDATORY_METADATA);
@@ -279,7 +279,7 @@ public class CompleteRecordTest extends BaseRMTestCase
public void given() throws Exception public void given() throws Exception
{ {
// enable mandatory parameter check // enable mandatory parameter check
action.setCheckMandatoryPropertiesEnabled(true); recordServiceImpl.setCheckMandatoryPropertiesEnabled(true);
// create the custom metadata definition (that has a mandatory property) for non-electronic records // 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); defineCustomMetadata(CUSTOM_NON_ELECTRONIC_TEST, TYPE_NON_ELECTRONIC_DOCUMENT, MANDATORY_METADATA);
@@ -326,7 +326,7 @@ public class CompleteRecordTest extends BaseRMTestCase
public void given() throws Exception public void given() throws Exception
{ {
// enable mandatory parameter check // enable mandatory parameter check
action.setCheckMandatoryPropertiesEnabled(true); recordServiceImpl.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, TYPE_NON_ELECTRONIC_DOCUMENT, MANDATORY_METADATA); defineCustomMetadata(CUSTOM_NON_ELECTRONIC_TEST, TYPE_NON_ELECTRONIC_DOCUMENT, MANDATORY_METADATA);
@@ -375,7 +375,7 @@ public class CompleteRecordTest extends BaseRMTestCase
public void given() throws Exception public void given() throws Exception
{ {
// enable mandatory parameter check // enable mandatory parameter check
action.setCheckMandatoryPropertiesEnabled(true); recordServiceImpl.setCheckMandatoryPropertiesEnabled(true);
// create the custom metadata definition (that does not have a mandatory property) // create the custom metadata definition (that does not have a mandatory property)
defineCustomMetadata(CUSTOM_ELECTRONIC_TEST, ASPECT_RECORD, OPTIONAL_METADATA); defineCustomMetadata(CUSTOM_ELECTRONIC_TEST, ASPECT_RECORD, OPTIONAL_METADATA);
@@ -422,7 +422,7 @@ public class CompleteRecordTest extends BaseRMTestCase
public void given() throws Exception public void given() throws Exception
{ {
// enable mandatory parameter check // enable mandatory parameter check
action.setCheckMandatoryPropertiesEnabled(true); recordServiceImpl.setCheckMandatoryPropertiesEnabled(true);
// create the record 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);
@@ -469,7 +469,7 @@ public class CompleteRecordTest extends BaseRMTestCase
public void given() throws Exception public void given() throws Exception
{ {
// enable mandatory parameter check // enable mandatory parameter check
action.setCheckMandatoryPropertiesEnabled(true); recordServiceImpl.setCheckMandatoryPropertiesEnabled(true);
// create the non-electronic record 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, TYPE_NON_ELECTRONIC_DOCUMENT, MANDATORY_METADATA); defineCustomMetadata(CUSTOM_NON_ELECTRONIC_TEST, TYPE_NON_ELECTRONIC_DOCUMENT, MANDATORY_METADATA);
@@ -515,7 +515,7 @@ public class CompleteRecordTest extends BaseRMTestCase
public void given() public void given()
{ {
// disable mandatory parameter check // disable mandatory parameter check
action.setCheckMandatoryPropertiesEnabled(false); recordServiceImpl.setCheckMandatoryPropertiesEnabled(false);
// create a record // create a record
record = utils.createRecord(rmFolder, "record.txt", "title"); record = utils.createRecord(rmFolder, "record.txt", "title");
@@ -555,7 +555,7 @@ public class CompleteRecordTest extends BaseRMTestCase
public void given() public void given()
{ {
// enable mandatory parameter check // enable mandatory parameter check
action.setCheckMandatoryPropertiesEnabled(false); recordServiceImpl.setCheckMandatoryPropertiesEnabled(false);
// create a record // create a record
record = utils.createRecord(rmFolder, "record.txt", "title"); record = utils.createRecord(rmFolder, "record.txt", "title");