Add some more object record fields, and denormalize media alt text and some exhibition fields.
denormMediaRecords(session, csid, tenantId, denormValues);
denormAcquisitionRecords(session, csid, tenantId, denormValues);
+ denormExhibitionRecords(session, csid, tenantId, denormValues);
// Compute the title of the record for the public browser, and store it so that it can
// be used for sorting ES query results.
}
private void denormMediaRecords(CoreSession session, String csid, String tenantId, ObjectNode denormValues) {
- // Store the csids of media records that are related to this object.
+ // Store the csid and alt text of media records that are related to this object.
String relatedRecordQuery = String.format("SELECT * FROM Relation WHERE relations_common:subjectCsid = '%s' AND relations_common:objectDocumentType = 'Media' AND ecm:currentLifeCycleState = 'project' AND collectionspace_core:tenantId = '%s'", csid, tenantId);
DocumentModelList relationDocs = session.query(relatedRecordQuery);
List<JsonNode> mediaCsids = new ArrayList<JsonNode>();
+ List<JsonNode> mediaAltTexts = new ArrayList<JsonNode>();
if (relationDocs.size() > 0) {
Iterator<DocumentModel> iterator = relationDocs.iterator();
while (iterator.hasNext()) {
DocumentModel relationDoc = iterator.next();
String mediaCsid = (String) relationDoc.getProperty("relations_common", "objectCsid");
+ DocumentModel mediaDoc = getRecordByCsid(session, tenantId, "Media", mediaCsid);
- if (isMediaPublished(session, tenantId, mediaCsid)) {
+ if (isMediaPublished(mediaDoc)) {
mediaCsids.add(new TextNode(mediaCsid));
+
+ String altText = (String) mediaDoc.getProperty("media_common", "altText");
+
+ if (altText == null) {
+ altText = "";
+ }
+
+ mediaAltTexts.add(new TextNode(altText));
}
}
}
denormValues.putArray("mediaCsid").addAll(mediaCsids);
+ denormValues.putArray("mediaAltText").addAll(mediaAltTexts);
denormValues.put("hasMedia", mediaCsids.size() > 0);
}
denormValues.putArray("creditLine").addAll(creditLines);
}
+private void denormExhibitionRecords(CoreSession session, String csid, String tenantId, ObjectNode denormValues) {
+ // Store the title, general note, and curatorial note of exhibition records that are published, and related to this object.
+
+ String relatedRecordQuery = String.format("SELECT * FROM Relation WHERE relations_common:subjectCsid = '%s' AND relations_common:objectDocumentType = 'Exhibition' AND ecm:currentLifeCycleState = 'project' AND collectionspace_core:tenantId = '%s'", csid, tenantId);
+ DocumentModelList relationDocs = session.query(relatedRecordQuery);
+ List<JsonNode> exhibitions = new ArrayList<JsonNode>();
+
+ if (relationDocs.size() > 0) {
+ Iterator<DocumentModel> iterator = relationDocs.iterator();
+
+ while (iterator.hasNext()) {
+ DocumentModel relationDoc = iterator.next();
+ String exhibitionCsid = (String) relationDoc.getProperty("relations_common", "objectCsid");
+ DocumentModel exhibitionDoc = getRecordByCsid(session, tenantId, "Exhibition", exhibitionCsid);
+
+ if (exhibitionDoc != null && isExhibitionPublished(exhibitionDoc)) {
+ ObjectNode exhibitionNode = objectMapper.createObjectNode();
+
+ String title = (String) exhibitionDoc.getProperty("exhibitions_common", "title");
+ String generalNote = (String) exhibitionDoc.getProperty("exhibitions_common", "generalNote");
+ String curatorialNote = (String) exhibitionDoc.getProperty("exhibitions_common", "curatorialNote");
+
+ exhibitionNode.put("title", title);
+ exhibitionNode.put("generalNote", generalNote);
+ exhibitionNode.put("curatorialNote", curatorialNote);
+
+ exhibitions.add(exhibitionNode);
+ }
+ }
+ }
+
+ denormValues.putArray("exhibition").addAll(exhibitions);
+}
+
/**
* Compute a title for the public browser. This needs to be indexed in ES so that it can
* be used for sorting. (Even if it's just extracting the primary value.)
return primaryObjectName;
}
- private boolean isMediaPublished(CoreSession session, String tenantId, String mediaCsid) {
+ private boolean isPublished(DocumentModel doc, String publishedFieldPart, String publishedFieldName) {
boolean isPublished = false;
- DocumentModel mediaDoc = getRecordByCsid(session, tenantId, "Media", mediaCsid);
- if (mediaDoc != null) {
- List<String> publishToValues = (List<String>) mediaDoc.getProperty("media_common", "publishToList");
+ if (doc != null) {
+ List<String> publishToValues = (List<String>) doc.getProperty(publishedFieldPart, publishedFieldName);
if (publishToValues != null) {
for (int i=0; i<publishToValues.size(); i++) {
}
return isPublished;
+
+ }
+
+ private boolean isMediaPublished(DocumentModel mediaDoc) {
+ return isPublished(mediaDoc, "media_common", "publishToList");
+ }
+
+ private boolean isExhibitionPublished(DocumentModel exhibitionDoc) {
+ return isPublished(exhibitionDoc, "exhibitions_common", "publishToList");
}
private String getCreditLine(CoreSession session, String tenantId, String acquisitionCsid) {
String refName = (String) doc.getProperty("collectionspace_core", "refName");
if (StringUtils.isNotEmpty(refName)) {
- String escapedRefName = refName.replace("'", "\\'");
String tenantId = (String) doc.getProperty("collectionspace_core", "tenantId");
- String mediaQuery = String.format("SELECT * FROM Media WHERE media_common:coverage = '%s' AND ecm:currentLifeCycleState = 'project' AND collectionspace_core:tenantId = '%s' ORDER BY media_common:identificationNumber", escapedRefName, tenantId);
-
- DocumentModelList mediaDocs = session.query(mediaQuery);
- List<JsonNode> mediaCsids = new ArrayList<JsonNode>();
-
- if (mediaDocs.size() > 0) {
- Iterator<DocumentModel> iterator = mediaDocs.iterator();
-
- while (iterator.hasNext()) {
- DocumentModel mediaDoc = iterator.next();
- if (isMediaPublished(mediaDoc)) {
- String mediaCsid = (String) mediaDoc.getName();
-
- mediaCsids.add(new TextNode(mediaCsid));
- }
- }
- }
-
- denormValues.putArray("mediaCsid").addAll(mediaCsids);
+ denormMediaRecords(session, refName, tenantId, denormValues);
}
// Compute the title of the record for the public browser, and store it so that it can
return denormValues;
}
+ private void denormMediaRecords(CoreSession session, String refName, String tenantId, ObjectNode denormValues) {
+ // Store the csid and alt text of media records that are related to this object.
+
+ String escapedRefName = refName.replace("'", "\\'");
+ String mediaQuery = String.format("SELECT * FROM Media WHERE media_common:coverage = '%s' AND ecm:currentLifeCycleState = 'project' AND collectionspace_core:tenantId = '%s' ORDER BY media_common:identificationNumber", escapedRefName, tenantId);
+ DocumentModelList mediaDocs = session.query(mediaQuery);
+ List<JsonNode> mediaCsids = new ArrayList<JsonNode>();
+ List<JsonNode> mediaAltTexts = new ArrayList<JsonNode>();
+
+ if (mediaDocs.size() > 0) {
+ Iterator<DocumentModel> iterator = mediaDocs.iterator();
+
+ while (iterator.hasNext()) {
+ DocumentModel mediaDoc = iterator.next();
+
+ if (isMediaPublished(mediaDoc)) {
+ String mediaCsid = (String) mediaDoc.getName();
+
+ mediaCsids.add(new TextNode(mediaCsid));
+
+ String altText = (String) mediaDoc.getProperty("media_common", "altText");
+
+ if (altText == null) {
+ altText = "";
+ }
+
+ mediaAltTexts.add(new TextNode(altText));
+ }
+ }
+ }
+
+ denormValues.putArray("mediaCsid").addAll(mediaCsids);
+ denormValues.putArray("mediaAltText").addAll(mediaAltTexts);
+ }
+
+
/**
* Compute a title for the public browser. This needs to be indexed in ES so that it can
* be used for sorting. (Even if it's just extracting the primary value.)
// save does not hold up the save.
public static final String PREV_COVERAGE_KEY = "Reindex.PREV_COVERAGE";
+ public static final String PREV_ALT_TEXT_KEY = "Reindex.PREV_ALT_TEXT";
public static final String PREV_CREDIT_LINE_KEY = "Reindex.PREV_CREDIT_LINE";
public static final String PREV_PUBLISH_TO_KEY = "Reindex.PREV_PUBLISH_TO";
+ public static final String PREV_EXH_TITLE_KEY = "Reindex.PREV_EXH_TITLE";
+ public static final String PREV_EXH_GENERAL_NOTE_KEY = "Reindex.PREV_EXH_GENERAL_NOTE";
+ public static final String PREV_EXH_CURATORIAL_NOTE_KEY = "Reindex.PREV_EXH_CURATORIAL_NOTE";
+ public static final String PREV_EXH_PUBLISH_TO_KEY = "Reindex.PREV_EXH_PUBLISH_TO";
public static final String PREV_RELATED_COLLECTION_OBJECT_CSID_KEY = "Reindex.PREV_RELATED_COLLECTION_OBJECT_CSID";
public static final String ELASTICSEARCH_ENABLED_PROP = "elasticsearch.enabled";
docType.startsWith("Media")
|| docType.startsWith("Relation")
|| docType.startsWith("Acquisition")
+ || docType.startsWith("Exhibition")
) {
return true;
}
doc.hasSchema("media_materials") ? "media_materials" : "media_common",
"publishToList");
+ String prevAltText = (String) eventContext.getProperty(PREV_ALT_TEXT_KEY);
+ String altText = (String) doc.getProperty("media_common", "altText");
+
if (
!ListUtils.isEqualList(prevPublishTo, publishTo) ||
+ !StringUtils.equals(prevAltText, altText) ||
!StringUtils.equals(prevCoverage, coverage)
) {
if (!StringUtils.equals(prevCoverage, coverage)) {
reindexMaterial(doc.getRepositoryName(), coverage);
- if (!ListUtils.isEqualList(prevPublishTo, publishTo)) {
+ if (
+ !ListUtils.isEqualList(prevPublishTo, publishTo) ||
+ !StringUtils.equals(prevAltText, altText)
+ ) {
reindexRelatedCollectionObjects(doc);
}
}
reindexPrevRelatedCollectionObjects(eventContext);
}
}
+ else if (docType.startsWith("Exhibition")) {
+ if (eventName.equals(DocumentEventTypes.DOCUMENT_UPDATED)) {
+ String prevTitle = (String) eventContext.getProperty(PREV_EXH_TITLE_KEY);
+ String prevGeneralNote = (String) eventContext.getProperty(PREV_EXH_GENERAL_NOTE_KEY);
+ String prevCuratorialNote = (String) eventContext.getProperty(PREV_EXH_CURATORIAL_NOTE_KEY);
+ List<String> prevPublishTo = (List<String>) eventContext.getProperty(PREV_EXH_PUBLISH_TO_KEY);
+
+ String title = (String) doc.getProperty("exhibitions_common", "title");
+ String generalNote = (String) doc.getProperty("exhibitions_common", "generalNote");
+ String curatorialNote = (String) doc.getProperty("exhibitions_common", "curatorialNote");
+ List<String> publishTo = (List<String>) doc.getProperty("exhibitions_common", "publishToList");
+
+ if (
+ !ListUtils.isEqualList(prevPublishTo, publishTo) ||
+ !StringUtils.equals(prevTitle, title) ||
+ !StringUtils.equals(prevGeneralNote, generalNote) ||
+ !StringUtils.equals(prevCuratorialNote, curatorialNote)
+ ) {
+ reindexRelatedCollectionObjects(doc);
+ }
+ }
+ else if (eventName.equals(DocumentEventTypes.DOCUMENT_REMOVED)) {
+ reindexPrevRelatedCollectionObjects(eventContext);
+ }
+ }
else if (docType.startsWith("Relation")) {
if (
eventName.equals(DocumentEventTypes.DOCUMENT_CREATED)
String objectDocumentType = (String) doc.getProperty("relations_common", "objectDocumentType");
if (
- (subjectDocumentType.equals("Media") || subjectDocumentType.equals("Acquisition"))
+ (
+ subjectDocumentType.equals("Media") ||
+ subjectDocumentType.equals("Acquisition") ||
+ subjectDocumentType.equals("Exhibition")
+ )
&& objectDocumentType.equals("CollectionObject")
) {
String collectionObjectCsid = (String) doc.getProperty("relations_common", "objectCsid");
docType.startsWith("Media")
|| docType.startsWith("Relation")
|| docType.startsWith("Acquisition")
- ) {
+ || docType.startsWith("Exhibition")
+ ) {
return true;
}
}
// For core/all profiles:
// - When a media record is about to be updated, store the value of the publishToList
- // field.
+ // and altText fields.
+ // - When an exhibition record is about to be updated, store the value of the title,
+ // generalNote, and curatorialNote fields.
// For materials profile:
// - When a media record is about to be updated, store the value of the coverage field.
if (eventName.equals(DocumentEventTypes.BEFORE_DOC_UPDATE)) {
DocumentModel previousDoc = (DocumentModel) eventContext.getProperty(CoreEventConstants.PREVIOUS_DOCUMENT_MODEL);
String coverage = (String) previousDoc.getProperty("media_common", "coverage");
+ String altText = (String) previousDoc.getProperty("media_common", "altText");
// Materials profile had publishToList defined in a local extension schema before
// that field was added to the common schema.
previousDoc.hasSchema("media_materials") ? "media_materials" : "media_common",
"publishToList");
+ eventContext.setProperty(Reindex.PREV_ALT_TEXT_KEY, altText);
eventContext.setProperty(Reindex.PREV_COVERAGE_KEY, coverage);
eventContext.setProperty(Reindex.PREV_PUBLISH_TO_KEY, (Serializable) publishTo);
}
storePrevRelatedCollectionObjects(eventContext, doc);
}
}
+ else if (docType.startsWith("Exhibition")) {
+ if (eventName.equals(DocumentEventTypes.BEFORE_DOC_UPDATE)) {
+ DocumentModel previousDoc = (DocumentModel) eventContext.getProperty(CoreEventConstants.PREVIOUS_DOCUMENT_MODEL);
+ String title = (String) previousDoc.getProperty("exhibitions_common", "title");
+ String generalNote = (String) previousDoc.getProperty("exhibitions_common", "generalNote");
+ String curatorialNote = (String) previousDoc.getProperty("exhibitions_common", "curatorialNote");
+ List<String> publishTo = (List<String>) previousDoc.getProperty("exhibitions_common", "publishToList");
+
+ eventContext.setProperty(Reindex.PREV_EXH_TITLE_KEY, title);
+ eventContext.setProperty(Reindex.PREV_EXH_GENERAL_NOTE_KEY, generalNote);
+ eventContext.setProperty(Reindex.PREV_EXH_CURATORIAL_NOTE_KEY, curatorialNote);
+ eventContext.setProperty(Reindex.PREV_EXH_PUBLISH_TO_KEY, (Serializable) publishTo);
+ }
+ else if (eventName.equals(DocumentEventTypes.ABOUT_TO_REMOVE)) {
+ storePrevRelatedCollectionObjects(eventContext, doc);
+ }
+ }
else if (docType.startsWith("Relation")) {
if (eventName.equals(DocumentEventTypes.ABOUT_TO_REMOVE)) {
String subjectDocumentType = (String) doc.getProperty("relations_common", "subjectDocumentType");
String objectDocumentType = (String) doc.getProperty("relations_common", "objectDocumentType");
if (
- (subjectDocumentType.equals("Media") || subjectDocumentType.equals("Acquisition"))
+ (
+ subjectDocumentType.equals("Media") ||
+ subjectDocumentType.equals("Acquisition") ||
+ subjectDocumentType.equals("Exhibition")
+ )
&& objectDocumentType.equals("CollectionObject")
) {
String collectionObjectCsid = (String) doc.getProperty("relations_common", "objectCsid");
"collectionobjects_common:materialGroupList",
"collectionobjects_common:measuredPartGroupList",
"collectionobjects_common:numberOfObjects",
+ "collectionobjects_common:objectHistoryNote",
"collectionobjects_common:objectNameList",
"collectionobjects_common:objectNumber",
"collectionobjects_common:objectProductionDateGroupList",
"collectionobjects_common:objectProductionPlaceGroupList",
"collectionobjects_common:objectStatusList",
"collectionobjects_common:otherNumberList",
+ "collectionobjects_common:ownersContributionNote",
"collectionobjects_common:publishToList",
"collectionobjects_common:responsibleDepartments",
"collectionobjects_common:techniqueGroupList",
"collectionobjects_common:titleGroupList",
+ "collectionobjects_common:viewersContributionNote",
"collectionobjects_naturalhistory_extension:taxonomicIdentGroupList",
"collectionspace_core:*",
"collectionspace_denorm:*",
"collectionspace_denorm:hasMedia": {
"type": "boolean"
},
+ "collectionspace_denorm:mediaAltText": {
+ "type": "text",
+ "copy_to": "all_field"
+ },
"collectionspace_denorm:prodYears": {
"type": "integer"
},
"collectionspace_denorm:collectionYears": {
"type": "integer"
},
+ "collectionspace_denorm:exhibition": {
+ "type": "object",
+ "properties": {
+ "title": {
+ "type": "text",
+ "copy_to": "all_field"
+ },
+ "generalNote": {
+ "type": "text",
+ "copy_to": "all_field"
+ },
+ "curatorialNote": {
+ "type": "text",
+ "copy_to": "all_field"
+ }
+ }
+ },
"collectionobjects_common:objectNumber": {
"type": "keyword",
}
}
},
+ "collectionobjects_common:objectHistoryNote": {
+ "type": "text",
+ "copy_to": "all_field"
+ },
+ "collectionobjects_common:ownersContributionNote": {
+ "type": "text",
+ "copy_to": "all_field"
+ },
+ "collectionobjects_common:viewersContributionNote": {
+ "type": "text",
+ "copy_to": "all_field"
+ },
"media_common:blobCsid": {
"type": "keyword"
"collectionobjects_common:materialGroupList",
"collectionobjects_common:measuredPartGroupList",
"collectionobjects_common:numberOfObjects",
+ "collectionobjects_common:objectHistoryNote",
"collectionobjects_common:objectNameList",
"collectionobjects_common:objectNumber",
"collectionobjects_common:objectProductionDateGroupList",
"collectionobjects_common:objectProductionPlaceGroupList",
"collectionobjects_common:objectStatusList",
"collectionobjects_common:otherNumberList",
+ "collectionobjects_common:ownersContributionNote",
"collectionobjects_common:publishToList",
"collectionobjects_common:responsibleDepartments",
"collectionobjects_common:techniqueGroupList",
"collectionobjects_common:titleGroupList",
+ "collectionobjects_common:viewersContributionNote",
"collectionobjects_fineart:materialTechniqueDescription",
"collectionspace_core:*",
"collectionspace_denorm:*",
"collectionspace_denorm:hasMedia": {
"type": "boolean"
},
+ "collectionspace_denorm:mediaAltText": {
+ "type": "text",
+ "copy_to": "all_field"
+ },
"collectionspace_denorm:prodYears": {
"type": "integer"
},
+ "collectionspace_denorm:exhibition": {
+ "type": "object",
+ "properties": {
+ "title": {
+ "type": "text",
+ "copy_to": "all_field"
+ },
+ "generalNote": {
+ "type": "text",
+ "copy_to": "all_field"
+ },
+ "curatorialNote": {
+ "type": "text",
+ "copy_to": "all_field"
+ }
+ }
+ },
"collectionobjects_common:objectNumber": {
"type": "keyword",
}
}
},
+ "collectionobjects_common:objectHistoryNote": {
+ "type": "text",
+ "copy_to": "all_field"
+ },
+ "collectionobjects_common:ownersContributionNote": {
+ "type": "text",
+ "copy_to": "all_field"
+ },
+ "collectionobjects_common:viewersContributionNote": {
+ "type": "text",
+ "copy_to": "all_field"
+ },
"media_common:blobCsid": {
"type": "keyword"
"materials_common:rapidPrototypingProcesses",
"materials_common:additionalProcessGroupList",
"materials_common:processNote",
+ "collectionobjects_common:objectHistoryNote",
"collectionobjects_common:objectNumber",
"collectionobjects_common:objectStatusList",
"collectionobjects_common:publishToList",
"collectionobjects_common:materialGroupList",
"collectionobjects_common:otherNumberList",
+ "collectionobjects_common:ownersContributionNote",
"collectionobjects_common:collection",
"collectionobjects_common:computedCurrentLocation",
"collectionobjects_materials:materialContainerGroupList",
"collectionobjects_common:numberOfObjects",
"collectionobjects_common:briefDescriptions",
"collectionobjects_common:measuredPartGroupList",
+ "collectionobjects_common:viewersContributionNote",
"media_common:blobCsid",
"media_materials:publishToList"
]
}
}
},
+ "collectionspace_denorm:mediaAltText": {
+ "type": "text",
+ "copy_to": "all_field"
+ },
+ "collectionspace_denorm:exhibition": {
+ "type": "object",
+ "properties": {
+ "title": {
+ "type": "text",
+ "copy_to": "all_field"
+ },
+ "generalNote": {
+ "type": "text",
+ "copy_to": "all_field"
+ },
+ "curatorialNote": {
+ "type": "text",
+ "copy_to": "all_field"
+ }
+ }
+ },
"collectionspace_core:createdAt": {
"type": "date",
}
}
},
+ "collectionobjects_common:objectHistoryNote": {
+ "type": "text",
+ "copy_to": "all_field"
+ },
+ "collectionobjects_common:ownersContributionNote": {
+ "type": "text",
+ "copy_to": "all_field"
+ },
+ "collectionobjects_common:viewersContributionNote": {
+ "type": "text",
+ "copy_to": "all_field"
+ },
"media_materials:publishToList": {
"type": "keyword",
"collectionobjects_common:materialGroupList",
"collectionobjects_common:measuredPartGroupList",
"collectionobjects_common:numberOfObjects",
+ "collectionobjects_common:objectHistoryNote",
"collectionobjects_common:objectNameList",
"collectionobjects_common:objectNumber",
"collectionobjects_common:objectProductionDateGroupList",
"collectionobjects_common:objectProductionPlaceGroupList",
"collectionobjects_common:objectStatusList",
"collectionobjects_common:otherNumberList",
+ "collectionobjects_common:ownersContributionNote",
"collectionobjects_common:publishToList",
"collectionobjects_common:responsibleDepartments",
"collectionobjects_common:techniqueGroupList",
"collectionobjects_common:titleGroupList",
+ "collectionobjects_common:viewersContributionNote",
"collectionspace_core:*",
"collectionspace_denorm:*",
"ecm:currentLifeCycleState",
"collectionspace_denorm:hasMedia": {
"type": "boolean"
},
+ "collectionspace_denorm:mediaAltText": {
+ "type": "text",
+ "copy_to": "all_field"
+ },
"collectionspace_denorm:prodYears": {
"type": "integer"
},
+ "collectionspace_denorm:exhibition": {
+ "type": "object",
+ "properties": {
+ "title": {
+ "type": "text",
+ "copy_to": "all_field"
+ },
+ "generalNote": {
+ "type": "text",
+ "copy_to": "all_field"
+ },
+ "curatorialNote": {
+ "type": "text",
+ "copy_to": "all_field"
+ }
+ }
+ },
"collectionobjects_common:objectNumber": {
"type": "keyword",
}
}
},
+ "collectionobjects_common:objectHistoryNote": {
+ "type": "text",
+ "copy_to": "all_field"
+ },
+ "collectionobjects_common:ownersContributionNote": {
+ "type": "text",
+ "copy_to": "all_field"
+ },
+ "collectionobjects_common:viewersContributionNote": {
+ "type": "text",
+ "copy_to": "all_field"
+ },
"media_common:blobCsid": {
"type": "keyword"