From: Richard Millet Date: Sun, 9 Aug 2009 02:12:42 +0000 (+0000) Subject: CSPACE-332: Added remaining URL paths for symmetry. X-Git-Url: https://git.aero2k.de/?a=commitdiff_plain;h=42cfa5b9628e6ec5ffcec72c0018a004106f03ea;p=tmp%2Fjakarta-migration.git CSPACE-332: Added remaining URL paths for symmetry. --- diff --git a/services/common/src/main/java/org/collectionspace/services/common/relation/RelationUtils.java b/services/common/src/main/java/org/collectionspace/services/common/relation/RelationUtils.java index 1148a3aa4..25e0015c6 100644 --- a/services/common/src/main/java/org/collectionspace/services/common/relation/RelationUtils.java +++ b/services/common/src/main/java/org/collectionspace/services/common/relation/RelationUtils.java @@ -32,6 +32,7 @@ import java.util.List; import org.collectionspace.services.common.repository.DocumentException; import org.collectionspace.services.relation.Relation; import org.dom4j.Document; +import org.nuxeo.ecm.core.api.DocumentModel; /** * The Interface RelationUtils. @@ -105,4 +106,21 @@ public interface RelationUtils { * @return the q property name */ public String getQPropertyName(String propertyName); + + /** + * Checks if is query match. + * + * @param documentModel the document model + * @param subjectCsid the subject csid + * @param predicate the predicate + * @param objectCsid the object csid + * + * @return true, if is query match + * + * @throws DocumentException the document exception + */ + public boolean isQueryMatch(DocumentModel documentModel, + String subjectCsid, + String predicate, + String objectCsid) throws DocumentException; } \ No newline at end of file diff --git a/services/common/src/main/java/org/collectionspace/services/common/relation/RelationsManager.java b/services/common/src/main/java/org/collectionspace/services/common/relation/RelationsManager.java index 0a944c9c2..242627ef3 100644 --- a/services/common/src/main/java/org/collectionspace/services/common/relation/RelationsManager.java +++ b/services/common/src/main/java/org/collectionspace/services/common/relation/RelationsManager.java @@ -35,12 +35,22 @@ import org.collectionspace.services.relation.Relation; import org.collectionspace.services.common.relation.RelationUtils; import org.dom4j.Document; +import org.nuxeo.ecm.core.api.DocumentModel; /** * The Class RelationsManager. */ public class RelationsManager { + /** The Constant SUBJECT. */ + static public final String SUBJECT = "subjectCsid"; + + /** The Constant PREDICATE. */ + static public final String PREDICATE = "predicate"; + + /** The Constant OBJECT. */ + static public final String OBJECT = "objectCsid"; + /** The relation utils. */ static private RelationUtils relationUtils = new RelationUtilsNuxeoImpl(); @@ -120,5 +130,24 @@ public class RelationsManager { static public String getQPropertyName(String propertyName) { return relationUtils.getQPropertyName(propertyName); } + + /** + * Checks if is query match. + * + * @param documentModel the document model + * @param subjectCsid the subject csid + * @param predicate the predicate + * @param objectCsid the object csid + * + * @return true, if is query match + * + * @throws DocumentException the document exception + */ + static public boolean isQueryMatch(DocumentModel documentModel, + String subjectCsid, String predicate, String objectCsid) + throws DocumentException { + return relationUtils.isQueryMatch(documentModel, subjectCsid, + predicate, objectCsid); + } } diff --git a/services/common/src/main/java/org/collectionspace/services/common/relation/nuxeo/RelationUtilsNuxeoImpl.java b/services/common/src/main/java/org/collectionspace/services/common/relation/nuxeo/RelationUtilsNuxeoImpl.java index eb963480f..d7ef70b3c 100644 --- a/services/common/src/main/java/org/collectionspace/services/common/relation/nuxeo/RelationUtilsNuxeoImpl.java +++ b/services/common/src/main/java/org/collectionspace/services/common/relation/nuxeo/RelationUtilsNuxeoImpl.java @@ -581,12 +581,13 @@ public class RelationUtilsNuxeoImpl implements RelationUtils { * * @throws ClientException the client exception */ - private boolean isQueryMatch(DocumentModel documentModel, + public boolean isQueryMatch(DocumentModel documentModel, String subjectCsid, String predicate, - String objectCsid) throws ClientException { + String objectCsid) throws DocumentException { boolean result = true; + try { block: { if (subjectCsid != null) { if (isSubjectOfRelation(subjectCsid, documentModel) == false) { @@ -607,6 +608,12 @@ public class RelationUtilsNuxeoImpl implements RelationUtils { } } } + } catch (ClientException e) { + if (logger.isDebugEnabled() == true) { + e.printStackTrace(); + } + throw new DocumentException(e); + } return result; } 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 f77645fb7..c4874470a 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 @@ -1,5 +1,33 @@ +/** + * NewRelationResource.java + * + * {Purpose of This Class} + * + * {Other Notes Relating to This Class (Optional)} + * + * $LastChangedBy: $ + * $LastChangedRevision: $ + * $LastChangedDate: $ + * + * This document is a part of the source code and related artifacts + * for CollectionSpace, an open source collections management system + * for museums and related institutions: + * + * http://www.collectionspace.org + * http://wiki.collectionspace.org + * + * Copyright © 2009 {Contributing Institution} + * + * Licensed under the Educational Community License (ECL), Version 2.0. + * You may not use this file except in compliance with this License. + * + * You may obtain a copy of the ECL 2.0 License at + * https://source.collectionspace.org/collection-space/LICENSE.txt + */ package org.collectionspace.services.relation; +import java.util.Map; + import javax.ws.rs.Consumes; import javax.ws.rs.GET; import javax.ws.rs.Path; @@ -22,6 +50,7 @@ import org.collectionspace.services.relation.nuxeo.RelationNuxeoConstants; import org.collectionspace.services.relation.nuxeo.RelationHandlerFactory; import org.collectionspace.services.common.NuxeoClientType; import org.collectionspace.services.common.ServiceMain; +import org.collectionspace.services.common.relation.RelationsManager; import org.collectionspace.services.common.repository.DocumentNotFoundException; import org.collectionspace.services.common.repository.DocumentHandler; import org.collectionspace.services.common.repository.RepositoryClient; @@ -35,209 +64,334 @@ import org.slf4j.LoggerFactory; @Produces("application/xml") public class NewRelationResource { - public final static String SERVICE_NAME = "relations"; - final Logger logger = LoggerFactory.getLogger(NewRelationResource.class); - //FIXME retrieve client type from configuration - final static NuxeoClientType CLIENT_TYPE = ServiceMain.getInstance().getNuxeoClientType(); - - public NewRelationResource() { - // do nothing - } - - @POST - public Response createRelation( - Relation relation) { - - String csid = null; - try{ - RepositoryClientFactory clientFactory = RepositoryClientFactory.getInstance(); - RepositoryClient client = clientFactory.getClient(CLIENT_TYPE.toString()); - RelationHandlerFactory handlerFactory = RelationHandlerFactory.getInstance(); - DocumentHandler handler = (DocumentHandler) handlerFactory.getHandler(CLIENT_TYPE.toString()); - handler.setCommonObject(relation); - csid = client.create(SERVICE_NAME, handler); - relation.setCsid(csid); - if(logger.isDebugEnabled()){ - verbose("createRelation: ", relation); - } - UriBuilder path = UriBuilder.fromResource(RelationResource.class); - path.path("" + csid); - Response response = Response.created(path.build()).build(); - return response; - }catch(Exception e){ - if(logger.isDebugEnabled()){ - logger.debug("Caught exception in createRelation", e); - } - Response response = Response.status( - Response.Status.INTERNAL_SERVER_ERROR).entity("Create failed").type("text/plain").build(); - throw new WebApplicationException(response); - } - } - - @GET - @Path("{csid}") - public Relation getRelation( - @PathParam("csid") String csid) { - if(logger.isDebugEnabled()){ - verbose("getRelation with csid=" + csid); - } - if(csid == null || "".equals(csid)){ - logger.error("getRelation: missing csid!"); - Response response = Response.status(Response.Status.BAD_REQUEST).entity( - "get failed on Relation csid=" + csid).type( - "text/plain").build(); - throw new WebApplicationException(response); - } - Relation relation = null; - try{ - RepositoryClientFactory clientFactory = RepositoryClientFactory.getInstance(); - RepositoryClient client = clientFactory.getClient(CLIENT_TYPE.toString()); - RelationHandlerFactory handlerFactory = RelationHandlerFactory.getInstance(); - DocumentHandler handler = (DocumentHandler) handlerFactory.getHandler(CLIENT_TYPE.toString()); - client.get(csid, handler); - relation = (Relation) handler.getCommonObject(); - }catch(DocumentNotFoundException dnfe){ - if(logger.isDebugEnabled()){ - logger.debug("getRelation", dnfe); - } - Response response = Response.status(Response.Status.NOT_FOUND).entity( - "Get failed on Relation csid=" + csid).type( - "text/plain").build(); - throw new WebApplicationException(response); - }catch(Exception e){ - if(logger.isDebugEnabled()){ - logger.debug("getRelation", e); - } - Response response = Response.status( - Response.Status.INTERNAL_SERVER_ERROR).entity("Get failed").type("text/plain").build(); - throw new WebApplicationException(response); - } - - if(relation == null){ - Response response = Response.status(Response.Status.NOT_FOUND).entity( - "Get failed, the requested Relation CSID:" + csid + ": was not found.").type( - "text/plain").build(); - throw new WebApplicationException(response); - } - if(logger.isDebugEnabled()){ - verbose("getRelation: ", relation); - } - return relation; - } - - @GET - public RelationList getRelationList(@Context UriInfo ui) { - RelationList relationList = new RelationList(); - try{ - RepositoryClientFactory clientFactory = RepositoryClientFactory.getInstance(); - RepositoryClient client = clientFactory.getClient(CLIENT_TYPE.toString()); - RelationHandlerFactory handlerFactory = RelationHandlerFactory.getInstance(); - DocumentHandler handler = (DocumentHandler) handlerFactory.getHandler(CLIENT_TYPE.toString()); - client.getAll(SERVICE_NAME, handler); - relationList = (RelationList) handler.getCommonObjectList(); - }catch(Exception e){ - if(logger.isDebugEnabled()){ - logger.debug("Caught exception in getRelationList", e); - } - Response response = Response.status( - Response.Status.INTERNAL_SERVER_ERROR).entity("Index failed").type("text/plain").build(); - throw new WebApplicationException(response); - } - return relationList; - } - - @PUT - @Path("{csid}") - public Relation updateRelation( - @PathParam("csid") String csid, - Relation theUpdate) { - if(logger.isDebugEnabled()){ - verbose("updateRelation with csid=" + csid); - } - if(csid == null || "".equals(csid)){ - logger.error("updateRelation: missing csid!"); - Response response = Response.status(Response.Status.BAD_REQUEST).entity( - "update failed on Relation csid=" + csid).type( - "text/plain").build(); - throw new WebApplicationException(response); - } - if(logger.isDebugEnabled()){ - verbose("updateRelation with input: ", theUpdate); - } - try{ - RepositoryClientFactory clientFactory = RepositoryClientFactory.getInstance(); - RepositoryClient client = clientFactory.getClient(CLIENT_TYPE.toString()); - RelationHandlerFactory handlerFactory = RelationHandlerFactory.getInstance(); - DocumentHandler handler = (DocumentHandler) handlerFactory.getHandler(CLIENT_TYPE.toString()); - handler.setCommonObject(theUpdate); - client.update(csid, handler); - }catch(DocumentNotFoundException dnfe){ - if(logger.isDebugEnabled()){ - logger.debug("caugth exception in updateRelation", dnfe); - } - Response response = Response.status(Response.Status.NOT_FOUND).entity( - "Update failed on Relation csid=" + csid).type( - "text/plain").build(); - throw new WebApplicationException(response); - }catch(Exception e){ - Response response = Response.status( - Response.Status.INTERNAL_SERVER_ERROR).entity("Update failed").type("text/plain").build(); - throw new WebApplicationException(response); - } - return theUpdate; - } - - @DELETE - @Path("{csid}") - public Response deleteRelation(@PathParam("csid") String csid) { - - if(logger.isDebugEnabled()){ - verbose("deleteRelation with csid=" + csid); - } - if(csid == null || "".equals(csid)){ - logger.error("deleteRelation: missing csid!"); - Response response = Response.status(Response.Status.BAD_REQUEST).entity( - "delete failed on Relation csid=" + csid).type( - "text/plain").build(); - throw new WebApplicationException(response); - } - try{ - RepositoryClientFactory clientFactory = RepositoryClientFactory.getInstance(); - RepositoryClient client = clientFactory.getClient(CLIENT_TYPE.toString()); - client.delete(csid); - return Response.status(HttpResponseCodes.SC_OK).build(); - }catch(DocumentNotFoundException dnfe){ - if(logger.isDebugEnabled()){ - logger.debug("caught exception in deleteRelation", dnfe); - } - Response response = Response.status(Response.Status.NOT_FOUND).entity( - "Delete failed on Relation csid=" + csid).type( - "text/plain").build(); - throw new WebApplicationException(response); - }catch(Exception e){ - Response response = Response.status( - Response.Status.INTERNAL_SERVER_ERROR).entity("Delete failed").type("text/plain").build(); - throw new WebApplicationException(response); - } - - } - - private void verbose(String msg, Relation relation) { - try{ - verbose(msg); - JAXBContext jc = JAXBContext.newInstance( - Relation.class); - - Marshaller m = jc.createMarshaller(); - m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE); - m.marshal(relation, System.out); - }catch(Exception e){ - e.printStackTrace(); - } - - } - - private void verbose(String msg) { - System.out.println("RelationResource. " + msg); - } + public final static String SERVICE_NAME = "relations"; + final Logger logger = LoggerFactory.getLogger(NewRelationResource.class); + // FIXME retrieve client type from configuration + final static NuxeoClientType CLIENT_TYPE = ServiceMain.getInstance() + .getNuxeoClientType(); + + public NewRelationResource() { + // do nothing + } + + @POST + public Response createRelation(Relation relation) { + + String csid = null; + try { + RepositoryClientFactory clientFactory = RepositoryClientFactory + .getInstance(); + RepositoryClient client = clientFactory.getClient(CLIENT_TYPE + .toString()); + RelationHandlerFactory handlerFactory = RelationHandlerFactory + .getInstance(); + DocumentHandler handler = (DocumentHandler) handlerFactory + .getHandler(CLIENT_TYPE.toString()); + handler.setCommonObject(relation); + csid = client.create(SERVICE_NAME, handler); + relation.setCsid(csid); + if (logger.isDebugEnabled()) { + verbose("createRelation: ", relation); + } + UriBuilder path = UriBuilder.fromResource(RelationResource.class); + path.path("" + csid); + Response response = Response.created(path.build()).build(); + return response; + } catch (Exception e) { + if (logger.isDebugEnabled()) { + logger.debug("Caught exception in createRelation", e); + } + Response response = Response.status( + Response.Status.INTERNAL_SERVER_ERROR).entity( + "Create failed").type("text/plain").build(); + throw new WebApplicationException(response); + } + } + + @GET + @Path("{csid}") + public Relation getRelation(@PathParam("csid") String csid) { + if (logger.isDebugEnabled()) { + verbose("getRelation with csid=" + csid); + } + if (csid == null || "".equals(csid)) { + logger.error("getRelation: missing csid!"); + Response response = Response.status(Response.Status.BAD_REQUEST) + .entity("get failed on Relation csid=" + csid).type( + "text/plain").build(); + throw new WebApplicationException(response); + } + Relation relation = null; + try { + RepositoryClientFactory clientFactory = RepositoryClientFactory + .getInstance(); + RepositoryClient client = clientFactory.getClient(CLIENT_TYPE + .toString()); + RelationHandlerFactory handlerFactory = RelationHandlerFactory + .getInstance(); + DocumentHandler handler = (DocumentHandler) handlerFactory + .getHandler(CLIENT_TYPE.toString()); + client.get(csid, handler); + relation = (Relation) handler.getCommonObject(); + } catch (DocumentNotFoundException dnfe) { + if (logger.isDebugEnabled()) { + logger.debug("getRelation", dnfe); + } + Response response = Response.status(Response.Status.NOT_FOUND) + .entity("Get failed on Relation csid=" + csid).type( + "text/plain").build(); + throw new WebApplicationException(response); + } catch (Exception e) { + if (logger.isDebugEnabled()) { + logger.debug("getRelation", e); + } + Response response = Response.status( + Response.Status.INTERNAL_SERVER_ERROR).entity("Get failed") + .type("text/plain").build(); + throw new WebApplicationException(response); + } + + if (relation == null) { + Response response = Response.status(Response.Status.NOT_FOUND) + .entity( + "Get failed, the requested Relation CSID:" + csid + + ": was not found.").type("text/plain") + .build(); + throw new WebApplicationException(response); + } + if (logger.isDebugEnabled()) { + verbose("getRelation: ", relation); + } + return relation; + } + + /* + * BEGIN OF GET LIST + */ + + @GET + public RelationList getRelationList(@Context UriInfo ui) { + return this.getRelationListRequest(null, null, null); + } + + @GET + @Path("subject/{subjectCsid}") + public RelationList getRelationList_S(@Context UriInfo ui, + @PathParam("subjectCsid") String subjectCsid) { + return this.getRelationListRequest(subjectCsid, null, null); + } + + @GET + @Path("type/{predicate}") + public RelationList getRelationList_P(@Context UriInfo ui, + @PathParam("predicate") String predicate) { + return this.getRelationListRequest(null, predicate, null); + } + + @GET + @Path("object/{objectCsid}") + public RelationList getRelationList_O(@Context UriInfo ui, + @PathParam("objectCsid") String objectCsid) { + return this.getRelationListRequest(null, null, objectCsid); + } + + @GET + @Path("type/{predicate}/subject/{subjectCsid}") + public RelationList getRelationList_PS(@Context UriInfo ui, + @PathParam("predicate") String predicate, + @PathParam("subjectCsid") String subjectCsid) { + return this.getRelationListRequest(subjectCsid, predicate, null); + } + + @GET + @Path("subject/{subjectCsid}/type/{predicate}") + public RelationList getRelationList_SP(@Context UriInfo ui, + @PathParam("subjectCsid") String subjectCsid, + @PathParam("predicate") String predicate) { + return this.getRelationListRequest(subjectCsid, predicate, null); + } + + @GET + @Path("type/{predicate}/object/{objectCsid}") + public RelationList getRelationList_PO(@Context UriInfo ui, + @PathParam("predicate") String predicate, + @PathParam("objectCsid") String objectCsid) { + return this.getRelationListRequest(null, predicate, objectCsid); + } + + @GET + @Path("object/{objectCsid}/type/{predicate}") + public RelationList getRelationList_OP(@Context UriInfo ui, + @PathParam("objectCsid") String objectCsid, + @PathParam("predicate") String predicate) { + return this.getRelationListRequest(null, predicate, objectCsid); + } + + @GET + @Path("type/{predicate}/subject/{subjectCsid}/object/{objectCsid}") + public RelationList getRelationList_PSO(@Context UriInfo ui, + @PathParam("predicate") String predicate, + @PathParam("subjectCsid") String subjectCsid, + @PathParam("objectCsid") String objectCsid) { + return this.getRelationListRequest(subjectCsid, predicate, objectCsid); + } + + @GET + @Path("subject/{subjectCsid}/type/{predicate}/object/{objectCsid}") + public RelationList getRelationList_SPO(@Context UriInfo ui, + @PathParam("subjectCsid") String subjectCsid, + @PathParam("predicate") String predicate, + @PathParam("objectCsid") String objectCsid) { + return this.getRelationListRequest(subjectCsid, predicate, objectCsid); + } + + /* + * END OF GET LIST + */ + + @PUT + @Path("{csid}") + public Relation updateRelation(@PathParam("csid") String csid, + Relation theUpdate) { + if (logger.isDebugEnabled()) { + verbose("updateRelation with csid=" + csid); + } + if (csid == null || "".equals(csid)) { + logger.error("updateRelation: missing csid!"); + Response response = Response.status(Response.Status.BAD_REQUEST) + .entity("update failed on Relation csid=" + csid).type( + "text/plain").build(); + throw new WebApplicationException(response); + } + if (logger.isDebugEnabled()) { + verbose("updateRelation with input: ", theUpdate); + } + try { + RepositoryClientFactory clientFactory = RepositoryClientFactory + .getInstance(); + RepositoryClient client = clientFactory.getClient(CLIENT_TYPE + .toString()); + RelationHandlerFactory handlerFactory = RelationHandlerFactory + .getInstance(); + DocumentHandler handler = (DocumentHandler) handlerFactory + .getHandler(CLIENT_TYPE.toString()); + handler.setCommonObject(theUpdate); + client.update(csid, handler); + } catch (DocumentNotFoundException dnfe) { + if (logger.isDebugEnabled()) { + logger.debug("caugth exception in updateRelation", dnfe); + } + Response response = Response.status(Response.Status.NOT_FOUND) + .entity("Update failed on Relation csid=" + csid).type( + "text/plain").build(); + throw new WebApplicationException(response); + } catch (Exception e) { + Response response = Response.status( + Response.Status.INTERNAL_SERVER_ERROR).entity( + "Update failed").type("text/plain").build(); + throw new WebApplicationException(response); + } + return theUpdate; + } + + @DELETE + @Path("{csid}") + public Response deleteRelation(@PathParam("csid") String csid) { + + if (logger.isDebugEnabled()) { + verbose("deleteRelation with csid=" + csid); + } + if (csid == null || "".equals(csid)) { + logger.error("deleteRelation: missing csid!"); + Response response = Response.status(Response.Status.BAD_REQUEST) + .entity("delete failed on Relation csid=" + csid).type( + "text/plain").build(); + throw new WebApplicationException(response); + } + try { + RepositoryClientFactory clientFactory = RepositoryClientFactory + .getInstance(); + RepositoryClient client = clientFactory.getClient(CLIENT_TYPE + .toString()); + client.delete(csid); + return Response.status(HttpResponseCodes.SC_OK).build(); + } catch (DocumentNotFoundException dnfe) { + if (logger.isDebugEnabled()) { + logger.debug("caught exception in deleteRelation", dnfe); + } + Response response = Response.status(Response.Status.NOT_FOUND) + .entity("Delete failed on Relation csid=" + csid).type( + "text/plain").build(); + throw new WebApplicationException(response); + } catch (Exception e) { + Response response = Response.status( + Response.Status.INTERNAL_SERVER_ERROR).entity( + "Delete failed").type("text/plain").build(); + throw new WebApplicationException(response); + } + + } + + /* + * Private Methods + */ + + /** + * Gets the relation list request. + * + * @return the relation list request + * + * @throws WebApplicationException the web application exception + */ + private RelationList getRelationListRequest(String subjectCsid, + String predicate, + String objectCsid) + throws WebApplicationException { + RelationList relationList = new RelationList(); + try { + RepositoryClientFactory clientFactory = RepositoryClientFactory + .getInstance(); + RepositoryClient client = clientFactory.getClient(CLIENT_TYPE + .toString()); + RelationHandlerFactory handlerFactory = RelationHandlerFactory + .getInstance(); + DocumentHandler handler = (DocumentHandler) handlerFactory + .getHandler(CLIENT_TYPE.toString()); + + Map propsFromPath = handler.getProperties(); + propsFromPath.put(RelationsManager.SUBJECT, subjectCsid); + propsFromPath.put(RelationsManager.PREDICATE, predicate); + propsFromPath.put(RelationsManager.OBJECT, objectCsid); + + client.getAll(SERVICE_NAME, handler); + relationList = (RelationList) handler.getCommonObjectList(); + } catch (Exception e) { + if (logger.isDebugEnabled()) { + logger.debug("Caught exception in getRelationList", e); + } + Response response = Response.status( + Response.Status.INTERNAL_SERVER_ERROR).entity( + "Index failed").type("text/plain").build(); + throw new WebApplicationException(response); + } + return relationList; + } + + private void verbose(String msg, Relation relation) { + try { + verbose(msg); + JAXBContext jc = JAXBContext.newInstance(Relation.class); + + Marshaller m = jc.createMarshaller(); + m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE); + m.marshal(relation, System.out); + } catch (Exception e) { + e.printStackTrace(); + } + + } + + private void verbose(String msg) { + System.out.println("RelationResource. " + msg); + } } 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 0bb0abe59..c6b74c1a6 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,6 +25,8 @@ package org.collectionspace.services.relation.nuxeo; import java.util.Iterator; import java.util.List; +import java.util.Map; + import org.collectionspace.services.common.relation.RelationJAXBSchema; import org.collectionspace.services.common.relation.nuxeo.RelationUtilsNuxeoImpl; import org.collectionspace.services.common.relation.RelationsManager; @@ -122,6 +124,11 @@ public class RelationDocumentModelHandler public RelationList extractCommonObjectList(DocumentWrapper wrapDoc) throws Exception { DocumentModelList docList = (DocumentModelList) wrapDoc.getWrappedObject(); + Map propsFromResource = this.getProperties(); + String subjectCsid = (String)propsFromResource.get(RelationsManager.SUBJECT); + String predicate = (String)propsFromResource.get(RelationsManager.PREDICATE); + String objectCsid = (String)propsFromResource.get(RelationsManager.OBJECT); + RelationList coList = new RelationList(); List list = coList.getRelationListItem(); @@ -130,11 +137,13 @@ public class RelationDocumentModelHandler Iterator iter = docList.iterator(); while(iter.hasNext()){ DocumentModel docModel = iter.next(); - RelationListItem coListItem = new RelationListItem(); - - RelationUtilsNuxeoImpl.fillRelationListItemFromDocModel(coListItem, docModel); - - list.add(coListItem); + if (RelationsManager.isQueryMatch(docModel, subjectCsid, + predicate, objectCsid) == true) { + RelationListItem coListItem = new RelationListItem(); + RelationUtilsNuxeoImpl.fillRelationListItemFromDocModel( + coListItem, docModel); + list.add(coListItem); + } } return coList;