ACE-5622: Search api scope now uses "locations"

git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/BRANCHES/DEV/5.2.N/root@133518 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Gethin James
2016-12-08 15:49:24 +00:00
parent ffdb176db2
commit d8c47d60e1
17 changed files with 539 additions and 47 deletions

View File

@@ -27,10 +27,13 @@ package org.alfresco.rest.api;
import org.alfresco.repo.node.archive.RestoreNodeReport;
import org.alfresco.rest.api.model.Node;
import org.alfresco.rest.api.model.UserInfo;
import org.alfresco.rest.framework.resource.parameters.CollectionWithPagingInfo;
import org.alfresco.rest.framework.resource.parameters.Parameters;
import org.alfresco.service.cmr.repository.NodeRef;
import java.util.Map;
/**
* Handles trashcan / deleted nodes
*
@@ -38,8 +41,33 @@ import org.alfresco.service.cmr.repository.NodeRef;
*/
public interface DeletedNodes
{
/**
* Lists deleted nodes using a ArchivedNodesCannedQuery
* @param parameters
* @return Collection of deleted Nodes
*/
CollectionWithPagingInfo<Node> listDeleted(Parameters parameters);
Node getDeletedNode(String originalId, Parameters parameters);
/**
* Gets a single deleted node by id.
* @param originalId
* @param parameters
* @param fullnode Should we return the full representation of the minimal one?
* @param mapUserInfo
* @return a deleted node
*/
Node getDeletedNode(String originalId, Parameters parameters, boolean fullnode, Map<String, UserInfo> mapUserInfo);
/**
* Restores a deleted node and returns it.
* @param archivedId
* @return the new undeleted node.
*/
Node restoreArchivedNode(String archivedId);
/**
* Permanently delete the node.
* @param archivedId
*/
void purgeArchivedNode(String archivedId);
}

View File

@@ -130,7 +130,7 @@ public class DeletedNodesImpl implements DeletedNodes
}
@Override
public Node getDeletedNode(String originalId, Parameters parameters)
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);
@@ -139,8 +139,16 @@ public class DeletedNodesImpl implements DeletedNodes
NodeRef nodeRef = new NodeRef(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE, validatedNodeRef.getId());
NodeRef archivedNodeRef = nodeArchiveService.getArchivedNode(nodeRef);
//Turn it into a JSON Node (FULL version)
Node foundNode = nodes.getFolderOrDocumentFullInfo(archivedNodeRef, null, null, parameters, null);
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;
}

View File

@@ -70,7 +70,9 @@ public class Node implements Comparable<Node>
protected UserInfo archivedByUser;
// Version info - specifically for version node - see Version History API
protected String versionLabel;
protected String versionComment;
protected String nodeId; //This is the frozen node id NOT the current node id
protected Boolean isFolder;
protected Boolean isFile;
@@ -95,6 +97,7 @@ public class Node implements Comparable<Node>
//optional SearchEntry (only ever returned from a search)
protected SearchEntry search = null;
protected String location;
public Node(NodeRef nodeRef, NodeRef parentNodeRef, Map<QName, Serializable> nodeProps, Map<String, UserInfo> mapUserInfo, ServiceRegistry sr)
{
@@ -377,6 +380,16 @@ public class Node implements Comparable<Node>
this.archivedByUser = archivedByUser;
}
public String getVersionLabel()
{
return versionLabel;
}
public void setVersionLabel(String versionLabel)
{
this.versionLabel = versionLabel;
}
public String getVersionComment()
{
return versionComment;
@@ -387,6 +400,26 @@ public class Node implements Comparable<Node>
this.versionComment = versionComment;
}
public String getLocation()
{
return location;
}
public void setLocation(String location)
{
this.location = location;
}
public String getNodeId()
{
return nodeId;
}
public void setNodeId(String nodeId)
{
this.nodeId = nodeId;
}
public boolean equals(Object other)
{
if(this == other)
@@ -451,6 +484,22 @@ public class Node implements Comparable<Node>
{
sb.append(", archivedByUser=").append(getArchivedByUser());
}
if (getVersionLabel() != null)
{
sb.append(", versionLabel=").append(getVersionLabel());
}
if (getVersionComment() != null)
{
sb.append(", versionComment=").append(getVersionComment());
}
if (getLocation() != null)
{
sb.append(", location=").append(getLocation());
}
if (getNodeId() != null)
{
sb.append(", nodeId=").append(getNodeId());
}
if (getIsLink() != null)
{
sb.append(", isLink=").append(getIsLink()); // note: symbolic link (not shared link)

View File

@@ -133,8 +133,12 @@ public class NodeVersionsRelation extends AbstractNodeRelation implements
private void mapVersionInfo(Version v, Node aNode)
{
aNode.setNodeRef(new NodeRef("", "", v.getVersionLabel()));
mapVersionInfo(v, aNode, new NodeRef("", "", v.getVersionLabel()));
}
public void mapVersionInfo(Version v, Node aNode, NodeRef nodeRef)
{
aNode.setNodeRef(nodeRef);
aNode.setVersionComment(v.getDescription());
Map<String, Object> props = aNode.getProperties();
@@ -279,7 +283,7 @@ public class NodeVersionsRelation extends AbstractNodeRelation implements
}
}
private Version findVersion(String nodeId, String versionLabelId)
public Version findVersion(String nodeId, String versionLabelId)
{
NodeRef nodeRef = nodes.validateOrLookupNode(nodeId, null);
VersionHistory vh = versionService.getVersionHistory(nodeRef);

View File

@@ -77,8 +77,8 @@ public class SearchApiWebscript extends AbstractWebScript implements RecognizedP
PropertyCheck.mandatory(this, "serviceRegistry", serviceRegistry);
this.searchService = serviceRegistry.getSearchService();
ParameterCheck.mandatory("assistant", this.assistant);
searchMapper = new SearchMapper();
ParameterCheck.mandatory("searchMapper", this.searchMapper);
ParameterCheck.mandatory("resultMapper", this.resultMapper);
}
@Override
@@ -142,6 +142,11 @@ public class SearchApiWebscript extends AbstractWebScript implements RecognizedP
return Params.valueOf(null, recognizedParams, null, webScriptRequest);
}
public void setSearchMapper(SearchMapper searchMapper)
{
this.searchMapper = searchMapper;
}
public void setResultMapper(ResultMapper resultMapper)
{
this.resultMapper = resultMapper;

View File

@@ -26,11 +26,18 @@
package org.alfresco.rest.api.search.impl;
import static org.alfresco.rest.api.search.impl.StoreMapper.DELETED;
import static org.alfresco.rest.api.search.impl.StoreMapper.LIVE_NODES;
import static org.alfresco.rest.api.search.impl.StoreMapper.VERSIONS;
import org.alfresco.repo.search.impl.lucene.SolrJSONResultSet;
import org.alfresco.repo.version.Version2Model;
import org.alfresco.repo.version.VersionBaseModel;
import org.alfresco.rest.api.DeletedNodes;
import org.alfresco.rest.api.Nodes;
import org.alfresco.rest.api.lookups.PropertyLookupRegistry;
import org.alfresco.rest.api.model.Node;
import org.alfresco.rest.api.model.UserInfo;
import org.alfresco.rest.api.nodes.NodeVersionsRelation;
import org.alfresco.rest.api.search.context.FacetFieldContext;
import org.alfresco.rest.api.search.context.FacetFieldContext.Bucket;
import org.alfresco.rest.api.search.context.FacetQueryContext;
@@ -38,15 +45,24 @@ import org.alfresco.rest.api.search.context.SearchContext;
import org.alfresco.rest.api.search.context.SpellCheckContext;
import org.alfresco.rest.api.search.model.HighlightEntry;
import org.alfresco.rest.api.search.model.SearchEntry;
import org.alfresco.rest.framework.core.exceptions.EntityNotFoundException;
import org.alfresco.rest.framework.resource.parameters.CollectionWithPagingInfo;
import org.alfresco.rest.framework.resource.parameters.Params;
import org.alfresco.service.ServiceRegistry;
import org.alfresco.service.cmr.repository.InvalidNodeRefException;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.cmr.repository.StoreRef;
import org.alfresco.service.cmr.search.ResultSet;
import org.alfresco.service.cmr.search.ResultSetRow;
import org.alfresco.service.cmr.search.SpellCheckResult;
import org.alfresco.service.cmr.version.Version;
import org.alfresco.service.cmr.version.VersionHistory;
import org.alfresco.service.namespace.QName;
import org.alfresco.util.Pair;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
@@ -60,15 +76,38 @@ import java.util.Map.Entry;
*/
public class ResultMapper
{
private ServiceRegistry serviceRegistry;
private Nodes nodes;
private NodeVersionsRelation nodeVersions;
private PropertyLookupRegistry propertyLookup;
private StoreMapper storeMapper;
private DeletedNodes deletedNodes;
private static Log logger = LogFactory.getLog(ResultMapper.class);
public ResultMapper()
{
}
public void setServiceRegistry(ServiceRegistry serviceRegistry)
{
this.serviceRegistry = serviceRegistry;
}
public void setNodeVersions(NodeVersionsRelation nodeVersions)
{
this.nodeVersions = nodeVersions;
}
public void setDeletedNodes(DeletedNodes deletedNodes)
{
this.deletedNodes = deletedNodes;
}
public void setStoreMapper(StoreMapper storeMapper)
{
this.storeMapper = storeMapper;
}
public void setNodes(Nodes nodes)
{
this.nodes = nodes;
@@ -92,10 +131,12 @@ public class ResultMapper
List<Node> noderesults = new ArrayList();
Map<String, UserInfo> mapUserInfo = new HashMap<>(10);
Map<NodeRef, List<Pair<String, List<String>>>> hightLighting = results.getHighlighting();
int notFound = 0;
results.forEach(row ->
for (ResultSetRow row:results)
{
Node aNode = nodes.getFolderOrDocument(row.getNodeRef(), null, null, params.getInclude(), mapUserInfo);
Node aNode = getNode(row, params, mapUserInfo);
if (aNode != null)
{
float f = row.getScore();
@@ -116,15 +157,16 @@ public class ResultMapper
else
{
logger.debug("Unknown noderef returned from search results "+row.getNodeRef());
notFound++;
}
});
}
SolrJSONResultSet solrResultSet = findSolrResultSet(results);
if (solrResultSet != null)
{
//We used Solr for this query
context = toSearchContext(solrResultSet);
context = toSearchContext(solrResultSet, notFound);
total = setTotal(solrResultSet);
}
else
@@ -141,6 +183,65 @@ public class ResultMapper
return CollectionWithPagingInfo.asPaged(params.getPaging(), noderesults, results.hasMore(), total, null, context);
}
/**
* Builds a node representation based on a ResultSetRow;
* @param aRow
* @param params
* @param mapUserInfo
* @return Node
*/
public Node getNode(ResultSetRow aRow, Params params, Map<String, UserInfo> mapUserInfo)
{
String nodeStore = storeMapper.getStore(aRow.getNodeRef());
Node aNode = null;
switch (nodeStore)
{
case LIVE_NODES:
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
{
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;
}
/**
* Sets the total number found.
* @param results
@@ -158,7 +259,7 @@ public class ResultMapper
* @param SolrJSONResultSet
* @return SearchContext
*/
public SearchContext toSearchContext(SolrJSONResultSet solrResultSet)
public SearchContext toSearchContext(SolrJSONResultSet solrResultSet, int notFound)
{
SearchContext context = null;
Map<String, Integer> facetQueries = solrResultSet.getFacetQueries();

View File

@@ -83,6 +83,7 @@ public class SearchMapper
public static final String CMIS = "cmis";
public static final String LUCENE = "lucene";
public static final String AFTS = "afts";
private StoreMapper storeMapper;
/**
* Turn the SearchQuery params serialized by Jackson into the Java SearchParameters object
@@ -430,7 +431,7 @@ public class SearchMapper
{
if (scope != null)
{
List<String> stores = scope.getStores();
List<String> stores = scope.getLocations();
if (stores!= null && !stores.isEmpty())
{
//First reset the stores then add them.
@@ -439,7 +440,7 @@ public class SearchMapper
{
try
{
sp.addStore(new StoreRef(aStore));
sp.addStore(storeMapper.getStoreRef(aStore));
}
catch (AlfrescoRuntimeException are)
{
@@ -485,4 +486,9 @@ public class SearchMapper
}
}
}
public void setStoreMapper(StoreMapper storeMapper)
{
this.storeMapper = storeMapper;
}
}

View File

@@ -0,0 +1,102 @@
/*-
* #%L
* Alfresco Remote API
* %%
* Copyright (C) 2005 - 2016 Alfresco Software Limited
* %%
* This file is part of the Alfresco software.
* If the software was purchased under a paid Alfresco license, the terms of
* the paid license agreement will prevail. Otherwise, the software is
* provided under the following open source license terms:
*
* Alfresco is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Alfresco is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
* #L%
*/
package org.alfresco.rest.api.search.impl;
import org.alfresco.repo.version.Version2Model;
import org.alfresco.rest.framework.core.exceptions.InvalidArgumentException;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.cmr.repository.StoreRef;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
/**
* Maps to and from a StoreRef for the json public api.
*
* @author Gethin James
*/
public class StoreMapper
{
public static final String LIVE_NODES = "nodes";
public static final String VERSIONS = "versions";
public static final String DELETED = "deleted-nodes";
private static Log logger = LogFactory.getLog(StoreMapper.class);
public static final StoreRef STORE_REF_VERSION2_SPACESSTORE = new StoreRef("workspace", Version2Model.STORE_ID);
/**
* Work out which StoreRef this store belongs to.
* @param String representing a store
* @return StoreRef
*/
public StoreRef getStoreRef(String store)
{
if (store != null && !store.isEmpty())
{
switch (store.toLowerCase())
{
case LIVE_NODES:
return StoreRef.STORE_REF_WORKSPACE_SPACESSTORE;
case VERSIONS:
return STORE_REF_VERSION2_SPACESSTORE;
case DELETED:
return StoreRef.STORE_REF_ARCHIVE_SPACESSTORE;
}
}
throw new InvalidArgumentException(InvalidArgumentException.DEFAULT_MESSAGE_ID,
new Object[] { ": scope allowed values: nodes,deleted-nodes,versions" });
}
/**
* Work out which store this noderef belongs to.
* @param nodeRef
* @return String representing a store
*/
public String getStore(NodeRef nodeRef)
{
if (nodeRef != null)
{
if (StoreRef.STORE_REF_WORKSPACE_SPACESSTORE.equals(nodeRef.getStoreRef()))
{
return LIVE_NODES;
}
if (STORE_REF_VERSION2_SPACESSTORE.equals(nodeRef.getStoreRef()))
{
return VERSIONS;
}
if (StoreRef.STORE_REF_ARCHIVE_SPACESSTORE.equals(nodeRef.getStoreRef()))
{
return DELETED;
}
}
logger.warn("Unknown store ref: "+nodeRef);
return null;
}
}

View File

@@ -37,16 +37,16 @@ import java.util.List;
*/
public class Scope
{
private final List<String> stores;
private final List<String> locations;
@JsonCreator
public Scope(@JsonProperty("stores") List<String> stores)
public Scope(@JsonProperty("locations") List<String> locations)
{
this.stores = stores;
this.locations = locations;
}
public List<String> getStores()
public List<String> getLocations()
{
return stores;
return locations;
}
}

View File

@@ -77,7 +77,7 @@ public class TrashcanEntityResource implements
@Override
public Node readById(String nodeId, Parameters parameters) throws EntityNotFoundException
{
return deletedNodes.getDeletedNode(nodeId, parameters);
return deletedNodes.getDeletedNode(nodeId, parameters, true, null);
}
@Operation("restore")