Statistics
| Revision:

gvsig-projects-pool / org.gvsig.vcsgis / trunk / org.gvsig.vcsgis / org.gvsig.vcsgis.lib / org.gvsig.vcsgis.lib.impl / src / main / java / org / gvsig / vcsgis / lib / VCSGisUtils.java @ 2697

History | View | Annotate | Download (7.98 KB)

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;
24

    
25
import java.util.Map;
26
import javax.json.JsonObject;
27
import org.gvsig.json.Json;
28
import org.gvsig.json.JsonObjectBuilder;
29
import org.gvsig.tools.ToolsLocator;
30
import org.gvsig.tools.util.MapBuilder;
31
import org.gvsig.vcsgis.lib.client.VCSGisWorkspace.Change;
32
import static org.gvsig.vcsgis.lib.client.VCSGisWorkspace.ERR_CANT_CHECKOUT;
33
import static org.gvsig.vcsgis.lib.client.VCSGisWorkspace.ERR_CANT_COMMIT;
34
import static org.gvsig.vcsgis.lib.client.VCSGisWorkspace.ERR_CANT_COMMIT_WORKSPACE_OUTDATED;
35
import static org.gvsig.vcsgis.lib.client.VCSGisWorkspace.ERR_CANT_CREATE_TABLE;
36
import static org.gvsig.vcsgis.lib.client.VCSGisWorkspace.ERR_CANT_CREATE_TABLE_CHANGES;
37
import static org.gvsig.vcsgis.lib.client.VCSGisWorkspace.ERR_CANT_CREATE_TABLE_CONFIG;
38
import static org.gvsig.vcsgis.lib.client.VCSGisWorkspace.ERR_CANT_CREATE_TABLE_ENTITIES;
39
import static org.gvsig.vcsgis.lib.client.VCSGisWorkspace.ERR_CANT_INSERT_CHANGE;
40
import static org.gvsig.vcsgis.lib.client.VCSGisWorkspace.ERR_CANT_INSERT_ENTITIES;
41
import static org.gvsig.vcsgis.lib.client.VCSGisWorkspace.ERR_CANT_INSERT_FEATURES;
42
import static org.gvsig.vcsgis.lib.client.VCSGisWorkspace.ERR_CANT_OPEN_CHANGES;
43
import static org.gvsig.vcsgis.lib.client.VCSGisWorkspace.ERR_CANT_OPEN_ENTITIES;
44
import static org.gvsig.vcsgis.lib.client.VCSGisWorkspace.ERR_CANT_OPEN_STORE;
45
import static org.gvsig.vcsgis.lib.client.VCSGisWorkspace.ERR_CANT_OPEN_WORKSPACE;
46
import static org.gvsig.vcsgis.lib.client.VCSGisWorkspace.ERR_CANT_OPEN_WORKSPACE_SERVEREXPLORER;
47
import static org.gvsig.vcsgis.lib.client.VCSGisWorkspace.ERR_CANT_PREPARE_UPDATE;
48
import static org.gvsig.vcsgis.lib.client.VCSGisWorkspace.ERR_CANT_RETRIEVE_SOURCE_FEATURES;
49
import static org.gvsig.vcsgis.lib.client.VCSGisWorkspace.ERR_CANT_UPDATE;
50
import static org.gvsig.vcsgis.lib.client.VCSGisWorkspace.ERR_CANT_UPDATE_ENTITIES;
51
import static org.gvsig.vcsgis.lib.client.VCSGisWorkspace.ERR_DBFILE_IS_NULL;
52
import static org.gvsig.vcsgis.lib.client.VCSGisWorkspace.ERR_ENTITY_ALREADY_EXISTS;
53
import static org.gvsig.vcsgis.lib.client.VCSGisWorkspace.ERR_ENTITY_NOT_HAS_VCSGISCODE;
54
import static org.gvsig.vcsgis.lib.client.VCSGisWorkspace.ERR_LABEL_IS_NULL;
55
import static org.gvsig.vcsgis.lib.client.VCSGisWorkspace.ERR_NO_ERROR;
56
import static org.gvsig.vcsgis.lib.client.VCSGisWorkspace.ERR_STORE_NOT_IN_VERSION_CONTROL;
57
import static org.gvsig.vcsgis.lib.client.VCSGisWorkspace.ERR_WSEXPLORER_IS_NULL;
58

    
59
/**
60
 *
61
 * @author gvSIG Team
62
 */
63
public class VCSGisUtils {
64
    
65
    private static final Map<Integer,String> ERRMSGS = new MapBuilder<>()
66
            .add(ERR_NO_ERROR, "_No_errors")
67
            .add(ERR_DBFILE_IS_NULL, "_dbfile_is_null")
68
            .add(ERR_WSEXPLORER_IS_NULL, "_workspace_explorer_is_null")
69
            .add(ERR_LABEL_IS_NULL, "_label_is_null")
70
            .add(ERR_CANT_OPEN_WORKSPACE, "_Cant_open_workspace")
71
            .add(ERR_CANT_OPEN_WORKSPACE_SERVEREXPLORER, "_Cant_open_workspace")
72
            .add(ERR_STORE_NOT_IN_VERSION_CONTROL, "_Store_not_in_control_version")
73
            .add(ERR_CANT_CREATE_TABLE, "_Cant_create_table")
74
            .add(ERR_CANT_CREATE_TABLE_CONFIG, "_Cant_create_config_table")
75
            .add(ERR_CANT_CREATE_TABLE_ENTITIES, "_Cant_create_table_entities")
76
            .add(ERR_CANT_CREATE_TABLE_CHANGES, "_Cant_create_table_changes")
77
            .add(ERR_ENTITY_ALREADY_EXISTS, "_Entity_already_exists")
78
            .add(ERR_ENTITY_NOT_HAS_VCSGISCODE, "_Entity_has_not_VCSGISCODE")
79
            .add(ERR_CANT_OPEN_ENTITIES, "_Cant_open_entities")
80
            .add(ERR_CANT_INSERT_ENTITIES, "_Cant_insert_entities")
81
            .add(ERR_CANT_OPEN_CHANGES, "_Cant_open_changes")
82
            .add(ERR_CANT_INSERT_CHANGE, "_Cant_insert_change")
83
            .add(ERR_CANT_OPEN_STORE, "_Cant_open_store")
84
            .add(ERR_CANT_RETRIEVE_SOURCE_FEATURES, "_Cant_retrieve_source_features")
85
            .add(ERR_CANT_INSERT_FEATURES, "_Cant_insert_features")
86
            .add(ERR_CANT_COMMIT, "_Cant_commit")
87
            .add(ERR_CANT_COMMIT_WORKSPACE_OUTDATED, "_Cant_commit_workspace_is_out_of_date")
88
            .add(ERR_CANT_CHECKOUT, "_Cant_checkout")
89
            .add(ERR_CANT_UPDATE_ENTITIES, "_Cant_update_entities")
90
            .add(ERR_CANT_PREPARE_UPDATE, "_Cant_prepare_update")
91
            .add(ERR_CANT_UPDATE, "_Cant_update")
92
            .build();
93

    
94
    public static String getErrorMessage(int errcode) {
95
        String msg = ERRMSGS.get(errcode);
96
        msg = ToolsLocator.getI18nManager().getTranslation(msg);
97
        return msg;
98
    }
99
    
100
    public static void copy(VCSGisEntity source, VCSGisEntityEditable target) {
101
        target.setDataTableName(source.getDataTableName());
102
        target.setDescription(source.getDescription());
103
        target.setEntityCode(source.getEntityCode());
104
        target.setEntityName(source.getEntityName());
105
        target.setFeatureIdFieldName(source.getFeatureIdFieldName());
106
        target.setFeatureTypeAsJson(source.getFeatureTypeAsJson());
107
        target.setFieldForLabel(source.getFieldForLabel());
108
        target.setGeometryFieldName(source.getGeometryFieldName());
109
        target.setRepositoryRevisionCode(source.getRepositoryRevisionCode());
110
        target.setTopologyPlanCode(source.getTopologyPlanCode());
111
        target.setUserCode(source.getUserCode());
112
    }
113
    
114
    public static JsonObjectBuilder toJsonBuilder(VCSGisEntity entity) {
115
        JsonObjectBuilder jsonEntity = Json.createObjectBuilder();
116
        jsonEntity.add("DataTableName", entity.getDataTableName());
117
        jsonEntity.add("Description", entity.getDescription());
118
        jsonEntity.add("EntityCode", entity.getEntityCode());
119
        jsonEntity.add("EntityName", entity.getEntityName());
120
        jsonEntity.add("FeatureIdFieldName", entity.getFeatureIdFieldName());
121
        jsonEntity.add("FeatureTypeAsJson", entity.getFeatureTypeAsJson());
122
        jsonEntity.add("FieldForLabel()", entity.getFieldForLabel());
123
        jsonEntity.add("GeometryFieldName()()", entity.getGeometryFieldName());
124
        jsonEntity.add("RevisionCode", entity.getRepositoryRevisionCode());
125
        jsonEntity.add("TopologyPlanCode", entity.getTopologyPlanCode());
126
        jsonEntity.add("UserCode", entity.getUserCode());
127
        return jsonEntity;
128
    }
129

    
130
    public static void fromJson(VCSGisEntityEditable entity, JsonObject jsonEntity) {
131
        entity.setDataTableName(jsonEntity.getString("DataTableName", null));
132
        entity.setDescription(jsonEntity.getString("Description", null));
133
        entity.setEntityCode(jsonEntity.getString("EntityCode", null));
134
        entity.setEntityName(jsonEntity.getString("EntityName", null));
135
        entity.setFeatureIdFieldName(jsonEntity.getString("FeatureIdFieldName", null));
136
        entity.setFeatureTypeAsJson(jsonEntity.getString("FeatureTypeAsJson", null));
137
        entity.setFieldForLabel(jsonEntity.getString("FieldForLabel", null));
138
        entity.setGeometryFieldName(jsonEntity.getString("GeometryFieldName", null));
139
        entity.setRepositoryRevisionCode(jsonEntity.getString("RevisionCode", null));
140
        entity.setTopologyPlanCode(jsonEntity.getString("TopologyPlanCode", null));
141
        entity.setUserCode(jsonEntity.getString("UserCode", null));                
142
    }
143
}