mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-07-31 17:39:05 +00:00
DOD Recert: Search sort order now works as expected
git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/modules/recordsmanagement/DEV/DODRECERT@50934 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -25,7 +25,6 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.alfresco.error.AlfrescoRuntimeException;
|
||||
import org.alfresco.model.ContentModel;
|
||||
import org.alfresco.service.namespace.NamespaceService;
|
||||
import org.alfresco.service.namespace.QName;
|
||||
import org.json.JSONArray;
|
||||
@@ -38,14 +37,6 @@ import org.json.JSONObject;
|
||||
@SuppressWarnings("serial")
|
||||
public class RecordsManagementSearchParameters
|
||||
{
|
||||
/** Default sort order */
|
||||
private static final Map<QName, Boolean> DEFAULT_SORT_ORDER = new HashMap<QName, Boolean>()
|
||||
{
|
||||
{
|
||||
put(ContentModel.PROP_NAME, Boolean.TRUE);
|
||||
}
|
||||
};
|
||||
|
||||
/** Default templates */
|
||||
private static final Map<String, String> DEFAULT_TEMPLATES = new HashMap<String, String>()
|
||||
{
|
||||
@@ -87,7 +78,7 @@ public class RecordsManagementSearchParameters
|
||||
private boolean includeCutoff = false;
|
||||
|
||||
private List<QName> includedContainerTypes = DEFAULT_INCLUDED_CONTAINER_TYPES;
|
||||
private Map<QName, Boolean> sortOrder = DEFAULT_SORT_ORDER;
|
||||
private List<SortItem> sortOrder;
|
||||
private Map<String, String> templates = DEFAULT_TEMPLATES;
|
||||
|
||||
private static final String JSON_MAXITEMS = "maxitems";
|
||||
@@ -196,16 +187,16 @@ public class RecordsManagementSearchParameters
|
||||
if (jsonObject.has(JSON_SORT) == true)
|
||||
{
|
||||
JSONArray jsonArray = jsonObject.getJSONArray(JSON_SORT);
|
||||
Map<QName, Boolean> sortOrder = new HashMap<QName, Boolean>(jsonArray.length());
|
||||
List<SortItem> sortOrder = new ArrayList<SortItem>(jsonArray.length());
|
||||
for (int i = 0; i < jsonArray.length(); i++)
|
||||
{
|
||||
JSONObject sortJSONObject = jsonArray.getJSONObject(i);
|
||||
if (sortJSONObject.has(JSON_FIELD) == true &&
|
||||
sortJSONObject.has(JSON_ASCENDING) == true)
|
||||
{
|
||||
sortOrder.put(
|
||||
sortOrder.add(new SortItem(
|
||||
QName.createQName(sortJSONObject.getString(JSON_FIELD), namespaceService),
|
||||
Boolean.valueOf(sortJSONObject.getBoolean(JSON_ASCENDING)));
|
||||
sortJSONObject.getBoolean(JSON_ASCENDING)));
|
||||
}
|
||||
}
|
||||
searchParameters.setSortOrder(sortOrder);
|
||||
@@ -251,11 +242,11 @@ public class RecordsManagementSearchParameters
|
||||
|
||||
// Sort
|
||||
JSONArray jsonSortArray = new JSONArray();
|
||||
for (Map.Entry<QName, Boolean> entry : sortOrder.entrySet())
|
||||
for (SortItem entry : sortOrder)
|
||||
{
|
||||
JSONObject jsonEntry = new JSONObject();
|
||||
jsonEntry.put(JSON_FIELD, entry.getKey().toPrefixString(namespaceService));
|
||||
jsonEntry.put(JSON_ASCENDING, entry.getValue().booleanValue());
|
||||
jsonEntry.put(JSON_FIELD, entry.property.toPrefixString(namespaceService));
|
||||
jsonEntry.put(JSON_ASCENDING, entry.assc);
|
||||
jsonSortArray.put(jsonEntry);
|
||||
}
|
||||
jsonObject.put(JSON_SORT, jsonSortArray);
|
||||
@@ -278,12 +269,12 @@ public class RecordsManagementSearchParameters
|
||||
return maxItems;
|
||||
}
|
||||
|
||||
public void setSortOrder(Map<QName, Boolean> sortOrder)
|
||||
public void setSortOrder(List<SortItem> sortOrder)
|
||||
{
|
||||
this.sortOrder = sortOrder;
|
||||
}
|
||||
|
||||
public Map<QName, Boolean> getSortOrder()
|
||||
public List<SortItem> getSortOrder()
|
||||
{
|
||||
return sortOrder;
|
||||
}
|
||||
|
@@ -182,9 +182,9 @@ public class RecordsManagementSearchServiceImpl implements RecordsManagementSear
|
||||
searchParameters.setNamespace(RecordsManagementModel.RM_URI);
|
||||
|
||||
// set sort
|
||||
for(Entry<QName, Boolean> entry : rmSearchParameters.getSortOrder().entrySet())
|
||||
for(SortItem entry : rmSearchParameters.getSortOrder())
|
||||
{
|
||||
searchParameters.addSort(entry.getKey().toPrefixString(namespaceService), entry.getValue().booleanValue());
|
||||
searchParameters.addSort(entry.property.toPrefixString(namespaceService), entry.assc);
|
||||
}
|
||||
|
||||
// set templates
|
||||
|
@@ -21,9 +21,7 @@ package org.alfresco.module.org_alfresco_module_rm.search;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.net.URLDecoder;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.alfresco.module.org_alfresco_module_rm.model.RecordsManagementModel;
|
||||
import org.alfresco.service.namespace.NamespaceService;
|
||||
@@ -128,10 +126,6 @@ public class SavedSearchDetailsCompatibility implements RecordsManagementModel
|
||||
{
|
||||
includedContainerTypes.add(TYPE_RECORD_CATEGORY);
|
||||
}
|
||||
// else if ("series".equals(paramName) == true && Boolean.parseBoolean(paramValue) == true)
|
||||
// {
|
||||
// includedContainerTypes.add(DOD5015Model.TYPE_RECORD_SERIES);
|
||||
// }
|
||||
}
|
||||
result.setIncludedContainerTypes(includedContainerTypes);
|
||||
|
||||
@@ -139,7 +133,7 @@ public class SavedSearchDetailsCompatibility implements RecordsManagementModel
|
||||
{
|
||||
// Map the sort string into the search details
|
||||
String[] sortPairs = sort.split(",");
|
||||
Map<QName, Boolean> sortOrder = new HashMap<QName, Boolean>(sortPairs.length);
|
||||
List<SortItem> sortOrder = new ArrayList<SortItem>(sortPairs.length);
|
||||
for (String sortPairString : sortPairs)
|
||||
{
|
||||
String[] sortPair = sortPairString.split("/");
|
||||
@@ -149,7 +143,7 @@ public class SavedSearchDetailsCompatibility implements RecordsManagementModel
|
||||
{
|
||||
isAcsending = Boolean.TRUE;
|
||||
}
|
||||
sortOrder.put(field, isAcsending);
|
||||
sortOrder.add(new SortItem(field, isAcsending));
|
||||
}
|
||||
result.setSortOrder(sortOrder);
|
||||
}
|
||||
@@ -178,7 +172,7 @@ public class SavedSearchDetailsCompatibility implements RecordsManagementModel
|
||||
{
|
||||
StringBuilder builder = new StringBuilder(64);
|
||||
|
||||
for (Map.Entry<QName, Boolean> entry : this.savedSearchDetails.getSearchParameters().getSortOrder().entrySet())
|
||||
for (SortItem entry : this.savedSearchDetails.getSearchParameters().getSortOrder())
|
||||
{
|
||||
if (builder.length() !=0)
|
||||
{
|
||||
@@ -186,11 +180,11 @@ public class SavedSearchDetailsCompatibility implements RecordsManagementModel
|
||||
}
|
||||
|
||||
String order = "desc";
|
||||
if (Boolean.TRUE.equals(entry.getValue()) == true)
|
||||
if (entry.assc == true)
|
||||
{
|
||||
order = "asc";
|
||||
}
|
||||
builder.append(entry.getKey().toPrefixString(this.namespaceService))
|
||||
builder.append(entry.property.toPrefixString(this.namespaceService))
|
||||
.append("/")
|
||||
.append(order);
|
||||
}
|
||||
|
@@ -0,0 +1,15 @@
|
||||
package org.alfresco.module.org_alfresco_module_rm.search;
|
||||
|
||||
import org.alfresco.service.namespace.QName;
|
||||
|
||||
/*package*/ class SortItem
|
||||
{
|
||||
public QName property = null;
|
||||
public boolean assc = true;
|
||||
public SortItem(QName property, boolean assc)
|
||||
{
|
||||
this.property = property;
|
||||
this.assc = assc;
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user