Commit c3b1a107 authored by Noel Alonso's avatar Noel Alonso
Browse files

Elimina componentes de series temporales

parent 83d4b8f9
Loading
Loading
Loading
Loading
+3 −42
Original line number Diff line number Diff line
@@ -46,8 +46,6 @@ import com.kjetland.jackson.jsonSchema.JsonSchemaResources;

import es.redmic.api.common.controller.RWController;
import es.redmic.api.geodata.common.controller.RWGeoDataController;
import es.redmic.api.series.common.controller.RWSeriesController;
import es.redmic.api.series.common.controller.RWSeriesWithOutDataDefinitionController;
import es.redmic.mediastorage.service.MediaStorageService;
import es.redmic.models.es.administrative.dto.ActivityPlatformRoleDTO;
import es.redmic.models.es.administrative.dto.ContactOrganisationRoleDTO;
@@ -133,43 +131,6 @@ public class GenerateJsonSchemaScanBean implements ApplicationContextAware {
			}
		}

		@SuppressWarnings("rawtypes")
		final Map<String, RWSeriesWithOutDataDefinitionController> seriesNewControllers = applicationContext
				.getBeansOfType(RWSeriesWithOutDataDefinitionController.class);
		for (@SuppressWarnings("rawtypes")
		final RWSeriesWithOutDataDefinitionController controller : seriesNewControllers.values()) {

			try {
				Class<?> typeOfTDTO = (Class<?>) ((ParameterizedType) controller.getClass().getGenericSuperclass())
						.getActualTypeArguments()[2];
				generateAndSaveJsonSchema(typeOfTDTO);

			} catch (Exception e) {
				System.err.println("Error al generar el jsonSchema " + controller.getClass());
				e.printStackTrace();
			}
		}

		// TODO: eliminar cuando las series se pasen a lo nuevo (filtrado
		// siempre por actividad y geodata
		/* Genera los esquemas de Json de series */
		@SuppressWarnings("rawtypes")
		final Map<String, RWSeriesController> seriesControllers = applicationContext
				.getBeansOfType(RWSeriesController.class);
		for (@SuppressWarnings("rawtypes")
		final RWSeriesController controller : seriesControllers.values()) {

			try {
				Class<?> typeOfTDTO = (Class<?>) ((ParameterizedType) controller.getClass().getGenericSuperclass())
						.getActualTypeArguments()[1];
				generateAndSaveJsonSchema(typeOfTDTO);

			} catch (Exception e) {
				System.err.println("Error al generar el jsonSchema " + controller.getClass());
				e.printStackTrace();
			}
		}

		for (int i = 0; i < specialBeansToGenerate.size(); i++) {

			try {
+0 −44
Original line number Diff line number Diff line
package es.redmic.api.series.common.controller;

/*-
 * #%L
 * API
 * %%
 * 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 javax.validation.Valid;

import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;

import es.redmic.models.es.common.dto.SuperDTO;
import es.redmic.models.es.common.query.dto.SimpleQueryDTO;
import es.redmic.models.es.geojson.common.dto.MetaFeatureDTO;
import es.redmic.models.es.geojson.common.model.Feature;
import es.redmic.models.es.geojson.properties.model.GeoDataProperties;

public interface IRSeriesController<TModel extends Feature<GeoDataProperties, ?>, TDTO extends MetaFeatureDTO<?, ?>, TQueryDTO extends SimpleQueryDTO> {

	public SuperDTO _search(@RequestParam(required = false, value = "from") Integer from,
			@RequestParam(required = false, value = "size") Integer size);

	public SuperDTO _advancedSearch(@Valid @RequestBody TQueryDTO queryDTO, BindingResult errorDto);

	public SuperDTO _get(@PathVariable("id") String id);
}
+0 −88
Original line number Diff line number Diff line
package es.redmic.api.series.common.controller;

/*-
 * #%L
 * API
 * %%
 * 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 javax.validation.Valid;

import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import es.redmic.api.common.controller.RBaseController;
import es.redmic.es.series.common.service.RSeriesESService;
import es.redmic.exception.custom.ResourceNotFoundException;
import es.redmic.models.es.common.dto.ElasticSearchDTO;
import es.redmic.models.es.common.dto.JSONCollectionDTO;
import es.redmic.models.es.common.dto.SuperDTO;
import es.redmic.models.es.common.query.dto.SimpleQueryDTO;
import es.redmic.models.es.series.common.dto.SeriesBaseDTO;
import es.redmic.models.es.series.common.model.SeriesBase;

public abstract class RSeriesController<TModel extends SeriesBase, TDTO extends SeriesBaseDTO, TQueryDTO extends SimpleQueryDTO>
		extends RBaseController<TModel, TDTO, TQueryDTO> {

	protected RSeriesESService<TModel, TDTO> ESService;

	protected RSeriesController(RSeriesESService<TModel, TDTO> service) {
		super(service);
		ESService = service;
	}

	@SuppressWarnings("unchecked")
	@GetMapping(value = "")
	@ResponseBody
	public SuperDTO _search(@RequestParam(required = false, value = "from") Integer from,
			@RequestParam(required = false, value = "size") Integer size) {

		SimpleQueryDTO queryDTO = ESService.createSimpleQueryDTOFromQueryParams(from, size);
		processQuery((TQueryDTO) queryDTO);
		return new ElasticSearchDTO(ESService.find(convertToGeoDataQuery((TQueryDTO) queryDTO)));
	}

	@PostMapping(value = "/_search")
	@ResponseBody
	public SuperDTO _advancedSearch(@Valid @RequestBody TQueryDTO queryDTO, BindingResult errorDto) {

		processQuery(queryDTO, errorDto);

		JSONCollectionDTO result = ESService.find(convertToGeoDataQuery(queryDTO));
		return new ElasticSearchDTO(result, result.getTotal());
	}

	@GetMapping(value = "/{id}")
	@ResponseBody
	public SuperDTO _get(@PathVariable("id") String id) {

		TDTO result = ESService.searchById(id);
		return new ElasticSearchDTO(result, result == null ? 0 : 1);
	}

	@GetMapping(value = "/_suggest")
	@ResponseBody
	public SuperDTO _suggest() {

		throw new ResourceNotFoundException();
	}
}
+0 −93
Original line number Diff line number Diff line
package es.redmic.api.series.common.controller;

/*-
 * #%L
 * API
 * %%
 * 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 javax.validation.Valid;

import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import es.redmic.api.common.controller.RBaseController;
import es.redmic.es.series.common.service.RSeriesESService;
import es.redmic.exception.custom.ResourceNotFoundException;
import es.redmic.models.es.common.dto.ElasticSearchDTO;
import es.redmic.models.es.common.dto.JSONCollectionDTO;
import es.redmic.models.es.common.dto.SuperDTO;
import es.redmic.models.es.common.query.dto.SimpleQueryDTO;
import es.redmic.models.es.series.common.dto.SeriesCommonDTO;
import es.redmic.models.es.series.common.model.SeriesCommon;

public abstract class RSeriesWithOutDataDefinitionController<TModel extends SeriesCommon, TDTO extends SeriesCommonDTO, TQueryDTO extends SimpleQueryDTO>
		extends RBaseController<TModel, TDTO, TQueryDTO> {

	protected RSeriesESService<TModel, TDTO> ESService;

	protected RSeriesWithOutDataDefinitionController(RSeriesESService<TModel, TDTO> service) {
		super(service);
		ESService = service;
	}

	@SuppressWarnings("unchecked")
	@GetMapping(value = "")
	@ResponseBody
	public SuperDTO _search(@PathVariable("activityId") String activityId, @PathVariable("uuid") String uuid,
			@RequestParam(required = false, value = "from") Integer from,
			@RequestParam(required = false, value = "size") Integer size) {

		SimpleQueryDTO queryDTO = ESService.createSimpleQueryDTOFromQueryParams(from, size);
		processQuery((TQueryDTO) queryDTO);
		return new ElasticSearchDTO(ESService.find(convertToGeoDataQuery((TQueryDTO) queryDTO), uuid, activityId));
	}

	@PostMapping(value = "/_search")
	@ResponseBody
	public SuperDTO _advancedSearch(@PathVariable("activityId") String activityId, @PathVariable("uuid") String uuid,
			@Valid @RequestBody TQueryDTO queryDTO, BindingResult errorDto) {

		processQuery(queryDTO, errorDto);

		JSONCollectionDTO result = ESService.find(convertToGeoDataQuery(queryDTO), uuid, activityId);
		return new ElasticSearchDTO(result, result.getTotal());
	}

	@GetMapping(value = "/{id}")
	@ResponseBody
	public SuperDTO _get(@PathVariable("activityId") String activityId, @PathVariable("uuid") String uuid,
			@PathVariable("id") String id) {

		TDTO result = ESService.get(id, uuid, activityId);
		return new ElasticSearchDTO(result, result == null ? 0 : 1);
	}

	@GetMapping(value = "/_suggest")
	@ResponseBody
	public SuperDTO _suggest() {

		throw new ResourceNotFoundException();
	}
}
+0 −97
Original line number Diff line number Diff line
package es.redmic.api.series.common.controller;

/*-
 * #%L
 * API
 * %%
 * 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 java.lang.reflect.ParameterizedType;
import java.util.HashMap;

import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import es.redmic.api.common.service.JsonSchemaService;
import es.redmic.databaselib.common.model.LongModel;
import es.redmic.db.series.common.service.RWBaseSeriesService;
import es.redmic.exception.databinding.DTONotValidException;
import es.redmic.models.es.common.dto.BodyItemDTO;
import es.redmic.models.es.common.dto.SuperDTO;
import es.redmic.models.es.series.common.dto.SeriesBaseDTO;

public abstract class RWSeriesController<TModel extends LongModel, TDTO extends SeriesBaseDTO> {
	
	@Autowired
	JsonSchemaService jsonSchemaService;
	
	private Class<TDTO> typeOfTDTO;

	private RWBaseSeriesService<TModel, TDTO> service;

	@SuppressWarnings("unchecked")
	public RWSeriesController(RWBaseSeriesService<TModel, TDTO> service) {
		this.service = service;
		this.typeOfTDTO = (Class<TDTO>) ((ParameterizedType) getClass().getGenericSuperclass())
				.getActualTypeArguments()[1];
	}
	
	@RequestMapping(value = "/", method = RequestMethod.POST)
	@ResponseBody
	public SuperDTO addSeries(@Valid @RequestBody TDTO dto, BindingResult errorDto,
			@PathVariable("dataDefinitionId") Long dataDefinitionId) {
		if (errorDto.hasErrors())
			throw new DTONotValidException(errorDto);

		dto.setDataDefinition(dataDefinitionId);

		return new BodyItemDTO<TDTO>(service.save(dto));
	}

	@RequestMapping(value = "/{id}", method = RequestMethod.PUT)
	@ResponseBody
	public SuperDTO updateSeries(@Valid @RequestBody TDTO dto, BindingResult errorDto,
			@PathVariable("id") Long id, @PathVariable("dataDefinitionId") Long dataDefinitionId) {
		if (errorDto.hasErrors())
			throw new DTONotValidException(errorDto);
		dto.setId(id);
		dto.setDataDefinition(dataDefinitionId);
		return new BodyItemDTO<TDTO>(service.update(dto));
	}

	@RequestMapping(value = "/{id}", method = RequestMethod.DELETE)
	@ResponseBody
	public SuperDTO delete(@PathVariable("dataDefinitionId") Long dataDefinitionId, @PathVariable("id") Long id) {
		service.delete(id);
		return new SuperDTO(true);
	}
	
	@RequestMapping(value = "${controller.mapping.EDIT_SCHEMA}", method = RequestMethod.GET)
	@ResponseBody
	public HashMap<String,Object> getJsonSchema(HttpServletResponse response) {
		
		return jsonSchemaService.getJsonSchema(typeOfTDTO.getName());
	}
}
Loading