FINERACT-2036: Fix code quality
This commit is contained in:
committed by
Aleksandar Vidakovic
parent
314929e692
commit
478fb55b0f
@@ -73,8 +73,8 @@ class EmailService {
|
|||||||
if(params.bcc) {
|
if(params.bcc) {
|
||||||
msg.setRecipients(Message.RecipientType.BCC, InternetAddress.parse(params.bcc))
|
msg.setRecipients(Message.RecipientType.BCC, InternetAddress.parse(params.bcc))
|
||||||
}
|
}
|
||||||
msg.setSubject(params.subject)
|
msg.setSubject(params.subject, "UTF-8")
|
||||||
msg.setText(params.message);
|
msg.setText(params.message, "UTF-8");
|
||||||
|
|
||||||
Transport.send(msg);
|
Transport.send(msg);
|
||||||
|
|
||||||
|
|||||||
@@ -27,6 +27,8 @@ import org.apache.fineract.gradle.FineractPluginExtension
|
|||||||
import org.slf4j.Logger
|
import org.slf4j.Logger
|
||||||
import org.slf4j.LoggerFactory
|
import org.slf4j.LoggerFactory
|
||||||
|
|
||||||
|
import java.nio.charset.Charset
|
||||||
|
|
||||||
class TemplateService {
|
class TemplateService {
|
||||||
private static final Logger log = LoggerFactory.getLogger(TemplateService.class)
|
private static final Logger log = LoggerFactory.getLogger(TemplateService.class)
|
||||||
|
|
||||||
@@ -35,7 +37,7 @@ class TemplateService {
|
|||||||
TemplateService(FineractPluginExtension.FineractPluginConfigTemplate config) {
|
TemplateService(FineractPluginExtension.FineractPluginConfigTemplate config) {
|
||||||
def dir = new File(config.templateDir);
|
def dir = new File(config.templateDir);
|
||||||
|
|
||||||
this.config = new Configuration(Configuration.VERSION_2_3_31);
|
this.config = new Configuration(Configuration.VERSION_2_3_32);
|
||||||
this.config.setDirectoryForTemplateLoading(dir)
|
this.config.setDirectoryForTemplateLoading(dir)
|
||||||
this.config.setDefaultEncoding("UTF-8");
|
this.config.setDefaultEncoding("UTF-8");
|
||||||
this.config.setLogTemplateExceptions(false);
|
this.config.setLogTemplateExceptions(false);
|
||||||
@@ -58,7 +60,7 @@ class TemplateService {
|
|||||||
Template template = null;
|
Template template = null;
|
||||||
|
|
||||||
if(params.templateFile) {
|
if(params.templateFile) {
|
||||||
template = new Template("template", new FileReader(new File(params.templateFile)), this.config)
|
template = new Template("template", new FileReader(new File(params.templateFile), Charset.forName("UTF-8")), this.config)
|
||||||
}
|
}
|
||||||
if(params.template) {
|
if(params.template) {
|
||||||
template = new Template("template", new StringReader(params.template), this.config)
|
template = new Template("template", new StringReader(params.template), this.config)
|
||||||
@@ -69,7 +71,7 @@ class TemplateService {
|
|||||||
def output = new File(params.outputFile)
|
def output = new File(params.outputFile)
|
||||||
output.createNewFile()
|
output.createNewFile()
|
||||||
|
|
||||||
template.process(data, new FileWriter(output, false))
|
template.process(data, new FileWriter(output, Charset.forName("UTF-8"), false))
|
||||||
} else {
|
} else {
|
||||||
def output = new StringWriter()
|
def output = new StringWriter()
|
||||||
|
|
||||||
|
|||||||
+11
-11
@@ -219,7 +219,7 @@ public class ReadWriteNonCoreDataServiceImpl implements ReadWriteNonCoreDataServ
|
|||||||
Object columnValue = SearchUtil.parseJdbcColumnValue(column, columnValueString, null, null, null, false, sqlGenerator);
|
Object columnValue = SearchUtil.parseJdbcColumnValue(column, columnValueString, null, null, null, false, sqlGenerator);
|
||||||
String sql = sqlGenerator.buildSelect(selectColumns, null, false) + " " + sqlGenerator.buildFrom(datatable, null, false) + " WHERE "
|
String sql = sqlGenerator.buildSelect(selectColumns, null, false) + " " + sqlGenerator.buildFrom(datatable, null, false) + " WHERE "
|
||||||
+ EQ.formatPlaceholder(sqlGenerator, column.getColumnName(), 1, null);
|
+ EQ.formatPlaceholder(sqlGenerator, column.getColumnName(), 1, null);
|
||||||
SqlRowSet rowSet = jdbcTemplate.queryForRowSet(sql, columnValue);
|
SqlRowSet rowSet = jdbcTemplate.queryForRowSet(sql, columnValue); // NOSONAR
|
||||||
|
|
||||||
List<JsonObject> results = new ArrayList<>();
|
List<JsonObject> results = new ArrayList<>();
|
||||||
while (rowSet.next()) {
|
while (rowSet.next()) {
|
||||||
@@ -279,7 +279,7 @@ public class ReadWriteNonCoreDataServiceImpl implements ReadWriteNonCoreDataServ
|
|||||||
|
|
||||||
// Execute the count Query
|
// Execute the count Query
|
||||||
String countQuery = "SELECT COUNT(*)" + from + where;
|
String countQuery = "SELECT COUNT(*)" + from + where;
|
||||||
Integer totalElements = jdbcTemplate.queryForObject(countQuery, Integer.class, args);
|
Integer totalElements = jdbcTemplate.queryForObject(countQuery, Integer.class, args); // NOSONAR
|
||||||
if (totalElements == null || totalElements == 0) {
|
if (totalElements == null || totalElements == 0) {
|
||||||
return PageableExecutionUtils.getPage(results, pageable, () -> 0);
|
return PageableExecutionUtils.getPage(results, pageable, () -> 0);
|
||||||
}
|
}
|
||||||
@@ -1012,7 +1012,7 @@ public class ReadWriteNonCoreDataServiceImpl implements ReadWriteNonCoreDataServ
|
|||||||
String findFKSql = "SELECT count(*) FROM information_schema.TABLE_CONSTRAINTS i" + " WHERE i.CONSTRAINT_TYPE = 'FOREIGN KEY' AND "
|
String findFKSql = "SELECT count(*) FROM information_schema.TABLE_CONSTRAINTS i" + " WHERE i.CONSTRAINT_TYPE = 'FOREIGN KEY' AND "
|
||||||
+ schemaSql + " AND i.TABLE_NAME = '" + datatableName + "' AND i.CONSTRAINT_NAME = '" + fkName + "' ";
|
+ schemaSql + " AND i.TABLE_NAME = '" + datatableName + "' AND i.CONSTRAINT_NAME = '" + fkName + "' ";
|
||||||
|
|
||||||
final Integer count = this.jdbcTemplate.queryForObject(findFKSql, Integer.class);
|
final Integer count = this.jdbcTemplate.queryForObject(findFKSql, Integer.class); // NOSONAR
|
||||||
if (count != null && count > 0) {
|
if (count != null && count > 0) {
|
||||||
codeMappings.add(datatableAlias + "_" + name);
|
codeMappings.add(datatableAlias + "_" + name);
|
||||||
constrainBuilder.append(", DROP FOREIGN KEY ").append(sqlGenerator.escape(fkName)).append(" ");
|
constrainBuilder.append(", DROP FOREIGN KEY ").append(sqlGenerator.escape(fkName)).append(" ");
|
||||||
@@ -1076,7 +1076,7 @@ public class ReadWriteNonCoreDataServiceImpl implements ReadWriteNonCoreDataServ
|
|||||||
if (type != null && mandatory && type.isStringType()) {
|
if (type != null && mandatory && type.isStringType()) {
|
||||||
String sql = "UPDATE " + sqlGenerator.escape(datatableName) + " SET " + sqlGenerator.escape(name) + " = '' WHERE "
|
String sql = "UPDATE " + sqlGenerator.escape(datatableName) + " SET " + sqlGenerator.escape(name) + " = '' WHERE "
|
||||||
+ sqlGenerator.escape(name) + " IS NULL";
|
+ sqlGenerator.escape(name) + " IS NULL";
|
||||||
this.jdbcTemplate.update(sql);
|
this.jdbcTemplate.update(sql); // NOSONAR
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1141,12 +1141,12 @@ public class ReadWriteNonCoreDataServiceImpl implements ReadWriteNonCoreDataServ
|
|||||||
private void createUniqueConstraint(String datatableName, String columnName, String uniqueKeyName) {
|
private void createUniqueConstraint(String datatableName, String columnName, String uniqueKeyName) {
|
||||||
String sql = "ALTER TABLE " + sqlGenerator.escape(datatableName) + " ADD CONSTRAINT " + sqlGenerator.escape(uniqueKeyName)
|
String sql = "ALTER TABLE " + sqlGenerator.escape(datatableName) + " ADD CONSTRAINT " + sqlGenerator.escape(uniqueKeyName)
|
||||||
+ " UNIQUE (" + sqlGenerator.escape(columnName) + ");";
|
+ " UNIQUE (" + sqlGenerator.escape(columnName) + ");";
|
||||||
this.jdbcTemplate.execute(sql);
|
this.jdbcTemplate.execute(sql); // NOSONAR
|
||||||
}
|
}
|
||||||
|
|
||||||
private void dropUniqueConstraint(String datatableName, String uniqueKeyName) {
|
private void dropUniqueConstraint(String datatableName, String uniqueKeyName) {
|
||||||
String sql = "ALTER TABLE " + sqlGenerator.escape(datatableName) + " DROP CONSTRAINT " + sqlGenerator.escape(uniqueKeyName) + ";";
|
String sql = "ALTER TABLE " + sqlGenerator.escape(datatableName) + " DROP CONSTRAINT " + sqlGenerator.escape(uniqueKeyName) + ";";
|
||||||
this.jdbcTemplate.execute(sql);
|
this.jdbcTemplate.execute(sql); // NOSONAR
|
||||||
}
|
}
|
||||||
|
|
||||||
private void updateIndexesForTable(String datatableName, JsonArray changeColumns,
|
private void updateIndexesForTable(String datatableName, JsonArray changeColumns,
|
||||||
@@ -1430,7 +1430,7 @@ public class ReadWriteNonCoreDataServiceImpl implements ReadWriteNonCoreDataServ
|
|||||||
params.add(primaryKey);
|
params.add(primaryKey);
|
||||||
final String sql = sqlGenerator.buildUpdate(dataTableName, updateColumns, headersByName) + " WHERE " + pkColumn.getColumnName()
|
final String sql = sqlGenerator.buildUpdate(dataTableName, updateColumns, headersByName) + " WHERE " + pkColumn.getColumnName()
|
||||||
+ " = ?";
|
+ " = ?";
|
||||||
int updated = jdbcTemplate.update(sql, params.toArray(Object[]::new));
|
int updated = jdbcTemplate.update(sql, params.toArray(Object[]::new)); // NOSONAR
|
||||||
if (updated != 1) {
|
if (updated != 1) {
|
||||||
throw new PlatformDataIntegrityException("error.msg.invalid.update", "Expected one updated row.");
|
throw new PlatformDataIntegrityException("error.msg.invalid.update", "Expected one updated row.");
|
||||||
}
|
}
|
||||||
@@ -1486,7 +1486,7 @@ public class ReadWriteNonCoreDataServiceImpl implements ReadWriteNonCoreDataServ
|
|||||||
String sql = "DELETE FROM " + sqlGenerator.escape(dataTableName) + " WHERE " + sqlGenerator.escape(whereColumn) + " = "
|
String sql = "DELETE FROM " + sqlGenerator.escape(dataTableName) + " WHERE " + sqlGenerator.escape(whereColumn) + " = "
|
||||||
+ whereValue;
|
+ whereValue;
|
||||||
|
|
||||||
this.jdbcTemplate.update(sql);
|
this.jdbcTemplate.update(sql); // NOSONAR
|
||||||
return new CommandProcessingResultBuilder() //
|
return new CommandProcessingResultBuilder() //
|
||||||
.withCommandId(command.commandId()) //
|
.withCommandId(command.commandId()) //
|
||||||
.withEntityId(whereValue) //
|
.withEntityId(whereValue) //
|
||||||
@@ -1643,7 +1643,7 @@ public class ReadWriteNonCoreDataServiceImpl implements ReadWriteNonCoreDataServ
|
|||||||
String sql = "SELECT COUNT(edc.x_registered_table_name) FROM x_registered_table xrt"
|
String sql = "SELECT COUNT(edc.x_registered_table_name) FROM x_registered_table xrt"
|
||||||
+ " JOIN m_entity_datatable_check edc ON edc.x_registered_table_name = xrt.registered_table_name"
|
+ " JOIN m_entity_datatable_check edc ON edc.x_registered_table_name = xrt.registered_table_name"
|
||||||
+ " WHERE edc.x_registered_table_name = '" + datatableName + "'";
|
+ " WHERE edc.x_registered_table_name = '" + datatableName + "'";
|
||||||
final Long count = this.jdbcTemplate.queryForObject(sql, Long.class);
|
final Long count = this.jdbcTemplate.queryForObject(sql, Long.class); // NOSONAR
|
||||||
return count != null && count > 0;
|
return count != null && count > 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1682,7 +1682,7 @@ public class ReadWriteNonCoreDataServiceImpl implements ReadWriteNonCoreDataServ
|
|||||||
private void validateDataTableExists(final String datatableName) {
|
private void validateDataTableExists(final String datatableName) {
|
||||||
final String sql = "select (CASE WHEN exists (select 1 from information_schema.tables where table_schema = "
|
final String sql = "select (CASE WHEN exists (select 1 from information_schema.tables where table_schema = "
|
||||||
+ sqlGenerator.currentSchema() + " and table_name = ?) THEN 'true' ELSE 'false' END)";
|
+ sqlGenerator.currentSchema() + " and table_name = ?) THEN 'true' ELSE 'false' END)";
|
||||||
final boolean dataTableExists = Boolean.parseBoolean(this.jdbcTemplate.queryForObject(sql, String.class, datatableName));
|
final boolean dataTableExists = Boolean.parseBoolean(this.jdbcTemplate.queryForObject(sql, String.class, datatableName)); // NOSONAR
|
||||||
if (!dataTableExists) {
|
if (!dataTableExists) {
|
||||||
throw new PlatformDataIntegrityException("error.msg.invalid.datatable", "Invalid Data Table: " + datatableName, API_FIELD_NAME,
|
throw new PlatformDataIntegrityException("error.msg.invalid.datatable", "Invalid Data Table: " + datatableName, API_FIELD_NAME,
|
||||||
datatableName);
|
datatableName);
|
||||||
@@ -1716,7 +1716,7 @@ public class ReadWriteNonCoreDataServiceImpl implements ReadWriteNonCoreDataServ
|
|||||||
|
|
||||||
private int getDatatableRowCount(final String datatableName) {
|
private int getDatatableRowCount(final String datatableName) {
|
||||||
final String sql = "select count(*) from " + sqlGenerator.escape(datatableName);
|
final String sql = "select count(*) from " + sqlGenerator.escape(datatableName);
|
||||||
Integer count = this.jdbcTemplate.queryForObject(sql, Integer.class);
|
Integer count = this.jdbcTemplate.queryForObject(sql, Integer.class); // NOSONAR
|
||||||
return count == null ? 0 : count;
|
return count == null ? 0 : count;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+2
-2
@@ -114,7 +114,7 @@ public class SavingsAccountTransactionsSearchServiceImpl implements SavingsAccou
|
|||||||
Object[] args = params.toArray();
|
Object[] args = params.toArray();
|
||||||
|
|
||||||
String countQuery = "SELECT COUNT(*) " + tm.from() + where;
|
String countQuery = "SELECT COUNT(*) " + tm.from() + where;
|
||||||
Integer totalElements = jdbcTemplate.queryForObject(countQuery, Integer.class, args);
|
Integer totalElements = jdbcTemplate.queryForObject(countQuery, Integer.class, args); // NOSONAR
|
||||||
if (totalElements == null || totalElements == 0) {
|
if (totalElements == null || totalElements == 0) {
|
||||||
return emptyResult;
|
return emptyResult;
|
||||||
}
|
}
|
||||||
@@ -266,7 +266,7 @@ public class SavingsAccountTransactionsSearchServiceImpl implements SavingsAccou
|
|||||||
|
|
||||||
// Execute the count Query
|
// Execute the count Query
|
||||||
String countQuery = "SELECT COUNT(*)" + from + where;
|
String countQuery = "SELECT COUNT(*)" + from + where;
|
||||||
Integer totalElements = jdbcTemplate.queryForObject(countQuery, Integer.class, args);
|
Integer totalElements = jdbcTemplate.queryForObject(countQuery, Integer.class, args); // NOSONAR
|
||||||
if (totalElements == null || totalElements == 0) {
|
if (totalElements == null || totalElements == 0) {
|
||||||
return PageableExecutionUtils.getPage(results, pageable, () -> 0);
|
return PageableExecutionUtils.getPage(results, pageable, () -> 0);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user