root / src / gr / ebs / gss / client / rest / resource / OthersResource.java @ c5070ebe
History | View | Annotate | Download (3 kB)
1 | a52ea5e4 | pastith | /*
|
---|---|---|---|
2 | a52ea5e4 | pastith | * Copyright 2009 Electronic Business Systems Ltd.
|
3 | a52ea5e4 | pastith | *
|
4 | a52ea5e4 | pastith | * This file is part of GSS.
|
5 | a52ea5e4 | pastith | *
|
6 | a52ea5e4 | pastith | * GSS is free software: you can redistribute it and/or modify
|
7 | a52ea5e4 | pastith | * it under the terms of the GNU General Public License as published by
|
8 | a52ea5e4 | pastith | * the Free Software Foundation, either version 3 of the License, or
|
9 | a52ea5e4 | pastith | * (at your option) any later version.
|
10 | a52ea5e4 | pastith | *
|
11 | a52ea5e4 | pastith | * GSS is distributed in the hope that it will be useful,
|
12 | a52ea5e4 | pastith | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13 | a52ea5e4 | pastith | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
14 | a52ea5e4 | pastith | * GNU General Public License for more details.
|
15 | a52ea5e4 | pastith | *
|
16 | a52ea5e4 | pastith | * You should have received a copy of the GNU General Public License
|
17 | a52ea5e4 | pastith | * along with GSS. If not, see <http://www.gnu.org/licenses/>.
|
18 | a52ea5e4 | pastith | */
|
19 | a52ea5e4 | pastith | package gr.ebs.gss.client.rest.resource; |
20 | a52ea5e4 | pastith | |
21 | c5070ebe | Natasa Kapravelou | import gr.ebs.gss.client.GSS; |
22 | c5070ebe | Natasa Kapravelou | |
23 | a52ea5e4 | pastith | import java.util.ArrayList; |
24 | a52ea5e4 | pastith | import java.util.List; |
25 | a52ea5e4 | pastith | |
26 | d98c561b | Giannis Koutsoubos | import com.google.gwt.core.client.GWT; |
27 | a52ea5e4 | pastith | import com.google.gwt.json.client.JSONArray; |
28 | a52ea5e4 | pastith | import com.google.gwt.json.client.JSONObject; |
29 | a52ea5e4 | pastith | import com.google.gwt.json.client.JSONParser; |
30 | c5070ebe | Natasa Kapravelou | import com.google.gwt.user.client.ui.TreeItem; |
31 | a52ea5e4 | pastith | |
32 | a52ea5e4 | pastith | /**
|
33 | a52ea5e4 | pastith | * @author kman
|
34 | a52ea5e4 | pastith | */
|
35 | a52ea5e4 | pastith | public class OthersResource extends RestResource { |
36 | a52ea5e4 | pastith | |
37 | 555e8e59 | pastith | public OthersResource(String aUri) { |
38 | 555e8e59 | pastith | super(aUri);
|
39 | a52ea5e4 | pastith | } |
40 | a52ea5e4 | pastith | |
41 | a52ea5e4 | pastith | List<String> others = new ArrayList<String>(); |
42 | d98c561b | Giannis Koutsoubos | List<OtherUserResource> otherUsers = new ArrayList<OtherUserResource>(); |
43 | 86c951b2 | Panagiotis Astithas | |
44 | a52ea5e4 | pastith | /**
|
45 | a52ea5e4 | pastith | * Retrieve the others.
|
46 | a52ea5e4 | pastith | *
|
47 | a52ea5e4 | pastith | * @return the others
|
48 | a52ea5e4 | pastith | */
|
49 | a52ea5e4 | pastith | public List<String> getOthers() { |
50 | a52ea5e4 | pastith | return others;
|
51 | a52ea5e4 | pastith | } |
52 | a52ea5e4 | pastith | |
53 | a52ea5e4 | pastith | /**
|
54 | a52ea5e4 | pastith | * Modify the others.
|
55 | a52ea5e4 | pastith | *
|
56 | 0e4865ee | pastith | * @param newOthers the others to set
|
57 | a52ea5e4 | pastith | */
|
58 | 0e4865ee | pastith | public void setOthers(List<String> newOthers) { |
59 | 0e4865ee | pastith | others = newOthers; |
60 | a52ea5e4 | pastith | } |
61 | 86c951b2 | Panagiotis Astithas | |
62 | d98c561b | Giannis Koutsoubos | public List<OtherUserResource> getOtherUsers() { |
63 | d98c561b | Giannis Koutsoubos | return otherUsers;
|
64 | d98c561b | Giannis Koutsoubos | } |
65 | d98c561b | Giannis Koutsoubos | |
66 | 86c951b2 | Panagiotis Astithas | public void setOtherUsers(List<OtherUserResource> newOtherUsers) { |
67 | 86c951b2 | Panagiotis Astithas | otherUsers = newOtherUsers; |
68 | d98c561b | Giannis Koutsoubos | } |
69 | a52ea5e4 | pastith | |
70 | 0e4865ee | pastith | @Override
|
71 | a52ea5e4 | pastith | public void createFromJSON(String text) { |
72 | a52ea5e4 | pastith | JSONArray array = (JSONArray) JSONParser.parse(text); |
73 | a52ea5e4 | pastith | if (array != null) |
74 | a52ea5e4 | pastith | for (int i = 0; i < array.size(); i++) { |
75 | a52ea5e4 | pastith | JSONObject js = array.get(i).isObject(); |
76 | a52ea5e4 | pastith | if (js != null) { |
77 | 555e8e59 | pastith | String othersUri = unmarshallString(js, "uri"); |
78 | d98c561b | Giannis Koutsoubos | String username = unmarshallString(js, "username"); |
79 | d98c561b | Giannis Koutsoubos | if(othersUri != null){ |
80 | 555e8e59 | pastith | getOthers().add(othersUri); |
81 | d98c561b | Giannis Koutsoubos | OtherUserResource r = new OtherUserResource(othersUri);
|
82 | d98c561b | Giannis Koutsoubos | r.setUsername(username); |
83 | d98c561b | Giannis Koutsoubos | getOtherUsers().add(r); |
84 | d98c561b | Giannis Koutsoubos | } |
85 | a52ea5e4 | pastith | } |
86 | a52ea5e4 | pastith | } |
87 | a52ea5e4 | pastith | } |
88 | 86c951b2 | Panagiotis Astithas | |
89 | d98c561b | Giannis Koutsoubos | public String getUsernameOfUri(String u){ |
90 | d98c561b | Giannis Koutsoubos | if(!u.endsWith("/")) |
91 | d98c561b | Giannis Koutsoubos | u=u+"/";
|
92 | d98c561b | Giannis Koutsoubos | for(OtherUserResource o : getOtherUsers()){
|
93 | d98c561b | Giannis Koutsoubos | GWT.log("CHECKING USER URI:"+o.getUri(), null); |
94 | d98c561b | Giannis Koutsoubos | String toCheck = o.getUri();
|
95 | d98c561b | Giannis Koutsoubos | if(!toCheck.endsWith("/")) |
96 | d98c561b | Giannis Koutsoubos | toCheck=toCheck+"/";
|
97 | d98c561b | Giannis Koutsoubos | if(toCheck.equals(u))
|
98 | d98c561b | Giannis Koutsoubos | return o.getUsername();
|
99 | d98c561b | Giannis Koutsoubos | } |
100 | d98c561b | Giannis Koutsoubos | return null; |
101 | d98c561b | Giannis Koutsoubos | } |
102 | 86c951b2 | Panagiotis Astithas | |
103 | 62f168b2 | Giannis Koutsoubos | @Override
|
104 | 62f168b2 | Giannis Koutsoubos | public String getLastModifiedSince() { |
105 | 62f168b2 | Giannis Koutsoubos | return null; |
106 | 62f168b2 | Giannis Koutsoubos | } |
107 | c5070ebe | Natasa Kapravelou | |
108 | c5070ebe | Natasa Kapravelou | /**
|
109 | c5070ebe | Natasa Kapravelou | * Bugzilla – Bug 371, Add history support for folder navigation
|
110 | c5070ebe | Natasa Kapravelou | */
|
111 | c5070ebe | Natasa Kapravelou | @Override
|
112 | c5070ebe | Natasa Kapravelou | public void updateHistoryAbs(TreeItem item, String path){ |
113 | c5070ebe | Natasa Kapravelou | try{
|
114 | c5070ebe | Natasa Kapravelou | GSS.get().updateHistory("Files/"+ path.substring(path.lastIndexOf("/")+1) + "others/", item); |
115 | c5070ebe | Natasa Kapravelou | }catch(Exception e){ |
116 | c5070ebe | Natasa Kapravelou | throw new UnsupportedOperationException(e); |
117 | c5070ebe | Natasa Kapravelou | } |
118 | c5070ebe | Natasa Kapravelou | } |
119 | a52ea5e4 | pastith | } |