use of ddf.catalog.operation.impl.UpdateRequestImpl in project ddf by codice.
the class CatalogFrameworkImplTest method testUpdateWithDefaults.
@Test
public void testUpdateWithDefaults() throws Exception {
final String title = "some title";
final Date expiration = new Date();
List<Metacard> metacards = getMetacards(title, expiration);
CreateRequest createRequest = new CreateRequestImpl(metacards);
CreateResponse createResponse = framework.create(createRequest);
verifyDefaults(createResponse.getCreatedMetacards(), title, expiration, null, null, null, null);
registerDefaults();
List<Result> mockFederationResults = metacards.stream().map(m -> {
Result mockResult = mock(Result.class);
when(mockResult.getMetacard()).thenReturn(m);
return mockResult;
}).collect(Collectors.toList());
QueryResponseImpl queryResponse = new QueryResponseImpl(mock(QueryRequest.class), mockFederationResults, 1);
when(mockFederationStrategy.federate(anyList(), anyObject())).thenReturn(queryResponse);
UpdateRequest updateRequest = new UpdateRequestImpl(new String[] { "1", "2", "3", "4", "5" }, createResponse.getCreatedMetacards());
UpdateResponse updateResponse = framework.update(updateRequest);
List<Metacard> updatedMetacards = updateResponse.getUpdatedMetacards().stream().map(Update::getNewMetacard).collect(Collectors.toList());
verifyDefaults(updatedMetacards, title, expiration, DEFAULT_TITLE, DEFAULT_EXPIRATION, DEFAULT_TITLE_CUSTOM, DEFAULT_EXPIRATION_CUSTOM);
}
use of ddf.catalog.operation.impl.UpdateRequestImpl in project ddf by codice.
the class CswEndpoint method updateRecords.
private int updateRecords(UpdateAction updateAction) throws CswException, FederationException, IngestException, SourceUnavailableException, UnsupportedQueryException {
if (updateAction.getMetacard() != null) {
Metacard newRecord = updateAction.getMetacard();
if (newRecord.getId() != null) {
UpdateRequest updateRequest = new UpdateRequestImpl(newRecord.getId(), newRecord);
LOGGER.debug("Attempting to update {} ", newRecord.getId());
UpdateResponse updateResponse = framework.update(updateRequest);
return updateResponse.getUpdatedMetacards().size();
} else {
throw new CswException("Unable to update record. No ID was specified in the request.", CswConstants.MISSING_PARAMETER_VALUE, updateAction.getHandle());
}
} else if (updateAction.getConstraint() != null) {
QueryConstraintType constraint = updateAction.getConstraint();
QueryRequest queryRequest = queryFactory.getQuery(constraint);
queryRequest = queryFactory.updateQueryRequestTags(queryRequest, schemaTransformerManager.getTransformerSchemaForId(updateAction.getTypeName()));
QueryResponse response = framework.query(queryRequest);
if (response.getHits() > 0) {
Map<String, Serializable> recordProperties = updateAction.getRecordProperties();
List<String> updatedMetacardIdsList = new ArrayList<>();
List<Metacard> updatedMetacards = new ArrayList<>();
for (Result result : response.getResults()) {
Metacard metacard = result.getMetacard();
if (metacard != null) {
for (Entry<String, Serializable> recordProperty : recordProperties.entrySet()) {
Attribute attribute = new AttributeImpl(recordProperty.getKey(), recordProperty.getValue());
metacard.setAttribute(attribute);
}
updatedMetacardIdsList.add(metacard.getId());
updatedMetacards.add(metacard);
}
}
if (updatedMetacardIdsList.size() > 0) {
String[] updatedMetacardIds = updatedMetacardIdsList.toArray(new String[updatedMetacardIdsList.size()]);
UpdateRequest updateRequest = new UpdateRequestImpl(updatedMetacardIds, updatedMetacards);
LOGGER.debug("Attempting to update {} metacards.", updatedMetacardIdsList.size());
UpdateResponse updateResponse = framework.update(updateRequest);
return updateResponse.getUpdatedMetacards().size();
}
}
}
return 0;
}
use of ddf.catalog.operation.impl.UpdateRequestImpl in project ddf by codice.
the class TestRegistryStore method testUpdateNonRegistryMetacard.
@Test(expected = IngestException.class)
public void testUpdateNonRegistryMetacard() throws Exception {
MetacardImpl updatedMcard = getDefaultMetacard();
updatedMcard.setAttribute(RegistryObjectMetacardType.REGISTRY_ID, null);
UpdateRequestImpl request = new UpdateRequestImpl("testId", updatedMcard);
registryStore.update(request);
}
use of ddf.catalog.operation.impl.UpdateRequestImpl in project ddf by codice.
the class CatalogFrameworkImplTest method testProviderRuntimeExceptionOnUpdateByID.
@Test(expected = IngestException.class)
public void testProviderRuntimeExceptionOnUpdateByID() throws IngestException {
MockEventProcessor eventAdmin = new MockEventProcessor();
// use exception provider instead of memory
MockExceptionProvider provider = new MockExceptionProvider("Provider", "Provider", "v1.0", "DDF", new HashSet<ContentType>(), true, null);
CatalogFramework framework = this.createDummyCatalogFramework(provider, storageProvider, eventAdmin, true);
List<Entry<Object, Metacard>> metacards = new ArrayList<Entry<Object, Metacard>>();
HashMap<Object, Metacard> map = new HashMap<Object, Metacard>();
// expected to throw exception due to catalog provider being unavailable
try {
MetacardImpl newCard = new MetacardImpl();
newCard.setId(null);
newCard.setResourceURI(new URI("uri:///1234"));
map.put(Metacard.ID, newCard);
metacards.addAll(map.entrySet());
UpdateRequest update = new UpdateRequestImpl(null, Metacard.ID, null);
framework.update(update);
} catch (URISyntaxException e) {
fail();
} catch (SourceUnavailableException e) {
fail();
}
}
use of ddf.catalog.operation.impl.UpdateRequestImpl in project ddf by codice.
the class FederationAdminServiceImpl method updateRegistryEntry.
@Override
public void updateRegistryEntry(Metacard updateMetacard, Set<String> destinations) throws FederationAdminException {
validateRegistryMetacards(Collections.singletonList(updateMetacard));
Map<String, Serializable> properties = new HashMap<>();
String mcardId = updateMetacard.getId();
if (isRemoteMetacard(updateMetacard) || CollectionUtils.isNotEmpty(destinations)) {
Filter idFilter = filterBuilder.attribute(RegistryObjectMetacardType.REMOTE_METACARD_ID).is().equalTo().text(updateMetacard.getId());
Filter tagFilter = filterBuilder.attribute(Metacard.TAGS).is().like().text(RegistryConstants.REGISTRY_TAG_INTERNAL);
List<Metacard> results = this.getRegistryMetacardsByFilter(filterBuilder.allOf(tagFilter, idFilter), destinations);
if (results.size() != 1) {
throw new FederationAdminException("Could not find metacard to update.");
}
mcardId = results.get(0).getId();
LOGGER.debug("Looked up remote-mcard-id {} and got id {}", updateMetacard.getId(), mcardId);
}
List<Map.Entry<Serializable, Metacard>> updateList = new ArrayList<>();
updateList.add(new AbstractMap.SimpleEntry<>(mcardId, updateMetacard));
UpdateRequest updateRequest = new UpdateRequestImpl(updateList, Metacard.ID, properties, destinations);
try {
UpdateResponse updateResponse = security.runWithSubjectOrElevate(() -> catalogFramework.update(updateRequest));
if (!updateResponse.getProcessingErrors().isEmpty()) {
throw new FederationAdminException("Processing error occurred while updating registry entry. Details:" + System.lineSeparator() + stringifyProcessingErrors(updateResponse.getProcessingErrors()));
}
} catch (SecurityServiceException | InvocationTargetException e) {
String message = "Error updating registry entry.";
LOGGER.debug("{} Metacard ID: {}", message, updateMetacard.getId());
throw new FederationAdminException(message, e);
}
}
Aggregations