Merged PR 36: refinements
This commit is contained in:
@@ -24,9 +24,15 @@ public class ExecutionController {
|
||||
return scenarioExecutionRepository.findById(id).get();
|
||||
}
|
||||
|
||||
@PostMapping("/updateRating")
|
||||
public String updateScenarioExecRating(@RequestBody ScenarioExecution scenarioExecution){
|
||||
String result = scenarioExecutionService.updateRating(scenarioExecution);
|
||||
// @PostMapping("/updateRating")
|
||||
// public String updateScenarioExecRating(@RequestBody ScenarioExecution scenarioExecution){
|
||||
// String result = scenarioExecutionService.updateRating2(scenarioExecution);
|
||||
// return result;
|
||||
// }
|
||||
|
||||
@GetMapping("/updateRating")
|
||||
public String updateScenarioExecRating(@RequestParam String id, @RequestParam String rating){
|
||||
String result = scenarioExecutionService.updateRating(id, rating);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,58 @@
|
||||
package com.olympus.hermione.controllers;
|
||||
|
||||
import java.io.File;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.ModelAttribute;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import com.olympus.dto.FileUploadDTO;
|
||||
import com.olympus.model.apollo.KSDocument;
|
||||
import com.olympus.model.apollo.KSIngestionInfo;
|
||||
|
||||
@RestController
|
||||
public class FileController {
|
||||
|
||||
private static final String UPLOAD_DIR = "C:\\mnt\\hermione_storage\\documents\\file_input_scenarios\\";
|
||||
|
||||
@PostMapping("/uploadListFiles")
|
||||
public ResponseEntity<String> uploadFiles(
|
||||
@RequestParam("MultiFileUpload") List<MultipartFile> files) {
|
||||
|
||||
long timestamp = System.currentTimeMillis();
|
||||
int randomNum = new Random().nextInt(1000); // Numero random tra 0 e 999
|
||||
|
||||
// Crea un nome di cartella basato sulla data e sul numero randomico
|
||||
String folderName = timestamp + "_" + randomNum;
|
||||
File folder = new File(UPLOAD_DIR + folderName);
|
||||
|
||||
if (!folder.exists()) {
|
||||
folder.mkdirs(); // Crea la cartella se non esiste
|
||||
}
|
||||
|
||||
try {
|
||||
// Salva ogni file nella cartella
|
||||
for (MultipartFile file : files) {
|
||||
// Path path = Paths.get(UPLOAD_DIR + file.getOriginalFilename());
|
||||
// file.transferTo(path);
|
||||
String fileName = file.getOriginalFilename();
|
||||
File destFile = new File(folder, fileName);
|
||||
file.transferTo(destFile);
|
||||
}
|
||||
return ResponseEntity.ok(folderName);
|
||||
|
||||
} catch (Exception e) {
|
||||
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR)
|
||||
.body("Error uploading files: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -100,6 +100,11 @@ public class ScenarioController {
|
||||
public List<ScenarioExecution> getScenarioByUser() {
|
||||
return scenarioExecutionService.getListExecutionScenarioByUser();
|
||||
}
|
||||
|
||||
@GetMapping("/getScenariosForRE")
|
||||
public List<Scenario> getScenariosForRE() {
|
||||
return scenarioService.getListScenariosForRE();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -25,7 +25,7 @@ public class Scenario {
|
||||
private List<ScenarioStep> steps;
|
||||
private List<ScenarioInputs> inputs;
|
||||
private String visible;
|
||||
|
||||
private String category;
|
||||
|
||||
@DocumentReference
|
||||
private List<Project> availableForProjects;
|
||||
|
||||
@@ -27,4 +27,12 @@ public interface ScenarioRepository extends MongoRepository<Scenario, String> {
|
||||
List<Scenario> findByAvailableForProjectsIsNullAndAvailableForApplicationsIsNullAndVisible(String visible);
|
||||
|
||||
|
||||
@Query("{ 'visible': 'Y', 'category': 'RE', " +
|
||||
" $or: [ " +
|
||||
" { 'availableForProjects': ObjectId(?0) }, " +
|
||||
" { 'availableForApplications': ObjectId(?1) } " +
|
||||
" ] " +
|
||||
"}")
|
||||
List<Scenario> findByVisibleAndCategoryAndProjectOrApplication(String projectId, String applicationId);
|
||||
|
||||
}
|
||||
|
||||
@@ -378,7 +378,7 @@ public class ScenarioExecutionService {
|
||||
|
||||
}
|
||||
|
||||
public String updateRating(ScenarioExecution scenaExec){
|
||||
public String updateRating2(ScenarioExecution scenaExec){
|
||||
logger.info("updateRating function:");
|
||||
String result = "KO";
|
||||
try{
|
||||
@@ -391,4 +391,20 @@ public class ScenarioExecutionService {
|
||||
return result;
|
||||
|
||||
}
|
||||
|
||||
public String updateRating(String id, String rating){
|
||||
logger.info("updateRating function:");
|
||||
String result = "KO";
|
||||
try{
|
||||
Optional<ScenarioExecution> o_scenarioExecution = scenarioExecutionRepository.findById(id);
|
||||
if(o_scenarioExecution.isPresent()){
|
||||
o_scenarioExecution.get().setRating(rating);
|
||||
scenarioExecutionRepository.save(o_scenarioExecution.get());
|
||||
result = "OK";
|
||||
}
|
||||
}catch(Exception e){
|
||||
logger.error("Exception in updateRating: {}", e.getMessage());
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,6 +12,7 @@ import com.olympus.hermione.repository.ScenarioRepository;
|
||||
import com.olympus.hermione.security.entity.User;
|
||||
import com.olympus.model.Project;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import org.bson.types.ObjectId;
|
||||
|
||||
@@ -64,4 +65,24 @@ public class ScenarioService {
|
||||
return lstScenarios;
|
||||
|
||||
}
|
||||
|
||||
public List<Scenario> getListScenariosForRE(){
|
||||
logger.info("getListProjectByUser function:");
|
||||
List<Scenario> lstScenarios = new ArrayList<Scenario>();
|
||||
Scenario scenarioDefault = new Scenario();
|
||||
scenarioDefault.setName("Default");
|
||||
scenarioDefault.setId("");
|
||||
try{
|
||||
|
||||
User user = (User) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
|
||||
lstScenarios = scenarioRepo.findByVisibleAndCategoryAndProjectOrApplication(user.getSelectedProject().getId(), user.getSelectedApplication().getId());
|
||||
lstScenarios.add(scenarioDefault);
|
||||
}catch(Exception e){
|
||||
logger.error("Exception ScenarioRepository:", e.getMessage());
|
||||
}
|
||||
|
||||
logger.info("getListProjectByUser function:");
|
||||
return lstScenarios;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user