Loading time-series-view/src/main/java/es/redmic/timeseriesview/mapper/ObjectCollectingSeriesESMapper.java +13 −13 Original line number Diff line number Diff line Loading @@ -115,21 +115,21 @@ public abstract class ObjectCollectingSeriesESMapper extends SeriesESMapper<Obje classification.setName(classificationType.get(i).get("key").toString()); /** Obtiene las estadisticas a nivel de tipo de classificación **/ List<Map<String, Object>> timeIntervals = ElasticSearchUtils .getBucketsFromAggregations((Map<String, Object>) classificationType.get(i).get("timeIntervals")); .getBucketsFromAggregations((Map<String, Object>) classificationType.get(i).get("reverse_nested#timeIntervals")); for (int timeIntervalsIt = 0; timeIntervalsIt < timeIntervals.size(); timeIntervalsIt++) { classification.addHeader(timeIntervals.get(timeIntervalsIt).get("key_as_string").toString()); classification.addV(getValue((Map<String, Object>) timeIntervals.get(timeIntervalsIt).get("value"))); classification.addV(getValue((Map<String, Object>) timeIntervals.get(timeIntervalsIt).get("stats#value"))); } /** Obtiene todas las clasificaciones del tipo actual **/ List<Map<String, Object>> levels = ElasticSearchUtils.getBucketsFromAggregations( (Map<String, Object>) classificationType.get(i).get("objectClassification")); (Map<String, Object>) classificationType.get(i).get("nested#objectClassification")); List<ObjectClassificationForListDTO> data = new ArrayList<>(); for (int levelIt = 0; levelIt < levels.size(); levelIt++) { // niveles de clasificación /** Obtiene cada uno de los elementos de la clasificación **/ List<Map<String, Object>> objects = ElasticSearchUtils.getBucketsFromAggregations( (Map<String, Object>) levels.get(levelIt).get("objectClassificationPath")); (Map<String, Object>) levels.get(levelIt).get("sterms#objectClassificationPath")); boolean isLeave = (levelIt == levels.size() - 1); for (int objectIt = 0; objectIt < objects.size(); objectIt++) { // objectos Loading @@ -140,11 +140,11 @@ public abstract class ObjectCollectingSeriesESMapper extends SeriesESMapper<Obje object.setLeaves(1); List<Map<String, Object>> type = ElasticSearchUtils.getBucketsFromAggregations( (Map<String, Object>) objects.get(objectIt).get("objectClassificationName")); (Map<String, Object>) objects.get(objectIt).get("sterms#objectClassificationName")); object.setCategory(type.get(0).get("key").toString()); List<Map<String, Object>> timeIntervalsObject = ElasticSearchUtils .getBucketsFromAggregations((Map<String, Object>) type.get(0).get("timeIntervals")); .getBucketsFromAggregations((Map<String, Object>) type.get(0).get("reverse_nested#timeIntervals")); for (int timeIntervalsIt = 0; timeIntervalsIt < timeIntervalsObject.size(); timeIntervalsIt++) { // posición donde se debe insertar el dato y que depende del intervalo actual Loading @@ -152,7 +152,7 @@ public abstract class ObjectCollectingSeriesESMapper extends SeriesESMapper<Obje .getHeaderPos(timeIntervalsObject.get(timeIntervalsIt).get("key_as_string").toString()); Map<String, Object> stats = (Map<String, Object>) timeIntervalsObject.get(timeIntervalsIt) .get("value"); .get("stats#value"); object.setV(pos, getValue(stats)); // Setea el número de hijos si no es una hoja Integer count = (Integer) stats.get("count"); Loading Loading @@ -185,7 +185,7 @@ public abstract class ObjectCollectingSeriesESMapper extends SeriesESMapper<Obje String timeInterval = classificationIntervals.get(i).get("key_as_string").toString(); List<Map<String, Object>> types = ElasticSearchUtils .getBucketsFromAggregations((Map<String, Object>) classificationIntervals.get(i).get("object")); .getBucketsFromAggregations((Map<String, Object>) classificationIntervals.get(i).get("nested#object")); for (int typesIt = 0; typesIt < types.size(); typesIt++) { Loading @@ -203,7 +203,7 @@ public abstract class ObjectCollectingSeriesESMapper extends SeriesESMapper<Obje /** Obtiene todas las clasificaciones para recorrerlas por niveles **/ List<Map<String, Object>> levels = ElasticSearchUtils.getBucketsFromAggregations( (Map<String, Object>) types.get(typesIt).get("objectClassification")); (Map<String, Object>) types.get(typesIt).get("nested#objectClassification")); for (int levelIt = 0; levelIt < levels.size(); levelIt++) { Loading @@ -211,19 +211,19 @@ public abstract class ObjectCollectingSeriesESMapper extends SeriesESMapper<Obje * Obtiene cada uno de los elementos de la clasificación **/ List<Map<String, Object>> objects = ElasticSearchUtils.getBucketsFromAggregations( (Map<String, Object>) levels.get(levelIt).get("objectClassificationPath")); (Map<String, Object>) levels.get(levelIt).get("sterms#objectClassificationPath")); for (int objectIt = 0; objectIt < objects.size(); objectIt++) { // objectos List<Map<String, Object>> type = ElasticSearchUtils.getBucketsFromAggregations( (Map<String, Object>) objects.get(objectIt).get("objectClassificationName")); (Map<String, Object>) objects.get(objectIt).get("sterms#objectClassificationName")); /** * Obtiene las estadisticas a nivel de tipo de classificación **/ Map<String, Object> stats = (Map<String, Object>) type.get(0).get("stats"); Map<String, Object> stats = (Map<String, Object>) type.get(0).get("reverse_nested#stats"); interval.addCategory(objects.get(objectIt).get("key").toString(), type.get(0).get("key").toString(), getValue((Map<String, Object>) stats.get("value"))); type.get(0).get("key").toString(), getValue((Map<String, Object>) stats.get("stats#value"))); } } data.add(interval); Loading time-series-view/src/main/java/es/redmic/timeseriesview/repository/ObjectCollectingSeriesESRepository.java +7 −5 Original line number Diff line number Diff line Loading @@ -47,6 +47,7 @@ import es.redmic.timeseriesview.model.objectcollectingseries.ObjectCollectingSer public class ObjectCollectingSeriesESRepository extends RWSeriesESRepository<ObjectCollectingSeries, DataQueryDTO> { private static final String objectNestedPath = "object"; private static final String activityField = "activityId"; private static int aggsSize = 200; Loading Loading @@ -99,7 +100,7 @@ public class ObjectCollectingSeriesESRepository extends RWSeriesESRepository<Obj : DateHistogramInterval.QUARTER) .subAggregation(AggregationBuilders.stats(defaultField).field(defaultField)); return AggregationBuilders.nested("object", "object") return AggregationBuilders.nested(objectNestedPath, objectNestedPath) .subAggregation(AggregationBuilders.terms("objectType").field("object.name") .subAggregation( AggregationBuilders.reverseNested("timeIntervals").subAggregation(dateHistogramBuilder)) Loading @@ -123,7 +124,7 @@ public class ObjectCollectingSeriesESRepository extends RWSeriesESRepository<Obj return getDateHistogramAggregation( elasticQueryDTO.getInterval() != null ? SeriesQueryUtils.getInterval(elasticQueryDTO.getInterval()) : DateHistogramInterval.QUARTER) .subAggregation(AggregationBuilders.nested("object", "object") .subAggregation(AggregationBuilders.nested(objectNestedPath, objectNestedPath) .subAggregation(AggregationBuilders.terms("objectType").field("object.name") .subAggregation(AggregationBuilders.nested("objectClassification", "object.classification") .subAggregation(AggregationBuilders Loading Loading @@ -153,13 +154,14 @@ public class ObjectCollectingSeriesESRepository extends RWSeriesESRepository<Obj @Override protected QueryBuilder getTermQuery(Map<String, Object> terms, BoolQueryBuilder query) { if (terms != null && terms.containsKey("grandparentId")) { // Se mantiene grandparentId por retrocompatibilidad if (terms != null && (terms.containsKey("grandparentId") || terms.containsKey(activityField))) { String activityId = (String) terms.get("grandparentId"); query.must(QueryBuilders.boolQuery().filter(QueryBuilders.termQuery("activityId", activityId))); query.must(QueryBuilders.boolQuery().filter(QueryBuilders.termQuery(activityField, activityId))); } else { throw new ESTermQueryException("activityId", "null"); throw new ESTermQueryException(activityField, "null"); } return query; Loading time-series-view/src/test/java/es/redmic/test/timeseriesview/integration/controller/ObjectCollectingSeriesControllerTest.java +55 −14 Original line number Diff line number Diff line Loading @@ -21,6 +21,7 @@ package es.redmic.test.timeseriesview.integration.controller; */ import static org.hamcrest.CoreMatchers.is; import static org.hamcrest.CoreMatchers.notNullValue; import static org.springframework.restdocs.mockmvc.RestDocumentationRequestBuilders.get; import static org.springframework.restdocs.mockmvc.RestDocumentationRequestBuilders.post; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath; Loading Loading @@ -53,6 +54,8 @@ import org.springframework.web.context.WebApplicationContext; import es.redmic.models.es.common.query.dto.DataQueryDTO; import es.redmic.test.timeseriesview.integration.common.controller.SeriesControllerBaseTest; import es.redmic.timeseriesview.TimeSeriesViewApplication; import es.redmic.timeseriesview.model.objectcollectingseries.ObjectCollectingSeries; import es.redmic.timeseriesview.repository.ObjectCollectingSeriesESRepository; @SpringBootTest(classes = { TimeSeriesViewApplication.class }) @ActiveProfiles("test") Loading @@ -65,6 +68,9 @@ public class ObjectCollectingSeriesControllerTest extends SeriesControllerBaseTe @Autowired protected FilterChainProxy springSecurityFilterChain; @Autowired ObjectCollectingSeriesESRepository repository; protected MockMvc mockMvc; @Value("${controller.mapping.OBJECTCOLLECTING}") Loading @@ -76,6 +82,11 @@ public class ObjectCollectingSeriesControllerTest extends SeriesControllerBaseTe @Value("${controller.mapping.OBJECT_CLASSIFICATION_LIST}") private String OBJECT_CLASSIFICATION_LIST; @Value("${controller.mapping.OBJECT_CLASSIFICATION}") private String OBJECT_CLASSIFICATION; DataQueryDTO dataQuery; @BeforeClass public static void beforeClass() { } Loading @@ -85,13 +96,27 @@ public class ObjectCollectingSeriesControllerTest extends SeriesControllerBaseTe mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).addFilters(springSecurityFilterChain) .build(); String modelPath = "/data/objectcollectingseries/model/objectCollectingSeriesModel.json"; ObjectCollectingSeries objectCollectingSeries = mapper.readValue(getClass().getResource(modelPath).openStream(), ObjectCollectingSeries.class); repository.save(objectCollectingSeries); dataQuery = new DataQueryDTO(); Map<String, Object> terms = new HashMap<>(); terms.put("parentId", "sdsd323sdds_3ed"); terms.put("grandparentId", "3"); dataQuery.setTerms(terms); dataQuery.setInterval("1q"); } @After public void restore() { } @Test public void getObjectClassificationListSchema_Return200_WhenSchemaIsFound() throws Exception { Loading @@ -112,28 +137,44 @@ public class ObjectCollectingSeriesControllerTest extends SeriesControllerBaseTe @Test public void getObjectClassificationList_Return200_IfQueryIsOK() throws Exception { String searchSchema = "/data/objectcollectingseries/schema/searchSchema.json"; // @formatter:off DataQueryDTO dataQuery = new DataQueryDTO(); Map<String, Object> terms = new HashMap<>(); terms.put("parentId", "6f49792c-b2b2-4875-8f00-9729b24b0e1b"); terms.put("grandparentId", "1193"); dataQuery.setTerms(terms); this.mockMvc .perform(post(OBJECTCOLLECTINGSERIES_BASE_PATH + OBJECT_CLASSIFICATION_LIST + "/_search") .content(getQueryAsString(dataQuery)) .contentType(MediaType.APPLICATION_JSON).accept(MediaType.APPLICATION_JSON)) .andExpect(status().is(200)) .andExpect(jsonPath("$.success", is(true))) .andExpect(jsonPath("$.body", notNullValue())) .andExpect(jsonPath("$.body.length()", is(2))) .andExpect(jsonPath("$.body[0].name", notNullValue())) .andExpect(jsonPath("$.body[0].v", notNullValue())) .andExpect(jsonPath("$.body[0].v.length()", is(1))) .andExpect(jsonPath("$.body[0].data", notNullValue())) .andExpect(jsonPath("$.body[0].data.length()", is(3))) .andExpect(jsonPath("$.body[0].header", notNullValue())); dataQuery.setInterval("1q"); // @formatter:on } @Test public void getObjectClassification_Return200_IfQueryIsOK() throws Exception { // @formatter:off MvcResult result = this.mockMvc .perform(post(OBJECTCOLLECTINGSERIES_BASE_PATH + OBJECT_CLASSIFICATION_LIST + "/_search") this.mockMvc .perform(post(OBJECTCOLLECTINGSERIES_BASE_PATH + OBJECT_CLASSIFICATION + "/_search") .content(getQueryAsString(dataQuery)) .contentType(MediaType.APPLICATION_JSON).accept(MediaType.APPLICATION_JSON)) .andExpect(status().is(200)) .andExpect(jsonPath("$.success", is(true))).andReturn(); System.out.println(result.getResponse().getContentAsString()); .andExpect(jsonPath("$.success", is(true))) .andExpect(jsonPath("$.body", notNullValue())) .andExpect(jsonPath("$.body.length()", is(2))) .andExpect(jsonPath("$.body[0].data", notNullValue())) .andExpect(jsonPath("$.body[0].data.length()", is(1))) .andExpect(jsonPath("$.body[0].data[0].categories", notNullValue())) .andExpect(jsonPath("$.body[0].data[0].timeInterval", notNullValue())); //.andExpect(jsonPath("$.body", is(mapper.readValue(getClass().getResource(searchSchema).openStream(), Map.class)))); // @formatter:on } Loading time-series-view/src/test/java/es/redmic/test/timeseriesview/integration/controller/WindRoseControllerTest.java +0 −1 Original line number Diff line number Diff line Loading @@ -52,7 +52,6 @@ import org.springframework.web.context.WebApplicationContext; import com.fasterxml.jackson.core.JsonParseException; import com.fasterxml.jackson.core.type.TypeReference; import com.fasterxml.jackson.databind.JsonMappingException; import com.fasterxml.jackson.databind.ObjectMapper; import es.redmic.models.es.common.query.dto.DataQueryDTO; import es.redmic.models.es.common.query.dto.DateLimitsDTO; Loading time-series-view/src/test/resources/data/objectcollectingseries/model/classificationForList.json +33 −33 Original line number Diff line number Diff line Loading @@ -15,14 +15,14 @@ "buckets": [{ "doc_count": 93, "key": "Basura - OSPAR", "timeIntervals": { "reverse_nested#timeIntervals": { "doc_count": 74, "dateHistogram": { "buckets": [{ "key_as_string": "2013-01-01", "key": 1356998400000, "doc_count": 17, "value": { "stats#value": { "count": 17, "min": 1, "max": 15, Loading @@ -33,7 +33,7 @@ "key_as_string": "2013-04-01", "key": 1364774400000, "doc_count": 29, "value": { "stats#value": { "count": 29, "min": 1, "max": 205, Loading @@ -44,7 +44,7 @@ "key_as_string": "2013-07-01", "key": 1372636800000, "doc_count": 0, "value": { "stats#value": { "count": 0, "min": null, "max": null, Loading @@ -55,7 +55,7 @@ "key_as_string": "2013-10-01", "key": 1380585600000, "doc_count": 28, "value": { "stats#value": { "count": 28, "min": 1, "max": 90, Loading @@ -65,30 +65,30 @@ }] } }, "objectClassification": { "nested#objectClassification": { "doc_count": 167, "level": { "doc_count_error_upper_bound": 0, "sum_other_doc_count": 0, "buckets": [{ "doc_count": 93, "objectClassificationPath": { "sterms#objectClassificationPath": { "doc_count_error_upper_bound": 0, "sum_other_doc_count": 0, "buckets": [{ "doc_count": 35, "objectClassificationName": { "sterms#objectClassificationName": { "doc_count_error_upper_bound": 0, "sum_other_doc_count": 0, "buckets": [{ "doc_count": 35, "timeIntervals": { "reverse_nested#timeIntervals": { "doc_count": 35, "dateHistogram": { "buckets": [{ "key_as_string": "2013-01-01", "doc_count": 10, "value": { "stats#value": { "min": 1.0, "avg": 7.0, "max": 35.0, Loading @@ -99,7 +99,7 @@ }, { "key_as_string": "2013-04-01", "doc_count": 14, "value": { "stats#value": { "min": 1.0, "avg": 11.285714285714286, "max": 79.0, Loading @@ -110,7 +110,7 @@ }, { "key_as_string": "2013-07-01", "doc_count": 0, "value": { "stats#value": { "min": null, "avg": null, "max": null, Loading @@ -121,7 +121,7 @@ }, { "key_as_string": "2013-10-01", "doc_count": 11, "value": { "stats#value": { "min": 1.0, "avg": 5.636363636363637, "max": 31.0, Loading @@ -141,23 +141,23 @@ "key": 1 }, { "doc_count": 74, "objectClassificationPath": { "sterms#objectClassificationPath": { "doc_count_error_upper_bound": 0, "sum_other_doc_count": 0, "buckets": [{ "doc_count": 3, "objectClassificationName": { "sterms#objectClassificationName": { "doc_count_error_upper_bound": 0, "sum_other_doc_count": 0, "buckets": [{ "doc_count": 3, "timeIntervals": { "reverse_nested#timeIntervals": { "doc_count": 3, "dateHistogram": { "buckets": [{ "key_as_string": "2013-01-01", "doc_count": 1, "value": { "stats#value": { "min": 15.0, "avg": 15.0, "max": 15.0, Loading @@ -168,7 +168,7 @@ }, { "key_as_string": "2013-04-01", "doc_count": 1, "value": { "stats#value": { "min": 7.0, "avg": 7.0, "max": 7.0, Loading @@ -179,7 +179,7 @@ }, { "key_as_string": "2013-07-01", "doc_count": 0, "value": { "stats#value": { "min": null, "avg": null, "max": null, Loading @@ -190,7 +190,7 @@ }, { "key_as_string": "2013-10-01", "doc_count": 1, "value": { "stats#value": { "min": 4.0, "avg": 4.0, "max": 4.0, Loading @@ -207,18 +207,18 @@ "key": "root.122.15" }, { "doc_count": 3, "objectClassificationName": { "sterms#objectClassificationName": { "doc_count_error_upper_bound": 0, "sum_other_doc_count": 0, "buckets": [{ "doc_count": 3, "timeIntervals": { "reverse_nested#timeIntervals": { "doc_count": 3, "dateHistogram": { "buckets": [{ "key_as_string": "2013-01-01", "doc_count": 1, "value": { "stats#value": { "min": 3.0, "avg": 3.0, "max": 3.0, Loading @@ -229,7 +229,7 @@ }, { "key_as_string": "2013-04-01", "doc_count": 1, "value": { "stats#value": { "min": 2.0, "avg": 2.0, "max": 2.0, Loading @@ -240,7 +240,7 @@ }, { "key_as_string": "2013-07-01", "doc_count": 0, "value": { "stats#value": { "min": null, "avg": null, "max": null, Loading @@ -251,7 +251,7 @@ }, { "key_as_string": "2013-10-01", "doc_count": 1, "value": { "stats#value": { "min": 1.0, "avg": 1.0, "max": 1.0, Loading @@ -268,18 +268,18 @@ "key": "root.122.2" }, { "doc_count": 3, "objectClassificationName": { "sterms#objectClassificationName": { "doc_count_error_upper_bound": 0, "sum_other_doc_count": 0, "buckets": [{ "doc_count": 3, "timeIntervals": { "reverse_nested#timeIntervals": { "doc_count": 3, "dateHistogram": { "buckets": [{ "key_as_string": "2013-01-01", "doc_count": 1, "value": { "stats#value": { "min": 3.0, "avg": 3.0, "max": 3.0, Loading @@ -290,7 +290,7 @@ }, { "key_as_string": "2013-04-01", "doc_count": 1, "value": { "stats#value": { "min": 7.0, "avg": 7.0, "max": 7.0, Loading @@ -301,7 +301,7 @@ }, { "key_as_string": "2013-07-01", "doc_count": 0, "value": { "stats#value": { "min": null, "avg": null, "max": null, Loading @@ -312,7 +312,7 @@ }, { "key_as_string": "2013-10-01", "doc_count": 1, "value": { "stats#value": { "min": 1.0, "avg": 1.0, "max": 1.0, Loading Loading
time-series-view/src/main/java/es/redmic/timeseriesview/mapper/ObjectCollectingSeriesESMapper.java +13 −13 Original line number Diff line number Diff line Loading @@ -115,21 +115,21 @@ public abstract class ObjectCollectingSeriesESMapper extends SeriesESMapper<Obje classification.setName(classificationType.get(i).get("key").toString()); /** Obtiene las estadisticas a nivel de tipo de classificación **/ List<Map<String, Object>> timeIntervals = ElasticSearchUtils .getBucketsFromAggregations((Map<String, Object>) classificationType.get(i).get("timeIntervals")); .getBucketsFromAggregations((Map<String, Object>) classificationType.get(i).get("reverse_nested#timeIntervals")); for (int timeIntervalsIt = 0; timeIntervalsIt < timeIntervals.size(); timeIntervalsIt++) { classification.addHeader(timeIntervals.get(timeIntervalsIt).get("key_as_string").toString()); classification.addV(getValue((Map<String, Object>) timeIntervals.get(timeIntervalsIt).get("value"))); classification.addV(getValue((Map<String, Object>) timeIntervals.get(timeIntervalsIt).get("stats#value"))); } /** Obtiene todas las clasificaciones del tipo actual **/ List<Map<String, Object>> levels = ElasticSearchUtils.getBucketsFromAggregations( (Map<String, Object>) classificationType.get(i).get("objectClassification")); (Map<String, Object>) classificationType.get(i).get("nested#objectClassification")); List<ObjectClassificationForListDTO> data = new ArrayList<>(); for (int levelIt = 0; levelIt < levels.size(); levelIt++) { // niveles de clasificación /** Obtiene cada uno de los elementos de la clasificación **/ List<Map<String, Object>> objects = ElasticSearchUtils.getBucketsFromAggregations( (Map<String, Object>) levels.get(levelIt).get("objectClassificationPath")); (Map<String, Object>) levels.get(levelIt).get("sterms#objectClassificationPath")); boolean isLeave = (levelIt == levels.size() - 1); for (int objectIt = 0; objectIt < objects.size(); objectIt++) { // objectos Loading @@ -140,11 +140,11 @@ public abstract class ObjectCollectingSeriesESMapper extends SeriesESMapper<Obje object.setLeaves(1); List<Map<String, Object>> type = ElasticSearchUtils.getBucketsFromAggregations( (Map<String, Object>) objects.get(objectIt).get("objectClassificationName")); (Map<String, Object>) objects.get(objectIt).get("sterms#objectClassificationName")); object.setCategory(type.get(0).get("key").toString()); List<Map<String, Object>> timeIntervalsObject = ElasticSearchUtils .getBucketsFromAggregations((Map<String, Object>) type.get(0).get("timeIntervals")); .getBucketsFromAggregations((Map<String, Object>) type.get(0).get("reverse_nested#timeIntervals")); for (int timeIntervalsIt = 0; timeIntervalsIt < timeIntervalsObject.size(); timeIntervalsIt++) { // posición donde se debe insertar el dato y que depende del intervalo actual Loading @@ -152,7 +152,7 @@ public abstract class ObjectCollectingSeriesESMapper extends SeriesESMapper<Obje .getHeaderPos(timeIntervalsObject.get(timeIntervalsIt).get("key_as_string").toString()); Map<String, Object> stats = (Map<String, Object>) timeIntervalsObject.get(timeIntervalsIt) .get("value"); .get("stats#value"); object.setV(pos, getValue(stats)); // Setea el número de hijos si no es una hoja Integer count = (Integer) stats.get("count"); Loading Loading @@ -185,7 +185,7 @@ public abstract class ObjectCollectingSeriesESMapper extends SeriesESMapper<Obje String timeInterval = classificationIntervals.get(i).get("key_as_string").toString(); List<Map<String, Object>> types = ElasticSearchUtils .getBucketsFromAggregations((Map<String, Object>) classificationIntervals.get(i).get("object")); .getBucketsFromAggregations((Map<String, Object>) classificationIntervals.get(i).get("nested#object")); for (int typesIt = 0; typesIt < types.size(); typesIt++) { Loading @@ -203,7 +203,7 @@ public abstract class ObjectCollectingSeriesESMapper extends SeriesESMapper<Obje /** Obtiene todas las clasificaciones para recorrerlas por niveles **/ List<Map<String, Object>> levels = ElasticSearchUtils.getBucketsFromAggregations( (Map<String, Object>) types.get(typesIt).get("objectClassification")); (Map<String, Object>) types.get(typesIt).get("nested#objectClassification")); for (int levelIt = 0; levelIt < levels.size(); levelIt++) { Loading @@ -211,19 +211,19 @@ public abstract class ObjectCollectingSeriesESMapper extends SeriesESMapper<Obje * Obtiene cada uno de los elementos de la clasificación **/ List<Map<String, Object>> objects = ElasticSearchUtils.getBucketsFromAggregations( (Map<String, Object>) levels.get(levelIt).get("objectClassificationPath")); (Map<String, Object>) levels.get(levelIt).get("sterms#objectClassificationPath")); for (int objectIt = 0; objectIt < objects.size(); objectIt++) { // objectos List<Map<String, Object>> type = ElasticSearchUtils.getBucketsFromAggregations( (Map<String, Object>) objects.get(objectIt).get("objectClassificationName")); (Map<String, Object>) objects.get(objectIt).get("sterms#objectClassificationName")); /** * Obtiene las estadisticas a nivel de tipo de classificación **/ Map<String, Object> stats = (Map<String, Object>) type.get(0).get("stats"); Map<String, Object> stats = (Map<String, Object>) type.get(0).get("reverse_nested#stats"); interval.addCategory(objects.get(objectIt).get("key").toString(), type.get(0).get("key").toString(), getValue((Map<String, Object>) stats.get("value"))); type.get(0).get("key").toString(), getValue((Map<String, Object>) stats.get("stats#value"))); } } data.add(interval); Loading
time-series-view/src/main/java/es/redmic/timeseriesview/repository/ObjectCollectingSeriesESRepository.java +7 −5 Original line number Diff line number Diff line Loading @@ -47,6 +47,7 @@ import es.redmic.timeseriesview.model.objectcollectingseries.ObjectCollectingSer public class ObjectCollectingSeriesESRepository extends RWSeriesESRepository<ObjectCollectingSeries, DataQueryDTO> { private static final String objectNestedPath = "object"; private static final String activityField = "activityId"; private static int aggsSize = 200; Loading Loading @@ -99,7 +100,7 @@ public class ObjectCollectingSeriesESRepository extends RWSeriesESRepository<Obj : DateHistogramInterval.QUARTER) .subAggregation(AggregationBuilders.stats(defaultField).field(defaultField)); return AggregationBuilders.nested("object", "object") return AggregationBuilders.nested(objectNestedPath, objectNestedPath) .subAggregation(AggregationBuilders.terms("objectType").field("object.name") .subAggregation( AggregationBuilders.reverseNested("timeIntervals").subAggregation(dateHistogramBuilder)) Loading @@ -123,7 +124,7 @@ public class ObjectCollectingSeriesESRepository extends RWSeriesESRepository<Obj return getDateHistogramAggregation( elasticQueryDTO.getInterval() != null ? SeriesQueryUtils.getInterval(elasticQueryDTO.getInterval()) : DateHistogramInterval.QUARTER) .subAggregation(AggregationBuilders.nested("object", "object") .subAggregation(AggregationBuilders.nested(objectNestedPath, objectNestedPath) .subAggregation(AggregationBuilders.terms("objectType").field("object.name") .subAggregation(AggregationBuilders.nested("objectClassification", "object.classification") .subAggregation(AggregationBuilders Loading Loading @@ -153,13 +154,14 @@ public class ObjectCollectingSeriesESRepository extends RWSeriesESRepository<Obj @Override protected QueryBuilder getTermQuery(Map<String, Object> terms, BoolQueryBuilder query) { if (terms != null && terms.containsKey("grandparentId")) { // Se mantiene grandparentId por retrocompatibilidad if (terms != null && (terms.containsKey("grandparentId") || terms.containsKey(activityField))) { String activityId = (String) terms.get("grandparentId"); query.must(QueryBuilders.boolQuery().filter(QueryBuilders.termQuery("activityId", activityId))); query.must(QueryBuilders.boolQuery().filter(QueryBuilders.termQuery(activityField, activityId))); } else { throw new ESTermQueryException("activityId", "null"); throw new ESTermQueryException(activityField, "null"); } return query; Loading
time-series-view/src/test/java/es/redmic/test/timeseriesview/integration/controller/ObjectCollectingSeriesControllerTest.java +55 −14 Original line number Diff line number Diff line Loading @@ -21,6 +21,7 @@ package es.redmic.test.timeseriesview.integration.controller; */ import static org.hamcrest.CoreMatchers.is; import static org.hamcrest.CoreMatchers.notNullValue; import static org.springframework.restdocs.mockmvc.RestDocumentationRequestBuilders.get; import static org.springframework.restdocs.mockmvc.RestDocumentationRequestBuilders.post; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath; Loading Loading @@ -53,6 +54,8 @@ import org.springframework.web.context.WebApplicationContext; import es.redmic.models.es.common.query.dto.DataQueryDTO; import es.redmic.test.timeseriesview.integration.common.controller.SeriesControllerBaseTest; import es.redmic.timeseriesview.TimeSeriesViewApplication; import es.redmic.timeseriesview.model.objectcollectingseries.ObjectCollectingSeries; import es.redmic.timeseriesview.repository.ObjectCollectingSeriesESRepository; @SpringBootTest(classes = { TimeSeriesViewApplication.class }) @ActiveProfiles("test") Loading @@ -65,6 +68,9 @@ public class ObjectCollectingSeriesControllerTest extends SeriesControllerBaseTe @Autowired protected FilterChainProxy springSecurityFilterChain; @Autowired ObjectCollectingSeriesESRepository repository; protected MockMvc mockMvc; @Value("${controller.mapping.OBJECTCOLLECTING}") Loading @@ -76,6 +82,11 @@ public class ObjectCollectingSeriesControllerTest extends SeriesControllerBaseTe @Value("${controller.mapping.OBJECT_CLASSIFICATION_LIST}") private String OBJECT_CLASSIFICATION_LIST; @Value("${controller.mapping.OBJECT_CLASSIFICATION}") private String OBJECT_CLASSIFICATION; DataQueryDTO dataQuery; @BeforeClass public static void beforeClass() { } Loading @@ -85,13 +96,27 @@ public class ObjectCollectingSeriesControllerTest extends SeriesControllerBaseTe mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).addFilters(springSecurityFilterChain) .build(); String modelPath = "/data/objectcollectingseries/model/objectCollectingSeriesModel.json"; ObjectCollectingSeries objectCollectingSeries = mapper.readValue(getClass().getResource(modelPath).openStream(), ObjectCollectingSeries.class); repository.save(objectCollectingSeries); dataQuery = new DataQueryDTO(); Map<String, Object> terms = new HashMap<>(); terms.put("parentId", "sdsd323sdds_3ed"); terms.put("grandparentId", "3"); dataQuery.setTerms(terms); dataQuery.setInterval("1q"); } @After public void restore() { } @Test public void getObjectClassificationListSchema_Return200_WhenSchemaIsFound() throws Exception { Loading @@ -112,28 +137,44 @@ public class ObjectCollectingSeriesControllerTest extends SeriesControllerBaseTe @Test public void getObjectClassificationList_Return200_IfQueryIsOK() throws Exception { String searchSchema = "/data/objectcollectingseries/schema/searchSchema.json"; // @formatter:off DataQueryDTO dataQuery = new DataQueryDTO(); Map<String, Object> terms = new HashMap<>(); terms.put("parentId", "6f49792c-b2b2-4875-8f00-9729b24b0e1b"); terms.put("grandparentId", "1193"); dataQuery.setTerms(terms); this.mockMvc .perform(post(OBJECTCOLLECTINGSERIES_BASE_PATH + OBJECT_CLASSIFICATION_LIST + "/_search") .content(getQueryAsString(dataQuery)) .contentType(MediaType.APPLICATION_JSON).accept(MediaType.APPLICATION_JSON)) .andExpect(status().is(200)) .andExpect(jsonPath("$.success", is(true))) .andExpect(jsonPath("$.body", notNullValue())) .andExpect(jsonPath("$.body.length()", is(2))) .andExpect(jsonPath("$.body[0].name", notNullValue())) .andExpect(jsonPath("$.body[0].v", notNullValue())) .andExpect(jsonPath("$.body[0].v.length()", is(1))) .andExpect(jsonPath("$.body[0].data", notNullValue())) .andExpect(jsonPath("$.body[0].data.length()", is(3))) .andExpect(jsonPath("$.body[0].header", notNullValue())); dataQuery.setInterval("1q"); // @formatter:on } @Test public void getObjectClassification_Return200_IfQueryIsOK() throws Exception { // @formatter:off MvcResult result = this.mockMvc .perform(post(OBJECTCOLLECTINGSERIES_BASE_PATH + OBJECT_CLASSIFICATION_LIST + "/_search") this.mockMvc .perform(post(OBJECTCOLLECTINGSERIES_BASE_PATH + OBJECT_CLASSIFICATION + "/_search") .content(getQueryAsString(dataQuery)) .contentType(MediaType.APPLICATION_JSON).accept(MediaType.APPLICATION_JSON)) .andExpect(status().is(200)) .andExpect(jsonPath("$.success", is(true))).andReturn(); System.out.println(result.getResponse().getContentAsString()); .andExpect(jsonPath("$.success", is(true))) .andExpect(jsonPath("$.body", notNullValue())) .andExpect(jsonPath("$.body.length()", is(2))) .andExpect(jsonPath("$.body[0].data", notNullValue())) .andExpect(jsonPath("$.body[0].data.length()", is(1))) .andExpect(jsonPath("$.body[0].data[0].categories", notNullValue())) .andExpect(jsonPath("$.body[0].data[0].timeInterval", notNullValue())); //.andExpect(jsonPath("$.body", is(mapper.readValue(getClass().getResource(searchSchema).openStream(), Map.class)))); // @formatter:on } Loading
time-series-view/src/test/java/es/redmic/test/timeseriesview/integration/controller/WindRoseControllerTest.java +0 −1 Original line number Diff line number Diff line Loading @@ -52,7 +52,6 @@ import org.springframework.web.context.WebApplicationContext; import com.fasterxml.jackson.core.JsonParseException; import com.fasterxml.jackson.core.type.TypeReference; import com.fasterxml.jackson.databind.JsonMappingException; import com.fasterxml.jackson.databind.ObjectMapper; import es.redmic.models.es.common.query.dto.DataQueryDTO; import es.redmic.models.es.common.query.dto.DateLimitsDTO; Loading
time-series-view/src/test/resources/data/objectcollectingseries/model/classificationForList.json +33 −33 Original line number Diff line number Diff line Loading @@ -15,14 +15,14 @@ "buckets": [{ "doc_count": 93, "key": "Basura - OSPAR", "timeIntervals": { "reverse_nested#timeIntervals": { "doc_count": 74, "dateHistogram": { "buckets": [{ "key_as_string": "2013-01-01", "key": 1356998400000, "doc_count": 17, "value": { "stats#value": { "count": 17, "min": 1, "max": 15, Loading @@ -33,7 +33,7 @@ "key_as_string": "2013-04-01", "key": 1364774400000, "doc_count": 29, "value": { "stats#value": { "count": 29, "min": 1, "max": 205, Loading @@ -44,7 +44,7 @@ "key_as_string": "2013-07-01", "key": 1372636800000, "doc_count": 0, "value": { "stats#value": { "count": 0, "min": null, "max": null, Loading @@ -55,7 +55,7 @@ "key_as_string": "2013-10-01", "key": 1380585600000, "doc_count": 28, "value": { "stats#value": { "count": 28, "min": 1, "max": 90, Loading @@ -65,30 +65,30 @@ }] } }, "objectClassification": { "nested#objectClassification": { "doc_count": 167, "level": { "doc_count_error_upper_bound": 0, "sum_other_doc_count": 0, "buckets": [{ "doc_count": 93, "objectClassificationPath": { "sterms#objectClassificationPath": { "doc_count_error_upper_bound": 0, "sum_other_doc_count": 0, "buckets": [{ "doc_count": 35, "objectClassificationName": { "sterms#objectClassificationName": { "doc_count_error_upper_bound": 0, "sum_other_doc_count": 0, "buckets": [{ "doc_count": 35, "timeIntervals": { "reverse_nested#timeIntervals": { "doc_count": 35, "dateHistogram": { "buckets": [{ "key_as_string": "2013-01-01", "doc_count": 10, "value": { "stats#value": { "min": 1.0, "avg": 7.0, "max": 35.0, Loading @@ -99,7 +99,7 @@ }, { "key_as_string": "2013-04-01", "doc_count": 14, "value": { "stats#value": { "min": 1.0, "avg": 11.285714285714286, "max": 79.0, Loading @@ -110,7 +110,7 @@ }, { "key_as_string": "2013-07-01", "doc_count": 0, "value": { "stats#value": { "min": null, "avg": null, "max": null, Loading @@ -121,7 +121,7 @@ }, { "key_as_string": "2013-10-01", "doc_count": 11, "value": { "stats#value": { "min": 1.0, "avg": 5.636363636363637, "max": 31.0, Loading @@ -141,23 +141,23 @@ "key": 1 }, { "doc_count": 74, "objectClassificationPath": { "sterms#objectClassificationPath": { "doc_count_error_upper_bound": 0, "sum_other_doc_count": 0, "buckets": [{ "doc_count": 3, "objectClassificationName": { "sterms#objectClassificationName": { "doc_count_error_upper_bound": 0, "sum_other_doc_count": 0, "buckets": [{ "doc_count": 3, "timeIntervals": { "reverse_nested#timeIntervals": { "doc_count": 3, "dateHistogram": { "buckets": [{ "key_as_string": "2013-01-01", "doc_count": 1, "value": { "stats#value": { "min": 15.0, "avg": 15.0, "max": 15.0, Loading @@ -168,7 +168,7 @@ }, { "key_as_string": "2013-04-01", "doc_count": 1, "value": { "stats#value": { "min": 7.0, "avg": 7.0, "max": 7.0, Loading @@ -179,7 +179,7 @@ }, { "key_as_string": "2013-07-01", "doc_count": 0, "value": { "stats#value": { "min": null, "avg": null, "max": null, Loading @@ -190,7 +190,7 @@ }, { "key_as_string": "2013-10-01", "doc_count": 1, "value": { "stats#value": { "min": 4.0, "avg": 4.0, "max": 4.0, Loading @@ -207,18 +207,18 @@ "key": "root.122.15" }, { "doc_count": 3, "objectClassificationName": { "sterms#objectClassificationName": { "doc_count_error_upper_bound": 0, "sum_other_doc_count": 0, "buckets": [{ "doc_count": 3, "timeIntervals": { "reverse_nested#timeIntervals": { "doc_count": 3, "dateHistogram": { "buckets": [{ "key_as_string": "2013-01-01", "doc_count": 1, "value": { "stats#value": { "min": 3.0, "avg": 3.0, "max": 3.0, Loading @@ -229,7 +229,7 @@ }, { "key_as_string": "2013-04-01", "doc_count": 1, "value": { "stats#value": { "min": 2.0, "avg": 2.0, "max": 2.0, Loading @@ -240,7 +240,7 @@ }, { "key_as_string": "2013-07-01", "doc_count": 0, "value": { "stats#value": { "min": null, "avg": null, "max": null, Loading @@ -251,7 +251,7 @@ }, { "key_as_string": "2013-10-01", "doc_count": 1, "value": { "stats#value": { "min": 1.0, "avg": 1.0, "max": 1.0, Loading @@ -268,18 +268,18 @@ "key": "root.122.2" }, { "doc_count": 3, "objectClassificationName": { "sterms#objectClassificationName": { "doc_count_error_upper_bound": 0, "sum_other_doc_count": 0, "buckets": [{ "doc_count": 3, "timeIntervals": { "reverse_nested#timeIntervals": { "doc_count": 3, "dateHistogram": { "buckets": [{ "key_as_string": "2013-01-01", "doc_count": 1, "value": { "stats#value": { "min": 3.0, "avg": 3.0, "max": 3.0, Loading @@ -290,7 +290,7 @@ }, { "key_as_string": "2013-04-01", "doc_count": 1, "value": { "stats#value": { "min": 7.0, "avg": 7.0, "max": 7.0, Loading @@ -301,7 +301,7 @@ }, { "key_as_string": "2013-07-01", "doc_count": 0, "value": { "stats#value": { "min": null, "avg": null, "max": null, Loading @@ -312,7 +312,7 @@ }, { "key_as_string": "2013-10-01", "doc_count": 1, "value": { "stats#value": { "min": 1.0, "avg": 1.0, "max": 1.0, Loading