Datatables datetime fields management
This commit is contained in:
committed by
Arnold Gálovics
parent
865b9efc6e
commit
e15459c659
+4
-4
@@ -22,17 +22,17 @@ import java.util.List;
|
|||||||
|
|
||||||
public final class ResultsetRowData {
|
public final class ResultsetRowData {
|
||||||
|
|
||||||
private final List<String> row;
|
private final List<Object> row;
|
||||||
|
|
||||||
public static ResultsetRowData create(final List<String> rowValues) {
|
public static ResultsetRowData create(final List<Object> rowValues) {
|
||||||
return new ResultsetRowData(rowValues);
|
return new ResultsetRowData(rowValues);
|
||||||
}
|
}
|
||||||
|
|
||||||
private ResultsetRowData(final List<String> rowValues) {
|
private ResultsetRowData(final List<Object> rowValues) {
|
||||||
this.row = rowValues;
|
this.row = rowValues;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<String> getRow() {
|
public List<Object> getRow() {
|
||||||
return this.row;
|
return this.row;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+17
-24
@@ -18,15 +18,17 @@
|
|||||||
*/
|
*/
|
||||||
package org.apache.fineract.infrastructure.dataqueries.service;
|
package org.apache.fineract.infrastructure.dataqueries.service;
|
||||||
|
|
||||||
|
import static java.lang.String.format;
|
||||||
|
|
||||||
|
import java.sql.Timestamp;
|
||||||
import java.time.LocalDate;
|
import java.time.LocalDate;
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
import java.time.temporal.ChronoField;
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Date;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import javax.sql.DataSource;
|
import javax.sql.DataSource;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.apache.fineract.infrastructure.core.exception.PlatformDataIntegrityException;
|
import org.apache.fineract.infrastructure.core.exception.PlatformDataIntegrityException;
|
||||||
import org.apache.fineract.infrastructure.core.service.DateUtils;
|
|
||||||
import org.apache.fineract.infrastructure.core.service.RoutingDataSource;
|
import org.apache.fineract.infrastructure.core.service.RoutingDataSource;
|
||||||
import org.apache.fineract.infrastructure.core.service.database.DatabaseIndependentQueryService;
|
import org.apache.fineract.infrastructure.core.service.database.DatabaseIndependentQueryService;
|
||||||
import org.apache.fineract.infrastructure.dataqueries.data.GenericResultsetData;
|
import org.apache.fineract.infrastructure.dataqueries.data.GenericResultsetData;
|
||||||
@@ -77,7 +79,7 @@ public class GenericDataServiceImpl implements GenericDataService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
while (rs.next()) {
|
while (rs.next()) {
|
||||||
final List<String> columnValues = new ArrayList<>();
|
final List<Object> columnValues = new ArrayList<>();
|
||||||
for (int i = 0; i < rsmd.getColumnCount(); i++) {
|
for (int i = 0; i < rsmd.getColumnCount(); i++) {
|
||||||
final String columnName = rsmd.getColumnName(i + 1);
|
final String columnName = rsmd.getColumnName(i + 1);
|
||||||
final String columnValue = rs.getString(columnName);
|
final String columnValue = rs.getString(columnName);
|
||||||
@@ -134,12 +136,12 @@ public class GenericDataServiceImpl implements GenericDataService {
|
|||||||
final List<ResultsetColumnHeaderData> columnHeaders = grs.getColumnHeaders();
|
final List<ResultsetColumnHeaderData> columnHeaders = grs.getColumnHeaders();
|
||||||
|
|
||||||
final List<ResultsetRowData> data = grs.getData();
|
final List<ResultsetRowData> data = grs.getData();
|
||||||
List<String> row;
|
List<Object> row;
|
||||||
Integer rSize;
|
Integer rSize;
|
||||||
final String doubleQuote = "\"";
|
final String doubleQuote = "\"";
|
||||||
final String slashDoubleQuote = "\\\"";
|
final String slashDoubleQuote = "\\\"";
|
||||||
String currColType;
|
String currColType;
|
||||||
String currVal;
|
Object currVal;
|
||||||
|
|
||||||
for (int i = 0; i < data.size(); i++) {
|
for (int i = 0; i < data.size(); i++) {
|
||||||
writer.append("\n{");
|
writer.append("\n{");
|
||||||
@@ -160,23 +162,24 @@ public class GenericDataServiceImpl implements GenericDataService {
|
|||||||
if (currColType == null && colType.equalsIgnoreCase("DATE")) {
|
if (currColType == null && colType.equalsIgnoreCase("DATE")) {
|
||||||
currColType = "DATE";
|
currColType = "DATE";
|
||||||
}
|
}
|
||||||
|
if (currColType == null && colType.equalsIgnoreCase("DATETIME")) {
|
||||||
|
currColType = "DATETIME";
|
||||||
|
}
|
||||||
currVal = row.get(j);
|
currVal = row.get(j);
|
||||||
if (currVal != null && currColType != null) {
|
if (currVal != null && currColType != null) {
|
||||||
if (currColType.equals("DECIMAL") || currColType.equals("INTEGER")) {
|
if (currColType.equals("DECIMAL") || currColType.equals("INTEGER")) {
|
||||||
writer.append(currVal);
|
writer.append(currVal);
|
||||||
} else {
|
} else {
|
||||||
if (currColType.equals("DATE")) {
|
if (currColType.equals("DATE")) {
|
||||||
final LocalDate localDate = LocalDate.parse(currVal);
|
final LocalDate localDate = new java.sql.Date(((Date) currVal).getTime()).toLocalDate();
|
||||||
writer.append(
|
writer.append(format("[%d,%d,%d]", localDate.getYear(), localDate.getMonthValue(), localDate.getDayOfMonth()));
|
||||||
"[" + localDate.getYear() + ", " + localDate.getMonthValue() + ", " + localDate.getDayOfMonth() + "]");
|
|
||||||
} else if (currColType.equals("DATETIME")) {
|
} else if (currColType.equals("DATETIME")) {
|
||||||
final LocalDateTime localDateTime = LocalDateTime.parse(formatDateTimeValue(currVal),
|
final LocalDateTime ldt = currVal instanceof Timestamp ? ((Timestamp) currVal).toLocalDateTime()
|
||||||
DateUtils.DEFAULT_DATETIME_FORMATTER);
|
: (LocalDateTime) currVal;
|
||||||
writer.append("[" + localDateTime.getYear() + ", " + localDateTime.getMonthValue() + ", "
|
writer.append(format("[%d,%d,%d,%d,%d,%d,%d]", ldt.getYear(), ldt.getMonthValue(), ldt.getDayOfMonth(),
|
||||||
+ localDateTime.getDayOfMonth() + ", " + localDateTime.getHour() + ", " + localDateTime.getMinute()
|
ldt.getHour(), ldt.getMinute(), ldt.getSecond(), ldt.getNano()));
|
||||||
+ ", " + localDateTime.getSecond() + ", " + localDateTime.get(ChronoField.MILLI_OF_SECOND) + "]");
|
|
||||||
} else {
|
} else {
|
||||||
writer.append(doubleQuote + replace(currVal, doubleQuote, slashDoubleQuote) + doubleQuote);
|
writer.append(doubleQuote + replace((String) currVal, doubleQuote, slashDoubleQuote) + doubleQuote);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@@ -264,14 +267,4 @@ public class GenericDataServiceImpl implements GenericDataService {
|
|||||||
throw new DatatableNotFoundException(datatable);
|
throw new DatatableNotFoundException(datatable);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private String formatDateTimeValue(String dateTimeValue) {
|
|
||||||
if (dateTimeValue.length() > 19) {
|
|
||||||
dateTimeValue = dateTimeValue.substring(0, 19);
|
|
||||||
}
|
|
||||||
if (dateTimeValue.contains("T")) {
|
|
||||||
dateTimeValue = dateTimeValue.replace("T", " ");
|
|
||||||
}
|
|
||||||
return dateTimeValue;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
+4
-4
@@ -115,7 +115,7 @@ public class ReadReportingServiceImpl implements ReadReportingService {
|
|||||||
writer.append('\n');
|
writer.append('\n');
|
||||||
|
|
||||||
final List<ResultsetRowData> data = result.getData();
|
final List<ResultsetRowData> data = result.getData();
|
||||||
List<String> row;
|
List<Object> row;
|
||||||
Integer rSize;
|
Integer rSize;
|
||||||
// String currCol;
|
// String currCol;
|
||||||
String currColType;
|
String currColType;
|
||||||
@@ -129,7 +129,7 @@ public class ReadReportingServiceImpl implements ReadReportingService {
|
|||||||
for (int j = 0; j < rSize; j++) {
|
for (int j = 0; j < rSize; j++) {
|
||||||
// currCol = columnHeaders.get(j).getColumnName();
|
// currCol = columnHeaders.get(j).getColumnName();
|
||||||
currColType = columnHeaders.get(j).getColumnType();
|
currColType = columnHeaders.get(j).getColumnType();
|
||||||
currVal = row.get(j);
|
currVal = (String) row.get(j);
|
||||||
if (currVal != null) {
|
if (currVal != null) {
|
||||||
if (currColType.equals("DECIMAL") || currColType.equals("DOUBLE") || currColType.equals("BIGINT")
|
if (currColType.equals("DECIMAL") || currColType.equals("DOUBLE") || currColType.equals("BIGINT")
|
||||||
|| currColType.equals("SMALLINT") || currColType.equals("INT")) {
|
|| currColType.equals("SMALLINT") || currColType.equals("INT")) {
|
||||||
@@ -252,7 +252,7 @@ public class ReadReportingServiceImpl implements ReadReportingService {
|
|||||||
|
|
||||||
final List<ResultsetColumnHeaderData> columnHeaders = result.getColumnHeaders();
|
final List<ResultsetColumnHeaderData> columnHeaders = result.getColumnHeaders();
|
||||||
final List<ResultsetRowData> data = result.getData();
|
final List<ResultsetRowData> data = result.getData();
|
||||||
List<String> row;
|
List<Object> row;
|
||||||
|
|
||||||
log.info("NO. of Columns: {}", columnHeaders.size());
|
log.info("NO. of Columns: {}", columnHeaders.size());
|
||||||
final Integer chSize = columnHeaders.size();
|
final Integer chSize = columnHeaders.size();
|
||||||
@@ -282,7 +282,7 @@ public class ReadReportingServiceImpl implements ReadReportingService {
|
|||||||
rSize = row.size();
|
rSize = row.size();
|
||||||
for (int j = 0; j < rSize; j++) {
|
for (int j = 0; j < rSize; j++) {
|
||||||
currColType = columnHeaders.get(j).getColumnType();
|
currColType = columnHeaders.get(j).getColumnType();
|
||||||
currVal = row.get(j);
|
currVal = (String) row.get(j);
|
||||||
if (currVal != null) {
|
if (currVal != null) {
|
||||||
if (currColType.equals("DECIMAL") || currColType.equals("DOUBLE") || currColType.equals("BIGINT")
|
if (currColType.equals("DECIMAL") || currColType.equals("DOUBLE") || currColType.equals("BIGINT")
|
||||||
|| currColType.equals("SMALLINT") || currColType.equals("INT")) {
|
|| currColType.equals("SMALLINT") || currColType.equals("INT")) {
|
||||||
|
|||||||
+19
-11
@@ -1310,7 +1310,7 @@ public class ReadWriteNonCoreDataServiceImpl implements ReadWriteNonCoreDataServ
|
|||||||
sql = sql + " order by " + order;
|
sql = sql + " order by " + order;
|
||||||
}
|
}
|
||||||
|
|
||||||
final List<ResultsetRowData> result = fillDatatableResultSetDataRows(sql);
|
final List<ResultsetRowData> result = fillDatatableResultSetDataRows(sql, columnHeaders);
|
||||||
|
|
||||||
return new GenericResultsetData(columnHeaders, result);
|
return new GenericResultsetData(columnHeaders, result);
|
||||||
}
|
}
|
||||||
@@ -1331,7 +1331,7 @@ public class ReadWriteNonCoreDataServiceImpl implements ReadWriteNonCoreDataServ
|
|||||||
sql = sql + " and id = " + id;
|
sql = sql + " and id = " + id;
|
||||||
}
|
}
|
||||||
|
|
||||||
final List<ResultsetRowData> result = fillDatatableResultSetDataRows(sql);
|
final List<ResultsetRowData> result = fillDatatableResultSetDataRows(sql, columnHeaders);
|
||||||
|
|
||||||
return new GenericResultsetData(columnHeaders, result);
|
return new GenericResultsetData(columnHeaders, result);
|
||||||
}
|
}
|
||||||
@@ -1339,7 +1339,7 @@ public class ReadWriteNonCoreDataServiceImpl implements ReadWriteNonCoreDataServ
|
|||||||
private CommandProcessingResult checkMainResourceExistsWithinScope(final String appTable, final Long appTableId) {
|
private CommandProcessingResult checkMainResourceExistsWithinScope(final String appTable, final Long appTableId) {
|
||||||
|
|
||||||
final String sql = dataScopedSQL(appTable, appTableId);
|
final String sql = dataScopedSQL(appTable, appTableId);
|
||||||
LOG.info("data scoped sql: {}", sql);
|
LOG.debug("data scoped sql: {}", sql);
|
||||||
final SqlRowSet rs = this.jdbcTemplate.queryForRowSet(sql);
|
final SqlRowSet rs = this.jdbcTemplate.queryForRowSet(sql);
|
||||||
|
|
||||||
if (!rs.next()) {
|
if (!rs.next()) {
|
||||||
@@ -1471,22 +1471,30 @@ public class ReadWriteNonCoreDataServiceImpl implements ReadWriteNonCoreDataServ
|
|||||||
return appTable;
|
return appTable;
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<ResultsetRowData> fillDatatableResultSetDataRows(final String sql) {
|
private List<ResultsetRowData> fillDatatableResultSetDataRows(final String sql, final List<ResultsetColumnHeaderData> columnHeaders) {
|
||||||
final List<ResultsetRowData> resultsetDataRows = new ArrayList<>();
|
final List<ResultsetRowData> resultsetDataRows = new ArrayList<>();
|
||||||
|
final GenericResultsetData genericResultsetData = new GenericResultsetData(columnHeaders, null);
|
||||||
|
|
||||||
final SqlRowSet rowSet = jdbcTemplate.queryForRowSet(sql); // NOSONAR
|
final SqlRowSet rowSet = jdbcTemplate.queryForRowSet(sql); // NOSONAR
|
||||||
final SqlRowSetMetaData rsmd = rowSet.getMetaData();
|
final SqlRowSetMetaData rsmd = rowSet.getMetaData();
|
||||||
|
|
||||||
while (rowSet.next()) {
|
while (rowSet.next()) {
|
||||||
final List<String> columnValues = new ArrayList<>();
|
final List<Object> columnValues = new ArrayList<>();
|
||||||
|
|
||||||
for (int i = 0; i < rsmd.getColumnCount(); i++) {
|
for (int i = 0; i < rsmd.getColumnCount(); i++) {
|
||||||
final String columnName = rsmd.getColumnName(i + 1);
|
final String columnName = rsmd.getColumnName(i + 1);
|
||||||
final String columnValue = rowSet.getString(columnName);
|
final String colType = genericResultsetData.getColTypeOfColumnNamed(columnName);
|
||||||
columnValues.add(columnValue);
|
if ("DECIMAL".equalsIgnoreCase(colType)) {
|
||||||
|
columnValues.add(rowSet.getBigDecimal(columnName));
|
||||||
|
} else if ("DATE".equalsIgnoreCase(colType) || ("TIMESTAMP WITHOUT TIME ZONE".equalsIgnoreCase(colType) // PostgreSQL
|
||||||
|
|| "DATETIME".equalsIgnoreCase(colType) || "TIMESTAMP".equalsIgnoreCase(colType))) {
|
||||||
|
columnValues.add(rowSet.getObject(columnName));
|
||||||
|
} else {
|
||||||
|
columnValues.add(rowSet.getString(columnName));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
final ResultsetRowData resultsetDataRow = ResultsetRowData.create(columnValues);
|
resultsetDataRows.add(ResultsetRowData.create(columnValues));
|
||||||
resultsetDataRows.add(resultsetDataRow);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return resultsetDataRows;
|
return resultsetDataRows;
|
||||||
@@ -1696,13 +1704,13 @@ public class ReadWriteNonCoreDataServiceImpl implements ReadWriteNonCoreDataServ
|
|||||||
|
|
||||||
private boolean columnChanged(final String key, final String keyValue, final String colType, final GenericResultsetData grs) {
|
private boolean columnChanged(final String key, final String keyValue, final String colType, final GenericResultsetData grs) {
|
||||||
|
|
||||||
final List<String> columnValues = grs.getData().get(0).getRow();
|
final List<Object> columnValues = grs.getData().get(0).getRow();
|
||||||
|
|
||||||
String columnValue = null;
|
String columnValue = null;
|
||||||
for (int i = 0; i < grs.getColumnHeaders().size(); i++) {
|
for (int i = 0; i < grs.getColumnHeaders().size(); i++) {
|
||||||
|
|
||||||
if (key.equals(grs.getColumnHeaders().get(i).getColumnName())) {
|
if (key.equals(grs.getColumnHeaders().get(i).getColumnName())) {
|
||||||
columnValue = columnValues.get(i);
|
columnValue = (String) columnValues.get(i);
|
||||||
|
|
||||||
if (notTheSame(columnValue, keyValue, colType)) {
|
if (notTheSame(columnValue, keyValue, colType)) {
|
||||||
return true;
|
return true;
|
||||||
|
|||||||
+2
-2
@@ -22,8 +22,8 @@
|
|||||||
<databaseChangeLog xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
|
<databaseChangeLog xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
|
||||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-4.1.xsd">
|
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-4.1.xsd">
|
||||||
<changeSet author="fineract" id="1">
|
<changeSet author="fineract" id="1" onValidationFail="MARK_RAN">
|
||||||
<validCheckSum>8:4500ffb68c695d72caba498deff75643</validCheckSum>
|
<validCheckSum>8:177f2e2cbac12752ede2182bbbfde6ae</validCheckSum>
|
||||||
<addColumn tableName="m_loan_transaction">
|
<addColumn tableName="m_loan_transaction">
|
||||||
<column name="createdby_id" type="BIGINT" valueComputed="appuser_id"/>
|
<column name="createdby_id" type="BIGINT" valueComputed="appuser_id"/>
|
||||||
<column name="lastmodifiedby_id" type="BIGINT"/>
|
<column name="lastmodifiedby_id" type="BIGINT"/>
|
||||||
|
|||||||
Reference in New Issue
Block a user