Done ticket GEPAFINBE-133 User action api response.
This commit is contained in:
@@ -41,6 +41,8 @@ public class LoggingUtil {
|
||||
@Autowired
|
||||
private TokenProvider tokenProvider;
|
||||
|
||||
private static final ThreadLocal<Long> userActionIdHolder = new ThreadLocal<>();
|
||||
|
||||
public UserActionEntity logUserAction(UserActionRequest userActionRequest) {
|
||||
UserActionEntity userAction = new UserActionEntity();
|
||||
try {
|
||||
@@ -83,12 +85,22 @@ public class LoggingUtil {
|
||||
userAction.setResponse(response);
|
||||
userActionsRepository.save(userAction);
|
||||
userActionRequest.getRequest().setAttribute(GepafinConstant.USER_ACTION_ID, userAction.getId());
|
||||
userActionIdHolder.set(userAction.getId());
|
||||
} catch (Exception e) {
|
||||
log.error("Error logging user action: {}", e.getMessage(), e);
|
||||
}
|
||||
return userAction;
|
||||
}
|
||||
|
||||
public Long getUserActionId() {
|
||||
return userActionIdHolder.get();
|
||||
}
|
||||
|
||||
public void clearUserActionId() {
|
||||
userActionIdHolder.remove();
|
||||
log.info("UserActionId cleared from ThreadLocal");
|
||||
}
|
||||
|
||||
private String normalizeUrl(String url) {
|
||||
|
||||
url = url.replaceAll("(?<!:)//+", "/");
|
||||
@@ -263,6 +275,7 @@ public class LoggingUtil {
|
||||
userAction.setResponse(response);
|
||||
userActionsRepository.save(userAction);
|
||||
userActionRequest.getRequest().setAttribute(GepafinConstant.USER_ACTION_ID, userAction.getId());
|
||||
|
||||
} catch (Exception e) {
|
||||
log.error("Error logging user action: {}", e.getMessage(), e);
|
||||
}
|
||||
@@ -323,10 +336,35 @@ public class LoggingUtil {
|
||||
|
||||
public UserActionEntity getUserActionLogById(Long id) {
|
||||
|
||||
return userActionsRepository.findUserActionById(id);
|
||||
return userActionsRepository.findUserActionByIdAndIsDeletedFalse(id);
|
||||
}
|
||||
public List<VersionHistoryEntity> getVersionHistoryLogById(Long id) {
|
||||
|
||||
return versionHistoryRepository.findVersionHistoryByUserActionId(id);
|
||||
}
|
||||
|
||||
public void updateUserActionWithError(Long userActionId, String errorDetails) {
|
||||
if (userActionId == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
UserActionEntity userAction = userActionsRepository.findUserActionByIdAndIsDeletedFalse(userActionId);
|
||||
if (userAction != null) {
|
||||
userAction.setResponse(errorDetails);
|
||||
userActionsRepository.save(userAction);
|
||||
}
|
||||
}
|
||||
|
||||
public void updateUserActionWithResponse(Long userActionId, String response) {
|
||||
if (userActionId == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
UserActionEntity userAction = userActionsRepository.findUserActionByIdAndIsDeletedFalse(userActionId);
|
||||
if (userAction != null) {
|
||||
userAction.setResponse(response);
|
||||
userActionsRepository.save(userAction);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user