Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MOSIP-31617: Sonar Fixes #1537

Open
wants to merge 6 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public class RefreshController {

@GetMapping("/refresh")
public Map<String, String> refreshContext(@RequestParam("servicename") String serviceName) {
logger.info("refreshContext invoked with serviceName : {}", serviceName);
logger.info("refreshContext invoked with serviceName : {}", serviceName.replaceAll("[\n\r\t]", "_"));
vishwa-vyom marked this conversation as resolved.
Show resolved Hide resolved
Map<String, String> result = new HashMap<>();

if(Objects.nonNull(discoveryClient)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,22 +18,19 @@
import org.springframework.context.annotation.ComponentScan.Filter;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.FilterType;
import org.springframework.context.annotation.Import;
import org.springframework.context.annotation.PropertySource;
import org.springframework.core.env.Environment;
import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
import org.springframework.orm.jpa.JpaTransactionManager;
import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean;
import org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfiguration;
import org.springframework.transaction.PlatformTransactionManager;
import org.springframework.transaction.annotation.EnableTransactionManagement;

import com.zaxxer.hikari.HikariConfig;
import com.zaxxer.hikari.HikariDataSource;

import io.mosip.kernel.vidgenerator.constant.HibernatePersistenceConstant;
import io.mosip.kernel.idgenerator.constant.HibernatePersistenceConstant;
import jakarta.persistence.EntityManagerFactory;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;

import io.mosip.kernel.uingenerator.constant.HibernatePersistenceConstant;
import io.mosip.kernel.uingenerator.constant.UINHealthConstants;
import io.mosip.kernel.idgenerator.constant.HibernatePersistenceConstant;
import io.mosip.kernel.idgenerator.constant.HealthConstants;
import io.mosip.kernel.uingenerator.constant.UinGeneratorConstant;
import io.netty.handler.codec.http.HttpResponse;
import io.vertx.core.AsyncResult;
Expand Down Expand Up @@ -102,7 +102,7 @@ public void databaseHealthChecker(Promise<Status> future) {
try {
Class.forName(driver);
} catch (ClassNotFoundException exception) {
final JsonObject result = resultBuilder.create().add(UINHealthConstants.ERROR, exception.getMessage())
final JsonObject result = resultBuilder.create().add(HealthConstants.ERROR, exception.getMessage())
.build();
future.complete(Status.KO(result));
}
Expand All @@ -113,15 +113,15 @@ public void databaseHealthChecker(Promise<Status> future) {

if (rs.next()) {
final JsonObject result = resultBuilder.create()
.add(UINHealthConstants.DATABASE, conn.getMetaData().getDatabaseProductName())
.add(UINHealthConstants.HELLO, JdbcUtils.getResultSetValue(rs, 1)).build();
.add(HealthConstants.DATABASE, conn.getMetaData().getDatabaseProductName())
.add(HealthConstants.HELLO, JdbcUtils.getResultSetValue(rs, 1)).build();
future.complete(Status.OK(result));

}
}
}
} catch (SQLException exception) {
final JsonObject result = resultBuilder.create().add(UINHealthConstants.ERROR, exception.getMessage())
final JsonObject result = resultBuilder.create().add(HealthConstants.ERROR, exception.getMessage())
.build();
future.complete(Status.KO(result));
}
Expand All @@ -137,12 +137,12 @@ public void dispSpaceHealthChecker(Promise<Status> future) {
final long diskFreeInBytes = this.currentWorkingDirPath.getUsableSpace();
if (diskFreeInBytes >= THRESHOLD) {
final JsonObject result = resultBuilder.create()
.add(UINHealthConstants.TOTAL, this.currentWorkingDirPath.getTotalSpace())
.add(UINHealthConstants.FREE, diskFreeInBytes).add(UINHealthConstants.THRESHOLD, THRESHOLD).build();
.add(HealthConstants.TOTAL, this.currentWorkingDirPath.getTotalSpace())
.add(HealthConstants.FREE, diskFreeInBytes).add(HealthConstants.THRESHOLD, THRESHOLD).build();
future.complete(Status.OK(result));
} else {
final JsonObject result = resultBuilder.create().add(UINHealthConstants.ERROR,
String.format(UINHealthConstants.THRESHOLD_ERROR, diskFreeInBytes, THRESHOLD)).build();
final JsonObject result = resultBuilder.create().add(HealthConstants.ERROR,
String.format(HealthConstants.THRESHOLD_ERROR, diskFreeInBytes, THRESHOLD)).build();
future.complete(Status.KO(result));
}

Expand All @@ -156,11 +156,11 @@ public void dispSpaceHealthChecker(Promise<Status> future) {
*/
public void verticleHealthHandler(Promise<Status> future, Vertx vertx) {

vertx.eventBus().send(UinGeneratorConstant.UIN_GENERATOR_ADDRESS, UINHealthConstants.PING, response -> {
vertx.eventBus().send(UinGeneratorConstant.UIN_GENERATOR_ADDRESS, HealthConstants.PING, response -> {

if (response.succeeded()) {
final JsonObject result = resultBuilder.create()
.add(UINHealthConstants.RESPONSE, response.result().body()).build();
.add(HealthConstants.RESPONSE, response.result().body()).build();
future.complete(Status.OK(result));
} else {
future.complete(Status.KO());
Expand Down Expand Up @@ -246,9 +246,9 @@ private void createResponse(JsonObject json, HttpServerResponse response) {
status = 500;
}

json.put(UINHealthConstants.DETAILS, new JsonObject());
json.put(HealthConstants.DETAILS, new JsonObject());

JsonArray checks = json.getJsonArray(UINHealthConstants.CHECKS);
JsonArray checks = json.getJsonArray(HealthConstants.CHECKS);

if (status == 200 && checks.isEmpty()) {
// Special case, no procedure installed.
Expand All @@ -270,24 +270,24 @@ private void createResponse(JsonObject json, HttpServerResponse response) {
private void createResponse(JsonObject json, JsonArray checks) {
for (int i = 0; i < checks.size(); i++) {
JsonObject jsonobject = checks.getJsonObject(i);
String id = jsonobject.getString(UINHealthConstants.ID);
String id = jsonobject.getString(HealthConstants.ID);
BaseHealthCheckModel healthCheckModel = new BaseHealthCheckModel();
healthCheckModel.setStatus(jsonobject.getString(UINHealthConstants.STATUS));
healthCheckModel.setStatus(jsonobject.getString(HealthConstants.STATUS));
JsonObject result = null;
try {
if (jsonobject.containsKey(UINHealthConstants.DATA)) {
healthCheckModel.setDetails(jsonobject.getJsonObject(UINHealthConstants.DATA).getMap());
if (jsonobject.containsKey(HealthConstants.DATA)) {
healthCheckModel.setDetails(jsonobject.getJsonObject(HealthConstants.DATA).getMap());
result = new JsonObject(objectMapper.writeValueAsString(healthCheckModel));

} else {
result = new JsonObject(objectMapper.writeValueAsString(healthCheckModel));
result.remove(UINHealthConstants.DETAILS);
result.remove(HealthConstants.DETAILS);
}
} catch (JsonProcessingException e) {
LOGGER.error(e.getMessage());
}

json.getJsonObject(UINHealthConstants.DETAILS).put(id, result);
json.getJsonObject(HealthConstants.DETAILS).put(id, result);

}
}
Expand All @@ -305,12 +305,12 @@ public synchronized HealthCheckHandler unregister(String name) {
* @return True if has Error;else False
*/
private boolean hasErrors(JsonObject json) {
JsonObject data = json.getJsonObject(UINHealthConstants.DATA);
JsonObject data = json.getJsonObject(HealthConstants.DATA);
if (data != null && data.getBoolean("procedure-execution-failure", false)) {
return true;
}

JsonArray checks = json.getJsonArray(UINHealthConstants.CHECKS);
JsonArray checks = json.getJsonArray(HealthConstants.CHECKS);
if (checks != null) {
for (int i = 0; i < checks.size(); i++) {
JsonObject check = checks.getJsonObject(i);
Expand All @@ -330,9 +330,9 @@ private boolean hasErrors(JsonObject json) {
* @return Encoded Json String
*/
private String encode(JsonObject json) {
final String outcome = json.getString(UINHealthConstants.OUTCOME);
json.remove(UINHealthConstants.OUTCOME);
json.put(UINHealthConstants.STATUS, outcome);
final String outcome = json.getString(HealthConstants.OUTCOME);
json.remove(HealthConstants.OUTCOME);
json.put(HealthConstants.STATUS, outcome);
return json.encode();
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package io.mosip.kernel.uingenerator.constant;
package io.mosip.kernel.idgenerator.constant;

public class UINHealthConstants {
public class HealthConstants {
/**
vishwa-vyom marked this conversation as resolved.
Show resolved Hide resolved
* The string field ERROR
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
*
*/
package io.mosip.kernel.uingenerator.constant;
package io.mosip.kernel.idgenerator.constant;

/**
* @author Dharmesh Khandelwal
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

import org.springframework.context.ApplicationContext;

import io.mosip.kernel.uingenerator.constant.UINHealthConstants;
import io.mosip.kernel.idgenerator.constant.HealthConstants;
import io.mosip.kernel.uingenerator.constant.UinGeneratorConstant;
import io.mosip.kernel.uingenerator.generator.UinProcesser;
import io.vertx.core.AbstractVerticle;
Expand Down Expand Up @@ -68,7 +68,7 @@ public void start() {
}else {
LOGGER.info("Generated and persisted uins lock is true.");
}
receivedMessage.reply(UINHealthConstants.ACTIVE);
receivedMessage.reply(HealthConstants.ACTIVE);
});
}
}

This file was deleted.

Loading
Loading