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 / UsersRequestClient.java @ 3632
History | View | Annotate | Download (3.93 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_USERS; |
35 |
import static org.gvsig.vcsgis.lib.VCSGisManager.ERR_OK; |
36 |
import org.gvsig.vcsgis.lib.VCSGisUser; |
37 |
import org.gvsig.vcsgis.lib.VCSGisUserImpl; |
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.VCSGisUsersRequest; |
41 |
import org.gvsig.vcsgis.lib.requests.UsersRequestHelper; |
42 |
|
43 |
/**
|
44 |
*
|
45 |
* @author gvSIG Team
|
46 |
*/
|
47 |
public class UsersRequestClient extends AbstractRequestClient implements VCSGisUsersRequest { |
48 |
|
49 |
public UsersRequestClient(VCSGisRepositoryClient repository) {
|
50 |
super(
|
51 |
new UsersRequestHelper(repository),
|
52 |
"users"
|
53 |
); |
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 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<VCSGisUser> theUsers = 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_USERS); |
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 |
JsonArray jsonUsers = jsonResponse.getJsonArray("Users");
|
91 |
LOGGER.debug("===: ["+this.getRequestName()+"] responseConsumer user " + jsonUsers.size()); |
92 |
for (JsonValue x : jsonUsers) {
|
93 |
VCSGisUserImpl user = new VCSGisUserImpl((JsonObject) x);
|
94 |
LOGGER.debug("===: ["+this.getRequestName()+"] responseConsumer user "+user.getIdentifier()); |
95 |
theUsers.add(user); |
96 |
} |
97 |
helper().users = theUsers; |
98 |
LOGGER.debug("===: ["+this.getRequestName()+"] responseConsumer ok"); |
99 |
error(ERR_OK); |
100 |
} catch (Exception ex) { |
101 |
LOGGER.warn("Can't retrieve users from '"+this.getRequestUrl()+"'.",ex); |
102 |
error(ERR_CANT_RETRIEVE_USERS, "Can't retrieve users from '"+this.getRequestUrl()+"'."); |
103 |
} |
104 |
} |
105 |
|
106 |
} |