Revision 9459

View differences:

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
212 212
                        String symbolid = ((ISymbol_v2) symbol).getID();
213 213
                        switch(symbolid) {
214 214
                            case "online-remote-polygon":
215
                                this.highlightedPolygonSymbols.put(HIGHLIGHT_REPOSITORY, symbol);
215
                                this.highlightedPolygonSymbols.put(HIGHLIGHT_REMOTE, symbol);
216 216
                                break;
217 217
                            case "online-remote-line":
218
                                this.highlightedLineSymbols.put(HIGHLIGHT_REPOSITORY, symbol);
218
                                this.highlightedLineSymbols.put(HIGHLIGHT_REMOTE, symbol);
219 219
                                break;
220 220
                            case "online-remote-point":
221
                                this.highlightedPointSymbols.put(HIGHLIGHT_REPOSITORY, symbol);
221
                                this.highlightedPointSymbols.put(HIGHLIGHT_REMOTE, symbol);
222 222
                                break;
223 223
 
224 224
                            case "online-workspace-polygon":
org.gvsig.online/trunk/org.gvsig.online/org.gvsig.online.app/org.gvsig.online.app.mainplugin/src/main/resources-plugin/i18n/text.properties
4 4
_Print_form=Imprimir formulario
5 5
_Simple_form=Formulario sencillo
6 6
_Reports=Informes
7
_Copy_template=Copiar plantilla
7
_Copy_template=Copiar plantilla
8
_Working_copy=Copia de trabajo
9
_Synchronize=Sincronizar
10
_Revert=Revertir
11
_Select_recomended=Seleccionar recomendado
12
_Unselect_all=Deseleccionar todo
13
_Collapse_all=Collapse all
14
_Expande_all=Expande all
15
_Upload=Subir
16
_Highlight=Resaltar
17
_Clean_highlighted=Limpiar resaltados
18
_Online_Show_changes=Mostrar cambios
19
_Online_Changes=gvSIG Online Cambios
20
_Online_operation_insert=Nuevo
21
_Online_operation_update=Modificado
22
_Online_operation_delete=Borrado
23
_Local_changes=Cambios locales
24
_Remote_changes=Cambios remotos
25
_Unmodified_locally=No modificada en local
26
_New_locally=Nueva en local
27
_Modified_locally=Modificada en local
28
_Modified_in_the_repository=Modificada en remoto
29
_Modified_in_the_repository_and_locally=Modificada tanto en remoto como en local
30
_Conflict=Conflicto
31
_New_in_the_repository=No existe en la copia de trabajo
32
_Unknow_state=Estado desconocido
org.gvsig.online/trunk/org.gvsig.online/org.gvsig.online.app/org.gvsig.online.app.mainplugin/src/main/resources-plugin/i18n/text_en.properties
5 5
_Simple_form=Simple form
6 6
_Reports=Reports
7 7
_Copy_template=Copy template
8
_Working_copy=Working copy
9
_Synchronize=Synchronize
10
_Revert=Revert
11
_Select_recomended=Select recomended
12
_Unselect_all=Unselect all
13
_Collapse_all=Colapsar todo
14
_Expande_all=Expandir todo
15
_Upload=Upload
16
_Highlight=Highlight
17
_Clean_highlighted=Clean highlighted
18
_Online_Show_changes=Show changes
19
_Online_Changes=gvSIG Online Changes
20
_Online_operation_insert=Insert
21
_Online_operation_update=Update
22
_Online_operation_delete=Delete
23
_Local_changes=Local changes
24
_Remote_changes=Remote changes
25
_Unmodified_locally=Unmodified locally
26
_New_locally=New locally
27
_Modified_locally=Modified locally
28
_Modified_in_the_repository=Modified in remote
29
_Modified_in_the_repository_and_locally=Modified in remote and locally
30
_Conflict=Conflict
31
_New_in_the_repository=Not in the working copy
32
_Unknow_state=Unknow state
33

  
org.gvsig.online/trunk/org.gvsig.online/org.gvsig.online.app/org.gvsig.online.app.mainplugin/src/main/resources-plugin/config.xml
18 18
  <depends plugin-name="org.gvsig.h2spatial.h2gis132.app.mainplugin" />  
19 19
  <depends plugin-name="org.gvsig.raster.mainplugin" optional="true" />
20 20
  <depends plugin-name="org.gvsig.raster.wms.app.wmsclient" optional="true" />
21
  <depends plugin-name="org.gvsig.raster.osm.app.osmclient" optional="true" />
21 22
  
22 23
  <resourceBundle name="text" />
23 24
  <libraries library-dir="lib" />
org.gvsig.online/trunk/org.gvsig.online/org.gvsig.online.app/org.gvsig.online.app.mainplugin/src/main/resources-plugin/plugin-persistence.def
1
<?xml version="1.0"?>
2
<!--
3
Definitions of plugin persistence org.gvsig.vcsgis.app.mainplugin.
4
 -->
5
<definitions>
6
  <version>1.0.0</version>
7
  <classes>
8
    <class name="org.gvsig.online.app.mainplugin">
9
      <description>Persistence of online plugin</description>
10
      <fields>
11
        <field name="workspaces" type="Map" classOfItems="org.gvsig.online.lib.api.workingcopy.OnlineWorkingcopyDescriptor" mandatory="false">
12
          <description></description>
13
        </field>
14
        <field name="EmptyEffectiveDateAllowedInCommitPanel" type="Boolean" mandatory="false" defaultValue="false">
15
          <description></description>
16
        </field>
17
        <field name="CurrentDateAsEffectiveDateByDefaultInCommitPanel" type="Boolean" mandatory="false" defaultValue="false">
18
          <description></description>
19
        </field>
20
        <field name="RepositoryEntityFeatureTypeEditorMode" type="Integer" mandatory="false" defaultValue="0">
21
          <description></description>
22
        </field>
23
      </fields>
24
    </class>
25
  </classes>
26
</definitions>
0 27

  
org.gvsig.online/trunk/org.gvsig.online/pom.xml
4 4
    <parent>
5 5
        <groupId>org.gvsig</groupId>
6 6
        <artifactId>org.gvsig.desktop</artifactId>
7
        <version>2.0.443-SNAPSHOT</version>
7
        <version>2.0.444-SNAPSHOT</version>
8 8
    </parent>
9 9
    <artifactId>org.gvsig.online</artifactId>
10 10
    <version>1.0.1-SNAPSHOT</version>
......
105 105
                <artifactId>org.gvsig.online.swing.impl</artifactId>
106 106
                <version>1.0.1-SNAPSHOT</version>
107 107
            </dependency>
108

  
109
<!--            <dependency>
110
                <groupId>org.gvsig</groupId>
111
                <artifactId>org.gvsig.raster.osm.app.osmclient</artifactId>
112
                <version>2.2.242-SNAPSHOT</version>
113
            </dependency>
114
            <dependency>
115
                <groupId>org.gvsig</groupId>
116
                <artifactId>org.gvsig.raster.osm.io</artifactId>
117
                <version>2.2.242-SNAPSHOT</version>
118
            </dependency>-->
108 119
            
109 120
        </dependencies>
110 121
    </dependencyManagement>
org.gvsig.online/trunk/org.gvsig.online/org.gvsig.online.lib/org.gvsig.online.lib.api/src/main/java/org/gvsig/online/lib/api/OnlineSite.java
29 29
    public URL getBaseUrl();
30 30
    
31 31
    public OnlineDownloader getDownloader();
32
    
33
    public URL getGeoserverURL(String s);    
32 34
}
org.gvsig.online/trunk/org.gvsig.online/org.gvsig.online.lib/org.gvsig.online.lib.api/src/main/java/org/gvsig/online/lib/api/workingcopy/OnlineChange.java
45 45

  
46 46
    public String getLabel();
47 47

  
48
    public String getRelatedFeatureCode();
48
    public long getRelatedFeatureCode();
49 49

  
50 50
    public String getRelatedFeatureData();
51 51

  
org.gvsig.online/trunk/org.gvsig.online/org.gvsig.online.lib/org.gvsig.online.lib.api/src/main/java/org/gvsig/online/lib/api/workingcopy/OnlineWorkingcopy.java
21 21
 */
22 22
package org.gvsig.online.lib.api.workingcopy;
23 23

  
24
import org.gvsig.online.lib.api.OnlineUserIdentificationRequester;
25
import java.util.Collection;
26 24
import java.util.List;
25
import org.apache.commons.lang3.mutable.MutableLong;
26
import org.apache.commons.lang3.mutable.MutableObject;
27 27
import org.gvsig.fmap.dal.OpenDataStoreParameters;
28 28
import org.gvsig.fmap.dal.feature.Feature;
29 29
import org.gvsig.fmap.dal.feature.FeatureStore;
......
32 32
import org.gvsig.fmap.dal.store.jdbc.JDBCServerExplorerParameters;
33 33
import org.gvsig.fmap.dal.store.jdbc2.JDBCServerExplorer;
34 34
import org.gvsig.fmap.geom.primitive.Envelope;
35
import org.gvsig.online.lib.api.OnlineLayer;
36 35
import org.gvsig.online.lib.api.OnlineProject;
37 36
import org.gvsig.online.lib.api.OnlineSite;
37
import org.gvsig.online.lib.api.OnlineUserIdentificationRequester;
38 38
import org.gvsig.tools.dispose.Disposable;
39 39
import org.gvsig.tools.task.SimpleTaskStatus;
40 40

  
......
144 144

  
145 145
    public boolean isInMyDatabase(String tableName);
146 146

  
147
    public Feature getRelatedFeature(OnlineEntity entity, String featureCode);
147
    public Feature getRelatedFeature(OnlineEntity entity, long featureCode);
148 148
    
149 149
    public Feature getRelatedFeature(OnlineRemoteChange change);
150 150
       
......
185 185
    public void download_resources(boolean overwrite, SimpleTaskStatus status);
186 186

  
187 187
    public int download(String name, Envelope workingAream, SimpleTaskStatus status);
188
    
189
    public boolean canUpload();
190
    
191
    public boolean canUpload(MutableObject<String> message);
192
    
193
    public boolean canUpload(MutableObject<String> message, List<String> entityCodes);
194

  
195
    public int updateClean(String entityName);
196
    
197
    public int updateClean(String entityCode, SimpleTaskStatus status);
198

  
199
    public boolean canUpdate(MutableObject<String> msg, String entityName);
200

  
201
    public boolean updateNeedMerge(String entityName);
202

  
203
    public int update(String entityName, SimpleTaskStatus taskStatus);
204

  
205
    public int merge(String tableName, MutableLong localChangesCreated, SimpleTaskStatus simpleTaskStatus);
206

  
188 207
}
org.gvsig.online/trunk/org.gvsig.online/org.gvsig.online.lib/org.gvsig.online.lib.api/src/main/java/org/gvsig/online/lib/api/OnlineUserIdentificationRequester.java
25 25
 *
26 26
 * @author gvSIG Team
27 27
 */
28
public interface OnlineUserIdentificationRequester {
28
public interface OnlineUserIdentificationRequester extends org.gvsig.tools.observer.Observable {
29
    public static final String CHANGE_USER = "CHANGE_USER";
29 30
    
30 31
    public boolean requestIdentification();
31 32
    
org.gvsig.online/trunk/org.gvsig.online/org.gvsig.online.lib/org.gvsig.online.lib.api/src/main/java/org/gvsig/online/lib/api/OnlineManager.java
43 43
    public static final int ONLINECODELEN = 60;
44 44
    
45 45
    public static final String FEATURECODE_FIELD_NAME = "ogc_fid";
46
    public static final String FEATUREMODIFIEDBY_FIELD_NAME = "modified_by";
47
    public static final String FEATURELASTMODIFICATION_FIELD_NAME = "last_modification";
48
    public static final String FEATUREDATE_FIELD_NAME = "feat_date_gvol";
49
    public static final String FEATUREVERSION_FIELD_NAME = "feat_version_gvol";
46 50
    
47 51
    public static final int STATE_UNKNOWN = 0; 
48 52
    public static final int STATE_LOCAL_UNMODIFIED = 1;
......
88 92
    public static final int ERR_INVALID_ENTITY = 36;
89 93
    
90 94
    public static final int ERR_WORKINGCOPY_REQUIRED = 37;
95

  
96
    public static final int ERR_CANT_UPDATE = 80;
97
    public static final int ERR_CANT_PREPARE_UPDATE = 81;
98
    public static final int ERR_UPDATE_NEED_MERGE = 82;
99
    public static final int ERR_CANT_UPDATE_CLEAN = 83;
100
    public static final int ERR_CANT_MERGE = 84;
101
    public static final int ERR_CANNOT_UPDATE_TABLE_THAT_NOT_EXIST = 85;
91 102
    
92 103
    public static final int ERR_CANT_CREATE_TABLE = 100;
93 104
    public static final int ERR_CANT_CREATE_TABLE_CONFIG = 110;
......
95 106
    public static final int ERR_CANT_CREATE_TABLE_CHANGES = 130;
96 107

  
97 108
    public static final int ERR_ENTITY_ALREADY_EXISTS = 200;
98
    public static final int ERR_ENTITY_NOT_HAS_VCSGISCODE = 210;
109
    public static final int ERR_ENTITY_NOT_HAS_FEATURECODE = 210;
99 110
    public static final int ERR_CANT_OPEN_ENTITIES = 220;
100 111
    public static final int ERR_CANT_INSERT_ENTITIES = 230;
101 112
    public static final int ERR_ENTITY_NOT_EXISTS = 240;
......
115 126
    
116 127
    public static final int ERR_CANT_REVERT = 700;
117 128
    
129
    public static final int ERR_USER_CANCELLED = 10000;
130
    public static final int ERR_OFFLINE = 10001;
131
    
118 132
    // workspace operations
119 133
    public static final int OP_UNKNOWN = -1;
120 134
    public static final int OP_DELETE = 0;
121 135
    public static final int OP_UPDATE = 1;
122 136
    public static final int OP_INSERT = 2;
123
    public static final int OP_ADD_ENTITY = 3;
137
//    public static final int OP_ADD_ENTITY = 3;
124 138
    public static final int OP_IGNORE = 4;
125 139

  
126 140
    public static final String TAG_ONLINE_LABEL = "online.label";
127 141
    public static final String TAG_ONLINE_DATAMODEL = "online.datamodel";
128 142
    public static final String TAG_ONLINE_FIELDFORLABEL = "online.fieldforlabel";
143
    public static final String TAG_ONLINE_TABLENAME = "online.storename";
144
    
129 145
        
130 146
    public String getErrorMessage(int errcode);
131 147
    
org.gvsig.online/trunk/org.gvsig.online/org.gvsig.online.lib/org.gvsig.online.lib.api/src/main/java/org/gvsig/online/lib/api/OnlineLayer.java
62 62
    public LayerData getDataPage(Envelope env, int pageSize, int page);
63 63
    
64 64
    public Iterator<JsonObject> getData(Envelope env, int pageSize, SimpleTaskStatus status);
65
    
66
    public String getWorkspace();
65 67

  
66 68
}
67 69

  
org.gvsig.online/trunk/org.gvsig.online/org.gvsig.online.lib/org.gvsig.online.lib.impl/src/main/java/org/gvsig/online/lib/impl/OnlineLibraryImpl.java
27 27
import org.gvsig.fmap.geom.GeometryLibrary;
28 28
import org.gvsig.online.lib.api.OnlineLibrary;
29 29
import org.gvsig.online.lib.api.OnlineLocator;
30
import org.gvsig.online.lib.impl.workspace.FeatureStoreObserver;
31
import org.gvsig.online.lib.impl.workspace.OnlineWorkingcopyDescriptorImpl;
30 32
import org.gvsig.tools.ToolsLibrary;
31 33
import org.gvsig.tools.library.AbstractLibrary;
32 34
import org.gvsig.tools.library.LibraryException;
......
51 53

  
52 54
    @Override
53 55
    protected void doPostInitialize() throws LibraryException {
56
        OnlineProjectImpl.selfRegister();
57
        OnlineWorkingcopyDescriptorImpl.selfRegister();
58
        FeatureStoreObserver.install();
54 59
    }
55 60

  
56 61
}
org.gvsig.online/trunk/org.gvsig.online/org.gvsig.online.lib/org.gvsig.online.lib.impl/src/main/java/org/gvsig/online/lib/impl/OnlineSiteImpl.java
267 267
    @Override
268 268
    public void fromJson(JsonObject json) {
269 269
        try {
270
            String s = json.getString("url", null);
271
            if( s == null ) {
272
                throw new IllegalArgumentException("url is required");
273
            }
274
            URL url = new URL(s);
270
//            String s = json.getString("url", null);
271
//            if( s == null ) {
272
//                throw new IllegalArgumentException("url is required");
273
//            }
274
//            URL url = new URL(s);
275
            URL url = (URL) Json.toObject(json, "url");
275 276
            this.clear();
276 277
            this.urlbase = url;
277
        } catch (MalformedURLException ex) {
278
        } catch (Exception ex) {
278 279
            throw new IllegalArgumentException("url is required", ex);
279 280
        }
280 281
    }
......
297 298
            throw new RuntimeException("Can't get URL",ex);
298 299
        }
299 300
    }
301

  
302
    public URL getGeoserverURL(String s) {
303
        try {
304
            String base_s = StringUtils.removeEnd(this.urlbase.toString(), "/");
305
            base_s = StringUtils.left(base_s, StringUtils.lastIndexOf(base_s, '/'));
306
            if( StringUtils.startsWith(s, "/") ) {
307
                return new URL(base_s+"/geoserver"+s);
308
            }
309
            return new URL(base_s+"/geoserver/"+s);
310
        } catch (Exception ex) {
311
            throw new RuntimeException("Can't get geoserver URL",ex);
312
        }
313
    }
300 314
}
org.gvsig.online/trunk/org.gvsig.online/org.gvsig.online.lib/org.gvsig.online.lib.impl/src/main/java/org/gvsig/online/lib/impl/OnlineProjectImpl.java
4 4
import java.io.File;
5 5
import java.io.FileInputStream;
6 6
import java.net.URL;
7
import java.nio.charset.StandardCharsets;
7 8
import java.util.Iterator;
8 9
import java.util.function.Predicate;
9 10
import javax.json.JsonArray;
......
11 12
import javax.json.JsonNumber;
12 13
import javax.json.JsonObject;
13 14
import javax.json.JsonValue;
15
import org.apache.commons.io.FileUtils;
14 16
import org.apache.commons.io.IOUtils;
15 17
import org.apache.commons.lang3.StringUtils;
16 18
import org.gvsig.fmap.geom.Geometry;
......
19 21
import org.gvsig.json.Json;
20 22
import org.gvsig.json.JsonObjectBuilder;
21 23
import org.gvsig.online.lib.api.OnlineLayer;
24
import org.gvsig.online.lib.api.OnlineLocator;
25
import org.gvsig.online.lib.api.OnlineManager;
22 26
import org.gvsig.online.lib.api.OnlineSite;
27
import org.gvsig.online.lib.api.OnlineUserIdentificationRequester;
23 28
import org.gvsig.tools.ToolsLocator;
24 29
import org.gvsig.tools.i18n.I18nManager;
30
import org.gvsig.tools.library.impl.DefaultLibrariesInitializer;
31
import org.gvsig.tools.observer.Observer;
25 32
import org.gvsig.tools.task.SimpleTaskStatus;
26 33

  
27 34
/**
......
52 59
            OnlineSiteImpl theSite = new OnlineSiteImpl();
53 60
            theSite.fromJson(theSite_json);
54 61
            this.data = data.getJsonObject("project");
62
            this.site = theSite;
55 63
        } else {
56 64
            this.data = data;
57 65
        }
......
60 68
    @Override
61 69
    public JsonObjectBuilder toJsonBuilder() {
62 70
        JsonObjectBuilder builder = Json.createObjectBuilder();
71
        builder.add_class(this);
63 72
        builder.add("site", this.site.toJsonBuilder());
64 73
        builder.add("project", (JsonValue)data);
65 74
        return builder;
......
208 217
    public OnlineLayer getResourcesTable(SimpleTaskStatus status) {
209 218
        return this.getLayer((OnlineLayer t) -> StringUtils.equalsIgnoreCase(t.getName(),this.getResourcesTablaName()), status);
210 219
    }
220

  
221
    public static void selfRegister() {
222
        Json.registerSerializer(OnlineProjectImpl.class);
223
    }
224

  
225
    public static void main(String[] args) throws Exception {
226
        new DefaultLibrariesInitializer().fullInitialize();
227
        
228
        OnlineManager manager = OnlineLocator.getOnlineManager();
229
        manager.setUserIdentificationRequester(new OnlineUserIdentificationRequester() {
230
            @Override
231
            public boolean requestIdentification() {
232
                return true;
233
            }
234

  
235
            @Override
236
            public String getUserId() {
237
//                return "TheUserName";
238
                return "jjdelcerro";
239
            }
240

  
241
            @Override
242
            public String getPassword() {
243
//                return "ThePassword";
244
                return "Iefo0She";
245
            }
246

  
247
            @Override
248
            public void addObserver(Observer o) {
249
                throw new UnsupportedOperationException("Not supported yet."); // Generated from nbfs://nbhost/SystemFileSystem/Templates/Classes/Code/GeneratedMethodBody
250
            }
251

  
252
            @Override
253
            public void deleteObserver(Observer o) {
254
                throw new UnsupportedOperationException("Not supported yet."); // Generated from nbfs://nbhost/SystemFileSystem/Templates/Classes/Code/GeneratedMethodBody
255
            }
256

  
257
            @Override
258
            public void deleteObservers() {
259
                throw new UnsupportedOperationException("Not supported yet."); // Generated from nbfs://nbhost/SystemFileSystem/Templates/Classes/Code/GeneratedMethodBody
260
            }
261
        });
262
        File f;
263
        String s;
264
        OnlineSiteImpl site = (OnlineSiteImpl) manager.connectSite(new URL("https://devel.gvsigonline.com/gvsigonline"));
265
        OnlineProjectImpl proj = site.getProject("jjdctestdesktop");
266
        s = proj.toJson().toString();
267
        System.out.println(s);
268
        proj = new OnlineProjectImpl();
269
        proj.fromJson(Json.createObject(s));
270
        s = proj.toJson().toString();
271
        System.out.println(s);
272
        System.out.println("Fin");
273
    }
211 274
    
212 275
}
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/OnlineWorkspaceDescriptorImpl.java
1
/*
2
 * gvSIG. Desktop Geographic Information System.
3
 * 
4
 * Copyright (C) 2007-2020 gvSIG Association.
5
 * 
6
 * This program is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU General Public License
8
 * as published by the Free Software Foundation; either version 3
9
 * of the License, or (at your option) any later version.
10
 * 
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 * 
16
 * You should have received a copy of the GNU General Public License 
17
 * along with this program. If not, see <https://www.gnu.org/licenses/>. 
18
 * 
19
 * For any additional information, do not hesitate to contact us
20
 * at info AT gvsig.com, or visit our website www.gvsig.com.
21
 */
22

  
23
package org.gvsig.online.lib.impl.workspace;
24

  
25
import java.util.ConcurrentModificationException;
26
import java.util.Date;
27
import org.gvsig.fmap.dal.DALLocator;
28
import org.gvsig.fmap.dal.DataManager;
29
import org.gvsig.fmap.dal.store.jdbc.JDBCServerExplorerParameters;
30
import org.gvsig.fmap.dal.store.jdbc2.JDBCServerExplorer;
31
import org.gvsig.online.lib.api.OnlineLocator;
32
import org.gvsig.online.lib.api.OnlineManager;
33
import org.gvsig.tools.ToolsLocator;
34
import org.gvsig.tools.dispose.DisposeUtils;
35
import org.gvsig.tools.dispose.impl.AbstractDisposable;
36
import org.gvsig.tools.dynobject.DynStruct;
37
import org.gvsig.tools.exception.BaseException;
38
import org.gvsig.tools.persistence.PersistenceManager;
39
import org.gvsig.tools.persistence.PersistentState;
40
import org.gvsig.tools.persistence.exception.PersistenceException;
41
import org.gvsig.online.lib.api.workingcopy.OnlineWorkingcopy;
42
import org.gvsig.online.lib.api.workingcopy.OnlineWorkingcopyDescriptor;
43

  
44
/**
45
 *
46
 * @author gvSIG Team
47
 */
48
@SuppressWarnings("UseSpecificCatch")
49
public class OnlineWorkspaceDescriptorImpl extends AbstractDisposable implements OnlineWorkingcopyDescriptor 
50
    {
51

  
52
    private String label;
53
    private String code;
54
    private JDBCServerExplorerParameters explorerParameters;
55

  
56
    private JDBCServerExplorer explorer;
57
    private OnlineWorkingcopy workspace;
58
    private long lastUse;
59

  
60
    public OnlineWorkspaceDescriptorImpl() {
61
        
62
    }
63

  
64
    public OnlineWorkspaceDescriptorImpl(OnlineWorkingcopy workspace) {
65
        setWorkspace(workspace);
66
    }
67

  
68
    @Override
69
    public String getCode() {
70
        return this.code;
71
    }
72
    
73
    @Override
74
    public boolean isWorkspaceInitialized() {
75
        if( this.workspace == null || this.workspace.getExplorer() == null) {
76
            return false;
77
        }
78
        return true;
79
//        return this.workspace != null;
80
    }
81

  
82
    @Override
83
    public OnlineWorkingcopy getWorkspace() {
84
        if( this.workspace == null || this.workspace.getExplorer() == null) {
85
            OnlineManager manager = OnlineLocator.getOnlineManager();
86
            OnlineWorkingcopy theWorkspace = manager.openWorkingcopy(this.getExplorer());
87
            if( this.workspace!=theWorkspace ) {
88
                throw new ConcurrentModificationException("The workspace has ben modified");
89
            }
90
        }
91
        lastUse = new Date().getTime();
92
        DisposeUtils.bind(this.workspace);
93
        return this.workspace;
94
    }
95

  
96
    @Override
97
    public String getLabel() {
98
        return this.label;
99
    }
100

  
101
    @Override
102
    public OnlineWorkingcopyDescriptor getValue() {
103
        return this;
104
    }
105

  
106
    @Override
107
    public JDBCServerExplorer getExplorer() {
108
        if (this.explorer == null) {
109
            if (this.workspace == null) {
110
                try {
111
                    DataManager manager = DALLocator.getDataManager();
112
                    this.explorer = (JDBCServerExplorer) manager.openServerExplorer(
113
                            this.explorerParameters.getProviderName(),
114
                            this.explorerParameters
115
                    );
116
                } catch (Exception ex) {
117
                    throw new RuntimeException(ex);
118
                }
119
            } else {
120
                this.explorer = this.workspace.getExplorer();
121
            }
122
//            DisposeUtils.bind(this.explorer);
123
        }
124
        DisposeUtils.bind(this.explorer);
125
        return this.explorer;
126
    }
127

  
128
    @Override
129
    public JDBCServerExplorerParameters getExplorerParameters() {
130
        return this.explorerParameters;
131
    }
132

  
133
    @Override
134
    public void saveToState(PersistentState state) throws PersistenceException {
135
        state.set("label", this.label);
136
        state.set("code", this.code);
137
        state.set("explorerParameters", this.explorerParameters);
138
    }
139

  
140
    @Override
141
    public void loadFromState(PersistentState state) throws PersistenceException {
142
        this.code = state.getString("code");
143
        this.label = state.getString("label");
144
        this.explorerParameters = (JDBCServerExplorerParameters) state.get("explorerParameters");
145
    }
146

  
147
    public static void selfRegister() {
148
        PersistenceManager manager = ToolsLocator.getPersistenceManager();
149

  
150
        if (manager.getDefinition("OnlineWorkspaceDescriptor")== null) {
151
            DynStruct definition = manager.addDefinition(OnlineWorkspaceDescriptorImpl.class,
152
                    "OnlineWorkspaceDescriptor",
153
                    "OnlineWorkspaceDescriptor persistent definition",
154
                    null,
155
                    null
156
            );
157
            definition.addDynFieldString("code");
158
            definition.addDynFieldString("label");
159
            definition.addDynFieldObject("explorerParameters")
160
                .setClassOfValue(JDBCServerExplorerParameters.class)
161
                .setMandatory(true);
162
        }
163
        
164
    }
165

  
166
    @Override
167
    public String toString() {
168
        return this.getLabel();
169
    }
170

  
171
    /**
172
     * Only for testing purposes
173
     * @param workspace
174
     */
175
    public void setWorkspace(OnlineWorkingcopy workspace) {
176
        if(workspace == null){
177
            throw new IllegalArgumentException("workspace can't be null.");
178
        }
179
        DisposeUtils.disposeQuietly(this.workspace);
180
        DisposeUtils.disposeQuietly(this.explorer);
181
        this.workspace = workspace;
182
        DisposeUtils.bind(this.workspace);
183
        this.explorerParameters = workspace.getExplorerParameters();
184
        this.explorer = null;
185
        this.label = workspace.getLabel();
186
        this.code = workspace.getCode();
187
        lastUse = new Date().getTime();
188
    }
189

  
190
    @Override
191
    protected void doDispose() throws BaseException {
192
        DisposeUtils.disposeQuietly(this.workspace);
193
        DisposeUtils.disposeQuietly(this.explorer);
194
        this.explorerParameters = null;
195
        this.explorer = null;
196
        this.workspace = null;
197
//        this.label = null; //Don't null for debugging purposses
198
        this.code = null;
199

  
200
    }
201
    
202
    public void dropExpiredCaches() {
203
        long now = new Date().getTime();
204
        if (now > this.lastUse+60000) {
205
            dropCaches();
206
        }
207
        
208
    }
209
    
210
    public void dropCaches() {
211
        DisposeUtils.disposeQuietly(this.workspace);
212
        DisposeUtils.disposeQuietly(this.explorer);
213
        this.workspace = null;
214
        this.explorer = null;
215
    }
216
    
217
}
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
26 26
import org.apache.commons.lang3.ArrayUtils;
27 27
import org.apache.commons.lang3.BooleanUtils;
28 28
import org.apache.commons.lang3.StringUtils;
29
import org.apache.commons.lang3.mutable.MutableLong;
30
import org.apache.commons.lang3.mutable.MutableObject;
29 31
import org.cresques.cts.IProjection;
32
import org.gvsig.expressionevaluator.Expression;
30 33
import org.gvsig.expressionevaluator.ExpressionBuilder;
34
import org.gvsig.expressionevaluator.ExpressionEvaluatorLocator;
35
import org.gvsig.expressionevaluator.ExpressionEvaluatorManager;
31 36
import org.gvsig.expressionevaluator.ExpressionUtils;
32 37
import org.gvsig.fmap.dal.DALLocator;
33 38
import org.gvsig.fmap.dal.DataManager;
......
62 67
import org.gvsig.fmap.geom.primitive.Envelope;
63 68
import org.gvsig.json.Json;
64 69
import org.gvsig.online.lib.api.OnlineCodeGenerator;
70
import org.gvsig.online.lib.api.OnlineDownloader;
65 71
import org.gvsig.online.lib.api.OnlineLayer;
66
import org.gvsig.online.lib.api.workingcopy.OnlineEntity;
72
import org.gvsig.online.lib.api.OnlineManager;
67 73
import static org.gvsig.online.lib.api.OnlineManager.ERR_CANT_ADD_CHANGE;
68 74
import static org.gvsig.online.lib.api.OnlineManager.ERR_CANT_INSERT_CHANGE;
69 75
import static org.gvsig.online.lib.api.OnlineManager.ERR_CANT_OPEN_CHANGES;
70 76
import static org.gvsig.online.lib.api.OnlineManager.ERR_CANT_OPEN_ENTITIES;
71 77
import static org.gvsig.online.lib.api.OnlineManager.ERR_CANT_REMOVE_CHANGES;
72 78
import static org.gvsig.online.lib.api.OnlineManager.ERR_CANT_REMOVE_ENTITY;
79
import static org.gvsig.online.lib.api.OnlineManager.ERR_CANT_RETRIEVE_ENTITIES;
73 80
import static org.gvsig.online.lib.api.OnlineManager.ERR_CANT_REVERT;
81
import static org.gvsig.online.lib.api.OnlineManager.ERR_CANT_UPDATE;
82
import static org.gvsig.online.lib.api.OnlineManager.ERR_CANT_UPDATE_CLEAN;
74 83
import static org.gvsig.online.lib.api.OnlineManager.ERR_ENTITY_NOT_EXISTS;
75
import static org.gvsig.online.lib.api.OnlineManager.ERR_ENTITY_NOT_HAS_VCSGISCODE;
76 84
import static org.gvsig.online.lib.api.OnlineManager.ERR_INVALID_ENTITY;
77 85
import static org.gvsig.online.lib.api.OnlineManager.ERR_NO_ERROR;
86
import static org.gvsig.online.lib.api.OnlineManager.ERR_OFFLINE;
78 87
import static org.gvsig.online.lib.api.OnlineManager.ERR_OK;
79 88
import static org.gvsig.online.lib.api.OnlineManager.ERR_STORE_NOT_IN_WORKINGCOPY;
89
import static org.gvsig.online.lib.api.OnlineManager.ERR_UPDATE_NEED_MERGE;
80 90
import static org.gvsig.online.lib.api.OnlineManager.FEATURECODE_FIELD_NAME;
81
import static org.gvsig.online.lib.api.OnlineManager.ONLINECODELEN;
82
import static org.gvsig.online.lib.api.OnlineManager.OP_ADD_ENTITY;
83 91
import static org.gvsig.online.lib.api.OnlineManager.OP_DELETE;
84 92
import static org.gvsig.online.lib.api.OnlineManager.OP_IGNORE;
85 93
import static org.gvsig.online.lib.api.OnlineManager.OP_INSERT;
......
95 103
import static org.gvsig.online.lib.api.OnlineManager.STATE_LOCAL_UNMODIFIED;
96 104
import static org.gvsig.online.lib.api.OnlineManager.STATE_REMOTE_NEW;
97 105
import static org.gvsig.online.lib.api.OnlineManager.STATE_UNKNOWN;
98
import static org.gvsig.online.lib.api.OnlineManager.TAG_ONLINE_DATAMODEL;
99
import static org.gvsig.online.lib.api.OnlineManager.TAG_ONLINE_FIELDFORLABEL;
100
import static org.gvsig.online.lib.api.OnlineManager.TAG_ONLINE_LABEL;
101 106
import org.gvsig.online.lib.api.OnlineProject;
102 107
import org.gvsig.online.lib.api.OnlineRuntimeException;
103 108
import org.gvsig.online.lib.api.OnlineSite;
104 109
import org.gvsig.online.lib.api.OnlineUserIdentificationRequester;
110
import static org.gvsig.online.lib.api.OnlineUserIdentificationRequester.CHANGE_USER;
111
import org.gvsig.online.lib.api.workingcopy.OnlineEntity;
105 112
import org.gvsig.online.lib.api.workingcopy.OnlineRemoteChange;
106
import org.gvsig.online.lib.api.OnlineDownloader;
107
import static org.gvsig.online.lib.api.OnlineManager.ERR_CANT_RETRIEVE_ENTITIES;
113
import org.gvsig.online.lib.api.workingcopy.OnlineWorkingcopy;
114
import org.gvsig.online.lib.api.workingcopy.OnlineWorkingcopyChange;
115
import org.gvsig.online.lib.api.workingcopy.OnlineWorkingcopyChanges;
108 116
import static org.gvsig.online.lib.impl.OnlineManagerImpl.INTERNAL_WORKSPACE_TABLES;
109 117
import org.gvsig.online.lib.impl.OnlineProjectImpl;
110 118
import org.gvsig.online.lib.impl.OnlineSiteImpl;
......
117 125
import org.gvsig.online.lib.impl.workspace.tables.VarsTable;
118 126
import org.gvsig.online.lib.impl.workspace.tables.WorkspaceChangesTable;
119 127
import org.gvsig.online.lib.impl.workspace.tables.WorkspaceChangesTable.WorkspaceChangeRow;
128
import org.gvsig.timesupport.DataTypes;
120 129
import org.gvsig.tools.ToolsLocator;
121 130
import org.gvsig.tools.dataTypes.DataTypeUtils;
122
import org.gvsig.tools.dataTypes.DataTypes;
123 131
import org.gvsig.tools.dispose.DisposeUtils;
124 132
import org.gvsig.tools.dispose.impl.AbstractDisposable;
125 133
import static org.gvsig.tools.dynform.spi.DynFormSPIManager.TAG_DYNFORM_READONLY;
126
import org.gvsig.tools.dynobject.Tags;
127 134
import org.gvsig.tools.i18n.I18nManager;
128 135
import org.gvsig.tools.logger.FilteredLogger;
136
import org.gvsig.tools.observer.Notification;
137
import org.gvsig.tools.observer.Observable;
138
import org.gvsig.tools.observer.Observer;
129 139
import org.gvsig.tools.resourcesstorage.ResourcesStorage;
130 140
import org.gvsig.tools.swing.api.ChangeListenerHelper;
131 141
import org.gvsig.tools.swing.api.ToolsSwingLocator;
......
135 145
import org.gvsig.tools.util.GetItemWithSize64;
136 146
import org.gvsig.tools.util.HasAFile;
137 147
import org.gvsig.tools.util.Rewind;
138
import org.gvsig.vcsgis.lib.workspace.StoreProperties;
139 148
import org.slf4j.Logger;
140 149
import org.slf4j.LoggerFactory;
141
import org.gvsig.online.lib.api.workingcopy.OnlineWorkingcopy;
142
import org.gvsig.online.lib.api.workingcopy.OnlineWorkingcopyChange;
143
import org.gvsig.online.lib.api.workingcopy.OnlineWorkingcopyChanges;
150
import static org.gvsig.online.lib.api.OnlineManager.ONLINECODELEN;
151
import static org.gvsig.online.lib.api.OnlineManager.TAG_ONLINE_DATAMODEL;
152
import static org.gvsig.online.lib.api.OnlineManager.TAG_ONLINE_FIELDFORLABEL;
153
import static org.gvsig.online.lib.api.OnlineManager.TAG_ONLINE_LABEL;
154
import org.gvsig.tools.dynobject.Tags;
155
import static org.gvsig.online.lib.api.OnlineManager.ERR_ENTITY_NOT_HAS_FEATURECODE;
144 156

  
145 157
/**
146 158
 *
......
182 194
    private boolean offline;
183 195
    private String entityLabelTemplate;
184 196
    private boolean disposed = false;
197
    private Observer changeUserObserver;
185 198

  
186 199
    public OnlineWorkspaceImpl(JDBCServerExplorer wsexplorer, OnlineCodeGenerator codeGenerator, OnlineProject project, String label) {
187 200
        // Usado en la inicializacion del workspace
......
201 214
        this.userIdentificationRequester = null;
202 215
        this.offline = false;
203 216
        this.entityLabelTemplate = "${label}";
217
        this.changeUserObserver = createChangeUserObserver();
204 218
    }
205 219

  
206 220
    public OnlineWorkspaceImpl(JDBCServerExplorer wsexplorer, OnlineCodeGenerator codeGenerator, String newLabel) {
......
250 264
        this.setCurrentUserCode(this.project, vars.get(CONFIG_USER_NAME));
251 265
        this.setAuthenticationToken(this.project, vars.get(CONFIG_AUTHENTICATIONTOKEN_NAME));
252 266
        this.label = vars.get(CONFIG_WORKSPACE_LABEL_NAME);
267
        this.changeUserObserver = createChangeUserObserver();
268
        
253 269
//        LOGGER.debug("===: CREATE WORKSPACE "+ hexId(this)+ " (open code='"+this.code+"', label='"+this.label+"')");
254 270
    }
255 271

  
272
    private org.gvsig.tools.observer.Observer createChangeUserObserver() {
273
        return (Observable observable, Object notification) -> {
274
            if(notification instanceof Notification) {
275
                Notification n = (Notification)notification;
276
                if(n.isOfType(CHANGE_USER)){
277
                    String userCode = (String) n.getValue();
278
                    setCurrentUserCode(project, userCode);
279
                    VarsTable varsTable = new VarsTable();
280
                    varsTable.set(this,"USER", userCode);
281
                }
282
            }
283
        };
284
    }
285
    
256 286
    @Override
257 287
    public String getCode() {
258 288
        return this.code;
......
271 301
        return this.codeGenerator.generateCodeString();
272 302
    }
273 303

  
304
    public final long createUniqueCodeLong() {
305
        return this.codeGenerator.generateCodelong();
306
    }
307

  
274 308
    @Override
275 309
    public String getErrorMessage(int errcode) {
276 310
        return OnlineUtils.getErrorMessage(errcode);
......
359 393
        } catch (Exception ex) {
360 394
            LOGGER.trace("can't open store from '" + this.getMessageLabel() + "'.", ex);
361 395
            return null;
362
//            String msg = "can't open store from '" + this.getMessageLabel() + "'.";
363
//            throw new RuntimeException(msg, ex);
364 396
        }
365 397
    }
366 398

  
......
384 416
        } catch (Exception ex) {
385 417
            LOGGER.trace("can't open store from '" + this.getMessageLabel() + "'.", ex);
386 418
            return null;
387
//            String msg = "can't open store from '" + this.getMessageLabel() + "'.";
388
//            throw new RuntimeException(msg, ex);
389 419
        }
390 420
    }
391 421

  
......
827 857

  
828 858
            EditableFeatureAttributeDescriptor attr = (EditableFeatureAttributeDescriptor) ft.getAttributeDescriptor(FEATURECODE_FIELD_NAME);
829 859
            if (attr == null) {
830
                err = ERR_ENTITY_NOT_HAS_VCSGISCODE;
831
                attr = (EditableFeatureAttributeDescriptor) ft.add(FEATURECODE_FIELD_NAME, DataTypes.STRING)
832
                        .setSize(ONLINECODELEN)
860
                err = ERR_ENTITY_NOT_HAS_FEATURECODE;
861
                attr = (EditableFeatureAttributeDescriptor) ft.add(FEATURECODE_FIELD_NAME, DataTypes.LONG)
862
//                        .setSize(ONLINECODELEN)
833 863
                        .setIsPrimaryKey(true)
834 864
                        .setIsIndexed(true)
835 865
                        .setAllowIndexDuplicateds(false)
836
                        .setLabel("VCSGIS Code");
866
                        .setLabel("Online Code");
837 867
                ft.setHasOID(false);
838 868
            } else {
839 869
                if (!attr.isPrimaryKey()) {
......
883 913
            this.forceReloadWorkspaceEntities();
884 914
            err = ERR_CANT_INSERT_CHANGE;
885 915

  
886
//            entity = this.getWorkspaceEntityByName(name);
887
//            FeatureStore changesStore = this.getFeatureStore(WorkspaceChangesTable.TABLE_NAME);
888
//            addChange(entity, OP_ADD_ENTITY, changesStore, null, null);
889
            WorkspaceChangeRow change = new WorkspaceChangeRow(this);
890
            change.newCode();
891
            change.setEditingSession(null);
892
            change.setEntityCode(entity.getCode());
893
            change.setFeatureCode(null);
894
            change.setOperation(OP_ADD_ENTITY);
895
            change.setSelected(true);
896
            change.insert();
916
//            WorkspaceChangeRow change = new WorkspaceChangeRow(this);
917
//            change.newCode();
918
//            change.setEditingSession(null);
919
//            change.setEntityCode(entity.getCode());
920
//            change.setFeatureCode(0);
921
//            change.setOperation(OP_ADD_ENTITY);
922
//            change.setSelected(true);
923
//            change.insert();
897 924

  
898 925
            this.create_table(entity);
899 926
        } catch (OnlineRuntimeException ex) {
......
969 996
        try {
970 997
            workspaceChangesStore = this.openFeatureStore(WorkspaceChangesTable.TABLE_NAME, false);
971 998
            err = ERR_CANT_INSERT_CHANGE;
972
            Map<String, Integer> previousOperations = null;
999
            Map<Long, Integer> previousOperations = null;
973 1000
            if (updatedsFeatures instanceof Rewind && insertedsFeatures instanceof Rewind) {
974 1001
                previousOperations = calculatePreviousOperations(entity, workspaceChangesStore, insertedsFeatures, updatedsFeatures);
975 1002
                workspaceChangesStore.edit(FeatureStore.MODE_APPEND);
......
1037 1064
//                            throw new RuntimeException("Feature already exists for vcsgiscode = '"+featurecode+"'");
1038 1065
//                        }
1039 1066
//                    }
1040
                    addDeleteChange(editingSession, entity, workspaceChangesStore, f.getString(entity.getFeatureIdFieldName()), f.getString(entity.getFieldForLabel()), originalFeature);
1067
                    addDeleteChange(editingSession, entity, workspaceChangesStore, f.getLong(entity.getFeatureIdFieldName()), f.getString(entity.getFieldForLabel()), originalFeature);
1041 1068
                }
1042 1069
            }
1043 1070
            workspaceChangesStore.finishEditing();
......
1062 1089
        }
1063 1090
        return err;
1064 1091
    }
1092
    
1093
    public int addChange(String editingSession, int operation, FeatureStore userStore, Feature feature) {
1094
        String entityName = StoreProperties.getEntityName(userStore);
1095
        if (StringUtils.isBlank(entityName)) {
1096
            return ERR_STORE_NOT_IN_WORKINGCOPY;
1097
        }
1098
        if (this.isInStoreIgnoreChanges(userStore)) {
1099
            LOGGER.debug("===: ADD_CHANGE: Skip (" + userStore.getName() + ")");
1100
            return ERR_NO_ERROR;
1101
        }
1102
        boolean isUserStoreInAppendMode = userStore.getMode()==FeatureStore.MODE_APPEND;
1103
        EntityRow entity = (EntityRow) this.getWorkspaceEntityByName(entityName);
1104
        if( entity.getState()==STATE_DISCONNECTED ) {
1105
            return ERR_OK;
1106
        }
1107
        FeatureStore changesStore = this.openFeatureStore(WorkspaceChangesTable.TABLE_NAME,false);
1108
        try {
1109
            changesStore.edit(MODE_PASS_THROUGH);
1110
            long featureCode = feature.getLong(entity.getFeatureIdFieldName());
1111
            switch(operation) {
1112
            case OP_DELETE:
1113
                String label = feature.getString(entity.getFieldForLabel());
1114
//               if( this.useSafeMode() && !isUserStoreInAppendMode ) {
1115
//                    Feature fuser = userStore.findFirst("VCSGISCODE = '"+featureCode+"'");
1116
//                    if( fuser==null ) {
1117
//                        throw new RuntimeException("Can't get original feature for deleted vcsgiscode = '"+featureCode+"'");
1118
//                    }
1119
//                }                
1120
                return addDeleteChange(editingSession, entity, changesStore, featureCode, label, userStore.getOriginalFeature(feature));
1121
            case OP_INSERT:
1122
//               if( this.useSafeMode() && !isUserStoreInAppendMode ) {
1123
//                    Feature fuser = userStore.findFirst("VCSGISCODE = '"+featureCode+"'");
1124
//                    if( fuser!=null ) {
1125
//                        throw new RuntimeException("Already exists feature with vcsgiscode = '"+featureCode+"'");
1126
//                    }
1127
//                }                
1128
                return addChange(editingSession, entity, operation, changesStore, feature, userStore.getOriginalFeature(feature), null);
1129
            case OP_UPDATE:
1130
//               if( this.useSafeMode() && !isUserStoreInAppendMode ) {
1131
//                    Feature fuser = userStore.findFirst("VCSGISCODE = '"+featureCode+"'");
1132
//                    if( fuser==null ) {
1133
//                        throw new RuntimeException("Can't get original feature for update vcsgiscode = '"+featureCode+"'");
1134
//                    }
1135
//                }                
1136
                return addChange(editingSession, entity, operation, changesStore, feature, userStore.getOriginalFeature(feature), null);
1137
            default:
1138
                LOGGER.warn("Unsupported operation "+operation+".");
1139
                return addChange(editingSession, entity, operation, changesStore, feature, userStore.getOriginalFeature(feature), null);
1140
            }
1141
        } catch (Exception ex) {
1142
            LOGGER.warn("Can't add change (op " + OnlineUtils.getOperationLabel(operation) + ", " + entity.getEntityName() + ")", ex);
1143
            changesStore.cancelEditingQuietly();
1144
            return ERR_CANT_ADD_CHANGE;
1145
        } finally {
1146
            changesStore.finishEditingQuietly();
1147
            DisposeUtils.dispose(changesStore);
1148
        }
1149
    }
1065 1150

  
1066
    private int addChange(String editingSession, EntityRow entity, int operation, FeatureStore changesStore, Feature feature, Feature oldFeature, Map<String, Integer> previousOperations) {
1151

  
1152

  
1153
    private int addChange(String editingSession, EntityRow entity, int operation, FeatureStore changesStore, Feature feature, Feature oldFeature, Map<Long, Integer> previousOperations) {
1067 1154
        if (entity.getState() == STATE_DISCONNECTED) {
1068 1155
            return ERR_OK;
1069 1156
        }
......
1073 1160
            // En MODE_PASSTH... el otro metodo addChange deberia haberlo atrapado,
1074 1161
            // y derivado al addDeleteChange. 
1075 1162
            // Por si acaso llega aqui, lo derivamos al addDeleteChange.
1076
            String featureCode = feature.getString(entity.getFeatureIdFieldName());
1163
            long featureCode = feature.getLong(entity.getFeatureIdFieldName());
1077 1164
            String label = feature.getString(entity.getFieldForLabel());
1078 1165
            return addDeleteChange(editingSession, entity, changesStore, featureCode, label, oldFeature);
1079 1166
        }
......
1083 1170
            }
1084 1171
        }
1085 1172
        try {
1086
            String featureCode = feature.getString(entity.getFeatureIdFieldName());
1173
            long featureCode = feature.getLong(entity.getFeatureIdFieldName());
1087 1174
            Integer previousOperation = null;
1088 1175
            if (previousOperations != null) {
1089 1176
                previousOperation = previousOperations.get(featureCode);
......
1164 1251
        }
1165 1252
    }
1166 1253

  
1167
    private int addDeleteChange(String editingSession, EntityRow entity, FeatureStore changesStore, String featureCode, String label, Feature oldFeature) {
1254
    public int addDeleteChanges(String editingSession, FeatureStore userStore, Expression exp) {
1255
        String entityName = StoreProperties.getEntityName(userStore);
1256
        if (StringUtils.isBlank(entityName)) {
1257
            return ERR_STORE_NOT_IN_WORKINGCOPY;
1258
        }
1259
        if (this.isInStoreIgnoreChanges(userStore)) {
1260
            return ERR_NO_ERROR;
1261
        }
1262
        EntityRow entity = this.getWorkspaceEntityByName(entityName);
1263
        if (entity == null) {
1264
            return ERR_STORE_NOT_IN_WORKINGCOPY;
1265
        }
1266
        if( entity.getState()==STATE_DISCONNECTED ) {
1267
            return ERR_OK;
1268
        }
1269
        FeatureStore workspaceChangesStore = null;
1270
        int err = ERR_CANT_OPEN_CHANGES;
1271
        try {
1272
            workspaceChangesStore = this.openFeatureStore(WorkspaceChangesTable.TABLE_NAME,false);
1273
            workspaceChangesStore.edit(FeatureStore.MODE_PASS_THROUGH);
1274
            FeatureSet deletedsFeatures = userStore.getFeatureSet(exp);
1275
            err = ERR_CANT_INSERT_CHANGE;
1276
            for (Feature f : deletedsFeatures) {
1277
                addDeleteChange(editingSession, 
1278
                        entity, 
1279
                        workspaceChangesStore, 
1280
                        f.getLong(entity.getFeatureIdFieldName()), 
1281
                        f.getString(entity.getFieldForLabel()), 
1282
                        f
1283
                );
1284
            }
1285
            workspaceChangesStore.finishEditing();
1286
            err = ERR_NO_ERROR;
1287
        } catch (Exception ex) {
1288
            LOGGER.warn("Can't add  delete changes.", ex);
1289
            FeatureStore.cancelEditingQuietly(workspaceChangesStore);
1290
        } finally {
1291
            DisposeUtils.disposeQuietly(workspaceChangesStore);
1292
        }
1293
        return err;
1294
    }
1295
    
1296
    
1297
    private int addDeleteChange(String editingSession, EntityRow entity, FeatureStore changesStore, long featureCode, String label, Feature oldFeature) {
1168 1298
        if (entity.getState() == STATE_DISCONNECTED) {
1169 1299
            return ERR_OK;
1170 1300
        }
......
1267 1397
                        break;
1268 1398
                }
1269 1399
                break;
1270
            case OP_ADD_ENTITY:
1271
                entity.setState(STATE_LOCAL_NEW);
1272
                save = true;
1273
                break;
1400
//            case OP_ADD_ENTITY:
1401
//                entity.setState(STATE_LOCAL_NEW);
1402
//                save = true;
1403
//                break;
1274 1404
        }
1275 1405

  
1276 1406
        if (save) {
......
1308 1438
        }
1309 1439
    }
1310 1440

  
1311
    private Map<String, Integer> calculatePreviousOperations(EntityRow entity, FeatureStore changesStore, Iterator<Feature> insertedsFeatures, Iterator<Feature> updatedsFeatures) {
1441
    private Map<Long, Integer> calculatePreviousOperations(EntityRow entity, FeatureStore changesStore, Iterator<Feature> insertedsFeatures, Iterator<Feature> updatedsFeatures) {
1312 1442
        // Esta version agrupa las consultas a la base de datos de 200 en 200
1313 1443
        // para reducir el numero de consultas y aumentar el rendimiento.
1314 1444
        try {
1315
            Map<String, Integer> previousOperations = new HashMap<>();
1445
            Map<Long, Integer> previousOperations = new HashMap<>();
1316 1446
            Iterator<Feature> it = new ChainedIterator<>(insertedsFeatures, updatedsFeatures);
1317 1447
            ExpressionBuilder builder = ExpressionUtils.createExpressionBuilder();
1318 1448
            int count = 0;
......
1332 1462
                        FeatureSet set = changesStore.getFeatureSet(filter);
1333 1463
                        for (Feature previousChange : set) {
1334 1464
                            if (previousChange != null) {
1335
                                String featureCode2 = previousChange.getString(WorkspaceChangesTable.FEATUREID);
1465
                                long featureCode2 = previousChange.getLong(WorkspaceChangesTable.FEATUREID);
1336 1466
                                int previousOperation = previousChange.getInt(WorkspaceChangesTable.OPERATION);
1337 1467
                                previousOperations.put(featureCode2, previousOperation);
1338 1468
                            }
......
1597 1727
    }
1598 1728

  
1599 1729
    @Override
1600
    public Feature getRelatedFeature(OnlineEntity entity, String featureCode) {
1730
    public Feature getRelatedFeature(OnlineEntity entity, long featureCode) {
1601 1731
        FeatureStore store = null;
1602 1732
        try {
1603 1733
            store = this.getFeatureStore(entity.getEntityName());
1604
            Feature f = store.findFirst("\"" + entity.getFeatureIdFieldName() + "\"='" + featureCode + "'");
1734
            Feature f = store.findFirst("\"" + entity.getFeatureIdFieldName() + "\"=" + featureCode);
1605 1735
            return f;
1606 1736
        } catch (Exception ex) {
1607 1737
            throw new RuntimeException("Can't retrieve feature '" + entity.getEntityName() + "/" + code + "'.", ex);
......
1802 1932

  
1803 1933
    @Override
1804 1934
    public void setUserIdentificationRequester(OnlineUserIdentificationRequester userIdentificationRequester) {
1935
        if(this.userIdentificationRequester != null){
1936
            this.userIdentificationRequester.deleteObserver(changeUserObserver);
1937
        }
1805 1938
        this.userIdentificationRequester = userIdentificationRequester;
1939
        this.userIdentificationRequester.addObserver(changeUserObserver);
1806 1940
    }
1807 1941

  
1808 1942
    @Override
......
2313 2447
        return 0;
2314 2448
    }
2315 2449

  
2450
    public String getCurrentUserCode() {
2451
        return getCurrentUserCode(null);
2452
    }
2453
    
2316 2454
    private String getCurrentUserCode(OnlineProject project) {
2317 2455
        // Esto es por si acabamos cargando en un workspace 
2318 2456
        // tablas de mas de un proyecto del mismo site.
......
2367 2505
        this.authenticationTokens.put(projectid, token);
2368 2506
    }
2369 2507
   
2508
    public boolean isAResourceTable(String entityName) {
2509
        // Deberia comprobar gvsigd_resources?
2510
        return false;
2511
    }
2512

  
2513
    @Override
2514
    public boolean canUpload() {
2515
        return canUpload(null);
2516
    }
2517

  
2518
    @Override
2519
    public boolean canUpload(MutableObject<String> message) {
2520
        return canUpload(message, null);
2521
    }
2522

  
2523
    @Override
2524
    public boolean canUpload(MutableObject<String> message, List<String> entityCodes) {
2525
        if( this.isOffline() ) {
2526
            return false;
2527
        }
2528
        I18nManager i18n = ToolsLocator.getI18nManager();
2529
        if (entityCodes == null) {
2530
            LOGGER.warn("entityCodes is null");
2531
            if (message != null) {
2532
                String msg = i18n.getTranslation("_It_is_mandatory_to_indicate_the_tables_on_which_you_want_to_commit");
2533
                message.setValue(msg);
2534
            }
2535
            return false;
2536
        }
2537
        return true;
2538
//        List<String> outdatedEntityNames = new ArrayList<>();
2539
//        WorkspaceChangesTable changesTable = new WorkspaceChangesTable();
2540
//        DisposableFeatureSetIterable changesGroupedByEntity = null;
2541
//        try {
2542
//            Set<String> repositoryCodes = new HashSet<>();
2543
//            repositoryCodes.add(this.getRepository().getCode());
2544
//            for (String entityCode : entityCodes) {
2545
//                EntityRow entity = this.getWorkspaceEntity(entityCode);
2546
//                int maskStatus = entity.getState();
2547
//                if( (maskStatus & STATE_CORRUPT) == STATE_CORRUPT ) {
2548
//                    LOGGER.info("Entity '"+entity.getEntityName()+"' marked as corrupt.");
2549
//                    if (message != null) {
2550
//                        String msg = i18n.getTranslation("_Some_of_the_selected_tables_are_marked_as_corrupt")
2551
//                                + ". (" + entity.getEntityName() + ")";
2552
//                        message.setValue(msg);
2553
//                    }
2554
//                    return false;
2555
//                }
2556
//                if( (maskStatus & STATE_DISCONNECTED) == STATE_DISCONNECTED ) {
2557
//                    LOGGER.info("Entity '"+entity.getEntityName()+"' marked as disconnected.");
2558
//                    if (message != null) {
2559
//                        String msg = i18n.getTranslation("_Some_of_the_selected_tables_are_marked_as_disconnected")
2560
//                                + ". (" + entity.getEntityName() + ")";
2561
//                        message.setValue(msg);
2562
//                    }
2563
//                    return false;
2564
//                }
2565
//                if( entity.isLinkedTable() ) {
2566
//                    VCSGisRepository linkedRepo = entity.getLinkedRepository();
2567
//                    if( linkedRepo!=null ) {
2568
//                        repositoryCodes.add(linkedRepo.getCode());
2569
//                    }
2570
//                }
2571
//            }
2572
//            if( repositoryCodes.size() > 1 ) {
2573
//                LOGGER.info("Too many repositories, only one allowed in commit.");
2574
//                if (message != null) {
2575
//                    String msg = i18n.getTranslation("_Too_many_repositories_only_one_allowed");
2576
//                    message.setValue(msg);
2577
//                }
2578
//                return false;
2579
//            }
2580
//            changesGroupedByEntity = changesTable.getGroupedByEntity(this);
2581
//            for (Feature fchange : changesGroupedByEntity) {
2582
//                WorkspaceChangeRow change = new WorkspaceChangeRow(this, fchange);
2583
//                VCSGisWorkspaceEntity entity = change.getEntity();
2584
//                if(entity == null){
2585
//                    continue;
2586
//                }
2587
//                if(CollectionUtils.isEmpty(entityCodes) || entityCodes.contains(entity.getEntityCode())){
2588
//                    LOGGER.debug("===: CAN-COMMIT: add used entity = " + fchange.toJson().toString().replace('\n', ' '));
2589
//                    if (change.isSelected() && entity.isOutdated()) {
2590
//                        outdatedEntityNames.add(entity.getEntityName());
2591
//                    }
2592
//                }
2593
//                
2594
//                switch (this.getEditMode(entity)) {
2595
//                    case FeatureStore.MODE_UNKNOWN:
2596
//                        // La tabla no existe en la copia de trabajo
2597
//                        LOGGER.info("Can access to '"+entity.getEntityName()+"'.");
2598
//                        if (message != null) {
2599
//                            String msg = i18n.getTranslation("_Some_of_the_selected_tables_are_damaged")
2600
//                                    + ". ("
2601
//                                    + entity.getEntityName()
2602
//                                    + ")";
2603
//                            message.setValue(msg);
2604
//                        }
2605
//                        return false;
2606
//                    case FeatureStore.MODE_FULLEDIT:
2607
//                    case FeatureStore.MODE_APPEND:
2608
//                    case FeatureStore.MODE_PASS_THROUGH:
2609
//                        LOGGER.info("Table '"+entity.getEntityName()+"' is editing.");
2610
//                        if (message != null) {
2611
//                            String msg = i18n.getTranslation("_Selected_tables_are_editing")
2612
//                                    + ". ("
2613
//                                    + entity.getEntityName()
2614
//                                    + ")";
2615
//                            message.setValue(msg);
2616
//                        }
2617
//
2618
//                        return false;
2619
//                }
2620
//
2621
//            }
2622
//            DisposeUtils.dispose(changesGroupedByEntity);
2623
//
2624
//            if (!outdatedEntityNames.isEmpty()) {
2625
//                LOGGER.info("Somme tables in working copy are outdated ("+StringUtils.join(outdatedEntityNames, ",")+").");
2626
//                if (message != null) {
2627
//                    String msg = i18n.getTranslation("_Tables_in_working_copy_are_outdated")
2628
//                            + ". ("
2629
//                            + StringUtils.join(outdatedEntityNames, ", ")
2630
//                            + ")";
2631
//                    message.setValue(msg);
2632
//                }
2633
//                return false;
2634
//            }
2635
//            return true;
2636
//        } catch (Exception ex) {
2637
//            LOGGER.warn("You cannot check that a commit can be done", ex);
2638
//            if (message != null) {
2639
//                String msg = i18n.getTranslation("_You_cannot_check_that_a_commit_can_be_done");
2640
//                message.setValue(msg);
2641
//            }
2642
//            return false;
2643
//        } finally {
2644
//            DisposeUtils.dispose(changesGroupedByEntity);
2645
//        }
2646
    }
2647

  
2648
    @Override
2649
    public int updateClean(String entityCode) {
2650
        return updateClean(entityCode, null);
2651
    }
2652

  
2653
    @Override
2654
    public int updateClean(String entityCode, SimpleTaskStatus status) {
2655
        OnlineEntity entity = this.getEntity(entityCode);
2656
        if (entity == null) {
2657
            return ERR_ENTITY_NOT_EXISTS;
2658
        }
2659
        if (status == null) {
2660
            status = ToolsLocator.getTaskStatusManager().createDefaultSimpleTaskStatus(
2661
                    "Update-clean " + entity.getEntityName()
2662
            );
2663
            status.setAutoremove(true);
2664
            status.add();
2665
        } else {
2666
            status.push();
2667
        }
2668
        try {
2669
            status.message("Deleting temporary remote changes (" + entity.getEntityName() + ")");
2670
            RemoteChangesTable remoteChangesTable = new RemoteChangesTable();
2671
            remoteChangesTable.delete(this, entityCode);
2672
            status.message("Delete temporary remote changes completed");
2673
            status.terminate();
2674
            return ERR_OK;
2675
        } catch (Exception ex) {
2676
            LOGGER.warn("Can't deleting temporary remote changes of " + entity.getEntityName() + ".", ex);
2677
            status.message("Can't deleting temporary remote changes of " + entity.getEntityName() + ".");
2678
            status.abort();
2679
            return ERR_CANT_UPDATE_CLEAN;
2680
        } finally {
2681
            status.pop();
2682
        }
2683

  
2684
    }
2685

  
2686
    @Override
2687
    public boolean canUpdate(MutableObject<String> message, String tableName) {
2688
        if( this.isOffline() ) {
2689
            return false;
2690
        }
2691
        I18nManager i18n = ToolsLocator.getI18nManager();
2692
        EntityRow lentity = this.getWorkspaceEntityByName(tableName);
2693
        if (lentity == null) {
2694
            if (message != null) {
2695
                String msg = i18n.getTranslation("_Cant_update_table_XtablaX_dont_exists",new String[] {tableName});
2696
                message.setValue(msg);
2697
            }
2698
            return false;
2699
        }
2700
        switch (this.getEditMode(lentity)) {
2701
            case FeatureStore.MODE_UNKNOWN:
2702
                // La tabla no existe en la copia de trabajo
2703
                if (message != null) {
2704
                    String msg = i18n.getTranslation("_Cant_update_table_XtablaX_dont_exists",new String[] {tableName});
2705
                    message.setValue(msg);
2706
                }
2707
                return false;
2708

  
2709
            case FeatureStore.MODE_FULLEDIT:
2710
            case FeatureStore.MODE_APPEND:
2711
            case FeatureStore.MODE_PASS_THROUGH:
2712
                LOGGER.info("Table '"+lentity.getEntityName()+"' is editing.");
2713
                if (message != null) {
2714
                    String msg = i18n.getTranslation("_Cant_update_table_XtablaX_are_in_edition",new String[] {tableName});
2715
                    message.setValue(msg);
2716
                }
2717
                return false;
2718
        }
2719
        return true;
2720
    }
2370 2721
    
2722
    private int getEditMode(OnlineEntity entity) {
2723
        FeatureStore userStore = null;
2724
        try {
2725
            userStore = this.openFeatureStore(entity);
2726
            if( userStore == null ) {
2727
                return FeatureStore.MODE_UNKNOWN;
2728
            }
2729
            return FeatureStoreObserver.getEditMode(userStore);
2730
        } finally {
2731
            DisposeUtils.dispose(userStore);
2732
        }
2733

  
2734
    }
2735
    
2736

  
2737
    @Override
2738
    public boolean updateNeedMerge(String entityName) {
2739
        if( this.isOffline() ) {
2740
            return false;
2741
        }
2742
        RemoteChangesTable remoteChangesTable = new RemoteChangesTable();
2743

  
2744
        OnlineEntity entity = this.getWorkspaceEntity(entityName);
2745

  
2746
        return remoteChangesTable.updateNeedMerge(this, entity.getEntityCode());
2747
    }
2748

  
2749
    @Override
2750
    public int update(String tableName, SimpleTaskStatus status) {
2751
        return this.update(tableName, false, status);
2752
    }
2753
    
2754
    public int update(String tableName, boolean merge, SimpleTaskStatus status) {
2755
        return update(tableName, merge, null, status);
2756
    }
2757

  
2758
    public int update(String tableName, boolean merge, MutableLong localChangesModifieds, SimpleTaskStatus status) {
2759
        if( this.isOffline() ) {
2760
            return ERR_OFFLINE;
2761
        }
2762
        if(localChangesModifieds == null){
2763
            localChangesModifieds = new MutableLong(0);
2764
        }
2765
        int errcode = ERR_NO_ERROR;
2766
        if (status == null) {
2767
            status = ToolsLocator.getTaskStatusManager().createDefaultSimpleTaskStatus(
2768
                    "Update " + tableName
2769
            );
2770
            status.setAutoremove(true);
2771
            status.add();
2772
        } else {
2773
            status.push();
2774
        }
2775
        LOGGER.debug("===: UPDATE " + this.getCode() + ", '" + this.getLabel() + "', " + tableName);
2776
        RemoteChangesTable remoteChangesTable = new RemoteChangesTable();
2777
        WorkspaceChangesTable localChangesTable = new WorkspaceChangesTable();
2778

  
2779
        EditableFeature ef;
2780
        DisposableFeatureSetIterable remoteChanges = null;
2781

  
2782
        FeatureStore workspaceChangesStore = null;
2783
        FeatureStore remoteChangesStore = null;
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff