use of net.opengis.cat.csw.v_2_0_2.TransactionSummaryType in project ddf by codice.
the class CswEndpoint method transaction.
@Override
@POST
@Consumes({ MediaType.TEXT_XML, MediaType.APPLICATION_XML })
@Produces({ MediaType.TEXT_XML, MediaType.APPLICATION_XML })
public TransactionResponseType transaction(CswTransactionRequest request) throws CswException {
if (request == null) {
throw new CswException("TransactionRequest request is null");
}
TransactionResponseType response = new TransactionResponseType();
TransactionSummaryType summary = new TransactionSummaryType();
summary.setTotalInserted(BigInteger.valueOf(0));
summary.setTotalUpdated(BigInteger.valueOf(0));
summary.setTotalDeleted(BigInteger.valueOf(0));
response.setTransactionSummary(summary);
response.setVersion(CswConstants.VERSION_2_0_2);
int numInserted = 0;
for (InsertAction insertAction : request.getInsertActions()) {
CreateRequest createRequest = new CreateRequestImpl(insertAction.getRecords());
try {
CreateResponse createResponse = framework.create(createRequest);
if (request.isVerbose()) {
response.getInsertResult().add(getInsertResultFromResponse(createResponse));
}
numInserted += createResponse.getCreatedMetacards().size();
} catch (IngestException | SourceUnavailableException e) {
throw new CswException("Unable to insert record(s).", CswConstants.TRANSACTION_FAILED, insertAction.getHandle());
}
}
LOGGER.debug("{} records inserted.", numInserted);
response.getTransactionSummary().setTotalInserted(BigInteger.valueOf(numInserted));
int numUpdated = 0;
for (UpdateAction updateAction : request.getUpdateActions()) {
try {
numUpdated += updateRecords(updateAction);
} catch (CswException | FederationException | IngestException | SourceUnavailableException | UnsupportedQueryException e) {
throw new CswException("Unable to update record(s).", CswConstants.TRANSACTION_FAILED, updateAction.getHandle());
}
}
LOGGER.debug("{} records updated.", numUpdated);
response.getTransactionSummary().setTotalUpdated(BigInteger.valueOf(numUpdated));
int numDeleted = 0;
for (DeleteAction deleteAction : request.getDeleteActions()) {
try {
numDeleted += deleteRecords(deleteAction);
} catch (CswException | FederationException | IngestException | SourceUnavailableException | UnsupportedQueryException e) {
throw new CswException("Unable to delete record(s).", CswConstants.TRANSACTION_FAILED, deleteAction.getHandle());
}
}
LOGGER.debug("{} records deleted.", numDeleted);
response.getTransactionSummary().setTotalDeleted(BigInteger.valueOf(numDeleted));
return response;
}
use of net.opengis.cat.csw.v_2_0_2.TransactionSummaryType 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.TransactionSummaryType 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.TransactionSummaryType in project ddf by codice.
the class TestCswEndpoint method testIngestTransaction.
@Test
public void testIngestTransaction() throws CswException, SourceUnavailableException, FederationException, IngestException {
CswTransactionRequest request = new CswTransactionRequest();
request.getInsertActions().add(new InsertAction(CswConstants.CSW_TYPE, null, Arrays.asList(new MetacardImpl())));
TransactionResponseType response = csw.transaction(request);
assertThat(response, notNullValue());
assertThat(response.getInsertResult().isEmpty(), is(true));
assertThat(response.getTransactionSummary(), notNullValue());
TransactionSummaryType summary = response.getTransactionSummary();
assertThat(summary.getTotalDeleted().intValue(), is(0));
assertThat(summary.getTotalUpdated().intValue(), is(0));
assertThat(summary.getTotalInserted().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);
}
use of net.opengis.cat.csw.v_2_0_2.TransactionSummaryType 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"));
}
Aggregations