diff --git a/src/main/java/com/datastax/oss/cass_stac/entity/Item.java b/src/main/java/com/datastax/oss/cass_stac/entity/Item.java index 594927a..5096683 100644 --- a/src/main/java/com/datastax/oss/cass_stac/entity/Item.java +++ b/src/main/java/com/datastax/oss/cass_stac/entity/Item.java @@ -18,25 +18,32 @@ @Getter @Setter public class Item { - @PrimaryKey - private ItemPrimaryKey id; - private String collection; - private Instant datetime; - private ByteBuffer geometry; - private Map indexed_properties_text; - private Map indexed_properties_double; - private Map indexed_properties_boolean; - private Map indexed_properties_timestamp; - private String properties; - private String additional_attributes; - private CqlVector centroid; + @PrimaryKey + private ItemPrimaryKey id; + private String collection; + private Instant datetime; + private ByteBuffer geometry; + private Map indexed_properties_text; + private Map indexed_properties_double; + private Map indexed_properties_boolean; + private Map indexed_properties_timestamp; + private String properties; + private String additional_attributes; + private CqlVector centroid; - public Double getCloudCover() throws JsonProcessingException { - ObjectMapper objectMapper = new ObjectMapper().registerModule(new JavaTimeModule()); + public Double getCloudCover() throws JsonProcessingException { + ObjectMapper objectMapper = new ObjectMapper().registerModule(new JavaTimeModule()); - Map map = objectMapper.readValue(properties, new TypeReference<>() { - }); - Object value = map.get("eo:cloud_cover"); - return value != null ? Double.parseDouble(value.toString()) : null; - } + Map map = objectMapper.readValue(properties, new TypeReference<>() { + }); + Object value = map.get("eo:cloud_cover"); + if (value != null) { + try { + return Double.parseDouble(value.toString()); + } catch (NumberFormatException e) { + return Double.longBitsToDouble(Long.getLong(value.toString())); + } + } + return null; + } } diff --git a/src/main/java/com/datastax/oss/cass_stac/util/AggregationUtil.java b/src/main/java/com/datastax/oss/cass_stac/util/AggregationUtil.java index cb0c37a..f3ef280 100644 --- a/src/main/java/com/datastax/oss/cass_stac/util/AggregationUtil.java +++ b/src/main/java/com/datastax/oss/cass_stac/util/AggregationUtil.java @@ -6,8 +6,10 @@ import com.fasterxml.jackson.core.JsonProcessingException; import lombok.Getter; -import java.time.*; -import java.util.ArrayList; +import java.time.Instant; +import java.time.Month; +import java.time.Year; +import java.time.ZoneId; import java.util.List; import java.util.Map; import java.util.Optional; @@ -68,10 +70,7 @@ public Aggregation apply(List items, List ranges) } catch (JsonProcessingException e) { throw new RuntimeException(e); } - List _ranges = new ArrayList<>(); - if(ranges == null) - _ranges.add(new AggregateRequest.Range()); - else _ranges = ranges; + List _ranges = ranges == null ? List.of(new AggregateRequest.Range()) : ranges; return _ranges.stream() .filter(range -> range.contains(value)).findFirst(); }, Collectors.counting())); @@ -119,7 +118,7 @@ public Aggregation apply(List items, List ranges) @Override public Aggregation apply(List items, List ranges) { Map frequencyMap = items.stream().collect(Collectors.groupingBy(item -> - Year.from(item.getDatetime().atZone(ZoneId.systemDefault())).getValue(), Collectors.counting())); + Year.from(item.getDatetime().atZone(ZoneId.systemDefault())).getValue(), Collectors.counting())); List buckets = frequencyMap.entrySet().stream() .map(entry -> {