Search in sources :

Example 1 with StyleSet

use of com.baremaps.model.StyleSet in project baremaps by baremaps.

the class StylesResource method getStyleSet.

@Override
public Response getStyleSet() {
    List<UUID> ids = jdbi.withHandle(handle -> handle.createQuery("select id from styles").mapTo(UUID.class).list());
    StyleSet styleSet = new StyleSet();
    List<StyleSetEntry> entries = new ArrayList<>();
    String address = uriInfo.getRequestUri().toString();
    for (UUID id : ids) {
        Link link = new Link();
        link.setHref(address + id);
        link.setType("application/vnd.mapbox.style+json");
        link.setRel("stylesheet");
        StyleSetEntry entry = new StyleSetEntry();
        entry.setId(id);
        entry.setLinks(List.of(link));
        entries.add(entry);
    }
    styleSet.setStyles(entries);
    return Response.ok(styleSet).build();
}
Also used : StyleSetEntry(com.baremaps.model.StyleSetEntry) ArrayList(java.util.ArrayList) UUID(java.util.UUID) StyleSet(com.baremaps.model.StyleSet) Link(com.baremaps.model.Link)

Example 2 with StyleSet

use of com.baremaps.model.StyleSet in project baremaps by baremaps.

the class StylesResourceIntegrationTest method test.

@Test
public void test() {
    // List the styles
    StyleSet styles = target().path("/styles").request().get(StyleSet.class);
    assertEquals(0, styles.getStyles().size());
    // Create a new style with the service
    MbStyle style = new MbStyle();
    style.setName("test");
    target().path("/styles").request(MediaType.APPLICATION_JSON).post(Entity.entity(style, MediaType.valueOf("application/vnd.mapbox.style+json")));
    // List the styles
    styles = target().path("/styles").request().get(StyleSet.class);
    assertEquals(1, styles.getStyles().size());
    // Get the style
    UUID id = styles.getStyles().get(0).getId();
    style = target().path("/styles/" + id).request().get(MbStyle.class);
    assertEquals("test", style.getName());
    // Delete the style
    target().path("/styles/" + styles.getStyles().get(0).getId()).request().delete();
    // List the styles
    styles = target().path("/styles").request().get(StyleSet.class);
    assertEquals(0, styles.getStyles().size());
}
Also used : UUID(java.util.UUID) StyleSet(com.baremaps.model.StyleSet) MbStyle(com.baremaps.model.MbStyle) Test(org.junit.Test) JerseyTest(org.glassfish.jersey.test.JerseyTest)

Aggregations

StyleSet (com.baremaps.model.StyleSet)2 UUID (java.util.UUID)2 Link (com.baremaps.model.Link)1 MbStyle (com.baremaps.model.MbStyle)1 StyleSetEntry (com.baremaps.model.StyleSetEntry)1 ArrayList (java.util.ArrayList)1 JerseyTest (org.glassfish.jersey.test.JerseyTest)1 Test (org.junit.Test)1