commit 031c4f3c59875788c3e5bcfbf707c9db8512de96
Author: Hrabikv <hrabikv@students.zcu.cz>
Date:   Fri Oct 20 15:48:19 2023 +0200

    https://kivprogrammers.atlassian.net/browse/TSP2-30 přidání posílání antiPatternů

diff --git a/src/main/java/cz/zcu/fav/kiv/antipatterndetectionapp/repository/AntiPatternRepository.java b/src/main/java/cz/zcu/fav/kiv/antipatterndetectionapp/repository/AntiPatternRepository.java
index 72e03f7..c2313bb 100644
--- a/src/main/java/cz/zcu/fav/kiv/antipatterndetectionapp/repository/AntiPatternRepository.java
+++ b/src/main/java/cz/zcu/fav/kiv/antipatterndetectionapp/repository/AntiPatternRepository.java
@@ -137,7 +137,7 @@ public class AntiPatternRepository {
      * @param jsonFileName Name of the file
      * @return AntiPattern object
      */
-    private AntiPattern getAntiPatternFromJsonFile(String jsonFileName){
+    public AntiPattern getAntiPatternFromJsonFile(String jsonFileName){
         String json = "";  // json configuration file content as string
 
         LOGGER.info("Reading anti-pattern from json file " + jsonFileName);
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 fe755b0..f7c6595 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,6 +1,8 @@
 package cz.zcu.fav.kiv.antipatterndetectionapp.v2.controller;
 
 import com.google.gson.Gson;
+import cz.zcu.fav.kiv.antipatterndetectionapp.model.AntiPattern;
+import cz.zcu.fav.kiv.antipatterndetectionapp.repository.AntiPatternRepository;
 import cz.zcu.fav.kiv.antipatterndetectionapp.v2.dials.ConfigurationControllerStatusCodes;
 import cz.zcu.fav.kiv.antipatterndetectionapp.v2.model.*;
 import cz.zcu.fav.kiv.antipatterndetectionapp.v2.service.configuration.ConfigService;
@@ -41,13 +43,7 @@ public class ConfigurationController {
         return new ResponseEntity<>(JSONBuilder.buildJSON(json),HttpStatus.valueOf(returnCode.getStatusCode()));
     }
 
-    /**
-     * Endpoint returns the definitions of configurations (ie the json objects) and their names
-     * @param user User querying the configurations
-     * @return ResponseEntity with json body  appropriate status code indicating result of the operation
-     *         200 with requested body if everything is okay
-     *         500 if db server died or no default configurations are present in the database
-     */
+
     @PostMapping(value="/configuration")
     public ResponseEntity<String> getConfiguration(@RequestBody UserConfiguration userConfiguration) {
         Map<String, Object> json = new HashMap<>();
@@ -55,12 +51,20 @@ public class ConfigurationController {
 
         Configuration config = this.configurationService.getConfiguration(userConfiguration.getUser().getName(), Integer.parseInt(userConfiguration.getId()));
 
-        if(config == null) {
+        Map<String, AntiPattern> antiPatterns = this.configurationService.getAntiPatterns();
+
+        if (config == null) {
+            json.put("message", "internal sever error");
+            return new ResponseEntity<>(JSONBuilder.buildJSON(json), HttpStatus.INTERNAL_SERVER_ERROR);
+        }
+
+        if (antiPatterns == null) {
             json.put("message", "internal sever error");
             return new ResponseEntity<>(JSONBuilder.buildJSON(json), HttpStatus.INTERNAL_SERVER_ERROR);
         }
 
         json.put("configuration", config.getConfig());
+        json.put("antiPatterns", antiPatterns);
 
         return new ResponseEntity<>(new Gson().toJson(json),HttpStatus.OK);
 
diff --git a/src/main/java/cz/zcu/fav/kiv/antipatterndetectionapp/v2/service/configuration/ConfigService.java b/src/main/java/cz/zcu/fav/kiv/antipatterndetectionapp/v2/service/configuration/ConfigService.java
index b79c3d2..4f3de98 100644
--- a/src/main/java/cz/zcu/fav/kiv/antipatterndetectionapp/v2/service/configuration/ConfigService.java
+++ b/src/main/java/cz/zcu/fav/kiv/antipatterndetectionapp/v2/service/configuration/ConfigService.java
@@ -1,10 +1,13 @@
 package cz.zcu.fav.kiv.antipatterndetectionapp.v2.service.configuration;
+import cz.zcu.fav.kiv.antipatterndetectionapp.model.AntiPattern;
 import cz.zcu.fav.kiv.antipatterndetectionapp.v2.dials.ConfigurationControllerStatusCodes;
 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 java.util.List;
+import java.util.Map;
+
 public interface ConfigService {
     //upload configuration
     ConfigurationControllerStatusCodes addConfiguration(Configuration cfg);
@@ -20,5 +23,5 @@ public interface ConfigService {
     public Configuration getConfiguration(String userName, int id);
     String getConfigurationName(int userId, int configurationId);
 
-
+    Map<String, AntiPattern> getAntiPatterns();
 }
diff --git a/src/main/java/cz/zcu/fav/kiv/antipatterndetectionapp/v2/service/configuration/ConfigurationServiceImplementation.java b/src/main/java/cz/zcu/fav/kiv/antipatterndetectionapp/v2/service/configuration/ConfigurationServiceImplementation.java
index 97782c7..0b5054a 100644
--- a/src/main/java/cz/zcu/fav/kiv/antipatterndetectionapp/v2/service/configuration/ConfigurationServiceImplementation.java
+++ b/src/main/java/cz/zcu/fav/kiv/antipatterndetectionapp/v2/service/configuration/ConfigurationServiceImplementation.java
@@ -1,6 +1,8 @@
 package cz.zcu.fav.kiv.antipatterndetectionapp.v2.service.configuration;
 
 import com.google.gson.Gson;
+import cz.zcu.fav.kiv.antipatterndetectionapp.model.AntiPattern;
+import cz.zcu.fav.kiv.antipatterndetectionapp.repository.AntiPatternRepository;
 import cz.zcu.fav.kiv.antipatterndetectionapp.v2.dials.ConfigurationControllerStatusCodes;
 import cz.zcu.fav.kiv.antipatterndetectionapp.v2.model.*;
 import cz.zcu.fav.kiv.antipatterndetectionapp.v2.repository.ConfigRepository;
@@ -11,7 +13,9 @@ import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
 import java.util.ArrayList;
+import java.util.HashMap;
 import java.util.List;
+import java.util.Map;
 
 @Service
 public class ConfigurationServiceImplementation implements ConfigService {
@@ -21,6 +25,15 @@ public class ConfigurationServiceImplementation implements ConfigService {
     //repository for Join table, necessary to add associations between users and configurations
     @Autowired
     private UserConfigurationJoinRepository userConfigurationJoinRepository;
+
+    @Autowired
+    private AntiPatternRepository antiPatternRepository;
+
+    private String[] configJsonFileNames = {"BusinessAsUsual.json", "BystanderApathy.json", "LongOrNonExistentFeedbackLoops.json",
+            "NinetyNinetyRule.json", "RoadToNowhere.json", "SpecifyNothing.json", "TooLongSprint.json", "UnknownPoster.json",
+            "VaryingSprintLength.json", "YetAnotherProgrammer.json"};
+
+
     //user service is also necessary for retrieving information about users (primarily database query for fetching id)
     @Autowired
     private UserService userService;
@@ -164,4 +177,15 @@ public class ConfigurationServiceImplementation implements ConfigService {
     public String getConfigurationName(int userId, int configurationId) {
         return this.configurationRepository.findConfigurationByCompoundKey(new UserConfigKey(userId, configurationId));
     }
+
+    @Override
+    public Map<String, AntiPattern> getAntiPatterns() {
+        Map<String, AntiPattern> antiPatterns = new HashMap<>();
+        AntiPattern tmp = null;
+        for (int i = 0; i < this.configJsonFileNames.length; i++) {
+            tmp = this.antiPatternRepository.getAntiPatternFromJsonFile(configJsonFileNames[i]);
+            antiPatterns.put(tmp.getName(), tmp);
+        }
+        return antiPatterns;
+    }
 }
