Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found
Select Git revision
  • Phytophthoraregistrering-VIPSUTV-735
  • UpdateGrovfor
  • VIPSInSchweiz
  • addIsPrivateToPOI-VIPSUTV-767
  • bugfix/vipsutv-706-observation-without-poi
  • develop
  • feature/time-series
  • feature/time-series-in-vipsweb
  • feature/upgrade-openlayers
  • feature/vipsutv-1047-timeseries
  • feature/vipsutv-405-observation-time-series
  • feature/vipsutv-710-download-excel
  • feature/vipsutv-737-map-module
  • fix/ensure-supported-locale
  • forecast-gridweather-option-vipsutv-610
  • freemarkertest
  • jakartaee-10
  • master
  • renovate-updates
  • renovate/no.nibio.vips-vipscommon-3.x
  • renovate/org.apache.commons-commons-csv-1.x
  • renovate/org.apache.poi-poi-5.x
  • renovate/org.apache.poi-poi-ooxml-5.x
  • renovate/org.flywaydb-flyway-core-11.x
  • renovate/org.flywaydb-flyway-database-postgresql-11.x
  • renovate/org.hibernate-hibernate-core-6.x
  • renovate/org.hibernate.orm-hibernate-spatial-6.x
  • renovate/org.postgresql-postgresql-42.x
  • renovate/selenium-4.x
  • revert-5e539475
  • revert-63b94469
  • revert-df8d2a9d
  • wildfly-34
  • Tag-Phenology-V3
34 results

Target

Select target project
  • VIPS/VIPSLogic
1 result
Select Git revision
  • Phytophthoraregistrering-VIPSUTV-735
  • UpdateGrovfor
  • VIPSInSchweiz
  • addIsPrivateToPOI-VIPSUTV-767
  • bugfix/vipsutv-706-observation-without-poi
  • develop
  • feature/time-series
  • feature/time-series-in-vipsweb
  • feature/upgrade-openlayers
  • feature/vipsutv-1047-timeseries
  • feature/vipsutv-405-observation-time-series
  • feature/vipsutv-710-download-excel
  • feature/vipsutv-737-map-module
  • fix/ensure-supported-locale
  • forecast-gridweather-option-vipsutv-610
  • freemarkertest
  • jakartaee-10
  • master
  • renovate-updates
  • renovate/no.nibio.vips-vipscommon-3.x
  • renovate/org.apache.commons-commons-csv-1.x
  • renovate/org.apache.poi-poi-5.x
  • renovate/org.apache.poi-poi-ooxml-5.x
  • renovate/org.flywaydb-flyway-core-11.x
  • renovate/org.flywaydb-flyway-database-postgresql-11.x
  • renovate/org.hibernate-hibernate-core-6.x
  • renovate/org.hibernate.orm-hibernate-spatial-6.x
  • renovate/org.postgresql-postgresql-42.x
  • renovate/selenium-4.x
  • revert-5e539475
  • revert-63b94469
  • revert-df8d2a9d
  • wildfly-34
  • Tag-Phenology-V3
34 results
Show changes
Showing
with 1514 additions and 1167 deletions
...@@ -27,13 +27,13 @@ import java.text.MessageFormat; ...@@ -27,13 +27,13 @@ import java.text.MessageFormat;
import java.util.Date; import java.util.Date;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import javax.ejb.EJB; import jakarta.ejb.EJB;
import javax.persistence.EntityManager; import jakarta.persistence.EntityManager;
import javax.persistence.PersistenceContext; import jakarta.persistence.PersistenceContext;
import javax.servlet.ServletException; import jakarta.servlet.ServletException;
import javax.servlet.http.HttpServlet; import jakarta.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest; import jakarta.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse; import jakarta.servlet.http.HttpServletResponse;
import no.nibio.vips.logic.controller.session.SchedulingBean; import no.nibio.vips.logic.controller.session.SchedulingBean;
import no.nibio.vips.logic.controller.session.UserBean; import no.nibio.vips.logic.controller.session.UserBean;
import no.nibio.vips.logic.entity.TaskHistory; import no.nibio.vips.logic.entity.TaskHistory;
......
...@@ -31,15 +31,15 @@ import java.util.Map; ...@@ -31,15 +31,15 @@ import java.util.Map;
import java.util.Set; import java.util.Set;
import java.util.regex.Matcher; import java.util.regex.Matcher;
import java.util.regex.Pattern; import java.util.regex.Pattern;
import javax.ejb.EJB; import jakarta.ejb.EJB;
import javax.persistence.EntityManager; import jakarta.persistence.EntityManager;
import javax.persistence.NoResultException; import jakarta.persistence.NoResultException;
import javax.persistence.NonUniqueResultException; import jakarta.persistence.NonUniqueResultException;
import javax.persistence.PersistenceContext; import jakarta.persistence.PersistenceContext;
import javax.servlet.ServletException; import jakarta.servlet.ServletException;
import javax.servlet.http.HttpServlet; import jakarta.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest; import jakarta.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse; import jakarta.servlet.http.HttpServletResponse;
import no.nibio.vips.i18n.LanguageUtil; import no.nibio.vips.i18n.LanguageUtil;
import no.nibio.vips.logic.controller.session.DeleteUserException; import no.nibio.vips.logic.controller.session.DeleteUserException;
import no.nibio.vips.logic.controller.session.UserBean; import no.nibio.vips.logic.controller.session.UserBean;
...@@ -51,6 +51,8 @@ import no.nibio.vips.logic.entity.VipsLogicRole; ...@@ -51,6 +51,8 @@ import no.nibio.vips.logic.entity.VipsLogicRole;
import no.nibio.vips.logic.entity.VipsLogicUser; import no.nibio.vips.logic.entity.VipsLogicUser;
import no.nibio.vips.logic.entity.misc.UserResources; import no.nibio.vips.logic.entity.misc.UserResources;
import no.nibio.vips.logic.i18n.SessionLocaleUtil; import no.nibio.vips.logic.i18n.SessionLocaleUtil;
import no.nibio.vips.logic.modules.barkbeetle.BarkbeetleBean;
import no.nibio.vips.logic.modules.barkbeetle.SeasonTrapsite;
import no.nibio.vips.logic.util.Globals; import no.nibio.vips.logic.util.Globals;
import no.nibio.vips.util.ServletUtil; import no.nibio.vips.util.ServletUtil;
import no.nibio.web.forms.FormField; import no.nibio.web.forms.FormField;
...@@ -71,6 +73,9 @@ public class UserController extends HttpServlet { ...@@ -71,6 +73,9 @@ public class UserController extends HttpServlet {
@EJB @EJB
UserBean userBean; UserBean userBean;
@EJB
BarkbeetleBean barkbeetleBean;
/** /**
* Processes requests for both HTTP <code>GET</code> and <code>POST</code> * Processes requests for both HTTP <code>GET</code> and <code>POST</code>
...@@ -406,9 +411,12 @@ public class UserController extends HttpServlet { ...@@ -406,9 +411,12 @@ public class UserController extends HttpServlet {
Integer userId = Integer.valueOf(request.getParameter("userId")); Integer userId = Integer.valueOf(request.getParameter("userId"));
VipsLogicUser viewUser = em.find(VipsLogicUser.class, userId); VipsLogicUser viewUser = em.find(VipsLogicUser.class, userId);
UserResources userResources = userBean.getUserResources(viewUser); UserResources userResources = userBean.getUserResources(viewUser);
// Barkbeetle module dependencies
List<SeasonTrapsite> userSeasonTrapsites = barkbeetleBean.getSeasonTrapsites(viewUser);
// If some resources connected, render form, otherwise, route to user delete // If some resources connected, render form, otherwise, route to user delete
if(userResources.isEmpty()) if(userResources.isEmpty() && userSeasonTrapsites.isEmpty())
{ {
response.sendRedirect(new StringBuilder(Globals.PROTOCOL + "://").append(ServletUtil.getServerName(request)).append("/user").append("?action=deleteUser&userId=").append(userId).toString()); response.sendRedirect(new StringBuilder(Globals.PROTOCOL + "://").append(ServletUtil.getServerName(request)).append("/user").append("?action=deleteUser&userId=").append(userId).toString());
} }
...@@ -423,7 +431,9 @@ public class UserController extends HttpServlet { ...@@ -423,7 +431,9 @@ public class UserController extends HttpServlet {
request.setAttribute("viewUser", viewUser); request.setAttribute("viewUser", viewUser);
request.setAttribute("userResources", userResources); request.setAttribute("userResources", userResources);
java.util.Collections.sort(users);
request.setAttribute("users", users); request.setAttribute("users", users);
request.setAttribute("userBarkbeetleSeasonTrapsites", userSeasonTrapsites);
request.setAttribute("errorMsg", request.getParameter("errorMsg")); request.setAttribute("errorMsg", request.getParameter("errorMsg"));
request.getRequestDispatcher("/userDeleteForm.ftl").forward(request, response); request.getRequestDispatcher("/userDeleteForm.ftl").forward(request, response);
} }
...@@ -450,7 +460,9 @@ public class UserController extends HttpServlet { ...@@ -450,7 +460,9 @@ public class UserController extends HttpServlet {
// Are there resources connected to this user? // Are there resources connected to this user?
UserResources userResources = userBean.getUserResources(viewUser); UserResources userResources = userBean.getUserResources(viewUser);
if(! userResources.isEmpty()) // Barkbeetle module dependencies
List<SeasonTrapsite> userSeasonTrapsites = barkbeetleBean.getSeasonTrapsites(viewUser);
if(! userResources.isEmpty() || ! userSeasonTrapsites.isEmpty())
{ {
boolean resourcesTransferred = false; boolean resourcesTransferred = false;
try try
...@@ -460,6 +472,7 @@ public class UserController extends HttpServlet { ...@@ -460,6 +472,7 @@ public class UserController extends HttpServlet {
if(transferToUser != null) if(transferToUser != null)
{ {
userBean.transferUserResources(viewUser,transferToUser); userBean.transferUserResources(viewUser,transferToUser);
barkbeetleBean.transferSeasonTrapsites(viewUser,transferToUser);
resourcesTransferred = true; resourcesTransferred = true;
} }
} }
......
/*
* 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 jakarta.ejb.EJB;
import jakarta.servlet.ServletException;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import no.nibio.vips.gis.LonLatStringFormatException;
import no.nibio.vips.logic.controller.session.PointOfInterestBean;
import no.nibio.vips.logic.entity.VipsLogicUser;
import no.nibio.vips.logic.entity.WeatherStationDataSource;
import no.nibio.vips.logic.util.Globals;
import no.nibio.vips.logic.util.SystemTime;
import no.nibio.vips.util.ServletUtil;
import no.nibio.web.forms.FormValidation;
import no.nibio.web.forms.FormValidationException;
import no.nibio.web.forms.FormValidator;;
/**
* 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{
private static Logger LOGGER = LoggerFactory.getLogger(WeatherStationDataSourceController.class);
@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("messageKey", request.getParameter("messageKey") != null ? request.getParameter("messageKey") : null);
request.setAttribute("weatherStationDataSources", wsDataSources);
request.getRequestDispatcher("/weatherStationDataSourceList.ftl").forward(request, response);
}
else if(action.equals("editWeatherStationDataSource") || action.equals("newWeatherStationDataSource"))
{
WeatherStationDataSource weatherStationDataSource = null;
try
{
weatherStationDataSource = poiBean.getWeatherStationDataSource(Integer.valueOf(request.getParameter("weatherStationDataSourceId")));
}
catch(NullPointerException | NumberFormatException ex){}
if(weatherStationDataSource == null)
{
LOGGER.debug("Could not find weather data source with ID = " + request.getParameter("weatherStationDataSourceId"));
weatherStationDataSource = new WeatherStationDataSource();
}
request.setAttribute("messageKey", request.getParameter("messageKey") != null ? request.getParameter("messageKey") : null);
request.setAttribute("weatherStationDataSource", weatherStationDataSource);
request.getRequestDispatcher("/weatherStationDataSourceForm.ftl").forward(request, response);
}
else if(action.equals("weatherStationDataSourceFormSubmit"))
{
try
{
// Check that the provided id is either -1 or it already exists
Integer weatherStationDataSourceId = null;
WeatherStationDataSource weatherStationDataSource;
try
{
weatherStationDataSourceId = Integer.valueOf(request.getParameter("weatherStationDataSourceId"));
}
catch(NullPointerException | NumberFormatException ex)
{
response.sendError(400,"Wrong format of id for weather station data source");
}
if(weatherStationDataSourceId < 0)
{
weatherStationDataSource = new WeatherStationDataSource();
}
else
{
weatherStationDataSource = poiBean.getWeatherStationDataSource(weatherStationDataSourceId);
if(weatherStationDataSource == null)
{
response.sendError(404,"Could not find weather station data source with id=" + weatherStationDataSourceId);
}
}
FormValidation formValidation = FormValidator.validateForm("weatherStationDataSourceForm", request, getServletContext());
if(formValidation.isValid())
{
weatherStationDataSource.setName(formValidation.getFormField("name").getWebValue());
weatherStationDataSource.setDefaultDescription(formValidation.getFormField("defaultDescription").getWebValue());
weatherStationDataSource.setUri(formValidation.getFormField("uri").getWebValue());
weatherStationDataSource.setDatafetchUriExpression(formValidation.getFormField("datafetchUriExpression").getWebValue());
weatherStationDataSource.setInfoUriExpression(formValidation.getFormField("infoUriExpression").getWebValue());
weatherStationDataSource.setIsGrid(formValidation.getFormField("isGrid").getWebValue() != null);
weatherStationDataSource = poiBean.storeWeatherStationDataSource(weatherStationDataSource);
response.sendRedirect(
Globals.PROTOCOL + "://" + ServletUtil.getServerName(request)
+ "/weatherstationdatasource?action=editWeatherStationDataSource&weatherStationDataSourceId=" + weatherStationDataSource.getWeatherStationDataSourceId()
+ "&messageKey=weatherStationDataSourceStored"
);
}
else
{
request.setAttribute("formValidation", formValidation);
request.setAttribute("weatherStationDataSource", weatherStationDataSource);
LOGGER.debug("Form NOT valid. Dispatching");
request.getRequestDispatcher("/weatherStationDataSourceForm.ftl").forward(request, response);
}
}
catch(FormValidationException ex)
{
ex.printStackTrace();
response.sendError(500, ex.getClass().toString() + ": " + ex.getMessage());
}
}
else if(action.equals("deleteWeatherStationDataSource"))
{
try
{
Integer weatherStationDataSourceId = Integer.valueOf(request.getParameter("weatherStationDataSourceId"));
WeatherStationDataSource weatherStationDataSource = poiBean.getWeatherStationDataSource(weatherStationDataSourceId);
if(weatherStationDataSource == null)
{
response.sendError(404,"Could not find weather station data source with id=" + weatherStationDataSourceId);
}
// Check: Can it be deleted? Not if organizations or weatherStations refer to it
if(poiBean.isweatherStationDataSourceDeleteable(weatherStationDataSource))
{
poiBean.deleteWeatherStationDataSource(weatherStationDataSource);
// Redirect to list from which the deleted item has been removed
response.sendRedirect(
Globals.PROTOCOL + "://" + ServletUtil.getServerName(request)
+ "/weatherstationdatasource?messageKey=weatherStationDataSourceDeleted"
);
}
else
{
response.sendError(403,weatherStationDataSource.getName() + " is in use by one or more organizations, so it cannot be deleted. Hit the browser's back button return to your form.");
}
}
catch(NullPointerException | NumberFormatException ex)
{
response.sendError(400,"Wrong format of id for weather station data source");
}
}
}
// <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>
}
...@@ -26,11 +26,11 @@ import java.util.HashSet; ...@@ -26,11 +26,11 @@ import java.util.HashSet;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
import javax.ejb.Stateless; import jakarta.ejb.Stateless;
import javax.persistence.EntityManager; import jakarta.persistence.EntityManager;
import javax.persistence.NoResultException; import jakarta.persistence.NoResultException;
import javax.persistence.PersistenceContext; import jakarta.persistence.PersistenceContext;
import javax.persistence.Query; import jakarta.persistence.Query;
import no.nibio.vips.logic.entity.Message; import no.nibio.vips.logic.entity.Message;
import no.nibio.vips.logic.entity.MessageIllustration; import no.nibio.vips.logic.entity.MessageIllustration;
import no.nibio.vips.logic.entity.MessageIllustrationCaptionLocale; import no.nibio.vips.logic.entity.MessageIllustrationCaptionLocale;
...@@ -43,7 +43,7 @@ import no.nibio.vips.logic.entity.Organization; ...@@ -43,7 +43,7 @@ import no.nibio.vips.logic.entity.Organization;
import no.nibio.vips.logic.entity.VipsLogicUser; import no.nibio.vips.logic.entity.VipsLogicUser;
import no.nibio.vips.logic.util.SystemTime; import no.nibio.vips.logic.util.SystemTime;
import no.nibio.web.forms.FormField; import no.nibio.web.forms.FormField;
import org.apache.commons.fileupload.FileItem; import org.apache.commons.fileupload2.core.FileItem;
import org.apache.commons.io.FilenameUtils; import org.apache.commons.io.FilenameUtils;
/** /**
...@@ -186,7 +186,7 @@ public class MessageBean { ...@@ -186,7 +186,7 @@ public class MessageBean {
cropCategoryIds.add(Integer.valueOf(cropCategoryId)); cropCategoryIds.add(Integer.valueOf(cropCategoryId));
} }
} }
message.setCropCategoryIds(cropCategoryIds.toArray(new Integer[cropCategoryIds.size()])); message.setCropCategoryIds(cropCategoryIds);
return message; return message;
} }
...@@ -224,7 +224,7 @@ public class MessageBean { ...@@ -224,7 +224,7 @@ public class MessageBean {
} }
// Store file // Store file
item.write(illustration); item.write(illustration.toPath());
// Update MessageIllustrations // Update MessageIllustrations
message = em.merge(message); message = em.merge(message);
......
/*
* Copyright (c) 2018 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.session;
import java.util.*;
import jakarta.ejb.EJB;
import jakarta.ejb.Stateless;
import jakarta.persistence.EntityManager;
import jakarta.persistence.PersistenceContext;
import no.nibio.vips.logic.entity.ObservationTimeSeries;
import no.nibio.vips.logic.entity.PointOfInterest;
import no.nibio.vips.logic.entity.VipsLogicUser;
@Stateless
public class ObservationTimeSeriesBean {
@PersistenceContext(unitName = "VIPSLogic-PU")
EntityManager em;
@EJB
PointOfInterestBean pointOfInterestBean;
@EJB
UserBean userBean;
@EJB
ObservationBean observationBean;
public List<ObservationTimeSeries> getObservationTimeSeriesListForUser(VipsLogicUser user) {
List<ObservationTimeSeries> resultList = em.createNamedQuery("ObservationTimeSeries.findByUserId", ObservationTimeSeries.class)
.setParameter("userId", user.getUserId())
.getResultList();
this.enrichObservationTimeSeriesListWithPointOfInterest(resultList);
this.enrichObservationTimeSeriesListWithObservers(resultList);
return resultList;
}
/**
* Get observation time series with given id. Enrich object with user information before returning.
* @param observationTimeSeriesId the id of the observation time series to retrieve
* @return the observation time series with the given id
*/
public ObservationTimeSeries getObservationTimeSeries(Integer observationTimeSeriesId) {
ObservationTimeSeries ots = em.find(ObservationTimeSeries.class, observationTimeSeriesId);
if (ots != null) {
ots.setUser(em.find(VipsLogicUser.class, ots.getUserId()));
if (ots.getLastModifiedBy() != null) {
ots.setLastModifiedByUser(em.find(VipsLogicUser.class, ots.getLastModifiedBy()));
}
}
return ots;
}
public List<ObservationTimeSeries> getObservationTimeSeriesList(Set<Integer> observationTimeSeriesIds) {
return em.createNamedQuery("ObservationTimeSeries.findByObservationTimeSeriesIds")
.setParameter("observationTimeSeriesIds", observationTimeSeriesIds)
.getResultList();
}
/**
* @param ots the observation time series
* @return The merged object
*/
public ObservationTimeSeries storeObservationTimeSeries(ObservationTimeSeries ots) {
return em.merge(ots);
}
public void deleteObservationTimeSeries(Integer id) {
ObservationTimeSeries observationTimeSeries = em.find(ObservationTimeSeries.class, id);
if (observationTimeSeries != null) {
// The app prevents deletion of time series with observations
observationBean.deleteObservationsForObservationTimeSeries(observationTimeSeries);
em.remove(observationTimeSeries);
}
}
/**
* Enrich given list of observation time series with point of interest information
*
* @param otsList The list of observation time series to enrich
*/
public void enrichObservationTimeSeriesListWithPointOfInterest(List<ObservationTimeSeries> otsList) {
Set<Integer> locationPoiIds = new HashSet<>();
otsList.stream().filter((o) -> (o.getLocationPointOfInterestId() != null)).forEach((o) -> {
locationPoiIds.add(o.getLocationPointOfInterestId());
});
if (locationPoiIds.isEmpty()) {
return;
}
List<PointOfInterest> pois = pointOfInterestBean.getPois(locationPoiIds);
Map<Integer, PointOfInterest> mappedPois = new HashMap<>();
pois.stream().forEach((poi) -> {
mappedPois.put(poi.getPointOfInterestId(), poi);
});
otsList.stream().filter((o) -> (o.getLocationPointOfInterestId() != null)).forEach((o) -> {
o.setLocationPointOfInterest(mappedPois.get(o.getLocationPointOfInterestId()));
});
}
/**
* Enrich given observation time series with point of interest information
*
* @param ots The observation time series to enrich
*/
public void enrichObservationTimeSeriesWithPointOfInterest(ObservationTimeSeries ots) {
if (ots == null || ots.getLocationPointOfInterestId() == null) {
return;
}
ots.setLocationPointOfInterest(pointOfInterestBean.getPointOfInterest(ots.getLocationPointOfInterestId()));
}
/**
* Enrich given list of observation time series with user information
*
* @param otsList The list of observation time series to enrich
*/
private void enrichObservationTimeSeriesListWithObservers(List<ObservationTimeSeries> otsList) {
Set<Integer> userIds = new HashSet<>();
otsList.stream().filter((o) -> (o.getUserId() != null)).forEach((o) -> {
userIds.add(o.getUserId());
});
if (userIds.isEmpty()) {
return;
}
List<VipsLogicUser> users = userBean.getUsers(userIds);
Map<Integer, VipsLogicUser> mappedUsers = new HashMap<>();
users.stream().forEach((user) -> {
mappedUsers.put(user.getUserId(), user);
});
otsList.stream().filter((o) -> (o.getUserId() != null)).forEach((o) -> {
o.setUser(mappedUsers.get(o.getUserId()));
});
}
}
...@@ -33,11 +33,11 @@ import java.util.HashSet; ...@@ -33,11 +33,11 @@ import java.util.HashSet;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
import javax.ejb.Stateless; import jakarta.ejb.Stateless;
import javax.persistence.EntityManager; import jakarta.persistence.EntityManager;
import javax.persistence.NoResultException; import jakarta.persistence.NoResultException;
import javax.persistence.PersistenceContext; import jakarta.persistence.PersistenceContext;
import javax.persistence.Query; import jakarta.persistence.Query;
import no.nibio.vips.logic.entity.CropCategory; import no.nibio.vips.logic.entity.CropCategory;
import no.nibio.vips.logic.entity.CropPest; import no.nibio.vips.logic.entity.CropPest;
import no.nibio.vips.logic.entity.DbUpdate; import no.nibio.vips.logic.entity.DbUpdate;
...@@ -419,7 +419,7 @@ public class OrganismBean { ...@@ -419,7 +419,7 @@ public class OrganismBean {
cropCategories.stream() cropCategories.stream()
.filter((cc) -> (cc.getCropOrganismIds() != null)) .filter((cc) -> (cc.getCropOrganismIds() != null))
.forEachOrdered((cc) -> { .forEachOrdered((cc) -> {
retVal.addAll(Arrays.asList(cc.getCropOrganismIds())); retVal.addAll(cc.getCropOrganismIds());
}); });
return retVal; return retVal;
......
...@@ -33,13 +33,13 @@ import java.util.List; ...@@ -33,13 +33,13 @@ import java.util.List;
import java.util.ResourceBundle; import java.util.ResourceBundle;
import java.util.Set; import java.util.Set;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import javax.ejb.EJB; import jakarta.ejb.EJB;
import javax.ejb.LocalBean; import jakarta.ejb.LocalBean;
import javax.ejb.Stateless; import jakarta.ejb.Stateless;
import javax.persistence.EntityManager; import jakarta.persistence.EntityManager;
import javax.persistence.NoResultException; import jakarta.persistence.NoResultException;
import javax.persistence.PersistenceContext; import jakarta.persistence.PersistenceContext;
import javax.persistence.Query; import jakarta.persistence.Query;
import no.nibio.vips.gis.GISUtil; import no.nibio.vips.gis.GISUtil;
import no.nibio.vips.logic.entity.ExternalResource; import no.nibio.vips.logic.entity.ExternalResource;
import no.nibio.vips.logic.entity.ExternalResourceType; import no.nibio.vips.logic.entity.ExternalResourceType;
...@@ -263,10 +263,54 @@ public class PointOfInterestBean { ...@@ -263,10 +263,54 @@ public class PointOfInterestBean {
return kml; return kml;
} }
public WeatherStationDataSource getWeatherStationDataSource(Integer weatherStationDataSourceId)
{
return em.find(WeatherStationDataSource.class, weatherStationDataSourceId);
}
public List<WeatherStationDataSource> getWeatherStationDataSources() { public List<WeatherStationDataSource> getWeatherStationDataSources() {
return em.createNamedQuery("WeatherStationDataSource.findAll").getResultList(); return em.createNamedQuery("WeatherStationDataSource.findAll").getResultList();
} }
public List<WeatherStationDataSource> getGridWeatherStationDataSources() {
return em.createNamedQuery("WeatherStationDataSource.findGridSources").getResultList();
}
/**
* Checks if the weather station data source can be deleted from the system. Criteria:
* <ul>
* <li>Not referenced from public.point_of_interest_weather_station</li>
* <li>Not referenced from public.organization</li>
* </ul>
* @param weatherStationDataSource
* @return
*/
public Boolean isweatherStationDataSourceDeleteable(WeatherStationDataSource weatherStationDataSource)
{
Query poiRefQuery = em.createQuery("SELECT COUNT(*) FROM PointOfInterestWeatherStation poiws where poiws.weatherStationDataSourceId = :weatherStationDataSourceId");
Long weatherStationReferences = (Long) poiRefQuery.setParameter("weatherStationDataSourceId", weatherStationDataSource).getSingleResult();
if(weatherStationReferences > 0)
{
return false;
}
Query orgRefQuery = em.createQuery("SELECT COUNT(*) FROM Organization o where o.defaultGridWeatherStationDataSource = :weatherStationDataSourceId");
Long organizationReferences = (Long) orgRefQuery.setParameter("weatherStationDataSourceId", weatherStationDataSource).getSingleResult();
return organizationReferences == 0;
}
public void deleteWeatherStationDataSource(WeatherStationDataSource weatherStationDataSource)
{
WeatherStationDataSource sourceToDelete = em.find(WeatherStationDataSource.class, weatherStationDataSource.getWeatherStationDataSourceId());
em.remove(sourceToDelete);
}
public WeatherStationDataSource storeWeatherStationDataSource(WeatherStationDataSource weatherStationDataSource)
{
weatherStationDataSource = em.merge(weatherStationDataSource);
return weatherStationDataSource;
}
public PointOfInterestWeatherStation storeWeatherStation(PointOfInterestWeatherStation weatherStation) { public PointOfInterestWeatherStation storeWeatherStation(PointOfInterestWeatherStation weatherStation) {
weatherStation = em.merge(weatherStation); weatherStation = em.merge(weatherStation);
return weatherStation; return weatherStation;
......
...@@ -37,16 +37,16 @@ import java.util.Set; ...@@ -37,16 +37,16 @@ import java.util.Set;
import java.util.SortedMap; import java.util.SortedMap;
import java.util.TimeZone; import java.util.TimeZone;
import java.util.TreeMap; import java.util.TreeMap;
import javax.ejb.EJB; import jakarta.ejb.EJB;
import javax.ejb.Stateless; import jakarta.ejb.Stateless;
import javax.persistence.EntityManager; import jakarta.persistence.EntityManager;
import javax.persistence.PersistenceContext; import jakarta.persistence.PersistenceContext;
import javax.persistence.Query; import jakarta.persistence.Query;
import javax.ws.rs.client.Client; import jakarta.ws.rs.client.Client;
import javax.ws.rs.client.ClientBuilder; import jakarta.ws.rs.client.ClientBuilder;
import javax.ws.rs.client.WebTarget; import jakarta.ws.rs.client.WebTarget;
import javax.ws.rs.core.GenericType; import jakarta.ws.rs.core.GenericType;
import javax.ws.rs.core.Response; import jakarta.ws.rs.core.Response;
import no.nibio.vips.coremanager.service.ManagerResource; import no.nibio.vips.coremanager.service.ManagerResource;
import no.nibio.vips.entity.ModelConfiguration; import no.nibio.vips.entity.ModelConfiguration;
import no.nibio.vips.entity.ModelRunRequest; import no.nibio.vips.entity.ModelRunRequest;
...@@ -217,9 +217,6 @@ public class SchedulingBean { ...@@ -217,9 +217,6 @@ public class SchedulingBean {
sendForecastNotificationsCollector.getTasks().add(morningAndAfternoonPattern, VipsLogicTaskFactory.createVipsLogicTask(VipsLogicTaskFactory.SEND_FORECAST_EVENT_NOTIFICATIONS_TASK)); sendForecastNotificationsCollector.getTasks().add(morningAndAfternoonPattern, VipsLogicTaskFactory.createVipsLogicTask(VipsLogicTaskFactory.SEND_FORECAST_EVENT_NOTIFICATIONS_TASK));
// Run grid models
VIPSLogicTaskCollector runGridModelsCollector = new VIPSLogicTaskCollector(-1);
runGridModelsCollector.getTasks().add(morningAndAfternoonPattern, VipsLogicTaskFactory.createVipsLogicTask(VipsLogicTaskFactory.RUN_GRID_MODELS_TASK));
List<TaskCollector> definedTasks = new ArrayList<>(); List<TaskCollector> definedTasks = new ArrayList<>();
definedTasks.add(modelRunCollector); definedTasks.add(modelRunCollector);
...@@ -227,7 +224,6 @@ public class SchedulingBean { ...@@ -227,7 +224,6 @@ public class SchedulingBean {
definedTasks.add(summariesCollector); definedTasks.add(summariesCollector);
definedTasks.add(deleteAllExpiredUserUuidsCollector); definedTasks.add(deleteAllExpiredUserUuidsCollector);
definedTasks.add(sendForecastNotificationsCollector); definedTasks.add(sendForecastNotificationsCollector);
definedTasks.add(runGridModelsCollector);
return definedTasks; return definedTasks;
} }
......
...@@ -26,7 +26,7 @@ import no.nibio.vips.logic.messaging.MessagingBean; ...@@ -26,7 +26,7 @@ import no.nibio.vips.logic.messaging.MessagingBean;
/** /**
* Thought this was oblivious because of @EJB, but it turns out this is necessary when invoking beans from outside managed beans! * Thought this was oblivious because of @EJB, but it turns out this is necessary when invoking beans from outside managed beans!
* @copyright 2013-2022 <a href="http://www.nibio.no/">NIBIO</a> * @copyright 2013-2025 <a href="http://www.nibio.no/">NIBIO</a>
* @author Tor-Einar Skog <tor-einar.skog@nibio.no> * @author Tor-Einar Skog <tor-einar.skog@nibio.no>
*/ */
...@@ -34,7 +34,7 @@ public class SessionControllerGetter { ...@@ -34,7 +34,7 @@ public class SessionControllerGetter {
// This obviously has to be changed when changing the application name in Maven // This obviously has to be changed when changing the application name in Maven
// TODO: Refactor out to System properties (e.g. in standalone.xml in JBoss/WildFly) // TODO: Refactor out to System properties (e.g. in standalone.xml in JBoss/WildFly)
public static final String JNDI_PATH = "java:global/VIPSLogic-2024.1/"; public static final String JNDI_PATH = "java:global/VIPSLogic-2025.1/";
public static SchedulingBean getSchedulingBean() public static SchedulingBean getSchedulingBean()
{ {
......
...@@ -41,14 +41,14 @@ import java.util.Set; ...@@ -41,14 +41,14 @@ import java.util.Set;
import java.util.UUID; import java.util.UUID;
import java.util.logging.Level; import java.util.logging.Level;
import java.util.logging.Logger; import java.util.logging.Logger;
import javax.ejb.EJB; import jakarta.ejb.EJB;
import javax.ejb.LocalBean; import jakarta.ejb.LocalBean;
import javax.ejb.Stateless; import jakarta.ejb.Stateless;
import javax.persistence.*; import jakarta.persistence.*;
import javax.servlet.http.HttpServletRequest; import jakarta.servlet.http.HttpServletRequest;
import javax.validation.ConstraintViolation; import jakarta.validation.ConstraintViolation;
import javax.validation.ConstraintViolationException; import jakarta.validation.ConstraintViolationException;
import javax.ws.rs.core.HttpHeaders; import jakarta.ws.rs.core.HttpHeaders;
import no.nibio.vips.logic.authenticate.PasswordValidationException; import no.nibio.vips.logic.authenticate.PasswordValidationException;
import no.nibio.vips.logic.entity.*; import no.nibio.vips.logic.entity.*;
......
...@@ -21,19 +21,19 @@ package no.nibio.vips.logic.entity; ...@@ -21,19 +21,19 @@ package no.nibio.vips.logic.entity;
import java.io.Serializable; import java.io.Serializable;
import java.util.Locale; import java.util.Locale;
import java.util.Set; import java.util.Set;
import javax.persistence.Basic; import jakarta.persistence.Basic;
import javax.persistence.Column; import jakarta.persistence.Column;
import javax.persistence.Entity; import jakarta.persistence.Entity;
import javax.persistence.Id; import jakarta.persistence.Id;
import javax.persistence.JoinColumn; import jakarta.persistence.JoinColumn;
import javax.persistence.JoinTable; import jakarta.persistence.JoinTable;
import javax.persistence.ManyToMany; import jakarta.persistence.ManyToMany;
import javax.persistence.NamedQueries; import jakarta.persistence.NamedQueries;
import javax.persistence.NamedQuery; import jakarta.persistence.NamedQuery;
import javax.persistence.OneToMany; import jakarta.persistence.OneToMany;
import javax.persistence.Table; import jakarta.persistence.Table;
import javax.validation.constraints.NotNull; import jakarta.validation.constraints.NotNull;
import javax.validation.constraints.Size; import jakarta.validation.constraints.Size;
import javax.xml.bind.annotation.XmlRootElement; import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient; import javax.xml.bind.annotation.XmlTransient;
import com.fasterxml.jackson.annotation.JsonIgnore; import com.fasterxml.jackson.annotation.JsonIgnore;
......