diff options
author | sourabh_sourabh <sourabh.sourabh@est.tech> | 2024-10-22 14:00:29 +0100 |
---|---|---|
committer | sourabh_sourabh <sourabh.sourabh@est.tech> | 2024-10-23 11:29:07 +0100 |
commit | 1e1f49f7947271b15fa9b096a022e827d952a043 (patch) | |
tree | 3958d835c4df52547590bdfb98d945233e72a035 /dmi-stub/dmi-plugin-demo-and-csit-stub-service/src/main/java | |
parent | 46cbc868a7d0adbd8d5f2de0f33ec995c6c13f0a (diff) |
Added maven-checkstyle-plugin to parent POM for code style checks
- Integrate Checkstyle to enforce coding standards across modules.
- Ensure Checkstyle applies to both dmi-service and dmi-stub modules.
- Fixed all code check style issues.
Issue-ID: CPS-2461
Change-Id: Ie84928c1f2e3de549cc8fab2001974369884a831
Signed-off-by: sourabh_sourabh <sourabh.sourabh@est.tech>
Diffstat (limited to 'dmi-stub/dmi-plugin-demo-and-csit-stub-service/src/main/java')
2 files changed, 34 insertions, 29 deletions
diff --git a/dmi-stub/dmi-plugin-demo-and-csit-stub-service/src/main/java/org/onap/cps/ncmp/dmi/rest/stub/controller/DmiRestStubController.java b/dmi-stub/dmi-plugin-demo-and-csit-stub-service/src/main/java/org/onap/cps/ncmp/dmi/rest/stub/controller/DmiRestStubController.java index 2ba56fac..85d454b2 100644 --- a/dmi-stub/dmi-plugin-demo-and-csit-stub-service/src/main/java/org/onap/cps/ncmp/dmi/rest/stub/controller/DmiRestStubController.java +++ b/dmi-stub/dmi-plugin-demo-and-csit-stub-service/src/main/java/org/onap/cps/ncmp/dmi/rest/stub/controller/DmiRestStubController.java @@ -294,9 +294,9 @@ public class DmiRestStubController { public ResponseEntity<Object> retrieveDataJobResult( @PathVariable("dataProducerId") final String dataProducerId, @PathVariable("dataProducerJobId") final String dataProducerJobId, - @RequestParam(name = "destination") String destination) { - log.debug("Received request to retrieve data job result. Data Producer ID: {}, " + - "Data Producer Job ID: {}, Destination: {}", + @RequestParam(name = "destination") final String destination) { + log.debug("Received request to retrieve data job result. Data Producer ID: {}, " + + "Data Producer Job ID: {}, Destination: {}", dataProducerId, dataProducerJobId, destination); return ResponseEntity.ok(Map.of("result", "some status")); } @@ -350,24 +350,25 @@ public class DmiRestStubController { return dataOperationEvent; } - private ResponseEntity<String> processModuleRequest(Object moduleRequest, String responseFileName, long simulatedResponseDelay) { - String moduleSetTag = extractModuleSetTagFromRequest(moduleRequest); + private ResponseEntity<String> processModuleRequest(final Object moduleRequest, final String responseFileName, + final long simulatedResponseDelay) { + final String moduleSetTag = extractModuleSetTagFromRequest(moduleRequest); logRequestBody(moduleRequest); - String moduleResponseContent = getModuleResponseContent(moduleSetTag, responseFileName); + final String moduleResponseContent = getModuleResponseContent(moduleSetTag, responseFileName); delay(simulatedResponseDelay); return ResponseEntity.ok(moduleResponseContent); } - private String extractModuleSetTagFromRequest(Object moduleReferencesRequest) { - JsonNode rootNode = objectMapper.valueToTree(moduleReferencesRequest); + private String extractModuleSetTagFromRequest(final Object moduleReferencesRequest) { + final JsonNode rootNode = objectMapper.valueToTree(moduleReferencesRequest); return rootNode.path("moduleSetTag").asText(null); } - private boolean isModuleSetTagNullOrEmpty(String moduleSetTag) { + private boolean isModuleSetTagNullOrEmpty(final String moduleSetTag) { return moduleSetTag == null || moduleSetTag.trim().isEmpty(); } - private void logRequestBody(Object request) { + private void logRequestBody(final Object request) { try { log.info("Incoming DMI request body: {}", objectMapper.writeValueAsString(request)); } catch (final JsonProcessingException jsonProcessingException) { @@ -376,12 +377,12 @@ public class DmiRestStubController { } private String getModuleResponseContent(final String moduleSetTag, final String responseFileName) { - String moduleResponseFilePath = isModuleSetTagNullOrEmpty(moduleSetTag) + final String moduleResponseFilePath = isModuleSetTagNullOrEmpty(moduleSetTag) ? String.format("module/ietfYang-%s", responseFileName) : String.format("module/%s-%s", moduleSetTag, responseFileName); log.info("Using module responses from : {}", moduleResponseFilePath); - Resource moduleResponseResource = applicationContext.getResource( + final Resource moduleResponseResource = applicationContext.getResource( ResourceLoader.CLASSPATH_URL_PREFIX + moduleResponseFilePath); return ResourceFileReaderUtil.getResourceFileContent(moduleResponseResource); } diff --git a/dmi-stub/dmi-plugin-demo-and-csit-stub-service/src/main/java/org/onap/cps/ncmp/dmi/rest/stub/controller/aop/ModuleInitialProcessAspect.java b/dmi-stub/dmi-plugin-demo-and-csit-stub-service/src/main/java/org/onap/cps/ncmp/dmi/rest/stub/controller/aop/ModuleInitialProcessAspect.java index 32dfeb85..2cecc145 100644 --- a/dmi-stub/dmi-plugin-demo-and-csit-stub-service/src/main/java/org/onap/cps/ncmp/dmi/rest/stub/controller/aop/ModuleInitialProcessAspect.java +++ b/dmi-stub/dmi-plugin-demo-and-csit-stub-service/src/main/java/org/onap/cps/ncmp/dmi/rest/stub/controller/aop/ModuleInitialProcessAspect.java @@ -22,6 +22,8 @@ package org.onap.cps.ncmp.dmi.rest.stub.controller.aop; import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.ObjectMapper; +import java.util.Map; +import java.util.concurrent.ConcurrentHashMap; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.aspectj.lang.ProceedingJoinPoint; @@ -29,10 +31,9 @@ import org.aspectj.lang.annotation.Around; import org.aspectj.lang.annotation.Aspect; import org.springframework.beans.factory.annotation.Value; import org.springframework.http.HttpStatus; -import org.springframework.stereotype.Component; import org.springframework.http.ResponseEntity; -import java.util.Map; -import java.util.concurrent.ConcurrentHashMap; +import org.springframework.stereotype.Component; + /** * Aspect to handle initial processing for methods annotated with @ModuleInitialProcess. @@ -57,47 +58,50 @@ public class ModuleInitialProcessAspect { * @return the result of the method execution or a ResponseEntity indicating that the service is unavailable */ @Around("@annotation(moduleInitialProcess)") - public Object handleModuleInitialProcess(ProceedingJoinPoint proceedingJoinPoint, ModuleInitialProcess moduleInitialProcess) throws Throwable { + public Object handleModuleInitialProcess(final ProceedingJoinPoint proceedingJoinPoint, + final ModuleInitialProcess moduleInitialProcess) throws Throwable { log.debug("Aspect invoked for method: {}", proceedingJoinPoint.getSignature()); - Object moduleRequest = proceedingJoinPoint.getArgs()[1]; - String moduleSetTag = extractModuleSetTagFromRequest(moduleRequest); + final Object moduleRequest = proceedingJoinPoint.getArgs()[1]; + final String moduleSetTag = extractModuleSetTagFromRequest(moduleRequest); if (isModuleSetTagEmptyOrInvalid(moduleSetTag)) { log.debug("Received request with an empty or null moduleSetTag. Returning default processing."); return proceedingJoinPoint.proceed(); } - long firstRequestTimestamp = getFirstRequestTimestamp(moduleSetTag); - long currentTimestamp = System.currentTimeMillis(); + final long firstRequestTimestamp = getFirstRequestTimestamp(moduleSetTag); + final long currentTimestamp = System.currentTimeMillis(); if (isInitialProcessingCompleted(currentTimestamp, firstRequestTimestamp)) { log.debug("Initial processing for moduleSetTag '{}' is completed.", moduleSetTag); return proceedingJoinPoint.proceed(); } - long remainingProcessingTime = calculateRemainingProcessingTime(currentTimestamp, firstRequestTimestamp); - log.info("Initial processing for moduleSetTag '{}' is still active. Returning HTTP 503. Remaining time: {} ms.", moduleSetTag, remainingProcessingTime); + final long remainingProcessingTime = calculateRemainingProcessingTime(currentTimestamp, firstRequestTimestamp); + log.info("Initial processing for moduleSetTag '{}' is still active. Returning HTTP 503. Remaining time: {} ms.", + moduleSetTag, remainingProcessingTime); return ResponseEntity.status(HttpStatus.SERVICE_UNAVAILABLE).build(); } - private String extractModuleSetTagFromRequest(Object moduleRequest) { - JsonNode rootNode = objectMapper.valueToTree(moduleRequest); + private String extractModuleSetTagFromRequest(final Object moduleRequest) { + final JsonNode rootNode = objectMapper.valueToTree(moduleRequest); return rootNode.path("moduleSetTag").asText(null); } - private boolean isModuleSetTagEmptyOrInvalid(String moduleSetTag) { + private boolean isModuleSetTagEmptyOrInvalid(final String moduleSetTag) { return moduleSetTag == null || moduleSetTag.trim().isEmpty(); } - private long getFirstRequestTimestamp(String moduleSetTag) { - return firstRequestTimePerModuleSetTag.computeIfAbsent(moduleSetTag, firstRequestTime -> System.currentTimeMillis()); + private long getFirstRequestTimestamp(final String moduleSetTag) { + return firstRequestTimePerModuleSetTag + .computeIfAbsent(moduleSetTag, firstRequestTime -> System.currentTimeMillis()); } - private boolean isInitialProcessingCompleted(long currentTimestamp, long firstRequestTimestamp) { + private boolean isInitialProcessingCompleted(final long currentTimestamp, final long firstRequestTimestamp) { return currentTimestamp - firstRequestTimestamp >= moduleInitialProcessingDelayMs; } - private long calculateRemainingProcessingTime(long currentTimestamp, long firstRequestTimestamp) { + private long calculateRemainingProcessingTime(final long currentTimestamp, final long firstRequestTimestamp) { return moduleInitialProcessingDelayMs - (currentTimestamp - firstRequestTimestamp); } } |