Search in sources :

Example 1 with Thumbnail

use of gov.usgs.cida.coastalhazards.model.Thumbnail in project coastal-hazards by USGS-CIDA.

the class ThumbnailResource method getList.

@GET
@Path("/")
@Produces(MediaType.APPLICATION_JSON)
public Response getList(@QueryParam("dirty") @DefaultValue("false") boolean dirty) {
    Response response = null;
    try (ThumbnailManager manager = new ThumbnailManager()) {
        List<Thumbnail> thumbnails = manager.loadAll(dirty);
        Gson gson = GsonUtil.getDefault();
        response = Response.ok(gson.toJson(thumbnails, List.class), MediaType.APPLICATION_JSON_TYPE).build();
    }
    return response;
}
Also used : Response(javax.ws.rs.core.Response) ThumbnailManager(gov.usgs.cida.coastalhazards.jpa.ThumbnailManager) Gson(com.google.gson.Gson) List(java.util.List) Thumbnail(gov.usgs.cida.coastalhazards.model.Thumbnail) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 2 with Thumbnail

use of gov.usgs.cida.coastalhazards.model.Thumbnail in project coastal-hazards by USGS-CIDA.

the class ThumbnailResource method putImage.

@RolesAllowed({ CoastalHazardsTokenBasedSecurityFilter.CCH_ADMIN_ROLE })
@PUT
@Path("/item/{id}")
@Consumes(MediaType.TEXT_PLAIN)
@Produces(MediaType.APPLICATION_JSON)
public Response putImage(@PathParam("id") String id, String content, @Context HttpServletRequest request) {
    Response response = null;
    Thumbnail thumb = new Thumbnail();
    thumb.setItemId(id);
    thumb.setImage(content);
    thumb.setDirty(false);
    try (ThumbnailManager manager = new ThumbnailManager()) {
        response = Response.ok(manager.save(thumb), MediaType.APPLICATION_JSON_TYPE).build();
        manager.updateDirtyBits(id);
    }
    return response;
}
Also used : Response(javax.ws.rs.core.Response) ThumbnailManager(gov.usgs.cida.coastalhazards.jpa.ThumbnailManager) Thumbnail(gov.usgs.cida.coastalhazards.model.Thumbnail) Path(javax.ws.rs.Path) RolesAllowed(javax.annotation.security.RolesAllowed) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) PUT(javax.ws.rs.PUT)

Example 3 with Thumbnail

use of gov.usgs.cida.coastalhazards.model.Thumbnail in project coastal-hazards by USGS-CIDA.

the class ThumbnailManager method loadAll.

public List<Thumbnail> loadAll(boolean dirtyOnly) {
    String sql = "select t from Thumbnail t";
    if (dirtyOnly) {
        sql += " where t.dirty = TRUE";
    }
    Query query = em.createQuery(sql);
    List<Thumbnail> resultList = query.getResultList();
    return resultList;
}
Also used : Query(javax.persistence.Query) Thumbnail(gov.usgs.cida.coastalhazards.model.Thumbnail)

Aggregations

Thumbnail (gov.usgs.cida.coastalhazards.model.Thumbnail)3 ThumbnailManager (gov.usgs.cida.coastalhazards.jpa.ThumbnailManager)2 Path (javax.ws.rs.Path)2 Produces (javax.ws.rs.Produces)2 Response (javax.ws.rs.core.Response)2 Gson (com.google.gson.Gson)1 List (java.util.List)1 RolesAllowed (javax.annotation.security.RolesAllowed)1 Query (javax.persistence.Query)1 Consumes (javax.ws.rs.Consumes)1 GET (javax.ws.rs.GET)1 PUT (javax.ws.rs.PUT)1