Skip to content

Commit

Permalink
HISTORIAN
Browse files Browse the repository at this point in the history
  • Loading branch information
malmgrens4 authored and alexabird committed Aug 8, 2024
1 parent b012c59 commit 833fe00
Show file tree
Hide file tree
Showing 2 changed files with 208 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import static ddf.catalog.core.versioning.MetacardVersion.SKIP_VERSIONING;

import com.google.common.collect.Lists;
import com.google.common.collect.Sets;
import com.google.common.io.ByteSource;
import ddf.catalog.content.StorageException;
import ddf.catalog.content.StorageProvider;
Expand All @@ -40,6 +41,7 @@
import ddf.catalog.operation.CreateResponse;
import ddf.catalog.operation.DeleteResponse;
import ddf.catalog.operation.Operation;
import ddf.catalog.operation.Response;
import ddf.catalog.operation.SourceResponse;
import ddf.catalog.operation.Update;
import ddf.catalog.operation.UpdateResponse;
Expand Down Expand Up @@ -68,6 +70,7 @@
import java.util.Map;
import java.util.Objects;
import java.util.Optional;
import java.util.Set;
import java.util.concurrent.Callable;
import java.util.concurrent.TimeUnit;
import java.util.function.Function;
Expand Down Expand Up @@ -103,6 +106,20 @@ public class Historian {
.or(DeletedMetacardImpl::isDeleted)
.negate();

public static final String SKIP_UPDATE_PROPERTY =
"org.codice.ddf.history.update.blacklist.metacardTypes";

public static final String SKIP_DELETE_PROPERTY =
"org.codice.ddf.history.deletes.blacklist.metacardTypes";

private final Set<String> skipUpdateMetacardTypes =
Sets.newHashSet(
System.getProperty(SKIP_UPDATE_PROPERTY, "").replaceAll("\\s+", "").split(","));

private final Set<String> skipDeleteMetacardTypes =
Sets.newHashSet(
System.getProperty(SKIP_DELETE_PROPERTY, "").replaceAll("\\s+", "").split(","));

private List<StorageProvider> storageProviders;

private List<CatalogProvider> catalogProviders;
Expand Down Expand Up @@ -163,6 +180,7 @@ public UpdateResponse version(UpdateResponse updateResponse) {
updateResponse.getUpdatedMetacards().stream()
.map(Update::getOldMetacard)
.filter(isNotVersionNorDeleted)
.filter(this::isNotBlackListedUpdate)
.collect(Collectors.toList());

if (inputMetacards.isEmpty()) {
Expand Down Expand Up @@ -223,6 +241,7 @@ public UpdateStorageResponse version(
.map(ContentItem::getMetacard)
.filter(Objects::nonNull)
.filter(isNotVersionNorDeleted)
.filter(this::isNotBlackListedUpdate)
.collect(Collectors.toList());

if (updatedMetacards.isEmpty()) {
Expand Down Expand Up @@ -287,6 +306,14 @@ public UpdateStorageResponse version(
return updateStorageResponse;
}

private boolean isNotBlackListedUpdate(Metacard metacard) {
return !skipUpdateMetacardTypes.contains(metacard.getMetacardType().getName());
}

private boolean isNotBlackListedDelete(Metacard metacard) {
return !skipDeleteMetacardTypes.contains(metacard.getMetacardType().getName());
}

/**
* Versions deleted {@link Metacard}s.
*
Expand All @@ -306,6 +333,7 @@ public DeleteResponse version(DeleteResponse deleteResponse)
List<Metacard> originalMetacards =
deleteResponse.getDeletedMetacards().stream()
.filter(isNotVersionNorDeleted)
.filter(this::isNotBlackListedDelete)
.collect(Collectors.toList());

if (originalMetacards.isEmpty()) {
Expand Down Expand Up @@ -636,11 +664,12 @@ private <T> T executeAsSystem(Callable<T> func) {
return systemSubject.execute(func);
}

private boolean doSkip(@Nullable Operation op) {
private boolean doSkip(@Nullable Response response) {
return !historyEnabled
|| op == null
|| response == null
|| ((boolean)
Optional.of(op)
Optional.of(response)
.map(Response::getRequest)
.map(Operation::getProperties)
.orElse(Collections.emptyMap())
.getOrDefault(SKIP_VERSIONING, false));
Expand Down
Loading

0 comments on commit 833fe00

Please sign in to comment.