commit fe28bf6bd9fb546a89a905c6d371fc13eb82fae9
Author: Jiri Trefil <badjokke@gmail.com>
Date:   Tue Dec 19 21:27:48 2023 +0100

    opraveny status codes - neni chtene hodit 500, kdyz server zpracuje spravne request.
    upraveny selecty pro podporu default konfigurace

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 c5360b0..71b51ca 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
@@ -74,13 +74,13 @@ public class ConfigurationController {
         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);
+            json.put("message", "no configurations found");
+            return new ResponseEntity<>(JSONBuilder.buildJSON(json), HttpStatus.BAD_REQUEST);
         }
 
         if (antiPatterns == null) {
-            json.put("message", "internal sever error");
-            return new ResponseEntity<>(JSONBuilder.buildJSON(json), HttpStatus.INTERNAL_SERVER_ERROR);
+            json.put("message", "no anti patterns found");
+            return new ResponseEntity<>(JSONBuilder.buildJSON(json), HttpStatus.NOT_FOUND);
         }
 
         json.put("configuration", config.getConfig());
diff --git a/src/main/java/cz/zcu/fav/kiv/antipatterndetectionapp/v2/model/UserConfigKey.java b/src/main/java/cz/zcu/fav/kiv/antipatterndetectionapp/v2/model/UserConfigKey.java
index 745ef4c..4b54e34 100644
--- a/src/main/java/cz/zcu/fav/kiv/antipatterndetectionapp/v2/model/UserConfigKey.java
+++ b/src/main/java/cz/zcu/fav/kiv/antipatterndetectionapp/v2/model/UserConfigKey.java
@@ -6,7 +6,6 @@ import java.io.Serializable;
 /**
  * @Author Jiri Trefil
  * primary key of table user_configuration is compound (userId,configurationId) pair is unique
- * @Deprecated not being used (29.04.2023)
  * the business logic involving this table is in ConfigurationRepository interface
  */
 @Embeddable
@@ -37,6 +36,7 @@ public UserConfigKey(int userId,int configId){
     }
 
     public UserConfigKey() {
-
+        this.userId = -1;
+        this.configId = -1;
     }
 }
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 6954251..03d9a1b 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
@@ -8,6 +8,7 @@ import org.springframework.beans.factory.annotation.Value;
 import org.springframework.data.jpa.repository.JpaRepository;
 import org.springframework.data.jpa.repository.Modifying;
 import org.springframework.data.jpa.repository.Query;
+import org.springframework.data.repository.query.Param;
 import org.springframework.stereotype.Repository;
 import org.springframework.transaction.annotation.Transactional;
 
@@ -22,7 +23,7 @@ public interface ConfigRepository extends JpaRepository<Configuration,Integer> {
     List<Configuration> getPublicConfigurations();
     //retrieve all public configurations and configurations available to the user
     //assumption - default configurations are not assigned to any user explicitly
-    @Query("select config, userconfig from Configuration config inner join UserConfigurationJoin userconfig on config.id = userconfig.id.configId where userconfig.id.userId = ?1 or config.isDefault = 'Y'")
+    @Query("select config, userconfig from Configuration config left join UserConfigurationJoin userconfig on config.id = userconfig.id.configId where userconfig.id.userId = ?1 or config.isDefault = 'Y'")
     List<Object[]> getAllUserConfigurations(int userId);
 
     @Modifying
@@ -38,12 +39,11 @@ public interface ConfigRepository extends JpaRepository<Configuration,Integer> {
     @Query("select userconfig.configurationName from UserConfigurationJoin userconfig where userconfig.id = ?1")
     String findConfigurationByCompoundKey(UserConfigKey key);
 
-    @Query("SELECT \n" +
-            "cfg \n" +
-            "FROM \n" +
-            "UserConfigurationJoin userconfig INNER JOIN Configuration cfg \n" +
-            "ON userconfig.id.configId = cfg.id\n" +
-            "WHERE\n" +
-            "userconfig.id = ?1")
-    Configuration findConfigurationByUserNameAndID(UserConfigKey key);
+    @Query("SELECT cfg FROM UserConfigurationJoin userconfig RIGHT JOIN Configuration cfg " +
+            "ON userconfig.id.configId = cfg.id " +
+            "WHERE userconfig.id = ?1 or (cfg.isDefault = 'Y' and cfg.id = ?2)")
+    Configuration findConfigurationByUserNameAndID(UserConfigKey key,int configId);
+
+
+
 }
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 c3ba1f9..d43caa0 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
@@ -247,7 +247,7 @@ public class ConfigurationServiceImplementation implements ConfigService {
             return null;
         }
         UserConfigKey key = new UserConfigKey(user.getId(), id);
-        Configuration configuration = this.configurationRepository.findConfigurationByUserNameAndID(key);
+        Configuration configuration = this.configurationRepository.findConfigurationByUserNameAndID(key,key.getConfigId());
         return configuration;
     }
 
