Search in sources :

Example 1 with Link

use of org.apache.tapestry5.Link in project tapestry5-hotel-booking by ccordenier.

the class View method startBooking.

/**
     * Start booking process.
     * 
     * @param hotel
     * @return link to the current hotel booking
     */
@OnEvent(value = EventConstants.SUCCESS, component = "startBookingForm")
Object startBooking(Hotel hotel) {
    User user = (User) dao.find(User.class, authenticator.getLoggedUser().getId());
    userWorkspace.startBooking(hotel, user);
    return Book.class;
}
Also used : User(com.tap5.hotelbooking.entities.User) OnEvent(org.apache.tapestry5.annotations.OnEvent)

Example 2 with Link

use of org.apache.tapestry5.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.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 3 with Link

use of org.apache.tapestry5.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.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 4 with Link

use of org.apache.tapestry5.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 5 with Link

use of org.apache.tapestry5.Link in project tapestry5-hotel-booking by ccordenier.

the class AuthenticationFilter method dispatchedToLoginPage.

private boolean dispatchedToLoginPage(String pageName) throws IOException {
    if (authenticator.isLoggedIn()) {
        // Logged user should not go back to Signin or Signup
        if (signinPage.equalsIgnoreCase(pageName) || signupPage.equalsIgnoreCase(pageName)) {
            Link link = renderLinkSource.createPageRenderLink(defaultPage);
            response.sendRedirect(link);
            return true;
        }
        return false;
    }
    Component page = componentSource.getPage(pageName);
    if (page.getClass().isAnnotationPresent(AnonymousAccess.class)) {
        return false;
    }
    Link link = renderLinkSource.createPageRenderLink("Signin");
    response.sendRedirect(link);
    return true;
}
Also used : Component(org.apache.tapestry5.runtime.Component) Link(org.apache.tapestry5.Link)

Aggregations

Link (de.micromata.opengis.kml.v_2_2_0.Link)3 NetworkLink (de.micromata.opengis.kml.v_2_2_0.NetworkLink)3 Kml (de.micromata.opengis.kml.v_2_2_0.Kml)2 UriBuilder (javax.ws.rs.core.UriBuilder)2 Handlebars (com.github.jknack.handlebars.Handlebars)1 Template (com.github.jknack.handlebars.Template)1 User (com.tap5.hotelbooking.entities.User)1 IOException (java.io.IOException)1 URI (java.net.URI)1 Link (org.apache.tapestry5.Link)1 OnEvent (org.apache.tapestry5.annotations.OnEvent)1 Component (org.apache.tapestry5.runtime.Component)1 Test (org.junit.Test)1