From 61164cc4010e500a7c154f7fea0abfd0ac1c8e8c Mon Sep 17 00:00:00 2001 From: Michael Ritter Date: Wed, 22 Oct 2025 12:32:43 -0600 Subject: [PATCH] DRYD-1903: Query Relations in AdvancedSearch Service (#484) * Query relations in advanced search --- .../main/resources/advanced-search_common.xsd | 107 +++++++++--------- .../advancedsearch/AdvancedSearch.java | 12 +- .../common/relation/RelationResource.java | 5 +- 3 files changed, 66 insertions(+), 58 deletions(-) diff --git a/services/advancedsearch/jaxb/src/main/resources/advanced-search_common.xsd b/services/advancedsearch/jaxb/src/main/resources/advanced-search_common.xsd index 1613fd829..7e07e92db 100644 --- a/services/advancedsearch/jaxb/src/main/resources/advanced-search_common.xsd +++ b/services/advancedsearch/jaxb/src/main/resources/advanced-search_common.xsd @@ -11,62 +11,63 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/services/advancedsearch/service/src/main/java/org/collectionspace/services/advancedsearch/AdvancedSearch.java b/services/advancedsearch/service/src/main/java/org/collectionspace/services/advancedsearch/AdvancedSearch.java index f508de6c5..91856347b 100644 --- a/services/advancedsearch/service/src/main/java/org/collectionspace/services/advancedsearch/AdvancedSearch.java +++ b/services/advancedsearch/service/src/main/java/org/collectionspace/services/advancedsearch/AdvancedSearch.java @@ -2,7 +2,6 @@ package org.collectionspace.services.advancedsearch; import java.util.ArrayList; import java.util.Collections; -import java.util.HashMap; import java.util.List; import java.util.stream.Collectors; @@ -36,18 +35,17 @@ import org.collectionspace.services.common.AbstractCollectionSpaceResourceImpl; import org.collectionspace.services.common.UriInfoWrapper; import org.collectionspace.services.common.context.RemoteServiceContextFactory; import org.collectionspace.services.common.context.ServiceContextFactory; +import org.collectionspace.services.common.relation.RelationResource; import org.collectionspace.services.jaxb.AbstractCommonList; -import org.collectionspace.services.jaxb.AbstractCommonList.ListItem; -import org.collectionspace.services.jaxb.BlobJAXBSchema; import org.collectionspace.services.media.MediaResource; import org.collectionspace.services.nuxeo.client.handler.CSDocumentModelList; import org.collectionspace.services.nuxeo.client.handler.CSDocumentModelList.CSDocumentModelResponse; import org.collectionspace.services.nuxeo.client.handler.UnfilteredDocumentModelHandler; +import org.collectionspace.services.relation.RelationsCommonList; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.w3c.dom.Document; import org.w3c.dom.Element; -import org.w3c.dom.NodeList; /** * This class defines the advanced search endpoints. @@ -66,6 +64,7 @@ public class AdvancedSearch private final Logger logger = LoggerFactory.getLogger(AdvancedSearch.class); private final CollectionObjectResource cor = new CollectionObjectResource(); private final MediaResource mr = new MediaResource(); + private final RelationResource relations = new RelationResource(); public AdvancedSearch() { super(); @@ -83,6 +82,7 @@ public class AdvancedSearch logger.info("advancedsearch called with path: {}", uriInfo.getPath()); MultivaluedMap queryParams = uriInfo.getQueryParameters(true); logger.info("advancedsearch called with query params: {}", queryParams); + final String markRelated = queryParams.getFirst(IQueryManager.MARK_RELATED_TO_CSID_AS_SUBJECT); cor.setDocumentHandlerClass(UnfilteredDocumentModelHandler.class); ObjectFactory objectFactory = new ObjectFactory(); @@ -162,6 +162,10 @@ public class AdvancedSearch logger.warn("advancedsearch: could not find CollectionobjectsCommon associated with csid {}", csid); } + if (markRelated != null) { + RelationsCommonList relationsList = relations.getRelationForSubject(markRelated, csid, uriInfo); + listItem.setRelated(!relationsList.getRelationListItem().isEmpty()); + } } // NOTE: I think this is necessary for the front end to know what to do with diff --git a/services/common/src/main/java/org/collectionspace/services/common/relation/RelationResource.java b/services/common/src/main/java/org/collectionspace/services/common/relation/RelationResource.java index 503b0826e..a371832d3 100644 --- a/services/common/src/main/java/org/collectionspace/services/common/relation/RelationResource.java +++ b/services/common/src/main/java/org/collectionspace/services/common/relation/RelationResource.java @@ -108,6 +108,9 @@ public class RelationResource extends NuxeoBasedResource { return resultList; } + public RelationsCommonList getRelationForSubject(String subject, String object, UriInfo uriInfo) { + return getRelationList(null, uriInfo, subject, null, null, object, null, false); + } private RelationsCommonList getRelationList( ServiceContext parentCtx, @@ -129,7 +132,7 @@ public class RelationResource extends NuxeoBasedResource { // // Handle keyword clause // - String keywords = uriInfo.getQueryParameters().getFirst(IQueryManager.SEARCH_TYPE_KEYWORDS_KW); + String keywords = uriInfo.getQueryParameters().getFirst(IQueryManager.SEARCH_TYPE_KEYWORDS_KW); if (keywords != null && keywords.isEmpty() == false) { String keywordClause = QueryManager.createWhereClauseFromKeywords(keywords); handler.getDocumentFilter().appendWhereClause(keywordClause, IQueryManager.SEARCH_QUALIFIER_AND); -- 2.47.3