Search in sources :

Example 1 with NetworkLink

use of de.micromata.opengis.kml.v_2_2_0.NetworkLink in project ddf by codice.

the class KmlEndpoint method createRootNetworkLink.

private Kml createRootNetworkLink(UriInfo uriInfo) throws UnknownHostException {
    Kml kml = KmlFactory.createKml();
    NetworkLink rootNetworkLink = kml.createAndSetNetworkLink();
    rootNetworkLink.setName(this.productName);
    rootNetworkLink.setSnippet(KmlFactory.createSnippet().withMaxLines(0));
    UriBuilder baseUrlBuidler = UriBuilder.fromUri(uriInfo.getBaseUri());
    baseUrlBuidler.replacePath("");
    this.baseUrl = baseUrlBuidler.build().toString();
    String descriptionHtml = description;
    Handlebars handlebars = new Handlebars(templateLoader);
    try {
        Template template = handlebars.compile("description");
        descriptionHtml = template.apply(this);
        LOGGER.debug(descriptionHtml);
    } catch (IOException e) {
        LOGGER.debug("Failed to apply description Template", e);
    }
    rootNetworkLink.setDescription(descriptionHtml);
    rootNetworkLink.setOpen(true);
    rootNetworkLink.setVisibility(false);
    Link link = rootNetworkLink.createAndSetLink();
    UriBuilder builder = UriBuilder.fromUri(uriInfo.getBaseUri());
    builder = generateEndpointUrl(SystemBaseUrl.getRootContext() + FORWARD_SLASH + CATALOG_URL_PATH + FORWARD_SLASH + KML_TRANSFORM_PARAM + FORWARD_SLASH + "sources", builder);
    link.setHref(builder.build().toString());
    link.setViewRefreshMode(ViewRefreshMode.NEVER);
    link.setRefreshMode(RefreshMode.ON_INTERVAL);
    link.setRefreshInterval(REFRESH_INTERVAL);
    return kml;
}
Also used : NetworkLink(de.micromata.opengis.kml.v_2_2_0.NetworkLink) Handlebars(com.github.jknack.handlebars.Handlebars) Kml(de.micromata.opengis.kml.v_2_2_0.Kml) IOException(java.io.IOException) UriBuilder(javax.ws.rs.core.UriBuilder) Link(de.micromata.opengis.kml.v_2_2_0.Link) NetworkLink(de.micromata.opengis.kml.v_2_2_0.NetworkLink) Template(com.github.jknack.handlebars.Template)

Example 2 with NetworkLink

use of de.micromata.opengis.kml.v_2_2_0.NetworkLink in project ddf by codice.

the class KmlEndpoint method generateViewBasedNetworkLink.

/*
     * Generates xml for View-based Network Link
     * 
     * @param networkLinkUrl - url to set as the Link href.
     * 
     * @return Networklink
     */
private NetworkLink generateViewBasedNetworkLink(URL networkLinkUrl, String sourceId) {
    // create network link and give it a name
    NetworkLink networkLink = KmlFactory.createNetworkLink();
    networkLink.setName(sourceId);
    networkLink.setOpen(true);
    networkLink.setVisibility(this.visibleByDefault);
    // create link and add it to networkLinkElements
    Link link = networkLink.createAndSetLink();
    LOGGER.debug("View Based Network Link href: {}", networkLinkUrl.toString());
    link.setHref(networkLinkUrl.toString());
    link.setViewRefreshMode(ViewRefreshMode.ON_STOP);
    link.setViewRefreshTime(DEFAULT_VIEW_REFRESH_TIME);
    link.setViewFormat(VIEW_FORMAT_STRING);
    link.setViewBoundScale(1);
    link.setHttpQuery(COUNT_PARAM + maxResults);
    return networkLink;
}
Also used : NetworkLink(de.micromata.opengis.kml.v_2_2_0.NetworkLink) Link(de.micromata.opengis.kml.v_2_2_0.Link) NetworkLink(de.micromata.opengis.kml.v_2_2_0.NetworkLink)

Example 3 with NetworkLink

use of de.micromata.opengis.kml.v_2_2_0.NetworkLink in project ddf by codice.

the class TestKmlEndpoint method testGetAvailableSourcesWithCount.

@Test
public void testGetAvailableSourcesWithCount() throws UnknownHostException, MalformedURLException, IllegalArgumentException, UriBuilderException, SourceUnavailableException {
    when(mockUriInfo.getQueryParameters(false)).thenReturn(mockMap);
    KmlEndpoint kmlEndpoint = new KmlEndpoint(mockBranding, mockFramework);
    kmlEndpoint.setMaxResults(250);
    Kml response = kmlEndpoint.getAvailableSources(mockUriInfo);
    assertThat(response, notNullValue());
    assertThat(response.getFeature(), instanceOf(Folder.class));
    Folder folder = (Folder) response.getFeature();
    assertThat(folder.getFeature(), notNullValue());
    assertThat(folder.getFeature().size(), is(2));
    assertThat(folder.getFeature().get(0), instanceOf(NetworkLink.class));
    assertThat(folder.getFeature().get(1), instanceOf(NetworkLink.class));
    NetworkLink nl1 = (NetworkLink) folder.getFeature().get(0);
    assertThat(nl1.getName(), anyOf(is(REMOTE_SITE_NAME), is(LOCAL_SITE_NAME)));
    assertThat(nl1.getLink().getHttpQuery(), is("count=250"));
    NetworkLink nl2 = (NetworkLink) folder.getFeature().get(1);
    assertThat(nl2.getName(), anyOf(is(REMOTE_SITE_NAME), is(LOCAL_SITE_NAME)));
    assertThat(nl2.getLink().getHttpQuery(), is("count=250"));
}
Also used : NetworkLink(de.micromata.opengis.kml.v_2_2_0.NetworkLink) Kml(de.micromata.opengis.kml.v_2_2_0.Kml) Folder(de.micromata.opengis.kml.v_2_2_0.Folder) Test(org.junit.Test)

Example 4 with NetworkLink

use of de.micromata.opengis.kml.v_2_2_0.NetworkLink 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)

Example 5 with NetworkLink

use of de.micromata.opengis.kml.v_2_2_0.NetworkLink in project ddf by codice.

the class TestKmlEndpoint method testGetKmlNetworkLink.

@Test
public void testGetKmlNetworkLink() {
    when(mockUriInfo.getQueryParameters(false)).thenReturn(mockMap);
    KmlEndpoint kmlEndpoint = new KmlEndpoint(mockBranding, mockFramework);
    kmlEndpoint.setDescription("This is some description.");
    kmlEndpoint.setLogo("https://tools.codice.org/wiki/download/attachments/3047457/DDF?version=1&modificationDate=1369422662164&api=v2");
    kmlEndpoint.setWebSite("https://tools.codice.org/wiki/display/DDF/DDF+Home");
    Kml response = kmlEndpoint.getKmlNetworkLink(mockUriInfo);
    assertThat(response, notNullValue());
    assertThat(response.getFeature(), instanceOf(NetworkLink.class));
    NetworkLink networkLink = (NetworkLink) response.getFeature();
    Link link = networkLink.getLink();
    assertThat(link, notNullValue());
    assertThat(link.getHref(), notNullValue());
    UriBuilder builder = UriBuilder.fromUri(link.getHref());
    URI uri = builder.build();
    assertThat(uri.getHost(), is(TEST_HOST));
    assertThat(String.valueOf(uri.getPort()), is(TEST_PORT));
    assertThat(uri.getPath(), is("/services/catalog/kml/sources"));
}
Also used : NetworkLink(de.micromata.opengis.kml.v_2_2_0.NetworkLink) Kml(de.micromata.opengis.kml.v_2_2_0.Kml) UriBuilder(javax.ws.rs.core.UriBuilder) URI(java.net.URI) Link(de.micromata.opengis.kml.v_2_2_0.Link) NetworkLink(de.micromata.opengis.kml.v_2_2_0.NetworkLink) Test(org.junit.Test)

Aggregations

NetworkLink (de.micromata.opengis.kml.v_2_2_0.NetworkLink)7 Kml (de.micromata.opengis.kml.v_2_2_0.Kml)6 Folder (de.micromata.opengis.kml.v_2_2_0.Folder)4 Test (org.junit.Test)4 Link (de.micromata.opengis.kml.v_2_2_0.Link)3 UriBuilder (javax.ws.rs.core.UriBuilder)3 Handlebars (com.github.jknack.handlebars.Handlebars)1 Template (com.github.jknack.handlebars.Template)1 SourceInfoResponse (ddf.catalog.operation.SourceInfoResponse)1 SourceInfoRequestEnterprise (ddf.catalog.operation.impl.SourceInfoRequestEnterprise)1 SourceDescriptor (ddf.catalog.source.SourceDescriptor)1 SourceUnavailableException (ddf.catalog.source.SourceUnavailableException)1 IOException (java.io.IOException)1 MalformedURLException (java.net.MalformedURLException)1 URI (java.net.URI)1 UnknownHostException (java.net.UnknownHostException)1 GET (javax.ws.rs.GET)1 Path (javax.ws.rs.Path)1 Produces (javax.ws.rs.Produces)1 WebApplicationException (javax.ws.rs.WebApplicationException)1