mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-08-14 17:58:59 +00:00
Merged 5.2.N (5.2.1) to HEAD (5.2)
130297 gjames: Merged searchapi (5.2.1) to 5.2.N (5.2.1) 130050 gjames: SEARCH-161: Supporting synonyms for sorting fieldNames git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@130369 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -341,7 +341,7 @@ public class NodesImpl implements Nodes
|
|||||||
ContentModel.PROP_LOCK_OWNER,
|
ContentModel.PROP_LOCK_OWNER,
|
||||||
ContentModel.PROP_WORKING_COPY_OWNER);
|
ContentModel.PROP_WORKING_COPY_OWNER);
|
||||||
|
|
||||||
private final static Map<String,QName> MAP_PARAM_QNAME;
|
public final static Map<String,QName> PARAM_SYNONYMS_QNAME;
|
||||||
static
|
static
|
||||||
{
|
{
|
||||||
Map<String,QName> aMap = new HashMap<>(9);
|
Map<String,QName> aMap = new HashMap<>(9);
|
||||||
@@ -356,7 +356,7 @@ public class NodesImpl implements Nodes
|
|||||||
aMap.put(PARAM_SIZEINBYTES, GetChildrenCannedQuery.SORT_QNAME_CONTENT_SIZE);
|
aMap.put(PARAM_SIZEINBYTES, GetChildrenCannedQuery.SORT_QNAME_CONTENT_SIZE);
|
||||||
aMap.put(PARAM_NODETYPE, GetChildrenCannedQuery.SORT_QNAME_NODE_TYPE);
|
aMap.put(PARAM_NODETYPE, GetChildrenCannedQuery.SORT_QNAME_NODE_TYPE);
|
||||||
|
|
||||||
MAP_PARAM_QNAME = Collections.unmodifiableMap(aMap);
|
PARAM_SYNONYMS_QNAME = Collections.unmodifiableMap(aMap);
|
||||||
}
|
}
|
||||||
|
|
||||||
// list children filtering (via where clause)
|
// list children filtering (via where clause)
|
||||||
@@ -1259,7 +1259,7 @@ public class NodesImpl implements Nodes
|
|||||||
sortProps = new ArrayList<>(sortCols.size());
|
sortProps = new ArrayList<>(sortCols.size());
|
||||||
for (SortColumn sortCol : sortCols)
|
for (SortColumn sortCol : sortCols)
|
||||||
{
|
{
|
||||||
QName propQname = MAP_PARAM_QNAME.get(sortCol.column);
|
QName propQname = PARAM_SYNONYMS_QNAME.get(sortCol.column);
|
||||||
if (propQname == null)
|
if (propQname == null)
|
||||||
{
|
{
|
||||||
propQname = createQName(sortCol.column);
|
propQname = createQName(sortCol.column);
|
||||||
|
@@ -45,7 +45,9 @@ import org.alfresco.service.cmr.search.SearchParameters;
|
|||||||
import org.alfresco.rest.api.model.Node;
|
import org.alfresco.rest.api.model.Node;
|
||||||
import org.alfresco.service.cmr.search.SearchParameters.Operator;
|
import org.alfresco.service.cmr.search.SearchParameters.Operator;
|
||||||
import org.alfresco.service.cmr.search.SearchParameters.SortDefinition;
|
import org.alfresco.service.cmr.search.SearchParameters.SortDefinition;
|
||||||
|
import org.alfresco.service.cmr.search.SearchParameters.SortDefinition.SortType;
|
||||||
import org.alfresco.service.cmr.search.SearchService;
|
import org.alfresco.service.cmr.search.SearchService;
|
||||||
|
import org.alfresco.service.namespace.QName;
|
||||||
import org.alfresco.util.ParameterCheck;
|
import org.alfresco.util.ParameterCheck;
|
||||||
import org.apache.commons.lang.NotImplementedException;
|
import org.apache.commons.lang.NotImplementedException;
|
||||||
|
|
||||||
@@ -55,6 +57,7 @@ import static org.alfresco.rest.api.Nodes.PARAM_INCLUDE_ISLINK;
|
|||||||
import static org.alfresco.rest.api.Nodes.PARAM_INCLUDE_PATH;
|
import static org.alfresco.rest.api.Nodes.PARAM_INCLUDE_PATH;
|
||||||
import static org.alfresco.rest.api.Nodes.PARAM_INCLUDE_ASPECTNAMES;
|
import static org.alfresco.rest.api.Nodes.PARAM_INCLUDE_ASPECTNAMES;
|
||||||
import static org.alfresco.rest.api.Nodes.PARAM_INCLUDE_PROPERTIES;
|
import static org.alfresco.rest.api.Nodes.PARAM_INCLUDE_PROPERTIES;
|
||||||
|
import static org.alfresco.rest.api.impl.NodesImpl.PARAM_SYNONYMS_QNAME;
|
||||||
import static org.alfresco.service.cmr.search.SearchService.*;
|
import static org.alfresco.service.cmr.search.SearchService.*;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
@@ -177,7 +180,10 @@ public class SearchMapper
|
|||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
sp.addSort(sortDef.toDefinition());
|
SortType sortType = SortType.valueOf(sortDef.getType());
|
||||||
|
String field = sortDef.getField();
|
||||||
|
QName propQname = PARAM_SYNONYMS_QNAME.get(field);
|
||||||
|
sp.addSort(new SortDefinition(sortType, propQname==null?field:propQname.toString(), sortDef.isAscending()));
|
||||||
}
|
}
|
||||||
catch (IllegalArgumentException e)
|
catch (IllegalArgumentException e)
|
||||||
{
|
{
|
||||||
|
@@ -59,15 +59,13 @@ public class SortDef
|
|||||||
return type;
|
return type;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
public String getField()
|
||||||
* You are allowed to create an instance of this class that has an invalid sortType
|
|
||||||
* but this method will validate the definition is correct and return it.
|
|
||||||
*
|
|
||||||
* @return SortDefinition
|
|
||||||
*/
|
|
||||||
public SortDefinition toDefinition()
|
|
||||||
{
|
{
|
||||||
return new SortDefinition(SortType.valueOf(type), field, ascending);
|
return field;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean isAscending()
|
||||||
|
{
|
||||||
|
return ascending;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -193,6 +193,23 @@ public class SearchMapperTests
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
searchParameters = new SearchParameters();
|
||||||
|
searchMapper.fromSort(searchParameters, Arrays.asList(new SortDef("FIELD", "createdAt", true)));
|
||||||
|
assertEquals(1 , searchParameters.getSortDefinitions().size());
|
||||||
|
assertEquals("{http://www.alfresco.org/model/content/1.0}created", searchParameters.getSortDefinitions().get(0).getField());
|
||||||
|
|
||||||
|
searchParameters = new SearchParameters();
|
||||||
|
searchMapper.fromSort(searchParameters, Arrays.asList(new SortDef("FIELD", "cm:created", true)));
|
||||||
|
assertEquals("cm:created", searchParameters.getSortDefinitions().get(0).getField());
|
||||||
|
|
||||||
|
searchParameters = new SearchParameters();
|
||||||
|
searchMapper.fromSort(searchParameters, Arrays.asList(new SortDef("FIELD", "modifiedByUser", true)));
|
||||||
|
assertEquals("{http://www.alfresco.org/model/content/1.0}modifier", searchParameters.getSortDefinitions().get(0).getField());
|
||||||
|
|
||||||
|
searchParameters = new SearchParameters();
|
||||||
|
searchMapper.fromSort(searchParameters, Arrays.asList(new SortDef("FIELD", "nodeType", true)));
|
||||||
|
assertEquals("{}TYPE", searchParameters.getSortDefinitions().get(0).getField());
|
||||||
|
|
||||||
searchParameters = new SearchParameters();
|
searchParameters = new SearchParameters();
|
||||||
searchParameters.setLanguage(SearchMapper.CMIS);
|
searchParameters.setLanguage(SearchMapper.CMIS);
|
||||||
try
|
try
|
||||||
|
Reference in New Issue
Block a user