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

Añade mapper y query por defecto

parent 9a0e2163
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -35,6 +35,7 @@ import es.redmic.models.es.common.deserializer.CustomDateTimeDeserializer;
import es.redmic.models.es.common.dto.DTOImplementWithMeta;
import es.redmic.models.es.common.serializer.CustomDateTimeSerializer;

@JsonIgnoreProperties(value = {"_meta"}, ignoreUnknown = true)
public class ObservationSeriesDTO extends DTOImplementWithMeta {

	@NotNull
+45 −0
Original line number Diff line number Diff line
package es.redmic.api.privatedata.mapper;

/*-
 * #%L
 * API
 * %%
 * Copyright (C) 2024 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 org.springframework.stereotype.Component;

import es.redmic.api.privatedata.dto.ObservationDTO;
import es.redmic.api.privatedata.model.Observation;
import es.redmic.models.es.administrative.taxonomy.dto.AnimalTaxonomyCompactDTO;
import es.redmic.models.es.administrative.taxonomy.dto.TaxonomyCompactDTO;
import es.redmic.models.es.common.dto.DomainDTO;
import es.redmic.models.es.maintenance.device.dto.DeviceCompactDTO;
import ma.glasnost.orika.CustomMapper;
import ma.glasnost.orika.MappingContext;

@Component
public class ObservationESMapper extends CustomMapper<Observation, ObservationDTO> {

	@Override
	public void mapAtoB(Observation a, ObservationDTO b, MappingContext context) {

		b.setTaxonomy(mapperFacade.map(a.getTaxonomy(), TaxonomyCompactDTO.class);
		b.setAnimal(mapperFacade.map(a.getAnimal(), AnimalTaxonomyCompactDTO.class));
		b.setDevice(mapperFacade.map(a.getDevice(), DeviceCompactDTO.class));
		b.setObservationType(mapperFacade.map(a.getObservationType(), DomainDTO.class));
	}
}
+40 −0
Original line number Diff line number Diff line
package es.redmic.api.privatedata.mapper;

/*-
 * #%L
 * API
 * %%
 * Copyright (C) 2024 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 org.springframework.stereotype.Component;

import es.redmic.api.privatedata.dto.ObservationDTO;
import es.redmic.api.privatedata.dto.ObservationSeriesDTO;
import es.redmic.api.privatedata.model.ObservationSeries;
import ma.glasnost.orika.CustomMapper;
import ma.glasnost.orika.MappingContext;

@Component
public class ObservationSeriesESMapper extends CustomMapper<ObservationSeries, ObservationSeriesDTO> {

	@Override
	public void mapAtoB(ObservationSeries a, ObservationSeriesDTO b, MappingContext context) {


		b.setObservationDTO(mapperFacade.map(a.getObservation(), ObservationDTO.class));
	}
}
+4 −0
Original line number Diff line number Diff line
@@ -67,6 +67,10 @@ public class ObservationSeriesESRepository extends RDataESRepository<Observation
	@Override
	public QueryBuilder getTermQuery(Map<String, Object> terms, BoolQueryBuilder query) {

		if (terms.containsKey("dataDefinition")) {
			Long dataDefinitionId = (Long) terms.get("dataDefinition");
			query.must(QueryBuilders.termQuery("dataDefinition", dataDefinitionId));
		}
		return super.getTermQuery(terms, query);
	}

+0 −3
Original line number Diff line number Diff line
@@ -33,11 +33,8 @@ import es.redmic.es.data.common.service.RDataESService;
@Service
public class ObservationSeriesESService extends RDataESService<ObservationSeries, ObservationSeriesDTO> {

	ObservationSeriesESRepository repository;

	@Autowired
	public ObservationSeriesESService(ObservationSeriesESRepository repository) {
		super(repository);
		this.repository = repository;
	}
}