generated from bcgov/quickstart-openshift
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
1 parent
984fe72
commit 59a2ec8
Showing
30 changed files
with
613 additions
and
292 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
backend/src/main/java/ca/bc/gov/restapi/results/oracle/endpoint/UserActionsEndpoint.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package ca.bc.gov.restapi.results.oracle.endpoint; | ||
|
||
import ca.bc.gov.restapi.results.oracle.service.UserActionsService; | ||
import ca.bc.gov.restapi.results.postgres.dto.MyRecentActionsRequestsDto; | ||
import java.util.List; | ||
import lombok.RequiredArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
@RestController | ||
@RequestMapping("/api/users") | ||
@RequiredArgsConstructor | ||
@Slf4j | ||
public class UserActionsEndpoint { | ||
|
||
private final UserActionsService userActionsService; | ||
|
||
@GetMapping("/recent-actions") | ||
public ResponseEntity<List<MyRecentActionsRequestsDto>> getUserRecentOpeningsActions() { | ||
List<MyRecentActionsRequestsDto> actionsDto = | ||
userActionsService.getResultsAuditActivity(); | ||
|
||
log.info("Returning {} recent actions", actionsDto.size()); | ||
|
||
if (actionsDto.isEmpty()) { | ||
return ResponseEntity.noContent().build(); | ||
} | ||
|
||
return ResponseEntity.ok(actionsDto); | ||
} | ||
|
||
} |
14 changes: 14 additions & 0 deletions
14
...nd/src/main/java/ca/bc/gov/restapi/results/oracle/entity/ResultsAuditEventProjection.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package ca.bc.gov.restapi.results.oracle.entity; | ||
|
||
import java.time.LocalDateTime; | ||
|
||
public interface ResultsAuditEventProjection { | ||
Long getResultsAuditEventId(); | ||
Long getOpeningId(); | ||
String getActionCode(); | ||
String getActionCodeDescription(); | ||
String getCategoryCode(); | ||
String getCategoryCodeDescription(); | ||
LocalDateTime getEntryTimestamp(); | ||
String getEntryUserid(); | ||
} |
41 changes: 41 additions & 0 deletions
41
backend/src/main/java/ca/bc/gov/restapi/results/oracle/enums/AuditActionCodeEnum.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package ca.bc.gov.restapi.results.oracle.enums; | ||
|
||
import com.fasterxml.jackson.annotation.JsonFormat; | ||
import lombok.AccessLevel; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Getter; | ||
|
||
@JsonFormat(shape = JsonFormat.Shape.OBJECT) | ||
@AllArgsConstructor(access = AccessLevel.PRIVATE) | ||
@Getter | ||
public enum AuditActionCodeEnum { | ||
UPD("UPD", "Update"), | ||
COR("COR", "Correction"), | ||
O("O", "Original"), | ||
SEC197("197", "Section 197"), | ||
AMG("AMG", "Amalgamate"), | ||
ES("ES", "E-submission"), | ||
MIL("MIL", "Milestone"), | ||
MIN("MIN", "Amended (Minor)"), | ||
SPA("SPA", "Site Plan Amendment"), | ||
VAR("VAR", "Variation"), | ||
AMD("AMD", "Amended"), | ||
APP("APP", "Approved"), | ||
DEL("DEL", "Deleted"), | ||
REJ("REJ", "Rejected"), | ||
RET("RET", "Retired"), | ||
RMD("RMD", "Removed"), | ||
SUB("SUB", "Submitted"); | ||
|
||
private final String code; | ||
private final String description; | ||
|
||
public static AuditActionCodeEnum of(String code) { | ||
for (AuditActionCodeEnum value : AuditActionCodeEnum.values()) { | ||
if (value.getCode().equals(code)) { | ||
return value; | ||
} | ||
} | ||
return null; | ||
} | ||
} |
33 changes: 33 additions & 0 deletions
33
...main/java/ca/bc/gov/restapi/results/oracle/repository/ResultsAuditActivityRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package ca.bc.gov.restapi.results.oracle.repository; | ||
|
||
import ca.bc.gov.restapi.results.oracle.entity.OpeningEntity; | ||
import ca.bc.gov.restapi.results.oracle.entity.ResultsAuditEventProjection; | ||
import java.util.List; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
import org.springframework.data.jpa.repository.Query; | ||
|
||
public interface ResultsAuditActivityRepository extends JpaRepository<OpeningEntity, Long> { | ||
|
||
@Query( | ||
value = """ | ||
SELECT | ||
rae.results_audit_event_id, | ||
rae.opening_id, | ||
rae.results_audit_action_code as action_code, | ||
raac.description as action_code_description, | ||
o.open_category_code as category_code, | ||
occ.description as category_code_description, | ||
rae.entry_timestamp, | ||
rae.entry_userid | ||
FROM THE.RESULTS_AUDIT_EVENT rae | ||
LEFT JOIN THE.RESULTS_AUDIT_ACTION_CODE raac ON raac.RESULTS_AUDIT_ACTION_CODE = rae.RESULTS_AUDIT_ACTION_CODE | ||
LEFT JOIN THE.OPENING o ON o.OPENING_ID = rae.OPENING_ID | ||
LEFT JOIN THE.OPEN_CATEGORY_CODE occ ON occ.OPEN_CATEGORY_CODE = o.OPEN_CATEGORY_CODE | ||
WHERE rae.ENTRY_USERID = ?1 | ||
ORDER BY rae.ENTRY_TIMESTAMP DESC | ||
FETCH FIRST ?2 ROWS ONLY""", | ||
nativeQuery = true) | ||
List<ResultsAuditEventProjection> findUserRecentAuditEvents(String userId, Integer limit); | ||
|
||
|
||
} |
45 changes: 45 additions & 0 deletions
45
backend/src/main/java/ca/bc/gov/restapi/results/oracle/service/UserActionsService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package ca.bc.gov.restapi.results.oracle.service; | ||
|
||
import ca.bc.gov.restapi.results.common.configuration.SilvaConfiguration; | ||
import ca.bc.gov.restapi.results.common.security.LoggedUserService; | ||
import ca.bc.gov.restapi.results.oracle.repository.ResultsAuditActivityRepository; | ||
import ca.bc.gov.restapi.results.postgres.dto.MyRecentActionsRequestsDto; | ||
import java.util.List; | ||
import lombok.RequiredArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.ocpsoft.prettytime.PrettyTime; | ||
import org.springframework.stereotype.Service; | ||
|
||
@Slf4j | ||
@Service | ||
@RequiredArgsConstructor | ||
public class UserActionsService { | ||
|
||
private final ResultsAuditActivityRepository auditActivityRepository; | ||
private final LoggedUserService loggedUserService; | ||
private final SilvaConfiguration silvaConfiguration; | ||
private final PrettyTime prettyTime = new PrettyTime(); | ||
|
||
public List<MyRecentActionsRequestsDto> getResultsAuditActivity() { | ||
String userId = loggedUserService.getLoggedUserId(); | ||
|
||
log.info("Getting recent audit events for user {}", userId); | ||
|
||
return | ||
auditActivityRepository | ||
.findUserRecentAuditEvents(userId, silvaConfiguration.getLimits().getMaxActionsResults()) | ||
.stream() | ||
.map(entity -> | ||
new MyRecentActionsRequestsDto( | ||
entity.getActionCodeDescription(), | ||
entity.getOpeningId(), | ||
entity.getCategoryCode(), | ||
entity.getCategoryCodeDescription(), | ||
prettyTime.format(entity.getEntryTimestamp()), | ||
entity.getEntryTimestamp() | ||
) | ||
) | ||
.toList(); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.