Search in sources :

Example 1 with Link

use of org.dishevelled.bio.assembly.gfa1.Link 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)

Example 2 with Link

use of org.dishevelled.bio.assembly.gfa1.Link in project ddf by codice.

the class KmlEndpointTest 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)

Example 3 with Link

use of org.dishevelled.bio.assembly.gfa1.Link 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.EXTERNAL.constructUrl(FORWARD_SLASH + CATALOG_URL_PATH + FORWARD_SLASH + KML_TRANSFORM_PARAM + FORWARD_SLASH + "sources", true), 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 4 with Link

use of org.dishevelled.bio.assembly.gfa1.Link 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);
    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 5 with Link

use of org.dishevelled.bio.assembly.gfa1.Link in project candlepin by candlepin.

the class RootResourceTest method getMethodEntryWithTrailingSlash.

@Test
public void getMethodEntryWithTrailingSlash() throws NoSuchMethodException {
    Method m = FooResource.class.getMethod("methodWithTrailingSlash");
    Link result = rootResource.methodLink("hello_world", m);
    assertEquals("hello_world", result.getRel());
    assertEquals("/foo/trailingslash", result.getHref());
}
Also used : Method(java.lang.reflect.Method) Link(org.candlepin.dto.api.v1.Link) Test(org.junit.jupiter.api.Test)

Aggregations

Link (org.candlepin.dto.api.v1.Link)8 Link (org.apache.tapestry5.Link)6 PrintWriter (java.io.PrintWriter)5 Method (java.lang.reflect.Method)5 Link (org.dishevelled.bio.assembly.gfa1.Link)5 Link (de.micromata.opengis.kml.v_2_2_0.Link)4 NetworkLink (de.micromata.opengis.kml.v_2_2_0.NetworkLink)4 HashMap (java.util.HashMap)4 Gfa1Adapter (org.dishevelled.bio.assembly.gfa1.Gfa1Adapter)4 CommandLineParseException (org.dishevelled.commandline.CommandLineParseException)4 Test (org.junit.jupiter.api.Test)4 Kml (de.micromata.opengis.kml.v_2_2_0.Kml)3 Map (java.util.Map)3 UriBuilder (javax.ws.rs.core.UriBuilder)3 JSONObject (org.apache.tapestry5.json.JSONObject)3 BufferedReader (java.io.BufferedReader)2 URI (java.net.URI)2 Path (javax.ws.rs.Path)2 AfterRender (org.apache.tapestry5.annotations.AfterRender)2 Containment (org.dishevelled.bio.assembly.gfa1.Containment)2