Revision 86c951b2 src/gr/ebs/gss/client/rest/HeadCommand.java
b/src/gr/ebs/gss/client/rest/HeadCommand.java | ||
---|---|---|
39 | 39 |
* @author kman |
40 | 40 |
* |
41 | 41 |
*/ |
42 |
public abstract class HeadCommand <T extends RestResource> extends RestCommand{
|
|
42 |
public abstract class HeadCommand<T extends RestResource> extends RestCommand{ |
|
43 | 43 |
|
44 | 44 |
boolean complete = false; |
45 | 45 |
T result = null; |
... | ... | |
47 | 47 |
private boolean requestSent = false; |
48 | 48 |
T cached; |
49 | 49 |
final String path; |
50 |
public HeadCommand(Class<T> aclass, String pathToGet, T cached){ |
|
51 |
this(aclass, pathToGet, true, cached); |
|
50 |
|
|
51 |
public HeadCommand(Class<T> theclass, String pathToGet, T theCached){ |
|
52 |
this(theclass, pathToGet, true, theCached); |
|
52 | 53 |
} |
53 |
public HeadCommand(Class<T> aclass, String pathToGet, boolean showLoading, T cached){ |
|
54 |
|
|
55 |
public HeadCommand(Class<T> theClass, String pathToGet, boolean showLoading, T theCached){ |
|
54 | 56 |
setShowLoadingIndicator(showLoading); |
55 |
this.aclass = aclass;
|
|
57 |
this.aclass = theClass;
|
|
56 | 58 |
if(isShowLoadingIndicator()) |
57 | 59 |
GSS.get().showLoadingIndicator(); |
58 | 60 |
|
59 |
if(aclass.equals(FileResource.class))
|
|
61 |
if(theClass.equals(FileResource.class))
|
|
60 | 62 |
path = pathToGet; |
61 | 63 |
else |
62 | 64 |
path = fixPath(pathToGet); |
63 |
this.cached = cached;
|
|
65 |
this.cached = theCached;
|
|
64 | 66 |
|
65 | 67 |
} |
66 | 68 |
|
... | ... | |
77 | 79 |
handleHeaders(builder, path); |
78 | 80 |
builder.sendRequest("", new RestCallback(path) { |
79 | 81 |
|
82 |
@Override |
|
80 | 83 |
public Object deserialize(Response response) { |
81 | 84 |
return deserializeResponse(path, response); |
82 | 85 |
} |
83 | 86 |
|
87 |
@Override |
|
84 | 88 |
public void handleError(Request request, Throwable exception) { |
85 | 89 |
if(exception instanceof RestException) |
86 | 90 |
if(((RestException)exception).getHttpStatusCode() == 304 && cached != null){ |
... | ... | |
92 | 96 |
HeadCommand.this.onError(exception); |
93 | 97 |
} |
94 | 98 |
|
99 |
@Override |
|
95 | 100 |
public void handleSuccess(Object object) { |
96 | 101 |
result = (T) object; |
97 | 102 |
complete = true; |
... | ... | |
104 | 109 |
} |
105 | 110 |
} |
106 | 111 |
|
107 |
|
|
108 | 112 |
public boolean isComplete() { |
109 | 113 |
return complete; |
110 | 114 |
} |
... | ... | |
129 | 133 |
return true; |
130 | 134 |
} |
131 | 135 |
|
132 |
public Object deserializeResponse(String path, Response response){
|
|
136 |
public Object deserializeResponse(String aPath, Response response){
|
|
133 | 137 |
RestResource result1 = null; |
134 | 138 |
if(aclass.equals(FolderResource.class)){ |
135 |
result1 = new FolderResource(path);
|
|
139 |
result1 = new FolderResource(aPath);
|
|
136 | 140 |
result1.createFromJSON(response.getText()); |
137 | 141 |
|
138 | 142 |
} |
139 | 143 |
else if(aclass.equals(FileResource.class)){ |
140 |
result1 = new FileResource(path);
|
|
144 |
result1 = new FileResource(aPath);
|
|
141 | 145 |
result1.createFromJSON(response.getHeader("X-GSS-Metadata")); |
142 | 146 |
} |
143 | 147 |
else if(aclass.equals(GroupsResource.class)){ |
144 |
result1 = new GroupsResource(path);
|
|
148 |
result1 = new GroupsResource(aPath);
|
|
145 | 149 |
result1.createFromJSON(response.getText()); |
146 | 150 |
} |
147 | 151 |
else if(aclass.equals(TrashResource.class)){ |
148 |
result1 = new TrashResource(path);
|
|
152 |
result1 = new TrashResource(aPath);
|
|
149 | 153 |
result1.createFromJSON(response.getText()); |
150 | 154 |
|
151 | 155 |
} |
152 | 156 |
else if(aclass.equals(SharedResource.class)){ |
153 |
result1 = new SharedResource(path);
|
|
157 |
result1 = new SharedResource(aPath);
|
|
154 | 158 |
result1.createFromJSON(response.getText()); |
155 | 159 |
|
156 | 160 |
} |
157 | 161 |
else if(aclass.equals(GroupResource.class)){ |
158 |
result1 = new GroupResource(path);
|
|
162 |
result1 = new GroupResource(aPath);
|
|
159 | 163 |
result1.createFromJSON(response.getText()); |
160 | 164 |
|
161 | 165 |
} |
162 | 166 |
else if(aclass.equals(GroupUserResource.class)){ |
163 |
result1 = new GroupUserResource(path);
|
|
167 |
result1 = new GroupUserResource(aPath);
|
|
164 | 168 |
result1.createFromJSON(response.getText()); |
165 | 169 |
|
166 | 170 |
} |
167 | 171 |
else if(aclass.equals(UserResource.class)){ |
168 |
result1 = new UserResource(path);
|
|
172 |
result1 = new UserResource(aPath);
|
|
169 | 173 |
result1.createFromJSON(response.getText()); |
170 | 174 |
|
171 | 175 |
} |
172 | 176 |
return result1; |
173 |
|
|
174 | 177 |
} |
175 |
|
|
176 | 178 |
} |
Also available in: Unified diff