Search in sources :

Example 11 with Alias

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

the class AliasResource method getAliasesForItem.

@GET
@Path("/item/{id}")
@Produces(MediaType.APPLICATION_JSON)
public Response getAliasesForItem(@PathParam("id") String itemId) {
    Response response = null;
    try (AliasManager manager = new AliasManager()) {
        List<Alias> aliasList = manager.getAliasesForItemId(itemId);
        Gson gson = GsonUtil.getDefault();
        response = Response.ok(gson.toJson(aliasList, List.class), MediaType.APPLICATION_JSON_TYPE).build();
    }
    return response;
}
Also used : Response(javax.ws.rs.core.Response) AliasManager(gov.usgs.cida.coastalhazards.jpa.AliasManager) Alias(gov.usgs.cida.coastalhazards.model.Alias) Gson(com.google.gson.Gson) List(java.util.List) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 12 with Alias

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

the class AliasResource method postAlias.

@RolesAllowed({ CoastalHazardsTokenBasedSecurityFilter.CCH_ADMIN_ROLE })
@POST
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public Response postAlias(String content, @Context HttpServletRequest request) {
    Response response;
    Alias alias = Alias.fromJSON(content);
    String aliasId = alias != null ? alias.getId() : null;
    try (AliasManager aliasManager = new AliasManager()) {
        Alias savedAlias = aliasManager.load(alias.getId());
        if (savedAlias == null) {
            aliasId = aliasManager.save(alias);
        }
    } catch (RollbackException r) {
        response = Response.status(417).build();
        return response;
    } catch (Exception e) {
        throw new Error();
    }
    if (null == aliasId) {
        throw new Error();
    } else {
        response = Response.ok(GsonUtil.getDefault().toJson(alias, Alias.class), MediaType.APPLICATION_JSON_TYPE).build();
    }
    return response;
}
Also used : Response(javax.ws.rs.core.Response) AliasManager(gov.usgs.cida.coastalhazards.jpa.AliasManager) Alias(gov.usgs.cida.coastalhazards.model.Alias) RollbackException(javax.persistence.RollbackException) BadRequestException(gov.usgs.cida.coastalhazards.exception.BadRequestException) NotFoundException(javax.ws.rs.NotFoundException) RollbackException(javax.persistence.RollbackException) RolesAllowed(javax.annotation.security.RolesAllowed) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces)

Example 13 with Alias

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

the class PrintRouter method useAliasInfoPrintViewJsp.

@GET
@Produces(MediaType.TEXT_HTML)
@Path("/alias/{aliasId}")
public Response useAliasInfoPrintViewJsp(@PathParam("aliasId") String aliasId) {
    Map<String, Object> map = new HashMap<>();
    try (ItemManager mgr = new ItemManager();
        AliasManager amgr = new AliasManager()) {
        Alias alias = amgr.load(aliasId);
        if (alias != null) {
            Item item = mgr.load(alias.getItemId());
            if (item == null) {
                return Response.status(Response.Status.NOT_FOUND).build();
            }
            map.put("item", item);
            map.put("alias", alias);
            return Response.ok(new Viewable("/WEB-INF/jsp/ui/back/index-print.jsp", map)).build();
        } else {
            return Response.status(Response.Status.NOT_FOUND).build();
        }
    }
}
Also used : AliasManager(gov.usgs.cida.coastalhazards.jpa.AliasManager) Item(gov.usgs.cida.coastalhazards.model.Item) HashMap(java.util.HashMap) ItemManager(gov.usgs.cida.coastalhazards.jpa.ItemManager) Alias(gov.usgs.cida.coastalhazards.model.Alias) Viewable(org.glassfish.jersey.server.mvc.Viewable) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Aggregations

Alias (gov.usgs.cida.coastalhazards.model.Alias)13 AliasManager (gov.usgs.cida.coastalhazards.jpa.AliasManager)10 Produces (javax.ws.rs.Produces)10 GET (javax.ws.rs.GET)8 Path (javax.ws.rs.Path)8 Response (javax.ws.rs.core.Response)7 ItemManager (gov.usgs.cida.coastalhazards.jpa.ItemManager)5 Item (gov.usgs.cida.coastalhazards.model.Item)5 Gson (com.google.gson.Gson)4 HashMap (java.util.HashMap)4 NotFoundException (javax.ws.rs.NotFoundException)4 RolesAllowed (javax.annotation.security.RolesAllowed)3 Query (javax.persistence.Query)3 Viewable (org.glassfish.jersey.server.mvc.Viewable)3 Consumes (javax.ws.rs.Consumes)2 JsonObject (com.google.gson.JsonObject)1 JsonSyntaxException (com.google.gson.JsonSyntaxException)1 BadRequestException (gov.usgs.cida.coastalhazards.exception.BadRequestException)1 LayerManager (gov.usgs.cida.coastalhazards.jpa.LayerManager)1 StatusManager (gov.usgs.cida.coastalhazards.jpa.StatusManager)1