Skip to content

Commit

Permalink
[KNOWAGE-8277] When I click on the date value of the table column, no…
Browse files Browse the repository at this point in the history
… data is displayed
  • Loading branch information
masseb974 committed Nov 28, 2024
1 parent f36d29d commit 00a510c
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,11 @@ protected Object getFieldValue(IField field, IFieldMetaData fieldMetaData) {
result = TIMESTAMP_FORMATTER.format(timestamp);
} else if (Time.class.isAssignableFrom(type)) {
result = CACHE_TIMEONLY_FORMATTER_V2.format(((Time) value).toLocalTime());
} else if (Date.class.isAssignableFrom(type)) {
} else if (java.sql.Date.class.isAssignableFrom(fieldMetaData.getType())) {
java.sql.Date sqlDate = (java.sql.Date) field.getValue();
Date valueAsDate = new Date(sqlDate.getTime());
result = DATE_FORMATTER_V2.format(valueAsDate.toInstant().atZone(ZoneId.systemDefault()));
} else if (java.util.Date.class.isAssignableFrom(type)) {
result = DATE_FORMATTER_V2.format(LocalDateTime.ofInstant(((Date) value).toInstant(), ZoneId.systemDefault()));
} else if (Boolean.class.isAssignableFrom(type)) {
result = Boolean.valueOf(value.toString());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,11 @@ protected Object getFieldValue(IField field, IFieldMetaData fieldMetaData) {
result = TIMESTAMP_FORMATTER_V2.format(valueAsTimestamp.toInstant().atZone(ZoneId.systemDefault()));
} else if (Time.class.isAssignableFrom(fieldMetaData.getType())) {
result = CACHE_TIMEONLY_FORMATTER_V2.format(((Time) field.getValue()).toLocalTime());
} else if (Date.class.isAssignableFrom(fieldMetaData.getType())) {
} else if (java.sql.Date.class.isAssignableFrom(fieldMetaData.getType())) {
java.sql.Date sqlDate = (java.sql.Date) field.getValue();
Date valueAsDate = new Date(sqlDate.getTime());
result = DATE_FORMATTER_V2.format(valueAsDate.toInstant().atZone(ZoneId.systemDefault()));
} else if (java.util.Date.class.isAssignableFrom(fieldMetaData.getType())) {
Date valueAsDate = (Date) field.getValue();
result = DATE_FORMATTER_V2.format(valueAsDate.toInstant().atZone(ZoneId.systemDefault()));
} else if (Boolean.class.isAssignableFrom(fieldMetaData.getType())) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,10 @@
import java.math.BigDecimal;
import java.math.BigInteger;
import java.sql.Timestamp;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.time.format.DateTimeParseException;
import java.util.Date;
import java.util.HashMap;
import java.util.Iterator;
Expand All @@ -48,7 +50,7 @@
import it.eng.spagobi.tools.dataset.bo.DataSetParameterItem;
import it.eng.spagobi.tools.dataset.bo.DataSetParametersList;
import it.eng.spagobi.tools.dataset.bo.IDataSet;
import it.eng.spagobi.tools.dataset.common.datawriter.CockpitJSONDataWriter;
import it.eng.spagobi.tools.dataset.common.datawriter.JSONDataWriter;
import it.eng.spagobi.tools.dataset.common.metadata.IFieldMetaData;
import it.eng.spagobi.tools.dataset.common.metadata.IMetaData;
import it.eng.spagobi.utilities.Helper;
Expand Down Expand Up @@ -379,21 +381,28 @@ public static Object getValue(String value, Class type) {
Object result = null;

if (value != null && !value.equalsIgnoreCase("null")) {
if (type.toString().toLowerCase().contains("timestamp")) {
if (type.toString().toLowerCase().contains("timestamp") || LocalDateTime.class.isAssignableFrom(type)) {
try {
result = Timestamp.valueOf(value);
} catch (IllegalArgumentException e) {
try {
Date date = new SimpleDateFormat(CockpitJSONDataWriter.TIMESTAMP_FORMAT).parse(value);
String formattedValue = new SimpleDateFormat(CockpitJSONDataWriter.CACHE_TIMESTAMP_FORMAT).format(date);

LocalDateTime localDateTime = LocalDateTime.parse(value,
java.time.format.DateTimeFormatter.ofPattern(JSONDataWriter.TIMESTAMP_FORMAT));
String formattedValue = localDateTime
.format(java.time.format.DateTimeFormatter.ofPattern(JSONDataWriter.CACHE_TIMESTAMP_FORMAT));
// Date date = new SimpleDateFormat(CockpitJSONDataWriter.TIMESTAMP_FORMAT).parse(value);
// String formattedValue = new SimpleDateFormat(CockpitJSONDataWriter.CACHE_TIMESTAMP_FORMAT).format(date);
result = Timestamp.valueOf(formattedValue);
} catch (ParseException | IllegalArgumentException ex) { // tries Solr date format
} catch (DateTimeParseException | IllegalArgumentException ex) { // tries Solr date format
try {
DateTimeFormatter dateTime = ISODateTimeFormat.dateTimeNoMillis();
DateTime parsedDateTime = dateTime.parseDateTime(value);
Date dateToconvert = parsedDateTime.toDate();
SimpleDateFormat sdf = new SimpleDateFormat(CockpitJSONDataWriter.CACHE_TIMESTAMP_FORMAT);
String valuesToChange = sdf.format(dateToconvert);
// SimpleDateFormat sdf = new SimpleDateFormat(CockpitJSONDataWriter.CACHE_TIMESTAMP_FORMAT);
// String valuesToChange = sdf.format(dateToconvert);
java.time.format.DateTimeFormatter formatter = java.time.format.DateTimeFormatter.ofPattern(JSONDataWriter.CACHE_TIMESTAMP_FORMAT);
String valuesToChange = formatter.format(dateToconvert.toInstant().atZone(ZoneId.systemDefault()));
result = Timestamp.valueOf(valuesToChange);
} catch (Exception ex2) {
throw new SpagoBIRuntimeException(ex2);
Expand All @@ -402,11 +411,15 @@ public static Object getValue(String value, Class type) {
}
} else if (Date.class.isAssignableFrom(type)) {
try {
result = new SimpleDateFormat(CockpitJSONDataWriter.DATE_FORMAT).parse(value);
} catch (ParseException e) {
LocalDate dateTime = LocalDate.parse(value, java.time.format.DateTimeFormatter.ofPattern(JSONDataWriter.DATE_FORMAT));
result = Date.from(dateTime.atStartOfDay(ZoneId.systemDefault()).toInstant());
// result = new SimpleDateFormat(CockpitJSONDataWriter.DATE_FORMAT).parse(value);
} catch (DateTimeParseException e) {
try {
result = new SimpleDateFormat(CockpitJSONDataWriter.CACHE_DATE_FORMAT).parse(value);
} catch (ParseException pe) {
LocalDate dateTime = LocalDate.parse(value, java.time.format.DateTimeFormatter.ofPattern(JSONDataWriter.CACHE_DATE_FORMAT));
result = Date.from(dateTime.atStartOfDay(ZoneId.systemDefault()).toInstant());
// result = new SimpleDateFormat(CockpitJSONDataWriter.CACHE_DATE_FORMAT).parse(value);
} catch (DateTimeParseException pe) {
throw new SpagoBIRuntimeException(pe);
}
}
Expand Down

0 comments on commit 00a510c

Please sign in to comment.