commit f31ea2fe0bfdf953daefa39a6107d9ad7772fdc7
Author: Jiri Trefil <badjokke@gmail.com>
Date:   Sun May 7 21:32:07 2023 +0200

    #10621 posílání výsledků detekce zpět na klienta

diff --git a/src/main/java/cz/zcu/fav/kiv/antipatterndetectionapp/v2/controller/ConfigurationController.java b/src/main/java/cz/zcu/fav/kiv/antipatterndetectionapp/v2/controller/ConfigurationController.java
index a5981df..8e90781 100644
--- a/src/main/java/cz/zcu/fav/kiv/antipatterndetectionapp/v2/controller/ConfigurationController.java
+++ b/src/main/java/cz/zcu/fav/kiv/antipatterndetectionapp/v2/controller/ConfigurationController.java
@@ -1,9 +1,7 @@
 package cz.zcu.fav.kiv.antipatterndetectionapp.v2.controller;
 
 import cz.zcu.fav.kiv.antipatterndetectionapp.v2.model.*;
-import cz.zcu.fav.kiv.antipatterndetectionapp.v2.repository.ConfigRepository;
-import cz.zcu.fav.kiv.antipatterndetectionapp.v2.repository.UserConfigurationJoinRepository;
-import cz.zcu.fav.kiv.antipatterndetectionapp.v2.service.ConfigurationService;
+import cz.zcu.fav.kiv.antipatterndetectionapp.v2.service.ConfigService;
 import cz.zcu.fav.kiv.antipatterndetectionapp.v2.utils.JSONBuilder;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.http.HttpStatus;
@@ -22,7 +20,7 @@ import java.util.Map;
 @RequestMapping("v2/configuration")
 public class ConfigurationController {
     @Autowired
-    private ConfigurationService configurationService;
+    private ConfigService configurationService;
 
     @PostMapping(value="/upload_configuration")
     public ResponseEntity<String> test(@RequestBody UserConfiguration userConfiguration) {
diff --git a/src/main/java/cz/zcu/fav/kiv/antipatterndetectionapp/v2/controller/DetectController.java b/src/main/java/cz/zcu/fav/kiv/antipatterndetectionapp/v2/controller/DetectController.java
index 279a7c5..b6220dd 100644
--- a/src/main/java/cz/zcu/fav/kiv/antipatterndetectionapp/v2/controller/DetectController.java
+++ b/src/main/java/cz/zcu/fav/kiv/antipatterndetectionapp/v2/controller/DetectController.java
@@ -1,35 +1,47 @@
 package cz.zcu.fav.kiv.antipatterndetectionapp.v2.controller;
 
 import com.google.gson.Gson;
+import cz.zcu.fav.kiv.antipatterndetectionapp.detecting.AntiPatternManager;
 import cz.zcu.fav.kiv.antipatterndetectionapp.model.AntiPattern;
 import cz.zcu.fav.kiv.antipatterndetectionapp.model.Project;
 import cz.zcu.fav.kiv.antipatterndetectionapp.model.Query;
+import cz.zcu.fav.kiv.antipatterndetectionapp.model.QueryResult;
 import cz.zcu.fav.kiv.antipatterndetectionapp.service.AntiPatternService;
+import cz.zcu.fav.kiv.antipatterndetectionapp.service.ConfigurationService;
 import cz.zcu.fav.kiv.antipatterndetectionapp.service.ProjectService;
+import cz.zcu.fav.kiv.antipatterndetectionapp.v2.model.UserDetectionDto;
+import cz.zcu.fav.kiv.antipatterndetectionapp.v2.service.DetectionService;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.http.HttpStatus;
 import org.springframework.http.ResponseEntity;
-import org.springframework.web.bind.annotation.GetMapping;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RestController;
+import org.springframework.web.bind.annotation.*;
 
 import java.util.List;
+import java.util.Map;
 
 @RestController
 @RequestMapping("v2/detect")
 public class DetectController {
     @Autowired
-    private ProjectService projectService;
-
-    @Autowired
-    private AntiPatternService antiPatternService;
+    DetectionService detectionService;
 
     @GetMapping("/list")
     public ResponseEntity<String> getAntipatternsAndProjects(){
         //List<Project> projects = projectService.getAllProjects();
         //List<AntiPattern> antiPatterns = antiPatternService.antiPatternsToModel(antiPatternService.getAllAntiPatterns());
         //List<AntiPattern> antiPatterns = antiPatternService.antiPatternsToModel(antiPatternService.getAllAntiPatterns());
-        return ResponseEntity.ok(new Gson().toJson( new Query(projectService.getAllProjects(), antiPatternService.antiPatternsToModel(antiPatternService.getAllAntiPatterns()))));
+        Query query = detectionService.getAllProjectsAndAntipatterns();
+        return ResponseEntity.ok(new Gson().toJson(query));
     }
 
+    @PostMapping("/analyze")
+    public ResponseEntity<String> detect(@RequestBody UserDetectionDto detectionRequest) {
+
+        List<QueryResult> results = detectionService.analyze(detectionRequest);
+        //Map<String, Map<String, String>> currentConfiguration = configurationService.getConfigurationByName();
+        return ResponseEntity.ok(new Gson().toJson(results));
+
+    }
+
+
 }
diff --git a/src/main/java/cz/zcu/fav/kiv/antipatterndetectionapp/v2/repository/ConfigRepository.java b/src/main/java/cz/zcu/fav/kiv/antipatterndetectionapp/v2/repository/ConfigRepository.java
index 4e427cb..04d86a9 100644
--- a/src/main/java/cz/zcu/fav/kiv/antipatterndetectionapp/v2/repository/ConfigRepository.java
+++ b/src/main/java/cz/zcu/fav/kiv/antipatterndetectionapp/v2/repository/ConfigRepository.java
@@ -24,10 +24,14 @@ public interface ConfigRepository extends JpaRepository<Configuration,Integer> {
             "or config.id in (select userconfig.id.userId from UserConfigurationJoin userconfig where userconfig.id.userId = ?1)")
     List<Configuration> getAllUserConfigurations(int userId);
 
-
-    @Query("select userconfig.configurationName from UserConfigurationJoin userconfig where userconfig.id.userId = ?1 or userconfig.id.userId=2 ")
+    //todo default user id parametrem
+    @Query("select userconfig.configurationName from UserConfigurationJoin userconfig where userconfig.id.userId = ?1 or userconfig.id.userId=2")
     List<String> getAllUserConfigurationNames(int userId);
 
+    @Query("select userconfig.configurationName from UserConfigurationJoin userconfig where userconfig.id = ?1")
+    String findConfigurationByCompoundKey(UserConfigKey key);
+
+
 
 
 }
diff --git a/src/main/java/cz/zcu/fav/kiv/antipatterndetectionapp/v2/service/ConfigService.java b/src/main/java/cz/zcu/fav/kiv/antipatterndetectionapp/v2/service/ConfigService.java
new file mode 100644
index 0000000..adccf3b
--- /dev/null
+++ b/src/main/java/cz/zcu/fav/kiv/antipatterndetectionapp/v2/service/ConfigService.java
@@ -0,0 +1,22 @@
+package cz.zcu.fav.kiv.antipatterndetectionapp.v2.service;
+import cz.zcu.fav.kiv.antipatterndetectionapp.v2.model.Configuration;
+import cz.zcu.fav.kiv.antipatterndetectionapp.v2.model.User;
+import cz.zcu.fav.kiv.antipatterndetectionapp.v2.model.UserConfiguration;
+import org.springframework.http.ResponseEntity;
+import java.util.List;
+public interface ConfigService {
+    //upload configuration
+    ResponseEntity<String> addConfiguration(Configuration cfg);
+    ResponseEntity<String> addConfiguration(UserConfiguration cfg);
+
+    ResponseEntity<String> pairConfigurationWithUser(User user, Configuration configuration);
+    //get all configurations available to user
+    ResponseEntity<String> getUserConfigurations(User user);
+
+    List<String> getConfigurationNames(User user);
+
+    Configuration getConfigurationById(int id);
+    String getConfigurationName(int userId, int configurationId);
+
+
+}
diff --git a/src/main/java/cz/zcu/fav/kiv/antipatterndetectionapp/v2/service/ConfigurationService.java b/src/main/java/cz/zcu/fav/kiv/antipatterndetectionapp/v2/service/ConfigurationService.java
deleted file mode 100644
index ad1ab54..0000000
--- a/src/main/java/cz/zcu/fav/kiv/antipatterndetectionapp/v2/service/ConfigurationService.java
+++ /dev/null
@@ -1,22 +0,0 @@
-package cz.zcu.fav.kiv.antipatterndetectionapp.v2.service;
-import cz.zcu.fav.kiv.antipatterndetectionapp.v2.model.Configuration;
-import cz.zcu.fav.kiv.antipatterndetectionapp.v2.model.User;
-import cz.zcu.fav.kiv.antipatterndetectionapp.v2.model.UserConfiguration;
-import org.springframework.http.ResponseEntity;
-import java.util.List;
-public interface ConfigurationService {
-    //upload configuration
-    ResponseEntity<String> addConfiguration(Configuration cfg);
-    ResponseEntity<String> addConfiguration(UserConfiguration cfg);
-
-    ResponseEntity<String> pairConfigurationWithUser(User user, Configuration configuration);
-    //get all configurations available to user
-    ResponseEntity<String> getUserConfigurations(User user);
-
-    List<String> getConfigurationNames(User user);
-
-
-
-
-
-}
diff --git a/src/main/java/cz/zcu/fav/kiv/antipatterndetectionapp/v2/service/ConfigurationServiceImplementation.java b/src/main/java/cz/zcu/fav/kiv/antipatterndetectionapp/v2/service/ConfigurationServiceImplementation.java
index 7197343..b5f3106 100644
--- a/src/main/java/cz/zcu/fav/kiv/antipatterndetectionapp/v2/service/ConfigurationServiceImplementation.java
+++ b/src/main/java/cz/zcu/fav/kiv/antipatterndetectionapp/v2/service/ConfigurationServiceImplementation.java
@@ -15,7 +15,7 @@ import java.util.List;
 import java.util.Map;
 
 @Service
-public class ConfigurationServiceImplementation implements ConfigurationService{
+public class ConfigurationServiceImplementation implements ConfigService {
     //repository which represents connection to database and the configuration table in particular
     @Autowired
     private ConfigRepository configurationRepository;
@@ -133,4 +133,14 @@ public class ConfigurationServiceImplementation implements ConfigurationService{
         List<String> configurationNames = this.configurationRepository.getAllUserConfigurationNames(userInfo.getId());
         return configurationNames;
     }
+
+    @Override
+    public Configuration getConfigurationById(int id) {
+        return this.configurationRepository.findConfigurationById(id);
+    }
+
+    @Override
+    public String getConfigurationName(int userId, int configurationId) {
+        return this.configurationRepository.findConfigurationByCompoundKey(new UserConfigKey(userId, configurationId));
+    }
 }
diff --git a/src/main/java/cz/zcu/fav/kiv/antipatterndetectionapp/v2/utils/JSONBuilder.java b/src/main/java/cz/zcu/fav/kiv/antipatterndetectionapp/v2/utils/JSONBuilder.java
index 7b41d76..2303451 100644
--- a/src/main/java/cz/zcu/fav/kiv/antipatterndetectionapp/v2/utils/JSONBuilder.java
+++ b/src/main/java/cz/zcu/fav/kiv/antipatterndetectionapp/v2/utils/JSONBuilder.java
@@ -74,6 +74,32 @@ public class JSONBuilder {
         return json;
     }
 
+    public static Map<String, Map<String, String>> createMapFromString(String jsonContent){
+
+        ConfigurationDto cfgDto = new Gson().fromJson(jsonContent, ConfigurationDto.class);
+
+        Map<String, Map<String, String>> newAntiPatternMap = new HashMap<>();
+
+        for (AntiPatternDto antiPatternDto : cfgDto.getConfiguration()) {
+
+            String antiPatternName = antiPatternDto.getAntiPattern();
+
+            Map<String, String> newThresholds = new HashMap<String, String>();
+
+            for (ThresholdDto thresholdDto : antiPatternDto.getThresholds()) {
+
+                String thresholdName = thresholdDto.getThresholdName();
+                String value = thresholdDto.getValue();
+
+                newThresholds.put(thresholdName, value);
+            }
+            newAntiPatternMap.put(antiPatternName, newThresholds);
+
+        }
+
+        return newAntiPatternMap;
+    }
+
 
 
 
