Revision 1003

View differences:

org.gvsig.busquedacatastral/tags/org.gvsig.busquedacatastral-1.0.26/org.gvsig.busquedacatastral.lib/org.gvsig.busquedacatastral.lib.impl/pom.xml
1
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
2
 <modelVersion>4.0.0</modelVersion>
3
 <parent>
4
  <groupId>org.gvsig</groupId>
5
  <artifactId>org.gvsig.busquedacatastral.lib</artifactId>
6
  <version>1.0.26</version>
7
 </parent>
8
 <artifactId>org.gvsig.busquedacatastral.lib.impl</artifactId>
9
 <name>${project.artifactId}</name>
10

  
11
 <dependencies>
12
  <dependency>
13
   <groupId>org.gvsig</groupId>
14
   <artifactId>org.gvsig.busquedacatastral.lib.api</artifactId>
15
   <scope>compile</scope>
16
  </dependency>
17
  <dependency>
18
   <groupId>org.gvsig</groupId>
19
   <artifactId>org.gvsig.fmap.geometry.api</artifactId>
20
   <scope>compile</scope>
21
  </dependency>
22
  <dependency>
23
   <groupId>org.gvsig</groupId>
24
   <artifactId>org.gvsig.fmap.dal.api</artifactId>
25
   <scope>compile</scope>
26
  </dependency>
27
  <dependency>
28
   <groupId>org.gvsig</groupId>
29
   <artifactId>org.gvsig.fmap.dal.file.lib</artifactId>
30
   <scope>compile</scope>
31
  </dependency>
32

  
33
  <!--These dependencies are added to use the webservice and parse its response -->
34
  <dependency>
35
   <groupId>axis</groupId>
36
   <artifactId>axis-jaxrpc</artifactId>
37
   <scope>compile</scope>
38
  </dependency>
39
  <dependency>
40
   <groupId>org.apache.axis</groupId>
41
   <artifactId>axis</artifactId>
42
   <scope>compile</scope>
43
  </dependency>
44
  <dependency>
45
   <groupId>commons-logging</groupId>
46
   <artifactId>commons-logging</artifactId>
47
   <scope>compile</scope>
48
  </dependency>
49
  <dependency>
50
   <groupId>commons-discovery</groupId>
51
   <artifactId>commons-discovery</artifactId>
52
   <scope>compile</scope>
53
  </dependency>
54
  <dependency>
55
   <groupId>wsdl4j</groupId>
56
   <artifactId>wsdl4j</artifactId>
57
   <scope>compile</scope>
58
  </dependency>
59

  
60
 </dependencies>
61
</project>
org.gvsig.busquedacatastral/tags/org.gvsig.busquedacatastral-1.0.26/org.gvsig.busquedacatastral.lib/org.gvsig.busquedacatastral.lib.impl/src/main/resources/META-INF/services/org.gvsig.tools.library.Library
1
org.gvsig.busquedacatastral.lib.impl.DefaultBusquedaCatastralLibrary
org.gvsig.busquedacatastral/tags/org.gvsig.busquedacatastral-1.0.26/org.gvsig.busquedacatastral.lib/org.gvsig.busquedacatastral.lib.impl/src/main/java/org/gvsig/busquedacatastral/lib/impl/NumerosFactory.java
1
package org.gvsig.busquedacatastral.lib.impl;
2

  
3
import java.io.ByteArrayInputStream;
4
import java.io.File;
5
import java.io.InputStream;
6
import java.rmi.RemoteException;
7
import java.util.ArrayList;
8
import java.util.HashSet;
9
import java.util.List;
10
import java.util.Set;
11

  
12
import javax.xml.bind.JAXBContext;
13
import javax.xml.bind.Unmarshaller;
14

  
15
import org.apache.axis.message.MessageElement;
16
import org.apache.commons.lang3.StringUtils;
17

  
18
import org.gvsig.busquedacatastral.lib.api.BusquedaCatastralManager;
19
import org.gvsig.busquedacatastral.lib.api.QueryCatastral;
20
import org.gvsig.busquedacatastral.lib.api.exceptions.BusquedaCatastralException;
21
import org.gvsig.busquedacatastral.lib.api.exceptions.BusquedaCatastralGettingParamsException;
22
import org.gvsig.busquedacatastral.lib.api.exceptions.BusquedaCatastralRemoteServiceException;
23
import org.gvsig.busquedacatastral.lib.impl.ws.classes.CallejeroWSResponse;
24
import org.gvsig.busquedacatastral.lib.impl.ws.classes.MunicipiosWSResponse;
25
import org.gvsig.busquedacatastral.lib.impl.ws.classes.cxf.Callejero;
26
import org.gvsig.busquedacatastral.lib.impl.ws.classes.cxf.ConsultaCallejero;
27
import org.gvsig.busquedacatastral.lib.impl.ws.classes.cxf.ConsultaMunicipieror;
28
import org.gvsig.busquedacatastral.lib.impl.ws.classes.cxf.ConsultaNumereror;
29
import org.gvsig.busquedacatastral.lib.impl.ws.classes.cxf.Df;
30
import org.gvsig.busquedacatastral.lib.impl.ws.classes.cxf.Muni;
31
import org.gvsig.busquedacatastral.lib.impl.ws.classes.cxf.Municipiero;
32
import org.gvsig.busquedacatastral.lib.impl.ws.classes.cxf.Numereror;
33
import org.gvsig.busquedacatastral.lib.impl.ws.classes.cxf.Nump;
34
import org.gvsig.fmap.dal.DataTypes;
35
import org.gvsig.fmap.dal.exception.DataException;
36
import org.gvsig.fmap.dal.feature.EditableFeature;
37
import org.gvsig.fmap.dal.feature.EditableFeatureType;
38
import org.gvsig.fmap.dal.feature.FeatureStore;
39
import org.gvsig.tools.ToolsLocator;
40
import org.gvsig.tools.dynobject.DynObject;
41
import org.gvsig.tools.exception.BaseException;
42
import org.gvsig.tools.i18n.I18nManager;
43

  
44
import org.slf4j.Logger;
45
import org.slf4j.LoggerFactory;
46

  
47
public class NumerosFactory extends WSObjectsFactory{
48

  
49
    private static final Logger logger = LoggerFactory
50
        .getLogger(NumerosFactory.class);
51

  
52

  
53
    public NumerosFactory(BusquedaCatastralManager manager){
54
        super(manager);
55
    }
56

  
57
    private QueryCatastral query;
58
    private String ini;
59
    private String fin;
60

  
61
    public List<String> getNumeros(QueryCatastral query, String ini, String fin) throws BusquedaCatastralException{
62
        if (query==null||query.getProvincia()==null){
63
            logger.error("Provincia no informada");
64
            I18nManager i18nManager = ToolsLocator.getI18nManager();
65
            throw new BusquedaCatastralGettingParamsException(i18nManager.getTranslation("_error_provincia_not_informed"), null);
66
        }
67
        if (query.getMunicipio()==null){
68
            logger.error("Municipio no informado");
69
            I18nManager i18nManager = ToolsLocator.getI18nManager();
70
            throw new BusquedaCatastralGettingParamsException(i18nManager.getTranslation("_error_municipio_not_informed"), null);
71
        }
72
        if (query.getTipoVia()==null){
73
            logger.error("Tipo Via no informado");
74
            I18nManager i18nManager = ToolsLocator.getI18nManager();
75
            throw new BusquedaCatastralGettingParamsException(i18nManager.getTranslation("_error_tipo_via_not_informed"), null);
76
        }
77
        if (query.getVia()==null){
78
            logger.error("Via no informado");
79
            I18nManager i18nManager = ToolsLocator.getI18nManager();
80
            throw new BusquedaCatastralGettingParamsException(i18nManager.getTranslation("_error_via_not_informed"), null);
81
        }
82
        if (StringUtils.isEmpty(ini) && StringUtils.isEmpty(fin)){
83
            logger.error("Numeros no informado");
84
            I18nManager i18nManager = ToolsLocator.getI18nManager();
85
            throw new BusquedaCatastralGettingParamsException(i18nManager.getTranslation("_error_numero_not_informed"), null);
86
        }
87
        this.query=query;
88
        this.ini=ini;
89
        this.fin=fin;
90
        Set<String> numeros=getNumeros(ini,fin);
91
        Set<String> results = new HashSet<>();
92
        for (String numero:numeros){
93

  
94
            Set<String> consulta=null;
95
            try {
96
                consulta = consultaNumerero(numero);
97
            } catch (Exception e) {
98
                //Do nothing; It is possible that there is not a given number in the interval
99
                //So no exception is thrown.
100
                logger.warn("No se ha podido encontar el n?mero: "+numero, e);
101
            }
102

  
103
            if (consulta!=null){
104
                results.addAll(consulta);
105
            }
106
        }
107
        if (results==null || results.isEmpty()){
108
            logger.error("No se ha encontrado ningun numero");
109
            I18nManager i18nManager = ToolsLocator.getI18nManager();
110
            throw new BusquedaCatastralGettingParamsException(i18nManager.getTranslation("_numero_not_found_for_parameters"), null);
111
        }
112
        return new ArrayList<String>(results);
113
    }
114

  
115
    private Set<String> getNumeros(String ini,String fin){
116
        Set<String> numeros = new HashSet<>();
117
        if (StringUtils.isNotEmpty(ini) && StringUtils.isNotEmpty(fin)){
118
            numeros.add(ini);
119
            numeros.add(fin);
120
            try {
121
                int numIni=Integer.valueOf(ini);
122
                int numFin=Integer.valueOf(fin);
123
                if (numIni<numFin){
124
                    for (int i=numIni+1;i<numFin;i++){
125
                        numeros.add(String.valueOf(i));
126
                    }
127
                }
128
            } catch (NumberFormatException e) {
129
                // Do nothing
130
            }
131
        }else{
132
            if (StringUtils.isNotEmpty(ini)){
133
                numeros.add(ini);
134
            }else if (StringUtils.isNotEmpty(fin)){
135
                numeros.add(fin);
136
            }
137
        }
138
        return numeros;
139
    }
140

  
141
    private Set<String> consultaNumerero(String numero) throws BusquedaCatastralException{
142
        try {
143
            DynObject provincia=query.getProvincia();
144
            DynObject municipio=query.getMunicipio();
145
            DynObject via=query.getVia();
146
            String nombreProvincia=(String) provincia.getDynValue(BusquedaCatastralManager.CAMPO_PROVINCIA_NOMBRE);
147
            String nombreMunicipio=(String) municipio.getDynValue(BusquedaCatastralManager.CAMPO_MUNICIPIO_NOMBRE);
148
            String tipoViaAbrev=query.getTipoVia().getAbrev();
149
            String nombreVia=(String)via.getDynValue(BusquedaCatastralManager.CAMPO_VIA_NOMBRE);
150

  
151
            CallejeroWSResponse callejeroResponse = getCatastroWS().
152
                 obtenerNumerero(nombreProvincia, nombreMunicipio, tipoViaAbrev, nombreVia, numero);
153
            if (callejeroResponse!=null){
154
                MessageElement[] any = callejeroResponse.get_any();
155
                MessageElement me=any[0];
156
                JAXBContext jaxbContext = JAXBContext.newInstance(ConsultaNumereror.class);
157

  
158
                Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller();
159
                InputStream input = new ByteArrayInputStream(me.getAsString().getBytes());
160
                ConsultaNumereror cn = (ConsultaNumereror) jaxbUnmarshaller.unmarshal(input);
161

  
162
                if (cn!=null && cn.getLerr()!=null){
163
                    webserviceErrors(cn.getLerr().getErr());
164
                }
165

  
166
                Numereror numerero = cn.getNumerero();
167
                return numereroToListString(numerero);
168
            }else{
169
                logger.error("Webservice response is empty");
170
                I18nManager i18nManager = ToolsLocator.getI18nManager();
171
                throw new BusquedaCatastralGettingParamsException(i18nManager.getTranslation("_error_reading_response_from_ws"),null);
172
            }
173

  
174
        } catch (RemoteException e) {
175
            logger.error("Error accesing webservice",e);
176
            I18nManager i18nManager = ToolsLocator.getI18nManager();
177
            throw new BusquedaCatastralRemoteServiceException(i18nManager.getTranslation("_error_obtaining_catastro_webservice"), e);
178
        } catch (Exception e) {
179
            logger.error("Error marshalling response from webservice",e);
180
            I18nManager i18nManager = ToolsLocator.getI18nManager();
181
            throw new BusquedaCatastralGettingParamsException(i18nManager.getTranslation("_error_reading_response_from_ws"), e);
182
        }
183

  
184
    }
185

  
186
    private Set<String> numereroToListString(Numereror numerero){
187
        if (numerero==null){
188
            return null;
189
        }
190
        Set<String> numeros=new HashSet<>();
191
        for (Nump nump:numerero.getNump()){
192
            String num = nump.getNum().getPnp();
193
            numeros.add(num);
194
        }
195
        return numeros;
196
    }
197

  
198
    @Override
199
    protected void defineType(EditableFeatureType type)
200
        throws BusquedaCatastralException {
201
        // Do Nothing
202

  
203
    }
204

  
205
    @Override
206
    protected void writeFileData(FeatureStore featureStore)
207
        throws BusquedaCatastralException, DataException {
208
      // Do Nothing
209

  
210
    }
211

  
212
    @Override
213
    protected String getExpressionQuery() {
214
     // Do Nothing
215
        return null;
216
    }
217

  
218

  
219
}
org.gvsig.busquedacatastral/tags/org.gvsig.busquedacatastral-1.0.26/org.gvsig.busquedacatastral.lib/org.gvsig.busquedacatastral.lib.impl/src/main/java/org/gvsig/busquedacatastral/lib/impl/PointFactory.java
1
package org.gvsig.busquedacatastral.lib.impl;
2

  
3
import java.io.ByteArrayInputStream;
4
import java.io.InputStream;
5
import java.rmi.RemoteException;
6
import java.util.List;
7

  
8
import javax.xml.bind.JAXBContext;
9
import javax.xml.bind.Unmarshaller;
10
import javax.xml.rpc.ServiceException;
11

  
12
import org.apache.axis.message.MessageElement;
13
import org.apache.commons.lang3.StringUtils;
14

  
15
import org.gvsig.busquedacatastral.lib.api.ReferenciaCatastral;
16
import org.gvsig.busquedacatastral.lib.api.SRSCatastro;
17
import org.gvsig.busquedacatastral.lib.api.exceptions.BusquedaCatastralException;
18
import org.gvsig.busquedacatastral.lib.api.exceptions.BusquedaCatastralGettingDataException;
19
import org.gvsig.busquedacatastral.lib.api.exceptions.BusquedaCatastralGettingParamsException;
20
import org.gvsig.busquedacatastral.lib.api.exceptions.BusquedaCatastralInvalidSRSException;
21
import org.gvsig.busquedacatastral.lib.api.exceptions.BusquedaCatastralRemoteServiceException;
22
import org.gvsig.busquedacatastral.lib.impl.ws.OVCCoordenadasLocator;
23
import org.gvsig.busquedacatastral.lib.impl.ws.OVCCoordenadasSoap;
24
import org.gvsig.busquedacatastral.lib.impl.ws.classes.Consulta_Coordenadas;
25
import org.gvsig.busquedacatastral.lib.impl.ws.classes.cxf.ConsultaCoord;
26
import org.gvsig.busquedacatastral.lib.impl.ws.classes.cxf.Coord;
27
import org.gvsig.busquedacatastral.lib.impl.ws.classes.cxf.Coords;
28
import org.gvsig.busquedacatastral.lib.impl.ws.classes.cxf.Err;
29
import org.gvsig.fmap.geom.Geometry;
30
import org.gvsig.fmap.geom.GeometryLocator;
31
import org.gvsig.fmap.geom.exception.CreateGeometryException;
32
import org.gvsig.fmap.geom.primitive.Point;
33
import org.gvsig.tools.ToolsLocator;
34
import org.gvsig.tools.i18n.I18nManager;
35
import org.gvsig.tools.locator.LocatorException;
36

  
37
import org.slf4j.Logger;
38
import org.slf4j.LoggerFactory;
39

  
40
public class PointFactory {
41

  
42
    private static final Logger logger = LoggerFactory
43
        .getLogger(PointFactory.class);
44

  
45
    public Point getPoint(String referenciacatastral, SRSCatastro srs)
46
        throws BusquedaCatastralException {
47

  
48
        if (StringUtils.isEmpty(referenciacatastral)){
49
            logger.error("Referencia Catastral no valida");
50
            I18nManager i18nManager = ToolsLocator.getI18nManager();
51
            throw new BusquedaCatastralGettingDataException(i18nManager.getTranslation("_error_refCatastral_not_informed"), null);
52
        }else if (srs==null){
53
            logger.error("SRS de catastro no valido");
54
            I18nManager i18nManager = ToolsLocator.getI18nManager();
55
            throw new BusquedaCatastralInvalidSRSException(i18nManager.getTranslation("_error_SRS"), null);
56
        }else{
57
            Coords coords=getCoords(referenciacatastral,srs);
58
            if (coords!=null){
59
                return getPointFromCoords(coords);
60
            }else{
61
                logger.error("No se pudieron encontrar las coordenadas para la RC: "+referenciacatastral);
62
                I18nManager i18nManager = ToolsLocator.getI18nManager();
63
                throw new BusquedaCatastralGettingDataException(i18nManager.getTranslation("_error_couldnt_get_coords"), null);
64
            }
65

  
66
        }
67
    }
68

  
69

  
70
    public Point getPoint(ReferenciaCatastral referenciacatastral, SRSCatastro srs)
71
        throws BusquedaCatastralException {
72
        if (referenciacatastral==null){
73
            logger.error("Referencia Catastral no valida");
74
            I18nManager i18nManager = ToolsLocator.getI18nManager();
75
            throw new BusquedaCatastralGettingDataException(i18nManager.getTranslation("_error_refCatastral_not_informed"), null);
76
        }else{
77
            return getPoint(referenciacatastral.getRCParcial(),srs);
78
        }
79
    }
80

  
81
    private Point getPointFromCoords(Coords coords){
82
        double x;
83
        double y;
84
        for (Coord coord:coords.getCoord()){
85
            x=Double.valueOf(coord.getGeo().getXcen());
86
            y=Double.valueOf(coord.getGeo().getYcen());
87
            Point point=null;
88
            try {
89
                point= GeometryLocator.getGeometryManager().createPoint(x, y, Geometry.SUBTYPES.GEOM2D);
90
            } catch (CreateGeometryException | LocatorException e) {
91
                logger.error("Error getting center point "+e.getMessage());
92
            }
93
            return point;
94
        }
95
        return null;
96
    }
97

  
98
    private OVCCoordenadasSoap getCoordenadasWS() throws BusquedaCatastralGettingDataException{
99
        try {
100
            OVCCoordenadasLocator locator=
101
                new OVCCoordenadasLocator();
102
            OVCCoordenadasSoap coordenadasWS =
103
                locator.getOVCCoordenadasSoap();
104
            return coordenadasWS;
105
        } catch (ServiceException e) {
106
            logger.error("Error obtaining webservice",e);
107
            I18nManager i18nManager = ToolsLocator.getI18nManager();
108
            throw new BusquedaCatastralGettingDataException(i18nManager.getTranslation("_error_obtaining_catastro_webservice"), e);
109
        }
110

  
111
    }
112

  
113

  
114

  
115
    private Coords getCoords(String rc,SRSCatastro srs) throws BusquedaCatastralException{
116
        try {
117
              Consulta_Coordenadas consultaCoord = getCoordenadasWS().consulta_CPMRC("", "", srs.getCod(), rc);
118

  
119
            if (consultaCoord!=null){
120
                MessageElement[] any = consultaCoord.get_any();
121
                MessageElement me=any[0];
122
                JAXBContext jaxbContext = JAXBContext.newInstance(ConsultaCoord.class);
123

  
124
                Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller();
125
                InputStream input = new ByteArrayInputStream(me.getAsString().getBytes());
126
                ConsultaCoord ccord = (ConsultaCoord) jaxbUnmarshaller.unmarshal(input);
127

  
128
                if (ccord!=null && ccord.getLerr()!=null){
129
                    webserviceErrors(ccord.getLerr().getErr());
130
                }
131

  
132
                return ccord.getCoordenadas();
133
            }else{
134
                logger.error("Webservice response is empty");
135
                I18nManager i18nManager = ToolsLocator.getI18nManager();
136
                throw new BusquedaCatastralGettingDataException(i18nManager.getTranslation("_error_reading_response_from_ws"),null);
137
            }
138

  
139
        } catch (RemoteException e) {
140
            logger.error("Error accesing webservice",e);
141
            I18nManager i18nManager = ToolsLocator.getI18nManager();
142
            throw new BusquedaCatastralRemoteServiceException(i18nManager.getTranslation("_error_obtaining_catastro_webservice"), e);
143
        } catch (Exception e) {
144
            logger.error("Error marshalling response from webservice",e);
145
            I18nManager i18nManager = ToolsLocator.getI18nManager();
146
            throw new BusquedaCatastralGettingDataException(i18nManager.getTranslation("_error_reading_response_from_ws"), e);
147
        }
148

  
149
    }
150

  
151
    private void webserviceErrors(List<Err>errores) throws BusquedaCatastralException{
152
        if (errores!=null && !errores.isEmpty()){
153
            StringBuilder descErrores=new StringBuilder();
154
            I18nManager i18nManager = ToolsLocator.getI18nManager();
155
            descErrores.append(i18nManager.getTranslation("_errors_found_by_ws")+":");
156
            for (Err error:errores){
157
                descErrores.append("\n"+error.getDes());
158
                logger.error(descErrores.toString());
159
                throw new BusquedaCatastralGettingParamsException(descErrores.toString(), null);
160
            }
161
        }
162
    }
163

  
164

  
165
}
org.gvsig.busquedacatastral/tags/org.gvsig.busquedacatastral-1.0.26/org.gvsig.busquedacatastral.lib/org.gvsig.busquedacatastral.lib.impl/src/main/java/org/gvsig/busquedacatastral/lib/impl/DefaultBusquedaCatastralLibrary.java
1
/* gvSIG. Desktop Geographic Information System.
2
 *
3
 * Copyright ? 2007-2016 gvSIG Association
4
 *
5
 * This program is free software; you can redistribute it and/or
6
 * modify it under the terms of the GNU General Public License
7
 * as published by the Free Software Foundation; either version 2
8
 * of the License, or (at your option) any later version.
9
 *
10
 * This program is distributed in the hope that it will be useful,
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 * GNU General Public License for more details.
14
 *
15
 * You should have received a copy of the GNU General Public License
16
 * along with this program; if not, write to the Free Software
17
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
18
 * MA  02110-1301, USA.
19
 *
20
 * For any additional information, do not hesitate to contact us
21
 * at info AT gvsig.com, or visit our website www.gvsig.com.
22
 */
23
package org.gvsig.busquedacatastral.lib.impl;
24

  
25
import org.gvsig.busquedacatastral.lib.api.BusquedaCatastralLibrary;
26
import org.gvsig.busquedacatastral.lib.api.BusquedaCatastralLocator;
27
import org.gvsig.tools.library.AbstractLibrary;
28
import org.gvsig.tools.library.LibraryException;
29

  
30

  
31
/**
32
 * Defines library for busqueda catastral
33
 * @author daniel
34
 *
35
 */
36
public class DefaultBusquedaCatastralLibrary  extends AbstractLibrary{
37
    @Override
38
    public void doRegistration() {
39
        registerAsImplementationOf(BusquedaCatastralLibrary.class);
40
    }
41

  
42
    @Override
43
    protected void doInitialize() throws LibraryException {
44
        BusquedaCatastralLocator.registerManager(DefaultBusquedaCatastralManager.class);
45
    }
46

  
47
    @Override
48
    protected void doPostInitialize() throws LibraryException {
49
        //Do nothing
50
    }
51
}
org.gvsig.busquedacatastral/tags/org.gvsig.busquedacatastral-1.0.26/org.gvsig.busquedacatastral.lib/org.gvsig.busquedacatastral.lib.impl/src/main/java/org/gvsig/busquedacatastral/lib/impl/Main.java
1
package org.gvsig.busquedacatastral.lib.impl;
2
import java.io.ByteArrayInputStream;
3
import java.io.InputStream;
4
import java.rmi.RemoteException;
5

  
6
import javax.xml.bind.JAXBContext;
7
import javax.xml.bind.JAXBException;
8
import javax.xml.bind.Unmarshaller;
9
import javax.xml.rpc.ServiceException;
10

  
11
import org.apache.axis.message.MessageElement;
12
import org.gvsig.busquedacatastral.lib.impl.ws.CallejeroCatastroWSLocator;
13
import org.gvsig.busquedacatastral.lib.impl.ws.CallejeroCatastroWSSoap;
14
import org.gvsig.busquedacatastral.lib.impl.ws.classes.MunicipiosWSResponse;
15
import org.gvsig.busquedacatastral.lib.impl.ws.classes.ProvinciasWSResponse;
16
import org.gvsig.busquedacatastral.lib.impl.ws.classes.cxf.ConsultaMunicipieror;
17
import org.gvsig.busquedacatastral.lib.impl.ws.classes.cxf.ConsultaProvincieror;
18
import org.gvsig.busquedacatastral.lib.impl.ws.classes.cxf.ObjectFactory;
19

  
20

  
21
/*
22
 * Copyright 2016 DiSiD Technologies S.L.L. All rights reserved.
23
 *
24
 * Project  : DiSiD WebServiceProject
25
 * SVN Id   : $Id$
26
 */
27

  
28
public class Main {
29

  
30
    public static void main(String[] args)  {
31
        try {
32
            CallejeroCatastroWSLocator locator=
33
                new CallejeroCatastroWSLocator();
34
            CallejeroCatastroWSSoap callejeroWS =
35
                locator.getCallejeroCatastroSoap();
36
            ProvinciasWSResponse provincias = callejeroWS.obtenerProvincias();
37

  
38
            ObjectFactory objfactory=new ObjectFactory();
39
            if (provincias!=null){
40
                MessageElement[] any = provincias.get_any();
41
                MessageElement me=any[0];
42
                JAXBContext jaxbContext = JAXBContext.newInstance(ConsultaProvincieror.class);
43

  
44
                Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller();
45
                InputStream input = new ByteArrayInputStream(me.getAsString().getBytes());
46
                ConsultaProvincieror cp = (ConsultaProvincieror) jaxbUnmarshaller.unmarshal(input);
47
                cp.getProvinciero();
48
            }
49
            MunicipiosWSResponse municipios = callejeroWS.obtenerMunicipios("VALENCIA", "");
50
            if (municipios!=null){
51
                MessageElement[] any = municipios.get_any();
52
                MessageElement me=any[0];
53
                JAXBContext jaxbContext = JAXBContext.newInstance(ConsultaMunicipieror.class);
54

  
55
                Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller();
56
                InputStream input = new ByteArrayInputStream(me.getAsString().getBytes());
57
                ConsultaMunicipieror cm = (ConsultaMunicipieror) jaxbUnmarshaller.unmarshal(input);
58
                cm.getMunicipiero();
59
            }
60

  
61

  
62
        } catch (ServiceException e) {
63
            // TODO Auto-generated catch block
64
            e.printStackTrace();
65
        } catch (RemoteException e) {
66
            // TODO Auto-generated catch block
67
            e.printStackTrace();
68
        } catch (JAXBException e) {
69
            // TODO Auto-generated catch block
70
            e.printStackTrace();
71
        } catch (Exception e) {
72
            // TODO Auto-generated catch block
73
            e.printStackTrace();
74
        }
75

  
76

  
77

  
78
    }
79

  
80
}
org.gvsig.busquedacatastral/tags/org.gvsig.busquedacatastral-1.0.26/org.gvsig.busquedacatastral.lib/org.gvsig.busquedacatastral.lib.impl/src/main/java/org/gvsig/busquedacatastral/lib/impl/ProvinciasFactory.java
1
package org.gvsig.busquedacatastral.lib.impl;
2

  
3
import java.io.ByteArrayInputStream;
4
import java.io.File;
5
import java.io.IOException;
6
import java.io.InputStream;
7
import java.rmi.RemoteException;
8
import java.util.List;
9

  
10
import javax.xml.bind.JAXBContext;
11
import javax.xml.bind.Unmarshaller;
12

  
13
import org.apache.axis.message.MessageElement;
14
import org.apache.commons.lang3.StringUtils;
15

  
16
import org.gvsig.busquedacatastral.lib.api.BusquedaCatastralManager;
17
import org.gvsig.busquedacatastral.lib.api.exceptions.BusquedaCatastralException;
18
import org.gvsig.busquedacatastral.lib.api.exceptions.BusquedaCatastralGettingParamsException;
19
import org.gvsig.busquedacatastral.lib.api.exceptions.BusquedaCatastralRemoteServiceException;
20
import org.gvsig.busquedacatastral.lib.impl.ws.classes.ProvinciasWSResponse;
21
import org.gvsig.busquedacatastral.lib.impl.ws.classes.cxf.ConsultaProvincieror;
22
import org.gvsig.busquedacatastral.lib.impl.ws.classes.cxf.Err;
23
import org.gvsig.busquedacatastral.lib.impl.ws.classes.cxf.Prov;
24
import org.gvsig.busquedacatastral.lib.impl.ws.classes.cxf.Provinciero;
25
import org.gvsig.fmap.dal.DataTypes;
26
import org.gvsig.fmap.dal.exception.DataException;
27
import org.gvsig.fmap.dal.feature.EditableFeature;
28
import org.gvsig.fmap.dal.feature.EditableFeatureType;
29
import org.gvsig.fmap.dal.feature.FeatureStore;
30
import org.gvsig.tools.ToolsLocator;
31
import org.gvsig.tools.dynobject.DynObject;
32
import org.gvsig.tools.exception.BaseException;
33
import org.gvsig.tools.i18n.I18nManager;
34

  
35
import org.slf4j.Logger;
36
import org.slf4j.LoggerFactory;
37

  
38
public class ProvinciasFactory extends WSObjectsFactory{
39

  
40
    private static final Logger logger = LoggerFactory
41
        .getLogger(ProvinciasFactory.class);
42

  
43
    private final static String PROVINCIAS_FILENAME="provincias.dbf";
44

  
45

  
46
    public ProvinciasFactory(BusquedaCatastralManager manager){
47
        super(manager);
48
    }
49

  
50
    private Provinciero provinciero=null;
51
    public  List<DynObject> getProvincias() throws BusquedaCatastralException{
52
        //TODO
53
        //1.-Ver si existe fichero en tmp
54
        //2.- Si no existe
55
        //  2.1.- consulta web para obtener provinciero
56
        //  2.2.- generar archivo a partir de provinciero
57
        //3.-Leer fichero con listado de provincias
58
        //  3.1.- Por cada registro en provincia, construir un DynObject
59
        //4.-Devolver listado de DynObject
60

  
61
        File provinciasFile=null;
62

  
63
        try {
64
            provinciasFile = new File(manager.getCacheFolder(),PROVINCIAS_FILENAME);
65
            if (!provinciasFile.exists()){
66
                createDBF(provinciasFile);
67
            }
68
            return this.getListFromDBF(provinciasFile);
69
        } catch ( BusquedaCatastralException e) {
70
            throw e;
71
        } catch ( Exception e) {
72
            logger.warn("Error getting provincias from file '"+provinciasFile.getAbsolutePath()+"'.",e);
73
            throw new BusquedaCatastralGettingParamsException(e);
74
        }
75
    }
76

  
77

  
78
    @Override
79
    protected void defineType(EditableFeatureType type) throws BusquedaCatastralException {
80
        provinciero=getProvinciero();
81
        int maxNombre=0;
82
        int maxCodigo=0;
83
        for(Prov prov:provinciero.getProv()){
84
            if(StringUtils.isNotEmpty(prov.getNp()) && prov.getNp().length()>maxNombre){
85
                maxNombre=prov.getNp().length();
86
            }
87
            if(StringUtils.isNotEmpty(prov.getCpine()) && prov.getCpine().length()>maxCodigo){
88
                maxCodigo=prov.getCpine().length();
89
            }
90
        }
91
        type.add(BusquedaCatastralManager.CAMPO_PROVINCIA_NOMBRE, DataTypes.STRING,
92
            maxNombre);
93
        type.add(BusquedaCatastralManager.CAMPO_PROVINCIA_CODIGO, DataTypes.STRING,
94
            maxCodigo);
95
    }
96

  
97
    @Override
98
    protected void writeFileData(FeatureStore featureStore) throws DataException, BusquedaCatastralException {
99
        provinciero=getProvinciero();
100
        for(Prov prov:provinciero.getProv()){
101
            EditableFeature ef;
102
            ef = featureStore.createNewFeature().getEditable();
103
            ef.set(BusquedaCatastralManager.CAMPO_PROVINCIA_NOMBRE, prov.getNp());
104
            ef.set(BusquedaCatastralManager.CAMPO_PROVINCIA_CODIGO, prov.getCpine());
105
            featureStore.insert(ef);
106
        }
107
        provinciero = null;
108
    }
109

  
110
    private Provinciero getProvinciero() throws BusquedaCatastralException{
111
        if( provinciero == null ) {
112
            try {
113
                ProvinciasWSResponse provincias = getCatastroWS().obtenerProvincias();
114
                if (provincias!=null){
115
                    MessageElement[] any = provincias.get_any();
116
                    MessageElement me=any[0];
117
                    JAXBContext jaxbContext = JAXBContext.newInstance(ConsultaProvincieror.class);
118

  
119
                    Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller();
120
                    InputStream input = new ByteArrayInputStream(me.getAsString().getBytes());
121
                    ConsultaProvincieror cp = (ConsultaProvincieror) jaxbUnmarshaller.unmarshal(input);
122

  
123
                    if (cp!=null && cp.getLerr()!=null){
124
                        webserviceErrors(cp.getLerr().getErr());
125
                    }
126

  
127
                    provinciero =  cp.getProvinciero();
128
                }else{
129
                    logger.error("Webservice response is empty");
130
                    I18nManager i18nManager = ToolsLocator.getI18nManager();
131
                    throw new BusquedaCatastralGettingParamsException(i18nManager.getTranslation("_error_reading_response_from_ws"),null);
132
                }
133

  
134
            } catch (BusquedaCatastralRemoteServiceException e) {
135
                logger.error("Error accesing webservice",e);
136
                I18nManager i18nManager = ToolsLocator.getI18nManager();
137
                throw e;
138
            } catch (RemoteException e) {
139
                logger.error("Error marshalling response from webservice",e);
140
                I18nManager i18nManager = ToolsLocator.getI18nManager();
141
                throw new BusquedaCatastralRemoteServiceException(i18nManager.getTranslation("_error_reading_response_from_ws"), e);
142
            } catch (Exception e) {
143
                logger.error("Error marshalling response from webservice",e);
144
                I18nManager i18nManager = ToolsLocator.getI18nManager();
145
                throw new BusquedaCatastralGettingParamsException(i18nManager.getTranslation("_error_reading_response_from_ws"), e);
146
            }
147
        }
148
        return provinciero;
149
    }
150

  
151

  
152
    @Override
153
    protected String getExpressionQuery() {
154
        return null;
155
    }
156

  
157

  
158
}
org.gvsig.busquedacatastral/tags/org.gvsig.busquedacatastral-1.0.26/org.gvsig.busquedacatastral.lib/org.gvsig.busquedacatastral.lib.impl/src/main/java/org/gvsig/busquedacatastral/lib/impl/ReferenciasCatastralesFactory.java
1
package org.gvsig.busquedacatastral.lib.impl;
2

  
3
import java.io.ByteArrayInputStream;
4
import java.io.InputStream;
5
import java.rmi.RemoteException;
6
import java.util.ArrayList;
7
import java.util.HashSet;
8
import java.util.List;
9
import java.util.Set;
10

  
11
import javax.xml.bind.JAXBContext;
12
import javax.xml.bind.Unmarshaller;
13

  
14
import org.apache.axis.message.MessageElement;
15
import org.apache.commons.lang3.StringUtils;
16

  
17
import org.gvsig.busquedacatastral.lib.api.BusquedaCatastralManager;
18
import org.gvsig.busquedacatastral.lib.api.QueryCatastral;
19
import org.gvsig.busquedacatastral.lib.api.QueryCatastral.TipoParcela;
20
import org.gvsig.busquedacatastral.lib.api.QueryCatastral.TipoQuery;
21
import org.gvsig.busquedacatastral.lib.api.ReferenciaCatastral;
22
import org.gvsig.busquedacatastral.lib.api.TipoVia;
23
import org.gvsig.busquedacatastral.lib.api.exceptions.BusquedaCatastralException;
24
import org.gvsig.busquedacatastral.lib.api.exceptions.BusquedaCatastralGettingParamsException;
25
import org.gvsig.busquedacatastral.lib.api.exceptions.BusquedaCatastralRemoteServiceException;
26
import org.gvsig.busquedacatastral.lib.impl.ws.classes.ConsultaDNPPPWSResponse;
27
import org.gvsig.busquedacatastral.lib.impl.ws.classes.ConsultaDNPWSResponse;
28
import org.gvsig.busquedacatastral.lib.impl.ws.classes.cxf.Bico;
29
import org.gvsig.busquedacatastral.lib.impl.ws.classes.cxf.ConsultaDnp;
30
import org.gvsig.busquedacatastral.lib.impl.ws.classes.cxf.Dt;
31
import org.gvsig.busquedacatastral.lib.impl.ws.classes.cxf.Lors;
32
import org.gvsig.busquedacatastral.lib.impl.ws.classes.cxf.Lorus;
33
import org.gvsig.busquedacatastral.lib.impl.ws.classes.cxf.Lourb;
34
import org.gvsig.busquedacatastral.lib.impl.ws.classes.cxf.Lous;
35
import org.gvsig.busquedacatastral.lib.impl.ws.classes.cxf.Lrcdnp;
36
import org.gvsig.busquedacatastral.lib.impl.ws.classes.cxf.Rc;
37
import org.gvsig.busquedacatastral.lib.impl.ws.classes.cxf.Rcdnp;
38
import org.gvsig.fmap.dal.exception.DataException;
39
import org.gvsig.fmap.dal.feature.EditableFeatureType;
40
import org.gvsig.fmap.dal.feature.FeatureStore;
41
import org.gvsig.tools.ToolsLocator;
42
import org.gvsig.tools.dynobject.DynObject;
43
import org.gvsig.tools.i18n.I18nManager;
44

  
45
import org.slf4j.Logger;
46
import org.slf4j.LoggerFactory;
47

  
48
public class ReferenciasCatastralesFactory extends WSObjectsFactory{
49

  
50
    private static final Logger logger = LoggerFactory
51
        .getLogger(ReferenciasCatastralesFactory.class);
52

  
53

  
54
    public ReferenciasCatastralesFactory(BusquedaCatastralManager manager){
55
        super(manager);
56
    }
57

  
58

  
59
    public List<ReferenciaCatastral> getReferencias(QueryCatastral query) throws BusquedaCatastralException{
60
        ConsultaDnp consultaDatosNoPrivados=null;
61

  
62
        if (query==null){
63
            logger.error("Query no valida");
64
            I18nManager i18nManager = ToolsLocator.getI18nManager();
65
            throw new BusquedaCatastralGettingParamsException(i18nManager.getTranslation("_error_invalid_query"), null);
66
        }else{
67
            if ( TipoQuery.POR_RC.equals(query.getTipoQuery()) ){
68
                consultaDatosNoPrivados =getReferenciasByRC(query.getReferenciaCatastral());
69
            }else if( TipoQuery.POR_LOCALIZACION.equals(query.getTipoQuery()) ){
70
                if (TipoParcela.URBANA.equals(query.getTipoParcela())){
71
                    consultaDatosNoPrivados =getReferenciasUrbanas(query);
72
                }else if (TipoParcela.RUSTICA.equals(query.getTipoParcela())){
73
                    consultaDatosNoPrivados =getReferenciasRusticas(query);
74
                }else{
75
                    logger.error("Tipo parcela invalido");
76
                    I18nManager i18nManager = ToolsLocator.getI18nManager();
77
                    throw new BusquedaCatastralGettingParamsException(i18nManager.getTranslation("_error_tipo_parcela_not_informed"), null);
78
                }
79
            } else{
80
                logger.error("Tipo query invalido");
81
                I18nManager i18nManager = ToolsLocator.getI18nManager();
82
                throw new BusquedaCatastralGettingParamsException(i18nManager.getTranslation("_error_tipo_query_not_informed"), null);
83
            }
84

  
85
            if (consultaDatosNoPrivados!=null && consultaDatosNoPrivados.getLerr()!=null){
86
                webserviceErrors(consultaDatosNoPrivados.getLerr().getErr());
87
            }
88

  
89
            return  new ArrayList( createReferenciasCatastrales( consultaDatosNoPrivados) );
90

  
91
        }
92
    }
93

  
94
    private Set<ReferenciaCatastral> createReferenciasCatastrales(ConsultaDnp consultaDatosNoPrivados){
95
        Set<ReferenciaCatastral> results=new HashSet<ReferenciaCatastral>();
96
        if ( consultaDatosNoPrivados.getLrcdnp()!=null ){
97
            getReferenciasCatastralesFrom(consultaDatosNoPrivados.getLrcdnp());
98
            results.addAll( getReferenciasCatastralesFrom(consultaDatosNoPrivados.getLrcdnp()) );
99
        }
100
        if ( consultaDatosNoPrivados.getBico()!=null ){
101
            DefaultReferenciaCatastral refCatastral=getReferenciaCatastralFrom(consultaDatosNoPrivados.getBico());
102
            if (refCatastral!=null){
103
                results.add(refCatastral);
104
            }
105
        }
106
        return results;
107
    }
108

  
109
    private DefaultReferenciaCatastral getReferenciaCatastralFrom(Bico bico){
110
        if ( bico!=null ){
111
            DefaultReferenciaCatastral refCatastral=new DefaultReferenciaCatastral();
112
            if (bico.getBi()!=null){
113
                if( bico.getBi().getIdbi()!=null ){
114
                    fillReferenciaCatastralFrom(bico.getBi().getIdbi().getRc(), refCatastral);
115
                }
116
                if ( bico.getBi().getDt()!=null ){
117
                    fillReferenciaCatastralFrom(bico.getBi().getDt(), refCatastral);
118
                }
119
            }
120
            return refCatastral;
121
        }else{
122
            return null;
123
        }
124
    }
125

  
126
    private Set<ReferenciaCatastral> getReferenciasCatastralesFrom(Lrcdnp lrcdnp){
127
        Set<ReferenciaCatastral> results=new HashSet<ReferenciaCatastral>();
128
        for ( Rcdnp rcdnp:lrcdnp.getRcdnp()){
129
            if(rcdnp!=null){
130
                DefaultReferenciaCatastral refCatastral=new DefaultReferenciaCatastral();
131
                if (rcdnp.getRc()!=null){
132
                    fillReferenciaCatastralFrom(rcdnp.getRc(), refCatastral);
133
                }
134
                if (rcdnp.getDt()!=null){
135
                    fillReferenciaCatastralFrom(rcdnp.getDt(), refCatastral);
136
                }
137
            results.add(refCatastral);
138
            }
139
        }
140
        return results;
141
    }
142

  
143
    private void fillReferenciaCatastralFrom(Rc rc, DefaultReferenciaCatastral refCatastral){
144
        if (rc!=null){
145
            refCatastral.setPc1(rc.getPc1());
146
            refCatastral.setPc2(rc.getPc2());
147
            refCatastral.setCar(rc.getCar());
148
            refCatastral.setDc1(rc.getCc1());
149
            refCatastral.setDc2(rc.getCc2());
150
        }
151
    }
152

  
153
    private void fillReferenciaCatastralFrom(Dt dt, DefaultReferenciaCatastral refCatastral){
154
        if (dt!=null){
155
            refCatastral.setProvincia(dt.getNp());
156
            refCatastral.setMunicipio(dt.getNm());
157
            if (dt.getLocs()!=null){
158
                if (dt.getLocs().getLous()!=null){
159
                    Lous lous=dt.getLocs().getLous();
160
                    if (lous.getLourb()!=null){
161
                        //Urbana
162
                        Lourb lourb=lous.getLourb();
163
                        fillReferenciaCatastralFrom(lourb, refCatastral);
164
                    }
165
                    if(lous.getLorus()!=null && lous.getLorus().getCpp()!=null){
166
                        Lorus lorus=lous.getLorus();
167
                        fillReferenciaCatastralFrom(lorus, refCatastral);;
168
                    }
169
                }
170
                if (dt.getLocs().getLors()!=null){
171
                    Lors lors=dt.getLocs().getLors();
172
                    if (lors.getLourb()!=null){
173
                        //Urbana
174
                        Lourb lourb=lors.getLourb();
175
                        fillReferenciaCatastralFrom(lourb, refCatastral);
176
                    }
177
                    if(lors.getLorus()!=null && lors.getLorus().getCpp()!=null){
178
                        Lorus lorus=lors.getLorus();
179
                        fillReferenciaCatastralFrom(lorus, refCatastral);
180
                    }
181
                }
182
            }
183
        }
184
    }
185

  
186
    private void fillReferenciaCatastralFrom(Lorus lorus, DefaultReferenciaCatastral refCatastral){
187
        if(lorus!=null && lorus.getCpp()!=null){
188
            refCatastral.setPoligono(lorus.getCpp().getCpo());
189
            refCatastral.setParcela(lorus.getCpp().getCpa());
190
            refCatastral.setParaje(lorus.getNpa());
191
        }
192
    }
193

  
194
    private void fillReferenciaCatastralFrom(Lourb lourb, DefaultReferenciaCatastral refCatastral){
195
        if (lourb.getDir()!=null){
196
            if (lourb.getDir().getTv()!=null){
197
                TipoVia tipoVia=TipoVia.getTipoViaByAbrev(lourb.getDir().getTv());
198
                refCatastral.setTipoVia(tipoVia);
199
            }
200
            refCatastral.setVia(lourb.getDir().getNv());
201
            refCatastral.setPatio(lourb.getDir().getPnp());
202
            refCatastral.setKm(lourb.getDir().getKm());
203
            if (lourb.getLoint()!=null){
204
                refCatastral.setBloque(lourb.getLoint().getBq());
205
                refCatastral.setEscalera(lourb.getLoint().getEs());
206
                refCatastral.setPlanta(lourb.getLoint().getPt());
207
                refCatastral.setPuerta(lourb.getLoint().getPu());
208
            }
209
        }
210
    }
211

  
212

  
213
    private ConsultaDnp getReferenciasByRC(String rc) throws BusquedaCatastralException{
214
        try {
215
             ConsultaDNPWSResponse dnpResponse = getCatastroWS().
216
                 consulta_DNPRC("", "", rc);
217
            if (dnpResponse!=null){
218
                MessageElement[] any = dnpResponse.get_any();
219
                MessageElement me=any[0];
220
                JAXBContext jaxbContext = JAXBContext.newInstance(ConsultaDnp.class);
221

  
222
                Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller();
223
                InputStream input = new ByteArrayInputStream(me.getAsString().getBytes());
224
                ConsultaDnp cdnp = (ConsultaDnp) jaxbUnmarshaller.unmarshal(input);
225

  
226
                return cdnp;
227
            }else{
228
                logger.error("Webservice response is empty");
229
                I18nManager i18nManager = ToolsLocator.getI18nManager();
230
                throw new BusquedaCatastralGettingParamsException(i18nManager.getTranslation("_error_reading_response_from_ws"),null);
231
            }
232

  
233
        } catch (RemoteException e) {
234
            logger.error("Error accesing webservice",e);
235
            I18nManager i18nManager = ToolsLocator.getI18nManager();
236
            throw new BusquedaCatastralRemoteServiceException(i18nManager.getTranslation("_error_obtaining_catastro_webservice"), e);
237
        } catch (Exception e) {
238
            logger.error("Error marshalling response from webservice",e);
239
            I18nManager i18nManager = ToolsLocator.getI18nManager();
240
            throw new BusquedaCatastralGettingParamsException(i18nManager.getTranslation("_error_reading_response_from_ws"), e);
241
        }
242

  
243
    }
244

  
245
    private ConsultaDnp getReferenciasUrbanas(QueryCatastral query) throws BusquedaCatastralException{
246
        validateQueryUrbana(query);
247
        try {
248
            DynObject provincia=query.getProvincia();
249
            DynObject municipio=query.getMunicipio();
250
            DynObject via=query.getVia();
251
            String nombreProvincia=(String) provincia.getDynValue(BusquedaCatastralManager.CAMPO_PROVINCIA_NOMBRE);
252
            String nombreMunicipio=(String) municipio.getDynValue(BusquedaCatastralManager.CAMPO_MUNICIPIO_NOMBRE);
253
            String tipoViaAbrev=query.getTipoVia().getAbrev();
254
            String nombreVia=(String)via.getDynValue(BusquedaCatastralManager.CAMPO_VIA_NOMBRE);
255

  
256
            ConsultaDNPWSResponse dnpResponse = getCatastroWS().
257
                 consulta_DNPLOC(nombreProvincia, nombreMunicipio, tipoViaAbrev, nombreVia,
258
                     query.getNumero(), query.getBloque(), query.getEscalera(), query.getPlanta(), query.getPuerta());
259
            if (dnpResponse!=null){
260
                MessageElement[] any = dnpResponse.get_any();
261
                MessageElement me=any[0];
262
                JAXBContext jaxbContext = JAXBContext.newInstance(ConsultaDnp.class);
263

  
264
                Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller();
265
                InputStream input = new ByteArrayInputStream(me.getAsString().getBytes());
266
                ConsultaDnp cdnp = (ConsultaDnp) jaxbUnmarshaller.unmarshal(input);
267

  
268
                return cdnp;
269
            }else{
270
                logger.error("Webservice response is empty");
271
                I18nManager i18nManager = ToolsLocator.getI18nManager();
272
                throw new BusquedaCatastralGettingParamsException(i18nManager.getTranslation("_error_reading_response_from_ws"),null);
273
            }
274

  
275
        } catch (RemoteException e) {
276
            logger.error("Error accesing webservice",e);
277
            I18nManager i18nManager = ToolsLocator.getI18nManager();
278
            throw new BusquedaCatastralRemoteServiceException(i18nManager.getTranslation("_error_obtaining_catastro_webservice"), e);
279
        } catch (Exception e) {
280
            logger.error("Error marshalling response from webservice",e);
281
            I18nManager i18nManager = ToolsLocator.getI18nManager();
282
            throw new BusquedaCatastralGettingParamsException(i18nManager.getTranslation("_error_reading_response_from_ws"), e);
283
        }
284
    }
285

  
286

  
287
    private ConsultaDnp getReferenciasRusticas(QueryCatastral query) throws BusquedaCatastralException{
288
        validateQueryRustica(query);
289
        try {
290
            DynObject provincia=query.getProvincia();
291
            DynObject municipio=query.getMunicipio();
292
            String nombreProvincia=(String) provincia.getDynValue(BusquedaCatastralManager.CAMPO_PROVINCIA_NOMBRE);
293
            String nombreMunicipio=(String) municipio.getDynValue(BusquedaCatastralManager.CAMPO_MUNICIPIO_NOMBRE);
294

  
295

  
296
            ConsultaDNPPPWSResponse dnpResponse = getCatastroWS().
297
                 consulta_DNPPP(nombreProvincia, nombreMunicipio, query.getPoligono(), query.getParcela());
298
            if (dnpResponse!=null){
299
                MessageElement[] any = dnpResponse.get_any();
300
                MessageElement me=any[0];
301
                JAXBContext jaxbContext = JAXBContext.newInstance(ConsultaDnp.class);
302

  
303
                Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller();
304
                InputStream input = new ByteArrayInputStream(me.getAsString().getBytes());
305
                ConsultaDnp cdnp = (ConsultaDnp) jaxbUnmarshaller.unmarshal(input);
306

  
307
                return cdnp;
308
            }else{
309
                logger.error("Webservice response is empty");
310
                I18nManager i18nManager = ToolsLocator.getI18nManager();
311
                throw new BusquedaCatastralGettingParamsException(i18nManager.getTranslation("_error_reading_response_from_ws"),null);
312
            }
313

  
314
        } catch (RemoteException e) {
315
            logger.error("Error accesing webservice",e);
316
            I18nManager i18nManager = ToolsLocator.getI18nManager();
317
            throw new BusquedaCatastralRemoteServiceException(i18nManager.getTranslation("_error_obtaining_catastro_webservice"), e);
318
        } catch (Exception e) {
319
            logger.error("Error marshalling response from webservice",e);
320
            I18nManager i18nManager = ToolsLocator.getI18nManager();
321
            throw new BusquedaCatastralGettingParamsException(i18nManager.getTranslation("_error_reading_response_from_ws"), e);
322
        }
323
    }
324

  
325

  
326
    private void validateQueryUrbana(QueryCatastral query) throws BusquedaCatastralException{
327
        if (query.getProvincia()==null){
328
            logger.error("Provincia no informada");
329
            I18nManager i18nManager = ToolsLocator.getI18nManager();
330
            throw new BusquedaCatastralGettingParamsException(i18nManager.getTranslation("_error_provincia_not_informed"), null);
331
        }
332
        if (query.getMunicipio()==null){
333
            logger.error("Municipio no informado");
334
            I18nManager i18nManager = ToolsLocator.getI18nManager();
335
            throw new BusquedaCatastralGettingParamsException(i18nManager.getTranslation("_error_municipio_not_informed"), null);
336
        }
337
        if (query.getTipoVia()==null){
338
            logger.error("Tipo Via no informado");
339
            I18nManager i18nManager = ToolsLocator.getI18nManager();
340
            throw new BusquedaCatastralGettingParamsException(i18nManager.getTranslation("_error_tipo_via_not_informed"), null);
341
        }
342
        if (query.getVia()==null){
343
            logger.error("Via no informado");
344
            I18nManager i18nManager = ToolsLocator.getI18nManager();
345
            throw new BusquedaCatastralGettingParamsException(i18nManager.getTranslation("_error_via_not_informed"), null);
346
        }
347
        if (query.getNumero()==null){
348
            logger.error("Numero no informado");
349
            I18nManager i18nManager = ToolsLocator.getI18nManager();
350
            throw new BusquedaCatastralGettingParamsException(i18nManager.getTranslation("_error_numero_not_informed"), null);
351
        }
352
    }
353

  
354

  
355
    private void validateQueryRustica(QueryCatastral query) throws BusquedaCatastralException{
356
        if (query.getProvincia()==null){
357
            logger.error("Provincia no informada");
358
            I18nManager i18nManager = ToolsLocator.getI18nManager();
359
            throw new BusquedaCatastralGettingParamsException(i18nManager.getTranslation("_error_provincia_not_informed"), null);
360
        }
361
        if (query.getMunicipio()==null){
362
            logger.error("Municipio no informado");
363
            I18nManager i18nManager = ToolsLocator.getI18nManager();
364
            throw new BusquedaCatastralGettingParamsException(i18nManager.getTranslation("_error_municipio_not_informed"), null);
365
        }
366
        if (query.getPoligono()==null){
367
            logger.error("Poligono no informado");
368
            I18nManager i18nManager = ToolsLocator.getI18nManager();
369
            throw new BusquedaCatastralGettingParamsException(i18nManager.getTranslation("_error_poligono_not_informed"), null);
370
        }
371
        if (query.getParcela()==null){
372
            logger.error("Municipio no informado");
373
            I18nManager i18nManager = ToolsLocator.getI18nManager();
374
            throw new BusquedaCatastralGettingParamsException(i18nManager.getTranslation("_error_parcela_not_informed"), null);
375
        }
376
    }
377

  
378
    @Override
379
    protected void defineType(EditableFeatureType type)
380
        throws BusquedaCatastralException {
381
        // Do Nothing
382

  
383
    }
384

  
385
    @Override
386
    protected void writeFileData(FeatureStore featureStore)
387
        throws BusquedaCatastralException, DataException {
388
      // Do Nothing
389

  
390
    }
391

  
392
    @Override
393
    protected String getExpressionQuery() {
394
     // Do Nothing
395
        return null;
396
    }
397

  
398

  
399
}
org.gvsig.busquedacatastral/tags/org.gvsig.busquedacatastral-1.0.26/org.gvsig.busquedacatastral.lib/org.gvsig.busquedacatastral.lib.impl/src/main/java/org/gvsig/busquedacatastral/lib/impl/QueryCatastralImpl.java
1
package org.gvsig.busquedacatastral.lib.impl;
2

  
3
import org.gvsig.busquedacatastral.lib.api.QueryCatastral;
4
import org.gvsig.busquedacatastral.lib.api.TipoVia;
5
import org.gvsig.busquedacatastral.lib.api.exceptions.BusquedaCatastralInvalidQueryException;
6
import org.gvsig.tools.ToolsLocator;
7
import org.gvsig.tools.dynobject.DynObject;
8
import org.gvsig.tools.i18n.I18nManager;
9
import org.slf4j.Logger;
10
import org.slf4j.LoggerFactory;
11

  
12

  
13
/**
14
 * This class implements query catastral
15
 * @author dmartinezizquierdo
16
 *
17
 */
18
public class QueryCatastralImpl implements QueryCatastral{
19

  
20
    private static final Logger logger = LoggerFactory.getLogger(QueryCatastralImpl.class);
21

  
22
    TipoQuery tipoQuery;
23
    TipoParcela tipoParcela;
24
    String referenciaCatastral;
25
    DynObject provincia;
26
    DynObject municipio;
27
    TipoVia tipoVia;
28
    DynObject via;
29
    String numero;
30
    String bloque;
31
    String escalera;
32
    String planta;
33
    String puerta;
34
    String poligono;
35
    String parcela;
36

  
37

  
38
    @Override
39
    public void setTipoParcela(TipoParcela tipoParcela) {
40
        this.tipoParcela=tipoParcela;
41
    }
42

  
43
    @Override
44
    public TipoParcela getTipoParcela() {
45
        return this.tipoParcela;
46
    }
47

  
48
    @Override
49
    public void setReferenciaCatastral(String referenciaCatastral) {
50
        this.referenciaCatastral=referenciaCatastral;
51
    }
52

  
53
    @Override
54
    public String getReferenciaCatastral() {
55
        return referenciaCatastral;
56
    }
57

  
58
    @Override
59
    public DynObject getProvincia() {
60
        return provincia;
61
    }
62

  
63
    @Override
64
    public void setProvincia(DynObject provincia) {
65
        this.provincia=provincia;
66
    }
67

  
68
    @Override
69
    public DynObject getMunicipio() {
70
        return municipio;
71
    }
72

  
73
    @Override
74
    public void setMunicipio(DynObject municipio) {
75
        this.municipio=municipio;
76
    }
77

  
78
    @Override
79
    public TipoVia getTipoVia() {
80
        return tipoVia;
81
    }
82

  
83
    @Override
84
    public void setTipoVia(TipoVia tipoVia) {
85
        this.tipoVia=tipoVia;
86
    }
87

  
88
    @Override
89
    public DynObject getVia() {
90
        return via;
91
    }
92

  
93
    @Override
94
    public void setVia(DynObject via) {
95
        this.via=via;
96
    }
97

  
98
    @Override
99
    public String getNumero() {
100
        return numero;
101
    }
102

  
103
    @Override
104
    public void setNumero(String numero) {
105
        this.numero=numero;
106
    }
107

  
108
    @Override
109
    public String getBloque() {
110
        return bloque;
111
    }
112

  
113
    @Override
114
    public void setBloque(String bloque) {
115
        this.bloque=bloque;
116
    }
117

  
118
    @Override
119
    public String getEscalera() {
120
        return escalera;
121
    }
122

  
123
    @Override
124
    public void setEscalera(String escalera) {
125
        this.escalera=escalera;
126
    }
127

  
128
    @Override
129
    public String getPlanta() {
130
        return planta;
131
    }
132

  
133
    @Override
134
    public void setPlanta(String planta) {
135
        this.planta=planta;
136
    }
137

  
138
    @Override
139
    public String getPuerta() {
140
        return puerta;
141
    }
142

  
143
    @Override
144
    public void setPuerta(String puerta) {
145
        this.puerta=puerta;
146
    }
147

  
148
    @Override
149
    public String getPoligono() {
150
        return poligono;
151
    }
152

  
153
    @Override
154
    public void setPoligono(String poligono) {
155
        this.poligono=poligono;
156
    }
157

  
158
    @Override
159
    public String getParcela() {
160
        return parcela;
161
    }
162

  
163
    @Override
164
    public void setParcela(String parcela) {
165
        this.parcela=parcela;
166
    }
167

  
168
    @Override
169
    public void validateQuery() throws BusquedaCatastralInvalidQueryException {
170
        I18nManager i18nManager = ToolsLocator.getI18nManager();
171
        if (TipoQuery.POR_RC.equals(tipoQuery)){
172
            if(referenciaCatastral==null){
173
                logger.error("RC not informed");
174
                throw new BusquedaCatastralInvalidQueryException(i18nManager.getTranslation("_error_rc_not_informed"),null);
175
            }
176
        }
177
        else if (TipoQuery.POR_LOCALIZACION.equals(tipoQuery)){
178
            if (provincia==null){
179
                logger.error("Provincia not informed");
180
                throw new BusquedaCatastralInvalidQueryException(i18nManager.getTranslation("_error_provincia_not_informed"),null);
181
            }else{
182
                if (municipio==null){
183
                    logger.error("Municipio not informed");
184
                    throw new BusquedaCatastralInvalidQueryException(i18nManager.getTranslation("_error_municipio_not_informed"),null);
185
                }else{
186
                    if (tipoParcela==null){
187
                        logger.error("Tipo Parcela not informed");
188
                        throw new BusquedaCatastralInvalidQueryException(i18nManager.getTranslation("_error_tipo_parcela_not_informed"),null);
189
                    }else{
190
                        if (tipoParcela.equals(TipoParcela.URBANA)){
191
                            if (via==null){
192
                                logger.error("Via not informed");
193
                                throw new BusquedaCatastralInvalidQueryException(i18nManager.getTranslation("_error_via_not_informed"),null);
194
                            }else{
195
                                if (numero==null){
196
                                    logger.error("Numero not informed");
197
                                    throw new BusquedaCatastralInvalidQueryException(i18nManager.getTranslation("_error_numero_not_informed"),null);
198
                                }
199
                            }
200
                        }else if (tipoParcela.equals(TipoParcela.RUSTICA)){
201
                            if (poligono==null){
202
                                logger.error("Poligono not informed");
203
                                throw new BusquedaCatastralInvalidQueryException(i18nManager.getTranslation("_error_poligono_not_informed"),null);
204
                            }else if(parcela==null){
205
                                logger.error("Parcela not informed");
206
                                throw new BusquedaCatastralInvalidQueryException(i18nManager.getTranslation("_error_parcela_not_informed"),null);
207
                            }
208
                        }
209
                    }
210
                }
211
            }
212
        }else{
213
            logger.error("Tipo query not informed");
214
            throw new BusquedaCatastralInvalidQueryException(i18nManager.getTranslation("_error_tipo_query_not_informed"),null);
215
        }
216

  
217

  
218
    }
219

  
220
    @Override
221
    public TipoQuery getTipoQuery() {
222
        return tipoQuery;
223
    }
224

  
225
    @Override
226
    public void setTipoQuery(TipoQuery tipoQuery) {
227
        this.tipoQuery=tipoQuery;
228

  
229
    }
230

  
231
}
org.gvsig.busquedacatastral/tags/org.gvsig.busquedacatastral-1.0.26/org.gvsig.busquedacatastral.lib/org.gvsig.busquedacatastral.lib.impl/src/main/java/org/gvsig/busquedacatastral/lib/impl/DefaultReferenciaCatastral.java
1
package org.gvsig.busquedacatastral.lib.impl;
2

  
3
import org.apache.commons.lang3.StringUtils;
4
import org.gvsig.busquedacatastral.lib.api.ReferenciaCatastral;
5
import org.gvsig.busquedacatastral.lib.api.TipoVia;
6
import org.gvsig.tools.ToolsLocator;
7
import org.gvsig.tools.i18n.I18nManager;
8

  
9
public class DefaultReferenciaCatastral implements ReferenciaCatastral{
10

  
11
    String pc1;//Posiciones 1-7
12
    String pc2;//Posiciones 8-14
13
    String car;//Posiciones 15-18
14
    String dc1;//19
15
    String dc2;//20
16

  
17
    String via;
18
    TipoVia tipoVia;
19
    String patio;
20
    String km;
21
    String bloque;
22
    String escalera;
23
    String planta;
24
    String puerta;
25
    String poligono;
26
    String parcela;
27
    String provincia;
28
    String municipio;
29
    String paraje;
30

  
31
    @Override
32
    public String getRC() {
33
        return getPc1()+getPc2()+getCar()+getDc1()+getDc2();
34
    }
35

  
36
    @Override
37
    public String getRCParcial() {
38
        return getPc1()+getPc2();
39
    }
40

  
41
    @Override
42
    public String getLocalizacion() {
43
        I18nManager i18nManager = ToolsLocator.getI18nManager();
44
        String localizacion="";
45
        if (getTipoVia()!=null){
46
            localizacion+=getTipoVia().getAbrev();
47
        }
48
        if (getVia()!=null){
49
            if (StringUtils.isNotEmpty(localizacion)){
50
                localizacion+=" ";
51
            }
52
            localizacion+=getVia();
53
        }
54
        if (getPatio()!=null){
55
            if (StringUtils.isNotEmpty(localizacion)){
56
                localizacion+=" ";
57
            }
58
            localizacion+=getPatio();
59
        }
60
        if (getKm()!=null){
61
            if (StringUtils.isNotEmpty(localizacion)){
62
                localizacion+=" ";
63
            }
64
            String km=i18nManager.getTranslation("_km");
65
            localizacion+=km+" "+getKm();
66
        }
67
        if (getBloque()!=null){
68
            if (StringUtils.isNotEmpty(localizacion)){
69
                localizacion+=" ";
70
            }
71
            String bloque=i18nManager.getTranslation("_bloque");
72
            localizacion+=bloque+" "+getBloque();
73
        }
74
        if (getEscalera()!=null){
75
            if (StringUtils.isNotEmpty(localizacion)){
76
                localizacion+=" ";
77
            }
78
            String escalera=i18nManager.getTranslation("_escalera");
79
            localizacion+=escalera+" "+getEscalera();
80
        }
81
        if (getPlanta()!=null){
82
            if (StringUtils.isNotEmpty(localizacion)){
83
                localizacion+=" ";
84
            }
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff