Skip to content

Commit f231311

Browse files
committed
adjustments to work with unit conversion
1 parent 536f007 commit f231311

File tree

6 files changed

+50
-11
lines changed

6 files changed

+50
-11
lines changed

src/main/java/me/steffenjacobs/syntacticjsonmatcher/TestFileGenerator.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,13 @@ public class TestFileGenerator {
1515
private static final String[] VALUES_HUMIDITY = new String[] { "44", "\"44\"", "\"44%\"", "44.4", "\"44.4%\"" };
1616

1717
private static final String[] KEYS_PRESSURE = new String[] { "pressure", "p", "pres", "air pressure", "druck", "Luftdruck", "pressione" };
18-
private static final String[] VALUES_PRESSURE = new String[] { "905", "\"905\"", "905.5", "\"905ppi\"", "\"905.5ppi\"", "\"905.5bar\"" };
18+
private static final String[] VALUES_PRESSURE = new String[] { "905", "\"905\"", "905.5", "\"905psi\"", "\"905.5psi\"", "\"905.5bar\"" };
1919

2020
private static final String[] KEYS_CO2 = new String[] { "co2", "CO2", "co2 value" };
2121
private static final String[] VALUES_CO2 = new String[] { "505", "505.5", "\"505ppm\"" };
2222

2323
private static final String[] KEYS_LIGHT = new String[] { "light", "brightness", "Helligkeit", "luminance" };
24-
private static final String[] VALUES_LIGHT = new String[] { "1505", "1505.5", "\"1505lx\"", "\"1505lm\"" };
24+
private static final String[] VALUES_LIGHT = new String[] { "1505", "1505.5", "\"1505lx\"", "\"1505phots\"" };
2525

2626
private static final double RANDOM_SAMPLING_RATE = .00008;
2727

src/main/java/me/steffenjacobs/syntacticjsonmatcher/domain/wolframapi/ObjectFactory.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// Diese Datei wurde mit der JavaTM Architecture for XML Binding(JAXB) Reference Implementation, v2.2.8-b130911.1802 generiert
33
// Siehe <a href="http://java.sun.com/xml/jaxb">http://java.sun.com/xml/jaxb</a>
44
// Änderungen an dieser Datei gehen bei einer Neukompilierung des Quellschemas verloren.
5-
// Generiert: 2018.11.23 um 03:11:54 PM CET
5+
// Generiert: 2018.11.23 um 06:16:42 PM CET
66
//
77

88

src/main/java/me/steffenjacobs/syntacticjsonmatcher/domain/wolframapi/Queryresult.java

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// Diese Datei wurde mit der JavaTM Architecture for XML Binding(JAXB) Reference Implementation, v2.2.8-b130911.1802 generiert
33
// Siehe <a href="http://java.sun.com/xml/jaxb">http://java.sun.com/xml/jaxb</a>
44
// Änderungen an dieser Datei gehen bei einer Neukompilierung des Quellschemas verloren.
5-
// Generiert: 2018.11.23 um 03:11:54 PM CET
5+
// Generiert: 2018.11.23 um 06:16:42 PM CET
66
//
77

88

@@ -66,6 +66,7 @@
6666
* &lt;attribute name="position" type="{http://www.w3.org/2001/XMLSchema}int" />
6767
* &lt;attribute name="error" type="{http://www.w3.org/2001/XMLSchema}boolean" />
6868
* &lt;attribute name="numsubpods" type="{http://www.w3.org/2001/XMLSchema}int" />
69+
* &lt;attribute name="primary" type="{http://www.w3.org/2001/XMLSchema}string" />
6970
* &lt;/restriction>
7071
* &lt;/complexContent>
7172
* &lt;/complexType>
@@ -613,6 +614,7 @@ public void setVersion(BigDecimal value) {
613614
* &lt;attribute name="position" type="{http://www.w3.org/2001/XMLSchema}int" />
614615
* &lt;attribute name="error" type="{http://www.w3.org/2001/XMLSchema}boolean" />
615616
* &lt;attribute name="numsubpods" type="{http://www.w3.org/2001/XMLSchema}int" />
617+
* &lt;attribute name="primary" type="{http://www.w3.org/2001/XMLSchema}string" />
616618
* &lt;/restriction>
617619
* &lt;/complexContent>
618620
* &lt;/complexType>
@@ -639,6 +641,8 @@ public static class Pod {
639641
protected Boolean error;
640642
@XmlAttribute(name = "numsubpods")
641643
protected Integer numsubpods;
644+
@XmlAttribute(name = "primary")
645+
protected String primary;
642646

643647
/**
644648
* Gets the value of the subpod property.
@@ -813,6 +817,30 @@ public void setNumsubpods(Integer value) {
813817
this.numsubpods = value;
814818
}
815819

820+
/**
821+
* Ruft den Wert der primary-Eigenschaft ab.
822+
*
823+
* @return
824+
* possible object is
825+
* {@link String }
826+
*
827+
*/
828+
public String getPrimary() {
829+
return primary;
830+
}
831+
832+
/**
833+
* Legt den Wert der primary-Eigenschaft fest.
834+
*
835+
* @param value
836+
* allowed object is
837+
* {@link String }
838+
*
839+
*/
840+
public void setPrimary(String value) {
841+
this.primary = value;
842+
}
843+
816844

817845
/**
818846
* <p>Java-Klasse für anonymous complex type.

src/main/java/me/steffenjacobs/syntacticjsonmatcher/service/UnitConversionService.java

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,14 @@ public String convert(String source, String unit) {
4646
return (String) conversionCache.get(key);
4747
} else {
4848
String request = buildRequest(source, unit);
49-
String result = httpRequester.sendGet(request);
49+
String oldresult = httpRequester.sendGet(request);
50+
String result = "";
5051
try {
51-
result = extractResult(result, unit);
52+
result = extractResult(oldresult, source, unit);
53+
if (result == null) {
54+
conversionCache.put(key, source);
55+
return source;
56+
}
5257
result = cleanResult(result);
5358
} catch (JAXBException e) {
5459
LOG.error(e.getMessage());
@@ -69,7 +74,7 @@ public String cleanResult(String extractedResult) {
6974
return extractedResult;
7075
}
7176

72-
public String extractResult(String input, String unit) throws JAXBException {
77+
public String extractResult(String input, String source, String unit) throws JAXBException {
7378

7479
JAXBContext jc = JAXBContext.newInstance(Queryresult.class);
7580

@@ -79,7 +84,6 @@ public String extractResult(String input, String unit) throws JAXBException {
7984
if (result.isSuccess()) {
8085
for (Pod pod : result.getPod()) {
8186
if ("Result".equals(pod.getId())) {
82-
8387
for (Subpod subpod : pod.getSubpod()) {
8488
if (subpod != null && "".equals(subpod.getTitle())) {
8589
return subpod.getPlaintext();
@@ -92,10 +96,11 @@ public String extractResult(String input, String unit) throws JAXBException {
9296
return subpod.getPlaintext();
9397
}
9498
}
95-
LOG.error("No result with correct converted unit in subpods not found.");
99+
System.out.println(input);
100+
LOG.error("No result with correct converted unit in subpods found.");
96101
}
97102
}
98-
LOG.error("Result pod not found.");
103+
LOG.error("No result found for conversion {} -> {}.", source, unit);
99104
} else {
100105
LOG.error("Query not successful.");
101106
}
146 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)