Search in sources :

Example 36 with Extend

use of org.alfresco.traitextender.Extend in project alfresco-repository by Alfresco.

the class Version2ServiceImpl method isAVersion.

@Override
@Extend(extensionAPI = VersionServiceExtension.class, traitAPI = VersionServiceTrait.class)
public boolean isAVersion(NodeRef nodeRef) {
    if (logger.isDebugEnabled()) {
        logger.debug("Run as user " + AuthenticationUtil.getRunAsUser());
        logger.debug("Fully authenticated " + AuthenticationUtil.getFullyAuthenticatedUser());
    }
    NodeRef realNodeRef = nodeRef;
    if (nodeRef.getStoreRef().getProtocol().equals(VersionBaseModel.STORE_PROTOCOL)) {
        realNodeRef = VersionUtil.convertNodeRef(nodeRef);
    }
    return this.dbNodeService.hasAspect(realNodeRef, Version2Model.ASPECT_VERSION);
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) Extend(org.alfresco.traitextender.Extend)

Example 37 with Extend

use of org.alfresco.traitextender.Extend in project alfresco-repository by Alfresco.

the class CheckOutCheckInServiceImpl method checkout.

@Override
@Extend(traitAPI = CheckOutCheckInServiceTrait.class, extensionAPI = CheckOutCheckInServiceExtension.class)
public NodeRef checkout(final NodeRef nodeRef, final NodeRef destinationParentNodeRef, final QName destinationAssocTypeQName, QName destinationAssocQName) {
    if (nodeService.hasAspect(nodeRef, ContentModel.ASPECT_CHECKED_OUT)) {
        throw new CheckOutCheckInServiceException(MSG_ALREADY_CHECKEDOUT);
    }
    // Make sure we are not checking out a working copy node
    if (nodeService.hasAspect(nodeRef, ContentModel.ASPECT_WORKING_COPY)) {
        throw new CheckOutCheckInServiceException(MSG_ERR_ALREADY_WORKING_COPY);
    }
    // It is not enough to check LockUtils.isLockedOrReadOnly in case when the same user does offline and online edit (for instance in two open browsers). In this case we get
    // set ContentModel.ASPECT_LOCKABLE and LockType.WRITE_LOCK. So, here we have to check following
    LockStatus lockStatus = lockService.getLockStatus(nodeRef);
    if (lockStatus != LockStatus.NO_LOCK && lockStatus != LockStatus.LOCK_EXPIRED) {
        throw new NodeLockedException(nodeRef);
    }
    behaviourFilter.disableBehaviour(nodeRef, ContentModel.ASPECT_AUDITABLE);
    behaviourFilter.disableBehaviour(destinationParentNodeRef, ContentModel.ASPECT_AUDITABLE);
    try {
        return doCheckout(nodeRef, destinationParentNodeRef, destinationAssocTypeQName, destinationAssocQName);
    } finally {
        behaviourFilter.enableBehaviour(nodeRef, ContentModel.ASPECT_AUDITABLE);
        behaviourFilter.enableBehaviour(destinationParentNodeRef, ContentModel.ASPECT_AUDITABLE);
    }
}
Also used : CheckOutCheckInServiceException(org.alfresco.service.cmr.coci.CheckOutCheckInServiceException) LockStatus(org.alfresco.service.cmr.lock.LockStatus) NodeLockedException(org.alfresco.service.cmr.lock.NodeLockedException) Extend(org.alfresco.traitextender.Extend)

Example 38 with Extend

use of org.alfresco.traitextender.Extend 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 39 with Extend

use of org.alfresco.traitextender.Extend 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)

Example 40 with Extend

use of org.alfresco.traitextender.Extend in project alfresco-repository by Alfresco.

the class Version2ServiceImpl method createVersion.

@Override
@Extend(extensionAPI = VersionServiceExtension.class, traitAPI = VersionServiceTrait.class)
public Collection<Version> createVersion(Collection<NodeRef> nodeRefs, Map<String, Serializable> versionProperties) throws ReservedVersionNameException, AspectMissingException {
    if (logger.isDebugEnabled()) {
        logger.debug("Run as user " + AuthenticationUtil.getRunAsUser());
        logger.debug("Fully authenticated " + AuthenticationUtil.getFullyAuthenticatedUser());
    }
    /* 
         * Note: we can't control the order of the list, so if we have children and parents in the list and the
         * parents get versioned before the children and the children are not already versioned then the parents
         * child references will be pointing to the node ref, rather than the version history.
         */
    long startTime = System.currentTimeMillis();
    Collection<Version> result = new ArrayList<Version>(nodeRefs.size());
    // deprecated (unused)
    int versionNumber = 0;
    // Version each node in the list
    for (NodeRef nodeRef : nodeRefs) {
        result.add(createVersion(nodeRef, versionProperties, versionNumber));
    }
    if (logger.isDebugEnabled()) {
        logger.debug("created version list (" + getVersionStoreReference() + ") in " + (System.currentTimeMillis() - startTime) + " ms (with " + nodeRefs.size() + " nodes)");
    }
    return result;
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) Version(org.alfresco.service.cmr.version.Version) ArrayList(java.util.ArrayList) Extend(org.alfresco.traitextender.Extend)

Aggregations

Extend (org.alfresco.traitextender.Extend)75 NodeRef (org.alfresco.service.cmr.repository.NodeRef)47 ChildAssociationRef (org.alfresco.service.cmr.repository.ChildAssociationRef)25 QName (org.alfresco.service.namespace.QName)21 ArrayList (java.util.ArrayList)19 Pair (org.alfresco.util.Pair)15 HashSet (java.util.HashSet)10 Serializable (java.io.Serializable)9 MutableInt (org.apache.commons.lang3.mutable.MutableInt)9 HashMap (java.util.HashMap)8 LinkedHashSet (java.util.LinkedHashSet)8 ChildAssocRefQueryCallback (org.alfresco.repo.domain.node.NodeDAO.ChildAssocRefQueryCallback)8 AssociationRef (org.alfresco.service.cmr.repository.AssociationRef)8 LockStatus (org.alfresco.service.cmr.lock.LockStatus)6 Version (org.alfresco.service.cmr.version.Version)6 NodeDAO (org.alfresco.repo.domain.node.NodeDAO)5 LockState (org.alfresco.repo.lock.mem.LockState)5 PermissionReference (org.alfresco.repo.security.permissions.PermissionReference)5 StoreRef (org.alfresco.service.cmr.repository.StoreRef)5 Map (java.util.Map)4