Search in sources :

Example 11 with SourceUnavailableException

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

the class CatalogFrameworkImplTest method testNullIdsDelete.

@Test(expected = IngestException.class)
public void testNullIdsDelete() throws IngestException {
    MockEventProcessor eventAdmin = new MockEventProcessor();
    MockMemoryProvider provider = new MockMemoryProvider("Provider", "Provider", "v1.0", "DDF", new HashSet<ContentType>(), true, new Date());
    CatalogFramework framework = this.createDummyCatalogFramework(provider, storageProvider, eventAdmin, true);
    // call framework with null request
    try {
        framework.delete(null);
    } catch (SourceUnavailableException e) {
        fail();
    }
}
Also used : SourceUnavailableException(ddf.catalog.source.SourceUnavailableException) ContentType(ddf.catalog.data.ContentType) CatalogFramework(ddf.catalog.CatalogFramework) Date(java.util.Date) Test(org.junit.Test)

Example 12 with SourceUnavailableException

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

the class CatalogFrameworkImplTest method testNullEntriesUpdate.

@Test(expected = IngestException.class)
public void testNullEntriesUpdate() throws IngestException {
    MockEventProcessor eventAdmin = new MockEventProcessor();
    MockMemoryProvider provider = new MockMemoryProvider("Provider", "Provider", "v1.0", "DDF", new HashSet<ContentType>(), true, new Date());
    CatalogFramework framework = this.createDummyCatalogFramework(provider, storageProvider, eventAdmin, true);
    // call framework with null request
    try {
        framework.update((UpdateRequest) null);
    } catch (SourceUnavailableException e) {
        fail();
    }
}
Also used : SourceUnavailableException(ddf.catalog.source.SourceUnavailableException) ContentType(ddf.catalog.data.ContentType) CatalogFramework(ddf.catalog.CatalogFramework) Date(java.util.Date) Test(org.junit.Test)

Example 13 with SourceUnavailableException

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

the class SearchControllerTest method createFramework.

private CatalogFramework createFramework() {
    final long COUNT = 2;
    CatalogFramework framework = mock(CatalogFramework.class);
    List<Result> results = new ArrayList<Result>();
    for (int i = 0; i < COUNT; i++) {
        Result result = mock(Result.class);
        MetacardImpl metacard = new MetacardImpl();
        metacard.setId("Metacard_" + i);
        metacard.setTitle("Metacard " + i);
        metacard.setLocation("POINT(" + i + " " + i + ")");
        metacard.setType(BasicTypes.BASIC_METACARD);
        metacard.setCreatedDate(TIMESTAMP);
        metacard.setEffectiveDate(TIMESTAMP);
        metacard.setExpirationDate(TIMESTAMP);
        metacard.setModifiedDate(TIMESTAMP);
        metacard.setContentTypeName("TEST");
        metacard.setContentTypeVersion("1.0");
        metacard.setTargetNamespace(URI.create(getClass().getPackage().getName()));
        when(result.getDistanceInMeters()).thenReturn(100.0 * i);
        when(result.getRelevanceScore()).thenReturn(100.0 * (COUNT - i) / COUNT);
        when(result.getMetacard()).thenReturn(metacard);
        results.add(result);
    }
    QueryResponse response = new QueryResponseImpl(mock(QueryRequest.class), new ArrayList<Result>(), COUNT);
    response.getResults().addAll(results);
    try {
        when(framework.query(any(QueryRequest.class))).thenReturn(response);
    } catch (UnsupportedQueryException e) {
        LOGGER.debug("Error querying framework", e);
    } catch (SourceUnavailableException e) {
        LOGGER.debug("Error querying framework", e);
    } catch (FederationException e) {
        LOGGER.debug("Error querying framework", e);
    }
    return framework;
}
Also used : SourceUnavailableException(ddf.catalog.source.SourceUnavailableException) QueryRequest(ddf.catalog.operation.QueryRequest) UnsupportedQueryException(ddf.catalog.source.UnsupportedQueryException) ArrayList(java.util.ArrayList) FederationException(ddf.catalog.federation.FederationException) MetacardImpl(ddf.catalog.data.impl.MetacardImpl) Result(ddf.catalog.data.Result) QueryResponseImpl(ddf.catalog.operation.impl.QueryResponseImpl) QueryResponse(ddf.catalog.operation.QueryResponse) CatalogFramework(ddf.catalog.CatalogFramework)

Example 14 with SourceUnavailableException

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

the class QueryRunnable method queryCatalog.

protected QueryResponse queryCatalog(String sourceId, SearchRequest searchRequest, Subject subject, Map<String, Serializable> properties) {
    Query query = searchRequest.getQuery();
    QueryResponse response = getEmptyResponse(sourceId);
    long startTime = System.currentTimeMillis();
    try {
        if (query != null) {
            List<String> sourceIds;
            if (sourceId == null) {
                sourceIds = new ArrayList<>(searchRequest.getSourceIds());
            } else {
                sourceIds = Collections.singletonList(sourceId);
            }
            QueryRequest request = new QueryRequestImpl(query, false, sourceIds, properties);
            if (subject != null) {
                LOGGER.debug("Adding {} property with value {} to request.", SecurityConstants.SECURITY_SUBJECT, subject);
                request.getProperties().put(SecurityConstants.SECURITY_SUBJECT, subject);
            }
            LOGGER.debug("Sending query: {}", query);
            response = searchController.getFramework().query(request);
        }
    } catch (UnsupportedQueryException | FederationException e) {
        LOGGER.info("Error executing query. {}. Set log level to DEBUG for more information", e.getMessage());
        LOGGER.debug("Error executing query", e);
        response.getProcessingDetails().add(new ProcessingDetailsImpl(sourceId, e));
    } catch (SourceUnavailableException e) {
        LOGGER.info("Error executing query because the underlying source was unavailable. {}. Set log level to DEBUG for more information", e.getMessage());
        LOGGER.debug("Error executing query because the underlying source was unavailable.", e);
        response.getProcessingDetails().add(new ProcessingDetailsImpl(sourceId, e));
    } catch (RuntimeException e) {
        // Account for any runtime exceptions and send back a server error
        // this prevents full stacktraces returning to the client
        // this allows for a graceful server error to be returned
        LOGGER.info("RuntimeException on executing query. {}. Set log level to DEBUG for more information", e.getMessage());
        LOGGER.debug("RuntimeException on executing query", e);
        response.getProcessingDetails().add(new ProcessingDetailsImpl(sourceId, e));
    }
    long estimatedTime = System.currentTimeMillis() - startTime;
    response.getProperties().put("elapsed", estimatedTime);
    return response;
}
Also used : SourceUnavailableException(ddf.catalog.source.SourceUnavailableException) Query(ddf.catalog.operation.Query) QueryRequest(ddf.catalog.operation.QueryRequest) UnsupportedQueryException(ddf.catalog.source.UnsupportedQueryException) FederationException(ddf.catalog.federation.FederationException) ProcessingDetailsImpl(ddf.catalog.operation.impl.ProcessingDetailsImpl) QueryResponse(ddf.catalog.operation.QueryResponse) QueryRequestImpl(ddf.catalog.operation.impl.QueryRequestImpl)

Example 15 with SourceUnavailableException

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

the class KmlEndpoint method getAvailableSources.

/**
     * Creates a list of {@link NetworkLink}s, one for each {@link ddf.catalog.source.Source} including the local
     * catalog.
     *
     * @param uriInfo - injected resource provding the URI.
     * @return - {@link Kml} containing a folder of {@link NetworkLink}s.
     */
@GET
@Path(FORWARD_SLASH + "sources")
@Produces(KML_MIME_TYPE)
public Kml getAvailableSources(@Context UriInfo uriInfo) {
    try {
        SourceInfoResponse response = framework.getSourceInfo(new SourceInfoRequestEnterprise(false));
        Kml kml = KmlFactory.createKml();
        Folder folder = kml.createAndSetFolder();
        folder.setOpen(true);
        for (SourceDescriptor descriptor : response.getSourceInfo()) {
            UriBuilder builder = UriBuilder.fromUri(uriInfo.getBaseUri());
            builder = generateEndpointUrl(SystemBaseUrl.getRootContext() + FORWARD_SLASH + CATALOG_URL_PATH + FORWARD_SLASH + OPENSEARCH_URL_PATH, builder);
            builder = builder.queryParam(SOURCE_PARAM, descriptor.getSourceId());
            builder = builder.queryParam(OPENSEARCH_SORT_KEY, OPENSEARCH_DEFAULT_SORT);
            builder = builder.queryParam(OPENSEARCH_FORMAT_KEY, KML_TRANSFORM_PARAM);
            NetworkLink networkLink = generateViewBasedNetworkLink(builder.build().toURL(), descriptor.getSourceId());
            folder.getFeature().add(networkLink);
        }
        return kml;
    } catch (SourceUnavailableException e) {
        throw new WebApplicationException(e, Status.INTERNAL_SERVER_ERROR);
    } catch (UnknownHostException e) {
        throw new WebApplicationException(e, Status.INTERNAL_SERVER_ERROR);
    } catch (MalformedURLException e) {
        throw new WebApplicationException(e, Status.INTERNAL_SERVER_ERROR);
    } catch (IllegalArgumentException e) {
        throw new WebApplicationException(e, Status.INTERNAL_SERVER_ERROR);
    } catch (UriBuilderException e) {
        throw new WebApplicationException(e, Status.INTERNAL_SERVER_ERROR);
    }
}
Also used : SourceUnavailableException(ddf.catalog.source.SourceUnavailableException) SourceDescriptor(ddf.catalog.source.SourceDescriptor) MalformedURLException(java.net.MalformedURLException) WebApplicationException(javax.ws.rs.WebApplicationException) UnknownHostException(java.net.UnknownHostException) Kml(de.micromata.opengis.kml.v_2_2_0.Kml) UriBuilderException(javax.ws.rs.core.UriBuilderException) Folder(de.micromata.opengis.kml.v_2_2_0.Folder) SourceInfoRequestEnterprise(ddf.catalog.operation.impl.SourceInfoRequestEnterprise) NetworkLink(de.micromata.opengis.kml.v_2_2_0.NetworkLink) UriBuilder(javax.ws.rs.core.UriBuilder) SourceInfoResponse(ddf.catalog.operation.SourceInfoResponse) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Aggregations

SourceUnavailableException (ddf.catalog.source.SourceUnavailableException)63 FederationException (ddf.catalog.federation.FederationException)27 UnsupportedQueryException (ddf.catalog.source.UnsupportedQueryException)26 QueryResponse (ddf.catalog.operation.QueryResponse)22 IngestException (ddf.catalog.source.IngestException)22 Test (org.junit.Test)22 ArrayList (java.util.ArrayList)21 Metacard (ddf.catalog.data.Metacard)20 QueryRequestImpl (ddf.catalog.operation.impl.QueryRequestImpl)20 CatalogFramework (ddf.catalog.CatalogFramework)18 QueryImpl (ddf.catalog.operation.impl.QueryImpl)18 SourceInfoResponse (ddf.catalog.operation.SourceInfoResponse)17 CreateResponse (ddf.catalog.operation.CreateResponse)16 ContentType (ddf.catalog.data.ContentType)14 QueryRequest (ddf.catalog.operation.QueryRequest)14 HashMap (java.util.HashMap)14 Filter (org.opengis.filter.Filter)12 Result (ddf.catalog.data.Result)11 CreateRequestImpl (ddf.catalog.operation.impl.CreateRequestImpl)11 SourceDescriptor (ddf.catalog.source.SourceDescriptor)10