Search in sources :

Example 1 with AspectMissingException

use of org.alfresco.service.cmr.repository.AspectMissingException in project alfresco-repository by Alfresco.

the class LockServiceImpl method checkForLock.

/**
 * {@inheritDoc}
 */
@Extend(traitAPI = LockServiceTrait.class, extensionAPI = LockServiceExtension.class)
public void checkForLock(NodeRef nodeRef) throws NodeLockedException {
    String userName = getUserName();
    nodeRef = tenantService.getName(nodeRef);
    // Ensure we have found a node reference
    if (nodeRef != null && userName != null) {
        String effectiveUserName = AuthenticationUtil.getRunAsUser();
        // Check to see if should just ignore this node - note: special MT System due to AuditableAspect
        if (!(ignore(nodeRef) || tenantService.getBaseNameUser(effectiveUserName).equals(AuthenticationUtil.getSystemUserName()))) {
            try {
                // Get the current lock status on the node ref
                LockStatus currentLockStatus = getLockStatus(nodeRef, userName);
                LockType lockType = getLockType(nodeRef);
                if (LockType.WRITE_LOCK.equals(lockType) == true && LockStatus.LOCKED.equals(currentLockStatus) == true) {
                    // Lock is of type Write Lock and the node is locked by another owner.
                    throw new NodeLockedException(nodeRef);
                } else if (LockType.READ_ONLY_LOCK.equals(lockType) == true && (LockStatus.LOCKED.equals(currentLockStatus) == true || LockStatus.LOCK_OWNER.equals(currentLockStatus) == true)) {
                    // modifications are prevented
                    throw new NodeLockedException(nodeRef);
                } else if (LockType.NODE_LOCK.equals(lockType) == true && (LockStatus.LOCKED.equals(currentLockStatus) == true || LockStatus.LOCK_OWNER.equals(currentLockStatus) == true)) {
                    // modifications are prevented
                    throw new NodeLockedException(nodeRef);
                }
            } catch (AspectMissingException exception) {
            // Ignore since this indicates that the node does not have the lock aspect applied
            }
        }
    }
}
Also used : LockStatus(org.alfresco.service.cmr.lock.LockStatus) NodeLockedException(org.alfresco.service.cmr.lock.NodeLockedException) LockType(org.alfresco.service.cmr.lock.LockType) AspectMissingException(org.alfresco.service.cmr.repository.AspectMissingException) Extend(org.alfresco.traitextender.Extend)

Example 2 with AspectMissingException

use of org.alfresco.service.cmr.repository.AspectMissingException in project alfresco-repository by Alfresco.

the class CheckOutCheckInServiceImpl method cancelCheckout.

@Override
@Extend(traitAPI = CheckOutCheckInServiceTrait.class, extensionAPI = CheckOutCheckInServiceExtension.class)
public NodeRef cancelCheckout(NodeRef workingCopyNodeRef) {
    // Check that we have been handed a working copy
    if (!nodeService.hasAspect(workingCopyNodeRef, ContentModel.ASPECT_WORKING_COPY)) {
        // Error since we have not been passed a working copy
        throw new AspectMissingException(ContentModel.ASPECT_WORKING_COPY, workingCopyNodeRef);
    }
    // Get the checked out node
    NodeRef nodeRef = getCheckedOut(workingCopyNodeRef);
    if (nodeRef == null) {
        // Error since the original node can not be found
        throw new CheckOutCheckInServiceException(MSG_ERR_BAD_COPY);
    }
    // Invoke policy
    invokeBeforeCancelCheckOut(workingCopyNodeRef);
    behaviourFilter.disableBehaviour(nodeRef, ContentModel.ASPECT_AUDITABLE);
    behaviourFilter.disableBehaviour(workingCopyNodeRef, ContentModel.ASPECT_WORKING_COPY);
    behaviourFilter.disableBehaviour(nodeRef, ContentModel.ASPECT_CMIS_CREATED_CHECKEDOUT);
    try {
        if (nodeService.hasAspect(nodeRef, ContentModel.ASPECT_LOCKABLE)) {
            // Release the lock on the original node
            lockService.unlock(nodeRef, false, true);
        }
        nodeService.removeAspect(nodeRef, ContentModel.ASPECT_CHECKED_OUT);
        // Delete the working copy
        nodeService.deleteNode(workingCopyNodeRef);
        // Invoke policy
        invokeOnCancelCheckOut(nodeRef);
        if (nodeService.hasAspect(nodeRef, ContentModel.ASPECT_CMIS_CREATED_CHECKEDOUT)) {
            nodeService.deleteNode(nodeRef);
        }
    } catch (UnableToReleaseLockException exception) {
        throw new CheckOutCheckInServiceException(MSG_ERR_NOT_OWNER, exception);
    } finally {
        behaviourFilter.enableBehaviour(nodeRef, ContentModel.ASPECT_AUDITABLE);
        behaviourFilter.enableBehaviour(nodeRef, ContentModel.ASPECT_CMIS_CREATED_CHECKEDOUT);
    }
    return nodeRef;
}
Also used : CheckOutCheckInServiceException(org.alfresco.service.cmr.coci.CheckOutCheckInServiceException) NodeRef(org.alfresco.service.cmr.repository.NodeRef) UnableToReleaseLockException(org.alfresco.service.cmr.lock.UnableToReleaseLockException) AspectMissingException(org.alfresco.service.cmr.repository.AspectMissingException) Extend(org.alfresco.traitextender.Extend)

Example 3 with AspectMissingException

use of org.alfresco.service.cmr.repository.AspectMissingException in project alfresco-repository by Alfresco.

the class CheckOutCheckInServiceImpl method checkin.

@Override
@Extend(traitAPI = CheckOutCheckInServiceTrait.class, extensionAPI = CheckOutCheckInServiceExtension.class)
public NodeRef checkin(NodeRef workingCopyNodeRef, Map<String, Serializable> versionProperties, String contentUrl, boolean keepCheckedOut) {
    // Check that we have been handed a working copy
    if (!nodeService.hasAspect(workingCopyNodeRef, ContentModel.ASPECT_WORKING_COPY)) {
        // Error since we have not been passed a working copy
        throw new AspectMissingException(ContentModel.ASPECT_WORKING_COPY, workingCopyNodeRef);
    }
    // Get the checked out node
    NodeRef nodeRef = getCheckedOut(workingCopyNodeRef);
    if (nodeRef == null) {
        // Error since the original node can not be found
        throw new CheckOutCheckInServiceException(MSG_ERR_BAD_COPY);
    }
    // Invoke policy
    invokeBeforeCheckIn(workingCopyNodeRef, versionProperties, contentUrl, keepCheckedOut);
    try {
        if (nodeService.hasAspect(nodeRef, ContentModel.ASPECT_LOCKABLE)) {
            // Release the lock on the original node
            lockService.unlock(nodeRef, false, true);
        }
    } catch (UnableToReleaseLockException exception) {
        throw new CheckOutCheckInServiceException(MSG_ERR_NOT_OWNER, exception);
    }
    if (contentUrl != null) {
        ContentData contentData = (ContentData) nodeService.getProperty(workingCopyNodeRef, ContentModel.PROP_CONTENT);
        if (contentData == null) {
            throw new AlfrescoRuntimeException(MSG_ERR_WORKINGCOPY_HAS_NO_CONTENT, new Object[] { workingCopyNodeRef });
        } else {
            contentData = new ContentData(contentUrl, contentData.getMimetype(), contentData.getSize(), contentData.getEncoding());
        }
        // Set the content url value onto the working copy
        nodeService.setProperty(workingCopyNodeRef, ContentModel.PROP_CONTENT, contentData);
    }
    // Copy the contents of the working copy onto the original
    this.copyService.copy(workingCopyNodeRef, nodeRef);
    // Handle name change on working copy (only for folders/files)
    if (fileFolderService.getFileInfo(workingCopyNodeRef) != null) {
        String origName = (String) nodeService.getProperty(nodeRef, ContentModel.PROP_NAME);
        String name = (String) nodeService.getProperty(workingCopyNodeRef, ContentModel.PROP_NAME);
        String wcLabel = (String) this.nodeService.getProperty(workingCopyNodeRef, ContentModel.PROP_WORKING_COPY_LABEL);
        if (wcLabel == null) {
            wcLabel = getWorkingCopyLabel();
        }
        if (hasWorkingCopyNameChanged(name, origName, wcLabel)) {
            // ensure working copy has working copy label in its name to avoid name clash
            if (!name.contains(" " + wcLabel)) {
                try {
                    fileFolderService.rename(workingCopyNodeRef, createWorkingCopyName(name, wcLabel));
                } catch (FileExistsException e) {
                    throw new CheckOutCheckInServiceException(e, MSG_ERR_CANNOT_RENAME, name, wcLabel);
                } catch (FileNotFoundException e) {
                    throw new CheckOutCheckInServiceException(e, MSG_ERR_CANNOT_RENAME, name, wcLabel);
                }
            }
            String newName = getNameFromWorkingCopyName(name, wcLabel);
            try {
                // rename original to changed working name
                fileFolderService.rename(nodeRef, newName);
            } catch (FileExistsException e) {
                throw new CheckOutCheckInServiceException(e, MSG_ERR_CANNOT_RENAME, origName, newName);
            } catch (FileNotFoundException e) {
                throw new CheckOutCheckInServiceException(e, MSG_ERR_CANNOT_RENAME, name, newName);
            }
        }
    }
    if (versionProperties != null && nodeService.hasAspect(nodeRef, ContentModel.ASPECT_VERSIONABLE) && !nodeService.hasAspect(nodeRef, ContentModel.ASPECT_CMIS_CREATED_CHECKEDOUT)) {
        // Create the new version
        this.versionService.createVersion(nodeRef, versionProperties);
    }
    nodeService.removeAspect(nodeRef, ContentModel.ASPECT_CMIS_CREATED_CHECKEDOUT);
    if (keepCheckedOut == false) {
        // Delete the working copy
        // Disable cm:auditable aspect
        // See MNT-8789
        behaviourFilter.disableBehaviour(nodeRef, ContentModel.ASPECT_AUDITABLE);
        behaviourFilter.disableBehaviour(workingCopyNodeRef, ContentModel.ASPECT_WORKING_COPY);
        try {
            // Clean up original node
            // Note: Lock has already been removed.  So no lockService.unlock(nodeRef);
            nodeService.removeAspect(nodeRef, ContentModel.ASPECT_CHECKED_OUT);
            // Delete the working copy
            nodeService.deleteNode(workingCopyNodeRef);
        } finally {
            // Just for symmetry; the node is gone
            behaviourFilter.enableBehaviour(workingCopyNodeRef, ContentModel.ASPECT_WORKING_COPY);
            behaviourFilter.enableBehaviour(nodeRef, ContentModel.ASPECT_AUDITABLE);
        }
    } else {
        // Re-lock the original node
        lockService.lock(nodeRef, LockType.READ_ONLY_LOCK);
    }
    // Invoke policy
    invokeOnCheckIn(nodeRef);
    return nodeRef;
}
Also used : CheckOutCheckInServiceException(org.alfresco.service.cmr.coci.CheckOutCheckInServiceException) NodeRef(org.alfresco.service.cmr.repository.NodeRef) ContentData(org.alfresco.service.cmr.repository.ContentData) FileNotFoundException(org.alfresco.service.cmr.model.FileNotFoundException) AlfrescoRuntimeException(org.alfresco.error.AlfrescoRuntimeException) UnableToReleaseLockException(org.alfresco.service.cmr.lock.UnableToReleaseLockException) AspectMissingException(org.alfresco.service.cmr.repository.AspectMissingException) FileExistsException(org.alfresco.service.cmr.model.FileExistsException) Extend(org.alfresco.traitextender.Extend)

Aggregations

AspectMissingException (org.alfresco.service.cmr.repository.AspectMissingException)3 Extend (org.alfresco.traitextender.Extend)3 CheckOutCheckInServiceException (org.alfresco.service.cmr.coci.CheckOutCheckInServiceException)2 UnableToReleaseLockException (org.alfresco.service.cmr.lock.UnableToReleaseLockException)2 NodeRef (org.alfresco.service.cmr.repository.NodeRef)2 AlfrescoRuntimeException (org.alfresco.error.AlfrescoRuntimeException)1 LockStatus (org.alfresco.service.cmr.lock.LockStatus)1 LockType (org.alfresco.service.cmr.lock.LockType)1 NodeLockedException (org.alfresco.service.cmr.lock.NodeLockedException)1 FileExistsException (org.alfresco.service.cmr.model.FileExistsException)1 FileNotFoundException (org.alfresco.service.cmr.model.FileNotFoundException)1 ContentData (org.alfresco.service.cmr.repository.ContentData)1