From f941fe0f6ef4bdf5c1796c53fddd62c48e19e002 Mon Sep 17 00:00:00 2001 From: Said Gedik Date: Fri, 2 Jun 2023 10:37:19 +0200 Subject: [PATCH] added missing docs and modified docs of changed code --- .../com/nttdata/calender/ApiApplication.java | 11 ++ .../com/nttdata/calender/WebMvcConfig.java | 5 + .../calender/api/KalenderRestController.java | 37 +++++- .../nttdata/calender/api/RemedyJavaAPI.java | 51 +++++++++ .../com/nttdata/calender/api/rsso/Rsso.java | 18 +++ .../calender/api/rsso/RssoInterceptor.java | 13 +++ .../calender/api/rsso/RssoResponse.java | 43 +++++++ .../com/nttdata/calender/changes/Change.java | 30 ++++- .../nttdata/calender/changes/ChangeItem.java | 107 ++++++++++-------- .../calender/changes/ChangeRequest.java | 57 ++++++++-- .../nttdata/calender/contracts/Contract.java | 11 +- .../ErrorTypes/BackendError.java | 23 ++++ .../ErrorTypes/NotFoundError.java | 11 ++ .../ErrorTypes/ValidationError.java | 4 + .../errorhandling/GlobalExceptionHandler.java | 33 ++++++ .../calender/supportgroup/SupportGroup.java | 9 +- .../urlConstructor/UrlConstructor.java | 7 ++ .../calender/urlConstructor/UrlResponse.java | 26 +++++ 18 files changed, 422 insertions(+), 74 deletions(-) diff --git a/backend/src/main/java/com/nttdata/calender/ApiApplication.java b/backend/src/main/java/com/nttdata/calender/ApiApplication.java index 7be7950..8526a15 100644 --- a/backend/src/main/java/com/nttdata/calender/ApiApplication.java +++ b/backend/src/main/java/com/nttdata/calender/ApiApplication.java @@ -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<>()); diff --git a/backend/src/main/java/com/nttdata/calender/WebMvcConfig.java b/backend/src/main/java/com/nttdata/calender/WebMvcConfig.java index 5e45d13..ab87283 100644 --- a/backend/src/main/java/com/nttdata/calender/WebMvcConfig.java +++ b/backend/src/main/java/com/nttdata/calender/WebMvcConfig.java @@ -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); diff --git a/backend/src/main/java/com/nttdata/calender/api/KalenderRestController.java b/backend/src/main/java/com/nttdata/calender/api/KalenderRestController.java index 9a50692..bc19dbf 100644 --- a/backend/src/main/java/com/nttdata/calender/api/KalenderRestController.java +++ b/backend/src/main/java/com/nttdata/calender/api/KalenderRestController.java @@ -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 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); diff --git a/backend/src/main/java/com/nttdata/calender/api/RemedyJavaAPI.java b/backend/src/main/java/com/nttdata/calender/api/RemedyJavaAPI.java index 49efaee..d54850e 100644 --- a/backend/src/main/java/com/nttdata/calender/api/RemedyJavaAPI.java +++ b/backend/src/main/java/com/nttdata/calender/api/RemedyJavaAPI.java @@ -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 getAllListEntryObjects(QualifierInfo qual, String formName, List sortOrder, int[] fieldIds, OutputInteger nMatches, int maxEntriesNumber) throws ARException { List entries = new ArrayList(); @@ -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 getSomeListEntryObjects(int sliceStart, int sliceEnd, QualifierInfo qual, String formName, List sortOrder, int[] fieldIds, OutputInteger nMatches, int maxEntriesNumber) throws ARException { List entries = new ArrayList(); @@ -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 fields = server.getListFieldObjects(formName); QualifierInfo qual = server.parseQualification(qualStr, diff --git a/backend/src/main/java/com/nttdata/calender/api/rsso/Rsso.java b/backend/src/main/java/com/nttdata/calender/api/rsso/Rsso.java index 198bf7c..a225690 100644 --- a/backend/src/main/java/com/nttdata/calender/api/rsso/Rsso.java +++ b/backend/src/main/java/com/nttdata/calender/api/rsso/Rsso.java @@ -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(); diff --git a/backend/src/main/java/com/nttdata/calender/api/rsso/RssoInterceptor.java b/backend/src/main/java/com/nttdata/calender/api/rsso/RssoInterceptor.java index a64fb45..d773979 100644 --- a/backend/src/main/java/com/nttdata/calender/api/rsso/RssoInterceptor.java +++ b/backend/src/main/java/com/nttdata/calender/api/rsso/RssoInterceptor.java @@ -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 diff --git a/backend/src/main/java/com/nttdata/calender/api/rsso/RssoResponse.java b/backend/src/main/java/com/nttdata/calender/api/rsso/RssoResponse.java index 17792b2..3e3a003 100644 --- a/backend/src/main/java/com/nttdata/calender/api/rsso/RssoResponse.java +++ b/backend/src/main/java/com/nttdata/calender/api/rsso/RssoResponse.java @@ -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; } diff --git a/backend/src/main/java/com/nttdata/calender/changes/Change.java b/backend/src/main/java/com/nttdata/calender/changes/Change.java index 71c0d0d..8404f15 100644 --- a/backend/src/main/java/com/nttdata/calender/changes/Change.java +++ b/backend/src/main/java/com/nttdata/calender/changes/Change.java @@ -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 - * @throws ARException if an error occurs during the retrieval process + * @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(); diff --git a/backend/src/main/java/com/nttdata/calender/changes/ChangeItem.java b/backend/src/main/java/com/nttdata/calender/changes/ChangeItem.java index d1b05d8..990d061 100644 --- a/backend/src/main/java/com/nttdata/calender/changes/ChangeItem.java +++ b/backend/src/main/java/com/nttdata/calender/changes/ChangeItem.java @@ -162,89 +162,100 @@ public class ChangeItem { } // /** - // * Retrieves the flag indicating whether the change item has a permit. - // * - // * @return {@code true} if the change item has a permit, {@code false} - // * otherwise. - // */ + // * Retrieves the flag indicating whether the change item has a permit. + // * + // * @return {@code true} if the change item has a permit, {@code false} + // * otherwise. + // */ // public boolean getFlagPermit() { - // return this.flagPermit; + // return this.flagPermit; // } // /** - // * Sets the flag indicating whether the change item has a permit. - // * - // * @param flagPermit {@code true} if the change item has a permit, {@code false} - // * otherwise. - // */ + // * Sets the flag indicating whether the change item has a permit. + // * + // * @param flagPermit {@code true} if the change item has a permit, {@code + // false} + // * otherwise. + // */ // public void setFlagPermit(boolean flagPermit) { - // this.flagPermit = flagPermit; + // this.flagPermit = flagPermit; // } // /** - // * Retrieves the flag indicating whether the change item has been approved. - // * - // * @return {@code true} if the change item has been approved, {@code false} - // * otherwise. - // */ + // * Retrieves the flag indicating whether the change item has been approved. + // * + // * @return {@code true} if the change item has been approved, {@code false} + // * otherwise. + // */ // public boolean getFlagApprove() { - // return this.flagApprove; + // return this.flagApprove; // } // /** - // * Sets the flag indicating whether the change item has been approved. - // * - // * @param flagApprove {@code true} if the change item has been approved, - // * {@code false} otherwise. - // */ + // * Sets the flag indicating whether the change item has been approved. + // * + // * @param flagApprove {@code true} if the change item has been approved, + // * {@code false} otherwise. + // */ // public void setFlagApprove(boolean flagApprove) { - // this.flagApprove = flagApprove; + // this.flagApprove = flagApprove; // } // /** - // * Retrieves the flag indicating whether the change item has been rejected. - // * - // * @return {@code true} if the change item has been rejected, {@code false} - // * otherwise. - // */ + // * Retrieves the flag indicating whether the change item has been rejected. + // * + // * @return {@code true} if the change item has been rejected, {@code false} + // * otherwise. + // */ // public boolean getFlagReject() { - // return this.flagReject; + // return this.flagReject; // } // /** - // * Sets the flag indicating whether the change item has been rejected. - // * - // * @param flagReject {@code true} if the change item has been rejected, - // * {@code false} otherwise. - // */ + // * Sets the flag indicating whether the change item has been rejected. + // * + // * @param flagReject {@code true} if the change item has been rejected, + // * {@code false} otherwise. + // */ // public void setFlagReject(boolean flagReject) { - // this.flagReject = flagReject; + // this.flagReject = flagReject; // } // /** - // * Retrieves the flag indicating whether the change item has been canceled. - // * - // * @return {@code true} if the change item has been canceled, {@code false} - // * otherwise. - // */ + // * Retrieves the flag indicating whether the change item has been canceled. + // * + // * @return {@code true} if the change item has been canceled, {@code false} + // * otherwise. + // */ // public boolean getFlagCancel() { - // return this.flagCancel; + // return this.flagCancel; // } // /** - // * Sets the flag indicating whether the change item has been canceled. - // * - // * @param flagCancel {@code true} if the change item has been canceled, - // * {@code false} otherwise. - // */ + // * Sets the flag indicating whether the change item has been canceled. + // * + // * @param flagCancel {@code true} if the change item has been canceled, + // * {@code false} otherwise. + // */ // public void setFlagCancel(boolean flagCancel) { - // this.flagCancel = flagCancel; + // 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; } diff --git a/backend/src/main/java/com/nttdata/calender/changes/ChangeRequest.java b/backend/src/main/java/com/nttdata/calender/changes/ChangeRequest.java index 3e7521c..421ad5f 100644 --- a/backend/src/main/java/com/nttdata/calender/changes/ChangeRequest.java +++ b/backend/src/main/java/com/nttdata/calender/changes/ChangeRequest.java @@ -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(); @@ -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"; diff --git a/backend/src/main/java/com/nttdata/calender/contracts/Contract.java b/backend/src/main/java/com/nttdata/calender/contracts/Contract.java index 340bf29..159050c 100644 --- a/backend/src/main/java/com/nttdata/calender/contracts/Contract.java +++ b/backend/src/main/java/com/nttdata/calender/contracts/Contract.java @@ -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 allChanges = new ArrayList(); ArrayList allContracts = new ArrayList(); diff --git a/backend/src/main/java/com/nttdata/calender/errorhandling/ErrorTypes/BackendError.java b/backend/src/main/java/com/nttdata/calender/errorhandling/ErrorTypes/BackendError.java index 59837f8..0f82b63 100644 --- a/backend/src/main/java/com/nttdata/calender/errorhandling/ErrorTypes/BackendError.java +++ b/backend/src/main/java/com/nttdata/calender/errorhandling/ErrorTypes/BackendError.java @@ -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; } diff --git a/backend/src/main/java/com/nttdata/calender/errorhandling/ErrorTypes/NotFoundError.java b/backend/src/main/java/com/nttdata/calender/errorhandling/ErrorTypes/NotFoundError.java index 7f10c51..8538390 100644 --- a/backend/src/main/java/com/nttdata/calender/errorhandling/ErrorTypes/NotFoundError.java +++ b/backend/src/main/java/com/nttdata/calender/errorhandling/ErrorTypes/NotFoundError.java @@ -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); } diff --git a/backend/src/main/java/com/nttdata/calender/errorhandling/ErrorTypes/ValidationError.java b/backend/src/main/java/com/nttdata/calender/errorhandling/ErrorTypes/ValidationError.java index ee2dfbe..dab4b7a 100644 --- a/backend/src/main/java/com/nttdata/calender/errorhandling/ErrorTypes/ValidationError.java +++ b/backend/src/main/java/com/nttdata/calender/errorhandling/ErrorTypes/ValidationError.java @@ -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) { diff --git a/backend/src/main/java/com/nttdata/calender/errorhandling/GlobalExceptionHandler.java b/backend/src/main/java/com/nttdata/calender/errorhandling/GlobalExceptionHandler.java index bf6b213..bbf85ca 100644 --- a/backend/src/main/java/com/nttdata/calender/errorhandling/GlobalExceptionHandler.java +++ b/backend/src/main/java/com/nttdata/calender/errorhandling/GlobalExceptionHandler.java @@ -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 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 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 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 entityResponse(String userMessage, String errorMessage, Exception e, HttpStatus status) { var errorResponse = new ErrorResponse(userMessage, e.getClass().getSimpleName()); diff --git a/backend/src/main/java/com/nttdata/calender/supportgroup/SupportGroup.java b/backend/src/main/java/com/nttdata/calender/supportgroup/SupportGroup.java index 9207a68..3ead15a 100644 --- a/backend/src/main/java/com/nttdata/calender/supportgroup/SupportGroup.java +++ b/backend/src/main/java/com/nttdata/calender/supportgroup/SupportGroup.java @@ -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) diff --git a/backend/src/main/java/com/nttdata/calender/urlConstructor/UrlConstructor.java b/backend/src/main/java/com/nttdata/calender/urlConstructor/UrlConstructor.java index c504607..b829604 100644 --- a/backend/src/main/java/com/nttdata/calender/urlConstructor/UrlConstructor.java +++ b/backend/src/main/java/com/nttdata/calender/urlConstructor/UrlConstructor.java @@ -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 }; diff --git a/backend/src/main/java/com/nttdata/calender/urlConstructor/UrlResponse.java b/backend/src/main/java/com/nttdata/calender/urlConstructor/UrlResponse.java index 412f9cc..119f654 100644 --- a/backend/src/main/java/com/nttdata/calender/urlConstructor/UrlResponse.java +++ b/backend/src/main/java/com/nttdata/calender/urlConstructor/UrlResponse.java @@ -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; }