mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-08-07 17:49:17 +00:00
Search for undeclared records results in exception
git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/modules/recordsmanagement/DEV/DODRECERT@51218 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -21,6 +21,7 @@ package org.alfresco.module.org_alfresco_module_rm.script.slingshot;
|
|||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
import java.io.UnsupportedEncodingException;
|
import java.io.UnsupportedEncodingException;
|
||||||
import java.net.URLEncoder;
|
import java.net.URLEncoder;
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@@ -53,7 +54,7 @@ import org.springframework.extensions.webscripts.WebScriptRequest;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* RM search GET web script
|
* RM search GET web script
|
||||||
*
|
*
|
||||||
* @author Roy Wetherall
|
* @author Roy Wetherall
|
||||||
*/
|
*/
|
||||||
public class RMSearchGet extends DeclarativeWebScript
|
public class RMSearchGet extends DeclarativeWebScript
|
||||||
@@ -63,34 +64,34 @@ public class RMSearchGet extends DeclarativeWebScript
|
|||||||
private static final String PARAM_SORTBY = "sortby";
|
private static final String PARAM_SORTBY = "sortby";
|
||||||
private static final String PARAM_FILTERS = "filters";
|
private static final String PARAM_FILTERS = "filters";
|
||||||
private static final String PARAM_MAX_ITEMS = "maxitems";
|
private static final String PARAM_MAX_ITEMS = "maxitems";
|
||||||
|
|
||||||
/** Records management search service */
|
/** Records management search service */
|
||||||
protected RecordsManagementSearchService recordsManagementSearchService;
|
protected RecordsManagementSearchService recordsManagementSearchService;
|
||||||
|
|
||||||
/** Site service */
|
/** Site service */
|
||||||
protected SiteService siteService;
|
protected SiteService siteService;
|
||||||
|
|
||||||
/** Namespace service */
|
/** Namespace service */
|
||||||
protected NamespaceService namespaceService;
|
protected NamespaceService namespaceService;
|
||||||
|
|
||||||
/** Node serivce */
|
/** Node serivce */
|
||||||
protected NodeService nodeService;
|
protected NodeService nodeService;
|
||||||
|
|
||||||
/** Dictionary service */
|
/** Dictionary service */
|
||||||
protected DictionaryService dictionaryService;
|
protected DictionaryService dictionaryService;
|
||||||
|
|
||||||
/** Permission service */
|
/** Permission service */
|
||||||
protected PermissionService permissionService;
|
protected PermissionService permissionService;
|
||||||
|
|
||||||
/** Person service */
|
/** Person service */
|
||||||
protected PersonService personService;
|
protected PersonService personService;
|
||||||
|
|
||||||
/** Content service */
|
/** Content service */
|
||||||
protected ContentService contentService;
|
protected ContentService contentService;
|
||||||
|
|
||||||
/** Person data cache */
|
/** Person data cache */
|
||||||
private Map<String, String> personDataCache = null;
|
private Map<String, String> personDataCache = null;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param recordsManagementSearchService records management search service
|
* @param recordsManagementSearchService records management search service
|
||||||
*/
|
*/
|
||||||
@@ -98,7 +99,7 @@ public class RMSearchGet extends DeclarativeWebScript
|
|||||||
{
|
{
|
||||||
this.recordsManagementSearchService = recordsManagementSearchService;
|
this.recordsManagementSearchService = recordsManagementSearchService;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param siteService site service
|
* @param siteService site service
|
||||||
*/
|
*/
|
||||||
@@ -106,7 +107,7 @@ public class RMSearchGet extends DeclarativeWebScript
|
|||||||
{
|
{
|
||||||
this.siteService = siteService;
|
this.siteService = siteService;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param namespaceService namespace service
|
* @param namespaceService namespace service
|
||||||
*/
|
*/
|
||||||
@@ -114,7 +115,7 @@ public class RMSearchGet extends DeclarativeWebScript
|
|||||||
{
|
{
|
||||||
this.namespaceService = namespaceService;
|
this.namespaceService = namespaceService;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param nodeService node service
|
* @param nodeService node service
|
||||||
*/
|
*/
|
||||||
@@ -122,7 +123,7 @@ public class RMSearchGet extends DeclarativeWebScript
|
|||||||
{
|
{
|
||||||
this.nodeService = nodeService;
|
this.nodeService = nodeService;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param dictionaryService dictionary service
|
* @param dictionaryService dictionary service
|
||||||
*/
|
*/
|
||||||
@@ -130,7 +131,7 @@ public class RMSearchGet extends DeclarativeWebScript
|
|||||||
{
|
{
|
||||||
this.dictionaryService = dictionaryService;
|
this.dictionaryService = dictionaryService;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param permissionService permission service
|
* @param permissionService permission service
|
||||||
*/
|
*/
|
||||||
@@ -138,7 +139,7 @@ public class RMSearchGet extends DeclarativeWebScript
|
|||||||
{
|
{
|
||||||
this.permissionService = permissionService;
|
this.permissionService = permissionService;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param personService person service
|
* @param personService person service
|
||||||
*/
|
*/
|
||||||
@@ -146,7 +147,7 @@ public class RMSearchGet extends DeclarativeWebScript
|
|||||||
{
|
{
|
||||||
this.personService = personService;
|
this.personService = personService;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param contentService content service
|
* @param contentService content service
|
||||||
*/
|
*/
|
||||||
@@ -154,7 +155,7 @@ public class RMSearchGet extends DeclarativeWebScript
|
|||||||
{
|
{
|
||||||
this.contentService = contentService;
|
this.contentService = contentService;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* @see org.alfresco.web.scripts.DeclarativeWebScript#executeImpl(org.alfresco.web.scripts.WebScriptRequest, org.alfresco.web.scripts.Status, org.alfresco.web.scripts.Cache)
|
* @see org.alfresco.web.scripts.DeclarativeWebScript#executeImpl(org.alfresco.web.scripts.WebScriptRequest, org.alfresco.web.scripts.Status, org.alfresco.web.scripts.Cache)
|
||||||
*/
|
*/
|
||||||
@@ -162,7 +163,7 @@ public class RMSearchGet extends DeclarativeWebScript
|
|||||||
protected Map<String, Object> executeImpl(WebScriptRequest req, Status status, Cache cache)
|
protected Map<String, Object> executeImpl(WebScriptRequest req, Status status, Cache cache)
|
||||||
{
|
{
|
||||||
// Get the site id and confirm it is valid
|
// Get the site id and confirm it is valid
|
||||||
Map<String, String> templateVars = req.getServiceMatch().getTemplateVars();
|
Map<String, String> templateVars = req.getServiceMatch().getTemplateVars();
|
||||||
String siteId = templateVars.get("site");
|
String siteId = templateVars.get("site");
|
||||||
if (siteId == null || siteId.length() == 0)
|
if (siteId == null || siteId.length() == 0)
|
||||||
{
|
{
|
||||||
@@ -172,50 +173,55 @@ public class RMSearchGet extends DeclarativeWebScript
|
|||||||
{
|
{
|
||||||
throw new WebScriptException(Status.STATUS_NOT_FOUND, "Site not found.");
|
throw new WebScriptException(Status.STATUS_NOT_FOUND, "Site not found.");
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get the query parameter
|
// Get the query parameter
|
||||||
String query = req.getParameter(PARAM_QUERY);
|
String query = req.getParameter(PARAM_QUERY);
|
||||||
// TODO check that this is there
|
// TODO check that this is there
|
||||||
|
|
||||||
String sortby = req.getParameter(PARAM_SORTBY);
|
String sortby = req.getParameter(PARAM_SORTBY);
|
||||||
// TODO this is optional
|
// TODO this is optional
|
||||||
|
|
||||||
String filters = req.getParameter(PARAM_FILTERS);
|
String filters = req.getParameter(PARAM_FILTERS);
|
||||||
// TODO this is optional
|
// TODO this is optional
|
||||||
|
|
||||||
// Convert into a rm search parameter object
|
// Convert into a rm search parameter object
|
||||||
RecordsManagementSearchParameters searchParameters =
|
RecordsManagementSearchParameters searchParameters =
|
||||||
SavedSearchDetailsCompatibility.createSearchParameters(filters, new String[]{",", "/"}, sortby, namespaceService);
|
SavedSearchDetailsCompatibility.createSearchParameters(filters, new String[]{",", "/"}, sortby, namespaceService);
|
||||||
|
|
||||||
// Set the max results
|
// Set the max results
|
||||||
String maxItems = req.getParameter(PARAM_MAX_ITEMS);
|
String maxItems = req.getParameter(PARAM_MAX_ITEMS);
|
||||||
if (maxItems != null && maxItems.length() != 0)
|
if (maxItems != null && maxItems.length() != 0)
|
||||||
{
|
{
|
||||||
searchParameters.setMaxItems(Integer.parseInt(maxItems));
|
searchParameters.setMaxItems(Integer.parseInt(maxItems));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Execute search
|
// Execute search
|
||||||
List<NodeRef> results = recordsManagementSearchService.search(siteId, query, searchParameters);
|
List<NodeRef> results = recordsManagementSearchService.search(siteId, query, searchParameters);
|
||||||
|
|
||||||
// Reset person data cache
|
// Reset person data cache
|
||||||
personDataCache = new HashMap<String, String>(57);
|
personDataCache = new HashMap<String, String>(57);
|
||||||
|
|
||||||
// Process the result items
|
// Process the result items
|
||||||
Item[] items = new Item[results.size()];
|
List<Item> items = new ArrayList<Item>(results.size());
|
||||||
int index = 0;
|
|
||||||
for (NodeRef nodeRef : results)
|
for (NodeRef nodeRef : results)
|
||||||
{
|
{
|
||||||
items[index] = new Item(nodeRef);
|
// FIXME: This is a workaround for DOD Recert
|
||||||
index++;
|
// TC 3-3 Create User Groups
|
||||||
|
try
|
||||||
|
{
|
||||||
|
Item item = new Item(nodeRef);
|
||||||
|
items.add(item);
|
||||||
|
}
|
||||||
|
catch(Exception e) {}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Return model
|
// Return model
|
||||||
Map<String, Object> model = new HashMap<String, Object>(1);
|
Map<String, Object> model = new HashMap<String, Object>(1);
|
||||||
model.put("items", items);
|
model.put("items", items);
|
||||||
return model;
|
return model;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Item class to contain information about items being placed in model.
|
* Item class to contain information about items being placed in model.
|
||||||
*/
|
*/
|
||||||
@@ -231,38 +237,38 @@ public class RMSearchGet extends DeclarativeWebScript
|
|||||||
private String createdBy;
|
private String createdBy;
|
||||||
private Map<QName, Serializable> nodeProperties;
|
private Map<QName, Serializable> nodeProperties;
|
||||||
private Map<String, Serializable> properties;
|
private Map<String, Serializable> properties;
|
||||||
|
|
||||||
public Item(NodeRef nodeRef)
|
public Item(NodeRef nodeRef)
|
||||||
{
|
{
|
||||||
// Set node ref
|
// Set node ref
|
||||||
this.nodeRef = nodeRef;
|
this.nodeRef = nodeRef;
|
||||||
|
|
||||||
// Get type
|
// Get type
|
||||||
QName nodeRefType = nodeService.getType(nodeRef);
|
QName nodeRefType = nodeService.getType(nodeRef);
|
||||||
this.type = nodeRefType.toPrefixString(namespaceService);
|
this.type = nodeRefType.toPrefixString(namespaceService);
|
||||||
|
|
||||||
// Get properties
|
// Get properties
|
||||||
this.nodeProperties = nodeService.getProperties(nodeRef);
|
this.nodeProperties = nodeService.getProperties(nodeRef);
|
||||||
|
|
||||||
// Determine if container or not
|
// Determine if container or not
|
||||||
isContainer = true;
|
isContainer = true;
|
||||||
if (dictionaryService.isSubClass(nodeRefType, ContentModel.TYPE_CONTENT) == true)
|
if (dictionaryService.isSubClass(nodeRefType, ContentModel.TYPE_CONTENT) == true)
|
||||||
{
|
{
|
||||||
isContainer = false;
|
isContainer = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get parent node reference
|
// Get parent node reference
|
||||||
NodeRef parent = null;
|
NodeRef parent = null;
|
||||||
ChildAssociationRef assoc = nodeService.getPrimaryParent(nodeRef);
|
ChildAssociationRef assoc = nodeService.getPrimaryParent(nodeRef);
|
||||||
if (assoc != null)
|
if (assoc != null)
|
||||||
{
|
{
|
||||||
parent = assoc.getParentRef();
|
parent = assoc.getParentRef();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isContainer == true)
|
if (isContainer == true)
|
||||||
{
|
{
|
||||||
this.size = -1;
|
this.size = -1;
|
||||||
|
|
||||||
String displayPath = nodeService.getPath(nodeRef).toDisplayPath(nodeService, permissionService);
|
String displayPath = nodeService.getPath(nodeRef).toDisplayPath(nodeService, permissionService);
|
||||||
String[] pathElements = displayPath.split("/");
|
String[] pathElements = displayPath.split("/");
|
||||||
if (pathElements.length >= 5)
|
if (pathElements.length >= 5)
|
||||||
@@ -271,7 +277,7 @@ public class RMSearchGet extends DeclarativeWebScript
|
|||||||
{
|
{
|
||||||
this.parentFolder = (String)nodeService.getProperty(parent, ContentModel.PROP_NAME);
|
this.parentFolder = (String)nodeService.getProperty(parent, ContentModel.PROP_NAME);
|
||||||
}
|
}
|
||||||
|
|
||||||
pathElements = (String[])ArrayUtils.subarray(pathElements, 5, pathElements.length);
|
pathElements = (String[])ArrayUtils.subarray(pathElements, 5, pathElements.length);
|
||||||
String newPath = StringUtils.join(pathElements, "/");
|
String newPath = StringUtils.join(pathElements, "/");
|
||||||
StringBuilder relPath = new StringBuilder("/").append(newPath);
|
StringBuilder relPath = new StringBuilder("/").append(newPath);
|
||||||
@@ -287,7 +293,7 @@ public class RMSearchGet extends DeclarativeWebScript
|
|||||||
catch (UnsupportedEncodingException e)
|
catch (UnsupportedEncodingException e)
|
||||||
{
|
{
|
||||||
throw new AlfrescoRuntimeException("Could not process search results.", e);
|
throw new AlfrescoRuntimeException("Could not process search results.", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -299,27 +305,27 @@ public class RMSearchGet extends DeclarativeWebScript
|
|||||||
{
|
{
|
||||||
this.size = (int)contentData.getSize();
|
this.size = (int)contentData.getSize();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set the document parent name
|
// Set the document parent name
|
||||||
if (parent != null)
|
if (parent != null)
|
||||||
{
|
{
|
||||||
this.parentFolder = (String)nodeService.getProperty(parent, ContentModel.PROP_NAME);
|
this.parentFolder = (String)nodeService.getProperty(parent, ContentModel.PROP_NAME);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set the document browse URL
|
// Set the document browse URL
|
||||||
this.browseUrl = "document-details?nodeRef=" + nodeRef.toString();
|
this.browseUrl = "document-details?nodeRef=" + nodeRef.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
this.modifiedBy = getDisplayName(getModifiedByUser());
|
this.modifiedBy = getDisplayName(getModifiedByUser());
|
||||||
this.createdBy = getDisplayName(getCreatedByUser());
|
this.createdBy = getDisplayName(getCreatedByUser());
|
||||||
|
|
||||||
// Process the custom properties
|
// Process the custom properties
|
||||||
properties = new HashMap<String, Serializable>(nodeProperties.size());
|
properties = new HashMap<String, Serializable>(nodeProperties.size());
|
||||||
for (Map.Entry<QName, Serializable> entry : nodeProperties.entrySet())
|
for (Map.Entry<QName, Serializable> entry : nodeProperties.entrySet())
|
||||||
{
|
{
|
||||||
QName qName = entry.getKey().getPrefixedQName(namespaceService);
|
QName qName = entry.getKey().getPrefixedQName(namespaceService);
|
||||||
if (NamespaceService.SYSTEM_MODEL_1_0_URI.equals(qName.getNamespaceURI()) == false)
|
if (NamespaceService.SYSTEM_MODEL_1_0_URI.equals(qName.getNamespaceURI()) == false)
|
||||||
{
|
{
|
||||||
String prefixName = qName.getPrefixString().replace(":", "_");
|
String prefixName = qName.getPrefixString().replace(":", "_");
|
||||||
Serializable value = entry.getValue();
|
Serializable value = entry.getValue();
|
||||||
if (value instanceof NodeRef)
|
if (value instanceof NodeRef)
|
||||||
@@ -335,7 +341,7 @@ public class RMSearchGet extends DeclarativeWebScript
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private String getDisplayName(String userName)
|
private String getDisplayName(String userName)
|
||||||
{
|
{
|
||||||
String result = personDataCache.get(userName);
|
String result = personDataCache.get(userName);
|
||||||
@@ -356,85 +362,85 @@ public class RMSearchGet extends DeclarativeWebScript
|
|||||||
}
|
}
|
||||||
personDataCache.put(userName, result);
|
personDataCache.put(userName, result);
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
public NodeRef getNodeRef()
|
public NodeRef getNodeRef()
|
||||||
{
|
{
|
||||||
return nodeRef;
|
return nodeRef;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getType()
|
public String getType()
|
||||||
{
|
{
|
||||||
return type;
|
return type;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getName()
|
public String getName()
|
||||||
{
|
{
|
||||||
return (String)nodeProperties.get(ContentModel.PROP_NAME);
|
return (String)nodeProperties.get(ContentModel.PROP_NAME);
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getTitle()
|
public String getTitle()
|
||||||
{
|
{
|
||||||
return (String)nodeProperties.get(ContentModel.PROP_TITLE);
|
return (String)nodeProperties.get(ContentModel.PROP_TITLE);
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getDescription()
|
public String getDescription()
|
||||||
{
|
{
|
||||||
return (String)nodeProperties.get(ContentModel.PROP_DESCRIPTION);
|
return (String)nodeProperties.get(ContentModel.PROP_DESCRIPTION);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Date getModifiedOn()
|
public Date getModifiedOn()
|
||||||
{
|
{
|
||||||
return (Date)nodeProperties.get(ContentModel.PROP_MODIFIED);
|
return (Date)nodeProperties.get(ContentModel.PROP_MODIFIED);
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getModifiedByUser()
|
public String getModifiedByUser()
|
||||||
{
|
{
|
||||||
return (String)nodeProperties.get(ContentModel.PROP_MODIFIER);
|
return (String)nodeProperties.get(ContentModel.PROP_MODIFIER);
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getModifiedBy()
|
public String getModifiedBy()
|
||||||
{
|
{
|
||||||
return modifiedBy;
|
return modifiedBy;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Date getCreatedOn()
|
public Date getCreatedOn()
|
||||||
{
|
{
|
||||||
return (Date)nodeProperties.get(ContentModel.PROP_CREATED);
|
return (Date)nodeProperties.get(ContentModel.PROP_CREATED);
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getCreatedByUser()
|
public String getCreatedByUser()
|
||||||
{
|
{
|
||||||
return (String)nodeProperties.get(ContentModel.PROP_CREATOR);
|
return (String)nodeProperties.get(ContentModel.PROP_CREATOR);
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getCreatedBy()
|
public String getCreatedBy()
|
||||||
{
|
{
|
||||||
return createdBy;
|
return createdBy;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getAuthor()
|
public String getAuthor()
|
||||||
{
|
{
|
||||||
return (String)nodeProperties.get(ContentModel.PROP_AUTHOR);
|
return (String)nodeProperties.get(ContentModel.PROP_AUTHOR);
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getParentFolder()
|
public String getParentFolder()
|
||||||
{
|
{
|
||||||
return parentFolder;
|
return parentFolder;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getSize()
|
public int getSize()
|
||||||
{
|
{
|
||||||
return size;
|
return size;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getBrowseUrl()
|
public String getBrowseUrl()
|
||||||
{
|
{
|
||||||
return browseUrl;
|
return browseUrl;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Map<String, Serializable> getProperties()
|
public Map<String, Serializable> getProperties()
|
||||||
{
|
{
|
||||||
return properties;
|
return properties;
|
||||||
|
Reference in New Issue
Block a user