1 package org.collectionspace.services.nuxeo.elasticsearch.anthro;
6 import org.apache.commons.lang3.StringUtils;
7 import org.codehaus.jackson.node.ObjectNode;
8 import org.collectionspace.services.common.api.RefNameUtils;
9 import org.collectionspace.services.nuxeo.elasticsearch.DefaultESDocumentWriter;
10 import org.nuxeo.ecm.core.api.DocumentModel;
12 public class AnthroESDocumentWriter extends DefaultESDocumentWriter {
15 public ObjectNode getDenormValues(DocumentModel doc) {
16 ObjectNode denormValues = super.getDenormValues(doc);
17 String docType = doc.getType();
19 if (docType.startsWith("CollectionObject")) {
20 // Create a list of collection years from the field collection date structured date.
22 Map<String, Object> fieldCollectionDateGroup = (Map<String, Object>) doc.getProperty("collectionobjects_common", "fieldCollectionDateGroup");
24 denormValues.putArray("collectionYears").addAll(structDateToYearNodes(fieldCollectionDateGroup));
31 protected String computeTitle(DocumentModel doc) {
32 List<Map<String, Object>> objectNameGroups = (List<Map<String, Object>>) doc.getProperty("collectionobjects_common", "objectNameList");
33 String primaryObjectName = null;
35 if (objectNameGroups.size() > 0) {
36 Map<String, Object> primaryObjectNameGroup = objectNameGroups.get(0);
37 primaryObjectName = (String) primaryObjectNameGroup.get("objectName");
40 if (StringUtils.isNotEmpty(primaryObjectName)) {
41 return primaryObjectName;
44 List<Map<String, Object>> titleGroups = (List<Map<String, Object>>) doc.getProperty("collectionobjects_common", "titleGroupList");
45 String primaryTitle = null;
47 if (titleGroups.size() > 0) {
48 Map<String, Object> primaryTitleGroup = titleGroups.get(0);
49 primaryTitle = (String) primaryTitleGroup.get("title");
52 if (StringUtils.isNotEmpty(primaryTitle)) {
56 List<Map<String, Object>> taxonomicIdentGroups = (List<Map<String, Object>>) doc.getProperty("collectionobjects_naturalhistory_extension", "taxonomicIdentGroupList");
57 String primaryTaxon = null;
59 if (taxonomicIdentGroups.size() > 0) {
60 Map<String, Object> primaryTaxonomicIdentGroup = taxonomicIdentGroups.get(0);
61 primaryTaxon = (String) primaryTaxonomicIdentGroup.get("taxon");
64 if (StringUtils.isNotEmpty(primaryTaxon)) {
65 primaryTaxon = RefNameUtils.getDisplayName(primaryTaxon);