use of net.opengis.cat.csw.v_2_0_2.TransactionResponseType in project ddf by codice.
the class TestRegistryStore method testCreateNoExistingMetacard.
@Test
public void testCreateNoExistingMetacard() throws Exception {
Metacard mcard = getDefaultMetacard();
Csw csw = mock(Csw.class);
TransactionResponseType responseType = mock(TransactionResponseType.class);
InsertResultType insertResultType = mock(InsertResultType.class);
BriefRecordType briefRecord = mock(BriefRecordType.class);
JAXBElement identifier = mock(JAXBElement.class);
SimpleLiteral literal = mock(SimpleLiteral.class);
when(literal.getContent()).thenReturn(Collections.singletonList(mcard.getId()));
when(identifier.getValue()).thenReturn(literal);
when(briefRecord.getIdentifier()).thenReturn(Collections.singletonList(identifier));
when(insertResultType.getBriefRecord()).thenReturn(Collections.singletonList(briefRecord));
when(responseType.getInsertResult()).thenReturn(Collections.singletonList(insertResultType));
when(factory.getClientForSubject(any())).thenReturn(csw);
when(csw.transaction(any())).thenReturn(responseType);
when(transformer.getTransformerIdForSchema(any())).thenReturn("myInsertType");
queryResults.add(new ResultImpl(mcard));
CreateRequest request = new CreateRequestImpl(mcard);
CreateResponse response = registryStore.create(request);
assertThat(response.getCreatedMetacards().get(0), is(mcard));
}
use of net.opengis.cat.csw.v_2_0_2.TransactionResponseType in project ddf by codice.
the class TestCswEndpoint method testDeleteTransaction.
@Test
public void testDeleteTransaction() throws CswException, UnsupportedQueryException, SourceUnavailableException, FederationException, IngestException {
DeleteType deleteType = mock(DeleteType.class);
doReturn(CswConstants.CSW_RECORD).when(deleteType).getTypeName();
doReturn("").when(deleteType).getHandle();
QueryConstraintType queryConstraintType = new QueryConstraintType();
queryConstraintType.setCqlText("title = \"foo\"");
doReturn(queryConstraintType).when(deleteType).getConstraint();
List<Result> results = new ArrayList<>();
results.add(new ResultImpl(new MetacardImpl()));
results.add(new ResultImpl(new MetacardImpl()));
QueryResponse queryResponse = new QueryResponseImpl(null, results, results.size());
doReturn(queryResponse).when(catalogFramework).query(any(QueryRequest.class));
List<Metacard> deletedMetacards = new ArrayList<>();
deletedMetacards.add(new MetacardImpl());
deletedMetacards.add(new MetacardImpl());
DeleteResponse deleteResponse = new DeleteResponseImpl(null, null, deletedMetacards);
doReturn(deleteResponse).when(catalogFramework).delete(any(DeleteRequest.class));
DeleteAction deleteAction = new DeleteAction(deleteType, DefaultCswRecordMap.getDefaultCswRecordMap().getPrefixToUriMapping());
CswTransactionRequest deleteRequest = new CswTransactionRequest();
deleteRequest.getDeleteActions().add(deleteAction);
deleteRequest.setVersion(CswConstants.VERSION_2_0_2);
deleteRequest.setService(CswConstants.CSW);
deleteRequest.setVerbose(false);
TransactionResponseType response = csw.transaction(deleteRequest);
assertThat(response, notNullValue());
TransactionSummaryType summary = response.getTransactionSummary();
assertThat(summary, notNullValue());
assertThat(summary.getTotalDeleted().intValue(), is(2));
assertThat(summary.getTotalInserted().intValue(), is(0));
assertThat(summary.getTotalUpdated().intValue(), is(0));
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);
}
use of net.opengis.cat.csw.v_2_0_2.TransactionResponseType in project ddf by codice.
the class TestCswEndpoint method testUpdateTransactionWithNewRecord.
@Test
public void testUpdateTransactionWithNewRecord() throws CswException, FederationException, IngestException, SourceUnavailableException, UnsupportedQueryException {
List<Update> updatedMetacards = new ArrayList<>();
updatedMetacards.add(new UpdateImpl(new MetacardImpl(), new MetacardImpl()));
UpdateResponse updateResponse = new UpdateResponseImpl(null, null, updatedMetacards);
doReturn(updateResponse).when(catalogFramework).update(any(UpdateRequest.class));
MetacardImpl updatedMetacard = new MetacardImpl();
updatedMetacard.setId("123");
UpdateAction updateAction = new UpdateAction(updatedMetacard, CswConstants.CSW_RECORD, "");
CswTransactionRequest transactionRequest = new CswTransactionRequest();
transactionRequest.getUpdateActions().add(updateAction);
transactionRequest.setVersion(CswConstants.VERSION_2_0_2);
transactionRequest.setService(CswConstants.CSW);
transactionRequest.setVerbose(false);
TransactionResponseType response = csw.transaction(transactionRequest);
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(1));
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();
assertThat(actualUpdateRequest.getUpdates().size(), is(1));
assertThat(actualUpdateRequest.getUpdates().get(0).getValue().getId(), is("123"));
}
use of net.opengis.cat.csw.v_2_0_2.TransactionResponseType in project ddf by codice.
the class CswEndpointTest method testDeleteBatching.
@Test
public void testDeleteBatching() throws Exception {
// configure query responses
queryResponseBatch = getQueryResponseBatch(500, 800);
QueryResponse[] qrRest = queryResponseBatch.subList(1, queryResponseBatch.size()).toArray(new QueryResponse[0]);
when(catalogFramework.query(any(QueryRequest.class))).thenReturn(queryResponseBatch.get(0), qrRest);
// configure delete responses
DeleteType deleteType = mock(DeleteType.class);
doReturn(CswConstants.CSW_RECORD).when(deleteType).getTypeName();
doReturn("").when(deleteType).getHandle();
QueryConstraintType queryConstraintType = new QueryConstraintType();
queryConstraintType.setCqlText("title = \"foo\"");
doReturn(queryConstraintType).when(deleteType).getConstraint();
when(deleteResponse.getDeletedMetacards()).thenReturn(populateMetacardList(1));
when(catalogFramework.delete(any(DeleteRequest.class))).thenAnswer((Answer<DeleteResponse>) invocation -> deleteResponse);
DeleteAction deleteAction = new DeleteActionImpl(deleteType, DefaultCswRecordMap.getPrefixToUriMapping());
CswTransactionRequest deleteRequest = new CswTransactionRequest();
deleteRequest.getDeleteActions().add(deleteAction);
TransactionResponseType response = csw.transaction(deleteRequest);
assertThat(response.getTransactionSummary().getTotalDeleted().intValue(), equalTo(800));
verify(catalogFramework, times(4)).query(any());
verify(catalogFramework, times(800)).delete(any());
}
use of net.opengis.cat.csw.v_2_0_2.TransactionResponseType in project ddf by codice.
the class AbstractCswStore method create.
@Override
public CreateResponse create(CreateRequest createRequest) throws IngestException {
Map<String, Serializable> properties = new HashMap<>();
validateOperation();
Subject subject = (Subject) createRequest.getPropertyValue(SecurityConstants.SECURITY_SUBJECT);
Csw csw = factory.getClientForSubject(subject);
CswTransactionRequest transactionRequest = getTransactionRequest();
List<Metacard> metacards = createRequest.getMetacards();
List<String> metacardIds = metacards.stream().map(Metacard::getId).collect(Collectors.toList());
List<Metacard> createdMetacards = new ArrayList<>();
List<Filter> createdMetacardFilters;
HashSet<ProcessingDetails> errors = new HashSet<>();
String insertTypeName = schemaTransformerManager.getTransformerIdForSchema(cswSourceConfiguration.getOutputSchema());
if (insertTypeName == null) {
throw new IngestException("Could not find transformer for output schema " + cswSourceConfiguration.getOutputSchema());
}
transactionRequest.getInsertActions().add(new InsertActionImpl(insertTypeName, null, metacards));
try {
TransactionResponseType response = csw.transaction(transactionRequest);
Set<String> processedIds = new HashSet<>();
// dive down into the response to get the created ID's. We need these so we can query
// the source again to get the created metacards and put them in the result
createdMetacardFilters = response.getInsertResult().stream().map(InsertResultType::getBriefRecord).flatMap(Collection::stream).map(BriefRecordType::getIdentifier).flatMap(Collection::stream).map(JAXBElement::getValue).map(SimpleLiteral::getContent).flatMap(Collection::stream).map(id -> {
processedIds.add(id);
return filterBuilder.attribute(Core.ID).is().equalTo().text(id);
}).collect(Collectors.toList());
metacardIds.removeAll(processedIds);
errors.addAll(metacardIds.stream().map(id -> new ProcessingDetailsImpl(id, null, "Failed to create metacard")).collect(Collectors.toList()));
} catch (CswException e) {
throw new IngestException("Csw Transaction Failed : ", e);
}
try {
createdMetacards = transactionQuery(createdMetacardFilters, subject);
} catch (UnsupportedQueryException e) {
errors.add(new ProcessingDetailsImpl(this.getId(), e, "Failed to retrieve newly created metacards"));
}
return new CreateResponseImpl(createRequest, properties, createdMetacards, errors);
}
Aggregations