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

Add admin for weather station data sources: Main menu item and default page (list)

parent 8f1fd006
No related branches found
No related tags found
1 merge request!191Add map module and Open-Meteo support
Showing
with 170 additions and 0 deletions
/*
* Copyright (c) 2024 NIBIO <http://www.nibio.no/>.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
*/
package no.nibio.vips.logic.controller.servlet;
import java.io.IOException;
import java.util.List;
import javax.ejb.EJB;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import no.nibio.vips.logic.controller.session.PointOfInterestBean;
import no.nibio.vips.logic.entity.VipsLogicUser;
import no.nibio.vips.logic.entity.WeatherStationDataSource;;
/**
* Handles actions regarding listing and modifying weather station data sources
*
* @copyright 2024 <a href="http://www.nibio.no/">NIBIO</a>
* @author Tor-Einar Skog <tor-einar.skog@nibio.no>
*/
public class WeatherStationDataSourceController extends HttpServlet{
@EJB
PointOfInterestBean poiBean;
/**
* Processes requests for both HTTP <code>GET</code> and <code>POST</code> methods.
* @param request servlet request
* @param response servlet response
* @throws ServletException if a servlet-specific error occurs
* @throws IOException if an I/O error occurs
*/
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html;charset=UTF-8");
VipsLogicUser user = (VipsLogicUser) request.getSession().getAttribute("user");
// Basic authorization
if(!user.isSuperUser() && ! user.isOrganizationAdmin()){
response.sendError(403,"Access not authorized");
return;
}
String action = request.getParameter("action");
if(action == null)
{
List<WeatherStationDataSource> wsDataSources = poiBean.getWeatherStationDataSources();
request.setAttribute("weatherStationDataSources", wsDataSources);
request.getRequestDispatcher("/weatherStationDataSourceList.ftl").forward(request, response);
}
}
// <editor-fold defaultstate="collapsed" desc="HttpServlet methods. Click on the + sign on the left to edit the code.">
/**
* Handles the HTTP <code>GET</code> method.
* @param request servlet request
* @param response servlet response
* @throws ServletException if a servlet-specific error occurs
* @throws IOException if an I/O error occurs
*/
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
processRequest(request, response);
}
/**
* Handles the HTTP <code>POST</code> method.
* @param request servlet request
* @param response servlet response
* @throws ServletException if a servlet-specific error occurs
* @throws IOException if an I/O error occurs
*/
@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
processRequest(request, response);
}
/**
* Returns a short description of the servlet.
* @return a String containing servlet description
*/
@Override
public String getServletInfo() {
return "Short description";
}// </editor-fold>
}
......@@ -1055,3 +1055,5 @@ thresholdDSVTempMin=Minimum temperature for DSV calculation
useGridWeatherData=Use grid weather data
doNotUse=Do not use
defaultGridWeatherStationDataSource=Gridded weather data source
weatherStationDataSources=Weather station data sources
newWeatherStationDataSource=New weather (station) data source
......@@ -1049,3 +1049,5 @@ thresholdDSVTempMin=Minimum temperature for DSV calculation
useGridWeatherData=Use grid weather data
doNotUse=Do not use
defaultGridWeatherStationDataSource=Gridded weather data source
weatherStationDataSources=Weather station data sources
newWeatherStationDataSource=New weather (station) data source
......@@ -1047,3 +1047,5 @@ thresholdDSVTempMin=Minimum temperature for DSV calculation
useGridWeatherData=Use grid weather data
doNotUse=Do not use
defaultGridWeatherStationDataSource=Gridded weather data source
weatherStationDataSources=Weather station data sources
newWeatherStationDataSource=New weather (station) data source
......@@ -1055,3 +1055,5 @@ thresholdDSVTempMin=Minimumstemperatur for beregning av DSV
useGridWeatherData=Bruk v\u00e6rdata fra rutenett
doNotUse=Ikke bruk
defaultGridWeatherStationDataSource=GRID-basert v\u00e6rdatakilde
weatherStationDataSources=V\u00e6r(stasjons)datakilder
newWeatherStationDataSource=Ny v\u00e6r(stasjons)datakilde
......@@ -1049,3 +1049,5 @@ thresholdDSVTempMin=Minimum temperature for DSV calculation
useGridWeatherData=Use grid weather data
doNotUse=Do not use
defaultGridWeatherStationDataSource=Gridded weather data source
weatherStationDataSources=Weather station data sources
newWeatherStationDataSource=New weather (station) data source
......@@ -1043,3 +1043,5 @@ thresholdDSVTempMin=Minimum temperature for DSV calculation
useGridWeatherData=Use grid weather data
doNotUse=Do not use
defaultGridWeatherStationDataSource=Gridded weather data source
weatherStationDataSources=Weather station data sources
newWeatherStationDataSource=New weather (station) data source
......@@ -79,6 +79,10 @@
<servlet-name>CropCategoryController</servlet-name>
<servlet-class>no.nibio.vips.logic.controller.servlet.CropCategoryController</servlet-class>
</servlet>
<servlet>
<servlet-name>WeatherStationDataSourceController</servlet-name>
<servlet-class>no.nibio.vips.logic.controller.servlet.WeatherStationDataSourceController</servlet-class>
</servlet>
<servlet>
<servlet-name>JSEnvironment</servlet-name>
<servlet-class>no.nibio.vips.logic.web.js.JSEnvironment</servlet-class>
......@@ -156,6 +160,10 @@
<servlet-name>CropCategoryController</servlet-name>
<url-pattern>/organism/cropcategory</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>WeatherStationDataSourceController</servlet-name>
<url-pattern>/weatherstationdatasource</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>JSEnvironment</servlet-name>
<url-pattern>/js/environment.js</url-pattern>
......
......@@ -59,6 +59,9 @@
<#else>
<li><a href="/user?action=viewUser&userId=${user.userId}">${i18nBundle.myAccount}</a></li>
</#if>
<#if user.isOrganizationAdmin() || user.isSuperUser()>
<li><a href="/weatherstationdatasource">${i18nBundle.weatherStationDataSources}</a></li>
</#if>
<li><a href="/poi">${i18nBundle.pois}</a></li>
<#if user.isOrganizationAdmin() || user.isSuperUser() || user.isMessageAuthor()>
<li><a href="/message">${i18nBundle.messages}</a></li>
......
<#--
Copyright (c) 2024 NIBIO <http://www.nibio.no/>.
This file is part of VIPSLogic.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
--><#include "master.ftl">
<#macro page_head>
<title>${i18nBundle.weatherStationDataSources}</title>
</#macro>
<#macro custom_css>
</#macro>
<#macro custom_js>
</#macro>
<#macro page_contents>
<div class="singleBlockContainer">
<h1>${i18nBundle.weatherStationDataSources}</h1>
<#if messageKey?has_content>
<div class="alert alert-success">${i18nBundle(messageKey)}</div>
</#if>
<ul>
<#list weatherStationDataSources as dSource>
<li><a href="/weatherstationdatasource?action=editWeatherStationDataSource&weatherStationDataSourceId=${dSource.weatherStationDataSourceId}">${dSource.name}</a></li>
</#list>
</ul>
<p><a href="/weatherstationdatasource??action=newWeatherStationDataSource" class="btn btn-default back" role="button">${i18nBundle.newWeatherStationDataSource}</a></p>
</div>
</#macro>
<@page_html/>
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment