gvsig-projects-pool / org.gvsig.vcsgis / trunk / org.gvsig.vcsgis / org.gvsig.vcsgis.lib / org.gvsig.vcsgis.lib.impl / src / main / java / org / gvsig / vcsgis / lib / workspace / tables / EntitiesTable.java @ 3308
History | View | Annotate | Download (19 KB)
1 | 2699 | jjdelcerro | package org.gvsig.vcsgis.lib.workspace.tables; |
---|---|---|---|
2 | 2268 | jjdelcerro | |
3 | import javax.json.JsonObject; |
||
4 | 2713 | fdiaz | import org.apache.commons.lang3.StringUtils; |
5 | 2268 | jjdelcerro | import org.gvsig.fmap.dal.DALLocator; |
6 | import org.gvsig.fmap.dal.DataManager; |
||
7 | import org.gvsig.fmap.dal.feature.EditableFeatureType; |
||
8 | import org.gvsig.fmap.dal.feature.Feature; |
||
9 | import org.gvsig.fmap.dal.feature.FeatureSet.DisposableFeatureSetIterable; |
||
10 | import org.gvsig.fmap.dal.feature.FeatureStore; |
||
11 | import org.gvsig.fmap.dal.feature.FeatureType; |
||
12 | import org.gvsig.json.Json; |
||
13 | 2697 | jjdelcerro | import org.gvsig.json.JsonObjectBuilder; |
14 | 2268 | jjdelcerro | import org.gvsig.tools.dataTypes.DataTypes; |
15 | import org.gvsig.tools.dispose.DisposeUtils; |
||
16 | 2697 | jjdelcerro | import org.gvsig.vcsgis.lib.VCSGisEntity; |
17 | import org.gvsig.vcsgis.lib.VCSGisEntityEditable; |
||
18 | 2708 | jjdelcerro | import static org.gvsig.vcsgis.lib.VCSGisManager.STATE_CONFLICT; |
19 | import org.gvsig.vcsgis.lib.VCSGisUtils; |
||
20 | 2699 | jjdelcerro | import org.gvsig.vcsgis.lib.workspace.VCSGisWorkspace; |
21 | import org.gvsig.vcsgis.lib.workspace.VCSGisWorkspaceEntity; |
||
22 | 2708 | jjdelcerro | import org.gvsig.vcsgis.lib.workspace.tables.AbstractTable.AbstractRow; |
23 | 2897 | jjdelcerro | import static org.gvsig.vcsgis.lib.VCSGisManager.STATE_LOCAL_UNMODIFIED; |
24 | import static org.gvsig.vcsgis.lib.VCSGisManager.STATE_LOCAL_NEW; |
||
25 | import static org.gvsig.vcsgis.lib.VCSGisManager.STATE_LOCAL_MODIFIED; |
||
26 | import static org.gvsig.vcsgis.lib.VCSGisManager.STATE_LOCAL_OUTDATED; |
||
27 | import static org.gvsig.vcsgis.lib.VCSGisManager.STATE_LOCAL_OUTDATED_AND_MODIFIED; |
||
28 | 2268 | jjdelcerro | |
29 | /**
|
||
30 | *
|
||
31 | * @author gvSIG Team
|
||
32 | */
|
||
33 | @SuppressWarnings("UseSpecificCatch") |
||
34 | public class EntitiesTable extends AbstractTable { |
||
35 | |||
36 | 2381 | jjdelcerro | public static final String TABLE_NAME = "VCSGIS_ENTITIES"; |
37 | 2268 | jjdelcerro | |
38 | 3233 | fdiaz | public static final String COD_ENTITY = "COD_ENTITY"; |
39 | 2324 | jjdelcerro | private static final String ENTITY_NAME = "ENT_NAME"; |
40 | private static final String ENTITY_STATE = "ENT_STATE"; |
||
41 | private static final String DATATABLE_NAME = "ENT_DATATABLE"; |
||
42 | private static final String FEATUREID_FIELD_NAME = "ENT_FEATURECODE"; |
||
43 | private static final String GEOMETRY_FIELD_NAME = "ENT_GEOMNAME"; |
||
44 | private static final String DESCRIPTION = "ENT_DESCRIPTION"; |
||
45 | 2631 | fdiaz | private static final String FIELD_FOR_LABEL = "ENT_FIELDFORLABEL"; |
46 | 2324 | jjdelcerro | private static final String FEATURETYPE = "ENT_FEATURETYPE"; |
47 | private static final String COD_LOCAL_REVISION = "COD_LOCAL_REVISION"; |
||
48 | private static final String COD_REPOSITORY_REVISION = "COD_REPO_REVISION"; |
||
49 | 2697 | jjdelcerro | private static final String COD_USER = "COD_USER"; |
50 | private static final String COD_TOPOLOGYPLAN = "COD_TOPOLOGYPLAN"; |
||
51 | 3182 | jjdelcerro | private static final String CATEGORY = "ENT_CATEGORY"; |
52 | 3234 | jjdelcerro | private static final String LABEL = "ENT_LABEL"; |
53 | 3308 | jjdelcerro | private static final String AUTHORIZATIONS = "ENT_AUTORIZATIONS"; |
54 | private static final String TOPOLOGYPLAN_MODE = "ENT_TOPOLOGYPLAN_MODE"; |
||
55 | 2268 | jjdelcerro | |
56 | 2697 | jjdelcerro | public static class EntityRow extends AbstractRow implements VCSGisWorkspaceEntity { |
57 | 2278 | jjdelcerro | |
58 | 2268 | jjdelcerro | private FeatureType featureType;
|
59 | 2278 | jjdelcerro | |
60 | 2572 | jjdelcerro | public EntityRow(VCSGisWorkspace workspace) {
|
61 | 2831 | jjdelcerro | super(workspace, TABLE_NAME, COD_ENTITY);
|
62 | 2268 | jjdelcerro | } |
63 | 2278 | jjdelcerro | |
64 | 2572 | jjdelcerro | public EntityRow(VCSGisWorkspace workspace, Feature feature) {
|
65 | 2831 | jjdelcerro | super(workspace, TABLE_NAME, COD_ENTITY,feature);
|
66 | 2268 | jjdelcerro | } |
67 | 2278 | jjdelcerro | |
68 | @Override
|
||
69 | 2268 | jjdelcerro | public String getEntityName() { |
70 | 2831 | jjdelcerro | return this.getString(ENTITY_NAME); |
71 | 2268 | jjdelcerro | } |
72 | 2278 | jjdelcerro | |
73 | @Override
|
||
74 | 2268 | jjdelcerro | public String getDataTableName() { |
75 | 2831 | jjdelcerro | return this.getString(DATATABLE_NAME); |
76 | 2268 | jjdelcerro | } |
77 | |||
78 | 2694 | fdiaz | @Override
|
79 | public String getFeatureIdFieldName() { |
||
80 | 2831 | jjdelcerro | return this.getString(FEATUREID_FIELD_NAME); |
81 | 2268 | jjdelcerro | } |
82 | |||
83 | 2694 | fdiaz | |
84 | 2697 | jjdelcerro | @Override
|
85 | 2268 | jjdelcerro | public String getGeometryFieldName() { |
86 | 2831 | jjdelcerro | return this.getString(GEOMETRY_FIELD_NAME); |
87 | 2268 | jjdelcerro | } |
88 | |||
89 | 2278 | jjdelcerro | @Override
|
90 | 2268 | jjdelcerro | public String getDescription() { |
91 | 2831 | jjdelcerro | return this.getString(DESCRIPTION); |
92 | 2268 | jjdelcerro | } |
93 | |||
94 | 2632 | jjdelcerro | @Override
|
95 | 2631 | fdiaz | public String getFieldForLabel() { |
96 | 2831 | jjdelcerro | return this.getString(FIELD_FOR_LABEL); |
97 | 2631 | fdiaz | } |
98 | |||
99 | 2697 | jjdelcerro | @Override
|
100 | public String getUserCode() { |
||
101 | 2831 | jjdelcerro | return this.getString(COD_USER); |
102 | 2697 | jjdelcerro | } |
103 | |||
104 | @Override
|
||
105 | public String getTopologyPlanCode() { |
||
106 | 2831 | jjdelcerro | return this.getString(COD_TOPOLOGYPLAN); |
107 | 2697 | jjdelcerro | } |
108 | |||
109 | @Override
|
||
110 | public String getEntityCode() { |
||
111 | return this.getCode(); |
||
112 | } |
||
113 | |||
114 | @Override
|
||
115 | public String getLocalRevisionCode() { |
||
116 | 2831 | jjdelcerro | return this.getString(COD_LOCAL_REVISION); |
117 | 2697 | jjdelcerro | } |
118 | |||
119 | @Override
|
||
120 | public String getRepositoryRevisionCode() { |
||
121 | 2831 | jjdelcerro | return this.getString(COD_REPOSITORY_REVISION); |
122 | 2697 | jjdelcerro | } |
123 | |||
124 | @Override
|
||
125 | 3182 | jjdelcerro | public String getCategory() { |
126 | return this.getString(CATEGORY); |
||
127 | } |
||
128 | |||
129 | @Override
|
||
130 | 3308 | jjdelcerro | public String getAuthorizations() { |
131 | return this.getString(AUTHORIZATIONS); |
||
132 | } |
||
133 | |||
134 | @Override
|
||
135 | public int getTopologyPlanMode() { |
||
136 | return this.getInt(TOPOLOGYPLAN_MODE); |
||
137 | } |
||
138 | |||
139 | @Override
|
||
140 | 3234 | jjdelcerro | public String getLabel() { |
141 | return this.getString(LABEL); |
||
142 | } |
||
143 | |||
144 | @Override
|
||
145 | 2268 | jjdelcerro | public String getFeatureTypeAsJson() { |
146 | 2831 | jjdelcerro | return this.getString(FEATURETYPE); |
147 | 2268 | jjdelcerro | } |
148 | |||
149 | 2278 | jjdelcerro | @Override
|
150 | 2268 | jjdelcerro | public FeatureType getFeatureType() {
|
151 | 2278 | jjdelcerro | if (this.featureType == null) { |
152 | 2268 | jjdelcerro | JsonObject json = Json.createObject(this.getFeatureTypeAsJson());
|
153 | this.featureType = DALLocator.getDataManager().createFeatureType(json);
|
||
154 | } |
||
155 | return this.featureType; |
||
156 | } |
||
157 | |||
158 | 2697 | jjdelcerro | |
159 | @Override
|
||
160 | public EntityRow setEntityName(String entityName) { |
||
161 | 2831 | jjdelcerro | this.set(ENTITY_NAME, entityName);
|
162 | 3234 | jjdelcerro | if( StringUtils.isBlank(this.getLabel())) { |
163 | this.setLabel(entityName);
|
||
164 | } |
||
165 | 2697 | jjdelcerro | return this; |
166 | 2268 | jjdelcerro | } |
167 | 2278 | jjdelcerro | |
168 | 2697 | jjdelcerro | @Override
|
169 | public EntityRow setDataTableName(String dataTableName) { |
||
170 | 2831 | jjdelcerro | this.set(DATATABLE_NAME, dataTableName);
|
171 | 2697 | jjdelcerro | return this; |
172 | 2268 | jjdelcerro | } |
173 | |||
174 | 2697 | jjdelcerro | @Override
|
175 | public EntityRow setFeatureIdFieldName(String name) { |
||
176 | 2831 | jjdelcerro | this.set(FEATUREID_FIELD_NAME, name);
|
177 | 2697 | jjdelcerro | return this; |
178 | 2268 | jjdelcerro | } |
179 | |||
180 | 2697 | jjdelcerro | @Override
|
181 | public EntityRow setGeometryFieldName(String name) { |
||
182 | 2831 | jjdelcerro | this.set(GEOMETRY_FIELD_NAME, name);
|
183 | 2697 | jjdelcerro | return this; |
184 | 2268 | jjdelcerro | } |
185 | |||
186 | 2697 | jjdelcerro | @Override
|
187 | public EntityRow setDescription(String description) { |
||
188 | 2831 | jjdelcerro | this.set(DESCRIPTION, description);
|
189 | 2697 | jjdelcerro | return this; |
190 | 2268 | jjdelcerro | } |
191 | |||
192 | 2697 | jjdelcerro | @Override
|
193 | public EntityRow setFieldForLabel(String fieldForLabel) { |
||
194 | 2831 | jjdelcerro | this.set(FIELD_FOR_LABEL, fieldForLabel);
|
195 | 2697 | jjdelcerro | return this; |
196 | 2631 | fdiaz | } |
197 | 2635 | fdiaz | |
198 | 2697 | jjdelcerro | @Override
|
199 | public EntityRow setFeatureTypeAsJson(String json) { |
||
200 | 2831 | jjdelcerro | this.set(FEATURETYPE, json);
|
201 | 2706 | fdiaz | this.featureType = null; |
202 | 2697 | jjdelcerro | return this; |
203 | 2268 | jjdelcerro | } |
204 | |||
205 | 2697 | jjdelcerro | public EntityRow setFeatureType(FeatureType featureType) {
|
206 | 2831 | jjdelcerro | this.set(FEATURETYPE, featureType.toJson().toString());
|
207 | 2697 | jjdelcerro | return this; |
208 | 2268 | jjdelcerro | } |
209 | |||
210 | 2697 | jjdelcerro | @Override
|
211 | public EntityRow setLocalRevisionCode(String code) { |
||
212 | 2831 | jjdelcerro | this.set(COD_LOCAL_REVISION, code);
|
213 | 2697 | jjdelcerro | return this; |
214 | 2268 | jjdelcerro | } |
215 | |||
216 | 2697 | jjdelcerro | @Override
|
217 | public EntityRow setRepositoryRevisionCode(String code) { |
||
218 | 2831 | jjdelcerro | this.set(COD_REPOSITORY_REVISION, code);
|
219 | 2697 | jjdelcerro | return this; |
220 | 2278 | jjdelcerro | } |
221 | |||
222 | |||
223 | @Override
|
||
224 | 2697 | jjdelcerro | public VCSGisEntityEditable setUserCode(String userCode) { |
225 | 2831 | jjdelcerro | this.set(COD_USER, userCode);
|
226 | 2697 | jjdelcerro | return this; |
227 | 2278 | jjdelcerro | } |
228 | |||
229 | @Override
|
||
230 | 2697 | jjdelcerro | public VCSGisEntityEditable setTopologyPlanCode(String topologyplanCode) { |
231 | 2831 | jjdelcerro | this.set(COD_TOPOLOGYPLAN, topologyplanCode);
|
232 | 2697 | jjdelcerro | return this; |
233 | 2278 | jjdelcerro | } |
234 | |||
235 | @Override
|
||
236 | 3182 | jjdelcerro | public VCSGisEntityEditable setCategory(String category) { |
237 | this.set(CATEGORY, category);
|
||
238 | return this; |
||
239 | } |
||
240 | |||
241 | @Override
|
||
242 | 3308 | jjdelcerro | public VCSGisEntityEditable setAuthorizations(String authorizations) { |
243 | this.set(AUTHORIZATIONS, authorizations);
|
||
244 | return this; |
||
245 | } |
||
246 | |||
247 | @Override
|
||
248 | public VCSGisEntityEditable setTopologyPlanMode(int topologyPlanMode) { |
||
249 | this.set(TOPOLOGYPLAN_MODE, topologyPlanMode);
|
||
250 | return this; |
||
251 | } |
||
252 | |||
253 | @Override
|
||
254 | 3234 | jjdelcerro | public VCSGisEntityEditable setLabel(String label) { |
255 | 3298 | fdiaz | if(label != null){ |
256 | this.set(LABEL, label);
|
||
257 | } |
||
258 | 3234 | jjdelcerro | return this; |
259 | } |
||
260 | |||
261 | @Override
|
||
262 | 2278 | jjdelcerro | public long getCountLocalChanges() { |
263 | 2701 | fdiaz | WorkspaceChangesTable changesTable = new WorkspaceChangesTable();
|
264 | 2625 | fdiaz | return changesTable.getCountLocalChangesOfEntity(workspace, this.getCode()); |
265 | 2278 | jjdelcerro | } |
266 | |||
267 | private void updateState() { |
||
268 | long countChanges;
|
||
269 | 2831 | jjdelcerro | int state = this.getInt(ENTITY_STATE, -1); |
270 | if( state == -1 ) { |
||
271 | 2897 | jjdelcerro | state = STATE_LOCAL_UNMODIFIED; |
272 | 2831 | jjdelcerro | this.setState(state);
|
273 | } |
||
274 | 2278 | jjdelcerro | switch (state) {
|
275 | 2897 | jjdelcerro | case STATE_LOCAL_UNMODIFIED:
|
276 | 2278 | jjdelcerro | countChanges = this.getCountLocalChanges();
|
277 | if (countChanges > 0) { |
||
278 | 2897 | jjdelcerro | state = STATE_LOCAL_MODIFIED; |
279 | 2713 | fdiaz | if(this.isOutdated()){ |
280 | 2897 | jjdelcerro | state = STATE_LOCAL_OUTDATED_AND_MODIFIED; |
281 | 2713 | fdiaz | } |
282 | 2278 | jjdelcerro | this.setState(state);
|
283 | 2719 | fdiaz | } else if(this.isOutdated()){ |
284 | 2897 | jjdelcerro | state = STATE_LOCAL_OUTDATED; |
285 | 2719 | fdiaz | this.setState(state);
|
286 | 2278 | jjdelcerro | } |
287 | break;
|
||
288 | 2897 | jjdelcerro | case STATE_LOCAL_OUTDATED:
|
289 | 2713 | fdiaz | if(!this.isOutdated()){ |
290 | countChanges = this.getCountLocalChanges();
|
||
291 | if (countChanges > 0) { |
||
292 | 2897 | jjdelcerro | state = STATE_LOCAL_MODIFIED; |
293 | 2713 | fdiaz | } else {
|
294 | 2897 | jjdelcerro | state = STATE_LOCAL_UNMODIFIED; |
295 | 2713 | fdiaz | } |
296 | } else {
|
||
297 | countChanges = this.getCountLocalChanges();
|
||
298 | if (countChanges > 0) { |
||
299 | 2897 | jjdelcerro | state = STATE_LOCAL_OUTDATED_AND_MODIFIED; |
300 | 2713 | fdiaz | this.setState(state);
|
301 | } |
||
302 | } |
||
303 | this.setState(state);
|
||
304 | break;
|
||
305 | 2897 | jjdelcerro | case STATE_LOCAL_MODIFIED:
|
306 | 2278 | jjdelcerro | countChanges = this.getCountLocalChanges();
|
307 | 2713 | fdiaz | if (countChanges == 0) { |
308 | 2897 | jjdelcerro | state = STATE_LOCAL_UNMODIFIED; |
309 | 2713 | fdiaz | if(this.isOutdated()){ |
310 | 2897 | jjdelcerro | state = STATE_LOCAL_OUTDATED; |
311 | 2713 | fdiaz | } |
312 | } else {
|
||
313 | if(this.isOutdated()){ |
||
314 | 2897 | jjdelcerro | state = STATE_LOCAL_OUTDATED_AND_MODIFIED; |
315 | 2713 | fdiaz | } |
316 | } |
||
317 | |||
318 | this.setState(state);
|
||
319 | break;
|
||
320 | 2897 | jjdelcerro | case STATE_LOCAL_OUTDATED_AND_MODIFIED:
|
321 | 2713 | fdiaz | if(!this.isOutdated()){ |
322 | countChanges = this.getCountLocalChanges();
|
||
323 | if (countChanges > 0) { |
||
324 | 2897 | jjdelcerro | state = STATE_LOCAL_MODIFIED; |
325 | 2713 | fdiaz | this.setState(state);
|
326 | } else {
|
||
327 | 2897 | jjdelcerro | state = STATE_LOCAL_UNMODIFIED; |
328 | 2713 | fdiaz | } |
329 | } else {
|
||
330 | countChanges = this.getCountLocalChanges();
|
||
331 | if (countChanges > 0) { |
||
332 | 2897 | jjdelcerro | state = STATE_LOCAL_OUTDATED_AND_MODIFIED; |
333 | 2713 | fdiaz | this.setState(state);
|
334 | } else {
|
||
335 | 2897 | jjdelcerro | state = STATE_LOCAL_OUTDATED; |
336 | 2713 | fdiaz | } |
337 | } |
||
338 | this.setState(state);
|
||
339 | break;
|
||
340 | |||
341 | 2897 | jjdelcerro | case STATE_LOCAL_NEW:
|
342 | 2713 | fdiaz | countChanges = this.getCountLocalChanges();
|
343 | 2278 | jjdelcerro | if (countChanges > 0) { |
344 | 2897 | jjdelcerro | state = STATE_LOCAL_MODIFIED; |
345 | 2713 | fdiaz | if(this.isOutdated()){ |
346 | 2897 | jjdelcerro | state = STATE_LOCAL_OUTDATED_AND_MODIFIED; |
347 | 2713 | fdiaz | } |
348 | 2278 | jjdelcerro | this.setState(state);
|
349 | 2713 | fdiaz | } else {
|
350 | 2897 | jjdelcerro | state = STATE_LOCAL_UNMODIFIED; |
351 | 2278 | jjdelcerro | } |
352 | 2713 | fdiaz | this.setState(state);
|
353 | 2278 | jjdelcerro | break;
|
354 | case STATE_CONFLICT:
|
||
355 | break;
|
||
356 | 2713 | fdiaz | default:
|
357 | if(this.isOutdated()){ |
||
358 | 2897 | jjdelcerro | state = STATE_LOCAL_OUTDATED; |
359 | 2713 | fdiaz | this.setState(state);
|
360 | } |
||
361 | |||
362 | |||
363 | 2278 | jjdelcerro | } |
364 | } |
||
365 | |||
366 | @Override
|
||
367 | public int getState() { |
||
368 | this.updateState();
|
||
369 | 2831 | jjdelcerro | int state = this.getInt(ENTITY_STATE); |
370 | 2278 | jjdelcerro | return state;
|
371 | } |
||
372 | |||
373 | 2713 | fdiaz | @Override
|
374 | public boolean isOutdated() { |
||
375 | final String repositoryRevisionCode = this.getRepositoryRevisionCode(); |
||
376 | if(StringUtils.isBlank(repositoryRevisionCode)){
|
||
377 | return false; |
||
378 | } |
||
379 | return !StringUtils.equalsIgnoreCase(repositoryRevisionCode,this.getLocalRevisionCode()); |
||
380 | } |
||
381 | |||
382 | 2572 | jjdelcerro | public String getStateLabel() { |
383 | 2713 | fdiaz | return VCSGisUtils.getStateLabel(this.getState()); |
384 | 2572 | jjdelcerro | } |
385 | |||
386 | 2278 | jjdelcerro | public void setState(int state) { |
387 | 2831 | jjdelcerro | this.set(ENTITY_STATE, state);
|
388 | 2278 | jjdelcerro | } |
389 | |||
390 | @Override
|
||
391 | public void update() { |
||
392 | this.updateState();
|
||
393 | super.update();
|
||
394 | } |
||
395 | 2331 | fdiaz | |
396 | @Override
|
||
397 | 2697 | jjdelcerro | public VCSGisWorkspaceEntity getValue() {
|
398 | 2331 | fdiaz | return this; |
399 | } |
||
400 | |||
401 | @Override
|
||
402 | public String toString() { |
||
403 | 3234 | jjdelcerro | if( StringUtils.isBlank(this.getLabel()) ) { |
404 | return this.getEntityName(); |
||
405 | } |
||
406 | return this.getLabel(); |
||
407 | 2331 | fdiaz | } |
408 | 2572 | jjdelcerro | |
409 | 2697 | jjdelcerro | @Override
|
410 | public EntityRow setEntityCode(String code) { |
||
411 | this.setCode(code);
|
||
412 | return this; |
||
413 | } |
||
414 | 2694 | fdiaz | |
415 | 2697 | jjdelcerro | @Override
|
416 | public void copyfrom(VCSGisEntity entity) { |
||
417 | 2715 | jjdelcerro | VCSGisUtils.copy(entity, this, null); |
418 | 2697 | jjdelcerro | } |
419 | |||
420 | @Override
|
||
421 | public void copyto(VCSGisEntityEditable entity) { |
||
422 | 2715 | jjdelcerro | VCSGisUtils.copy(this, entity, null); |
423 | 2697 | jjdelcerro | } |
424 | |||
425 | @Override
|
||
426 | public JsonObject toJson() {
|
||
427 | return this.toJsonBuilder().build(); |
||
428 | } |
||
429 | |||
430 | @Override
|
||
431 | public JsonObjectBuilder toJsonBuilder() {
|
||
432 | 2715 | jjdelcerro | return VCSGisUtils.toJsonBuilder(this, null); |
433 | 2697 | jjdelcerro | } |
434 | |||
435 | @Override
|
||
436 | public void fromJson(JsonObject json) { |
||
437 | VCSGisUtils.fromJson(this, json);
|
||
438 | } |
||
439 | |||
440 | 3308 | jjdelcerro | @Override
|
441 | public boolean isAuthorized(String userName, String operation) { |
||
442 | return VCSGisUtils.isAuthoriced(this, operation, userName); |
||
443 | } |
||
444 | 2268 | jjdelcerro | } |
445 | |||
446 | 2278 | jjdelcerro | |
447 | 2268 | jjdelcerro | public EntitiesTable() {
|
448 | super(TABLE_NAME, featureType());
|
||
449 | } |
||
450 | 2278 | jjdelcerro | |
451 | 2572 | jjdelcerro | public EntityRow getByEntityName(VCSGisWorkspace workspace, String entityName) { |
452 | 2268 | jjdelcerro | FeatureStore store = null;
|
453 | try {
|
||
454 | store = workspace.getFeatureStore(TABLE_NAME); |
||
455 | 2278 | jjdelcerro | Feature f = store.findFirst("\"" + ENTITY_NAME + "\"='" + entityName + "'"); |
456 | if (f == null) { |
||
457 | 2268 | jjdelcerro | return null; |
458 | } |
||
459 | EntityRow row = new EntityRow(workspace, f);
|
||
460 | return row;
|
||
461 | } catch (Exception ex) { |
||
462 | 2278 | jjdelcerro | throw new RuntimeException("Can't retrieve entity '" + entityName + "'.", ex); |
463 | 2268 | jjdelcerro | } finally {
|
464 | DisposeUtils.disposeQuietly(store); |
||
465 | } |
||
466 | } |
||
467 | 2278 | jjdelcerro | |
468 | 2695 | fdiaz | public EntityRow getByEntityCode(VCSGisWorkspace workspace, String entityCode) { |
469 | FeatureStore store = null;
|
||
470 | try {
|
||
471 | store = workspace.getFeatureStore(TABLE_NAME); |
||
472 | Feature f = store.findFirst("\"" + COD_ENTITY + "\"='" + entityCode + "'"); |
||
473 | if (f == null) { |
||
474 | return null; |
||
475 | } |
||
476 | EntityRow row = new EntityRow(workspace, f);
|
||
477 | return row;
|
||
478 | } catch (Exception ex) { |
||
479 | throw new RuntimeException("Can't retrieve entity '" + entityCode + "'.", ex); |
||
480 | } finally {
|
||
481 | DisposeUtils.disposeQuietly(store); |
||
482 | } |
||
483 | } |
||
484 | |||
485 | 2572 | jjdelcerro | public DisposableFeatureSetIterable getAll(VCSGisWorkspace workspace) {
|
486 | 2268 | jjdelcerro | FeatureStore store = null;
|
487 | try {
|
||
488 | store = workspace.getFeatureStore(TABLE_NAME); |
||
489 | DisposableFeatureSetIterable items = store.getFeatureSet().iterable(); |
||
490 | return items;
|
||
491 | } catch (Exception ex) { |
||
492 | throw new RuntimeException("Can't retrieve all entities.", ex); |
||
493 | } finally {
|
||
494 | 2278 | jjdelcerro | if (store != null) { |
495 | 2268 | jjdelcerro | DisposeUtils.dispose(store); |
496 | } |
||
497 | } |
||
498 | } |
||
499 | 2278 | jjdelcerro | |
500 | 2268 | jjdelcerro | public static final FeatureType featureType() { |
501 | DataManager dataManager = DALLocator.getDataManager(); |
||
502 | EditableFeatureType ft = dataManager.createFeatureType(); |
||
503 | 2381 | jjdelcerro | ft.setLabel("VCSGIS Entities");
|
504 | 2268 | jjdelcerro | ft.getTags().set("ID", TABLE_NAME);
|
505 | ft.add(COD_ENTITY, DataTypes.STRING) |
||
506 | .setSize(40)
|
||
507 | .setIsPrimaryKey(true)
|
||
508 | 2324 | jjdelcerro | .setLabel("Code");
|
509 | 2697 | jjdelcerro | ft.add(COD_USER, DataTypes.STRING) |
510 | .setSize(40)
|
||
511 | .setIsPrimaryKey(false)
|
||
512 | .setLabel("Code");
|
||
513 | ft.add(COD_TOPOLOGYPLAN, DataTypes.STRING) |
||
514 | .setSize(40)
|
||
515 | .setIsPrimaryKey(false)
|
||
516 | .setLabel("Code");
|
||
517 | 2268 | jjdelcerro | ft.add(ENTITY_NAME, DataTypes.STRING) |
518 | .setIsIndexed(true)
|
||
519 | .setAllowIndexDuplicateds(false)
|
||
520 | .setSize(200)
|
||
521 | .setLabel("Name");
|
||
522 | ft.add(DATATABLE_NAME, DataTypes.STRING) |
||
523 | .setSize(200)
|
||
524 | .setLabel("Table name")
|
||
525 | .setDescription("Name of the table in which the data is stored");
|
||
526 | 2324 | jjdelcerro | ft.add(FEATUREID_FIELD_NAME, DataTypes.STRING) |
527 | 2268 | jjdelcerro | .setSize(200)
|
528 | .setLabel("Pk field name")
|
||
529 | .setDescription("Name of the primary key of the table.");
|
||
530 | 2278 | jjdelcerro | ft.add(COD_LOCAL_REVISION, DataTypes.STRING) |
531 | 2268 | jjdelcerro | .setSize(40)
|
532 | .setLabel("Revision")
|
||
533 | 2278 | jjdelcerro | .setDescription("Local revision.");
|
534 | ft.add(COD_REPOSITORY_REVISION, DataTypes.STRING) |
||
535 | .setSize(40)
|
||
536 | .setLabel("Revision")
|
||
537 | .setDescription("Last revision in repository.");
|
||
538 | ft.add(ENTITY_STATE, DataTypes.INTEGER) |
||
539 | .setLabel("State")
|
||
540 | .setDescription("State of entity.");
|
||
541 | 2268 | jjdelcerro | ft.add(GEOMETRY_FIELD_NAME, DataTypes.STRING) |
542 | .setSize(200)
|
||
543 | .setLabel("Geometry field name")
|
||
544 | .setDescription("Name of the geometry attribute.");
|
||
545 | 2631 | fdiaz | ft.add(FIELD_FOR_LABEL, DataTypes.STRING) |
546 | .setSize(200)
|
||
547 | .setLabel("Field for label");
|
||
548 | 3182 | jjdelcerro | ft.add(CATEGORY, DataTypes.STRING) |
549 | .setSize(200)
|
||
550 | .setLabel("Category");
|
||
551 | 3234 | jjdelcerro | ft.add(LABEL, DataTypes.STRING) |
552 | .setSize(200)
|
||
553 | .setLabel("Label");
|
||
554 | 3308 | jjdelcerro | ft.add(AUTHORIZATIONS, DataTypes.STRING) |
555 | .setSize(10240)
|
||
556 | .setLabel("Authorizations");
|
||
557 | 2268 | jjdelcerro | ft.add(DESCRIPTION, DataTypes.STRING) |
558 | .setSize(10240)
|
||
559 | .setLabel("Description");
|
||
560 | ft.add(FEATURETYPE, DataTypes.STRING) |
||
561 | .setSize(10240)
|
||
562 | .setLabel("Feature type");
|
||
563 | 2278 | jjdelcerro | |
564 | 2268 | jjdelcerro | return ft.getNotEditableCopy();
|
565 | } |
||
566 | 2278 | jjdelcerro | |
567 | 2268 | jjdelcerro | } |