Search in sources :

Example 1 with Link

use of com.baremaps.model.Link 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 Link

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

the class CollectionsResourceIntegrationTest method test.

@Test
public void test() {
    // Create a new collection
    Collection collection = new Collection().title("test").links(List.of(new Link().href("/link").rel("self")));
    // List the collections
    Collections collections = target().path("/collections").request().get(Collections.class);
    assertEquals(0, collections.getCollections().size());
    // Insert the collection
    Response response = target().path("/collections").request(MediaType.APPLICATION_JSON).post(Entity.entity(collection, MediaType.valueOf("application/json")));
    assertEquals(201, response.getStatus());
    // List the collections
    collections = target().path("/collections").request().get(Collections.class);
    assertEquals(1, collections.getCollections().size());
    // Get the collection
    String id = response.getHeaderString("Location").split("/")[4];
    collection = target().path("/collections/" + id).request().get(Collection.class);
    assertEquals("test", collection.getTitle());
    // Update the collection
    collection.setTitle("test_update");
    response = target().path("/collections/" + id).request().put(Entity.entity(collection, MediaType.valueOf("application/json")));
    assertEquals(204, response.getStatus());
    // Delete the collection
    response = target().path("/collections/" + id).request().delete();
    assertEquals(204, response.getStatus());
    // List the collections
    collections = target().path("/collections").request().get(Collections.class);
    assertEquals(0, collections.getCollections().size());
}
Also used : Response(javax.ws.rs.core.Response) Collection(com.baremaps.model.Collection) Collections(com.baremaps.model.Collections) Link(com.baremaps.model.Link) Test(org.junit.Test) JerseyTest(org.glassfish.jersey.test.JerseyTest)

Example 3 with Link

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

the class CollectionsResource method getCollection.

@Override
public Response getCollection(UUID collectionId) {
    Collection collection = jdbi.withHandle(handle -> handle.createQuery("select collection from collections where id = :id").bind("id", collectionId).mapTo(COLLECTION).one());
    collection.getLinks().add(new Link().href(uriInfo.getRequestUri().toString()).rel("self"));
    return Response.ok(collection).build();
}
Also used : Collection(com.baremaps.model.Collection) Link(com.baremaps.model.Link)

Example 4 with Link

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

the class CollectionsResource method getCollections.

@Override
public Response getCollections() {
    List<Collection> collectionList = jdbi.withHandle(handle -> handle.createQuery("select collection from collections").mapTo(COLLECTION).list());
    collectionList.forEach(collection -> collection.getLinks().add(new Link().href(uriInfo.getRequestUri().toString() + "/" + collection.getId()).rel("self")));
    Collections collections = new Collections().collections(collectionList);
    collections.getLinks().add(new Link().href(uriInfo.getRequestUri().toString()).rel("self"));
    return Response.ok(collections).build();
}
Also used : Collection(com.baremaps.model.Collection) Collections(com.baremaps.model.Collections) Link(com.baremaps.model.Link)

Example 5 with Link

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

the class RootResource method getLandingPage.

@Override
public Response getLandingPage() {
    String address = uriInfo.getBaseUri().toString();
    LandingPage landingPage = new LandingPage().title("Baremaps").description("Baremaps OGC API Landing Page").links(Arrays.asList(new Link().title("This document (landing page)").href(address).type("application/json").rel("self"), new Link().title("Conformance declaration").href(address + "conformance").type("application/json").rel("conformance"), new Link().title("API description").href(address + "api").type("application/json").rel("service-desc"), new Link().title("API description").href(address + "api").type("application/yaml").rel("service-desc"), new Link().title("API documentation").href(address + "swagger").type("text/html").rel("service-doc")));
    return Response.ok().entity(landingPage).build();
}
Also used : LandingPage(com.baremaps.model.LandingPage) Link(com.baremaps.model.Link)

Aggregations

Link (com.baremaps.model.Link)5 Collection (com.baremaps.model.Collection)3 Collections (com.baremaps.model.Collections)2 LandingPage (com.baremaps.model.LandingPage)1 StyleSet (com.baremaps.model.StyleSet)1 StyleSetEntry (com.baremaps.model.StyleSetEntry)1 ArrayList (java.util.ArrayList)1 UUID (java.util.UUID)1 Response (javax.ws.rs.core.Response)1 JerseyTest (org.glassfish.jersey.test.JerseyTest)1 Test (org.junit.Test)1