diff --git a/metis-indexing/src/main/java/eu/europeana/indexing/IndexedRecordAccess.java b/metis-indexing/src/main/java/eu/europeana/indexing/IndexedRecordAccess.java index 0445cf6b5..7ef5224de 100644 --- a/metis-indexing/src/main/java/eu/europeana/indexing/IndexedRecordAccess.java +++ b/metis-indexing/src/main/java/eu/europeana/indexing/IndexedRecordAccess.java @@ -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): + * + * 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); + } + } + /** *

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)}.

diff --git a/metis-indexing/src/main/java/eu/europeana/indexing/Indexer.java b/metis-indexing/src/main/java/eu/europeana/indexing/Indexer.java index f72963077..65e750de1 100644 --- a/metis-indexing/src/main/java/eu/europeana/indexing/Indexer.java +++ b/metis-indexing/src/main/java/eu/europeana/indexing/Indexer.java @@ -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; + /** *

* Removes all records that belong to a given dataset. This method also removes the associated diff --git a/metis-indexing/src/main/java/eu/europeana/indexing/IndexerImpl.java b/metis-indexing/src/main/java/eu/europeana/indexing/IndexerImpl.java index f6b075d19..3d6a4e457 100644 --- a/metis-indexing/src/main/java/eu/europeana/indexing/IndexerImpl.java +++ b/metis-indexing/src/main/java/eu/europeana/indexing/IndexerImpl.java @@ -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) {