CSPACE-1846: Relation Service needs to paginate list results.
CSPACE-602: Update Relations service/manager to use Nuxeo queries instead of "get all" and filter with Java code
import java.util.List;\r
import javax.ws.rs.core.MultivaluedMap;\r
import org.collectionspace.services.client.IClientQueryParams;\r
-import org.collectionspace.services.common.query.IQueryManager;\r
import org.collectionspace.services.common.context.ServiceContext;\r
\r
-//TODO: would be great to not rely on resteasy directly\r
-import org.jboss.resteasy.specimpl.MultivaluedMapImpl;\r
-\r
/**\r
- * DocumentFilter bundles simple query filtering parameters. \r
- * It is designed to be used with filtered get and search calls to RepositoryClient.\r
- * The values are set up and stored on a DocumentHandler, and\r
- * fetched by a RepositoryClient when calling filtered get methods.\r
+ * The Class DocumentFilter.\r
*/\r
public class DocumentFilter {\r
\r
+ /** The Constant DEFAULT_PAGE_SIZE_INIT. */\r
public static final int DEFAULT_PAGE_SIZE_INIT = 40;\r
+ \r
+ /** The Constant PAGE_SIZE_DEFAULT_PROPERTY. */\r
public static final String PAGE_SIZE_DEFAULT_PROPERTY = "pageSizeDefault";\r
+ \r
+ /** The default page size. */\r
public static int defaultPageSize = DEFAULT_PAGE_SIZE_INIT;\r
\r
+ /** The where clause. */\r
protected String whereClause; // Filtering clause. Omit the "WHERE".\r
+ \r
+ /** The start page. */\r
protected int startPage; // Pagination offset for list results\r
+ \r
+ /** The page size. */\r
protected int pageSize; // Pagination limit for list results\r
- private boolean pageSizeDirty = false; // True if default page size explicitly set/overridden\r
-\r
+ \r
//queryParams is not initialized as it would require a multi-valued map implementation\r
//unless it is used from opensource lib...this variable holds ref to\r
//implementation available in JBoss RESTeasy\r
+ /** The query params. */\r
private MultivaluedMap<String, String> queryParams = null;\r
\r
/**\r
- * ParamBinding encapsulates parameter binding for query\r
+ * The Class ParamBinding.\r
*/\r
public static class ParamBinding {\r
\r
+ /** The name. */\r
private String name;\r
+ \r
+ /** The value. */\r
private Object value;\r
\r
- public ParamBinding(String name, Object value) {\r
- this.name = name;\r
- this.value = value;\r
+ /**\r
+ * Instantiates a new param binding.\r
+ *\r
+ * @param theName the name\r
+ * @param theValue the value\r
+ */\r
+ public ParamBinding(String theName, Object theValue) {\r
+ this.name = theName;\r
+ this.value = theValue;\r
}\r
\r
/**\r
+ * Gets the name.\r
+ *\r
* @return the name\r
*/\r
public String getName() {\r
}\r
\r
/**\r
- * @param name the name to set\r
+ * Sets the name.\r
+ *\r
+ * @param theName the new name\r
*/\r
- public void setName(String name) {\r
- this.name = name;\r
+ public void setName(String theName) {\r
+ this.name = theName;\r
}\r
\r
/**\r
+ * Gets the value.\r
+ *\r
* @return the value\r
*/\r
public Object getValue() {\r
}\r
\r
/**\r
- * @param value the value to set\r
+ * Sets the value.\r
+ *\r
+ * @param theValue the new value\r
*/\r
- public void setValue(Object value) {\r
- this.value = value;\r
+ public void setValue(Object theValue) {\r
+ this.value = theValue;\r
}\r
}\r
\r
/**\r
* Instantiates a new document filter.\r
- * \r
+ *\r
* @param ctx the ctx\r
*/\r
public DocumentFilter(ServiceContext ctx) {\r
DocumentFilter.PAGE_SIZE_DEFAULT_PROPERTY));\r
}\r
\r
+ /**\r
+ * Instantiates a new document filter.\r
+ */\r
public DocumentFilter() {\r
this("", 0, defaultPageSize); // Use empty string for easy concatenation\r
}\r
\r
- public DocumentFilter(String whereClause, int startPage, int pageSize) {\r
- this.whereClause = whereClause;\r
- this.startPage = (startPage > 0) ? startPage : 0;\r
- this.pageSize = (pageSize > 0) ? pageSize : defaultPageSize;\r
+ /**\r
+ * Instantiates a new document filter.\r
+ *\r
+ * @param theWhereClause the the where clause\r
+ * @param theStartPage the the start page\r
+ * @param thePageSize the the page size\r
+ */\r
+ public DocumentFilter(String theWhereClause, int theStartPage, int thePageSize) {\r
+ this.whereClause = theWhereClause;\r
+ this.startPage = (theStartPage > 0) ? theStartPage : 0;\r
+ this.pageSize = (thePageSize > 0) ? thePageSize : defaultPageSize;\r
}\r
\r
/**\r
* Sets the pagination.\r
- * \r
- * @param queryParams the query params\r
+ *\r
+ * @param theQueryParams the the query params\r
*/\r
- public void setPagination(MultivaluedMap<String, String> queryParams) {\r
+ public void setPagination(MultivaluedMap<String, String> theQueryParams) {\r
//\r
// Bail if there are no params\r
//\r
- if (queryParams == null) {\r
+ if (theQueryParams == null) {\r
return;\r
}\r
-\r
//\r
// Set the page size\r
//\r
String pageSizeStr = null;\r
- List<String> list = queryParams.get(IClientQueryParams.PAGE_SIZE_PARAM);\r
+ List<String> list = theQueryParams.get(IClientQueryParams.PAGE_SIZE_PARAM);\r
if (list != null) {\r
pageSizeStr = list.get(0);\r
}\r
setPageSize(pageSizeStr);\r
-\r
//\r
// Set the start page\r
//\r
String startPageStr = null;\r
- list = queryParams.get(IClientQueryParams.START_PAGE_PARAM);\r
+ list = theQueryParams.get(IClientQueryParams.START_PAGE_PARAM);\r
if (list != null) {\r
startPageStr = list.get(0);\r
}\r
}\r
\r
/**\r
- * @return the current default page size for new DocumentFilter instances\r
+ * Gets the default page size.\r
+ *\r
+ * @return the default page size\r
*/\r
public static int getDefaultPageSize() {\r
return defaultPageSize;\r
}\r
\r
/**\r
- * @param defaultPageSize the working default page size for new DocumentFilter instances\r
+ * Sets the default page size.\r
+ *\r
+ * @param theDefaultPageSize the new default page size\r
*/\r
- public static void setDefaultPageSize(int defaultPageSize) {\r
- DocumentFilter.defaultPageSize = defaultPageSize;\r
+ public static void setDefaultPageSize(int theDefaultPageSize) {\r
+ DocumentFilter.defaultPageSize = theDefaultPageSize;\r
}\r
\r
/**\r
- * @return the WHERE filtering clause\r
+ * Gets the where clause.\r
+ *\r
+ * @return the where clause\r
*/\r
public String getWhereClause() {\r
return whereClause;\r
}\r
\r
/**\r
- * @param whereClause the filtering clause (do not include "WHERE")\r
+ * Sets the where clause.\r
+ *\r
+ * @param theWhereClause the new where clause\r
*/\r
- public void setWhereClause(String whereClause) {\r
- this.whereClause = whereClause;\r
+ public void setWhereClause(String theWhereClause) {\r
+ this.whereClause = theWhereClause;\r
}\r
\r
- public void appendWhereClause(String whereClause) {\r
- String currentClause = getWhereClause();\r
- if (currentClause != null) {\r
- String newClause = currentClause.concat(IQueryManager.SEARCH_TERM_SEPARATOR + whereClause);\r
- this.setWhereClause(newClause);\r
- }\r
+ /**\r
+ * Append where clause.\r
+ *\r
+ * @param theWhereClause the the where clause\r
+ * @param conjunction the conjunction\r
+ */\r
+ public void appendWhereClause(String theWhereClause, String conjunction) {\r
+ if (theWhereClause != null && theWhereClause.length() > 0) {\r
+ String currentClause = getWhereClause();\r
+ if (currentClause != null) {\r
+ String newClause = currentClause.concat(conjunction + theWhereClause);\r
+ this.setWhereClause(newClause);\r
+ } else {\r
+ this.setWhereClause(theWhereClause);\r
+ }\r
+ }\r
}\r
\r
/**\r
- * buildWhereClause builds where clause for search query\r
- * @param queryStrBldr query string to append with where clause\r
- * @return parameter binding\r
+ * Builds the where for search.\r
+ *\r
+ * @param queryStrBldr the query str bldr\r
+ * @return the list\r
*/\r
public List<ParamBinding> buildWhereForSearch(StringBuilder queryStrBldr) {\r
return new ArrayList<ParamBinding>();\r
}\r
\r
/**\r
- * buildWhereClause builds where clause for get, update or delete\r
- * @param queryStrBldr query string to append with where clause\r
- * @return parameter binding\r
+ * Builds the where.\r
+ *\r
+ * @param queryStrBldr the query str bldr\r
+ * @return the list\r
*/\r
public List<ParamBinding> buildWhere(StringBuilder queryStrBldr) {\r
return new ArrayList<ParamBinding>();\r
}\r
\r
/**\r
- * @return the specified (0-based) page offset\r
+ * Gets the start page.\r
+ *\r
+ * @return the start page\r
*/\r
public int getStartPage() {\r
return startPage;\r
}\r
\r
/**\r
- * @param startPage the (0-based) page offset to use\r
+ * Sets the start page.\r
+ *\r
+ * @param theStartPage the new start page\r
*/\r
- public void setStartPage(int startPage) {\r
- this.startPage = startPage;\r
+ public void setStartPage(int theStartPage) {\r
+ this.startPage = theStartPage;\r
}\r
\r
/**\r
- * @return the max number of items to return for list requests\r
+ * Gets the page size.\r
+ *\r
+ * @return the page size\r
*/\r
public int getPageSize() {\r
return pageSize;\r
}\r
\r
+ /**\r
+ * Gets the page size dirty.\r
+ *\r
+ * @return the page size dirty\r
+ */\r
public boolean getPageSizeDirty() {\r
return this.getPageSizeDirty();\r
}\r
\r
/**\r
- * @param pageSize the max number of items to return for list requests\r
+ * Sets the page size.\r
+ *\r
+ * @param thePageSize the new page size\r
*/\r
- public void setPageSize(int pageSize) {\r
- this.pageSize = pageSize;\r
- this.pageSizeDirty = true; // page size explicity set/overriden\r
+ public void setPageSize(int thePageSize) {\r
+ this.pageSize = thePageSize;\r
}\r
\r
/**\r
- * @param pageSize the max number of items to return for list requests\r
+ * Sets the page size.\r
+ *\r
+ * @param thePageSizeStr the new page size\r
*/\r
- public void setPageSize(String pageSizeStr) {\r
- int pageSize = this.defaultPageSize;\r
- if (pageSizeStr != null) {\r
+ public void setPageSize(String thePageSizeStr) {\r
+ int newPageSize = DocumentFilter.defaultPageSize;\r
+ if (thePageSizeStr != null) {\r
try {\r
- pageSize = Integer.valueOf(pageSizeStr);\r
+ newPageSize = Integer.valueOf(thePageSizeStr);\r
} catch (NumberFormatException e) {\r
//FIXME This should cause a warning in the log file and should result in the\r
//FIXME page size being set to the default. We don't need to throw an exception here.\r
}\r
}\r
\r
- setPageSize(pageSize);\r
+ setPageSize(newPageSize);\r
}\r
\r
/**\r
* Sets the start page.\r
- * \r
+ *\r
* @param startPageStr the new start page\r
*/\r
protected void setStartPage(String startPageStr) {\r
}\r
\r
/**\r
- * @return the offset computed from the startPage and the pageSize\r
+ * Gets the offset.\r
+ *\r
+ * @return the offset\r
*/\r
public int getOffset() {\r
return pageSize * startPage;\r
}\r
\r
+ /**\r
+ * Adds the query param.\r
+ *\r
+ * @param key the key\r
+ * @param value the value\r
+ */\r
public void addQueryParam(String key, String value) {\r
if (queryParams != null) {\r
queryParams.add(key, value);\r
}\r
}\r
\r
+ /**\r
+ * Gets the query param.\r
+ *\r
+ * @param key the key\r
+ * @return the query param\r
+ */\r
public List<String> getQueryParam(String key) {\r
if (queryParams != null) {\r
return queryParams.get(key);\r
}\r
}\r
\r
+ /**\r
+ * Gets the query params.\r
+ *\r
+ * @return the query params\r
+ */\r
public MultivaluedMap<String, String> getQueryParams() {\r
return queryParams;\r
}\r
\r
- public void setQueryParams(MultivaluedMap<String, String> queryParams) {\r
- this.queryParams = queryParams;\r
+ /**\r
+ * Sets the query params.\r
+ *\r
+ * @param theQueryParams the the query params\r
+ */\r
+ public void setQueryParams(MultivaluedMap<String, String> theQueryParams) {\r
+ this.queryParams = theQueryParams;\r
}\r
}\r
\r
public interface IQueryManager {\r
\r
- final static String SEARCH_LIKE = "LIKE";\r
+ final static String SEARCH_TERM_SEPARATOR = " ";\r
+ final static String SEARCH_LIKE = " LIKE ";\r
final static String SEARCH_TYPE_KEYWORDS = "keywords";\r
final static String SEARCH_TYPE_KEYWORDS_KW = "kw";\r
final static String SEARCH_TYPE_PARTIALTERM = "pt";\r
- final static String ECM_FULLTEXT_LIKE = "ecm:fulltext " + SEARCH_LIKE;\r
- final static String SEARCH_QUALIFIER_AND = "AND";\r
- final static String SEARCH_QUALIFIER_OR = "OR";\r
- final static String SEARCH_TERM_SEPARATOR = " ";\r
+ final static String ECM_FULLTEXT_LIKE = "ecm:fulltext" + SEARCH_TERM_SEPARATOR + SEARCH_LIKE;\r
+ final static String SEARCH_QUALIFIER_AND = SEARCH_TERM_SEPARATOR + "AND" + SEARCH_TERM_SEPARATOR;\r
+ final static String SEARCH_QUALIFIER_OR = SEARCH_TERM_SEPARATOR + "OR" + SEARCH_TERM_SEPARATOR;\r
\r
public void execQuery(String queryString);\r
\r
\r
/** The Constant SUBJECT. */\r
static public final String SUBJECT = "subjectCsid";\r
+ static public final String SUBJECT_QP = "sbj";\r
+ \r
/** The Constant PREDICATE. */\r
static public final String PREDICATE = "predicate";\r
+ static public final String PREDICATE_QP = "prd";\r
+ \r
/** The Constant OBJECT. */\r
static public final String OBJECT = "objectCsid";\r
-\r
+ static public final String OBJECT_QP = "obj";\r
\r
/**\r
* Gets the relationships for the entity corresponding to the CSID=csid.\r
final static String CSID = "csid";\r
\r
final static String SUBJECT_CSID = "subjectCsid";\r
+ final static String RELATIONSHIP_TYPE = "relationshipType";\r
final static String OBJECT_CSID = "objectCsid";\r
\r
/** The Constant URI. */\r
public final static String NUXEO_DOCTYPE = "Relation";
public final static String NUXEO_SCHEMA_NAME = "relations_common";
- public final static String NUXEO_DC_TITLE = "CollectionSpace-Relation";
/** The Constant REL_NUXEO_SCHEMA_ROOT_ELEMENT. */
final public static String NUXEO_SCHEMA_ROOT_ELEMENT = "relationtype";
}
*/
package org.collectionspace.services.common.relation.nuxeo;
-import java.util.Iterator;
-import java.util.List;
+import java.lang.StringBuilder;
-import org.collectionspace.services.common.relation.RelationListItemJAXBSchema;
+import org.collectionspace.services.common.query.IQueryManager;
import org.collectionspace.services.common.relation.RelationJAXBSchema;
-import org.collectionspace.services.common.document.DocumentException;
-import org.collectionspace.services.common.document.DocumentWrapper;
-import org.collectionspace.services.common.context.ServiceContext;
-import org.collectionspace.services.nuxeo.util.NuxeoUtils;
-import org.collectionspace.services.relation.RelationsCommonList;
-import org.collectionspace.services.relation.RelationsCommonList.RelationListItem;
-import org.nuxeo.ecm.core.api.DocumentModel;
-import org.nuxeo.ecm.core.api.DocumentModelList;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
*/
public class RelationsUtils {
+ /** The Constant logger. */
private static final Logger logger = LoggerFactory.getLogger(RelationsUtils.class);
- public static RelationsCommonList extractCommonPartList(ServiceContext ctx, DocumentWrapper wrapDoc,
- String serviceContextPath)
- throws Exception {
- DocumentModelList docList = (DocumentModelList) wrapDoc.getWrappedObject();
-
- RelationsCommonList relList = new RelationsCommonList();
- List<RelationsCommonList.RelationListItem> list = relList.getRelationListItem();
-
- //FIXME: iterating over a long list of documents is not a long term
- //strategy...need to change to more efficient iterating in future
- Iterator<DocumentModel> iter = docList.iterator();
- while (iter.hasNext()) {
- DocumentModel docModel = iter.next();
- RelationListItem relationListItem = getRelationListItem(ctx, docModel,
- serviceContextPath);
- list.add(relationListItem);
- }
- return relList;
- }
-
- public static RelationListItem getRelationListItem(ServiceContext ctx, DocumentModel docModel,
- String serviceContextPath) throws Exception {
- RelationListItem relationListItem = new RelationListItem();
- String id = NuxeoUtils.extractId(docModel.getPathAsString());
- relationListItem.setCsid(id);
- relationListItem.setSubjectCsid((String) docModel.getProperty(ctx.getCommonPartLabel(),
- RelationJAXBSchema.DOCUMENT_ID_1));
- relationListItem.setObjectCsid((String) docModel.getProperty(ctx.getCommonPartLabel(),
- RelationJAXBSchema.DOCUMENT_ID_2));
-
- relationListItem.setUri(serviceContextPath + id);
- return relationListItem;
- }
-
- public static void fillDublinCoreObject(DocumentWrapper wrapDoc) throws Exception {
- DocumentModel docModel = (DocumentModel) wrapDoc.getWrappedObject();
- //FIXME property setter should be dynamically set using schema inspection
- //so it does not require hard coding
- // a default title for the Dublin Core schema
- docModel.setPropertyValue("dublincore:title", RelationConstants.NUXEO_DC_TITLE);
- }
-
- /**
- * Checks if is subject of relation.
- *
- * @param csid the csid
- * @param documentModel the document model
- *
- * @return true, if is subject of relation
- *
- * @throws Exception
- */
- private static boolean isSubjectOfRelation(String csid, DocumentModel documentModel)
- throws Exception {
- boolean result = false;
- Object valueObject = documentModel.getProperty(RelationConstants.NUXEO_SCHEMA_NAME, RelationJAXBSchema.DOCUMENT_ID_1);
- if (valueObject != null && csid != null) {
- String subjectID = (String) valueObject;
- result = subjectID.equals(csid);
- }
-
- return result;
- }
-
- /**
- * Checks if is object of relation.
- *
- * @param csid the csid
- * @param documentModel the document model
- *
- * @return true, if is object of relation
- *
- * @throws Exception
- */
- private static boolean isObjectOfRelation(String csid, DocumentModel documentModel)
- throws Exception {
- boolean result = false;
-
- Object valueObject = documentModel.getProperty(RelationConstants.NUXEO_SCHEMA_NAME,
- RelationJAXBSchema.DOCUMENT_ID_2);
- if (valueObject != null && csid != null) {
- String subjectID = (String) valueObject;
- result = subjectID.equals(csid);
- }
-
- return result;
- }
-
- /**
- * Checks if is predicate of relation.
- *
- * @param predicate the predicate
- * @param documentModel the document model
- *
- * @return true, if is predicate of relation
- *
- * @throws Exception
- */
- private static boolean isPredicateOfRelation(String predicate,
- DocumentModel documentModel) throws Exception {
- boolean result = false;
-
- Object valueObject = documentModel.getProperty(RelationConstants.NUXEO_SCHEMA_NAME,
- RelationJAXBSchema.RELATIONSHIP_TYPE);
- if (valueObject != null && predicate != null) {
- String relationType = (String) valueObject;
- result = predicate.equalsIgnoreCase(relationType);
- }
-
- return result;
- }
-
/**
- * Gets the object from subject.
- *
- * @param csid the csid
- * @param documentModel the document model
+ * Builds the where clause.
*
- * @return the object from subject
- *
- * @throws Exception
- */
- private static String getObjectFromSubject(String csid, DocumentModel documentModel)
- throws Exception {
- String result = null;
-
- Object valueObject = documentModel.getProperty(RelationConstants.NUXEO_SCHEMA_NAME,
- RelationJAXBSchema.DOCUMENT_ID_1);
- if (valueObject != null) {
- String subjectID = (String) valueObject;
- if (subjectID.equals(csid) == true) {
- valueObject = documentModel.getProperty(RelationConstants.NUXEO_SCHEMA_NAME,
- RelationJAXBSchema.DOCUMENT_ID_2);
- if (valueObject != null) {
- result = (String) valueObject;
- }
- }
- }
-
- return result;
- }
-
- /**
- * Checks if is query match.
- *
- * @param documentModel the document model
- * @param subjectCsid the subject csid
+ * @param subject the subject
* @param predicate the predicate
- * @param objectCsid the object csid
- *
- * @return true, if is query match
- *
- * @throws ClientException the client exception
- */
- public static boolean isQueryMatch(DocumentModel documentModel,
- String subjectCsid,
- String predicate,
- String objectCsid) throws DocumentException {
- boolean result = true;
-
- try {
- block:
- {
- if (subjectCsid != null) {
- if (isSubjectOfRelation(subjectCsid, documentModel) == false) {
- result = false;
- break block;
- }
- }
- if (predicate != null) {
- if (isPredicateOfRelation(predicate, documentModel) == false) {
- result = false;
- break block;
- }
- }
- if (objectCsid != null) {
- if (isObjectOfRelation(objectCsid, documentModel) == false) {
- result = false;
- break block;
- }
- }
- }
- } catch (Exception e) {
- if (logger.isDebugEnabled() == true) {
- e.printStackTrace();
- }
- throw new DocumentException(e);
- }
-
- return result;
- }
-
- /**
- * Gets the rel url.
- *
- * @param repo the repo
- * @param uuid the uuid
- *
- * @return the rel url
+ * @param object the object
+ * @return the string
*/
- private static String getRelURL(String repo, String uuid) {
- return '/' + repo + '/' + uuid;
+ public static String buildWhereClause(String subject, String predicate, String object) {
+ String result = null;
+
+ StringBuilder stringBuilder = new StringBuilder();
+ if (subject != null) {
+ stringBuilder.append(RelationConstants.NUXEO_SCHEMA_NAME + ":" +
+ RelationJAXBSchema.DOCUMENT_ID_1 + " = " + "'" + subject + "'");
+ }
+
+ if (predicate != null) {
+ if (stringBuilder.length() > 0) {
+ stringBuilder.append(IQueryManager.SEARCH_QUALIFIER_AND);
+ }
+ stringBuilder.append(RelationConstants.NUXEO_SCHEMA_NAME + ":" +
+ RelationJAXBSchema.RELATIONSHIP_TYPE + " = " + "'" + predicate + "'");
+ }
+
+ if (object != null) {
+ if (stringBuilder.length() > 0) {
+ stringBuilder.append(IQueryManager.SEARCH_QUALIFIER_AND);
+ }
+ stringBuilder.append(RelationConstants.NUXEO_SCHEMA_NAME + ":" +
+ RelationJAXBSchema.DOCUMENT_ID_2 + " = " + "'" + object + "'");
+ }
+
+ if (stringBuilder.length() > 0) {
+ result = stringBuilder.toString();
+ }
+
+ return result;
}
}
import org.collectionspace.services.common.document.DocumentFilter;
import org.collectionspace.services.common.service.ObjectPartType;
import org.collectionspace.services.common.vocabulary.RefNameUtils;
-//import org.collectionspace.services.vocabulary.VocabulariesCommonList;
+
import org.jboss.resteasy.plugins.providers.multipart.InputPart;
import org.jboss.resteasy.plugins.providers.multipart.MultipartInput;
+import org.jboss.resteasy.plugins.providers.multipart.MultipartOutput;
import org.nuxeo.ecm.core.api.DocumentModel;
import org.nuxeo.ecm.core.api.DocumentModelList;
import org.nuxeo.ecm.core.api.model.PropertyException;
*
* $LastChangedRevision: $
* $LastChangedDate: $
+ * @param <T>
+ * @param <TL>
*/
public abstract class RemoteDocumentModelHandlerImpl<T, TL>
extends DocumentModelHandler<T, TL> {
import org.collectionspace.services.common.document.DocumentWrapperImpl;
import org.collectionspace.services.nuxeo.util.NuxeoUtils;
+import org.collectionspace.services.common.query.IQueryManager;
import org.collectionspace.services.common.repository.RepositoryClient;
import org.collectionspace.services.nuxeo.client.java.DocumentModelHandler;
DocumentModelList docList = null;
String query = buildNXQLQuery(queryContext);
+ if (logger.isDebugEnabled()) {
+ logger.debug("Executing NXQL query: " + query.toString());
+ }
+
// If we have limit and/or offset, then pass true to get totalSize
// in returned DocumentModelList.
if ((queryContext.docFilter.getOffset() > 0) || (queryContext.docFilter.getPageSize() > 0)) {
docList = repoSession.query(query);
}
- if (logger.isDebugEnabled()) {
- logger.debug("Executed NXQL query: " + query.toString());
- }
-
//set repoSession to handle the document
((DocumentModelHandler) handler).setRepositorySession(repoSession);
DocumentWrapper<DocumentModelList> wrapDoc = new DocumentWrapperImpl<DocumentModelList>(docList);
//
// Restrict search to the current tenant ID. Is the domain path filter (above) still needed?
//
- query.append("AND " + DocumentModelHandler.COLLECTIONSPACE_CORE_SCHEMA + ":" +
+ query.append(IQueryManager.SEARCH_QUALIFIER_AND + DocumentModelHandler.COLLECTIONSPACE_CORE_SCHEMA + ":" +
DocumentModelHandler.COLLECTIONSPACE_CORE_TENANTID +
" = " + queryContext.tenantId);
//
if (whereClause != null && whereClause.length() > 0) {
// Due to an apparent bug/issue in how Nuxeo translates the NXQL query string
// into SQL, we need to parenthesize our 'where' clause
- query.append(" AND " + "(" + whereClause + ")");
+ query.append(IQueryManager.SEARCH_QUALIFIER_AND + "(" + whereClause + ")");
}
//
// Please lookup this use in Nuxeo support and document here
//
- query.append(" AND ecm:isProxy = 0");
+ query.append(IQueryManager.SEARCH_QUALIFIER_AND + "ecm:isProxy = 0");
}
/**
<xs:complexType>\r
<xs:sequence>\r
<xs:element name="csid" type="xs:string" /> \r
- <xs:element name="documentId1" type="xs:string" minOccurs="1" maxOccurs="1"/>\r
- <xs:element name="documentType1" type="xs:string" minOccurs="1" maxOccurs="1"/>\r
- <xs:element name="documentId2" type="xs:string" minOccurs="1" maxOccurs="1"/>\r
- <xs:element name="documentType2" type="xs:string" minOccurs="1" maxOccurs="1"/>\r
+ <xs:element name="documentId1" type="xs:string" minOccurs="1"/>\r
+ <xs:element name="documentType1" type="xs:string" minOccurs="1"/>\r
+ <xs:element name="documentId2" type="xs:string" minOccurs="1"/>\r
+ <xs:element name="documentType2" type="xs:string" minOccurs="1"/>\r
<!-- type of relationship between two entities -->\r
- <xs:element name="relationshipType" type="rel:RelationshipType" minOccurs="1" maxOccurs="1"/>\r
+ <xs:element name="relationshipType" type="rel:RelationshipType" minOccurs="1"/>\r
</xs:sequence>\r
</xs:complexType>\r
</xs:element>\r
<xs:element name="uri" type="xs:anyURI" minOccurs="1"/>\r
<xs:element name="csid" type="xs:string" minOccurs="1"/>\r
<xs:element name="subjectCsid" type="xs:string" minOccurs="1"/>\r
+ <xs:element name="relationshipType" type="xs:string" minOccurs="1"/>\r
<xs:element name="objectCsid" type="xs:string" minOccurs="1"/>\r
</xs:sequence>\r
</xs:complexType>\r
return contactResource.getServiceName();
}
- /*
- public RemoteServiceContext createItemServiceContext(MultipartInput input) throws Exception {
- RemoteServiceContext ctx = new RemoteServiceContextImpl(getItemServiceName());
- ctx.setInput(input);
- return ctx;
- }
- */
- /* (non-Javadoc)
- * @see org.collectionspace.services.common.AbstractCollectionSpaceResourceImpl#createDocumentHandler(org.collectionspace.services.common.context.ServiceContext)
- */
-// @Override
-// public DocumentHandler createDocumentHandler(ServiceContext ctx) throws Exception {
-// DocumentHandler docHandler =ctx.getDocumentHandler();
-// if (ctx.getInput() != null) {
-// Object obj = ((MultipartServiceContext) ctx).getInputPart(ctx.getCommonPartLabel(), OrgauthoritiesCommon.class);
-// if (obj != null) {
-// docHandler.setCommonPart((OrgauthoritiesCommon) obj);
-// }
-// }
-// return docHandler;
-// }
-
/**
* Creates the item document handler.
*
ctx.getCommonPartLabel(getItemServiceName()),
OrganizationsCommon.class);
docHandler.setInAuthority(inAuthority);
-
-
-// ((OrganizationDocumentModelHandler) docHandler).setInAuthority(inAuthority);
-// if (ctx.getInput() != null) {
-// Object obj = ((MultipartServiceContext) ctx).getInputPart(ctx.getCommonPartLabel(getItemServiceName()),
-// OrganizationsCommon.class);
-// if (obj != null) {
-// docHandler.setCommonPart((OrganizationsCommon) obj);
-// }
-// }
-
+
return docHandler;
}
docHandler.setInAuthority(inAuthority);
docHandler.setInItem(inItem);
-// DocumentHandler docHandler = ctx.getDocumentHandler();
-// // Set the inAuthority and inItem values, which specify the
-// // parent authority (e.g. PersonAuthority, OrgAuthority) and the item
-// // (e.g. Person, Organization) with which the Contact is associated.
-// ((ContactDocumentModelHandler) docHandler).setInAuthority(inAuthority);
-// ((ContactDocumentModelHandler) docHandler).setInItem(inItem);
-// if (ctx.getInput() != null) {
-// Object obj = ((MultipartServiceContext) ctx)
-// .getInputPart(ctx.getCommonPartLabel(getContactServiceName()),
-// ContactsCommon.class);
-// if (obj != null) {
-// docHandler.setCommonPart((ContactsCommon) obj);
-// }
-// }
return docHandler;
}
ServiceContext<MultipartInput, MultipartOutput> ctx = createServiceContext(input);
DocumentHandler handler = createDocumentHandler(ctx);
String csid = getRepositoryClient(ctx).create(ctx, handler);
- //orgAuthorityObject.setCsid(csid);
UriBuilder path = UriBuilder.fromResource(OrgAuthorityResource.class);
path.path("" + csid);
Response response = Response.created(path.build()).build();
@GET
@Path("urn:cspace:name({specifier})")
public MultipartOutput getOrgAuthorityByName(@PathParam("specifier") String specifier) {
- String idValue = null;
if (specifier == null) {
logger.error("getOrgAuthority: missing name!");
Response response = Response.status(Response.Status.BAD_REQUEST).entity(
@GET
@Path("{csid}")
public MultipartOutput getOrgAuthority(@PathParam("csid") String csid) {
- String idValue = null;
if (csid == null) {
logger.error("getOrgAuthority: missing csid!");
Response response = Response.status(Response.Status.BAD_REQUEST).entity(
Response.Status.INTERNAL_SERVER_ERROR).entity("Delete failed").type("text/plain").build();
throw new WebApplicationException(response);
}
-
}
/*************************************************************************
* Organization parts - this is a sub-resource of OrgAuthority
+ * @param parentcsid
+ * @param input
+ * @return org response
*************************************************************************/
@POST
@Path("{csid}/items")
/**
* Gets the organization.
+ * @param parentcsid
*
* @param csid The organization authority (parent) CSID.
* @param itemcsid The organization item CSID.
/**
* Gets the authority refs for an Organization item.
+ * @param parentcsid
*
* @param csid The organization authority (parent) CSID.
* @param itemcsid The organization item CSID.
+ * @param ui
*
* @return the authority refs for the Organization item.
*/
String ptClause = "AND " + OrganizationJAXBSchema.ORGANIZATIONS_COMMON +
":" + OrganizationJAXBSchema.DISPLAY_NAME +
" LIKE " + "'%" + partialTerm + "%'";
- myFilter.appendWhereClause(ptClause);
+ myFilter.appendWhereClause(ptClause, IQueryManager.SEARCH_QUALIFIER_AND);
}
getRepositoryClient(ctx).getFiltered(ctx, handler);
organizationObjectList = (OrganizationsCommonList) handler.getCommonPartList();
OrganizationJAXBSchema.DISPLAY_NAME +
" LIKE " +
"'%" + partialTerm + "%'";
- myFilter.appendWhereClause(ptClause);
+ myFilter.appendWhereClause(ptClause, IQueryManager.SEARCH_QUALIFIER_AND);
}
getRepositoryClient(ctx).getFiltered(ctx, handler);
personObjectList = (OrganizationsCommonList) handler.getCommonPartList();
/*************************************************************************
* Contact parts - this is a sub-resource of Organization (or "item")
+ * @param parentcsid
+ * @param itemcsid
+ * @param input
+ * @return contact
*************************************************************************/
@POST
@Path("{parentcsid}/items/{itemcsid}/contacts")
myFilter.setWhereClause(ContactJAXBSchema.CONTACTS_COMMON + ":" +
ContactJAXBSchema.IN_AUTHORITY +
"='" + parentcsid + "'" +
- " AND " +
+ IQueryManager.SEARCH_QUALIFIER_AND +
ContactJAXBSchema.CONTACTS_COMMON + ":" +
ContactJAXBSchema.IN_ITEM +
"='" + itemcsid + "'" +
- " AND ecm:isProxy = 0");
+ IQueryManager.SEARCH_QUALIFIER_AND +
+ "ecm:isProxy = 0");
getRepositoryClient(ctx).getFiltered(ctx, handler);
contactObjectList = (ContactsCommonList) handler.getCommonPartList();
} catch (UnauthorizedException ue) {
import org.collectionspace.services.common.ClientType;
import org.collectionspace.services.common.ServiceMain;
import org.collectionspace.services.common.authorityref.AuthorityRefDocList;
-//import org.collectionspace.services.common.authorityref.AuthorityRefList;
-//import org.collectionspace.services.common.context.MultipartServiceContext;
-import org.collectionspace.services.common.context.MultipartServiceContextFactory;
-//import org.collectionspace.services.common.context.MultipartServiceContextImpl;
import org.collectionspace.services.common.context.ServiceBindingUtils;
import org.collectionspace.services.common.context.ServiceContext;
import org.collectionspace.services.common.document.BadRequestException;
-//import org.collectionspace.services.common.document.DocumentException;
import org.collectionspace.services.common.document.DocumentFilter;
import org.collectionspace.services.common.document.DocumentHandler;
import org.collectionspace.services.common.document.DocumentNotFoundException;
import org.collectionspace.services.common.repository.RepositoryClient;
import org.collectionspace.services.common.security.UnauthorizedException;
import org.collectionspace.services.common.vocabulary.RefNameServiceUtils;
-//import org.collectionspace.services.common.vocabulary.RefNameUtils;
import org.collectionspace.services.common.query.IQueryManager;
import org.collectionspace.services.contact.ContactResource;
import org.collectionspace.services.contact.ContactsCommon;
import org.collectionspace.services.contact.ContactsCommonList;
import org.collectionspace.services.contact.ContactJAXBSchema;
import org.collectionspace.services.contact.nuxeo.ContactDocumentModelHandler;
-//import org.collectionspace.services.nuxeo.client.java.RemoteDocumentModelHandlerImpl;
import org.collectionspace.services.person.nuxeo.PersonDocumentModelHandler;
+
import org.jboss.resteasy.plugins.providers.multipart.MultipartInput;
import org.jboss.resteasy.plugins.providers.multipart.MultipartOutput;
import org.jboss.resteasy.util.HttpResponseCodes;
+
import org.nuxeo.ecm.core.api.DocumentModel;
+
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
return contactResource.getServiceName();
}
-// @Override
-// public DocumentHandler createDocumentHandler(ServiceContext<MultipartInput, MultipartOutput> ctx) throws Exception {
-// DocumentHandler docHandler = ctx.getDocumentHandler();
-// if (ctx.getInput() != null) {
-// Object obj = ((MultipartServiceContext) ctx).getInputPart(ctx.getCommonPartLabel(), PersonauthoritiesCommon.class);
-// if (obj != null) {
-// docHandler.setCommonPart((PersonauthoritiesCommon) obj);
-// }
-// }
-// return docHandler;
-// }
-
/**
* Creates the item document handler.
*
docHandler.setInAuthority(inAuthority);
docHandler.setInItem(inItem);
-// DocumentHandler docHandler = ctx.getDocumentHandler();
-// // Set the inAuthority and inItem values, which specify the
-// // parent authority (e.g. PersonAuthority, OrgAuthority) and the item
-// // (e.g. Person, Organization) with which the Contact is associated.
-// ((ContactDocumentModelHandler) docHandler).setInAuthority(inAuthority);
-// ((ContactDocumentModelHandler) docHandler).setInItem(inItem);
-// if (ctx.getInput() != null) {
-// Object obj = ((MultipartServiceContext) ctx)
-// .getInputPart(ctx.getCommonPartLabel(getContactServiceName()),
-// ContactsCommon.class);
-// if (obj != null) {
-// docHandler.setCommonPart((ContactsCommon) obj);
-// }
-// }
return docHandler;
}
@GET
@Path("urn:cspace:name({specifier})")
public MultipartOutput getPersonAuthorityByName(@PathParam("specifier") String specifier) {
-//REM: String idValue = null;
if (specifier == null) {
logger.error("getPersonAuthority: missing name!");
Response response = Response.status(Response.Status.BAD_REQUEST).entity(
@Path("{csid}/items/{itemcsid}/refObjs")
@Produces("application/xml") //FIXME: REM do this for CSPACE-1079 in Org authority.
public AuthorityRefDocList getReferencingObjects(
- @PathParam("csid") String parentcsid,
- @PathParam("itemcsid") String itemcsid,
+ @PathParam("csid") String parentcsid,
+ @PathParam("itemcsid") String itemcsid,
@Context UriInfo ui) {
AuthorityRefDocList authRefDocList = null;
- if (logger.isDebugEnabled()) {
- logger.debug("getReferencingObjects with parentcsid="
- + parentcsid + " and itemcsid=" + itemcsid);
- }
- if (parentcsid == null || "".equals(parentcsid)
- || itemcsid == null || "".equals(itemcsid)) {
- logger.error("getPerson: missing parentcsid or itemcsid!");
- Response response = Response.status(Response.Status.BAD_REQUEST).entity(
- "get failed on Person with parentcsid="
- + parentcsid + " and itemcsid=" + itemcsid).type(
- "text/plain").build();
- throw new WebApplicationException(response);
- }
- try {
- MultivaluedMap<String, String> queryParams = ui.getQueryParameters();
- // Note that we have to create the service context for the Items, not the main service
- ServiceContext<MultipartInput, MultipartOutput> ctx = createServiceContext(getItemServiceName(),
- queryParams);
- DocumentHandler handler = createItemDocumentHandler(ctx, parentcsid);
- RepositoryClient repoClient = getRepositoryClient(ctx);
- DocumentFilter myFilter = handler.getDocumentFilter();
- String serviceType = ServiceBindingUtils.SERVICE_TYPE_PROCEDURE;
- List<String> list = queryParams.remove(ServiceBindingUtils.SERVICE_TYPE_PROP);
- if (list != null) {
- serviceType = list.get(0);
- }
- DocumentWrapper<DocumentModel> docWrapper = repoClient.getDoc(ctx, itemcsid);
- DocumentModel docModel = docWrapper.getWrappedObject();
- String refName = (String)docModel.getPropertyValue(PersonJAXBSchema.REF_NAME);
+ if (logger.isDebugEnabled()) {
+ logger.debug("getReferencingObjects with parentcsid="
+ + parentcsid + " and itemcsid=" + itemcsid);
+ }
+ if (parentcsid == null || "".equals(parentcsid)
+ || itemcsid == null || "".equals(itemcsid)) {
+ logger.error("getPerson: missing parentcsid or itemcsid!");
+ Response response = Response.status(Response.Status.BAD_REQUEST).entity(
+ "get failed on Person with parentcsid="
+ + parentcsid + " and itemcsid=" + itemcsid).type(
+ "text/plain").build();
+ throw new WebApplicationException(response);
+ }
+ try {
+ MultivaluedMap<String, String> queryParams = ui.getQueryParameters();
+ // Note that we have to create the service context for the Items, not the main service
+ ServiceContext<MultipartInput, MultipartOutput> ctx = createServiceContext(getItemServiceName(),
+ queryParams);
+ DocumentHandler handler = createItemDocumentHandler(ctx, parentcsid);
+ RepositoryClient repoClient = getRepositoryClient(ctx);
+ DocumentFilter myFilter = handler.getDocumentFilter();
+ String serviceType = ServiceBindingUtils.SERVICE_TYPE_PROCEDURE;
+ List<String> list = queryParams.remove(ServiceBindingUtils.SERVICE_TYPE_PROP);
+ if (list != null) {
+ serviceType = list.get(0);
+ }
+ DocumentWrapper<DocumentModel> docWrapper = repoClient.getDoc(ctx, itemcsid);
+ DocumentModel docModel = docWrapper.getWrappedObject();
+ String refName = (String)docModel.getPropertyValue(PersonJAXBSchema.REF_NAME);
- authRefDocList = RefNameServiceUtils.getAuthorityRefDocs(ctx,
- repoClient,
- serviceType,
- refName,
- myFilter.getPageSize(), myFilter.getStartPage(), true /*computeTotal*/ );
- } catch (UnauthorizedException ue) {
- Response response = Response.status(
- Response.Status.UNAUTHORIZED).entity("Get failed reason " + ue.getErrorReason()).type("text/plain").build();
- throw new WebApplicationException(response);
- } catch (DocumentNotFoundException dnfe) {
- if (logger.isDebugEnabled()) {
- logger.debug("getReferencingObjects", dnfe);
- }
- Response response = Response.status(Response.Status.NOT_FOUND).entity(
- "GetReferencingObjects failed with parentcsid="
- + parentcsid + " and itemcsid=" + itemcsid).type(
- "text/plain").build();
- throw new WebApplicationException(response);
- } catch (Exception e) { // Includes DocumentException
- if (logger.isDebugEnabled()) {
- logger.debug("GetReferencingObjects", e);
- }
- Response response = Response.status(
- Response.Status.INTERNAL_SERVER_ERROR).entity("Get failed").type("text/plain").build();
- throw new WebApplicationException(response);
- }
- if (authRefDocList == null) {
- Response response = Response.status(Response.Status.NOT_FOUND).entity(
- "Get failed, the requested Person CSID:" + itemcsid + ": was not found.").type(
- "text/plain").build();
- throw new WebApplicationException(response);
- }
- return authRefDocList;
+ authRefDocList = RefNameServiceUtils.getAuthorityRefDocs(ctx,
+ repoClient,
+ serviceType,
+ refName,
+ myFilter.getPageSize(), myFilter.getStartPage(), true /*computeTotal*/ );
+ } catch (UnauthorizedException ue) {
+ Response response = Response.status(
+ Response.Status.UNAUTHORIZED).entity("Get failed reason " + ue.getErrorReason()).type("text/plain").build();
+ throw new WebApplicationException(response);
+ } catch (DocumentNotFoundException dnfe) {
+ if (logger.isDebugEnabled()) {
+ logger.debug("getReferencingObjects", dnfe);
+ }
+ Response response = Response.status(Response.Status.NOT_FOUND).entity(
+ "GetReferencingObjects failed with parentcsid="
+ + parentcsid + " and itemcsid=" + itemcsid).type(
+ "text/plain").build();
+ throw new WebApplicationException(response);
+ } catch (Exception e) { // Includes DocumentException
+ if (logger.isDebugEnabled()) {
+ logger.debug("GetReferencingObjects", e);
+ }
+ Response response = Response.status(
+ Response.Status.INTERNAL_SERVER_ERROR).entity("Get failed").type("text/plain").build();
+ throw new WebApplicationException(response);
+ }
+ if (authRefDocList == null) {
+ Response response = Response.status(Response.Status.NOT_FOUND).entity(
+ "Get failed, the requested Person CSID:" + itemcsid + ": was not found.").type(
+ "text/plain").build();
+ throw new WebApplicationException(response);
+ }
+ return authRefDocList;
}
@GET
PersonJAXBSchema.DISPLAY_NAME +
" LIKE " +
"'%" + partialTerm + "%'";
- handler.getDocumentFilter().appendWhereClause(ptClause);
+ handler.getDocumentFilter().appendWhereClause(ptClause, IQueryManager.SEARCH_QUALIFIER_AND);
}
getRepositoryClient(ctx).getFiltered(ctx, handler);
personObjectList = (PersonsCommonList) handler.getCommonPartList();
PersonJAXBSchema.DISPLAY_NAME +
" LIKE " +
"'%" + partialTerm + "%'";
- handler.getDocumentFilter().appendWhereClause(ptClause);
+ handler.getDocumentFilter().appendWhereClause(ptClause, IQueryManager.SEARCH_QUALIFIER_AND);
}
getRepositoryClient(ctx).getFiltered(ctx, handler);
personObjectList = (PersonsCommonList) handler.getCommonPartList();
.type("text/plain").build();
throw new WebApplicationException(response);
}
+
return result;
-
}
/**
*/
package org.collectionspace.services.client.test;
-import java.util.ArrayList;
import java.util.List;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import org.jboss.resteasy.plugins.providers.multipart.MultipartOutput;
import org.jboss.resteasy.plugins.providers.multipart.OutputPart;
import org.testng.Assert;
-import org.testng.annotations.AfterClass;
import org.testng.annotations.Test;
import org.slf4j.Logger;
/** The known resource id. */
private String knownResourceId = null;
- /** The all resource ids created. */
- private List<String> allResourceIdsCreated = new ArrayList<String>();
-
/* (non-Javadoc)
* @see org.collectionspace.services.client.test.BaseServiceTest#getClientInstance()
*/
invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
}
-
- /* (non-Javadoc)
- * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#readPaginatedList(java.lang.String)
- */
- @Test(dataProvider = "testName")
- /*
- * FIXME: Until the Relation service uses NXQL queries to get results,
- * we need to skip the pagination tests
- */
- @Override
- public void readPaginatedList(String testName) throws Exception {
- //Override and skip the pagination tests
- }
// ---------------------------------------------------------------
// CRUD tests : READ_LIST tests
" status=" + statusCode);
}
Assert.assertEquals(statusCode, EXPECTED_STATUS);
-
- }
-
- // ---------------------------------------------------------------
- // Cleanup of resources created during testing
- // ---------------------------------------------------------------
-
- /**
- * Deletes all resources created by tests, after all tests have been run.
- *
- * This cleanup method will always be run, even if one or more tests fail.
- * For this reason, it attempts to remove all resources created
- * at any point during testing, even if some of those resources
- * may be expected to be deleted by certain tests.
- */
- @AfterClass(alwaysRun=true)
- public void cleanUp() {
- String noTest = System.getProperty("noTestCleanup");
- if(Boolean.TRUE.toString().equalsIgnoreCase(noTest)) {
- if (logger.isDebugEnabled()) {
- logger.debug("Skipping Cleanup phase ...");
- }
- return;
- }
- if (logger.isDebugEnabled()) {
- logger.debug("Cleaning up temporary resources created for testing ...");
- }
- RelationClient client = new RelationClient();
- for (String resourceId : allResourceIdsCreated) {
- // Note: Any non-success responses are ignored and not reported.
- ClientResponse<Response> res = client.delete(resourceId);
- }
}
// ---------------------------------------------------------------
*/
package org.collectionspace.services.relation;
-import java.util.Map;
-
import javax.ws.rs.Consumes;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.core.UriBuilder;
import javax.ws.rs.core.UriInfo;
+import org.collectionspace.services.common.query.IQueryManager;
+import org.collectionspace.services.common.relation.nuxeo.RelationsUtils;
import org.collectionspace.services.common.AbstractMultiPartCollectionSpaceResourceImpl;
-//import org.collectionspace.services.common.context.MultipartServiceContext;
import org.collectionspace.services.common.context.ServiceContext;
-import org.collectionspace.services.common.relation.IRelationsManager;
import org.collectionspace.services.common.document.DocumentNotFoundException;
import org.collectionspace.services.common.document.DocumentHandler;
import org.collectionspace.services.common.security.UnauthorizedException;
public Class<RelationsCommon> getCommonPartClass() {
return RelationsCommon.class;
}
-
- /* (non-Javadoc)
- * @see org.collectionspace.services.common.AbstractCollectionSpaceResource#createDocumentHandler(org.collectionspace.services.common.context.ServiceContext)
- */
-// @Override
-// public DocumentHandler createDocumentHandler(ServiceContext<MultipartInput, MultipartOutput> ctx)
-// throws Exception {
-// DocumentHandler docHandler = ctx.getDocumentHandler();
-// if (ctx.getInput() != null) {
-// Object obj = ((MultipartServiceContext) ctx).getInputPart(ctx
-// .getCommonPartLabel(), RelationsCommon.class);
-// if (obj != null) {
-// docHandler.setCommonPart((RelationsCommon) obj);
-// }
-// }
-// return docHandler;
-// }
/**
* Creates the relation.
RelationsCommonList relationList = new RelationsCommonList();
try {
ServiceContext<MultipartInput, MultipartOutput> ctx = createServiceContext(queryParams);
- DocumentHandler handler = createDocumentHandler(ctx);
- Map<String, Object> propsFromPath = handler.getProperties();
- propsFromPath.put(IRelationsManager.SUBJECT, subjectCsid);
- propsFromPath.put(IRelationsManager.PREDICATE, predicate);
- propsFromPath.put(IRelationsManager.OBJECT, objectCsid);
- // Until we replace this with a search, "getAll()" is better then "getFiltered"
- getRepositoryClient(ctx).getAll(ctx, handler);
- relationList = (RelationsCommonList) handler.getCommonPartList();
+ DocumentHandler handler = createDocumentHandler(ctx);
+ String relationClause = RelationsUtils.buildWhereClause(subjectCsid, predicate, objectCsid);
+ handler.getDocumentFilter().appendWhereClause(relationClause, IQueryManager.SEARCH_QUALIFIER_AND);
+ getRepositoryClient(ctx).getFiltered(ctx, handler);
+ relationList = (RelationsCommonList)handler.getCommonPartList();
} catch (UnauthorizedException ue) {
- Response response = Response.status(Response.Status.UNAUTHORIZED)
- .entity(
- "Get relations failed reason "
- + ue.getErrorReason()).type("text/plain")
- .build();
+ Response response = Response.status(Response.Status.UNAUTHORIZED).entity(
+ "Get relations failed reason " +
+ ue.getErrorReason()).type("text/plain").build();
throw new WebApplicationException(response);
} catch (Exception e) {
if (logger.isDebugEnabled()) {
"Index failed").type("text/plain").build();
throw new WebApplicationException(response);
}
+
return relationList;
}
}
import java.util.Iterator;
import java.util.List;
-import java.util.Map;
-
-import org.collectionspace.services.common.relation.IRelationsManager;
+import org.collectionspace.services.common.relation.RelationJAXBSchema;
import org.collectionspace.services.common.relation.nuxeo.RelationConstants;
-import org.collectionspace.services.common.relation.nuxeo.RelationsUtils;
-import org.collectionspace.services.common.document.DocumentHandler.Action;
+import org.collectionspace.services.common.context.ServiceContext;
import org.collectionspace.services.relation.RelationsCommon;
import org.collectionspace.services.relation.RelationsCommonList;
import org.collectionspace.services.relation.RelationsCommonList.RelationListItem;
import org.collectionspace.services.common.document.DocumentWrapper;
import org.collectionspace.services.nuxeo.client.java.RemoteDocumentModelHandlerImpl;
+import org.collectionspace.services.nuxeo.util.NuxeoUtils;
+import org.jboss.resteasy.plugins.providers.multipart.MultipartInput;
+import org.jboss.resteasy.plugins.providers.multipart.MultipartOutput;
import org.nuxeo.ecm.core.api.DocumentModel;
import org.nuxeo.ecm.core.api.DocumentModelList;
import org.slf4j.Logger;
/**
* getCommonObject get associated Relation
- * @return
+ * @return relation
*/
@Override
public RelationsCommon getCommonPart() {
* @param relation
*/
@Override
- public void setCommonPart(RelationsCommon relation) {
- this.relation = relation;
+ public void setCommonPart(RelationsCommon theRelation) {
+ this.relation = theRelation;
}
/**
* getRelationList get associated Relation (for index/GET_ALL)
- * @return
+ * @return relationCommonList
*/
@Override
public RelationsCommonList getCommonPartList() {
* @see org.collectionspace.services.nuxeo.client.java.DocumentModelHandler#setCommonPartList(java.lang.Object)
*/
@Override
- public void setCommonPartList(RelationsCommonList relationList) {
- this.relationList = relationList;
+ public void setCommonPartList(RelationsCommonList theRelationList) {
+ this.relationList = theRelationList;
}
/* (non-Javadoc)
* @see org.collectionspace.services.nuxeo.client.java.DocumentModelHandler#fillCommonPart(java.lang.Object, org.collectionspace.services.common.document.DocumentWrapper)
*/
@Override
- public void fillCommonPart(RelationsCommon relation, DocumentWrapper<DocumentModel> wrapDoc) throws Exception {
+ public void fillCommonPart(RelationsCommon theRelation, DocumentWrapper<DocumentModel> wrapDoc) throws Exception {
throw new UnsupportedOperationException();
}
*/
@Override
public RelationsCommonList extractCommonPartList(DocumentWrapper<DocumentModelList> wrapDoc) throws Exception {
- Map propsFromResource = this.getProperties();
- String subjectCsid = (String) propsFromResource.get(IRelationsManager.SUBJECT);
- String predicate = (String) propsFromResource.get(IRelationsManager.PREDICATE);
- String objectCsid = (String) propsFromResource.get(IRelationsManager.OBJECT);
-
- //FIXME - Need to change this into a NXQL on subject, predicate, object terms. Currently,
- //FIXME - we're performing a post query filter which is far from ideal and not scalable.
RelationsCommonList relList = this.extractPagingInfo(new RelationsCommonList(), wrapDoc) ;
List<RelationsCommonList.RelationListItem> itemList = relList.getRelationListItem();
Iterator<DocumentModel> iter = wrapDoc.getWrappedObject().iterator();
while(iter.hasNext()){
DocumentModel docModel = iter.next();
- if (RelationsUtils.isQueryMatch(docModel, subjectCsid,
- predicate, objectCsid) == true){
- RelationListItem relListItem = RelationsUtils.getRelationListItem(getServiceContext(),
- docModel, getServiceContextPath());
- itemList.add(relListItem);
- }
+ RelationListItem relListItem = getRelationListItem(getServiceContext(),
+ docModel, getServiceContextPath());
+ itemList.add(relListItem);
}
return relList;
}
@Override
public void fillAllParts(DocumentWrapper<DocumentModel> wrapDoc) throws Exception {
super.fillAllParts(wrapDoc);
- fillDublinCoreObject(wrapDoc); //dublincore might not be needed in future
}
/**
- * Fill dublin core object.
+ * Gets the relation list item.
*
- * @param wrapDoc the wrap doc
+ * @param ctx the ctx
+ * @param docModel the doc model
+ * @param serviceContextPath the service context path
+ * @return the relation list item
* @throws Exception the exception
*/
- private void fillDublinCoreObject(DocumentWrapper<DocumentModel> wrapDoc) throws Exception {
- DocumentModel docModel = wrapDoc.getWrappedObject();
- //FIXME property setter should be dynamically set using schema inspection
- //so it does not require hard coding
- // a default title for the Dublin Core schema
- docModel.setPropertyValue("dublincore:title", RelationConstants.NUXEO_DC_TITLE);
+ private RelationListItem getRelationListItem(ServiceContext<MultipartInput, MultipartOutput> ctx,
+ DocumentModel docModel,
+ String serviceContextPath) throws Exception {
+ RelationListItem relationListItem = new RelationListItem();
+ String id = NuxeoUtils.extractId(docModel.getPathAsString());
+ relationListItem.setCsid(id);
+ //
+ // Subject
+ //
+ relationListItem.setSubjectCsid((String) docModel.getProperty(ctx.getCommonPartLabel(),
+ RelationJAXBSchema.DOCUMENT_ID_1));
+ //
+ // Predicate
+ //
+ relationListItem.setRelationshipType((String) docModel.getProperty(ctx.getCommonPartLabel(),
+ RelationJAXBSchema.RELATIONSHIP_TYPE));
+ //
+ // Object
+ //
+ relationListItem.setObjectCsid((String) docModel.getProperty(ctx.getCommonPartLabel(),
+ RelationJAXBSchema.DOCUMENT_ID_2));
+
+ relationListItem.setUri(serviceContextPath + id);
+ return relationListItem;
}
-
/* (non-Javadoc)
* @see org.collectionspace.services.common.document.AbstractMultipartDocumentHandlerImpl#getQProperty(java.lang.String)
*/
import org.collectionspace.services.common.AbstractMultiPartCollectionSpaceResourceImpl;
import org.collectionspace.services.common.ClientType;
import org.collectionspace.services.common.ServiceMain;
-import org.collectionspace.services.common.context.MultipartServiceContext;
-import org.collectionspace.services.common.context.MultipartServiceContextFactory;
import org.collectionspace.services.common.context.ServiceContext;
import org.collectionspace.services.common.document.BadRequestException;
import org.collectionspace.services.common.document.DocumentFilter;
public String getItemServiceName() {
return vocabularyItemServiceName;
}
-
- /*
- public RemoteServiceContext createItemServiceContext(MultipartInput input) throws Exception {
- RemoteServiceContext ctx = new RemoteServiceContextImpl(getItemServiceName());
- ctx.setInput(input);
- return ctx;
- }
- */
-// @Override
-// public DocumentHandler createDocumentHandler(ServiceContext ctx) throws Exception {
-// DocumentHandler docHandler = ctx.getDocumentHandler();
-// if (ctx.getInput() != null) {
-// Object obj = ((MultipartServiceContext) ctx).getInputPart(ctx.getCommonPartLabel(), VocabulariesCommon.class);
-// if (obj != null) {
-// docHandler.setCommonPart((VocabulariesCommon) obj);
-// }
-// }
-// return docHandler;
-// }
-
-// @Override
-// public DocumentHandler createDocumentHandler(ServiceContext ctx)
-// throws Exception {
-// DocumentHandler docHandler = createDocumentHandler(ctx, VocabulariesCommon.class);
-// return docHandler;
-// }
/**
* Creates the item document handler.
@GET
@Path("{csid}")
public MultipartOutput getVocabulary(@PathParam("csid") String csid) {
- String idValue = null;
+// String idValue = null;
if (csid == null) {
logger.error("getVocabulary: missing csid!");
Response response = Response.status(Response.Status.BAD_REQUEST).entity(
/*************************************************************************
* VocabularyItem parts - this is a sub-resource of Vocabulary
+ * @param parentcsid
+ * @param input
+ * @return vocab item response
*************************************************************************/
@POST
@Path("{csid}/items")
// AND vocabularyitems_common:displayName LIKE '%partialTerm%'
if (partialTerm != null && !partialTerm.isEmpty()) {
- String ptClause = "AND "
- + VocabularyItemJAXBSchema.VOCABULARYITEMS_COMMON + ":"
+ String ptClause = VocabularyItemJAXBSchema.VOCABULARYITEMS_COMMON + ":"
+ VocabularyItemJAXBSchema.DISPLAY_NAME
- + " LIKE "
+ + IQueryManager.SEARCH_LIKE
+ "'%" + partialTerm + "%'";
- myFilter.appendWhereClause(ptClause);
+ myFilter.appendWhereClause(ptClause, IQueryManager.SEARCH_QUALIFIER_AND);
}
if (logger.isDebugEnabled()) {