Fix some issues with XPath querying and time conversion. Now PCB events get logged to the DB successfully

This commit is contained in:
skogaby
2019-01-11 17:42:35 -06:00
parent 66483b5d42
commit cd12a94d50
2 changed files with 8 additions and 6 deletions

View File

@@ -16,6 +16,8 @@ public class TimeUtils {
* @return
*/
public static LocalDateTime timeFromEpoch(final long millis) {
return LocalDateTime.ofInstant(Instant.ofEpochMilli(millis), ZoneId.systemDefault());
final Instant instant = Instant.ofEpochSecond(millis);
return instant.atZone(ZoneId.systemDefault()).toLocalDateTime();
}
}

View File

@@ -79,7 +79,7 @@ public class XmlUtils {
*/
public static String strValueAtPath(final Element doc, final String path) {
try {
return (String) XPATH.compile(path).evaluate(doc, XPathConstants.STRING);
return (String) XPATH.compile("/" + path).evaluate(doc, XPathConstants.STRING);
} catch (Exception e) {
e.printStackTrace();
return "";
@@ -94,7 +94,7 @@ public class XmlUtils {
*/
public static Boolean boolValueAtPath(final Element doc, final String path) {
try {
return (Boolean) XPATH.compile(path).evaluate(doc, XPathConstants.BOOLEAN);
return (Boolean) XPATH.compile("/" + path).evaluate(doc, XPathConstants.BOOLEAN);
} catch (Exception e) {
e.printStackTrace();
return null;
@@ -109,7 +109,7 @@ public class XmlUtils {
*/
public static Double doubleValueAtPath(final Element doc, final String path) {
try {
return (Double) XPATH.compile(path).evaluate(doc, XPathConstants.NUMBER);
return (Double) XPATH.compile("/" + path).evaluate(doc, XPathConstants.NUMBER);
} catch (Exception e) {
e.printStackTrace();
return null;
@@ -124,7 +124,7 @@ public class XmlUtils {
*/
public static Long longValueAtPath(final Element doc, final String path) {
try {
return Long.parseLong((String) XPATH.compile(path).evaluate(doc, XPathConstants.STRING));
return Long.parseLong((String) XPATH.compile("/" + path).evaluate(doc, XPathConstants.STRING));
} catch (Exception e) {
e.printStackTrace();
return null;
@@ -139,7 +139,7 @@ public class XmlUtils {
*/
public static Integer intValueAtPath(final Element doc, final String path) {
try {
return ((Double) XPATH.compile(path).evaluate(doc, XPathConstants.NUMBER)).intValue();
return ((Double) XPATH.compile("/" + path).evaluate(doc, XPathConstants.NUMBER)).intValue();
} catch (Exception e) {
e.printStackTrace();
return null;