Search in sources :

Example 6 with JavaBehaviour

use of org.alfresco.repo.policy.JavaBehaviour in project records-management by Alfresco.

the class RecordsManagementAdminServiceImplTest method testCreateReference.

public void testCreateReference() throws Exception {
    inTest = true;
    try {
        // Create the necessary test objects in the db: two records.
        final Pair<NodeRef, NodeRef> testRecords = retryingTransactionHelper.doInTransaction(new RetryingTransactionHelper.RetryingTransactionCallback<Pair<NodeRef, NodeRef>>() {

            public Pair<NodeRef, NodeRef> execute() throws Throwable {
                NodeRef rec1 = utils.createRecord(rmFolder, "testRecordA" + System.currentTimeMillis());
                NodeRef rec2 = utils.createRecord(rmFolder, "testRecordB" + System.currentTimeMillis());
                Pair<NodeRef, NodeRef> result = new Pair<NodeRef, NodeRef>(rec1, rec2);
                return result;
            }
        });
        final NodeRef testRecord1 = testRecords.getFirst();
        final NodeRef testRecord2 = testRecords.getSecond();
        retryingTransactionHelper.doInTransaction(new RetryingTransactionHelper.RetryingTransactionCallback<Void>() {

            public Void execute() throws Throwable {
                utils.completeRecord(testRecord1);
                utils.completeRecord(testRecord2);
                policyComponent.bindClassBehaviour(RecordsManagementPolicies.BEFORE_CREATE_REFERENCE, this, new JavaBehaviour(RecordsManagementAdminServiceImplTest.this, "beforeCreateReference", NotificationFrequency.EVERY_EVENT));
                policyComponent.bindClassBehaviour(RecordsManagementPolicies.ON_CREATE_REFERENCE, this, new JavaBehaviour(RecordsManagementAdminServiceImplTest.this, "onCreateReference", NotificationFrequency.EVERY_EVENT));
                assertFalse(beforeMarker);
                assertFalse(onMarker);
                relationshipService.addRelationship(CUSTOM_REF_VERSIONS.getLocalName(), testRecord1, testRecord2);
                assertTrue(beforeMarker);
                assertTrue(onMarker);
                return null;
            }
        });
    } finally {
        inTest = false;
    }
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) RetryingTransactionHelper(org.alfresco.repo.transaction.RetryingTransactionHelper) JavaBehaviour(org.alfresco.repo.policy.JavaBehaviour) Pair(org.alfresco.util.Pair)

Example 7 with JavaBehaviour

use of org.alfresco.repo.policy.JavaBehaviour in project records-management by Alfresco.

the class RecordsManagementActionServiceImplTest method executionImpl.

private void executionImpl() {
    inTest = true;
    try {
        policyComponent.bindClassBehaviour(RecordsManagementPolicies.BEFORE_RM_ACTION_EXECUTION, this, new JavaBehaviour(this, "beforeRMActionExecution", NotificationFrequency.EVERY_EVENT));
        policyComponent.bindClassBehaviour(RecordsManagementPolicies.ON_RM_ACTION_EXECUTION, this, new JavaBehaviour(this, "onRMActionExecution", NotificationFrequency.EVERY_EVENT));
        assertFalse(beforeMarker);
        assertFalse(onMarker);
        assertFalse(this.nodeService.hasAspect(this.nodeRef, ASPECT_RECORD));
        Map<String, Serializable> params = new HashMap<String, Serializable>(1);
        params.put(TestAction.PARAM, TestAction.PARAM_VALUE);
        this.rmActionService.executeRecordsManagementAction(this.nodeRef, TestAction.NAME, params);
        assertTrue(beforeMarker);
        assertTrue(onMarker);
        assertTrue(this.nodeService.hasAspect(this.nodeRef, ASPECT_RECORD));
    } finally {
        inTest = false;
    }
}
Also used : Serializable(java.io.Serializable) HashMap(java.util.HashMap) JavaBehaviour(org.alfresco.repo.policy.JavaBehaviour)

Aggregations

JavaBehaviour (org.alfresco.repo.policy.JavaBehaviour)7 HashMap (java.util.HashMap)2 NodeRef (org.alfresco.service.cmr.repository.NodeRef)2 InputStream (java.io.InputStream)1 Serializable (java.io.Serializable)1 AlfrescoRuntimeException (org.alfresco.error.AlfrescoRuntimeException)1 AuditEvent (org.alfresco.module.org_alfresco_module_rm.audit.event.AuditEvent)1 RetryingTransactionHelper (org.alfresco.repo.transaction.RetryingTransactionHelper)1 Pair (org.alfresco.util.Pair)1 Test (org.junit.Test)1