From: Ray Lee Date: Sat, 6 Apr 2019 00:31:34 +0000 (-0400) Subject: NOJIRA: Generate holdingInstitution field in ES index for Material Order. X-Git-Url: https://git.aero2k.de/?a=commitdiff_plain;h=cf57b0b27b96ddf714d514693c9f5b00c830320a;p=tmp%2Fjakarta-migration.git NOJIRA: Generate holdingInstitution field in ES index for Material Order. --- diff --git a/3rdparty/nuxeo/nuxeo-platform-elasticsearch/src/main/java/org/collectionspace/services/nuxeo/elasticsearch/CSJsonESDocumentWriter.java b/3rdparty/nuxeo/nuxeo-platform-elasticsearch/src/main/java/org/collectionspace/services/nuxeo/elasticsearch/CSJsonESDocumentWriter.java index 3862e6f08..f32464b3f 100644 --- a/3rdparty/nuxeo/nuxeo-platform-elasticsearch/src/main/java/org/collectionspace/services/nuxeo/elasticsearch/CSJsonESDocumentWriter.java +++ b/3rdparty/nuxeo/nuxeo-platform-elasticsearch/src/main/java/org/collectionspace/services/nuxeo/elasticsearch/CSJsonESDocumentWriter.java @@ -2,9 +2,12 @@ package org.collectionspace.services.nuxeo.elasticsearch; import java.io.IOException; import java.util.ArrayList; +import java.util.Collection; +import java.util.HashSet; import java.util.Iterator; import java.util.List; import java.util.Map; +import java.util.Set; import javax.ws.rs.core.HttpHeaders; @@ -62,7 +65,7 @@ public class CSJsonESDocumentWriter extends JsonESDocumentWriter { if (isMediaPublished(mediaDoc)) { String mediaCsid = (String) mediaDoc.getName(); - + mediaCsids.add(new TextNode(mediaCsid)); } } @@ -79,7 +82,7 @@ public class CSJsonESDocumentWriter extends JsonESDocumentWriter { if (title != null) { denormValues.put("title", title); } - + List> termGroups = (List>) doc.getProperty("materials_common", "materialTermGroupList"); List commercialNames = findTermDisplayNamesWithFlag(termGroups, "commercial"); List commonNames = findTermDisplayNamesWithFlag(termGroups, "common"); @@ -94,6 +97,18 @@ public class CSJsonESDocumentWriter extends JsonESDocumentWriter { if (commonNames.size() > 0) { denormValues.putArray("commonNames").addAll(jsonNodes(commonNames)); } + + // Combine term creator organizations and term editor organizations into a holding + // institutions field. + + Set holdingInstitutions = new HashSet(); + + holdingInstitutions.addAll(getTermAttributionContributors(doc)); + holdingInstitutions.addAll(getTermAttributionEditors(doc)); + + if (holdingInstitutions.size() > 0) { + denormValues.putArray("holdingInstitutions").addAll(jsonNodes(holdingInstitutions)); + } } // Below is sample code for denormalizing fields from the computed current location (place @@ -238,10 +253,38 @@ public class CSJsonESDocumentWriter extends JsonESDocumentWriter { return termDisplayNames; } + private Set getTermAttributionContributors(DocumentModel doc) { + Set orgs = new HashSet(); + + List> groups = (List>) doc.getProperty("materials_common", "materialTermAttributionContributingGroupList"); + + for (Map group : groups) { + String org = (String) group.get("materialTermAttributionContributingOrganization"); + + orgs.add(org); + } + + return orgs; + } + + private Set getTermAttributionEditors(DocumentModel doc) { + Set orgs = new HashSet(); + + List> groups = (List>) doc.getProperty("materials_common", "materialTermAttributionEditingGroupList"); + + for (Map group : groups) { + String org = (String) group.get("materialTermAttributionEditingOrganization"); + + orgs.add(org); + } + + return orgs; + } + private boolean isMediaPublished(DocumentModel mediaDoc) { List publishToValues = (List) mediaDoc.getProperty("media_materials", "publishToList"); boolean isPublished = false; - + for (int i=0; i jsonNodes(List values) { + private List jsonNodes(Collection values) { List nodes = new ArrayList(); Iterator iterator = values.iterator(); diff --git a/services/common/src/main/cspace/config/services/tenants/materials/materials-tenant-bindings.delta.xml b/services/common/src/main/cspace/config/services/tenants/materials/materials-tenant-bindings.delta.xml index 812d8bb3a..8bdd9f990 100644 --- a/services/common/src/main/cspace/config/services/tenants/materials/materials-tenant-bindings.delta.xml +++ b/services/common/src/main/cspace/config/services/tenants/materials/materials-tenant-bindings.delta.xml @@ -125,6 +125,15 @@ "analyzer" : "fulltext", "include_in_all": "false" }, + "collectionspace_denorm:holdingInstitutions": { + "type": "string", + "fields": { + "displayName": { + "type": "string", + "analyzer": "refname_displayname_analyzer" + } + } + }, "collectionspace_core:createdAt": { "type": "date",