Revision 3315

View differences:

org.gvsig.vcsgis/trunk/org.gvsig.vcsgis/org.gvsig.vcsgis.lib/org.gvsig.vcsgis.lib.api/src/main/java/org/gvsig/vcsgis/lib/VCSGisUser.java
51 51
    public List<String> getRolesAsList();
52 52
    
53 53
    public boolean hasRole(String roleid);
54

  
55
    public void copyFrom(VCSGisUser other);
54 56
}
org.gvsig.vcsgis/trunk/org.gvsig.vcsgis/org.gvsig.vcsgis.lib/org.gvsig.vcsgis.lib.api/src/main/java/org/gvsig/vcsgis/lib/repository/requests/VCSGisRequest.java
22 22
package org.gvsig.vcsgis.lib.repository.requests;
23 23

  
24 24
import org.gvsig.tools.dispose.Disposable;
25
import org.gvsig.vcsgis.lib.VCSGisUser;
25 26

  
26 27
/**
27 28
 *
org.gvsig.vcsgis/trunk/org.gvsig.vcsgis/org.gvsig.vcsgis.lib/org.gvsig.vcsgis.lib.api/src/main/java/org/gvsig/vcsgis/lib/repository/requests/VCSGisUsersRequest.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
package org.gvsig.vcsgis.lib.repository.requests;
23

  
24
import java.util.List;
25
import org.gvsig.vcsgis.lib.VCSGisUser;
26

  
27
/**
28
 *
29
 * @author gvSIG Team
30
 */
31
public interface VCSGisUsersRequest extends VCSGisRequest {
32

  
33
    public List<VCSGisUser> getUsers();
34
    
35
}
org.gvsig.vcsgis/trunk/org.gvsig.vcsgis/org.gvsig.vcsgis.lib/org.gvsig.vcsgis.lib.api/src/main/java/org/gvsig/vcsgis/lib/repository/requests/VCSGisCheckoutRequest.java
50 50

  
51 51
    public DisposableIterable<VCSGisRepositoryData> getData();
52 52
    
53
    public String getUsersHashCode();
54
    
55
    public String getTopologyPlansHashCode();
56
    
53 57
}
org.gvsig.vcsgis/trunk/org.gvsig.vcsgis/org.gvsig.vcsgis.lib/org.gvsig.vcsgis.lib.api/src/main/java/org/gvsig/vcsgis/lib/repository/VCSGisRepository.java
34 34
import org.gvsig.vcsgis.lib.repository.requests.VCSGisRowUpdateRequest;
35 35
import org.gvsig.vcsgis.lib.repository.requests.VCSGisUpdateRequest;
36 36
import org.gvsig.vcsgis.lib.repository.requests.VCSGisHistoryRequest;
37
import org.gvsig.vcsgis.lib.repository.requests.VCSGisTopologyPlansRequest;
38
import org.gvsig.vcsgis.lib.repository.requests.VCSGisUsersRequest;
37 39

  
38 40
/**
39 41
 *
......
72 74
    public void addObserver(String tableName, String type, String operation, String command);
73 75

  
74 76
    public VCSGisAuthenticateRequest createAuthenticateRequest(String userId, String password);
77
    
78
    public VCSGisTopologyPlansRequest createTopologyPlansRequest();
79

  
80
    public VCSGisUsersRequest createUsersRequest();
81
    
75 82
}
org.gvsig.vcsgis/trunk/org.gvsig.vcsgis/org.gvsig.vcsgis.lib/org.gvsig.vcsgis.lib.api/src/main/java/org/gvsig/vcsgis/lib/VCSGisTopologyPlan.java
21 21
 */
22 22
package org.gvsig.vcsgis.lib;
23 23

  
24
import java.sql.Timestamp;
24
import org.gvsig.json.SupportJson;
25 25
import org.gvsig.json.SupportToJson;
26 26
import org.gvsig.tools.util.LabeledValue;
27 27

  
org.gvsig.vcsgis/trunk/org.gvsig.vcsgis/org.gvsig.vcsgis.lib/org.gvsig.vcsgis.lib.api/src/main/java/org/gvsig/vcsgis/lib/server/VCSGisServerController.java
46 46
    
47 47
    public VCSGisServerHandler createRowDeleteHandler();
48 48
    
49
    public VCSGisServerHandler createUsersHandler();
50

  
51
    public VCSGisServerHandler createTopologyPlansHandler();
49 52
}
org.gvsig.vcsgis/trunk/org.gvsig.vcsgis/org.gvsig.vcsgis.lib/org.gvsig.vcsgis.lib.api/src/main/java/org/gvsig/vcsgis/lib/VCSGisManager.java
69 69
    public static final int ERR_AUTHENTICATION_EXPIRED = 22;
70 70
    public static final int ERR_INVALID_USERCODE = 23;
71 71

  
72
    public static final int ERR_CANT_RETRIEVE_USERS = 30;
73
    public static final int ERR_CANT_RETRIEVE_TOPOLOGYPLANS = 31;
74
    
72 75
    public static final int ERR_CANT_CREATE_TABLE = 100;
73 76
    public static final int ERR_CANT_CREATE_TABLE_CONFIG = 110;
74 77
    public static final int ERR_CANT_CREATE_TABLE_ENTITIES = 120;
org.gvsig.vcsgis/trunk/org.gvsig.vcsgis/org.gvsig.vcsgis.lib/org.gvsig.vcsgis.lib.impl/src/main/java/org/gvsig/vcsgis/lib/server/VCSGisServerControllerImpl.java
29 29
import org.gvsig.vcsgis.lib.server.handlers.RowCreateHandler;
30 30
import org.gvsig.vcsgis.lib.server.handlers.RowDeleteHandler;
31 31
import org.gvsig.vcsgis.lib.server.handlers.RowUpdateHandler;
32
import org.gvsig.vcsgis.lib.server.handlers.TopologyPlansHandler;
32 33
import org.gvsig.vcsgis.lib.server.handlers.UpdateHandler;
34
import org.gvsig.vcsgis.lib.server.handlers.UsersHandler;
33 35

  
34 36
/**
35 37
 *
......
95 97
        VCSGisServerHandler handler = new RowDeleteHandler(repository);
96 98
        return handler;
97 99
    }
100

  
101
    @Override
102
    public VCSGisServerHandler createUsersHandler() {
103
        VCSGisServerHandler handler = new UsersHandler(repository);
104
        return handler;
105
    }
106

  
107
    @Override
108
    public VCSGisServerHandler createTopologyPlansHandler() {
109
        VCSGisServerHandler handler = new TopologyPlansHandler(repository);
110
        return handler;
111
    }
112

  
98 113
}
org.gvsig.vcsgis/trunk/org.gvsig.vcsgis/org.gvsig.vcsgis.lib/org.gvsig.vcsgis.lib.impl/src/main/java/org/gvsig/vcsgis/lib/server/handlers/CheckoutHandler.java
106 106
            }
107 107

  
108 108
            gen.write("Entity", request.getEntity().toJson());
109
            gen.write("UsershashCode", request.getUsersHashCode());
110
            gen.write("TopologyPlansHashCode", request.getTopologyPlansHashCode());
109 111
            gen.writeEnd(); // Paramaters
110 112

  
111 113
            gen.writeStartArray("Data");
org.gvsig.vcsgis/trunk/org.gvsig.vcsgis/org.gvsig.vcsgis.lib/org.gvsig.vcsgis.lib.impl/src/main/java/org/gvsig/vcsgis/lib/server/handlers/TopologyPlansHandler.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.vcsgis.lib.server.handlers;
24

  
25
import java.io.IOException;
26
import java.io.InputStream;
27
import java.io.Writer;
28
import java.util.List;
29
import java.util.Map;
30
import org.apache.commons.io.IOUtils;
31
import org.apache.commons.lang3.mutable.MutableObject;
32
import org.gvsig.json.Json;
33
import org.gvsig.json.JsonArrayBuilder;
34
import org.gvsig.json.JsonObjectBuilder;
35
import static org.gvsig.vcsgis.lib.VCSGisManager.ERR_OK;
36
import org.gvsig.vcsgis.lib.VCSGisRuntimeException;
37
import org.gvsig.vcsgis.lib.VCSGisTopologyPlan;
38
import org.gvsig.vcsgis.lib.repository.VCSGisRepository;
39
import org.gvsig.vcsgis.lib.repository.requests.VCSGisRequest;
40
import org.gvsig.vcsgis.lib.repository.requests.VCSGisTopologyPlansRequest;
41

  
42
/**
43
 *
44
 * @author gvSIG Team
45
 */
46
public class TopologyPlansHandler extends AbstractVCSGisServertHandler {
47

  
48
    public TopologyPlansHandler(VCSGisRepository repository) {
49
        super(repository, "TopologyPlansHandler");
50
    }
51

  
52
    @Override
53
    protected void requestProducer(MutableObject<VCSGisRequest> req,Map<String,String> params, InputStream request_contents) throws IOException {
54
        LOGGER.debug("===: ["+this.getName()+"] requestProducer 1");
55
        final VCSGisTopologyPlansRequest request = this.getRepository().createTopologyPlansRequest();
56
        req.setValue(request);
57
        LOGGER.debug("===: ["+this.getName()+"] requestProducer 2 notifyRequestConsumers");
58
        notifyRequestConsumers();
59
        LOGGER.debug("===: ["+this.getName()+"] requestProducer 3 return");
60
    }
61
    
62
    @Override
63
    protected void responseProducer(VCSGisRequest req, Writer response_contents) throws IOException {
64
        LOGGER.debug("===: ["+this.getName()+"] responseProducer  1");
65
        VCSGisTopologyPlansRequest request = (VCSGisTopologyPlansRequest) req;
66
        if( request.execute()!=ERR_OK ) {
67
            LOGGER.debug("===: ["+this.getName()+"] responseProducer 2 error "+request.getLastErrorCode());
68
            throw new VCSGisRuntimeException(request.getLastErrorCode(), request.getLastErrorMessage());
69
        }
70
        
71
        LOGGER.debug("===: ["+this.getName()+"] responseProducer  3");
72
        List<VCSGisTopologyPlan> topologyPlans = request.getTopologyPlans();
73
        JsonArrayBuilder jsonTopologyPlans = Json.createArrayBuilder();
74
        for (VCSGisTopologyPlan topologyPlan : topologyPlans) {
75
            LOGGER.debug("===: ["+this.getName()+"] responseProducer  4 entity "+topologyPlan.getName());
76
            jsonTopologyPlans.add(topologyPlan.toJsonBuilder());
77
        }
78
        JsonObjectBuilder jsonResponse = Json.createObjectBuilder();
79
        jsonResponse.add("StatusCode", ERR_OK);
80
        jsonResponse.addNull("StatusMessage");
81
        jsonResponse.add("TopologyPlans", jsonTopologyPlans);
82
        
83
        LOGGER.debug("===: ["+this.getName()+"] responseProducer  5 notifyResponseConsumers");
84
        notifyResponseConsumers();
85
        
86
        LOGGER.debug("===: ["+this.getName()+"] responseProducer  6 write json");
87
        IOUtils.write(jsonResponse.toString(), response_contents);
88
        
89
        LOGGER.debug("===: ["+this.getName()+"] responseProducer  7 flush");
90
        response_contents.flush();
91
        
92
        LOGGER.debug("===: ["+this.getName()+"] responseProducer  8 close");
93
        IOUtils.closeQuietly(response_contents);
94
        
95
        LOGGER.debug("===: ["+this.getName()+"] responseProducer  9 return");
96
        
97
    }
98

  
99
}
org.gvsig.vcsgis/trunk/org.gvsig.vcsgis/org.gvsig.vcsgis.lib/org.gvsig.vcsgis.lib.impl/src/main/java/org/gvsig/vcsgis/lib/server/handlers/UsersHandler.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.vcsgis.lib.server.handlers;
24

  
25
import java.io.IOException;
26
import java.io.InputStream;
27
import java.io.Writer;
28
import java.util.List;
29
import java.util.Map;
30
import org.apache.commons.io.IOUtils;
31
import org.apache.commons.lang3.mutable.MutableObject;
32
import org.gvsig.json.Json;
33
import org.gvsig.json.JsonArrayBuilder;
34
import org.gvsig.json.JsonObjectBuilder;
35
import org.gvsig.vcsgis.lib.VCSGisEntity;
36
import static org.gvsig.vcsgis.lib.VCSGisManager.ERR_OK;
37
import org.gvsig.vcsgis.lib.VCSGisRuntimeException;
38
import org.gvsig.vcsgis.lib.VCSGisUser;
39
import org.gvsig.vcsgis.lib.repository.VCSGisRepository;
40
import org.gvsig.vcsgis.lib.repository.requests.VCSGisEntitiesRequest;
41
import org.gvsig.vcsgis.lib.repository.requests.VCSGisRequest;
42
import org.gvsig.vcsgis.lib.repository.requests.VCSGisUsersRequest;
43

  
44
/**
45
 *
46
 * @author gvSIG Team
47
 */
48
public class UsersHandler extends AbstractVCSGisServertHandler {
49

  
50
    public UsersHandler(VCSGisRepository repository) {
51
        super(repository, "UsersHandler");
52
    }
53

  
54
    @Override
55
    protected void requestProducer(MutableObject<VCSGisRequest> req,Map<String,String> params, InputStream request_contents) throws IOException {
56
        LOGGER.debug("===: ["+this.getName()+"] requestProducer 1");
57
        final VCSGisUsersRequest request = this.getRepository().createUsersRequest();
58
        req.setValue(request);
59
        LOGGER.debug("===: ["+this.getName()+"] requestProducer 2 notifyRequestConsumers");
60
        notifyRequestConsumers();
61
        LOGGER.debug("===: ["+this.getName()+"] requestProducer 3 return");
62
    }
63
    
64
    @Override
65
    protected void responseProducer(VCSGisRequest req, Writer response_contents) throws IOException {
66
        LOGGER.debug("===: ["+this.getName()+"] responseProducer  1");
67
        VCSGisUsersRequest request = (VCSGisUsersRequest) req;
68
        if( request.execute()!=ERR_OK ) {
69
            LOGGER.debug("===: ["+this.getName()+"] responseProducer 2 error "+request.getLastErrorCode());
70
            throw new VCSGisRuntimeException(request.getLastErrorCode(), request.getLastErrorMessage());
71
        }
72
        
73
        LOGGER.debug("===: ["+this.getName()+"] responseProducer  3");
74
        List<VCSGisUser> users = request.getUsers();
75
        JsonArrayBuilder jsonUsers = Json.createArrayBuilder();
76
        for (VCSGisUser user : users) {
77
            LOGGER.debug("===: ["+this.getName()+"] responseProducer  4 entity "+user.getIdentifier());
78
            jsonUsers.add(user.toJsonBuilder());
79
        }
80
        JsonObjectBuilder jsonResponse = Json.createObjectBuilder();
81
        jsonResponse.add("StatusCode", ERR_OK);
82
        jsonResponse.addNull("StatusMessage");
83
        jsonResponse.add("Users", jsonUsers);
84
        
85
        LOGGER.debug("===: ["+this.getName()+"] responseProducer  5 notifyResponseConsumers");
86
        notifyResponseConsumers();
87
        
88
        LOGGER.debug("===: ["+this.getName()+"] responseProducer  6 write json");
89
        IOUtils.write(jsonResponse.toString(), response_contents);
90
        
91
        LOGGER.debug("===: ["+this.getName()+"] responseProducer  7 flush");
92
        response_contents.flush();
93
        
94
        LOGGER.debug("===: ["+this.getName()+"] responseProducer  8 close");
95
        IOUtils.closeQuietly(response_contents);
96
        
97
        LOGGER.debug("===: ["+this.getName()+"] responseProducer  9 return");
98
        
99
    }
100

  
101
}
org.gvsig.vcsgis/trunk/org.gvsig.vcsgis/org.gvsig.vcsgis.lib/org.gvsig.vcsgis.lib.impl/src/main/java/org/gvsig/vcsgis/lib/VCSGisTopologyPlanImpl.java
37 37
    private String description;
38 38
    private String data;
39 39

  
40
    public VCSGisTopologyPlanImpl() {
41
        
42
    }
43
    
40 44
    public VCSGisTopologyPlanImpl(JsonObject jsonData) {
41 45
        this.topologyPlanCode = jsonData.getString("TopologyPlanCode", null);
42 46
        this.name = jsonData.getString("Name", null);
......
44 48
        this.data = jsonData.getString("Data", null);
45 49
    }
46 50

  
47

  
48 51
    @Override
49 52
    public String getTopologyPlanCode() {
50 53
        return this.topologyPlanCode;
org.gvsig.vcsgis/trunk/org.gvsig.vcsgis/org.gvsig.vcsgis.lib/org.gvsig.vcsgis.lib.impl/src/main/java/org/gvsig/vcsgis/lib/requests/UsersRequestHelper.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.vcsgis.lib.requests;
24

  
25
import java.util.List;
26
import org.gvsig.vcsgis.lib.VCSGisUser;
27
import org.gvsig.vcsgis.lib.repository.VCSGisRepository;
28
import org.gvsig.vcsgis.lib.repository.requests.VCSGisUsersRequest;
29

  
30
/**
31
 *
32
 * @author gvSIG Team
33
 */
34
public class UsersRequestHelper extends AbstractRequestHelper implements VCSGisUsersRequest {
35

  
36
    private static final String REQUEST_NAME = "Users";
37
    
38
    // in
39
    // (no imputs)
40
    
41
    // out
42
    public List<VCSGisUser> users;
43

  
44
    public UsersRequestHelper(VCSGisRepository repository) {
45
        super(repository, REQUEST_NAME);
46
        this.users = null;
47
    }
48

  
49
    @Override
50
    public List<VCSGisUser> getUsers() {
51
        if (this.users == null) {
52
            throw new IllegalStateException("The request needs to be executed before calling this method.");
53
        }
54
        return users;
55
    }
56

  
57
    @Override
58
    public void dispose() {
59
        super.dispose();
60
        this.users = null;
61
    }
62

  
63
}
org.gvsig.vcsgis/trunk/org.gvsig.vcsgis/org.gvsig.vcsgis.lib/org.gvsig.vcsgis.lib.impl/src/main/java/org/gvsig/vcsgis/lib/requests/AbstractRequestHelper.java
26 26
import java.time.LocalDateTime;
27 27
import java.time.ZoneOffset;
28 28
import static org.gvsig.vcsgis.lib.VCSGisManager.ERR_OK;
29
import org.gvsig.vcsgis.lib.VCSGisUser;
29 30
import org.gvsig.vcsgis.lib.VCSGisUtils;
30 31
import org.gvsig.vcsgis.lib.repository.VCSGisRepository;
32
import org.gvsig.vcsgis.lib.repository.localdb.tables.UsersRepoTable;
31 33
import org.slf4j.Logger;
32 34
import org.slf4j.LoggerFactory;
33 35

  
org.gvsig.vcsgis/trunk/org.gvsig.vcsgis/org.gvsig.vcsgis.lib/org.gvsig.vcsgis.lib.impl/src/main/java/org/gvsig/vcsgis/lib/requests/CheckoutRequestHelper.java
48 48
    // out
49 49
    public VCSGisEntityEditable entity;
50 50
    public DisposableIterable<VCSGisRepositoryData> data;
51
    public String usersHashCode;
52
    public String topologyPlansHashCode;
51 53

  
52 54
    public CheckoutRequestHelper(VCSGisRepository repository, String entityName) {
53 55
        super(repository, REQUEST_NAME);
......
104 106
    }
105 107

  
106 108
    @Override
109
    public String getUsersHashCode() {
110
        return this.usersHashCode;
111
    }
112

  
113
    @Override
114
    public String getTopologyPlansHashCode() {
115
        return this.topologyPlansHashCode;
116
    }
117
    
118
    @Override
107 119
    public void dispose() {
108 120
        super.dispose();
109 121
        DisposeUtils.disposeQuietly(this.data);
org.gvsig.vcsgis/trunk/org.gvsig.vcsgis/org.gvsig.vcsgis.lib/org.gvsig.vcsgis.lib.impl/src/main/java/org/gvsig/vcsgis/lib/requests/TopologyPlansRequestHelper.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.vcsgis.lib.requests;
24

  
25
import java.util.List;
26
import org.gvsig.vcsgis.lib.VCSGisTopologyPlan;
27
import org.gvsig.vcsgis.lib.repository.VCSGisRepository;
28
import org.gvsig.vcsgis.lib.repository.requests.VCSGisTopologyPlansRequest;
29

  
30
/**
31
 *
32
 * @author gvSIG Team
33
 */
34
public class TopologyPlansRequestHelper extends AbstractRequestHelper implements VCSGisTopologyPlansRequest {
35

  
36
    private static final String REQUEST_NAME = "TopologyPlans";
37
    
38
    // in
39
    // (no imputs)
40
    
41
    // out
42
    public List<VCSGisTopologyPlan> topologyplans;
43

  
44
    public TopologyPlansRequestHelper(VCSGisRepository repository) {
45
        super(repository, REQUEST_NAME);
46
        this.topologyplans = null;
47
    }
48

  
49
    @Override
50
    public List<VCSGisTopologyPlan> getTopologyPlans() {
51
        if (this.topologyplans == null) {
52
            throw new IllegalStateException("The request needs to be executed before calling this method.");
53
        }
54
        return topologyplans;
55
    }
56

  
57
    @Override
58
    public void dispose() {
59
        super.dispose();
60
        this.topologyplans = null;
61
    }
62

  
63
}
org.gvsig.vcsgis/trunk/org.gvsig.vcsgis/org.gvsig.vcsgis.lib/org.gvsig.vcsgis.lib.impl/src/main/java/org/gvsig/vcsgis/lib/repository/remoteclient/requests/UsersRequestClient.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.vcsgis.lib.repository.remoteclient.requests;
24

  
25
import java.io.BufferedReader;
26
import java.io.OutputStream;
27
import java.util.ArrayList;
28
import java.util.List;
29
import javax.json.Json;
30
import javax.json.JsonArray;
31
import javax.json.JsonObject;
32
import javax.json.JsonReader;
33
import javax.json.JsonValue;
34
import static org.gvsig.vcsgis.lib.VCSGisManager.ERR_CANT_COMMIT;
35
import static org.gvsig.vcsgis.lib.VCSGisManager.ERR_CANT_RETRIEVE_ENTITIES;
36
import static org.gvsig.vcsgis.lib.VCSGisManager.ERR_CANT_RETRIEVE_USERS;
37
import static org.gvsig.vcsgis.lib.VCSGisManager.ERR_OK;
38
import org.gvsig.vcsgis.lib.VCSGisUser;
39
import org.gvsig.vcsgis.lib.VCSGisUserImpl;
40
import static org.gvsig.vcsgis.lib.VCSGisUtils.getErrorMessage;
41
import org.gvsig.vcsgis.lib.repository.remoteclient.VCSGisRepositoryClient;
42
import org.gvsig.vcsgis.lib.repository.requests.VCSGisUsersRequest;
43
import org.gvsig.vcsgis.lib.requests.EntitiesRequestHelper;
44
import org.gvsig.vcsgis.lib.requests.UsersRequestHelper;
45

  
46
/**
47
 *
48
 * @author gvSIG Team
49
 */
50
public class UsersRequestClient extends AbstractRequestClient implements VCSGisUsersRequest {
51
    
52
    public UsersRequestClient(VCSGisRepositoryClient repository) {
53
        super(
54
                new EntitiesRequestHelper(repository),
55
                repository.getUrl("users")
56
        );
57
    }
58

  
59
    @Override
60
    public UsersRequestHelper helper() {
61
        return (UsersRequestHelper) super.helper(); 
62
    }
63

  
64
    @Override
65
    public List<VCSGisUser> getUsers() {
66
        return helper().getUsers();
67
    }
68

  
69
    @Override
70
    public void requestProducer(OutputStream out) {
71
       error(ERR_OK);
72
    }
73

  
74
    @Override
75
    public void responseConsumer(BufferedReader inputData) {
76
        try {
77
            LOGGER.debug("===: ["+this.getRequestName()+"] responseConsumer");
78
            List<VCSGisUser> theUsers = new ArrayList<>();
79
        
80
            JsonReader reader = Json.createReader(inputData);
81
            JsonObject jsonResponse = reader.readObject();
82
            
83
            int statusCode = jsonResponse.getInt("StatusCode", ERR_CANT_COMMIT);
84
            LOGGER.debug("===: ["+this.getRequestName()+"] responseConsumer status code "+statusCode);
85
            if( statusCode!=ERR_OK ) {
86
                error(
87
                        statusCode,
88
                        jsonResponse.getString("StatusMessage", getErrorMessage(statusCode))
89
                );
90
                return;
91
            }
92
            JsonArray jsonUsers = jsonResponse.getJsonArray("Users");
93
            LOGGER.debug("===: ["+this.getRequestName()+"] responseConsumer user " + jsonUsers.size());
94
            for (JsonValue x : jsonUsers) {
95
                VCSGisUserImpl user = new VCSGisUserImpl((JsonObject) x);
96
                LOGGER.debug("===: ["+this.getRequestName()+"] responseConsumer user "+user.getIdentifier());
97
                theUsers.add(user);
98
            }
99
            helper().users = theUsers;
100
            LOGGER.debug("===: ["+this.getRequestName()+"] responseConsumer ok");
101
            error(ERR_OK);
102
        } catch (Exception ex) {
103
            LOGGER.warn("Can't retrieve users from '"+this.getRequestUrl()+"'.",ex);
104
            error(ERR_CANT_RETRIEVE_USERS, "Can't retrieve users from '"+this.getRequestUrl()+"'.");
105
        }
106
    }
107

  
108
}
org.gvsig.vcsgis/trunk/org.gvsig.vcsgis/org.gvsig.vcsgis.lib/org.gvsig.vcsgis.lib.impl/src/main/java/org/gvsig/vcsgis/lib/repository/remoteclient/requests/EntitiesRequestClient.java
91 91
            JsonArray jsonEntities = jsonResponse.getJsonArray("Entities");
92 92
            LOGGER.debug("===: ["+this.getRequestName()+"] responseConsumer entitities " + jsonEntities.size());
93 93
            for (JsonValue x : jsonEntities) {
94
                VCSGisEntityEditable entity = new EntityEditableImpl();
95
                entity.fromJson((JsonObject) x);
94
                VCSGisEntityEditable entity = new EntityEditableImpl((JsonObject) x);
96 95
                LOGGER.debug("===: ["+this.getRequestName()+"] responseConsumer entity "+entity.getEntityName());
97 96
                theEntities.add(entity);
98 97
            }
org.gvsig.vcsgis/trunk/org.gvsig.vcsgis/org.gvsig.vcsgis.lib/org.gvsig.vcsgis.lib.impl/src/main/java/org/gvsig/vcsgis/lib/repository/remoteclient/requests/CheckoutRequestClient.java
103 103
    }
104 104

  
105 105
    @Override
106
    public String getUsersHashCode() {
107
        return this.helper().usersHashCode;
108
    }
109

  
110
    @Override
111
    public String getTopologyPlansHashCode() {
112
        return this.helper().topologyPlansHashCode;
113
    }
114
    
115
    @Override
106 116
    public void requestProducer(OutputStream out) {
107 117
        try {
108 118
            LOGGER.debug("===: ["+this.getRequestName()+"] requestProducer 1");
......
159 169
                                                jsonParams.getJsonObject("Entity")
160 170
                                        );
161 171
                                    }
172
                                    helper().usersHashCode = jsonParams.getString("UsershashCode",null);
173
                                    helper().topologyPlansHashCode = jsonParams.getString("TopologyPlansHashCode",null);
162 174
                                    notifyResponseConsumers();
163 175
                                    break;
164 176
                                case "/Data/?":
org.gvsig.vcsgis/trunk/org.gvsig.vcsgis/org.gvsig.vcsgis.lib/org.gvsig.vcsgis.lib.impl/src/main/java/org/gvsig/vcsgis/lib/repository/remoteclient/requests/TopologyPlansRequestClient.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.vcsgis.lib.repository.remoteclient.requests;
24

  
25
import java.io.BufferedReader;
26
import java.io.OutputStream;
27
import java.util.ArrayList;
28
import java.util.List;
29
import javax.json.Json;
30
import javax.json.JsonArray;
31
import javax.json.JsonObject;
32
import javax.json.JsonReader;
33
import javax.json.JsonValue;
34
import org.gvsig.vcsgis.lib.EntityEditableImpl;
35
import org.gvsig.vcsgis.lib.VCSGisEntity;
36
import org.gvsig.vcsgis.lib.VCSGisEntityEditable;
37
import static org.gvsig.vcsgis.lib.VCSGisManager.ERR_CANT_COMMIT;
38
import static org.gvsig.vcsgis.lib.VCSGisManager.ERR_CANT_RETRIEVE_TOPOLOGYPLANS;
39
import static org.gvsig.vcsgis.lib.VCSGisManager.ERR_OK;
40
import org.gvsig.vcsgis.lib.VCSGisTopologyPlan;
41
import org.gvsig.vcsgis.lib.VCSGisTopologyPlanImpl;
42
import static org.gvsig.vcsgis.lib.VCSGisUtils.getErrorMessage;
43
import org.gvsig.vcsgis.lib.repository.remoteclient.VCSGisRepositoryClient;
44
import org.gvsig.vcsgis.lib.repository.requests.VCSGisTopologyPlansRequest;
45
import org.gvsig.vcsgis.lib.requests.TopologyPlansRequestHelper;
46

  
47
/**
48
 *
49
 * @author gvSIG Team
50
 */
51
public class TopologyPlansRequestClient extends AbstractRequestClient implements VCSGisTopologyPlansRequest {
52
    
53
    public TopologyPlansRequestClient(VCSGisRepositoryClient repository) {
54
        super(
55
                new TopologyPlansRequestHelper(repository),
56
                repository.getUrl("topologyplans")
57
        );
58
    }
59

  
60
    @Override
61
    public TopologyPlansRequestHelper helper() {
62
        return (TopologyPlansRequestHelper) super.helper(); 
63
    }
64

  
65
    @Override
66
    public List<VCSGisTopologyPlan> getTopologyPlans() {
67
        return helper().getTopologyPlans();
68
    }
69
    
70
    @Override
71
    public void requestProducer(OutputStream out) {
72
       error(ERR_OK);
73
    }
74

  
75
    @Override
76
    public void responseConsumer(BufferedReader inputData) {
77
        try {
78
            LOGGER.debug("===: ["+this.getRequestName()+"] responseConsumer");
79
            List<VCSGisTopologyPlan> theTopologyPlans = new ArrayList<>();
80
        
81
            JsonReader reader = Json.createReader(inputData);
82
            JsonObject jsonResponse = reader.readObject();
83
            
84
            int statusCode = jsonResponse.getInt("StatusCode", ERR_CANT_COMMIT);
85
            LOGGER.debug("===: ["+this.getRequestName()+"] responseConsumer status code "+statusCode);
86
            if( statusCode!=ERR_OK ) {
87
                error(
88
                        statusCode,
89
                        jsonResponse.getString("StatusMessage", getErrorMessage(statusCode))
90
                );
91
                return;
92
            }
93
            JsonArray jsonTopologyPlans = jsonResponse.getJsonArray("TopologyPlans");
94
            LOGGER.debug("===: ["+this.getRequestName()+"] responseConsumer TopologyPlans " + jsonTopologyPlans.size());
95
            for (JsonValue x : jsonTopologyPlans) {
96
                VCSGisTopologyPlan topologyPlan = new VCSGisTopologyPlanImpl((JsonObject) x);
97
                LOGGER.debug("===: ["+this.getRequestName()+"] responseConsumer TopologyPlans "+topologyPlan.getName());
98
                theTopologyPlans.add(topologyPlan);
99
            }
100
            helper().topologyplans = theTopologyPlans;
101
            LOGGER.debug("===: ["+this.getRequestName()+"] responseConsumer ok");
102
            error(ERR_OK);
103
        } catch (Exception ex) {
104
            LOGGER.warn("Can't retrieve topology plans from '"+this.getRequestUrl()+"'.",ex);
105
            error(ERR_CANT_RETRIEVE_TOPOLOGYPLANS, "Can't retrieve topology plans from '"+this.getRequestUrl()+"'.");
106
        }
107
    }
108

  
109
}
org.gvsig.vcsgis/trunk/org.gvsig.vcsgis/org.gvsig.vcsgis.lib/org.gvsig.vcsgis.lib.impl/src/main/java/org/gvsig/vcsgis/lib/repository/remoteclient/VCSGisRepositoryClient.java
38 38
import org.gvsig.vcsgis.lib.repository.remoteclient.requests.RowCreateRequestClient;
39 39
import org.gvsig.vcsgis.lib.repository.remoteclient.requests.RowDeleteRequestClient;
40 40
import org.gvsig.vcsgis.lib.repository.remoteclient.requests.RowUpdateRequestClient;
41
import org.gvsig.vcsgis.lib.repository.remoteclient.requests.TopologyPlansRequestClient;
41 42
import org.gvsig.vcsgis.lib.repository.remoteclient.requests.UpdateRequestClient;
43
import org.gvsig.vcsgis.lib.repository.remoteclient.requests.UsersRequestClient;
42 44
import org.gvsig.vcsgis.lib.repository.requests.VCSGisAuthenticateRequest;
43 45
import org.gvsig.vcsgis.lib.repository.requests.VCSGisCheckoutRequest;
44 46
import org.gvsig.vcsgis.lib.repository.requests.VCSGisCommitRequest;
......
48 50
import org.gvsig.vcsgis.lib.repository.requests.VCSGisRowUpdateRequest;
49 51
import org.gvsig.vcsgis.lib.repository.requests.VCSGisUpdateRequest;
50 52
import org.gvsig.vcsgis.lib.repository.requests.VCSGisHistoryRequest;
53
import org.gvsig.vcsgis.lib.repository.requests.VCSGisTopologyPlansRequest;
54
import org.gvsig.vcsgis.lib.repository.requests.VCSGisUsersRequest;
51 55

  
52 56

  
53 57

  
......
216 220
        return null; // TODO: Implements remote request Authenticate
217 221
    }
218 222

  
223
    @Override
224
    public VCSGisTopologyPlansRequest createTopologyPlansRequest() {
225
        VCSGisTopologyPlansRequest request = new TopologyPlansRequestClient(this);
226
        return request;
227
    }
228

  
229
    @Override
230
    public VCSGisUsersRequest createUsersRequest() {
231
        VCSGisUsersRequest request = new UsersRequestClient(this);
232
        return request;
233
    }
234

  
219 235
}
org.gvsig.vcsgis/trunk/org.gvsig.vcsgis/org.gvsig.vcsgis.lib/org.gvsig.vcsgis.lib.impl/src/main/java/org/gvsig/vcsgis/lib/repository/localdb/tables/UsersRepoTable.java
1 1
package org.gvsig.vcsgis.lib.repository.localdb.tables;
2 2

  
3
import java.security.MessageDigest;
3 4
import java.util.List;
4 5
import javax.json.JsonObject;
6
import org.apache.commons.codec.binary.Hex;
5 7
import org.gvsig.fmap.dal.DALLocator;
6 8
import org.gvsig.fmap.dal.DataManager;
7 9
import org.gvsig.fmap.dal.feature.EditableFeatureType;
8 10
import org.gvsig.fmap.dal.feature.Feature;
11
import org.gvsig.fmap.dal.feature.FeatureSet;
12
import org.gvsig.fmap.dal.feature.FeatureSet.DisposableFeatureSetIterable;
9 13
import org.gvsig.fmap.dal.feature.FeatureStore;
10 14
import org.gvsig.fmap.dal.feature.FeatureType;
11 15
import org.gvsig.json.JsonObjectBuilder;
......
15 19
import org.gvsig.vcsgis.lib.VCSGisUser;
16 20
import org.gvsig.vcsgis.lib.VCSGisUserEditable;
17 21
import org.gvsig.vcsgis.lib.VCSGisUserImpl;
22
import static org.gvsig.vcsgis.lib.VCSGisUtils.updateMessageDigest;
18 23
import org.gvsig.vcsgis.lib.repository.localdb.VCSGisRepositoryLocaldb;
19 24

  
20 25
/**
......
144 149
        }
145 150

  
146 151
        @Override
152
        public void copyFrom(VCSGisUser other) {
153
            VCSGisUserImpl.copyUser(other, this);
154
        }
155
        
156
        @Override
147 157
        public List<String> getRolesAsList() {
148 158
            if (this.roles_list == null) {
149 159
                this.roles_list = VCSGisUserImpl.getRolesAsList(this);
......
213 223
        }
214 224
    }
215 225

  
226
    public DisposableFeatureSetIterable getAll(VCSGisRepositoryLocaldb repository) {
227
        FeatureStore store = null;
228
        try {
229
            store = repository.getFeatureStore(TABLE_NAME);
230
            FeatureSet.DisposableFeatureSetIterable changes = store.getFeatureSet().iterable();
231
            return changes;
232
        } catch (Exception ex) {
233
            throw new RuntimeException("Can't retrieve all users.", ex);
234
        } finally {
235
            if( store!=null ) {
236
                DisposeUtils.dispose(store);
237
            }
238
        }
239
    }
240
    
241
    public String getHashCode(VCSGisRepositoryLocaldb repository) {
242
        FeatureStore store = null;
243
        DisposableFeatureSetIterable changes = null;
244
        try {
245
            MessageDigest md = MessageDigest.getInstance("MD5");
246
            store = repository.getFeatureStore(TABLE_NAME);
247
            changes = store.getFeatureSet().iterable();
248
            for (Feature change : changes) {
249
                updateMessageDigest(md, change, COD_USER);
250
                updateMessageDigest(md, change, USER_ID);
251
//                updateMessageDigest(md, change, USER_PASSWORD);
252
                updateMessageDigest(md, change, USER_ROLES);
253
                updateMessageDigest(md, change, USER_DESCRIPTION);
254
            }
255
            String hash = Hex.encodeHexString(md.digest());
256
            return hash;
257
        } catch (Exception ex) {
258
            throw new RuntimeException("Can't retrieve hash of users.", ex);
259
        } finally {
260
            DisposeUtils.dispose(changes);
261
            DisposeUtils.dispose(store);
262
        }
263
    }
264
    
216 265
}
org.gvsig.vcsgis/trunk/org.gvsig.vcsgis/org.gvsig.vcsgis.lib/org.gvsig.vcsgis.lib.impl/src/main/java/org/gvsig/vcsgis/lib/repository/localdb/tables/TopologyplanRepoTable.java
1 1
package org.gvsig.vcsgis.lib.repository.localdb.tables;
2 2

  
3
import java.security.MessageDigest;
4
import javax.json.JsonObject;
5
import org.apache.commons.codec.binary.Hex;
3 6
import org.gvsig.fmap.dal.DALLocator;
4 7
import org.gvsig.fmap.dal.DataManager;
5 8
import org.gvsig.fmap.dal.feature.EditableFeatureType;
6 9
import org.gvsig.fmap.dal.feature.Feature;
10
import org.gvsig.fmap.dal.feature.FeatureSet.DisposableFeatureSetIterable;
7 11
import org.gvsig.fmap.dal.feature.FeatureStore;
8 12
import org.gvsig.fmap.dal.feature.FeatureType;
13
import org.gvsig.json.JsonObjectBuilder;
9 14
import org.gvsig.tools.dataTypes.DataTypes;
10 15
import org.gvsig.tools.dispose.DisposeUtils;
11 16
import org.gvsig.tools.dynform.spi.DynFormSPIManager;
17
import org.gvsig.vcsgis.lib.VCSGisTopologyPlan;
18
import org.gvsig.vcsgis.lib.VCSGisTopologyPlanImpl;
19
import static org.gvsig.vcsgis.lib.VCSGisUtils.updateMessageDigest;
12 20
import org.gvsig.vcsgis.lib.repository.localdb.VCSGisRepositoryLocaldb;
21
import static org.gvsig.vcsgis.lib.repository.localdb.tables.UsersRepoTable.COD_USER;
22
import static org.gvsig.vcsgis.lib.repository.localdb.tables.UsersRepoTable.USER_ID;
13 23

  
14 24
/**
15 25
 *
......
24 34
    public static final String TOPPLAN_NAME = "TOPP_NAME";
25 35
    private static final String TOPPLAN_DESCRIPTION = "TOPP_DESCRIPTION";
26 36
    private static final String TOPPLAN_DATA = "TOPP_DATA";
27
    
37

  
38
    public static class TopologyplanRow extends AbstractRow implements VCSGisTopologyPlan {
39

  
40
        public TopologyplanRow(VCSGisRepositoryLocaldb repository) {
41
            super(repository, TABLE_NAME, COD_TOPOLOGYPLAN, null);
42
        }
43

  
44
        public TopologyplanRow(VCSGisRepositoryLocaldb repository, Feature feature) {
45
            super(repository, TABLE_NAME, COD_TOPOLOGYPLAN, feature);
46
        }
47

  
48
        @Override
49
        public String getTopologyPlanCode() {
50
            return this.getString(COD_TOPOLOGYPLAN);
51
        }
52

  
53
        @Override
54
        public String getName() {
55
            return this.getString(TOPPLAN_NAME);
56
        }
57

  
58
        @Override
59
        public String getDescription() {
60
            return this.getString(TOPPLAN_DESCRIPTION);
61
        }
62

  
63
        @Override
64
        public String getData() {
65
            return this.getString(TOPPLAN_DATA);
66
        }
67

  
68
        @Override
69
        public String getLabel() {
70
            return this.getName();
71
        }
72

  
73
        @Override
74
        public VCSGisTopologyPlan getValue() {
75
            return this;
76
        }
77

  
78
        @Override
79
        public void copyFrom(VCSGisTopologyPlan other) {
80
            this.set(COD_TOPOLOGYPLAN,other.getTopologyPlanCode());
81
            this.set(TOPPLAN_NAME,other.getName());
82
            this.set(TOPPLAN_DESCRIPTION,other.getDescription());
83
            this.set(TOPPLAN_DATA,other.getData());
84
        }
85

  
86
        @Override
87
        public JsonObject toJson() {
88
            return this.toJsonBuilder().build();
89
        }
90

  
91
        @Override
92
        public JsonObjectBuilder toJsonBuilder() {
93
            return VCSGisTopologyPlanImpl.toJsonBuilder(this);
94
        }
95

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

  
101
    }
102

  
28 103
    public static final FeatureType featureType() {
29 104
        DataManager dataManager = DALLocator.getDataManager();
30 105
        EditableFeatureType ft = dataManager.createFeatureType();
......
51 126
                .setDataProfileName("Text")
52 127
                .setSize(10240)
53 128
                .setLabel("Serialized topology plan in json.");
54
        
129

  
55 130
        return ft.getNotEditableCopy();
56 131
    }
57
    
132

  
58 133
    public TopologyplanRepoTable() {
59 134
        super(TABLE_NAME, featureType());
60 135
    }
......
63 138
        FeatureStore store = null;
64 139
        try {
65 140
            store = repository.getFeatureStore(TABLE_NAME);
66
            Feature f = store.findFirst("\""+COD_TOPOLOGYPLAN+"\"='"+topologyPlanCode+"'");
67
            if( f==null ) {
141
            Feature f = store.findFirst("\"" + COD_TOPOLOGYPLAN + "\"='" + topologyPlanCode + "'");
142
            if (f == null) {
68 143
                return null;
69 144
            }
70 145
            return f.getString(TOPPLAN_DATA);
71 146
        } catch (Exception ex) {
72
            throw new RuntimeException("Can't retrieve topology plan '"+topologyPlanCode+"'.", ex);
147
            throw new RuntimeException("Can't retrieve topology plan '" + topologyPlanCode + "'.", ex);
73 148
        } finally {
74 149
            DisposeUtils.disposeQuietly(store);
75 150
        }
76 151
    }
77 152
    
153
    public DisposableFeatureSetIterable getAll(VCSGisRepositoryLocaldb repository) {
154
        FeatureStore store = null;
155
        try {
156
            store = repository.getFeatureStore(TABLE_NAME);
157
            DisposableFeatureSetIterable changes = store.getFeatureSet().iterable();
158
            return changes;
159
        } catch (Exception ex) {
160
            throw new RuntimeException("Can't retrieve all topology plans.", ex);
161
        } finally {
162
            if( store!=null ) {
163
                DisposeUtils.dispose(store);
164
            }
165
        }
166
    }
167
    
168
    public String getHashCode(VCSGisRepositoryLocaldb repository) {
169
        FeatureStore store = null;
170
        DisposableFeatureSetIterable changes = null;
171
        try {
172
            MessageDigest md = MessageDigest.getInstance("MD5");
173
            store = repository.getFeatureStore(TABLE_NAME);
174
            changes = store.getFeatureSet().iterable();
175
            for (Feature change : changes) {
176
                updateMessageDigest(md, change, COD_TOPOLOGYPLAN);
177
                updateMessageDigest(md, change, TOPPLAN_NAME);
178
                updateMessageDigest(md, change, TOPPLAN_DESCRIPTION);
179
                updateMessageDigest(md, change, TOPPLAN_DATA);
180
            }
181
            String hash = Hex.encodeHexString(md.digest());
182
            return hash;
183
        } catch (Exception ex) {
184
            throw new RuntimeException("Can't retrieve hash of topology plans.", ex);
185
        } finally {
186
            DisposeUtils.dispose(changes);
187
            DisposeUtils.dispose(store);
188
        }
189
    }
78 190
}
org.gvsig.vcsgis/trunk/org.gvsig.vcsgis/org.gvsig.vcsgis.lib/org.gvsig.vcsgis.lib.impl/src/main/java/org/gvsig/vcsgis/lib/repository/localdb/requests/CheckoutRequestLocaldb.java
37 37
import org.gvsig.vcsgis.lib.repository.localdb.tables.EntitiesRepoTable.EntityRepoRow;
38 38
import org.gvsig.vcsgis.lib.repository.localdb.tables.RevisionsRepoTable;
39 39
import org.gvsig.vcsgis.lib.repository.localdb.tables.RevisionsRepoTable.RevisionRepoRow;
40
import org.gvsig.vcsgis.lib.repository.localdb.tables.TopologyplanRepoTable;
41
import org.gvsig.vcsgis.lib.repository.localdb.tables.UsersRepoTable;
40 42
import org.gvsig.vcsgis.lib.repository.requests.VCSGisCheckoutRequest;
41 43
import org.gvsig.vcsgis.lib.requests.CheckoutRequestHelper;
42 44

  
......
96 98
    }
97 99

  
98 100
    @Override
101
    public String getUsersHashCode() {
102
        return this.helper().usersHashCode;
103
    }
104

  
105
    @Override
106
    public String getTopologyPlansHashCode() {
107
        return this.helper().topologyPlansHashCode;
108
    }
109
    
110
    @Override
99 111
    public int execute() {
100
        if( !this.isAuthorized() ) {
101
            return this.getLastErrorCode();
102
        }
103 112
        EntitiesRepoTable entitiesTable = new EntitiesRepoTable();
104 113
        EntityRepoRow entityRow = entitiesTable.getByEntityName(
105 114
                this.getRepository(), 
......
108 117
        if (entityRow == null) {
109 118
            return error(ERR_ENTITY_NOT_EXISTS,"Entity '"+helper().entityName+"' not exists.");
110 119
        }
120
        if( !this.isAuthorized(entityRow) ) {
121
            return this.getLastErrorCode();
122
        }
111 123
        helper().entity = new EntityEditableImpl();
112 124
        helper().entity.copyfrom(entityRow);
113 125

  
......
133 145
                    revisionNumber
134 146
            );
135 147
        }
136
            
148

  
149
        helper().usersHashCode = new UsersRepoTable().getHashCode(this.getRepository());
150
        helper().topologyPlansHashCode = new TopologyplanRepoTable().getHashCode(this.getRepository());
151
        
137 152
        helper().data = new DisposableIterableAdapter<>(
138 153
                features, 
139 154
                (Feature f) -> new DataRepoTable.DataRepoRow(this.getRepository(),f)
org.gvsig.vcsgis/trunk/org.gvsig.vcsgis/org.gvsig.vcsgis.lib/org.gvsig.vcsgis.lib.impl/src/main/java/org/gvsig/vcsgis/lib/repository/localdb/requests/CommitRequestLocaldb.java
27 27
import java.util.HashMap;
28 28
import java.util.List;
29 29
import java.util.Map;
30
import org.apache.commons.collections.CollectionUtils;
30 31
import org.apache.commons.lang3.StringUtils;
31 32
import org.gvsig.fmap.dal.feature.EditableFeature;
32 33
import org.gvsig.fmap.dal.feature.FeatureStore;
......
168 169
            EntitiesRepoTable entitiesTable = new EntitiesRepoTable();
169 170
            Map<String, EntityRepoRow> repositoryEntities = entitiesTable.getAllAsMap(this.getRepository());
170 171
            
172
            if( CollectionUtils.isNotEmpty(helper().newLocalEntities) && !this.isAuthorized("add") ) {
173
                return this.getLastErrorCode();
174
            }
171 175
            for (String newLocalEntityCode : helper().newLocalEntities) {
172 176
                VCSGisEntity entity = repositoryEntities.get(newLocalEntityCode);
173 177
                if( entity != null ) {
......
194 198
                if( !StringUtils.equalsIgnoreCase(entity.getRepositoryRevisionCode(), changedLocalEntity.getLocalRevisionCode()) ) {
195 199
                    return error(ERR_CANT_COMMIT_WORKSPACE_OUTDATED, "Revision 'REVISION["+changedLocalEntity.getLocalRevisionCode()+"]' in 'ENTITY["+changedLocalEntity.getEntityCode()+"]' not in head, workspace out of date.");
196 200
                }
201
                if( !this.isAuthorized(entity) ) {
202
                    return this.getLastErrorCode();            
203
                }
197 204
            }
198 205
            
199 206
            VCSGisRepositoryLocaldb repository = (VCSGisRepositoryLocaldb) helper().getRepository();
org.gvsig.vcsgis/trunk/org.gvsig.vcsgis/org.gvsig.vcsgis.lib/org.gvsig.vcsgis.lib.impl/src/main/java/org/gvsig/vcsgis/lib/repository/localdb/requests/RowDeleteRequestLocaldb.java
115 115

  
116 116
    @Override
117 117
    public int execute() {
118
        if( !this.isAuthorized() ) {
119
            return this.getLastErrorCode();
120
        }
121 118
        FeatureStore entitiesStore = null;
122 119
        FeatureStore revisionsStore = null;
123 120
        FeatureStore dataStore = null;
......
131 128
            if( entity == null ) {
132 129
                return error(VCSGisManager.ERR_ENTITY_NOT_EXISTS, "Entity '"+this.getEntityName()+"' not exists.");
133 130
            }
131
            if( !this.isAuthorized(entity) ) {
132
                return this.getLastErrorCode();
133
            }
134 134
            if( !StringUtils.equalsIgnoreCase(entity.getRepositoryRevisionCode(), this.getLocalRevisionCode()) ) {
135 135
                return error(ERR_CANT_COMMIT_WORKSPACE_OUTDATED, "Revision 'REVISION["+this.getLocalRevisionCode()+"]' in 'ENTITY["+this.getEntityName()+"]' not is head revision 'REVISION["+entity.getRepositoryRevisionCode()+"]', workspace out of date.");
136 136
            }
org.gvsig.vcsgis/trunk/org.gvsig.vcsgis/org.gvsig.vcsgis.lib/org.gvsig.vcsgis.lib.impl/src/main/java/org/gvsig/vcsgis/lib/repository/localdb/requests/RowUpdateRequestLocaldb.java
124 124

  
125 125
    @Override
126 126
    public int execute() {
127
        if( !this.isAuthorized() ) {
128
            return this.getLastErrorCode();
129
        }
130 127
        FeatureStore entitiesStore = null;
131 128
        FeatureStore revisionsStore = null;
132 129
        FeatureStore dataStore = null;
......
140 137
            if( entity == null ) {
141 138
                return error(VCSGisManager.ERR_ENTITY_NOT_EXISTS, "Entity '"+this.getEntityName()+"' not exists.");
142 139
            }
140
            if( !this.isAuthorized(entity) ) {
141
                return this.getLastErrorCode();
142
            }
143 143
            if( !StringUtils.equalsIgnoreCase(entity.getRepositoryRevisionCode(), this.getLocalRevisionCode()) ) {
144 144
                return error(ERR_CANT_COMMIT_WORKSPACE_OUTDATED, "Revision 'REVISION["+this.getLocalRevisionCode()+"]' in 'ENTITY["+this.getEntityName()+"]' not is head revision 'REVISION["+entity.getRepositoryRevisionCode()+"]', workspace out of date.");
145 145
            }
org.gvsig.vcsgis/trunk/org.gvsig.vcsgis/org.gvsig.vcsgis.lib/org.gvsig.vcsgis.lib.impl/src/main/java/org/gvsig/vcsgis/lib/repository/localdb/requests/TopologyPlansRequestLocaldb.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.vcsgis.lib.repository.localdb.requests;
24

  
25
import java.util.ArrayList;
26
import java.util.List;
27
import org.gvsig.fmap.dal.feature.Feature;
28
import org.gvsig.fmap.dal.feature.FeatureSet.DisposableFeatureSetIterable;
29
import org.gvsig.tools.dispose.DisposeUtils;
30
import org.gvsig.vcsgis.lib.EntityEditableImpl;
31
import org.gvsig.vcsgis.lib.VCSGisEntityEditable;
32
import static org.gvsig.vcsgis.lib.VCSGisManager.ERR_CANT_RETRIEVE_ENTITIES;
33
import static org.gvsig.vcsgis.lib.VCSGisManager.ERR_CANT_RETRIEVE_TOPOLOGYPLANS;
34
import static org.gvsig.vcsgis.lib.VCSGisManager.ERR_NO_ERROR;
35
import org.gvsig.vcsgis.lib.VCSGisTopologyPlan;
36
import org.gvsig.vcsgis.lib.VCSGisTopologyPlanImpl;
37
import org.gvsig.vcsgis.lib.repository.localdb.VCSGisRepositoryLocaldb;
38
import org.gvsig.vcsgis.lib.repository.localdb.tables.EntitiesRepoTable;
39
import org.gvsig.vcsgis.lib.repository.localdb.tables.TopologyplanRepoTable;
40
import org.gvsig.vcsgis.lib.repository.localdb.tables.TopologyplanRepoTable.TopologyplanRow;
41
import org.gvsig.vcsgis.lib.repository.requests.VCSGisTopologyPlansRequest;
42
import org.gvsig.vcsgis.lib.requests.TopologyPlansRequestHelper;
43

  
44
/**
45
 *
46
 * @author gvSIG Team
47
 */
48
public class TopologyPlansRequestLocaldb extends AbstractRequestLocaldb implements VCSGisTopologyPlansRequest {
49
    
50
    public TopologyPlansRequestLocaldb(VCSGisRepositoryLocaldb repository) {
51
        super(new TopologyPlansRequestHelper(repository));
52
    }
53

  
54
    @Override
55
    public TopologyPlansRequestHelper helper() {
56
        return (TopologyPlansRequestHelper) super.helper(); 
57
    }
58

  
59
    @Override
60
    public List<VCSGisTopologyPlan> getTopologyPlans() {
61
        return helper().getTopologyPlans();
62
    }
63

  
64
    @Override
65
    public int execute() {
66
        if( !this.isAuthorized() ) {
67
            return this.getLastErrorCode();
68
        }
69
        DisposableFeatureSetIterable topologyPlansTable_it=null;
70
        try {
71
            TopologyplanRepoTable topologyPlansTable = new TopologyplanRepoTable();
72

  
73
            List<VCSGisTopologyPlan> list = new ArrayList<>();
74
            topologyPlansTable_it = topologyPlansTable.getAll(this.getRepository());
75
            for (Feature ftopologyPlan : topologyPlansTable_it) {
76
                VCSGisTopologyPlan topologyPlan = new VCSGisTopologyPlanImpl();
77
                topologyPlan.copyFrom(new TopologyplanRow(this.getRepository(), ftopologyPlan));
78
                list.add(topologyPlan);
79
            }
80
            helper().topologyplans = list;
81
            return error(ERR_NO_ERROR);
82
            
83
        } catch (Exception ex) {
84
            LOGGER.warn("Can't retrieve topology plans from '"+getRepository().getLabel()+"'.",ex);
85
            return error(ERR_CANT_RETRIEVE_TOPOLOGYPLANS, "Can't retrieve topology plans from '"+getRepository().getLabel()+"'.");
86
        } finally {
87
            DisposeUtils.disposeQuietly(topologyPlansTable_it);
88
        }
89
    }
90

  
91
}
org.gvsig.vcsgis/trunk/org.gvsig.vcsgis/org.gvsig.vcsgis.lib/org.gvsig.vcsgis.lib.impl/src/main/java/org/gvsig/vcsgis/lib/repository/localdb/requests/RowCreateRequestLocaldb.java
131 131

  
132 132
    @Override
133 133
    public int execute() {
134
        if( !this.isAuthorized() ) {
135
            return this.getLastErrorCode();
136
        }
137 134
        FeatureStore entitiesStore = null;
138 135
        FeatureStore revisionsStore = null;
139 136
        FeatureStore dataStore = null;
......
146 143
            if( entity == null ) {
147 144
                return error(ERR_ENTITY_NOT_EXISTS, "Entity '"+this.getEntityName()+"' not exists.");
148 145
            }
146
            if( !this.isAuthorized(entity) ) {
147
                return this.getLastErrorCode();
148
            }
149 149
            if( !StringUtils.equalsIgnoreCase(entity.getRepositoryRevisionCode(), this.getLocalRevisionCode()) ) {
150 150
                return error(ERR_CANT_COMMIT_WORKSPACE_OUTDATED, "Revision 'REVISION["+this.getLocalRevisionCode()+"]' in 'ENTITY["+this.getEntityName()+"]' not is head revision 'REVISION["+entity.getRepositoryRevisionCode()+"]', workspace out of date.");
151 151
            }
org.gvsig.vcsgis/trunk/org.gvsig.vcsgis/org.gvsig.vcsgis.lib/org.gvsig.vcsgis.lib.impl/src/main/java/org/gvsig/vcsgis/lib/repository/localdb/requests/UsersRequestLocaldb.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.vcsgis.lib.repository.localdb.requests;
24

  
25
import java.util.ArrayList;
26
import java.util.List;
27
import org.gvsig.fmap.dal.feature.Feature;
28
import org.gvsig.fmap.dal.feature.FeatureSet.DisposableFeatureSetIterable;
29
import org.gvsig.tools.dispose.DisposeUtils;
30
import static org.gvsig.vcsgis.lib.VCSGisManager.ERR_CANT_RETRIEVE_ENTITIES;
31
import static org.gvsig.vcsgis.lib.VCSGisManager.ERR_CANT_RETRIEVE_USERS;
32
import static org.gvsig.vcsgis.lib.VCSGisManager.ERR_NO_ERROR;
33
import org.gvsig.vcsgis.lib.VCSGisTopologyPlan;
34
import org.gvsig.vcsgis.lib.VCSGisTopologyPlanImpl;
35
import org.gvsig.vcsgis.lib.VCSGisUser;
36
import org.gvsig.vcsgis.lib.VCSGisUserImpl;
37
import org.gvsig.vcsgis.lib.repository.localdb.VCSGisRepositoryLocaldb;
38
import org.gvsig.vcsgis.lib.repository.localdb.tables.TopologyplanRepoTable;
39
import org.gvsig.vcsgis.lib.repository.localdb.tables.TopologyplanRepoTable.TopologyplanRow;
40
import org.gvsig.vcsgis.lib.repository.localdb.tables.UsersRepoTable;
41
import org.gvsig.vcsgis.lib.repository.localdb.tables.UsersRepoTable.UserRow;
42
import org.gvsig.vcsgis.lib.repository.requests.VCSGisUsersRequest;
43
import org.gvsig.vcsgis.lib.requests.TopologyPlansRequestHelper;
44
import org.gvsig.vcsgis.lib.requests.UsersRequestHelper;
45

  
46
/**
47
 *
48
 * @author gvSIG Team
49
 */
50
public class UsersRequestLocaldb extends AbstractRequestLocaldb implements VCSGisUsersRequest {
51
    
52
    public UsersRequestLocaldb(VCSGisRepositoryLocaldb repository) {
53
        super(new UsersRequestHelper(repository));
54
    }
55

  
56
    @Override
57
    public UsersRequestHelper helper() {
58
        return (UsersRequestHelper) super.helper(); 
59
    }
60

  
61
    @Override
62
    public List<VCSGisUser> getUsers() {
63
        return helper().getUsers();
64
    }
65

  
66
    @Override
67
    public int execute() {
68
        if( !this.isAuthorized() ) {
69
            return this.getLastErrorCode();
70
        }
71
        DisposableFeatureSetIterable usersTable_it=null;
72
        try {
73
            UsersRepoTable usersTable = new UsersRepoTable();
74

  
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff