]> git.aero2k.de Git - tmp/jakarta-migration.git/commitdiff
DRYD-1903: Query Relations in AdvancedSearch Service (#484)
authorMichael Ritter <mikejritter@users.noreply.github.com>
Wed, 22 Oct 2025 18:32:43 +0000 (12:32 -0600)
committerGitHub <noreply@github.com>
Wed, 22 Oct 2025 18:32:43 +0000 (12:32 -0600)
* Query relations in advanced search

services/advancedsearch/jaxb/src/main/resources/advanced-search_common.xsd
services/advancedsearch/service/src/main/java/org/collectionspace/services/advancedsearch/AdvancedSearch.java
services/common/src/main/java/org/collectionspace/services/common/relation/RelationResource.java

index 1613fd82907ee2549e55ae987bcc92c303bed874..7e07e92db2b0ace60a910ef57ae0ca1c707465ea 100644 (file)
 <xs:schema
   xmlns:xs="http://www.w3.org/2001/XMLSchema"
   xmlns:jaxb="http://java.sun.com/xml/ns/jaxb"
-  jaxb:version="2.0" elementFormDefault="unqualified"
+  jaxb:version="2.0"
   xmlns="http://collectionspace.org/services/advancedsearch"
   targetNamespace="http://collectionspace.org/services/advancedsearch"
   version="0.1"
 >
 
-       <xs:complexType name="abstractCommonList">
-       <xs:annotation>
-               <xs:appinfo>
-               <jaxb:class ref="org.collectionspace.services.jaxb.AbstractCommonList"/>
-               </xs:appinfo>
-       </xs:annotation>
-       </xs:complexType>
-  
-       <xs:complexType name="responsibleDepartment">
-               <xs:sequence>
-            <xs:element name="uri" type="xs:anyURI" minOccurs="1"/>
-            <xs:element name="csid" type="xs:string" minOccurs="1"/>
-            <xs:element name="refName" type="xs:string" minOccurs="1"/>
-            <xs:element name="name" type="xs:string" minOccurs="1"/>
-               </xs:sequence>
-       </xs:complexType>
-       <xs:complexType name="responsibleDepartmentsList">
-               <xs:sequence>
-            <xs:element name="responsibleDepartment" type="responsibleDepartment" minOccurs="0" maxOccurs="unbounded" />
-               </xs:sequence>
-       </xs:complexType>
-  
-    <xs:element name="advancedsearch-common-list">
-        <xs:complexType>
-            <xs:complexContent>
-                <xs:extension base="abstractCommonList">                    
-                    <xs:sequence>
-                         <xs:element name="advancedsearch-list-item" maxOccurs="unbounded">
-                            <xs:complexType>
-                                <xs:sequence>
-                                       <xs:element name="uri" type="xs:anyURI" minOccurs="1" />
-                                       <xs:element name="csid" type="xs:string" minOccurs="1" />
-                                       <xs:element name="refName" type="xs:string" minOccurs="1" />
-                                       <xs:element name="blobCsid" type="xs:string" minOccurs="1" />
-                                       <xs:element name="updatedAt" type="xs:dateTime" minOccurs="1" />
-                                       <xs:element name="objectId" type="xs:string" minOccurs="1" />
-                                       <xs:element name="objectNumber" type="xs:string" minOccurs="1" />
-                                       <xs:element name="objectName" type="xs:string" minOccurs="1" />
-                                       <xs:element name="title" type="xs:string" minOccurs="1" />
-                                       <xs:element name="computedCurrentLocation" type="xs:string" minOccurs="1" />
-                                       <xs:element name="responsibleDepartments" type="responsibleDepartmentsList" minOccurs="1" />
-                                       <xs:element name="responsibleDepartment" type="xs:string" minOccurs="1" />
-                                       <xs:element name="contentConcepts" type="xs:string" minOccurs="1" />
-                                       <xs:element name="briefDescription" type="xs:string" minOccurs="1" />
-                                </xs:sequence>
-                            </xs:complexType>
-                         </xs:element>
-                    </xs:sequence>
-                               </xs:extension>
-                       </xs:complexContent>
-               </xs:complexType>
-       </xs:element>
+  <xs:complexType name="abstractCommonList">
+    <xs:annotation>
+      <xs:appinfo>
+        <jaxb:class ref="org.collectionspace.services.jaxb.AbstractCommonList"/>
+      </xs:appinfo>
+    </xs:annotation>
+  </xs:complexType>
+
+  <xs:complexType name="responsibleDepartment">
+    <xs:sequence>
+      <xs:element name="uri" type="xs:anyURI"/>
+      <xs:element name="csid" type="xs:string"/>
+      <xs:element name="refName" type="xs:string"/>
+      <xs:element name="name" type="xs:string"/>
+    </xs:sequence>
+  </xs:complexType>
+  <xs:complexType name="responsibleDepartmentsList">
+    <xs:sequence>
+      <xs:element name="responsibleDepartment" type="responsibleDepartment" minOccurs="0" maxOccurs="unbounded"/>
+    </xs:sequence>
+  </xs:complexType>
+
+  <xs:element name="advancedsearch-common-list">
+    <xs:complexType>
+      <xs:complexContent>
+        <xs:extension base="abstractCommonList">
+          <xs:sequence>
+            <xs:element name="advancedsearch-list-item" maxOccurs="unbounded">
+              <xs:complexType>
+                <xs:sequence>
+                  <xs:element name="uri" type="xs:anyURI"/>
+                  <xs:element name="csid" type="xs:string"/>
+                  <xs:element name="related" type="xs:boolean" minOccurs="0"/>
+                  <xs:element name="refName" type="xs:string"/>
+                  <xs:element name="blobCsid" type="xs:string"/>
+                  <xs:element name="updatedAt" type="xs:dateTime"/>
+                  <xs:element name="objectId" type="xs:string"/>
+                  <xs:element name="objectNumber" type="xs:string"/>
+                  <xs:element name="objectName" type="xs:string"/>
+                  <xs:element name="title" type="xs:string"/>
+                  <xs:element name="computedCurrentLocation" type="xs:string"/>
+                  <xs:element name="responsibleDepartments" type="responsibleDepartmentsList"/>
+                  <xs:element name="responsibleDepartment" type="xs:string"/>
+                  <xs:element name="contentConcepts" type="xs:string"/>
+                  <xs:element name="briefDescription" type="xs:string"/>
+                </xs:sequence>
+              </xs:complexType>
+            </xs:element>
+          </xs:sequence>
+        </xs:extension>
+      </xs:complexContent>
+    </xs:complexType>
+  </xs:element>
 </xs:schema>
\ No newline at end of file
index f508de6c5e4a4b19829a0221b8d175123b12e240..91856347bcb944150bf5b111dd95d156e1f8bef6 100644 (file)
@@ -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<String, String> 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
index 503b0826ed923c9619c8eda423b5c3513ca94c80..a371832d3317feb7fc95f7c3bddf4bd47b4465ab 100644 (file)
@@ -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<PoxPayloadIn, PoxPayloadOut> 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);