// Path: src/main/java/org/centralperf/service/BootstrapService.java
// @Service
// public class BootstrapService implements InitializingBean {
// 
//     @Resource
//     private ConfigurationService configurationService;
// 
//     @Resource
//     private ScriptService scriptService;
// 
//     @Resource
//     private ProjectService projectService;
// 
//     @Resource
//     private BootstrapServiceFiles bootstrapServiceFiles;
// 
//     @Resource
//     private RunRepository runRepository;
// 
//     private static final Logger log = LoggerFactory.getLogger(BootstrapService.class);
// 
//     /**
//      * Check if it's necessary to launch bootstrap.
//      * If the user has already imported sample data or refused it, then it returns false
//      *
//      * @return true if already initialized, false otherwise
//      */
//     public boolean isAlreadyInitialized() {
//         Boolean initialized = Boolean.parseBoolean(configurationService.getConfigurationValue(Configuration.INITIALIZED));
//         return initialized != null ? initialized : false;
//     }
// 
//     public void setInitialized() {
//         // Update configuration, set as initialized
//         configurationService.updateConfigurationValue(Configuration.INITIALIZED, Boolean.TRUE.toString());
//     }
// 
//     public void importSamples() {
// 
//         // Create sample Projet
//         Project sampleProject = new Project();
//         sampleProject.setName("Sample project");
//         sampleProject.setDescription("Central Perf default sample Project");
//         projectService.addProject(sampleProject);
// 
//         // Associate sample script
//         // Load sample JMX and Gatling files
//         String jmxContent;
//         //String gatlingContent;
//         jmxContent = new Scanner(bootstrapServiceFiles.getSampleJMXFile()).useDelimiter("\\Z").next();
//         scriptService.addScript(sampleProject, JMeterSampler.UID, "JMETER Sample script", "Central Perf sample JMETER script. Queries a single URL with few scenario's parameters", jmxContent);
//         //gatlingContent = new Scanner(bootstrapServiceFiles.getSampleGatlingFile().getFile()).useDelimiter("\\Z").next();
//         //scriptService.addScript(sampleProject,GatlingSampler.UID, "GATLING Sample script", "Central Perf sample script. Queries Google; only for demonstration (no parameters)", gatlingContent);
//         // Import sample resuts
//         // TODO : Import sample result
//     }
// 
//     /**
//      * Check if jobs where running while the application stopped (after a crash for example ...)
//      * These runs should not be running on startup
//      */
//     private void fixIncompleteRuns() {
//         List<Run> incompleteRuns = runRepository.findByRunning(true);
//         for (Run incompleteRun : incompleteRuns) {
//             incompleteRun.setRunning(false);
//             incompleteRun.setComment(
//                     (incompleteRun.getComment() != null ? incompleteRun.getComment() : "") +
//                             "\r\n*** System message : this run didn't complete normally *** ");
//             runRepository.save(incompleteRun);
//         }
//     }
// 
//     /**
//      * Launched after container started
//      *
//      * @throws Exception
//      */
//     @Override
//     public void afterPropertiesSet() throws Exception {
//         log.debug("Launch bootstrap actions");
// 
//         log.debug("fix uncomplete runs");
//         fixIncompleteRuns();
//     }
// 
// }


import javax.annotation.Resource;
import org.centralperf.service.BootstrapService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
/*
 * Copyright (C) 2014  The Central Perf authors
 *
 * 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 <http://www.gnu.org/licenses/>.
 */

package org.centralperf.controller;



/**
 * The Bootstrap controller is used when CP is launched for the first time, to propose to initialize with samples
 * 
 * @since 1.0
 * 
 */
@Controller
public class BootstrapController {
	
	@Resource
// Path: src/main/java/org/centralperf/service/BootstrapService.java
// @Service
// public class BootstrapService implements InitializingBean {
// 
//     @Resource
//     private ConfigurationService configurationService;
// 
//     @Resource
//     private ScriptService scriptService;
// 
//     @Resource
//     private ProjectService projectService;
// 
//     @Resource
//     private BootstrapServiceFiles bootstrapServiceFiles;
// 
//     @Resource
//     private RunRepository runRepository;
// 
//     private static final Logger log = LoggerFactory.getLogger(BootstrapService.class);
// 
//     /**
//      * Check if it's necessary to launch bootstrap.
//      * If the user has already imported sample data or refused it, then it returns false
//      *
//      * @return true if already initialized, false otherwise
//      */
//     public boolean isAlreadyInitialized() {
//         Boolean initialized = Boolean.parseBoolean(configurationService.getConfigurationValue(Configuration.INITIALIZED));
//         return initialized != null ? initialized : false;
//     }
// 
//     public void setInitialized() {
//         // Update configuration, set as initialized
//         configurationService.updateConfigurationValue(Configuration.INITIALIZED, Boolean.TRUE.toString());
//     }
// 
//     public void importSamples() {
// 
//         // Create sample Projet
//         Project sampleProject = new Project();
//         sampleProject.setName("Sample project");
//         sampleProject.setDescription("Central Perf default sample Project");
//         projectService.addProject(sampleProject);
// 
//         // Associate sample script
//         // Load sample JMX and Gatling files
//         String jmxContent;
//         //String gatlingContent;
//         jmxContent = new Scanner(bootstrapServiceFiles.getSampleJMXFile()).useDelimiter("\\Z").next();
//         scriptService.addScript(sampleProject, JMeterSampler.UID, "JMETER Sample script", "Central Perf sample JMETER script. Queries a single URL with few scenario's parameters", jmxContent);
//         //gatlingContent = new Scanner(bootstrapServiceFiles.getSampleGatlingFile().getFile()).useDelimiter("\\Z").next();
//         //scriptService.addScript(sampleProject,GatlingSampler.UID, "GATLING Sample script", "Central Perf sample script. Queries Google; only for demonstration (no parameters)", gatlingContent);
//         // Import sample resuts
//         // TODO : Import sample result
//     }
// 
//     /**
//      * Check if jobs where running while the application stopped (after a crash for example ...)
//      * These runs should not be running on startup
//      */
//     private void fixIncompleteRuns() {
//         List<Run> incompleteRuns = runRepository.findByRunning(true);
//         for (Run incompleteRun : incompleteRuns) {
//             incompleteRun.setRunning(false);
//             incompleteRun.setComment(
//                     (incompleteRun.getComment() != null ? incompleteRun.getComment() : "") +
//                             "\r\n*** System message : this run didn't complete normally *** ");
//             runRepository.save(incompleteRun);
//         }
//     }
// 
//     /**
//      * Launched after container started
//      *
//      * @throws Exception
//      */
//     @Override
//     public void afterPropertiesSet() throws Exception {
//         log.debug("Launch bootstrap actions");
// 
//         log.debug("fix uncomplete runs");
//         fixIncompleteRuns();
//     }
// 
// }


// Path: src/main/java/org/centralperf/controller/BootstrapController.java
import javax.annotation.Resource;
import org.centralperf.service.BootstrapService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

/*
 * Copyright (C) 2014  The Central Perf authors
 *
 * 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 <http://www.gnu.org/licenses/>.
 */

package org.centralperf.controller;



/**
 * The Bootstrap controller is used when CP is launched for the first time, to propose to initialize with samples
 * 
 * @since 1.0
 * 
 */
@Controller
public class BootstrapController {
	
	@Resource
	BootstrapService bootstrapService;