Search in sources :

Example 6 with VersionHistory

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

the class RecordableVersionServiceImpl method getRecordedVersion.

/**
 * @see org.alfresco.module.org_alfresco_module_rm.version.RecordableVersionService#getRecordedVersion(org.alfresco.service.cmr.repository.NodeRef)
 */
@Override
public Version getRecordedVersion(NodeRef versionRecord) {
    Version version = null;
    NodeRef versionedNodeRef = (NodeRef) nodeService.getProperty(versionRecord, RecordableVersionModel.PROP_VERSIONED_NODEREF);
    if (versionedNodeRef != null) {
        String versionLabel = (String) nodeService.getProperty(versionRecord, RecordableVersionModel.PROP_VERSION_LABEL);
        if (StringUtils.isNotBlank(versionLabel)) {
            VersionHistory versionHistory = getVersionHistory(versionedNodeRef);
            if (versionHistory != null) {
                version = versionHistory.getVersion(versionLabel);
            }
        }
    }
    return version;
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) Version(org.alfresco.service.cmr.version.Version) VersionHistory(org.alfresco.service.cmr.version.VersionHistory)

Example 7 with VersionHistory

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

the class NodeVersionsRelation method findVersion.

public Version findVersion(String nodeId, String versionLabelId) {
    NodeRef nodeRef = nodes.validateOrLookupNode(nodeId, null);
    VersionHistory vh = versionService.getVersionHistory(nodeRef);
    if (vh != null) {
        return vh.getVersion(versionLabelId);
    }
    return null;
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) VersionHistory(org.alfresco.service.cmr.version.VersionHistory)

Example 8 with VersionHistory

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

the class ResultMapperTests method setupTests.

@BeforeClass
public static void setupTests() throws Exception {
    Map<String, UserInfo> mapUserInfo = new HashMap<>();
    mapUserInfo.put(AuthenticationUtil.getSystemUserName(), new UserInfo(AuthenticationUtil.getSystemUserName(), "sys", "sys"));
    Map<QName, Serializable> nodeProps = new HashMap<>();
    NodesImpl nodes = mock(NodesImpl.class);
    ServiceRegistry sr = mock(ServiceRegistry.class);
    DeletedNodes deletedNodes = mock(DeletedNodes.class);
    nodes.setServiceRegistry(sr);
    VersionService versionService = mock(VersionService.class);
    VersionHistory versionHistory = mock(VersionHistory.class);
    Map<String, Serializable> versionProperties = new HashMap<>();
    versionProperties.put(Version.PROP_DESCRIPTION, "ver desc");
    versionProperties.put(Version2Model.PROP_VERSION_TYPE, "v type");
    when(versionHistory.getVersion(anyString())).thenAnswer(invocation -> {
        return new VersionImpl(versionProperties, new NodeRef(StoreMapper.STORE_REF_VERSION2_SPACESSTORE, GUID.generate()));
    });
    NodeService nodeService = mock(NodeService.class);
    when(versionService.getVersionHistory(any(NodeRef.class))).thenAnswer(invocation -> {
        Object[] args = invocation.getArguments();
        NodeRef aNode = (NodeRef) args[0];
        return versionHistory;
    });
    when(nodeService.getProperties(any(NodeRef.class))).thenAnswer(invocation -> {
        Object[] args = invocation.getArguments();
        NodeRef aNode = (NodeRef) args[0];
        if (StoreMapper.STORE_REF_VERSION2_SPACESSTORE.equals(aNode.getStoreRef())) {
            nodeProps.put(Version2Model.PROP_QNAME_FROZEN_NODE_REF, new NodeRef(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE, FROZEN_ID + aNode.getId()));
            nodeProps.put(Version2Model.PROP_QNAME_VERSION_LABEL, FROZEN_VER);
        }
        return nodeProps;
    });
    when(sr.getVersionService()).thenReturn(versionService);
    when(sr.getNodeService()).thenReturn(nodeService);
    when(nodes.validateOrLookupNode(nullable(String.class), nullable(String.class))).thenAnswer(invocation -> {
        Object[] args = invocation.getArguments();
        String aNode = (String) args[0];
        if (aNode.endsWith("" + VERSIONED_ID)) {
            throw new EntityNotFoundException("" + VERSIONED_ID);
        } else {
            return new NodeRef(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE, aNode);
        }
    });
    // // NodeRef nodeRef = nodes.validateOrLookupNode(nodeId, null);
    when(nodes.getFolderOrDocument(any(NodeRef.class), nullable(NodeRef.class), nullable(QName.class), nullable(List.class), nullable(Map.class))).thenAnswer(new Answer<Node>() {

        @Override
        public Node answer(InvocationOnMock invocation) throws Throwable {
            Object[] args = invocation.getArguments();
            NodeRef aNode = (NodeRef) args[0];
            if (StoreRef.STORE_REF_ARCHIVE_SPACESSTORE.equals(aNode.getStoreRef())) {
                // Return NULL if its from the archive store.
                return null;
            }
            return new Node(aNode, (NodeRef) args[1], nodeProps, mapUserInfo, sr);
        }
    });
    when(deletedNodes.getDeletedNode(nullable(String.class), nullable(Parameters.class), anyBoolean(), nullable(Map.class))).thenAnswer(new Answer<Node>() {

        @Override
        public Node answer(InvocationOnMock invocation) throws Throwable {
            Object[] args = invocation.getArguments();
            String nodeId = (String) args[0];
            if (FROZEN_ID.equals(nodeId))
                throw new EntityNotFoundException(nodeId);
            NodeRef aNode = new NodeRef(StoreRef.STORE_REF_ARCHIVE_SPACESSTORE, nodeId);
            return new Node(aNode, new NodeRef(StoreRef.STORE_REF_ARCHIVE_SPACESSTORE, "unknown"), nodeProps, mapUserInfo, sr);
        }
    });
    PersonPropertyLookup propertyLookups = mock(PersonPropertyLookup.class);
    when(propertyLookups.supports()).thenReturn(Stream.of("creator", "modifier").collect(Collectors.toSet()));
    when(propertyLookups.lookup(notNull(String.class))).thenAnswer(invocation -> {
        Object[] args = invocation.getArguments();
        String value = (String) args[0];
        if ("mjackson".equals(value))
            return "Michael Jackson";
        return null;
    });
    PropertyLookupRegistry propertyLookupRegistry = new PropertyLookupRegistry();
    propertyLookupRegistry.setLookups(Arrays.asList(propertyLookups));
    mapper = new ResultMapper();
    mapper.setNodes(nodes);
    mapper.setStoreMapper(new StoreMapper());
    mapper.setPropertyLookup(propertyLookupRegistry);
    mapper.setDeletedNodes(deletedNodes);
    mapper.setServiceRegistry(sr);
    NodeVersionsRelation nodeVersionsRelation = new NodeVersionsRelation();
    nodeVersionsRelation.setNodes(nodes);
    nodeVersionsRelation.setServiceRegistry(sr);
    nodeVersionsRelation.afterPropertiesSet();
    mapper.setNodeVersions(nodeVersionsRelation);
    helper = new SerializerTestHelper();
    searchMapper.setStoreMapper(new StoreMapper());
}
Also used : Serializable(java.io.Serializable) HashMap(java.util.HashMap) Node(org.alfresco.rest.api.model.Node) StoreMapper(org.alfresco.rest.api.search.impl.StoreMapper) VersionService(org.alfresco.service.cmr.version.VersionService) UserInfo(org.alfresco.rest.api.model.UserInfo) Mockito.anyString(org.mockito.Mockito.anyString) VersionImpl(org.alfresco.repo.version.common.VersionImpl) NodeRef(org.alfresco.service.cmr.repository.NodeRef) List(java.util.List) TupleList(org.alfresco.rest.api.search.model.TupleList) ArrayList(java.util.ArrayList) DeletedNodes(org.alfresco.rest.api.DeletedNodes) Parameters(org.alfresco.rest.framework.resource.parameters.Parameters) GeneralHighlightParameters(org.alfresco.service.cmr.search.GeneralHighlightParameters) FieldHighlightParameters(org.alfresco.service.cmr.search.FieldHighlightParameters) SearchParameters(org.alfresco.service.cmr.search.SearchParameters) QName(org.alfresco.service.namespace.QName) PersonPropertyLookup(org.alfresco.rest.api.lookups.PersonPropertyLookup) NodeService(org.alfresco.service.cmr.repository.NodeService) EntityNotFoundException(org.alfresco.rest.framework.core.exceptions.EntityNotFoundException) VersionHistory(org.alfresco.service.cmr.version.VersionHistory) NodesImpl(org.alfresco.rest.api.impl.NodesImpl) PropertyLookupRegistry(org.alfresco.rest.api.lookups.PropertyLookupRegistry) InvocationOnMock(org.mockito.invocation.InvocationOnMock) ResultMapper(org.alfresco.rest.api.search.impl.ResultMapper) JSONObject(org.json.JSONObject) ServiceRegistry(org.alfresco.service.ServiceRegistry) NodeVersionsRelation(org.alfresco.rest.api.nodes.NodeVersionsRelation) Map(java.util.Map) HashMap(java.util.HashMap) BeforeClass(org.junit.BeforeClass)

Example 9 with VersionHistory

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

the class DocumentDetailsDialog method getVersionHistory.

/**
 * Returns a list of objects representing the versions of the
 * current document
 *
 * @return List of previous versions
 */
public List getVersionHistory() {
    List<MapNode> versions = new ArrayList<MapNode>();
    if (getDocument().hasAspect(ContentModel.ASPECT_VERSIONABLE)) {
        VersionHistory history = this.getVersionService().getVersionHistory(getDocument().getNodeRef());
        if (history != null) {
            for (Version version : history.getAllVersions()) {
                // create a map node representation of the version
                MapNode clientVersion = new MapNode(version.getFrozenStateNodeRef());
                clientVersion.put("versionLabel", version.getVersionLabel());
                clientVersion.put("notes", version.getDescription());
                clientVersion.put("author", version.getCreator());
                clientVersion.put("versionDate", version.getCreatedDate());
                if (getDocument().hasAspect(ContentModel.ASPECT_MULTILINGUAL_EMPTY_TRANSLATION)) {
                    clientVersion.put("url", null);
                } else {
                    clientVersion.put("url", DownloadContentServlet.generateBrowserURL(version.getFrozenStateNodeRef(), clientVersion.getName()));
                }
                // add the client side version to the list
                versions.add(clientVersion);
            }
        }
    }
    return versions;
}
Also used : Version(org.alfresco.service.cmr.version.Version) ArrayList(java.util.ArrayList) MapNode(org.alfresco.web.bean.repository.MapNode) VersionHistory(org.alfresco.service.cmr.version.VersionHistory)

Example 10 with VersionHistory

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

the class DocumentDetailsDialog method initEditionHistory.

/**
 * Constructs a list of objects representing the editions of the
 * logical document
 *
 * @return List of editions
 */
@SuppressWarnings("unused")
private List<SingleEditionBean> initEditionHistory() {
    // get the mlContainer
    NodeRef mlContainer = getDocumentMlContainer().getNodeRef();
    // get all editions (in descending order - ie. most recent first)
    List<Version> orderedEditionList = new ArrayList<Version>(getEditionService().getEditions(mlContainer).getAllVersions());
    // the list of Single Edition Bean to return
    editionHistory = new ArrayList<SingleEditionBean>(orderedEditionList.size());
    boolean firstEdition = true;
    // for each edition, init a SingleEditionBean
    for (Version edition : orderedEditionList) {
        SingleEditionBean editionBean = new SingleEditionBean();
        MapNode clientEdition = new MapNode(edition.getFrozenStateNodeRef());
        String editionLabel = edition.getVersionLabel();
        if (firstEdition) {
            editionLabel += " (" + Application.getMessage(FacesContext.getCurrentInstance(), MSG_CURRENT) + ")";
        }
        clientEdition.put("editionLabel", editionLabel);
        clientEdition.put("editionNotes", edition.getDescription());
        clientEdition.put("editionAuthor", edition.getCreator());
        clientEdition.put("editionDate", edition.getCreatedDate());
        // Set the edition of the edition bean
        editionBean.setEdition(clientEdition);
        // get translations
        List<VersionHistory> translationHistories = null;
        if (firstEdition) {
            // Get the translations because the current edition doesn't content link with its
            // translation in the version store.
            Map<Locale, NodeRef> translations = getMultilingualContentService().getTranslations(mlContainer);
            translationHistories = new ArrayList<VersionHistory>(translations.size());
            for (NodeRef translation : translations.values()) {
                translationHistories.add(getVersionService().getVersionHistory(translation));
            }
        } else {
            translationHistories = getEditionService().getVersionedTranslations(edition);
        }
        // add each translation in the SingleEditionBean
        for (VersionHistory versionHistory : translationHistories) {
            // get the list of versions (in descending order - ie. most recent first)
            List<Version> orderedVersions = new ArrayList<Version>(versionHistory.getAllVersions());
            // the last version (ie. most recent) is the first version of the list
            Version lastVersion = orderedVersions.get(0);
            // get the properties of the lastVersion
            Map<QName, Serializable> lastVersionProperties = getEditionService().getVersionedMetadatas(lastVersion);
            Locale language = (Locale) lastVersionProperties.get(ContentModel.PROP_LOCALE);
            // create a map node representation of the last version
            MapNode clientLastVersion = new MapNode(lastVersion.getFrozenStateNodeRef());
            clientLastVersion.put("versionName", lastVersionProperties.get(ContentModel.PROP_NAME));
            // use the node service for the description to ensure that the returned value is a text and not a MLText
            clientLastVersion.put("versionDescription", getNodeService().getProperty(lastVersion.getFrozenStateNodeRef(), ContentModel.PROP_DESCRIPTION));
            clientLastVersion.put("versionAuthor", lastVersionProperties.get(ContentModel.PROP_AUTHOR));
            clientLastVersion.put("versionCreatedDate", lastVersionProperties.get(ContentModel.PROP_CREATED));
            clientLastVersion.put("versionModifiedDate", lastVersionProperties.get(ContentModel.PROP_MODIFIED));
            clientLastVersion.put("versionLanguage", this.getContentFilterLanguagesService().convertToNewISOCode(language.getLanguage()).toUpperCase());
            if (getNodeService().hasAspect(lastVersion.getFrozenStateNodeRef(), ContentModel.ASPECT_MULTILINGUAL_EMPTY_TRANSLATION)) {
                clientLastVersion.put("versionUrl", null);
            } else {
                clientLastVersion.put("versionUrl", DownloadContentServlet.generateBrowserURL(lastVersion.getFrozenStateNodeRef(), clientLastVersion.getName()));
            }
            // add a translation of the editionBean
            editionBean.addTranslations(clientLastVersion);
        }
        editionHistory.add(editionBean);
        firstEdition = false;
    }
    return editionHistory;
}
Also used : Locale(java.util.Locale) Serializable(java.io.Serializable) QName(org.alfresco.service.namespace.QName) ArrayList(java.util.ArrayList) MapNode(org.alfresco.web.bean.repository.MapNode) VersionHistory(org.alfresco.service.cmr.version.VersionHistory) NodeRef(org.alfresco.service.cmr.repository.NodeRef) Version(org.alfresco.service.cmr.version.Version) SingleEditionBean(org.alfresco.web.bean.ml.SingleEditionBean)

Aggregations

VersionHistory (org.alfresco.service.cmr.version.VersionHistory)20 Version (org.alfresco.service.cmr.version.Version)18 NodeRef (org.alfresco.service.cmr.repository.NodeRef)17 Serializable (java.io.Serializable)7 ArrayList (java.util.ArrayList)6 QName (org.alfresco.service.namespace.QName)6 HashMap (java.util.HashMap)5 Set (java.util.Set)5 Locale (java.util.Locale)4 Map (java.util.Map)4 MapNode (org.alfresco.web.bean.repository.MapNode)4 Collection (java.util.Collection)2 MimetypeMap (org.alfresco.repo.content.MimetypeMap)2 Node (org.alfresco.rest.api.model.Node)2 UserInfo (org.alfresco.rest.api.model.UserInfo)2 ContentWriter (org.alfresco.service.cmr.repository.ContentWriter)2 HashSet (java.util.HashSet)1 List (java.util.List)1 RunAsWork (org.alfresco.repo.security.authentication.AuthenticationUtil.RunAsWork)1 VersionImpl (org.alfresco.repo.version.common.VersionImpl)1