Search in sources :

Example 41 with IngestException

use of ddf.catalog.source.IngestException in project ddf by codice.

the class CatalogFrameworkImplTest method testProviderUnavailableUpdateByIdentifier.

/**
     * Tests that the framework properly throws a catalog exception when the local provider is not
     * available for update by identifier.
     *
     * @throws IngestException
     * @throws SourceUnavailableException
     */
@Test(expected = SourceUnavailableException.class)
public void testProviderUnavailableUpdateByIdentifier() throws SourceUnavailableException {
    MockEventProcessor eventAdmin = new MockEventProcessor();
    MockMemoryProvider provider = new MockMemoryProvider("Provider", "Provider", "v1.0", "DDF", new HashSet<ContentType>(), false, null);
    CatalogFramework framework = this.createDummyCatalogFramework(provider, storageProvider, eventAdmin, false);
    List<Metacard> metacards = new ArrayList<Metacard>();
    List<URI> uris = new ArrayList<URI>();
    // expected to throw exception due to catalog provider being unavailable
    try {
        MetacardImpl newCard = new MetacardImpl();
        newCard.setId(null);
        newCard.setResourceURI(new URI("uri:///1234"));
        metacards.add(newCard);
        uris.add(new URI("uri:////1234"));
        UpdateRequest update = new UpdateRequestImpl((URI[]) uris.toArray(new URI[uris.size()]), metacards);
        framework.update(update);
    } catch (URISyntaxException e) {
        fail();
    } catch (IngestException e) {
        fail();
    }
}
Also used : ContentType(ddf.catalog.data.ContentType) UpdateRequest(ddf.catalog.operation.UpdateRequest) ArrayList(java.util.ArrayList) URISyntaxException(java.net.URISyntaxException) URI(java.net.URI) MetacardImpl(ddf.catalog.data.impl.MetacardImpl) Metacard(ddf.catalog.data.Metacard) CatalogFramework(ddf.catalog.CatalogFramework) IngestException(ddf.catalog.source.IngestException) UpdateRequestImpl(ddf.catalog.operation.impl.UpdateRequestImpl) Test(org.junit.Test)

Example 42 with IngestException

use of ddf.catalog.source.IngestException in project ddf by codice.

the class TestRestEndpoint method assertExceptionThrown.

protected void assertExceptionThrown(Class<? extends Throwable> klass) throws IngestException, SourceUnavailableException, URISyntaxException {
    CatalogFramework framework = mock(CatalogFramework.class);
    when(framework.create(isA(CreateRequest.class))).thenThrow(klass);
    when(framework.create(isA(CreateStorageRequest.class))).thenThrow(klass);
    HttpHeaders headers = createHeaders(Arrays.asList(MediaType.APPLICATION_JSON));
    RESTEndpoint rest = new RESTEndpoint(framework);
    addMatchingService(rest, Arrays.asList(getSimpleTransformer()));
    UriInfo info = givenUriInfo(SAMPLE_ID);
    try {
        rest.addDocument(headers, info, mock(HttpServletRequest.class), mock(MultipartBody.class), null, new ByteArrayInputStream("".getBytes()));
        fail();
    } catch (ServerErrorException e) {
        if (klass.getName().equals(SourceUnavailableException.class.getName())) {
            assertThat(e.getResponse().getStatus(), equalTo(INTERNAL_SERVER_ERROR));
        } else if (klass.getName().equals(IngestException.class.getName())) {
            assertThat(e.getResponse().getStatus(), equalTo(BAD_REQUEST));
        }
    }
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) HttpHeaders(javax.ws.rs.core.HttpHeaders) ByteArrayInputStream(java.io.ByteArrayInputStream) CreateRequest(ddf.catalog.operation.CreateRequest) MultipartBody(org.apache.cxf.jaxrs.ext.multipart.MultipartBody) CatalogFramework(ddf.catalog.CatalogFramework) IngestException(ddf.catalog.source.IngestException) UriInfo(javax.ws.rs.core.UriInfo) CreateStorageRequest(ddf.catalog.content.operation.CreateStorageRequest)

Example 43 with IngestException

use of ddf.catalog.source.IngestException in project ddf by codice.

the class AbstractCswStore method update.

@Override
public UpdateResponse update(UpdateRequest updateRequest) throws IngestException {
    Map<String, Serializable> properties = new HashMap<>();
    validateOperation();
    Subject subject = (Subject) updateRequest.getPropertyValue(SecurityConstants.SECURITY_SUBJECT);
    Csw csw = factory.getClientForSubject(subject);
    CswTransactionRequest transactionRequest = getTransactionRequest();
    OperationTransaction opTrans = (OperationTransaction) updateRequest.getPropertyValue(Constants.OPERATION_TRANSACTION_KEY);
    String insertTypeName = schemaTransformerManager.getTransformerIdForSchema(cswSourceConfiguration.getOutputSchema());
    HashSet<ProcessingDetails> errors = new HashSet<>();
    if (insertTypeName == null) {
        insertTypeName = CswConstants.CSW_RECORD;
    }
    ArrayList<Metacard> updatedMetacards = new ArrayList<>(updateRequest.getUpdates().size());
    ArrayList<Filter> updatedMetacardFilters = new ArrayList<>(updateRequest.getUpdates().size());
    for (Map.Entry<Serializable, Metacard> update : updateRequest.getUpdates()) {
        Metacard metacard = update.getValue();
        properties.put(metacard.getId(), metacard);
        updatedMetacardFilters.add(filterBuilder.attribute(updateRequest.getAttributeName()).is().equalTo().text(update.getKey().toString()));
        transactionRequest.getUpdateActions().add(new UpdateAction(metacard, insertTypeName, null));
    }
    try {
        TransactionResponseType response = csw.transaction(transactionRequest);
        if (response.getTransactionSummary().getTotalUpdated().longValue() != updateRequest.getUpdates().size()) {
            errors.add(new ProcessingDetailsImpl(this.getId(), null, "One or more updates failed"));
        }
    } catch (CswException e) {
        throw new IngestException("Csw Transaction Failed.", e);
    }
    try {
        updatedMetacards.addAll(transactionQuery(updatedMetacardFilters, subject));
    } catch (UnsupportedQueryException e) {
        errors.add(new ProcessingDetailsImpl(this.getId(), e, "Failed to retrieve updated metacards"));
    }
    return new UpdateResponseImpl(updateRequest, properties, updatedMetacards, new ArrayList(opTrans.getPreviousStateMetacards()), errors);
}
Also used : Serializable(java.io.Serializable) HashMap(java.util.HashMap) UnsupportedQueryException(ddf.catalog.source.UnsupportedQueryException) ArrayList(java.util.ArrayList) CswException(org.codice.ddf.spatial.ogc.csw.catalog.common.CswException) ProcessingDetailsImpl(ddf.catalog.operation.impl.ProcessingDetailsImpl) TransactionResponseType(net.opengis.cat.csw.v_2_0_2.TransactionResponseType) OperationTransaction(ddf.catalog.operation.OperationTransaction) ProcessingDetails(ddf.catalog.operation.ProcessingDetails) UpdateResponseImpl(ddf.catalog.operation.impl.UpdateResponseImpl) IngestException(ddf.catalog.source.IngestException) HashSet(java.util.HashSet) UpdateAction(org.codice.ddf.spatial.ogc.csw.catalog.common.transaction.UpdateAction) Csw(org.codice.ddf.spatial.ogc.csw.catalog.common.Csw) Subject(ddf.security.Subject) Metacard(ddf.catalog.data.Metacard) Filter(org.opengis.filter.Filter) CswTransactionRequest(org.codice.ddf.spatial.ogc.csw.catalog.common.transaction.CswTransactionRequest) Map(java.util.Map) DefaultCswRecordMap(org.codice.ddf.spatial.ogc.csw.catalog.common.converter.DefaultCswRecordMap) HashMap(java.util.HashMap)

Example 44 with IngestException

use of ddf.catalog.source.IngestException 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)

Example 45 with IngestException

use of ddf.catalog.source.IngestException in project ddf by codice.

the class SourceQueryRunnable method normalize.

private void normalize(Query query, List<Result> responseResults) {
    if (shouldNormalizeRelevance) {
        FilteringSolrIndex index = null;
        try {
            index = solrIndexFuture.get(FUTURE_TIMEOUT_SECONDS, TimeUnit.SECONDS);
            index.add(responseResults);
            List<Result> indexResults = index.query(new QueryRequestImpl(query)).getResults();
            normalizeRelevance(indexResults, results);
        } catch (InterruptedException | ExecutionException | TimeoutException e) {
            LOGGER.debug("Failed to get index for relevance normalization", e);
        } catch (UnsupportedQueryException e) {
            LOGGER.debug("Failed to parse query for relevance normalization", e);
        } catch (IngestException e) {
            LOGGER.debug("Failed to ingest results for relevance normalization", e);
        }
    } else if (shouldNormalizeDistance) {
        normalizeDistances(query, results);
    }
}
Also used : FilteringSolrIndex(org.codice.ddf.ui.searchui.query.solr.FilteringSolrIndex) QueryRequestImpl(ddf.catalog.operation.impl.QueryRequestImpl) UnsupportedQueryException(ddf.catalog.source.UnsupportedQueryException) IngestException(ddf.catalog.source.IngestException) ExecutionException(java.util.concurrent.ExecutionException) Result(ddf.catalog.data.Result) TimeoutException(java.util.concurrent.TimeoutException)

Aggregations

IngestException (ddf.catalog.source.IngestException)56 Metacard (ddf.catalog.data.Metacard)33 ArrayList (java.util.ArrayList)32 HashMap (java.util.HashMap)21 SourceUnavailableException (ddf.catalog.source.SourceUnavailableException)20 CreateResponse (ddf.catalog.operation.CreateResponse)19 CreateRequestImpl (ddf.catalog.operation.impl.CreateRequestImpl)17 IOException (java.io.IOException)17 UnsupportedQueryException (ddf.catalog.source.UnsupportedQueryException)15 Test (org.junit.Test)15 QueryRequestImpl (ddf.catalog.operation.impl.QueryRequestImpl)13 InternalIngestException (ddf.catalog.source.InternalIngestException)13 QueryResponse (ddf.catalog.operation.QueryResponse)11 Serializable (java.io.Serializable)11 List (java.util.List)11 Map (java.util.Map)11 FederationException (ddf.catalog.federation.FederationException)10 CreateRequest (ddf.catalog.operation.CreateRequest)10 DeleteResponse (ddf.catalog.operation.DeleteResponse)10 QueryImpl (ddf.catalog.operation.impl.QueryImpl)10