use of org.codice.ddf.spatial.ogc.csw.catalog.actions.DeleteAction in project ddf by codice.
the class TransactionMessageBodyReaderTest method testReadDeleteWithCqlFrom.
@Test
public void testReadDeleteWithCqlFrom() throws IOException {
TransactionMessageBodyReader reader = new TransactionMessageBodyReader(mock(Converter.class), CswQueryFactoryTest.getCswMetacardType(), registry);
CswTransactionRequest request = reader.readFrom(CswTransactionRequest.class, null, null, null, null, IOUtils.toInputStream(DELETE_REQUEST_CQL_XML, StandardCharsets.UTF_8));
assertThat(request, notNullValue());
assertThat(request.getDeleteActions().size(), is(1));
assertThat(request.getInsertActions().size(), is(0));
assertThat(request.getUpdateActions().size(), is(0));
DeleteAction deleteAction = request.getDeleteActions().get(0);
assertThat(deleteAction, notNullValue());
assertThat(deleteAction.getTypeName(), is(CswConstants.CSW_RECORD));
assertThat(deleteAction.getHandle(), is("something"));
assertThat(deleteAction.getConstraint(), notNullValue());
assertThat(deleteAction.getConstraint().getCqlText().trim(), is("title = 'foo'"));
assertThat(request.getService(), is(CswConstants.CSW));
assertThat(request.getVersion(), is(CswConstants.VERSION_2_0_2));
assertThat(request.isVerbose(), is(false));
}
use of org.codice.ddf.spatial.ogc.csw.catalog.actions.DeleteAction in project ddf by codice.
the class AbstractCswStore method delete.
@Override
public DeleteResponse delete(DeleteRequest deleteRequest) throws IngestException {
Map<String, Serializable> properties = new HashMap<>();
validateOperation();
Subject subject = (Subject) deleteRequest.getPropertyValue(SecurityConstants.SECURITY_SUBJECT);
Csw csw = factory.getClientForSubject(subject);
CswTransactionRequest transactionRequest = getTransactionRequest();
OperationTransaction opTrans = (OperationTransaction) deleteRequest.getPropertyValue(Constants.OPERATION_TRANSACTION_KEY);
String typeName = schemaTransformerManager.getTransformerIdForSchema(cswSourceConfiguration.getOutputSchema());
if (typeName == null) {
typeName = CswConstants.CSW_RECORD;
}
for (Serializable itemToDelete : deleteRequest.getAttributeValues()) {
try {
DeleteType deleteType = new DeleteType();
deleteType.setTypeName(typeName);
QueryConstraintType queryConstraintType = new QueryConstraintType();
Filter filter;
FilterType filterType;
filter = filterBuilder.attribute(deleteRequest.getAttributeName()).is().equalTo().text(itemToDelete.toString());
filterType = filterAdapter.adapt(filter, cswFilterDelegate);
queryConstraintType.setCqlText(CswCqlTextFilter.getInstance().getCqlText(filterType));
deleteType.setConstraint(queryConstraintType);
DeleteAction deleteAction = new DeleteActionImpl(deleteType, DefaultCswRecordMap.getPrefixToUriMapping());
transactionRequest.getDeleteActions().add(deleteAction);
} catch (UnsupportedQueryException e) {
throw new IngestException("Unsupported Query.", e);
}
}
try {
TransactionResponseType response = csw.transaction(transactionRequest);
if (response.getTransactionSummary().getTotalDeleted().intValue() != deleteRequest.getAttributeValues().size()) {
throw new IngestException("Csw Transaction Failed. Number of metacards deleted did not match number requested.");
}
} catch (CswException e) {
throw new IngestException("Csw Transaction Failed", e);
}
return new DeleteResponseImpl(deleteRequest, properties, new ArrayList(opTrans.getPreviousStateMetacards()));
}
use of org.codice.ddf.spatial.ogc.csw.catalog.actions.DeleteAction in project ddf by codice.
the class CswEndpointTest 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();
when(catalogFramework.delete(any(DeleteRequest.class))).thenAnswer((Answer<DeleteResponse>) invocation -> {
DeleteRequest request = (DeleteRequest) invocation.getArguments()[0];
long numResults = request.getAttributeValues().size();
when(deleteResponse.getDeletedMetacards()).thenReturn(populateMetacardList((int) numResults));
return deleteResponse;
});
DeleteAction deleteAction = new DeleteActionImpl(deleteType, DefaultCswRecordMap.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(BATCH_TOTAL));
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 org.codice.ddf.spatial.ogc.csw.catalog.actions.DeleteAction in project ddf by codice.
the class TransactionMessageBodyReaderTest method testReadDeleteWithFilterFrom.
@Test
public void testReadDeleteWithFilterFrom() throws IOException {
TransactionMessageBodyReader reader = new TransactionMessageBodyReader(mock(Converter.class), CswQueryFactoryTest.getCswMetacardType(), registry);
CswTransactionRequest request = reader.readFrom(CswTransactionRequest.class, null, null, null, null, IOUtils.toInputStream(DELETE_REQUEST_FILTER_XML, StandardCharsets.UTF_8));
assertThat(request, notNullValue());
assertThat(request.getDeleteActions().size(), is(1));
assertThat(request.getInsertActions().size(), is(0));
assertThat(request.getUpdateActions().size(), is(0));
DeleteAction deleteAction = request.getDeleteActions().get(0);
assertThat(deleteAction, notNullValue());
assertThat(deleteAction.getTypeName(), is(CswConstants.CSW_RECORD));
assertThat(deleteAction.getHandle(), is("something"));
assertThat(deleteAction.getConstraint(), notNullValue());
assertThat(deleteAction.getConstraint().getFilter(), notNullValue());
assertThat(request.getService(), is(CswConstants.CSW));
assertThat(request.getVersion(), is(CswConstants.VERSION_2_0_2));
assertThat(request.isVerbose(), is(false));
}
use of org.codice.ddf.spatial.ogc.csw.catalog.actions.DeleteAction in project ddf by codice.
the class TransactionRequestConverterTest method testValidDeleteMarshal.
@Test
public void testValidDeleteMarshal() throws SAXException, IOException, XpathException {
CswTransactionRequest transactionRequest = new CswTransactionRequest();
MetacardImpl metacard = new MetacardImpl();
metacard.setId(METACARD_ID);
DeleteType deleteType = new DeleteType();
QueryConstraintType queryConstraintType = new QueryConstraintType();
queryConstraintType.setCqlText("identifier = " + METACARD_ID);
deleteType.setConstraint(queryConstraintType);
DeleteAction deleteAction = new DeleteActionImpl(deleteType, null);
transactionRequest.getDeleteActions().add(deleteAction);
transactionRequest.setService(CswConstants.CSW);
transactionRequest.setVerbose(true);
transactionRequest.setVersion(CswConstants.VERSION_2_0_2);
String xml = xStream.toXML(transactionRequest);
Diff diff = XMLUnit.compareXML(xml, EXPECTED_DELETE_XML);
assertThat(diff.similar(), is(true));
}
Aggregations