commit 536a33e6c4d0229554206a5245bfedd908d12946
Author: Pavel Fidransky <pavel.fidransky@yoso.fi>
Date:   Sat Jun 27 14:51:02 2020 +0200

    re #41 simplify enum conversion

diff --git a/server/src/main/java/org/danekja/ymanager/domain/RequestType.java b/server/src/main/java/org/danekja/ymanager/domain/RequestType.java
index 0f618c0..f65d0ed 100644
--- a/server/src/main/java/org/danekja/ymanager/domain/RequestType.java
+++ b/server/src/main/java/org/danekja/ymanager/domain/RequestType.java
@@ -12,21 +12,5 @@ public enum RequestType {
     /**
      * The request for an authorization.
      */
-    AUTHORIZATION;
-
-    /**
-     * Creates the type of a request from the provided string.
-     * The method is case insensitive. If the given string does not correspond to any values of the enum the method returns null.
-     *
-     * @param type the string representation of the type of a request
-     * @return the value of the enum or null
-     */
-    public static RequestType getType(final String type) {
-        if (type == null || type.isEmpty()) return null;
-        try {
-            return RequestType.valueOf(type.toUpperCase());
-        } catch (final IllegalArgumentException e) {
-            return null;
-        }
-    }
+    AUTHORIZATION,
 }
diff --git a/server/src/main/java/org/danekja/ymanager/domain/Status.java b/server/src/main/java/org/danekja/ymanager/domain/Status.java
index 4e709c9..e915160 100644
--- a/server/src/main/java/org/danekja/ymanager/domain/Status.java
+++ b/server/src/main/java/org/danekja/ymanager/domain/Status.java
@@ -17,21 +17,5 @@ public enum Status {
     /**
      * The subject of a request is rejected.
      */
-    REJECTED;
-
-    /**
-     * Creates the status from the provided string.
-     * The method is case insensitive. If the given string does not correspond to any values of the enum the method returns null.
-     *
-     * @param status the string representation of the status
-     * @return the value of the enum or null
-     */
-    public static Status getStatus(final String status) {
-        if (status == null || status.isEmpty()) return null;
-        try {
-            return Status.valueOf(status.toUpperCase());
-        } catch (final IllegalArgumentException e) {
-            return null;
-        }
-    }
+    REJECTED,
 }
diff --git a/server/src/main/java/org/danekja/ymanager/repository/RequestRepository.java b/server/src/main/java/org/danekja/ymanager/repository/RequestRepository.java
index da4b591..27fd30b 100644
--- a/server/src/main/java/org/danekja/ymanager/repository/RequestRepository.java
+++ b/server/src/main/java/org/danekja/ymanager/repository/RequestRepository.java
@@ -43,7 +43,7 @@ public class RequestRepository {
             request.setFirstName(resultSet.getString("first_name"));
             request.setLastName(resultSet.getString("last_name"));
             request.setTimestamp(resultSet.getTimestamp("creation_date").toLocalDateTime());
-            request.setStatus(Status.getStatus(resultSet.getString("status")));
+            request.setStatus(Status.valueOf(resultSet.getString("status")));
             return request;
         }
     }
@@ -85,7 +85,7 @@ public class RequestRepository {
 
             request.setTimestamp(resultSet.getTimestamp("v.creation_date").toLocalDateTime());
             request.setType(VacationType.getVacationType(resultSet.getString("v.vacation_type")));
-            request.setStatus(Status.getStatus(resultSet.getString("v.status")));
+            request.setStatus(Status.valueOf(resultSet.getString("v.status")));
             return request;
         }
     }
diff --git a/server/src/main/java/org/danekja/ymanager/repository/UserRepository.java b/server/src/main/java/org/danekja/ymanager/repository/UserRepository.java
index 9ad8ad5..ed976dc 100644
--- a/server/src/main/java/org/danekja/ymanager/repository/UserRepository.java
+++ b/server/src/main/java/org/danekja/ymanager/repository/UserRepository.java
@@ -170,7 +170,7 @@ public class UserRepository {
         user.setEmail((String) resultMap.get("out_email"));
         user.setPhoto((String) resultMap.get("out_photo"));
         user.setRole(getUserRole((String) resultMap.get("out_role")));
-        user.setStatus(Status.getStatus((String) resultMap.get("out_status")));
+        user.setStatus(Status.valueOf((String) resultMap.get("out_status")));
         return user;
 
     }
diff --git a/server/src/main/java/org/danekja/ymanager/repository/VacationRepository.java b/server/src/main/java/org/danekja/ymanager/repository/VacationRepository.java
index cf5dfdc..b5db971 100644
--- a/server/src/main/java/org/danekja/ymanager/repository/VacationRepository.java
+++ b/server/src/main/java/org/danekja/ymanager/repository/VacationRepository.java
@@ -19,7 +19,6 @@ import java.util.List;
 import java.util.Optional;
 
 import static java.util.Optional.ofNullable;
-import static org.danekja.ymanager.domain.Status.getStatus;
 
 @Repository
 public class VacationRepository {
@@ -56,7 +55,7 @@ public class VacationRepository {
                 item.setTo(timeTo.toLocalTime());
             }
 
-            item.setStatus(getStatus(resultSet.getString("v.status")));
+            item.setStatus(Status.valueOf(resultSet.getString("v.status")));
             item.setType(VacationType.getVacationType(resultSet.getString("v.vacation_type")));
             return item;
         }
@@ -140,7 +139,7 @@ public class VacationRepository {
                     }
 
                     vacation.setCreationDate(rs.getTimestamp("creation_date").toLocalDateTime());
-                    vacation.setStatus(getStatus(rs.getString("status")));
+                    vacation.setStatus(Status.valueOf(rs.getString("status")));
                     vacation.setType(VacationType.getVacationType(rs.getString("vacation_type")));
                     vacation.setUserId(rs.getLong("user_id"));
                     return vacation;
diff --git a/server/src/main/java/org/danekja/ymanager/ws/rest/ApiController.java b/server/src/main/java/org/danekja/ymanager/ws/rest/ApiController.java
index e92503f..19a9f44 100644
--- a/server/src/main/java/org/danekja/ymanager/ws/rest/ApiController.java
+++ b/server/src/main/java/org/danekja/ymanager/ws/rest/ApiController.java
@@ -38,17 +38,17 @@ public class ApiController {
     @RequestMapping(value = "/users/requests/vacation", method=GET)
     public List<VacationRequest> usersRequestsVacation(
             @RequestParam(value = "lang", required = false) String lang,
-            @RequestParam(value = "status", required = false) String status)
+            @RequestParam(value = "status", required = false) Status status)
     {
-        return manager.getVacationRequests(Status.getStatus(status));
+        return manager.getVacationRequests(status);
     }
 
     @RequestMapping(value = "/users/requests/authorization", method=GET)
     public List<AuthorizationRequest> userRequestsAuthorization(
             @RequestParam(value = "lang", required = false) String lang,
-            @RequestParam(value = "status", required = false) String status)
+            @RequestParam(value = "status", required = false) Status status)
     {
-        return manager.getAuthorizationRequests(Status.getStatus(status));
+        return manager.getAuthorizationRequests(status);
     }
 
     @RequestMapping(value = "/user/{id}/calendar", method=GET)
@@ -57,12 +57,12 @@ public class ApiController {
             @RequestParam(value = "lang", required = false) String lang,
             @RequestParam(value = "from") String from,
             @RequestParam(value = "to", required = false) String to,
-            @RequestParam(value = "status", required = false) String status)
+            @RequestParam(value = "status", required = false) Status status)
     {
         DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy/MM/dd");
         LocalDate fromDate = LocalDate.parse(from, formatter);
         LocalDate toDate = to != null ? LocalDate.parse(to, formatter) : null;
-        return manager.getUserCalendar(id, fromDate, toDate, Status.getStatus(status));
+        return manager.getUserCalendar(id, fromDate, toDate, status);
     }
 
     @RequestMapping(value = "/settings", method=GET)
@@ -128,10 +128,10 @@ public class ApiController {
     @RequestMapping(value = "/user/requests", method=PUT)
     public ResponseEntity<Void> userRequests(
             @RequestParam(value = "lang", required = false) String lang,
-            @RequestParam(value = "type", required = true) String type,
+            @RequestParam(value = "type") RequestType type,
             @RequestBody BasicRequest request)
     {
-        manager.changeRequest(RequestType.getType(type), request);
+        manager.changeRequest(type, request);
 
         return ResponseEntity.ok().build();
     }
diff --git a/server/src/main/java/org/danekja/ymanager/ws/rest/UserController.java b/server/src/main/java/org/danekja/ymanager/ws/rest/UserController.java
index 1076801..ff1a16c 100644
--- a/server/src/main/java/org/danekja/ymanager/ws/rest/UserController.java
+++ b/server/src/main/java/org/danekja/ymanager/ws/rest/UserController.java
@@ -29,8 +29,8 @@ public class UserController {
     @GetMapping
     public List<BasicProfileUser> users(
             @RequestParam(value = "lang", required = false) String lang,
-            @RequestParam(value = "status", required = false) String status) {
-        return userManager.getUsers(Status.getStatus(status));
+            @RequestParam(value = "status", required = false) Status status) {
+        return userManager.getUsers(status);
     }
 
 
