diff --git a/pom.xml b/pom.xml index f4f039601..ccd0e6950 100644 --- a/pom.xml +++ b/pom.xml @@ -63,6 +63,11 @@ spring-boot-starter-data-jpa + + org.springframework.boot + spring-boot-starter-aop + + org.springframework.boot spring-boot-starter-validation diff --git a/src/main/java/org/ays/common/util/exception/EmergencyEvacuationApplicationEndpointNotActiveException.java b/src/main/java/org/ays/common/util/exception/EmergencyEvacuationApplicationEndpointNotActiveException.java new file mode 100644 index 000000000..7d209408c --- /dev/null +++ b/src/main/java/org/ays/common/util/exception/EmergencyEvacuationApplicationEndpointNotActiveException.java @@ -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!"); + } + +} diff --git a/src/main/java/org/ays/emergency_application/controller/EmergencyEvacuationApplicationController.java b/src/main/java/org/ays/emergency_application/controller/EmergencyEvacuationApplicationController.java index 06df3db07..79b62d375 100644 --- a/src/main/java/org/ays/emergency_application/controller/EmergencyEvacuationApplicationController.java +++ b/src/main/java/org/ays/emergency_application/controller/EmergencyEvacuationApplicationController.java @@ -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; @@ -77,6 +78,7 @@ public AysResponse 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. @@ -85,6 +87,7 @@ public AysResponse 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 create(@RequestBody @Valid EmergencyEvacuationApplicationRequest emergencyEvacuationApplicationRequest) { emergencyEvacuationApplicationService.create(emergencyEvacuationApplicationRequest); @@ -101,7 +104,7 @@ public AysResponse create(@RequestBody @Valid EmergencyEvacuationApplicati * The user must have the authority 'application:evacuation:update' to access this endpoint. *

* - * @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 */ diff --git a/src/main/java/org/ays/emergency_application/util/annotation/CheckEmergencyEvacuationApplicationActivity.java b/src/main/java/org/ays/emergency_application/util/annotation/CheckEmergencyEvacuationApplicationActivity.java new file mode 100644 index 000000000..23e801913 --- /dev/null +++ b/src/main/java/org/ays/emergency_application/util/annotation/CheckEmergencyEvacuationApplicationActivity.java @@ -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 { +} diff --git a/src/main/java/org/ays/emergency_application/util/annotation/CheckEmergencyEvacuationApplicationActivityAspect.java b/src/main/java/org/ays/emergency_application/util/annotation/CheckEmergencyEvacuationApplicationActivityAspect.java new file mode 100644 index 000000000..3fee412b1 --- /dev/null +++ b/src/main/java/org/ays/emergency_application/util/annotation/CheckEmergencyEvacuationApplicationActivityAspect.java @@ -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(); + } + +} diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index 86ec797e4..f9ac8e885 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -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 * * ?}