reset
parent
48f343c09a
commit
b4e6181cc0
|
|
@ -117,7 +117,7 @@ public class KalenderRestController {
|
|||
|
||||
@CrossOrigin("*")
|
||||
@GetMapping("/api/getPlanTimes")
|
||||
public ArrayList<CalendarWeek> getPlanTimes(@RequestBody PlanTimesRequest request) throws ARException, ValidationError {
|
||||
public ArrayList<CalendarWeek> getPlanTimes(@RequestBody PlanTimesRequest request) throws ARException {
|
||||
PlanTimes p = new PlanTimes(javaAPI);
|
||||
p.setPlanTimes(request);
|
||||
return p.getPlanTimes();
|
||||
|
|
|
|||
|
|
@ -5,14 +5,17 @@ import java.time.DayOfWeek;
|
|||
import java.time.LocalDate;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.time.temporal.IsoFields;
|
||||
import java.time.temporal.TemporalAdjuster;
|
||||
import java.time.temporal.TemporalAdjusters;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.Objects;
|
||||
|
||||
import com.bmc.arsys.api.ARException;
|
||||
import com.bmc.thirdparty.org.springframework.cglib.core.Local;
|
||||
import com.nttdata.calender.api.Query;
|
||||
import com.nttdata.calender.api.RemedyJavaAPI;
|
||||
import com.nttdata.calender.errorhandling.ErrorTypes.ValidationError;
|
||||
import com.nttdata.calender.changes.ChangeItem;
|
||||
|
||||
public class PlanTimes {
|
||||
private RemedyJavaAPI remedyJavaAPI;
|
||||
|
|
@ -24,14 +27,13 @@ public class PlanTimes {
|
|||
this.calenderWeeks = new ArrayList<>();
|
||||
}
|
||||
|
||||
public void setPlanTimes(PlanTimesRequest req) throws ARException, ValidationError {
|
||||
public void setPlanTimes(PlanTimesRequest req) throws ARException {
|
||||
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("dd.MM.yyyy");
|
||||
LocalDate startDate = LocalDate.parse(req.getRenderStartDate(), formatter);
|
||||
LocalDate endDate = LocalDate.parse(req.getRenderEndDate(), formatter);
|
||||
|
||||
var queryChanges = new Query.QueryBuilder(formName).addFieldId("D2", 1000000350)
|
||||
.addFieldId("ChangeNr", 1000000182).addFieldId("PlanTimeHours", 666000009)
|
||||
.addFieldId("PlanTimeMinutes", 666000010).build();
|
||||
.addFieldId("ChangeNr", 1000000182).addFieldId("PlanTimeHours", 666000009).addFieldId("PlanTimeMinutes", 666000010).build();
|
||||
|
||||
while (!startDate.isAfter(endDate)) {
|
||||
CalendarWeek calendarWeek = new CalendarWeek();
|
||||
|
|
@ -53,12 +55,9 @@ public class PlanTimes {
|
|||
startDate = startDate.with(TemporalAdjusters.next(DayOfWeek.MONDAY));
|
||||
}
|
||||
|
||||
var qualifier = req.constructQualifier(queryChanges,
|
||||
var changesInDateRange = remedyJavaAPI.queryFieldsById(
|
||||
"\'Scheduled Start Date\' > \"" + req.getRenderStartDate() + "\" AND \'Scheduled Start Date\' <= \""
|
||||
+ req.getRenderEndDate() + "\"",
|
||||
remedyJavaAPI);
|
||||
|
||||
var changesInDateRange = remedyJavaAPI.queryFieldsById(qualifier,
|
||||
queryChanges.getFieldIds(), formName, null, 0, 0);
|
||||
|
||||
for (var week : calenderWeeks) {
|
||||
|
|
@ -69,10 +68,10 @@ public class PlanTimes {
|
|||
LocalDate dateEnd = LocalDate.parse(week.getEndDate(), formatter);
|
||||
|
||||
if (d2.isAfter(dateStart) && (d2.isEqual(dateEnd) || d2.isBefore(dateEnd))) {
|
||||
var minutes = change.get(queryChanges.getFieldId("PlanTimeMinutes")).toString();
|
||||
var hours = change.get(queryChanges.getFieldId("PlanTimeHours")).toString();
|
||||
double plantime = convertPlanTime(hours, minutes);
|
||||
planTimePerWeek += plantime;
|
||||
var minutes = change.get(queryChanges.getFieldId("PlanTimeMinutes")).toString();
|
||||
var hours = change.get(queryChanges.getFieldId("PlanTimeHours")).toString();
|
||||
double plantime = convertPlanTime(hours, minutes);
|
||||
planTimePerWeek += plantime;
|
||||
}
|
||||
}
|
||||
week.setPlanTime((int) Math.ceil(planTimePerWeek));
|
||||
|
|
@ -82,13 +81,12 @@ public class PlanTimes {
|
|||
public double convertPlanTime(String hours, String minutes) throws ARException {
|
||||
double mins = 0.0;
|
||||
double hrs = 0.0;
|
||||
if (minutes != null)
|
||||
mins = (Double.valueOf(minutes) / 60.0);
|
||||
if (hours != null)
|
||||
Double.valueOf(hours);
|
||||
if (minutes != null) mins = (Double.valueOf(minutes) / 60.0);
|
||||
if (hours != null) Double.valueOf(hours);
|
||||
double totalHours = hrs + mins;
|
||||
return totalHours;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public LocalDate timestampToDate(String timestamp) {
|
||||
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("dd.MM.yyyy");
|
||||
|
|
|
|||
|
|
@ -1,15 +1,8 @@
|
|||
package com.nttdata.calender.planTimes;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.time.format.DateTimeParseException;
|
||||
import java.util.ArrayList;
|
||||
|
||||
import com.bmc.arsys.api.ARException;
|
||||
import com.nttdata.calender.api.Query;
|
||||
import com.nttdata.calender.api.RemedyJavaAPI;
|
||||
import com.nttdata.calender.changes.query.Filter;
|
||||
import com.nttdata.calender.errorhandling.ErrorTypes.ValidationError;
|
||||
|
||||
public class PlanTimesRequest {
|
||||
private ArrayList<Filter> filter;
|
||||
|
|
@ -39,138 +32,4 @@ public class PlanTimesRequest {
|
|||
public void setRenderEndDate(String renderEndDate) {
|
||||
this.renderEndDate = renderEndDate;
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs and returns a qualifier based on the filters defined in the object
|
||||
* and the given Query object.
|
||||
*
|
||||
* @param query the Query object containing form and field information
|
||||
* @param api the RemedyJavaAPI object used for accessing the AR System API
|
||||
* @return a String representing the constructed qualifier
|
||||
* @throws ARException if an error occurs while constructing the qualifier
|
||||
* or an invalid filter is provided
|
||||
* @throws ValidationError if the fields inside the filter are empty or an
|
||||
* invalid inner filter argument is provided
|
||||
*/
|
||||
public String constructQualifier(Query query, String qualstr, RemedyJavaAPI api) throws ARException, ValidationError {
|
||||
var qualifier = "";
|
||||
|
||||
if (this.filter == null) {
|
||||
return qualifier;
|
||||
}
|
||||
|
||||
for (int i = 0; i < this.filter.size(); i++) {
|
||||
var current_filter = this.filter.get(i);
|
||||
var column = current_filter.getColumn();
|
||||
var criterias = current_filter.getCriteria();
|
||||
|
||||
if (column.isEmpty() || criterias.length <= 0) {
|
||||
throw new ValidationError("Fields inside filter empty");
|
||||
}
|
||||
var inner_qualifier = "";
|
||||
|
||||
if (column.equals("D2")) {
|
||||
var dateQualifier = constructDateQualifier(current_filter, column, query, api);
|
||||
qualifier = "(" + dateQualifier + ")";
|
||||
} else {
|
||||
column = api.getFieldDatabaseName(query.getFormName(), query.getFieldId(column));
|
||||
|
||||
var inner_filter = "\'" + column + "\' ";
|
||||
var inner_concat = " OR ";
|
||||
var inner_criteria_prefix = "";
|
||||
|
||||
switch (current_filter.getFilter()) {
|
||||
case "equals":
|
||||
inner_filter += "= ";
|
||||
break;
|
||||
case "contains":
|
||||
inner_filter += "LIKE ";
|
||||
inner_concat = " AND ";
|
||||
inner_criteria_prefix = "%";
|
||||
break;
|
||||
default:
|
||||
throw new ValidationError("Invalid inner filter argument");
|
||||
}
|
||||
|
||||
for (int j = 0; j < criterias.length; j++) {
|
||||
criterias[j] = inner_criteria_prefix + criterias[j] + inner_criteria_prefix;
|
||||
inner_qualifier += "(" + inner_filter + "\"" + criterias[j] + "\")";
|
||||
if (j < criterias.length - 1) {
|
||||
inner_qualifier += inner_concat;
|
||||
}
|
||||
}
|
||||
qualifier += "(" + inner_qualifier + ")";
|
||||
}
|
||||
|
||||
if (i < filter.size() - 1) {
|
||||
qualifier += " AND ";
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return qualifier;
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs and returns a date qualifier for the given filter, column, query,
|
||||
* and API.
|
||||
* Throws a ValidationError if the date filter does not contain two date
|
||||
* elements.
|
||||
*
|
||||
* @param current_filter the current filter to construct the date qualifier for
|
||||
* @param column the column to apply the date qualifier on
|
||||
* @param query the query object
|
||||
* @param api the RemedyJavaAPI object
|
||||
* @return the constructed date qualifier as a string
|
||||
* @throws ValidationError if the date filter does not contain two date elements
|
||||
* @throws ARException if an AR exception occurs
|
||||
*/
|
||||
private String constructDateQualifier(Filter current_filter, String column, Query query, RemedyJavaAPI api)
|
||||
throws ValidationError, ARException {
|
||||
if (current_filter.getCriteria().length != 2) {
|
||||
throw new ValidationError("Date Filter does not contain 2 date elements");
|
||||
}
|
||||
var startFrom = current_filter.getCriteria()[0];
|
||||
var startTo = current_filter.getCriteria()[1];
|
||||
var startFromFormatted = convertDate(startFrom);
|
||||
var startToFormatted = convertDate(startTo);
|
||||
var qualifier = "";
|
||||
|
||||
var dateColumn = api.getFieldDatabaseName(query.getFormName(), query.getFieldId(column));
|
||||
|
||||
// Same day changes need to startFrom=day and startTo=day+24h 60m 60s
|
||||
if (startFromFormatted.equals(startToFormatted)) {
|
||||
startToFormatted = "\' < (\"" + startToFormatted + "\"" + " + (24 * (60 * 60)))";
|
||||
} else
|
||||
startToFormatted = "\' <= \"" + startToFormatted + "\"";
|
||||
|
||||
qualifier += "\'" + dateColumn + "\' >= \"" + startFromFormatted + "\" AND ";
|
||||
qualifier += "\'" + dateColumn + startToFormatted;
|
||||
return qualifier;
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts the provided date string into a Remedy-specific date format and
|
||||
* returns it.
|
||||
* Throws a ValidationError if the provided date format cannot be parsed into
|
||||
* the Remedy-specific date format.
|
||||
*
|
||||
* @param date the date string to convert
|
||||
* @return the converted date string in Remedy-specific format
|
||||
* @throws ValidationError if the provided date format cannot be parsed into the
|
||||
* Remedy-specific date format
|
||||
*/
|
||||
private String convertDate(String date) throws ValidationError {
|
||||
String inputFormat = "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'";
|
||||
String outputFormat = "dd/MM/yyyy";
|
||||
|
||||
var parsed = "";
|
||||
try {
|
||||
LocalDateTime parser = LocalDateTime.parse(date, DateTimeFormatter.ofPattern(inputFormat));
|
||||
parsed = parser.format(DateTimeFormatter.ofPattern(outputFormat));
|
||||
} catch (DateTimeParseException e) {
|
||||
throw new ValidationError("Provided date format cannot be parsed into Remedy specific date format");
|
||||
}
|
||||
return parsed;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue