Skip to content

Commit

Permalink
feat/MET-6303-Implement-tombstone-deletion-in-Metis (#708)
Browse files Browse the repository at this point in the history
* MET-6303 Implemented tombstone deletion.

* MET-6303 Fix sonar issues

---------

Co-authored-by: marcin-rp <[email protected]>
  • Loading branch information
stzanakis and marcin-rp authored Dec 24, 2024
1 parent b0d0a17 commit 06454b1
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,45 @@ public boolean removeRecord(String rdfAbout) throws IndexerRelatedIndexingExcept
}
}

/**
* Removes the tombstone of the record with the given rdf:about value. Also removes any associated entities (i.e. those entities
* that are always part of only one record and the removal of which can not invalidate references from other records):
* <ul>
* <li>Aggregation</li>
* <li>EuropeanaAggregation</li>
* <li>ProvidedCHO</li>
* <li>Proxy (both provider and Europeana proxies)</li>
* </ul>
* However, entities that are potentially shared are not removed.
*
* @param rdfAbout The about value of the record to remove. Is not null.
* @return Whether the record was removed.
* @throws IndexerRelatedIndexingException In case something went wrong.
*/
public boolean removeTombstone(String rdfAbout) throws IndexerRelatedIndexingException {
try {
// Obtain the Mongo record
final Datastore datastore = tombstoneDao.getDatastore();
final FullBeanImpl recordToDelete = datastore.find(FullBeanImpl.class)
.filter(Filters.eq(ABOUT_FIELD, rdfAbout)).first();

// Remove mongo record and dependencies
if (recordToDelete != null) {
datastore.delete(recordToDelete);
recordToDelete.getAggregations().forEach(datastore::delete);
datastore.delete(recordToDelete.getEuropeanaAggregation());
recordToDelete.getProvidedCHOs().forEach(datastore::delete);
recordToDelete.getProxies().forEach(datastore::delete);
}

// Done
return recordToDelete != null;

} catch (RuntimeException e) {
throw new IndexerRelatedIndexingException("Could not remove tombstone '" + rdfAbout + "'.", e);
}
}

/**
* <p>Removes all records that belong to a given dataset. For details on what parts of the record
* are removed, see the documentation of {@link #removeRecord(String)}.</p>
Expand Down
11 changes: 11 additions & 0 deletions metis-indexing/src/main/java/eu/europeana/indexing/Indexer.java
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,17 @@ TierResults indexAndGetTierCalculations(InputStream recordContent,
*/
boolean indexTombstone(String rdfAbout, DepublicationReason depublicationReason) throws IndexingException;

/**
* Removes the tombstone of the record with the given rdf:about value. This method also removes the associated objects (i.e.
* those objects that are always part of only one record and the removal of which can not invalidate references from other
* records):
*
* @param rdfAbout the id of the record
* @return information if tombstone really existed.
* @throws IndexingException in case something went wrong.
*/
boolean removeTombstone(String rdfAbout) throws IndexingException;

/**
* <p>
* Removes all records that belong to a given dataset. This method also removes the associated
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,11 @@ public FullBeanImpl getTombstone(String rdfAbout) {
return this.connectionProvider.getIndexedRecordAccess().getTombstoneFullbean(rdfAbout);
}

@Override
public boolean removeTombstone(String rdfAbout) throws IndexerRelatedIndexingException {
return this.connectionProvider.getIndexedRecordAccess().removeTombstone(rdfAbout);
}

@Override
public boolean indexTombstone(String rdfAbout, DepublicationReason depublicationReason) throws IndexingException {
if (depublicationReason == DepublicationReason.LEGACY) {
Expand Down

0 comments on commit 06454b1

Please sign in to comment.