From bfe52a77b1a53547e771973387f64d632d3b0d74 Mon Sep 17 00:00:00 2001 From: JOSHUA Date: Thu, 4 Jan 2024 12:07:51 +0300 Subject: [PATCH] O3-310: simple code cleaning --- .../FrontendJsonConfigController2_4.java | 26 +++++++++---------- 1 file changed, 12 insertions(+), 14 deletions(-) diff --git a/omod-2.4/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/controller/openmrs2_4/FrontendJsonConfigController2_4.java b/omod-2.4/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/controller/openmrs2_4/FrontendJsonConfigController2_4.java index 56105ff77..5e4506e42 100644 --- a/omod-2.4/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/controller/openmrs2_4/FrontendJsonConfigController2_4.java +++ b/omod-2.4/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/controller/openmrs2_4/FrontendJsonConfigController2_4.java @@ -28,14 +28,14 @@ import org.openmrs.module.webservices.rest.web.RestConstants; import org.openmrs.module.webservices.rest.web.v1_0.controller.BaseRestController; import org.openmrs.util.OpenmrsUtil; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.springframework.http.HttpStatus; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.ResponseStatus; import org.apache.commons.lang.StringUtils; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; import org.codehaus.jackson.JsonProcessingException; import org.codehaus.jackson.map.ObjectMapper; import org.openmrs.module.ModuleException; @@ -44,11 +44,11 @@ @RequestMapping(value = "/rest/" + RestConstants.VERSION_1 + "/frontend/config.json") public class FrontendJsonConfigController2_4 extends BaseRestController { - public static final String DEFAULT_FRONTEND_DIRECTORY = "frontend"; - public static final String GP_LOCAL_DIRECTORY = "spa.local.directory"; + private static final String DEFAULT_FRONTEND_DIRECTORY = "frontend"; + private static final String GP_LOCAL_DIRECTORY = "spa.local.directory"; private static final String JSON_CONFIG_FILE_NAME = "config.json"; - private Log log = LogFactory.getLog(this.getClass()); + private static final Logger log = LoggerFactory.getLogger(FrontendJsonConfigController2_4.class); @RequestMapping(method = RequestMethod.POST) @ResponseStatus(HttpStatus.OK) @@ -83,14 +83,15 @@ private void saveJsonConfigFile(HttpServletRequest request, HttpServletResponse } String requestBody = stringBuilder.toString(); - new ObjectMapper().readTree(requestBody); // verify that is in a valid JSON format + // verify that is in a valid JSON format + new ObjectMapper().readTree(requestBody); InputStream inputStream = new ByteArrayInputStream(requestBody.getBytes(StandardCharsets.UTF_8)); OutputStream outStream = Files.newOutputStream(jsonConfigFile.toPath()); OpenmrsUtil.copyFile(inputStream, outStream); if (jsonConfigFile.exists()) { - log.debug("file: '{" + jsonConfigFile.getAbsolutePath() + "}' written successfully"); + log.debug("file: '{}' written successfully", jsonConfigFile.getAbsolutePath()); response.setStatus(HttpServletResponse.SC_OK); } } catch (JsonProcessingException e) { @@ -115,10 +116,8 @@ private boolean isValidAuthFormat(HttpServletResponse response, String basicAuth String[] userAndPass = decoded.split(":"); Context.authenticate(new UsernamePasswordCredentials(userAndPass[0], userAndPass[1])); - log.debug("authenticated [{" + userAndPass[0] + "}]"); + log.debug("authenticated [{}]", userAndPass[0]); } catch (Exception ex) { - // This filter never stops execution. If the user failed to - // authenticate, that will be caught later. log.debug("authentication exception ", ex); } } @@ -128,9 +127,9 @@ private boolean isValidAuthFormat(HttpServletResponse response, String basicAuth private File getJsonConfigFile() { File folder = getSpaStaticFilesDir(); if (!folder.isDirectory()) { - log.warn("SPA frontend repository is not a directory hence creating it at: " + folder.getAbsolutePath()); + log.warn("Unable to find the OpenMRS SPA module frontend directory hence creating it at: " + folder.getAbsolutePath()); if (!folder.mkdirs()) { - throw new ModuleException("Failed to create the SPA frontend repository folder at: " + folder.getAbsolutePath()); + throw new ModuleException("Failed to create the OpenMRS SPA module frontend directory at: " + folder.getAbsolutePath()); } } return new File(folder.getAbsolutePath(), JSON_CONFIG_FILE_NAME); @@ -144,8 +143,7 @@ private File getSpaStaticFilesDir() { File folder = new File(folderName); // if the property wasn't a full path already, assume it was intended to be a - // folder in the - // application directory + // folder in the application directory if (!folder.exists()) { folder = new File(OpenmrsUtil.getApplicationDataDirectory(), folderName); }