Search in sources :

Example 1 with Behaviour

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

the class RecordServiceImpl method onRemoveAspect.

/**
 * @see org.alfresco.repo.node.NodeServicePolicies.OnRemoveAspectPolicy#onRemoveAspect(org.alfresco.service.cmr.repository.NodeRef, org.alfresco.service.namespace.QName)
 */
@Override
@Behaviour(kind = BehaviourKind.CLASS, type = "sys:noContent")
public void onRemoveAspect(NodeRef nodeRef, QName aspect) {
    if (nodeService.hasAspect(nodeRef, ASPECT_RECORD)) {
        ContentData contentData = (ContentData) nodeService.getProperty(nodeRef, ContentModel.PROP_CONTENT);
        if (ContentData.hasContent(contentData) && contentData.getSize() > 0) {
            appendIdentifierToName(nodeService, nodeRef);
            reevaluateIncompleteTag(nodeRef);
        }
    }
}
Also used : ContentData(org.alfresco.service.cmr.repository.ContentData) Behaviour(org.alfresco.repo.policy.annotation.Behaviour)

Example 2 with Behaviour

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

the class RecordFolderType method onCreateChildAssociationOnCommit.

/**
 * On transaction commit
 *
 * @see org.alfresco.repo.node.NodeServicePolicies.OnCreateChildAssociationPolicy#onCreateChildAssociation(org.alfresco.service.cmr.repository.ChildAssociationRef, boolean)
 */
@Behaviour(kind = BehaviourKind.ASSOCIATION, policy = "alf:onCreateChildAssociation", notificationFrequency = NotificationFrequency.TRANSACTION_COMMIT)
public void onCreateChildAssociationOnCommit(ChildAssociationRef childAssocRef, boolean bNew) {
    final NodeRef child = childAssocRef.getChildRef();
    if (!nodeService.exists(child)) {
        return;
    }
    // only records can be added in a record folder or hidden folders(is the case of e-mail attachments)
    if (instanceOf(child, ContentModel.TYPE_FOLDER) && !nodeService.hasAspect(child, ContentModel.ASPECT_HIDDEN)) {
        throw new IntegrityException(I18NUtil.getMessage(MSG_CANNOT_CREATE_RECORD_FOLDER_CHILD, nodeService.getType(child)), null);
    }
    behaviourFilter.disableBehaviour();
    try {
        AuthenticationUtil.runAsSystem(new RunAsWork<Void>() {

            @Override
            public Void doWork() {
                // setup vital record definition
                vitalRecordService.setupVitalRecordDefinition(child);
                return null;
            }
        });
    } finally {
        behaviourFilter.enableBehaviour();
    }
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) IntegrityException(org.alfresco.repo.node.integrity.IntegrityException) Behaviour(org.alfresco.repo.policy.annotation.Behaviour)

Example 3 with Behaviour

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

the class RmSiteType method beforeDeleteNode.

/**
 * @see org.alfresco.repo.node.NodeServicePolicies.BeforeDeleteNodePolicy#beforeDeleteNode(org.alfresco.service.cmr.repository.NodeRef)
 */
@Behaviour(kind = BehaviourKind.CLASS, notificationFrequency = NotificationFrequency.FIRST_EVENT)
public void beforeDeleteNode(NodeRef nodeRef) {
    final SiteInfo siteInfo = siteService.getSite(nodeRef);
    if (siteInfo != null) {
        // grab the file plan for the RM site
        NodeRef filePlan = AuthenticationUtil.runAsSystem(new RunAsWork<NodeRef>() {

            @Override
            public NodeRef doWork() {
                return siteService.getContainer(siteInfo.getShortName(), COMPONENT_DOCUMENT_LIBRARY);
            }
        });
        if (filePlan != null) {
            // determine whether the current user has delete capability on the file plan node
            AccessStatus accessStatus = capabilityService.getCapabilityAccessState(filePlan, "Delete");
            if (AccessStatus.DENIED.equals(accessStatus)) {
                throw new AlfrescoRuntimeException("The records management site can not be deleted, because the user doesn't have sufficient privillages to delete the file plan.");
            }
            // work around for MNT-11038 .. we want to ensure that the RM site can be created once it's been deleted since we only
            // allow one short name for the RM site
            AuthenticationUtil.runAsSystem(new RunAsWork<Void>() {

                @Override
                public Void doWork() {
                    // delete the authority
                    String siteGroup = siteService.getSiteGroup(siteInfo.getShortName());
                    authorityService.deleteAuthority(siteGroup, true);
                    return null;
                }
            });
            filePlanType.disable();
        }
    }
}
Also used : SiteInfo(org.alfresco.service.cmr.site.SiteInfo) NodeRef(org.alfresco.service.cmr.repository.NodeRef) AlfrescoRuntimeException(org.alfresco.error.AlfrescoRuntimeException) AccessStatus(org.alfresco.service.cmr.security.AccessStatus) Behaviour(org.alfresco.repo.policy.annotation.Behaviour)

Example 4 with Behaviour

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

the class RecordCategoryType method onCreateChildAssociationOnCommit.

/**
 * On transaction commit
 *
 * @see org.alfresco.repo.node.NodeServicePolicies.OnCreateChildAssociationPolicy#onCreateChildAssociation(org.alfresco.service.cmr.repository.ChildAssociationRef, boolean)
 */
@Behaviour(kind = BehaviourKind.ASSOCIATION, policy = "alf:onCreateChildAssociation", notificationFrequency = NotificationFrequency.TRANSACTION_COMMIT)
public void onCreateChildAssociationOnCommit(ChildAssociationRef childAssocRef, final boolean bNew) {
    final NodeRef child = childAssocRef.getChildRef();
    behaviourFilter.disableBehaviour();
    try {
        AuthenticationUtil.runAsSystem(new RunAsWork<Void>() {

            @Override
            public Void doWork() {
                // setup vital record definition
                if (nodeService.exists(child)) {
                    vitalRecordService.setupVitalRecordDefinition(child);
                }
                return null;
            }
        });
    } finally {
        behaviourFilter.enableBehaviour();
    }
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) Behaviour(org.alfresco.repo.policy.annotation.Behaviour)

Example 5 with Behaviour

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

the class CmObjectType method beforeCopy.

/**
 * @see org.alfresco.repo.copy.CopyServicePolicies.BeforeCopyPolicy#beforeCopy(org.alfresco.service.namespace.QName, org.alfresco.service.cmr.repository.NodeRef, org.alfresco.service.cmr.repository.NodeRef)
 */
@Override
@Behaviour(kind = BehaviourKind.CLASS, name = COPY_BEHAVIOUR_NAME)
public void beforeCopy(QName classRef, NodeRef sourceNodeRef, NodeRef targetNodeRef) {
    mandatory("sourceNodeRef", sourceNodeRef);
    mandatory("targetNodeRef", targetNodeRef);
    NodeRef sourceParentNodeRef = nodeService.getPrimaryParent(sourceNodeRef).getParentRef();
    boolean isSourceParentFilePlanComponent = isFilePlanComponent(sourceParentNodeRef);
    NodeRef targetParentNodeRef = nodeService.getPrimaryParent(targetNodeRef).getParentRef();
    boolean isTargetNodeParentFilePlanComponent = isFilePlanComponent(targetParentNodeRef);
    // The method should just check copy operations from outside of RM into the RM site
    if (isSourceParentFilePlanComponent && isTargetNodeParentFilePlanComponent) {
        return;
    }
    // Do not allow to copy anything outside of RM site into the RM site
    if (!isSourceParentFilePlanComponent && isTargetNodeParentFilePlanComponent) {
        throw new AlfrescoRuntimeException("Nothing can be copied from a collaboration site into a RM site.");
    }
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) AlfrescoRuntimeException(org.alfresco.error.AlfrescoRuntimeException) 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