Commit 5168f89a authored by Noel Alonso's avatar Noel Alonso
Browse files

Añade controladores de esquema de búsqueda + tests

parent 6488f047
Loading
Loading
Loading
Loading
+11 −0
Original line number Diff line number Diff line
@@ -24,6 +24,7 @@ import javax.validation.Valid;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
@@ -31,6 +32,7 @@ import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import es.redmic.exception.databinding.DTONotValidException;
import es.redmic.models.es.common.dto.ElasticSearchDTO;
import es.redmic.models.es.common.dto.SuperDTO;
import es.redmic.models.es.common.query.dto.AggsPropertiesDTO;
import es.redmic.models.es.common.query.dto.DataQueryDTO;
@@ -96,4 +98,13 @@ public class ObjectCollectingSeriesController extends RSeriesController<ObjectCo

		return service.findTemporalDataStatistics(queryDTO);
	}


	@GetMapping(value = { "${controller.mapping.OBJECT_CLASSIFICATION_LIST_SCHEMA}",
		"${controller.mapping.OBJECT_CLASSIFICATION_SCHEMA}" })
	@ResponseBody
	public ElasticSearchDTO getAdditionalFilterSchema() {

		return new ElasticSearchDTO(service.getFilterSchema(fieldsExcludedOnQuery), 1);
	}
}
+1 −0
Original line number Diff line number Diff line
@@ -46,6 +46,7 @@ controller.mapping.TIMESERIES_ACTIVITY=/activities/{activityId}

controller.mapping.SERIES_WINDROSE=/windrose

controller.mapping.OBJECTCOLLECTING=/objectcollectingseries

controller.mapping.OBJECT_CLASSIFICATION_LIST=/classificationlist
controller.mapping.OBJECT_CLASSIFICATION_LIST_SCHEMA=${controller.mapping.OBJECT_CLASSIFICATION_LIST}${controller.mapping.FILTER_SCHEMA}
+121 −0
Original line number Diff line number Diff line
package es.redmic.test.timeseriesview.integration.controller;

/*-
 * #%L
 * Time series view
 * %%
 * Copyright (C) 2019 REDMIC Project / Server
 * %%
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * #L%
 */

import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.CoreMatchers.notNullValue;
import static org.springframework.restdocs.mockmvc.RestDocumentationRequestBuilders.get;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;

import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.joda.time.DateTime;
import org.joda.time.DateTimeZone;
import org.junit.After;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.http.MediaType;
import org.springframework.security.web.FilterChainProxy;
import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.test.web.servlet.MvcResult;
import org.springframework.test.web.servlet.setup.MockMvcBuilders;
import org.springframework.web.context.WebApplicationContext;

import com.fasterxml.jackson.core.JsonParseException;
import com.fasterxml.jackson.core.JsonProcessingException;
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;
import es.redmic.timeseriesview.TimeSeriesViewApplication;
import es.redmic.timeseriesview.model.timeseries.TimeSeries;
import es.redmic.timeseriesview.repository.TimeSeriesESRepository;

@SpringBootTest(classes = { TimeSeriesViewApplication.class })
@ActiveProfiles("test")
@RunWith(SpringJUnit4ClassRunner.class)
public class ObjectCollectingSeriesControllerTest {

	@Autowired
	protected WebApplicationContext webApplicationContext;

	@Autowired
	protected FilterChainProxy springSecurityFilterChain;

	protected MockMvc mockMvc;

	@Autowired
	ObjectMapper mapper;


	@Value("${controller.mapping.OBJECTCOLLECTING}")
	private String OBJECTCOLLECTINGSERIES_BASE_PATH;

	@Value("${controller.mapping.OBJECT_CLASSIFICATION_LIST_SCHEMA}")
	private String OBJECT_CLASSIFICATION_LIST_SCHEMA;

	@BeforeClass
	public static void beforeClass() {
	}

	@Before
	public void setUp() throws JsonParseException, JsonMappingException, IOException {

		mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).addFilters(springSecurityFilterChain)
				.build();
	}

	@After
	public void restore() {
	}


	@Test
	public void getObjectClassificationListSchema_Return200_WhenSchemaIsFound() throws Exception {

		String searchSchema = "/data/objectcollectingseries/schema/searchSchema.json";

		// @formatter:off

		this.mockMvc
			.perform(get(OBJECTCOLLECTINGSERIES_BASE_PATH + OBJECT_CLASSIFICATION_LIST_SCHEMA)
				.contentType(MediaType.APPLICATION_JSON).accept(MediaType.APPLICATION_JSON))
			.andExpect(status().is(200))
			.andExpect(jsonPath("$.success", is(true)))
			.andExpect(jsonPath("$.body", is(mapper.readValue(getClass().getResource(searchSchema).openStream(), Map.class))));

		// @formatter:on
	}
}
+267 −0
Original line number Diff line number Diff line
{
    "schema": {
        "$schema": "http://json-schema.org/draft-04/schema#",
        "title": "Data Query DTO",
        "type": "object",
        "properties": {
            "from": {
                "type": ["integer", "null"],
                "default": "0"
            },
            "size": {
                "type": ["integer", "null"],
                "default": "100"
            },
            "terms": {
                "type": ["object", "null"],
                "additionalProperties": true
            },
            "sorts": {
                "type": ["array", "null"],
                "uniqueItems": true,
                "items": {
                    "$ref": "#/definitions/SortDTO"
                }
            },
            "returnFields": {
                "type": ["array", "null"],
                "uniqueItems": true,
                "items": {
                    "type": "string"
                }
            },
            "text": {
                "$ref": "#/definitions/TextQueryDTO"
            },
            "suggest": {
                "$ref": "#/definitions/SuggestQueryDTO"
            },
            "regexp": {
                "type": ["array", "null"],
                "uniqueItems": true,
                "items": {
                    "$ref": "#/definitions/RegexpDTO"
                }
            },
            "postFilter": {
                "type": ["object", "null"],
                "additionalProperties": true
            },
            "aggs": {
                "type": ["array", "null"],
                "uniqueItems": true,
                "items": {
                    "$ref": "#/definitions/AggsPropertiesDTO"
                }
            },
            "activityId": {
                "type": ["string", "null"]
            },
            "bbox": {
                "$ref": "#/definitions/BboxQueryDTO",
                "description": "Obtiene registros de geometrías comprendidas dentro de los límites especificados."
            },
            "precision": {
                "$ref": "#/definitions/PrecisionQueryDTO"
            },
            "qFlags": {
                "type": ["array", "null"],
                "maxItems": 11,
                "uniqueItems": true,
                "items": {
                    "type": "string"
                }
            },
            "vFlags": {
                "type": ["array", "null"],
                "maxItems": 5,
                "uniqueItems": true,
                "items": {
                    "type": "string"
                }
            },
            "dateLimits": {
                "$ref": "#/definitions/DateLimitsDTO"
            },
            "interval": {
                "type": ["string", "null"]
            },
            "z": {
                "$ref": "#/definitions/ZRangeDTO"
            },
            "value": {
                "type": ["array", "null"],
                "uniqueItems": true,
                "items": {
                    "$ref": "#/definitions/ValueQueryDTO"
                }
            }
        },
        "definitions": {
            "SortDTO": {
                "type": ["object", "null"],
                "properties": {
                    "field": {
                        "type": "string"
                    },
                    "order": {
                        "type": "string"
                    }
                },
                "required": ["field", "order"]
            },
            "TextQueryDTO": {
                "type": ["object", "null"],
                "properties": {
                    "text": {
                        "type": "string",
                        "minLength": 2
                    },
                    "searchFields": {
                        "type": "array",
                        "uniqueItems": true,
                        "items": {
                            "type": "string"
                        }
                    },
                    "highlightFields": {
                        "type": ["array", "null"],
                        "uniqueItems": true,
                        "items": {
                            "type": "string"
                        }
                    }
                },
                "required": ["text", "searchFields"]
            },
            "SuggestQueryDTO": {
                "type": ["object", "null"],
                "properties": {
                    "text": {
                        "type": "string",
                        "minLength": 2
                    },
                    "searchFields": {
                        "type": "array",
                        "uniqueItems": true,
                        "items": {
                            "type": "string"
                        }
                    },
                    "size": {
                        "type": ["integer", "null"]
                    }
                },
                "required": ["text", "searchFields"]
            },
            "RegexpDTO": {
                "type": ["object", "null"],
                "properties": {
                    "field": {
                        "type": "string"
                    },
                    "exp": {
                        "type": "string"
                    }
                },
                "required": ["field", "exp"]
            },
            "AggsPropertiesDTO": {
                "type": ["object", "null"],
                "properties": {
                    "field": {
                        "type": "string"
                    },
                    "term": {
                        "type": "string"
                    },
                    "nested": {
                        "type": ["string", "null"]
                    },
                    "size": {
                        "type": ["integer", "null"],
                        "default": "20"
                    },
                    "minCount": {
                        "type": ["integer", "null"]
                    }
                },
                "required": ["field", "term"]
            },
            "BboxQueryDTO": {
                "type": ["object", "null"],
                "properties": {
                    "bottomRightLat": {
                        "type": "number",
                        "minimum": -90,
                        "maximum": 90
                    },
                    "bottomRightLon": {
                        "type": "number",
                        "minimum": -180,
                        "maximum": 180
                    },
                    "topLeftLat": {
                        "type": "number",
                        "minimum": -90,
                        "maximum": 90
                    },
                    "topLeftLon": {
                        "type": "number",
                        "minimum": -180,
                        "maximum": 180
                    }
                },
                "required": ["bottomRightLat", "bottomRightLon", "topLeftLat", "topLeftLon"]
            },
            "PrecisionQueryDTO": {
                "type": ["object", "null"],
                "properties": {
                    "min": {
                        "type": ["number", "null"]
                    },
                    "max": {
                        "type": ["number", "null"]
                    }
                }
            },
            "DateLimitsDTO": {
                "type": ["object", "null"],
                "properties": {
                    "startDate": {
                        "type": ["string", "null"],
                        "format": "date-time"
                    },
                    "endDate": {
                        "type": ["string", "null"],
                        "format": "date-time"
                    }
                }
            },
            "ZRangeDTO": {
                "type": ["object", "null"],
                "properties": {
                    "min": {
                        "type": ["number", "null"]
                    },
                    "max": {
                        "type": ["number", "null"]
                    }
                }
            },
            "ValueQueryDTO": {
                "type": ["object", "null"],
                "properties": {
                    "op": {
                        "type": "number"
                    },
                    "operator": {
                        "type": "string",
                        "enum": ["Equal", "NotEqual", "Greater", "Less", "GreaterOrEqual", "LessOrEqual"]
                    }
                },
                "required": ["op", "operator"]
            }
        }
    }
}