use of ddf.catalog.operation.UpdateRequest in project ddf by codice.
the class CatalogFrameworkImplTest method testUpdateByIdentifier.
/**
* Tests that the framework properly passes an update by identifier request to the local
* provider.
*/
@Test
public void testUpdateByIdentifier() throws Exception {
List<Metacard> metacards = new ArrayList<Metacard>();
MetacardImpl newCard = new MetacardImpl();
newCard.setId(null);
newCard.setResourceURI(new URI("DDF:///12345"));
metacards.add(newCard);
// create the entry manually in the provider
List<Metacard> insertedCards = provider.create(new CreateRequestImpl(metacards)).getCreatedMetacards();
ArrayList<URI> list = new ArrayList<URI>();
list.add(new URI("DDF:///12345"));
UpdateRequest request = new UpdateRequestImpl((URI[]) list.toArray(new URI[list.size()]), insertedCards);
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);
// send update to framework
UpdateResponse updateResponse = framework.update(request);
List<Update> returnedCards = updateResponse.getUpdatedMetacards();
assertNotNull(returnedCards);
assertEquals(list.size(), returnedCards.size());
assertTrue(provider.hasReceivedUpdateByIdentifier());
// make sure that the event was posted correctly
assertTrue(eventAdmin.wasEventPosted());
assertEquals(eventAdmin.getLastEvent().getId(), returnedCards.get(returnedCards.size() - 1).getOldMetacard().getId());
}
use of ddf.catalog.operation.UpdateRequest in project ddf by codice.
the class UpdateOperations method createQueryRequest.
private QueryRequestImpl createQueryRequest(UpdateRequest updateRequest) {
List<Filter> idFilters = updateRequest.getUpdates().stream().map(update -> frameworkProperties.getFilterBuilder().attribute(updateRequest.getAttributeName()).is().equalTo().text(update.getKey().toString())).collect(Collectors.toList());
QueryImpl queryImpl = new QueryImpl(queryOperations.getFilterWithAdditionalFilters(idFilters), 1, /* start index */
0, /* page size */
null, false, /* total result count */
0);
Map<String, Serializable> properties = new HashMap<>();
properties.put(SecurityConstants.SECURITY_SUBJECT, opsSecuritySupport.getSubject(updateRequest));
return new QueryRequestImpl(queryImpl, false, updateRequest.getStoreIds(), properties);
}
use of ddf.catalog.operation.UpdateRequest in project ddf by codice.
the class WorkspaceAccessPluginTest method testIgnoreNonWorkspaceMetacards.
@Test
public void testIgnoreNonWorkspaceMetacards() throws Exception {
Map<String, Metacard> updates = ImmutableMap.of("rand", new MetacardImpl());
UpdateRequest update = mockUpdateRequest(updates);
// should ignore all non-workspace metacards and do nothing
accessPlugin.processPreUpdate(update, updates);
}
use of ddf.catalog.operation.UpdateRequest 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.UpdateRequest 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;
}
Aggregations