Skip to content
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<groupId>org.grad.secom</groupId>
<artifactId>secom-parent</artifactId>
<packaging>pom</packaging>
<version>0.0.50</version>
<version>0.0.51-SNAPSHOT</version>

<modules>
<module>secom-core</module>
Expand Down
13 changes: 10 additions & 3 deletions secom-core-jakarta/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@
<parent>
<artifactId>secom-parent</artifactId>
<groupId>org.grad.secom</groupId>
<version>0.0.50</version>
<version>0.0.51-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

<groupId>org.grad.secom</groupId>
<artifactId>secom-core-jakarta</artifactId>
<version>0.0.50</version>
<version>0.0.51-SNAPSHOT</version>

<properties>
<version.maven.jakartaee>9.0.0</version.maven.jakartaee>
Expand Down Expand Up @@ -82,7 +82,7 @@
<dependency>
<groupId>io.swagger.core.v3</groupId>
<artifactId>swagger-annotations-jakarta</artifactId>
<version>2.2.8</version>
<version>2.2.30</version>
<scope>provided</scope>
</dependency>

Expand All @@ -106,6 +106,13 @@
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<version>5.8.0</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>com.fasterxml.jackson.datatype</groupId>
<artifactId>jackson-datatype-jsr310</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import org.grad.secom.core.models.enums.SECOM_Enum;

import java.nio.charset.StandardCharsets;
import java.time.LocalDateTime;
import java.time.Instant;
import java.time.ZoneOffset;
import java.util.Arrays;
import java.util.Base64;
Expand Down Expand Up @@ -82,10 +82,10 @@ else if(attribute instanceof CsvStringGenerator) {
.map(CsvStringGenerator::getCsvString)
.orElse("");
}
else if(attribute instanceof LocalDateTime) {
else if(attribute instanceof Instant) {
return Optional.of(attribute)
.map(LocalDateTime.class::cast)
.map(ldt -> ldt.toEpochSecond(ZoneOffset.UTC))
.map(Instant.class::cast)
.map(Instant::getEpochSecond)
.map(String::valueOf)
.orElse("");
} else if(attribute instanceof Boolean) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
import java.nio.charset.StandardCharsets;
import java.security.NoSuchAlgorithmException;
import java.security.cert.CertificateEncodingException;
import java.time.LocalDateTime;
import java.time.Instant;
import java.util.Optional;

/**
Expand Down Expand Up @@ -102,7 +102,7 @@ default EnvelopeSignatureBearer signEnvelope(SecomCertificateProvider certificat
try {
this.getEnvelope().setEnvelopeSignatureCertificate(SecomPemUtils.getMinifiedPemFromCert(signatureCertificate.getCertificate()));
this.getEnvelope().setEnvelopeRootCertificateThumbprint(SecomPemUtils.getCertThumbprint(signatureCertificate.getRootCertificate(), SecomConstants.CERTIFICATE_THUMBPRINT_HASH));
this.getEnvelope().setEnvelopeSignatureTime(LocalDateTime.now());
this.getEnvelope().setEnvelopeSignatureTime(Instant.now());
} catch (CertificateEncodingException | NoSuchAlgorithmException exception) {
throw new SecomInvalidCertificateException(exception.getMessage());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,14 @@
import com.fasterxml.jackson.databind.deser.std.StdDeserializer;

import java.io.IOException;
import java.time.LocalDateTime;
import java.time.Instant;
import java.util.Optional;

import static java.util.function.Predicate.not;
import static org.grad.secom.core.base.SecomConstants.SECOM_DATE_TIME_FORMATTER;

/**
* The DateTimeDeSerializer Class
* The DateTimeDeserializer Class
* <p/>
* In SECOM the date-time format is not the frequently used ISO. According to
* the standard A DateTime is a combination of a date and a time type.
Expand All @@ -37,12 +37,12 @@
*
* @author Nikolaos Vastardis (email: Nikolaos.Vastardis@gla-rad.org)
*/
public class DateTimeDeSerializer extends StdDeserializer<LocalDateTime> {
public class InstantDeserializer extends StdDeserializer<Instant> {

/**
* Instantiates a new Byte array de serializer.
*/
protected DateTimeDeSerializer() {
protected InstantDeserializer() {
this(null);
}

Expand All @@ -51,24 +51,25 @@ protected DateTimeDeSerializer() {
*
* @param t the byte array class
*/
protected DateTimeDeSerializer(Class<LocalDateTime> t) {
protected InstantDeserializer(Class<Instant> t) {
super(t);
}

/**
* Implements the de-serialization procedure of the de-serializer.
*
* @param jp The JSON Parser
* @param ctxt The deserialization context
* @param jp The JSON Parser
* @param context The deserialization context
* @return the deserialized output
* @throws IOException for any IO exceptions
*/
@Override
public LocalDateTime deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException {
public Instant deserialize(JsonParser jp, DeserializationContext context) throws IOException {
final String value = jp.getCodec().readValue(jp, String.class);
return Optional.ofNullable(value)
.filter(not(String::isBlank))
.map(v -> LocalDateTime.parse(v, SECOM_DATE_TIME_FORMATTER))
.map(SECOM_DATE_TIME_FORMATTER::parse)
.map(Instant::from)
.orElse(null);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
import com.fasterxml.jackson.databind.ser.std.StdSerializer;

import java.io.IOException;
import java.time.LocalDateTime;
import java.time.Instant;
import java.time.ZoneId;
import java.util.Optional;

Expand All @@ -37,12 +37,12 @@
*
* @author Nikolaos Vastardis (email: Nikolaos.Vastardis@gla-rad.org)
*/
public class DateTimeSerializer extends StdSerializer<LocalDateTime> {
public class InstantSerializer extends StdSerializer<Instant> {

/**
* Instantiates a new Byte array serializer.
*/
protected DateTimeSerializer() {
protected InstantSerializer() {
this(null);
}

Expand All @@ -51,22 +51,22 @@ protected DateTimeSerializer() {
*
* @param t the byte array class
*/
protected DateTimeSerializer(Class<LocalDateTime> t) {
protected InstantSerializer(Class<Instant> t) {
super(t);
}

/**
* Implements the serialization procedure of the serializer.
*
* @param localDateTime The input to be serialized
* @param instant The input to be serialized
* @param jg The JSON generator
* @param serializerProvider The serialization provider
* @return the serialized output
* @throws IOException for any IO exceptions
*/
@Override
public void serialize(LocalDateTime localDateTime, JsonGenerator jg, SerializerProvider serializerProvider) throws IOException {
jg.writeString(Optional.ofNullable(localDateTime)
public void serialize(Instant instant, JsonGenerator jg, SerializerProvider serializerProvider) throws IOException {
jg.writeString(Optional.ofNullable(instant)
.map(dt -> dt.atZone(ZoneId.systemDefault()))
.map(SECOM_DATE_TIME_FORMATTER::format)
.orElse(""));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

package org.grad.secom.core.base;

import java.time.ZoneId;
import java.time.format.DateTimeFormatter;
import java.time.format.DateTimeFormatterBuilder;

Expand Down Expand Up @@ -66,7 +67,9 @@ public class SecomConstants {
.parseLenient()
.appendOffset("+HHMM", "Z")
.parseStrict()
.toFormatter();
.optionalEnd()
.toFormatter()
.withZone(ZoneId.systemDefault());
}
public static final String SECOM_DATE_TIME_FORMAT = SECOM_DATE_FORMAT + "'T'" + SECOM_TIME_FORMAT;

Expand All @@ -79,7 +82,9 @@ public class SecomConstants {
.parseLenient()
.appendOffset("+HHMM", "Z")
.parseStrict()
.toFormatter();
.optionalEnd()
.toFormatter()
.withZone(ZoneId.systemDefault());
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
import java.lang.reflect.Type;

/**
* The LocalDateTime Converter Provider.
* The Instant Converter Provider.
*
* @author Nikolaos Vastardis (email: Nikolaos.Vastardis@gla-rad.org)
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,22 +23,20 @@

import java.lang.annotation.Annotation;
import java.lang.reflect.Type;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.time.ZonedDateTime;
import java.time.*;

import static org.grad.secom.core.base.SecomConstants.SECOM_DATE_TIME_FORMATTER;

/**
* The LocalDateTime Converter Provider.
* The Instant Converter Provider.
*
* @author Nikolaos Vastardis (email: Nikolaos.Vastardis@gla-rad.org)
*/
@Provider
public class LocalDateTimeConverterProvider implements ParamConverterProvider {
public class InstantConverterProvider implements ParamConverterProvider {

// Class Variables
private final LocalDateTimeConverter converter = new LocalDateTimeConverter();
private final InstantConverter converter = new InstantConverter();

/**
* Implement the converter provision function.
Expand All @@ -51,31 +49,30 @@ public class LocalDateTimeConverterProvider implements ParamConverterProvider {
*/
@Override
public <T> ParamConverter<T> getConverter(Class<T> aClass, Type type, Annotation[] annotations) {
if (!aClass.equals(LocalDateTime.class)) return null;
if (!aClass.equals(Instant.class)) return null;
return (ParamConverter<T>) converter;
}

/**
* The LocalDateTime Converter Class.
* The Instant Converter Class.
*
* @author Nikolaos Vastardis (email: Nikolaos.Vastardis@gla-rad.org)
*/
public class LocalDateTimeConverter implements ParamConverter<LocalDateTime> {
public static class InstantConverter implements ParamConverter<Instant> {

/**
* Implement the fromString operation.
*
* @param value the string value to be converted into an object
* @return the converted object
*/
public LocalDateTime fromString(String value) {
public Instant fromString(String value) {
if (value == null || value.isEmpty()) return null;
try {
return LocalDateTime.parse(value, SECOM_DATE_TIME_FORMATTER);
return Instant.from(SECOM_DATE_TIME_FORMATTER.parse(value));
} catch (Exception ex) { // Direct to BAD_REQUEST
throw new SecomValidationException(ex.getMessage());
}

}

/**
Expand All @@ -84,11 +81,10 @@ public LocalDateTime fromString(String value) {
* @param value the object to be converted into a string
* @return the converted string
*/
public String toString(LocalDateTime value) {
public String toString(Instant value) {
if (value == null) return "";
try {
final ZonedDateTime zonedValue = value.atZone(ZoneId.systemDefault());
return SECOM_DATE_TIME_FORMATTER.format(zonedValue);
return SECOM_DATE_TIME_FORMATTER.format(value);
} catch (Exception ex) { // Direct to BAD_REQUEST
throw new SecomValidationException(ex.getMessage());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@
package org.grad.secom.core.interfaces;

import com.fasterxml.jackson.databind.JsonMappingException;
import com.fasterxml.jackson.databind.exc.InvalidFormatException;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.ws.rs.*;
import org.grad.secom.core.exceptions.SecomNotAuthorisedException;
import org.grad.secom.core.exceptions.SecomNotFoundException;
Expand All @@ -33,7 +34,7 @@
import jakarta.validation.constraints.Pattern;
import jakarta.ws.rs.core.MediaType;
import jakarta.ws.rs.core.Response;
import java.time.LocalDateTime;
import java.time.Instant;
import java.util.UUID;

/**
Expand Down Expand Up @@ -78,8 +79,8 @@ GetResponseObject get(@QueryParam("dataReference") UUID dataReference,
@QueryParam("productVersion") String productVersion,
@QueryParam("geometry") String geometry,
@QueryParam("unlocode") @Pattern(regexp = "[A-Z]{5}") String unlocode,
@QueryParam("validFrom") LocalDateTime validFrom,
@QueryParam("validTo") LocalDateTime validTo,
@QueryParam("validFrom") @Parameter(example = "20200101T123000", schema = @Schema(implementation = String.class, pattern = "(\\d{8})T(\\d{6})(Z|\\+\\d{4})?")) Instant validFrom,
@QueryParam("validTo") @Parameter(example = "20200101T123000", schema = @Schema(implementation = String.class, pattern = "(\\d{8})T(\\d{6})(Z|\\+\\d{4})?")) Instant validTo,
@QueryParam("page") @Min(0) Integer page,
@QueryParam("pageSize") @Min(0) Integer pageSize);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@

import com.fasterxml.jackson.databind.JsonMappingException;
import com.fasterxml.jackson.databind.exc.InvalidFormatException;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.ws.rs.*;
import org.grad.secom.core.exceptions.SecomNotAuthorisedException;
import org.grad.secom.core.exceptions.SecomNotFoundException;
Expand All @@ -33,7 +35,7 @@
import jakarta.validation.constraints.Pattern;
import jakarta.ws.rs.core.MediaType;
import jakarta.ws.rs.core.Response;
import java.time.LocalDateTime;
import java.time.Instant;

/**
* The SECOM Get Summary Interface Definition.
Expand Down Expand Up @@ -76,8 +78,8 @@ GetSummaryResponseObject getSummary(@QueryParam("containerType") ContainerTypeEn
@QueryParam("productVersion") String productVersion,
@QueryParam("geometry") String geometry,
@QueryParam("unlocode") @Pattern(regexp = "[A-Z]{5}") String unlocode,
@QueryParam("validFrom") LocalDateTime validFrom,
@QueryParam("validTo") LocalDateTime validTo,
@QueryParam("validFrom") @Parameter(example = "20200101T123000", schema = @Schema(implementation = String.class, pattern = "(\\d{8})T(\\d{6})(Z|\\+\\d{4})?")) Instant validFrom,
@QueryParam("validTo") @Parameter(example = "20200101T123000", schema = @Schema(implementation = String.class, pattern = "(\\d{8})T(\\d{6})(Z|\\+\\d{4})?")) Instant validTo,
@QueryParam("page") @Min(0) Integer page,
@QueryParam("pageSize") @Min(0) Integer pageSize);

Expand Down
Loading
Loading