Search in sources :

Example 1 with Kml

use of de.micromata.opengis.kml.v_2_2_0.Kml 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 2 with Kml

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

the class KMLTransformerImpl method getKmlGeoFromWkt.

private Geometry getKmlGeoFromWkt(final String wkt) throws CatalogTransformerException {
    if (StringUtils.isBlank(wkt)) {
        throw new CatalogTransformerException("WKT was null or empty. Unable to preform KML Transform on Metacard.");
    }
    com.vividsolutions.jts.geom.Geometry geo = readGeoFromWkt(wkt);
    Geometry kmlGeo = createKmlGeo(geo);
    if (!Point.class.getSimpleName().equals(geo.getGeometryType())) {
        kmlGeo = addPointToKmlGeo(kmlGeo, geo.getCoordinate());
    }
    return kmlGeo;
}
Also used : Geometry(de.micromata.opengis.kml.v_2_2_0.Geometry) CatalogTransformerException(ddf.catalog.transform.CatalogTransformerException)

Example 3 with Kml

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

the class KMLTransformerImpl method encloseKml.

/**
     * Wrap KML document with the opening and closing kml tags
     *
     * @param document
     * @param folderId
     *            which should be the subscription id if it exists
     * @return completed KML
     */
public static Kml encloseKml(Document doc, String docId, String docName) {
    Kml kml = KmlFactory.createKml();
    if (doc != null) {
        kml.setFeature(doc);
        // Id should be subscription id
        doc.setId(docId);
        doc.setName(docName);
        doc.setOpen(false);
    }
    return kml;
}
Also used : Kml(de.micromata.opengis.kml.v_2_2_0.Kml)

Example 4 with Kml

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

the class KMLTransformerImpl method performDefaultTransformation.

/**
     * The default Transformation from a {@link Metacard} to a KML {@link Placemark}. Protected to
     * easily allow other default transformations.
     *
     * @param entry
     *            - the {@link Metacard} to transform.
     * @param urlToMetacard
     * @return
     * @throws javax.xml.transform.TransformerException
     */
protected Placemark performDefaultTransformation(Metacard entry, String url) throws CatalogTransformerException {
    // wrap metacard to work around classLoader/reflection issues
    entry = new MetacardImpl(entry);
    Placemark kmlPlacemark = KmlFactory.createPlacemark();
    kmlPlacemark.setId("Placemark-" + entry.getId());
    kmlPlacemark.setName(entry.getTitle());
    DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");
    dateFormat.setTimeZone(TimeZone.getTimeZone("GMT"));
    String effectiveTime = null;
    if (entry.getEffectiveDate() == null) {
        effectiveTime = dateFormat.format(new Date());
    } else {
        effectiveTime = dateFormat.format(entry.getEffectiveDate());
    }
    TimeSpan timeSpan = KmlFactory.createTimeSpan();
    timeSpan.setBegin(effectiveTime);
    kmlPlacemark.setTimePrimitive(timeSpan);
    kmlPlacemark.setGeometry(getKmlGeoFromWkt(entry.getLocation()));
    String description = entry.getTitle();
    Handlebars handlebars = new Handlebars(templateLoader);
    handlebars.registerHelpers(templateHelper);
    try {
        Template template = handlebars.compile(DESCRIPTION_TEMPLATE);
        description = template.apply(new HandlebarsMetacard(entry));
        LOGGER.debug(description);
    } catch (IOException e) {
        LOGGER.debug("Failed to apply description Template", e);
    }
    kmlPlacemark.setDescription(description);
    String styleUrl = styleMapper.getStyleForMetacard(entry);
    if (StringUtils.isNotBlank(styleUrl)) {
        kmlPlacemark.setStyleUrl(styleUrl);
    }
    return kmlPlacemark;
}
Also used : TimeSpan(de.micromata.opengis.kml.v_2_2_0.TimeSpan) Placemark(de.micromata.opengis.kml.v_2_2_0.Placemark) Handlebars(com.github.jknack.handlebars.Handlebars) DateFormat(java.text.DateFormat) SimpleDateFormat(java.text.SimpleDateFormat) LineString(com.vividsolutions.jts.geom.LineString) IOException(java.io.IOException) SimpleDateFormat(java.text.SimpleDateFormat) MetacardImpl(ddf.catalog.data.impl.MetacardImpl) Date(java.util.Date) Template(com.github.jknack.handlebars.Template)

Example 5 with Kml

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

Kml (de.micromata.opengis.kml.v_2_2_0.Kml)53 InputStream (java.io.InputStream)34 Test (org.junit.Test)31 Placemark (de.micromata.opengis.kml.v_2_2_0.Placemark)15 BeforeClass (org.junit.BeforeClass)13 NetworkLink (de.micromata.opengis.kml.v_2_2_0.NetworkLink)10 Folder (de.micromata.opengis.kml.v_2_2_0.Folder)9 Geometry (org.locationtech.jts.geom.Geometry)8 Document (de.micromata.opengis.kml.v_2_2_0.Document)7 MetacardImpl (ddf.catalog.data.impl.MetacardImpl)6 Metacard (ddf.catalog.data.Metacard)4 CatalogTransformerException (ddf.catalog.transform.CatalogTransformerException)4 LinearRing (de.micromata.opengis.kml.v_2_2_0.LinearRing)4 MultiGeometry (de.micromata.opengis.kml.v_2_2_0.MultiGeometry)4 ByteArrayInputStream (java.io.ByteArrayInputStream)4 IOException (java.io.IOException)4 UriBuilder (javax.ws.rs.core.UriBuilder)4 Handlebars (com.github.jknack.handlebars.Handlebars)3 Template (com.github.jknack.handlebars.Template)3 Feature (de.micromata.opengis.kml.v_2_2_0.Feature)3