Merge branch 'main' of https://dev.azure.com/asfinag/Tech-Supporting.ITSM/_git/Tech-Supporting.ITSM.ChangeKalender
commit
df37610e1c
|
|
@ -11,10 +11,21 @@ import java.util.TimeZone;
|
||||||
import com.bmc.arsys.api.Timestamp;
|
import com.bmc.arsys.api.Timestamp;
|
||||||
import com.nttdata.calender.errorhandling.ErrorTypes.ValidationError;
|
import com.nttdata.calender.errorhandling.ErrorTypes.ValidationError;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Util class for converting dates into remedy compatible format.
|
||||||
|
*/
|
||||||
public class DateConverter {
|
public class DateConverter {
|
||||||
|
|
||||||
final String DATEFORMAT = "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'";
|
final String DATEFORMAT = "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Converts the timestamp as a String into into a LocalDate.
|
||||||
|
* The timestamp pattern has to be: "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'"
|
||||||
|
*
|
||||||
|
* @param timestamp
|
||||||
|
* @return
|
||||||
|
* @throws ValidationError
|
||||||
|
*/
|
||||||
public LocalDate convertDateTime(String timestamp) throws ValidationError {
|
public LocalDate convertDateTime(String timestamp) throws ValidationError {
|
||||||
try {
|
try {
|
||||||
LocalDate date = LocalDate.parse(timestamp, DateTimeFormatter.ofPattern(DATEFORMAT));
|
LocalDate date = LocalDate.parse(timestamp, DateTimeFormatter.ofPattern(DATEFORMAT));
|
||||||
|
|
@ -24,6 +35,14 @@ public class DateConverter {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Converts the timestamp as a String into into a Timestamp type.
|
||||||
|
* The timestamp pattern has to be: "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'"
|
||||||
|
*
|
||||||
|
* @param timestamp
|
||||||
|
* @return
|
||||||
|
* @throws ValidationError
|
||||||
|
*/
|
||||||
public Timestamp convertTimestamp(String timestamp) throws ValidationError {
|
public Timestamp convertTimestamp(String timestamp) throws ValidationError {
|
||||||
SimpleDateFormat sdf = new SimpleDateFormat(DATEFORMAT);
|
SimpleDateFormat sdf = new SimpleDateFormat(DATEFORMAT);
|
||||||
sdf.setTimeZone(TimeZone.getTimeZone("GMT"));
|
sdf.setTimeZone(TimeZone.getTimeZone("GMT"));
|
||||||
|
|
|
||||||
|
|
@ -115,9 +115,18 @@ public class KalenderRestController {
|
||||||
return urlConstructor.construct(javaAPI);
|
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("*")
|
@CrossOrigin("*")
|
||||||
@PostMapping("/api/fetchPlanTimes")
|
@PostMapping("/api/fetchPlanTimes")
|
||||||
public ArrayList<CalendarWeek> getPlanTimes(@RequestBody PlanTimesRequest request) throws ARException, ValidationError {
|
public ArrayList<CalendarWeek> getPlanTimes(@RequestBody PlanTimesRequest request)
|
||||||
|
throws ARException, ValidationError {
|
||||||
PlanTimes p = new PlanTimes(javaAPI);
|
PlanTimes p = new PlanTimes(javaAPI);
|
||||||
p.setPlanTimes(request);
|
p.setPlanTimes(request);
|
||||||
return p.getPlanTimes();
|
return p.getPlanTimes();
|
||||||
|
|
|
||||||
|
|
@ -10,6 +10,10 @@ import com.nttdata.calender.api.Query;
|
||||||
import com.nttdata.calender.api.RemedyJavaAPI;
|
import com.nttdata.calender.api.RemedyJavaAPI;
|
||||||
import com.nttdata.calender.errorhandling.ErrorTypes.ValidationError;
|
import com.nttdata.calender.errorhandling.ErrorTypes.ValidationError;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This class is a wrapper for the ArrayList of {@link FilterElement}. This
|
||||||
|
* class constructs a query from the filter.
|
||||||
|
*/
|
||||||
public class Filter {
|
public class Filter {
|
||||||
private ArrayList<FilterElement> filterElement;
|
private ArrayList<FilterElement> filterElement;
|
||||||
private Query queryChange;
|
private Query queryChange;
|
||||||
|
|
@ -53,10 +57,20 @@ public class Filter {
|
||||||
this.filterElement.add(filter);
|
this.filterElement.add(filter);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the filter element.
|
||||||
|
*
|
||||||
|
* @param filter the filter element to set
|
||||||
|
*/
|
||||||
public void setFilterElement(ArrayList<FilterElement> filter) {
|
public void setFilterElement(ArrayList<FilterElement> filter) {
|
||||||
this.filterElement = filter;
|
this.filterElement = filter;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the filter element.
|
||||||
|
*
|
||||||
|
* @return the filter element
|
||||||
|
*/
|
||||||
public ArrayList<FilterElement> getFilterElement() {
|
public ArrayList<FilterElement> getFilterElement() {
|
||||||
return this.filterElement;
|
return this.filterElement;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -4,12 +4,17 @@ import org.springframework.http.HttpStatus;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Error class representing a Validation Error.
|
* 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 {
|
public class ValidationError extends BackendError {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructs a new ValidationError with the specified error message.
|
||||||
|
*
|
||||||
|
* @param message the error message
|
||||||
|
*/
|
||||||
public ValidationError(String message) {
|
public ValidationError(String message) {
|
||||||
super(message, 400, HttpStatus.BAD_REQUEST);
|
super(message, 400, HttpStatus.BAD_REQUEST);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,39 +1,84 @@
|
||||||
package com.nttdata.calender.planTimes;
|
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 {
|
public class CalendarWeek {
|
||||||
private String week;
|
private String week;
|
||||||
private int planTime;
|
private int planTime;
|
||||||
private String startDate;
|
private String startDate;
|
||||||
private String endDate;
|
private String endDate;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the week.
|
||||||
|
*
|
||||||
|
* @return String representing the week
|
||||||
|
*/
|
||||||
public String getWeek() {
|
public String getWeek() {
|
||||||
return week;
|
return week;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the week.
|
||||||
|
*
|
||||||
|
* @param week String to set representing the week
|
||||||
|
*/
|
||||||
public void setWeek(String week) {
|
public void setWeek(String week) {
|
||||||
this.week = week;
|
this.week = week;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the planned time.
|
||||||
|
*
|
||||||
|
* @return int representing the planned time
|
||||||
|
*/
|
||||||
public int getPlanTime() {
|
public int getPlanTime() {
|
||||||
return planTime;
|
return planTime;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the planned time.
|
||||||
|
*
|
||||||
|
* @param planTime an int to set representing the planned time
|
||||||
|
*/
|
||||||
public void setPlanTime(int planTime) {
|
public void setPlanTime(int planTime) {
|
||||||
this.planTime = planTime;
|
this.planTime = planTime;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the start date.
|
||||||
|
*
|
||||||
|
* @return String representing the start date
|
||||||
|
*/
|
||||||
public String getStartDate() {
|
public String getStartDate() {
|
||||||
return startDate;
|
return startDate;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the start date.
|
||||||
|
*
|
||||||
|
* @param startDate String to set representing the start date
|
||||||
|
*/
|
||||||
public void setStartDate(String startDate) {
|
public void setStartDate(String startDate) {
|
||||||
this.startDate = startDate;
|
this.startDate = startDate;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the end date.
|
||||||
|
*
|
||||||
|
* @return String representing the end date
|
||||||
|
*/
|
||||||
public String getEndDate() {
|
public String getEndDate() {
|
||||||
return endDate;
|
return endDate;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the end date.
|
||||||
|
*
|
||||||
|
* @param endDate String to set representing the end date
|
||||||
|
*/
|
||||||
public void setEndDate(String endDate) {
|
public void setEndDate(String endDate) {
|
||||||
this.endDate = endDate;
|
this.endDate = endDate;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -5,30 +5,41 @@ import java.time.DayOfWeek;
|
||||||
import java.time.LocalDate;
|
import java.time.LocalDate;
|
||||||
import java.time.format.DateTimeFormatter;
|
import java.time.format.DateTimeFormatter;
|
||||||
import java.time.temporal.IsoFields;
|
import java.time.temporal.IsoFields;
|
||||||
import java.time.temporal.TemporalAdjuster;
|
|
||||||
import java.time.temporal.TemporalAdjusters;
|
import java.time.temporal.TemporalAdjusters;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.Objects;
|
|
||||||
|
|
||||||
import com.bmc.arsys.api.ARException;
|
import com.bmc.arsys.api.ARException;
|
||||||
import com.bmc.thirdparty.org.springframework.cglib.core.Local;
|
|
||||||
import com.nttdata.calender.DateConverter;
|
import com.nttdata.calender.DateConverter;
|
||||||
import com.nttdata.calender.api.Query;
|
import com.nttdata.calender.api.Query;
|
||||||
import com.nttdata.calender.api.RemedyJavaAPI;
|
import com.nttdata.calender.api.RemedyJavaAPI;
|
||||||
import com.nttdata.calender.changes.ChangeItem;
|
|
||||||
import com.nttdata.calender.errorhandling.ErrorTypes.ValidationError;
|
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 {
|
public class PlanTimes {
|
||||||
private RemedyJavaAPI remedyJavaAPI;
|
private RemedyJavaAPI remedyJavaAPI;
|
||||||
private ArrayList<CalendarWeek> calenderWeeks;
|
private ArrayList<CalendarWeek> calenderWeeks;
|
||||||
private final String formName = "ASF:WI_TAS_Paket";
|
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) {
|
public PlanTimes(RemedyJavaAPI remedyJavaAPI) {
|
||||||
this.remedyJavaAPI = remedyJavaAPI;
|
this.remedyJavaAPI = remedyJavaAPI;
|
||||||
this.calenderWeeks = new ArrayList<>();
|
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 {
|
public void setPlanTimes(PlanTimesRequest req) throws ARException, ValidationError {
|
||||||
var dateConverter = new DateConverter();
|
var dateConverter = new DateConverter();
|
||||||
var startDate = dateConverter.convertDateTime(req.getRenderStartDate());
|
var startDate = dateConverter.convertDateTime(req.getRenderStartDate());
|
||||||
|
|
@ -80,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 {
|
public double convertPlanTime(String hours, String minutes) throws ARException {
|
||||||
double mins = 0.0;
|
double mins = 0.0;
|
||||||
double hrs = 0.0;
|
double hrs = 0.0;
|
||||||
|
|
@ -91,6 +110,12 @@ public class PlanTimes {
|
||||||
return totalHours;
|
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) {
|
public LocalDate timestampToDate(String timestamp) {
|
||||||
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("dd.MM.yyyy");
|
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("dd.MM.yyyy");
|
||||||
SimpleDateFormat sdf = new SimpleDateFormat("dd.MM.yyyy");
|
SimpleDateFormat sdf = new SimpleDateFormat("dd.MM.yyyy");
|
||||||
|
|
@ -104,6 +129,11 @@ public class PlanTimes {
|
||||||
return LocalDate.parse(date, formatter);
|
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() {
|
public ArrayList<CalendarWeek> getPlanTimes() {
|
||||||
return this.calenderWeeks;
|
return this.calenderWeeks;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -2,31 +2,66 @@ package com.nttdata.calender.planTimes;
|
||||||
|
|
||||||
import com.nttdata.calender.changes.query.Filter;
|
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 {
|
public class PlanTimesRequest {
|
||||||
private Filter filter;
|
private Filter filter;
|
||||||
private String renderStartDate;
|
private String renderStartDate;
|
||||||
private String renderEndDate;
|
private String renderEndDate;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the filter object.
|
||||||
|
*
|
||||||
|
* @return Filter object representing the filter
|
||||||
|
*/
|
||||||
public Filter getFilter() {
|
public Filter getFilter() {
|
||||||
return filter;
|
return filter;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the filter object.
|
||||||
|
*
|
||||||
|
* @param filter Filter object to set for filtering plan times
|
||||||
|
*/
|
||||||
public void setFilter(Filter filter) {
|
public void setFilter(Filter filter) {
|
||||||
this.filter = filter;
|
this.filter = filter;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the start date for rendering plan times.
|
||||||
|
*
|
||||||
|
* @return String representing the start date
|
||||||
|
*/
|
||||||
public String getRenderStartDate() {
|
public String getRenderStartDate() {
|
||||||
return renderStartDate;
|
return renderStartDate;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the start date for rendering plan times.
|
||||||
|
*
|
||||||
|
* @param renderStartDate String representing the start date to set
|
||||||
|
*/
|
||||||
public void setRenderStartDate(String renderStartDate) {
|
public void setRenderStartDate(String renderStartDate) {
|
||||||
this.renderStartDate = renderStartDate;
|
this.renderStartDate = renderStartDate;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the end date for rendering plan times.
|
||||||
|
*
|
||||||
|
* @return String representing the end date
|
||||||
|
*/
|
||||||
public String getRenderEndDate() {
|
public String getRenderEndDate() {
|
||||||
return renderEndDate;
|
return renderEndDate;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the end date for rendering plan times.
|
||||||
|
*
|
||||||
|
* @param renderEndDate String representing the end date to set
|
||||||
|
*/
|
||||||
public void setRenderEndDate(String renderEndDate) {
|
public void setRenderEndDate(String renderEndDate) {
|
||||||
this.renderEndDate = renderEndDate;
|
this.renderEndDate = renderEndDate;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue