diff --git a/backend/src/main/java/it/smartcommunitylab/pgazienda/service/PGAppService.java b/backend/src/main/java/it/smartcommunitylab/pgazienda/service/PGAppService.java index d163d14..6a14621 100644 --- a/backend/src/main/java/it/smartcommunitylab/pgazienda/service/PGAppService.java +++ b/backend/src/main/java/it/smartcommunitylab/pgazienda/service/PGAppService.java @@ -27,6 +27,7 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; +import org.springframework.util.StringUtils; import org.springframework.web.client.RestTemplate; import it.smartcommunitylab.pgazienda.domain.Campaign; @@ -135,12 +136,14 @@ private Campaign convertCampaign(Map cm) { private VirtualScore extractVirtualScore(Map map) { VirtualScore score = new VirtualScore(); score.setLabel((String)map.getOrDefault("label", "km")); - score.setScoreDailyLimit(Double.parseDouble(map.getOrDefault("scoreDailyLimit", "0").toString())); - score.setScoreWeeklyLimit(Double.parseDouble(map.getOrDefault("scoreWeeklyLimit", "0").toString())); - score.setScoreMonthlyLimit(Double.parseDouble(map.getOrDefault("scoreMonthlyLimit", "0").toString())); - score.setTrackDailyLimit(Integer.parseInt(map.getOrDefault("trackDailyLimit", "0").toString())); - score.setTrackWeeklyLimit(Integer.parseInt(map.getOrDefault("trackWeeklyLimit", "0").toString())); - score.setTrackMonthlyLimit(Integer.parseInt(map.getOrDefault("trackMonthlyLimit", "0").toString())); + score.setScoreDailyLimit(getNumValue(map, "scoreDailyLimit").doubleValue()); + score.setScoreWeeklyLimit(getNumValue(map, "scoreWeeklyLimit").doubleValue()); + score.setScoreMonthlyLimit(getNumValue(map, "scoreMonthlyLimit").doubleValue()); + + score.setTrackDailyLimit(getNumValue(map, "trackDailyLimit").intValue()); + score.setTrackWeeklyLimit(getNumValue(map, "trackWeeklyLimit").intValue()); + score.setTrackMonthlyLimit(getNumValue(map, "trackMonthlyLimit").intValue()); + for (MEAN m : MEAN.values()) { if (map.get(m.name()) != null) { Map sv = (Map) map.get(m.name()); @@ -156,6 +159,15 @@ private VirtualScore extractVirtualScore(Map map) { return score; } + private Number getNumValue(Map map, String key) { + String v = map.getOrDefault(key, "0").toString(); + if (!StringUtils.hasText(v)) return 0; + try { + return Double.parseDouble(v); + } catch (Exception e) { + return 0; + } + } /** * @param object