use of org.codice.ddf.spatial.ogc.csw.catalog.common.transaction.DeleteAction in project ddf by codice.
the class TransactionRequestConverter method unmarshal.
@Override
public Object unmarshal(HierarchicalStreamReader reader, UnmarshallingContext context) {
CswTransactionRequest cswTransactionRequest = new CswTransactionRequest();
cswTransactionRequest.setVersion(reader.getAttribute(CswConstants.VERSION));
cswTransactionRequest.setService(reader.getAttribute(CswConstants.SERVICE));
cswTransactionRequest.setVerbose(Boolean.valueOf(reader.getAttribute(CswConstants.VERBOSE_RESPONSE)));
XStreamAttributeCopier.copyXmlNamespaceDeclarationsIntoContext(reader, context);
while (reader.hasMoreChildren()) {
reader.moveDown();
if (reader.getNodeName().contains("Insert")) {
String typeName = StringUtils.defaultIfEmpty(reader.getAttribute(CswConstants.TYPE_NAME_PARAMETER), CswConstants.CSW_RECORD);
String handle = StringUtils.defaultIfEmpty(reader.getAttribute(CswConstants.HANDLE_PARAMETER), "");
context.put(CswConstants.TRANSFORMER_LOOKUP_KEY, TransformerManager.ID);
context.put(CswConstants.TRANSFORMER_LOOKUP_VALUE, typeName);
List<Metacard> metacards = new ArrayList<>();
// Loop through the individual records to be inserted, converting each into a Metacard
while (reader.hasMoreChildren()) {
// move down to the record's tag
reader.moveDown();
Metacard metacard = (Metacard) context.convertAnother(null, MetacardImpl.class, delegatingTransformer);
if (metacard != null) {
metacards.add(metacard);
}
// move back up to the <SearchResults> parent of the <csw:Record> tags
reader.moveUp();
}
cswTransactionRequest.getInsertActions().add(new InsertAction(typeName, handle, metacards));
} else if (reader.getNodeName().contains("Delete")) {
XStreamAttributeCopier.copyXmlNamespaceDeclarationsIntoContext(reader, context);
Map<String, String> xmlnsAttributeToUriMappings = getXmlnsAttributeToUriMappingsFromContext(context);
Map<String, String> prefixToUriMappings = getPrefixToUriMappingsFromXmlnsAttributes(xmlnsAttributeToUriMappings);
StringWriter writer = new StringWriter();
XStreamAttributeCopier.copyXml(reader, writer, xmlnsAttributeToUriMappings);
DeleteType deleteType = getElementFromXml(writer.toString(), DeleteType.class);
cswTransactionRequest.getDeleteActions().add(new DeleteAction(deleteType, prefixToUriMappings));
} else if (reader.getNodeName().contains("Update")) {
XStreamAttributeCopier.copyXmlNamespaceDeclarationsIntoContext(reader, context);
UpdateAction updateAction = parseUpdateAction(reader, context);
cswTransactionRequest.getUpdateActions().add(updateAction);
}
reader.moveUp();
}
return cswTransactionRequest;
}
use of org.codice.ddf.spatial.ogc.csw.catalog.common.transaction.DeleteAction in project ddf by codice.
the class TestTransactionRequestConverter 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 DeleteAction(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));
}
use of org.codice.ddf.spatial.ogc.csw.catalog.common.transaction.DeleteAction in project ddf by codice.
the class TestTransactionMessageBodyReader 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));
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.common.transaction.DeleteAction in project ddf by codice.
the class TestTransactionMessageBodyReader 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));
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.common.transaction.DeleteAction in project ddf by codice.
the class TestTransactionMessageBodyReader method testReadInsertAndDeleteFrom.
@Test
public void testReadInsertAndDeleteFrom() throws IOException {
Converter mockConverter = mock(Converter.class);
when(mockConverter.canConvert(any(Metacard.class.getClass()))).thenReturn(true);
when(mockConverter.unmarshal(any(HierarchicalStreamReader.class), any(UnmarshallingContext.class))).thenReturn(mock(Metacard.class));
TransactionMessageBodyReader reader = new TransactionMessageBodyReader(mockConverter, CswQueryFactoryTest.getCswMetacardType(), registry);
CswTransactionRequest request = reader.readFrom(CswTransactionRequest.class, null, null, null, null, IOUtils.toInputStream(INSERT_AND_DELETE_REQUEST_XML));
assertThat(request, notNullValue());
assertThat(request.getDeleteActions().size(), is(1));
assertThat(request.getInsertActions().size(), is(1));
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'"));
InsertAction insertAction = request.getInsertActions().get(0);
assertThat(insertAction, notNullValue());
assertThat(insertAction.getRecords().size(), is(1));
assertThat(request.getService(), is(CswConstants.CSW));
assertThat(request.getVersion(), is(CswConstants.VERSION_2_0_2));
assertThat(request.isVerbose(), is(true));
}
Aggregations