aggiunto tipo time
This commit is contained in:
@@ -58,7 +58,6 @@ public class CommonConstants {
|
||||
public static final DateTimeFormatter DATETIME_DMY_DASHED_FORMATTER = DateTimeFormatter.ofPattern(CommonConstants.DATETIME_FORMAT_DMY_DASHED)
|
||||
.withZone(ZoneId.systemDefault());
|
||||
|
||||
|
||||
public static final String ULTC = "ULTC";
|
||||
public static final String DIST = "DIST";
|
||||
public static final String CMPPF = "CMPPF";
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
package it.integry.ems.adapter;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonParser;
|
||||
import com.fasterxml.jackson.databind.DeserializationContext;
|
||||
import com.fasterxml.jackson.databind.JsonDeserializer;
|
||||
import it.integry.ems_model.config.EmsRestConstants;
|
||||
import it.integry.ems_model.utility.UtilityString;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.LocalTime;
|
||||
|
||||
public class JsonLocalTimeAdapterDeserializer extends JsonDeserializer<LocalTime> {
|
||||
|
||||
@Override
|
||||
public LocalTime deserialize(JsonParser jp, DeserializationContext arg1)
|
||||
throws IOException {
|
||||
|
||||
if (UtilityString.isNullOrEmpty(jp.getText()))
|
||||
return null;
|
||||
|
||||
if (jp.getText().equalsIgnoreCase("null") || jp.getText().equalsIgnoreCase("1900-01-01"))
|
||||
return EmsRestConstants.LOCAL_TIME_NULL;
|
||||
|
||||
|
||||
return UtilityString.parseLocalTime(jp.getText());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
package it.integry.ems.adapter;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonGenerator;
|
||||
import com.fasterxml.jackson.databind.JsonSerializer;
|
||||
import com.fasterxml.jackson.databind.SerializerProvider;
|
||||
import it.integry.common.var.CommonConstants;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import java.time.LocalTime;
|
||||
|
||||
public class JsonLocalTimeAdapterSerializer extends JsonSerializer<LocalTime> {
|
||||
@Override
|
||||
public void serialize(LocalTime value, JsonGenerator gen,
|
||||
SerializerProvider serializers) throws IOException {
|
||||
|
||||
if (value == null)
|
||||
gen.writeNull();
|
||||
else
|
||||
gen.writeString(CommonConstants.DATETIME_DMY_SLASHED_FORMATTER.format(value));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -30,6 +30,7 @@ import java.lang.reflect.Field;
|
||||
import java.math.BigDecimal;
|
||||
import java.time.LocalDate;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.LocalTime;
|
||||
import java.util.AbstractMap;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
@@ -51,6 +52,9 @@ public class ResponseJSONObjectMapper extends ObjectMapper {
|
||||
module.addSerializer(LocalDateTime.class, new JsonLocalDateTimeAdapterSerializer());
|
||||
module.addDeserializer(LocalDateTime.class, new JsonLocalDateTimeAdapterDeserializer());
|
||||
|
||||
module.addSerializer(LocalTime.class, new JsonLocalTimeAdapterSerializer());
|
||||
module.addDeserializer(LocalTime.class, new JsonLocalTimeAdapterDeserializer());
|
||||
|
||||
module.addSerializer(EsitoType.class, new EsitoSerialize());
|
||||
module.addDeserializer(EsitoType.class, new EsitoDeserialize());
|
||||
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
package it.integry.ems.migration.model;
|
||||
|
||||
import it.integry.ems.migration._base.BaseMigration;
|
||||
import it.integry.ems.migration._base.MigrationModelInterface;
|
||||
|
||||
public class Migration_20250403144545 extends BaseMigration implements MigrationModelInterface {
|
||||
|
||||
@Override
|
||||
public void up() throws Exception {
|
||||
if (isHistoryDB())
|
||||
return;
|
||||
|
||||
executeStatement("alter table atb_piano_logistico_det add ora_max_ord time",
|
||||
"alter table atb_piano_logistico_det add ora_scarico time");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void down() throws Exception {
|
||||
}
|
||||
}
|
||||
@@ -7,6 +7,8 @@ import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.kie.api.definition.type.PropertyReactive;
|
||||
|
||||
import java.time.LocalTime;
|
||||
|
||||
@PropertyReactive
|
||||
@Table(AtbPianoLogisticoDet.ENTITY)
|
||||
@JsonTypeName(AtbPianoLogisticoDet.ENTITY)
|
||||
@@ -46,6 +48,12 @@ public class AtbPianoLogisticoDet extends EntityBase {
|
||||
@SqlField(value = "note_consegna", maxLength = 255)
|
||||
private String noteConsegna;
|
||||
|
||||
@SqlField(value = "ora_max_ord")
|
||||
private LocalTime oraMaxOrd;
|
||||
|
||||
@SqlField(value = "ora_scarico")
|
||||
private LocalTime oraScarico;
|
||||
|
||||
public Long getIdRiga() {
|
||||
return idRiga;
|
||||
}
|
||||
@@ -98,4 +106,22 @@ public class AtbPianoLogisticoDet extends EntityBase {
|
||||
public void setNoteConsegna(String noteConsegna) {
|
||||
this.noteConsegna = noteConsegna;
|
||||
}
|
||||
|
||||
public LocalTime getOraMaxOrd() {
|
||||
return oraMaxOrd;
|
||||
}
|
||||
|
||||
public AtbPianoLogisticoDet setOraMaxOrd(LocalTime oraMaxOrd) {
|
||||
this.oraMaxOrd = oraMaxOrd;
|
||||
return this;
|
||||
}
|
||||
|
||||
public LocalTime getOraScarico() {
|
||||
return oraScarico;
|
||||
}
|
||||
|
||||
public AtbPianoLogisticoDet setOraScarico(LocalTime oraScarico) {
|
||||
this.oraScarico = oraScarico;
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -219,6 +219,14 @@ public class SqlFieldHolder {
|
||||
return data;
|
||||
}
|
||||
};
|
||||
} else if (dtoType.equals(LocalTime.class)) {
|
||||
converter = data -> {
|
||||
try {
|
||||
return UtilityString.parseLocalTime(data.toString());
|
||||
} catch (Exception e) {
|
||||
return data;
|
||||
}
|
||||
};
|
||||
} else if (dtoType.equals(Byte[].class) && sqlType.equals(byte[].class)) {
|
||||
converter = data -> ArrayUtils.toObject((byte[]) data);
|
||||
} else if (dtoType.equals(LatLng.class)) {
|
||||
|
||||
@@ -14,6 +14,7 @@ import java.math.RoundingMode;
|
||||
import java.text.*;
|
||||
import java.time.LocalDate;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.LocalTime;
|
||||
import java.time.ZoneId;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.*;
|
||||
@@ -108,15 +109,31 @@ public class UtilityString {
|
||||
put("^(\\d{4})-(\\d{2})-(\\d{2})t(\\d{2}):(\\d{2}):(\\d{2})((\\+|-)(\\d{2}):(\\d{2}))$", "yyyy-MM-dd'T'HH:mm:ss");
|
||||
}};
|
||||
|
||||
public static String determineDateFormat(String dateString) {
|
||||
private static final Map<String, String> TIME_FORMAT_REGEXPS = new HashMap<String, String>() {{
|
||||
put("^\\d{1,2}:\\d{2}$", "HH:mm");
|
||||
put("^\\d{2}:\\d{2}$", "HH:mm");
|
||||
put("^\\d{1,2}:\\d{2}:\\d{2}$", "HH:mm:ss");
|
||||
put("^\\d{2}:\\d{2}:\\d{2}$", "HH:mm:ss");
|
||||
}};
|
||||
|
||||
public static String determineDateFormat(String timeString) {
|
||||
for (String regexp : DATE_FORMAT_REGEXPS.keySet()) {
|
||||
if (dateString.toLowerCase().matches(regexp)) {
|
||||
if (timeString.toLowerCase().matches(regexp)) {
|
||||
return DATE_FORMAT_REGEXPS.get(regexp);
|
||||
}
|
||||
}
|
||||
return null; // Unknown format.
|
||||
}
|
||||
|
||||
public static String determineTimeFormat(String timeString) {
|
||||
for (String regexp : TIME_FORMAT_REGEXPS.keySet()) {
|
||||
if (timeString.toLowerCase().matches(regexp)) {
|
||||
return TIME_FORMAT_REGEXPS.get(regexp);
|
||||
}
|
||||
}
|
||||
return null; // Unknown format.
|
||||
}
|
||||
|
||||
public static Date parseDate(String value) throws IOException {
|
||||
String format = determineDateFormat(value);
|
||||
|
||||
@@ -155,6 +172,28 @@ public class UtilityString {
|
||||
return LocalDate.parse(value, formatter);
|
||||
}
|
||||
|
||||
|
||||
|
||||
public static LocalTime parseLocalTime(String value) throws IOException {
|
||||
String format = determineTimeFormat(value);
|
||||
|
||||
if (format == null) {
|
||||
try {
|
||||
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("HH:mm");
|
||||
return LocalTime.parse(value, formatter);
|
||||
} catch (Exception ignored) {
|
||||
}
|
||||
}
|
||||
|
||||
if (format == null)
|
||||
throw new IOException("Impossibile riconoscere il formato data per " + value);
|
||||
|
||||
DateTimeFormatter formatter = DateTimeFormatter.ofPattern(format)
|
||||
.withZone(ZoneId.systemDefault());
|
||||
|
||||
return LocalTime.parse(value, formatter);
|
||||
}
|
||||
|
||||
public static LocalDateTime parseLocalDateTime(String value) throws IOException {
|
||||
String format = determineDateFormat(value);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user