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;
}
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;
}
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());
}
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;
}
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;
}
Aggregations