use of gov.usgs.cida.coastalhazards.model.Item in project coastal-hazards by USGS-CIDA.
the class DownloadUtility method stageSessionDownload.
/**
* TODO stage all the items with some smarts about naming and such
*
* @param stageThis
* @param stagingDir
* @return
* @throws java.io.IOException
*/
public static boolean stageSessionDownload(Session stageThis, File stagingDir) throws IOException, ConcurrentModificationException {
boolean success = false;
lock(stagingDir);
List<String> missing = new LinkedList<>();
try {
Map<WFSService, SingleDownload> downloadMap = new HashMap<>(stageThis.getItems().size());
for (SessionItem sessionItem : stageThis.getItems()) {
Item item;
try (ItemManager itemManager = new ItemManager()) {
item = itemManager.load(sessionItem.getItemId());
}
populateDownloadMap(downloadMap, item);
}
List<String> namesUsed = new ArrayList<>(downloadMap.size());
for (SingleDownload stagedDownload : downloadMap.values()) {
while (namesUsed.contains(stagedDownload.getName())) {
stagedDownload.incrementName();
}
namesUsed.add(stagedDownload.getName());
// TODO try/catch this to isolate/retry problem downloads?
boolean stage = stagedDownload.stage(stagingDir, missing);
success = success || stage;
}
} finally {
writeMissingFile(stagingDir, missing);
writeReadmeFile(stagingDir);
unlock(stagingDir);
}
return success;
}
use of gov.usgs.cida.coastalhazards.model.Item in project coastal-hazards by USGS-CIDA.
the class ShorelineTest method testGenerateSLDInfoSelected.
/**
* Test of generateSLDInfo method, of class Shoreline with an overriding
* selected item.
*/
@Test
public void testGenerateSLDInfoSelected() {
Item item = new Item();
Item selectedItem = new Item();
item.setAttr("Date_");
item.setId("abcd");
item.setType(Item.Type.historical);
selectedItem.setAttr("Date_");
selectedItem.setId("efg");
selectedItem.setType(Item.Type.historical);
selectedItem.setItemType(Item.ItemType.aggregation);
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);
selectedItem.setServices(services);
Summary summary = new Summary();
Tiny tiny = new Tiny();
tiny.setText("Shoreline");
summary.setTiny(tiny);
item.setSummary(summary);
selectedItem.setSummary(summary);
SLDGenerator shoreline = new SLDGenerator(item, selectedItem.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");
}
use of gov.usgs.cida.coastalhazards.model.Item in project coastal-hazards by USGS-CIDA.
the class ShorelineTest method testGenerateSLD.
@Test
public void testGenerateSLD() {
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.generateSLD();
Viewable sld = (Viewable) response.getEntity();
}
use of gov.usgs.cida.coastalhazards.model.Item in project coastal-hazards by USGS-CIDA.
the class ItemLastUpdateComparatorTest method testMin.
@Test
public void testMin() {
ItemLastUpdateComparator comparator = new ItemLastUpdateComparator();
List<Item> items = new ArrayList<>();
items.add(o1);
items.add(o2);
Item min = Collections.min(items, comparator);
assertThat(o1.getId(), is(equalTo(min.getId())));
}
use of gov.usgs.cida.coastalhazards.model.Item in project coastal-hazards by USGS-CIDA.
the class ItemResource method getItem.
/**
* Retrieves representation of an instance of
* gov.usgs.cida.coastalhazards.model.Item
*
* @param id identifier of requested item
* @param subtree whether to return all items below this as a subtree
* @param request request object
* @return JSON representation of the item(s)
*/
@GET
@Path("/{id}")
@Produces(MediaType.APPLICATION_JSON)
public Response getItem(@PathParam("id") String id, @DefaultValue("false") @QueryParam("subtree") boolean subtree, @Context Request request) {
Response response = null;
Item item = null;
try (StatusManager statusMan = new StatusManager()) {
try (ItemManager itemManager = new ItemManager()) {
item = itemManager.load(id);
}
if (item == null) {
throw new NotFoundException();
} else {
// Check when the item and/or structure was last modified, if at all.
// - If both are null, use today's date.
// - If one of the two is not null, use that.
// - Else, if both are not null, use the latest between them.
Status lastItemUpdate = statusMan.load(Status.StatusName.ITEM_UPDATE);
Status lastStructureUpdate = statusMan.load(Status.StatusName.STRUCTURE_UPDATE);
Date modified = new Date();
if (lastItemUpdate != null && lastStructureUpdate != null) {
// Both updates exist, so compare between them and choose the latest
Date lastItemUpdateDate = lastItemUpdate.getLastUpdate();
Date lastStructureUpdateDate = lastStructureUpdate.getLastUpdate();
modified = lastItemUpdateDate.after(lastStructureUpdateDate) ? lastItemUpdateDate : lastStructureUpdateDate;
} else {
// least one exists and use that.
if (lastItemUpdate != null) {
modified = lastItemUpdate.getLastUpdate();
}
if (lastStructureUpdate != null) {
modified = lastStructureUpdate.getLastUpdate();
}
}
Response unmodified = HTTPCachingUtil.checkModified(request, modified);
if (unmodified != null) {
response = unmodified;
} else {
String jsonResult = item.toJSON(subtree);
response = Response.ok(jsonResult, MediaType.APPLICATION_JSON_TYPE).lastModified(modified).build();
}
}
}
return response;
}
Aggregations