use of ddf.catalog.operation.impl.CreateRequestImpl in project ddf by codice.
the class MetacardValidityMarkerPluginTest method testPreExistingMetacardErrorsAndWarnings.
@Test
public void testPreExistingMetacardErrorsAndWarnings() throws ValidationException, StopProcessingException, PluginExecutionException {
metacardValidators.add(getMockPassingValidator());
CreateRequestImpl request = new CreateRequestImpl(metacardsWithPreExistingAttributes(true, true), PROPERTIES, DESTINATIONS);
verifyCreate(request, expectError, expectWarning, INVALID_TAG);
}
use of ddf.catalog.operation.impl.CreateRequestImpl in project ddf by codice.
the class PluginTest method testCreateNullTransformer.
@Test
@Ignore
public void testCreateNullTransformer() throws PluginExecutionException, IngestException, SourceUnavailableException {
// given
plugin = new RestReplicatorPlugin(null);
CreateResponse createResponse = new CreateResponseImpl(new CreateRequestImpl(metacard), null, Arrays.asList(metacard));
// when
plugin.process(createResponse);
// then
verify(endpoint, never()).addDocument(isA(HttpHeaders.class), isA(UriInfo.class), isA(InputStream.class));
}
use of ddf.catalog.operation.impl.CreateRequestImpl in project ddf by codice.
the class DuplicateCommands method ingestSingly.
private List<Metacard> ingestSingly(CatalogFacade provider, List<Metacard> metacards) {
if (metacards.isEmpty()) {
return Collections.emptyList();
}
List<Metacard> createdMetacards = new ArrayList<>();
LOGGER.debug("Preparing to ingest {} records one at time.", metacards.size());
for (Metacard metacard : metacards) {
CreateRequest createRequest = new CreateRequestImpl(Arrays.asList(metacard));
CreateResponse createResponse;
try {
createResponse = provider.create(createRequest);
createdMetacards.addAll(createResponse.getCreatedMetacards());
} catch (IngestException | SourceUnavailableException e) {
LOGGER.debug("Error during ingest:", e);
} catch (Exception e) {
LOGGER.debug("Unexpected Exception during ingest:", e);
}
}
return createdMetacards;
}
use of ddf.catalog.operation.impl.CreateRequestImpl in project ddf by codice.
the class DuplicateCommands method ingestMetacards.
protected List<Metacard> ingestMetacards(CatalogFacade provider, List<Metacard> metacards) {
if (metacards.isEmpty()) {
return Collections.emptyList();
}
List<Metacard> createdMetacards = new ArrayList<>();
LOGGER.debug("Preparing to ingest {} records", metacards.size());
CreateRequest createRequest = new CreateRequestImpl(metacards);
CreateResponse createResponse;
try {
createResponse = provider.create(createRequest);
createdMetacards = createResponse.getCreatedMetacards();
} catch (IngestException e) {
printErrorMessage(String.format("Received error while ingesting: %s%n", e.getMessage()));
LOGGER.debug("Error during ingest. Attempting to ingest batch individually.");
return ingestSingly(provider, metacards);
} catch (SourceUnavailableException e) {
printErrorMessage(String.format("Received error while ingesting: %s%n", e.getMessage()));
LOGGER.debug("Error during ingest:", e);
return createdMetacards;
} catch (Exception e) {
printErrorMessage(String.format("Unexpected Exception received while ingesting: %s%n", e.getMessage()));
LOGGER.debug("Unexpected Exception during ingest:", e);
return createdMetacards;
}
ingestedCount.addAndGet(createdMetacards.size());
failedCount.addAndGet(metacards.size() - createdMetacards.size());
failedMetacards.addAll(subtract(metacards, createdMetacards));
return createdMetacards;
}
use of ddf.catalog.operation.impl.CreateRequestImpl in project ddf by codice.
the class Historian method version.
/**
* Versions deleted {@link Metacard}s.
*
* @param deleteResponse Versions this responses deleted metacards
*/
public DeleteResponse version(DeleteResponse deleteResponse) throws SourceUnavailableException, IngestException {
if (doSkip(deleteResponse)) {
return deleteResponse;
}
setSkipFlag(deleteResponse);
if (LOGGER.isTraceEnabled()) {
LOGGER.trace("Versioning Deleted Metacards {}", deleteResponse);
}
List<Metacard> originalMetacards = deleteResponse.getDeletedMetacards().stream().filter(isNotVersionNorDeleted).collect(Collectors.toList());
if (originalMetacards.isEmpty()) {
LOGGER.trace("No deleted metacards applicable to versioning");
securityLogger.audit("Skipping versioning deleted metacards with ids: {}", deleteResponse.getDeletedMetacards().stream().map(Metacard::getId).collect(TO_A_STRING));
return deleteResponse;
}
if (LOGGER.isTraceEnabled()) {
LOGGER.trace("Versioning following deleted metacards: {}", originalMetacards.stream().map(Metacard::getId).collect(TO_A_STRING));
}
// [OriginalMetacardId: Original Metacard]
Map<String, Metacard> originalMetacardsMap = originalMetacards.stream().collect(Collectors.toMap(Metacard::getId, Function.identity(), Historian::firstInWinsMerge));
// [ContentItem.getId: content items]
Map<String, List<ContentItem>> contentItems = getContent(getReadStorageRequests(originalMetacards));
if (LOGGER.isTraceEnabled()) {
LOGGER.trace("Got content under the following ID's: {}", contentItems.keySet().stream().collect(TO_A_STRING));
}
Function<String, Action> getAction = id -> contentItems.containsKey(id) ? Action.DELETED_CONTENT : Action.DELETED;
// VERSION_OF_ID is equivalent to the Original Metacard ID
// [MetacardVersion.VERSION_OF_ID: versioned metacard]
Map<String, Metacard> versionedMap = getVersionMetacards(originalMetacards, getAction, (Subject) deleteResponse.getRequest().getProperties().get(SecurityConstants.SECURITY_SUBJECT));
if (LOGGER.isDebugEnabled() && !versionedMap.keySet().equals(originalMetacardsMap.keySet())) {
LOGGER.debug("There is not a one to one mapping between original metacards and their versions!" + " (Some metacards may not have been versioned or too many versions may have been created). " + "More information regarding the IDs is available by setting log level to trace " + "(log:set trace ddf.catalog.history)");
if (LOGGER.isTraceEnabled()) {
LOGGER.trace("Original Metacards: {}", originalMetacards.stream().map(Metacard::getId).collect(TO_A_STRING));
LOGGER.trace("Version Metacards: {}", versionedMap.keySet().stream().collect(TO_A_STRING));
}
}
CreateStorageResponse createStorageResponse = versionContentItems(contentItems, versionedMap);
if (createStorageResponse != null) {
setResourceUriForContent(/*Mutable*/
versionedMap, createStorageResponse);
if (LOGGER.isTraceEnabled()) {
LOGGER.trace("Successfully stored content under ids: {}", createStorageResponse.getCreatedContentItems());
}
}
executeAsSystem(() -> catalogProvider().create(new CreateRequestImpl(new ArrayList<>(versionedMap.values()))));
if (LOGGER.isTraceEnabled()) {
LOGGER.trace("Successfully created versioned metacards under ids: {}", versionedMap.values().stream().map(Metacard::getId).collect(TO_A_STRING));
}
String userid = subjectIdentity.getUniqueIdentifier((Subject) deleteResponse.getProperties().get(SecurityConstants.SECURITY_SUBJECT));
List<Metacard> deletionMetacards = versionedMap.entrySet().stream().map(s -> new DeletedMetacardImpl(uuidGenerator.generateUuid(), s.getKey(), userid, s.getValue().getId(), originalMetacardsMap.get(s.getKey()))).collect(Collectors.toList());
CreateResponse deletionMetacardsCreateResponse = executeAsSystem(() -> catalogProvider().create(new CreateRequestImpl(deletionMetacards, new HashMap<>())));
if (LOGGER.isTraceEnabled()) {
LOGGER.trace("Successfully created deletion metacards under ids: {}", deletionMetacardsCreateResponse.getCreatedMetacards().stream().map(Metacard::getId).collect(TO_A_STRING));
}
return deleteResponse;
}
Aggregations