Search in sources :

Example 66 with Extend

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

the class Version2ServiceImpl method getVersionHistory.

@Override
@Extend(extensionAPI = VersionServiceExtension.class, traitAPI = VersionServiceTrait.class)
public VersionHistory getVersionHistory(NodeRef nodeRef) {
    if (logger.isDebugEnabled()) {
        logger.debug("Run as user " + AuthenticationUtil.getRunAsUser());
        logger.debug("Fully authenticated " + AuthenticationUtil.getFullyAuthenticatedUser());
    }
    VersionHistory versionHistory = null;
    // Get the version history regardless of whether the node is still 'live' or not
    NodeRef versionHistoryRef = getVersionHistoryNodeRef(nodeRef);
    if (versionHistoryRef != null) {
        versionHistory = buildVersionHistory(versionHistoryRef, nodeRef);
    }
    return versionHistory;
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) VersionHistory(org.alfresco.service.cmr.version.VersionHistory) Extend(org.alfresco.traitextender.Extend)

Example 67 with Extend

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

the class Version2ServiceImpl method restore.

@Override
@Extend(extensionAPI = VersionServiceExtension.class, traitAPI = VersionServiceTrait.class)
public NodeRef restore(NodeRef nodeRef, NodeRef parentNodeRef, QName assocTypeQName, QName assocQName, boolean deep) {
    if (logger.isDebugEnabled()) {
        logger.debug("Run as user " + AuthenticationUtil.getRunAsUser());
        logger.debug("Fully authenticated " + AuthenticationUtil.getFullyAuthenticatedUser());
    }
    NodeRef restoredNodeRef = null;
    // Check that the node does not exist
    if (this.nodeService.exists(nodeRef) == true) {
        // Error since you can not restore a node that already exists
        throw new VersionServiceException(MSGID_ERR_RESTORE_EXISTS, new Object[] { nodeRef.toString() });
    }
    // Try and get the version details that we want to restore to
    Version version = getHeadVersion(nodeRef);
    if (version == null) {
        // Error since there is no version information available to restore the node from
        throw new VersionServiceException(MSGID_ERR_RESTORE_NO_VERSION, new Object[] { nodeRef.toString() });
    }
    // Set the uuid of the new node
    Map<QName, Serializable> props = new HashMap<QName, Serializable>(1);
    props.put(ContentModel.PROP_NODE_UUID, ((NodeRef) version.getVersionProperty(Version2Model.PROP_FROZEN_NODE_REF)).getId());
    props.put(ContentModel.PROP_VERSION_LABEL, version.getVersionLabel());
    // Get the type of the frozen node
    QName type = (QName) dbNodeService.getType(VersionUtil.convertNodeRef(version.getFrozenStateNodeRef()));
    // Disable auto-version behaviour
    this.policyBehaviourFilter.disableBehaviour(ContentModel.ASPECT_VERSIONABLE);
    try {
        // Create the restored node
        restoredNodeRef = this.nodeService.createNode(parentNodeRef, assocTypeQName, assocQName, type, props).getChildRef();
    } finally {
        // Enable auto-version behaviour
        this.policyBehaviourFilter.enableBehaviour(ContentModel.ASPECT_VERSIONABLE);
    }
    // Now we need to revert the newly restored node
    revert(restoredNodeRef, version, deep);
    return restoredNodeRef;
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) Serializable(java.io.Serializable) Version(org.alfresco.service.cmr.version.Version) HashMap(java.util.HashMap) QName(org.alfresco.service.namespace.QName) VersionServiceException(org.alfresco.service.cmr.version.VersionServiceException) Extend(org.alfresco.traitextender.Extend)

Example 68 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)

Example 69 with Extend

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

the class Version2ServiceImpl method deleteVersion.

@Override
@Extend(extensionAPI = VersionServiceExtension.class, traitAPI = VersionServiceTrait.class)
public void deleteVersion(NodeRef nodeRef, Version version) {
    if (logger.isDebugEnabled()) {
        logger.debug("Run as user " + AuthenticationUtil.getRunAsUser());
        logger.debug("Fully authenticated " + AuthenticationUtil.getFullyAuthenticatedUser());
    }
    // Check the mandatory parameters
    ParameterCheck.mandatory("nodeRef", nodeRef);
    ParameterCheck.mandatory("version", version);
    Version currentVersion = getCurrentVersion(nodeRef);
    // Delete the version node
    this.dbNodeService.deleteNode(VersionUtil.convertNodeRef(version.getFrozenStateNodeRef()));
    // If we try to delete the last version
    if (currentVersion.getVersionLabel().equals(version.getVersionLabel())) {
        Version headVersion = getHeadVersion(nodeRef);
        if (headVersion != null) {
            // Reset the version label property on the versionable node to new head version
            // Disable the VersionableAspect for this change though, we don't want
            // to have this create a new version for the property change!
            policyBehaviourFilter.disableBehaviour(nodeRef, ContentModel.ASPECT_VERSIONABLE);
            try {
                this.nodeService.setProperty(nodeRef, ContentModel.PROP_VERSION_LABEL, headVersion.getVersionLabel());
                // MNT-13097 Content will be reverted as well
                revert(nodeRef, headVersion);
            } finally {
                policyBehaviourFilter.enableBehaviour(nodeRef, ContentModel.ASPECT_VERSIONABLE);
            }
        } else {
            deleteVersionHistory(nodeRef);
        }
    }
}
Also used : Version(org.alfresco.service.cmr.version.Version) Extend(org.alfresco.traitextender.Extend)

Example 70 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 Version createVersion(NodeRef nodeRef, Map<String, Serializable> versionProperties) throws ReservedVersionNameException, AspectMissingException {
    if (logger.isDebugEnabled()) {
        logger.debug("Run as user " + AuthenticationUtil.getRunAsUser());
        logger.debug("Fully authenticated " + AuthenticationUtil.getFullyAuthenticatedUser());
    }
    long startTime = System.currentTimeMillis();
    // deprecated (unused)
    int versionNumber = 0;
    // Create the version
    Version version = createVersion(nodeRef, versionProperties, versionNumber);
    if (logger.isDebugEnabled()) {
        logger.debug("created version (" + VersionUtil.convertNodeRef(version.getFrozenStateNodeRef()) + ") in " + (System.currentTimeMillis() - startTime) + " ms");
    }
    return version;
}
Also used : Version(org.alfresco.service.cmr.version.Version) 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