Skip to content
Snippets Groups Projects
Commit fcf8032b authored by Tor-Einar Skog's avatar Tor-Einar Skog
Browse files

Fixed view of weather stations in admin system. Filter for organization.

parent e5cf97d1
Branches
Tags
No related merge requests found
Showing
with 103 additions and 11 deletions
......@@ -19,6 +19,9 @@
package no.bioforsk.vips.logic.controller.servlet;
import com.vividsolutions.jts.geom.Coordinate;
import com.vividsolutions.jts.geom.GeometryFactory;
import com.vividsolutions.jts.geom.Point;
import java.io.IOException;
import java.util.List;
import java.util.TimeZone;
......@@ -29,6 +32,7 @@ import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import no.bioforsk.vips.logic.entity.Country;
import no.bioforsk.vips.logic.entity.Organization;
import no.bioforsk.vips.logic.entity.PointOfInterest;
import no.bioforsk.vips.logic.entity.PointOfInterestWeatherStation;
import no.bioforsk.vips.logic.entity.VipsLogicRole;
......@@ -85,16 +89,46 @@ public class PointOfInterestController extends HttpServlet {
// List view
if(pointOfInterestId == null)
{
Organization organization = null;
List<PointOfInterestWeatherStation> weatherStations;
if(user.isSuperUser()){
weatherStations = SessionControllerGetter.getPointOfInterestBean().getAllWeatherStations();
Integer organizationId = request.getParameter("organizationId") != null ?
Integer.parseInt(request.getParameter("organizationId"))
:user.getOrganizationId().getOrganizationId();
if(organizationId.equals(-1))
{
weatherStations = SessionControllerGetter.getPointOfInterestBean().getAllWeatherStations();
}
else
{
organization = em.find(Organization.class, organizationId);
weatherStations = SessionControllerGetter.getPointOfInterestBean().getWeatherstationsForOrganization(organization);
}
request.setAttribute("organizations", SessionControllerGetter.getUserBean().getOrganizations());
request.setAttribute("organizationId", organizationId);
}
else
{
weatherStations = SessionControllerGetter.getPointOfInterestBean().getWeatherstationsForOrganization(user.getOrganizationId());
organization = user.getOrganizationId();
weatherStations = SessionControllerGetter.getPointOfInterestBean().getWeatherstationsForOrganization(organization);
request.setAttribute("organizationId", organization.getOrganizationId());
}
if(organization != null)
{
request.setAttribute("defaultMapCenter",organization.getDefaultMapCenter());
request.setAttribute("defaultMapZoom", organization.getDefaultMapZoom());
}
else
{
// Set map to cover Europe
GeometryFactory gFact = new GeometryFactory();
Coordinate coord = new Coordinate(16.51699219, 55.39404223);
Point mapCenter = gFact.createPoint(coord);
request.setAttribute("defaultMapCenter",mapCenter);
request.setAttribute("defaultMapZoom", 3);
}
request.setAttribute("defaultMapCenter",user.getOrganizationId().getDefaultMapCenter());
request.setAttribute("defaultMapZoom", user.getOrganizationId().getDefaultMapZoom());
request.getSession().setAttribute("weatherStations", weatherStations);
request.getRequestDispatcher("/weatherstationList.ftl").forward(request, response);
}
......
......@@ -25,6 +25,7 @@ import de.micromata.opengis.kml.v_2_2_0.Kml;
import de.micromata.opengis.kml.v_2_2_0.KmlFactory;
import de.micromata.opengis.kml.v_2_2_0.Placemark;
import de.micromata.opengis.kml.v_2_2_0.Point;
import java.util.ArrayList;
import java.util.List;
import java.util.ResourceBundle;
import javax.ejb.LocalBean;
......@@ -91,7 +92,22 @@ public class PointOfInterestBean {
public Kml getWeatherstationsForOrganization(Integer organizationId, Integer excludeWeatherStationId, Integer highlightWeatherStationId, String serverName, ResourceBundle i18nBundle) {
String iconPath = "http://" + serverName + "/public/images/";
Organization organization = em.find(Organization.class, organizationId);
List<PointOfInterestWeatherStation> weatherStations = new ArrayList<>();
if(organizationId.equals(-1))
{
List<Organization> organizations = em.createNamedQuery("Organization.findAllTopLevelOrganizations").getResultList();
for(Organization organization:organizations)
{
weatherStations.addAll(this.getWeatherstationsForOrganization(organization));
}
}
else
{
weatherStations.addAll(this.getWeatherstationsForOrganization(em.find(Organization.class, organizationId)));
}
// Initialization
final Kml kml = KmlFactory.createKml();
final Document document = kml.createAndSetDocument()
......@@ -111,7 +127,8 @@ public class PointOfInterestBean {
.createAndSetIcon()
.withHref(iconPath + "anemometer_mono.png");
List<PointOfInterestWeatherStation> weatherStations = this.getWeatherstationsForOrganization(organization);
String description = "";
for(PointOfInterestWeatherStation weatherStation:weatherStations)
{
......@@ -158,8 +175,16 @@ public class PointOfInterestBean {
}
public List<PointOfInterestWeatherStation> getWeatherstationsForOrganization(Organization organization) {
return em.createNamedQuery("PointOfInterestWeatherStation.findByOrganizationId", PointOfInterestWeatherStation.class)
List<PointOfInterestWeatherStation> retVal = em.createNamedQuery("PointOfInterestWeatherStation.findByOrganizationId", PointOfInterestWeatherStation.class)
.setParameter("organizationId", organization)
.getResultList();
for(Organization subdivision:organization.getOrganizationSet())
{
retVal.addAll(em.createNamedQuery("PointOfInterestWeatherStation.findByOrganizationId", PointOfInterestWeatherStation.class)
.setParameter("organizationId", subdivision)
.getResultList()
);
}
return retVal;
}
}
......@@ -364,6 +364,15 @@ public class UserBean {
return em.find(Organization.class, organizationId);
}
/**
*
* @return only the organizations without parent
*/
public List<Organization> getTopLevelOrganizations()
{
return em.createNamedQuery("Organization.findAllTopLevelOrganizations").getResultList();
}
/**
* Returns the available user status Ids
* @return
......
......@@ -38,6 +38,7 @@ import javax.validation.constraints.Size;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;
import com.fasterxml.jackson.annotation.JsonIgnore;
import javax.persistence.FetchType;
import org.hibernate.annotations.Type;
/**
......@@ -49,6 +50,7 @@ import org.hibernate.annotations.Type;
@XmlRootElement
@NamedQueries({
@NamedQuery(name = "Organization.findAll", query = "SELECT o FROM Organization o"),
@NamedQuery(name = "Organization.findAllTopLevelOrganizations", query = "SELECT o FROM Organization o WHERE o.parentOrganizationId IS NULL"),
@NamedQuery(name = "Organization.findByOrganizationId", query = "SELECT o FROM Organization o WHERE o.organizationId = :organizationId"),
@NamedQuery(name = "Organization.findByOrganizationName", query = "SELECT o FROM Organization o WHERE o.organizationName = :organizationName"),
@NamedQuery(name = "Organization.findByAddress1", query = "SELECT o FROM Organization o WHERE o.address1 = :address1"),
......@@ -86,7 +88,7 @@ public class Organization implements Serializable {
@Type(type = "org.hibernate.spatial.GeometryType")
@Column(name = "default_map_center", columnDefinition = "Geometry")
private Point defaultMapCenter;
@OneToMany(mappedBy = "parentOrganizationId")
@OneToMany(mappedBy = "parentOrganizationId", fetch = FetchType.EAGER)
private Set<Organization> organizationSet;
@JoinColumn(name = "parent_organization_id", referencedColumnName = "organization_id")
@ManyToOne
......
......@@ -26,8 +26,6 @@ import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.servlet.http.HttpServletRequest;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
......
......@@ -256,3 +256,4 @@ task_UpdateForecastSummaryTableTask_description=This task updates the table for
pestOrganismId=Pest
weatherForecastProvider=Weather forecast service
none=None
allOrganizations=All organizations
......@@ -256,3 +256,4 @@ task_UpdateForecastSummaryTableTask_description=This task updates the table for
pestOrganismId=Pest
weatherForecastProvider=Weather forecast service
none=None
allOrganizations=All organizations
......@@ -255,3 +255,4 @@ task_UpdateForecastSummaryTableTask_description=This task updates the table for
pestOrganismId=Pest
weatherForecastProvider=Weather forecast service
none=None
allOrganizations=All organizations
......@@ -256,3 +256,4 @@ task_UpdateForecastSummaryTableTask_description=This task updates the table for
pestOrganismId=Skadegj\u00f8rer
weatherForecastProvider=V\u00e6rvarslingstjeneste
none=Ingen
allOrganizations=Alle organisasjoner
......@@ -256,3 +256,4 @@ task_UpdateForecastSummaryTableTask_description=This task updates the table for
pestOrganismId=Pest
weatherForecastProvider=Weather forecast service
none=None
allOrganizations=All organizations
......@@ -27,8 +27,14 @@
<script type="text/javascript" src="/js/weatherStationListMap.js"></script>
<script type="text/javascript">
$(document).ready(function() {
initMap([${(defaultMapCenter.x?c)!"0"},${(defaultMapCenter.y?c)!"0"}],${defaultMapZoom!"1"},${user.organizationId.organizationId});
initMap([${(defaultMapCenter.x?c)!"0"},${(defaultMapCenter.y?c)!"0"}],${defaultMapZoom!"1"},${organizationId!user.organizationId.organizationId});
});
function changeOrganization(selectList)
{
var organizationId = selectList.options[selectList.selectedIndex].value;
window.location="/weatherStation?organizationId=" + organizationId;
}
</script>
</#macro>
<#macro page_contents>
......@@ -43,6 +49,19 @@
</div>
</div>
<div class="col-md-4">
<#if user.isSuperUser() >
<div class="form-group">
<label for="organizationId">${i18nBundle.organizationId}</label>
<select name="organizationId" class="form-control" onchange="changeOrganization(this);">
<option value="-1">${i18nBundle.allOrganizations}</option>
<#list organizations?sort_by("organizationName") as organization>
<option value="${organization.organizationId}" <#if organizationId == organization.organizationId> selected="selected"</#if>>
${organization.organizationName}
</option>
</#list>
</select>
</div>
</#if>
<div class="table-responsive">
<table class="table table-striped">
<thead>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment