use of ddf.catalog.operation.impl.QueryResponseImpl in project ddf by codice.
the class CatalogFrameworkImplTest method testUpdate.
/**
* Tests that the framework properly passes an update request to the local provider.
*/
@Test
public void testUpdate() throws Exception {
List<Metacard> metacards = new ArrayList<Metacard>();
MetacardImpl newCard = new MetacardImpl();
newCard.setId(null);
metacards.add(newCard);
// create the entry manually in the provider
CreateResponse response = provider.create(new CreateRequestImpl(metacards, null));
Metacard insertedCard = response.getCreatedMetacards().get(0);
Result mockFederationResult = mock(Result.class);
MetacardImpl metacard = new MetacardImpl();
metacard.setId(insertedCard.getId());
when(mockFederationResult.getMetacard()).thenReturn(metacard);
QueryResponseImpl queryResponse = new QueryResponseImpl(mock(QueryRequest.class), Collections.singletonList(mockFederationResult), 1);
when(mockFederationStrategy.federate(anyList(), anyObject())).thenReturn(queryResponse);
List<Entry<Serializable, Metacard>> updatedEntries = new ArrayList<Entry<Serializable, Metacard>>();
updatedEntries.add(new SimpleEntry<Serializable, Metacard>(insertedCard.getId(), insertedCard));
UpdateRequest request = new UpdateRequestImpl(updatedEntries, Metacard.ID, null);
// send update to framework
List<Update> returnedCards = framework.update(request).getUpdatedMetacards();
for (Update curCard : returnedCards) {
assertNotNull(curCard.getNewMetacard().getId());
}
// 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.impl.QueryResponseImpl in project ddf by codice.
the class FanoutCatalogFrameworkTest method testBlacklistedTagDeleteRequestFails.
@Test(expected = IngestException.class)
public void testBlacklistedTagDeleteRequestFails() throws Exception {
Metacard metacard = new MetacardImpl();
metacard.setAttribute(new AttributeImpl(Metacard.ID, "metacardId"));
metacard.setAttribute(new AttributeImpl(Metacard.TAGS, "blacklisted"));
CatalogProvider catalogProvider = mock(CatalogProvider.class);
doReturn(true).when(catalogProvider).isAvailable();
StorageProvider storageProvider = new MockMemoryStorageProvider();
FilterBuilder filterBuilder = new GeotoolsFilterBuilder();
FilterAdapter filterAdapter = mock(FilterAdapter.class);
ValidationQueryFactory validationQueryFactory = new ValidationQueryFactory(filterAdapter, filterBuilder);
QueryRequestImpl queryRequest = new QueryRequestImpl(mock(Query.class));
ResultImpl result = new ResultImpl(metacard);
List<Result> results = new ArrayList<>();
results.add(result);
QueryResponseImpl queryResponse = new QueryResponseImpl(queryRequest, results, 1);
FederationStrategy strategy = mock(FederationStrategy.class);
when(strategy.federate(anyList(), any())).thenReturn(queryResponse);
QueryResponsePostProcessor queryResponsePostProcessor = mock(QueryResponsePostProcessor.class);
doNothing().when(queryResponsePostProcessor).processResponse(any());
frameworkProperties.setCatalogProviders(Collections.singletonList(catalogProvider));
frameworkProperties.setStorageProviders(Collections.singletonList(storageProvider));
frameworkProperties.setFilterBuilder(filterBuilder);
frameworkProperties.setValidationQueryFactory(validationQueryFactory);
frameworkProperties.setFederationStrategy(strategy);
frameworkProperties.setQueryResponsePostProcessor(queryResponsePostProcessor);
OperationsSecuritySupport opsSecurity = new OperationsSecuritySupport();
MetacardFactory metacardFactory = new MetacardFactory(frameworkProperties.getMimeTypeToTransformerMapper(), uuidGenerator);
OperationsMetacardSupport opsMetacard = new OperationsMetacardSupport(frameworkProperties, metacardFactory);
SourceOperations sourceOperations = new SourceOperations(frameworkProperties);
sourceOperations.bind(catalogProvider);
sourceOperations.bind(storageProvider);
TransformOperations transformOperations = new TransformOperations(frameworkProperties);
QueryOperations queryOperations = new QueryOperations(frameworkProperties, sourceOperations, opsSecurity, opsMetacard);
OperationsCatalogStoreSupport opsCatStore = new OperationsCatalogStoreSupport(frameworkProperties, sourceOperations);
ResourceOperations resourceOperations = new ResourceOperations(frameworkProperties, queryOperations, opsSecurity);
DeleteOperations deleteOperations = new DeleteOperations(frameworkProperties, queryOperations, sourceOperations, opsSecurity, null);
deleteOperations.setOpsCatStoreSupport(opsCatStore);
framework = new CatalogFrameworkImpl(null, null, deleteOperations, queryOperations, resourceOperations, sourceOperations, transformOperations);
framework.setId(NEW_SOURCE_ID);
framework.setFanoutEnabled(true);
framework.setFanoutTagBlacklist(Collections.singletonList("blacklisted"));
DeleteRequest request = new DeleteRequestImpl(metacard.getId());
framework.delete(request);
}
use of ddf.catalog.operation.impl.QueryResponseImpl in project ddf by codice.
the class FanoutCatalogFrameworkTest method testReplaceSourceId.
@Test
public void testReplaceSourceId() {
QueryRequest request = new QueryRequestImpl(null);
List<Result> results = new ArrayList<Result>();
MetacardImpl newCard1 = new MetacardImpl();
newCard1.setSourceId(OLD_SOURCE_ID);
ResultImpl result1 = new ResultImpl(newCard1);
MetacardImpl newCard2 = new MetacardImpl();
newCard2.setSourceId(OLD_SOURCE_ID);
ResultImpl result2 = new ResultImpl(newCard2);
results.add(result1);
results.add(result2);
QueryResponse response = new QueryResponseImpl(request, results, 2);
QueryResponse newResponse = framework.getQueryOperations().replaceSourceId(response);
assertNotNull(newResponse);
List<Result> newResults = newResponse.getResults();
assertNotNull(newResults);
assertEquals(2, newResults.size());
Metacard card = new MetacardImpl();
for (Result newResult : newResults) {
card = newResult.getMetacard();
assertNotNull(card);
assertEquals(NEW_SOURCE_ID, card.getSourceId());
}
}
use of ddf.catalog.operation.impl.QueryResponseImpl in project ddf by codice.
the class TestCswEndpoint method testUpdateTransactionWithConstraint.
@Test
public void testUpdateTransactionWithConstraint() throws CswException, FederationException, IngestException, SourceUnavailableException, UnsupportedQueryException {
List<Result> results = new ArrayList<>();
MetacardImpl firstResult = new MetacardImpl();
firstResult.setId("123");
firstResult.setTitle("Title one");
firstResult.setAttribute("subject", "Subject one");
results.add(new ResultImpl(firstResult));
MetacardImpl secondResult = new MetacardImpl();
secondResult.setId("789");
secondResult.setTitle("Title two");
secondResult.setAttribute("subject", "Subject two");
results.add(new ResultImpl(secondResult));
QueryResponse queryResponse = new QueryResponseImpl(null, results, results.size());
doReturn(queryResponse).when(catalogFramework).query(any(QueryRequest.class));
List<Update> updatedMetacards = new ArrayList<>();
updatedMetacards.add(new UpdateImpl(new MetacardImpl(), new MetacardImpl()));
updatedMetacards.add(new UpdateImpl(new MetacardImpl(), new MetacardImpl()));
UpdateResponse updateResponse = new UpdateResponseImpl(null, null, updatedMetacards);
doReturn(updateResponse).when(catalogFramework).update(any(UpdateRequest.class));
Map<String, Serializable> recordProperties = new HashMap<>();
recordProperties.put("title", "foo");
recordProperties.put("subject", "bar");
QueryConstraintType constraint = new QueryConstraintType();
constraint.setCqlText("title = 'fake'");
UpdateAction updateAction = new UpdateAction(recordProperties, CswConstants.CSW_RECORD, "", constraint, DefaultCswRecordMap.getDefaultCswRecordMap().getPrefixToUriMapping());
CswTransactionRequest updateRequest = new CswTransactionRequest();
updateRequest.getUpdateActions().add(updateAction);
updateRequest.setVersion(CswConstants.VERSION_2_0_2);
updateRequest.setService(CswConstants.CSW);
updateRequest.setVerbose(false);
TransactionResponseType response = csw.transaction(updateRequest);
assertThat(response, notNullValue());
TransactionSummaryType summary = response.getTransactionSummary();
assertThat(summary, notNullValue());
assertThat(summary.getTotalDeleted().intValue(), is(0));
assertThat(summary.getTotalInserted().intValue(), is(0));
assertThat(summary.getTotalUpdated().intValue(), is(2));
verifyMarshalResponse(response, "net.opengis.cat.csw.v_2_0_2:net.opengis.filter.v_1_1_0:net.opengis.gml.v_3_1_1", cswQnameOutPutSchema);
ArgumentCaptor<UpdateRequest> updateRequestArgumentCaptor = ArgumentCaptor.forClass(UpdateRequest.class);
verify(catalogFramework, times(1)).update(updateRequestArgumentCaptor.capture());
UpdateRequest actualUpdateRequest = updateRequestArgumentCaptor.getValue();
List<Map.Entry<Serializable, Metacard>> updates = actualUpdateRequest.getUpdates();
assertThat(updates.size(), is(2));
Metacard firstUpdate = updates.get(0).getValue();
assertThat(firstUpdate.getId(), is("123"));
assertThat(firstUpdate.getTitle(), is("foo"));
assertThat(firstUpdate.getAttribute("subject").getValue(), is("bar"));
Metacard secondUpdate = updates.get(1).getValue();
assertThat(secondUpdate.getId(), is("789"));
assertThat(secondUpdate.getTitle(), is("foo"));
assertThat(secondUpdate.getAttribute("subject").getValue(), is("bar"));
}
use of ddf.catalog.operation.impl.QueryResponseImpl in project ddf by codice.
the class SolrCacheSource method query.
@Override
public SourceResponse query(QueryRequest request) throws UnsupportedQueryException {
final QueryResponseImpl queryResponse = new QueryResponseImpl(request);
try {
SourceResponse result = cache.query(request);
queryResponse.setHits(result.getHits());
queryResponse.setProperties(result.getProperties());
queryResponse.addResults(result.getResults(), true);
} catch (UnsupportedQueryException e) {
queryResponse.getProcessingDetails().add(new ProcessingDetailsImpl(getId(), e));
queryResponse.closeResultQueue();
}
return queryResponse;
}
Aggregations