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">
<property name="publicAction" value="true"/>
<property name="checkMandatoryPropertiesEnabled" value="${rm.completerecord.mandatorypropertiescheck.enabled}"/>
<property name="transactionalResourceHelper" ref="rm.transactionalResourceHelper" />
<property name="recordService" ref="RecordService" />
</bean>
<!-- undeclare record -->

View File

@@ -16,7 +16,8 @@
<!-- Helper beans -->
<bean id="baseTransaction" abstract="true" class="org.springframework.transaction.interceptor.TransactionInterceptor">
<bean id="baseTransaction" abstract="true"
class="org.springframework.transaction.interceptor.TransactionInterceptor">
<property name="transactionManager">
<ref bean="transactionManager" />
</property>
@@ -27,7 +28,8 @@
</property>
</bean>
<bean id="baseSecurity" abstract="true" class="org.alfresco.module.org_alfresco_module_rm.security.RMMethodSecurityInterceptor">
<bean id="baseSecurity" abstract="true"
class="org.alfresco.module.org_alfresco_module_rm.security.RMMethodSecurityInterceptor">
<property name="authenticationManager">
<ref bean="authenticationManager" />
</property>
@@ -49,11 +51,13 @@
<!-- Records Management Service Registry -->
<bean id="RecordsManagementServiceRegistry" class="org.alfresco.module.org_alfresco_module_rm.RecordsManagementServiceRegistryImpl" />
<bean id="RecordsManagementServiceRegistry"
class="org.alfresco.module.org_alfresco_module_rm.RecordsManagementServiceRegistryImpl" />
<!-- Vital Record Service -->
<bean id="vitalRecordService" parent="baseService" class="org.alfresco.module.org_alfresco_module_rm.vital.VitalRecordServiceImpl">
<bean id="vitalRecordService" parent="baseService"
class="org.alfresco.module.org_alfresco_module_rm.vital.VitalRecordServiceImpl">
<property name="filePlanService" ref="FilePlanService" />
</bean>
@@ -95,7 +99,8 @@
</bean>
<!-- Disposition Service -->
<bean id="dispositionService" parent="baseService" class="org.alfresco.module.org_alfresco_module_rm.disposition.DispositionServiceImpl">
<bean id="dispositionService" parent="baseService"
class="org.alfresco.module.org_alfresco_module_rm.disposition.DispositionServiceImpl">
<property name="recordsManagementServiceRegistry" ref="RecordsManagementServiceRegistry" />
<property name="behaviourFilter" ref="policyBehaviourFilter" />
<property name="filePlanService" ref="FilePlanService" />
@@ -167,7 +172,8 @@
</bean>
<!-- Transfer Service -->
<bean id="rmTransferService" class="org.alfresco.module.org_alfresco_module_rm.transfer.TransferServiceImpl" parent="baseService">
<bean id="rmTransferService" class="org.alfresco.module.org_alfresco_module_rm.transfer.TransferServiceImpl"
parent="baseService">
<property name="filePlanService" ref="FilePlanService" />
<property name="dispositionService" ref="dispositionService" />
<property name="recordService" ref="RecordService" />
@@ -262,7 +268,8 @@
<!-- Records Management Search Service -->
<bean id="recordsManagementSearchService" class="org.alfresco.module.org_alfresco_module_rm.search.RecordsManagementSearchServiceImpl">
<bean id="recordsManagementSearchService"
class="org.alfresco.module.org_alfresco_module_rm.search.RecordsManagementSearchServiceImpl">
<property name="fileFolderService" ref="FileFolderService" />
<property name="siteService" ref="SiteService" />
<property name="namespaceService" ref="NamespaceService" />
@@ -359,7 +366,8 @@
</property>
</bean>
<bean id="RecordsManagementSearchService_transaction" class="org.springframework.transaction.interceptor.TransactionInterceptor">
<bean id="RecordsManagementSearchService_transaction"
class="org.springframework.transaction.interceptor.TransactionInterceptor">
<property name="transactionManager">
<ref bean="transactionManager" />
</property>
@@ -481,7 +489,8 @@
</property>
</bean>
<bean id="FilePlanPermissionService_transaction" class="org.springframework.transaction.interceptor.TransactionInterceptor">
<bean id="FilePlanPermissionService_transaction"
class="org.springframework.transaction.interceptor.TransactionInterceptor">
<property name="transactionManager">
<ref bean="transactionManager" />
</property>
@@ -537,7 +546,8 @@
</property>
</bean>
<bean id="FilePlanRoleService_transaction" class="org.springframework.transaction.interceptor.TransactionInterceptor">
<bean id="FilePlanRoleService_transaction"
class="org.springframework.transaction.interceptor.TransactionInterceptor">
<property name="transactionManager">
<ref bean="transactionManager" />
</property>
@@ -642,7 +652,8 @@
</property>
</bean>
<bean id="ModelSecurityService_transaction" class="org.springframework.transaction.interceptor.TransactionInterceptor">
<bean id="ModelSecurityService_transaction"
class="org.springframework.transaction.interceptor.TransactionInterceptor">
<property name="transactionManager">
<ref bean="transactionManager" />
</property>
@@ -665,7 +676,9 @@
<!-- Records Management Action Service -->
<bean id="recordsManagementActionService" class="org.alfresco.module.org_alfresco_module_rm.action.RecordsManagementActionServiceImpl" init-method="init">
<bean id="recordsManagementActionService"
class="org.alfresco.module.org_alfresco_module_rm.action.RecordsManagementActionServiceImpl"
init-method="init">
<property name="policyComponent" ref="policyComponent" />
<property name="nodeService" ref="nodeService" />
</bean>
@@ -686,7 +699,8 @@
</property>
</bean>
<bean id="RecordsManagementActionService_transaction" class="org.springframework.transaction.interceptor.TransactionInterceptor">
<bean id="RecordsManagementActionService_transaction"
class="org.springframework.transaction.interceptor.TransactionInterceptor">
<property name="transactionManager">
<ref bean="transactionManager" />
</property>
@@ -722,7 +736,8 @@
<!-- Records Management Event Service -->
<bean id="recordsManagementEventService" class="org.alfresco.module.org_alfresco_module_rm.event.RecordsManagementEventServiceImpl">
<bean id="recordsManagementEventService"
class="org.alfresco.module.org_alfresco_module_rm.event.RecordsManagementEventServiceImpl">
<property name="nodeService" ref="NodeService" />
<property name="contentService" ref="ContentService" />
</bean>
@@ -743,7 +758,8 @@
</property>
</bean>
<bean id="RecordsManagementEventService_transaction" class="org.springframework.transaction.interceptor.TransactionInterceptor">
<bean id="RecordsManagementEventService_transaction"
class="org.springframework.transaction.interceptor.TransactionInterceptor">
<property name="transactionManager">
<ref bean="transactionManager" />
</property>
@@ -775,7 +791,8 @@
</property>
</bean>
<bean id="recordsManagementAdminBase" class="org.alfresco.module.org_alfresco_module_rm.admin.RecordsManagementAdminBase" abstract="true">
<bean id="recordsManagementAdminBase"
class="org.alfresco.module.org_alfresco_module_rm.admin.RecordsManagementAdminBase" abstract="true">
<property name="dictionaryService" ref="DictionaryService" />
<property name="nodeService" ref="NodeService" />
<property name="contentService" ref="contentService" />
@@ -785,7 +802,9 @@
<!-- Records Management Admin Service -->
<bean id="recordsManagementAdminService" class="org.alfresco.module.org_alfresco_module_rm.admin.RecordsManagementAdminServiceImpl" parent="recordsManagementAdminBase">
<bean id="recordsManagementAdminService"
class="org.alfresco.module.org_alfresco_module_rm.admin.RecordsManagementAdminServiceImpl"
parent="recordsManagementAdminBase">
<property name="relationshipService" ref="RelationshipService" />
<property name="transactionService" ref="transactionService" />
<property name="customisableTypes">
@@ -814,7 +833,8 @@
</property>
</bean>
<bean id="RecordsManagementAdminService_transaction" class="org.springframework.transaction.interceptor.TransactionInterceptor">
<bean id="RecordsManagementAdminService_transaction"
class="org.springframework.transaction.interceptor.TransactionInterceptor">
<property name="transactionManager">
<ref bean="transactionManager" />
</property>
@@ -926,7 +946,8 @@
<!-- Records Management Audit Service -->
<bean id="recordsManagementAuditService" class="org.alfresco.module.org_alfresco_module_rm.audit.RecordsManagementAuditServiceImpl" init-method="init">
<bean id="recordsManagementAuditService"
class="org.alfresco.module.org_alfresco_module_rm.audit.RecordsManagementAuditServiceImpl" init-method="init">
<property name="policyComponent" ref="policyComponent" />
<property name="dictionaryService" ref="dictionaryService" />
<property name="transactionService" ref="transactionService" />
@@ -964,7 +985,8 @@
</property>
</bean>
<bean id="RecordsManagementAuditService_transaction" class="org.springframework.transaction.interceptor.TransactionInterceptor">
<bean id="RecordsManagementAuditService_transaction"
class="org.springframework.transaction.interceptor.TransactionInterceptor">
<property name="transactionManager">
<ref bean="transactionManager" />
</property>
@@ -1000,7 +1022,8 @@
<!-- Record Folder Service -->
<bean id="recordFolderService" class="org.alfresco.module.org_alfresco_module_rm.recordfolder.RecordFolderServiceImpl">
<bean id="recordFolderService"
class="org.alfresco.module.org_alfresco_module_rm.recordfolder.RecordFolderServiceImpl">
<property name="nodeService" ref="NodeService" />
<property name="dispositionService" ref="DispositionService" />
<property name="dictionaryService" ref="DictionaryService" />
@@ -1024,7 +1047,8 @@
</property>
</bean>
<bean id="RecordFolderService_transaction" class="org.springframework.transaction.interceptor.TransactionInterceptor">
<bean id="RecordFolderService_transaction"
class="org.springframework.transaction.interceptor.TransactionInterceptor">
<property name="transactionManager">
<ref bean="transactionManager" />
</property>
@@ -1054,7 +1078,8 @@
<!-- Record Service -->
<bean id="recordService" parent="rm.baseBehaviour" class="org.alfresco.module.org_alfresco_module_rm.record.RecordServiceImpl" init-method="init">
<bean id="recordService" parent="rm.baseBehaviour"
class="org.alfresco.module.org_alfresco_module_rm.record.RecordServiceImpl" init-method="init">
<property name="identifierService" ref="recordsManagementIdentifierService" />
<property name="extendedPermissionService" ref="ExtendedPermissionService" />
<property name="extendedSecurityService" ref="ExtendedSecurityService" />
@@ -1076,6 +1101,9 @@
<property name="recordableVersionService" ref="RecordableVersionService" />
<property name="alwaysEditURIs" ref="recordService_alwaysEditURIs" />
<property name="incompleteNodeTagger" ref="incompleteNodeTagger" />
<property name="freezeService" ref="FreezeService" />
<property name="namespaceService" ref="NamespaceService" />
<property name="checkMandatoryPropertiesEnabled" value="${rm.completerecord.mandatorypropertiescheck.enabled}" />
</bean>
<!-- Defines a list of namespace URIs for properties, which should be always editable -->
@@ -1090,7 +1118,9 @@
<value>http://www.alfresco.org/model/rendition/1.0</value>
</util:list>
<bean id="recordMetadataAspectBootstrap" class="org.alfresco.module.org_alfresco_module_rm.record.RecordMetadataBootstrap" init-method="init" abstract="true">
<bean id="recordMetadataAspectBootstrap"
class="org.alfresco.module.org_alfresco_module_rm.record.RecordMetadataBootstrap" init-method="init"
abstract="true">
<property name="recordService" ref="recordService" />
<property name="namespaceService" ref="namespaceService" />
</bean>
@@ -1152,6 +1182,7 @@
org.alfresco.module.org_alfresco_module_rm.record.RecordService.makeRecord=RM_ALLOW
org.alfresco.module.org_alfresco_module_rm.record.RecordService.link=RM_ALLOW
org.alfresco.module.org_alfresco_module_rm.record.RecordService.unlink=RM_ALLOW
org.alfresco.module.org_alfresco_module_rm.record.RecordService.complete=RM_ALLOW
org.alfresco.module.org_alfresco_module_rm.record.RecordService.*=RM_DENY
]]>
</value>
@@ -1160,7 +1191,8 @@
<!-- Inplace Record Service -->
<bean id="inplaceRecordService" parent="baseService" class="org.alfresco.module.org_alfresco_module_rm.record.InplaceRecordServiceImpl">
<bean id="inplaceRecordService" parent="baseService"
class="org.alfresco.module.org_alfresco_module_rm.record.InplaceRecordServiceImpl">
<property name="siteService" ref="SiteService" />
<property name="extendedSecurityService" ref="ExtendedSecurityService" />
<property name="fileFolderService" ref="FileFolderService" />
@@ -1186,7 +1218,8 @@
</property>
</bean>
<bean id="InplaceRecordService_transaction" class="org.springframework.transaction.interceptor.TransactionInterceptor">
<bean id="InplaceRecordService_transaction"
class="org.springframework.transaction.interceptor.TransactionInterceptor">
<property name="transactionManager">
<ref bean="transactionManager" />
</property>
@@ -1250,7 +1283,9 @@
<property name="namespacePrefixResolver">
<ref bean="namespaceService"></ref>
</property>
<property name="transactionService"><ref bean="transactionService" /></property>
<property name="transactionService">
<ref bean="transactionService" />
</property>
<property name="emailMappingKeys">
<list>
<value>Thread-Index</value>
@@ -1263,7 +1298,8 @@
</property>
</bean>
<bean id="CustomEmailMappingService_transaction" class="org.springframework.transaction.interceptor.TransactionInterceptor">
<bean id="CustomEmailMappingService_transaction"
class="org.springframework.transaction.interceptor.TransactionInterceptor">
<property name="transactionManager">
<ref bean="transactionManager" />
</property>
@@ -1308,7 +1344,8 @@
</bean>
<!-- RM Notification Helper -->
<bean id="recordsManagementNotificationHelper" class="org.alfresco.module.org_alfresco_module_rm.notification.RecordsManagementNotificationHelper" >
<bean id="recordsManagementNotificationHelper"
class="org.alfresco.module.org_alfresco_module_rm.notification.RecordsManagementNotificationHelper">
<property name="filePlanRoleService" ref="FilePlanRoleService" />
<property name="notificationService" ref="NotificationService" />
<property name="filePlanService" ref="FilePlanService" />
@@ -1382,7 +1419,8 @@
</constructor-arg>
</bean>
<bean id="rmListOfValuesContraintInit" class="org.alfresco.module.org_alfresco_module_rm.caveat.RMListOfValuesConstraint">
<bean id="rmListOfValuesContraintInit"
class="org.alfresco.module.org_alfresco_module_rm.caveat.RMListOfValuesConstraint">
<property name="caveatConfigService" ref="caveatConfigService" />
</bean>
@@ -1411,7 +1449,8 @@
</property>
</bean>
<bean id="CaveatConfigService_transaction" class="org.springframework.transaction.interceptor.TransactionInterceptor">
<bean id="CaveatConfigService_transaction"
class="org.springframework.transaction.interceptor.TransactionInterceptor">
<property name="transactionManager">
<ref bean="transactionManager" />
</property>
@@ -1441,7 +1480,8 @@
</bean>
<!-- Site service work around (see https://issues.alfresco.com/jira/browse/RM-387) -->
<bean name="siteGetChildrenCannedQueryFactory" class="org.alfresco.module.org_alfresco_module_rm.site.GetChildrenCannedQueryFactory">
<bean name="siteGetChildrenCannedQueryFactory"
class="org.alfresco.module.org_alfresco_module_rm.site.GetChildrenCannedQueryFactory">
<property name="registry" ref="siteCannedQueryRegistry" />
<property name="dictionaryService" ref="dictionaryService" />
<property name="tenantService" ref="tenantService" />
@@ -1508,7 +1548,8 @@
<!-- Data Set Implementations -->
<bean id="dataSetBase" abstract="true" init-method="register" class="org.alfresco.module.org_alfresco_module_rm.dataset.DataSetBase">
<bean id="dataSetBase" abstract="true" init-method="register"
class="org.alfresco.module.org_alfresco_module_rm.dataset.DataSetBase">
<property name="dataSetService" ref="dataSetService" />
</bean>
@@ -1575,7 +1616,9 @@
<!-- Relationship Service -->
<bean id="relationshipService" class="org.alfresco.module.org_alfresco_module_rm.relationship.RelationshipServiceImpl" init-method="init" parent="recordsManagementAdminBase">
<bean id="relationshipService"
class="org.alfresco.module.org_alfresco_module_rm.relationship.RelationshipServiceImpl" init-method="init"
parent="recordsManagementAdminBase">
<property name="policyComponent" ref="policyComponent" />
</bean>
@@ -1595,7 +1638,8 @@
</property>
</bean>
<bean id="RelationshipService_transaction" class="org.springframework.transaction.interceptor.TransactionInterceptor">
<bean id="RelationshipService_transaction"
class="org.springframework.transaction.interceptor.TransactionInterceptor">
<property name="transactionManager">
<ref bean="transactionManager" />
</property>
@@ -1628,7 +1672,8 @@
<!-- Recordable Verison Config Service -->
<bean id="recordableVersionConfigService" class="org.alfresco.module.org_alfresco_module_rm.recordableversion.RecordableVersionConfigServiceImpl">
<bean id="recordableVersionConfigService"
class="org.alfresco.module.org_alfresco_module_rm.recordableversion.RecordableVersionConfigServiceImpl">
<property name="nodeService" ref="NodeService" />
</bean>
@@ -1648,7 +1693,8 @@
</property>
</bean>
<bean id="RecordableVersionConfigService_transaction" class="org.springframework.transaction.interceptor.TransactionInterceptor">
<bean id="RecordableVersionConfigService_transaction"
class="org.springframework.transaction.interceptor.TransactionInterceptor">
<property name="transactionManager">
<ref bean="transactionManager" />
</property>

View File

@@ -27,33 +27,13 @@
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.record.RecordServiceImpl;
import org.alfresco.module.org_alfresco_module_rm.util.TransactionalResourceHelper;
import org.alfresco.module.org_alfresco_module_rm.record.RecordService;
import org.alfresco.repo.action.executer.ActionExecuterAbstractBase;
import org.alfresco.repo.security.authentication.AuthenticationUtil;
import org.alfresco.repo.security.authentication.AuthenticationUtil.RunAsWork;
import org.alfresco.repo.node.integrity.IntegrityException;
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.security.OwnableService;
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;
import org.alfresco.util.ParameterCheck;
/**
* Declare record action
@@ -62,36 +42,24 @@ import org.springframework.extensions.surf.util.I18NUtil;
*/
public class DeclareRecordAction extends RMActionExecuterAbstractBase
{
/** action name */
/**
* action name
*/
public static final String NAME = "declareRecord";
/** I18N */
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";
/** Logger */
private static Log logger = LogFactory.getLog(DeclareRecordAction.class);
/** check mandatory properties */
private boolean checkMandatoryPropertiesEnabled = true;
/** transactional resource helper */
private TransactionalResourceHelper transactionalResourceHelper;
/**
* Record service
*/
private RecordService recordService;
/**
* @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;
}
/**
* @param transactionalResourceHelper
*/
public void setTransactionalResourceHelper(TransactionalResourceHelper transactionalResourceHelper)
{
this.transactionalResourceHelper = transactionalResourceHelper;
this.recordService = recordService;
}
/**
@@ -100,167 +68,14 @@ public class DeclareRecordAction extends RMActionExecuterAbstractBase
@Override
protected void executeImpl(final Action action, final NodeRef actionedUponNodeRef)
{
if (getNodeService().exists(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();
ParameterCheck.mandatory("actionedUponNodeRef", actionedUponNodeRef);
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());
this.getNodeService().addAspect(actionedUponNodeRef, ASPECT_DECLARED_RECORD, declaredProps);
AuthenticationUtil.runAsSystem(new RunAsWork<Void>()
recordService.complete(actionedUponNodeRef);
} catch (IntegrityException e)
{
@Override
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()));
}
}
action.setParameterValue(ActionExecuterAbstractBase.PARAM_RESULT, e.getMessage());
}
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 filePlanType file plan type
*
* @since 2.2
*/
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.
*
* @param nodeRef node reference
*
* @since 2.2
*/
void disablePropertyEditableCheck(NodeRef nodeRef);
@@ -87,7 +85,6 @@ public interface RecordService
* Gets a list of all the 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
@@ -99,7 +96,6 @@ public interface RecordService
*
* @param aspect aspect {@link QName}
* @return boolean true if the aspect is a registered record meta-data aspect, false otherwise
*
* @since 2.3
*/
boolean isRecordMetadataAspect(QName aspect);
@@ -111,7 +107,6 @@ public interface RecordService
* @param property property {@link QName}
* @return boolean true if the property is declared on a registered record meta-data aspect,
* false otherwise
*
* @since 2.3
*/
boolean isRecordMetadataProperty(QName property);
@@ -125,7 +120,6 @@ public interface RecordService
*
* @param nodeRef node reference to file plan component providing context
* @return {@link Set}<{@link QName}> list of record meta-data aspects
*
* @since 2.2
*/
Set<QName> getRecordMetadataAspects(NodeRef nodeRef);
@@ -138,7 +132,6 @@ public interface RecordService
*
* @param filePlanType file plan type
* @return{@link Set}<{@link QName}> list of record meta-data aspects
*
* @since 2.2
*/
Set<QName> getRecordMetadataAspects(QName filePlanType);
@@ -201,7 +194,7 @@ public interface RecordService
/**
* Indicates whether the record is filed or not
*
* @param nodeRef record
* @param record Record node reference
* @return boolean true if filed, false otherwise
*/
boolean isFiled(NodeRef record);
@@ -209,25 +202,10 @@ public interface RecordService
/**
* 'File' a new document that arrived in the file plan structure.
*
* @param nodeRef record
* @param record Record node reference
*/
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
*
@@ -289,8 +267,14 @@ public interface RecordService
*
* @param record the record to unlink
* @param recordFolder the record folder to unlink it from
*
* @since 2.3
*/
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 java.io.Serializable;
import java.text.MessageFormat;
import java.util.ArrayList;
import java.util.Arrays;
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.dod5015.DOD5015Model;
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.model.BaseBehaviourBean;
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.integrity.IncompleteNodeTagger;
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.PolicyComponent;
import org.alfresco.repo.policy.Behaviour.NotificationFrequency;
import org.alfresco.repo.policy.annotation.Behaviour;
import org.alfresco.repo.policy.annotation.BehaviourBean;
import org.alfresco.repo.policy.annotation.BehaviourKind;
@@ -143,33 +145,54 @@ public class RecordServiceImpl extends BaseBehaviourBean
NodeServicePolicies.OnUpdatePropertiesPolicy,
ContentServicePolicies.OnContentUpdatePolicy
{
/** Logger */
/**
* Logger
*/
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";
/** Synced aspect */
/**
* Synced aspect
*/
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";
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 FINAL_VERSION = "rm.service.final-version";
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[]
{
ContentModel.PROP_LAST_THUMBNAIL_MODIFICATION_DATA
};
/** always edit model URI's */
/**
* always edit model URI's
*/
private List<String> alwaysEditURIs;
/**
* check mandatory properties
*/
private boolean checkMandatoryPropertiesEnabled = true;
/**
* @param alwaysEditURIs the alwaysEditURIs to set
*/
@@ -186,7 +209,9 @@ public class RecordServiceImpl extends BaseBehaviourBean
return this.alwaysEditURIs;
}
/** record model URI's */
/**
* record model URI's
*/
public static final List<String> RECORD_MODEL_URIS = Collections.unmodifiableList(
Arrays.asList(
RM_URI,
@@ -196,7 +221,9 @@ public class RecordServiceImpl extends BaseBehaviourBean
DOD5015Model.DOD_URI
));
/** non-record model URI's */
/**
* non-record model URI's
*/
private static final String[] NON_RECORD_MODEL_URIS = new String[]
{
NamespaceService.AUDIO_MODEL_1_0_URI,
@@ -208,64 +235,114 @@ public class RecordServiceImpl extends BaseBehaviourBean
NamespaceService.REPOSITORY_VIEW_1_0_URI
};
/** Indentity service */
/**
* Indentity service
*/
private IdentifierService identifierService;
/** Extended permission service */
/**
* Extended permission service
*/
private ExtendedPermissionService extendedPermissionService;
/** Extended security service */
/**
* Extended security service
*/
private ExtendedSecurityService extendedSecurityService;
/** File plan service */
/**
* File plan service
*/
private FilePlanService filePlanService;
/** Records management notification helper */
/**
* Records management notification helper
*/
private RecordsManagementNotificationHelper notificationHelper;
/** Policy component */
/**
* Policy component
*/
private PolicyComponent policyComponent;
/** Ownable service */
/**
* Ownable service
*/
private OwnableService ownableService;
/** Capability service */
/**
* Capability service
*/
private CapabilityService capabilityService;
/** Rule service */
/**
* Rule service
*/
private RuleService ruleService;
/** File folder service */
/**
* File folder service
*/
private FileFolderService fileFolderService;
/** Record folder service */
/**
* Record folder service
*/
private RecordFolderService recordFolderService;
/** File plan role service */
/**
* File plan role service
*/
private FilePlanRoleService filePlanRoleService;
/** Permission service */
/**
* Permission service
*/
private PermissionService permissionService;
/** Version service */
/**
* Version service
*/
private VersionService versionService;
/** Relationship service */
/**
* Relationship service
*/
private RelationshipService relationshipService;
/** Disposition service */
/**
* Disposition service
*/
private DispositionService dispositionService;
/** records management container type */
/**
* records management container type
*/
private RecordsManagementContainerType recordsManagementContainerType;
/** recordable version service */
/**
* recordable version service
*/
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;
/** policies */
/**
* Freeze service
*/
private FreezeService freezeService;
/**
* Namespace service
*/
private NamespaceService namespaceService;
/**
* policies
*/
private ClassPolicyDelegate<BeforeFileRecord> beforeFileRecord;
private ClassPolicyDelegate<OnFileRecord> onFileRecord;
private ClassPolicyDelegate<BeforeRecordDeclaration> beforeRecordDeclarationDelegate;
@@ -424,6 +501,30 @@ public class RecordServiceImpl extends BaseBehaviourBean
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
*/
@@ -521,8 +622,7 @@ public class RecordServiceImpl extends BaseBehaviourBean
{
Set<NodeRef> newRecords = transactionalResourceHelper.getSet(KEY_NEW_RECORDS);
newRecords.add(nodeRef);
}
else
} else
{
// if we are linking a record
NodeRef parentNodeRef = childAssocRef.getParentRef();
@@ -538,13 +638,11 @@ public class RecordServiceImpl extends BaseBehaviourBean
// recalculate disposition schedule for the record when linking it
dispositionService.recalculateNextDispositionStep(nodeRef);
}
}
catch (RecordLinkRuntimeException e)
} catch (RecordLinkRuntimeException e)
{
// rethrow exception
throw e;
}
catch (AlfrescoRuntimeException e)
} catch (AlfrescoRuntimeException e)
{
// do nothing but log error
LOGGER.warn("Unable to file pending record.", e);
@@ -634,12 +732,10 @@ public class RecordServiceImpl extends BaseBehaviourBean
afterCal.set(Calendar.SECOND, 0);
afterCal.set(Calendar.MILLISECOND, 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;
}
else
} else
{
// otherwise
propertyUnchanged = EqualsHelper.nullSafeEquals(beforeValue, afterValue);
@@ -663,7 +759,6 @@ public class RecordServiceImpl extends BaseBehaviourBean
* Get map containing record metadata aspects.
*
* @return {@link Map}<{@link QName}, {@link Set}<{@link QName}>> map containing record metadata aspects
*
* @since 2.2
*/
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
filePlanTypes = getRecordMetadataAspectsMap().get(recordMetadataAspect);
}
else
} else
{
// create a new set for the file plan type
filePlanTypes = new HashSet<QName>(1);
@@ -867,8 +961,7 @@ public class RecordServiceImpl extends BaseBehaviourBean
{
// move the document into the file plan
nodeService.moveNode(nodeRef, newRecordContainer, ContentModel.ASSOC_CONTAINS, parentAssoc.getQName());
}
finally
} finally
{
behaviourFilter.enableBehaviour();
}
@@ -907,14 +1000,12 @@ public class RecordServiceImpl extends BaseBehaviourBean
// set the extended security
extendedSecurityService.set(nodeRef, readersAndWriters);
}
finally
} finally
{
ruleService.enableRules();
}
}
}
finally
} finally
{
ruleService.enableRuleType("outbound");
}
@@ -955,8 +1046,7 @@ public class RecordServiceImpl extends BaseBehaviourBean
LOGGER.debug(msg);
throw new RecordCreationException(msg);
}
}
else
} else
{
// verify that the provided file plan is actually a file plan
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
FileInfo recordInfo = fileFolderService.copy(nodeRef, unfiledRecordFolder, null);
record = recordInfo.getNodeRef();
}
finally
} finally
{
recordsManagementContainerType.enable();
}
@@ -1084,8 +1173,7 @@ public class RecordServiceImpl extends BaseBehaviourBean
try
{
nodeService.removeAspect(record, ContentModel.ASPECT_VERSIONABLE);
}
finally
} finally
{
behaviourFilter.enableBehaviour(ContentModel.ASPECT_VERSIONABLE);
}
@@ -1108,16 +1196,14 @@ public class RecordServiceImpl extends BaseBehaviourBean
if (originalAssocs == null)
{
nodeService.removeAspect(record, ContentModel.ASPECT_COPIEDFROM);
}
else
} else
{
for (AssociationRef originalAssoc : originalAssocs)
{
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);
}
@@ -1188,8 +1274,7 @@ public class RecordServiceImpl extends BaseBehaviourBean
if (type == null)
{
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.");
}
@@ -1234,8 +1319,7 @@ public class RecordServiceImpl extends BaseBehaviourBean
}
});
}
finally
} finally
{
enablePropertyEditableCheck();
}
@@ -1273,8 +1357,7 @@ public class RecordServiceImpl extends BaseBehaviourBean
return null;
}
});
}
finally
} finally
{
ruleService.enableRules();
enablePropertyEditableCheck();
@@ -1308,7 +1391,7 @@ public class RecordServiceImpl extends BaseBehaviourBean
/**
* 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
* 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)
*/
@@ -1528,8 +1523,7 @@ public class RecordServiceImpl extends BaseBehaviourBean
// send an email to the record creator
notificationHelper.recordRejectedEmailNotification(nodeRef, recordId, documentOwner);
}
}
finally
} finally
{
ruleService.enableRules();
}
@@ -1630,8 +1624,7 @@ public class RecordServiceImpl extends BaseBehaviourBean
if (result)
{
LOGGER.debug(" ... property marked as always editable.");
}
else
} else
{
boolean allowRecordEdit = false;
boolean allowNonRecordEdit = false;
@@ -1657,29 +1650,25 @@ public class RecordServiceImpl extends BaseBehaviourBean
{
LOGGER.debug(" ... so all properties can be edited.");
result = true;
}
else if (allowNonRecordEdit && !allowRecordEdit)
} else if (allowNonRecordEdit && !allowRecordEdit)
{
// can only edit non record properties
if (!isRecordMetadata(filePlan, property))
{
LOGGER.debug(" ... property is not considered record metadata so editable.");
result = true;
}
else
} else
{
LOGGER.debug(" ... property is considered record metadata so not editable.");
}
}
else if (!allowNonRecordEdit && allowRecordEdit)
} else if (!allowNonRecordEdit && allowRecordEdit)
{
// can only edit record properties
if (isRecordMetadata(filePlan, property))
{
LOGGER.debug(" ... property is considered record metadata so editable.");
result = true;
}
else
} else
{
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()))
{
result = false;
}
else
} else
{
// check the URI's
result = RECORD_MODEL_URIS.contains(property.getNamespaceURI());
@@ -1808,8 +1796,7 @@ public class RecordServiceImpl extends BaseBehaviourBean
if (!nodeService.hasAspect(nodeRef, typeQName))
{
nodeService.addAspect(nodeRef, typeQName, null);
}
else
} else
{
LOGGER.info(I18NUtil.getMessage(MSG_NODE_HAS_ASPECT, nodeRef.toString(), typeQName.toString()));
}
@@ -1853,8 +1840,7 @@ public class RecordServiceImpl extends BaseBehaviourBean
// recalculate disposition schedule for the record when linking it
dispositionService.recalculateNextDispositionStep(record);
}
else
} else
{
// 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 recordFolder
*/
@@ -1912,8 +1897,7 @@ public class RecordServiceImpl extends BaseBehaviourBean
// recalculate disposition schedule for record after unlinking it
dispositionService.recalculateNextDispositionStep(record);
}
else
} else
{
// can only unlink a record from a record folder
throw new RecordLinkRuntimeException("Can only unlink a record from a record folder.");
@@ -2012,4 +1996,170 @@ public class RecordServiceImpl extends BaseBehaviourBean
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 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.record.RecordServiceImpl;
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;
@@ -55,9 +55,9 @@ public class CompleteRecordTest extends BaseRMTestCase
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()
@@ -67,8 +67,8 @@ public class CompleteRecordTest extends BaseRMTestCase
{
super.initServices();
// get the action
action = (DeclareRecordAction) applicationContext.getBean("declareRecord");
// get the record service
recordServiceImpl = (RecordServiceImpl) applicationContext.getBean("recordService");
}
/**
@@ -80,7 +80,7 @@ public class CompleteRecordTest extends BaseRMTestCase
super.tearDownImpl();
// 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()
{
// enable mandatory parameter check
action.setCheckMandatoryPropertiesEnabled(true);
recordServiceImpl.setCheckMandatoryPropertiesEnabled(true);
// create a record
record = utils.createRecord(rmFolder, "record.txt", "title");
@@ -140,7 +140,7 @@ public class CompleteRecordTest extends BaseRMTestCase
public void given()
{
// enable mandatory parameter check
action.setCheckMandatoryPropertiesEnabled(true);
recordServiceImpl.setCheckMandatoryPropertiesEnabled(true);
// create a record
record = utils.createRecord(rmFolder, "record.txt", "title");
@@ -183,7 +183,7 @@ public class CompleteRecordTest extends BaseRMTestCase
public void given() throws Exception
{
// enable mandatory parameter check
action.setCheckMandatoryPropertiesEnabled(true);
recordServiceImpl.setCheckMandatoryPropertiesEnabled(true);
// create the custom metadata definition (that has a mandatory property) for electronic records
defineCustomMetadata(CUSTOM_ELECTRONIC_TEST, ASPECT_RECORD, MANDATORY_METADATA);
@@ -229,7 +229,7 @@ public class CompleteRecordTest extends BaseRMTestCase
public void given() throws Exception
{
// enable mandatory parameter check
action.setCheckMandatoryPropertiesEnabled(true);
recordServiceImpl.setCheckMandatoryPropertiesEnabled(true);
// define the custom metadata definition (that has a mandatory property)
defineCustomMetadata(CUSTOM_ELECTRONIC_TEST, ASPECT_RECORD, MANDATORY_METADATA);
@@ -279,7 +279,7 @@ public class CompleteRecordTest extends BaseRMTestCase
public void given() throws Exception
{
// enable mandatory parameter check
action.setCheckMandatoryPropertiesEnabled(true);
recordServiceImpl.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);
@@ -326,7 +326,7 @@ public class CompleteRecordTest extends BaseRMTestCase
public void given() throws Exception
{
// enable mandatory parameter check
action.setCheckMandatoryPropertiesEnabled(true);
recordServiceImpl.setCheckMandatoryPropertiesEnabled(true);
// create the custom metadata definition (that has a mandatory property)
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
{
// enable mandatory parameter check
action.setCheckMandatoryPropertiesEnabled(true);
recordServiceImpl.setCheckMandatoryPropertiesEnabled(true);
// create the custom metadata definition (that does not have a mandatory property)
defineCustomMetadata(CUSTOM_ELECTRONIC_TEST, ASPECT_RECORD, OPTIONAL_METADATA);
@@ -422,7 +422,7 @@ public class CompleteRecordTest extends BaseRMTestCase
public void given() throws Exception
{
// enable mandatory parameter check
action.setCheckMandatoryPropertiesEnabled(true);
recordServiceImpl.setCheckMandatoryPropertiesEnabled(true);
// create the record custom metadata definition (that has a mandatory property)
defineCustomMetadata(CUSTOM_ELECTRONIC_TEST, ASPECT_RECORD, MANDATORY_METADATA);
@@ -469,7 +469,7 @@ public class CompleteRecordTest extends BaseRMTestCase
public void given() throws Exception
{
// enable mandatory parameter check
action.setCheckMandatoryPropertiesEnabled(true);
recordServiceImpl.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);
@@ -515,7 +515,7 @@ public class CompleteRecordTest extends BaseRMTestCase
public void given()
{
// disable mandatory parameter check
action.setCheckMandatoryPropertiesEnabled(false);
recordServiceImpl.setCheckMandatoryPropertiesEnabled(false);
// create a record
record = utils.createRecord(rmFolder, "record.txt", "title");
@@ -555,7 +555,7 @@ public class CompleteRecordTest extends BaseRMTestCase
public void given()
{
// enable mandatory parameter check
action.setCheckMandatoryPropertiesEnabled(false);
recordServiceImpl.setCheckMandatoryPropertiesEnabled(false);
// create a record
record = utils.createRecord(rmFolder, "record.txt", "title");