Statistics
| Branch: | Tag: | Revision:

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

History | View | Annotate | Download (4.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.Date;
39
import java.util.LinkedList;
40
import java.util.List;
41

    
42
import com.google.gwt.http.client.URL;
43
import com.google.gwt.json.client.JSONArray;
44
import com.google.gwt.json.client.JSONObject;
45
import com.google.gwt.json.client.JSONParser;
46

    
47
public class SearchResource extends RestResource {
48
        int size;
49
        public SearchResource(String aUri) {
50
                super(aUri);
51
        }
52

    
53
        List<FileResource> files = new ArrayList<FileResource>();
54
        List<String> filePaths = new LinkedList<String>();
55

    
56
        /**
57
         * Retrieve the files.
58
         *
59
         * @return the files
60
         */
61
        public List<String> getFilePaths() {
62
                return filePaths;
63
        }
64

    
65
        /**
66
         * Modify the files.
67
         *
68
         * @param newFilePaths the files to set
69
         */
70
        public void setFilePaths(List<String> newFilePaths) {
71
                filePaths = newFilePaths;
72
        }
73

    
74
        /**
75
         * Retrieve the files.
76
         *
77
         * @return the files
78
         */
79
        public List<FileResource> getFiles() {
80
                return files;
81
        }
82

    
83
        /**
84
         * Modify the files.
85
         *
86
         * @param newFiles the files to set
87
         */
88
        public void setFiles(List<FileResource> newFiles) {
89
                files = newFiles;
90
        }
91

    
92
        @Override
93
        public void createFromJSON(String text) {
94
                JSONArray subs = JSONParser.parse(text).isArray();
95
                if (subs != null)
96
                        for (int i = 0; i < subs.size(); i++) {
97
                                JSONObject fo = subs.get(i).isObject();
98
                                if (fo != null) {
99
                                        if(i==0&&unmarshallInt(fo, "length")!=-1){
100
                                                setSize(unmarshallInt(fo, "length"));
101
                                        }
102
                                        else{
103
                                        String fname = unmarshallString(fo, "name");
104
                                        String fowner = unmarshallString(fo, "owner");
105
                                        String fcontent = unmarshallString(fo, "content");
106
                                        String fpath = unmarshallString(fo, "path");
107
                                        Boolean fshared = unmarshallBoolean(fo,"shared");
108
                                        boolean fversioned = unmarshallBoolean(fo,"versioned");
109
                                        fpath = URL.decodeComponent(fpath);
110
                                        Integer fversion = null;
111
                                        if (fo.get("version") != null)
112
                                                fversion = new Integer(fo.get("version").toString());
113
                                        boolean fdeleted = unmarshallBoolean(fo, "deleted");
114
                                        Date fcreationDate = null;
115
                                        if (fo.get("creationDate") != null)
116
                                                fcreationDate = new Date(new Long(fo.get("creationDate").toString()));
117
                                        Date fmodificationDate = null;
118
                                        if (fo.get("modificationDate") != null)
119
                                                fmodificationDate = new Date(new Long(fo.get("modificationDate").toString()));
120
                                        String furi = unmarshallString(fo,"uri");
121
                                        Long fsize = 0L;
122
                                        if(fo.get("size") != null)
123
                                                fsize = new Long(fo.get("size").toString());
124
                                        filePaths.add(furi);
125
                                        FileResource fs = new FileResource(furi);
126
                                        fs.setName(fname);
127
                                        fs.setOwner(fowner);
128
                                        fs.setVersion(fversion);
129
                                        fs.setContentLength(fsize);
130
                                        fs.setDeleted(fdeleted);
131
                                        fs.setCreationDate(fcreationDate);
132
                                        fs.setModificationDate(fmodificationDate);
133
                                        fs.setContentType(fcontent);
134
                                        fs.setPath(fpath);
135
                                        fs.setShared(fshared);
136
                                        fs.setVersioned(fversioned);
137
                                        files.add(fs);
138
                                        }
139
                                }
140
                        }
141
        }
142

    
143
        @Override
144
        public String getLastModifiedSince() {
145
                return null;
146
        }
147
        
148
        
149
        /**
150
         * Retrieve the size.
151
         *
152
         * @return the size
153
         */
154
        public int getSize() {
155
                return size;
156
        }
157
        
158
        
159
        /**
160
         * Modify the size.
161
         *
162
         * @param size the size to set
163
         */
164
        public void setSize(int size) {
165
                this.size = size;
166
        }
167
}