mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-07-31 17:39:05 +00:00
Merge RM-5180 from 2.5 into master
This commit is contained in:
@@ -51,6 +51,8 @@ public interface RecordsManagementPolicies
|
||||
QName ON_REMOVE_REFERENCE = QName.createQName(NamespaceService.ALFRESCO_URI, "onRemoveReference");
|
||||
QName BEFORE_RECORD_DECLARATION = QName.createQName(NamespaceService.ALFRESCO_URI, "beforeRecordDeclaration");
|
||||
QName ON_RECORD_DECLARATION = QName.createQName(NamespaceService.ALFRESCO_URI, "onRecordDeclaration");
|
||||
QName BEFORE_RECORD_REJECTION = QName.createQName(NamespaceService.ALFRESCO_URI, "beforeRecordRejection");
|
||||
QName ON_RECORD_REJECTION = QName.createQName(NamespaceService.ALFRESCO_URI, "onRecordRejection");
|
||||
|
||||
/** Before records management action execution */
|
||||
interface BeforeRMActionExecution extends ClassPolicy
|
||||
@@ -146,4 +148,22 @@ public interface RecordsManagementPolicies
|
||||
{
|
||||
void onRecordDeclaration(NodeRef nodeRef);
|
||||
}
|
||||
|
||||
/**
|
||||
* Before record rejection
|
||||
* @since 2.5
|
||||
*/
|
||||
interface BeforeRecordRejection extends ClassPolicy
|
||||
{
|
||||
void beforeRecordRejection(NodeRef nodeRef);
|
||||
}
|
||||
|
||||
/**
|
||||
* On record rejection
|
||||
* @since 2.5
|
||||
*/
|
||||
interface OnRecordRejection extends ClassPolicy
|
||||
{
|
||||
void onRecordRejection(NodeRef nodeRef);
|
||||
}
|
||||
}
|
||||
|
@@ -51,8 +51,10 @@ import org.alfresco.error.AlfrescoRuntimeException;
|
||||
import org.alfresco.model.ContentModel;
|
||||
import org.alfresco.module.org_alfresco_module_rm.RecordsManagementPolicies.BeforeFileRecord;
|
||||
import org.alfresco.module.org_alfresco_module_rm.RecordsManagementPolicies.BeforeRecordDeclaration;
|
||||
import org.alfresco.module.org_alfresco_module_rm.RecordsManagementPolicies.BeforeRecordRejection;
|
||||
import org.alfresco.module.org_alfresco_module_rm.RecordsManagementPolicies.OnFileRecord;
|
||||
import org.alfresco.module.org_alfresco_module_rm.RecordsManagementPolicies.OnRecordDeclaration;
|
||||
import org.alfresco.module.org_alfresco_module_rm.RecordsManagementPolicies.OnRecordRejection;
|
||||
import org.alfresco.module.org_alfresco_module_rm.capability.Capability;
|
||||
import org.alfresco.module.org_alfresco_module_rm.capability.CapabilityService;
|
||||
import org.alfresco.module.org_alfresco_module_rm.capability.RMPermissionModel;
|
||||
@@ -265,6 +267,8 @@ public class RecordServiceImpl extends BaseBehaviourBean
|
||||
private ClassPolicyDelegate<OnFileRecord> onFileRecord;
|
||||
private ClassPolicyDelegate<BeforeRecordDeclaration> beforeRecordDeclarationDelegate;
|
||||
private ClassPolicyDelegate<OnRecordDeclaration> onRecordDeclarationDelegate;
|
||||
private ClassPolicyDelegate<BeforeRecordRejection> beforeRecordRejectionDelegate;
|
||||
private ClassPolicyDelegate<OnRecordRejection> onRecordRejectionDelegate;
|
||||
|
||||
/**
|
||||
* @param identifierService identifier service
|
||||
@@ -420,6 +424,8 @@ public class RecordServiceImpl extends BaseBehaviourBean
|
||||
onFileRecord = policyComponent.registerClassPolicy(OnFileRecord.class);
|
||||
beforeRecordDeclarationDelegate = policyComponent.registerClassPolicy(BeforeRecordDeclaration.class);
|
||||
onRecordDeclarationDelegate = policyComponent.registerClassPolicy(OnRecordDeclaration.class);
|
||||
beforeRecordRejectionDelegate = policyComponent.registerClassPolicy(BeforeRecordRejection.class);
|
||||
onRecordRejectionDelegate = policyComponent.registerClassPolicy(OnRecordRejection.class);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1341,6 +1347,9 @@ public class RecordServiceImpl extends BaseBehaviourBean
|
||||
// Save the id of the currently logged in user
|
||||
final String userId = AuthenticationUtil.getFullyAuthenticatedUser();
|
||||
|
||||
// invoke policy
|
||||
invokeBeforeRecordRejection(nodeRef);
|
||||
|
||||
// do the work of rejecting the record as the system user
|
||||
AuthenticationUtil.runAsSystem(new RunAsWork<Void>()
|
||||
{
|
||||
@@ -1457,6 +1466,9 @@ public class RecordServiceImpl extends BaseBehaviourBean
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
// invoke policy
|
||||
invokeOnRecordRejection(nodeRef);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1853,4 +1865,32 @@ public class RecordServiceImpl extends BaseBehaviourBean
|
||||
OnRecordDeclaration policy = onRecordDeclarationDelegate.get(qnames);
|
||||
policy.onRecordDeclaration(nodeRef);
|
||||
}
|
||||
|
||||
/**
|
||||
* Invoke invokeBeforeRecordRejection policy
|
||||
*
|
||||
* @param nodeRef node reference
|
||||
*/
|
||||
protected void invokeBeforeRecordRejection(NodeRef nodeRef)
|
||||
{
|
||||
// get qnames to invoke against
|
||||
Set<QName> qnames = PoliciesUtil.getTypeAndAspectQNames(nodeService, nodeRef);
|
||||
// execute policy for node type and aspects
|
||||
BeforeRecordRejection policy = beforeRecordRejectionDelegate.get(qnames);
|
||||
policy.beforeRecordRejection(nodeRef);
|
||||
}
|
||||
|
||||
/**
|
||||
* Invoke invokeOnRecordRejection policy
|
||||
*
|
||||
* @param nodeRef node reference
|
||||
*/
|
||||
protected void invokeOnRecordRejection(NodeRef nodeRef)
|
||||
{
|
||||
// get qnames to invoke against
|
||||
Set<QName> qnames = PoliciesUtil.getTypeAndAspectQNames(nodeService, nodeRef);
|
||||
// execute policy for node type and aspects
|
||||
OnRecordRejection policy = onRecordRejectionDelegate.get(qnames);
|
||||
policy.onRecordRejection(nodeRef);
|
||||
}
|
||||
}
|
||||
|
@@ -35,7 +35,9 @@ import java.util.Set;
|
||||
import org.alfresco.model.ContentModel;
|
||||
import org.alfresco.module.org_alfresco_module_rm.RecordsManagementPolicies;
|
||||
import org.alfresco.module.org_alfresco_module_rm.RecordsManagementPolicies.BeforeRecordDeclaration;
|
||||
import org.alfresco.module.org_alfresco_module_rm.RecordsManagementPolicies.BeforeRecordRejection;
|
||||
import org.alfresco.module.org_alfresco_module_rm.RecordsManagementPolicies.OnRecordDeclaration;
|
||||
import org.alfresco.module.org_alfresco_module_rm.RecordsManagementPolicies.OnRecordRejection;
|
||||
import org.alfresco.module.org_alfresco_module_rm.capability.Capability;
|
||||
import org.alfresco.module.org_alfresco_module_rm.capability.RMPermissionModel;
|
||||
import org.alfresco.module.org_alfresco_module_rm.model.RecordsManagementModel;
|
||||
@@ -62,7 +64,10 @@ import org.alfresco.util.GUID;
|
||||
* @author Tuna Aksoy
|
||||
* @since 2.1
|
||||
*/
|
||||
public class RecordServiceImplTest extends BaseRMTestCase implements BeforeRecordDeclaration, OnRecordDeclaration
|
||||
public class RecordServiceImplTest extends BaseRMTestCase implements BeforeRecordDeclaration,
|
||||
OnRecordDeclaration,
|
||||
BeforeRecordRejection,
|
||||
OnRecordRejection
|
||||
{
|
||||
/**
|
||||
* This is a user test
|
||||
@@ -835,4 +840,62 @@ public class RecordServiceImplTest extends BaseRMTestCase implements BeforeRecor
|
||||
assertEquals(nodeRef, dmDocument);
|
||||
onRecordDeclaration = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* RM-5180 - integration test for policies for record rejection
|
||||
* @see RecordService#rejectRecord(org.alfresco.service.cmr.repository.NodeRef)
|
||||
*/
|
||||
private boolean beforeRecordRejection = false;
|
||||
private boolean onRecordRejection = false;
|
||||
|
||||
@Override
|
||||
public void beforeRecordRejection(NodeRef nodeRef)
|
||||
{
|
||||
assertEquals(nodeRef, dmDocument);
|
||||
beforeRecordRejection = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRecordRejection(NodeRef nodeRef)
|
||||
{
|
||||
assertEquals(nodeRef, dmDocument);
|
||||
onRecordRejection = true;
|
||||
}
|
||||
|
||||
public void testPolicyNotificationForRecordRejection() throws Exception
|
||||
{
|
||||
doTestInTransaction(new Test<Void>()
|
||||
{
|
||||
|
||||
@Override
|
||||
public Void run()
|
||||
{
|
||||
assertFalse(recordService.isRecord(dmDocument));
|
||||
|
||||
BehaviourDefinition<ClassBehaviourBinding> beforeRecordRejectionBehaviour = policyComponent.bindClassBehaviour(
|
||||
RecordsManagementPolicies.BEFORE_RECORD_REJECTION, ContentModel.TYPE_CONTENT,
|
||||
new JavaBehaviour(RecordServiceImplTest.this, "beforeRecordRejection", NotificationFrequency.EVERY_EVENT));
|
||||
BehaviourDefinition<ClassBehaviourBinding> onRecordRejectionBehaviour = policyComponent.bindClassBehaviour(
|
||||
RecordsManagementPolicies.ON_RECORD_REJECTION, ContentModel.TYPE_CONTENT,
|
||||
new JavaBehaviour(RecordServiceImplTest.this, "onRecordRejection", NotificationFrequency.EVERY_EVENT));
|
||||
|
||||
recordService.createRecord(filePlan, dmDocument);
|
||||
|
||||
assertFalse(beforeRecordRejection);
|
||||
assertFalse(onRecordRejection);
|
||||
assertTrue(recordService.isRecord(dmDocument));
|
||||
|
||||
recordService.rejectRecord(dmDocument, "test reasons");
|
||||
|
||||
assertTrue(beforeRecordRejection);
|
||||
assertTrue(onRecordRejection);
|
||||
assertFalse(recordService.isRecord(dmDocument));
|
||||
|
||||
policyComponent.removeClassDefinition(beforeRecordRejectionBehaviour);
|
||||
policyComponent.removeClassDefinition(onRecordRejectionBehaviour);
|
||||
|
||||
return null;
|
||||
}
|
||||
}, dmCollaborator);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user