Skip to content

Commit

Permalink
Merge branch 'release/2023.5.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
sfeilmeier committed May 1, 2023
2 parents 20ec6c1 + ded2eb3 commit 1a9ce01
Show file tree
Hide file tree
Showing 197 changed files with 5,799 additions and 1,239 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ jobs:
key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }}
restore-keys: ${{ runner.os }}-maven-

# Uploads Checkstyle errors & warnings as GitHub Annotations
- uses: kiancross/checkstyle-annotations-action@v1

- name: Build all Java packages
run: ./gradlew build

Expand Down
6 changes: 3 additions & 3 deletions .gitpod.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,16 @@ ENV TRIGGER_REBUILD 4
RUN npm install -g @angular/cli

# Install odoo
ENV ODOO_VERSION 14.0
ENV ODOO_VERSION 15.0
ENV ODOO_RELEASE latest
RUN curl -o odoo.deb -sSL http://nightly.odoo.com/${ODOO_VERSION}/nightly/deb/odoo_${ODOO_VERSION}.${ODOO_RELEASE}_all.deb \
&& sudo apt-get update \
&& sudo apt-get -y install --no-install-recommends ./odoo.deb \
&& sudo rm -rf /var/lib/apt/lists/* odoo.deb

# Install wkhtmltopdf
ENV WKHTMLTOPDF_VERSION 0.12.6-1
ENV WKHTMLTOPDF_RELEASE focal_amd64
ENV WKHTMLTOPDF_VERSION 0.12.6.1-2
ENV WKHTMLTOPDF_RELEASE jammy_amd64
RUN curl -o wkhtmltox.deb -sSL https://github.com/wkhtmltopdf/packaging/releases/download/${WKHTMLTOPDF_VERSION}/wkhtmltox_${WKHTMLTOPDF_VERSION}.${WKHTMLTOPDF_RELEASE}.deb \
&& sudo apt-get update \
&& sudo apt-get install -y ./wkhtmltox.deb \
Expand Down
6 changes: 3 additions & 3 deletions .gitpod.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ tasks:
cd /workspace/odoo
mkdir -p addons-available addons-enabled
cd addons-available
git clone --depth=1 -b 14.0 https://github.com/OCA/partner-contact
git clone --depth=1 -b 14.0 https://github.com/OCA/web.git
git clone --depth=1 -b 14.0 https://github.com/OpenEMS/odoo-openems.git
git clone --depth=1 -b 15.0 https://github.com/OCA/partner-contact
git clone --depth=1 -b 15.0 https://github.com/OCA/web.git
git clone --depth=1 -b 15.0 https://github.com/OpenEMS/odoo-openems.git
cd ../addons-enabled
ln -s ../addons-available/partner-contact/partner_firstname
ln -s ../addons-available/web/web_m2x_options
Expand Down
6 changes: 3 additions & 3 deletions cnf/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,13 @@
<!-- Used by com.influxdb: influxdb -->
<groupId>com.squareup.okhttp3</groupId>
<artifactId>logging-interceptor</artifactId>
<version>4.10.0</version>
<version>4.11.0</version>
</dependency>
<dependency>
<!-- Used by com.influxdb: influxdb -->
<groupId>com.squareup.okhttp3</groupId>
<artifactId>okhttp</artifactId>
<version>4.10.0</version>
<version>4.11.0</version>
</dependency>
<dependency>
<!-- Used by com.squareup.okhttp3: okhttp -->
Expand Down Expand Up @@ -264,7 +264,7 @@
<dependency>
<groupId>org.dhatim</groupId>
<artifactId>fastexcel</artifactId>
<version>0.15.2</version>
<version>0.15.3</version>
</dependency>
<dependency>
<!-- Eclipse Paho MQTTv5 Client -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public class OpenemsConstants {
* <p>
* This is the month of the release.
*/
public static final short VERSION_MINOR = 4;
public static final short VERSION_MINOR = 5;

/**
* The patch version of OpenEMS.
Expand Down
3 changes: 2 additions & 1 deletion io.openems.common/src/io/openems/common/types/SystemLog.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import com.google.gson.JsonObject;

import io.openems.common.exceptions.OpenemsError.OpenemsNamedException;
import io.openems.common.utils.DateUtils;
import io.openems.common.utils.JsonUtils;

/**
Expand Down Expand Up @@ -109,7 +110,7 @@ public JsonObject toJson() {
* @throws OpenemsNamedException on error
*/
public static SystemLog fromJsonObject(JsonObject j) throws OpenemsNamedException {
var time = ZonedDateTime.parse(JsonUtils.getAsString(j, "time"), SystemLog.FORMAT);
var time = DateUtils.parseZonedDateTimeOrError(JsonUtils.getAsString(j, "time"), SystemLog.FORMAT);
var level = Level.valueOf(JsonUtils.getAsString(j, "level").toUpperCase());
var source = JsonUtils.getAsString(j, "source");
var message = JsonUtils.getAsString(j, "message");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package io.openems.common.utils;

import java.util.Objects;
import java.util.function.Predicate;
import java.util.stream.Collectors;
import java.util.stream.Stream;

Expand Down Expand Up @@ -79,6 +80,7 @@ public static String generateReferenceTargetFilter(String pid, boolean forceEnab
// add filter for given Component-IDs
String idsFilter = Stream.of(ids) //
.filter(Objects::nonNull) //
.filter(Predicate.not(String::isBlank)) //
.map(id -> "(id=" + id + ")") //
.collect(Collectors.joining());
if (!idsFilter.isEmpty()) {
Expand Down
228 changes: 228 additions & 0 deletions io.openems.common/src/io/openems/common/utils/DateUtils.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,27 @@
package io.openems.common.utils;

import java.time.LocalDate;
import java.time.LocalTime;
import java.time.ZoneOffset;
import java.time.ZonedDateTime;
import java.time.format.DateTimeFormatter;
import java.time.format.DateTimeParseException;
import java.util.function.BiFunction;

import io.openems.common.exceptions.OpenemsException;

public class DateUtils {

/**
* Day-Month-Year with dots separated {@link DateTimeFormatter}.
*/
public static final DateTimeFormatter DMY_FORMATTER = DateTimeFormatter.ofPattern("dd.MM.yyyy");

/**
* {@link DateTimeFormatter} with inclusively 24:00 which is converted to 00:00.
*/
public static final DateTimeFormatter TIME_FORMATTER = DateTimeFormatter.ofPattern("HH:mm");

private DateUtils() {
}

Expand All @@ -22,4 +37,217 @@ public static void assertSameTimezone(ZonedDateTime date1, ZonedDateTime date2)
throw new OpenemsException("FromDate and ToDate need to be in the same timezone!");
}
}

/**
* Parses a string to an {@link ZonedDateTime} or returns null.
*
* <p>
* See {@link ZonedDateTime#parse(CharSequence)}
*
* @param date the string value
* @return a {@link ZonedDateTime} or null
*/
public static ZonedDateTime parseZonedDateTimeOrNull(String date) {
return parseZonedDateTimeOrNull(date, DateTimeFormatter.ISO_ZONED_DATE_TIME);
}

/**
* Parses a string to an {@link ZonedDateTime} or returns null.
*
* <p>
* See {@link ZonedDateTime#parse(CharSequence, DateTimeFormatter)}
*
* @param date the string value
* @param formatter the formatter to use, not null
* @return a {@link ZonedDateTime} or null
*/
public static ZonedDateTime parseZonedDateTimeOrNull(String date, DateTimeFormatter formatter) {
return parseDateOrNull(ZonedDateTime::parse, date, formatter);
}

/**
* Parses a string to an {@link ZonedDateTime} or throws an error.
*
* <p>
* See {@link ZonedDateTime#parse(CharSequence)}
*
* @param date the string value
* @return a {@link ZonedDateTime}
* @throws OpenemsException on error
*/
public static ZonedDateTime parseZonedDateTimeOrError(String date) throws OpenemsException {
return parseZonedDateTimeOrError(date, DateTimeFormatter.ISO_ZONED_DATE_TIME);
}

/**
* Parses a string to an {@link ZonedDateTime} or throws an error.
*
* <p>
* See {@link ZonedDateTime#parse(CharSequence, DateTimeFormatter)}
*
* @param date the string value
* @param formatter the formatter to use, not null
* @return a {@link ZonedDateTime}
* @throws OpenemsException on error
*/
public static ZonedDateTime parseZonedDateTimeOrError(String date, DateTimeFormatter formatter)
throws OpenemsException {
return parseDateOrError(ZonedDateTime.class.getSimpleName(), ZonedDateTime::parse, date, formatter);
}

/**
* Parses a string to an {@link LocalDate} or returns null.
*
* <p>
* See {@link LocalDate#parse(CharSequence)}
*
* @param date the string value
* @return a {@link LocalDate} or null
*/
public static LocalDate parseLocalDateOrNull(String date) {
return parseLocalDateOrNull(date, DateTimeFormatter.ISO_LOCAL_DATE);
}

/**
* Parses a string to an {@link LocalDate} or returns null.
*
* <p>
* See {@link LocalDate#parse(CharSequence, DateTimeFormatter)}
*
* @param date the string value
* @param formatter the formatter to use, not null
* @return a {@link LocalDate} or null
*/
public static LocalDate parseLocalDateOrNull(String date, DateTimeFormatter formatter) {
return parseDateOrNull(LocalDate::parse, date, formatter);
}

/**
* Parses a string to an {@link LocalDate} or throws an error.
*
* <p>
* See {@link LocalDate#parse(CharSequence)}
*
* @param date the string value
* @return a {@link LocalDate}
* @throws OpenemsException on error
*/
public static LocalDate parseLocalDateOrError(String date) throws OpenemsException {
return parseLocalDateOrError(date, DateTimeFormatter.ISO_LOCAL_DATE);
}

/**
* Parses a string to an {@link LocalDate} or throws an error.
*
* <p>
* See {@link LocalDate#parse(CharSequence, DateTimeFormatter)}
*
* @param date the string value
* @param formatter the formatter to use, not null
* @return a {@link LocalDate}
* @throws OpenemsException on error
*/
public static LocalDate parseLocalDateOrError(String date, DateTimeFormatter formatter) throws OpenemsException {
return parseDateOrError(LocalDate.class.getSimpleName(), LocalDate::parse, date, formatter);
}

/**
* Parses a string to an {@link LocalTime} or returns null.
*
* <p>
* See {@link LocalTime#parse(CharSequence)}
*
* @param time the string value
* @return a {@link LocalTime} or null
*/
public static LocalTime parseLocalTimeOrNull(String time) {
return parseLocalTimeOrNull(time, DateTimeFormatter.ISO_LOCAL_TIME);
}

/**
* Parses a string to an {@link LocalTime} or returns null.
*
* <p>
* See {@link LocalTime#parse(CharSequence, DateTimeFormatter)}
*
* @param time the string value
* @param formatter the formatter to use, not null
* @return a {@link LocalTime} or null
*/
public static LocalTime parseLocalTimeOrNull(String time, DateTimeFormatter formatter) {
return parseDateOrNull(LocalTime::parse, time, formatter);
}

/**
* Parses a string to an {@link LocalTime} or throws an error.
*
* <p>
* See {@link LocalTime#parse(CharSequence)}
*
* @param time the string value
* @return a {@link LocalTime}
* @throws OpenemsException on error
*/
public static LocalTime parseLocalTimeOrError(String time) throws OpenemsException {
return parseLocalTimeOrError(time, DateTimeFormatter.ISO_LOCAL_TIME);
}

/**
* Parses a string to an {@link LocalTime} or throws an error.
*
* <p>
* See {@link LocalTime#parse(CharSequence, DateTimeFormatter)}
*
* @param time the string value
* @param formatter the formatter to use, not null
* @return a {@link LocalTime}
* @throws OpenemsException on error
*/
public static LocalTime parseLocalTimeOrError(String time, DateTimeFormatter formatter) throws OpenemsException {
return parseDateOrError(LocalTime.class.getSimpleName(), LocalTime::parse, time, formatter);
}

private static final <T> T parseDateOrNull(//
BiFunction<String, DateTimeFormatter, T> parser, //
String value, //
DateTimeFormatter formatter //
) {
if (value == null || value.isBlank()) {
return null;
}
try {
return parser.apply(value, formatter);
} catch (DateTimeParseException e) {
// unable to parse date
} catch (RuntimeException e) {
// unexpected error
e.printStackTrace();
}
return null;
}

private static final <T> T parseDateOrError(//
String variableName, //
BiFunction<String, DateTimeFormatter, T> parser, //
String value, //
DateTimeFormatter formatter //
) throws OpenemsException {
if (value == null) {
throw new OpenemsException(variableName + " is null");
}
if (value.isBlank()) {
throw new OpenemsException(variableName + " is blank");
}
try {
return parser.apply(value, formatter);
} catch (DateTimeParseException e) {
// unable to parse date
throw new OpenemsException("Unable to parse " + variableName + " [" + value + "] " + e.getMessage());
} catch (RuntimeException e) {
// unexpected error
throw new OpenemsException(
"Unexpected error while trying to parse " + variableName + " [" + value + "] " + e.getMessage());
}
}

}
Loading

0 comments on commit 1a9ce01

Please sign in to comment.