Commit 1ae24cf4 authored by oleg.pahhomov's avatar oleg.pahhomov

SA0140-575 | replace bigdecimal with string

parent 845d4903
......@@ -18,14 +18,15 @@ import static ee.stat.dashboard.util.StatListUtil.firstOrNull;
public class DataSet {
private String action;
private HashMap<String, List<BigDecimal>> observations;
private HashMap<String, List<String>> observations;
@JsonIgnore
public BigDecimal getObservation(String key) {
if (MapUtils.isEmpty(observations)){
return null;
}
return firstOrNull(observations.get(key));
String s = firstOrNull(observations.get(key));
return s != null ? new BigDecimal(s) : null;
}
@Override
......
......@@ -140,8 +140,8 @@ public class StatDbUpdater {
}
boolean responsesAreSame(ProcessLog processLog, Widget widget, StatResponse response, StatResponse newStatResponse, String cube) {
TreeMap<String, List<BigDecimal>> oldTreemap = new TreeMap<>(response.getDataSet().getObservations());
TreeMap<String, List<BigDecimal>> newTreemap = new TreeMap<>(newStatResponse.getDataSet().getObservations());
TreeMap<String, List<String>> oldTreemap = new TreeMap<>(response.getDataSet().getObservations());
TreeMap<String, List<String>> newTreemap = new TreeMap<>(newStatResponse.getDataSet().getObservations());
boolean dataIsSame = Objects.equals(newTreemap, oldTreemap);
if (!dataIsSame) {
log.log(processLog, widget, INFO, observationsHaveChanged(oldTreemap, newTreemap), cube);
......@@ -194,7 +194,7 @@ public class StatDbUpdater {
);
}
private String observationsHaveChanged(TreeMap<String, List<BigDecimal>> response, TreeMap<String, List<BigDecimal>> newStatResponse) {
private String observationsHaveChanged(TreeMap<String, List<String>> response, TreeMap<String, List<String>> newStatResponse) {
return format("Stat observations have changed! " +
"\n Before: %s " +
"\n After: %s",
......
......@@ -50,7 +50,7 @@ public class SdmxToCoordinates {
List<Dimension> observations = apiResponse.getStructure().getDimensions().getObservations();
List<DataPoint> dataPoints = new ArrayList<>();
for (Map.Entry<String, List<BigDecimal>> keyValue : apiResponse.getDataSet().getObservations().entrySet()) {
for (Map.Entry<String, List<String>> keyValue : apiResponse.getDataSet().getObservations().entrySet()) {
Optional<DataPoint> dataPointOp = mapToPoint(keyValue, observations, timeFilter, timePart, lang);
if (dataPointOp.isPresent()) {
DataPoint dataPoint = dataPointOp.get();
......@@ -82,7 +82,7 @@ public class SdmxToCoordinates {
return !county.equalsIgnoreCase(dim) || ehakNames.contains(val.toLowerCase());
}
private Optional<DataPoint> mapToPoint(Map.Entry<String, List<BigDecimal>> keyValue, List<Dimension> observations, Filter timeFilter, Optional<Filter> timePartFilterOp, Language lang) throws RawDataException {
private Optional<DataPoint> mapToPoint(Map.Entry<String, List<String>> keyValue, List<Dimension> observations, Filter timeFilter, Optional<Filter> timePartFilterOp, Language lang) throws RawDataException {
String code = keyValue.getKey();
List<Integer> indexes = Arrays.stream(code.split(":")).map(Integer::valueOf).collect(toList());
DataPoint dataPoint = new DataPoint();
......@@ -113,7 +113,8 @@ public class SdmxToCoordinates {
}
}
}
dataPoint.setValue(firstOrNull(keyValue.getValue()));
String value = firstOrNull(keyValue.getValue());
dataPoint.setValue(value != null ? new BigDecimal(value) : null);
dataPoint.setSource(Source.STAT_DB);
return of(dataPoint);
}
......
......@@ -10,8 +10,6 @@ import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
import javax.annotation.Resource;
import java.math.BigDecimal;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
......@@ -30,23 +28,23 @@ public class StatDbUpdaterTest {
assertTrue(statDbUpdater.responsesAreSame(null, null, response(existingData()), response(newData()), null));
}
private HashMap<String, List<BigDecimal>> newData() {
HashMap<String, List<BigDecimal>> newData = new HashMap<>();
newData.put("0:0:2:", asList(BigDecimal.valueOf(3253.6)));
newData.put("0:0:1:", asList(BigDecimal.valueOf(2704.4)));
newData.put("0:0:0:", asList(BigDecimal.valueOf(2572.3)));
private HashMap<String, List<String>> newData() {
HashMap<String, List<String>> newData = new HashMap<>();
newData.put("0:0:2:", asList("3253.6"));
newData.put("0:0:1:", asList("2704.4"));
newData.put("0:0:0:", asList("2572.3"));
return newData;
}
private HashMap<String, List<BigDecimal>> existingData() {
HashMap<String, List<BigDecimal>> existing = new HashMap<>();
existing.put("0:0:0:", asList(BigDecimal.valueOf(2572.3)));
existing.put("0:0:1:", asList(BigDecimal.valueOf(2704.4)));
existing.put("0:0:2:", asList(BigDecimal.valueOf(3253.6)));
private HashMap<String, List<String>> existingData() {
HashMap<String, List<String>> existing = new HashMap<>();
existing.put("0:0:0:", asList("2572.3"));
existing.put("0:0:1:", asList("2704.4"));
existing.put("0:0:2:", asList("3253.6"));
return existing;
}
private StatResponse response(HashMap<String, List<BigDecimal>> data) {
private StatResponse response(HashMap<String, List<String>> data) {
DataSet newDataSet = dataset(data);
StatResponse newStatResponse = new StatResponse();
newStatResponse.setDataSets(asList(newDataSet));
......@@ -54,7 +52,7 @@ public class StatDbUpdaterTest {
return newStatResponse;
}
private DataSet dataset(HashMap<String, List<BigDecimal>> data) {
private DataSet dataset(HashMap<String, List<String>> data) {
DataSet newDataSet = new DataSet();
newDataSet.setObservations(data);
return newDataSet;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment