Statistics
| Branch: | Tag: | Revision:

root / web_client / src / gr / grnet / pithos / web / client / rest / resource / OthersResource.java @ 58777026

History | View | Annotate | Download (3.7 kB)

1
/*
2
 * Copyright 2011 GRNET S.A. All rights reserved.
3
 *
4
 * Redistribution and use in source and binary forms, with or
5
 * without modification, are permitted provided that the following
6
 * conditions are met:
7
 *
8
 *   1. Redistributions of source code must retain the above
9
 *      copyright notice, this list of conditions and the following
10
 *      disclaimer.
11
 *
12
 *   2. Redistributions in binary form must reproduce the above
13
 *      copyright notice, this list of conditions and the following
14
 *      disclaimer in the documentation and/or other materials
15
 *      provided with the distribution.
16
 *
17
 * THIS SOFTWARE IS PROVIDED BY GRNET S.A. ``AS IS'' AND ANY EXPRESS
18
 * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19
 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
20
 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GRNET S.A OR
21
 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
24
 * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
25
 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
27
 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28
 * POSSIBILITY OF SUCH DAMAGE.
29
 *
30
 * The views and conclusions contained in the software and
31
 * documentation are those of the authors and should not be
32
 * interpreted as representing official policies, either expressed
33
 * or implied, of GRNET S.A.
34
 */
35
package gr.grnet.pithos.web.client.rest.resource;
36

    
37
import java.util.ArrayList;
38
import java.util.List;
39

    
40
import com.google.gwt.core.client.GWT;
41
import com.google.gwt.json.client.JSONArray;
42
import com.google.gwt.json.client.JSONObject;
43
import com.google.gwt.json.client.JSONParser;
44
import com.google.gwt.user.client.ui.TreeItem;
45

    
46
public class OthersResource extends RestResource {
47

    
48
        public OthersResource(String aUri) {
49
                super(aUri);
50
        }
51

    
52
        List<String> others = new ArrayList<String>();
53
        List<OtherUserResource> otherUsers = new ArrayList<OtherUserResource>();
54

    
55
        /**
56
         * Retrieve the others.
57
         *
58
         * @return the others
59
         */
60
        public List<String> getOthers() {
61
                return others;
62
        }
63

    
64
        /**
65
         * Modify the others.
66
         *
67
         * @param newOthers the others to set
68
         */
69
        public void setOthers(List<String> newOthers) {
70
                others = newOthers;
71
        }
72

    
73
        public List<OtherUserResource> getOtherUsers() {
74
                return otherUsers;
75
        }
76

    
77
        public void setOtherUsers(List<OtherUserResource> newOtherUsers) {
78
                otherUsers = newOtherUsers;
79
        }
80

    
81
        @Override
82
        public void createFromJSON(String text) {
83
                JSONArray array = (JSONArray) JSONParser.parse(text);
84
                if (array != null)
85
                        for (int i = 0; i < array.size(); i++) {
86
                                JSONObject js = array.get(i).isObject();
87
                                if (js != null) {
88
                                        String othersUri = unmarshallString(js, "uri");
89
                                        String username = unmarshallString(js, "username");
90
                                        if(othersUri != null){
91
                                                getOthers().add(othersUri);
92
                                                OtherUserResource r = new OtherUserResource(othersUri);
93
                                                r.setUsername(username);
94
                                                getOtherUsers().add(r);
95
                                        }
96
                                }
97
                        }
98
        }
99

    
100
        public String getUsernameOfUri(String u){
101
                if(!u.endsWith("/"))
102
                        u=u+"/";
103
                for(OtherUserResource o : getOtherUsers()){
104
                        GWT.log("CHECKING USER URI:"+o.getUri(), null);
105
                        String toCheck = o.getUri();
106
                        if(!toCheck.endsWith("/"))
107
                                toCheck=toCheck+"/";
108
                        if(toCheck.equals(u))
109
                                return o.getUsername();
110
                }
111
                return null;
112
        }
113

    
114
        @Override
115
        public String getLastModifiedSince() {
116
                return null;
117
        }
118

    
119
        @Override
120
        public String constructUri(TreeItem treeItem,String path){
121
                String constructedUri = "Files/"+ path.substring(path.lastIndexOf("/")+1) + "others/";
122
                return constructedUri;
123
        }
124
}