Skip to content

Commit

Permalink
fix for generic version
Browse files Browse the repository at this point in the history
  • Loading branch information
kazhamiakin committed Aug 2, 2023
1 parent 0efa8cf commit ad05d05
Showing 1 changed file with 18 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -135,12 +136,14 @@ private Campaign convertCampaign(Map<String, Object> cm) {
private VirtualScore extractVirtualScore(Map<String, Object> 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<String, Object> sv = (Map<String, Object>) map.get(m.name());
Expand All @@ -156,6 +159,15 @@ private VirtualScore extractVirtualScore(Map<String, Object> map) {
return score;
}

private Number getNumValue(Map<String, Object> 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
Expand Down

0 comments on commit ad05d05

Please sign in to comment.