Search in sources :

Example 6 with Behaviour

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

the class CmObjectType method onMoveNode.

/**
 * @see org.alfresco.repo.node.NodeServicePolicies.OnMoveNodePolicy#onMoveNode(org.alfresco.service.cmr.repository.ChildAssociationRef, org.alfresco.service.cmr.repository.ChildAssociationRef)
 */
@Override
@Behaviour(kind = BehaviourKind.CLASS, name = MOVE_BEHAVIOUR_NAME)
public void onMoveNode(ChildAssociationRef oldChildAssocRef, ChildAssociationRef newChildAssocRef) {
    mandatory("oldChildAssocRef", oldChildAssocRef);
    mandatory("newChildAssocRef", newChildAssocRef);
    NodeRef sourceParent = oldChildAssocRef.getParentRef();
    boolean isSourceParentFilePlanComponent = isFilePlanComponent(sourceParent);
    NodeRef targetParent = newChildAssocRef.getParentRef();
    boolean isTargetParentFilePlanComponent = isFilePlanComponent(targetParent);
    // The method should just check move operations from outside of RM into the RM site
    if (isSourceParentFilePlanComponent && isTargetParentFilePlanComponent) {
        return;
    }
    NodeRef object = oldChildAssocRef.getChildRef();
    QName objectType = nodeService.getType(object);
    // Only documents can be moved into the RM site
    if (!objectType.equals(ContentModel.TYPE_CONTENT) && isTargetParentFilePlanComponent) {
        throw new AlfrescoRuntimeException("Only documents can be moved from a collaboration site into a RM site.");
    }
    // Documents can be moved only into a RM folder
    if (isTargetParentFilePlanComponent && !isRecordFolder(targetParent)) {
        throw new AlfrescoRuntimeException("A document can only be moved into a folder in RM site.");
    }
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) QName(org.alfresco.service.namespace.QName) AlfrescoRuntimeException(org.alfresco.error.AlfrescoRuntimeException) Behaviour(org.alfresco.repo.policy.annotation.Behaviour)

Example 7 with Behaviour

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

the class OnReferenceCreateEventType method onCreateReference.

/**
 * @see org.alfresco.module.org_alfresco_module_rm.RecordsManagementPolicies.OnCreateReference#onCreateReference(org.alfresco.service.cmr.repository.NodeRef, org.alfresco.service.cmr.repository.NodeRef, org.alfresco.service.namespace.QName)
 */
@Override
@Behaviour(kind = BehaviourKind.CLASS, type = "rma:record", notificationFrequency = NotificationFrequency.TRANSACTION_COMMIT)
public void onCreateReference(final NodeRef fromNodeRef, final NodeRef toNodeRef, final QName reference) {
    AuthenticationUtil.RunAsWork<Object> work = new AuthenticationUtil.RunAsWork<Object>() {

        public Object doWork() {
            // Check whether it is the reference type we care about
            if (reference.equals(OnReferenceCreateEventType.this.reference)) {
                DispositionAction da = dispositionService.getNextDispositionAction(toNodeRef);
                if (da != null) {
                    List<EventCompletionDetails> events = da.getEventCompletionDetails();
                    for (EventCompletionDetails event : events) {
                        RecordsManagementEvent rmEvent = getRecordsManagementEventService().getEvent(event.getEventName());
                        if (!event.isEventComplete() && rmEvent.getType().equals(getName())) {
                            // Complete the event
                            Map<String, Serializable> params = new HashMap<String, Serializable>(3);
                            params.put(CompleteEventAction.PARAM_EVENT_NAME, event.getEventName());
                            params.put(CompleteEventAction.PARAM_EVENT_COMPLETED_BY, AuthenticationUtil.getFullyAuthenticatedUser());
                            params.put(CompleteEventAction.PARAM_EVENT_COMPLETED_AT, new Date());
                            recordsManagementActionService.executeRecordsManagementAction(toNodeRef, "completeEvent", params);
                            break;
                        }
                    }
                }
            }
            return null;
        }
    };
    AuthenticationUtil.runAs(work, AuthenticationUtil.getAdminUserName());
}
Also used : Serializable(java.io.Serializable) HashMap(java.util.HashMap) Date(java.util.Date) AuthenticationUtil(org.alfresco.repo.security.authentication.AuthenticationUtil) DispositionAction(org.alfresco.module.org_alfresco_module_rm.disposition.DispositionAction) Behaviour(org.alfresco.repo.policy.annotation.Behaviour)

Example 8 with Behaviour

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

the class HoldServiceImpl method beforeDeleteNode.

/**
 * Behaviour unfreezes node's that will no longer he held after delete.
 *
 * @see org.alfresco.repo.node.NodeServicePolicies.BeforeDeleteNodePolicy#beforeDeleteNode(org.alfresco.service.cmr.repository.NodeRef)
 */
@Behaviour(kind = BehaviourKind.CLASS, type = "rma:hold", notificationFrequency = NotificationFrequency.EVERY_EVENT)
@Override
public void beforeDeleteNode(final NodeRef hold) {
    if (nodeService.exists(hold) && isHold(hold)) {
        RunAsWork<Void> work = new RunAsWork<Void>() {

            @Override
            public Void doWork() {
                List<NodeRef> frozenNodes = getHeld(hold);
                for (NodeRef frozenNode : frozenNodes) {
                    removeFreezeAspect(frozenNode, 1);
                }
                return null;
            }
        };
        // run as system user
        authenticationUtil.runAsSystem(work);
    }
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) RunAsWork(org.alfresco.repo.security.authentication.AuthenticationUtil.RunAsWork) Behaviour(org.alfresco.repo.policy.annotation.Behaviour)

Example 9 with Behaviour

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

the class OnReferencedRecordActionedUpon method beforeRMActionExecution.

/**
 * Before action exeuction behaviour.
 *
 * @param nodeRef
 * @param name
 * @param parameters
 */
@Override
@Behaviour(kind = BehaviourKind.CLASS, type = "rma:filePlanComponent", notificationFrequency = NotificationFrequency.FIRST_EVENT)
public void beforeRMActionExecution(final NodeRef nodeRef, final String name, final Map<String, Serializable> parameters) {
    AuthenticationUtil.RunAsWork<Object> work = new AuthenticationUtil.RunAsWork<Object>() {

        public Object doWork() {
            if (nodeService.exists(nodeRef) && name.equals(actionName)) {
                QName type = nodeService.getType(nodeRef);
                if (TYPE_TRANSFER.equals(type)) {
                    List<ChildAssociationRef> assocs = nodeService.getChildAssocs(nodeRef, ASSOC_TRANSFERRED, RegexQNamePattern.MATCH_ALL);
                    for (ChildAssociationRef assoc : assocs) {
                        processRecordFolder(assoc.getChildRef());
                    }
                } else {
                    processRecordFolder(nodeRef);
                }
            }
            return null;
        }
    };
    AuthenticationUtil.runAs(work, AuthenticationUtil.getAdminUserName());
}
Also used : AuthenticationUtil(org.alfresco.repo.security.authentication.AuthenticationUtil) QName(org.alfresco.service.namespace.QName) ChildAssociationRef(org.alfresco.service.cmr.repository.ChildAssociationRef) Behaviour(org.alfresco.repo.policy.annotation.Behaviour)

Example 10 with Behaviour

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

the class VitalRecordServiceImpl method onFileRecord.

/**
 * Behavior to initialize vital record.
 *
 * @see org.alfresco.module.org_alfresco_module_rm.RecordsManagementPolicies.OnFileRecord#onFileRecord(org.alfresco.service.cmr.repository.NodeRef)
 * @since 2.2
 */
@Override
@Behaviour(kind = BehaviourKind.CLASS, type = "rma:record")
public void onFileRecord(NodeRef nodeRef) {
    // Calculate the review schedule
    VitalRecordDefinition viDef = getVitalRecordDefinition(nodeRef);
    if (viDef != null && viDef.isEnabled()) {
        Date reviewAsOf = viDef.getNextReviewDate();
        if (reviewAsOf != null) {
            Map<QName, Serializable> reviewProps = new HashMap<QName, Serializable>(1);
            reviewProps.put(RecordsManagementModel.PROP_REVIEW_AS_OF, reviewAsOf);
            if (!nodeService.hasAspect(nodeRef, ASPECT_VITAL_RECORD)) {
                nodeService.addAspect(nodeRef, RecordsManagementModel.ASPECT_VITAL_RECORD, reviewProps);
            } else {
                Map<QName, Serializable> props = nodeService.getProperties(nodeRef);
                props.putAll(reviewProps);
                nodeService.setProperties(nodeRef, props);
            }
        }
    } else {
        // if we are re-filling then remove the vital aspect if it is not longer a vital record
        if (nodeService.hasAspect(nodeRef, ASPECT_VITAL_RECORD)) {
            nodeService.removeAspect(nodeRef, ASPECT_VITAL_RECORD);
        }
    }
}
Also used : Serializable(java.io.Serializable) HashMap(java.util.HashMap) QName(org.alfresco.service.namespace.QName) Date(java.util.Date) Behaviour(org.alfresco.repo.policy.annotation.Behaviour)

Aggregations

Behaviour (org.alfresco.repo.policy.annotation.Behaviour)18 NodeRef (org.alfresco.service.cmr.repository.NodeRef)10 QName (org.alfresco.service.namespace.QName)7 Serializable (java.io.Serializable)3 Date (java.util.Date)3 HashMap (java.util.HashMap)3 AlfrescoRuntimeException (org.alfresco.error.AlfrescoRuntimeException)3 AuthenticationUtil (org.alfresco.repo.security.authentication.AuthenticationUtil)3 IntegrityException (org.alfresco.repo.node.integrity.IntegrityException)2 Calendar (java.util.Calendar)1 Map (java.util.Map)1 DispositionAction (org.alfresco.module.org_alfresco_module_rm.disposition.DispositionAction)1 ModelAccessDeniedException (org.alfresco.module.org_alfresco_module_rm.model.security.ModelAccessDeniedException)1 RunAsWork (org.alfresco.repo.security.authentication.AuthenticationUtil.RunAsWork)1 ChildAssociationRef (org.alfresco.service.cmr.repository.ChildAssociationRef)1 ContentData (org.alfresco.service.cmr.repository.ContentData)1 AccessStatus (org.alfresco.service.cmr.security.AccessStatus)1 SiteInfo (org.alfresco.service.cmr.site.SiteInfo)1 PropertyMap (org.alfresco.util.PropertyMap)1