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;
}
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;
}
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"));
}
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);
}
}
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"));
}
Aggregations