added missing documentation

main
Saidgdk 2023-06-22 11:58:22 +02:00
parent cc4b20078d
commit d36ddc4e34
6 changed files with 143 additions and 4 deletions

View File

@ -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<CalendarWeek> getPlanTimes(@RequestBody PlanTimesRequest request) throws ARException, ValidationError {
@PostMapping("/api/fetchPlanTimes")
public ArrayList<CalendarWeek> getPlanTimes(@RequestBody PlanTimesRequest request)
throws ARException, ValidationError {
PlanTimes p = new PlanTimes(javaAPI);
p.setPlanTimes(request);
return p.getPlanTimes();

View File

@ -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<FilterElement> filter) {
this.filterElement = filter;
}
/**
* Gets the filter element.
*
* @return the filter element
*/
public ArrayList<FilterElement> getFilterElement() {
return this.filterElement;
}

View File

@ -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);
}
}

View File

@ -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;
}

View File

@ -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<CalendarWeek> 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<CalendarWeek> getPlanTimes() {
return this.calenderWeeks;
}

View File

@ -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;
}