Statistics
| Branch: | Tag: | Revision:

root / src / gr / ebs / gss / client / rest / resource / OthersResource.java @ c5070ebe

History | View | Annotate | Download (3 kB)

1
/*
2
 * Copyright 2009 Electronic Business Systems Ltd.
3
 *
4
 * This file is part of GSS.
5
 *
6
 * GSS is free software: you can redistribute it and/or modify
7
 * it under the terms of the GNU General Public License as published by
8
 * the Free Software Foundation, either version 3 of the License, or
9
 * (at your option) any later version.
10
 *
11
 * GSS 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 GSS.  If not, see <http://www.gnu.org/licenses/>.
18
 */
19
package gr.ebs.gss.client.rest.resource;
20

    
21
import gr.ebs.gss.client.GSS;
22

    
23
import java.util.ArrayList;
24
import java.util.List;
25

    
26
import com.google.gwt.core.client.GWT;
27
import com.google.gwt.json.client.JSONArray;
28
import com.google.gwt.json.client.JSONObject;
29
import com.google.gwt.json.client.JSONParser;
30
import com.google.gwt.user.client.ui.TreeItem;
31

    
32
/**
33
 * @author kman
34
 */
35
public class OthersResource extends RestResource {
36

    
37
        public OthersResource(String aUri) {
38
                super(aUri);
39
        }
40

    
41
        List<String> others = new ArrayList<String>();
42
        List<OtherUserResource> otherUsers = new ArrayList<OtherUserResource>();
43

    
44
        /**
45
         * Retrieve the others.
46
         *
47
         * @return the others
48
         */
49
        public List<String> getOthers() {
50
                return others;
51
        }
52

    
53
        /**
54
         * Modify the others.
55
         *
56
         * @param newOthers the others to set
57
         */
58
        public void setOthers(List<String> newOthers) {
59
                others = newOthers;
60
        }
61

    
62
        public List<OtherUserResource> getOtherUsers() {
63
                return otherUsers;
64
        }
65

    
66
        public void setOtherUsers(List<OtherUserResource> newOtherUsers) {
67
                otherUsers = newOtherUsers;
68
        }
69

    
70
        @Override
71
        public void createFromJSON(String text) {
72
                JSONArray array = (JSONArray) JSONParser.parse(text);
73
                if (array != null)
74
                        for (int i = 0; i < array.size(); i++) {
75
                                JSONObject js = array.get(i).isObject();
76
                                if (js != null) {
77
                                        String othersUri = unmarshallString(js, "uri");
78
                                        String username = unmarshallString(js, "username");
79
                                        if(othersUri != null){
80
                                                getOthers().add(othersUri);
81
                                                OtherUserResource r = new OtherUserResource(othersUri);
82
                                                r.setUsername(username);
83
                                                getOtherUsers().add(r);
84
                                        }
85
                                }
86
                        }
87
        }
88

    
89
        public String getUsernameOfUri(String u){
90
                if(!u.endsWith("/"))
91
                        u=u+"/";
92
                for(OtherUserResource o : getOtherUsers()){
93
                        GWT.log("CHECKING USER URI:"+o.getUri(), null);
94
                        String toCheck = o.getUri();
95
                        if(!toCheck.endsWith("/"))
96
                                toCheck=toCheck+"/";
97
                        if(toCheck.equals(u))
98
                                return o.getUsername();
99
                }
100
                return null;
101
        }
102

    
103
        @Override
104
        public String getLastModifiedSince() {
105
                return null;
106
        }
107

    
108
        /**
109
         * Bugzilla – Bug 371, Add history support for folder navigation
110
         */
111
        @Override
112
        public void updateHistoryAbs(TreeItem item, String path){
113
                try{
114
                        GSS.get().updateHistory("Files/"+ path.substring(path.lastIndexOf("/")+1) + "others/", item);
115
                }catch(Exception e){
116
                        throw new UnsupportedOperationException(e);
117
                }
118
        }
119
}