Skip to content

Commit

Permalink
Merge branch 'development' into feature/FDP-622
Browse files Browse the repository at this point in the history
# Conflicts:
#	osgp/platform/osgp-adapter-ws-core/src/main/java/org/opensmartgridplatform/adapter/ws/core/application/services/FirmwareManagementService.java
#	osgp/platform/osgp-adapter-ws-core/src/main/java/org/opensmartgridplatform/adapter/ws/core/endpoints/FirmwareManagementEndpoint.java
  • Loading branch information
LucianoFavoroso committed Jan 4, 2024
2 parents 8ea0be6 + 1ac0a0b commit 476bac5
Show file tree
Hide file tree
Showing 670 changed files with 18,355 additions and 9,110 deletions.
18 changes: 18 additions & 0 deletions .github/workflows/dependency-review.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
name: Maven Dependency Tree Dependency Submission
on:
schedule:
- cron: '0 0 * * *'
workflow_dispatch:

permissions:
contents: write

jobs:
dependency-detection-and-submission:
runs-on: ubuntu-latest
steps:
- name: 'Checkout Repository'
uses: actions/checkout@v4

- name: Submit Dependency Snapshot
uses: advanced-security/maven-dependency-submission-action@v3
2 changes: 1 addition & 1 deletion integration-tests/cucumber-tests-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ SPDX-License-Identifier: Apache-2.0
<parent>
<groupId>org.opensmartgridplatform</groupId>
<artifactId>parent-integration-tests</artifactId>
<version>5.45.0-SNAPSHOT</version>
<version>5.49.0-SNAPSHOT</version>
<relativePath>../parent-integration-tests/pom.xml</relativePath>
</parent>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,15 @@
import com.luckycatlabs.sunrisesunset.SunriseSunsetCalculator;
import com.luckycatlabs.sunrisesunset.dto.Location;
import java.time.Instant;
import java.time.LocalTime;
import java.time.ZoneId;
import java.time.ZonedDateTime;
import java.time.format.DateTimeFormatter;
import java.util.Calendar;
import java.util.TimeZone;
import java.util.Date;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.joda.time.DateTime;
import org.joda.time.DateTimeZone;
import org.joda.time.format.DateTimeFormat;
import org.joda.time.format.DateTimeFormatter;
import org.opensmartgridplatform.shared.utils.JavaTimeHelpers;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand All @@ -29,8 +28,8 @@ public class DateTimeHelper {
/**
* @return CET/CEST time zone based on ID {@value #CET_TIMEZONE}
*/
public static DateTimeZone getCentralEuropeanTimeZone() {
return DateTimeZone.forID(CET_TIMEZONE);
public static ZoneId getCentralEuropeanTimeZone() {
return ZoneId.of(CET_TIMEZONE);
}

/**
Expand All @@ -57,12 +56,12 @@ public static ZoneId getCentralEuropeanZoneId() {
* <li>now at midday + 1 week
* </ul>
*/
public static DateTime getDateTime(final String dateString) {
public static ZonedDateTime getDateTime(final String dateString) {
if (dateString.isEmpty()) {
return null;
}

DateTime retval = DateTime.now(getCentralEuropeanTimeZone());
ZonedDateTime retval = ZonedDateTime.now(getCentralEuropeanTimeZone());

final String pattern = "([a-z ]*)[ ]*([+-]?)[ ]*([0-9]*)[ ]*([a-z]*)";
final Pattern r = Pattern.compile(pattern);
Expand Down Expand Up @@ -105,27 +104,27 @@ public static DateTime getDateTime(final String dateString) {
}

// Normalize the seconds and milliseconds to zero
retval = retval.withSecondOfMinute(0);
retval = retval.withMillisOfSecond(0);
retval = retval.withSecond(0);
retval = retval.withNano(0);

if (whenMatcher.groupCount() > 1 && whenMatcher.group(2).equals("at")) {

switch (whenMatcher.group(3)) {
case "midday":
case "noon":
retval = retval.withHourOfDay(12);
retval = retval.withHour(12);
break;
case "midnight":
retval = retval.withHourOfDay(0);
retval = retval.withHour(0);
break;
default:
throw new IllegalArgumentException(
"Invalid dateString ["
+ dateString
+ "], expected \"midday\", \"noon\" or \"midnight\"");
}
retval = retval.withMinuteOfHour(0);
retval = retval.withSecondOfMinute(0);
retval = retval.withMinute(0);
retval = retval.withSecond(0);
}

if (op.equals("+")) {
Expand Down Expand Up @@ -176,25 +175,25 @@ public static DateTime getDateTime(final String dateString) {
}

public static ZonedDateTime getZonedDateTime(final String dateString) {
return dateTimeToZonedDateTime(getDateTime(dateString));
return getDateTime(dateString);
}

public static Instant getInstant(final String dateString) {
final ZonedDateTime dateTime = getZonedDateTime(dateString);
return dateTime.toInstant();
}

public static DateTime getDateTime2(final String startDate, final DateTime defaultStartDate) {
public static ZonedDateTime getDateTime2(
final String startDate, final ZonedDateTime defaultStartDate) {
if (startDate == null) {
return defaultStartDate;
}
DateTime dateTime;
ZonedDateTime dateTime;
try {
dateTime = getDateTime(startDate);
} catch (final IllegalArgumentException e) {
LOGGER.debug(
"The string {} could not be parsed by DateTimeHelper.getDateTime, lets org.joda.time.DateTime");
dateTime = DateTime.parse(startDate);
LOGGER.debug("The string {} could not be parsed by DateTimeHelper.getDateTime");
dateTime = JavaTimeHelpers.parseToZonedDateTime(startDate);
}
if (dateTime == null) {
return defaultStartDate;
Expand All @@ -204,72 +203,37 @@ public static DateTime getDateTime2(final String startDate, final DateTime defau

public static ZonedDateTime getZonedDateTime2(
final String startDate, final ZonedDateTime defaultStartDate) {
return dateTimeToZonedDateTime(
getDateTime2(startDate, zonedDateTimeToDateTime(defaultStartDate)));
return getDateTime2(startDate, defaultStartDate);
}

/** Get time of sunrise/sunset */
public static DateTime getSunriseSunsetTime(
final String actionTimeType, final DateTime date, final Location location) {
public static ZonedDateTime getSunriseSunsetTime(
final String actionTimeType, final ZonedDateTime date, final Location location) {
final SunriseSunsetCalculator calculator = new SunriseSunsetCalculator(location, "UTC");

Calendar officialTransition = null;

final Calendar calender = Calendar.getInstance();

if (actionTimeType.equalsIgnoreCase("SUNSET")) {
calender.setTime(date.toDate());
calender.setTime(Date.from(date.toInstant()));
officialTransition = calculator.getOfficialSunsetCalendarForDate(calender);
} else if (actionTimeType.equalsIgnoreCase("SUNRISE")) {
calender.setTime(date.plusDays(1).toDate());
calender.setTime(Date.from(date.plusDays(1).toInstant()));
officialTransition = calculator.getOfficialSunriseCalendarForDate(calender);
}

if (officialTransition == null) {
return null;
}

return new DateTime(officialTransition.getTimeInMillis());
return ZonedDateTime.ofInstant(
Instant.ofEpochMilli(officialTransition.getTimeInMillis()), ZoneId.systemDefault());
}

public static ZonedDateTime getSunriseSunsetZonedDateTime(
final String actionTimeType, final ZonedDateTime date, final Location location) {
return dateTimeToZonedDateTime(
getSunriseSunsetTime(actionTimeType, zonedDateTimeToDateTime(date), location));
}

/**
* Shifts a DateTime from the system's timezone to UTC.
*
* @param dateTime The DateTime in local system's timezone.
* @return shifted DateTime in UTC
*/
public static final DateTime shiftSystemZoneToUtc(final DateTime dateTime) {
return dateTime
.plusSeconds(ZonedDateTime.now().getOffset().getTotalSeconds())
.withZone(DateTimeZone.UTC);
}

/**
* Shifts a time to from the system's timezone to CET. It assumes the time is for the current
* date.
*
* @param time Time in system's timezone, formatted as HH:mm
* @return Time in CET, formatted as HH:mm
*/
public static String shiftSystemZoneToCET(final String time) {
return DateTimeHelper.shiftTimeToOtherZone(time, true);
}

/**
* Shifts a time to from CET to the system's timezone. It assumes the time is for the current
* date.
*
* @param time Time in system's timezone, formatted as HH:mm
* @return Time in CET, formatted as HH:mm
*/
public static String shiftCETToSystemZone(final String time) {
return DateTimeHelper.shiftTimeToOtherZone(time, false);
return getSunriseSunsetTime(actionTimeType, date, location);
}

/**
Expand All @@ -281,40 +245,26 @@ public static String shiftCETToSystemZone(final String time) {
*/
private static String shiftTimeToOtherZone(final String time, final boolean positiveShift) {
// Extract hours and minutes from the time parameter
final DateTimeFormatter timeFormatter = DateTimeFormat.forPattern(TIME_FORMAT);
final DateTime parsedTime = timeFormatter.parseDateTime(time);
final DateTimeFormatter timeFormatter = DateTimeFormatter.ofPattern(TIME_FORMAT);
final LocalTime parsedTime = LocalTime.parse(time, timeFormatter);

// Determine current CET offset in hours for the system timezone.
final int UTCOffsetForCET = DateTimeZone.forID(CET_TIMEZONE).getOffset(new DateTime());
final int UTCOffsetForSystem = DateTimeZone.getDefault().getOffset(new DateTime());
final int UTCOffsetForCET =
ZoneId.of(CET_TIMEZONE).getRules().getOffset(Instant.now()).getTotalSeconds();
final int UTCOffsetForSystem =
ZoneId.systemDefault().getRules().getOffset(Instant.now()).getTotalSeconds();
final int offsetHours =
(UTCOffsetForCET - UTCOffsetForSystem) / (3600 * 1000) * (positiveShift ? 1 : -1);
(UTCOffsetForCET - UTCOffsetForSystem) / (3600) * (positiveShift ? 1 : -1);

// Add offset
final DateTime shiftedTime =
new DateTime()
.withTime(parsedTime.getHourOfDay(), parsedTime.getMinuteOfHour(), 0, 0)
final ZonedDateTime shiftedTime =
ZonedDateTime.now()
.withHour(parsedTime.getHour())
.withMinute(parsedTime.getMinute())
.withSecond(0)
.withNano(0)
.plusHours(offsetHours);

return timeFormatter.print(shiftedTime);
}

public static ZonedDateTime dateTimeToZonedDateTime(final DateTime dateTime) {
if (dateTime == null) {
return null;
}

return dateTime.toGregorianCalendar().toZonedDateTime();
}

private static DateTime zonedDateTimeToDateTime(final ZonedDateTime zonedDateTime) {
if (zonedDateTime == null) {
return null;
}

final long millis = zonedDateTime.toInstant().toEpochMilli();
final DateTimeZone dateTimeZone =
DateTimeZone.forTimeZone(TimeZone.getTimeZone(zonedDateTime.getZone()));
return new DateTime(millis, dateTimeZone);
return timeFormatter.format(shiftedTime);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
import org.apache.commons.codec.DecoderException;
import org.apache.commons.codec.binary.Hex;
import org.apache.commons.lang3.StringUtils;
import org.joda.time.DateTime;
import org.opensmartgridplatform.shared.utils.JavaTimeHelpers;

public class ReadSettingsHelper {
/**
Expand Down Expand Up @@ -58,8 +58,8 @@ public static Boolean getBoolean(
* @param key The key in the settings for the date time.
* @return The date time.
*/
public static DateTime getDate(final Map<String, String> settings, final String key) {
return getDate(settings, key, DateTime.now());
public static ZonedDateTime getDate(final Map<String, String> settings, final String key) {
return getDate(settings, key, ZonedDateTime.now());
}

/**
Expand All @@ -70,13 +70,12 @@ public static DateTime getDate(final Map<String, String> settings, final String
* @param defaultDate The default date to return.
* @return The date time.
*/
public static DateTime getDate(
final Map<String, String> settings, final String key, final DateTime defaultDate) {
public static ZonedDateTime getDate(
final Map<String, String> settings, final String key, final ZonedDateTime defaultDate) {
if (!settings.containsKey(key) || StringUtils.isBlank(settings.get(key))) {
return defaultDate;
}

return DateTime.parse(settings.get(key));
return JavaTimeHelpers.parseToZonedDateTime(settings.get(key));
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,20 @@

import static org.assertj.core.api.Assertions.assertThat;

import org.joda.time.DateTime;
import org.joda.time.DateTimeZone;
import java.time.ZoneId;
import java.time.ZonedDateTime;
import org.junit.jupiter.api.Test;

public class TestGetDateTime {

private DateTimeZone cetTime = DateTimeHelper.getCentralEuropeanTimeZone();
private final ZoneId cetTime = DateTimeHelper.getCentralEuropeanTimeZone();

@Test
public void testGetDateTime() {
final DateTime nowPlus4 = new DateTime(this.cetTime).plusMinutes(4);
final DateTime nowPlus6 = new DateTime(this.cetTime).plusMinutes(6);
final ZonedDateTime nowPlus4 = ZonedDateTime.now(this.cetTime).plusMinutes(4);
final ZonedDateTime nowPlus6 = ZonedDateTime.now(this.cetTime).plusMinutes(6);

final DateTime dt = DateTimeHelper.getDateTime("now + 5 minutes");
final ZonedDateTime dt = DateTimeHelper.getDateTime("now + 5 minutes");

assertThat(dt).isStrictlyBetween(nowPlus4, nowPlus6);
}
Expand Down
2 changes: 1 addition & 1 deletion integration-tests/cucumber-tests-execution/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ SPDX-License-Identifier: Apache-2.0
<parent>
<groupId>org.opensmartgridplatform</groupId>
<artifactId>parent-integration-tests</artifactId>
<version>5.45.0-SNAPSHOT</version>
<version>5.49.0-SNAPSHOT</version>
<relativePath>../parent-integration-tests/pom.xml</relativePath>
</parent>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
import java.util.stream.Collectors;
import junit.runner.Version;
import org.apache.tools.ant.taskdefs.optional.junit.XMLJUnitResultFormatter;
import org.joda.time.DateTimeZone;
import org.junit.runner.Computer;
import org.junit.runner.Description;
import org.junit.runner.JUnitCore;
Expand Down Expand Up @@ -48,7 +47,6 @@ public abstract class AppBase {
public static int run(final AppBase app, final String[] testClasses, final String... args) {
// Ensure the tests are executed in UTC time
TimeZone.setDefault(TimeZone.getTimeZone("UTC"));
DateTimeZone.setDefault(DateTimeZone.UTC);

final CmdLineParser p = new CmdLineParser(app);
try {
Expand Down
2 changes: 1 addition & 1 deletion integration-tests/cucumber-tests-platform-common/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ SPDX-License-Identifier: Apache-2.0
<parent>
<groupId>org.opensmartgridplatform</groupId>
<artifactId>parent-integration-tests</artifactId>
<version>5.45.0-SNAPSHOT</version>
<version>5.49.0-SNAPSHOT</version>
<relativePath>../parent-integration-tests/pom.xml</relativePath>
</parent>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import io.cucumber.java.en.Given;
import io.cucumber.java.en.Then;
import java.lang.reflect.Field;
import java.util.Date;
import java.time.Instant;
import java.util.Map;
import java.util.concurrent.TimeUnit;
import org.junit.jupiter.api.Assertions;
Expand Down Expand Up @@ -38,8 +38,8 @@ public ResponseData aResponseDataRecord(final Map<String, String> settings) {
final ResponseData responseData =
this.responseDataRepository.save(new ResponseDataBuilder().fromSettings(settings).build());

final Date creationTime =
DateTimeHelper.getDateTime(settings.get(PlatformKeys.KEY_CREATION_TIME)).toDate();
final Instant creationTime =
DateTimeHelper.getDateTime(settings.get(PlatformKeys.KEY_CREATION_TIME)).toInstant();

LOGGER.info(
"Creating response data record with correlationUid: {} and creationTime: {}",
Expand Down
Loading

0 comments on commit 476bac5

Please sign in to comment.