]> git.aero2k.de Git - tmp/jakarta-migration.git/commitdiff
DRYD-1982: Add blobAltText to advanced search (#489)
authorMichael Ritter <mikejritter@users.noreply.github.com>
Thu, 11 Dec 2025 22:15:42 +0000 (15:15 -0700)
committerGitHub <noreply@github.com>
Thu, 11 Dec 2025 22:15:42 +0000 (15:15 -0700)
services/advancedsearch/jaxb/src/main/resources/advanced-search_common.xsd
services/advancedsearch/service/src/main/java/org/collectionspace/services/advancedsearch/AdvancedSearch.java
services/advancedsearch/service/src/main/java/org/collectionspace/services/advancedsearch/mapper/CollectionObjectMapper.java
services/media/jaxb/src/main/java/org/collectionspace/services/MediaJAXBSchema.java

index 2ba600497e7d267cf0ba67a99f95a1a52ac19c75..50fb31c202134406a213a1a25f1080e53eab5d7a 100644 (file)
             <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="uri" type="xs:anyURI" nillable="true"/>
+                  <xs:element name="csid" type="xs:string" nillable="true"/>
                   <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="objectNumber" type="xs:string"/>
-                  <xs:element name="title" type="xs:string"/>
-                  <xs:element name="computedCurrentLocation" type="xs:string"/>
-                  <xs:element name="responsibleDepartment" type="xs:string"/>
-                  <xs:element name="briefDescription" type="xs:string"/>
+                  <xs:element name="refName" type="xs:string" nillable="true"/>
+                  <xs:element name="updatedAt" type="xs:dateTime" nillable="true"/>
+                  <xs:element name="blobCsid" type="xs:string" nillable="true"/>
+                  <xs:element name="blobAltText" type="xs:string" nillable="true"/>
+                  <xs:element name="objectNumber" type="xs:string" nillable="true"/>
+                  <xs:element name="title" type="xs:string" nillable="true"/>
+                  <xs:element name="computedCurrentLocation" type="xs:string" nillable="true"/>
+                  <xs:element name="responsibleDepartment" type="xs:string" nillable="true"/>
+                  <xs:element name="briefDescription" type="xs:string" nillable="true"/>
 
-                  <xs:element name="objectName" type="xs:string"/>
-                  <xs:element name="objectNameControlled" type="xs:string"/>
-                  <xs:element name="taxon" type="xs:string"/>
-                  <xs:element name="form" type="xs:string"/>
-                  <xs:element name="agent" type="xs:string"/>
-                  <xs:element name="agentRole" type="xs:string"/>
-                  <xs:element name="fieldCollector" type="xs:string"/>
-                  <xs:element name="fieldCollectorRole" type="xs:string"/>
+                  <xs:element name="objectName" type="xs:string" nillable="true"/>
+                  <xs:element name="objectNameControlled" type="xs:string" nillable="true"/>
+                  <xs:element name="taxon" type="xs:string" nillable="true"/>
+                  <xs:element name="form" type="xs:string" nillable="true"/>
+                  <xs:element name="agent" type="xs:string" nillable="true"/>
+                  <xs:element name="agentRole" type="xs:string" nillable="true"/>
+                  <xs:element name="fieldCollector" type="xs:string" nillable="true"/>
+                  <xs:element name="fieldCollectorRole" type="xs:string" nillable="true"/>
 
-                  <xs:element name="fieldCollectionDate" type="xs:string"/>
-                  <xs:element name="fieldCollectionPlace" type="xs:string"/>
-                  <xs:element name="fieldCollectionSite" type="xs:string"/>
-                  <xs:element name="objectProductionDate" type="xs:string"/>
-                  <xs:element name="objectProductionPlace" type="xs:string"/>
+                  <xs:element name="fieldCollectionDate" type="xs:string" nillable="true"/>
+                  <xs:element name="fieldCollectionPlace" type="xs:string" nillable="true"/>
+                  <xs:element name="fieldCollectionSite" type="xs:string" nillable="true"/>
+                  <xs:element name="objectProductionDate" type="xs:string" nillable="true"/>
+                  <xs:element name="objectProductionPlace" type="xs:string" nillable="true"/>
 
-                  <xs:element name="contentConcepts" type="contentConcepts"/>
-                  <xs:element name="nagpraCategories" type="nagpraCategories"/>
+                  <xs:element name="contentConcepts" type="contentConcepts" nillable="true"/>
+                  <xs:element name="nagpraCategories" type="nagpraCategories" nillable="true"/>
                 </xs:sequence>
               </xs:complexType>
             </xs:element>
index 932487746ef87f875e5599d7e7da6e27f6d5cea8..b30045e08e22d60dd5b5f7ee6d1400536bace048 100644 (file)
@@ -1,7 +1,8 @@
 package org.collectionspace.services.advancedsearch;
 
 import java.util.Collections;
-import java.util.List;
+import java.util.Map;
+import java.util.function.Predicate;
 import java.util.stream.Collectors;
 import javax.ws.rs.Consumes;
 import javax.ws.rs.GET;
@@ -90,9 +91,9 @@ public class AdvancedSearch
                for (CSDocumentModelResponse response : collectionObjectList.getResponseList()) {
                        String csid = response.getCsid();
                        UriInfoWrapper wrappedUriInfo = new UriInfoWrapper(uriInfo);
-                       List<String> blobCsids = findBlobCsids(csid, wrappedUriInfo);
+                       Map<String, String> blobInfo = findBlobInfo(csid, wrappedUriInfo);
 
-                       AdvancedsearchListItem listItem = responseMapper.asListItem(response, blobCsids);
+                       AdvancedsearchListItem listItem = responseMapper.asListItem(response, blobInfo);
                        if (listItem != null) {
                                if (markRelated != null) {
                                        RelationsCommonList relationsList = relations.getRelationForSubject(markRelated, csid, uriInfo);
@@ -118,7 +119,7 @@ public class AdvancedSearch
         * @param wrappedUriInfo The wrapped (mutable) UriInfo of the incoming query that ultimately triggered this call
         * @return A possibly-empty list of strings of the blob CSIDs associated with CSID
         */
-       private List<String> findBlobCsids(String csid, UriInfoWrapper wrappedUriInfo) {
+       private Map<String, String> findBlobInfo(String csid, UriInfoWrapper wrappedUriInfo) {
                MultivaluedMap<String, String> wrappedQueryParams = wrappedUriInfo.getQueryParameters();
                wrappedQueryParams.clear();
                wrappedQueryParams.add(IQueryManager.SEARCH_RELATED_TO_CSID_AS_SUBJECT, csid);
@@ -127,16 +128,19 @@ public class AdvancedSearch
                wrappedQueryParams.add("sortBy", "media_common:title");
                AbstractCommonList associatedMedia = mr.getList(wrappedUriInfo);
                if (associatedMedia == null || associatedMedia.getListItem() == null) {
-                       return Collections.emptyList();
+                       return Collections.emptyMap();
                }
 
-               return associatedMedia.getListItem().stream()
+               Predicate<Element> tagFilter = (element -> MediaJAXBSchema.blobCsid.equals(element.getTagName()) ||
+                                                                                                  MediaJAXBSchema.altText.equals(element.getTagName()));
+               Predicate<Element> tagNotEmpty = (element -> element.getTextContent()  != null &&
+                                                                                                        !element.getTextContent().isEmpty());
+
+        return associatedMedia.getListItem().stream()
                        .filter(item -> item != null && item.getAny() != null)
                        .flatMap(li -> li.getAny().stream())
-                       .filter(element -> MediaJAXBSchema.blobCsid.equals(element.getTagName()))
-                       .map(Element::getTextContent)
-                       .filter(blobCsid -> blobCsid != null && !blobCsid.isEmpty())
-                       .collect(Collectors.toList());
+                       .filter(tagFilter.and(tagNotEmpty))
+                       .collect(Collectors.toMap(Element::getTagName, Element::getTextContent));
        }
 
        @Override
index 3b83c2751edce8e6c99a311374d66bbe3283d663..4dd3622e4c52da4abc84c24b5ea7e4b510fcd4f7 100644 (file)
@@ -6,10 +6,11 @@ import static org.collectionspace.services.client.CollectionSpaceClient.NATURALH
 import static org.collectionspace.services.client.CollectionSpaceClient.PART_COMMON_LABEL;
 import static org.collectionspace.services.client.CollectionSpaceClient.PART_LABEL_SEPARATOR;
 
-import java.util.List;
+import java.util.Map;
 import javax.xml.bind.JAXBException;
 import javax.xml.bind.Unmarshaller;
 import org.collectionspace.collectionspace_core.CollectionSpaceCore;
+import org.collectionspace.services.MediaJAXBSchema;
 import org.collectionspace.services.advancedsearch.AdvancedsearchCommonList.AdvancedsearchListItem;
 import org.collectionspace.services.advancedsearch.ObjectFactory;
 import org.collectionspace.services.advancedsearch.model.AgentModel;
@@ -71,7 +72,8 @@ public class CollectionObjectMapper {
      * @param blobCsids The blobs associated with the object
      * @return the advanced search list item
      */
-    public AdvancedsearchListItem asListItem(final CSDocumentModelResponse response, final List<String> blobCsids) {
+    public AdvancedsearchListItem asListItem(final CSDocumentModelResponse response,
+                                             final Map<String, String> blobInfo) {
         // todo: what makes sense here?
         if (response == null || response.getPayload() == null) {
             return objectFactory.createAdvancedsearchCommonListAdvancedsearchListItem();
@@ -139,8 +141,9 @@ public class CollectionObjectMapper {
             item.setForm(TaxonModel.preservationForm(collectionObject));
 
             // from media resource
-            if (blobCsids.size() > 0) {
-                item.setBlobCsid(blobCsids.get(0));
+            if (!blobInfo.isEmpty()) {
+                item.setBlobCsid(blobInfo.get(MediaJAXBSchema.blobCsid));
+                item.setBlobAltText(blobInfo.get(MediaJAXBSchema.altText));
             }
         } else {
             logger.warn("advancedsearch: could not find CollectionobjectsCommon associated with csid {}", csid);
index 0a41337ce584f6173f6f6d584130d19ea966a36d..c54bf7c688f8ca82666d7accdec15a339e3ec028 100644 (file)
@@ -1,30 +1,31 @@
-/**
- * 
- */
 package org.collectionspace.services;
 
+/**
+ * Field names for the Media Schema
+ */
 public interface MediaJAXBSchema {
-    final static String contributor = "contributor";
-    final static String copyrightStatement = "copyrightStatement";
-    final static String coverage = "coverage";
-    final static String creator = "creator";
-    final static String dates = "dates";
-    final static String dateCreated = "dateCreated";
-    final static String dateModified = "dateModified";
-    final static String description = "description";
-    final static String dimensions = "dimensions";
-    final static String filename = "filename";
-    final static String format = "format";
-    final static String identificationNumber = "identificationNumber";
-    final static String languages = "languages";
-    final static String location = "location";
-    final static String publisher = "publisher";
-    final static String relation = "relation";
-    final static String rightsHolder = "rightsHolder";
-    final static String source = "source";
-    final static String subjects = "subjects";
-    final static String title = "title";
-    final static String type = "type";
-    final static String uri = "uri";
-    final static String blobCsid = "blobCsid";
+    String altText = "altText";
+    String contributor = "contributor";
+    String copyrightStatement = "copyrightStatement";
+    String coverage = "coverage";
+    String creator = "creator";
+    String dates = "dates";
+    String dateCreated = "dateCreated";
+    String dateModified = "dateModified";
+    String description = "description";
+    String dimensions = "dimensions";
+    String filename = "filename";
+    String format = "format";
+    String identificationNumber = "identificationNumber";
+    String languages = "languages";
+    String location = "location";
+    String publisher = "publisher";
+    String relation = "relation";
+    String rightsHolder = "rightsHolder";
+    String source = "source";
+    String subjects = "subjects";
+    String title = "title";
+    String type = "type";
+    String uri = "uri";
+    String blobCsid = "blobCsid";
 }