Commit 84f5fedd authored by Noel Alonso's avatar Noel Alonso
Browse files

Merge branch 'feature-cleanCapabilities' into 'dev'

Feature clean capabilities

See merge request redmic-project/server/library/utils!8
parents f46c8200 c9e944ef
Loading
Loading
Loading
Loading
+3 −3
Original line number Diff line number Diff line
@@ -14,15 +14,15 @@
	<groupId>es.redmic.lib</groupId>
	<artifactId>utils</artifactId>
	<packaging>jar</packaging>
	<version>0.9.0</version>
	<version>0.9.0-feature-cleanCapabilities</version>
	<name>Utils</name>
	<description>Server utils library</description>

	<properties>
		<!-- REDMIC -->
		<redmic.jts4jackson.version>0.0.1</redmic.jts4jackson.version>
		<redmic.models.version>0.8.0</redmic.models.version>
		<redmic.exceptions.version>0.7.0</redmic.exceptions.version>
		<redmic.models.version>0.11.0</redmic.models.version>
		<redmic.exceptions.version>0.10.0</redmic.exceptions.version>
		<redmic.sitemapgen4j.version>0.6.0</redmic.sitemapgen4j.version>

		<!-- OTHERS -->
+0 −108
Original line number Diff line number Diff line
package es.redmic.utils.geo.wms;

/*-
 * #%L
 * Utils
 * %%
 * 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.io.IOException;
import java.net.URL;
import java.util.HashMap;
import java.util.List;

import org.geotools.data.ows.Layer;
import org.geotools.data.ows.WMSCapabilities;
import org.geotools.data.wms.WebMapServer;
import org.geotools.ows.ServiceException;

import es.redmic.models.es.atlas.Contact;
import es.redmic.models.es.atlas.dto.LayerDTO;

public class GetCapabilities {

	WMSCapabilities capabilities;
	Contact contact;
	HashMap<String, LayerDTO> layers;
	String urlSource;

	public GetCapabilities(String url) throws ServiceException, IOException {

		URL serverURL = new URL(url);

		if (serverURL.getQuery() != null)
			serverURL = new URL(url.replaceAll(serverURL.getQuery(), ""));

		setUrlSource(url);

		WebMapServer wms = new WebMapServer(serverURL);
		capabilities = wms.getCapabilities();
	}

	public HashMap<String, LayerDTO> getCapabilities() throws ServiceException, IOException {

		if (capabilities.getService().getContactInformation() != null)
			setContact(new Contact(capabilities.getService().getContactInformation()));

		setLayers(new HashMap<String, LayerDTO>());

		layerList(capabilities.getLayerList());

		return getLayers();
	}

	public void layerList(List<Layer> layerList) {
		for (int i = 0; i < layerList.size(); i++) {
			LayerDTO layerAux;
			if (layerList.get(i).getName() != null) {
				layerAux = new LayerDTO(layerList.get(i));
				layerAux.setContact(getContact());
				layerAux.setUrlSource(getUrlSource());
				layerAux.setFormats(capabilities.getRequest().getGetMap().getFormats());
				getLayers().put(layerAux.getName(), layerAux);
			}
		}
	}

	public Contact getContact() {
		return contact;
	}

	public void setContact(Contact contact) {
		this.contact = contact;
	}

	public HashMap<String, LayerDTO> getLayers() {
		return layers;
	}

	public void setLayers(HashMap<String, LayerDTO> layers) {
		this.layers = layers;
	}

	public void setCapabilities(WMSCapabilities capabilities) {
		this.capabilities = capabilities;
	}

	public String getUrlSource() {
		return urlSource;
	}

	public void setUrlSource(String urlSource) {
		this.urlSource = urlSource;
	}
}
+1 −0
Original line number Diff line number Diff line
@@ -60,6 +60,7 @@ public class HttpClient {
		try {
			response = restTemplate.exchange(url, HttpMethod.GET, null, templateClass);
		} catch (Exception e) {
			e.printStackTrace();
		}

		if (response != null && response.getStatusCode().is2xxSuccessful())
+0 −146
Original line number Diff line number Diff line
package es.redmic.utils.geo.wms;

/*-
 * #%L
 * Utils
 * %%
 * 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.net.MalformedURLException;

import org.geotools.data.ows.Layer;
import org.geotools.ows.ServiceException;
import org.junit.Before;
import org.junit.Test;

import es.redmic.models.es.atlas.Contact;
import es.redmic.models.es.atlas.dto.LayerDTO;

public class CapabilitiesTest {

	GetCapabilities getCapabilities;

	LayerDTO layer;

	@Before
	public void setUp() throws ServiceException, MalformedURLException, IOException {

		String url = "src/test/resources/wms.xml";
		getCapabilities = new GetCapabilities(new File(url).toURI().toURL().toString());

		getCapabilities.getCapabilities();
	}

	@Test
	public void testWMSAtlasRedmic() throws IOException, ServiceException {

		assertEquals(getCapabilities.layers.size(), 5);

		assertEquals(getCapabilities.capabilities.getLayerList().size(), 6);
	}

	@Test
	public void testContact() throws IOException, ServiceException {

		Contact resultContact = getCapabilities.contact;

		assertEquals(resultContact.getName(), "José Andrés Sevilla");
		assertEquals(resultContact.getContactPosition(), "GIS");
		assertEquals(resultContact.getPhone(), "+34922298700");
		assertEquals(resultContact.getFax(), "+34922298704");
	}

	@Test
	public void testLayerData() throws IOException, ServiceException {

		Layer layerGet = getCapabilities.capabilities.getLayerList().get(3);

		LayerDTO layer = getCapabilities.layers.get(layerGet.getName());

		assertEquals(layer.getName(), layerGet.getName());
		assertEquals(layer.getTitle(), layerGet.getTitle());

		// System.out.println(layer.getLatLonBoundingBox().getMaxX());
		// System.out.println(layer.getBoundingBox());

		/*assertEquals(layer.getLatLonBoundingBox().getMaxX(), (Double) layerGet.getLatLonBoundingBox().getMaxX());
		assertEquals(layer.getLatLonBoundingBox().getMaxY(), (Double) layerGet.getLatLonBoundingBox().getMaxY());
		assertEquals(layer.getLatLonBoundingBox().getMinX(), (Double) layerGet.getLatLonBoundingBox().getMinX());
		assertEquals(layer.getLatLonBoundingBox().getMinY(), (Double) layerGet.getLatLonBoundingBox().getMinY());*/

		// assertEquals(layer.getStyleLayer().getName(),
		// layerGet.getStyles().get(0).getName());
		// assertEquals(layer.getStyleLayer().getUrl(),
		// layerGet.getStyles().get(0).getLegendURLs().get(0).toString());
	}

	@Test
	public void testLayerGrafCan() throws IOException, ServiceException {

		String url = "src/test/resources/OrtoExpress.xml";
		getCapabilities = new GetCapabilities(new File(url).toURI().toURL().toString());

		getCapabilities.getCapabilities();
	}

	@Test
	public void testParseAbstractLayerDefault() throws IOException, ServiceException {

		String abstractLayer = "Isolíneas batimétricas " + "\n(Batimetría de las Islas Canarias)\nref#817#";
		layer = new LayerDTO();
		layer.parseAbstractLayer(abstractLayer);

		assertEquals(layer.getAbstractLayer(), "Isolíneas batimétricas (Batimetría de las Islas Canarias) ");
		assertEquals(layer.getIdActivities().size(), 1);
		assertEquals(layer.getIdActivities().get(0), "817");

		abstractLayer = "Isolíneas batimétricas ref#817,201,54556# (Batimetría de las Islas Canarias)";
		layer = new LayerDTO();
		layer.parseAbstractLayer(abstractLayer);

		assertEquals(layer.getAbstractLayer(), "Isolíneas batimétricas (Batimetría de las Islas Canarias)");
		assertEquals(layer.getIdActivities().size(), 3);

		abstractLayer = "Isolíneas batimétricas " + "\n(Batimetría de las Islas Canarias)\nref#155,# aaaaaaaaaa";
		layer = new LayerDTO();
		layer.parseAbstractLayer(abstractLayer);

		assertEquals(layer.getAbstractLayer(), "Isolíneas batimétricas (Batimetría de las Islas Canarias) aaaaaaaaaa");
		assertEquals(layer.getIdActivities().size(), 1);
		assertEquals(layer.getIdActivities().get(0), "155");

		abstractLayer = "ref#155,#\nIsolíneas batimétricas (Batimetría de las Islas Canarias)\n";
		layer = new LayerDTO();
		layer.parseAbstractLayer(abstractLayer);

		assertEquals(layer.getAbstractLayer(), " Isolíneas batimétricas (Batimetría de las Islas Canarias) ");
		assertEquals(layer.getIdActivities().size(), 1);
		assertEquals(layer.getIdActivities().get(0), "155");

		abstractLayer = "ref#155#";
		layer = new LayerDTO();
		layer.parseAbstractLayer(abstractLayer);

		assertEquals(layer.getAbstractLayer(), "");
		assertEquals(layer.getIdActivities().size(), 1);
		assertEquals(layer.getIdActivities().get(0), "155");
	}
}
+0 −151
Original line number Diff line number Diff line
<?xml version='1.0' encoding="ISO-8859-1" standalone="no" ?>
<WMS_Capabilities version="1.3.0"  xmlns="http://www.opengis.net/wms"   xmlns:sld="http://www.opengis.net/sld"   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"   xmlns:ms="http://mapserver.gis.umn.edu/mapserver"   xsi:schemaLocation="http://www.opengis.net/wms http://schemas.opengis.net/wms/1.3.0/capabilities_1_3_0.xsd  http://www.opengis.net/sld http://schemas.opengis.net/sld/1.1.0/sld_capabilities.xsd  http://mapserver.gis.umn.edu/mapserver http://idecan1.grafcan.es/ServicioWMS/OrtoExpress?service=WMS&amp;version=1.3.0&amp;request=GetSchemaExtension">

<!-- 6.0.0 (vg 1.7) GRAFCAN 2011-->

<Service>
  <Name>WMS</Name>
  <Title>IDECanarias OrtoExpress Campaas 2014-2015</Title>
  <Abstract>Ortofotos Express de Canarias. Propiedad del Gobierno de Canarias.</Abstract>
        <KeywordList>
          <Keyword>WMS</Keyword>
          <Keyword>ORTOFOTOS</Keyword>
          <Keyword>FOTOGRAFIA</Keyword>
          <Keyword>AEREA</Keyword>
          <Keyword>ORTOEXPRESS</Keyword>
          <Keyword>CANARIAS</Keyword>
          <Keyword>GRAFCAN</Keyword>
          <Keyword>ORTHOPHOTO</Keyword>
          <Keyword>CANARY</Keyword>
          <Keyword>ISLANDS</Keyword>
          <Keyword>AERIAL</Keyword>
          <Keyword>PHOTO</Keyword>
        </KeywordList>
  <OnlineResource xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="http://idecan1.grafcan.es/ServicioWMS/OrtoExpress?"/>
  <ContactInformation>
    <ContactPersonPrimary>
      <ContactPerson></ContactPerson>
      <ContactOrganization>Cartografica de Canarias S.A. (GRAFCAN)</ContactOrganization>
    </ContactPersonPrimary>
  <ContactElectronicMailAddress>info@grafcan.com</ContactElectronicMailAddress>
  </ContactInformation>
  <Fees>none</Fees>
  <AccessConstraints>Acceso libre. Prohibido el uso comercial y la descarga masiva de informacin.</AccessConstraints>
  <MaxWidth>2048</MaxWidth>
  <MaxHeight>2048</MaxHeight>
</Service>

<Capability>
  <Request>
    <GetCapabilities>
      <Format>text/xml</Format>
      <DCPType>
        <HTTP>
          <Get><OnlineResource xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="http://idecan1.grafcan.es/ServicioWMS/OrtoExpress?"/></Get>
          <Post><OnlineResource xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="http://idecan1.grafcan.es/ServicioWMS/OrtoExpress?"/></Post>
        </HTTP>
      </DCPType>
    </GetCapabilities>
    <GetMap>
      <Format>image/jpeg</Format>
      <DCPType>
        <HTTP>
          <Get><OnlineResource xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="http://idecan1.grafcan.es/ServicioWMS/OrtoExpress?"/></Get>
          <Post><OnlineResource xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="http://idecan1.grafcan.es/ServicioWMS/OrtoExpress?"/></Post>
        </HTTP>
      </DCPType>
    </GetMap>
    <GetFeatureInfo>
      <Format>text/html</Format>
      <Format>application/vnd.ogc.gml</Format>
      <Format>text/plain</Format>
      <DCPType>
        <HTTP>
          <Get><OnlineResource xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="http://idecan1.grafcan.es/ServicioWMS/OrtoExpress?"/></Get>
          <Post><OnlineResource xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="http://idecan1.grafcan.es/ServicioWMS/OrtoExpress?"/></Post>
        </HTTP>
      </DCPType>
    </GetFeatureInfo>
    <sld:DescribeLayer>
      <Format>text/xml</Format>
      <DCPType>
        <HTTP>
          <Get><OnlineResource xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="http://idecan1.grafcan.es/ServicioWMS/OrtoExpress?"/></Get>
          <Post><OnlineResource xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="http://idecan1.grafcan.es/ServicioWMS/OrtoExpress?"/></Post>
        </HTTP>
      </DCPType>
    </sld:DescribeLayer>
    <sld:GetLegendGraphic>
      <Format>image/jpeg</Format>
      <Format>image/png</Format>
      <Format>image/gif</Format>
      <Format>image/png; mode=8bit</Format>
      <DCPType>
        <HTTP>
          <Get><OnlineResource xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="http://idecan1.grafcan.es/ServicioWMS/OrtoExpress?"/></Get>
          <Post><OnlineResource xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="http://idecan1.grafcan.es/ServicioWMS/OrtoExpress?"/></Post>
        </HTTP>
      </DCPType>
    </sld:GetLegendGraphic>
    <ms:GetStyles>
      <Format>text/xml</Format>
      <DCPType>
        <HTTP>
          <Get><OnlineResource xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="http://idecan1.grafcan.es/ServicioWMS/OrtoExpress?"/></Get>
          <Post><OnlineResource xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="http://idecan1.grafcan.es/ServicioWMS/OrtoExpress?"/></Post>
        </HTTP>
      </DCPType>
    </ms:GetStyles>
  </Request>
  <Exception>
    <Format>XML</Format>
    <Format>INIMAGE</Format>
    <Format>BLANK</Format>
  </Exception>
  <sld:UserDefinedSymbolization SupportSLD="1" UserLayer="0" UserStyle="1" RemoteWFS="0" InlineFeature="0" RemoteWCS="0"/>
  <Layer>
    <Name>WMS_OrtoExpress</Name>
    <Title>IDECanarias OrtoExpress Campaas 2014-2015</Title>
    <Abstract>Ortofotos Express de Canarias. Propiedad del Gobierno de Canarias.</Abstract>
    <KeywordList>
     <Keyword>WMS</Keyword>
     <Keyword>ORTOFOTOS</Keyword>
     <Keyword>FOTOGRAFIA</Keyword>
     <Keyword>AEREA</Keyword>
     <Keyword>ORTOEXPRESS</Keyword>
     <Keyword>CANARIAS</Keyword>
     <Keyword>GRAFCAN</Keyword>
     <Keyword>ORTHOPHOTO</Keyword>
     <Keyword>CANARY</Keyword>
     <Keyword>ISLANDS</Keyword>
     <Keyword>AERIAL</Keyword>
     <Keyword>PHOTO</Keyword>
    </KeywordList>
    <CRS>EPSG:32628</CRS>
    <CRS>EPSG:4326</CRS>
    <CRS>EPSG:32627</CRS>
    <EX_GeographicBoundingBox>
        <westBoundLongitude>-18.3099</westBoundLongitude>
        <eastBoundLongitude>-13.1373</eastBoundLongitude>
        <southBoundLatitude>26.1839</southBoundLatitude>
        <northBoundLatitude>29.8305</northBoundLatitude>
    </EX_GeographicBoundingBox>
    <BoundingBox CRS="EPSG:32628"
                minx="180000" miny="2.9e+06" maxx="680000" maxy="3.3e+06" />
    <Layer queryable="1" opaque="0" cascaded="0">
        <Name>ortoexpress</Name>
        <Title>OrtoExpress</Title>
        <CRS>EPSG:32628</CRS>
    <EX_GeographicBoundingBox>
        <westBoundLongitude>-18.2147</westBoundLongitude>
        <eastBoundLongitude>-13.33</eastBoundLongitude>
        <southBoundLatitude>27.6281</southBoundLatitude>
        <northBoundLatitude>29.4334</northBoundLatitude>
    </EX_GeographicBoundingBox>
        <BoundingBox CRS="EPSG:32628"
                    minx="188000" miny="3.06e+06" maxx="662000" maxy="3.256e+06" />
        <MinScaleDenominator>3000</MinScaleDenominator>
    </Layer>
  </Layer>
</Capability>
</WMS_Capabilities>
Loading