Skip to content

Commit

Permalink
AYS-467 | Emergency Evacuation Application Endpoint Checks with AOP A…
Browse files Browse the repository at this point in the history
…nnotation (#378)
  • Loading branch information
agitrubard authored Sep 19, 2024
1 parent a61440a commit 5f9c703
Show file tree
Hide file tree
Showing 6 changed files with 62 additions and 1 deletion.
5 changes: 5 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,11 @@
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-aop</artifactId>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-validation</artifactId>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package org.ays.common.util.exception;

import java.io.Serial;

public final class EmergencyEvacuationApplicationEndpointNotActiveException extends AysAuthException {

@Serial
private static final long serialVersionUID = -5238438967353670872L;

public EmergencyEvacuationApplicationEndpointNotActiveException() {
super("emergency evacuation application endpoint is not active!");
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import org.ays.emergency_application.model.response.EmergencyEvacuationApplicationResponse;
import org.ays.emergency_application.model.response.EmergencyEvacuationApplicationsResponse;
import org.ays.emergency_application.service.EmergencyEvacuationApplicationService;
import org.ays.emergency_application.util.annotation.CheckEmergencyEvacuationApplicationActivity;
import org.hibernate.validator.constraints.UUID;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
Expand Down Expand Up @@ -77,6 +78,7 @@ public AysResponse<EmergencyEvacuationApplicationResponse> findById(@PathVariabl
return AysResponse.successOf(emergencyEvacuationApplicationResponse);
}


/**
* Endpoint to create a new emergency evacuation application.
* This method accepts a POST request with the emergency evacuation application details in the request body.
Expand All @@ -85,6 +87,7 @@ public AysResponse<EmergencyEvacuationApplicationResponse> findById(@PathVariabl
* @param emergencyEvacuationApplicationRequest the details of the emergency evacuation application
* @return a response indicating the success of the operation
*/
@CheckEmergencyEvacuationApplicationActivity
@PostMapping("/emergency-evacuation-application")
public AysResponse<Void> create(@RequestBody @Valid EmergencyEvacuationApplicationRequest emergencyEvacuationApplicationRequest) {
emergencyEvacuationApplicationService.create(emergencyEvacuationApplicationRequest);
Expand All @@ -101,7 +104,7 @@ public AysResponse<Void> create(@RequestBody @Valid EmergencyEvacuationApplicati
* The user must have the authority 'application:evacuation:update' to access this endpoint.
* </p>
*
* @param id the unique identifier of the Emergency Evacuation Application to be updated
* @param id the unique identifier of the Emergency Evacuation Application to be updated
* @param updateRequest the request object containing the details to update the Emergency Evacuation Application
* @return a response indicating the success of the update operation
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package org.ays.emergency_application.util.annotation;

import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

@Target(ElementType.METHOD)
@Retention(RetentionPolicy.RUNTIME)
public @interface CheckEmergencyEvacuationApplicationActivity {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package org.ays.emergency_application.util.annotation;

import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.ays.common.util.exception.EmergencyEvacuationApplicationEndpointNotActiveException;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

@Aspect
@Component
class CheckEmergencyEvacuationApplicationActivityAspect {

@Value("${ays.emergency-evacuation-application.enabled}")
private boolean isEmergencyEvacuationApplicationEnabled;

@Before(value = "@annotation(CheckEmergencyEvacuationApplicationActivity)")
public void checkEmergencyEvacuationActivity() {

if (isEmergencyEvacuationApplicationEnabled) {
return;
}

throw new EmergencyEvacuationApplicationEndpointNotActiveException();
}

}
2 changes: 2 additions & 0 deletions src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@ management:
base-path: /public/actuator

ays:
emergency-evacuation-application:
enabled: ${AYS_EMERGENCY_EVACUATION_APPLICATION_ENABLED:true}
scheduler:
invalid-tokens-deletion:
cron: ${INVALID_TOKENS_DELETION_CRON:0 0 */3 * * ?}
Expand Down

0 comments on commit 5f9c703

Please sign in to comment.