Revision 9512
org.gvsig.online/trunk/org.gvsig.online/org.gvsig.online.app/org.gvsig.online.app.mainplugin/src/main/java/org/gvsig/online/app/mainplugin/OnlineSwingServicesImpl.java | ||
---|---|---|
389 | 389 |
String storeFullName = store.getFullName(); |
390 | 390 |
List<Document> views = project.getDocuments(ViewManager.TYPENAME); |
391 | 391 |
for (Document doc : views) { |
392 |
ViewDocument view = (ViewDocument)doc; |
|
392 |
ViewDocument view = (ViewDocument) doc;
|
|
393 | 393 |
for (Iterator<FLayer> it = view.deepiterator(); it.hasNext();) { |
394 | 394 |
FLayer layer = it.next(); |
395 |
if(layer instanceof FLyrVect){
|
|
395 |
if (layer instanceof FLyrVect) {
|
|
396 | 396 |
FeatureStore layerStore = ((FLyrVect) layer).getFeatureStore(); |
397 |
if( layerStore!=null && StringUtils.equals(layerStore.getFullName(), storeFullName)){ |
|
397 |
// if( layerStore!=null && StringUtils.equals(layerStore.getFullName(), storeFullName)){ |
|
398 |
if (layerStore != null && layerStore.getParameters().isTheSameStore(store.getParameters())) { //StringUtils.equals(layerStore.getFullName(),store.getFullName() )) { |
|
398 | 399 |
try { |
399 | 400 |
layerStore.refresh(); |
400 |
} catch(Exception ex) { |
|
401 |
LOGGER.warn("Can't refresh store from layer '"+layer.getName()+"'.", ex);
|
|
401 |
} catch (Exception ex) {
|
|
402 |
LOGGER.warn("Can't refresh store from layer '" + layer.getName() + "'.", ex);
|
|
402 | 403 |
} |
403 | 404 |
view.getMapContext().invalidate(); |
404 | 405 |
break; |
... | ... | |
406 | 407 |
} |
407 | 408 |
} |
408 | 409 |
} |
410 |
|
|
409 | 411 |
List<Document> tables = project.getDocuments(TableManager.TYPENAME); |
410 | 412 |
for (Document doc : tables) { |
411 | 413 |
TableDocument table = (TableDocument)doc; |
412 | 414 |
FeatureStore featureStore = table.getStore(); |
413 |
if( StringUtils.equals(featureStore.getFullName(), storeFullName)){ |
|
415 |
// if( StringUtils.equals(featureStore.getFullName(), storeFullName)){ |
|
416 |
if( featureStore.getParameters().isTheSameStore(store.getParameters())){ |
|
414 | 417 |
try { |
415 | 418 |
featureStore.refresh(); |
416 | 419 |
} catch (DataException e) { |
... | ... | |
486 | 489 |
FLayer layer = it.next(); |
487 | 490 |
if (layer instanceof FLyrVect) { |
488 | 491 |
FeatureStore layerStore = ((FLyrVect) layer).getFeatureStore(); |
489 |
if ( layerStore!=null && StringUtils.equals(layerStore.getFullName(),store.getFullName() )) { |
|
492 |
if ( layerStore!=null && layerStore.getParameters().isTheSameStore(store.getParameters()) ) { //StringUtils.equals(layerStore.getFullName(),store.getFullName() )) {
|
|
490 | 493 |
viewList.add(view); |
491 | 494 |
break; |
492 | 495 |
} |
org.gvsig.online/trunk/org.gvsig.online/org.gvsig.online.app/org.gvsig.online.app.mainplugin/src/main/resources-plugin/config.xml | ||
---|---|---|
37 | 37 |
/> |
38 | 38 |
<action |
39 | 39 |
name="tools-online-download" |
40 |
label="_Online_download"
|
|
40 |
label="_Online_Download"
|
|
41 | 41 |
tooltip="_Download_table_from_remote" |
42 | 42 |
position="900700220" |
43 | 43 |
action-command="tools-online-download" |
org.gvsig.online/trunk/org.gvsig.online/org.gvsig.online.app/org.gvsig.online.app.mainplugin/src/main/resources-plugin/i18n/text.properties | ||
---|---|---|
37 | 37 |
_Selected_working_copy_file_is_not_valid=El archivo de copia de trabajo seleccionado no es v\u00e1lido |
38 | 38 |
_Working_area=\u00c1rea de trabajo |
39 | 39 |
_You_must_select_some_layer=Debe seleccionar alguna capa |
40 |
_Area=\u00c1rea |
|
41 |
_Synchronization_zone=Zona de sincronizaci\u00f3n |
|
42 |
_Only_changes_zone=Solo zona de cambios |
|
43 |
_Changes_zone_and_working_area=Zona de cambios y \u00e1rea de trabajo |
|
44 |
_Show_working_area_selector=Mostrar el selector de \u00e1rea |
|
45 |
_Online=gvSIG online |
|
46 |
_Online_Download=Descargar |
|
47 |
_Select_a_Online_project=Seleccione un proyecto de gvSIG online |
|
48 |
_Working_area=\u00c1rea de trabajo |
|
49 |
_Downloading_data=Descargando datos |
|
50 |
_Downloading_data_from_area=Descargando datos del \u00e1rea |
|
51 |
_There_are_selected_entities_that_have_conflicts=Hay entidades seleccionadas con conflictos |
|
52 |
_There_are_selected_corrupted_or_disconnected_entities=Hay entidades seleccionadas corruptas o desconectadas |
|
53 |
_Not_in_local=No en local |
org.gvsig.online/trunk/org.gvsig.online/org.gvsig.online.app/org.gvsig.online.app.mainplugin/src/main/resources-plugin/i18n/text_en.properties | ||
---|---|---|
37 | 37 |
_Selected_working_copy_file_is_not_valid=Selected working copy file is not valid |
38 | 38 |
_Working_area=Working area |
39 | 39 |
_You_must_select_some_layer=You must select some layer |
40 |
_Area=Area |
|
41 |
_Synchronization_zone=Synchronization zone |
|
42 |
_Only_changes_zone=Only changes zone |
|
43 |
_Changes_zone_and_working_area=Changes zone and working area |
|
44 |
_Show_working_area_selector=Show working area selector |
|
45 |
_Online=gvSIG online |
|
46 |
_Online_Download=Download |
|
47 |
_Select_a_Online_project=Select a gvSIG online project |
|
48 |
_Working_area=Working area |
|
49 |
_Downloading_data=Downloading data |
|
50 |
_Downloading_data_from_area=Downloading data from area |
|
51 |
_There_are_selected_entities_that_have_conflicts=There are selected entities that have conflicts |
|
52 |
_There_are_selected_corrupted_or_disconnected_entities=Selected entities are corrupt or offline |
|
53 |
_Not_in_local=Not in local |
org.gvsig.online/trunk/org.gvsig.online/org.gvsig.online.lib/org.gvsig.online.lib.impl/pom.xml | ||
---|---|---|
63 | 63 |
<type>jar</type> |
64 | 64 |
</dependency> |
65 | 65 |
</dependencies> |
66 |
<build> |
|
67 |
<plugins> |
|
68 |
|
|
69 |
<plugin> |
|
70 |
<groupId>org.apache.maven.plugins</groupId> |
|
71 |
<artifactId>maven-surefire-plugin</artifactId> |
|
72 |
<configuration> |
|
73 |
<!-- Skip test execution ? --> |
|
74 |
<skipTests>false</skipTests> |
|
75 |
<!-- Ignore test execution failure ? --> |
|
76 |
<testFailureIgnore>true</testFailureIgnore> |
|
77 |
<excludes> |
|
78 |
<exclude>**/TestCheckoutAlternativo.java</exclude> |
|
79 |
</excludes> |
|
80 |
</configuration> |
|
81 |
</plugin> |
|
82 |
|
|
83 |
<!-- Skip test compilation ? --> |
|
84 |
<plugin> |
|
85 |
<groupId>org.apache.maven.plugins</groupId> |
|
86 |
<artifactId>maven-compiler-plugin</artifactId> |
|
87 |
<executions> |
|
88 |
<execution> |
|
89 |
<id>default-testCompile</id> |
|
90 |
<phase>process-test-sources</phase> |
|
91 |
<goals> |
|
92 |
<goal>testCompile</goal> |
|
93 |
</goals> |
|
94 |
<configuration> |
|
95 |
<skip>false</skip> |
|
96 |
</configuration> |
|
97 |
</execution> |
|
98 |
</executions> |
|
99 |
</plugin> |
|
100 |
<plugin> |
|
101 |
<groupId>org.apache.maven.plugins</groupId> |
|
102 |
<artifactId>maven-jar-plugin</artifactId> |
|
103 |
<configuration> |
|
104 |
</configuration> |
|
105 |
<executions> |
|
106 |
<!-- Generates a jar file only with the test classes --> |
|
107 |
<execution> |
|
108 |
<goals> |
|
109 |
<goal>test-jar</goal> |
|
110 |
</goals> |
|
111 |
</execution> |
|
112 |
</executions> |
|
113 |
</plugin> |
|
114 |
</plugins> |
|
115 |
</build> |
|
116 |
|
|
66 | 117 |
</project> |
org.gvsig.online/trunk/org.gvsig.online/org.gvsig.online.lib/org.gvsig.online.lib.impl/src/test/java/org/gvsig/tools/patch/PatchGeneratorTest01.java | ||
---|---|---|
1 |
/* gvSIG. Desktop Geographic Information System. |
|
2 |
* |
|
3 |
* Copyright (c) 2007-2024 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.tools.patch; |
|
24 |
|
|
25 |
import java.util.ArrayList; |
|
26 |
import java.util.List; |
|
27 |
import java.util.Objects; |
|
28 |
import junit.framework.TestCase; |
|
29 |
import org.apache.commons.lang3.tuple.ImmutablePair; |
|
30 |
import org.apache.commons.lang3.tuple.Pair; |
|
31 |
import org.gvsig.tools.task.SimpleTaskStatus; |
|
32 |
import org.gvsig.tools.util.ListBuilder; |
|
33 |
|
|
34 |
/** |
|
35 |
* |
|
36 |
* @author fdiaz |
|
37 |
*/ |
|
38 |
public class PatchGeneratorTest01 extends TestCase { |
|
39 |
|
|
40 |
public static int OP_INSERT = 1; |
|
41 |
public static int OP_DELETE = 2; |
|
42 |
public static int OP_MODIFY = 3; |
|
43 |
public static int OP_CONFLICT = 4; |
|
44 |
|
|
45 |
public static class TestItem { |
|
46 |
|
|
47 |
private final int id; |
|
48 |
private final String content; |
|
49 |
private final int revision; |
|
50 |
|
|
51 |
public TestItem(int id, String content, int revision) { |
|
52 |
this.id = id; |
|
53 |
this.content = content; |
|
54 |
this.revision = revision; |
|
55 |
} |
|
56 |
|
|
57 |
public int getId() { |
|
58 |
return id; |
|
59 |
} |
|
60 |
|
|
61 |
public String getContent() { |
|
62 |
return content; |
|
63 |
} |
|
64 |
|
|
65 |
public int getRevision() { |
|
66 |
return revision; |
|
67 |
} |
|
68 |
|
|
69 |
@Override |
|
70 |
public boolean equals(Object obj) { |
|
71 |
if(!(obj instanceof TestItem)){ |
|
72 |
return false; |
|
73 |
} |
|
74 |
TestItem other = (TestItem)obj; |
|
75 |
if(other.hashCode() != this.hashCode()) { |
|
76 |
return false; |
|
77 |
} |
|
78 |
// if(id != other.getId()){ |
|
79 |
// return false; |
|
80 |
// } |
|
81 |
// if(!StringUtils.equals(content, other.getContent())){ |
|
82 |
// return false; |
|
83 |
// } |
|
84 |
// if(revision != other.getRevision()){ |
|
85 |
// return false; |
|
86 |
// } |
|
87 |
return true; |
|
88 |
} |
|
89 |
|
|
90 |
@Override |
|
91 |
public int hashCode() { |
|
92 |
int hash = 3; |
|
93 |
hash = 13 * hash + this.id; |
|
94 |
hash = 13 * hash + Objects.hashCode(this.content); |
|
95 |
hash = 13 * hash + this.revision; |
|
96 |
return hash; |
|
97 |
} |
|
98 |
|
|
99 |
|
|
100 |
|
|
101 |
} |
|
102 |
|
|
103 |
public static class TestPatchHandler implements PatchGeneratorImpl.PatchHandler<TestItem> { |
|
104 |
|
|
105 |
private final List<TestItem> localChanges; |
|
106 |
private final List<Pair<Integer,TestItem>> remoteChanges; |
|
107 |
|
|
108 |
public TestPatchHandler(List<TestItem> localChanges) { |
|
109 |
this.localChanges = localChanges; |
|
110 |
this.remoteChanges = new ArrayList<>(); |
|
111 |
} |
|
112 |
|
|
113 |
@Override |
|
114 |
public int compareId(TestItem r, TestItem l) { |
|
115 |
return Integer.compare(r.getId(), l.getId()); |
|
116 |
} |
|
117 |
|
|
118 |
@Override |
|
119 |
public boolean isNew(TestItem l) { |
|
120 |
return l.getId() < 0; |
|
121 |
} |
|
122 |
|
|
123 |
@Override |
|
124 |
public boolean isLocalChange(TestItem l) { |
|
125 |
return localChanges.contains(l); |
|
126 |
} |
|
127 |
|
|
128 |
@Override |
|
129 |
public boolean isRemoteChange(TestItem r, TestItem l) { |
|
130 |
return r.getRevision() != l.getRevision(); |
|
131 |
} |
|
132 |
|
|
133 |
@Override |
|
134 |
public void addRemoteChangeDelete(TestItem r, boolean conflict) { |
|
135 |
if(conflict){ |
|
136 |
this.remoteChanges.add(new ImmutablePair<>(OP_CONFLICT, r)); |
|
137 |
} else { |
|
138 |
this.remoteChanges.add(new ImmutablePair<>(OP_DELETE, r)); |
|
139 |
} |
|
140 |
} |
|
141 |
|
|
142 |
@Override |
|
143 |
public void addRemoteChangeModify(TestItem r, boolean conflict) { |
|
144 |
//FIXME: Ver que pasa con el conflicto |
|
145 |
if(conflict){ |
|
146 |
this.remoteChanges.add(new ImmutablePair<>(OP_CONFLICT, r)); |
|
147 |
} else { |
|
148 |
this.remoteChanges.add(new ImmutablePair<>(OP_MODIFY, r)); |
|
149 |
} |
|
150 |
} |
|
151 |
|
|
152 |
@Override |
|
153 |
public void addRemoteChangeInsert(TestItem r) { |
|
154 |
this.remoteChanges.add(new ImmutablePair<>(OP_INSERT, r)); |
|
155 |
} |
|
156 |
|
|
157 |
public List<Pair<Integer,TestItem>> getRemoteChanges() { |
|
158 |
return this.remoteChanges; |
|
159 |
} |
|
160 |
|
|
161 |
} |
|
162 |
|
|
163 |
public PatchGeneratorTest01(String testName) { |
|
164 |
super(testName); |
|
165 |
} |
|
166 |
|
|
167 |
public void test01RemoteDelete() { |
|
168 |
List<TestItem> localChanges = ListBuilder.create( |
|
169 |
); |
|
170 |
|
|
171 |
TestPatchHandler handler = new TestPatchHandler(localChanges); |
|
172 |
PatchGenerator patch = PatchGenerator.create(handler); |
|
173 |
|
|
174 |
List<TestItem> remote = ListBuilder.create( |
|
175 |
new TestItem(1, "A", 1), |
|
176 |
new TestItem(3, "C", 1), |
|
177 |
new TestItem(4, "D", 1) |
|
178 |
); |
|
179 |
List<TestItem> local = ListBuilder.create( |
|
180 |
new TestItem(1, "A", 1), |
|
181 |
new TestItem(2, "B", 1), |
|
182 |
new TestItem(3, "C", 1), |
|
183 |
new TestItem(4, "D", 1) |
|
184 |
); |
|
185 |
|
|
186 |
patch.generate(remote.iterator(), local.iterator(), SimpleTaskStatus.FAKE_STATUS); |
|
187 |
List<Pair<Integer, TestItem>> remoteChanges = handler.getRemoteChanges(); |
|
188 |
|
|
189 |
assertEquals(1, remoteChanges.size()); |
|
190 |
assertEquals(OP_DELETE, remoteChanges.get(0).getLeft().intValue()); |
|
191 |
assertEquals(2, remoteChanges.get(0).getRight().id); |
|
192 |
|
|
193 |
} |
|
194 |
|
|
195 |
public void test02LocalDelete() { |
|
196 |
List<TestItem> localChanges = ListBuilder.create( |
|
197 |
); |
|
198 |
|
|
199 |
TestPatchHandler handler = new TestPatchHandler(localChanges); |
|
200 |
PatchGenerator patch = PatchGenerator.create(handler); |
|
201 |
|
|
202 |
List<TestItem> remote = ListBuilder.create( |
|
203 |
new TestItem(1, "A", 1), |
|
204 |
new TestItem(2, "B", 1), |
|
205 |
new TestItem(3, "C", 1), |
|
206 |
new TestItem(4, "D", 1) |
|
207 |
); |
|
208 |
List<TestItem> local = ListBuilder.create( |
|
209 |
new TestItem(1, "A", 1), |
|
210 |
new TestItem(3, "C", 1), |
|
211 |
new TestItem(4, "D", 1) |
|
212 |
); |
|
213 |
|
|
214 |
patch.generate(remote.iterator(), local.iterator(), SimpleTaskStatus.FAKE_STATUS); |
|
215 |
List<Pair<Integer, TestItem>> remoteChanges = handler.getRemoteChanges(); |
|
216 |
|
|
217 |
assertEquals(0, remoteChanges.size()); |
|
218 |
|
|
219 |
} |
|
220 |
|
|
221 |
public void test03LocalNew() { |
|
222 |
List<TestItem> localChanges = ListBuilder.create( |
|
223 |
new TestItem(-1, "E", 1) |
|
224 |
); |
|
225 |
|
|
226 |
TestPatchHandler handler = new TestPatchHandler(localChanges); |
|
227 |
PatchGenerator patch = PatchGenerator.create(handler); |
|
228 |
|
|
229 |
List<TestItem> remote = ListBuilder.create( |
|
230 |
new TestItem(1, "A", 1), |
|
231 |
new TestItem(2, "B", 1), |
|
232 |
new TestItem(3, "C", 1), |
|
233 |
new TestItem(4, "D", 1) |
|
234 |
); |
|
235 |
List<TestItem> local = ListBuilder.create( |
|
236 |
new TestItem(1, "A", 1), |
|
237 |
new TestItem(3, "C", 1), |
|
238 |
new TestItem(4, "D", 1) |
|
239 |
); |
|
240 |
|
|
241 |
patch.generate(remote.iterator(), local.iterator(), SimpleTaskStatus.FAKE_STATUS); |
|
242 |
List<Pair<Integer, TestItem>> remoteChanges = handler.getRemoteChanges(); |
|
243 |
|
|
244 |
assertEquals(0, remoteChanges.size()); |
|
245 |
|
|
246 |
} |
|
247 |
|
|
248 |
public void test04RemoteModify() { |
|
249 |
List<TestItem> localChanges = ListBuilder.create( |
|
250 |
new TestItem(-1, "E", 1) |
|
251 |
); |
|
252 |
|
|
253 |
TestPatchHandler handler = new TestPatchHandler(localChanges); |
|
254 |
PatchGenerator patch = PatchGenerator.create(handler); |
|
255 |
|
|
256 |
List<TestItem> remote = ListBuilder.create( |
|
257 |
new TestItem(1, "A", 1), |
|
258 |
new TestItem(2, "B2", 2), |
|
259 |
new TestItem(3, "C", 1), |
|
260 |
new TestItem(4, "D", 1) |
|
261 |
); |
|
262 |
List<TestItem> local = ListBuilder.create( |
|
263 |
new TestItem(1, "A", 1), |
|
264 |
new TestItem(2, "B", 1), |
|
265 |
new TestItem(3, "C", 1), |
|
266 |
new TestItem(4, "D", 1) |
|
267 |
); |
|
268 |
|
|
269 |
patch.generate(remote.iterator(), local.iterator(), SimpleTaskStatus.FAKE_STATUS); |
|
270 |
List<Pair<Integer, TestItem>> remoteChanges = handler.getRemoteChanges(); |
|
271 |
|
|
272 |
assertEquals(1, remoteChanges.size()); |
|
273 |
assertEquals(OP_MODIFY, remoteChanges.get(0).getLeft().intValue()); |
|
274 |
assertEquals(2, remoteChanges.get(0).getRight().id); |
|
275 |
|
|
276 |
} |
|
277 |
|
|
278 |
public void test05Conflict() { |
|
279 |
List<TestItem> localChanges = ListBuilder.create( |
|
280 |
new TestItem(-1, "E", 1), |
|
281 |
new TestItem(2, "B3", 1) |
|
282 |
); |
|
283 |
|
|
284 |
TestPatchHandler handler = new TestPatchHandler(localChanges); |
|
285 |
PatchGenerator patch = PatchGenerator.create(handler); |
|
286 |
|
|
287 |
List<TestItem> remote = ListBuilder.create( |
|
288 |
new TestItem(1, "A", 1), |
|
289 |
new TestItem(2, "B2", 2), |
|
290 |
new TestItem(3, "C", 1), |
|
291 |
new TestItem(4, "D", 1) |
|
292 |
); |
|
293 |
List<TestItem> local = ListBuilder.create( |
|
294 |
new TestItem(1, "A", 1), |
|
295 |
new TestItem(2, "B3", 1), |
|
296 |
new TestItem(3, "C", 1), |
|
297 |
new TestItem(4, "D", 1) |
|
298 |
); |
|
299 |
|
|
300 |
patch.generate(remote.iterator(), local.iterator(), SimpleTaskStatus.FAKE_STATUS); |
|
301 |
List<Pair<Integer, TestItem>> remoteChanges = handler.getRemoteChanges(); |
|
302 |
|
|
303 |
assertEquals(1, remoteChanges.size()); |
|
304 |
assertEquals(OP_CONFLICT, remoteChanges.get(0).getLeft().intValue()); |
|
305 |
assertEquals(2, remoteChanges.get(0).getRight().id); |
|
306 |
|
|
307 |
} |
|
308 |
|
|
309 |
public void test06RemoteNew() { |
|
310 |
List<TestItem> localChanges = ListBuilder.create( |
|
311 |
new TestItem(-1, "E", 1) |
|
312 |
); |
|
313 |
|
|
314 |
TestPatchHandler handler = new TestPatchHandler(localChanges); |
|
315 |
PatchGenerator patch = PatchGenerator.create(handler); |
|
316 |
|
|
317 |
List<TestItem> remote = ListBuilder.create( |
|
318 |
new TestItem(1, "A", 1), |
|
319 |
new TestItem(2, "B", 1), |
|
320 |
new TestItem(3, "C", 1), |
|
321 |
new TestItem(4, "D", 1), |
|
322 |
new TestItem(5, "E", 1) |
|
323 |
); |
|
324 |
List<TestItem> local = ListBuilder.create( |
|
325 |
new TestItem(1, "A", 1), |
|
326 |
new TestItem(2, "B", 1), |
|
327 |
new TestItem(3, "C", 1), |
|
328 |
new TestItem(4, "D", 1) |
|
329 |
); |
|
330 |
|
|
331 |
patch.generate(remote.iterator(), local.iterator(), SimpleTaskStatus.FAKE_STATUS); |
|
332 |
List<Pair<Integer, TestItem>> remoteChanges = handler.getRemoteChanges(); |
|
333 |
|
|
334 |
assertEquals(1, remoteChanges.size()); |
|
335 |
assertEquals(OP_INSERT, remoteChanges.get(0).getLeft().intValue()); |
|
336 |
assertEquals(5, remoteChanges.get(0).getRight().id); |
|
337 |
|
|
338 |
} |
|
339 |
|
|
340 |
public void test07All() { |
|
341 |
List<TestItem> localChanges = ListBuilder.create( |
|
342 |
new TestItem(-1, "E", 1), |
|
343 |
new TestItem(4, "DD", 1) |
|
344 |
); |
|
345 |
|
|
346 |
TestPatchHandler handler = new TestPatchHandler(localChanges); |
|
347 |
PatchGenerator patch = PatchGenerator.create(handler); |
|
348 |
|
|
349 |
List<TestItem> remote = ListBuilder.create( |
|
350 |
new TestItem(2, "B", 1), |
|
351 |
new TestItem(3, "C2", 2), |
|
352 |
new TestItem(4, "D2", 2), |
|
353 |
new TestItem(5, "E", 1) |
|
354 |
); |
|
355 |
List<TestItem> local = ListBuilder.create( |
|
356 |
new TestItem(1, "A", 1), |
|
357 |
new TestItem(3, "C", 1), |
|
358 |
new TestItem(4, "DD", 1) |
|
359 |
); |
|
360 |
|
|
361 |
patch.generate(remote.iterator(), local.iterator(), SimpleTaskStatus.FAKE_STATUS); |
|
362 |
List<Pair<Integer, TestItem>> remoteChanges = handler.getRemoteChanges(); |
|
363 |
|
|
364 |
assertEquals(4, remoteChanges.size()); |
|
365 |
|
|
366 |
assertEquals(OP_DELETE, remoteChanges.get(0).getLeft().intValue()); |
|
367 |
assertEquals(1, remoteChanges.get(0).getRight().id); |
|
368 |
|
|
369 |
assertEquals(OP_MODIFY, remoteChanges.get(1).getLeft().intValue()); |
|
370 |
assertEquals(3, remoteChanges.get(1).getRight().id); |
|
371 |
|
|
372 |
assertEquals(OP_CONFLICT, remoteChanges.get(2).getLeft().intValue()); |
|
373 |
assertEquals(4, remoteChanges.get(2).getRight().id); |
|
374 |
|
|
375 |
assertEquals(OP_INSERT, remoteChanges.get(3).getLeft().intValue()); |
|
376 |
assertEquals(5, remoteChanges.get(3).getRight().id); |
|
377 |
|
|
378 |
} |
|
379 |
|
|
380 |
} |
org.gvsig.online/trunk/org.gvsig.online/org.gvsig.online.lib/org.gvsig.online.lib.impl/src/main/java/org/gvsig/tools/patch/PatchGeneratorImpl.java | ||
---|---|---|
1 |
/* gvSIG. Desktop Geographic Information System. |
|
2 |
* |
|
3 |
* Copyright (c) 2007-2024 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.tools.patch; |
|
24 |
|
|
25 |
import java.util.Iterator; |
|
26 |
import org.gvsig.tools.ToolsLocator; |
|
27 |
import org.gvsig.tools.i18n.I18nManager; |
|
28 |
import org.gvsig.tools.task.SimpleTaskStatus; |
|
29 |
import org.gvsig.tools.task.UserCancelTaskException; |
|
30 |
import org.slf4j.Logger; |
|
31 |
import org.slf4j.LoggerFactory; |
|
32 |
|
|
33 |
/** |
|
34 |
* |
|
35 |
* @author fdiaz |
|
36 |
*/ |
|
37 |
class PatchGeneratorImpl<T> implements PatchGenerator<T> { |
|
38 |
|
|
39 |
public static final Logger LOGGER = LoggerFactory.getLogger(PatchGeneratorImpl.class); |
|
40 |
|
|
41 |
private final PatchHandler handler; |
|
42 |
|
|
43 |
PatchGeneratorImpl(PatchHandler handler) { |
|
44 |
this.handler = handler; |
|
45 |
} |
|
46 |
|
|
47 |
@Override |
|
48 |
public void generate(Iterator<T> r, Iterator<T> l, SimpleTaskStatus status) { |
|
49 |
I18nManager i18n = ToolsLocator.getI18nManager(); |
|
50 |
if (status == null) { |
|
51 |
status = ToolsLocator.getTaskStatusManager().createDefaultSimpleTaskStatus(i18n.getTranslation("_Generating_patch")); |
|
52 |
status.setAutoremove(true); |
|
53 |
status.add(); |
|
54 |
} else { |
|
55 |
status.push(); |
|
56 |
} |
|
57 |
|
|
58 |
try { |
|
59 |
T remoteItem = null; |
|
60 |
T localItem = null; |
|
61 |
|
|
62 |
if (r.hasNext()) { |
|
63 |
remoteItem = r.next(); |
|
64 |
} |
|
65 |
if (l.hasNext()) { |
|
66 |
localItem = l.next(); |
|
67 |
} |
|
68 |
|
|
69 |
while (true) { |
|
70 |
if (status.isCancellationRequested()) { |
|
71 |
throw new UserCancelTaskException(); |
|
72 |
} |
|
73 |
if (localItem == null) { |
|
74 |
if (remoteItem == null) { |
|
75 |
break; |
|
76 |
} else { |
|
77 |
//nuevo en REMOTO |
|
78 |
handler.addRemoteChangeInsert(remoteItem); |
|
79 |
if (r.hasNext()) { |
|
80 |
remoteItem = r.next(); |
|
81 |
} else { |
|
82 |
remoteItem = null; |
|
83 |
} |
|
84 |
} |
|
85 |
} else if (handler.isNew(localItem)) { |
|
86 |
//nuevo en LOCAL, do nothing |
|
87 |
if (l.hasNext()) { |
|
88 |
localItem = l.next(); |
|
89 |
} else { |
|
90 |
localItem = null; |
|
91 |
} |
|
92 |
} else if (remoteItem == null || (remoteItem != null && handler.compareId(remoteItem, localItem) > 0)) { |
|
93 |
//Hay un borrado remoto, |
|
94 |
if (handler.isLocalChange(localItem)) { |
|
95 |
handler.addRemoteChangeDelete(localItem, true); |
|
96 |
} else { |
|
97 |
handler.addRemoteChangeDelete(localItem, false); |
|
98 |
} |
|
99 |
if (l.hasNext()) { |
|
100 |
localItem = l.next(); |
|
101 |
} else { |
|
102 |
localItem = null; |
|
103 |
} |
|
104 |
} else if (remoteItem != null && handler.compareId(remoteItem, localItem) < 0) { |
|
105 |
//Hay un borrado local o un insert remoto |
|
106 |
if (handler.isLocalChange(remoteItem)) { |
|
107 |
//Do nothing |
|
108 |
} else { |
|
109 |
handler.addRemoteChangeInsert(remoteItem); |
|
110 |
} |
|
111 |
|
|
112 |
if (r.hasNext()) { |
|
113 |
remoteItem = r.next(); |
|
114 |
} else { |
|
115 |
remoteItem = null; |
|
116 |
} |
|
117 |
} else if (remoteItem != null) { // && handler.compare(remoteItem, localItem)!=0) { //same element, but changed |
|
118 |
if (handler.isLocalChange(localItem)) { |
|
119 |
if (handler.isRemoteChange(remoteItem, localItem)) { |
|
120 |
//conflicto |
|
121 |
handler.addRemoteChangeModify(remoteItem, true); |
|
122 |
} else { |
|
123 |
//Hay modificaci?n local, do nothing |
|
124 |
} |
|
125 |
} else { |
|
126 |
if (handler.isRemoteChange(remoteItem, localItem)) { |
|
127 |
//cambio remoto sin conflicto |
|
128 |
handler.addRemoteChangeModify(remoteItem, false); |
|
129 |
} else { |
|
130 |
//No es modificacion ni en local ni en remoto, no ha cambios. Do nothing |
|
131 |
} |
|
132 |
} |
|
133 |
if (l.hasNext()) { |
|
134 |
localItem = l.next(); |
|
135 |
} else { |
|
136 |
localItem = null; |
|
137 |
} |
|
138 |
if (r.hasNext()) { |
|
139 |
remoteItem = r.next(); |
|
140 |
} else { |
|
141 |
remoteItem = null; |
|
142 |
} |
|
143 |
} else { |
|
144 |
if (l.hasNext()) { |
|
145 |
localItem = l.next(); |
|
146 |
} else { |
|
147 |
localItem = null; |
|
148 |
} |
|
149 |
if (r.hasNext()) { |
|
150 |
remoteItem = r.next(); |
|
151 |
} else { |
|
152 |
remoteItem = null; |
|
153 |
} |
|
154 |
|
|
155 |
} |
|
156 |
} |
|
157 |
status.terminate(); |
|
158 |
} catch (UserCancelTaskException ex) { |
|
159 |
status.cancel(); |
|
160 |
throw ex; |
|
161 |
} catch (Exception ex) { |
|
162 |
status.abort(); |
|
163 |
throw ex; |
|
164 |
} finally { |
|
165 |
status.pop(); |
|
166 |
} |
|
167 |
} |
|
168 |
|
|
169 |
} |
org.gvsig.online/trunk/org.gvsig.online/org.gvsig.online.lib/org.gvsig.online.lib.impl/src/main/java/org/gvsig/tools/patch/PatchGenerator.java | ||
---|---|---|
1 |
/* gvSIG. Desktop Geographic Information System. |
|
2 |
* |
|
3 |
* Copyright (c) 2007-2024 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.tools.patch; |
|
24 |
|
|
25 |
import java.util.Iterator; |
|
26 |
import org.gvsig.tools.task.SimpleTaskStatus; |
|
27 |
|
|
28 |
/** |
|
29 |
* |
|
30 |
* @author fdiaz |
|
31 |
*/ |
|
32 |
public interface PatchGenerator<T> { |
|
33 |
|
|
34 |
public static PatchGenerator create(PatchHandler handler) { |
|
35 |
return new PatchGeneratorImpl(handler); |
|
36 |
} |
|
37 |
|
|
38 |
void generate(Iterator<T> r, Iterator<T> l, SimpleTaskStatus status); |
|
39 |
|
|
40 |
public interface PatchHandler<T> { |
|
41 |
|
|
42 |
public int compareId(T r, T l); |
|
43 |
|
|
44 |
public boolean isNew(T l); |
|
45 |
|
|
46 |
public boolean isLocalChange(T l); |
|
47 |
|
|
48 |
public boolean isRemoteChange(T r, T l); |
|
49 |
|
|
50 |
public void addRemoteChangeDelete(T r, boolean conflict); |
|
51 |
|
|
52 |
public void addRemoteChangeModify(T r, boolean conflict); |
|
53 |
|
|
54 |
public void addRemoteChangeInsert(T r); |
|
55 |
|
|
56 |
} |
|
57 |
|
|
58 |
} |
org.gvsig.online/trunk/org.gvsig.online/org.gvsig.online.lib/org.gvsig.online.lib.impl/src/main/java/org/gvsig/online/lib/impl/PatchGenerator.java | ||
---|---|---|
1 |
/* gvSIG. Desktop Geographic Information System. |
|
2 |
* |
|
3 |
* Copyright (c) 2007-2024 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.online.lib.impl; |
|
24 |
|
|
25 |
import java.util.Iterator; |
|
26 |
import org.gvsig.tools.ToolsLocator; |
|
27 |
import org.gvsig.tools.i18n.I18nManager; |
|
28 |
import org.gvsig.tools.task.SimpleTaskStatus; |
|
29 |
import org.gvsig.tools.task.UserCancelTaskException; |
|
30 |
|
|
31 |
/** |
|
32 |
* |
|
33 |
* @author fdiaz |
|
34 |
*/ |
|
35 |
public class PatchGenerator<T> { |
|
36 |
|
|
37 |
private final PatchHandler handler; |
|
38 |
|
|
39 |
public PatchGenerator(PatchHandler handler) { |
|
40 |
this.handler = handler; |
|
41 |
} |
|
42 |
|
|
43 |
public void generate(Iterator<T> r, Iterator<T> l, SimpleTaskStatus status) { |
|
44 |
I18nManager i18n = ToolsLocator.getI18nManager(); |
|
45 |
if (status == null) { |
|
46 |
status = ToolsLocator.getTaskStatusManager().createDefaultSimpleTaskStatus(i18n.getTranslation("_Generating_patch")); |
|
47 |
status.setAutoremove(true); |
|
48 |
status.add(); |
|
49 |
} else { |
|
50 |
status.push(); |
|
51 |
} |
|
52 |
|
|
53 |
try { |
|
54 |
|
|
55 |
T remoteItem = r.next(); |
|
56 |
T localItem = l.next(); |
|
57 |
|
|
58 |
while (true) { |
|
59 |
if (status.isCancellationRequested()) { |
|
60 |
throw new UserCancelTaskException(); |
|
61 |
} |
|
62 |
if (localItem == null) { |
|
63 |
if (remoteItem == null) { |
|
64 |
break; |
|
65 |
} else { |
|
66 |
//nuevo en REMOTO |
|
67 |
handler.addRemoteChangeInsert(remoteItem); |
|
68 |
if (r.hasNext()) { |
|
69 |
remoteItem = r.next(); |
|
70 |
} else { |
|
71 |
remoteItem = null; |
|
72 |
} |
|
73 |
} |
|
74 |
} else if (handler.isNew(localItem)) { |
|
75 |
//TODO: nuevo en LOCAL, do nothing? |
|
76 |
if (l.hasNext()) { |
|
77 |
localItem = l.next(); |
|
78 |
} else { |
|
79 |
localItem = null; |
|
80 |
} |
|
81 |
} else if (handler.compareId(remoteItem, localItem) > 0) { |
|
82 |
//Hay un borrado remoto, |
|
83 |
handler.addRemoteChangeDelete(localItem); |
|
84 |
if (l.hasNext()) { |
|
85 |
localItem = l.next(); |
|
86 |
} else { |
|
87 |
localItem = null; |
|
88 |
} |
|
89 |
} else if (handler.compareId(remoteItem, localItem) < 0) { |
|
90 |
//TODO: Hay un borrado local, do nothing? |
|
91 |
if (r.hasNext()) { |
|
92 |
remoteItem = r.next(); |
|
93 |
} else { |
|
94 |
remoteItem = null; |
|
95 |
} |
|
96 |
} else if (!localItem.equals(remoteItem)) { //same element, but changed |
|
97 |
if (handler.isLocalChange(localItem)) { |
|
98 |
if (handler.isRemoteChange(remoteItem, localItem)) { |
|
99 |
//conflicto |
|
100 |
handler.addRemoteChangeModify(remoteItem, true); |
|
101 |
} else { |
|
102 |
//TODO: Hay modificaci?n local, do nothing? |
|
103 |
} |
|
104 |
} else { |
|
105 |
if (handler.isRemoteChange(remoteItem, localItem)) { |
|
106 |
//cambio remoto sin conflicto |
|
107 |
handler.addRemoteChangeModify(remoteItem, false); |
|
108 |
} else { |
|
109 |
//TODO: Hay modificaci?n local, do nothing? |
|
110 |
} |
|
111 |
} |
|
112 |
if (l.hasNext()) { |
|
113 |
localItem = l.next(); |
|
114 |
} else { |
|
115 |
localItem = null; |
|
116 |
} |
|
117 |
if (r.hasNext()) { |
|
118 |
remoteItem = r.next(); |
|
119 |
} else { |
|
120 |
remoteItem = null; |
|
121 |
} |
|
122 |
} else { |
|
123 |
if (l.hasNext()) { |
|
124 |
localItem = l.next(); |
|
125 |
} else { |
|
126 |
localItem = null; |
|
127 |
} |
|
128 |
if (r.hasNext()) { |
|
129 |
remoteItem = r.next(); |
|
130 |
} else { |
|
131 |
remoteItem = null; |
|
132 |
} |
|
133 |
|
|
134 |
} |
|
135 |
} |
|
136 |
status.terminate(); |
|
137 |
} catch (UserCancelTaskException ex) { |
|
138 |
status.cancel(); |
|
139 |
throw ex; |
|
140 |
} catch (Exception ex) { |
|
141 |
status.abort(); |
|
142 |
throw ex; |
|
143 |
} finally { |
|
144 |
status.pop(); |
|
145 |
} |
|
146 |
} |
|
147 |
|
|
148 |
public interface PatchHandler<T> { |
|
149 |
|
|
150 |
public int compareId(T r, T l); |
|
151 |
|
|
152 |
public boolean isNew(T l); |
|
153 |
|
|
154 |
public boolean isLocalChange(T l); |
|
155 |
|
|
156 |
public boolean isRemoteChange(T r, T l); |
|
157 |
|
|
158 |
public void addRemoteChangeDelete(T r); |
|
159 |
|
|
160 |
public void addRemoteChangeModify(T r, boolean conflict); |
|
161 |
|
|
162 |
public void addRemoteChangeInsert(T r); |
|
163 |
|
|
164 |
} |
|
165 |
} |
org.gvsig.online/trunk/org.gvsig.online/org.gvsig.online.lib/org.gvsig.online.lib.impl/src/main/java/org/gvsig/online/lib/impl/TilesCalculator.java | ||
---|---|---|
261 | 261 |
private List<Cell> calculateCells(int cellSize, Iterator<Geometry> geoms) { |
262 | 262 |
Set<Cell> cells = new HashSet<>(); |
263 | 263 |
|
264 |
while(geoms.hasNext()){ |
|
265 |
cells.addAll(calculateCell(cellSize, geoms.next())); |
|
264 |
while (geoms.hasNext()) { |
|
265 |
Geometry g = geoms.next(); |
|
266 |
if (g != null) { |
|
267 |
cells.addAll(calculateCell(cellSize, g)); |
|
268 |
} |
|
266 | 269 |
} |
267 | 270 |
List<Cell> orderedCells = new ArrayList<>(cells); |
268 | 271 |
Collections.sort(orderedCells); |
org.gvsig.online/trunk/org.gvsig.online/org.gvsig.online.lib/org.gvsig.online.lib.impl/src/main/java/org/gvsig/online/lib/impl/workspace/FeatureStoreObserver.java | ||
---|---|---|
43 | 43 |
import org.gvsig.tools.dynobject.Tags; |
44 | 44 |
import org.gvsig.tools.observer.Observable; |
45 | 45 |
import org.gvsig.tools.observer.Observer; |
46 |
//import org.gvsig.vcsgis.lib.OnlineLocator; |
|
47 |
//import org.gvsig.vcsgis.lib.OnlineManager; |
|
48 |
//import static org.gvsig.vcsgis.lib.OnlineManager.ERR_NO_ERROR; |
|
49 |
//import static org.gvsig.vcsgis.lib.OnlineManager.FEATURECODE_FIELD_NAME; |
|
50 |
//import static org.gvsig.vcsgis.lib.OnlineManager.OP_DELETE; |
|
51 |
//import static org.gvsig.vcsgis.lib.OnlineManager.OP_INSERT; |
|
52 |
//import static org.gvsig.vcsgis.lib.OnlineManager.OP_UPDATE; |
|
53 |
//import static org.gvsig.vcsgis.lib.OnlineManager.TAG_VCSGIS_CATEGORY; |
|
54 |
//import static org.gvsig.vcsgis.lib.OnlineManager.TAG_VCSGIS_DATAMODEL; |
|
55 |
//import static org.gvsig.vcsgis.lib.OnlineManager.TAG_VCSGIS_FIELDFORLABEL; |
|
56 |
//import static org.gvsig.vcsgis.lib.OnlineManager.TAG_VCSGIS_LABEL; |
|
57 |
//import static org.gvsig.vcsgis.lib.OnlineManager.TAG_VCSGIS_RESOURCES; |
|
58 |
//import static org.gvsig.vcsgis.lib.OnlineManager.TAG_VCSGIS_TABLENAME; |
|
59 |
//import org.gvsig.vcsgis.lib.workspace.tables.EntitiesTable; |
|
60 | 46 |
import org.slf4j.Logger; |
61 | 47 |
import org.slf4j.LoggerFactory; |
62 | 48 |
|
... | ... | |
98 | 84 |
if (workspace != null) { |
99 | 85 |
Feature feature = n.getFeature(); |
100 | 86 |
if (StringUtils.isBlank(feature.getString(FEATURECODE_FIELD_NAME)) && feature instanceof EditableFeature) { |
101 |
((EditableFeature)feature).set(FEATURECODE_FIELD_NAME, workspace.createUniqueCodeLong()); |
|
87 |
((EditableFeature)feature).set(FEATURECODE_FIELD_NAME, workspace.createUniqueCodeLong(store.getName()));
|
|
102 | 88 |
((EditableFeature)feature).set(FEATUREDATE_FIELD_NAME, new Timestamp(System.currentTimeMillis())); |
103 | 89 |
((EditableFeature)feature).set(OnlineManager.FEATURELASTMODIFICATION_FIELD_NAME, new Timestamp(System.currentTimeMillis())); |
104 | 90 |
((EditableFeature)feature).set(FEATUREVERSION_FIELD_NAME, 0); |
... | ... | |
153 | 139 |
if (workspace != null) { |
154 | 140 |
EditableFeature feature = (EditableFeature) n.getFeature(); |
155 | 141 |
if (StringUtils.isBlank(feature.getString(FEATURECODE_FIELD_NAME))) { |
156 |
feature.set(FEATURECODE_FIELD_NAME, workspace.createUniqueCodeLong()); |
|
142 |
feature.set(FEATURECODE_FIELD_NAME, workspace.createUniqueCodeLong(store.getName()));
|
|
157 | 143 |
((EditableFeature)feature).set(FEATUREDATE_FIELD_NAME, new Timestamp(System.currentTimeMillis())); |
158 | 144 |
((EditableFeature)feature).set(FEATUREVERSION_FIELD_NAME, 0); |
159 | 145 |
} |
org.gvsig.online/trunk/org.gvsig.online/org.gvsig.online.lib/org.gvsig.online.lib.impl/src/main/java/org/gvsig/online/lib/impl/workspace/OnlineWorkspaceImpl.java | ||
---|---|---|
19 | 19 |
import java.util.List; |
20 | 20 |
import java.util.Map; |
21 | 21 |
import java.util.Set; |
22 |
import java.util.logging.Level; |
|
22 | 23 |
import javax.json.JsonArray; |
23 | 24 |
import javax.json.JsonObject; |
24 | 25 |
import javax.json.JsonValue; |
... | ... | |
34 | 35 |
import org.gvsig.expressionevaluator.ExpressionEvaluatorLocator; |
35 | 36 |
import org.gvsig.expressionevaluator.ExpressionEvaluatorManager; |
36 | 37 |
import org.gvsig.expressionevaluator.ExpressionUtils; |
38 |
import org.gvsig.expressionevaluator.GeometryExpressionBuilder; |
|
37 | 39 |
import org.gvsig.fmap.dal.DALLocator; |
38 | 40 |
import org.gvsig.fmap.dal.DataManager; |
39 | 41 |
import org.gvsig.fmap.dal.DataServerExplorer; |
... | ... | |
53 | 55 |
import org.gvsig.fmap.dal.feature.EditableFeatureType; |
54 | 56 |
import org.gvsig.fmap.dal.feature.Feature; |
55 | 57 |
import org.gvsig.fmap.dal.feature.FeatureAttributeDescriptor; |
58 |
import org.gvsig.fmap.dal.feature.FeatureQuery; |
|
56 | 59 |
import org.gvsig.fmap.dal.feature.FeatureReference; |
57 | 60 |
import org.gvsig.fmap.dal.feature.FeatureSet; |
58 | 61 |
import org.gvsig.fmap.dal.feature.FeatureStore; |
... | ... | |
66 | 69 |
import org.gvsig.fmap.dal.store.jdbc.JDBCStoreParameters; |
67 | 70 |
import org.gvsig.fmap.dal.store.jdbc2.JDBCServerExplorer; |
68 | 71 |
import org.gvsig.fmap.geom.Geometry; |
72 |
import org.gvsig.fmap.geom.GeometryException; |
|
69 | 73 |
import org.gvsig.fmap.geom.GeometryLocator; |
70 | 74 |
import org.gvsig.fmap.geom.GeometryManager; |
71 | 75 |
import org.gvsig.fmap.geom.primitive.Envelope; |
72 | 76 |
import org.gvsig.json.Json; |
77 |
import org.gvsig.json.JsonObjectBuilder; |
|
73 | 78 |
import org.gvsig.online.lib.api.OnlineCodeGenerator; |
74 | 79 |
import org.gvsig.online.lib.api.OnlineDownloader; |
75 | 80 |
import org.gvsig.online.lib.api.OnlineLayer; |
... | ... | |
122 | 127 |
import org.gvsig.online.lib.api.workingcopy.OnlineRemoteChange; |
123 | 128 |
import org.gvsig.online.lib.api.workingcopy.OnlineWorkingcopy; |
124 | 129 |
import org.gvsig.online.lib.api.workingcopy.OnlineWorkingcopyChange; |
125 |
import org.gvsig.online.lib.api.workingcopy.OnlineWorkingcopyChanges;
|
|
130 |
import org.gvsig.online.lib.api.workingcopy.WorkingArea;
|
|
126 | 131 |
import static org.gvsig.online.lib.impl.OnlineManagerImpl.INTERNAL_WORKSPACE_TABLES; |
127 | 132 |
import org.gvsig.online.lib.impl.OnlineProjectImpl; |
128 | 133 |
import org.gvsig.online.lib.impl.OnlineSiteImpl; |
129 | 134 |
import org.gvsig.online.lib.impl.OnlineUtils; |
130 |
import org.gvsig.online.lib.impl.PatchGenerator; |
|
131 | 135 |
import org.gvsig.online.lib.impl.TilesCalculator; |
132 | 136 |
import org.gvsig.online.lib.impl.workspace.tables.EntitiesTable; |
133 | 137 |
import org.gvsig.online.lib.impl.workspace.tables.EntitiesTable.EntityRow; |
... | ... | |
149 | 153 |
import org.gvsig.tools.observer.Notification; |
150 | 154 |
import org.gvsig.tools.observer.Observable; |
151 | 155 |
import org.gvsig.tools.observer.Observer; |
156 |
import org.gvsig.tools.patch.PatchGenerator; |
|
152 | 157 |
import org.gvsig.tools.resourcesstorage.ResourcesStorage; |
153 | 158 |
import org.gvsig.tools.swing.api.ChangeListenerHelper; |
154 | 159 |
import org.gvsig.tools.swing.api.ToolsSwingLocator; |
... | ... | |
160 | 165 |
import org.gvsig.tools.util.Rewind; |
161 | 166 |
import org.slf4j.Logger; |
162 | 167 |
import org.slf4j.LoggerFactory; |
168 |
import org.gvsig.online.lib.api.workingcopy.OnlineChanges; |
|
163 | 169 |
|
164 | 170 |
/** |
165 | 171 |
* |
... | ... | |
179 | 185 |
// public static final String CONFIG_REPOSITORY_ENTITY_CACHE_TIME_NAME = "REPOSITORY_ENTITY_CACHE_TIME"; |
180 | 186 |
public static final String CONFIG_OFFLINE = "OFFLINE"; |
181 | 187 |
public static final String CONFIG_ENTITY_LABEL_TEMPLATE = "ENTITY_LABEL_TEMPLATE"; |
188 |
public static final String CONFIG_CURRENT_WORKINGAREA = "CURRENT_WORKINGAREA"; |
|
182 | 189 |
// public static final String CONFIG_USE_SAFE_MODE = "USE_SAFE_MODE"; |
183 | 190 |
|
184 | 191 |
private final Map<String, FeatureStore> storesCache; |
... | ... | |
202 | 209 |
private String entityLabelTemplate; |
203 | 210 |
private boolean disposed = false; |
204 | 211 |
private Observer changeUserObserver; |
212 |
private WorkingArea currentWorkingArea; |
|
205 | 213 |
|
206 | 214 |
public OnlineWorkspaceImpl(JDBCServerExplorer wsexplorer, OnlineCodeGenerator codeGenerator, OnlineProject project, String label) { |
207 | 215 |
// Usado en la inicializacion del workspace |
... | ... | |
250 | 258 |
CONFIG_WORKSPACE_LABEL_NAME, |
251 | 259 |
CONFIG_OFFLINE, |
252 | 260 |
// CONFIG_USE_SAFE_MODE, |
253 |
CONFIG_ENTITY_LABEL_TEMPLATE |
|
261 |
CONFIG_ENTITY_LABEL_TEMPLATE, |
|
262 |
CONFIG_CURRENT_WORKINGAREA |
|
254 | 263 |
); |
255 | 264 |
this.code = vars.get(CONFIG_WORKSPACE_CODE_NAME); |
256 | 265 |
if (this.code == null) { |
... | ... | |
268 | 277 |
if (this.project == null) { |
269 | 278 |
throw new RuntimeException("Can't retrieve repository from workspace '" + this.getMessageLabel() + "'"); |
270 | 279 |
} |
280 |
this.currentWorkingArea = (WorkingAreaImpl) Json.toObject(vars.get(CONFIG_CURRENT_WORKINGAREA)); |
|
271 | 281 |
this.setCurrentUserCode(this.project, vars.get(CONFIG_USER_NAME)); |
272 | 282 |
this.setAuthenticationToken(this.project, vars.get(CONFIG_AUTHENTICATIONTOKEN_NAME)); |
273 | 283 |
this.label = vars.get(CONFIG_WORKSPACE_LABEL_NAME); |
274 | 284 |
this.changeUserObserver = createChangeUserObserver(); |
275 | 285 |
|
286 |
// this.refreshCodeGeneratorSequence(); |
|
287 |
|
|
276 | 288 |
// LOGGER.debug("===: CREATE WORKSPACE "+ hexId(this)+ " (open code='"+this.code+"', label='"+this.label+"')"); |
277 | 289 |
} |
278 | 290 |
|
... | ... | |
308 | 320 |
return this.codeGenerator.generateCodeString(); |
309 | 321 |
} |
310 | 322 |
|
311 |
public final long createUniqueCodeLong() { |
|
312 |
return this.codeGenerator.generateCodelong(); |
|
323 |
public final long createUniqueCodeLong(String entityName) { |
|
324 |
if(!this.codeGenerator.isInitialized(entityName)){ |
|
325 |
this.refreshCodeGeneratorSequence(entityName); |
|
326 |
} |
|
327 |
return this.codeGenerator.generateCodelong(entityName); |
|
328 |
|
|
313 | 329 |
} |
314 | 330 |
|
315 | 331 |
@Override |
... | ... | |
913 | 929 |
entity.setCRS(crs); |
914 | 930 |
} |
915 | 931 |
} |
916 |
entity.setState(STATE_LOCAL_NEW);
|
|
932 |
entity.setState(STATE_LOCAL_UNMODIFIED);
|
|
917 | 933 |
entity.insert(); |
918 | 934 |
addWorkspaceEntity(entity); |
919 | 935 |
|
... | ... | |
1180 | 1196 |
} |
1181 | 1197 |
} |
1182 | 1198 |
try { |
1199 |
Feature previousChange = null; |
|
1183 | 1200 |
long featureCode = feature.getLong(entity.getFeatureIdFieldName()); |
1184 | 1201 |
Integer previousOperation = null; |
1185 | 1202 |
if (previousOperations != null) { |
1186 | 1203 |
previousOperation = previousOperations.get(featureCode); |
1187 | 1204 |
} else { |
1188 |
Feature previousChange = changesStore.findFirst(WorkspaceChangesTable.FEATUREID + " = '" + featureCode + "'"); // and " + WorkspaceChangesTable.OPERATION+ " = " + operation);
|
|
1205 |
previousChange = changesStore.findFirst(WorkspaceChangesTable.FEATUREID + " = '" + featureCode + "'"); // and " + WorkspaceChangesTable.OPERATION+ " = " + operation); |
|
1189 | 1206 |
if (previousChange != null) { |
1190 | 1207 |
previousOperation = previousChange.getInt(WorkspaceChangesTable.OPERATION); |
1191 | 1208 |
} |
... | ... | |
1211 | 1228 |
switch (previousOperation) { |
1212 | 1229 |
case OP_INSERT: |
1213 | 1230 |
case OP_UPDATE: |
1231 |
//TODO: Migrar a VCSGIS |
|
1232 |
if(previousChange != null ) { |
|
1233 |
WorkspaceChangeRow change = new WorkspaceChangeRow(this, previousChange); |
|
1234 |
if(change.getStatus() == STATE_CONFLICT){ |
|
1235 |
change.setStatus(STATE_LOCAL_MODIFIED); |
|
1236 |
change.update(changesStore); |
|
1237 |
} |
|
1238 |
} |
|
1214 | 1239 |
return ERR_OK; |
1215 | 1240 |
case OP_DELETE: |
1216 | 1241 |
LOGGER.warn("A update change cannot be added as there is a previous change with operation delete (featureCode=" + featureCode + ")"); |
... | ... | |
1533 | 1558 |
} |
1534 | 1559 |
|
1535 | 1560 |
@Override |
1536 |
public OnlineWorkingcopyChanges<OnlineWorkingcopyChange> getLocalChanges() {
|
|
1561 |
public OnlineChanges<OnlineWorkingcopyChange> getLocalChanges() { |
|
1537 | 1562 |
return getLocalChanges(null); |
1538 | 1563 |
} |
1539 | 1564 |
|
1540 | 1565 |
@Override |
1541 |
public OnlineWorkingcopyChanges<OnlineWorkingcopyChange> getLocalChanges(List<OnlineEntity> entities) {
|
|
1566 |
public OnlineChanges<OnlineWorkingcopyChange> getLocalChanges(List<OnlineEntity> entities) { |
|
1542 | 1567 |
WorkspaceChangesTable changesTable = new WorkspaceChangesTable(); |
1543 | 1568 |
ChangesImpl changes = new ChangesImpl<WorkspaceChangeRow>(changesTable.getByEntityCode(this, entities), WorkspaceChangesTable.SELECTED) { |
1544 | 1569 |
@Override |
... | ... | |
2085 | 2110 |
} |
2086 | 2111 |
|
2087 | 2112 |
@Override |
2088 |
public OnlineWorkingcopyChanges<OnlineRemoteChange> getRemoteChanges() {
|
|
2113 |
public OnlineChanges<OnlineRemoteChange> getRemoteChanges() { |
|
2089 | 2114 |
return getRemoteChangesByEntity((String) null); |
2090 | 2115 |
} |
2091 | 2116 |
|
2092 | 2117 |
@Override |
2093 |
public OnlineWorkingcopyChanges<OnlineRemoteChange> getRemoteChangesByEntity(String... entityNames) {
|
|
2118 |
public OnlineChanges<OnlineRemoteChange> getRemoteChangesByEntity(String... entityNames) { |
|
2094 | 2119 |
String[] entityCodes = null; |
2095 | 2120 |
if (ArrayUtils.isNotEmpty(entityNames)) { |
2096 | 2121 |
entityCodes = new String[entityNames.length]; |
... | ... | |
2408 | 2433 |
this.addStoreIgnoreChanges(store); |
2409 | 2434 |
store.edit(FeatureStore.MODE_APPEND, FeatureStore.SUBMODE_MERGE); |
2410 | 2435 |
GeometryManager geomManager = GeometryLocator.getGeometryManager(); |
2436 |
IProjection layerProjection = layer.getProjection(); |
|
2437 |
String geometryName = store.getDefaultFeatureTypeQuietly().getDefaultGeometryAttributeName(); |
|
2411 | 2438 |
int nenv = 0; |
2412 | 2439 |
for (Envelope env : envs) { |
2413 | 2440 |
nenv++; |
... | ... | |
2417 | 2444 |
status.cancel(); |
2418 | 2445 |
throw new UserCancelTaskException(); |
2419 | 2446 |
} |
2420 |
JsonObject feature_json = it.next(); |
|
2421 |
EditableFeature feature = null; |
|
2422 |
Geometry geom = null; |
|
2423 |
JsonObject properties = feature_json.getJsonObject("properties"); |
|
2424 |
JsonObject geom_json = feature_json.getJsonObject("geometry"); |
|
2425 |
if( geom_json!=null ) { |
|
2426 |
geom = geomManager.createFrom(geom_json); |
|
2427 |
if( geom.getProjection()==null ) { |
|
2428 |
geom.setProjection(layer.getProjection()); |
|
2429 |
} |
|
2447 |
JsonObject feature_online_json = it.next(); |
|
2448 |
JsonObject feature_desktop_json = convertOnlineToDesktopFeature(feature_online_json, geometryName, geomManager, layerProjection); |
|
2449 |
if(feature_desktop_json == null){ |
|
2450 |
continue; |
|
2430 | 2451 |
} |
2431 |
if( properties==null ) { |
|
2432 |
if( geom == null ) { |
|
2433 |
continue; |
|
2434 |
} |
|
2435 |
feature = store.createNewFeature(); |
|
2436 |
} else { |
|
2437 |
feature = store.createNewFeature(properties); |
|
2438 |
} |
|
2439 |
feature.setDefaultGeometry(geom); |
|
2440 |
store.insert(feature); // Insert or replace |
|
2452 |
EditableFeature feature = store.createNewFeature(feature_desktop_json); |
|
2453 |
store.insert(feature); |
|
2454 |
// |
|
2455 |
// EditableFeature feature = null; |
|
2456 |
// Geometry geom = null; |
|
2457 |
// JsonObject properties = feature_json.getJsonObject("properties"); |
|
2458 |
// JsonObject geom_json = feature_json.getJsonObject("geometry"); |
|
2459 |
// if( geom_json!=null ) { |
|
2460 |
// geom = geomManager.createFrom(geom_json); |
|
2461 |
// if( geom.getProjection()==null ) { |
|
2462 |
// geom.setProjection(layer.getProjection()); |
|
2463 |
// } |
|
2464 |
// } |
|
2465 |
// if( properties==null ) { |
|
2466 |
// if( geom == null ) { |
|
2467 |
// continue; |
|
2468 |
// } |
|
2469 |
// feature = store.createNewFeature(); |
|
2470 |
// } else { |
|
2471 |
// feature = store.createNewFeature(properties); |
|
2472 |
// } |
|
2473 |
// feature.setDefaultGeometry(geom); |
|
2474 |
// store.insert(feature); // Insert or replace |
|
2441 | 2475 |
} |
2442 | 2476 |
} |
2443 | 2477 |
status.setIndeterminate(); |
... | ... | |
2458 | 2492 |
} |
2459 | 2493 |
return 0; |
2460 | 2494 |
} |
2495 |
|
|
2496 |
private JsonObject convertOnlineToDesktopFeature(JsonObject online_json, String geometryName, GeometryManager geomManager, IProjection proj) { |
|
2497 |
Geometry geom = null; |
|
2498 |
JsonObject properties = online_json.getJsonObject("properties"); |
|
2499 |
JsonObject geom_json = online_json.getJsonObject("geometry"); |
|
2500 |
if (geom_json != null) { |
|
2501 |
try { |
|
2502 |
geom = geomManager.createFrom(geom_json); |
|
2503 |
} catch (Exception ex) { |
|
2504 |
} |
|
2505 |
if (geom != null && geom.getProjection() == null) { |
|
2506 |
geom.setProjection(proj); |
|
2507 |
} |
|
2508 |
} |
|
2509 |
if (properties == null) { |
|
2510 |
if (geom == null) { |
|
2511 |
return null; |
|
2512 |
} |
|
2513 |
JsonObjectBuilder builder = Json.createObjectBuilder(); |
|
2514 |
builder.add(geometryName, geom.convertToHexWKBQuietly()); |
|
2515 |
return builder.build(); |
|
2516 |
} |
|
2517 |
JsonObjectBuilder builder = Json.createObjectBuilder(); |
|
2518 |
if (geom == null) { |
|
2519 |
builder.addNull(geometryName); |
|
2520 |
} else { |
|
2521 |
builder.add(geometryName, geom.convertToHexWKBQuietly()); |
|
2522 |
} |
|
2523 |
builder.addAll(properties); |
|
2524 |
return builder.build(); |
|
2525 |
} |
|
2461 | 2526 |
|
2462 | 2527 |
public String getCurrentUserCode() { |
2463 | 2528 |
return getCurrentUserCode(null); |
... | ... | |
2658 | 2723 |
} |
2659 | 2724 |
|
2660 | 2725 |
@Override |
2661 |
public int updateClean(String entityCode) {
|
|
2662 |
return updateClean(entityCode, null);
|
|
2726 |
public int removeRemoteChanges(String entityCode) {
|
|
2727 |
return removeRemoteChanges(entityCode, null);
|
|
2663 | 2728 |
} |
2664 | 2729 |
|
2665 | 2730 |
@Override |
2666 |
public int updateClean(String entityCode, SimpleTaskStatus status) {
|
|
2731 |
public int removeRemoteChanges(String entityCode, SimpleTaskStatus status) {
|
|
2667 | 2732 |
OnlineEntity entity = this.getEntity(entityCode); |
2668 | 2733 |
if (entity == null) { |
2669 | 2734 |
return ERR_ENTITY_NOT_EXISTS; |
... | ... | |
2677 | 2742 |
} else { |
2678 | 2743 |
status.push(); |
2679 | 2744 |
} |
2745 |
FeatureStore remoteChangesStore = null; |
|
2746 |
FeatureStore localChangesStore = null; |
|
2747 |
FeatureStore entitiesStore = null; |
|
2680 | 2748 |
try { |
2681 | 2749 |
status.message("Deleting temporary remote changes (" + entity.getEntityName() + ")"); |
2682 |
RemoteChangesTable remoteChangesTable = new RemoteChangesTable(); |
|
2683 |
remoteChangesTable.delete(this, entityCode); |
|
2750 |
remoteChangesStore = openFeatureStore(RemoteChangesTable.TABLE_NAME, false); |
|
2751 |
localChangesStore = openFeatureStore(WorkspaceChangesTable.TABLE_NAME, false); |
|
2752 |
entitiesStore = openFeatureStore(EntitiesTable.TABLE_NAME, false); |
|
2753 |
removeRemoteChanges(remoteChangesStore, localChangesStore, entitiesStore, (EntityRow)entity); |
|
2684 | 2754 |
status.message("Delete temporary remote changes completed"); |
2685 | 2755 |
status.terminate(); |
2686 | 2756 |
return ERR_OK; |
... | ... | |
2691 | 2761 |
return ERR_CANT_UPDATE_CLEAN; |
2692 | 2762 |
} finally { |
2693 | 2763 |
status.pop(); |
2764 |
DisposeUtils.dispose(remoteChangesStore); |
|
2765 |
DisposeUtils.dispose(localChangesStore); |
|
2766 |
DisposeUtils.dispose(entitiesStore); |
|
2694 | 2767 |
} |
2695 | 2768 |
|
2696 | 2769 |
} |
2770 |
|
|
2771 |
private void removeRemoteChanges(FeatureStore remoteChangesStore, FeatureStore localChangesStore, FeatureStore entitiesStore, EntityRow entity) throws DataException { |
|
2772 |
RemoteChangesTable remoteChangesTable = new RemoteChangesTable(); |
|
2773 |
remoteChangesTable.delete(remoteChangesStore, entity.getEntityCode()); |
|
2774 |
WorkspaceChangesTable localChangesTable = new WorkspaceChangesTable(); |
|
2775 |
localChangesTable.changeState(localChangesStore, entity.getEntityCode(), STATE_CONFLICT, STATE_LOCAL_UNMODIFIED); |
|
2776 |
if(entity.getState() == STATE_CONFLICT){ |
|
2777 |
entity.setState(STATE_LOCAL_MODIFIED); |
|
2778 |
boolean needFinish = false; |
|
2779 |
if(entitiesStore.getMode() == FeatureStore.MODE_QUERY){ |
|
2780 |
entitiesStore.edit(MODE_PASS_THROUGH); |
|
2781 |
needFinish = true; |
|
2782 |
} |
|
2783 |
entity.update(entitiesStore); |
|
2784 |
if(needFinish){ |
|
2785 |
entitiesStore.finishEditing(); |
|
2786 |
} |
|
2787 |
} |
|
2788 |
} |
|
2697 | 2789 |
|
2698 | 2790 |
@Override |
2699 | 2791 |
public boolean canUpdate(MutableObject<String> message, String tableName) { |
... | ... | |
2964 | 3056 |
throw new UserCancelTaskException(); |
2965 | 3057 |
} |
2966 | 3058 |
RemoteChangeRow remoteChangeRow = new RemoteChangeRow(this, feature); |
2967 |
Feature f = userStore.findFirst("\"" + lentity.getFeatureIdFieldName() + "\" = '" + remoteChangeRow.getRelatedFeatureCode() + "'");
|
|
3059 |
Feature f = userStore.findFirst("\"" + lentity.getFeatureIdFieldName() + "\" = " + remoteChangeRow.getRelatedFeatureCode());
|
|
2968 | 3060 |
switch (remoteChangeRow.getOperation()) { |
2969 | 3061 |
case OP_INSERT: |
2970 | 3062 |
LOGGER.debug("===: UPDATE: insert"); |
... | ... | |
2992 | 3084 |
case OP_DELETE: |
2993 | 3085 |
LOGGER.debug("===: UPDATE: delete"); |
2994 | 3086 |
if (f != null) { |
2995 |
userStore.delete("\"" + dataCodeFieldName + "\"='" + remoteChangeRow.getRelatedFeatureCode() + "'"); |
|
2996 |
|
|
3087 |
userStore.delete("\"" + dataCodeFieldName + "\"=" + remoteChangeRow.getRelatedFeatureCode()); |
|
2997 | 3088 |
ef = userStore.createNewFeature(f); |
2998 |
String newRelatedFeatureCode = this.createUniqueCode(); |
|
2999 |
ef.setString(lentity.getFeatureIdFieldName(), newRelatedFeatureCode); |
|
3089 |
String localEntityName = lentity.getEntityName(); |
|
3090 |
long newRelatedFeatureCode = this.createUniqueCodeLong(localEntityName); |
|
3091 |
ef.setLong(lentity.getFeatureIdFieldName(), newRelatedFeatureCode); |
|
3000 | 3092 |
userStore.insert(ef); |
3001 | 3093 |
|
3002 |
workspaceChangesStore.delete("\"" + WorkspaceChangesTable.FEATUREID + "\"='" + remoteChangeRow.getRelatedFeatureCode() + "'");
|
|
3003 |
LOGGER.debug("===: UPDATE: add insert operation to RelatedFeatureCode "+newRelatedFeatureCode);
|
|
3094 |
workspaceChangesStore.delete("\"" + WorkspaceChangesTable.FEATUREID + "\"=" + remoteChangeRow.getRelatedFeatureCode());
|
|
3095 |
LOGGER.debug("===: UPDATE: add insert operation to RelatedFeatureCode " + newRelatedFeatureCode);
|
|
3004 | 3096 |
this.addChange(null, lentity, OP_INSERT, workspaceChangesStore, ef, null, null); |
3005 | 3097 |
localChangesModifieds.increment(); |
3006 | 3098 |
} else { |
... | ... | |
3128 | 3220 |
} |
3129 | 3221 |
|
3130 | 3222 |
@Override |
3131 |
public int synchronize(OnlineEntity entity, SimpleTaskStatus status) { |
|
3223 |
public int synchronize(OnlineEntity entity, Envelope workingArea, SimpleTaskStatus status) {
|
|
3132 | 3224 |
I18nManager i18n = ToolsLocator.getI18nManager(); |
3133 | 3225 |
if (status == null) { |
3134 | 3226 |
status = ToolsLocator.getTaskStatusManager().createDefaultSimpleTaskStatus(i18n.getTranslation("_Synchronizing")); |
... | ... | |
3143 | 3235 |
|
3144 | 3236 |
WorkspaceChangesTable wct = new WorkspaceChangesTable(); |
3145 | 3237 |
Iterator<Geometry> geoms = null; |
3238 |
Iterator<Geometry> geoms2 = null; |
|
3146 | 3239 |
FeatureStore remoteStore = null; |
3147 | 3240 |
FeatureStore localStore = null; |
3148 | 3241 |
FeatureSet remoteSet = null; |
3149 |
DisposableIterator remoteIt = null; |
|
3242 |
DisposableIterator<Feature> remoteIt = null;
|
|
3150 | 3243 |
FeatureSet localSet = null; |
3151 |
DisposableIterator localIt = null; |
|
3244 |
DisposableIterator<Feature> localIt = null; |
|
3245 |
|
|
3246 |
FeatureStore localChangesStore = null; |
|
3247 |
FeatureStore remoteChangesStore = null; |
|
3248 |
FeatureStore entitiesStore = null; |
|
3249 |
GeometryManager geomManager = GeometryLocator.getGeometryManager(); |
|
3152 | 3250 |
|
3153 | 3251 |
try { |
3252 |
OnlineWorkspaceImpl wc = this; |
|
3154 | 3253 |
DisposableFeatureSetIterable it = wct.getSelectedsByEntityCodeAsIterator(this, entity.getEntityCode()); |
3155 |
|
|
3156 | 3254 |
geoms = new Iterator<Geometry>() { |
3157 | 3255 |
@Override |
3158 | 3256 |
public boolean hasNext() { |
... | ... | |
3161 | 3259 |
|
3162 | 3260 |
@Override |
3163 | 3261 |
public Geometry next() { |
3164 |
return it.next().getDefaultGeometry(); |
|
3262 |
Feature f = it.next(); |
|
3263 |
WorkspaceChangeRow row = new WorkspaceChangeRow(wc, f); |
|
3264 |
if (row.getOperation() == OP_DELETE) { |
|
3265 |
return null; |
|
3266 |
} |
|
3267 |
return row.getRelatedFeature().getDefaultGeometry(); |
|
3165 | 3268 |
} |
3166 | 3269 |
}; |
3167 | 3270 |
|
3271 |
DisposableFeatureSetIterable it2 = wct.getSelectedsByEntityCodeAsIterator(this, entity.getEntityCode()); |
|
3272 |
geoms2 = new Iterator<Geometry>() { |
|
3273 |
@Override |
|
3274 |
public boolean hasNext() { |
|
3275 |
return it2.hasNext(); |
|
3276 |
} |
|
3277 |
|
|
3278 |
@Override |
|
3279 |
public Geometry next() { |
|
3280 |
try { |
|
3281 |
Feature f = it2.next(); |
|
3282 |
WorkspaceChangeRow row = new WorkspaceChangeRow(wc, f); |
|
3283 |
|
|
3284 |
JsonObject dataAsJson = row.getDataAsJson(); |
|
3285 |
if(dataAsJson == null){ |
|
3286 |
return null; |
|
3287 |
} |
|
3288 |
String geom_wkb = dataAsJson.getString(entity.getGeometryFieldName()); |
|
3289 |
if(geom_wkb == null) { |
|
3290 |
return null; |
|
3291 |
} |
|
3292 |
return geomManager.createFrom(geom_wkb); |
|
3293 |
} catch (GeometryException ex) { |
|
3294 |
LOGGER.warn("Can't get geometry of workspace change", ex); |
|
3295 |
return null; |
|
3296 |
} |
|
3297 |
} |
|
3298 |
}; |
|
3299 |
|
|
3168 | 3300 |
TilesCalculator tilesCalculator = new TilesCalculator(); |
3169 |
List<Envelope> envs = tilesCalculator.calculateEnvelopes(entity.getTileSize(), geoms); |
|
3301 |
List<Envelope> envs = tilesCalculator.calculateEnvelopes( |
|
3302 |
entity.getTileSize(), |
|
3303 |
new ChainedIterator<>( |
Also available in: Unified diff