commit 2cb88500a4ae2e9beae9484391c4398a09568761
Author: Jiri Trefil <badjokke@gmail.com>
Date:   Mon May 8 18:55:42 2023 +0200

    #10621 osetreni empty array z detekce

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 8e90781..a2def1b 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
@@ -8,6 +8,7 @@ import org.springframework.http.HttpStatus;
 import org.springframework.http.ResponseEntity;
 import org.springframework.web.bind.annotation.*;
 
+import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
@@ -37,13 +38,23 @@ public class ConfigurationController {
     @PostMapping(value="/configuration_name")
     public ResponseEntity<String> getConfigurationNames(@RequestBody User user) {
         Map<String, Object> json = new HashMap<>();
-        List<String> configuration = this.configurationService.getConfigurationNames(user);
+        List<Object[]> configuration = this.configurationService.getConfigurationNamesAndIds(user);
         if(configuration == null) {
             json.put("message", "internal sever error");
             return new ResponseEntity<>(JSONBuilder.buildJSON(json), HttpStatus.INTERNAL_SERVER_ERROR);
         }
+        List<String> configurationNames = new ArrayList<>();
+        List<Integer> configurationIds = new ArrayList<>();
+        for(Object[] o : configuration){
+            String name = (String) o[0];
+            int id = (int) o[1];
+            configurationNames.add(name);
+            configurationIds.add(id);
+        }
         json.put("message", "ok");
-        json.put("configuration_names", configuration);
+        json.put("configuration_names", configurationNames);
+        json.put("configuration_ids", configurationIds);
+
         String jsonString = JSONBuilder.buildJSON(json);
         return new ResponseEntity<>(jsonString, HttpStatus.OK);
     }
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 e840848..ef9fb3d 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,6 +1,8 @@
 package cz.zcu.fav.kiv.antipatterndetectionapp.v2.controller;
 
 import com.google.gson.Gson;
+import com.google.gson.JsonElement;
+import com.google.gson.JsonObject;
 import cz.zcu.fav.kiv.antipatterndetectionapp.detecting.AntiPatternManager;
 import cz.zcu.fav.kiv.antipatterndetectionapp.model.AntiPattern;
 import cz.zcu.fav.kiv.antipatterndetectionapp.model.Project;
@@ -16,6 +18,7 @@ import org.springframework.http.HttpStatus;
 import org.springframework.http.ResponseEntity;
 import org.springframework.web.bind.annotation.*;
 
+import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 
@@ -36,11 +39,24 @@ public class DetectController {
 
     @PostMapping("/analyze")
     public ResponseEntity<String> detect(@RequestBody UserDetectionDto detectionRequest) {
-
+        final String[] projects = detectionRequest.getSelectedProjects();
+        if(projects == null ||projects.length == 0){
+            return sendDetectionBadRequest("No projects provided in request");
+        }
+        final String[] patterns = detectionRequest.getSelectedAntipatterns();
+        if(patterns == null ||patterns.length == 0){
+            return sendDetectionBadRequest("No antipatterns provided in request");
+        }
         List<QueryResult> results = detectionService.analyze(detectionRequest);
         //Map<String, Map<String, String>> currentConfiguration = configurationService.getConfigurationByName();
         return ResponseEntity.ok(new Gson().toJson(results));
+    }
+
 
+    private ResponseEntity<String> sendDetectionBadRequest(String message){
+        Map<String,String> error = new HashMap<>();
+        error.put("message",message);
+        return new ResponseEntity<>(new Gson().toJson(error), HttpStatus.BAD_REQUEST);
     }
 
 
diff --git a/src/main/java/cz/zcu/fav/kiv/antipatterndetectionapp/v2/model/UserConfigurationJoin.java b/src/main/java/cz/zcu/fav/kiv/antipatterndetectionapp/v2/model/UserConfigurationJoin.java
index 3fef2e8..045f283 100644
--- a/src/main/java/cz/zcu/fav/kiv/antipatterndetectionapp/v2/model/UserConfigurationJoin.java
+++ b/src/main/java/cz/zcu/fav/kiv/antipatterndetectionapp/v2/model/UserConfigurationJoin.java
@@ -20,7 +20,6 @@ public class UserConfigurationJoin {
     public UserConfigurationJoin(){
     }
 
-
     public UserConfigurationJoin(UserConfigKey id, String configurationName){
         this.configurationName = configurationName;
         this.id = id;
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 04d86a9..23ee53c 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
@@ -2,6 +2,7 @@ package cz.zcu.fav.kiv.antipatterndetectionapp.v2.repository;
 
 import cz.zcu.fav.kiv.antipatterndetectionapp.v2.model.Configuration;
 import cz.zcu.fav.kiv.antipatterndetectionapp.v2.model.UserConfigKey;
+import cz.zcu.fav.kiv.antipatterndetectionapp.v2.model.UserConfigurationJoin;
 import org.springframework.beans.factory.annotation.Value;
 import org.springframework.data.jpa.repository.JpaRepository;
 import org.springframework.data.jpa.repository.Modifying;
@@ -25,8 +26,8 @@ public interface ConfigRepository extends JpaRepository<Configuration,Integer> {
     List<Configuration> getAllUserConfigurations(int userId);
 
     //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,userconfig.id.configId from UserConfigurationJoin userconfig where userconfig.id.userId = ?1 or userconfig.id.userId=2")
+    List<Object[]> 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
index adccf3b..be30b51 100644
--- 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
@@ -13,7 +13,7 @@ public interface ConfigService {
     //get all configurations available to user
     ResponseEntity<String> getUserConfigurations(User user);
 
-    List<String> getConfigurationNames(User user);
+    List<Object[]> getConfigurationNamesAndIds(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/ConfigurationServiceImplementation.java b/src/main/java/cz/zcu/fav/kiv/antipatterndetectionapp/v2/service/ConfigurationServiceImplementation.java
index b5f3106..3f614c9 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
@@ -121,7 +121,7 @@ public class ConfigurationServiceImplementation implements ConfigService {
     }
 
     @Override
-    public List<String> getConfigurationNames(User user) {
+    public List<Object[]> getConfigurationNamesAndIds(User user) {
         final String userName = user.getName();
         if(userName == null){
             return null;
@@ -130,8 +130,8 @@ public class ConfigurationServiceImplementation implements ConfigService {
         User userInfo = this.userService.getUserByName(userName);
         //fetch all configurations this particular user can see
         //ie all public configs + configurations uploaded by this particular user
-        List<String> configurationNames = this.configurationRepository.getAllUserConfigurationNames(userInfo.getId());
-        return configurationNames;
+        List<Object[]> configurations = this.configurationRepository.getAllUserConfigurationNames(userInfo.getId());
+        return configurations;
     }
 
     @Override
