Search in sources :

Example 11 with DeleteAction

use of org.codice.ddf.spatial.ogc.csw.catalog.common.transaction.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 DeleteAction(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()));
}
Also used : Serializable(java.io.Serializable) HashMap(java.util.HashMap) Csw(org.codice.ddf.spatial.ogc.csw.catalog.common.Csw) UnsupportedQueryException(ddf.catalog.source.UnsupportedQueryException) CswException(org.codice.ddf.spatial.ogc.csw.catalog.common.CswException) ArrayList(java.util.ArrayList) Subject(ddf.security.Subject) QueryConstraintType(net.opengis.cat.csw.v_2_0_2.QueryConstraintType) TransactionResponseType(net.opengis.cat.csw.v_2_0_2.TransactionResponseType) OperationTransaction(ddf.catalog.operation.OperationTransaction) FilterType(net.opengis.filter.v_1_1_0.FilterType) DeleteResponseImpl(ddf.catalog.operation.impl.DeleteResponseImpl) Filter(org.opengis.filter.Filter) CswTransactionRequest(org.codice.ddf.spatial.ogc.csw.catalog.common.transaction.CswTransactionRequest) DeleteAction(org.codice.ddf.spatial.ogc.csw.catalog.common.transaction.DeleteAction) DeleteType(net.opengis.cat.csw.v_2_0_2.DeleteType) IngestException(ddf.catalog.source.IngestException)

Aggregations

DeleteAction (org.codice.ddf.spatial.ogc.csw.catalog.common.transaction.DeleteAction)11 CswTransactionRequest (org.codice.ddf.spatial.ogc.csw.catalog.common.transaction.CswTransactionRequest)10 Test (org.junit.Test)7 InsertAction (org.codice.ddf.spatial.ogc.csw.catalog.common.transaction.InsertAction)6 DeleteType (net.opengis.cat.csw.v_2_0_2.DeleteType)5 UpdateAction (org.codice.ddf.spatial.ogc.csw.catalog.common.transaction.UpdateAction)5 Metacard (ddf.catalog.data.Metacard)4 MetacardImpl (ddf.catalog.data.impl.MetacardImpl)4 QueryConstraintType (net.opengis.cat.csw.v_2_0_2.QueryConstraintType)4 Converter (com.thoughtworks.xstream.converters.Converter)3 ArrayList (java.util.ArrayList)3 TransactionResponseType (net.opengis.cat.csw.v_2_0_2.TransactionResponseType)3 CswRecordConverter (org.codice.ddf.spatial.ogc.csw.catalog.converter.CswRecordConverter)3 CswQueryFactoryTest (org.codice.ddf.spatial.ogc.csw.catalog.endpoint.CswQueryFactoryTest)3 DeleteResponseImpl (ddf.catalog.operation.impl.DeleteResponseImpl)2 IngestException (ddf.catalog.source.IngestException)2 UnsupportedQueryException (ddf.catalog.source.UnsupportedQueryException)2 HashMap (java.util.HashMap)2 TransactionSummaryType (net.opengis.cat.csw.v_2_0_2.TransactionSummaryType)2 CswException (org.codice.ddf.spatial.ogc.csw.catalog.common.CswException)2