use of gov.usgs.cida.coastalhazards.model.summary.Summary in project coastal-hazards by USGS-CIDA.
the class StormUtil method buildStormTemplateSummary.
public static Summary buildStormTemplateSummary(Layer layer) {
Summary summary = new Summary();
Document cswDoc = getStormCswDocument(layer);
if (cswDoc != null) {
String title = MetadataUtil.extractFirstStringFromCswDoc(cswDoc, "/*/metadata/idinfo/citation/citeinfo/title");
Map<String, String> titleParts = parseTitleParts(title);
String cswAbstract = MetadataUtil.extractFirstStringFromCswDoc(cswDoc, "/*/metadata/idinfo/descript/abstract");
List<String> dataSrcList = MetadataUtil.extractStringsFromCswDoc(cswDoc, "/*/metadata/dataqual/lineage/srcinfo/srccite/citeinfo/title");
String surgeDescription = buildSurgeDescription(cswDoc);
Tiny tiny = buildTinyText(titleParts);
Medium medium = buildMediumText(titleParts);
Full full = buildFullText(titleParts, title, surgeDescription);
Legend legend = buildLegendText(titleParts);
summary.setTiny(tiny);
summary.setMedium(medium);
summary.setFull(full);
summary.setLegend(legend);
}
return summary;
}
use of gov.usgs.cida.coastalhazards.model.summary.Summary in project coastal-hazards by USGS-CIDA.
the class MetadataResource method getMetadataSummaryByAttribtueUsingItemID.
@GET
@Path("/summarize/itemid/{itemid}/attribute/{attr}")
@Produces(MediaType.APPLICATION_JSON)
public Response getMetadataSummaryByAttribtueUsingItemID(@PathParam("itemid") String itemId, @PathParam("attr") String attr) throws URISyntaxException {
Response response;
try (ItemManager itemManager = new ItemManager()) {
Item item = itemManager.load(itemId);
String jsonSummary = MetadataUtil.getSummaryFromWPS(getMetadataUrl(item), attr);
Summary summary = GsonUtil.getDefault().fromJson(jsonSummary, Summary.class);
response = Response.ok(GsonUtil.getDefault().toJson(summary, Summary.class), MediaType.APPLICATION_JSON_TYPE).build();
} catch (IOException | ParserConfigurationException | SAXException | JsonSyntaxException ex) {
Map<String, String> err = new HashMap<>();
err.put("message", ex.getMessage());
response = Response.serverError().entity(GsonUtil.getDefault().toJson(err, HashMap.class)).build();
}
return response;
}
use of gov.usgs.cida.coastalhazards.model.summary.Summary in project coastal-hazards by USGS-CIDA.
the class TemplateResource method instantiateStormTemplate.
@GET
@Path("/storm")
@Produces(MediaType.APPLICATION_JSON)
@RolesAllowed({ CoastalHazardsTokenBasedSecurityFilter.CCH_ADMIN_ROLE })
public Response instantiateStormTemplate(@Context HttpServletRequest request, @QueryParam("layerId") String layerId, @QueryParam("activeStorm") String active, @QueryParam("alias") String alias, @QueryParam("copyType") String copyType, @QueryParam("copyVal") String copyVal, @QueryParam("trackId") String trackId) {
Response response;
if (layerId != null && active != null) {
Gson gson = GsonUtil.getDefault();
String childJson = null;
childJson = gson.toJson(StormUtil.createStormChildMap(layerId, Boolean.parseBoolean(active), trackId));
if (childJson != null && childJson.length() > 0) {
try (ItemManager itemMan = new ItemManager();
LayerManager layerMan = new LayerManager();
AliasManager aliasMan = new AliasManager()) {
Layer layer = layerMan.load(layerId);
if (layer != null) {
Summary summary = null;
if (copyType.equalsIgnoreCase("item") || copyType.equalsIgnoreCase("alias")) {
summary = copyExistingSummary(copyType, copyVal, itemMan, aliasMan);
} else {
summary = StormUtil.buildStormTemplateSummary(layer);
}
if (summary != null) {
List<Service> services = layer.getServices();
List<Service> serviceCopies = new LinkedList<>();
for (Service service : services) {
serviceCopies.add(Service.copyValues(service, new Service()));
}
Item baseTemplate = baseTemplateItem(Boolean.parseBoolean(active), layer.getBbox(), serviceCopies, summary);
String templateId = itemMan.persist(baseTemplate);
if (templateId != null && templateId.length() > 0) {
response = instantiateTemplate(request, templateId, childJson);
if (response.getStatus() == HttpStatus.SC_OK) {
Map<String, Object> ok = new HashMap<String, Object>() {
private static final long serialVersionUID = 2398472L;
{
put("id", templateId);
}
};
if (alias != null && alias.length() > 0) {
Alias fullAlias = aliasMan.load(alias);
if (fullAlias != null) {
fullAlias.setItemId(templateId);
aliasMan.update(fullAlias);
} else {
fullAlias = new Alias();
fullAlias.setId(alias);
fullAlias.setItemId(templateId);
aliasMan.save(fullAlias);
}
}
response = Response.ok(GsonUtil.getDefault().toJson(ok, HashMap.class), MediaType.APPLICATION_JSON_TYPE).build();
}
} else {
response = Response.status(500).build();
}
} else {
response = Response.status(400).build();
}
} else {
response = Response.status(400).build();
}
} catch (Exception e) {
log.error(e.toString());
response = Response.status(500).build();
}
} else {
response = Response.status(400).build();
}
} else {
response = Response.status(400).build();
}
return response;
}
use of gov.usgs.cida.coastalhazards.model.summary.Summary in project coastal-hazards by USGS-CIDA.
the class TemplateResource method makeItemsFromDocument.
private List<Item> makeItemsFromDocument(Item template, JsonArray children, Map<String, Item> childMap, ItemManager itemMan, LayerManager layerMan) {
Iterator<JsonElement> iterator = children.iterator();
while (iterator.hasNext()) {
String attr = "";
Layer layer;
JsonObject child = iterator.next().getAsJsonObject();
JsonElement childId = child.get("id");
JsonElement attrElement = child.get("attr");
JsonElement layerId = child.get("layerId");
String replaceId = null;
// Generate item JSON from metadata
if (layerId != null) {
layer = layerMan.load(layerId.getAsString());
if (childId != null) {
// Replace the existing item in this place
replaceId = childId.getAsString();
if (childMap.containsKey(replaceId)) {
Item item = itemMan.load(replaceId);
attr = item.getAttr();
} else {
throw new BadRequestException("Specified invalid child to replace");
}
} else if (attrElement != null) {
attr = attrElement.getAsString();
} else {
throw new BadRequestException("Must specify child or attribute to replace/use");
}
Summary summary = makeSummary(layer, attr);
Item newItem = templateItem(template, attr, layer, summary);
if (replaceId == null) {
replaceId = newItem.getId();
}
childMap.put(replaceId, newItem);
} else if (childId != null) {
String retainedChildId = childId.getAsString();
Item retainedChild = itemMan.load(retainedChildId);
if (retainedChild != null) {
childMap.put(retainedChildId, retainedChild);
}
} else {
throw new BadRequestException("Must specify childId if not including layerId");
}
}
return new LinkedList<>(childMap.values());
}
use of gov.usgs.cida.coastalhazards.model.summary.Summary in project coastal-hazards by USGS-CIDA.
the class TemplateResource method gatherTemplateSummary.
protected Summary gatherTemplateSummary(Summary previousSummary, List<Item> children) {
Summary newSummary = Summary.copyValues(previousSummary, null);
String keywords = previousSummary.getKeywords();
Set<String> keywordSet = keywordsFromString(keywords);
Set<Publication> publicationSet = new LinkedHashSet<>();
Full full = previousSummary.getFull();
List<Publication> publications = full.getPublications();
publicationSet.addAll(publications);
if (children != null) {
for (Item item : children) {
Set<String> childKeywords = keywordsFromString(item.getSummary().getKeywords());
keywordSet.addAll(childKeywords);
List<Publication> childPubs = item.getSummary().getFull().getPublications();
for (Publication pub : childPubs) {
publicationSet.add(Publication.copyValues(pub, null));
}
}
}
String newKeywords = StringUtils.join(keywordSet, "|");
newSummary.setKeywords(newKeywords);
newSummary.getFull().setPublications(Lists.newArrayList(publicationSet));
return newSummary;
}
Aggregations