Commit 7fe400fe authored by Noel Alonso's avatar Noel Alonso
Browse files

Añade mapper de resultados de queries a dto

parent a12eb9d2
Loading
Loading
Loading
Loading
+30 −0
Original line number Diff line number Diff line
package es.redmic.viewlib.common.mapper.es2dto;

import org.springframework.stereotype.Component;

import es.redmic.exception.common.ExceptionType;
import es.redmic.exception.common.InternalException;
import es.redmic.models.es.geojson.common.dto.GeoJSONFeatureCollectionDTO;
import es.redmic.models.es.geojson.wrapper.GeoHitsWrapper;
import es.redmic.viewlib.geodata.dto.GeoMetaDTO;
import ma.glasnost.orika.CustomMapper;
import ma.glasnost.orika.MappingContext;

@SuppressWarnings("rawtypes")
@Component
public class FeatureCollectionMapper extends CustomMapper<GeoHitsWrapper, GeoJSONFeatureCollectionDTO> {

	@SuppressWarnings("unchecked")
	@Override
	public void mapAtoB(GeoHitsWrapper a, GeoJSONFeatureCollectionDTO b, MappingContext context) {

		Class<?> targetTypeDto = (Class<?>) context.getProperty("targetTypeDto");

		if (targetTypeDto == null)
			throw new InternalException(ExceptionType.INTERNAL_EXCEPTION);

		b.setFeatures(mapperFacade.mapAsList(a.getHits(), GeoMetaDTO.class, context));
		b.get_meta().setMax_score(a.getMax_score());
		b.setTotal(a.getTotal());
	}
}
 No newline at end of file
+33 −0
Original line number Diff line number Diff line
package es.redmic.viewlib.common.mapper.es2dto;

import org.springframework.stereotype.Component;

import es.redmic.exception.common.ExceptionType;
import es.redmic.exception.common.InternalException;
import es.redmic.models.es.common.dto.MetaDataDTO;
import es.redmic.models.es.geojson.wrapper.GeoHitWrapper;
import es.redmic.viewlib.geodata.dto.GeoMetaDTO;
import ma.glasnost.orika.CustomMapper;
import ma.glasnost.orika.MappingContext;

@SuppressWarnings("rawtypes")
@Component
public class FeatureMapper extends CustomMapper<GeoHitWrapper, GeoMetaDTO> {

	@Override
	public void mapAtoB(GeoHitWrapper a, GeoMetaDTO b, MappingContext context) {

		Class<?> targetTypeDto = (Class<?>) context.getProperty("targetTypeDto");

		if (targetTypeDto == null)
			throw new InternalException(ExceptionType.INTERNAL_EXCEPTION);

		MetaDataDTO _meta = new MetaDataDTO();

		_meta.setScore(a.get_score());
		_meta.setVersion(a.get_version());
		_meta.setHighlight(a.getHighlight());

		b.set_meta(_meta);
	}
}
 No newline at end of file