From 02b5aa810aef5724bd5ec67ff4b1811f694e0f39 Mon Sep 17 00:00:00 2001 From: Richard Millet Date: Wed, 19 May 2010 07:37:18 +0000 Subject: [PATCH] CSPACE-1081: Relation list should probably include relationship type 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 --- .../common/document/DocumentFilter.java | 230 +++++++++++----- .../services/common/query/IQueryManager.java | 10 +- .../common/relation/IRelationsManager.java | 6 +- .../relation/RelationListItemJAXBSchema.java | 1 + .../relation/nuxeo/RelationConstants.java | 1 - .../common/relation/nuxeo/RelationsUtils.java | 246 +++--------------- .../java/RemoteDocumentModelHandlerImpl.java | 5 +- .../client/java/RepositoryJavaClientImpl.java | 15 +- .../src/main/resources/relations_common.xsd | 11 +- .../organization/OrgAuthorityResource.java | 71 ++--- .../person/PersonAuthorityResource.java | 171 +++++------- .../client/test/RelationServiceTest.java | 50 ---- .../relation/NewRelationResource.java | 45 +--- .../nuxeo/RelationDocumentModelHandler.java | 79 +++--- .../vocabulary/VocabularyResource.java | 40 +-- 15 files changed, 372 insertions(+), 609 deletions(-) diff --git a/services/common/src/main/java/org/collectionspace/services/common/document/DocumentFilter.java b/services/common/src/main/java/org/collectionspace/services/common/document/DocumentFilter.java index e5a15e67c..4c6d10e60 100644 --- a/services/common/src/main/java/org/collectionspace/services/common/document/DocumentFilter.java +++ b/services/common/src/main/java/org/collectionspace/services/common/document/DocumentFilter.java @@ -21,48 +21,62 @@ import java.util.ArrayList; import java.util.List; import javax.ws.rs.core.MultivaluedMap; import org.collectionspace.services.client.IClientQueryParams; -import org.collectionspace.services.common.query.IQueryManager; import org.collectionspace.services.common.context.ServiceContext; -//TODO: would be great to not rely on resteasy directly -import org.jboss.resteasy.specimpl.MultivaluedMapImpl; - /** - * DocumentFilter bundles simple query filtering parameters. - * It is designed to be used with filtered get and search calls to RepositoryClient. - * The values are set up and stored on a DocumentHandler, and - * fetched by a RepositoryClient when calling filtered get methods. + * The Class DocumentFilter. */ public class DocumentFilter { + /** The Constant DEFAULT_PAGE_SIZE_INIT. */ public static final int DEFAULT_PAGE_SIZE_INIT = 40; + + /** The Constant PAGE_SIZE_DEFAULT_PROPERTY. */ public static final String PAGE_SIZE_DEFAULT_PROPERTY = "pageSizeDefault"; + + /** The default page size. */ public static int defaultPageSize = DEFAULT_PAGE_SIZE_INIT; + /** The where clause. */ protected String whereClause; // Filtering clause. Omit the "WHERE". + + /** The start page. */ protected int startPage; // Pagination offset for list results + + /** The page size. */ protected int pageSize; // Pagination limit for list results - private boolean pageSizeDirty = false; // True if default page size explicitly set/overridden - + //queryParams is not initialized as it would require a multi-valued map implementation //unless it is used from opensource lib...this variable holds ref to //implementation available in JBoss RESTeasy + /** The query params. */ private MultivaluedMap queryParams = null; /** - * ParamBinding encapsulates parameter binding for query + * The Class ParamBinding. */ public static class ParamBinding { + /** The name. */ private String name; + + /** The value. */ private Object value; - public ParamBinding(String name, Object value) { - this.name = name; - this.value = value; + /** + * Instantiates a new param binding. + * + * @param theName the name + * @param theValue the value + */ + public ParamBinding(String theName, Object theValue) { + this.name = theName; + this.value = theValue; } /** + * Gets the name. + * * @return the name */ public String getName() { @@ -70,13 +84,17 @@ public class DocumentFilter { } /** - * @param name the name to set + * Sets the name. + * + * @param theName the new name */ - public void setName(String name) { - this.name = name; + public void setName(String theName) { + this.name = theName; } /** + * Gets the value. + * * @return the value */ public Object getValue() { @@ -84,16 +102,18 @@ public class DocumentFilter { } /** - * @param value the value to set + * Sets the value. + * + * @param theValue the new value */ - public void setValue(Object value) { - this.value = value; + public void setValue(Object theValue) { + this.value = theValue; } } /** * Instantiates a new document filter. - * + * * @param ctx the ctx */ public DocumentFilter(ServiceContext ctx) { @@ -101,44 +121,52 @@ public class DocumentFilter { DocumentFilter.PAGE_SIZE_DEFAULT_PROPERTY)); } + /** + * Instantiates a new document filter. + */ public DocumentFilter() { this("", 0, defaultPageSize); // Use empty string for easy concatenation } - public DocumentFilter(String whereClause, int startPage, int pageSize) { - this.whereClause = whereClause; - this.startPage = (startPage > 0) ? startPage : 0; - this.pageSize = (pageSize > 0) ? pageSize : defaultPageSize; + /** + * Instantiates a new document filter. + * + * @param theWhereClause the the where clause + * @param theStartPage the the start page + * @param thePageSize the the page size + */ + public DocumentFilter(String theWhereClause, int theStartPage, int thePageSize) { + this.whereClause = theWhereClause; + this.startPage = (theStartPage > 0) ? theStartPage : 0; + this.pageSize = (thePageSize > 0) ? thePageSize : defaultPageSize; } /** * Sets the pagination. - * - * @param queryParams the query params + * + * @param theQueryParams the the query params */ - public void setPagination(MultivaluedMap queryParams) { + public void setPagination(MultivaluedMap theQueryParams) { // // Bail if there are no params // - if (queryParams == null) { + if (theQueryParams == null) { return; } - // // Set the page size // String pageSizeStr = null; - List list = queryParams.get(IClientQueryParams.PAGE_SIZE_PARAM); + List list = theQueryParams.get(IClientQueryParams.PAGE_SIZE_PARAM); if (list != null) { pageSizeStr = list.get(0); } setPageSize(pageSizeStr); - // // Set the start page // String startPageStr = null; - list = queryParams.get(IClientQueryParams.START_PAGE_PARAM); + list = theQueryParams.get(IClientQueryParams.START_PAGE_PARAM); if (list != null) { startPageStr = list.get(0); } @@ -146,100 +174,134 @@ public class DocumentFilter { } /** - * @return the current default page size for new DocumentFilter instances + * Gets the default page size. + * + * @return the default page size */ public static int getDefaultPageSize() { return defaultPageSize; } /** - * @param defaultPageSize the working default page size for new DocumentFilter instances + * Sets the default page size. + * + * @param theDefaultPageSize the new default page size */ - public static void setDefaultPageSize(int defaultPageSize) { - DocumentFilter.defaultPageSize = defaultPageSize; + public static void setDefaultPageSize(int theDefaultPageSize) { + DocumentFilter.defaultPageSize = theDefaultPageSize; } /** - * @return the WHERE filtering clause + * Gets the where clause. + * + * @return the where clause */ public String getWhereClause() { return whereClause; } /** - * @param whereClause the filtering clause (do not include "WHERE") + * Sets the where clause. + * + * @param theWhereClause the new where clause */ - public void setWhereClause(String whereClause) { - this.whereClause = whereClause; + public void setWhereClause(String theWhereClause) { + this.whereClause = theWhereClause; } - public void appendWhereClause(String whereClause) { - String currentClause = getWhereClause(); - if (currentClause != null) { - String newClause = currentClause.concat(IQueryManager.SEARCH_TERM_SEPARATOR + whereClause); - this.setWhereClause(newClause); - } + /** + * Append where clause. + * + * @param theWhereClause the the where clause + * @param conjunction the conjunction + */ + public void appendWhereClause(String theWhereClause, String conjunction) { + if (theWhereClause != null && theWhereClause.length() > 0) { + String currentClause = getWhereClause(); + if (currentClause != null) { + String newClause = currentClause.concat(conjunction + theWhereClause); + this.setWhereClause(newClause); + } else { + this.setWhereClause(theWhereClause); + } + } } /** - * buildWhereClause builds where clause for search query - * @param queryStrBldr query string to append with where clause - * @return parameter binding + * Builds the where for search. + * + * @param queryStrBldr the query str bldr + * @return the list */ public List buildWhereForSearch(StringBuilder queryStrBldr) { return new ArrayList(); } /** - * buildWhereClause builds where clause for get, update or delete - * @param queryStrBldr query string to append with where clause - * @return parameter binding + * Builds the where. + * + * @param queryStrBldr the query str bldr + * @return the list */ public List buildWhere(StringBuilder queryStrBldr) { return new ArrayList(); } /** - * @return the specified (0-based) page offset + * Gets the start page. + * + * @return the start page */ public int getStartPage() { return startPage; } /** - * @param startPage the (0-based) page offset to use + * Sets the start page. + * + * @param theStartPage the new start page */ - public void setStartPage(int startPage) { - this.startPage = startPage; + public void setStartPage(int theStartPage) { + this.startPage = theStartPage; } /** - * @return the max number of items to return for list requests + * Gets the page size. + * + * @return the page size */ public int getPageSize() { return pageSize; } + /** + * Gets the page size dirty. + * + * @return the page size dirty + */ public boolean getPageSizeDirty() { return this.getPageSizeDirty(); } /** - * @param pageSize the max number of items to return for list requests + * Sets the page size. + * + * @param thePageSize the new page size */ - public void setPageSize(int pageSize) { - this.pageSize = pageSize; - this.pageSizeDirty = true; // page size explicity set/overriden + public void setPageSize(int thePageSize) { + this.pageSize = thePageSize; } /** - * @param pageSize the max number of items to return for list requests + * Sets the page size. + * + * @param thePageSizeStr the new page size */ - public void setPageSize(String pageSizeStr) { - int pageSize = this.defaultPageSize; - if (pageSizeStr != null) { + public void setPageSize(String thePageSizeStr) { + int newPageSize = DocumentFilter.defaultPageSize; + if (thePageSizeStr != null) { try { - pageSize = Integer.valueOf(pageSizeStr); + newPageSize = Integer.valueOf(thePageSizeStr); } catch (NumberFormatException e) { //FIXME This should cause a warning in the log file and should result in the //FIXME page size being set to the default. We don't need to throw an exception here. @@ -248,12 +310,12 @@ public class DocumentFilter { } } - setPageSize(pageSize); + setPageSize(newPageSize); } /** * Sets the start page. - * + * * @param startPageStr the new start page */ protected void setStartPage(String startPageStr) { @@ -268,18 +330,32 @@ public class DocumentFilter { } /** - * @return the offset computed from the startPage and the pageSize + * Gets the offset. + * + * @return the offset */ public int getOffset() { return pageSize * startPage; } + /** + * Adds the query param. + * + * @param key the key + * @param value the value + */ public void addQueryParam(String key, String value) { if (queryParams != null) { queryParams.add(key, value); } } + /** + * Gets the query param. + * + * @param key the key + * @return the query param + */ public List getQueryParam(String key) { if (queryParams != null) { return queryParams.get(key); @@ -288,11 +364,21 @@ public class DocumentFilter { } } + /** + * Gets the query params. + * + * @return the query params + */ public MultivaluedMap getQueryParams() { return queryParams; } - public void setQueryParams(MultivaluedMap queryParams) { - this.queryParams = queryParams; + /** + * Sets the query params. + * + * @param theQueryParams the the query params + */ + public void setQueryParams(MultivaluedMap theQueryParams) { + this.queryParams = theQueryParams; } } diff --git a/services/common/src/main/java/org/collectionspace/services/common/query/IQueryManager.java b/services/common/src/main/java/org/collectionspace/services/common/query/IQueryManager.java index d77dd2b24..3ac1e2742 100644 --- a/services/common/src/main/java/org/collectionspace/services/common/query/IQueryManager.java +++ b/services/common/src/main/java/org/collectionspace/services/common/query/IQueryManager.java @@ -28,14 +28,14 @@ package org.collectionspace.services.common.query; public interface IQueryManager { - final static String SEARCH_LIKE = "LIKE"; + final static String SEARCH_TERM_SEPARATOR = " "; + final static String SEARCH_LIKE = " LIKE "; final static String SEARCH_TYPE_KEYWORDS = "keywords"; final static String SEARCH_TYPE_KEYWORDS_KW = "kw"; final static String SEARCH_TYPE_PARTIALTERM = "pt"; - final static String ECM_FULLTEXT_LIKE = "ecm:fulltext " + SEARCH_LIKE; - final static String SEARCH_QUALIFIER_AND = "AND"; - final static String SEARCH_QUALIFIER_OR = "OR"; - final static String SEARCH_TERM_SEPARATOR = " "; + final static String ECM_FULLTEXT_LIKE = "ecm:fulltext" + SEARCH_TERM_SEPARATOR + SEARCH_LIKE; + final static String SEARCH_QUALIFIER_AND = SEARCH_TERM_SEPARATOR + "AND" + SEARCH_TERM_SEPARATOR; + final static String SEARCH_QUALIFIER_OR = SEARCH_TERM_SEPARATOR + "OR" + SEARCH_TERM_SEPARATOR; public void execQuery(String queryString); diff --git a/services/common/src/main/java/org/collectionspace/services/common/relation/IRelationsManager.java b/services/common/src/main/java/org/collectionspace/services/common/relation/IRelationsManager.java index 65a8b62f7..726d69783 100644 --- a/services/common/src/main/java/org/collectionspace/services/common/relation/IRelationsManager.java +++ b/services/common/src/main/java/org/collectionspace/services/common/relation/IRelationsManager.java @@ -40,11 +40,15 @@ public interface IRelationsManager { /** The Constant SUBJECT. */ static public final String SUBJECT = "subjectCsid"; + static public final String SUBJECT_QP = "sbj"; + /** The Constant PREDICATE. */ static public final String PREDICATE = "predicate"; + static public final String PREDICATE_QP = "prd"; + /** The Constant OBJECT. */ static public final String OBJECT = "objectCsid"; - + static public final String OBJECT_QP = "obj"; /** * Gets the relationships for the entity corresponding to the CSID=csid. diff --git a/services/common/src/main/java/org/collectionspace/services/common/relation/RelationListItemJAXBSchema.java b/services/common/src/main/java/org/collectionspace/services/common/relation/RelationListItemJAXBSchema.java index db7fa908b..c90ed4bd3 100644 --- a/services/common/src/main/java/org/collectionspace/services/common/relation/RelationListItemJAXBSchema.java +++ b/services/common/src/main/java/org/collectionspace/services/common/relation/RelationListItemJAXBSchema.java @@ -38,6 +38,7 @@ public interface RelationListItemJAXBSchema { final static String CSID = "csid"; final static String SUBJECT_CSID = "subjectCsid"; + final static String RELATIONSHIP_TYPE = "relationshipType"; final static String OBJECT_CSID = "objectCsid"; /** The Constant URI. */ diff --git a/services/common/src/main/java/org/collectionspace/services/common/relation/nuxeo/RelationConstants.java b/services/common/src/main/java/org/collectionspace/services/common/relation/nuxeo/RelationConstants.java index 762a32f15..ef9982447 100644 --- a/services/common/src/main/java/org/collectionspace/services/common/relation/nuxeo/RelationConstants.java +++ b/services/common/src/main/java/org/collectionspace/services/common/relation/nuxeo/RelationConstants.java @@ -31,7 +31,6 @@ public class RelationConstants { 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"; } diff --git a/services/common/src/main/java/org/collectionspace/services/common/relation/nuxeo/RelationsUtils.java b/services/common/src/main/java/org/collectionspace/services/common/relation/nuxeo/RelationsUtils.java index af2cabd6c..311fc42e6 100644 --- a/services/common/src/main/java/org/collectionspace/services/common/relation/nuxeo/RelationsUtils.java +++ b/services/common/src/main/java/org/collectionspace/services/common/relation/nuxeo/RelationsUtils.java @@ -23,20 +23,11 @@ */ 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; @@ -48,210 +39,47 @@ 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 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 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; } } diff --git a/services/common/src/main/java/org/collectionspace/services/nuxeo/client/java/RemoteDocumentModelHandlerImpl.java b/services/common/src/main/java/org/collectionspace/services/nuxeo/client/java/RemoteDocumentModelHandlerImpl.java index 22eaa36b9..269f7cd82 100644 --- a/services/common/src/main/java/org/collectionspace/services/nuxeo/client/java/RemoteDocumentModelHandlerImpl.java +++ b/services/common/src/main/java/org/collectionspace/services/nuxeo/client/java/RemoteDocumentModelHandlerImpl.java @@ -44,9 +44,10 @@ import org.collectionspace.services.common.document.DocumentWrapper; 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; @@ -59,6 +60,8 @@ import org.w3c.dom.Document; * * $LastChangedRevision: $ * $LastChangedDate: $ + * @param + * @param */ public abstract class RemoteDocumentModelHandlerImpl extends DocumentModelHandler { diff --git a/services/common/src/main/java/org/collectionspace/services/nuxeo/client/java/RepositoryJavaClientImpl.java b/services/common/src/main/java/org/collectionspace/services/nuxeo/client/java/RepositoryJavaClientImpl.java index a87112159..68a2a92fc 100644 --- a/services/common/src/main/java/org/collectionspace/services/nuxeo/client/java/RepositoryJavaClientImpl.java +++ b/services/common/src/main/java/org/collectionspace/services/nuxeo/client/java/RepositoryJavaClientImpl.java @@ -33,6 +33,7 @@ import org.collectionspace.services.common.document.DocumentWrapper; 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; @@ -633,6 +634,10 @@ public class RepositoryJavaClientImpl implements RepositoryClient { 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)) { @@ -642,10 +647,6 @@ public class RepositoryJavaClientImpl implements RepositoryClient { 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 wrapDoc = new DocumentWrapperImpl(docList); @@ -856,7 +857,7 @@ public class RepositoryJavaClientImpl implements RepositoryClient { // // 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); // @@ -866,12 +867,12 @@ public class RepositoryJavaClientImpl implements RepositoryClient { 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"); } /** diff --git a/services/jaxb/src/main/resources/relations_common.xsd b/services/jaxb/src/main/resources/relations_common.xsd index 7c5a5f80e..e5f739d5b 100644 --- a/services/jaxb/src/main/resources/relations_common.xsd +++ b/services/jaxb/src/main/resources/relations_common.xsd @@ -24,12 +24,12 @@ - - - - + + + + - + @@ -71,6 +71,7 @@ + diff --git a/services/organization/service/src/main/java/org/collectionspace/services/organization/OrgAuthorityResource.java b/services/organization/service/src/main/java/org/collectionspace/services/organization/OrgAuthorityResource.java index d84bbacb7..a33800ad7 100644 --- a/services/organization/service/src/main/java/org/collectionspace/services/organization/OrgAuthorityResource.java +++ b/services/organization/service/src/main/java/org/collectionspace/services/organization/OrgAuthorityResource.java @@ -152,28 +152,6 @@ public class OrgAuthorityResource extends 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. * @@ -192,17 +170,7 @@ public class OrgAuthorityResource extends 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; } @@ -228,20 +196,6 @@ public class OrgAuthorityResource extends 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; } @@ -258,7 +212,6 @@ public class OrgAuthorityResource extends ServiceContext 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(); @@ -291,7 +244,6 @@ public class OrgAuthorityResource extends @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( @@ -442,7 +394,6 @@ public class OrgAuthorityResource extends @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( @@ -620,11 +571,13 @@ public class OrgAuthorityResource extends 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") @@ -658,6 +611,7 @@ public class OrgAuthorityResource extends /** * Gets the organization. + * @param parentcsid * * @param csid The organization authority (parent) CSID. * @param itemcsid The organization item CSID. @@ -725,9 +679,11 @@ public class OrgAuthorityResource extends /** * 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. */ @@ -799,7 +755,7 @@ public class OrgAuthorityResource extends 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(); @@ -860,7 +816,7 @@ public class OrgAuthorityResource extends OrganizationJAXBSchema.DISPLAY_NAME + " LIKE " + "'%" + partialTerm + "%'"; - myFilter.appendWhereClause(ptClause); + myFilter.appendWhereClause(ptClause, IQueryManager.SEARCH_QUALIFIER_AND); } getRepositoryClient(ctx).getFiltered(ctx, handler); personObjectList = (OrganizationsCommonList) handler.getCommonPartList(); @@ -1000,6 +956,10 @@ public class OrgAuthorityResource extends /************************************************************************* * 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") @@ -1064,11 +1024,12 @@ public class OrgAuthorityResource extends 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) { diff --git a/services/person/service/src/main/java/org/collectionspace/services/person/PersonAuthorityResource.java b/services/person/service/src/main/java/org/collectionspace/services/person/PersonAuthorityResource.java index c177be729..3ddc1b10b 100644 --- a/services/person/service/src/main/java/org/collectionspace/services/person/PersonAuthorityResource.java +++ b/services/person/service/src/main/java/org/collectionspace/services/person/PersonAuthorityResource.java @@ -47,14 +47,9 @@ import org.collectionspace.services.common.AbstractMultiPartCollectionSpaceResou 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; @@ -62,19 +57,20 @@ import org.collectionspace.services.common.document.DocumentWrapper; 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; @@ -150,18 +146,6 @@ public class PersonAuthorityResource extends return contactResource.getServiceName(); } -// @Override -// public DocumentHandler createDocumentHandler(ServiceContext 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. * @@ -202,20 +186,6 @@ public class PersonAuthorityResource extends 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; } @@ -265,7 +235,6 @@ public class PersonAuthorityResource extends @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( @@ -337,73 +306,73 @@ public class PersonAuthorityResource extends @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 queryParams = ui.getQueryParameters(); - // Note that we have to create the service context for the Items, not the main service - ServiceContext ctx = createServiceContext(getItemServiceName(), - queryParams); - DocumentHandler handler = createItemDocumentHandler(ctx, parentcsid); - RepositoryClient repoClient = getRepositoryClient(ctx); - DocumentFilter myFilter = handler.getDocumentFilter(); - String serviceType = ServiceBindingUtils.SERVICE_TYPE_PROCEDURE; - List list = queryParams.remove(ServiceBindingUtils.SERVICE_TYPE_PROP); - if (list != null) { - serviceType = list.get(0); - } - DocumentWrapper 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 queryParams = ui.getQueryParameters(); + // Note that we have to create the service context for the Items, not the main service + ServiceContext ctx = createServiceContext(getItemServiceName(), + queryParams); + DocumentHandler handler = createItemDocumentHandler(ctx, parentcsid); + RepositoryClient repoClient = getRepositoryClient(ctx); + DocumentFilter myFilter = handler.getDocumentFilter(); + String serviceType = ServiceBindingUtils.SERVICE_TYPE_PROCEDURE; + List list = queryParams.remove(ServiceBindingUtils.SERVICE_TYPE_PROP); + if (list != null) { + serviceType = list.get(0); + } + DocumentWrapper 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 @@ -722,7 +691,7 @@ public class PersonAuthorityResource extends 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(); @@ -783,7 +752,7 @@ public class PersonAuthorityResource extends 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(); @@ -1069,8 +1038,8 @@ public class PersonAuthorityResource extends .type("text/plain").build(); throw new WebApplicationException(response); } + return result; - } /** diff --git a/services/relation/client/src/test/java/org/collectionspace/services/client/test/RelationServiceTest.java b/services/relation/client/src/test/java/org/collectionspace/services/client/test/RelationServiceTest.java index 09b34a2ec..8f82cc420 100644 --- a/services/relation/client/src/test/java/org/collectionspace/services/client/test/RelationServiceTest.java +++ b/services/relation/client/src/test/java/org/collectionspace/services/client/test/RelationServiceTest.java @@ -22,7 +22,6 @@ */ 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; @@ -40,7 +39,6 @@ import org.jboss.resteasy.plugins.providers.multipart.MultipartInput; 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; @@ -65,9 +63,6 @@ public class RelationServiceTest extends AbstractServiceTestImpl { /** The known resource id. */ private String knownResourceId = null; - /** The all resource ids created. */ - private List allResourceIdsCreated = new ArrayList(); - /* (non-Javadoc) * @see org.collectionspace.services.client.test.BaseServiceTest#getClientInstance() */ @@ -316,19 +311,6 @@ public class RelationServiceTest extends AbstractServiceTestImpl { 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 @@ -686,38 +668,6 @@ public class RelationServiceTest extends AbstractServiceTestImpl { " 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 res = client.delete(resourceId); - } } // --------------------------------------------------------------- diff --git a/services/relation/service/src/main/java/org/collectionspace/services/relation/NewRelationResource.java b/services/relation/service/src/main/java/org/collectionspace/services/relation/NewRelationResource.java index b57cdea49..175d52407 100644 --- a/services/relation/service/src/main/java/org/collectionspace/services/relation/NewRelationResource.java +++ b/services/relation/service/src/main/java/org/collectionspace/services/relation/NewRelationResource.java @@ -26,8 +26,6 @@ */ package org.collectionspace.services.relation; -import java.util.Map; - import javax.ws.rs.Consumes; import javax.ws.rs.GET; import javax.ws.rs.Path; @@ -43,10 +41,10 @@ import javax.ws.rs.core.Response; 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; @@ -98,23 +96,6 @@ public class NewRelationResource extends public Class getCommonPartClass() { return RelationsCommon.class; } - - /* (non-Javadoc) - * @see org.collectionspace.services.common.AbstractCollectionSpaceResource#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(), RelationsCommon.class); -// if (obj != null) { -// docHandler.setCommonPart((RelationsCommon) obj); -// } -// } -// return docHandler; -// } /** * Creates the relation. @@ -517,20 +498,15 @@ public class NewRelationResource extends RelationsCommonList relationList = new RelationsCommonList(); try { ServiceContext ctx = createServiceContext(queryParams); - DocumentHandler handler = createDocumentHandler(ctx); - Map 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()) { @@ -541,6 +517,7 @@ public class NewRelationResource extends "Index failed").type("text/plain").build(); throw new WebApplicationException(response); } + return relationList; } } diff --git a/services/relation/service/src/main/java/org/collectionspace/services/relation/nuxeo/RelationDocumentModelHandler.java b/services/relation/service/src/main/java/org/collectionspace/services/relation/nuxeo/RelationDocumentModelHandler.java index 9f4f631b4..dafee9181 100644 --- a/services/relation/service/src/main/java/org/collectionspace/services/relation/nuxeo/RelationDocumentModelHandler.java +++ b/services/relation/service/src/main/java/org/collectionspace/services/relation/nuxeo/RelationDocumentModelHandler.java @@ -25,19 +25,19 @@ package org.collectionspace.services.relation.nuxeo; 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; @@ -68,7 +68,7 @@ public class RelationDocumentModelHandler /** * getCommonObject get associated Relation - * @return + * @return relation */ @Override public RelationsCommon getCommonPart() { @@ -80,13 +80,13 @@ public class RelationDocumentModelHandler * @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() { @@ -97,8 +97,8 @@ public class RelationDocumentModelHandler * @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) @@ -114,7 +114,7 @@ public class RelationDocumentModelHandler * @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 wrapDoc) throws Exception { + public void fillCommonPart(RelationsCommon theRelation, DocumentWrapper wrapDoc) throws Exception { throw new UnsupportedOperationException(); } @@ -123,24 +123,14 @@ public class RelationDocumentModelHandler */ @Override public RelationsCommonList extractCommonPartList(DocumentWrapper 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 itemList = relList.getRelationListItem(); Iterator 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; } @@ -153,24 +143,43 @@ public class RelationDocumentModelHandler @Override public void fillAllParts(DocumentWrapper 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 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 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) */ diff --git a/services/vocabulary/service/src/main/java/org/collectionspace/services/vocabulary/VocabularyResource.java b/services/vocabulary/service/src/main/java/org/collectionspace/services/vocabulary/VocabularyResource.java index 5b8a12830..a84d06b20 100644 --- a/services/vocabulary/service/src/main/java/org/collectionspace/services/vocabulary/VocabularyResource.java +++ b/services/vocabulary/service/src/main/java/org/collectionspace/services/vocabulary/VocabularyResource.java @@ -43,8 +43,6 @@ import org.collectionspace.services.VocabularyItemJAXBSchema; 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; @@ -121,32 +119,6 @@ public class VocabularyResource extends 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. @@ -214,7 +186,7 @@ public class VocabularyResource extends @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( @@ -398,6 +370,9 @@ public class VocabularyResource extends /************************************************************************* * VocabularyItem parts - this is a sub-resource of Vocabulary + * @param parentcsid + * @param input + * @return vocab item response *************************************************************************/ @POST @Path("{csid}/items") @@ -530,12 +505,11 @@ public class VocabularyResource extends // 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()) { -- 2.47.3