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 / repository / remoteclient / requests / TopologyPlansRequestClient.java @ 3636
History | View | Annotate | Download (4.25 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.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_RETRIEVE_TOPOLOGYPLANS; |
35 |
import static org.gvsig.vcsgis.lib.VCSGisManager.ERR_OK; |
36 |
import org.gvsig.vcsgis.lib.VCSGisTopologyPlan; |
37 |
import org.gvsig.vcsgis.lib.VCSGisTopologyPlanImpl; |
38 |
import static org.gvsig.vcsgis.lib.VCSGisUtils.getErrorMessage; |
39 |
import org.gvsig.vcsgis.lib.repository.remoteclient.VCSGisRepositoryClient; |
40 |
import org.gvsig.vcsgis.lib.repository.requests.VCSGisTopologyPlansRequest; |
41 |
import org.gvsig.vcsgis.lib.requests.TopologyPlansRequestHelper; |
42 |
|
43 |
/**
|
44 |
*
|
45 |
* @author gvSIG Team
|
46 |
*/
|
47 |
public class TopologyPlansRequestClient extends AbstractRequestClient implements VCSGisTopologyPlansRequest { |
48 |
|
49 |
public TopologyPlansRequestClient(VCSGisRepositoryClient repository) {
|
50 |
super(
|
51 |
new TopologyPlansRequestHelper(repository),
|
52 |
"topologyplans"
|
53 |
); |
54 |
} |
55 |
|
56 |
@Override
|
57 |
public TopologyPlansRequestHelper helper() {
|
58 |
return (TopologyPlansRequestHelper) super.helper(); |
59 |
} |
60 |
|
61 |
@Override
|
62 |
public List<VCSGisTopologyPlan> getTopologyPlans() { |
63 |
return helper().getTopologyPlans();
|
64 |
} |
65 |
|
66 |
@Override
|
67 |
public void requestProducer(OutputStream out) { |
68 |
error(ERR_OK); |
69 |
} |
70 |
|
71 |
@Override
|
72 |
public void responseConsumer(BufferedReader inputData) { |
73 |
try {
|
74 |
LOGGER.debug("===: ["+this.getRequestName()+"] responseConsumer"); |
75 |
List<VCSGisTopologyPlan> theTopologyPlans = new ArrayList<>(); |
76 |
|
77 |
JsonReader reader = Json.createReader(inputData); |
78 |
JsonObject jsonResponse = reader.readObject(); |
79 |
JsonObject jsonParameters = jsonResponse.getJsonObject("Parameters");
|
80 |
|
81 |
int statusCode = jsonParameters.getInt("StatusCode", ERR_CANT_RETRIEVE_TOPOLOGYPLANS); |
82 |
LOGGER.debug("===: ["+this.getRequestName()+"] responseConsumer status code "+statusCode); |
83 |
if( statusCode!=ERR_OK ) {
|
84 |
error( |
85 |
statusCode, |
86 |
jsonParameters.getString("StatusMessage", getErrorMessage(statusCode))
|
87 |
); |
88 |
return;
|
89 |
} |
90 |
this.cleanLastError();
|
91 |
JsonArray jsonTopologyPlans = jsonResponse.getJsonArray("TopologyPlans");
|
92 |
LOGGER.debug("===: ["+this.getRequestName()+"] responseConsumer TopologyPlans " + jsonTopologyPlans.size()); |
93 |
for (JsonValue x : jsonTopologyPlans) {
|
94 |
VCSGisTopologyPlan topologyPlan = new VCSGisTopologyPlanImpl((JsonObject) x);
|
95 |
LOGGER.debug("===: ["+this.getRequestName()+"] responseConsumer TopologyPlans "+topologyPlan.getName()); |
96 |
theTopologyPlans.add(topologyPlan); |
97 |
} |
98 |
helper().topologyplans = theTopologyPlans; |
99 |
LOGGER.debug("===: ["+this.getRequestName()+"] responseConsumer ok"); |
100 |
error(ERR_OK); |
101 |
} catch (Exception ex) { |
102 |
LOGGER.warn("Can't retrieve topology plans from '"+this.getRequestUrl()+"'.",ex); |
103 |
error(ERR_CANT_RETRIEVE_TOPOLOGYPLANS, "Can't retrieve topology plans from '"+this.getRequestUrl()+"'."); |
104 |
} |
105 |
} |
106 |
|
107 |
} |