From: lsiepel Date: Fri, 27 Oct 2023 18:52:54 +0000 (+0200) Subject: [enturno] Remove org.apache.commons (#14406) X-Git-Url: https://git.basschouten.com/?a=commitdiff_plain;h=ab5ebbc41b0429ef05b57c486144803ad08d14b9;p=openhab-addons.git [enturno] Remove org.apache.commons (#14406) * Remove org.apache.commons * Fix warnings Also-by: Jacob Laursen Signed-off-by: Leo Siepel --- diff --git a/bundles/org.openhab.binding.enturno/src/main/java/org/openhab/binding/enturno/internal/EnturNoHandler.java b/bundles/org.openhab.binding.enturno/src/main/java/org/openhab/binding/enturno/internal/EnturNoHandler.java index a89e5bcefa..853f25fa8b 100644 --- a/bundles/org.openhab.binding.enturno/src/main/java/org/openhab/binding/enturno/internal/EnturNoHandler.java +++ b/bundles/org.openhab.binding.enturno/src/main/java/org/openhab/binding/enturno/internal/EnturNoHandler.java @@ -26,7 +26,7 @@ import org.eclipse.jetty.client.HttpClient; import org.openhab.binding.enturno.internal.connection.EnturCommunicationException; import org.openhab.binding.enturno.internal.connection.EnturConfigurationException; import org.openhab.binding.enturno.internal.connection.EnturNoConnection; -import org.openhab.binding.enturno.internal.model.simplified.DisplayData; +import org.openhab.binding.enturno.internal.dto.simplified.DisplayData; import org.openhab.core.library.types.DateTimeType; import org.openhab.core.library.types.StringType; import org.openhab.core.thing.Channel; diff --git a/bundles/org.openhab.binding.enturno/src/main/java/org/openhab/binding/enturno/internal/connection/EnturNoConnection.java b/bundles/org.openhab.binding.enturno/src/main/java/org/openhab/binding/enturno/internal/connection/EnturNoConnection.java index 8d9b01fe5e..6ed517a607 100644 --- a/bundles/org.openhab.binding.enturno/src/main/java/org/openhab/binding/enturno/internal/connection/EnturNoConnection.java +++ b/bundles/org.openhab.binding.enturno/src/main/java/org/openhab/binding/enturno/internal/connection/EnturNoConnection.java @@ -32,7 +32,6 @@ import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeoutException; import java.util.stream.Collectors; -import org.apache.commons.lang3.StringUtils; import org.eclipse.jdt.annotation.NonNullByDefault; import org.eclipse.jdt.annotation.Nullable; import org.eclipse.jetty.client.HttpClient; @@ -42,10 +41,11 @@ import org.eclipse.jetty.client.util.StringContentProvider; import org.eclipse.jetty.http.HttpHeader; import org.openhab.binding.enturno.internal.EnturNoConfiguration; import org.openhab.binding.enturno.internal.EnturNoHandler; -import org.openhab.binding.enturno.internal.model.EnturJsonData; -import org.openhab.binding.enturno.internal.model.estimated.EstimatedCalls; -import org.openhab.binding.enturno.internal.model.simplified.DisplayData; -import org.openhab.binding.enturno.internal.model.stopplace.StopPlace; +import org.openhab.binding.enturno.internal.dto.EnturJsonData; +import org.openhab.binding.enturno.internal.dto.estimated.EstimatedCalls; +import org.openhab.binding.enturno.internal.dto.simplified.DisplayData; +import org.openhab.binding.enturno.internal.dto.stopplace.StopPlace; +import org.openhab.binding.enturno.internal.util.DateUtil; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -189,10 +189,8 @@ public class EnturNoConnection { } private List processData(StopPlace stopPlace, String lineCode) { - Map> departures = stopPlace.estimatedCalls.stream() - .filter(call -> StringUtils.equalsIgnoreCase( - StringUtils.trimToEmpty(call.serviceJourney.journeyPattern.line.publicCode), - StringUtils.trimToEmpty(lineCode))) + Map> departures = stopPlace.estimatedCalls.stream().filter( + call -> call.serviceJourney.journeyPattern.line.publicCode.strip().equalsIgnoreCase(lineCode.strip())) .collect(groupingBy(call -> call.quay.id)); List processedData = new ArrayList<>(); @@ -214,8 +212,8 @@ public class EnturNoConnection { List keys = new ArrayList<>(departures.keySet()); DisplayData processedData = new DisplayData(); List quayCalls = departures.get(keys.get(quayIndex)); - List departureTimes = quayCalls.stream().map(eq -> eq.expectedDepartureTime).map(this::getIsoDateTime) - .collect(Collectors.toList()); + List departureTimes = quayCalls.stream().map(eq -> eq.expectedDepartureTime) + .map(DateUtil::getIsoDateTime).collect(Collectors.toList()); List estimatedFlags = quayCalls.stream().map(es -> es.realtime).collect(Collectors.toList()); @@ -233,13 +231,4 @@ public class EnturNoConnection { processedData.transportMode = stopPlace.transportMode; return processedData; } - - private String getIsoDateTime(String dateTimeWithoutColonInZone) { - String dateTime = StringUtils.substringBeforeLast(dateTimeWithoutColonInZone, "+"); - String offset = StringUtils.substringAfterLast(dateTimeWithoutColonInZone, "+"); - - StringBuilder builder = new StringBuilder(); - return builder.append(dateTime).append("+").append(StringUtils.substring(offset, 0, 2)).append(":00") - .toString(); - } } diff --git a/bundles/org.openhab.binding.enturno/src/main/java/org/openhab/binding/enturno/internal/dto/Data.java b/bundles/org.openhab.binding.enturno/src/main/java/org/openhab/binding/enturno/internal/dto/Data.java new file mode 100644 index 0000000000..c6a37b9b87 --- /dev/null +++ b/bundles/org.openhab.binding.enturno/src/main/java/org/openhab/binding/enturno/internal/dto/Data.java @@ -0,0 +1,24 @@ +/** + * Copyright (c) 2010-2023 Contributors to the openHAB project + * + * See the NOTICE file(s) distributed with this work for additional + * information. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.openhab.binding.enturno.internal.dto; + +import org.openhab.binding.enturno.internal.dto.stopplace.StopPlace; + +/** + * Generated Plain Old Java Objects class for {@link Data} from JSON. + * + * @author Michal Kloc - Initial contribution + */ +public class Data { + public StopPlace stopPlace; +} diff --git a/bundles/org.openhab.binding.enturno/src/main/java/org/openhab/binding/enturno/internal/dto/EnturData.java b/bundles/org.openhab.binding.enturno/src/main/java/org/openhab/binding/enturno/internal/dto/EnturData.java new file mode 100644 index 0000000000..04293d790d --- /dev/null +++ b/bundles/org.openhab.binding.enturno/src/main/java/org/openhab/binding/enturno/internal/dto/EnturData.java @@ -0,0 +1,22 @@ +/** + * Copyright (c) 2010-2023 Contributors to the openHAB project + * + * See the NOTICE file(s) distributed with this work for additional + * information. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.openhab.binding.enturno.internal.dto; + +/** + * Generated Plain Old Java Objects class for {@link Data} from JSON. + * + * @author Michal Kloc - Initial contribution + */ +public class EnturData { + public Data data; +} diff --git a/bundles/org.openhab.binding.enturno/src/main/java/org/openhab/binding/enturno/internal/dto/EnturJsonData.java b/bundles/org.openhab.binding.enturno/src/main/java/org/openhab/binding/enturno/internal/dto/EnturJsonData.java new file mode 100644 index 0000000000..f175af3fca --- /dev/null +++ b/bundles/org.openhab.binding.enturno/src/main/java/org/openhab/binding/enturno/internal/dto/EnturJsonData.java @@ -0,0 +1,22 @@ +/** + * Copyright (c) 2010-2023 Contributors to the openHAB project + * + * See the NOTICE file(s) distributed with this work for additional + * information. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.openhab.binding.enturno.internal.dto; + +/** + * {@link EnturJsonData} is a root level class to holding reference of data generated from JSON. + * + * @author Michal Kloc - Initial contribution + */ +public class EnturJsonData { + public Data data; +} diff --git a/bundles/org.openhab.binding.enturno/src/main/java/org/openhab/binding/enturno/internal/dto/estimated/DestinationDisplay.java b/bundles/org.openhab.binding.enturno/src/main/java/org/openhab/binding/enturno/internal/dto/estimated/DestinationDisplay.java new file mode 100644 index 0000000000..4818da5240 --- /dev/null +++ b/bundles/org.openhab.binding.enturno/src/main/java/org/openhab/binding/enturno/internal/dto/estimated/DestinationDisplay.java @@ -0,0 +1,22 @@ +/** + * Copyright (c) 2010-2023 Contributors to the openHAB project + * + * See the NOTICE file(s) distributed with this work for additional + * information. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.openhab.binding.enturno.internal.dto.estimated; + +/** + * Generated Plain Old Java Objects class for {@link DestinationDisplay} from JSON. + * + * @author Michal Kloc - Initial contribution + */ +public class DestinationDisplay { + public String frontText; +} diff --git a/bundles/org.openhab.binding.enturno/src/main/java/org/openhab/binding/enturno/internal/dto/estimated/EstimatedCalls.java b/bundles/org.openhab.binding.enturno/src/main/java/org/openhab/binding/enturno/internal/dto/estimated/EstimatedCalls.java new file mode 100644 index 0000000000..c3a056c05c --- /dev/null +++ b/bundles/org.openhab.binding.enturno/src/main/java/org/openhab/binding/enturno/internal/dto/estimated/EstimatedCalls.java @@ -0,0 +1,42 @@ +/** + * Copyright (c) 2010-2023 Contributors to the openHAB project + * + * See the NOTICE file(s) distributed with this work for additional + * information. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.openhab.binding.enturno.internal.dto.estimated; + +/** + * Generated Plain Old Java Objects class for {@link EstimatedCalls} from JSON. + * + * @author Michal Kloc - Initial contribution + */ +public class EstimatedCalls { + public String aimedArrivalTime; + + public String date; + + public String realtime; + + public String expectedDepartureTime; + + public String forAlighting; + + public DestinationDisplay destinationDisplay; + + public String forBoarding; + + public ServiceJourney serviceJourney; + + public Quay quay; + + public String aimedDepartureTime; + + public String expectedArrivalTime; +} diff --git a/bundles/org.openhab.binding.enturno/src/main/java/org/openhab/binding/enturno/internal/dto/estimated/JourneyPattern.java b/bundles/org.openhab.binding.enturno/src/main/java/org/openhab/binding/enturno/internal/dto/estimated/JourneyPattern.java new file mode 100644 index 0000000000..e5ba379f33 --- /dev/null +++ b/bundles/org.openhab.binding.enturno/src/main/java/org/openhab/binding/enturno/internal/dto/estimated/JourneyPattern.java @@ -0,0 +1,22 @@ +/** + * Copyright (c) 2010-2023 Contributors to the openHAB project + * + * See the NOTICE file(s) distributed with this work for additional + * information. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.openhab.binding.enturno.internal.dto.estimated; + +/** + * Generated Plain Old Java Objects class for {@link JourneyPattern} from JSON. + * + * @author Michal Kloc - Initial contribution + */ +public class JourneyPattern { + public Line line; +} diff --git a/bundles/org.openhab.binding.enturno/src/main/java/org/openhab/binding/enturno/internal/dto/estimated/Line.java b/bundles/org.openhab.binding.enturno/src/main/java/org/openhab/binding/enturno/internal/dto/estimated/Line.java new file mode 100644 index 0000000000..db43d2ea0c --- /dev/null +++ b/bundles/org.openhab.binding.enturno/src/main/java/org/openhab/binding/enturno/internal/dto/estimated/Line.java @@ -0,0 +1,28 @@ +/** + * Copyright (c) 2010-2023 Contributors to the openHAB project + * + * See the NOTICE file(s) distributed with this work for additional + * information. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.openhab.binding.enturno.internal.dto.estimated; + +/** + * Generated Plain Old Java Objects class for {@link Line} from JSON. + * + * @author Michal Kloc - Initial contribution + */ +public class Line { + public String name; + + public String transportMode; + + public String publicCode; + + public String id; +} diff --git a/bundles/org.openhab.binding.enturno/src/main/java/org/openhab/binding/enturno/internal/dto/estimated/Quay.java b/bundles/org.openhab.binding.enturno/src/main/java/org/openhab/binding/enturno/internal/dto/estimated/Quay.java new file mode 100644 index 0000000000..310ff8e323 --- /dev/null +++ b/bundles/org.openhab.binding.enturno/src/main/java/org/openhab/binding/enturno/internal/dto/estimated/Quay.java @@ -0,0 +1,24 @@ +/** + * Copyright (c) 2010-2023 Contributors to the openHAB project + * + * See the NOTICE file(s) distributed with this work for additional + * information. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.openhab.binding.enturno.internal.dto.estimated; + +/** + * Generated Plain Old Java Objects class for {@link Quay} from JSON. + * + * @author Michal Kloc - Initial contribution + */ +public class Quay { + public String publicCode; + + public String id; +} diff --git a/bundles/org.openhab.binding.enturno/src/main/java/org/openhab/binding/enturno/internal/dto/estimated/ServiceJourney.java b/bundles/org.openhab.binding.enturno/src/main/java/org/openhab/binding/enturno/internal/dto/estimated/ServiceJourney.java new file mode 100644 index 0000000000..e5f35fdc79 --- /dev/null +++ b/bundles/org.openhab.binding.enturno/src/main/java/org/openhab/binding/enturno/internal/dto/estimated/ServiceJourney.java @@ -0,0 +1,22 @@ +/** + * Copyright (c) 2010-2023 Contributors to the openHAB project + * + * See the NOTICE file(s) distributed with this work for additional + * information. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.openhab.binding.enturno.internal.dto.estimated; + +/** + * Generated Plain Old Java Objects class for {@link ServiceJourney} from JSON. + * + * @author Michal Kloc - Initial contribution + */ +public class ServiceJourney { + public JourneyPattern journeyPattern; +} diff --git a/bundles/org.openhab.binding.enturno/src/main/java/org/openhab/binding/enturno/internal/dto/simplified/DisplayData.java b/bundles/org.openhab.binding.enturno/src/main/java/org/openhab/binding/enturno/internal/dto/simplified/DisplayData.java new file mode 100644 index 0000000000..2ed9afd13b --- /dev/null +++ b/bundles/org.openhab.binding.enturno/src/main/java/org/openhab/binding/enturno/internal/dto/simplified/DisplayData.java @@ -0,0 +1,36 @@ +/** + * Copyright (c) 2010-2023 Contributors to the openHAB project + * + * See the NOTICE file(s) distributed with this work for additional + * information. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.openhab.binding.enturno.internal.dto.simplified; + +import java.util.List; + +/** + * {@link DisplayData} is a Plain Old Java Objects class to wrap only needed data after processing API call results. + * + * @author Michal Kloc - Initial contribution + */ +public class DisplayData { + public String stopPlaceId; + + public String stopName; + + public String transportMode; + + public String lineCode; + + public String frontText; + + public List departures; + + public List estimatedFlags; +} diff --git a/bundles/org.openhab.binding.enturno/src/main/java/org/openhab/binding/enturno/internal/dto/stopplace/StopPlace.java b/bundles/org.openhab.binding.enturno/src/main/java/org/openhab/binding/enturno/internal/dto/stopplace/StopPlace.java new file mode 100644 index 0000000000..7881e29a1b --- /dev/null +++ b/bundles/org.openhab.binding.enturno/src/main/java/org/openhab/binding/enturno/internal/dto/stopplace/StopPlace.java @@ -0,0 +1,30 @@ +/** + * Copyright (c) 2010-2023 Contributors to the openHAB project + * + * See the NOTICE file(s) distributed with this work for additional + * information. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.openhab.binding.enturno.internal.dto.stopplace; + +import org.openhab.binding.enturno.internal.dto.estimated.EstimatedCalls; + +/** + * Generated Plain Old Java Objects class for {@link StopPlace} from JSON. + * + * @author Michal Kloc - Initial contribution + */ +public class StopPlace { + public java.util.List estimatedCalls; + + public String name; + + public String id; + + public String transportMode; +} diff --git a/bundles/org.openhab.binding.enturno/src/main/java/org/openhab/binding/enturno/internal/model/Data.java b/bundles/org.openhab.binding.enturno/src/main/java/org/openhab/binding/enturno/internal/model/Data.java deleted file mode 100644 index f17de89a60..0000000000 --- a/bundles/org.openhab.binding.enturno/src/main/java/org/openhab/binding/enturno/internal/model/Data.java +++ /dev/null @@ -1,24 +0,0 @@ -/** - * Copyright (c) 2010-2023 Contributors to the openHAB project - * - * See the NOTICE file(s) distributed with this work for additional - * information. - * - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License 2.0 which is available at - * http://www.eclipse.org/legal/epl-2.0 - * - * SPDX-License-Identifier: EPL-2.0 - */ -package org.openhab.binding.enturno.internal.model; - -import org.openhab.binding.enturno.internal.model.stopplace.StopPlace; - -/** - * Generated Plain Old Java Objects class for {@link Data} from JSON. - * - * @author Michal Kloc - Initial contribution - */ -public class Data { - public StopPlace stopPlace; -} diff --git a/bundles/org.openhab.binding.enturno/src/main/java/org/openhab/binding/enturno/internal/model/EnturData.java b/bundles/org.openhab.binding.enturno/src/main/java/org/openhab/binding/enturno/internal/model/EnturData.java deleted file mode 100644 index b6d5db3bff..0000000000 --- a/bundles/org.openhab.binding.enturno/src/main/java/org/openhab/binding/enturno/internal/model/EnturData.java +++ /dev/null @@ -1,22 +0,0 @@ -/** - * Copyright (c) 2010-2023 Contributors to the openHAB project - * - * See the NOTICE file(s) distributed with this work for additional - * information. - * - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License 2.0 which is available at - * http://www.eclipse.org/legal/epl-2.0 - * - * SPDX-License-Identifier: EPL-2.0 - */ -package org.openhab.binding.enturno.internal.model; - -/** - * Generated Plain Old Java Objects class for {@link Data} from JSON. - * - * @author Michal Kloc - Initial contribution - */ -public class EnturData { - public Data data; -} diff --git a/bundles/org.openhab.binding.enturno/src/main/java/org/openhab/binding/enturno/internal/model/EnturJsonData.java b/bundles/org.openhab.binding.enturno/src/main/java/org/openhab/binding/enturno/internal/model/EnturJsonData.java deleted file mode 100644 index 446a5ce1a2..0000000000 --- a/bundles/org.openhab.binding.enturno/src/main/java/org/openhab/binding/enturno/internal/model/EnturJsonData.java +++ /dev/null @@ -1,22 +0,0 @@ -/** - * Copyright (c) 2010-2023 Contributors to the openHAB project - * - * See the NOTICE file(s) distributed with this work for additional - * information. - * - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License 2.0 which is available at - * http://www.eclipse.org/legal/epl-2.0 - * - * SPDX-License-Identifier: EPL-2.0 - */ -package org.openhab.binding.enturno.internal.model; - -/** - * {@link EnturJsonData} is a root level class to holding reference of data generated from JSON. - * - * @author Michal Kloc - Initial contribution - */ -public class EnturJsonData { - public Data data; -} diff --git a/bundles/org.openhab.binding.enturno/src/main/java/org/openhab/binding/enturno/internal/model/estimated/DestinationDisplay.java b/bundles/org.openhab.binding.enturno/src/main/java/org/openhab/binding/enturno/internal/model/estimated/DestinationDisplay.java deleted file mode 100644 index d16d3c30a8..0000000000 --- a/bundles/org.openhab.binding.enturno/src/main/java/org/openhab/binding/enturno/internal/model/estimated/DestinationDisplay.java +++ /dev/null @@ -1,22 +0,0 @@ -/** - * Copyright (c) 2010-2023 Contributors to the openHAB project - * - * See the NOTICE file(s) distributed with this work for additional - * information. - * - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License 2.0 which is available at - * http://www.eclipse.org/legal/epl-2.0 - * - * SPDX-License-Identifier: EPL-2.0 - */ -package org.openhab.binding.enturno.internal.model.estimated; - -/** - * Generated Plain Old Java Objects class for {@link DestinationDisplay} from JSON. - * - * @author Michal Kloc - Initial contribution - */ -public class DestinationDisplay { - public String frontText; -} diff --git a/bundles/org.openhab.binding.enturno/src/main/java/org/openhab/binding/enturno/internal/model/estimated/EstimatedCalls.java b/bundles/org.openhab.binding.enturno/src/main/java/org/openhab/binding/enturno/internal/model/estimated/EstimatedCalls.java deleted file mode 100644 index 52f51a7bf9..0000000000 --- a/bundles/org.openhab.binding.enturno/src/main/java/org/openhab/binding/enturno/internal/model/estimated/EstimatedCalls.java +++ /dev/null @@ -1,42 +0,0 @@ -/** - * Copyright (c) 2010-2023 Contributors to the openHAB project - * - * See the NOTICE file(s) distributed with this work for additional - * information. - * - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License 2.0 which is available at - * http://www.eclipse.org/legal/epl-2.0 - * - * SPDX-License-Identifier: EPL-2.0 - */ -package org.openhab.binding.enturno.internal.model.estimated; - -/** - * Generated Plain Old Java Objects class for {@link EstimatedCalls} from JSON. - * - * @author Michal Kloc - Initial contribution - */ -public class EstimatedCalls { - public String aimedArrivalTime; - - public String date; - - public String realtime; - - public String expectedDepartureTime; - - public String forAlighting; - - public DestinationDisplay destinationDisplay; - - public String forBoarding; - - public ServiceJourney serviceJourney; - - public Quay quay; - - public String aimedDepartureTime; - - public String expectedArrivalTime; -} diff --git a/bundles/org.openhab.binding.enturno/src/main/java/org/openhab/binding/enturno/internal/model/estimated/JourneyPattern.java b/bundles/org.openhab.binding.enturno/src/main/java/org/openhab/binding/enturno/internal/model/estimated/JourneyPattern.java deleted file mode 100644 index 39bbcd5331..0000000000 --- a/bundles/org.openhab.binding.enturno/src/main/java/org/openhab/binding/enturno/internal/model/estimated/JourneyPattern.java +++ /dev/null @@ -1,22 +0,0 @@ -/** - * Copyright (c) 2010-2023 Contributors to the openHAB project - * - * See the NOTICE file(s) distributed with this work for additional - * information. - * - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License 2.0 which is available at - * http://www.eclipse.org/legal/epl-2.0 - * - * SPDX-License-Identifier: EPL-2.0 - */ -package org.openhab.binding.enturno.internal.model.estimated; - -/** - * Generated Plain Old Java Objects class for {@link JourneyPattern} from JSON. - * - * @author Michal Kloc - Initial contribution - */ -public class JourneyPattern { - public Line line; -} diff --git a/bundles/org.openhab.binding.enturno/src/main/java/org/openhab/binding/enturno/internal/model/estimated/Line.java b/bundles/org.openhab.binding.enturno/src/main/java/org/openhab/binding/enturno/internal/model/estimated/Line.java deleted file mode 100644 index 068d066552..0000000000 --- a/bundles/org.openhab.binding.enturno/src/main/java/org/openhab/binding/enturno/internal/model/estimated/Line.java +++ /dev/null @@ -1,28 +0,0 @@ -/** - * Copyright (c) 2010-2023 Contributors to the openHAB project - * - * See the NOTICE file(s) distributed with this work for additional - * information. - * - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License 2.0 which is available at - * http://www.eclipse.org/legal/epl-2.0 - * - * SPDX-License-Identifier: EPL-2.0 - */ -package org.openhab.binding.enturno.internal.model.estimated; - -/** - * Generated Plain Old Java Objects class for {@link Line} from JSON. - * - * @author Michal Kloc - Initial contribution - */ -public class Line { - public String name; - - public String transportMode; - - public String publicCode; - - public String id; -} diff --git a/bundles/org.openhab.binding.enturno/src/main/java/org/openhab/binding/enturno/internal/model/estimated/Quay.java b/bundles/org.openhab.binding.enturno/src/main/java/org/openhab/binding/enturno/internal/model/estimated/Quay.java deleted file mode 100644 index 114072440a..0000000000 --- a/bundles/org.openhab.binding.enturno/src/main/java/org/openhab/binding/enturno/internal/model/estimated/Quay.java +++ /dev/null @@ -1,24 +0,0 @@ -/** - * Copyright (c) 2010-2023 Contributors to the openHAB project - * - * See the NOTICE file(s) distributed with this work for additional - * information. - * - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License 2.0 which is available at - * http://www.eclipse.org/legal/epl-2.0 - * - * SPDX-License-Identifier: EPL-2.0 - */ -package org.openhab.binding.enturno.internal.model.estimated; - -/** - * Generated Plain Old Java Objects class for {@link Quay} from JSON. - * - * @author Michal Kloc - Initial contribution - */ -public class Quay { - public String publicCode; - - public String id; -} diff --git a/bundles/org.openhab.binding.enturno/src/main/java/org/openhab/binding/enturno/internal/model/estimated/ServiceJourney.java b/bundles/org.openhab.binding.enturno/src/main/java/org/openhab/binding/enturno/internal/model/estimated/ServiceJourney.java deleted file mode 100644 index 7b7dbb969a..0000000000 --- a/bundles/org.openhab.binding.enturno/src/main/java/org/openhab/binding/enturno/internal/model/estimated/ServiceJourney.java +++ /dev/null @@ -1,22 +0,0 @@ -/** - * Copyright (c) 2010-2023 Contributors to the openHAB project - * - * See the NOTICE file(s) distributed with this work for additional - * information. - * - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License 2.0 which is available at - * http://www.eclipse.org/legal/epl-2.0 - * - * SPDX-License-Identifier: EPL-2.0 - */ -package org.openhab.binding.enturno.internal.model.estimated; - -/** - * Generated Plain Old Java Objects class for {@link ServiceJourney} from JSON. - * - * @author Michal Kloc - Initial contribution - */ -public class ServiceJourney { - public JourneyPattern journeyPattern; -} diff --git a/bundles/org.openhab.binding.enturno/src/main/java/org/openhab/binding/enturno/internal/model/simplified/DisplayData.java b/bundles/org.openhab.binding.enturno/src/main/java/org/openhab/binding/enturno/internal/model/simplified/DisplayData.java deleted file mode 100644 index bf210c3dca..0000000000 --- a/bundles/org.openhab.binding.enturno/src/main/java/org/openhab/binding/enturno/internal/model/simplified/DisplayData.java +++ /dev/null @@ -1,36 +0,0 @@ -/** - * Copyright (c) 2010-2023 Contributors to the openHAB project - * - * See the NOTICE file(s) distributed with this work for additional - * information. - * - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License 2.0 which is available at - * http://www.eclipse.org/legal/epl-2.0 - * - * SPDX-License-Identifier: EPL-2.0 - */ -package org.openhab.binding.enturno.internal.model.simplified; - -import java.util.List; - -/** - * {@link DisplayData} is a Plain Old Java Objects class to wrap only needed data after processing API call results. - * - * @author Michal Kloc - Initial contribution - */ -public class DisplayData { - public String stopPlaceId; - - public String stopName; - - public String transportMode; - - public String lineCode; - - public String frontText; - - public List departures; - - public List estimatedFlags; -} diff --git a/bundles/org.openhab.binding.enturno/src/main/java/org/openhab/binding/enturno/internal/model/stopplace/StopPlace.java b/bundles/org.openhab.binding.enturno/src/main/java/org/openhab/binding/enturno/internal/model/stopplace/StopPlace.java deleted file mode 100644 index 0f0492ae3c..0000000000 --- a/bundles/org.openhab.binding.enturno/src/main/java/org/openhab/binding/enturno/internal/model/stopplace/StopPlace.java +++ /dev/null @@ -1,30 +0,0 @@ -/** - * Copyright (c) 2010-2023 Contributors to the openHAB project - * - * See the NOTICE file(s) distributed with this work for additional - * information. - * - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License 2.0 which is available at - * http://www.eclipse.org/legal/epl-2.0 - * - * SPDX-License-Identifier: EPL-2.0 - */ -package org.openhab.binding.enturno.internal.model.stopplace; - -import org.openhab.binding.enturno.internal.model.estimated.EstimatedCalls; - -/** - * Generated Plain Old Java Objects class for {@link StopPlace} from JSON. - * - * @author Michal Kloc - Initial contribution - */ -public class StopPlace { - public java.util.List estimatedCalls; - - public String name; - - public String id; - - public String transportMode; -} diff --git a/bundles/org.openhab.binding.enturno/src/main/java/org/openhab/binding/enturno/internal/util/DateUtil.java b/bundles/org.openhab.binding.enturno/src/main/java/org/openhab/binding/enturno/internal/util/DateUtil.java new file mode 100644 index 0000000000..4f1be63128 --- /dev/null +++ b/bundles/org.openhab.binding.enturno/src/main/java/org/openhab/binding/enturno/internal/util/DateUtil.java @@ -0,0 +1,51 @@ +/** + * Copyright (c) 2010-2023 Contributors to the openHAB project + * + * See the NOTICE file(s) distributed with this work for additional + * information. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.openhab.binding.enturno.internal.util; + +import java.time.ZonedDateTime; +import java.time.format.DateTimeFormatter; +import java.time.format.DateTimeParseException; + +import org.eclipse.jdt.annotation.NonNullByDefault; + +/** + * EnturNo date utility methods. + * + * @author Jacob Laursen - Initial contribution + */ +@NonNullByDefault +public class DateUtil { + /** + * Converts a zoned date time string that lacks a colon in the zone to an ISO-8601 formatted string. + * + * @param dateTimeWithoutColonInZone + * @return ISO-8601 formatted string + */ + public static String getIsoDateTime(String dateTimeWithoutColonInZone) { + ZonedDateTime zonedDateTime = null; + try { + zonedDateTime = ZonedDateTime.parse(dateTimeWithoutColonInZone); + } catch (DateTimeParseException e) { + // Skip + } + try { + zonedDateTime = ZonedDateTime.parse(dateTimeWithoutColonInZone.replaceAll("(\\d{2})(\\d{2})$", "$1:$2")); + } catch (DateTimeParseException e) { + // Skip + } + if (zonedDateTime != null) { + return DateTimeFormatter.ISO_OFFSET_DATE_TIME.format(zonedDateTime); + } + return dateTimeWithoutColonInZone; + } +} diff --git a/bundles/org.openhab.binding.enturno/src/test/java/org/openhab/binding/enturno/internal/util/DateUtilTest.java b/bundles/org.openhab.binding.enturno/src/test/java/org/openhab/binding/enturno/internal/util/DateUtilTest.java new file mode 100644 index 0000000000..c9ac27df94 --- /dev/null +++ b/bundles/org.openhab.binding.enturno/src/test/java/org/openhab/binding/enturno/internal/util/DateUtilTest.java @@ -0,0 +1,46 @@ +/** + * Copyright (c) 2010-2023 Contributors to the openHAB project + * + * See the NOTICE file(s) distributed with this work for additional + * information. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.openhab.binding.enturno.internal.util; + +import static org.hamcrest.CoreMatchers.*; +import static org.hamcrest.MatcherAssert.assertThat; + +import java.util.stream.Stream; + +import org.eclipse.jdt.annotation.NonNullByDefault; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.Arguments; +import org.junit.jupiter.params.provider.MethodSource; + +/** + * Tests for {@link DateUtil}. + * + * @author Jacob Laursen - Initial contribution + */ +@NonNullByDefault +public class DateUtilTest { + @ParameterizedTest + @MethodSource("provideTestCasesForGetIsoDateTime") + void getIsoDateTime(String value, String expected) { + assertThat(DateUtil.getIsoDateTime(value), is(expected)); + } + + private static Stream provideTestCasesForGetIsoDateTime() { + return Stream.of( // + Arguments.of("2023-10-25T09:01:00+0200", "2023-10-25T09:01:00+02:00"), + Arguments.of("2023-10-25T09:01:00+02:00", "2023-10-25T09:01:00+02:00"), + Arguments.of("2023-10-25T09:01:00-0300", "2023-10-25T09:01:00-03:00"), + Arguments.of("2023-10-25T09:01:00+02:30", "2023-10-25T09:01:00+02:30"), + Arguments.of("2023-10-25T09:01:00", "2023-10-25T09:01:00")); + } +}