diff --git a/backend/src/main/java/com/nttdata/calender/ApplicationStartupListener.java b/backend/src/main/java/com/nttdata/calender/ApplicationStartupListener.java new file mode 100644 index 0000000..14ae878 --- /dev/null +++ b/backend/src/main/java/com/nttdata/calender/ApplicationStartupListener.java @@ -0,0 +1,21 @@ +package com.nttdata.calender; + +import org.springframework.boot.context.event.ApplicationReadyEvent; +import org.springframework.context.ApplicationListener; +import org.springframework.stereotype.Component; + +@Component +public class ApplicationStartupListener implements ApplicationListener { + + private static boolean applicationReady = false; + + @Override + public void onApplicationEvent(ApplicationReadyEvent event) { + System.out.println("Application is ready to service requests."); + applicationReady = true; + } + + public static boolean isApplicationReady() { + return applicationReady; + } +} diff --git a/backend/src/main/java/com/nttdata/calender/ReadyStatus.java b/backend/src/main/java/com/nttdata/calender/ReadyStatus.java new file mode 100644 index 0000000..69ee6d4 --- /dev/null +++ b/backend/src/main/java/com/nttdata/calender/ReadyStatus.java @@ -0,0 +1,17 @@ +package com.nttdata.calender; + +public class ReadyStatus { + private boolean ready; + + public ReadyStatus(boolean ready) { + this.ready = ready; + } + + public boolean isReady() { + return ready; + } + + public void setReady(boolean ready) { + this.ready = ready; + } +} diff --git a/backend/src/main/java/com/nttdata/calender/api/KalenderRestController.java b/backend/src/main/java/com/nttdata/calender/api/KalenderRestController.java index 7ffdbfe..7cb2f1d 100644 --- a/backend/src/main/java/com/nttdata/calender/api/KalenderRestController.java +++ b/backend/src/main/java/com/nttdata/calender/api/KalenderRestController.java @@ -8,6 +8,7 @@ import org.apache.logging.log4j.Logger; import org.checkerframework.common.util.report.qual.ReportCall; import org.json.JSONObject; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.CrossOrigin; import org.springframework.web.bind.annotation.GetMapping; @@ -17,7 +18,10 @@ import org.springframework.web.bind.annotation.ResponseBody; import org.springframework.web.bind.annotation.RestController; import com.bmc.arsys.api.ARException; import com.bmc.arsys.api.Value; +import com.bmc.thirdparty.org.springframework.context.ApplicationListener; import com.fasterxml.jackson.core.JsonProcessingException; +import com.nttdata.calender.ApplicationStartupListener; +import com.nttdata.calender.ReadyStatus; import com.nttdata.calender.approval.Approval; import com.nttdata.calender.approval.ApprovalUpdateRequest; import com.nttdata.calender.changes.Change; @@ -80,6 +84,13 @@ public class KalenderRestController { this.stateChange = stateChange; } + @CrossOrigin("*") + @PostMapping("/setReady") + @ResponseBody + public ReadyStatus setReady() { + return new ReadyStatus(ApplicationStartupListener.isApplicationReady()); + } + /** * Handles GET request to retrieve all the states and their actual and possible * states and results a JSON array. @@ -102,7 +113,7 @@ public class KalenderRestController { * * @return JSON Array of states with actualState, possibleStates, stateNameEN, * stateNameDE - * @throws ARException + * @throws ARException * @throws JsonProcessingException if an exception occurs during JSON processing */ @CrossOrigin("*") @@ -114,7 +125,8 @@ public class KalenderRestController { .addFieldId("Name", 1000000017) .build(); - var name = this.javaAPI.queryFieldsById("\'4\'==\"" + javaAPI.getUser() + "\"", query.getFieldIds(), query.getFormName(), null, 0, 0).get(0); + var name = this.javaAPI.queryFieldsById("\'4\'==\"" + javaAPI.getUser() + "\"", query.getFieldIds(), + query.getFormName(), null, 0, 0).get(0); String jsonString = "{\"userId\": \"" + name.get(query.getFieldId("Name")) + "\"}"; return jsonString; } diff --git a/backend/src/main/resources/application.properties b/backend/src/main/resources/application.properties index 600806b..c239ca1 100644 --- a/backend/src/main/resources/application.properties +++ b/backend/src/main/resources/application.properties @@ -1,2 +1,3 @@ #server.servlet.context-path=/test -server.servlet.session.timeout=24h \ No newline at end of file +server.servlet.session.timeout=24h +# server.port=${PROBE_PORT:8080}