Search in sources :

Example 1 with JavaBehaviour

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

the class RecordsManagementSearchBehaviour method init.

/**
 * Initialisation method
 */
public void init() {
    this.policyComponent.bindClassBehaviour(QName.createQName(NamespaceService.ALFRESCO_URI, "onCreateNode"), TYPE_DISPOSITION_ACTION, jbDispositionActionCreate);
    this.policyComponent.bindClassBehaviour(QName.createQName(NamespaceService.ALFRESCO_URI, "onUpdateProperties"), TYPE_DISPOSITION_ACTION, jbDispositionActionPropertiesUpdate);
    this.policyComponent.bindClassBehaviour(QName.createQName(NamespaceService.ALFRESCO_URI, "onUpdateProperties"), TYPE_DISPOSITION_SCHEDULE, jbDispositionSchedulePropertiesUpdate);
    this.policyComponent.bindAssociationBehaviour(QName.createQName(NamespaceService.ALFRESCO_URI, "onCreateChildAssociation"), TYPE_DISPOSITION_ACTION, ASSOC_EVENT_EXECUTIONS, jbEventExecutionUpdate);
    this.policyComponent.bindClassBehaviour(QName.createQName(NamespaceService.ALFRESCO_URI, "onDeleteNode"), TYPE_EVENT_EXECUTION, jbEventExecutionDelete);
    this.policyComponent.bindClassBehaviour(QName.createQName(NamespaceService.ALFRESCO_URI, "onAddAspect"), ASPECT_RM_SEARCH, onAddSearchAspect);
    this.policyComponent.bindClassBehaviour(QName.createQName(NamespaceService.ALFRESCO_URI, "onAddAspect"), ASPECT_DISPOSITION_LIFECYCLE, jbDispositionLifeCycleAspect);
    this.policyComponent.bindClassBehaviour(QName.createQName(NamespaceService.ALFRESCO_URI, "onAddAspect"), ASPECT_RECORD, new JavaBehaviour(this, "onAddRecordAspect", NotificationFrequency.TRANSACTION_COMMIT));
    this.policyComponent.bindClassBehaviour(QName.createQName(NamespaceService.ALFRESCO_URI, "onCreateNode"), TYPE_RECORD_FOLDER, new JavaBehaviour(this, "recordFolderCreate", NotificationFrequency.TRANSACTION_COMMIT));
    this.policyComponent.bindClassBehaviour(QName.createQName(NamespaceService.ALFRESCO_URI, "onSetNodeType"), TYPE_RECORD_FOLDER, new JavaBehaviour(this, "convertedToOrFromRecordFolder", NotificationFrequency.TRANSACTION_COMMIT));
    // Vital Records Review Details Rollup
    this.policyComponent.bindClassBehaviour(QName.createQName(NamespaceService.ALFRESCO_URI, "onAddAspect"), ASPECT_VITAL_RECORD_DEFINITION, new JavaBehaviour(this, "vitalRecordDefintionAddAspect", NotificationFrequency.TRANSACTION_COMMIT));
    this.policyComponent.bindClassBehaviour(QName.createQName(NamespaceService.ALFRESCO_URI, "onUpdateProperties"), ASPECT_VITAL_RECORD_DEFINITION, new JavaBehaviour(this, "vitalRecordDefintionUpdateProperties", NotificationFrequency.TRANSACTION_COMMIT));
}
Also used : JavaBehaviour(org.alfresco.repo.policy.JavaBehaviour)

Example 2 with JavaBehaviour

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

the class ProtectedAspects method init.

/**
 * Initialise method
 */
public void init() {
    // Watch removal of the aspect rma:record
    this.policyComponent.bindClassBehaviour(NodeServicePolicies.OnRemoveAspectPolicy.QNAME, RecordsManagementModel.ASPECT_RECORD, new JavaBehaviour(this, "onRemoveAspect"));
    // Watch removal of the aspect rma:filePlanComponent
    this.policyComponent.bindClassBehaviour(NodeServicePolicies.OnRemoveAspectPolicy.QNAME, RecordsManagementModel.ASPECT_FILE_PLAN_COMPONENT, new JavaBehaviour(this, "onRemoveAspect"));
    // Watch removal of the aspect rma:recordComponentIdentifier
    this.policyComponent.bindClassBehaviour(NodeServicePolicies.OnRemoveAspectPolicy.QNAME, RecordsManagementModel.ASPECT_RECORD_COMPONENT_ID, new JavaBehaviour(this, "onRemoveAspect"));
    // Watch removal of the aspect  rma:commonRecordDetails
    this.policyComponent.bindClassBehaviour(NodeServicePolicies.OnRemoveAspectPolicy.QNAME, RecordsManagementModel.ASPECT_COMMON_RECORD_DETAILS, new JavaBehaviour(this, "onRemoveAspect"));
}
Also used : JavaBehaviour(org.alfresco.repo.policy.JavaBehaviour)

Example 3 with JavaBehaviour

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

the class FilePlanPermissionServiceImpl method init.

/**
 * Initialisation method
 */
public void init() {
    getPolicyComponent().bindClassBehaviour(NodeServicePolicies.OnAddAspectPolicy.QNAME, ASPECT_RECORD, new JavaBehaviour(this, "onAddRecord", TRANSACTION_COMMIT));
    getPolicyComponent().bindClassBehaviour(NodeServicePolicies.OnMoveNodePolicy.QNAME, ASPECT_RECORD, new JavaBehaviour(this, "onMoveRecord", TRANSACTION_COMMIT));
    getPolicyComponent().bindClassBehaviour(NodeServicePolicies.OnMoveNodePolicy.QNAME, TYPE_RECORD_CATEGORY, new JavaBehaviour(this, "onMoveNode", TRANSACTION_COMMIT));
    AuthenticationUtil.runAsSystem(new RunAsWork<Void>() {

        @Override
        public Void doWork() throws Exception {
            recordsManagementAuditService.registerAuditEvent(new AuditEvent(AUDIT_SET_PERMISSION, "rm.audit.set-permission"));
            return null;
        }
    });
}
Also used : AuditEvent(org.alfresco.module.org_alfresco_module_rm.audit.event.AuditEvent) JavaBehaviour(org.alfresco.repo.policy.JavaBehaviour) AlfrescoRuntimeException(org.alfresco.error.AlfrescoRuntimeException)

Example 4 with JavaBehaviour

use of org.alfresco.repo.policy.JavaBehaviour in project alfresco-remote-api by Alfresco.

the class WebDAVonContentUpdateTest method testUploadNewContentFiresContentUpdatePolicies.

/**
 * Put a content file and check that onContentUpdate fired
 * <p>
 * Lock the file
 * <p>
 * Put the contents
 * <p>
 * Unlock the node
 */
@Test
public void testUploadNewContentFiresContentUpdatePolicies() throws Exception {
    flag = false;
    counter = 0;
    policyComponent.bindClassBehaviour(OnContentUpdatePolicy.QNAME, ContentModel.TYPE_CONTENT, new JavaBehaviour(this, "doOnContentUpdate"));
    String fileName = "file-" + GUID.generate();
    NodeRef fileNoderef = null;
    try {
        executeMethod(WebDAV.METHOD_LOCK, fileName, davLockInfoFile, null);
        List<NodeRef> refs = searchService.selectNodes(nodeService.getRootNode(storeRef), "/app:company_home/cm:" + fileName, null, namespaceService, false);
        fileNoderef = refs.get(0);
        assertEquals("File should be locked", LockStatus.LOCK_OWNER, lockService.getLockStatus(fileNoderef));
    } catch (Exception e) {
        fail("Failed to lock a file: " + (e.getCause() != null ? e.getCause().getMessage() : e.getMessage()));
    }
    txn.commit();
    txn = transactionService.getUserTransaction();
    txn.begin();
    // Construct IF HEADER
    String lockToken = fileNoderef.getId() + WebDAV.LOCK_TOKEN_SEPERATOR + AuthenticationUtil.getAdminUserName();
    String lockHeaderValue = "(<" + WebDAV.OPAQUE_LOCK_TOKEN + lockToken + ">)";
    HashMap<String, String> headers = new HashMap<String, String>();
    headers.put(WebDAV.HEADER_IF, lockHeaderValue);
    try {
        executeMethod(WebDAV.METHOD_PUT, fileName, testDataFile, headers);
        assertTrue("File does not exist.", nodeService.exists(fileNoderef));
        assertEquals("Filename is not correct", fileName, nodeService.getProperty(fileNoderef, ContentModel.PROP_NAME));
        assertTrue("Expected return status is " + HttpServletResponse.SC_NO_CONTENT + ", but returned is " + response.getStatus(), HttpServletResponse.SC_NO_CONTENT == response.getStatus());
        assertTrue("File should have NO_CONTENT aspect", nodeService.hasAspect(fileNoderef, ContentModel.ASPECT_NO_CONTENT));
        InputStream updatedFileIS = fileFolderService.getReader(fileNoderef).getContentInputStream();
        byte[] updatedFile = IOUtils.toByteArray(updatedFileIS);
        updatedFileIS.close();
        assertTrue("The content has to be equal", ArrayUtils.isEquals(testDataFile, updatedFile));
    } catch (Exception e) {
        fail("Failed to upload a file: " + (e.getCause() != null ? e.getCause().getMessage() : e.getMessage()));
    }
    txn.commit();
    txn = transactionService.getUserTransaction();
    txn.begin();
    headers = new HashMap<String, String>();
    headers.put(WebDAV.HEADER_LOCK_TOKEN, "<" + WebDAV.OPAQUE_LOCK_TOKEN + lockToken + ">");
    try {
        executeMethod(WebDAV.METHOD_UNLOCK, fileName, null, headers);
        assertTrue("Expected return status is " + HttpServletResponse.SC_NO_CONTENT + ", but returned is " + response.getStatus(), HttpServletResponse.SC_NO_CONTENT == response.getStatus());
        assertFalse("File should not have NO_CONTENT aspect", nodeService.hasAspect(fileNoderef, ContentModel.ASPECT_NO_CONTENT));
        assertEquals("File should be unlocked", LockStatus.NO_LOCK, lockService.getLockStatus(fileNoderef));
    } catch (Exception e) {
        fail("Failed to unlock a file: " + (e.getCause() != null ? e.getCause().getMessage() : e.getMessage()));
    }
    assertTrue("onContentUpdate policies were not triggered", flag);
    assertEquals("onContentUpdate policies should be triggered only once", counter, 1);
    if (fileNoderef != null) {
        nodeService.deleteNode(fileNoderef);
    }
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) HashMap(java.util.HashMap) InputStream(java.io.InputStream) JavaBehaviour(org.alfresco.repo.policy.JavaBehaviour) Test(org.junit.Test)

Example 5 with JavaBehaviour

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

the class JSONConversionComponent method init.

/**
 * The initialise method
 */
public void init() {
    policyComponent.bindClassBehaviour(QName.createQName(NamespaceService.ALFRESCO_URI, "onDeleteNode"), RecordsManagementModel.TYPE_RM_SITE, new JavaBehaviour(this, "onDeleteNode"));
    policyComponent.bindClassBehaviour(QName.createQName(NamespaceService.ALFRESCO_URI, "onCreateNode"), RecordsManagementModel.TYPE_RM_SITE, new JavaBehaviour(this, "onCreateNode"));
}
Also used : 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