From d36ddc4e347f55cbd1de62103e4218cdcd5c591b Mon Sep 17 00:00:00 2001 From: Saidgdk Date: Thu, 22 Jun 2023 11:58:22 +0200 Subject: [PATCH] added missing documentation --- .../calender/api/KalenderRestController.java | 13 +++++- .../calender/changes/query/Filter.java | 10 +++++ .../ErrorTypes/ValidationError.java | 9 +++- .../calender/planTimes/CalendarWeek.java | 45 +++++++++++++++++++ .../nttdata/calender/planTimes/PlanTimes.java | 35 +++++++++++++++ .../calender/planTimes/PlanTimesRequest.java | 35 +++++++++++++++ 6 files changed, 143 insertions(+), 4 deletions(-) diff --git a/backend/src/main/java/com/nttdata/calender/api/KalenderRestController.java b/backend/src/main/java/com/nttdata/calender/api/KalenderRestController.java index d3387e3..a1455d6 100644 --- a/backend/src/main/java/com/nttdata/calender/api/KalenderRestController.java +++ b/backend/src/main/java/com/nttdata/calender/api/KalenderRestController.java @@ -115,9 +115,18 @@ public class KalenderRestController { return urlConstructor.construct(javaAPI); } + /** + * Handles POST request to fetch plan times based on the provided request. + * + * @param request the PlanTimesRequest containing the required information + * @return the ArrayList of CalendarWeek representing the fetched plan times + * @throws ARException if an AR exception occurs + * @throws ValidationError if a validation error occurs + */ @CrossOrigin("*") - @PostMapping("/api/fetchPlanTimes") - public ArrayList getPlanTimes(@RequestBody PlanTimesRequest request) throws ARException, ValidationError { + @PostMapping("/api/fetchPlanTimes") + public ArrayList getPlanTimes(@RequestBody PlanTimesRequest request) + throws ARException, ValidationError { PlanTimes p = new PlanTimes(javaAPI); p.setPlanTimes(request); return p.getPlanTimes(); diff --git a/backend/src/main/java/com/nttdata/calender/changes/query/Filter.java b/backend/src/main/java/com/nttdata/calender/changes/query/Filter.java index 2f7f801..e9b2b78 100644 --- a/backend/src/main/java/com/nttdata/calender/changes/query/Filter.java +++ b/backend/src/main/java/com/nttdata/calender/changes/query/Filter.java @@ -57,10 +57,20 @@ public class Filter { this.filterElement.add(filter); } + /** + * Sets the filter element. + * + * @param filter the filter element to set + */ public void setFilterElement(ArrayList filter) { this.filterElement = filter; } + /** + * Gets the filter element. + * + * @return the filter element + */ public ArrayList getFilterElement() { return this.filterElement; } diff --git a/backend/src/main/java/com/nttdata/calender/errorhandling/ErrorTypes/ValidationError.java b/backend/src/main/java/com/nttdata/calender/errorhandling/ErrorTypes/ValidationError.java index dab4b7a..924971c 100644 --- a/backend/src/main/java/com/nttdata/calender/errorhandling/ErrorTypes/ValidationError.java +++ b/backend/src/main/java/com/nttdata/calender/errorhandling/ErrorTypes/ValidationError.java @@ -4,12 +4,17 @@ import org.springframework.http.HttpStatus; /** * Error class representing a Validation Error. - * It extends the BackendError class and sets the error code to 400 and the HTTP status to HttpStatus.BAD_REQUEST. + * It extends the BackendError class and sets the error code to 400 and the HTTP + * status to HttpStatus.BAD_REQUEST. */ public class ValidationError extends BackendError { + /** + * Constructs a new ValidationError with the specified error message. + * + * @param message the error message + */ public ValidationError(String message) { super(message, 400, HttpStatus.BAD_REQUEST); } - } diff --git a/backend/src/main/java/com/nttdata/calender/planTimes/CalendarWeek.java b/backend/src/main/java/com/nttdata/calender/planTimes/CalendarWeek.java index f099ff3..a931e3e 100644 --- a/backend/src/main/java/com/nttdata/calender/planTimes/CalendarWeek.java +++ b/backend/src/main/java/com/nttdata/calender/planTimes/CalendarWeek.java @@ -1,39 +1,84 @@ package com.nttdata.calender.planTimes; +/** + * The CalendarWeek class represents a week in a calendar. + * It contains information about the week, planned time, start date, and end + * date. + */ public class CalendarWeek { private String week; private int planTime; private String startDate; private String endDate; + /** + * Gets the week. + * + * @return String representing the week + */ public String getWeek() { return week; } + /** + * Sets the week. + * + * @param week String to set representing the week + */ public void setWeek(String week) { this.week = week; } + /** + * Gets the planned time. + * + * @return int representing the planned time + */ public int getPlanTime() { return planTime; } + /** + * Sets the planned time. + * + * @param planTime an int to set representing the planned time + */ public void setPlanTime(int planTime) { this.planTime = planTime; } + /** + * Gets the start date. + * + * @return String representing the start date + */ public String getStartDate() { return startDate; } + /** + * Sets the start date. + * + * @param startDate String to set representing the start date + */ public void setStartDate(String startDate) { this.startDate = startDate; } + /** + * Gets the end date. + * + * @return String representing the end date + */ public String getEndDate() { return endDate; } + /** + * Sets the end date. + * + * @param endDate String to set representing the end date + */ public void setEndDate(String endDate) { this.endDate = endDate; } diff --git a/backend/src/main/java/com/nttdata/calender/planTimes/PlanTimes.java b/backend/src/main/java/com/nttdata/calender/planTimes/PlanTimes.java index e4e6274..2612107 100644 --- a/backend/src/main/java/com/nttdata/calender/planTimes/PlanTimes.java +++ b/backend/src/main/java/com/nttdata/calender/planTimes/PlanTimes.java @@ -14,16 +14,32 @@ import com.nttdata.calender.api.Query; import com.nttdata.calender.api.RemedyJavaAPI; import com.nttdata.calender.errorhandling.ErrorTypes.ValidationError; +/** + * The PlanTimes class manages the calculation of planned times for calendar weeks. + * It interacts with RemedyJavaAPI and performs queries to retrieve relevant data. + */ public class PlanTimes { private RemedyJavaAPI remedyJavaAPI; private ArrayList calenderWeeks; private final String formName = "ASF:WI_TAS_Paket"; + /** + * Constructs a PlanTimes object with the provided RemedyJavaAPI instance. + * + * @param remedyJavaAPI the RemedyJavaAPI instance to use for data retrieval + */ public PlanTimes(RemedyJavaAPI remedyJavaAPI) { this.remedyJavaAPI = remedyJavaAPI; this.calenderWeeks = new ArrayList<>(); } + /** + * Sets the plan times for calendar weeks based on the provided PlanTimesRequest. + * + * @param req the PlanTimesRequest object containing the required information + * @throws ARException if an error occurs during the Remedy API operation + * @throws ValidationError if there is a validation error + */ public void setPlanTimes(PlanTimesRequest req) throws ARException, ValidationError { var dateConverter = new DateConverter(); var startDate = dateConverter.convertDateTime(req.getRenderStartDate()); @@ -75,6 +91,14 @@ public class PlanTimes { } } + /** + * Converts plan time hours and minutes to a decimal value. + * + * @param hours the plan time hours as a String + * @param minutes the plan time minutes as a String + * @return the total plan time as a decimal value + * @throws ARException if an error occurs during the conversion + */ public double convertPlanTime(String hours, String minutes) throws ARException { double mins = 0.0; double hrs = 0.0; @@ -86,6 +110,12 @@ public class PlanTimes { return totalHours; } + /** + * Converts a timestamp string to a LocalDate object. + * + * @param timestamp the timestamp string to convert + * @return the corresponding LocalDate object + */ public LocalDate timestampToDate(String timestamp) { DateTimeFormatter formatter = DateTimeFormatter.ofPattern("dd.MM.yyyy"); SimpleDateFormat sdf = new SimpleDateFormat("dd.MM.yyyy"); @@ -99,6 +129,11 @@ public class PlanTimes { return LocalDate.parse(date, formatter); } + /** + * Retrieves the calculated plan times for calendar weeks. + * + * @return the list of CalendarWeek objects representing the plan times + */ public ArrayList getPlanTimes() { return this.calenderWeeks; } diff --git a/backend/src/main/java/com/nttdata/calender/planTimes/PlanTimesRequest.java b/backend/src/main/java/com/nttdata/calender/planTimes/PlanTimesRequest.java index 618fa27..b081bba 100644 --- a/backend/src/main/java/com/nttdata/calender/planTimes/PlanTimesRequest.java +++ b/backend/src/main/java/com/nttdata/calender/planTimes/PlanTimesRequest.java @@ -2,31 +2,66 @@ package com.nttdata.calender.planTimes; import com.nttdata.calender.changes.query.Filter; +/** + * The PlanTimesRequest class represents a request used for rendering the + * planning times. + * It contains information about the filter to apply and the rendering dates. + */ public class PlanTimesRequest { private Filter filter; private String renderStartDate; private String renderEndDate; + /** + * Gets the filter object. + * + * @return Filter object representing the filter + */ public Filter getFilter() { return filter; } + /** + * Sets the filter object. + * + * @param filter Filter object to set for filtering plan times + */ public void setFilter(Filter filter) { this.filter = filter; } + /** + * Gets the start date for rendering plan times. + * + * @return String representing the start date + */ public String getRenderStartDate() { return renderStartDate; } + /** + * Sets the start date for rendering plan times. + * + * @param renderStartDate String representing the start date to set + */ public void setRenderStartDate(String renderStartDate) { this.renderStartDate = renderStartDate; } + /** + * Gets the end date for rendering plan times. + * + * @return String representing the end date + */ public String getRenderEndDate() { return renderEndDate; } + /** + * Sets the end date for rendering plan times. + * + * @param renderEndDate String representing the end date to set + */ public void setRenderEndDate(String renderEndDate) { this.renderEndDate = renderEndDate; }