=== added file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/SchedulingController.java' --- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/SchedulingController.java 1970-01-01 00:00:00 +0000 +++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/SchedulingController.java 2015-02-19 08:48:07 +0000 @@ -0,0 +1,140 @@ +package org.hisp.dhis.webapi.controller; + +/* + * Copyright (c) 2004-2015, University of Oslo + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * Neither the name of the HISP project nor the names of its contributors may + * be used to endorse or promote products derived from this software without + * specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +import static org.hisp.dhis.scheduling.SchedulingManager.TASK_ANALYTICS_ALL; +import static org.hisp.dhis.scheduling.SchedulingManager.TASK_ANALYTICS_LAST_3_YEARS; +import static org.hisp.dhis.scheduling.SchedulingManager.TASK_DATAMART_LAST_YEAR; +import static org.hisp.dhis.scheduling.SchedulingManager.TASK_DATA_SYNCH; +import static org.hisp.dhis.scheduling.SchedulingManager.TASK_MONITORING_LAST_DAY; +import static org.hisp.dhis.scheduling.SchedulingManager.TASK_RESOURCE_TABLE; +import static org.hisp.dhis.scheduling.SchedulingManager.TASK_RESOURCE_TABLE_15_MINS; +import static org.hisp.dhis.system.scheduling.Scheduler.CRON_DAILY_0AM; +import static org.hisp.dhis.system.scheduling.Scheduler.CRON_EVERY_15MIN; +import static org.hisp.dhis.system.scheduling.Scheduler.CRON_EVERY_MIN; + +import java.io.IOException; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.hisp.dhis.common.ListMap; +import org.hisp.dhis.dxf2.common.JacksonUtils; +import org.hisp.dhis.scheduling.SchedulingManager; +import org.hisp.dhis.webapi.utils.ContextUtils; +import org.hisp.dhis.webapi.webdomain.SchedulingStrategy; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.HttpStatus; +import org.springframework.security.access.prepost.PreAuthorize; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; +import org.springframework.web.bind.annotation.ResponseStatus; + +/** + * @author Lars Helge Overland + */ +@Controller +@RequestMapping( value = "/scheduling" ) +public class SchedulingController +{ + private static final String STRATEGY_ALL_DAILY = "allDaily"; + private static final String STRATEGY_ALL_15_MIN = "allEvery15Min"; + private static final String STRATEGY_LAST_3_YEARS_DAILY = "last3YearsDaily"; + private static final String STRATEGY_ENABLED = "enabled"; + + @Autowired + private SchedulingManager schedulingManager; + + @PreAuthorize( "hasRole('ALL') or hasRole('F_SCHEDULING_ADMIN')" ) + @ResponseStatus( value = HttpStatus.OK ) + @RequestMapping( method = { RequestMethod.POST, RequestMethod.PUT }, consumes = { ContextUtils.CONTENT_TYPE_JSON } ) + public void schedule( HttpServletRequest request, HttpServletResponse response ) + throws IOException + { + SchedulingStrategy strategy = JacksonUtils.fromJson( request.getInputStream(), SchedulingStrategy.class ); + + ListMap cronKeyMap = new ListMap<>(); + + // ------------------------------------------------------------- + // Resource tables + // ------------------------------------------------------------- + + if ( STRATEGY_ALL_DAILY.equals( strategy.getResourceTableStrategy() ) ) + { + cronKeyMap.putValue( CRON_DAILY_0AM, TASK_RESOURCE_TABLE ); + } + else if ( STRATEGY_ALL_15_MIN.equals( strategy.getResourceTableStrategy() ) ) + { + cronKeyMap.putValue( CRON_EVERY_15MIN, TASK_RESOURCE_TABLE_15_MINS ); + } + + // ------------------------------------------------------------- + // Analytics + // ------------------------------------------------------------- + + if ( STRATEGY_ALL_DAILY.equals( strategy.getAnalyticsStrategy() ) ) + { + cronKeyMap.putValue( CRON_DAILY_0AM, TASK_ANALYTICS_ALL ); + } + else if ( STRATEGY_LAST_3_YEARS_DAILY.equals( strategy.getAnalyticsStrategy() ) ) + { + cronKeyMap.putValue( CRON_DAILY_0AM, TASK_ANALYTICS_LAST_3_YEARS ); + } + + // ------------------------------------------------------------- + // Data mart + // ------------------------------------------------------------- + + if ( STRATEGY_ALL_DAILY.equals( strategy.getDataMartStrategy() ) ) + { + cronKeyMap.putValue( CRON_DAILY_0AM, TASK_DATAMART_LAST_YEAR ); + } + + // ------------------------------------------------------------- + // Monitoring + // ------------------------------------------------------------- + + if ( STRATEGY_ALL_DAILY.equals( strategy.getMonitoringStrategy() ) ) + { + cronKeyMap.putValue( CRON_DAILY_0AM, TASK_MONITORING_LAST_DAY ); + } + + // ------------------------------------------------------------- + // Data synch + // ------------------------------------------------------------- + + if ( STRATEGY_ENABLED.equals( strategy.getDataSynchStrategy() ) ) + { + cronKeyMap.putValue( CRON_EVERY_MIN, TASK_DATA_SYNCH ); + } + + schedulingManager.scheduleTasks( cronKeyMap ); + } +} === added file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/webdomain/SchedulingStrategy.java' --- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/webdomain/SchedulingStrategy.java 1970-01-01 00:00:00 +0000 +++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/webdomain/SchedulingStrategy.java 2015-02-19 08:48:07 +0000 @@ -0,0 +1,120 @@ +package org.hisp.dhis.webapi.webdomain; + +/* + * Copyright (c) 2004-2015, University of Oslo + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * Neither the name of the HISP project nor the names of its contributors may + * be used to endorse or promote products derived from this software without + * specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +import org.hisp.dhis.common.DxfNamespaces; + +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty; +import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlRootElement; + +/** + * @author Lars Helge Overland + */ +@JacksonXmlRootElement( localName = "scheduling", namespace = DxfNamespaces.DXF_2_0 ) +public class SchedulingStrategy +{ + private String resourceTableStrategy; + + private String analyticsStrategy; + + private String dataMartStrategy; + + private String monitoringStrategy; + + private String dataSynchStrategy; + + public SchedulingStrategy() + { + } + + // ------------------------------------------------------------------------- + // Getters and setters + // ------------------------------------------------------------------------- + + @JsonProperty + @JacksonXmlProperty( namespace = DxfNamespaces.DXF_2_0 ) + public String getResourceTableStrategy() + { + return resourceTableStrategy; + } + + public void setResourceTableStrategy( String resourceTableStrategy ) + { + this.resourceTableStrategy = resourceTableStrategy; + } + + @JsonProperty + @JacksonXmlProperty( namespace = DxfNamespaces.DXF_2_0 ) + public String getAnalyticsStrategy() + { + return analyticsStrategy; + } + + public void setAnalyticsStrategy( String analyticsStrategy ) + { + this.analyticsStrategy = analyticsStrategy; + } + + @JsonProperty + @JacksonXmlProperty( namespace = DxfNamespaces.DXF_2_0 ) + public String getDataMartStrategy() + { + return dataMartStrategy; + } + + public void setDataMartStrategy( String dataMartStrategy ) + { + this.dataMartStrategy = dataMartStrategy; + } + + @JsonProperty + @JacksonXmlProperty( namespace = DxfNamespaces.DXF_2_0 ) + public String getMonitoringStrategy() + { + return monitoringStrategy; + } + + public void setMonitoringStrategy( String monitoringStrategy ) + { + this.monitoringStrategy = monitoringStrategy; + } + + @JsonProperty + @JacksonXmlProperty( namespace = DxfNamespaces.DXF_2_0 ) + public String getDataSynchStrategy() + { + return dataSynchStrategy; + } + + public void setDataSynchStrategy( String dataSynchStrategy ) + { + this.dataSynchStrategy = dataSynchStrategy; + } +} === modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/java/org/hisp/dhis/dataadmin/action/scheduling/ScheduleTasksAction.java' --- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/java/org/hisp/dhis/dataadmin/action/scheduling/ScheduleTasksAction.java 2015-02-17 13:27:11 +0000 +++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/java/org/hisp/dhis/dataadmin/action/scheduling/ScheduleTasksAction.java 2015-02-19 08:48:07 +0000 @@ -65,7 +65,6 @@ import static org.hisp.dhis.system.scheduling.Scheduler.STATUS_RUNNING; import static org.hisp.dhis.system.util.CollectionUtils.emptyIfNull; - /** * @author Lars Helge Overland */