Merge branch 'prof_users' into 'master'
# Conflicts: # src/main/java/com/olympus/hermione/models/Scenario.java
This commit is contained in:
@@ -0,0 +1,76 @@
|
|||||||
|
package com.olympus.hermione.controllers;
|
||||||
|
|
||||||
|
import java.util.Optional;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
|
import org.springframework.web.bind.annotation.PostMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestBody;
|
||||||
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
|
import com.olympus.hermione.models.Application;
|
||||||
|
import com.olympus.hermione.models.Project;
|
||||||
|
import com.olympus.hermione.repository.ApplicationRepository;
|
||||||
|
import com.olympus.hermione.repository.ProjectRepository;
|
||||||
|
import com.olympus.hermione.services.ApplicationService;
|
||||||
|
import com.olympus.hermione.services.ProjectService;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
|
||||||
|
|
||||||
|
@RestController
|
||||||
|
public class ApplicationController {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
ApplicationService appService;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
ApplicationRepository appRepo;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
ProjectRepository projectRepo;
|
||||||
|
|
||||||
|
@GetMapping("/userApplications")
|
||||||
|
public Iterable<Application> getUserApplications() {
|
||||||
|
return appService.getListApplicationsByProject();
|
||||||
|
}
|
||||||
|
|
||||||
|
/*@PostMapping("/getApp")
|
||||||
|
public Project getUserProjects(@RequestBody String appId) {
|
||||||
|
Optional<Application> a = appRepo.findById(appId);
|
||||||
|
//Project p = a.get();
|
||||||
|
|
||||||
|
|
||||||
|
return p;
|
||||||
|
}*/
|
||||||
|
|
||||||
|
@GetMapping("/create")
|
||||||
|
public String createApplication() {
|
||||||
|
Application a = new Application();
|
||||||
|
|
||||||
|
a.setFE_name("");
|
||||||
|
a.setInternal_name("");
|
||||||
|
a.setDescription(null);
|
||||||
|
|
||||||
|
a = appRepo.save(a);
|
||||||
|
|
||||||
|
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
|
@GetMapping("/createProject")
|
||||||
|
public Project createProject() {
|
||||||
|
|
||||||
|
Application a = appRepo.findById("6708dfb56fbbc0bafa1df68c").get();
|
||||||
|
|
||||||
|
Project p = new Project();
|
||||||
|
|
||||||
|
p.setDescription("DOO Administrator");
|
||||||
|
p.setFE_name("DOOA");
|
||||||
|
p.setInternal_name("DOOA");
|
||||||
|
List<Application> lst = new ArrayList<Application>();
|
||||||
|
lst.add(a);
|
||||||
|
p.setLstApplications(lst);
|
||||||
|
projectRepo.save(p);
|
||||||
|
return p;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,36 @@
|
|||||||
|
package com.olympus.hermione.controllers;
|
||||||
|
|
||||||
|
import java.util.Optional;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
|
import org.springframework.web.bind.annotation.PostMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestBody;
|
||||||
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
import com.olympus.hermione.models.Project;
|
||||||
|
import com.olympus.hermione.repository.ProjectRepository;
|
||||||
|
import com.olympus.hermione.services.ProjectService;
|
||||||
|
|
||||||
|
@RestController
|
||||||
|
public class ProjectController {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
ProjectService projectService;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
ProjectRepository projectRepo;
|
||||||
|
|
||||||
|
@GetMapping("/userProjects")
|
||||||
|
public Iterable<Project> getUserProjects() {
|
||||||
|
return projectService.getListProjectsByUser();
|
||||||
|
}
|
||||||
|
|
||||||
|
@PostMapping("/updateSelectedProject")
|
||||||
|
public Boolean setSelectedProjects(@RequestBody Project projectId) {
|
||||||
|
return projectService.updateUserSelectedProject(projectId);
|
||||||
|
}
|
||||||
|
|
||||||
|
@PostMapping("/getProject")
|
||||||
|
public Optional<Project> getUserProjects(@RequestBody String projectId) {
|
||||||
|
return projectRepo.findById(projectId);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -8,11 +8,14 @@ import org.springframework.web.bind.annotation.RestController;
|
|||||||
|
|
||||||
import com.olympus.hermione.dto.ScenarioExecutionInput;
|
import com.olympus.hermione.dto.ScenarioExecutionInput;
|
||||||
import com.olympus.hermione.dto.ScenarioOutput;
|
import com.olympus.hermione.dto.ScenarioOutput;
|
||||||
|
import com.olympus.hermione.models.Application;
|
||||||
|
import com.olympus.hermione.models.Project;
|
||||||
import com.olympus.hermione.models.Scenario;
|
import com.olympus.hermione.models.Scenario;
|
||||||
import com.olympus.hermione.models.ScenarioExecution;
|
import com.olympus.hermione.models.ScenarioExecution;
|
||||||
import com.olympus.hermione.repository.ScenarioRepository;
|
import com.olympus.hermione.repository.ScenarioRepository;
|
||||||
import com.olympus.hermione.repository.ScenarioExecutionRepository;
|
import com.olympus.hermione.repository.ScenarioExecutionRepository;
|
||||||
import com.olympus.hermione.services.ScenarioExecutionService;
|
import com.olympus.hermione.services.ScenarioExecutionService;
|
||||||
|
import com.olympus.hermione.services.ScenarioService;
|
||||||
|
|
||||||
import org.springframework.web.bind.annotation.RequestBody;
|
import org.springframework.web.bind.annotation.RequestBody;
|
||||||
|
|
||||||
@@ -25,12 +28,24 @@ public class ScenarioController {
|
|||||||
ScenarioExecutionRepository scenarioExecutionRepository;
|
ScenarioExecutionRepository scenarioExecutionRepository;
|
||||||
@Autowired
|
@Autowired
|
||||||
ScenarioExecutionService scenarioExecutionService;
|
ScenarioExecutionService scenarioExecutionService;
|
||||||
|
@Autowired
|
||||||
|
ScenarioService scenarioService;
|
||||||
|
|
||||||
@GetMapping("/scenarios")
|
@GetMapping("/scenarios")
|
||||||
public Iterable<Scenario> getScenarios() {
|
public Iterable<Scenario> getScenarios() {
|
||||||
return scenarioRepository.findAll();
|
return scenarioRepository.findAll();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@PostMapping("/scenariosProject")
|
||||||
|
public Iterable<Scenario> getScenariosByProject(@RequestBody Project projectId) {
|
||||||
|
return scenarioService.getListScenariosByProject(projectId.getId());
|
||||||
|
}
|
||||||
|
|
||||||
|
@PostMapping("/scenariosByApp")
|
||||||
|
public Iterable<Scenario> getScenariosByApp(@RequestBody Application appId) {
|
||||||
|
return scenarioService.getListScenariosByApplication(appId.getId());
|
||||||
|
}
|
||||||
|
|
||||||
@GetMapping("/scenarios/{id}")
|
@GetMapping("/scenarios/{id}")
|
||||||
public Scenario getScenario(@PathVariable String id) {
|
public Scenario getScenario(@PathVariable String id) {
|
||||||
return scenarioRepository.findById(id).get();
|
return scenarioRepository.findById(id).get();
|
||||||
|
|||||||
24
src/main/java/com/olympus/hermione/models/Application.java
Normal file
24
src/main/java/com/olympus/hermione/models/Application.java
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
package com.olympus.hermione.models;
|
||||||
|
|
||||||
|
import org.bson.types.ObjectId;
|
||||||
|
import org.springframework.data.annotation.Id;
|
||||||
|
import org.springframework.data.mongodb.core.mapping.Document;
|
||||||
|
import org.springframework.data.mongodb.core.mapping.DocumentReference;
|
||||||
|
import org.springframework.data.mongodb.core.mapping.Field;
|
||||||
|
import org.springframework.data.mongodb.core.mapping.FieldType;
|
||||||
|
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.Setter;
|
||||||
|
|
||||||
|
@Document(collection = "applications")
|
||||||
|
@Getter @Setter
|
||||||
|
public class Application {
|
||||||
|
|
||||||
|
@Id
|
||||||
|
@Field(targetType = FieldType.OBJECT_ID)
|
||||||
|
private String id;
|
||||||
|
private String internal_name;
|
||||||
|
private String FE_name;
|
||||||
|
private String description;
|
||||||
|
|
||||||
|
}
|
||||||
28
src/main/java/com/olympus/hermione/models/Project.java
Normal file
28
src/main/java/com/olympus/hermione/models/Project.java
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
package com.olympus.hermione.models;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.bson.types.ObjectId;
|
||||||
|
import org.springframework.data.annotation.Id;
|
||||||
|
import org.springframework.data.mongodb.core.mapping.Document;
|
||||||
|
import org.springframework.data.mongodb.core.mapping.DocumentReference;
|
||||||
|
import org.springframework.data.mongodb.core.mapping.Field;
|
||||||
|
import org.springframework.data.mongodb.core.mapping.FieldType;
|
||||||
|
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.Setter;
|
||||||
|
|
||||||
|
@Document(collection = "projects")
|
||||||
|
@Getter @Setter
|
||||||
|
public class Project {
|
||||||
|
|
||||||
|
@Id
|
||||||
|
@Field(targetType = FieldType.OBJECT_ID)
|
||||||
|
private String id;
|
||||||
|
private String internal_name;
|
||||||
|
private String FE_name;
|
||||||
|
private String description;
|
||||||
|
@DocumentReference
|
||||||
|
private List<Application> lstApplications;
|
||||||
|
|
||||||
|
}
|
||||||
@@ -4,6 +4,9 @@ import java.util.List;
|
|||||||
|
|
||||||
import org.springframework.data.annotation.Id;
|
import org.springframework.data.annotation.Id;
|
||||||
import org.springframework.data.mongodb.core.mapping.Document;
|
import org.springframework.data.mongodb.core.mapping.Document;
|
||||||
|
import org.springframework.data.mongodb.core.mapping.DocumentReference;
|
||||||
|
import org.springframework.data.mongodb.core.mapping.Field;
|
||||||
|
import org.springframework.data.mongodb.core.mapping.FieldType;
|
||||||
|
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import lombok.Setter;
|
import lombok.Setter;
|
||||||
@@ -12,6 +15,7 @@ import lombok.Setter;
|
|||||||
@Getter @Setter
|
@Getter @Setter
|
||||||
public class Scenario {
|
public class Scenario {
|
||||||
@Id
|
@Id
|
||||||
|
@Field(targetType = FieldType.OBJECT_ID)
|
||||||
private String id;
|
private String id;
|
||||||
private String name;
|
private String name;
|
||||||
private String description;
|
private String description;
|
||||||
@@ -19,5 +23,10 @@ public class Scenario {
|
|||||||
private List<ScenarioStep> steps;
|
private List<ScenarioStep> steps;
|
||||||
private List<ScenarioInputs> inputs;
|
private List<ScenarioInputs> inputs;
|
||||||
private String modelId;
|
private String modelId;
|
||||||
|
@DocumentReference
|
||||||
|
private List<Project> availableForProjects;
|
||||||
|
@DocumentReference
|
||||||
|
private List<Project> availableForApplications;
|
||||||
|
|
||||||
private boolean useChatMemory=false;
|
private boolean useChatMemory=false;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,14 @@
|
|||||||
|
package com.olympus.hermione.repository;
|
||||||
|
|
||||||
|
import org.bson.types.ObjectId;
|
||||||
|
import org.springframework.data.mongodb.repository.MongoRepository;
|
||||||
|
import org.springframework.stereotype.Repository;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import com.olympus.hermione.models.Application;
|
||||||
|
|
||||||
|
@Repository
|
||||||
|
public interface ApplicationRepository extends MongoRepository<Application, String> {
|
||||||
|
|
||||||
|
//List<Application> findByProjectId(String projectId);
|
||||||
|
}
|
||||||
@@ -0,0 +1,14 @@
|
|||||||
|
package com.olympus.hermione.repository;
|
||||||
|
|
||||||
|
import org.bson.types.ObjectId;
|
||||||
|
import org.springframework.data.mongodb.repository.MongoRepository;
|
||||||
|
import org.springframework.stereotype.Repository;
|
||||||
|
|
||||||
|
import com.olympus.hermione.dto.ScenarioOutput;
|
||||||
|
import com.olympus.hermione.models.Project;
|
||||||
|
|
||||||
|
@Repository
|
||||||
|
public interface ProjectRepository extends MongoRepository<Project, String> {
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
@@ -1,11 +1,27 @@
|
|||||||
package com.olympus.hermione.repository;
|
package com.olympus.hermione.repository;
|
||||||
|
|
||||||
|
import org.bson.types.ObjectId;
|
||||||
|
import org.springframework.data.mongodb.repository.MongoRepository;
|
||||||
|
import org.springframework.data.mongodb.repository.Query;
|
||||||
import org.springframework.data.repository.CrudRepository;
|
import org.springframework.data.repository.CrudRepository;
|
||||||
import org.springframework.stereotype.Repository;
|
import org.springframework.stereotype.Repository;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
import com.olympus.hermione.models.Scenario;
|
import com.olympus.hermione.models.Scenario;
|
||||||
|
|
||||||
@Repository
|
@Repository
|
||||||
public interface ScenarioRepository extends CrudRepository<Scenario, String> {
|
public interface ScenarioRepository extends MongoRepository<Scenario, String> {
|
||||||
|
|
||||||
|
/* @Query("{ 'usable_for._id': ?0 }")
|
||||||
|
List<Scenario> findByUsableFor(String projectId);*/
|
||||||
|
|
||||||
|
/* @Query("{ 'usable_for': ?0 }")
|
||||||
|
List<Scenario> findByUsableFor(String projectId);*/
|
||||||
|
|
||||||
|
List<Scenario> findByAvailableForProjects_Id(String projectId);
|
||||||
|
|
||||||
|
List<Scenario> findByAvailableForApplications_Id(String projectId);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,6 +19,7 @@ import com.olympus.hermione.security.dto.FetchUserResponse;
|
|||||||
import com.olympus.hermione.security.entity.User;
|
import com.olympus.hermione.security.entity.User;
|
||||||
import com.olympus.hermione.security.utility.JwtTokenProvider;
|
import com.olympus.hermione.security.utility.JwtTokenProvider;
|
||||||
|
|
||||||
|
|
||||||
@RestController
|
@RestController
|
||||||
@RequestMapping("/api/auth")
|
@RequestMapping("/api/auth")
|
||||||
public class AuthController {
|
public class AuthController {
|
||||||
@@ -42,10 +43,10 @@ public class AuthController {
|
|||||||
SecurityContextHolder.getContext().setAuthentication(authentication);
|
SecurityContextHolder.getContext().setAuthentication(authentication);
|
||||||
String jwt = jwtTokenProvider.createToken(authentication);
|
String jwt = jwtTokenProvider.createToken(authentication);
|
||||||
|
|
||||||
|
|
||||||
HttpHeaders httpHeaders = new HttpHeaders();
|
HttpHeaders httpHeaders = new HttpHeaders();
|
||||||
httpHeaders.add("authorization", jwt);
|
httpHeaders.add("authorization", jwt);
|
||||||
httpHeaders.add("access-control-expose-headers", "authorization");
|
httpHeaders.add("access-control-expose-headers", "authorization");
|
||||||
|
|
||||||
AuthenticationResponse authenticationResponse = new AuthenticationResponse(jwt, (User) authentication.getPrincipal());
|
AuthenticationResponse authenticationResponse = new AuthenticationResponse(jwt, (User) authentication.getPrincipal());
|
||||||
|
|
||||||
return ResponseEntity.ok().headers(httpHeaders).body(authenticationResponse);
|
return ResponseEntity.ok().headers(httpHeaders).body(authenticationResponse);
|
||||||
|
|||||||
@@ -1,5 +1,8 @@
|
|||||||
package com.olympus.hermione.security.dto;
|
package com.olympus.hermione.security.dto;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import com.olympus.hermione.models.Project;
|
||||||
import com.olympus.hermione.security.entity.User;
|
import com.olympus.hermione.security.entity.User;
|
||||||
|
|
||||||
import lombok.AllArgsConstructor;
|
import lombok.AllArgsConstructor;
|
||||||
|
|||||||
@@ -1,12 +1,16 @@
|
|||||||
package com.olympus.hermione.security.entity;
|
package com.olympus.hermione.security.entity;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
|
|
||||||
|
import org.bson.types.ObjectId;
|
||||||
import org.springframework.data.annotation.Id;
|
import org.springframework.data.annotation.Id;
|
||||||
import org.springframework.data.mongodb.core.mapping.Document;
|
import org.springframework.data.mongodb.core.mapping.Document;
|
||||||
|
import org.springframework.data.mongodb.core.mapping.DocumentReference;
|
||||||
import org.springframework.security.core.GrantedAuthority;
|
import org.springframework.security.core.GrantedAuthority;
|
||||||
import org.springframework.security.core.authority.SimpleGrantedAuthority;
|
import org.springframework.security.core.authority.SimpleGrantedAuthority;
|
||||||
import org.springframework.security.core.userdetails.UserDetails;
|
import org.springframework.security.core.userdetails.UserDetails;
|
||||||
|
|
||||||
|
import com.olympus.hermione.models.Project;
|
||||||
|
|
||||||
import lombok.AllArgsConstructor;
|
import lombok.AllArgsConstructor;
|
||||||
import lombok.Builder;
|
import lombok.Builder;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
@@ -29,6 +33,11 @@ public class User implements UserDetails{
|
|||||||
private String password;
|
private String password;
|
||||||
private String name;
|
private String name;
|
||||||
private String surname;
|
private String surname;
|
||||||
|
@DocumentReference
|
||||||
|
private Project selectedProject;
|
||||||
|
@DocumentReference
|
||||||
|
private List<Project> lstProjects;
|
||||||
|
|
||||||
|
|
||||||
private Role role;
|
private Role role;
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,47 @@
|
|||||||
|
package com.olympus.hermione.services;
|
||||||
|
|
||||||
|
import org.bson.types.ObjectId;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.security.core.context.SecurityContextHolder;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import com.olympus.hermione.models.Project;
|
||||||
|
import com.olympus.hermione.repository.ApplicationRepository;
|
||||||
|
import com.olympus.hermione.repository.ProjectRepository;
|
||||||
|
import com.olympus.hermione.security.entity.User;
|
||||||
|
import com.olympus.hermione.models.Application;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@Service
|
||||||
|
public class ApplicationService {
|
||||||
|
|
||||||
|
private Logger logger = LoggerFactory.getLogger(ApplicationService.class);
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private ApplicationRepository appRepo;
|
||||||
|
|
||||||
|
public List<Application> getListApplicationsByProject(){
|
||||||
|
List<Application> lstApp = null;
|
||||||
|
User principal = (User) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
|
||||||
|
|
||||||
|
// lstApp = appRepo.findByProjectId(principal.getSelectedProject());
|
||||||
|
|
||||||
|
//List<ObjectId> objectIds = convertToObjectIdList(principal.getSelected_progect());
|
||||||
|
|
||||||
|
//List<Project> lstProject = projectRepo.findAllById(objectIds);
|
||||||
|
|
||||||
|
logger.info("getListProjectByIds function:");
|
||||||
|
|
||||||
|
/* Application all = new Application();
|
||||||
|
all.setFE_name("ALL");
|
||||||
|
all.setInternal_name("ALL");
|
||||||
|
all.setId(new ObjectId("ALL"));
|
||||||
|
lstApp.add(all);*/
|
||||||
|
|
||||||
|
return lstApp;
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,95 @@
|
|||||||
|
package com.olympus.hermione.services;
|
||||||
|
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Optional;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
import org.bson.types.ObjectId;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.security.core.context.SecurityContextHolder;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
|
import com.olympus.hermione.dto.ScenarioOutput;
|
||||||
|
import com.olympus.hermione.models.Project;
|
||||||
|
import com.olympus.hermione.models.ScenarioExecution;
|
||||||
|
import com.olympus.hermione.repository.ProjectRepository;
|
||||||
|
import com.olympus.hermione.security.entity.User;
|
||||||
|
import com.olympus.hermione.security.repository.UserRepository;
|
||||||
|
|
||||||
|
@Service
|
||||||
|
public class ProjectService {
|
||||||
|
|
||||||
|
private Logger logger = LoggerFactory.getLogger(ProjectService.class);
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private ProjectRepository projectRepo;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private UserRepository userRepo;
|
||||||
|
|
||||||
|
public List<Project> getListProjectsByUser(){
|
||||||
|
logger.info("getListProjectByUser function:");
|
||||||
|
|
||||||
|
User principal = (User) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
|
||||||
|
|
||||||
|
return principal.getLstProjects();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public Boolean updateUserSelectedProject(Project idProject){
|
||||||
|
User principal = (User) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
|
||||||
|
|
||||||
|
principal.setSelectedProject(idProject);
|
||||||
|
User u = userRepo.save(principal);
|
||||||
|
|
||||||
|
User principal2 = (User) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
|
||||||
|
|
||||||
|
return true;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* public static List<ObjectId> convertToObjectIdList(List<String> listProjectIds) {
|
||||||
|
List<ObjectId> objectIdList = new ArrayList<>();
|
||||||
|
ObjectMapper objectMapper = new ObjectMapper();
|
||||||
|
|
||||||
|
for (String jsonString : listProjectIds) {
|
||||||
|
try {
|
||||||
|
// Deserializza la stringa JSON in un oggetto mappa
|
||||||
|
Map<String, String> map = objectMapper.readValue(jsonString, Map.class);
|
||||||
|
// Estrai il valore dell'ObjectId e creane un'istanza
|
||||||
|
String oid = map.get("$oid");
|
||||||
|
if (oid != null) {
|
||||||
|
objectIdList.add(new ObjectId(oid));
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace(); // Gestione degli errori
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return objectIdList;
|
||||||
|
} */
|
||||||
|
|
||||||
|
public static List<ObjectId> convertToObjectIdList(List<String> listProjectIds) {
|
||||||
|
List<ObjectId> objectIdList = new ArrayList<>();
|
||||||
|
|
||||||
|
for (String idString : listProjectIds) {
|
||||||
|
try {
|
||||||
|
// Crea un nuovo ObjectId dalla stringa e aggiungilo alla lista
|
||||||
|
objectIdList.add(new ObjectId(idString));
|
||||||
|
} catch (IllegalArgumentException e) {
|
||||||
|
// Gestione degli errori per stringhe non valide che non possono essere convertite in ObjectId
|
||||||
|
System.err.println("Invalid ObjectId string: " + idString);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return objectIdList;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,52 @@
|
|||||||
|
package com.olympus.hermione.services;
|
||||||
|
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.security.core.context.SecurityContextHolder;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import com.olympus.hermione.models.Project;
|
||||||
|
import com.olympus.hermione.models.Scenario;
|
||||||
|
import com.olympus.hermione.repository.ProjectRepository;
|
||||||
|
import com.olympus.hermione.repository.ScenarioRepository;
|
||||||
|
import com.olympus.hermione.security.entity.User;
|
||||||
|
import java.util.List;
|
||||||
|
import org.bson.types.ObjectId;
|
||||||
|
|
||||||
|
@Service
|
||||||
|
public class ScenarioService {
|
||||||
|
|
||||||
|
private Logger logger = LoggerFactory.getLogger(ScenarioService.class);
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private ScenarioRepository scenarioRepo;
|
||||||
|
|
||||||
|
public List<Scenario> getListScenariosByProject(String project){
|
||||||
|
logger.info("getListProjectByUser function:");
|
||||||
|
List<Scenario> lstScenarios = null;
|
||||||
|
try{
|
||||||
|
lstScenarios = scenarioRepo.findByAvailableForProjects_Id(project);
|
||||||
|
}catch(Exception e){
|
||||||
|
logger.error("Exception ScenarioRepository:", e.getMessage());
|
||||||
|
}
|
||||||
|
|
||||||
|
logger.info("getListProjectByUser function:");
|
||||||
|
return lstScenarios;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<Scenario> getListScenariosByApplication(String app){
|
||||||
|
logger.info("getListProjectByUser function:");
|
||||||
|
List<Scenario> lstScenarios = null;
|
||||||
|
try{
|
||||||
|
lstScenarios = scenarioRepo.findByAvailableForApplications_Id(app);
|
||||||
|
}catch(Exception e){
|
||||||
|
logger.error("Exception ScenarioRepository:", e.getMessage());
|
||||||
|
}
|
||||||
|
|
||||||
|
logger.info("getListProjectByUser function:");
|
||||||
|
return lstScenarios;
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
package com.olympus.hermione.stepSolvers;
|
package com.olympus.hermione.stepSolvers;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
import org.springframework.ai.document.Document;
|
import org.springframework.ai.document.Document;
|
||||||
|
|||||||
Reference in New Issue
Block a user