use of ddf.catalog.operation.impl.UpdateRequestImpl in project ddf by codice.
the class UpdateOperations method update.
public UpdateResponse update(UpdateStorageRequest streamUpdateRequest) throws IngestException, SourceUnavailableException {
Map<String, Metacard> metacardMap = new HashMap<>();
List<ContentItem> contentItems = new ArrayList<>(streamUpdateRequest.getContentItems().size());
HashMap<String, Map<String, Path>> tmpContentPaths = new HashMap<>();
UpdateResponse updateResponse = null;
UpdateStorageRequest updateStorageRequest = null;
UpdateStorageResponse updateStorageResponse = null;
streamUpdateRequest = opsStorageSupport.prepareStorageRequest(streamUpdateRequest, streamUpdateRequest::getContentItems);
// Operation populates the metacardMap, contentItems, and tmpContentPaths
opsMetacardSupport.generateMetacardAndContentItems(streamUpdateRequest.getContentItems(), metacardMap, contentItems, tmpContentPaths);
streamUpdateRequest.getProperties().put(CONTENT_PATHS, tmpContentPaths);
streamUpdateRequest = applyAttributeOverrides(streamUpdateRequest, metacardMap);
try {
if (!contentItems.isEmpty()) {
updateStorageRequest = new UpdateStorageRequestImpl(contentItems, streamUpdateRequest.getId(), streamUpdateRequest.getProperties());
updateStorageRequest = processPreUpdateStoragePlugins(updateStorageRequest);
try {
updateStorageResponse = sourceOperations.getStorage().update(updateStorageRequest);
updateStorageResponse.getProperties().put(CONTENT_PATHS, tmpContentPaths);
} catch (StorageException e) {
throw new IngestException("Could not store content items. Removed created metacards.", e);
}
updateStorageResponse = processPostUpdateStoragePlugins(updateStorageResponse);
for (ContentItem contentItem : updateStorageResponse.getUpdatedContentItems()) {
if (StringUtils.isBlank(contentItem.getQualifier())) {
Metacard metacard = metacardMap.get(contentItem.getId());
Metacard overrideMetacard = contentItem.getMetacard();
Metacard updatedMetacard = OverrideAttributesSupport.overrideMetacard(metacard, overrideMetacard, true, true);
updatedMetacard.setAttribute(new AttributeImpl(Metacard.RESOURCE_SIZE, String.valueOf(contentItem.getSize())));
metacardMap.put(contentItem.getId(), updatedMetacard);
}
}
}
UpdateRequestImpl updateRequest = new UpdateRequestImpl(Iterables.toArray(metacardMap.values().stream().map(Metacard::getId).collect(Collectors.toList()), String.class), new ArrayList<>(metacardMap.values()));
updateRequest.setProperties(streamUpdateRequest.getProperties());
historian.setSkipFlag(updateRequest);
updateResponse = doUpdate(updateRequest);
historian.version(streamUpdateRequest, updateStorageResponse, updateResponse);
} catch (Exception e) {
if (updateStorageRequest != null) {
try {
sourceOperations.getStorage().rollback(updateStorageRequest);
} catch (StorageException e1) {
LOGGER.info("Unable to remove temporary content for id: {}", updateStorageRequest.getId(), e1);
}
}
throw new IngestException("Unable to store products for request: " + streamUpdateRequest.getId(), e);
} finally {
opsStorageSupport.commitAndCleanup(updateStorageRequest, tmpContentPaths);
}
updateResponse = doPostIngest(updateResponse);
return updateResponse;
}
use of ddf.catalog.operation.impl.UpdateRequestImpl in project ddf by codice.
the class FanoutCatalogFrameworkTest method testBlacklistedTagUpdateRequestFails.
@Test(expected = IngestException.class)
public void testBlacklistedTagUpdateRequestFails() throws Exception {
Metacard metacard = new MetacardImpl();
metacard.setAttribute(new AttributeImpl(Metacard.ID, "metacardId"));
metacard.setAttribute(new AttributeImpl(Metacard.TAGS, "blacklisted"));
UpdateRequest request = new UpdateRequestImpl(metacard.getId(), metacard);
framework.setFanoutTagBlacklist(Collections.singletonList("blacklisted"));
framework.update(request);
}
use of ddf.catalog.operation.impl.UpdateRequestImpl in project ddf by codice.
the class MetacardApplication method revertMetacard.
private void revertMetacard(Metacard versionMetacard, String id, boolean alreadyCreated) throws SourceUnavailableException, IngestException, FederationException, UnsupportedQueryException {
LOGGER.trace("Reverting metacard [{}] to version [{}]", id, versionMetacard.getId());
Metacard revertMetacard = MetacardVersionImpl.toMetacard(versionMetacard, types);
Action action = Action.fromKey((String) versionMetacard.getAttribute(MetacardVersion.ACTION).getValue());
if (DELETE_ACTIONS.contains(action)) {
attemptDeleteDeletedMetacard(id);
if (!alreadyCreated) {
catalogFramework.create(new CreateRequestImpl(revertMetacard));
}
} else {
tryUpdate(4, () -> {
catalogFramework.update(new UpdateRequestImpl(id, revertMetacard));
return true;
});
}
}
use of ddf.catalog.operation.impl.UpdateRequestImpl in project ddf by codice.
the class MetacardApplication method patchMetacards.
protected UpdateResponse patchMetacards(List<MetacardChanges> metacardChanges) throws SourceUnavailableException, IngestException, FederationException, UnsupportedQueryException {
Set<String> changedIds = metacardChanges.stream().flatMap(mc -> mc.getIds().stream()).collect(Collectors.toSet());
Map<String, Result> results = util.getMetacards(changedIds, "*");
for (MetacardChanges changeset : metacardChanges) {
for (AttributeChange attributeChange : changeset.getAttributes()) {
for (String id : changeset.getIds()) {
List<String> values = attributeChange.getValues();
Metacard result = results.get(id).getMetacard();
Function<Serializable, Serializable> mapFunc = Function.identity();
if (isChangeTypeDate(attributeChange, result)) {
mapFunc = mapFunc.andThen(util::parseDate);
}
result.setAttribute(new AttributeImpl(attributeChange.getAttribute(), values.stream().filter(Objects::nonNull).map(mapFunc).collect(Collectors.toList())));
}
}
}
List<Metacard> changedMetacards = results.values().stream().map(Result::getMetacard).collect(Collectors.toList());
return catalogFramework.update(new UpdateRequestImpl(changedMetacards.stream().map(Metacard::getId).collect(Collectors.toList()).toArray(new String[0]), changedMetacards));
}
use of ddf.catalog.operation.impl.UpdateRequestImpl in project ddf by codice.
the class DummyPreIngestPlugin method process.
public UpdateRequest process(UpdateRequest input) throws PluginExecutionException {
String methodName = "process(UpdateRequest)";
LOGGER.debug(ENTERING, methodName);
UpdateRequest newRequest = input;
if (newRequest != null) {
List<Entry<Serializable, Metacard>> updates = newRequest.getUpdates();
List<Metacard> updatedMetacards = new ArrayList<Metacard>();
for (Entry<Serializable, Metacard> updateEntry : updates) {
Metacard metacard = updateEntry.getValue();
updatedMetacards.add(metacard);
}
// Loop to get all ids
List<String> ids = new ArrayList<String>();
int i = 0;
for (Entry<Serializable, Metacard> updateEntry : updates) {
if (i % 2 == 0) {
ids.add((String) updateEntry.getKey());
}
i++;
}
updatedMetacards = this.filterOutMetacards(updatedMetacards);
LOGGER.debug("Returning new update request with id list size: {} and metacard list size: {}", ids.size(), updatedMetacards.size());
newRequest = new UpdateRequestImpl(ids.toArray(new String[ids.size()]), updatedMetacards);
}
LOGGER.debug(EXITING, methodName);
return newRequest;
}
Aggregations