Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ public class Reindex extends AbstractCSEventPostCommitListenerImpl {
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 PREV_RELATED_MEDIA_CSID_KEY = "Reindex.PREV_RELATED_MEDIA_CSID";
public static final String ELASTICSEARCH_ENABLED_PROP = "elasticsearch.enabled";

@Override
Expand Down Expand Up @@ -200,10 +201,27 @@ else if (docType.startsWith("Relation")) {
String collectionObjectCsid = (String) doc.getProperty("relations_common", "objectCsid");

reindexCollectionObject(doc.getRepositoryName(), collectionObjectCsid);

if (subjectDocumentType.equals("Media")) {
String mediaCsid = (String) doc.getProperty("relations_common", "subjectCsid");

reindexMedia(doc.getRepositoryName(), mediaCsid);
}
}
else if (
subjectDocumentType.equals("CollectionObject")
&& objectDocumentType.equals("Media")
) {
String collectionObjectCsid = (String) doc.getProperty("relations_common", "subjectCsid");
String mediaCsid = (String) doc.getProperty("relations_common", "objectCsid");

reindexCollectionObject(doc.getRepositoryName(), collectionObjectCsid);
reindexMedia(doc.getRepositoryName(), mediaCsid);
}
}
else if (eventName.equals(DocumentEventTypes.DOCUMENT_REMOVED)) {
reindexPrevRelatedCollectionObjects(eventContext);
reindexPrevRelatedMedia(eventContext);
}
}
}
Expand Down Expand Up @@ -261,6 +279,16 @@ private void reindexRelatedCollectionObjects(DocumentModel doc) {
}
}

private void reindexPrevRelatedMedia(DocumentEventContext eventContext) {
List<String> prevRelatedMediaCsids = (List<String>) eventContext.getProperty(PREV_RELATED_MEDIA_CSID_KEY);

if (prevRelatedMediaCsids != null) {
for (String prevRelatedMediaCsid : prevRelatedMediaCsids) {
reindexMedia(eventContext.getRepositoryName(), prevRelatedMediaCsid);
}
}
}

private void reindexCollectionObject(String repositoryName, String csid) {
if (StringUtils.isEmpty(csid)) {
return;
Expand All @@ -271,4 +299,15 @@ private void reindexCollectionObject(String repositoryName, String csid) {
ElasticSearchComponent es = (ElasticSearchComponent) Framework.getService(ElasticSearchService.class);
es.runReindexingWorker(repositoryName, query);
}

private void reindexMedia(String repositoryName, String csid) {
if (StringUtils.isEmpty(csid)) {
return;
}

String query = String.format("SELECT ecm:uuid FROM Media WHERE ecm:name = '%s'", csid);

ElasticSearchComponent es = (ElasticSearchComponent) Framework.getService(ElasticSearchService.class);
es.runReindexingWorker(repositoryName, query);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,22 @@ else if (docType.startsWith("Relation")) {
String collectionObjectCsid = (String) doc.getProperty("relations_common", "objectCsid");

eventContext.setProperty(Reindex.PREV_RELATED_COLLECTION_OBJECT_CSID_KEY, (Serializable) Arrays.asList(collectionObjectCsid));

if (subjectDocumentType.equals("Media")) {
String mediaCsid = (String) doc.getProperty("relations_common", "subjectCsid");

eventContext.setProperty(Reindex.PREV_RELATED_MEDIA_CSID_KEY, (Serializable) Arrays.asList(mediaCsid));
}
}
else if (
subjectDocumentType.equals("CollectionObject")
&& objectDocumentType.equals("Media")
) {
String collectionObjectCsid = (String) doc.getProperty("relations_common", "subjectCsid");
String mediaCsid = (String) doc.getProperty("relations_common", "objectCsid");

eventContext.setProperty(Reindex.PREV_RELATED_COLLECTION_OBJECT_CSID_KEY, (Serializable) Arrays.asList(collectionObjectCsid));
eventContext.setProperty(Reindex.PREV_RELATED_MEDIA_CSID_KEY, (Serializable) Arrays.asList(mediaCsid));
}
}
}
Expand Down
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
## 9.0.0
* Add home location to collectionobject schema and advanced search

### Bug Fixes

* Fix es indexing of Media records when relating/unrelating to Collection Objects

## 8.3.0

* Add new endpoint for returning search results
Expand Down