use of gov.usgs.cida.coastalhazards.model.Alias 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.Alias in project coastal-hazards by USGS-CIDA.
the class AliasManager method load.
public Alias load(String id) {
Alias alias = null;
Query selectQuery = em.createQuery(HQL_SELECT_BY_ID);
selectQuery.setParameter("id", id);
List<Alias> resultList = selectQuery.getResultList();
if (!resultList.isEmpty()) {
alias = resultList.get(0);
}
return alias;
}
use of gov.usgs.cida.coastalhazards.model.Alias in project coastal-hazards by USGS-CIDA.
the class AliasManager method getAliasesForItemId.
/**
* Grab all of the aliases associated with the provided item ID
* @return The list of related aliases
*/
public List<Alias> getAliasesForItemId(String itemId) {
if (itemId == null) {
throw new IllegalArgumentException("Item must be valid data item");
}
Query selectQuery = em.createQuery(HQL_SELECT_BY_ITEM_ID);
selectQuery.setParameter("item_id", itemId);
List<Alias> resultList = selectQuery.getResultList();
return resultList;
}
use of gov.usgs.cida.coastalhazards.model.Alias in project coastal-hazards by USGS-CIDA.
the class AliasResource method getAliasById.
@GET
@Path("/{id}")
@Produces(MediaType.APPLICATION_JSON)
public Response getAliasById(@PathParam("id") String id) {
Response response = null;
try (AliasManager manager = new AliasManager()) {
Alias alias = manager.load(id);
Gson gson = GsonUtil.getDefault();
if (alias != null) {
response = Response.ok(gson.toJson(alias), MediaType.APPLICATION_JSON_TYPE).build();
} else {
throw new NotFoundException();
}
}
return response;
}
use of gov.usgs.cida.coastalhazards.model.Alias in project coastal-hazards by USGS-CIDA.
the class InfoRouter method useAliasInfoPrintViewJsp.
@GET
@Produces(MediaType.TEXT_HTML)
@Path("/alias/print/{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();
}
}
}
Aggregations