commit 461445086a683416bc233171b3352b83505b8c98
Author: Jiri Trefil <badjokke@gmail.com>
Date:   Sun May 7 21:32:44 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/model/AntiPatternDto.java b/src/main/java/cz/zcu/fav/kiv/antipatterndetectionapp/v2/model/AntiPatternDto.java
new file mode 100644
index 0000000..60f5df4
--- /dev/null
+++ b/src/main/java/cz/zcu/fav/kiv/antipatterndetectionapp/v2/model/AntiPatternDto.java
@@ -0,0 +1,25 @@
+package cz.zcu.fav.kiv.antipatterndetectionapp.v2.model;
+
+import java.util.List;
+
+public class AntiPatternDto {
+
+    private String antiPattern;
+    private List<ThresholdDto> thresholds;
+
+    public String getAntiPattern() {
+        return antiPattern;
+    }
+
+    public void setAntiPattern(String antiPattern) {
+        this.antiPattern = antiPattern;
+    }
+
+    public List<ThresholdDto> getThresholds() {
+        return thresholds;
+    }
+
+    public void setThresholds(List<ThresholdDto> thresholds) {
+        this.thresholds = thresholds;
+    }
+}
diff --git a/src/main/java/cz/zcu/fav/kiv/antipatterndetectionapp/v2/model/ConfigurationDto.java b/src/main/java/cz/zcu/fav/kiv/antipatterndetectionapp/v2/model/ConfigurationDto.java
new file mode 100644
index 0000000..a836c6f
--- /dev/null
+++ b/src/main/java/cz/zcu/fav/kiv/antipatterndetectionapp/v2/model/ConfigurationDto.java
@@ -0,0 +1,15 @@
+package cz.zcu.fav.kiv.antipatterndetectionapp.v2.model;
+
+import java.util.List;
+
+public class ConfigurationDto {
+    private List<AntiPatternDto> configuration;
+
+    public List<AntiPatternDto> getConfiguration() {
+        return configuration;
+    }
+
+    public void setConfiguration(List<AntiPatternDto> configuration) {
+        this.configuration = configuration;
+    }
+}
diff --git a/src/main/java/cz/zcu/fav/kiv/antipatterndetectionapp/v2/model/ThresholdDto.java b/src/main/java/cz/zcu/fav/kiv/antipatterndetectionapp/v2/model/ThresholdDto.java
new file mode 100644
index 0000000..4770872
--- /dev/null
+++ b/src/main/java/cz/zcu/fav/kiv/antipatterndetectionapp/v2/model/ThresholdDto.java
@@ -0,0 +1,23 @@
+package cz.zcu.fav.kiv.antipatterndetectionapp.v2.model;
+
+public class ThresholdDto {
+
+    private String thresholdName;
+    private String value;
+
+    public String getThresholdName() {
+        return thresholdName;
+    }
+
+    public void setThresholdName(String thresholdName) {
+        this.thresholdName = thresholdName;
+    }
+
+    public String getValue() {
+        return value;
+    }
+
+    public void setValue(String value) {
+        this.value = value;
+    }
+}
diff --git a/src/main/java/cz/zcu/fav/kiv/antipatterndetectionapp/v2/model/UserDetectionDto.java b/src/main/java/cz/zcu/fav/kiv/antipatterndetectionapp/v2/model/UserDetectionDto.java
new file mode 100644
index 0000000..3552a77
--- /dev/null
+++ b/src/main/java/cz/zcu/fav/kiv/antipatterndetectionapp/v2/model/UserDetectionDto.java
@@ -0,0 +1,52 @@
+package cz.zcu.fav.kiv.antipatterndetectionapp.v2.model;
+
+public class UserDetectionDto {
+
+    private int configurationId;
+    private String userName;
+
+
+
+    private String[] selectedProjects;
+    private String[] selectedAntipatterns;
+
+    public UserDetectionDto(String userName,int configurationId, String[] selectedProjects, String[] selectedAntipatterns) {
+        this.configurationId = configurationId;
+        this.selectedProjects = selectedProjects;
+        this.selectedAntipatterns = selectedAntipatterns;
+        this.userName = userName;
+    }
+    public String getUserName(){
+        return this.userName;
+    }
+    public UserDetectionDto() {
+    }
+
+    public void setConfigurationId(int configurationId) {
+        this.configurationId = configurationId;
+    }
+
+    public void setSelectedProjects(String[] selectedProjects) {
+        this.selectedProjects = selectedProjects;
+    }
+
+    public void setSelectedAntipatterns(String[] selectedAntipatterns) {
+        this.selectedAntipatterns = selectedAntipatterns;
+    }
+    public void setUserName(String userName) {
+        this.userName = userName;
+    }
+
+    public int getConfigurationId() {
+        return configurationId;
+    }
+
+    public String[] getSelectedProjects() {
+        return selectedProjects;
+    }
+
+    public String[] getSelectedAntipatterns() {
+        return selectedAntipatterns;
+    }
+
+}
diff --git a/src/main/java/cz/zcu/fav/kiv/antipatterndetectionapp/v2/service/DetectionService.java b/src/main/java/cz/zcu/fav/kiv/antipatterndetectionapp/v2/service/DetectionService.java
new file mode 100644
index 0000000..fb85e8f
--- /dev/null
+++ b/src/main/java/cz/zcu/fav/kiv/antipatterndetectionapp/v2/service/DetectionService.java
@@ -0,0 +1,14 @@
+package cz.zcu.fav.kiv.antipatterndetectionapp.v2.service;
+
+import cz.zcu.fav.kiv.antipatterndetectionapp.model.Query;
+import cz.zcu.fav.kiv.antipatterndetectionapp.model.QueryResult;
+import cz.zcu.fav.kiv.antipatterndetectionapp.v2.model.UserDetectionDto;
+import org.springframework.stereotype.Service;
+
+import java.util.List;
+
+public interface DetectionService {
+    Query getAllProjectsAndAntipatterns();
+    List<QueryResult> analyze(UserDetectionDto detectionRequest);
+
+}
diff --git a/src/main/java/cz/zcu/fav/kiv/antipatterndetectionapp/v2/service/DetectionServiceImpl.java b/src/main/java/cz/zcu/fav/kiv/antipatterndetectionapp/v2/service/DetectionServiceImpl.java
new file mode 100644
index 0000000..9c84b61
--- /dev/null
+++ b/src/main/java/cz/zcu/fav/kiv/antipatterndetectionapp/v2/service/DetectionServiceImpl.java
@@ -0,0 +1,60 @@
+package cz.zcu.fav.kiv.antipatterndetectionapp.v2.service;
+
+import cz.zcu.fav.kiv.antipatterndetectionapp.detecting.AntiPatternManager;
+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.Configuration;
+import cz.zcu.fav.kiv.antipatterndetectionapp.v2.model.User;
+import cz.zcu.fav.kiv.antipatterndetectionapp.v2.model.UserDetectionDto;
+import cz.zcu.fav.kiv.antipatterndetectionapp.v2.utils.JSONBuilder;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+import java.util.List;
+import java.util.Map;
+
+@Service
+public class DetectionServiceImpl implements DetectionService{
+    @Autowired
+    ConfigService configService;
+
+    @Autowired
+    private ProjectService projectService;
+
+    @Autowired
+    private AntiPatternService antiPatternService;
+
+    @Autowired
+    private AntiPatternManager antiPatternManager;
+
+    @Autowired
+    private UserService userService;
+
+    @Autowired
+    private ConfigurationService configurationService;
+
+    @Override
+    public Query getAllProjectsAndAntipatterns() {
+        Query q = new Query(projectService.getAllProjects(), antiPatternService.antiPatternsToModel(antiPatternService.getAllAntiPatterns()));
+        return q;
+    }
+
+    @Override
+    public List<QueryResult> analyze(UserDetectionDto detectionRequest) {
+        //User user = userService.getUserByName(detectionRequest.getUserName());
+        int configurationId = detectionRequest.getConfigurationId();
+        //String currentConfigurationName = this.configService.getConfigurationName(user.getId(), configurationId);
+        Configuration cfg = this.configService.getConfigurationById(configurationId);
+
+        //namapovat cfg do jsonu
+        Map<String, Map<String,String>> currentConfiguration = JSONBuilder.createMapFromString(cfg.getConfig());
+
+        String[] selectedProjects = detectionRequest.getSelectedProjects();
+        String[] selectedAntiPatterns = detectionRequest.getSelectedAntipatterns();
+        List<QueryResult> results = antiPatternManager.analyze(selectedProjects, selectedAntiPatterns, currentConfiguration);
+        return results;
+    }
+}
