Search in sources :

Example 31 with Item

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

the class ShorelineTest method testGenerateSLDInfo.

/**
 * Test of generateSLDInfo method, of class Shoreline.
 */
@Test
public void testGenerateSLDInfo() {
    Item item = new Item();
    item.setAttr("Date_");
    item.setId("abcde");
    item.setType(Item.Type.historical);
    List<Service> services = new LinkedList<>();
    Service wmsService = new Service();
    wmsService.setEndpoint("http://test");
    wmsService.setServiceParameter("0");
    wmsService.setType(ServiceType.source_wms);
    services.add(wmsService);
    item.setServices(services);
    Summary summary = new Summary();
    Tiny tiny = new Tiny();
    tiny.setText("Shoreline");
    summary.setTiny(tiny);
    item.setSummary(summary);
    SLDGenerator shoreline = new SLDGenerator(item, item.getId(), null, Shorelines.shorelines);
    Response response = shoreline.generateSLDInfo();
    String json = (String) response.getEntity();
    Map<String, Object> sldInfo = new Gson().fromJson(json, HashMap.class);
    List<Object> bins = (List) sldInfo.get("bins");
    Map<String, Object> bin = (Map) bins.get(0);
    Double year0 = ((List<Double>) bin.get("years")).get(0);
    String color = (String) bin.get("color");
    assertEquals(year0, 0.0f, 0.01f);
    assertEquals(color, "#ff0000");
}
Also used : Tiny(gov.usgs.cida.coastalhazards.model.summary.Tiny) Service(gov.usgs.cida.coastalhazards.model.Service) Gson(com.google.gson.Gson) LinkedList(java.util.LinkedList) Response(javax.ws.rs.core.Response) Item(gov.usgs.cida.coastalhazards.model.Item) Summary(gov.usgs.cida.coastalhazards.model.summary.Summary) List(java.util.List) LinkedList(java.util.LinkedList) HashMap(java.util.HashMap) Map(java.util.Map) Test(org.junit.Test)

Example 32 with Item

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

the class ItemLastUpdateComparatorTest method setup.

@Before
public void setup() {
    // Before the other
    o1 = new Item();
    o1.setId("Object1");
    o1.setLastModified(new Date(12345678));
    // After the other
    o2 = new Item();
    o2.setId("Object2");
    o2.setLastModified(new Date(45678901));
}
Also used : Item(gov.usgs.cida.coastalhazards.model.Item) Date(java.util.Date) Before(org.junit.Before)

Example 33 with Item

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

the class ItemLastUpdateComparatorTest method testMax.

@Test
public void testMax() {
    ItemLastUpdateComparator comparator = new ItemLastUpdateComparator();
    List<Item> items = new ArrayList<>();
    items.add(o1);
    items.add(o2);
    Item max = Collections.max(items, comparator);
    assertThat(o2.getId(), is(equalTo(max.getId())));
}
Also used : Item(gov.usgs.cida.coastalhazards.model.Item) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 34 with Item

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

the class InfoRouter method useInfoJsp.

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

Example 35 with Item

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

the class InfoRouter method useInfoPrintViewJsp.

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

Aggregations

Item (gov.usgs.cida.coastalhazards.model.Item)60 ItemManager (gov.usgs.cida.coastalhazards.jpa.ItemManager)26 Response (javax.ws.rs.core.Response)24 Path (javax.ws.rs.Path)22 LinkedList (java.util.LinkedList)21 GET (javax.ws.rs.GET)20 Produces (javax.ws.rs.Produces)20 HashMap (java.util.HashMap)16 BadRequestException (gov.usgs.cida.coastalhazards.exception.BadRequestException)12 Summary (gov.usgs.cida.coastalhazards.model.summary.Summary)12 JsonObject (com.google.gson.JsonObject)10 ArrayList (java.util.ArrayList)10 Viewable (org.glassfish.jersey.server.mvc.Viewable)10 Gson (com.google.gson.Gson)9 Service (gov.usgs.cida.coastalhazards.model.Service)8 NotFoundException (javax.ws.rs.NotFoundException)8 Test (org.junit.Test)8 JsonElement (com.google.gson.JsonElement)7 StatusManager (gov.usgs.cida.coastalhazards.jpa.StatusManager)7 Status (gov.usgs.cida.coastalhazards.model.util.Status)7