added missing docs and modified docs of changed code
parent
6e2731f887
commit
f941fe0f6e
|
|
@ -16,11 +16,22 @@ public class ApiApplication extends SpringBootServletInitializer {
|
|||
SpringApplication.run(ApiApplication.class, args);
|
||||
}
|
||||
|
||||
/**
|
||||
* Configures the Spring application builder.
|
||||
*
|
||||
* @param builder the Spring application builder.
|
||||
* @return the configured Spring application builder.
|
||||
*/
|
||||
@Override
|
||||
protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) {
|
||||
return builder.sources(ApiApplication.class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a bean for the session repository.
|
||||
*
|
||||
* @return the session repository.
|
||||
*/
|
||||
@Bean
|
||||
public MapSessionRepository sessionRepository() {
|
||||
return new MapSessionRepository(new ConcurrentHashMap<>());
|
||||
|
|
|
|||
|
|
@ -15,6 +15,11 @@ public class WebMvcConfig implements WebMvcConfigurer {
|
|||
this.sessionInterceptor = sessionInterceptor;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds the session interceptor to the interceptor registry.
|
||||
*
|
||||
* @param registry the interceptor registry.
|
||||
*/
|
||||
@Override
|
||||
public void addInterceptors(InterceptorRegistry registry) {
|
||||
registry.addInterceptor(sessionInterceptor);
|
||||
|
|
|
|||
|
|
@ -99,6 +99,13 @@ public class KalenderRestController {
|
|||
return ResponseEntity.internalServerError().body("Support Groups couldnt be fetched.");
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the URL response by calling the URL constructor with the Java API.
|
||||
* Returns the constructed URL response.
|
||||
*
|
||||
* @return the URL response containing the constructed URL
|
||||
* @throws ARException if an AR exception occurs
|
||||
*/
|
||||
@CrossOrigin("*")
|
||||
@GetMapping("/api/getUrl")
|
||||
public UrlResponse getLink() throws ARException {
|
||||
|
|
@ -166,11 +173,13 @@ public class KalenderRestController {
|
|||
}
|
||||
|
||||
/**
|
||||
* Handles GET request to retrieve a List of all {@link Change} objects
|
||||
* Handles a GET request to retrieve a List of all {@link Change} objects.
|
||||
*
|
||||
* @param request the request object
|
||||
* @return {@link ChangeResponse} containing the JSON array of all changes
|
||||
* @throws ARException if an AR exception occurs
|
||||
* @throws NotFoundError if no changes are found in the specified context
|
||||
* @throws ValidationError if a validation error occurs
|
||||
*/
|
||||
@CrossOrigin("*")
|
||||
@PostMapping("/api/getChanges")
|
||||
|
|
@ -181,13 +190,14 @@ public class KalenderRestController {
|
|||
}
|
||||
|
||||
/**
|
||||
* Handles POST request to update the date for a specific {@link Change} object.
|
||||
* Handles a POST request to update the date for a specific {@link Change}
|
||||
* object.
|
||||
*
|
||||
* @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 ValidationError
|
||||
* @throws ValidationError if a validation error occurs
|
||||
*/
|
||||
@CrossOrigin("*")
|
||||
@PostMapping("/api/updateChange")
|
||||
|
|
@ -233,6 +243,15 @@ public class KalenderRestController {
|
|||
return ResponseEntity.ok(response);
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates an approval based on the data sent in the request.
|
||||
* Returns an error when the action is not possible or the request has an
|
||||
* incorrect format.
|
||||
*
|
||||
* @param request the request object
|
||||
* @return {@link ResponseEntity} with the updated state value "OK"
|
||||
* @throws ARException if an AR exception occurs
|
||||
*/
|
||||
@CrossOrigin("*")
|
||||
@PostMapping("api/updateApproval")
|
||||
@ResponseBody
|
||||
|
|
@ -255,6 +274,12 @@ public class KalenderRestController {
|
|||
return implementer.get(request);
|
||||
}
|
||||
|
||||
/**
|
||||
* Logs the received request with the endpoint and request body.
|
||||
*
|
||||
* @param endpoint the endpoint where the request was received
|
||||
* @param request the request body as a string
|
||||
*/
|
||||
private void logRequest(String endpoint, String request) {
|
||||
applicationLogger.info("Received request on endpoint %s with body:", endpoint);
|
||||
applicationLogger.info(request);
|
||||
|
|
|
|||
|
|
@ -214,6 +214,24 @@ public class RemedyJavaAPI {
|
|||
maxEntriesNumber);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves all list entry objects based on the provided qualifier, form name,
|
||||
* sort order, field IDs, maximum number of entries, and number of matches.
|
||||
* Returns a list of all the retrieved list entry objects.
|
||||
*
|
||||
* @param qual the qualifier info for filtering the list entry
|
||||
* objects
|
||||
* @param formName the name of the form
|
||||
* @param sortOrder the list of sort information for ordering the list
|
||||
* entry objects
|
||||
* @param fieldIds the array of field IDs to include in the list entry
|
||||
* objects
|
||||
* @param nMatches the output integer to store the number of matches
|
||||
* @param maxEntriesNumber the maximum number of entries to retrieve in each
|
||||
* iteration
|
||||
* @return a list of all the retrieved list entry objects
|
||||
* @throws ARException if an AR exception occurs
|
||||
*/
|
||||
private List<Entry> getAllListEntryObjects(QualifierInfo qual, String formName,
|
||||
List<SortInfo> sortOrder, int[] fieldIds, OutputInteger nMatches, int maxEntriesNumber) throws ARException {
|
||||
List<Entry> entries = new ArrayList<Entry>();
|
||||
|
|
@ -231,6 +249,29 @@ public class RemedyJavaAPI {
|
|||
return entries;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves a slice of list entry objects based on the provided slice start and
|
||||
* end indices,
|
||||
* qualifier, form name, sort order, field IDs, maximum number of entries, and
|
||||
* number of matches.
|
||||
* Returns a list of the retrieved list entry objects within the specified
|
||||
* slice.
|
||||
*
|
||||
* @param sliceStart the start index of the slice
|
||||
* @param sliceEnd the end index of the slice
|
||||
* @param qual the qualifier info for filtering the list entry
|
||||
* objects
|
||||
* @param formName the name of the form
|
||||
* @param sortOrder the list of sort information for ordering the list
|
||||
* entry objects
|
||||
* @param fieldIds the array of field IDs to include in the list entry
|
||||
* objects
|
||||
* @param nMatches the output integer to store the number of matches
|
||||
* @param maxEntriesNumber the maximum number of entries to retrieve in each
|
||||
* iteration
|
||||
* @return a list of the retrieved list entry objects within the specified slice
|
||||
* @throws ARException if an AR exception occurs
|
||||
*/
|
||||
private List<Entry> getSomeListEntryObjects(int sliceStart, int sliceEnd, QualifierInfo qual, String formName,
|
||||
List<SortInfo> sortOrder, int[] fieldIds, OutputInteger nMatches, int maxEntriesNumber) throws ARException {
|
||||
List<Entry> entries = new ArrayList<Entry>();
|
||||
|
|
@ -253,6 +294,16 @@ public class RemedyJavaAPI {
|
|||
return entries;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the size of a form based on the provided qualification string and
|
||||
* form name.
|
||||
* Returns the size of the form.
|
||||
*
|
||||
* @param qualStr the qualification string for filtering the form
|
||||
* @param formName the name of the form
|
||||
* @return the size of the form
|
||||
* @throws ARException if an AR exception occurs
|
||||
*/
|
||||
public int getFormSize(String qualStr, String formName) throws ARException {
|
||||
List<Field> fields = server.getListFieldObjects(formName);
|
||||
QualifierInfo qual = server.parseQualification(qualStr,
|
||||
|
|
|
|||
|
|
@ -10,6 +10,9 @@ import com.bmc.arsys.api.ARException;
|
|||
import com.bmc.thirdparty.org.springframework.beans.factory.annotation.Autowired;
|
||||
import com.nttdata.calender.api.RemedyJavaAPI;
|
||||
|
||||
/**
|
||||
* Service class for handling Rsso operations.
|
||||
*/
|
||||
@Service
|
||||
public class Rsso {
|
||||
private final RemedyJavaAPI javaAPI;
|
||||
|
|
@ -19,6 +22,15 @@ public class Rsso {
|
|||
this.javaAPI = javaAPI;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a session using the provided token and stores the user ID in the
|
||||
* HttpSession.
|
||||
*
|
||||
* @param token the token to validate and create the session
|
||||
* @param session the HttpSession object
|
||||
* @return a ResponseEntity with the result of the session creation
|
||||
* @throws ARException if an AR exception occurs
|
||||
*/
|
||||
public ResponseEntity<?> createSession(String token, HttpSession session) throws ARException {
|
||||
var response = validateToken(token);
|
||||
switch (response.getResponseSessionStatus()) {
|
||||
|
|
@ -34,6 +46,12 @@ public class Rsso {
|
|||
return ResponseEntity.internalServerError().body("Token could not be processed");
|
||||
}
|
||||
|
||||
/**
|
||||
* Validates the provided token by making a REST API call to the RRSO server.
|
||||
*
|
||||
* @param token the token to validate
|
||||
* @return an RssoResponse object containing the response from the RRSO server
|
||||
*/
|
||||
public RssoResponse validateToken(String token) {
|
||||
var server = javaAPI.getServer();
|
||||
var webclient = WebClient.create();
|
||||
|
|
|
|||
|
|
@ -8,6 +8,9 @@ import org.springframework.web.servlet.HandlerInterceptor;
|
|||
|
||||
import com.bmc.thirdparty.org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
/**
|
||||
* Interceptor for handling Rsso related operations.
|
||||
*/
|
||||
@Component
|
||||
public class RssoInterceptor implements HandlerInterceptor {
|
||||
private final static boolean DEBUG = true;
|
||||
|
|
@ -18,6 +21,16 @@ public class RssoInterceptor implements HandlerInterceptor {
|
|||
this.rsso = rsso;
|
||||
}
|
||||
|
||||
/**
|
||||
* Pre-handle method to intercept the request before it is handled by the
|
||||
* controller.
|
||||
*
|
||||
* @param request the HTTP servlet request
|
||||
* @param response the HTTP servlet response
|
||||
* @param handler the handler for the request
|
||||
* @return true if the request should be allowed to proceed, false otherwise
|
||||
* @throws Exception if an exception occurs during the interception process
|
||||
*/
|
||||
// TODO: what if there is no cookie? what if no rssotoken in cookie? what if
|
||||
// createSession throws Exception?
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -2,6 +2,9 @@ package com.nttdata.calender.api.rsso;
|
|||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
|
||||
/**
|
||||
* Represents the response from the Rsso API.
|
||||
*/
|
||||
public class RssoResponse {
|
||||
@JsonProperty("realm")
|
||||
private String realm;
|
||||
|
|
@ -15,34 +18,74 @@ public class RssoResponse {
|
|||
@JsonProperty("response-sessionStatus")
|
||||
private String responseSessionStatus;
|
||||
|
||||
/**
|
||||
* Get the realm.
|
||||
*
|
||||
* @return the realm
|
||||
*/
|
||||
public String getRealm() {
|
||||
return this.realm;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the realm.
|
||||
*
|
||||
* @param realm the realm to set
|
||||
*/
|
||||
public void setRealm(String realm) {
|
||||
this.realm = realm;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the user ID.
|
||||
*
|
||||
* @return the user ID
|
||||
*/
|
||||
public String getUserId() {
|
||||
return this.userId;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the user ID.
|
||||
*
|
||||
* @param userId the user ID to set
|
||||
*/
|
||||
public void setUserId(String userId) {
|
||||
this.userId = userId;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the tenant ID.
|
||||
*
|
||||
* @return the tenant ID
|
||||
*/
|
||||
public String getTenantId() {
|
||||
return this.tenantId;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the tenant ID.
|
||||
*
|
||||
* @param tenantId the tenant ID to set
|
||||
*/
|
||||
public void setTenantId(String tenantId) {
|
||||
this.tenantId = tenantId;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the response session status.
|
||||
*
|
||||
* @return the response session status
|
||||
*/
|
||||
public String getResponseSessionStatus() {
|
||||
return this.responseSessionStatus;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the response session status.
|
||||
*
|
||||
* @param responseSessionStatus the response session status to set
|
||||
*/
|
||||
public void setResponseSessionStatus(String responseSessionStatus) {
|
||||
this.responseSessionStatus = responseSessionStatus;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -63,14 +63,16 @@ public class Change {
|
|||
}
|
||||
|
||||
/**
|
||||
* Retrieve entries from the form using the given qualification. With the
|
||||
* Retrieves entries from the form using the given qualification. With the
|
||||
* returned entry set,
|
||||
* print out the ID of each entry and the contents in its shortDescription
|
||||
* prints out the ID of each entry and the contents in its shortDescription
|
||||
* field.
|
||||
*
|
||||
* @param request the defined qualifier for specific selection
|
||||
* @return a List of {@link Change} for every entry found
|
||||
* @return a List of Change for every entry found
|
||||
* @throws ARException if an error occurs during the retrieval process
|
||||
* @throws NotFoundError if no user is found with the specified login ID
|
||||
* @throws ValidationError if there is an invalid filter or qualification
|
||||
*/
|
||||
public ChangeResponse get(ChangeRequest request) throws ARException, NotFoundError, ValidationError {
|
||||
api.impersonateUser("ext_StanzPa");
|
||||
|
|
@ -139,6 +141,17 @@ public class Change {
|
|||
return new ChangeResponse(entriesSize, changes);
|
||||
}
|
||||
|
||||
/**
|
||||
* Processes the people information based on the provided change request.
|
||||
* Returns the full name of the impersonated user after querying for the support
|
||||
* group.
|
||||
*
|
||||
* @param request the change request object
|
||||
* @return the full name of the impersonated user
|
||||
* @throws ARException if an AR exception occurs
|
||||
* @throws NotFoundError if no user or support groups are found with the
|
||||
* provided login ID
|
||||
*/
|
||||
private String processPeopleInfo(ChangeRequest request) throws ARException, NotFoundError {
|
||||
// Queries for SupportGroup of impersonated User
|
||||
var queryPerson = new Query.QueryBuilder("CTM:Support Group Association")
|
||||
|
|
@ -243,6 +256,15 @@ public class Change {
|
|||
// approversOI.get(0).get(queryApprovalList.getFieldId("Approvers")).toString();
|
||||
// return approvers != null ? approvers.contains(user) : false;
|
||||
// }
|
||||
|
||||
/**
|
||||
* Queries and retrieves the package name based on the provided package type.
|
||||
* Returns the package name as a string.
|
||||
*
|
||||
* @param packageType the type of the package
|
||||
* @return the package name
|
||||
* @throws ARException if an AR exception occurs
|
||||
*/
|
||||
private String queryPackageName(String packageType) throws ARException {
|
||||
var queryPackage = new Query.QueryBuilder("CTR:GenericContractJoinCFG_Package")
|
||||
.addFieldId("PackageName", 200000020).build();
|
||||
|
|
|
|||
|
|
@ -174,7 +174,8 @@ public class ChangeItem {
|
|||
// /**
|
||||
// * Sets the flag indicating whether the change item has a permit.
|
||||
// *
|
||||
// * @param flagPermit {@code true} if the change item has a permit, {@code false}
|
||||
// * @param flagPermit {@code true} if the change item has a permit, {@code
|
||||
// false}
|
||||
// * otherwise.
|
||||
// */
|
||||
// public void setFlagPermit(boolean flagPermit) {
|
||||
|
|
@ -241,10 +242,20 @@ public class ChangeItem {
|
|||
// this.flagCancel = flagCancel;
|
||||
// }
|
||||
|
||||
/**
|
||||
* Retrieves the package name.
|
||||
*
|
||||
* @return the package name
|
||||
*/
|
||||
public String getPackageName() {
|
||||
return this.packageName;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the package name.
|
||||
*
|
||||
* @param packageName the package name to set
|
||||
*/
|
||||
public void setPackageName(String packageName) {
|
||||
this.packageName = packageName;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -97,6 +97,11 @@ public class ChangeRequest {
|
|||
this.sort = sort;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a filter to the list of filters.
|
||||
*
|
||||
* @param filter the filter to add
|
||||
*/
|
||||
public void addFilter(Filter filter) {
|
||||
if (this.filter == null) {
|
||||
this.filter = new ArrayList<Filter>();
|
||||
|
|
@ -104,6 +109,16 @@ public class ChangeRequest {
|
|||
this.filter.add(filter);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs and returns a `SortInfo` object based on the provided `Query`
|
||||
* object.
|
||||
* If no sort information is available, returns `null`.
|
||||
*
|
||||
* @param query the query object used for constructing the `SortInfo`
|
||||
* @return the constructed `SortInfo` object, or `null` if no sort information
|
||||
* is available
|
||||
* @throws ValidationError if a validation error occurs during construction
|
||||
*/
|
||||
public SortInfo constructSortInfo(Query query) throws ValidationError {
|
||||
if (this.sort != null) {
|
||||
return this.sort.getSortInfo(query);
|
||||
|
|
@ -112,15 +127,16 @@ public class ChangeRequest {
|
|||
}
|
||||
|
||||
/**
|
||||
* Constructs a qualifier based on the filters defined in the object and the
|
||||
* given Query object.
|
||||
* Constructs and returns a qualifier based on the filters defined in the object
|
||||
* and the given Query object.
|
||||
*
|
||||
* @param query the {@link Query} object containing form and field information.
|
||||
* @param api the {@link 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.
|
||||
* @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 = "";
|
||||
|
|
@ -181,6 +197,20 @@ public class ChangeRequest {
|
|||
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) {
|
||||
|
|
@ -205,6 +235,17 @@ public class ChangeRequest {
|
|||
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";
|
||||
|
|
|
|||
|
|
@ -35,12 +35,15 @@ public class Contract {
|
|||
|
||||
/**
|
||||
* Queries the Remedy AR Server using the provided `api` object to retrieve
|
||||
* Contract IDs from both changes and contracts forms, compares the IDs, and
|
||||
* stores the matching ones in the `contracts` list.
|
||||
* Contract IDs
|
||||
* from both the changes and contracts forms, compares the IDs, and stores the
|
||||
* matching
|
||||
* ones in the `contracts` list.
|
||||
*
|
||||
* @param api RemedyJavaAPI object used to connect to the Remedy AR Server
|
||||
* @param api the RemedyJavaAPI object used to connect to the Remedy AR Server
|
||||
* @throws ARException if an error occurs during the querying process
|
||||
* @throws NotFoundError if no contracts are found in the given context
|
||||
*/
|
||||
|
||||
public void queryContracts(RemedyJavaAPI api) throws ARException, NotFoundError {
|
||||
ArrayList<ContractGetResponse> allChanges = new ArrayList<ContractGetResponse>();
|
||||
ArrayList<ContractGetResponse> allContracts = new ArrayList<ContractGetResponse>();
|
||||
|
|
|
|||
|
|
@ -2,20 +2,43 @@ package com.nttdata.calender.errorhandling.ErrorTypes;
|
|||
|
||||
import org.springframework.http.HttpStatus;
|
||||
|
||||
/**
|
||||
* Abstract class representing a backend error.
|
||||
* It extends the Exception class and provides additional properties for error
|
||||
* code and HTTP status.
|
||||
*/
|
||||
public abstract class BackendError extends Exception {
|
||||
private int errorCode;
|
||||
private HttpStatus httpStatus;
|
||||
|
||||
/**
|
||||
* Constructs a BackendError object with the specified message, error code, and
|
||||
* HTTP status.
|
||||
*
|
||||
* @param message the error message.
|
||||
* @param errorCode the error code associated with the error.
|
||||
* @param httpStatus the HTTP status associated with the error.
|
||||
*/
|
||||
public BackendError(String message, int errorCode, HttpStatus httpStatus) {
|
||||
super(message);
|
||||
this.errorCode = errorCode;
|
||||
this.httpStatus = httpStatus;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the error code associated with the error.
|
||||
*
|
||||
* @return the error code.
|
||||
*/
|
||||
public int getErrorCode() {
|
||||
return errorCode;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the HTTP status associated with the error.
|
||||
*
|
||||
* @return the HTTP status.
|
||||
*/
|
||||
public HttpStatus getHttpStatus() {
|
||||
return httpStatus;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,7 +2,18 @@ package com.nttdata.calender.errorhandling.ErrorTypes;
|
|||
|
||||
import org.springframework.http.HttpStatus;
|
||||
|
||||
/**
|
||||
* Error class representing a Not Found error.
|
||||
* It extends the BackendError class and sets the error code to 404 and the HTTP
|
||||
* status to HttpStatus.NOT_FOUND.
|
||||
*/
|
||||
public class NotFoundError extends BackendError {
|
||||
|
||||
/**
|
||||
* Constructs a NotFoundError object with the specified error message.
|
||||
*
|
||||
* @param message the error message.
|
||||
*/
|
||||
public NotFoundError(String message) {
|
||||
super(message, 404, HttpStatus.NOT_FOUND);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,6 +2,10 @@ package com.nttdata.calender.errorhandling.ErrorTypes;
|
|||
|
||||
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.
|
||||
*/
|
||||
public class ValidationError extends BackendError {
|
||||
|
||||
public ValidationError(String message) {
|
||||
|
|
|
|||
|
|
@ -12,28 +12,61 @@ import org.springframework.web.bind.annotation.ExceptionHandler;
|
|||
import com.bmc.arsys.api.ARException;
|
||||
import com.nttdata.calender.errorhandling.ErrorTypes.BackendError;
|
||||
|
||||
/**
|
||||
* Global exception handler class for handling exceptions in the application.
|
||||
*/
|
||||
@ControllerAdvice
|
||||
public class GlobalExceptionHandler {
|
||||
private static final Logger errorLogger = LogManager.getLogger("error");
|
||||
|
||||
/**
|
||||
* Exception handler for ARException.
|
||||
*
|
||||
* @param e the ARException object.
|
||||
* @param request the HttpServletRequest object.
|
||||
* @return a ResponseEntity containing the error response.
|
||||
*/
|
||||
@ExceptionHandler(ARException.class)
|
||||
public ResponseEntity<ErrorResponse> handleARException(ARException e, HttpServletRequest request) {
|
||||
var errorMessage = "Remedy server error: " + e.getMessage();
|
||||
return entityResponse(errorMessage, errorMessage, e, HttpStatus.INTERNAL_SERVER_ERROR);
|
||||
}
|
||||
|
||||
/**
|
||||
* Exception handler for generic Exception.
|
||||
*
|
||||
* @param e the Exception object.
|
||||
* @param request the HttpServletRequest object.
|
||||
* @return a ResponseEntity containing the error response.
|
||||
*/
|
||||
@ExceptionHandler(Exception.class)
|
||||
public ResponseEntity<ErrorResponse> handleGenericException(Exception e, HttpServletRequest request) {
|
||||
var userMessage = "Backend internal server error";
|
||||
return entityResponse(userMessage, e.getMessage(), e, HttpStatus.INTERNAL_SERVER_ERROR);
|
||||
}
|
||||
|
||||
/**
|
||||
* Exception handler for BackendError.
|
||||
*
|
||||
* @param e the BackendError object.
|
||||
* @param request the HttpServletRequest object.
|
||||
* @return a ResponseEntity containing the error response.
|
||||
*/
|
||||
@ExceptionHandler(BackendError.class)
|
||||
public ResponseEntity<ErrorResponse> handleBackendErrorException(BackendError e, HttpServletRequest request) {
|
||||
var errorMessage = "Backend internal server error: " + e.getMessage();
|
||||
return entityResponse(errorMessage, errorMessage, e, e.getHttpStatus());
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a ResponseEntity with the error response and logs the error.
|
||||
*
|
||||
* @param userMessage the user-friendly error message.
|
||||
* @param errorMessage the detailed error message.
|
||||
* @param e the Exception object.
|
||||
* @param status the HTTP status code.
|
||||
* @return a ResponseEntity containing the error response.
|
||||
*/
|
||||
private ResponseEntity<ErrorResponse> entityResponse(String userMessage, String errorMessage, Exception e,
|
||||
HttpStatus status) {
|
||||
var errorResponse = new ErrorResponse(userMessage, e.getClass().getSimpleName());
|
||||
|
|
|
|||
|
|
@ -35,11 +35,12 @@ public class SupportGroup {
|
|||
}
|
||||
|
||||
/**
|
||||
* Queries the Remedy AR Server using the provided api object to retrieve
|
||||
* information about support groups and populates the supportGroups list
|
||||
* with the results.
|
||||
* Populates the supportGroups list by querying the Remedy AR Server using the
|
||||
* provided API object.
|
||||
*
|
||||
* @param api RemedyJavaAPI object used to connect to the Remedy AR Server.
|
||||
* @param api the RemedyJavaAPI object used to connect to the Remedy AR Server.
|
||||
* @throws ARException if an error occurs during the query.
|
||||
* @throws NotFoundError if no support groups are found in this context.
|
||||
*/
|
||||
public void querySupportGroups(RemedyJavaAPI api) throws ARException, NotFoundError {
|
||||
var querySupportGroups = new Query.QueryBuilder(formName)
|
||||
|
|
|
|||
|
|
@ -11,6 +11,13 @@ public class UrlConstructor {
|
|||
String viewForm = "/SHR%3ALandingConsole/Default+Administrator+View/?mode=search&F304255500=";
|
||||
String getPkg = "&F1000000076=FormOpenNoAppList&F303647600=SearchTicketWithQual&F304255610=";
|
||||
|
||||
/**
|
||||
* Constructs the URL for accessing the Remedy AR Server forms.
|
||||
*
|
||||
* @param api the RemedyJavaAPI object used to connect to the Remedy AR Server.
|
||||
* @return an instance of UrlResponse containing the constructed URL.
|
||||
* @throws ARException if an error occurs during the construction process.
|
||||
*/
|
||||
public UrlResponse construct(RemedyJavaAPI api) throws ARException {
|
||||
var server = api.getServer();
|
||||
var setting = new int[] { Constants.AR_SERVER_INFO_SERVER_NAME, Constants.AR_SERVER_INFO_DEFAULT_WEB_PATH };
|
||||
|
|
|
|||
|
|
@ -4,23 +4,49 @@ public class UrlResponse {
|
|||
private String entryUrl;
|
||||
private String viewFormUrl;
|
||||
|
||||
/**
|
||||
* Constructs a new instance of UrlResponse.
|
||||
*
|
||||
* @param entryUrl the URL for accessing the entry.
|
||||
* @param viewFormUrl the URL for accessing the view form.
|
||||
*/
|
||||
public UrlResponse(String entryUrl, String viewFormUrl) {
|
||||
this.entryUrl = entryUrl;
|
||||
this.viewFormUrl = viewFormUrl;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the URL for accessing the entry.
|
||||
*
|
||||
* @return the entry URL.
|
||||
*/
|
||||
public String getEntryUrl() {
|
||||
return this.entryUrl;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the URL for accessing the entry.
|
||||
*
|
||||
* @param entryUrl the entry URL to set.
|
||||
*/
|
||||
public void setEntryUrl(String entryUrl) {
|
||||
this.entryUrl = entryUrl;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the URL for accessing the view form.
|
||||
*
|
||||
* @return the view form URL.
|
||||
*/
|
||||
public String getViewFormUrl() {
|
||||
return this.viewFormUrl;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the URL for accessing the view form.
|
||||
*
|
||||
* @param viewFormUrl the view form URL to set.
|
||||
*/
|
||||
public void setViewFormUrl(String viewFormUrl) {
|
||||
this.viewFormUrl = viewFormUrl;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue