simplified code
parent
aa2763b4b2
commit
9523311710
|
|
@ -283,6 +283,10 @@ public class KalenderRestController {
|
||||||
public ChangeUpdateRequest updateChange(@RequestBody ChangeUpdateRequest request, HttpServletRequest httpRequest)
|
public ChangeUpdateRequest updateChange(@RequestBody ChangeUpdateRequest request, HttpServletRequest httpRequest)
|
||||||
throws ARException, ValidationError {
|
throws ARException, ValidationError {
|
||||||
httpRequest.setAttribute("requestBody", request);
|
httpRequest.setAttribute("requestBody", request);
|
||||||
|
|
||||||
|
String formName = (request.getState() == 0) ? "ASF:WI_TAS_Paket" : "CHG:Infrastructure Change";
|
||||||
|
httpRequest.setAttribute("formName", formName);
|
||||||
|
|
||||||
change.modifyTimestamp(request);
|
change.modifyTimestamp(request);
|
||||||
return request;
|
return request;
|
||||||
}
|
}
|
||||||
|
|
@ -304,6 +308,7 @@ public class KalenderRestController {
|
||||||
throws ARException {
|
throws ARException {
|
||||||
logRequest("/updateState", request.toString());
|
logRequest("/updateState", request.toString());
|
||||||
httpRequest.setAttribute("requestBody", request);
|
httpRequest.setAttribute("requestBody", request);
|
||||||
|
httpRequest.setAttribute("formName", "ASF:CHG_CAL_Interactions");
|
||||||
var response = stateChange.createStateChange(request);
|
var response = stateChange.createStateChange(request);
|
||||||
return ResponseEntity.ok(response);
|
return ResponseEntity.ok(response);
|
||||||
}
|
}
|
||||||
|
|
@ -322,6 +327,7 @@ public class KalenderRestController {
|
||||||
public ResponseEntity<String> updateImplementer(@RequestBody ImplementerUpdateRequest request,
|
public ResponseEntity<String> updateImplementer(@RequestBody ImplementerUpdateRequest request,
|
||||||
HttpServletRequest httpRequest) throws ARException {
|
HttpServletRequest httpRequest) throws ARException {
|
||||||
httpRequest.setAttribute("requestBody", request);
|
httpRequest.setAttribute("requestBody", request);
|
||||||
|
httpRequest.setAttribute("formName", "ASF:CHG_CAL_Interactions");
|
||||||
var response = implementer.update(request);
|
var response = implementer.update(request);
|
||||||
return ResponseEntity.ok(response);
|
return ResponseEntity.ok(response);
|
||||||
}
|
}
|
||||||
|
|
@ -341,6 +347,7 @@ public class KalenderRestController {
|
||||||
public ResponseEntity<String> updateApproval(@RequestBody ApprovalUpdateRequest request,
|
public ResponseEntity<String> updateApproval(@RequestBody ApprovalUpdateRequest request,
|
||||||
HttpServletRequest httpRequest) throws ARException {
|
HttpServletRequest httpRequest) throws ARException {
|
||||||
httpRequest.setAttribute("requestBody", request);
|
httpRequest.setAttribute("requestBody", request);
|
||||||
|
httpRequest.setAttribute("formName", "ASF:CHG_CAL_Interactions");
|
||||||
var response = approval.update(request);
|
var response = approval.update(request);
|
||||||
return ResponseEntity.ok(response);
|
return ResponseEntity.ok(response);
|
||||||
}
|
}
|
||||||
|
|
@ -363,9 +370,11 @@ public class KalenderRestController {
|
||||||
@CrossOrigin("*")
|
@CrossOrigin("*")
|
||||||
@PostMapping("/api/savePreset")
|
@PostMapping("/api/savePreset")
|
||||||
@ResponseBody
|
@ResponseBody
|
||||||
public List<Preset> savePreset(@RequestBody Preset request)
|
public List<Preset> savePreset(@RequestBody Preset request, HttpServletRequest httpRequest)
|
||||||
throws ARException, ValidationError, NotFoundError {
|
throws ARException, ValidationError, NotFoundError {
|
||||||
Presets presets = new Presets(javaAPI);
|
Presets presets = new Presets(javaAPI);
|
||||||
|
httpRequest.setAttribute("requestBody", request);
|
||||||
|
httpRequest.setAttribute("formName", "ASF:CHG_CAL_FilterDefinitions");
|
||||||
presets.savePreset(request);
|
presets.savePreset(request);
|
||||||
return presets.getAll();
|
return presets.getAll();
|
||||||
}
|
}
|
||||||
|
|
@ -373,8 +382,12 @@ public class KalenderRestController {
|
||||||
@CrossOrigin("*")
|
@CrossOrigin("*")
|
||||||
@PostMapping("/api/selectPreset")
|
@PostMapping("/api/selectPreset")
|
||||||
@ResponseBody
|
@ResponseBody
|
||||||
public boolean selectPreset(@RequestBody SelectPresetRequest guid) throws ARException,
|
public boolean selectPreset(@RequestBody SelectPresetRequest guid, HttpServletRequest httpRequest)
|
||||||
|
throws ARException,
|
||||||
NotFoundError {
|
NotFoundError {
|
||||||
|
httpRequest.setAttribute("requestBody", guid);
|
||||||
|
httpRequest.setAttribute("formName", "ASF:CHG_CAL_UserPreferences");
|
||||||
|
|
||||||
Presets presets = new Presets(javaAPI);
|
Presets presets = new Presets(javaAPI);
|
||||||
return presets.selectPreset(guid);
|
return presets.selectPreset(guid);
|
||||||
}
|
}
|
||||||
|
|
@ -390,8 +403,10 @@ public class KalenderRestController {
|
||||||
@CrossOrigin("*")
|
@CrossOrigin("*")
|
||||||
@PostMapping("api/updatePreset")
|
@PostMapping("api/updatePreset")
|
||||||
@ResponseBody
|
@ResponseBody
|
||||||
public List<Preset> updatePreset(@RequestBody UpdatePresetRequest request) throws NotFoundError, ARException {
|
public List<Preset> updatePreset(@RequestBody UpdatePresetRequest request, HttpServletRequest httpRequest) throws NotFoundError, ARException {
|
||||||
Presets presets = new Presets(javaAPI);
|
Presets presets = new Presets(javaAPI);
|
||||||
|
httpRequest.setAttribute("requestBody", request);
|
||||||
|
httpRequest.setAttribute("formName", "ASF:CHG_CAL_FilterDefinitions");
|
||||||
presets.updatePreset(request);
|
presets.updatePreset(request);
|
||||||
return presets.getAll();
|
return presets.getAll();
|
||||||
}
|
}
|
||||||
|
|
@ -399,8 +414,10 @@ public class KalenderRestController {
|
||||||
@CrossOrigin("*")
|
@CrossOrigin("*")
|
||||||
@PostMapping("api/deletePreset")
|
@PostMapping("api/deletePreset")
|
||||||
@ResponseBody
|
@ResponseBody
|
||||||
public Object deletePreset(@RequestBody DeletePresetRequest request) throws ARException, NotFoundError {
|
public Object deletePreset(@RequestBody DeletePresetRequest request, HttpServletRequest httpRequest) throws ARException, NotFoundError {
|
||||||
Presets presets = new Presets(javaAPI);
|
Presets presets = new Presets(javaAPI);
|
||||||
|
httpRequest.setAttribute("requestBody", request);
|
||||||
|
httpRequest.setAttribute("formName", "ASF:CHG_CAL_FilterDefinitions");
|
||||||
presets.deletePreset(request);
|
presets.deletePreset(request);
|
||||||
return presets.getAll();
|
return presets.getAll();
|
||||||
}
|
}
|
||||||
|
|
@ -408,8 +425,10 @@ public class KalenderRestController {
|
||||||
@CrossOrigin
|
@CrossOrigin
|
||||||
@PostMapping("api/renamePreset")
|
@PostMapping("api/renamePreset")
|
||||||
@ResponseBody
|
@ResponseBody
|
||||||
public List<Preset> renamePreset(@RequestBody RenamePresetRequest request) throws NotFoundError, ARException {
|
public List<Preset> renamePreset(@RequestBody RenamePresetRequest request, HttpServletRequest httpRequest) throws NotFoundError, ARException {
|
||||||
Presets presets = new Presets(javaAPI);
|
Presets presets = new Presets(javaAPI);
|
||||||
|
httpRequest.setAttribute("requestBody", request);
|
||||||
|
httpRequest.setAttribute("formName", "ASF:CHG_CAL_FilterDefinitions");
|
||||||
presets.renamePreset(request);
|
presets.renamePreset(request);
|
||||||
return presets.getAll();
|
return presets.getAll();
|
||||||
}
|
}
|
||||||
|
|
@ -417,8 +436,10 @@ public class KalenderRestController {
|
||||||
@CrossOrigin("*")
|
@CrossOrigin("*")
|
||||||
@PostMapping("api/editUserPreferences")
|
@PostMapping("api/editUserPreferences")
|
||||||
@ResponseBody
|
@ResponseBody
|
||||||
public void editUserPreferences(@RequestBody EditUserPreferencesRequest request) throws ARException, NotFoundError {
|
public void editUserPreferences(@RequestBody EditUserPreferencesRequest request, HttpServletRequest httpRequest) throws ARException, NotFoundError {
|
||||||
Presets presets = new Presets(javaAPI);
|
Presets presets = new Presets(javaAPI);
|
||||||
|
httpRequest.setAttribute("requestBody", request);
|
||||||
|
httpRequest.setAttribute("formName", "ASF:CHG_CAL_UserPreferences");
|
||||||
presets.editUserPreferences(request);
|
presets.editUserPreferences(request);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -9,16 +9,24 @@ import org.springframework.web.servlet.HandlerInterceptor;
|
||||||
import com.nttdata.calender.approval.ApprovalUpdateRequest;
|
import com.nttdata.calender.approval.ApprovalUpdateRequest;
|
||||||
import com.nttdata.calender.changes.ChangeUpdateRequest;
|
import com.nttdata.calender.changes.ChangeUpdateRequest;
|
||||||
import com.nttdata.calender.implementer.ImplementerUpdateRequest;
|
import com.nttdata.calender.implementer.ImplementerUpdateRequest;
|
||||||
|
import com.nttdata.calender.presets.Preset;
|
||||||
|
import com.nttdata.calender.presets.SelectPresetRequest;
|
||||||
|
import com.nttdata.calender.presets.UpdatePresetRequest;
|
||||||
import com.nttdata.calender.states.StateChangeRequest;
|
import com.nttdata.calender.states.StateChangeRequest;
|
||||||
|
|
||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
import javax.servlet.http.HttpServletResponse;
|
import javax.servlet.http.HttpServletResponse;
|
||||||
|
import com.bmc.arsys.api.Value;
|
||||||
|
|
||||||
|
import static org.mockito.ArgumentMatchers.startsWith;
|
||||||
|
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
import java.time.format.DateTimeFormatter;
|
import java.time.format.DateTimeFormatter;
|
||||||
|
|
||||||
@Component
|
@Component
|
||||||
public class RequestInterceptor implements HandlerInterceptor {
|
public class RequestInterceptor implements HandlerInterceptor {
|
||||||
|
private RemedyJavaAPI api;
|
||||||
|
private final static String form = "ASF:CHG_CAL_Transactions";
|
||||||
|
|
||||||
private static final Logger logger = LogManager.getLogger("application");
|
private static final Logger logger = LogManager.getLogger("application");
|
||||||
private static final DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
|
private static final DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
|
||||||
|
|
@ -26,6 +34,7 @@ public class RequestInterceptor implements HandlerInterceptor {
|
||||||
@Override
|
@Override
|
||||||
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler)
|
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler)
|
||||||
throws Exception {
|
throws Exception {
|
||||||
|
api = new RemedyJavaAPI();
|
||||||
String currentDateTime = LocalDateTime.now().format(dateTimeFormatter);
|
String currentDateTime = LocalDateTime.now().format(dateTimeFormatter);
|
||||||
long transactionId = System.currentTimeMillis();
|
long transactionId = System.currentTimeMillis();
|
||||||
String out = String.format("Transaction ID = %d %s - handling request: %s", transactionId, currentDateTime,
|
String out = String.format("Transaction ID = %d %s - handling request: %s", transactionId, currentDateTime,
|
||||||
|
|
@ -34,55 +43,61 @@ public class RequestInterceptor implements HandlerInterceptor {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static String output(String time, long id, String user, String status, String action, String ticket,
|
|
||||||
String result) {
|
|
||||||
return String.format(
|
|
||||||
"%s\n Transaction ID: %d\n User: %s\n Status: %s\n Action: %s\n Ticket: %s\n Result: %s",
|
|
||||||
time, id, user, status, action, ticket, result);
|
|
||||||
}
|
|
||||||
|
|
||||||
@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 {
|
||||||
if ("POST".equalsIgnoreCase(request.getMethod())) {
|
|
||||||
String currentDateTime = LocalDateTime.now().format(dateTimeFormatter);
|
|
||||||
long transactionId = System.currentTimeMillis();
|
|
||||||
String changeNr = "";
|
|
||||||
|
|
||||||
if (handler instanceof HandlerMethod) {
|
if (!"POST".equalsIgnoreCase(request.getMethod()) || !(handler instanceof HandlerMethod)) {
|
||||||
HandlerMethod handlerMethod = (HandlerMethod) handler;
|
return;
|
||||||
String action = handlerMethod.getMethod().getName();
|
}
|
||||||
Object requestBody = request.getAttribute("requestBody");
|
|
||||||
|
|
||||||
if (requestBody instanceof ChangeUpdateRequest) {
|
long transactionId = System.currentTimeMillis();
|
||||||
ChangeUpdateRequest changeUpdateRequest = (ChangeUpdateRequest) requestBody;
|
Query entry = null;
|
||||||
changeNr += changeUpdateRequest.getChangeNr();
|
|
||||||
action += " | Date change";
|
|
||||||
} else if (requestBody instanceof StateChangeRequest) {
|
|
||||||
StateChangeRequest changeStateRequest = (StateChangeRequest) requestBody;
|
|
||||||
changeNr += changeStateRequest.getChangeNr();
|
|
||||||
action += " | State transition";
|
|
||||||
} else if (requestBody instanceof ImplementerUpdateRequest) {
|
|
||||||
ImplementerUpdateRequest implementerUpdateRequest = (ImplementerUpdateRequest) requestBody;
|
|
||||||
action += " | Implementer Update";
|
|
||||||
} else if (requestBody instanceof ApprovalUpdateRequest) {
|
|
||||||
ApprovalUpdateRequest approvalUpdateRequest = (ApprovalUpdateRequest) requestBody;
|
|
||||||
action += " | Approval Update";
|
|
||||||
}
|
|
||||||
|
|
||||||
String status = (ex == null) ? "Success" : "Error";
|
Object requestBody = request.getAttribute("requestBody");
|
||||||
String result = (ex == null) ? "Successful" : ex.getMessage();
|
String formName = (String) request.getAttribute("formName");
|
||||||
String out = output(currentDateTime, transactionId, "User", status,
|
int status = (ex == null) ? 3 : 2;
|
||||||
request.getRequestURI() + " | " + action, changeNr, result);
|
|
||||||
|
|
||||||
if (ex == null) {
|
if (requestBody instanceof ChangeUpdateRequest) {
|
||||||
logger.info(out);
|
entry = buildQueryEntry(transactionId, "Date change", formName, ((ChangeUpdateRequest) requestBody).getChangeNr(), getAssignedTo(), status);
|
||||||
} else {
|
} else if (requestBody instanceof StateChangeRequest) {
|
||||||
logger.error(out);
|
entry = buildQueryEntry(transactionId, "State transition", formName, ((StateChangeRequest) requestBody).getChangeNr(), getAssignedTo(), status);
|
||||||
}
|
} else if (requestBody instanceof ImplementerUpdateRequest) {
|
||||||
|
entry = buildQueryEntry(transactionId, "Implementer Update", formName, ((ImplementerUpdateRequest) requestBody).getPkgId(), getAssignedTo(), status);
|
||||||
|
} else if (requestBody instanceof ApprovalUpdateRequest) {
|
||||||
|
entry = buildQueryEntry(transactionId, "Approval Update", formName, ((ApprovalUpdateRequest) requestBody).getChangeNr(), getAssignedTo(), status);
|
||||||
|
} else if (requestBody instanceof Preset) {
|
||||||
|
entry = buildQueryEntry(transactionId, "Save Preset", formName, ((Preset) requestBody).getId(), getAssignedTo(), status);
|
||||||
|
} else if (requestBody instanceof SelectPresetRequest) {
|
||||||
|
entry = buildQueryEntry(transactionId, "Preset selected", formName, ((SelectPresetRequest) requestBody).getGuid(), getAssignedTo(), status);
|
||||||
|
} else if (requestBody instanceof UpdatePresetRequest) {
|
||||||
|
entry = buildQueryEntry(transactionId, "Update Preset", formName, ((UpdatePresetRequest) requestBody).getId(), getAssignedTo(), status);
|
||||||
|
}
|
||||||
|
|
||||||
System.out.println("\n" + out);
|
if (entry != null) {
|
||||||
}
|
api.createEntry(entry);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private Query buildQueryEntry(long transactionId, String actionType, String affectedForm, String changeNr,
|
||||||
|
String assignedTo, int status) {
|
||||||
|
return new Query.QueryBuilder(form)
|
||||||
|
.addFieldValue("AssignedTo", 4, new Value(assignedTo))
|
||||||
|
.addFieldValue("Status", 7, new Value(status))
|
||||||
|
.addFieldValue("TransactionID", 666000000, new Value(transactionId))
|
||||||
|
.addFieldValue("FieldValue", 666000001, new Value(
|
||||||
|
"Die Felder und Werte die verändert wurde, z.B.: {\"6000434\" : \"24.05.2024 13:00:45\"}"))
|
||||||
|
.addFieldValue("FormIDs", 666000002,
|
||||||
|
new Value("Die Request IDs (1er Feld / entryid) der Einträge, die modifiziert werden"))
|
||||||
|
.addFieldValue("ActionType", 666000003, new Value(actionType))
|
||||||
|
.addFieldValue("AffectedForm", 666000004, new Value(affectedForm))
|
||||||
|
.addFieldValue("TicketID", 666000005, new Value(changeNr))
|
||||||
|
.build();
|
||||||
|
}
|
||||||
|
|
||||||
|
private String getAssignedTo() {
|
||||||
|
String assignedTo = api.getUser();
|
||||||
|
return (assignedTo == null || assignedTo.isEmpty()) ? "Placeholder User" : assignedTo;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue