use of org.alfresco.rest.api.model.Node in project alfresco-remote-api by Alfresco.
the class ResultMapper method getNode.
/**
* Builds a node representation based on a ResultSetRow;
* @param searchRequestContext
* @param aRow
* @param params
* @param mapUserInfo
* @param isHistory
* @return Node
*/
public Node getNode(ResultSetRow aRow, Params params, Map<String, UserInfo> mapUserInfo, boolean isHistory) {
String nodeStore = storeMapper.getStore(aRow.getNodeRef());
if (isHistory)
nodeStore = HISTORY;
Node aNode = null;
switch(nodeStore) {
case LIVE_NODES:
aNode = nodes.getFolderOrDocument(aRow.getNodeRef(), null, null, params.getInclude(), mapUserInfo);
break;
case HISTORY:
aNode = nodes.getFolderOrDocument(aRow.getNodeRef(), null, null, params.getInclude(), mapUserInfo);
break;
case VERSIONS:
Map<QName, Serializable> properties = serviceRegistry.getNodeService().getProperties(aRow.getNodeRef());
NodeRef frozenNodeRef = ((NodeRef) properties.get(Version2Model.PROP_QNAME_FROZEN_NODE_REF));
String versionLabelId = (String) properties.get(Version2Model.PROP_QNAME_VERSION_LABEL);
Version v = null;
try {
if (frozenNodeRef != null && versionLabelId != null) {
v = nodeVersions.findVersion(frozenNodeRef.getId(), versionLabelId);
aNode = nodes.getFolderOrDocument(v.getFrozenStateNodeRef(), null, null, params.getInclude(), mapUserInfo);
}
} catch (EntityNotFoundException | InvalidNodeRefException e) {
// Solr says there is a node but we can't find it
logger.debug("Failed to find a versioned node with id of " + frozenNodeRef + " this is probably because the original node has been deleted.");
}
if (v != null && aNode != null) {
nodeVersions.mapVersionInfo(v, aNode, aRow.getNodeRef());
aNode.setNodeId(frozenNodeRef.getId());
aNode.setVersionLabel(versionLabelId);
}
break;
case DELETED:
try {
aNode = deletedNodes.getDeletedNode(aRow.getNodeRef().getId(), params, false, mapUserInfo);
} catch (EntityNotFoundException enfe) {
// Solr says there is a deleted node but we can't find it, we want the rest of the search to return so lets ignore it.
logger.debug("Failed to find a deleted node with id of " + aRow.getNodeRef().getId());
}
break;
}
if (aNode != null) {
aNode.setLocation(nodeStore);
}
return aNode;
}
use of org.alfresco.rest.api.model.Node in project alfresco-remote-api by Alfresco.
the class DeletedNodesImpl method getDeletedNode.
@Override
public Node getDeletedNode(String originalId, Parameters parameters, boolean fullnode, Map<String, UserInfo> mapUserInfo) {
// First check the node is valid and has been archived.
NodeRef validatedNodeRef = nodes.validateNode(StoreRef.STORE_REF_ARCHIVE_SPACESSTORE, originalId);
// Now get the Node
NodeRef nodeRef = new NodeRef(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE, validatedNodeRef.getId());
NodeRef archivedNodeRef = nodeArchiveService.getArchivedNode(nodeRef);
Node foundNode = null;
if (fullnode) {
foundNode = nodes.getFolderOrDocumentFullInfo(archivedNodeRef, null, null, parameters, mapUserInfo);
} else {
foundNode = nodes.getFolderOrDocument(archivedNodeRef, null, null, parameters.getInclude(), mapUserInfo);
}
if (foundNode != null)
mapArchiveInfo(foundNode, null);
return foundNode;
}
use of org.alfresco.rest.api.model.Node in project alfresco-remote-api by Alfresco.
the class DeletedNodesImpl method listDeleted.
@Override
public CollectionWithPagingInfo<Node> listDeleted(Parameters parameters) {
PagingRequest pagingRequest = Util.getPagingRequest(parameters.getPaging());
NodeRef archiveStoreRootNodeRef = nodeService.getStoreArchiveNode(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE);
// Create canned query
ArchivedNodesCannedQueryBuilder queryBuilder = new ArchivedNodesCannedQueryBuilder.Builder(archiveStoreRootNodeRef, pagingRequest).sortOrderAscending(false).build();
// Query the DB
PagingResults<NodeRef> result = nodeArchiveService.listArchivedNodes(queryBuilder);
Integer totalItems = result.getTotalResultCount().getFirst();
List<Node> nodesFound = new ArrayList<Node>(result.getPage().size());
Map mapUserInfo = new HashMap<>();
for (NodeRef nRef : result.getPage()) {
Node foundNode = nodes.getFolderOrDocument(nRef, null, null, parameters.getInclude(), mapUserInfo);
mapArchiveInfo(foundNode, mapUserInfo);
nodesFound.add(foundNode);
}
return CollectionWithPagingInfo.asPaged(parameters.getPaging(), nodesFound, result.hasMoreItems(), (totalItems == null ? null : totalItems.intValue()));
}
use of org.alfresco.rest.api.model.Node 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.rest.api.model.Node in project alfresco-remote-api by Alfresco.
the class ResultMapperTests method testToCollectionWithPagingInfo.
@Test
public void testToCollectionWithPagingInfo() throws Exception {
ResultSet results = mockResultset(Arrays.asList(514l), Arrays.asList(566l, VERSIONED_ID));
SearchRequestContext searchRequest = SearchRequestContext.from(SearchQuery.EMPTY);
CollectionWithPagingInfo<Node> collectionWithPage = mapper.toCollectionWithPagingInfo(EMPTY_PARAMS, searchRequest, SearchQuery.EMPTY, results);
assertNotNull(collectionWithPage);
Long found = results.getNumberFound();
assertEquals(found.intValue(), collectionWithPage.getTotalItems().intValue());
Node firstNode = collectionWithPage.getCollection().stream().findFirst().get();
assertNotNull(firstNode.getSearch().getScore());
assertEquals(StoreMapper.LIVE_NODES, firstNode.getLocation());
collectionWithPage.getCollection().stream().forEach(aNode -> {
List<HighlightEntry> high = aNode.getSearch().getHighlight();
if (high != null) {
assertEquals(2, high.size());
HighlightEntry first = high.get(0);
assertNotNull(first.getField());
assertNotNull(first.getSnippets());
}
});
// 1 deleted node in the test data
assertEquals(1l, collectionWithPage.getCollection().stream().filter(node -> StoreMapper.DELETED.equals(node.getLocation())).count());
// 1 version nodes in the test data (and 1 is not shown because it is in the archive store)
assertEquals(1l, collectionWithPage.getCollection().stream().filter(node -> StoreMapper.VERSIONS.equals(node.getLocation())).count());
}
Aggregations