Search in sources :

Example 6 with Node

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;
}
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) Node(org.alfresco.rest.api.model.Node) InvalidNodeRefException(org.alfresco.service.cmr.repository.InvalidNodeRefException) EntityNotFoundException(org.alfresco.rest.framework.core.exceptions.EntityNotFoundException)

Example 7 with Node

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;
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) Node(org.alfresco.rest.api.model.Node)

Example 8 with Node

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()));
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) ArchivedNodesCannedQueryBuilder(org.alfresco.repo.node.archive.ArchivedNodesCannedQueryBuilder) HashMap(java.util.HashMap) ArchivedNodesCannedQueryBuilder(org.alfresco.repo.node.archive.ArchivedNodesCannedQueryBuilder) Node(org.alfresco.rest.api.model.Node) ArrayList(java.util.ArrayList) HashMap(java.util.HashMap) Map(java.util.Map) PagingRequest(org.alfresco.query.PagingRequest)

Example 9 with Node

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());
}
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 10 with Node

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());
}
Also used : Node(org.alfresco.rest.api.model.Node) ResultSet(org.alfresco.service.cmr.search.ResultSet) EmptyResultSet(org.alfresco.repo.search.EmptyResultSet) SolrJSONResultSet(org.alfresco.repo.search.impl.lucene.SolrJSONResultSet) SearchRequestContext(org.alfresco.rest.api.search.context.SearchRequestContext) HighlightEntry(org.alfresco.rest.api.search.model.HighlightEntry) Test(org.junit.Test)

Aggregations

Node (org.alfresco.rest.api.model.Node)21 NodeRef (org.alfresco.service.cmr.repository.NodeRef)14 HashMap (java.util.HashMap)12 QName (org.alfresco.service.namespace.QName)10 Serializable (java.io.Serializable)7 UserInfo (org.alfresco.rest.api.model.UserInfo)7 ArrayList (java.util.ArrayList)6 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)4 EntityNotFoundException (org.alfresco.rest.framework.core.exceptions.EntityNotFoundException)4 ChildAssociationRef (org.alfresco.service.cmr.repository.ChildAssociationRef)4 FilterPropBoolean (org.alfresco.repo.node.getchildren.FilterPropBoolean)3 SearchRequestContext (org.alfresco.rest.api.search.context.SearchRequestContext)3 WebApiDescription (org.alfresco.rest.framework.WebApiDescription)3 InvalidArgumentException (org.alfresco.rest.framework.core.exceptions.InvalidArgumentException)3 Version (org.alfresco.service.cmr.version.Version)3 List (java.util.List)2 Map (java.util.Map)2 PagingRequest (org.alfresco.query.PagingRequest)2 EmptyResultSet (org.alfresco.repo.search.EmptyResultSet)2 SolrJSONResultSet (org.alfresco.repo.search.impl.lucene.SolrJSONResultSet)2