[dwdunwetter] Removed dependency on org.apache.commons (#9138)
* Removed dependency on org.apache.commons * Incorporated comments from review Signed-off-by: Christoph Weitkamp <github@christophweitkamp.de>
This commit is contained in:
parent
219d370439
commit
a3835ebdc6
@ -12,7 +12,6 @@
|
|||||||
*/
|
*/
|
||||||
package org.openhab.binding.dwdunwetter.internal.config;
|
package org.openhab.binding.dwdunwetter.internal.config;
|
||||||
|
|
||||||
import org.apache.commons.lang.StringUtils;
|
|
||||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -24,5 +23,5 @@ import org.eclipse.jdt.annotation.NonNullByDefault;
|
|||||||
public class DwdUnwetterConfiguration {
|
public class DwdUnwetterConfiguration {
|
||||||
public int refresh;
|
public int refresh;
|
||||||
public int warningCount;
|
public int warningCount;
|
||||||
public String cellId = StringUtils.EMPTY;
|
public String cellId = "";
|
||||||
}
|
}
|
||||||
|
|||||||
@ -15,8 +15,6 @@ package org.openhab.binding.dwdunwetter.internal.data;
|
|||||||
import java.math.BigDecimal;
|
import java.math.BigDecimal;
|
||||||
import java.time.Instant;
|
import java.time.Instant;
|
||||||
|
|
||||||
import org.apache.commons.lang.StringUtils;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Data for one warning.
|
* Data for one warning.
|
||||||
*
|
*
|
||||||
@ -93,7 +91,7 @@ public class DwdWarningData {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public boolean isTest() {
|
public boolean isTest() {
|
||||||
return StringUtils.equalsIgnoreCase(status, "Test");
|
return "Test".equalsIgnoreCase(status);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setMsgType(String msgType) {
|
public void setMsgType(String msgType) {
|
||||||
@ -101,7 +99,7 @@ public class DwdWarningData {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public boolean isCancel() {
|
public boolean isCancel() {
|
||||||
return StringUtils.equalsIgnoreCase(msgType, "Cancel");
|
return "Cancel".equalsIgnoreCase(msgType);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setHeadline(String headline) {
|
public void setHeadline(String headline) {
|
||||||
|
|||||||
@ -16,7 +16,6 @@ import java.io.IOException;
|
|||||||
import java.net.URLEncoder;
|
import java.net.URLEncoder;
|
||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
|
|
||||||
import org.apache.commons.lang.StringUtils;
|
|
||||||
import org.openhab.core.io.net.http.HttpUtil;
|
import org.openhab.core.io.net.http.HttpUtil;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
@ -35,23 +34,22 @@ public class DwdWarningDataAccess {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the raw Data from the Endpoint.
|
* Returns the raw Data from the Endpoint.
|
||||||
* In case of errors or empty cellId value, returns an {@link StringUtils#EMPTY Empty String}.
|
* In case of errors or empty cellId value, returns an empty String.
|
||||||
*
|
*
|
||||||
* @param cellId The warnCell-Id for which the warnings should be returned
|
* @param cellId The warnCell-Id for which the warnings should be returned
|
||||||
* @return The raw data received or an empty string.
|
* @return The raw data received or an empty string.
|
||||||
*/
|
*/
|
||||||
public String getDataFromEndpoint(String cellId) {
|
public String getDataFromEndpoint(String cellId) {
|
||||||
try {
|
try {
|
||||||
if (StringUtils.isBlank(cellId)) {
|
if (cellId == null || cellId.isBlank()) {
|
||||||
logger.warn("No cellId provided");
|
logger.warn("No cellId provided");
|
||||||
return StringUtils.EMPTY;
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
StringBuilder stringBuilder = new StringBuilder();
|
StringBuilder stringBuilder = new StringBuilder();
|
||||||
stringBuilder.append(DWD_URL);
|
stringBuilder.append(DWD_URL);
|
||||||
stringBuilder.append("&CQL_FILTER=");
|
stringBuilder.append("&CQL_FILTER=");
|
||||||
stringBuilder
|
stringBuilder.append(URLEncoder.encode("WARNCELLID LIKE '" + cellId + "'", StandardCharsets.UTF_8));
|
||||||
.append(URLEncoder.encode("WARNCELLID LIKE '" + cellId + "'", StandardCharsets.UTF_8.toString()));
|
|
||||||
logger.debug("Refreshing Data for cell {}", cellId);
|
logger.debug("Refreshing Data for cell {}", cellId);
|
||||||
String rawData = HttpUtil.executeUrl("GET", stringBuilder.toString(), 5000);
|
String rawData = HttpUtil.executeUrl("GET", stringBuilder.toString(), 5000);
|
||||||
logger.trace("Raw request: {}", stringBuilder);
|
logger.trace("Raw request: {}", stringBuilder);
|
||||||
@ -63,6 +61,6 @@ public class DwdWarningDataAccess {
|
|||||||
logger.debug("Communication error trace", e);
|
logger.debug("Communication error trace", e);
|
||||||
}
|
}
|
||||||
|
|
||||||
return StringUtils.EMPTY;
|
return "";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -14,8 +14,6 @@ package org.openhab.binding.dwdunwetter.internal.data;
|
|||||||
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
|
||||||
import org.apache.commons.lang.StringUtils;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The XML Tags to extract the relevant parts from the API response.
|
* The XML Tags to extract the relevant parts from the API response.
|
||||||
* The names map directly to the XML Tags of the API Response.
|
* The names map directly to the XML Tags of the API Response.
|
||||||
@ -52,7 +50,7 @@ public enum DwdXmlTag {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static DwdXmlTag getDwdXmlTag(String tag) {
|
public static DwdXmlTag getDwdXmlTag(String tag) {
|
||||||
return Arrays.asList(DwdXmlTag.values()).stream().filter(t -> StringUtils.equals(t.getTag(), tag)).findFirst()
|
return Arrays.asList(DwdXmlTag.values()).stream().filter(t -> tag.equals(t.getTag())).findFirst()
|
||||||
.orElse(UNKNOWN);
|
.orElse(UNKNOWN);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -14,8 +14,6 @@ package org.openhab.binding.dwdunwetter.internal.data;
|
|||||||
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
|
||||||
import org.apache.commons.lang.StringUtils;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Severity enum to make the severity comparable
|
* Severity enum to make the severity comparable
|
||||||
*
|
*
|
||||||
@ -46,7 +44,7 @@ public enum Severity {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static Severity getSeverity(String input) {
|
public static Severity getSeverity(String input) {
|
||||||
return Arrays.asList(Severity.values()).stream()
|
return Arrays.asList(Severity.values()).stream().filter(sev -> input.equalsIgnoreCase(sev.getText())).findAny()
|
||||||
.filter(sev -> StringUtils.equalsIgnoreCase(input, sev.getText())).findAny().orElse(UNKNOWN);
|
.orElse(UNKNOWN);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -14,8 +14,6 @@ package org.openhab.binding.dwdunwetter.internal.data;
|
|||||||
|
|
||||||
import java.util.Comparator;
|
import java.util.Comparator;
|
||||||
|
|
||||||
import org.apache.commons.lang.ObjectUtils;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Comperator to sort a Warning first by Severity, second by the onSet date.
|
* Comperator to sort a Warning first by Severity, second by the onSet date.
|
||||||
*
|
*
|
||||||
@ -30,7 +28,14 @@ public class SeverityComparator implements Comparator<DwdWarningData> {
|
|||||||
|
|
||||||
int result = Integer.compare(o1.getSeverity().getOrder(), o2.getSeverity().getOrder());
|
int result = Integer.compare(o1.getSeverity().getOrder(), o2.getSeverity().getOrder());
|
||||||
if (result == 0) {
|
if (result == 0) {
|
||||||
result = ObjectUtils.compare(o1.getOnset(), o2.getOnset());
|
if (o1.getOnset() == o2.getOnset()) {
|
||||||
|
return 0;
|
||||||
|
} else if (o1.getOnset() == null) {
|
||||||
|
return -1;
|
||||||
|
} else if (o2.getOnset() == null) {
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
return o1.getOnset().compareTo(o2.getOnset());
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -14,8 +14,6 @@ package org.openhab.binding.dwdunwetter.internal.data;
|
|||||||
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
|
||||||
import org.apache.commons.lang.StringUtils;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Enum for the urgency of the warning.
|
* Enum for the urgency of the warning.
|
||||||
*
|
*
|
||||||
@ -38,7 +36,7 @@ public enum Urgency {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static Urgency getUrgency(String input) {
|
public static Urgency getUrgency(String input) {
|
||||||
return Arrays.asList(Urgency.values()).stream()
|
return Arrays.asList(Urgency.values()).stream().filter(urg -> input.equalsIgnoreCase(urg.getText())).findAny()
|
||||||
.filter(urg -> StringUtils.equalsIgnoreCase(input, urg.getText())).findAny().orElse(UNKNOWN);
|
.orElse(UNKNOWN);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -19,11 +19,11 @@ import static org.mockito.Mockito.*;
|
|||||||
|
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
import javax.xml.parsers.DocumentBuilder;
|
import javax.xml.parsers.DocumentBuilder;
|
||||||
import javax.xml.parsers.DocumentBuilderFactory;
|
import javax.xml.parsers.DocumentBuilderFactory;
|
||||||
|
|
||||||
import org.apache.commons.lang.StringUtils;
|
|
||||||
import org.hamcrest.CoreMatchers;
|
import org.hamcrest.CoreMatchers;
|
||||||
import org.junit.jupiter.api.BeforeEach;
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
@ -122,7 +122,7 @@ public class DwdUnwetterHandlerTest extends JavaTest {
|
|||||||
if (nodeId == null) {
|
if (nodeId == null) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (StringUtils.equals(nodeId.getTextContent(), uuid.getId())) {
|
if (Objects.equals(nodeId.getTextContent(), uuid.getId())) {
|
||||||
return getLabel(node.getChildNodes());
|
return getLabel(node.getChildNodes());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user