cleaning code + adding transaction id

main
Said Gedik 2024-06-18 20:06:06 +02:00
parent 022024219e
commit 330823b41d
7 changed files with 35 additions and 37 deletions

View File

@ -116,19 +116,27 @@ public class KalenderRestController {
* @throws ARException * @throws ARException
* @throws JsonProcessingException if an exception occurs during JSON processing * @throws JsonProcessingException if an exception occurs during JSON processing
*/ */
@CrossOrigin("*") @CrossOrigin("*")
@GetMapping("/api/getUser") @GetMapping("/api/getUser")
@ResponseBody @ResponseBody
public String getUserId() throws ARException { public ResponseEntity<String> getUserId() throws ARException {
var query = new Query.QueryBuilder("CTM:People LookUp") var query = new Query.QueryBuilder("CTM:People LookUp")
.addFieldId("Name", 1000000017) .addFieldId("Name", 1000000017)
.build(); .build();
var name = this.javaAPI.queryFieldsById("\'4\'==\"" + javaAPI.getUser() + "\"", query.getFieldIds(), var results = this.javaAPI.queryFieldsById("'4'==\"" + javaAPI.getUser() + "\"", query.getFieldIds(),
query.getFormName(), null, 0, 0).get(0); query.getFormName(), null, 0, 0);
if (results.isEmpty()) {
// Handle the case where no results are found
String errorMessage = "No user found with the given criteria.";
return ResponseEntity.status(HttpStatus.NOT_FOUND).body("{\"error\": \"" + errorMessage + "\"}");
}
var name = results.get(0);
String jsonString = "{\"userId\": \"" + name.get(query.getFieldId("Name")) + "\"}"; String jsonString = "{\"userId\": \"" + name.get(query.getFieldId("Name")) + "\"}";
return jsonString; return ResponseEntity.ok(jsonString);
} }
/** /**
@ -208,7 +216,7 @@ public class KalenderRestController {
@ResponseBody @ResponseBody
public ArrayList<ContractGetResponse> getContracts() throws ARException, NotFoundError { public ArrayList<ContractGetResponse> getContracts() throws ARException, NotFoundError {
Contract contract = new Contract(); Contract contract = new Contract();
System.out.println(javaAPI.getUser()); // System.out.println(javaAPI.getUser());
return contract.get(this.javaAPI); return contract.get(this.javaAPI);
} }
@ -254,7 +262,6 @@ public class KalenderRestController {
@ResponseBody @ResponseBody
public ChangeResponse getChanges(@RequestBody ChangeRequest request) public ChangeResponse getChanges(@RequestBody ChangeRequest request)
throws ARException, NotFoundError, ValidationError { throws ARException, NotFoundError, ValidationError {
return change.get(request); return change.get(request);
} }

View File

@ -7,8 +7,11 @@ import org.springframework.web.servlet.HandlerInterceptor;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
import java.text.SimpleDateFormat;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter; import java.time.format.DateTimeFormatter;
import java.util.Calendar;
@Component @Component
public class RequestInterceptor implements HandlerInterceptor { public class RequestInterceptor implements HandlerInterceptor {
@ -23,16 +26,23 @@ public class RequestInterceptor implements HandlerInterceptor {
String currentDateTime = LocalDateTime.now().format(dateTimeFormatter); String currentDateTime = LocalDateTime.now().format(dateTimeFormatter);
String out = currentDateTime + " - handling request: " + request.getRequestURI(); String out = currentDateTime + " - handling request: " + request.getRequestURI();
logger.info(out); logger.info(out);
System.out.println(out); // System.out.println(out);
return true; // Continue with the request return true; // Continue with the request
} }
@Override @Override
public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex)
throws Exception { throws Exception {
String currentDateTime = LocalDateTime.now().format(dateTimeFormatter);
long transactionId = System.currentTimeMillis();
if (ex == null) if (ex == null)
System.out.println("Success in handling request: " + request.getRequestURI()); System.out.println(
"Transaction ID: " + transactionId + "\n" + currentDateTime + " [SUCCESS] handling request: "
+ request.getRequestURI() + "\n");
else else
System.out.println("Error in handling request: " + request.getRequestURI()); System.err.println(currentDateTime + " [ERROR] handling request: " + request.getRequestURI() + "\n"
+ ex.getMessage() + "\n");
} }
} }

View File

@ -92,15 +92,11 @@ public class Change {
var peopleFullName = processPeopleInfo(request); var peopleFullName = processPeopleInfo(request);
var filter = request.getFilter(); var filter = request.getFilter();
for (var v : filter.getFilterElement()) {
System.out.println(v.getFilter() + ", " + v.getColumn() +", " + v.getCriteria());
}
var qualifier = filter.constructQualifier(queryChange, api); var qualifier = filter.constructQualifier(queryChange, api);
SortInfo sort = request.constructSortInfo(queryChange); SortInfo sort = request.constructSortInfo(queryChange);
log.initLog("getChanges", api.getUser()); // Logging log.initLog("getChanges", api.getUser()); // Logging
System.out.println(qualifier);
var entries = api.queryFieldsById(qualifier, this.queryChange.getFieldIds(), var entries = api.queryFieldsById(qualifier, this.queryChange.getFieldIds(),
this.queryChange.getFormName(), this.queryChange.getFormName(),
sort, request.getSliceStart(), sort, request.getSliceStart(),
@ -151,7 +147,6 @@ public class Change {
} }
} }
if(Optional.ofNullable(getValue(entry, "State")).map(Value::getIntValue).orElse(-1)== 9){ if(Optional.ofNullable(getValue(entry, "State")).map(Value::getIntValue).orElse(-1)== 9){
System.out.println("\n++++++++"+getValueStringByID(entry, "CurrentStageNumber"));
if(getValueStringByID(entry, "CurrentStageNumber").equals("1")){ if(getValueStringByID(entry, "CurrentStageNumber").equals("1")){
change.setState(9); change.setState(9);
}else{ }else{
@ -195,8 +190,6 @@ public class Change {
change.setPlanTime(convertPlanTime(ptHours, ptMinutes)); change.setPlanTime(convertPlanTime(ptHours, ptMinutes));
changes.add(change); changes.add(change);
} }
System.out.println(entries.size());
api.freeImpersonatedUser(); api.freeImpersonatedUser();
return new ChangeResponse(entriesSize, changes); return new ChangeResponse(entriesSize, changes);

View File

@ -103,8 +103,6 @@ public class Filter {
var column = current_filter.getColumn(); var column = current_filter.getColumn();
var criterias = current_filter.getCriteria(); var criterias = current_filter.getCriteria();
System.out.println(current_filter + " | ");
if (column.isEmpty() || criterias.length <= 0) { if (column.isEmpty() || criterias.length <= 0) {
throw new ValidationError("Fields inside filter empty"); throw new ValidationError("Fields inside filter empty");
} }

View File

@ -24,7 +24,6 @@ public class Contract {
this.contracts = new ArrayList<ContractGetResponse>(); this.contracts = new ArrayList<ContractGetResponse>();
} }
/** /**
* 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 * Contract IDs
@ -33,22 +32,20 @@ public class Contract {
* ones in the `contracts` list. * ones in the `contracts` list.
* *
* @param api the RemedyJavaAPI object used to connect to the Remedy AR Server * @param api the RemedyJavaAPI object used to connect to the Remedy AR Server
* @return * @return
* @throws ARException if an error occurs during the querying process * @throws ARException if an error occurs during the querying process
* @throws NotFoundError if no contracts are found in the given context * @throws NotFoundError if no contracts are found in the given context
*/ */
public ArrayList<ContractGetResponse> queryContracts(RemedyJavaAPI api) throws ARException, NotFoundError { public ArrayList<ContractGetResponse> queryContracts(RemedyJavaAPI api) throws ARException, NotFoundError {
ArrayList<ContractGetResponse> allContracts = new ArrayList<ContractGetResponse>(); ArrayList<ContractGetResponse> allContracts = new ArrayList<ContractGetResponse>();
var queryContracts = new Query.QueryBuilder(formName_contracts) var queryContracts = new Query.QueryBuilder(formName_contracts)
.addFieldId("Id", 179) .addFieldId("Id", 179)
.addFieldId("Name", 700008020).build(); .addFieldId("Name", 700008020).build();
System.out.println("\n### USER: "+api.getUser());
allContracts = api allContracts = api
.queryFieldsById("\'4\' = \""+api.getUser()+"\"", queryContracts.getFieldIds(), formName_contracts, null, .queryFieldsById("\'4\' = \"" + api.getUser() + "\"", queryContracts.getFieldIds(), formName_contracts,
null,
0, 0) 0, 0)
.stream() .stream()
.map(entry -> new ContractGetResponse( .map(entry -> new ContractGetResponse(
@ -57,22 +54,16 @@ public class Contract {
.distinct() .distinct()
.collect(Collectors.toCollection(ArrayList::new)); .collect(Collectors.toCollection(ArrayList::new));
for (ContractGetResponse contractGetResponse : allContracts) {
System.out.println(contractGetResponse.name);
}
if (allContracts.isEmpty()) { if (allContracts.isEmpty()) {
System.out.println("No contracts found in this context"); System.out.println("No contracts found in this context");
} }
return allContracts; return allContracts;
} }
/** /**
* @return the list of contracts * @return the list of contracts
* @throws ARException * @throws ARException
* @throws NotFoundError * @throws NotFoundError
*/ */
public ArrayList<ContractGetResponse> get(RemedyJavaAPI api) throws NotFoundError, ARException { public ArrayList<ContractGetResponse> get(RemedyJavaAPI api) throws NotFoundError, ARException {
return this.queryContracts(api); return this.queryContracts(api);

View File

@ -76,7 +76,6 @@ public class Presets {
var guid = preference.get(0).get(prefQuery.getFieldId("GUID")); var guid = preference.get(0).get(prefQuery.getFieldId("GUID"));
if (guid.toString() == null) { if (guid.toString() == null) {
// IF GUID IS NULL PUT SYSTEM DEFAULT INSIDE // IF GUID IS NULL PUT SYSTEM DEFAULT INSIDE
System.out.println("GEHT REIN");
var queryPreferenceNewValue = new Query.QueryBuilder(formUserPref) var queryPreferenceNewValue = new Query.QueryBuilder(formUserPref)
.addFieldValue("GUID", 364000001, new Value(sysdefGUID)).build(); .addFieldValue("GUID", 364000001, new Value(sysdefGUID)).build();
var pref = api.queryFieldsById("\'2\'==\"" + api.getUser() + "\"", var pref = api.queryFieldsById("\'2\'==\"" + api.getUser() + "\"",

View File

@ -114,7 +114,7 @@ public class State {
populateStateInfo(stateFields, stateStatusFields, configurationQuery, configurationStatusQuery); populateStateInfo(stateFields, stateStatusFields, configurationQuery, configurationStatusQuery);
// Print state information // Print state information
printStateInfo(); // printStateInfo();
} }
private void populateStateInfo(List<Entry> stateFields, List<Entry> stateStatusFields, private void populateStateInfo(List<Entry> stateFields, List<Entry> stateStatusFields,
@ -135,7 +135,7 @@ public class State {
implementerFlag = stateField.get(configurationQuery.getFieldId("implementerFlag")).toString() implementerFlag = stateField.get(configurationQuery.getFieldId("implementerFlag")).toString()
.equals("SETIMPLEMENTER_YES"); .equals("SETIMPLEMENTER_YES");
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); // e.printStackTrace();
} }
String engName = stateField.get(configurationQuery.getFieldId("engName")).toString(); String engName = stateField.get(configurationQuery.getFieldId("engName")).toString();