gvsig-projects-pool / org.gvsig.busquedacatastral / trunk / org.gvsig.busquedacatastral / org.gvsig.busquedacatastral.lib / org.gvsig.busquedacatastral.lib.impl / src / main / java / org / gvsig / busquedacatastral / lib / impl / WSObjectsFactory.java @ 435
History | View | Annotate | Download (7.43 KB)
1 |
package org.gvsig.busquedacatastral.lib.impl; |
---|---|
2 |
|
3 |
import java.io.File; |
4 |
import java.util.List; |
5 |
|
6 |
import javax.xml.rpc.ServiceException; |
7 |
|
8 |
import org.apache.commons.lang3.StringUtils; |
9 |
|
10 |
import org.gvsig.busquedacatastral.lib.api.BusquedaCatastralManager; |
11 |
import org.gvsig.busquedacatastral.lib.api.exceptions.BusquedaCatastralException; |
12 |
import org.gvsig.busquedacatastral.lib.api.exceptions.BusquedaCatastralGettingParamsException; |
13 |
import org.gvsig.busquedacatastral.lib.api.exceptions.BusquedaCatastralRemoteServiceException; |
14 |
import org.gvsig.busquedacatastral.lib.impl.ws.CallejeroCatastroWSLocator; |
15 |
import org.gvsig.busquedacatastral.lib.impl.ws.CallejeroCatastroWSSoap; |
16 |
import org.gvsig.busquedacatastral.lib.impl.ws.classes.cxf.Err; |
17 |
import org.gvsig.fmap.dal.DALLocator; |
18 |
import org.gvsig.fmap.dal.DataManager; |
19 |
import org.gvsig.fmap.dal.DataServerExplorerParameters; |
20 |
import org.gvsig.fmap.dal.DataStoreParameters; |
21 |
import org.gvsig.fmap.dal.exception.DataException; |
22 |
import org.gvsig.fmap.dal.exception.ValidateDataParametersException; |
23 |
import org.gvsig.fmap.dal.feature.EditableFeatureType; |
24 |
import org.gvsig.fmap.dal.feature.FeatureQuery; |
25 |
import org.gvsig.fmap.dal.feature.FeatureSet; |
26 |
import org.gvsig.fmap.dal.feature.FeatureStore; |
27 |
import org.gvsig.fmap.dal.feature.NewFeatureStoreParameters; |
28 |
import org.gvsig.fmap.dal.feature.paging.FeaturePagingHelper; |
29 |
import org.gvsig.fmap.dal.serverexplorer.filesystem.FilesystemServerExplorer; |
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 |
import org.gvsig.tools.locator.LocatorException; |
35 |
|
36 |
import org.slf4j.Logger; |
37 |
import org.slf4j.LoggerFactory; |
38 |
|
39 |
|
40 |
/**
|
41 |
* Used for classes wich need data from the webservice.
|
42 |
* Offers methods to manage webservice and cache files
|
43 |
* @author dmartinezizquierdo
|
44 |
*
|
45 |
*/
|
46 |
public abstract class WSObjectsFactory { |
47 |
|
48 |
private static final Logger logger = LoggerFactory |
49 |
.getLogger(WSObjectsFactory.class); |
50 |
|
51 |
private final static String DBF_PROVIDER_NAME="DBF"; |
52 |
|
53 |
protected BusquedaCatastralManager manager;
|
54 |
|
55 |
protected WSObjectsFactory(BusquedaCatastralManager manager){
|
56 |
this.manager=manager;
|
57 |
} |
58 |
|
59 |
|
60 |
protected CallejeroCatastroWSSoap getCatastroWS() throws BusquedaCatastralException{ |
61 |
try {
|
62 |
CallejeroCatastroWSLocator locator= |
63 |
new CallejeroCatastroWSLocator();
|
64 |
CallejeroCatastroWSSoap callejeroWS = |
65 |
locator.getCallejeroCatastroSoap(); |
66 |
return callejeroWS;
|
67 |
} catch (ServiceException e) {
|
68 |
logger.error("Error obtaining webservice",e);
|
69 |
I18nManager i18nManager = ToolsLocator.getI18nManager(); |
70 |
throw new BusquedaCatastralRemoteServiceException(i18nManager.getTranslation("_error_obtaining_catastro_webservice"), e); |
71 |
} |
72 |
} |
73 |
|
74 |
protected void createDBF(File file) |
75 |
throws BusquedaCatastralException{
|
76 |
|
77 |
FeatureStore dbfStore = null;
|
78 |
try {
|
79 |
if (!file.exists()) {
|
80 |
File folder=file.getParentFile();
|
81 |
if (!folder.exists()){
|
82 |
folder.mkdirs(); |
83 |
} |
84 |
} |
85 |
|
86 |
DataManager datamanager = DALLocator.getDataManager(); |
87 |
DataServerExplorerParameters explorerParameters = |
88 |
(DataServerExplorerParameters) datamanager |
89 |
.createServerExplorerParameters(FilesystemServerExplorer.NAME); |
90 |
FilesystemServerExplorer explorer = |
91 |
(FilesystemServerExplorer) datamanager.openServerExplorer( |
92 |
FilesystemServerExplorer.NAME, explorerParameters |
93 |
); |
94 |
|
95 |
NewFeatureStoreParameters addParams = (NewFeatureStoreParameters) explorer.getAddParameters(DBF_PROVIDER_NAME); |
96 |
addParams.setDynValue("DbfFile",file);
|
97 |
EditableFeatureType type = addParams.getDefaultFeatureType(); |
98 |
defineType(type); |
99 |
explorer.add(DBF_PROVIDER_NAME, addParams, true);
|
100 |
|
101 |
DataStoreParameters parameters = datamanager.createStoreParameters(DBF_PROVIDER_NAME); |
102 |
parameters.setDynValue("DbfFile", file);
|
103 |
dbfStore = |
104 |
(FeatureStore) datamanager.openStore(DBF_PROVIDER_NAME, parameters); |
105 |
dbfStore.edit(FeatureStore.MODE_APPEND); |
106 |
writeFileData(dbfStore); |
107 |
|
108 |
dbfStore.finishEditing(); |
109 |
dbfStore.dispose(); |
110 |
} catch (BusquedaCatastralException e) {
|
111 |
logger.error("Error getting feature store");
|
112 |
I18nManager i18nManager = ToolsLocator.getI18nManager(); |
113 |
if(dbfStore!=null && dbfStore.isEditing()) { |
114 |
try {
|
115 |
dbfStore.cancelEditing(); |
116 |
} catch (DataException e1) {
|
117 |
logger.error("Error cancelling edition of feature store");
|
118 |
throw new BusquedaCatastralGettingParamsException(i18nManager.getTranslation("_error_cancelling_edition_of_feature_store"),e); |
119 |
} |
120 |
} |
121 |
throw e;
|
122 |
} catch (Exception e) { |
123 |
logger.error("Error getting feature store");
|
124 |
I18nManager i18nManager = ToolsLocator.getI18nManager(); |
125 |
if(dbfStore!=null && dbfStore.isEditing()) { |
126 |
try {
|
127 |
dbfStore.cancelEditing(); |
128 |
} catch (DataException e1) {
|
129 |
logger.error("Error cancelling edition of feature store");
|
130 |
throw new BusquedaCatastralGettingParamsException(i18nManager.getTranslation("_error_cancelling_edition_of_feature_store"),e); |
131 |
} |
132 |
} |
133 |
throw new BusquedaCatastralGettingParamsException(i18nManager.getTranslation("_error_getting_feature_store"),e); |
134 |
} |
135 |
} |
136 |
|
137 |
|
138 |
protected List<DynObject> getListFromDBF(File file) throws BaseException { |
139 |
DataManager datamanager = DALLocator.getDataManager(); |
140 |
DataStoreParameters parameters = datamanager.createStoreParameters(DBF_PROVIDER_NAME); |
141 |
parameters.setDynValue("DbfFile", file);
|
142 |
|
143 |
FeatureStore dbf = (FeatureStore) datamanager.openStore(DBF_PROVIDER_NAME, parameters); |
144 |
|
145 |
String expressionQuery=getExpressionQuery();
|
146 |
|
147 |
FeaturePagingHelper pager; |
148 |
if(StringUtils.isEmpty(expressionQuery)){
|
149 |
pager = datamanager.createFeaturePagingHelper(dbf, 500);
|
150 |
}else{
|
151 |
FeatureQuery featureQuery = dbf.createFeatureQuery(); |
152 |
featureQuery.setFilter( datamanager.createExpresion(expressionQuery) ); |
153 |
pager = datamanager.createFeaturePagingHelper(dbf,featureQuery, 500);
|
154 |
} |
155 |
return pager.asListOfDynObjects();
|
156 |
} |
157 |
|
158 |
protected void webserviceErrors(List<Err>errores) throws BusquedaCatastralException{ |
159 |
if (errores!=null && !errores.isEmpty()){ |
160 |
StringBuilder descErrores=new StringBuilder(); |
161 |
I18nManager i18nManager = ToolsLocator.getI18nManager(); |
162 |
descErrores.append(i18nManager.getTranslation("_errors_found_by_ws")+":"); |
163 |
for (Err error:errores){
|
164 |
descErrores.append("\n"+error.getDes());
|
165 |
logger.error(descErrores.toString()); |
166 |
throw new BusquedaCatastralGettingParamsException(descErrores.toString(), null); |
167 |
} |
168 |
} |
169 |
} |
170 |
|
171 |
abstract protected void defineType(EditableFeatureType type) throws BusquedaCatastralException; |
172 |
|
173 |
abstract protected void writeFileData(FeatureStore featureStore) throws BusquedaCatastralException, DataException; |
174 |
|
175 |
abstract protected String getExpressionQuery(); |
176 |
} |