Search in sources :

Example 11 with Behaviour

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

the class RecordServiceImpl method onUpdateProperties.

/**
 * Ensure that the user only updates record properties that they have permission to.
 *
 * @see org.alfresco.repo.node.NodeServicePolicies.OnUpdatePropertiesPolicy#onUpdateProperties(org.alfresco.service.cmr.repository.NodeRef, java.util.Map, java.util.Map)
 */
@Override
@Behaviour(name = "onUpdateProperties", kind = BehaviourKind.CLASS, type = "rma:record")
public void onUpdateProperties(final NodeRef nodeRef, final Map<QName, Serializable> before, final Map<QName, Serializable> after) {
    if (AuthenticationUtil.getFullyAuthenticatedUser() != null && !AuthenticationUtil.isRunAsUserTheSystemUser() && nodeService.exists(nodeRef) && isRecord(nodeRef) && !transactionalResourceHelper.getSet(KEY_IGNORE_ON_UPDATE).contains(nodeRef)) {
        for (Map.Entry<QName, Serializable> entry : after.entrySet()) {
            Serializable beforeValue = null;
            QName property = entry.getKey();
            if (before != null) {
                beforeValue = before.get(property);
            }
            Serializable afterValue = entry.getValue();
            boolean propertyUnchanged = false;
            if (beforeValue instanceof Date && afterValue instanceof Date) {
                // deal with date values, remove the seconds and milliseconds for the
                // comparison as they are removed from the submitted for data
                Calendar beforeCal = Calendar.getInstance();
                beforeCal.setTime((Date) beforeValue);
                Calendar afterCal = Calendar.getInstance();
                afterCal.setTime((Date) afterValue);
                beforeCal.set(Calendar.SECOND, 0);
                beforeCal.set(Calendar.MILLISECOND, 0);
                afterCal.set(Calendar.SECOND, 0);
                afterCal.set(Calendar.MILLISECOND, 0);
                propertyUnchanged = (beforeCal.compareTo(afterCal) == 0);
            } else if ((afterValue instanceof Boolean) && (beforeValue == null) && (afterValue.equals(Boolean.FALSE))) {
                propertyUnchanged = true;
            } else {
                // otherwise
                propertyUnchanged = EqualsHelper.nullSafeEquals(beforeValue, afterValue);
            }
            if (!propertyUnchanged && !(ContentModel.PROP_CONTENT.equals(property) && beforeValue == null) && !isPropertyEditable(nodeRef, property)) {
                // the user can't edit the record property
                throw new ModelAccessDeniedException("The user " + AuthenticationUtil.getFullyAuthenticatedUser() + " does not have the permission to edit the record property " + property.toString() + " on the node " + nodeRef.toString());
            }
        }
    }
}
Also used : Serializable(java.io.Serializable) QName(org.alfresco.service.namespace.QName) Calendar(java.util.Calendar) Map(java.util.Map) PropertyMap(org.alfresco.util.PropertyMap) HashMap(java.util.HashMap) ModelAccessDeniedException(org.alfresco.module.org_alfresco_module_rm.model.security.ModelAccessDeniedException) Date(java.util.Date) Behaviour(org.alfresco.repo.policy.annotation.Behaviour)

Example 12 with Behaviour

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

the class FilePlanType method onCreateNode.

/**
 * @see org.alfresco.repo.node.NodeServicePolicies.OnCreateNodePolicy#onCreateNode(org.alfresco.service.cmr.repository.ChildAssociationRef)
 */
@Behaviour(kind = BehaviourKind.CLASS, notificationFrequency = NotificationFrequency.TRANSACTION_COMMIT)
@Override
public void onCreateNode(final ChildAssociationRef childAssocRef) {
    final NodeRef filePlan = childAssocRef.getChildRef();
    AuthenticationUtil.runAsSystem(new RunAsWork<Object>() {

        public Object doWork() {
            // ensure rules are not inherited
            nodeService.addAspect(filePlan, RuleModel.ASPECT_IGNORE_INHERITED_RULES, null);
            // set the identifier
            if (nodeService.getProperty(filePlan, PROP_IDENTIFIER) == null) {
                String id = getIdentifierService().generateIdentifier(filePlan);
                nodeService.setProperty(filePlan, RecordsManagementModel.PROP_IDENTIFIER, id);
            }
            return null;
        }
    });
    // setup the file plan roles
    getFilePlanRoleService().setupFilePlanRoles(filePlan);
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) Behaviour(org.alfresco.repo.policy.annotation.Behaviour)

Example 13 with Behaviour

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

the class RecordFolderType method onCreateChildAssociation.

/**
 * @see org.alfresco.repo.node.NodeServicePolicies.OnCreateChildAssociationPolicy#onCreateChildAssociation(org.alfresco.service.cmr.repository.ChildAssociationRef, boolean)
 */
@Override
@Behaviour(kind = BehaviourKind.ASSOCIATION, notificationFrequency = NotificationFrequency.FIRST_EVENT)
public void onCreateChildAssociation(ChildAssociationRef childAssocRef, boolean bNew) {
    NodeRef nodeRef = childAssocRef.getChildRef();
    if (nodeService.exists(nodeRef)) {
        boolean notFolderOrRmFolderSubType = !instanceOf(nodeRef, ContentModel.TYPE_FOLDER) || instanceOf(nodeRef, RecordsManagementModel.TYPE_RECORDS_MANAGEMENT_CONTAINER) || instanceOf(nodeRef, RecordsManagementModel.TYPE_RECORD_FOLDER) || instanceOf(nodeRef, RecordsManagementModel.TYPE_TRANSFER);
        if (!instanceOf(nodeRef, ContentModel.TYPE_CONTENT) && notFolderOrRmFolderSubType) {
            throw new IntegrityException(I18NUtil.getMessage(MSG_CANNOT_CREATE_RECORD_FOLDER_CHILD, nodeService.getType(nodeRef)), null);
        }
        // ensure nothing is being added to a closed record folder
        NodeRef recordFolder = childAssocRef.getParentRef();
        Boolean isClosed = (Boolean) nodeService.getProperty(recordFolder, PROP_IS_CLOSED);
        if (isClosed != null && isClosed) {
            throw new IntegrityException(I18NUtil.getMessage(MSG_CANNOT_CREATE_CHILDREN_IN_CLOSED_RECORD_FOLDER), null);
        }
    }
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) IntegrityException(org.alfresco.repo.node.integrity.IntegrityException) Behaviour(org.alfresco.repo.policy.annotation.Behaviour)

Example 14 with Behaviour

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

the class RecordFolderType method onMoveNode.

/**
 * Record folder move behaviour
 *
 * @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, notificationFrequency = NotificationFrequency.FIRST_EVENT)
public void onMoveNode(ChildAssociationRef oldChildAssocRef, ChildAssociationRef newChildAssocRef) {
    if (!nodeService.getType(newChildAssocRef.getParentRef()).equals(TYPE_RECORD_FOLDER)) {
        if (!oldChildAssocRef.getParentRef().equals(newChildAssocRef.getParentRef())) {
            final NodeRef newNodeRef = newChildAssocRef.getChildRef();
            AuthenticationUtil.runAs(new AuthenticationUtil.RunAsWork<Object>() {

                public Object doWork() {
                    // clean record folder
                    cleanDisposableItem(nodeService, newNodeRef);
                    // re-initialise the record folder
                    recordFolderService.setupRecordFolder(newNodeRef);
                    // sort out the child records
                    for (NodeRef record : recordService.getRecords(newNodeRef)) {
                        // clean record
                        cleanDisposableItem(nodeService, record);
                        // Re-initiate the records in the new folder.
                        recordService.file(record);
                    }
                    return null;
                }
            }, AuthenticationUtil.getSystemUserName());
        }
    } else {
        throw new UnsupportedOperationException("Cannot move record folder into another record folder.");
    }
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) AuthenticationUtil(org.alfresco.repo.security.authentication.AuthenticationUtil) Behaviour(org.alfresco.repo.policy.annotation.Behaviour)

Example 15 with Behaviour

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

the class UnfiledRecordFolderType method onCreateChildAssociation.

@Override
@Behaviour(kind = BehaviourKind.ASSOCIATION)
public void onCreateChildAssociation(ChildAssociationRef childAssocRef, boolean isNewNode) {
    // We need to automatically cast the created folder to record folder if it is a plain folder
    // This occurs if the RM folder has been created via IMap, WebDav, etc. Don't check subtypes.
    // Some modules use hidden folder subtypes to store information (see RM-3283).
    QName childType = nodeService.getType(childAssocRef.getChildRef());
    if (childType.equals(ContentModel.TYPE_FOLDER)) {
        nodeService.setType(childAssocRef.getChildRef(), TYPE_UNFILED_RECORD_FOLDER);
    }
    // check the created child is of an accepted type
    validateNewChildAssociationSubTypesIncluded(childAssocRef.getChildRef(), ACCEPTED_NON_UNIQUE_CHILD_TYPES);
}
Also used : QName(org.alfresco.service.namespace.QName) 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