added missing docs and modified docs of changed code

main
Said Gedik 2023-06-02 10:37:19 +02:00
parent 6e2731f887
commit f941fe0f6e
18 changed files with 422 additions and 74 deletions

View File

@ -16,11 +16,22 @@ public class ApiApplication extends SpringBootServletInitializer {
SpringApplication.run(ApiApplication.class, args); SpringApplication.run(ApiApplication.class, args);
} }
/**
* Configures the Spring application builder.
*
* @param builder the Spring application builder.
* @return the configured Spring application builder.
*/
@Override @Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) { protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) {
return builder.sources(ApiApplication.class); return builder.sources(ApiApplication.class);
} }
/**
* Creates a bean for the session repository.
*
* @return the session repository.
*/
@Bean @Bean
public MapSessionRepository sessionRepository() { public MapSessionRepository sessionRepository() {
return new MapSessionRepository(new ConcurrentHashMap<>()); return new MapSessionRepository(new ConcurrentHashMap<>());

View File

@ -15,6 +15,11 @@ public class WebMvcConfig implements WebMvcConfigurer {
this.sessionInterceptor = sessionInterceptor; this.sessionInterceptor = sessionInterceptor;
} }
/**
* Adds the session interceptor to the interceptor registry.
*
* @param registry the interceptor registry.
*/
@Override @Override
public void addInterceptors(InterceptorRegistry registry) { public void addInterceptors(InterceptorRegistry registry) {
registry.addInterceptor(sessionInterceptor); registry.addInterceptor(sessionInterceptor);

View File

@ -99,6 +99,13 @@ public class KalenderRestController {
return ResponseEntity.internalServerError().body("Support Groups couldnt be fetched."); 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("*") @CrossOrigin("*")
@GetMapping("/api/getUrl") @GetMapping("/api/getUrl")
public UrlResponse getLink() throws ARException { 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 * @param request the request object
* @return {@link ChangeResponse} containing the JSON array of all changes * @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("*") @CrossOrigin("*")
@PostMapping("/api/getChanges") @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 * @param request the request object containing the ID of the change entry and
* the new timestamp * the new timestamp
* @return the updated {@link ChangeUpdateRequest} object * @return the updated {@link ChangeUpdateRequest} object
* @throws ARException if an AR exception occurs * @throws ARException if an AR exception occurs
* @throws ValidationError * @throws ValidationError if a validation error occurs
*/ */
@CrossOrigin("*") @CrossOrigin("*")
@PostMapping("/api/updateChange") @PostMapping("/api/updateChange")
@ -233,6 +243,15 @@ public class KalenderRestController {
return ResponseEntity.ok(response); 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("*") @CrossOrigin("*")
@PostMapping("api/updateApproval") @PostMapping("api/updateApproval")
@ResponseBody @ResponseBody
@ -255,6 +274,12 @@ public class KalenderRestController {
return implementer.get(request); 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) { private void logRequest(String endpoint, String request) {
applicationLogger.info("Received request on endpoint %s with body:", endpoint); applicationLogger.info("Received request on endpoint %s with body:", endpoint);
applicationLogger.info(request); applicationLogger.info(request);

View File

@ -214,6 +214,24 @@ public class RemedyJavaAPI {
maxEntriesNumber); 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, private List<Entry> getAllListEntryObjects(QualifierInfo qual, String formName,
List<SortInfo> sortOrder, int[] fieldIds, OutputInteger nMatches, int maxEntriesNumber) throws ARException { List<SortInfo> sortOrder, int[] fieldIds, OutputInteger nMatches, int maxEntriesNumber) throws ARException {
List<Entry> entries = new ArrayList<Entry>(); List<Entry> entries = new ArrayList<Entry>();
@ -231,6 +249,29 @@ public class RemedyJavaAPI {
return entries; 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, private List<Entry> getSomeListEntryObjects(int sliceStart, int sliceEnd, QualifierInfo qual, String formName,
List<SortInfo> sortOrder, int[] fieldIds, OutputInteger nMatches, int maxEntriesNumber) throws ARException { List<SortInfo> sortOrder, int[] fieldIds, OutputInteger nMatches, int maxEntriesNumber) throws ARException {
List<Entry> entries = new ArrayList<Entry>(); List<Entry> entries = new ArrayList<Entry>();
@ -253,6 +294,16 @@ public class RemedyJavaAPI {
return entries; 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 { public int getFormSize(String qualStr, String formName) throws ARException {
List<Field> fields = server.getListFieldObjects(formName); List<Field> fields = server.getListFieldObjects(formName);
QualifierInfo qual = server.parseQualification(qualStr, QualifierInfo qual = server.parseQualification(qualStr,

View File

@ -10,6 +10,9 @@ import com.bmc.arsys.api.ARException;
import com.bmc.thirdparty.org.springframework.beans.factory.annotation.Autowired; import com.bmc.thirdparty.org.springframework.beans.factory.annotation.Autowired;
import com.nttdata.calender.api.RemedyJavaAPI; import com.nttdata.calender.api.RemedyJavaAPI;
/**
* Service class for handling Rsso operations.
*/
@Service @Service
public class Rsso { public class Rsso {
private final RemedyJavaAPI javaAPI; private final RemedyJavaAPI javaAPI;
@ -19,6 +22,15 @@ public class Rsso {
this.javaAPI = javaAPI; 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 { public ResponseEntity<?> createSession(String token, HttpSession session) throws ARException {
var response = validateToken(token); var response = validateToken(token);
switch (response.getResponseSessionStatus()) { switch (response.getResponseSessionStatus()) {
@ -34,6 +46,12 @@ public class Rsso {
return ResponseEntity.internalServerError().body("Token could not be processed"); 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) { public RssoResponse validateToken(String token) {
var server = javaAPI.getServer(); var server = javaAPI.getServer();
var webclient = WebClient.create(); var webclient = WebClient.create();

View File

@ -8,6 +8,9 @@ import org.springframework.web.servlet.HandlerInterceptor;
import com.bmc.thirdparty.org.springframework.beans.factory.annotation.Autowired; import com.bmc.thirdparty.org.springframework.beans.factory.annotation.Autowired;
/**
* Interceptor for handling Rsso related operations.
*/
@Component @Component
public class RssoInterceptor implements HandlerInterceptor { public class RssoInterceptor implements HandlerInterceptor {
private final static boolean DEBUG = true; private final static boolean DEBUG = true;
@ -18,6 +21,16 @@ public class RssoInterceptor implements HandlerInterceptor {
this.rsso = rsso; 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 // TODO: what if there is no cookie? what if no rssotoken in cookie? what if
// createSession throws Exception? // createSession throws Exception?
@Override @Override

View File

@ -2,6 +2,9 @@ package com.nttdata.calender.api.rsso;
import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.annotation.JsonProperty;
/**
* Represents the response from the Rsso API.
*/
public class RssoResponse { public class RssoResponse {
@JsonProperty("realm") @JsonProperty("realm")
private String realm; private String realm;
@ -15,34 +18,74 @@ public class RssoResponse {
@JsonProperty("response-sessionStatus") @JsonProperty("response-sessionStatus")
private String responseSessionStatus; private String responseSessionStatus;
/**
* Get the realm.
*
* @return the realm
*/
public String getRealm() { public String getRealm() {
return this.realm; return this.realm;
} }
/**
* Set the realm.
*
* @param realm the realm to set
*/
public void setRealm(String realm) { public void setRealm(String realm) {
this.realm = realm; this.realm = realm;
} }
/**
* Get the user ID.
*
* @return the user ID
*/
public String getUserId() { public String getUserId() {
return this.userId; return this.userId;
} }
/**
* Set the user ID.
*
* @param userId the user ID to set
*/
public void setUserId(String userId) { public void setUserId(String userId) {
this.userId = userId; this.userId = userId;
} }
/**
* Get the tenant ID.
*
* @return the tenant ID
*/
public String getTenantId() { public String getTenantId() {
return this.tenantId; return this.tenantId;
} }
/**
* Set the tenant ID.
*
* @param tenantId the tenant ID to set
*/
public void setTenantId(String tenantId) { public void setTenantId(String tenantId) {
this.tenantId = tenantId; this.tenantId = tenantId;
} }
/**
* Get the response session status.
*
* @return the response session status
*/
public String getResponseSessionStatus() { public String getResponseSessionStatus() {
return this.responseSessionStatus; return this.responseSessionStatus;
} }
/**
* Set the response session status.
*
* @param responseSessionStatus the response session status to set
*/
public void setResponseSessionStatus(String responseSessionStatus) { public void setResponseSessionStatus(String responseSessionStatus) {
this.responseSessionStatus = responseSessionStatus; this.responseSessionStatus = responseSessionStatus;
} }

View File

@ -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, * 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. * field.
* *
* @param request the defined qualifier for specific selection * @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 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 { public ChangeResponse get(ChangeRequest request) throws ARException, NotFoundError, ValidationError {
api.impersonateUser("ext_StanzPa"); api.impersonateUser("ext_StanzPa");
@ -139,6 +141,17 @@ public class Change {
return new ChangeResponse(entriesSize, changes); 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 { private String processPeopleInfo(ChangeRequest request) throws ARException, NotFoundError {
// Queries for SupportGroup of impersonated User // Queries for SupportGroup of impersonated User
var queryPerson = new Query.QueryBuilder("CTM:Support Group Association") var queryPerson = new Query.QueryBuilder("CTM:Support Group Association")
@ -243,6 +256,15 @@ public class Change {
// approversOI.get(0).get(queryApprovalList.getFieldId("Approvers")).toString(); // approversOI.get(0).get(queryApprovalList.getFieldId("Approvers")).toString();
// return approvers != null ? approvers.contains(user) : false; // 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 { private String queryPackageName(String packageType) throws ARException {
var queryPackage = new Query.QueryBuilder("CTR:GenericContractJoinCFG_Package") var queryPackage = new Query.QueryBuilder("CTR:GenericContractJoinCFG_Package")
.addFieldId("PackageName", 200000020).build(); .addFieldId("PackageName", 200000020).build();

View File

@ -162,89 +162,100 @@ public class ChangeItem {
} }
// /** // /**
// * Retrieves the flag indicating whether the change item has a permit. // * Retrieves the flag indicating whether the change item has a permit.
// * // *
// * @return {@code true} if the change item has a permit, {@code false} // * @return {@code true} if the change item has a permit, {@code false}
// * otherwise. // * otherwise.
// */ // */
// public boolean getFlagPermit() { // public boolean getFlagPermit() {
// return this.flagPermit; // return this.flagPermit;
// } // }
// /** // /**
// * Sets the flag indicating whether the change item has a permit. // * 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
// * otherwise. // false}
// */ // * otherwise.
// */
// public void setFlagPermit(boolean flagPermit) { // public void setFlagPermit(boolean flagPermit) {
// this.flagPermit = flagPermit; // this.flagPermit = flagPermit;
// } // }
// /** // /**
// * Retrieves the flag indicating whether the change item has been approved. // * Retrieves the flag indicating whether the change item has been approved.
// * // *
// * @return {@code true} if the change item has been approved, {@code false} // * @return {@code true} if the change item has been approved, {@code false}
// * otherwise. // * otherwise.
// */ // */
// public boolean getFlagApprove() { // public boolean getFlagApprove() {
// return this.flagApprove; // return this.flagApprove;
// } // }
// /** // /**
// * Sets the flag indicating whether the change item has been approved. // * Sets the flag indicating whether the change item has been approved.
// * // *
// * @param flagApprove {@code true} if the change item has been approved, // * @param flagApprove {@code true} if the change item has been approved,
// * {@code false} otherwise. // * {@code false} otherwise.
// */ // */
// public void setFlagApprove(boolean flagApprove) { // public void setFlagApprove(boolean flagApprove) {
// this.flagApprove = flagApprove; // this.flagApprove = flagApprove;
// } // }
// /** // /**
// * Retrieves the flag indicating whether the change item has been rejected. // * Retrieves the flag indicating whether the change item has been rejected.
// * // *
// * @return {@code true} if the change item has been rejected, {@code false} // * @return {@code true} if the change item has been rejected, {@code false}
// * otherwise. // * otherwise.
// */ // */
// public boolean getFlagReject() { // public boolean getFlagReject() {
// return this.flagReject; // return this.flagReject;
// } // }
// /** // /**
// * Sets the flag indicating whether the change item has been rejected. // * Sets the flag indicating whether the change item has been rejected.
// * // *
// * @param flagReject {@code true} if the change item has been rejected, // * @param flagReject {@code true} if the change item has been rejected,
// * {@code false} otherwise. // * {@code false} otherwise.
// */ // */
// public void setFlagReject(boolean flagReject) { // public void setFlagReject(boolean flagReject) {
// this.flagReject = flagReject; // this.flagReject = flagReject;
// } // }
// /** // /**
// * Retrieves the flag indicating whether the change item has been canceled. // * Retrieves the flag indicating whether the change item has been canceled.
// * // *
// * @return {@code true} if the change item has been canceled, {@code false} // * @return {@code true} if the change item has been canceled, {@code false}
// * otherwise. // * otherwise.
// */ // */
// public boolean getFlagCancel() { // public boolean getFlagCancel() {
// return this.flagCancel; // return this.flagCancel;
// } // }
// /** // /**
// * Sets the flag indicating whether the change item has been canceled. // * Sets the flag indicating whether the change item has been canceled.
// * // *
// * @param flagCancel {@code true} if the change item has been canceled, // * @param flagCancel {@code true} if the change item has been canceled,
// * {@code false} otherwise. // * {@code false} otherwise.
// */ // */
// public void setFlagCancel(boolean flagCancel) { // public void setFlagCancel(boolean flagCancel) {
// this.flagCancel = flagCancel; // this.flagCancel = flagCancel;
// } // }
/**
* Retrieves the package name.
*
* @return the package name
*/
public String getPackageName() { public String getPackageName() {
return this.packageName; return this.packageName;
} }
/**
* Sets the package name.
*
* @param packageName the package name to set
*/
public void setPackageName(String packageName) { public void setPackageName(String packageName) {
this.packageName = packageName; this.packageName = packageName;
} }

View File

@ -97,6 +97,11 @@ public class ChangeRequest {
this.sort = sort; this.sort = sort;
} }
/**
* Adds a filter to the list of filters.
*
* @param filter the filter to add
*/
public void addFilter(Filter filter) { public void addFilter(Filter filter) {
if (this.filter == null) { if (this.filter == null) {
this.filter = new ArrayList<Filter>(); this.filter = new ArrayList<Filter>();
@ -104,6 +109,16 @@ public class ChangeRequest {
this.filter.add(filter); 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 { public SortInfo constructSortInfo(Query query) throws ValidationError {
if (this.sort != null) { if (this.sort != null) {
return this.sort.getSortInfo(query); 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 * Constructs and returns a qualifier based on the filters defined in the object
* given Query object. * and the given Query object.
* *
* @param query the {@link Query} object containing form and field information. * @param query the Query object containing form and field information
* @param api the {@link RemedyJavaAPI} object used for accessing the AR * @param api the RemedyJavaAPI object used for accessing the AR System API
* System API. * @return a String representing the constructed qualifier
* @return a String representing the constructed qualifier. * @throws ARException if an error occurs while constructing the qualifier
* @throws ARException if an error occurs while constructing the qualifier or an * or an invalid filter is provided
* 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 { public String constructQualifier(Query query, RemedyJavaAPI api) throws ARException, ValidationError {
var qualifier = ""; var qualifier = "";
@ -181,6 +197,20 @@ public class ChangeRequest {
return qualifier; 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) private String constructDateQualifier(Filter current_filter, String column, Query query, RemedyJavaAPI api)
throws ValidationError, ARException { throws ValidationError, ARException {
if (current_filter.getCriteria().length != 2) { if (current_filter.getCriteria().length != 2) {
@ -205,6 +235,17 @@ public class ChangeRequest {
return qualifier; 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 { private String convertDate(String date) throws ValidationError {
String inputFormat = "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'"; String inputFormat = "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'";
String outputFormat = "dd/MM/yyyy"; String outputFormat = "dd/MM/yyyy";

View File

@ -35,12 +35,15 @@ public class Contract {
/** /**
* Queries the Remedy AR Server using the provided `api` object to retrieve * Queries the Remedy AR Server using the provided `api` object to retrieve
* Contract IDs from both changes and contracts forms, compares the IDs, and * Contract IDs
* stores the matching ones in the `contracts` list. * 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 { public void queryContracts(RemedyJavaAPI api) throws ARException, NotFoundError {
ArrayList<ContractGetResponse> allChanges = new ArrayList<ContractGetResponse>(); ArrayList<ContractGetResponse> allChanges = new ArrayList<ContractGetResponse>();
ArrayList<ContractGetResponse> allContracts = new ArrayList<ContractGetResponse>(); ArrayList<ContractGetResponse> allContracts = new ArrayList<ContractGetResponse>();

View File

@ -2,20 +2,43 @@ package com.nttdata.calender.errorhandling.ErrorTypes;
import org.springframework.http.HttpStatus; 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 { public abstract class BackendError extends Exception {
private int errorCode; private int errorCode;
private HttpStatus httpStatus; 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) { public BackendError(String message, int errorCode, HttpStatus httpStatus) {
super(message); super(message);
this.errorCode = errorCode; this.errorCode = errorCode;
this.httpStatus = httpStatus; this.httpStatus = httpStatus;
} }
/**
* Gets the error code associated with the error.
*
* @return the error code.
*/
public int getErrorCode() { public int getErrorCode() {
return errorCode; return errorCode;
} }
/**
* Gets the HTTP status associated with the error.
*
* @return the HTTP status.
*/
public HttpStatus getHttpStatus() { public HttpStatus getHttpStatus() {
return httpStatus; return httpStatus;
} }

View File

@ -2,7 +2,18 @@ package com.nttdata.calender.errorhandling.ErrorTypes;
import org.springframework.http.HttpStatus; 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 { public class NotFoundError extends BackendError {
/**
* Constructs a NotFoundError object with the specified error message.
*
* @param message the error message.
*/
public NotFoundError(String message) { public NotFoundError(String message) {
super(message, 404, HttpStatus.NOT_FOUND); super(message, 404, HttpStatus.NOT_FOUND);
} }

View File

@ -2,6 +2,10 @@ package com.nttdata.calender.errorhandling.ErrorTypes;
import org.springframework.http.HttpStatus; 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 class ValidationError extends BackendError {
public ValidationError(String message) { public ValidationError(String message) {

View File

@ -12,28 +12,61 @@ import org.springframework.web.bind.annotation.ExceptionHandler;
import com.bmc.arsys.api.ARException; import com.bmc.arsys.api.ARException;
import com.nttdata.calender.errorhandling.ErrorTypes.BackendError; import com.nttdata.calender.errorhandling.ErrorTypes.BackendError;
/**
* Global exception handler class for handling exceptions in the application.
*/
@ControllerAdvice @ControllerAdvice
public class GlobalExceptionHandler { public class GlobalExceptionHandler {
private static final Logger errorLogger = LogManager.getLogger("error"); 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) @ExceptionHandler(ARException.class)
public ResponseEntity<ErrorResponse> handleARException(ARException e, HttpServletRequest request) { public ResponseEntity<ErrorResponse> handleARException(ARException e, HttpServletRequest request) {
var errorMessage = "Remedy server error: " + e.getMessage(); var errorMessage = "Remedy server error: " + e.getMessage();
return entityResponse(errorMessage, errorMessage, e, HttpStatus.INTERNAL_SERVER_ERROR); 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) @ExceptionHandler(Exception.class)
public ResponseEntity<ErrorResponse> handleGenericException(Exception e, HttpServletRequest request) { public ResponseEntity<ErrorResponse> handleGenericException(Exception e, HttpServletRequest request) {
var userMessage = "Backend internal server error"; var userMessage = "Backend internal server error";
return entityResponse(userMessage, e.getMessage(), e, HttpStatus.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) @ExceptionHandler(BackendError.class)
public ResponseEntity<ErrorResponse> handleBackendErrorException(BackendError e, HttpServletRequest request) { public ResponseEntity<ErrorResponse> handleBackendErrorException(BackendError e, HttpServletRequest request) {
var errorMessage = "Backend internal server error: " + e.getMessage(); var errorMessage = "Backend internal server error: " + e.getMessage();
return entityResponse(errorMessage, errorMessage, e, e.getHttpStatus()); 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, private ResponseEntity<ErrorResponse> entityResponse(String userMessage, String errorMessage, Exception e,
HttpStatus status) { HttpStatus status) {
var errorResponse = new ErrorResponse(userMessage, e.getClass().getSimpleName()); var errorResponse = new ErrorResponse(userMessage, e.getClass().getSimpleName());

View File

@ -35,11 +35,12 @@ public class SupportGroup {
} }
/** /**
* Queries the Remedy AR Server using the provided api object to retrieve * Populates the supportGroups list by querying the Remedy AR Server using the
* information about support groups and populates the supportGroups list * provided API object.
* with the results.
* *
* @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 { public void querySupportGroups(RemedyJavaAPI api) throws ARException, NotFoundError {
var querySupportGroups = new Query.QueryBuilder(formName) var querySupportGroups = new Query.QueryBuilder(formName)

View File

@ -11,6 +11,13 @@ public class UrlConstructor {
String viewForm = "/SHR%3ALandingConsole/Default+Administrator+View/?mode=search&F304255500="; String viewForm = "/SHR%3ALandingConsole/Default+Administrator+View/?mode=search&F304255500=";
String getPkg = "&F1000000076=FormOpenNoAppList&F303647600=SearchTicketWithQual&F304255610="; 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 { public UrlResponse construct(RemedyJavaAPI api) throws ARException {
var server = api.getServer(); var server = api.getServer();
var setting = new int[] { Constants.AR_SERVER_INFO_SERVER_NAME, Constants.AR_SERVER_INFO_DEFAULT_WEB_PATH }; var setting = new int[] { Constants.AR_SERVER_INFO_SERVER_NAME, Constants.AR_SERVER_INFO_DEFAULT_WEB_PATH };

View File

@ -4,23 +4,49 @@ public class UrlResponse {
private String entryUrl; private String entryUrl;
private String viewFormUrl; 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) { public UrlResponse(String entryUrl, String viewFormUrl) {
this.entryUrl = entryUrl; this.entryUrl = entryUrl;
this.viewFormUrl = viewFormUrl; this.viewFormUrl = viewFormUrl;
} }
/**
* Retrieves the URL for accessing the entry.
*
* @return the entry URL.
*/
public String getEntryUrl() { public String getEntryUrl() {
return this.entryUrl; return this.entryUrl;
} }
/**
* Sets the URL for accessing the entry.
*
* @param entryUrl the entry URL to set.
*/
public void setEntryUrl(String entryUrl) { public void setEntryUrl(String entryUrl) {
this.entryUrl = entryUrl; this.entryUrl = entryUrl;
} }
/**
* Retrieves the URL for accessing the view form.
*
* @return the view form URL.
*/
public String getViewFormUrl() { public String getViewFormUrl() {
return this.viewFormUrl; return this.viewFormUrl;
} }
/**
* Sets the URL for accessing the view form.
*
* @param viewFormUrl the view form URL to set.
*/
public void setViewFormUrl(String viewFormUrl) { public void setViewFormUrl(String viewFormUrl) {
this.viewFormUrl = viewFormUrl; this.viewFormUrl = viewFormUrl;
} }