Commit 5b7109e7 authored by Noel Alonso's avatar Noel Alonso
Browse files

Añade mapper para completar dto

A partir de la info del cliente y las propiedades del servicio se
construye el dto que se enviará a guardar

Añade tests
parent 6d914c76
Loading
Loading
Loading
Loading
+51 −0
Original line number Diff line number Diff line
package es.redmic.atlascommands.mapper;

/*-
 * #%L
 * Atlas-management
 * %%
 * 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 org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.NullValuePropertyMappingStrategy;

import es.redmic.atlaslib.dto.layer.LayerDTO;
import es.redmic.atlaslib.dto.layerinfo.LayerInfoDTO;

@Mapper(nullValuePropertyMappingStrategy = NullValuePropertyMappingStrategy.IGNORE)
public interface LayerInfoDTOMapper {

	// @formatter:off

	@Mapping(source = "layerInfoDTO.id", target = "id")
	@Mapping(source = "layerDTO.name", target = "name")
	@Mapping(source = "layerInfoDTO.themeInspire", target = "themeInspire")
	@Mapping(source = "layerInfoDTO.latLonBoundsImage", target = "latLonBoundsImage")
	@Mapping(source = "layerInfoDTO.protocols", target = "protocols")
	@Mapping(source = "layerInfoDTO.description", target = "description")
	@Mapping(target = "alias",
		expression = "java(layerInfoDTO.getAlias() != null ? "
				+ "layerInfoDTO.getAlias() : (layerDTO.getTitle() != null ? layerDTO.getTitle() : layerDTO.getName()))")
	@Mapping(source = "layerInfoDTO.atlas", target = "atlas", defaultValue = "false")
	@Mapping(source = "layerInfoDTO.refresh", target = "refresh", defaultValue = "0")
	@Mapping(source = "layerDTO.urlSource", target = "urlSource")
	@Mapping(source = "layerInfoDTO.parent", target = "parent")
	LayerDTO map(LayerInfoDTO layerInfoDTO, LayerDTO layerDTO);
	
	// @formatter:on
}
+65 −0
Original line number Diff line number Diff line
package es.redmic.test.atlascommands.unit.aggregate.layer;

/*-
 * #%L
 * Atlas-management
 * %%
 * 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.junit.Assert.assertEquals;

import java.io.File;
import java.io.IOException;
import java.util.HashMap;

import org.junit.Test;
import org.mapstruct.factory.Mappers;

import es.redmic.atlascommands.mapper.LayerInfoDTOMapper;
import es.redmic.atlascommands.utils.Capabilities;
import es.redmic.atlaslib.dto.layer.LayerDTO;
import es.redmic.atlaslib.dto.layerinfo.LayerInfoDTO;
import es.redmic.testutils.utils.JsonToBeanTestUtil;

public class LayerInfoMapperTest {

	final String URL_CAPABILITIES = new File("src/test/resources/data/capabilities/wms.xml").toURI().toString();

	private HashMap<String, LayerDTO> layers;

	private LayerDTO expectedLayer;

	private LayerInfoDTO layerInfo;

	public LayerInfoMapperTest() throws IOException {

		layers = Capabilities.getCapabilities(URL_CAPABILITIES);

		expectedLayer = (LayerDTO) JsonToBeanTestUtil.getBean("/data/layers/layerDTO.json", LayerDTO.class);

		layerInfo = (LayerInfoDTO) JsonToBeanTestUtil.getBean("/data/layers/layerInfoDTO.json", LayerInfoDTO.class);
	}

	@Test
	public void layerInfoMapper_ReturnLayerDTO_IfLayerInfoAndCapabilitiesDataMergeCorrectly() {

		LayerDTO layer = Mappers.getMapper(LayerInfoDTOMapper.class).map(layerInfo,
				(LayerDTO) layers.values().toArray()[0]);

		assertEquals(expectedLayer, layer);
	}
}
+149 −0
Original line number Diff line number Diff line
{
	"queryable": true,
	"name": "batimetriaGlobal",
	"title": "Batimetrías",
	"abstractLayer": "Isolíneas batimétricas obtenidas por geoprocesamiento a partir del modelo batimétrico del \"General Bathymetric Chart of the Oceans (GEBCO), www.gebco.net\" con equidistancia de 100 m ",
	"formats": [
		"image/png",
		"application/atom+xml",
		"application/pdf",
		"application/rss+xml",
		"application/vnd.google-earth.kml+xml",
		"application/vnd.google-earth.kml+xml;mode=networklink",
		"application/vnd.google-earth.kmz",
		"image/geotiff",
		"image/geotiff8",
		"image/gif",
		"image/jpeg",
		"image/png; mode=8bit",
		"image/svg+xml",
		"image/tiff",
		"image/tiff8",
		"text/html; subtype=openlayers"
	],
	"legend": "file:/home/REDMIC/redmic_project/server/atlas/atlas-commands/src/test/resources/data/capabilities/wms.xml?request=GetLegendGraphic&version=1.0.0&format=image/png&layer=topp:states",
	"geometry": {
		"coordinates": [
			[
				[
					-19.332800035,
					27.404290052
				],
				[
					-19.332800035,
					29.416379848
				],
				[
					-12.666811229,
					29.416379848
				],
				[
					-12.666811229,
					27.404290052
				],
				[
					-19.332800035,
					27.404290052
				]
			]
		],
		"type": "Polygon"
	},
	"srs": [
		"EPSG:3857",
		"EPSG:4326",
		"EPSG:32628",
		"CRS:84"
	],
	"stylesLayer": [
		{
			"name": "el:batimetria50mCanarias",
			"title": "Isobatas cada 50 m azules",
			"abstractStyle": "Apropiado para representar isobatas con 50 m de equidistancia, en varios niveles de escala o zoom, en los que se adapta el etiquetado para mejorar la visualización",
			"format": "image/png",
			"url": "http://atlas.redmic.es:80/el/ows?service=WMS&request=GetLegendGraphic&format=image%2Fpng&width=20&height=20&layer=batimetriaCanarias"
		},
		{
			"name": "el:batimetriaMacaronesia",
			"title": null,
			"abstractStyle": null,
			"format": "image/png",
			"url": "http://atlas.redmic.es:80/el/ows?service=WMS&request=GetLegendGraphic&format=image%2Fpng&width=20&height=20&layer=batimetriaCanarias&style=batimetriaMacaronesia"
		},
		{
			"name": "el:batimetria1mCanarias",
			"title": null,
			"abstractStyle": null,
			"format": "image/png",
			"url": "http://atlas.redmic.es:80/el/ows?service=WMS&request=GetLegendGraphic&format=image%2Fpng&width=20&height=20&layer=batimetriaCanarias&style=batimetria1mCanarias"
		},
		{
			"name": "el:batimetria50mCanariasGroup",
			"title": null,
			"abstractStyle": null,
			"format": "image/png",
			"url": "http://atlas.redmic.es:80/el/ows?service=WMS&request=GetLegendGraphic&format=image%2Fpng&width=20&height=20&layer=batimetriaCanarias&style=batimetria50mCanariasGroup"
		}
	],
	"contact": {
		"name": "José Andrés Sevilla",
		"contactPosition": "GIS",
		"organization": "Observatorio Ambiental Granadilla",
		"phone": "+34922298700",
		"fax": "+34922298704",
		"address": "Edf. Puerto-Ciudad, of. 1b, S/C de Tenerife 38001 Spain ",
		"email": "gis@oag-fundacion.org"
	},
	"activities": [
		{
			"id": "817",
			"name": null,
			"path": null
		}
	],
	"timeDimension": {
		"name": "time",
		"units": "ISO8601",
		"defaultValue": "2017-03-15T08:15:38.742Z"
	},
	"elevationDimension": {
		"name": "elevation",
		"units": "EPSG:5030",
		"unitSymbol": "m",
		"defaultValue": "1"
	},
	"attribution": {
		"title": "Observatorio Ambiental Granadilla",
		"onlineResource": "http://www.oag-fundacion.org",
		"logoURL": {
			"format": "image/jpeg",
			"onlineResource": "http://www.oag-fundacion.org/content/logos/oag_sinmedusa.jpg"
		}
	},
	"keywords": ["WFS", "WMS", "GEOSERVER"],
	"urlSource": "file:/home/REDMIC/redmic_project/server/atlas/atlas-commands/src/test/resources/data/capabilities/wms.xml",
	"parent" : {
		"id": "category-213423",
		"name": "Batimetrías"
	},
	"themeInspire": {
		"id": "themeInspire-el",
		"code": "el",
		"name": "Elevaciones",
		"name_en": "Elevation"
	},
	
	"latLonBoundsImage": {
		"maxX": -15.826663970947266,
		"maxY": 27.962779998779297,
		"minX": -15.848636627197266,
		"minY": 27.940807342529297
	},
	"description": "Batimetrías de costera de las Islas Canarias (DGC)",
	"alias": "Batimetrías by operator",
	"atlas": true,
	"refresh": "1",
	"urlSource": "file:/home/REDMIC/redmic_project/server/atlas/atlas-commands/src/test/resources/data/capabilities/wms.xml",
	"name": "batimetriaGlobal",
	"id": "layer-1234"
}
 No newline at end of file
+26 −0
Original line number Diff line number Diff line
{
	"parent" : {
		"id": "category-213423",
		"name": "Batimetrías"
	},
	"themeInspire": {
		"id": "themeInspire-el",
		"code": "el",
		"name": "Elevaciones",
		"name_en": "Elevation"
	},
	
	"latLonBoundsImage": {
		"maxX": -15.826663970947266,
		"maxY": 27.962779998779297,
		"minX": -15.848636627197266,
		"minY": 27.940807342529297
	},
	"description": "Batimetrías de costera de las Islas Canarias (DGC)",
	"alias": "Batimetrías by operator",
	"atlas": true,
	"refresh": "1",
	"urlSource": "file:/home/REDMIC/redmic_project/server/atlas/atlas-commands/src/test/resources/data/capabilities/wms.xml",
	"name": "batimetriaGlobal",
	"id": "layer-1234"
}
 No newline at end of file