diff --git a/pom.xml b/pom.xml
index 08db8b70..d6285d36 100644
--- a/pom.xml
+++ b/pom.xml
@@ -231,6 +231,17 @@
+
+
+ org.springframework.session
+ spring-session-data-redis
+ 3.2.1
+
+
+
+ org.springframework.boot
+ spring-boot-starter-actuator
+
mmuapi-v1.0
diff --git a/src/main/java/com/iemr/mmu/config/BlockingHttpMethodInterceptor.java b/src/main/java/com/iemr/mmu/config/BlockingHttpMethodInterceptor.java
deleted file mode 100644
index 8c1c76db..00000000
--- a/src/main/java/com/iemr/mmu/config/BlockingHttpMethodInterceptor.java
+++ /dev/null
@@ -1,33 +0,0 @@
-package com.iemr.mmu.config;
-
-import jakarta.servlet.http.HttpServletRequest;
-import jakarta.servlet.http.HttpServletResponse;
-
-import org.springframework.web.servlet.HandlerInterceptor;
-import org.springframework.web.servlet.ModelAndView;
-
-public class BlockingHttpMethodInterceptor implements HandlerInterceptor {
- @Override
- public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
- String method = request.getMethod();
- if (!("GET".equals(method) || "POST".equals(method))) {
- response.setStatus(HttpServletResponse.SC_METHOD_NOT_ALLOWED);
- return false;
- }
- return true;
-}
-
- @Override
- public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler,
- ModelAndView modelAndView) throws Exception {
- // TODO Auto-generated method stub
-
- }
-
- @Override
- public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex)
- throws Exception {
- // TODO Auto-generated method stub
-
- }
-}
diff --git a/src/main/java/com/iemr/mmu/config/InterceptorConfig.java b/src/main/java/com/iemr/mmu/config/HttpInterceptorConfig.java
similarity index 83%
rename from src/main/java/com/iemr/mmu/config/InterceptorConfig.java
rename to src/main/java/com/iemr/mmu/config/HttpInterceptorConfig.java
index 80ecc4c2..70ca3b70 100644
--- a/src/main/java/com/iemr/mmu/config/InterceptorConfig.java
+++ b/src/main/java/com/iemr/mmu/config/HttpInterceptorConfig.java
@@ -26,17 +26,17 @@
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
-import com.iemr.mmu.utils.http.HTTPRequestInterceptor;
+import com.iemr.mmu.utils.http.HttpInterceptor;
+
@Configuration
-public class InterceptorConfig implements WebMvcConfigurer {
+public class HttpInterceptorConfig implements WebMvcConfigurer {
@Autowired
- HTTPRequestInterceptor requestInterceptor;
+ private HttpInterceptor httpInterceptor;
@Override
public void addInterceptors(InterceptorRegistry registry) {
- registry.addInterceptor(new BlockingHttpMethodInterceptor())
- .addPathPatterns("/**");
+ registry.addInterceptor(httpInterceptor);
}
-}
\ No newline at end of file
+}
diff --git a/src/main/java/com/iemr/mmu/utils/redis/RedisSessionException.java b/src/main/java/com/iemr/mmu/config/RedisConfig.java
similarity index 60%
rename from src/main/java/com/iemr/mmu/utils/redis/RedisSessionException.java
rename to src/main/java/com/iemr/mmu/config/RedisConfig.java
index 9c939566..7e26a959 100644
--- a/src/main/java/com/iemr/mmu/utils/redis/RedisSessionException.java
+++ b/src/main/java/com/iemr/mmu/config/RedisConfig.java
@@ -19,16 +19,22 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see https://www.gnu.org/licenses/.
*/
-package com.iemr.mmu.utils.redis;
+package com.iemr.mmu.config;
-import com.iemr.mmu.utils.exception.IEMRException;
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory;
-public class RedisSessionException extends IEMRException {
- public RedisSessionException(String message, Throwable cause) {
- super(message, cause);
- }
+@Configuration
+public class RedisConfig {
+
+ private @Value("${spring.redis.host}") String redisHost;
+ private @Value("${spring.redis.port}") int redisPort;
- public RedisSessionException(String message) {
- super(message);
+ @Bean
+ LettuceConnectionFactory lettuceConnectionFactory() {
+ return new LettuceConnectionFactory(redisHost, redisPort);
}
+
}
diff --git a/src/main/java/com/iemr/mmu/config/package-info.java b/src/main/java/com/iemr/mmu/config/package-info.java
deleted file mode 100644
index 54c68f02..00000000
--- a/src/main/java/com/iemr/mmu/config/package-info.java
+++ /dev/null
@@ -1,29 +0,0 @@
-/*
-* AMRIT – Accessible Medical Records via Integrated Technology
-* Integrated EHR (Electronic Health Records) Solution
-*
-* Copyright (C) "Piramal Swasthya Management and Research Institute"
-*
-* This file is part of AMRIT.
-*
-* This program is free software: you can redistribute it and/or modify
-* it under the terms of the GNU General Public License as published by
-* the Free Software Foundation, either version 3 of the License, or
-* (at your option) any later version.
-*
-* This program is distributed in the hope that it will be useful,
-* but WITHOUT ANY WARRANTY; without even the implied warranty of
-* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-* GNU General Public License for more details.
-*
-* You should have received a copy of the GNU General Public License
-* along with this program. If not, see https://www.gnu.org/licenses/.
-*/
-/**
- *
- */
-/**
- * @author NE298657
- *
- */
-package com.iemr.mmu.config;
\ No newline at end of file
diff --git a/src/main/java/com/iemr/mmu/utils/AESEncryption/AESEncryptionDecryption.java b/src/main/java/com/iemr/mmu/utils/AESEncryption/AESEncryptionDecryption.java
index 3a39cb19..f206a822 100644
--- a/src/main/java/com/iemr/mmu/utils/AESEncryption/AESEncryptionDecryption.java
+++ b/src/main/java/com/iemr/mmu/utils/AESEncryption/AESEncryptionDecryption.java
@@ -34,7 +34,6 @@
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;
-import com.iemr.mmu.utils.config.ConfigProperties;
/*
*
@@ -47,7 +46,7 @@
public class AESEncryptionDecryption {
- private Logger logger = LoggerFactory.getLogger(ConfigProperties.class);
+ private Logger logger = LoggerFactory.getLogger(AESEncryptionDecryption.class);
private static SecretKeySpec secretKey;
private byte[] key;
final String secret = "amrith$%2022@&*piramal@@swasthya!#";
diff --git a/src/main/java/com/iemr/mmu/utils/CommonMain.java b/src/main/java/com/iemr/mmu/utils/CommonMain.java
index cf730f52..95f390ea 100644
--- a/src/main/java/com/iemr/mmu/utils/CommonMain.java
+++ b/src/main/java/com/iemr/mmu/utils/CommonMain.java
@@ -21,16 +21,31 @@
*/
package com.iemr.mmu.utils;
+import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
+import org.springframework.context.annotation.Bean;
+import org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory;
+import org.springframework.session.data.redis.config.annotation.web.http.RedisHttpSessionConfiguration;
+
+import com.iemr.mmu.utils.redis.RedisStorage;
@EnableAutoConfiguration
public class CommonMain {
- /*
- * @Bean public ConfigProperties configProperties() { return new
- * ConfigProperties(); }
- *
- * @Bean public RedisHttpSessionConfiguration redisSession() { return new
- * RedisHttpSessionConfiguration(); }
- *
- * @Bean public RedisStorage redisStorage() { return new RedisStorage(); }
- */}
+
+ private @Value("${spring.redis.host}") String redisHost;
+ private @Value("${spring.redis.port}") int redisPort;
+
+
+ @Bean
+ public RedisHttpSessionConfiguration redisSession() {
+ return new RedisHttpSessionConfiguration();
+ }
+
+ @Bean public LettuceConnectionFactory connectionFactory() { return new
+ LettuceConnectionFactory(redisHost, redisPort); }
+
+ @Bean
+ public RedisStorage redisStorage() {
+ return new RedisStorage();
+ }
+ }
diff --git a/src/main/java/com/iemr/mmu/utils/IEMRApplBeans.java b/src/main/java/com/iemr/mmu/utils/IEMRApplBeans.java
index 06086222..9bfa21d2 100644
--- a/src/main/java/com/iemr/mmu/utils/IEMRApplBeans.java
+++ b/src/main/java/com/iemr/mmu/utils/IEMRApplBeans.java
@@ -21,31 +21,17 @@
*/
package com.iemr.mmu.utils;
-import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
-import org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.mail.javamail.JavaMailSenderImpl;
-import com.iemr.mmu.utils.config.ConfigProperties;
import com.iemr.mmu.utils.gateway.email.EmailService;
import com.iemr.mmu.utils.gateway.email.GenericEmailServiceImpl;
-import com.iemr.mmu.utils.redis.RedisStorage;
-import com.iemr.mmu.utils.sessionobject.SessionObject;
-import com.iemr.mmu.utils.validator.Validator;
@Configuration
public class IEMRApplBeans {
- private @Value("${spring.redis.host}") String redisHost;
- private @Value("${spring.redis.port}") int redisPort;
-
- @Bean
- public Validator getVaidator() {
- return new Validator();
- }
-
@Bean
public EmailService getEmailService() {
return new GenericEmailServiceImpl();
@@ -56,23 +42,4 @@ public JavaMailSender getJavaMailSender() {
return new JavaMailSenderImpl();
}
- @Bean
- public ConfigProperties configProperties() {
- return new ConfigProperties();
- }
-
- @Bean
- public SessionObject sessionObject() {
- return new SessionObject();
- }
-
- @Bean
- public RedisStorage redisStorage() {
- return new RedisStorage();
- }
-
- @Bean
- public LettuceConnectionFactory connectionFactory() {
- return new LettuceConnectionFactory(redisHost, redisPort);
- }
}
diff --git a/src/main/java/com/iemr/mmu/utils/config/ConfigProperties.java b/src/main/java/com/iemr/mmu/utils/config/ConfigProperties.java
deleted file mode 100644
index da9683c4..00000000
--- a/src/main/java/com/iemr/mmu/utils/config/ConfigProperties.java
+++ /dev/null
@@ -1,182 +0,0 @@
-/*
-* AMRIT – Accessible Medical Records via Integrated Technology
-* Integrated EHR (Electronic Health Records) Solution
-*
-* Copyright (C) "Piramal Swasthya Management and Research Institute"
-*
-* This file is part of AMRIT.
-*
-* This program is free software: you can redistribute it and/or modify
-* it under the terms of the GNU General Public License as published by
-* the Free Software Foundation, either version 3 of the License, or
-* (at your option) any later version.
-*
-* This program is distributed in the hope that it will be useful,
-* but WITHOUT ANY WARRANTY; without even the implied warranty of
-* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-* GNU General Public License for more details.
-*
-* You should have received a copy of the GNU General Public License
-* along with this program. If not, see https://www.gnu.org/licenses/.
-*/
-package com.iemr.mmu.utils.config;
-
-import java.io.IOException;
-import java.io.InputStream;
-import java.util.Base64;
-import java.util.Properties;
-
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.beans.factory.annotation.Value;
-import org.springframework.context.annotation.Configuration;
-import org.springframework.context.annotation.PropertySource;
-import org.springframework.core.env.Environment;
-import org.springframework.stereotype.Component;
-
-@Configuration /*
- * (defaultAutowire = Autowire.BY_TYPE, defaultLazy = Lazy.FALSE
- */
-@PropertySource("classpath:/application.properties")
-// @Component
-@Component
-public class ConfigProperties {
- private static Properties properties;
- private static Logger logger = LoggerFactory.getLogger(ConfigProperties.class);
-
- private static Environment environment;
-
- public ConfigProperties() {
- initalizeProperties();
- }
-
- private static void initalizeProperties() {
- if (properties == null) {
- properties = new Properties();
-
- // FileInputStream fis;
- try {
- // this.getClass().getResourceAsStream(
-
- InputStream fis = ConfigProperties.class.getResourceAsStream("/application.properties");
- properties.load(fis);
- // properties.
- // fis.close();
- } catch (IOException e) {
- logger.error("Loading of config file failed with error " + e.getLocalizedMessage(), e);
- }
- }
- }
-
- @Autowired
- public void setEnvironment(Environment environment) {
- this.environment = environment;
- }
-
- @Value("${iemr.extend.expiry.time:false}")
- private static Boolean extendExpiryTime;
-
- @Value("${iemr.session.expiry.time:100}")
- private static Integer sessionExpiryTime;
-
- @Value("${iemr.redis.url:localhost}")
- private static String redisurl;
-
- @Value("${iemr.redis.port:0000}")
- private static Integer redisport;
-
- public static String getRedisUrl() {
- if (redisurl == null) {
- redisurl = getPropertyByName("iemr.redis.url");
- }
- return redisurl;
- }
-
- public static int getRedisPort() {
- if (redisport == null) {
- redisport = getInteger("iemr.redis.port");
- }
- return redisport;
- }
-
- public static boolean getExtendExpiryTime() {
- if (extendExpiryTime == null) {
- extendExpiryTime = getBoolean("iemr.session.expiry.time");
- }
- return extendExpiryTime;
- }
-
- public static int getSessionExpiryTime() {
- if (sessionExpiryTime == null) {
- sessionExpiryTime = getInteger("iemr.session.expiry.time");
- }
- return sessionExpiryTime;
- }
-
- public static String getPropertyByName(String propertyName) {
- String result = null;
- try {
- if (properties == null) {
- initalizeProperties();
- }
- // result = environment.getProperty(propertyName);
- result = properties.getProperty(propertyName);
- } catch (Exception e) {
- logger.error(propertyName + " retrival failed.", e);
- }
- return result;
- }
-
- public static Boolean getBoolean(String propertyName) {
- Boolean result = false;
- try {
- result = Boolean.parseBoolean(getPropertyByName(propertyName));
- } catch (Exception e) {
- logger.error(propertyName + " retrival failed.", e);
- }
- return result;
- }
-
- public static Integer getInteger(String propertyName) {
- Integer result = 0;
- try {
- result = Integer.parseInt(getPropertyByName(propertyName));
- } catch (NumberFormatException e) {
- logger.error(propertyName + " retrival failed.", e);
- }
- return result;
- }
-
- public static Long getLong(String propertyName) {
- Long result = 0L;
- try {
- result = Long.parseLong(getPropertyByName(propertyName));
- } catch (NumberFormatException e) {
- logger.error(propertyName + " retrival failed.", e);
- }
- return result;
- }
-
- public static Float getFloat(String propertyName) {
- Float result = 0F;
- try {
- result = Float.parseFloat(getPropertyByName(propertyName));
- } catch (NumberFormatException e) {
- logger.error(propertyName + " retrival failed.", e);
- }
- return result;
- }
-
- public static String getPassword(String key) {
- String password = "";
- password = getPropertyByName(key);
-
- if (password != null && password.startsWith("0X10:")) {
- password = new String(Base64.getDecoder().decode(password.split(":")[1]));
- }
- return password;
- }
-
- private static Class configProperties = ConfigProperties.class;
-}
diff --git a/src/main/java/com/iemr/mmu/utils/exception/CustomExceptionResponse.java b/src/main/java/com/iemr/mmu/utils/exception/CustomExceptionResponse.java
new file mode 100644
index 00000000..f836752a
--- /dev/null
+++ b/src/main/java/com/iemr/mmu/utils/exception/CustomExceptionResponse.java
@@ -0,0 +1,231 @@
+package com.iemr.mmu.utils.exception;
+
+import java.util.Calendar;
+import java.util.Date;
+
+import org.json.JSONObject;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.stereotype.Component;
+
+import com.google.gson.GsonBuilder;
+import com.google.gson.JsonArray;
+import com.google.gson.JsonObject;
+import com.google.gson.JsonParser;
+import com.google.gson.LongSerializationPolicy;
+import com.google.gson.annotations.Expose;
+
+@Component
+public class CustomExceptionResponse {
+ @Expose
+ private Object data;
+ private final Logger logger = LoggerFactory.getLogger(this.getClass().getSimpleName());
+ public static final int SUCCESS = 200;
+ public static final int GENERIC_FAILURE = 5000;
+ public static final int OBJECT_FAILURE = 5001;
+ public static final int USERID_FAILURE = 5002;
+ public static final int PASSWORD_FAILURE = 5003;
+ public static final int PREVILAGE_FAILURE = 5004;
+ public static final int CODE_EXCEPTION = 5005;
+ public static final int ENVIRONMENT_EXCEPTION = 5006;
+ public static final int PARSE_EXCEPTION = 5007;
+ public static final int DB_EXCEPTION = 5008;
+ public static final int BAD_REQUEST = 400;
+ public static final int NOT_FOUND = 404;
+
+ public static final String SUCCESS_SC = "SUCCESS";
+ public static final String NOT_FOUND_SC = "NOT_FOUND";
+ public static final String DB_EXCEPTION_SC = "DB_EXCEPTION";
+ public static final String BAD_REQUEST_SC = "BAD_REQUEST";
+ public static final String INTERNAL_SERVER_ERROR_SC = "INTERNAL_SERVER_ERROR";
+
+ public static final String SUCCESS_SC_V = "200";
+ public static final String NOT_FOUND_SC_V = "404";
+ public static final String DB_EXCEPTION_SC_V = "5008";
+ public static final String BAD_REQUEST_SC_V = "400";
+ public static final String INTERNAL_SERVER_ERROR_SC_V = "500";
+
+ @Expose
+ private int statusCode = GENERIC_FAILURE;
+ @Expose
+ private String errorMessage = "Failed with generic error";
+ @Expose
+ private String status = "FAILURE";
+ private static final String RESPONSE = "{\"response\":\"$$STRING\"}";
+ private static final String RESPONSE_VALUE = "$$STRING";
+
+ public void setResponse(String message) {
+ JsonArray ja = null;
+ try {
+ Object obj = new JsonParser().parse(message);
+ if (obj instanceof JsonArray) {
+ ja = (JsonArray) obj;
+ this.data = ja;
+ } else if (obj instanceof JsonObject) {
+ this.data = obj;
+ } else {
+ this.data = new JsonParser().parse(RESPONSE.replace(RESPONSE_VALUE, message));
+ // this.data = message;
+ }
+ } catch (Exception exe) {
+ this.data = message;
+ this.data = new JsonParser().parse(RESPONSE.replace(RESPONSE_VALUE, message));
+ }
+ statusCode = SUCCESS;
+ errorMessage = "Success";
+ status = "Success";
+
+ }
+
+ public void setError(Throwable thrown) {
+ Date currDate = Calendar.getInstance().getTime();
+ logger.info("error happened due to " + thrown.getClass().getSimpleName() + " at " + currDate.toString());
+
+ switch (thrown.getCause().getClass().getSimpleName()) {
+ case "IEMRException":
+ this.statusCode = USERID_FAILURE;
+ status = "User login failed";
+ errorMessage = thrown.getMessage();
+ break;
+ case "JSONException":
+ this.statusCode = OBJECT_FAILURE;
+ status = "Invalid object conversion";
+ errorMessage = "Invalid object conversion";
+ break;
+
+ case "SQLException":
+ this.statusCode = DB_EXCEPTION;
+ status = DB_EXCEPTION_SC;
+ errorMessage = thrown.getMessage();
+ break;
+ case "SQLGrammarException":
+ this.statusCode = DB_EXCEPTION;
+ status = DB_EXCEPTION_SC;
+ errorMessage = thrown.getMessage();
+ break;
+ case "DataException":
+ this.statusCode = DB_EXCEPTION;
+ status = DB_EXCEPTION_SC;
+ errorMessage = thrown.getMessage();
+ break;
+ case "ConstraintViolationException":
+ this.statusCode = DB_EXCEPTION;
+ status = DB_EXCEPTION_SC;
+ errorMessage = thrown.getMessage();
+ break;
+ case "GenericJDBCException":
+ this.statusCode = DB_EXCEPTION;
+ status = DB_EXCEPTION_SC;
+ errorMessage = thrown.getMessage();
+ break;
+ case "JDBCConnectionException":
+ this.statusCode = DB_EXCEPTION;
+ status = DB_EXCEPTION_SC;
+ errorMessage = thrown.getMessage();
+ break;
+ case "LockAcquisitionException":
+ this.statusCode = DB_EXCEPTION;
+ status = DB_EXCEPTION_SC;
+ errorMessage = thrown.getMessage();
+ break;
+ case "InvalidDataAccessResourceUsageException":
+ this.statusCode = DB_EXCEPTION;
+ status = DB_EXCEPTION_SC;
+ errorMessage = thrown.getMessage();
+ break;
+
+ case "ParseException":
+ case "NullPointerException":
+
+ case "ArrayIndexOutOfBoundsException":
+
+ case "IOException":
+ case "ConnectException":
+ case "ConnectIOException":
+ this.statusCode = ENVIRONMENT_EXCEPTION;
+ status = "Failed with connection issues at " + currDate.toString() + "Please try after some time. "
+ + "If error is still seen, contact your administrator.";
+ errorMessage = thrown.getMessage();
+ break;
+ case "JDBCException":
+ this.statusCode = DB_EXCEPTION;
+ status = DB_EXCEPTION_SC;
+ errorMessage = thrown.getMessage();
+ break;
+ default:
+ this.statusCode = GENERIC_FAILURE;
+ status = "Failed with " + thrown.getMessage() + " at " + currDate.toString()
+ + ".Please try after some time. If error is still seen, contact your administrator.";
+ errorMessage = thrown.getMessage();
+ break;
+ }
+ logger.error("Failure happend with " + thrown.getMessage() + "at " + currDate.toString(), thrown);
+ }
+
+ public void setError(int errorCode, String message, String status) {
+ this.errorMessage = message;
+ this.status = status;
+ this.statusCode = errorCode;
+ }
+
+ public void setError(int errorCode, String message) {
+ setError(errorCode, message, message);
+ }
+
+ public boolean isSuccess() {
+ return this.statusCode == SUCCESS;
+ }
+
+ /**
+ * @return the data
+ */
+ public String getData() {
+ JSONObject obj = new JSONObject(toString());
+ if (obj.has("data")) {
+ return obj.get("data").toString();
+ } else if (obj.has("response")) {
+ return obj.getJSONObject("response").get("data").toString();
+ } else {
+ return null;
+ }
+ }
+
+ /**
+ * @return the statusCode
+ */
+ public int getStatusCode() {
+ return statusCode;
+ }
+
+ /**
+ * @return the errorMessage
+ */
+ public String getErrorMessage() {
+ return errorMessage;
+ }
+
+ /**
+ * @return the status
+ */
+ public String getStatus() {
+ return status;
+ }
+
+ @Override
+ public String toString() {
+ GsonBuilder builder = new GsonBuilder();
+ builder.excludeFieldsWithoutExposeAnnotation();
+ builder.setLongSerializationPolicy(LongSerializationPolicy.STRING);
+ String output = builder.create().toJson(this);
+ return output;
+
+ }
+
+ public String toStringWithSerialization() {
+ GsonBuilder builder = new GsonBuilder();
+ builder.excludeFieldsWithoutExposeAnnotation();
+ builder.serializeNulls();
+ return builder.create().toJson(this);
+ }
+
+}
diff --git a/src/main/java/com/iemr/mmu/utils/http/HTTPRequestInterceptor.java b/src/main/java/com/iemr/mmu/utils/http/HttpInterceptor.java
similarity index 90%
rename from src/main/java/com/iemr/mmu/utils/http/HTTPRequestInterceptor.java
rename to src/main/java/com/iemr/mmu/utils/http/HttpInterceptor.java
index c8331d78..d1e4affb 100644
--- a/src/main/java/com/iemr/mmu/utils/http/HTTPRequestInterceptor.java
+++ b/src/main/java/com/iemr/mmu/utils/http/HttpInterceptor.java
@@ -21,8 +21,6 @@
*/
package com.iemr.mmu.utils.http;
-import jakarta.servlet.http.HttpServletRequest;
-import jakarta.servlet.http.HttpServletResponse;
import javax.ws.rs.core.MediaType;
import org.slf4j.Logger;
@@ -32,13 +30,14 @@
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;
+import com.iemr.mmu.utils.exception.CustomExceptionResponse;
import com.iemr.mmu.utils.redis.RedisStorage;
-import com.iemr.mmu.utils.response.OutputResponse;
-import com.iemr.mmu.utils.sessionobject.SessionObject;
-import com.iemr.mmu.utils.validator.Validator;
+
+import jakarta.servlet.http.HttpServletRequest;
+import jakarta.servlet.http.HttpServletResponse;
@Component
-public class HTTPRequestInterceptor implements HandlerInterceptor {
+public class HttpInterceptor implements HandlerInterceptor {
Logger logger = LoggerFactory.getLogger(this.getClass().getName());
@Autowired
private RedisStorage redisStorage;
@@ -88,11 +87,10 @@ public boolean preHandle(HttpServletRequest request, HttpServletResponse respons
} catch (Exception e) {
logger.error(e.getLocalizedMessage());
- /*
- * CustomExceptionResponse output = new CustomExceptionResponse();
- * output.setError(5002, e.getLocalizedMessage());
- * response.getOutputStream().print(output.toString());
- */
+ CustomExceptionResponse output = new CustomExceptionResponse();
+ output.setError(5002, e.getLocalizedMessage());
+ response.getOutputStream().print(output.toString());
+
response.setContentType(MediaType.APPLICATION_JSON);
// response.setContentLength(e.getLocalizedMessage().length());
@@ -128,4 +126,5 @@ public void afterCompletion(HttpServletRequest request, HttpServletResponse resp
logger.info("http interceptor - after completion");
}
-}
\ No newline at end of file
+
+}
diff --git a/src/main/java/com/iemr/mmu/utils/redis/RedisConnection.java b/src/main/java/com/iemr/mmu/utils/redis/RedisConnection.java
deleted file mode 100644
index 98d93915..00000000
--- a/src/main/java/com/iemr/mmu/utils/redis/RedisConnection.java
+++ /dev/null
@@ -1,80 +0,0 @@
-/*
-* AMRIT – Accessible Medical Records via Integrated Technology
-* Integrated EHR (Electronic Health Records) Solution
-*
-* Copyright (C) "Piramal Swasthya Management and Research Institute"
-*
-* This file is part of AMRIT.
-*
-* This program is free software: you can redistribute it and/or modify
-* it under the terms of the GNU General Public License as published by
-* the Free Software Foundation, either version 3 of the License, or
-* (at your option) any later version.
-*
-* This program is distributed in the hope that it will be useful,
-* but WITHOUT ANY WARRANTY; without even the implied warranty of
-* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-* GNU General Public License for more details.
-*
-* You should have received a copy of the GNU General Public License
-* along with this program. If not, see https://www.gnu.org/licenses/.
-*/
-package com.iemr.mmu.utils.redis;
-
-public class RedisConnection {
- // // static ConfigProperties configProperties;
- // // @Autowired(required = true)
- // // @Required
- // // public void setConfigProperties(ConfigProperties configProperties)
- // // {
- // // if (configProperties == null) {
- // // configProperties = new ConfigProperties();
- // // }
- // // this.configProperties = configProperties;
- // // }
- // static JedisPool jedisPool = null;
- // static int paasConnectionCounter = 0;
- // static int redisPort;// = new ConfigProperties().getRedisPort();
- // static String redisURL;// = new ConfigProperties().getRedisUrl();
- //
- // private void intializeRedisPool() throws NumberFormatException {
- // // if (configProperties == null) {
- // // configProperties = new ConfigProperties();
- // // }
- // redisPort = ConfigProperties.getRedisPort();
- // redisURL = ConfigProperties.getRedisUrl();
- // JedisPoolConfig jedisPoolConfig = new JedisPoolConfig();
- // jedisPoolConfig.setMaxIdle(1);
- // jedisPoolConfig.setMinIdle(1);
- // jedisPoolConfig.setMaxTotal(500);
- //
- // // jedisPool = new JedisPool(jedisPoolConfig, "localhost", 6379);
- // jedisPool = new JedisPool(jedisPoolConfig, redisURL, redisPort);
- // }
- //
- // public Jedis getRedisConnection() throws RedisSessionException {
- // Jedis jedis = null;
- // try {
- // if (jedisPool == null) {
- // intializeRedisPool();
- // }
- // jedis = jedisPool.getResource();
- // } catch (JedisConnectionException | JedisDataException e) {
- // throw new RedisSessionException("Unable to connect to Redis server", e);
- // } catch (Exception e) {
- // if ((e instanceof SocketException)) {
- // throw new RedisSessionException("Not a proper config format", e);
- // }
- // throw new RedisSessionException("Redis exception occured on fetch", e);
- // }
- // return jedis;
- // }
- //
- // public void closeRedisConnection(Jedis jedis) throws
- // JedisConnectionException, JedisDataException {
- // if ((jedisPool != null) && (jedis != null)) {
- // jedisPool.returnResource(jedis);
- // jedis = null;
- // }
- // }
-}
diff --git a/src/main/java/com/iemr/mmu/utils/redis/RedisStorage.java b/src/main/java/com/iemr/mmu/utils/redis/RedisStorage.java
index d3722942..15147c3b 100644
--- a/src/main/java/com/iemr/mmu/utils/redis/RedisStorage.java
+++ b/src/main/java/com/iemr/mmu/utils/redis/RedisStorage.java
@@ -37,6 +37,7 @@
@Component
public class RedisStorage {
+
@Autowired
private LettuceConnectionFactory connection;
@@ -93,5 +94,4 @@ public void updateConcurrentSessionObject(String value) {
}
}
-
}
diff --git a/src/main/java/com/iemr/mmu/utils/sessionobject/SessionObject.java b/src/main/java/com/iemr/mmu/utils/sessionobject/SessionObject.java
deleted file mode 100644
index bbbbf35e..00000000
--- a/src/main/java/com/iemr/mmu/utils/sessionobject/SessionObject.java
+++ /dev/null
@@ -1,103 +0,0 @@
-/*
-* AMRIT – Accessible Medical Records via Integrated Technology
-* Integrated EHR (Electronic Health Records) Solution
-*
-* Copyright (C) "Piramal Swasthya Management and Research Institute"
-*
-* This file is part of AMRIT.
-*
-* This program is free software: you can redistribute it and/or modify
-* it under the terms of the GNU General Public License as published by
-* the Free Software Foundation, either version 3 of the License, or
-* (at your option) any later version.
-*
-* This program is distributed in the hope that it will be useful,
-* but WITHOUT ANY WARRANTY; without even the implied warranty of
-* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-* GNU General Public License for more details.
-*
-* You should have received a copy of the GNU General Public License
-* along with this program. If not, see https://www.gnu.org/licenses/.
-*/
-package com.iemr.mmu.utils.sessionobject;
-
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.stereotype.Component;
-
-import com.google.gson.JsonElement;
-import com.google.gson.JsonObject;
-import com.google.gson.JsonParser;
-import com.iemr.mmu.utils.config.ConfigProperties;
-import com.iemr.mmu.utils.redis.RedisSessionException;
-import com.iemr.mmu.utils.redis.RedisStorage;
-
-@Component
-public class SessionObject {
- /*
- *
- * // // // @Autowired(required = true) // // @Required // public void
- * setConfigProperties(ConfigProperties configProperties) // { // // if
- * (configProperties == null) // // { // // configProperties = new
- * ConfigProperties(); // // } // this.configProperties = configProperties; // }
- *
- * private RedisStorage objectStore;
- *
- * @Autowired(required = true) public void setObjectStore(RedisStorage
- * objectStore) { // if (objectStore == null) // { // objectStore = new
- * RedisStorage(); // } this.objectStore = objectStore; }
- *
- * public SessionObject() { // configProperties = new ConfigProperties(); //
- * objectStore = new RedisStorage(); // if (objectStore == null) // { //
- * objectStore = new RedisStorage(); // } extendExpirationTime =
- * ConfigProperties.getExtendExpiryTime(); sessionExpiryTime =
- * ConfigProperties.getSessionExpiryTime(); }
- *
- * private boolean extendExpirationTime;// = //
- * configProperties.getExtendExpiryTime(); private int sessionExpiryTime;// =
- * configProperties.getSessionExpiryTime();
- *
- * public String getSessionObject(String key) throws RedisSessionException {
- * Boolean extendExpirationTime = ConfigProperties.getExtendExpiryTime();
- * Integer sessionExpiryTime = ConfigProperties.getSessionExpiryTime(); //
- * RedisStorage objectStore = new RedisStorage() return
- * objectStore.getObject(key, extendExpirationTime, sessionExpiryTime); }
- *
- * private void updateConcurrentSessionObject(String key, String value, Boolean
- * extendExpirationTime, Integer sessionExpiryTime) { try { JsonObject jsnOBJ =
- * new JsonObject(); JsonParser jsnParser = new JsonParser(); JsonElement
- * jsnElmnt = jsnParser.parse(value); jsnOBJ = jsnElmnt.getAsJsonObject(); if
- * (jsnOBJ.has("userName") && jsnOBJ.get("userName") != null) {
- * objectStore.updateObject(jsnOBJ.get("userName").getAsString().trim().
- * toLowerCase(), key, extendExpirationTime, sessionExpiryTime); } } catch
- * (Exception e) { } } public String setSessionObject(String key, String value)
- * throws RedisSessionException { Integer sessionExpiryTime =
- * ConfigProperties.getSessionExpiryTime(); return objectStore.setObject(key,
- * value, sessionExpiryTime); }
- *
- * public String updateSessionObject(String key, String value) throws
- * RedisSessionException { Boolean extendExpirationTime =
- * ConfigProperties.getExtendExpiryTime(); Integer sessionExpiryTime =
- * ConfigProperties.getSessionExpiryTime(); // RedisStorage objectStore = new
- * RedisStorage(); updateConcurrentSessionObject(key, value,
- * extendExpirationTime, sessionExpiryTime); return
- * objectStore.updateObject(key, value, extendExpirationTime,
- * sessionExpiryTime); }
- *
- * public void deleteSessionObject(String key) throws RedisSessionException { //
- * RedisStorage objectStore = new RedisStorage();
- * System.out.println(objectStore.deleteObject(key)); }
- *
- * // public static void test(String[] args) // { // SessionObject obj = new
- * SessionObject(); // JSONObject testdata = new JSONObject(); // try // { //
- * System.out.println("Set Object " + obj.getSessionObject("test1234")); //
- * System.out.println("Set Object " + obj.setSessionObject("test1234", //
- * testdata.toString())); // System.out.println("Set Object " +
- * obj.getSessionObject("test1234")); // testdata.put("userName", "test"); // //
- * testdata.put("validity", obj.sessionExpiryTime); //
- * System.out.println("Set Object " + obj.updateSessionObject("test1234", //
- * testdata.toString())); // System.out.println("Set Object " +
- * obj.getSessionObject("test1234")); // obj.deleteSessionObject("test1234"); //
- * System.out.println("Set Object " + obj.getSessionObject("test1234")); // }
- * catch (RedisSessionException | JSONException e) // { // e.printStackTrace();
- * // } // }
- */}
diff --git a/src/main/java/com/iemr/mmu/utils/validator/Validator.java b/src/main/java/com/iemr/mmu/utils/validator/Validator.java
deleted file mode 100644
index 3892eafa..00000000
--- a/src/main/java/com/iemr/mmu/utils/validator/Validator.java
+++ /dev/null
@@ -1,80 +0,0 @@
-/*
-* AMRIT – Accessible Medical Records via Integrated Technology
-* Integrated EHR (Electronic Health Records) Solution
-*
-* Copyright (C) "Piramal Swasthya Management and Research Institute"
-*
-* This file is part of AMRIT.
-*
-* This program is free software: you can redistribute it and/or modify
-* it under the terms of the GNU General Public License as published by
-* the Free Software Foundation, either version 3 of the License, or
-* (at your option) any later version.
-*
-* This program is distributed in the hope that it will be useful,
-* but WITHOUT ANY WARRANTY; without even the implied warranty of
-* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-* GNU General Public License for more details.
-*
-* You should have received a copy of the GNU General Public License
-* along with this program. If not, see https://www.gnu.org/licenses/.
-*/
-package com.iemr.mmu.utils.validator;
-
-import org.json.JSONException;
-import org.json.JSONObject;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.stereotype.Service;
-
-import com.iemr.mmu.utils.exception.IEMRException;
-import com.iemr.mmu.utils.redis.RedisSessionException;
-import com.iemr.mmu.utils.sessionobject.SessionObject;
-
-@Service
-public class Validator {
- /*
- *
- * private SessionObject session; private static Boolean enableIPValidation =
- * false;
- *
- * @Autowired(required = true) public void setSessionObject(SessionObject
- * sessionObject) { this.session = sessionObject; }
- *
- * // private static void setSessionObject() { // if (session == null) { //
- * session = new SessionObject(); // } // }
- *
- * private Logger logger = LoggerFactory.getLogger(Validator.class);
- *
- * public JSONObject updateCacheObj(JSONObject responseObj, String key, String
- * ipKey) { try { Boolean loggedFromDifferentIP = false; String loginKey = key;
- * String status = "login failed"; try { responseObj.put("sessionStatus",
- * "session creation failed"); String sessionData =
- * session.getSessionObject(key); if (sessionData != null &&
- * sessionData.trim().length() > 0) { JSONObject sessionObj = new
- * JSONObject(sessionData); if
- * (!sessionObj.getString("loginIPAddress").equals(responseObj.getString(
- * "loginIPAddress"))) { loggedFromDifferentIP = true; status =
- * "login success, but user logged in from " +
- * sessionObj.getString("loginIPAddress"); } } } catch (RedisSessionException e)
- * { logger.error("Session validation failed with exception", e); } if
- * (!loggedFromDifferentIP) { status = "login success";
- * session.setSessionObject(key, responseObj.toString()); } else { responseObj =
- * new JSONObject(); } responseObj.put("key", loginKey);
- * responseObj.put("sessionStatus", status); } catch (RedisSessionException |
- * JSONException e) { logger.error("Session validation failed with exception",
- * e); } return responseObj; }
- *
- * public String getSessionObject(String key) throws RedisSessionException {
- * return session.getSessionObject(key); }
- *
- * public void checkKeyExists(String loginKey, String ipAddress) throws
- * IEMRException { try { String sessionString =
- * session.getSessionObject(loginKey); JSONObject sessionObj = new
- * JSONObject(sessionString); if (enableIPValidation) { if
- * (!sessionObj.getString("loginIPAddress").equals(ipAddress)) { logger.error(
- * "Logged in IP : " + sessionObj.getString("loginIPAddress") +
- * "\tRequest IP : " + ipAddress); throw new Exception(); } } } catch (Exception
- * e) { throw new IEMRException("Invalid login key or session is expired"); } }
- */}