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

chore: Remove unused imports

parent 2f812846
No related branches found
No related tags found
1 merge request!192Wildfly 34
/* /*
* Copyright (c) 2014 NIBIO <http://www.nibio.no/>. * Copyright (c) 2014 NIBIO <http://www.nibio.no/>.
* *
* This program is free software: you can redistribute it and/or modify * This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General
* it under the terms of the GNU Affero General Public License as published by * Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any
* the Free Software Foundation, either version 3 of the License, or * later version.
* (at your option) any later version.
* *
* This program is distributed in the hope that it will be useful, * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied
* but WITHOUT ANY WARRANTY; without even the implied warranty of * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * details.
* GNU Affero General Public License for more details.
* *
* You should have received a copy of the GNU Affero General Public License * You should have received a copy of the GNU Affero General Public License along with this program. If not, see
* along with this program. If not, see <https://www.gnu.org/licenses/>. * <https://www.gnu.org/licenses/>.
* *
*/ */
...@@ -29,10 +27,7 @@ import org.slf4j.Logger; ...@@ -29,10 +27,7 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import no.nibio.vips.i18n.I18nImpl; import no.nibio.vips.i18n.I18nImpl;
import no.nibio.vips.logic.controller.session.ForecastBean;
import no.nibio.vips.logic.controller.session.PointOfInterestBean;
import no.nibio.vips.logic.controller.session.SessionControllerGetter; import no.nibio.vips.logic.controller.session.SessionControllerGetter;
import no.nibio.vips.logic.controller.session.UserBean;
import no.nibio.vips.logic.entity.ForecastConfiguration; import no.nibio.vips.logic.entity.ForecastConfiguration;
import no.nibio.vips.logic.entity.ModelInformation; import no.nibio.vips.logic.entity.ModelInformation;
import no.nibio.vips.logic.entity.Organization; import no.nibio.vips.logic.entity.Organization;
...@@ -49,34 +44,32 @@ import no.nibio.web.forms.FormField; ...@@ -49,34 +44,32 @@ import no.nibio.web.forms.FormField;
* @copyright 2013-2022 <a href="http://www.nibio.no/">NIBIO</a> * @copyright 2013-2022 <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>
*/ */
public class RunAllForecastConfigurationsTask extends VipsLogicTask{ public class RunAllForecastConfigurationsTask extends VipsLogicTask {
private static Logger LOGGER = LoggerFactory.getLogger(RunAllForecastConfigurationsTask.class); private static Logger LOGGER = LoggerFactory.getLogger(RunAllForecastConfigurationsTask.class);
private I18nImpl i18n; private I18nImpl i18n;
//private boolean DEBUG=true;
// private boolean DEBUG=true;
@Override @Override
public void execute(TaskExecutionContext tec) throws RuntimeException { public void execute(TaskExecutionContext tec) throws RuntimeException {
Integer weatherStationPointOfInterestId = null; Integer weatherStationPointOfInterestId = null;
if(this.getConfiguration() != null && this.getConfiguration().get("weatherStationPointOfInterestId") != null) if (this.getConfiguration() != null && this.getConfiguration().get("weatherStationPointOfInterestId") != null) {
{ weatherStationPointOfInterestId =
weatherStationPointOfInterestId = Integer.valueOf(this.getConfiguration().get("weatherStationPointOfInterestId")[0]); Integer.valueOf(this.getConfiguration().get("weatherStationPointOfInterestId")[0]);
} }
// Is organization configured? In that case, pick only one. Otherwhise, pick em all // Is organization configured? In that case, pick only one. Otherwhise, pick em all
// The config could come from a form // The config could come from a form
if(this.getConfiguration() != null && this.getConfiguration().get("organizationId") != null) if (this.getConfiguration() != null && this.getConfiguration().get("organizationId") != null) {
{ this.setOrganization(SessionControllerGetter.getUserBean()
this.setOrganization(SessionControllerGetter.getUserBean().getOrganization(Integer.valueOf(this.getConfiguration().get("organizationId")[0]))); .getOrganization(Integer.valueOf(this.getConfiguration().get("organizationId")[0])));
} }
List<Organization> organizations = new ArrayList<>(); List<Organization> organizations = new ArrayList<>();
if(this.getOrganization() != null) if (this.getOrganization() != null) {
{
organizations.add(this.getOrganization()); organizations.add(this.getOrganization());
} } else {
else
{
organizations = SessionControllerGetter.getUserBean().getOrganizations(); organizations = SessionControllerGetter.getUserBean().getOrganizations();
} }
tec.setCompleteness(0d); tec.setCompleteness(0d);
...@@ -85,98 +78,99 @@ public class RunAllForecastConfigurationsTask extends VipsLogicTask{ ...@@ -85,98 +78,99 @@ public class RunAllForecastConfigurationsTask extends VipsLogicTask{
StringBuilder errorMessage = new StringBuilder(); StringBuilder errorMessage = new StringBuilder();
// Get all organizations, loop, get all current forecasts, loop, run models, store results // Get all organizations, loop, get all current forecasts, loop, run models, store results
boolean noForecastConfigurationsFound = true; boolean noForecastConfigurationsFound = true;
Map<String, ModelInformation> modelInformationMap = SessionControllerGetter.getForecastBean().getIndexedBatchableModelInformation(); Map<String, ModelInformation> modelInformationMap =
SessionControllerGetter.getForecastBean().getIndexedBatchableModelInformation();
for(Organization organization : organizations)
{ for (Organization organization : organizations) {
List<ForecastConfiguration> currentForecastConfigurations = SessionControllerGetter.getForecastBean().getForecastConfigurationsValidAtTime(organization, SystemTime.getSystemTime()); List<ForecastConfiguration> currentForecastConfigurations = SessionControllerGetter.getForecastBean()
//System.out.println("Current forecasts for " + organization.getOrganizationName() + ":" + currentForecastConfigurations.size()); .getForecastConfigurationsValidAtTime(organization, SystemTime.getSystemTime());
if(currentForecastConfigurations != null && !currentForecastConfigurations.isEmpty()) // System.out.println("Current forecasts for " + organization.getOrganizationName() + ":" +
{ // currentForecastConfigurations.size());
if (currentForecastConfigurations != null && !currentForecastConfigurations.isEmpty()) {
noForecastConfigurationsFound = false; noForecastConfigurationsFound = false;
for(ForecastConfiguration forecastConfiguration:currentForecastConfigurations) for (ForecastConfiguration forecastConfiguration : currentForecastConfigurations) {
{ if (forecastConfiguration.getUseGridWeatherData()
if(forecastConfiguration.getUseGridWeatherData() && forecastConfiguration.getWeatherStationPointOfInterestId() == null) && forecastConfiguration.getWeatherStationPointOfInterestId() == null) {
{
errorMessage.append( errorMessage.append(
SchedulingUtil.createSchedulingMessageHTML( SchedulingUtil.createSchedulingMessageHTML(
"Error with forecast #" + forecastConfiguration.getForecastConfigurationId() + " (" + forecastConfiguration.getLocationPointOfInterestId().getName() + " - " + modelInformationMap.get(forecastConfiguration.getModelId()).getDefaultName() + ")", "Error with forecast #" + forecastConfiguration.getForecastConfigurationId()
"The forecast is configured to use gridded weather data, but the organization " + forecastConfiguration.getVipsLogicUserId().getOrganizationId().getOrganizationName() + " has not set its gridded weather data source. Please contact the system administrator.", + " (" + forecastConfiguration.getLocationPointOfInterestId().getName()
SchedulingUtil.MESSAGE_STATUS_WARNING + " - "
) + modelInformationMap.get(forecastConfiguration.getModelId())
); .getDefaultName()
+ ")",
"The forecast is configured to use gridded weather data, but the organization "
+ forecastConfiguration.getVipsLogicUserId().getOrganizationId()
.getOrganizationName()
+ " has not set its gridded weather data source. Please contact the system administrator.",
SchedulingUtil.MESSAGE_STATUS_WARNING));
totalNumberofForecastConfigurations++; totalNumberofForecastConfigurations++;
} } else if (weatherStationPointOfInterestId == null
else if( || weatherStationPointOfInterestId <= 0
weatherStationPointOfInterestId == null || (forecastConfiguration.getWeatherStationPointOfInterestId() != null
|| weatherStationPointOfInterestId <= 0 && forecastConfiguration.getWeatherStationPointOfInterestId()
|| ( .getPointOfInterestId() != null
forecastConfiguration.getWeatherStationPointOfInterestId() != null && forecastConfiguration.getWeatherStationPointOfInterestId().getPointOfInterestId()
&& forecastConfiguration.getWeatherStationPointOfInterestId().getPointOfInterestId() != null .equals(weatherStationPointOfInterestId)))
&& forecastConfiguration.getWeatherStationPointOfInterestId().getPointOfInterestId().equals(weatherStationPointOfInterestId)
)
)
{ {
try try {
{
totalNumberofForecastConfigurations++; totalNumberofForecastConfigurations++;
LOGGER.debug("Running forecast #" + forecastConfiguration.getForecastConfigurationId()); LOGGER.debug("Running forecast #" + forecastConfiguration.getForecastConfigurationId());
SessionControllerGetter.getForecastBean().runForecast(forecastConfiguration); SessionControllerGetter.getForecastBean().runForecast(forecastConfiguration);
numberOfCompletedForecastConfigurations++; numberOfCompletedForecastConfigurations++;
} } catch (PreprocessorException | RunModelException ex) {
catch (PreprocessorException | RunModelException ex)
{
errorMessage errorMessage
.append( .append(
SchedulingUtil.createSchedulingMessageHTML( SchedulingUtil.createSchedulingMessageHTML(
"Error with forecast #" + forecastConfiguration.getForecastConfigurationId() + " (" + forecastConfiguration.getLocationPointOfInterestId().getName() + " - " + modelInformationMap.get(forecastConfiguration.getModelId()).getDefaultName() + ")", "Error with forecast #"
ex.getMessage(), + forecastConfiguration.getForecastConfigurationId() + " ("
SchedulingUtil.MESSAGE_STATUS_DANGER) + forecastConfiguration.getLocationPointOfInterestId()
); .getName()
+ " - "
+ modelInformationMap
.get(forecastConfiguration.getModelId())
.getDefaultName()
+ ")",
ex.getMessage(),
SchedulingUtil.MESSAGE_STATUS_DANGER));
} }
} }
if(totalNumberofForecastConfigurations > 0) if (totalNumberofForecastConfigurations > 0) {
{
noForecastConfigurationsFound = false; noForecastConfigurationsFound = false;
tec.setCompleteness(Double.valueOf(numberOfCompletedForecastConfigurations)/Double.valueOf(totalNumberofForecastConfigurations)); tec.setCompleteness(Double.valueOf(numberOfCompletedForecastConfigurations)
} / Double.valueOf(totalNumberofForecastConfigurations));
else } else {
{
noForecastConfigurationsFound = true; noForecastConfigurationsFound = true;
} }
} }
} }
} }
if(noForecastConfigurationsFound) if (noForecastConfigurationsFound) {
{ tec.setCompleteness(1.0);
tec.setCompleteness(1.0); tec.setStatusMessage("No current forecast configurations were found");
tec.setStatusMessage("No current forecast configurations were found");
} }
if(tec.getTaskExecutor().getCompleteness() != 1.0 || ! errorMessage.isEmpty()) if (tec.getTaskExecutor().getCompleteness() != 1.0 || !errorMessage.isEmpty()) {
{ // System.out.println("Error detected, RuntimeException thrown just after this");
//System.out.println("Error detected, RuntimeException thrown just after this");
tec.setStatusMessage(errorMessage.toString()); tec.setStatusMessage(errorMessage.toString());
throw new RuntimeException(); throw new RuntimeException();
} }
} }
@Override @Override
public boolean supportsStatusTracking() public boolean supportsStatusTracking() {
{
return true; return true;
} }
@Override @Override
public boolean supportsCompletenessTracking() public boolean supportsCompletenessTracking() {
{
return true; return true;
} }
...@@ -197,18 +191,19 @@ public class RunAllForecastConfigurationsTask extends VipsLogicTask{ ...@@ -197,18 +191,19 @@ public class RunAllForecastConfigurationsTask extends VipsLogicTask{
.append(" \"required\":false,") .append(" \"required\":false,")
.append(" \"options\": ["); .append(" \"options\": [");
retVal.append(" {\"value\":\"") retVal.append(" {\"value\":\"")
.append("-1") .append("-1")
.append("\", \"label\":\"") .append("\", \"label\":\"")
.append(this.getI18nImpl().getText("pleaseSelect", language)).append(" ").append(this.getI18nImpl().getText("weatherStationPointOfInterestId", language).toLowerCase()) .append(this.getI18nImpl().getText("pleaseSelect", language)).append(" ")
.append("\",\"selected\":") .append(this.getI18nImpl().getText("weatherStationPointOfInterestId", language).toLowerCase())
.append("false") .append("\",\"selected\":")
.append("}\n"); .append("false")
List<PointOfInterestWeatherStation> stations = SessionControllerGetter.getPointOfInterestBean().getAllWeatherStations(); .append("}\n");
List<PointOfInterestWeatherStation> stations =
SessionControllerGetter.getPointOfInterestBean().getAllWeatherStations();
Collections.sort(stations); Collections.sort(stations);
for(PointOfInterest station:stations) for (PointOfInterest station : stations) {
{
retVal.append(" ,{\"value\":\"") retVal.append(" ,{\"value\":\"")
.append(station.getPointOfInterestId()) .append(station.getPointOfInterestId())
.append("\", \"label\":\"") .append("\", \"label\":\"")
...@@ -218,9 +213,9 @@ public class RunAllForecastConfigurationsTask extends VipsLogicTask{ ...@@ -218,9 +213,9 @@ public class RunAllForecastConfigurationsTask extends VipsLogicTask{
.append("}\n"); .append("}\n");
} }
retVal .append(" ]") retVal.append(" ]")
.append(" }"); .append(" }");
retVal .append(" ,{") retVal.append(" ,{")
.append(" \"name\":\"organizationId\",") .append(" \"name\":\"organizationId\",")
.append(" \"dataType\":\"").append(FormField.DATA_TYPE_INTEGER).append("\",") .append(" \"dataType\":\"").append(FormField.DATA_TYPE_INTEGER).append("\",")
.append(" \"fieldType\":\"").append(FormField.FIELD_TYPE_SELECT_SINGLE).append("\",") .append(" \"fieldType\":\"").append(FormField.FIELD_TYPE_SELECT_SINGLE).append("\",")
...@@ -228,18 +223,18 @@ public class RunAllForecastConfigurationsTask extends VipsLogicTask{ ...@@ -228,18 +223,18 @@ public class RunAllForecastConfigurationsTask extends VipsLogicTask{
.append(" \"required\":false,") .append(" \"required\":false,")
.append(" \"options\": ["); .append(" \"options\": [");
retVal.append(" {\"value\":\"") retVal.append(" {\"value\":\"")
.append("-1") .append("-1")
.append("\", \"label\":\"") .append("\", \"label\":\"")
.append(this.getI18nImpl().getText("pleaseSelect", language)).append(" ").append(this.getI18nImpl().getText("organizationId", language).toLowerCase()) .append(this.getI18nImpl().getText("pleaseSelect", language)).append(" ")
.append("\",\"selected\":") .append(this.getI18nImpl().getText("organizationId", language).toLowerCase())
.append("false") .append("\",\"selected\":")
.append("}\n"); .append("false")
.append("}\n");
List<Organization> organizations = SessionControllerGetter.getUserBean().getOrganizations(); List<Organization> organizations = SessionControllerGetter.getUserBean().getOrganizations();
//Collections.sort(organizations); // Collections.sort(organizations);
for(Organization organization:organizations) for (Organization organization : organizations) {
{
retVal.append(" ,{\"value\":\"") retVal.append(" ,{\"value\":\"")
.append(organization.getOrganizationId()) .append(organization.getOrganizationId())
.append("\", \"label\":\"") .append("\", \"label\":\"")
...@@ -249,7 +244,7 @@ public class RunAllForecastConfigurationsTask extends VipsLogicTask{ ...@@ -249,7 +244,7 @@ public class RunAllForecastConfigurationsTask extends VipsLogicTask{
.append("}\n"); .append("}\n");
} }
retVal .append(" ]") retVal.append(" ]")
.append(" }") .append(" }")
.append(" ]") .append(" ]")
.append("}"); .append("}");
...@@ -258,13 +253,11 @@ public class RunAllForecastConfigurationsTask extends VipsLogicTask{ ...@@ -258,13 +253,11 @@ public class RunAllForecastConfigurationsTask extends VipsLogicTask{
return retVal.toString(); return retVal.toString();
} }
private I18nImpl getI18nImpl() private I18nImpl getI18nImpl() {
{ if (this.i18n == null) {
if(this.i18n == null)
{
this.i18n = new I18nImpl("no.nibio.vips.logic.i18n.vipslogictexts"); this.i18n = new I18nImpl("no.nibio.vips.logic.i18n.vipslogictexts");
} }
return this.i18n; return this.i18n;
} }
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment