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 | 2697 | jjdelcerro | /*
|
---|---|---|---|
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 | 2699 | jjdelcerro | package org.gvsig.vcsgis.lib.repository.remoteclient.requests; |
24 | 2697 | jjdelcerro | |
25 | 2715 | jjdelcerro | import java.io.BufferedReader; |
26 | 2708 | jjdelcerro | import java.io.OutputStream; |
27 | 2697 | jjdelcerro | 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 | 3315 | jjdelcerro | import static org.gvsig.vcsgis.lib.VCSGisManager.ERR_CANT_RETRIEVE_USERS; |
35 | 2708 | jjdelcerro | import static org.gvsig.vcsgis.lib.VCSGisManager.ERR_OK; |
36 | 3315 | jjdelcerro | import org.gvsig.vcsgis.lib.VCSGisUser; |
37 | import org.gvsig.vcsgis.lib.VCSGisUserImpl; |
||
38 | 2697 | jjdelcerro | import static org.gvsig.vcsgis.lib.VCSGisUtils.getErrorMessage; |
39 | 2699 | jjdelcerro | import org.gvsig.vcsgis.lib.repository.remoteclient.VCSGisRepositoryClient; |
40 | 3315 | jjdelcerro | import org.gvsig.vcsgis.lib.repository.requests.VCSGisUsersRequest; |
41 | import org.gvsig.vcsgis.lib.requests.UsersRequestHelper; |
||
42 | 2697 | jjdelcerro | |
43 | /**
|
||
44 | *
|
||
45 | * @author gvSIG Team
|
||
46 | */
|
||
47 | 3315 | jjdelcerro | public class UsersRequestClient extends AbstractRequestClient implements VCSGisUsersRequest { |
48 | 2697 | jjdelcerro | |
49 | 3315 | jjdelcerro | public UsersRequestClient(VCSGisRepositoryClient repository) {
|
50 | 2708 | jjdelcerro | super(
|
51 | 3456 | jolivas | new UsersRequestHelper(repository),
|
52 | 3375 | fdiaz | "users"
|
53 | 2708 | jjdelcerro | ); |
54 | 2697 | jjdelcerro | } |
55 | |||
56 | @Override
|
||
57 | 3315 | jjdelcerro | public UsersRequestHelper helper() {
|
58 | return (UsersRequestHelper) super.helper(); |
||
59 | 2697 | jjdelcerro | } |
60 | |||
61 | @Override
|
||
62 | 3315 | jjdelcerro | public List<VCSGisUser> getUsers() { |
63 | return helper().getUsers();
|
||
64 | 2708 | jjdelcerro | } |
65 | 2697 | jjdelcerro | |
66 | 2708 | jjdelcerro | @Override
|
67 | 2715 | jjdelcerro | public void requestProducer(OutputStream out) { |
68 | error(ERR_OK); |
||
69 | 2708 | jjdelcerro | } |
70 | |||
71 | @Override
|
||
72 | 2715 | jjdelcerro | public void responseConsumer(BufferedReader inputData) { |
73 | 2708 | jjdelcerro | try {
|
74 | 2715 | jjdelcerro | LOGGER.debug("===: ["+this.getRequestName()+"] responseConsumer"); |
75 | 3315 | jjdelcerro | List<VCSGisUser> theUsers = new ArrayList<>(); |
76 | 2708 | jjdelcerro | |
77 | JsonReader reader = Json.createReader(inputData); |
||
78 | 2697 | jjdelcerro | JsonObject jsonResponse = reader.readObject(); |
79 | 3632 | fdiaz | JsonObject jsonParameters = jsonResponse.getJsonObject("Parameters");
|
80 | |||
81 | int statusCode = jsonParameters.getInt("StatusCode", ERR_CANT_RETRIEVE_USERS); |
||
82 | 2715 | jjdelcerro | LOGGER.debug("===: ["+this.getRequestName()+"] responseConsumer status code "+statusCode); |
83 | 2697 | jjdelcerro | if( statusCode!=ERR_OK ) {
|
84 | 2715 | jjdelcerro | error( |
85 | 2697 | jjdelcerro | statusCode, |
86 | 3632 | fdiaz | jsonParameters.getString("StatusMessage", getErrorMessage(statusCode))
|
87 | 2697 | jjdelcerro | ); |
88 | 2715 | jjdelcerro | return;
|
89 | 2697 | jjdelcerro | } |
90 | 3315 | jjdelcerro | 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 | 2697 | jjdelcerro | } |
97 | 3315 | jjdelcerro | helper().users = theUsers; |
98 | 2715 | jjdelcerro | LOGGER.debug("===: ["+this.getRequestName()+"] responseConsumer ok"); |
99 | error(ERR_OK); |
||
100 | 2708 | jjdelcerro | } catch (Exception ex) { |
101 | 3315 | jjdelcerro | LOGGER.warn("Can't retrieve users from '"+this.getRequestUrl()+"'.",ex); |
102 | error(ERR_CANT_RETRIEVE_USERS, "Can't retrieve users from '"+this.getRequestUrl()+"'."); |
||
103 | 2697 | jjdelcerro | } |
104 | } |
||
105 | |||
106 | } |