change exceptions
parent
a2a1368518
commit
03c40b294e
|
|
@ -187,12 +187,14 @@ public class KalenderRestController {
|
|||
* @param request the request object containing the ID of the change entry and
|
||||
* the new timestamp
|
||||
* @return the updated {@link ChangeUpdateRequest} object
|
||||
* @throws ARException if an AR exception occurs
|
||||
* @throws ARException if an AR exception occurs
|
||||
* @throws ValidationError
|
||||
*/
|
||||
@CrossOrigin("*")
|
||||
@PostMapping("/api/updateChange")
|
||||
@ResponseBody
|
||||
public ChangeUpdateRequest updateChange(@RequestBody ChangeUpdateRequest request) throws ARException {
|
||||
public ChangeUpdateRequest updateChange(@RequestBody ChangeUpdateRequest request)
|
||||
throws ARException, ValidationError {
|
||||
change.modifyTimestamp(request);
|
||||
return request;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -13,6 +13,7 @@ import org.springframework.beans.factory.annotation.Autowired;
|
|||
import org.springframework.stereotype.Service;
|
||||
import com.bmc.arsys.api.ARException;
|
||||
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.api.Query;
|
||||
|
|
@ -79,14 +80,12 @@ public class Change {
|
|||
|
||||
var peopleFullName = processPeopleInfo(request);
|
||||
|
||||
var qualifier = "";
|
||||
if (request.getFilter() != null) {
|
||||
qualifier = request.constructQualifier(queryChange, api);
|
||||
}
|
||||
var qualifier = request.constructQualifier(queryChange, api);
|
||||
SortInfo sort = request.constructSortInfo(queryChange);
|
||||
|
||||
var entries = api.queryFieldsById(qualifier, this.queryChange.getFieldIds(),
|
||||
this.queryChange.getFormName(),
|
||||
request.getSort().getSortInfo(queryChange), request.getSliceStart(),
|
||||
sort, request.getSliceStart(),
|
||||
request.getSliceEnd());
|
||||
var entriesSize = api.getFormSize(qualifier, this.queryChange.getFormName());
|
||||
var changes = new ArrayList<ChangeItem>();
|
||||
|
|
@ -204,9 +203,10 @@ public class Change {
|
|||
*
|
||||
* @param request the object containing the ID of the change entry and the new
|
||||
* timestamp
|
||||
* @throws ARException if an error occurs during the modification process
|
||||
* @throws ARException if an error occurs during the modification process
|
||||
* @throws ValidationError
|
||||
*/
|
||||
public void modifyTimestamp(ChangeUpdateRequest request) throws ARException {
|
||||
public void modifyTimestamp(ChangeUpdateRequest request) throws ARException, ValidationError {
|
||||
String entryId = request.getResourceId();
|
||||
String d2 = request.getD2();
|
||||
int state = request.getState();
|
||||
|
|
@ -231,9 +231,9 @@ public class Change {
|
|||
|
||||
api.modifyEntry(change.get(0).getEntryId(), queryInfrastructureChange);
|
||||
}
|
||||
|
||||
} catch (ParseException e) {
|
||||
logger.error(e, e);
|
||||
throw new ValidationError("Incorrect dateformat in request");
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,7 +5,10 @@ import java.time.format.DateTimeFormatter;
|
|||
import java.time.format.DateTimeParseException;
|
||||
import java.util.ArrayList;
|
||||
|
||||
import org.apache.el.util.Validation;
|
||||
|
||||
import com.bmc.arsys.api.ARException;
|
||||
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;
|
||||
|
|
@ -103,6 +106,13 @@ public class ChangeRequest {
|
|||
this.filter.add(filter);
|
||||
}
|
||||
|
||||
public SortInfo constructSortInfo(Query query) throws ValidationError {
|
||||
if (this.sort != null) {
|
||||
return this.sort.getSortInfo(query);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a qualifier based on the filters defined in the object and the
|
||||
* given Query object.
|
||||
|
|
@ -114,16 +124,19 @@ public class ChangeRequest {
|
|||
* @throws ARException if an error occurs while constructing the qualifier or an
|
||||
* invalid filter is provided.
|
||||
*/
|
||||
// TODO: Exception handling (unsuppoprted qualifier)
|
||||
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 criteria = current_filter.getCriteria();
|
||||
var criterias = current_filter.getCriteria();
|
||||
|
||||
if (column.isEmpty() || criteria.length <= 0) {
|
||||
if (column.isEmpty() || criterias.length <= 0) {
|
||||
throw new ValidationError("Fields inside filter empty");
|
||||
}
|
||||
var inner_qualifier = "";
|
||||
|
|
@ -135,7 +148,6 @@ public class ChangeRequest {
|
|||
column = api.getFieldDatabaseName(query.getFormName(), query.getFieldId(column));
|
||||
|
||||
var inner_filter = "\'" + column + "\' ";
|
||||
var criterias = current_filter.getCriteria();
|
||||
var inner_concat = " OR ";
|
||||
var inner_criteria_prefix = "";
|
||||
|
||||
|
|
@ -149,7 +161,7 @@ public class ChangeRequest {
|
|||
inner_criteria_prefix = "%";
|
||||
break;
|
||||
default:
|
||||
throw new ARException();
|
||||
throw new ValidationError("Invalid inner filter argument");
|
||||
}
|
||||
|
||||
for (int j = 0; j < criterias.length; j++) {
|
||||
|
|
@ -199,9 +211,9 @@ public class ChangeRequest {
|
|||
String inputFormat = "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'";
|
||||
String outputFormat = "dd/MM/yyyy";
|
||||
|
||||
LocalDateTime parser = LocalDateTime.parse(date, DateTimeFormatter.ofPattern(inputFormat));
|
||||
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");
|
||||
|
|
|
|||
|
|
@ -61,7 +61,6 @@ public class Sort {
|
|||
*/
|
||||
public SortInfo getSortInfo(Query changeQuery) throws ValidationError {
|
||||
var column = changeQuery.getFieldId(this.column);
|
||||
// TODO: handle default of sortOrder
|
||||
int sortOrder = 0;
|
||||
|
||||
switch (this.mode) {
|
||||
|
|
|
|||
|
|
@ -18,19 +18,19 @@ public class GlobalExceptionHandler {
|
|||
|
||||
@ExceptionHandler(ARException.class)
|
||||
public ResponseEntity<ErrorResponse> handleARException(ARException e, HttpServletRequest request) {
|
||||
var errorMessage = "Remedy server error: \n" + e.getMessage();
|
||||
var errorMessage = "Remedy server error: " + e.getMessage();
|
||||
return entityResponse(errorMessage, e, HttpStatus.INTERNAL_SERVER_ERROR);
|
||||
}
|
||||
|
||||
@ExceptionHandler(Exception.class)
|
||||
public ResponseEntity<ErrorResponse> handleGenericException(Exception e, HttpServletRequest request) {
|
||||
var errorMessage = "Backend internal server error: \n" + e.getMessage();
|
||||
var errorMessage = "Backend internal server error: " + e.getMessage();
|
||||
return entityResponse(errorMessage, e, HttpStatus.INTERNAL_SERVER_ERROR);
|
||||
}
|
||||
|
||||
@ExceptionHandler(BackendError.class)
|
||||
public ResponseEntity<ErrorResponse> handleBackendErrorException(BackendError e, HttpServletRequest request) {
|
||||
var errorMessage = "Backend internal server error: \n" + e.getMessage();
|
||||
var errorMessage = "Backend internal server error: " + e.getMessage();
|
||||
return entityResponse(errorMessage, e, e.getHttpStatus());
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue