Merge branch 'fetchPlanTimes'
commit
489ef3adf2
|
|
@ -0,0 +1,37 @@
|
|||
package com.nttdata.calender;
|
||||
|
||||
import java.text.ParseException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.time.LocalDate;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.time.format.DateTimeParseException;
|
||||
import java.util.TimeZone;
|
||||
|
||||
import com.bmc.arsys.api.Timestamp;
|
||||
import com.nttdata.calender.errorhandling.ErrorTypes.ValidationError;
|
||||
|
||||
public class DateConverter {
|
||||
|
||||
final String DATEFORMAT = "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'";
|
||||
|
||||
public LocalDate convertDateTime(String timestamp) throws ValidationError {
|
||||
try {
|
||||
LocalDate date = LocalDate.parse(timestamp, DateTimeFormatter.ofPattern(DATEFORMAT));
|
||||
return date;
|
||||
} catch (DateTimeParseException e) {
|
||||
throw new ValidationError("Incorrect dateformat in request");
|
||||
}
|
||||
}
|
||||
|
||||
public Timestamp convertTimestamp(String timestamp) throws ValidationError {
|
||||
SimpleDateFormat sdf = new SimpleDateFormat(DATEFORMAT);
|
||||
sdf.setTimeZone(TimeZone.getTimeZone("GMT"));
|
||||
try {
|
||||
Timestamp ts = new Timestamp(sdf.parse(timestamp));
|
||||
return ts;
|
||||
} catch (ParseException e) {
|
||||
throw new ValidationError("Incorrect dateformat in request");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -31,6 +31,9 @@ import com.nttdata.calender.implementer.ImplementerGetResponse;
|
|||
import com.nttdata.calender.implementer.ImplementerUpdateRequest;
|
||||
import com.nttdata.calender.packageType.PackageItems;
|
||||
import com.nttdata.calender.packageType.PackageType;
|
||||
import com.nttdata.calender.planTimes.CalendarWeek;
|
||||
import com.nttdata.calender.planTimes.PlanTimes;
|
||||
import com.nttdata.calender.planTimes.PlanTimesRequest;
|
||||
import com.nttdata.calender.states.State;
|
||||
import com.nttdata.calender.states.StateChange;
|
||||
import com.nttdata.calender.states.StateChangeRequest;
|
||||
|
|
@ -112,6 +115,14 @@ public class KalenderRestController {
|
|||
return urlConstructor.construct(javaAPI);
|
||||
}
|
||||
|
||||
@CrossOrigin("*")
|
||||
@PostMapping("/api/fetchPlanTimes")
|
||||
public ArrayList<CalendarWeek> getPlanTimes(@RequestBody PlanTimesRequest request) throws ARException, ValidationError {
|
||||
PlanTimes p = new PlanTimes(javaAPI);
|
||||
p.setPlanTimes(request);
|
||||
return p.getPlanTimes();
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* Handles a GET request to retrieve the user's support group.
|
||||
|
|
|
|||
|
|
@ -14,9 +14,10 @@ import com.bmc.arsys.api.Entry;
|
|||
import com.bmc.arsys.api.SortInfo;
|
||||
import com.bmc.arsys.api.Timestamp;
|
||||
import com.bmc.arsys.api.Value;
|
||||
import com.nttdata.calender.DateConverter;
|
||||
import com.nttdata.calender.api.Query;
|
||||
import com.nttdata.calender.api.RemedyJavaAPI;
|
||||
import com.nttdata.calender.changes.query.Filter;
|
||||
import com.nttdata.calender.changes.query.FilterElement;
|
||||
import com.nttdata.calender.errorhandling.ErrorTypes.NotFoundError;
|
||||
import com.nttdata.calender.errorhandling.ErrorTypes.ValidationError;
|
||||
|
||||
|
|
@ -81,7 +82,8 @@ public class Change {
|
|||
|
||||
var peopleFullName = processPeopleInfo(request);
|
||||
|
||||
var qualifier = request.constructQualifier(queryChange, api);
|
||||
var filter = request.getFilter();
|
||||
var qualifier = filter.constructQualifier(queryChange, api);
|
||||
SortInfo sort = request.constructSortInfo(queryChange);
|
||||
|
||||
var entries = api.queryFieldsById(qualifier, this.queryChange.getFieldIds(),
|
||||
|
|
@ -139,8 +141,10 @@ public class Change {
|
|||
// state));
|
||||
change.setPackageName(queryPackageName(getValueStringByID(entry, "PackageType").toString()));
|
||||
|
||||
var ptMinutes = getValueStringByID(entry, "PlanTimeMinutes").isEmpty() ? "00" : getValueStringByID(entry, "PlanTimeMinutes");
|
||||
var ptHours = getValueStringByID(entry, "PlanTimeHours").isEmpty() ? "00" : getValueStringByID(entry, "PlanTimeHours");
|
||||
var ptMinutes = getValueStringByID(entry, "PlanTimeMinutes").isEmpty() ? "00"
|
||||
: getValueStringByID(entry, "PlanTimeMinutes");
|
||||
var ptHours = getValueStringByID(entry, "PlanTimeHours").isEmpty() ? "00"
|
||||
: getValueStringByID(entry, "PlanTimeHours");
|
||||
change.setPlanTime(convertPlanTime(ptHours, ptMinutes));
|
||||
|
||||
change.setPackageName(queryPackageName(getValueStringByID(entry, "PackageType").toString()));
|
||||
|
|
@ -183,7 +187,7 @@ public class Change {
|
|||
throw new NotFoundError("No supportGroups associated to the loginId ");
|
||||
}
|
||||
request.addFilter(
|
||||
new Filter("SupportGroupId", "equals", peopleSupportGroup));
|
||||
new FilterElement("SupportGroupId", "equals", peopleSupportGroup));
|
||||
|
||||
return peopleInfos.get(0).get(queryPerson.getFieldId("FullName")).toString();
|
||||
}
|
||||
|
|
@ -191,7 +195,7 @@ public class Change {
|
|||
/**
|
||||
* Converts the planned time which is passed in hours and minutes to total hours
|
||||
*
|
||||
* @param hours the hours as a String
|
||||
* @param hours the hours as a String
|
||||
* @param minutes the minutes as a String
|
||||
* @return the hours and minutes as total hours
|
||||
* @throws ARException
|
||||
|
|
@ -357,30 +361,24 @@ public class Change {
|
|||
public void modifyTimestamp(ChangeUpdateRequest request) throws ARException, ValidationError {
|
||||
String entryId = request.getResourceId();
|
||||
String d2 = request.getD2();
|
||||
var dateConverter = new DateConverter();
|
||||
int state = request.getState();
|
||||
String changeNr = request.getChangeNr();
|
||||
|
||||
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSS'Z'");
|
||||
sdf.setTimeZone(TimeZone.getTimeZone("GMT"));
|
||||
var ts = dateConverter.convertTimestamp(d2);
|
||||
if (state == 0) {
|
||||
Query query = new Query.QueryBuilder("ASF:WI_TAS_Paket")
|
||||
.addFieldValue("d2", 1000000350, new Value(ts)).build();
|
||||
api.modifyEntry(entryId, query);
|
||||
} else {
|
||||
Query queryInfrastructureChange = new Query.QueryBuilder("CHG:Infrastructure Change")
|
||||
.addFieldValue("d2", 1000000350, new Value(ts)).build();
|
||||
|
||||
try {
|
||||
Timestamp ts = new Timestamp(sdf.parse(d2));
|
||||
if (state == 0) {
|
||||
Query query = new Query.QueryBuilder("ASF:WI_TAS_Paket")
|
||||
.addFieldValue("d2", 1000000350, new Value(ts)).build();
|
||||
api.modifyEntry(entryId, query);
|
||||
} else {
|
||||
Query queryInfrastructureChange = new Query.QueryBuilder("CHG:Infrastructure Change")
|
||||
.addFieldValue("d2", 1000000350, new Value(ts)).build();
|
||||
var change = api.queryFieldsById("\'Infrastructure Change ID\' = \"" + changeNr + "\"",
|
||||
queryInfrastructureChange.getFieldIds(),
|
||||
queryInfrastructureChange.getFormName(), null, 0, 0);
|
||||
|
||||
var change = api.queryFieldsById("\'Infrastructure Change ID\' = \"" + changeNr + "\"",
|
||||
queryInfrastructureChange.getFieldIds(),
|
||||
queryInfrastructureChange.getFormName(), null, 0, 0);
|
||||
|
||||
api.modifyEntry(change.get(0).getEntryId(), queryInfrastructureChange);
|
||||
}
|
||||
} catch (ParseException e) {
|
||||
throw new ValidationError("Incorrect dateformat in request");
|
||||
api.modifyEntry(change.get(0).getEntryId(), queryInfrastructureChange);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -10,6 +10,7 @@ import com.bmc.arsys.api.SortInfo;
|
|||
import com.nttdata.calender.api.Query;
|
||||
import com.nttdata.calender.api.RemedyJavaAPI;
|
||||
import com.nttdata.calender.changes.query.Filter;
|
||||
import com.nttdata.calender.changes.query.FilterElement;
|
||||
import com.nttdata.calender.changes.query.Sort;
|
||||
import com.nttdata.calender.errorhandling.ErrorTypes.ValidationError;
|
||||
|
||||
|
|
@ -21,7 +22,7 @@ import com.nttdata.calender.errorhandling.ErrorTypes.ValidationError;
|
|||
public class ChangeRequest {
|
||||
private int sliceStart;
|
||||
private int sliceEnd;
|
||||
private ArrayList<Filter> filter;
|
||||
private Filter filter;
|
||||
private Sort sort;
|
||||
|
||||
/**
|
||||
|
|
@ -63,19 +64,21 @@ public class ChangeRequest {
|
|||
/**
|
||||
* Returns the array of filter criteria.
|
||||
*
|
||||
* @return an array of {@link Filter} objects representing the filter criteria.
|
||||
* @return an array of {@link FilterElement} objects representing the filter
|
||||
* criteria.
|
||||
*/
|
||||
public ArrayList<Filter> getFilter() {
|
||||
public Filter getFilter() {
|
||||
return this.filter;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the array of filter criteria.
|
||||
*
|
||||
* @param filter an array of {@link Filter} objects representing the filter
|
||||
* @param filter an array of {@link FilterElement} objects representing the
|
||||
* filter
|
||||
* criteria.
|
||||
*/
|
||||
public void setFilter(ArrayList<Filter> filter) {
|
||||
public void setFilter(Filter filter) {
|
||||
this.filter = filter;
|
||||
}
|
||||
|
||||
|
|
@ -102,11 +105,11 @@ public class ChangeRequest {
|
|||
*
|
||||
* @param filter the filter to add
|
||||
*/
|
||||
public void addFilter(Filter filter) {
|
||||
public void addFilter(FilterElement filter) {
|
||||
if (this.filter == null) {
|
||||
this.filter = new ArrayList<Filter>();
|
||||
this.filter = new Filter();
|
||||
}
|
||||
this.filter.add(filter);
|
||||
this.filter.addFilter(filter);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -125,138 +128,4 @@ public class ChangeRequest {
|
|||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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, 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;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,72 +1,161 @@
|
|||
package com.nttdata.calender.changes.query;
|
||||
|
||||
import com.nttdata.calender.changes.Change;
|
||||
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.errorhandling.ErrorTypes.ValidationError;
|
||||
|
||||
/**
|
||||
* Defines the filter objects used in the retrieval of {@link Change}.
|
||||
*/
|
||||
public class Filter {
|
||||
private String column;
|
||||
private String filter;
|
||||
private String[] criteria;
|
||||
private ArrayList<FilterElement> filter;
|
||||
|
||||
public Filter(String column, String filter, String[] criteria) {
|
||||
this.column = column;
|
||||
this.filter = filter;
|
||||
this.criteria = criteria;
|
||||
/**
|
||||
* Adds a filter to the list of filters.
|
||||
*
|
||||
* @param filter the filter to add
|
||||
*/
|
||||
public void addFilter(FilterElement filter) {
|
||||
if (this.filter == null) {
|
||||
this.filter = new ArrayList<FilterElement>();
|
||||
}
|
||||
this.filter.add(filter);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns column of {@link Filter}
|
||||
* Constructs and returns a qualifier based on the filters defined in the object
|
||||
* and the given Query object.
|
||||
*
|
||||
* @return the column
|
||||
* @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 getColumn() {
|
||||
return this.column;
|
||||
public String constructQualifier(Query query, 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;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets column of {@link Filter}
|
||||
* 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 column the column to set
|
||||
* @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
|
||||
*/
|
||||
public void setColumn(String column) {
|
||||
this.column = column;
|
||||
private String constructDateQualifier(FilterElement 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;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns filter of {@link Filter}
|
||||
* 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.
|
||||
*
|
||||
* @return the filter
|
||||
* @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
|
||||
*/
|
||||
public String getFilter() {
|
||||
return this.filter;
|
||||
}
|
||||
private String convertDate(String date) throws ValidationError {
|
||||
String inputFormat = "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'";
|
||||
String outputFormat = "dd/MM/yyyy";
|
||||
|
||||
/**
|
||||
* Sets filter of {@link Filter}
|
||||
*
|
||||
* @param filter the filter to set
|
||||
*/
|
||||
public void setFilter(String filter) {
|
||||
this.filter = filter;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the criterias of {@link Filter}.
|
||||
*
|
||||
* @return the criteria
|
||||
*/
|
||||
public String[] getCriteria() {
|
||||
return this.criteria;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the criteria of the {@link Filter}.
|
||||
*
|
||||
* @param criteria the criteria to set
|
||||
*/
|
||||
public void setCriteria(String[] criteria) {
|
||||
this.criteria = criteria;
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,72 @@
|
|||
package com.nttdata.calender.changes.query;
|
||||
|
||||
import com.nttdata.calender.changes.Change;
|
||||
|
||||
/**
|
||||
* Defines the filter objects used in the retrieval of {@link Change}.
|
||||
*/
|
||||
public class FilterElement {
|
||||
private String column;
|
||||
private String filter;
|
||||
private String[] criteria;
|
||||
|
||||
public FilterElement(String column, String filter, String[] criteria) {
|
||||
this.column = column;
|
||||
this.filter = filter;
|
||||
this.criteria = criteria;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns column of {@link FilterElement}
|
||||
*
|
||||
* @return the column
|
||||
*/
|
||||
public String getColumn() {
|
||||
return this.column;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets column of {@link FilterElement}
|
||||
*
|
||||
* @param column the column to set
|
||||
*/
|
||||
public void setColumn(String column) {
|
||||
this.column = column;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns filter of {@link FilterElement}
|
||||
*
|
||||
* @return the filter
|
||||
*/
|
||||
public String getFilter() {
|
||||
return this.filter;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets filter of {@link FilterElement}
|
||||
*
|
||||
* @param filter the filter to set
|
||||
*/
|
||||
public void setFilter(String filter) {
|
||||
this.filter = filter;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the criterias of {@link FilterElement}.
|
||||
*
|
||||
* @return the criteria
|
||||
*/
|
||||
public String[] getCriteria() {
|
||||
return this.criteria;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the criteria of the {@link FilterElement}.
|
||||
*
|
||||
* @param criteria the criteria to set
|
||||
*/
|
||||
public void setCriteria(String[] criteria) {
|
||||
this.criteria = criteria;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,40 @@
|
|||
package com.nttdata.calender.planTimes;
|
||||
|
||||
public class CalendarWeek {
|
||||
private String week;
|
||||
private int planTime;
|
||||
private String startDate;
|
||||
private String endDate;
|
||||
|
||||
public String getWeek() {
|
||||
return week;
|
||||
}
|
||||
|
||||
public void setWeek(String week) {
|
||||
this.week = week;
|
||||
}
|
||||
|
||||
public int getPlanTime() {
|
||||
return planTime;
|
||||
}
|
||||
|
||||
public void setPlanTime(int planTime) {
|
||||
this.planTime = planTime;
|
||||
}
|
||||
|
||||
public String getStartDate() {
|
||||
return startDate;
|
||||
}
|
||||
|
||||
public void setStartDate(String startDate) {
|
||||
this.startDate = startDate;
|
||||
}
|
||||
|
||||
public String getEndDate() {
|
||||
return endDate;
|
||||
}
|
||||
|
||||
public void setEndDate(String endDate) {
|
||||
this.endDate = endDate;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,110 @@
|
|||
package com.nttdata.calender.planTimes;
|
||||
|
||||
import java.text.SimpleDateFormat;
|
||||
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.DateConverter;
|
||||
import com.nttdata.calender.api.Query;
|
||||
import com.nttdata.calender.api.RemedyJavaAPI;
|
||||
import com.nttdata.calender.changes.ChangeItem;
|
||||
import com.nttdata.calender.errorhandling.ErrorTypes.ValidationError;
|
||||
|
||||
public class PlanTimes {
|
||||
private RemedyJavaAPI remedyJavaAPI;
|
||||
private ArrayList<CalendarWeek> calenderWeeks;
|
||||
private final String formName = "ASF:WI_TAS_Paket";
|
||||
|
||||
public PlanTimes(RemedyJavaAPI remedyJavaAPI) {
|
||||
this.remedyJavaAPI = remedyJavaAPI;
|
||||
this.calenderWeeks = new ArrayList<>();
|
||||
}
|
||||
|
||||
public void setPlanTimes(PlanTimesRequest req) throws ARException, ValidationError {
|
||||
var dateConverter = new DateConverter();
|
||||
var startDate = dateConverter.convertDateTime(req.getRenderStartDate());
|
||||
var endDate = dateConverter.convertDateTime(req.getRenderEndDate());
|
||||
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("dd.MM.yyyy");
|
||||
|
||||
var queryChanges = new Query.QueryBuilder(formName).addFieldId("D2", 1000000350)
|
||||
.addFieldId("ChangeNr", 1000000182).addFieldId("PlanTimeHours", 666000009)
|
||||
.addFieldId("PlanTimeMinutes", 666000010).build();
|
||||
|
||||
while (!startDate.isAfter(endDate)) {
|
||||
CalendarWeek calendarWeek = new CalendarWeek();
|
||||
|
||||
int startWeek = startDate.get(IsoFields.WEEK_OF_WEEK_BASED_YEAR);
|
||||
int year = startDate.get(IsoFields.WEEK_BASED_YEAR);
|
||||
String formattedStartWeek = String.format("%02d", startWeek);
|
||||
|
||||
LocalDate startOfWeek = startDate.with(TemporalAdjusters.previousOrSame(DayOfWeek.MONDAY));
|
||||
LocalDate endOfWeek = startDate.with(TemporalAdjusters.nextOrSame(DayOfWeek.SUNDAY));
|
||||
|
||||
calendarWeek.setWeek(year + "w" + formattedStartWeek);
|
||||
calendarWeek.setPlanTime(0);
|
||||
calendarWeek.setStartDate(startOfWeek.format(formatter));
|
||||
calendarWeek.setEndDate(endOfWeek.format(formatter));
|
||||
|
||||
calenderWeeks.add(calendarWeek);
|
||||
startDate = startDate.with(TemporalAdjusters.next(DayOfWeek.MONDAY));
|
||||
}
|
||||
|
||||
var filter = req.getFilter();
|
||||
var qual = filter.constructQualifier(null, remedyJavaAPI);
|
||||
var changesInDateRange = remedyJavaAPI.queryFieldsById(qual, queryChanges.getFieldIds(), formName, null, 0, 0);
|
||||
|
||||
for (var week : calenderWeeks) {
|
||||
double planTimePerWeek = 0.0;
|
||||
for (var change : changesInDateRange) {
|
||||
LocalDate d2 = timestampToDate(change.get(queryChanges.getFieldId("D2")).toString());
|
||||
LocalDate dateStart = LocalDate.parse(week.getStartDate(), formatter);
|
||||
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;
|
||||
}
|
||||
}
|
||||
week.setPlanTime((int) Math.ceil(planTimePerWeek));
|
||||
}
|
||||
}
|
||||
|
||||
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);
|
||||
double totalHours = hrs + mins;
|
||||
return totalHours;
|
||||
}
|
||||
|
||||
public LocalDate timestampToDate(String timestamp) {
|
||||
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("dd.MM.yyyy");
|
||||
SimpleDateFormat sdf = new SimpleDateFormat("dd.MM.yyyy");
|
||||
String numericPart = timestamp.replaceAll("[^\\d]", "");
|
||||
long ts = Long.parseLong(numericPart);
|
||||
|
||||
if (numericPart.length() <= 10)
|
||||
ts *= 1000;
|
||||
|
||||
String date = sdf.format(new Date(ts));
|
||||
return LocalDate.parse(date, formatter);
|
||||
}
|
||||
|
||||
public ArrayList<CalendarWeek> getPlanTimes() {
|
||||
return this.calenderWeeks;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,33 @@
|
|||
package com.nttdata.calender.planTimes;
|
||||
|
||||
import com.nttdata.calender.changes.query.Filter;
|
||||
|
||||
public class PlanTimesRequest {
|
||||
private Filter filter;
|
||||
private String renderStartDate;
|
||||
private String renderEndDate;
|
||||
|
||||
public Filter getFilter() {
|
||||
return filter;
|
||||
}
|
||||
|
||||
public void setFilter(Filter filter) {
|
||||
this.filter = filter;
|
||||
}
|
||||
|
||||
public String getRenderStartDate() {
|
||||
return renderStartDate;
|
||||
}
|
||||
|
||||
public void setRenderStartDate(String renderStartDate) {
|
||||
this.renderStartDate = renderStartDate;
|
||||
}
|
||||
|
||||
public String getRenderEndDate() {
|
||||
return renderEndDate;
|
||||
}
|
||||
|
||||
public void setRenderEndDate(String renderEndDate) {
|
||||
this.renderEndDate = renderEndDate;
|
||||
}
|
||||
}
|
||||
|
|
@ -215,7 +215,23 @@ export class DataService {
|
|||
return promise;
|
||||
}
|
||||
|
||||
|
||||
public async fetchPlanTimes(filters: any, renderStartDate: Date, renderEndtDate: Date){
|
||||
const promise = new Promise(resolve=>{
|
||||
let obj = {filter : filters.filter, renderStartDate : renderStartDate, renderEndDate: renderEndtDate };
|
||||
let stringyfiedData = JSON.stringify(obj);
|
||||
let dataJson = JSON.parse(stringyfiedData) as typeof stringyfiedData;
|
||||
console.log(dataJson);
|
||||
let res : any[] = [];
|
||||
this.http.post('http://localhost:8080/api/fetchPlanTimes', dataJson)
|
||||
.subscribe((response: any[])=>{
|
||||
response.forEach(week => {
|
||||
res.push(week);
|
||||
});
|
||||
resolve(res);
|
||||
})
|
||||
})
|
||||
return promise;
|
||||
}
|
||||
|
||||
public async fetchImplementers(change: any){
|
||||
const promise = new Promise(resolve=>{
|
||||
|
|
@ -259,12 +275,14 @@ export class DataService {
|
|||
* @returns promise for the fetched Changes Array
|
||||
*/
|
||||
public async fetchChanges(reqestParams: any = null){
|
||||
|
||||
// let filter = {'filterElement': [reqestParams]};
|
||||
let stringyfiedData = JSON.stringify(reqestParams);
|
||||
let dataJson = JSON.parse(stringyfiedData) as typeof stringyfiedData;
|
||||
const promise = new Promise(resolve=>{
|
||||
let first : boolean = true;
|
||||
let res : any[] = [];
|
||||
//console.log(dataJson);
|
||||
console.log(dataJson);
|
||||
this.http.post('http://localhost:8080/api/getChanges', dataJson)
|
||||
.subscribe((response:any)=>{
|
||||
//console.log(response);
|
||||
|
|
|
|||
|
|
@ -279,6 +279,7 @@ public logg(args){
|
|||
|
||||
|
||||
|
||||
|
||||
this.filterSettings = {
|
||||
ignoreAccent: true
|
||||
// columns: [
|
||||
|
|
@ -1064,7 +1065,8 @@ public logg(args){
|
|||
{
|
||||
'sliceStart': this.sliceStart,
|
||||
'sliceEnd': this.sliceEnd,
|
||||
filter: this.filterEnabled ? this.filters : [{column: "SupportGroup", filter: "equals", criteria: [this.userSupportGroup]}],
|
||||
|
||||
filter: this.filterEnabled ? this.filters : {filterElement: [{column: "SupportGroup", filter: "equals", criteria: [this.userSupportGroup]}]},
|
||||
sort: this.sortEnabled ? this.sort : {
|
||||
'column': 'ChangeNr',
|
||||
'mode': 'asc'
|
||||
|
|
|
|||
Loading…
Reference in New Issue