Search in sources :

Example 26 with Version

use of org.alfresco.service.cmr.version.Version in project acs-community-packaging by Alfresco.

the class VersionedDocumentDetailsDialog method getBrowsingVersionForMLContainer.

/**
 * Util method which return the last (most recent) version of a translation of a given edition of a mlContainer according its language
 */
@SuppressWarnings("unchecked")
private Version getBrowsingVersionForMLContainer(NodeRef document, String editionLabel, String lang) {
    // get the list of translations of the given edition of the mlContainer
    List<VersionHistory> translations = getEditionService().getVersionedTranslations(this.documentEdition);
    // if translation size == 0, the edition is the current edition and the translations are not yet attached.
    if (translations.size() == 0) {
        // the selection edition is the current.
        return getBrowsingCurrentVersionForMLContainer(document, lang);
    } else {
        Version versionToReturn = null;
        // get the last (most recent) version of the translation in the given lang of the edition
        for (VersionHistory history : translations) {
            // get the list of versions (in descending order - ie. most recent first)
            List<Version> orderedVersions = new ArrayList<Version>(history.getAllVersions());
            // the last version (ie. most recent) is the first version of the list
            Version lastVersion = orderedVersions.get(0);
            if (lastVersion != null) {
                Map<QName, Serializable> properties = getEditionService().getVersionedMetadatas(lastVersion);
                Locale locale = (Locale) properties.get(ContentModel.PROP_LOCALE);
                if (locale.getLanguage().equalsIgnoreCase(lang)) {
                    versionToReturn = lastVersion;
                    this.versionHistory = history;
                    break;
                }
            }
        }
        return versionToReturn;
    }
}
Also used : Locale(java.util.Locale) Serializable(java.io.Serializable) Version(org.alfresco.service.cmr.version.Version) QName(org.alfresco.service.namespace.QName) ArrayList(java.util.ArrayList) VersionHistory(org.alfresco.service.cmr.version.VersionHistory)

Example 27 with Version

use of org.alfresco.service.cmr.version.Version in project alfresco-remote-api by Alfresco.

the class NodeVersionsRelation method delete.

@Override
@WebApiDescription(title = "Delete version")
public void delete(String nodeId, String versionId, Parameters parameters) {
    Version v = findVersion(nodeId, versionId);
    // live (aka versioned) nodeRef
    NodeRef nodeRef = v.getVersionedNodeRef();
    if (sr.getPermissionService().hasPermission(nodeRef, PermissionService.DELETE) != AccessStatus.ALLOWED) {
        throw new PermissionDeniedException("Cannot delete version");
    }
    versionService.deleteVersion(nodeRef, v);
    Map<QName, Serializable> props = sr.getNodeService().getProperties(nodeRef);
    if (props.get(ContentModel.PROP_VERSION_LABEL) == null) {
        // note: alternatively, the client can remove the "cm:versionable" aspect (if permissions allow) to clear the version history and disable versioning
        throw new IntegrityException("Cannot delete last version (did you mean to disable versioning instead ?) [" + nodeId + "," + versionId + "]", null);
    /*
            if (props.get(ContentModel.PROP_VERSION_TYPE) != null)
            {
                // minor fix up to versionable aspect - ie. remove versionType
                behaviourFilter.disableBehaviour(nodeRef, ContentModel.ASPECT_VERSIONABLE);
                behaviourFilter.disableBehaviour(nodeRef, ContentModel.ASPECT_AUDITABLE);
                try
                {
                    sr.getNodeService().removeProperty(nodeRef, ContentModel.PROP_VERSION_TYPE);
                }
                finally
                {
                    behaviourFilter.enableBehaviour(nodeRef, ContentModel.ASPECT_AUDITABLE);
                    behaviourFilter.enableBehaviour(nodeRef, ContentModel.ASPECT_VERSIONABLE);
                }
            }
            */
    }
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) Serializable(java.io.Serializable) Version(org.alfresco.service.cmr.version.Version) QName(org.alfresco.service.namespace.QName) IntegrityException(org.alfresco.repo.node.integrity.IntegrityException) PermissionDeniedException(org.alfresco.rest.framework.core.exceptions.PermissionDeniedException) WebApiDescription(org.alfresco.rest.framework.WebApiDescription)

Example 28 with Version

use of org.alfresco.service.cmr.version.Version in project alfresco-remote-api by Alfresco.

the class NodeVersionsRelation method readAll.

/**
 * List version history
 *
 * @param nodeId String id of (live) node
 */
@Override
@WebApiDescription(title = "Return version history as a paged list of version node infos")
public CollectionWithPagingInfo<Node> readAll(String nodeId, Parameters parameters) {
    NodeRef nodeRef = nodes.validateOrLookupNode(nodeId, null);
    VersionHistory vh = versionService.getVersionHistory(nodeRef);
    Map<String, UserInfo> mapUserInfo = new HashMap<>(10);
    List<String> includeParam = parameters.getInclude();
    List<Node> collection = null;
    if (vh != null) {
        collection = new ArrayList<>(vh.getAllVersions().size());
        for (Version v : vh.getAllVersions()) {
            Node node = nodes.getFolderOrDocument(v.getFrozenStateNodeRef(), null, null, includeParam, mapUserInfo);
            mapVersionInfo(v, node);
            collection.add(node);
        }
    }
    return listPage(collection, parameters.getPaging());
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) HashMap(java.util.HashMap) Version(org.alfresco.service.cmr.version.Version) Node(org.alfresco.rest.api.model.Node) UserInfo(org.alfresco.rest.api.model.UserInfo) VersionHistory(org.alfresco.service.cmr.version.VersionHistory) WebApiDescription(org.alfresco.rest.framework.WebApiDescription)

Example 29 with Version

use of org.alfresco.service.cmr.version.Version in project records-management by Alfresco.

the class RecordableVersionServiceImpl method getLatestVersionRecord.

/**
 * Helper to get the latest version record for a given document (ie non-record)
 *
 * @param nodeRef node reference
 * @return NodeRef latest version record, null otherwise
 */
private NodeRef getLatestVersionRecord(NodeRef nodeRef) {
    NodeRef versionRecord = null;
    // wire record up to previous record
    VersionHistory versionHistory = getVersionHistory(nodeRef);
    if (versionHistory != null) {
        Collection<Version> previousVersions = versionHistory.getAllVersions();
        for (Version previousVersion : previousVersions) {
            // look for the associated record
            final NodeRef previousRecord = (NodeRef) previousVersion.getVersionProperties().get(PROP_VERSION_RECORD);
            if (previousRecord != null && nodeService.exists(previousRecord)) {
                versionRecord = previousRecord;
                break;
            }
        }
    }
    return versionRecord;
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) Version(org.alfresco.service.cmr.version.Version) VersionHistory(org.alfresco.service.cmr.version.VersionHistory)

Example 30 with Version

use of org.alfresco.service.cmr.version.Version in project records-management by Alfresco.

the class RecordableVersionServiceImpl method getVersion.

/**
 * @see org.alfresco.repo.version.Version2ServiceImpl#getVersion(org.alfresco.service.cmr.repository.NodeRef)
 */
@Override
protected Version getVersion(NodeRef versionRef) {
    Version version = super.getVersion(versionRef);
    // place the version record reference in the version properties
    NodeRef record = (NodeRef) dbNodeService.getProperty(versionRef, PROP_RECORD_NODE_REF);
    if (record != null) {
        version.getVersionProperties().put(PROP_VERSION_RECORD, record);
    }
    // place information about the destruction of the version record in the properties
    Boolean destroyed = (Boolean) dbNodeService.getProperty(versionRef, PROP_DESTROYED);
    if (destroyed == null) {
        destroyed = Boolean.FALSE;
    }
    version.getVersionProperties().put(PROP_RECORDED_VERSION_DESTROYED, destroyed);
    return version;
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) Version(org.alfresco.service.cmr.version.Version)

Aggregations

Version (org.alfresco.service.cmr.version.Version)39 NodeRef (org.alfresco.service.cmr.repository.NodeRef)31 VersionHistory (org.alfresco.service.cmr.version.VersionHistory)17 Serializable (java.io.Serializable)12 QName (org.alfresco.service.namespace.QName)9 ArrayList (java.util.ArrayList)8 BaseUnitTest (org.alfresco.module.org_alfresco_module_rm.test.util.BaseUnitTest)8 Test (org.junit.Test)8 HashMap (java.util.HashMap)7 Set (java.util.Set)6 MapNode (org.alfresco.web.bean.repository.MapNode)5 Locale (java.util.Locale)4 Map (java.util.Map)4 Node (org.alfresco.rest.api.model.Node)4 WebApiDescription (org.alfresco.rest.framework.WebApiDescription)4 RunAsWork (org.alfresco.repo.security.authentication.AuthenticationUtil.RunAsWork)3 EntityNotFoundException (org.alfresco.rest.framework.core.exceptions.EntityNotFoundException)3 ContentWriter (org.alfresco.service.cmr.repository.ContentWriter)3 PropertyMap (org.alfresco.util.PropertyMap)3 Collection (java.util.Collection)2