root / web_client / src / gr / grnet / pithos / web / client / VersionsList.java @ 0737a2a4
History | View | Annotate | Download (11.1 kB)
1 | ab1eb3f8 | Christos Stathis | /*
|
---|---|---|---|
2 | 58777026 | Christos Stathis | * Copyright 2011 GRNET S.A. All rights reserved.
|
3 | 58777026 | Christos Stathis | *
|
4 | 58777026 | Christos Stathis | * Redistribution and use in source and binary forms, with or
|
5 | 58777026 | Christos Stathis | * without modification, are permitted provided that the following
|
6 | 58777026 | Christos Stathis | * conditions are met:
|
7 | 58777026 | Christos Stathis | *
|
8 | 58777026 | Christos Stathis | * 1. Redistributions of source code must retain the above
|
9 | 58777026 | Christos Stathis | * copyright notice, this list of conditions and the following
|
10 | 58777026 | Christos Stathis | * disclaimer.
|
11 | 58777026 | Christos Stathis | *
|
12 | 58777026 | Christos Stathis | * 2. Redistributions in binary form must reproduce the above
|
13 | 58777026 | Christos Stathis | * copyright notice, this list of conditions and the following
|
14 | 58777026 | Christos Stathis | * disclaimer in the documentation and/or other materials
|
15 | 58777026 | Christos Stathis | * provided with the distribution.
|
16 | 58777026 | Christos Stathis | *
|
17 | 58777026 | Christos Stathis | * THIS SOFTWARE IS PROVIDED BY GRNET S.A. ``AS IS'' AND ANY EXPRESS
|
18 | 58777026 | Christos Stathis | * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
19 | 58777026 | Christos Stathis | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
20 | 58777026 | Christos Stathis | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GRNET S.A OR
|
21 | 58777026 | Christos Stathis | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
22 | 58777026 | Christos Stathis | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
23 | 58777026 | Christos Stathis | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
|
24 | 58777026 | Christos Stathis | * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
25 | 58777026 | Christos Stathis | * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
26 | 58777026 | Christos Stathis | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
27 | 58777026 | Christos Stathis | * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
28 | 58777026 | Christos Stathis | * POSSIBILITY OF SUCH DAMAGE.
|
29 | 58777026 | Christos Stathis | *
|
30 | 58777026 | Christos Stathis | * The views and conclusions contained in the software and
|
31 | 58777026 | Christos Stathis | * documentation are those of the authors and should not be
|
32 | 58777026 | Christos Stathis | * interpreted as representing official policies, either expressed
|
33 | 58777026 | Christos Stathis | * or implied, of GRNET S.A.
|
34 | ab1eb3f8 | Christos Stathis | */
|
35 | ab1eb3f8 | Christos Stathis | package gr.grnet.pithos.web.client; |
36 | ab1eb3f8 | Christos Stathis | |
37 | ab1eb3f8 | Christos Stathis | import gr.grnet.pithos.web.client.FilePropertiesDialog.Images; |
38 | ab1eb3f8 | Christos Stathis | import gr.grnet.pithos.web.client.rest.DeleteCommand; |
39 | ab1eb3f8 | Christos Stathis | import gr.grnet.pithos.web.client.rest.GetCommand; |
40 | ab1eb3f8 | Christos Stathis | import gr.grnet.pithos.web.client.rest.PostCommand; |
41 | ab1eb3f8 | Christos Stathis | import gr.grnet.pithos.web.client.rest.RestCommand; |
42 | ab1eb3f8 | Christos Stathis | import gr.grnet.pithos.web.client.rest.RestException; |
43 | ab1eb3f8 | Christos Stathis | import gr.grnet.pithos.web.client.rest.resource.FileResource; |
44 | ab1eb3f8 | Christos Stathis | import gr.grnet.pithos.web.client.rest.resource.UserResource; |
45 | ab1eb3f8 | Christos Stathis | import gr.grnet.pithos.web.client.rest.resource.UserSearchResource; |
46 | ab1eb3f8 | Christos Stathis | |
47 | ab1eb3f8 | Christos Stathis | import java.util.ArrayList; |
48 | ab1eb3f8 | Christos Stathis | import java.util.Collections; |
49 | ab1eb3f8 | Christos Stathis | import java.util.Comparator; |
50 | ab1eb3f8 | Christos Stathis | import java.util.Date; |
51 | ab1eb3f8 | Christos Stathis | import java.util.List; |
52 | ab1eb3f8 | Christos Stathis | |
53 | ab1eb3f8 | Christos Stathis | |
54 | ab1eb3f8 | Christos Stathis | import com.google.gwt.core.client.GWT; |
55 | ab1eb3f8 | Christos Stathis | import com.google.gwt.event.dom.client.ClickEvent; |
56 | ab1eb3f8 | Christos Stathis | import com.google.gwt.event.dom.client.ClickHandler; |
57 | ab1eb3f8 | Christos Stathis | import com.google.gwt.http.client.URL; |
58 | ab1eb3f8 | Christos Stathis | import com.google.gwt.i18n.client.DateTimeFormat; |
59 | ab1eb3f8 | Christos Stathis | import com.google.gwt.user.client.DeferredCommand; |
60 | ab1eb3f8 | Christos Stathis | import com.google.gwt.user.client.Window; |
61 | ab1eb3f8 | Christos Stathis | import com.google.gwt.user.client.ui.AbstractImagePrototype; |
62 | ab1eb3f8 | Christos Stathis | import com.google.gwt.user.client.ui.Composite; |
63 | ab1eb3f8 | Christos Stathis | import com.google.gwt.user.client.ui.FlexTable; |
64 | ab1eb3f8 | Christos Stathis | import com.google.gwt.user.client.ui.HTML; |
65 | ab1eb3f8 | Christos Stathis | import com.google.gwt.user.client.ui.HasHorizontalAlignment; |
66 | ab1eb3f8 | Christos Stathis | import com.google.gwt.user.client.ui.VerticalPanel; |
67 | ab1eb3f8 | Christos Stathis | |
68 | ab1eb3f8 | Christos Stathis | public class VersionsList extends Composite { |
69 | ab1eb3f8 | Christos Stathis | |
70 | ab1eb3f8 | Christos Stathis | int selectedRow = -1; |
71 | ab1eb3f8 | Christos Stathis | |
72 | ab1eb3f8 | Christos Stathis | int permissionCount = -1; |
73 | ab1eb3f8 | Christos Stathis | |
74 | ab1eb3f8 | Christos Stathis | List<FileResource> versions = null; |
75 | ab1eb3f8 | Christos Stathis | |
76 | ab1eb3f8 | Christos Stathis | final Images images;
|
77 | ab1eb3f8 | Christos Stathis | |
78 | ab1eb3f8 | Christos Stathis | final VerticalPanel permPanel = new VerticalPanel(); |
79 | ab1eb3f8 | Christos Stathis | |
80 | ab1eb3f8 | Christos Stathis | final FlexTable permTable = new FlexTable(); |
81 | ab1eb3f8 | Christos Stathis | |
82 | ab1eb3f8 | Christos Stathis | FileResource toRemove = null;
|
83 | ab1eb3f8 | Christos Stathis | |
84 | ab1eb3f8 | Christos Stathis | FilePropertiesDialog container; |
85 | ab1eb3f8 | Christos Stathis | |
86 | ab1eb3f8 | Christos Stathis | public VersionsList(FilePropertiesDialog aContainer, final Images theImages, List<FileResource> theVersions) { |
87 | ab1eb3f8 | Christos Stathis | images = theImages; |
88 | ab1eb3f8 | Christos Stathis | container = aContainer; |
89 | ab1eb3f8 | Christos Stathis | versions = theVersions; |
90 | ab1eb3f8 | Christos Stathis | Collections.sort(theVersions, new Comparator<FileResource>(){ |
91 | ab1eb3f8 | Christos Stathis | |
92 | ab1eb3f8 | Christos Stathis | @Override
|
93 | ab1eb3f8 | Christos Stathis | public int compare(FileResource o1, FileResource o2) { |
94 | ab1eb3f8 | Christos Stathis | return o1.getVersion().compareTo(o2.getVersion());
|
95 | ab1eb3f8 | Christos Stathis | } |
96 | ab1eb3f8 | Christos Stathis | |
97 | ab1eb3f8 | Christos Stathis | }); |
98 | ab1eb3f8 | Christos Stathis | permTable.setText(0, 0, "Version"); |
99 | ab1eb3f8 | Christos Stathis | permTable.setText(0, 1, "Created"); |
100 | ab1eb3f8 | Christos Stathis | permTable.setText(0, 2, "Modified"); |
101 | ab1eb3f8 | Christos Stathis | permTable.setText(0, 3, "Size"); |
102 | ab1eb3f8 | Christos Stathis | permTable.setText(0, 4, ""); |
103 | ab1eb3f8 | Christos Stathis | permTable.setText(0, 5, ""); |
104 | ab1eb3f8 | Christos Stathis | permTable.getFlexCellFormatter().setStyleName(0, 0, "props-toplabels"); |
105 | ab1eb3f8 | Christos Stathis | permTable.getFlexCellFormatter().setStyleName(0, 1, "props-toplabels"); |
106 | ab1eb3f8 | Christos Stathis | permTable.getFlexCellFormatter().setStyleName(0, 2, "props-toplabels"); |
107 | ab1eb3f8 | Christos Stathis | permTable.getFlexCellFormatter().setStyleName(0, 3, "props-toplabels"); |
108 | ab1eb3f8 | Christos Stathis | permTable.getFlexCellFormatter().setColSpan(0, 1, 2); |
109 | ab1eb3f8 | Christos Stathis | permTable.getFlexCellFormatter().setHorizontalAlignment(0, 0, HasHorizontalAlignment.ALIGN_CENTER); |
110 | ab1eb3f8 | Christos Stathis | permTable.getFlexCellFormatter().setHorizontalAlignment(0, 1, HasHorizontalAlignment.ALIGN_CENTER); |
111 | ab1eb3f8 | Christos Stathis | permTable.getFlexCellFormatter().setHorizontalAlignment(0, 2, HasHorizontalAlignment.ALIGN_CENTER); |
112 | ab1eb3f8 | Christos Stathis | permTable.getFlexCellFormatter().setHorizontalAlignment(0, 3, HasHorizontalAlignment.ALIGN_CENTER); |
113 | ab1eb3f8 | Christos Stathis | permPanel.add(permTable); |
114 | ab1eb3f8 | Christos Stathis | permPanel.addStyleName("pithos-TabPanelBottom");
|
115 | ab1eb3f8 | Christos Stathis | permTable.addStyleName("pithos-permList");
|
116 | ab1eb3f8 | Christos Stathis | initWidget(permPanel); |
117 | ab1eb3f8 | Christos Stathis | updateTable(); |
118 | ab1eb3f8 | Christos Stathis | } |
119 | ab1eb3f8 | Christos Stathis | |
120 | ab1eb3f8 | Christos Stathis | public void updateTable() { |
121 | ab1eb3f8 | Christos Stathis | copyListAndContinue(versions); |
122 | ab1eb3f8 | Christos Stathis | } |
123 | ab1eb3f8 | Christos Stathis | |
124 | ab1eb3f8 | Christos Stathis | public void showVersionsTable(){ |
125 | ab1eb3f8 | Christos Stathis | int i = 1; |
126 | ab1eb3f8 | Christos Stathis | if (toRemove != null) { |
127 | ab1eb3f8 | Christos Stathis | versions.remove(toRemove); |
128 | ab1eb3f8 | Christos Stathis | toRemove = null;
|
129 | ab1eb3f8 | Christos Stathis | } |
130 | ab1eb3f8 | Christos Stathis | for (final FileResource dto : versions) { |
131 | ab1eb3f8 | Christos Stathis | HTML restoreVersion = new HTML("<a href='#' class='hidden-link info'><span>"+AbstractImagePrototype.create(images.restore()).getHTML()+"</span><div>Restore this Version</div></a>"); |
132 | ab1eb3f8 | Christos Stathis | restoreVersion.addClickHandler(new ClickHandler() {
|
133 | ab1eb3f8 | Christos Stathis | @Override
|
134 | ab1eb3f8 | Christos Stathis | public void onClick(ClickEvent event) { |
135 | ab1eb3f8 | Christos Stathis | restoreVersion(dto); |
136 | ab1eb3f8 | Christos Stathis | } |
137 | ab1eb3f8 | Christos Stathis | }); |
138 | ab1eb3f8 | Christos Stathis | |
139 | ab1eb3f8 | Christos Stathis | permTable.setHTML(i, 0, "<span>" + dto.getVersion() + "</span>"); |
140 | ab1eb3f8 | Christos Stathis | permTable.setHTML(i, 1, "<span>" + formatDate(dto.getCreationDate()) + " by " + GSS.get().findUserFullName(dto.getCreatedBy()) + "</span>"); |
141 | ab1eb3f8 | Christos Stathis | permTable.setHTML(i, 2, "<span>" + formatDate(dto.getModificationDate()) + " by " + GSS.get().findUserFullName(dto.getModifiedBy()) + "</span>"); |
142 | ab1eb3f8 | Christos Stathis | permTable.setHTML(i, 3, "<span>" + dto.getFileSizeAsString() + "</span>"); |
143 | ab1eb3f8 | Christos Stathis | HTML downloadHtml = new HTML("<a class='hidden-link info' href='#'><span>"+AbstractImagePrototype.create(images.download()).getHTML()+"</span><div>View this Version</div></a>"); |
144 | ab1eb3f8 | Christos Stathis | downloadHtml.addClickHandler(new ClickHandler() {
|
145 | ab1eb3f8 | Christos Stathis | @Override
|
146 | ab1eb3f8 | Christos Stathis | public void onClick(ClickEvent event) { |
147 | ab1eb3f8 | Christos Stathis | GSS app = GSS.get(); |
148 | ab1eb3f8 | Christos Stathis | String dateString = RestCommand.getDate();
|
149 | ab1eb3f8 | Christos Stathis | String resource = dto.getUri().substring(app.getApiPath().length()-1, dto.getUri().length()); |
150 | ab1eb3f8 | Christos Stathis | String sig = app.getCurrentUserResource().getUsername()+" "+RestCommand.calculateSig("GET", dateString, resource, RestCommand.base64decode(app.getToken())); |
151 | ab1eb3f8 | Christos Stathis | String fileUrl = dto.getUri() + "?version=" + dto.getVersion() + "&Authorization=" + URL.encodeComponent(sig) + "&Date="+URL.encodeComponent(dateString); |
152 | ab1eb3f8 | Christos Stathis | Window.open(fileUrl, "_BLANK", ""); |
153 | ab1eb3f8 | Christos Stathis | } |
154 | ab1eb3f8 | Christos Stathis | }); |
155 | ab1eb3f8 | Christos Stathis | permTable.setWidget(i, 4, downloadHtml);
|
156 | ab1eb3f8 | Christos Stathis | permTable.setWidget(i, 5, restoreVersion);
|
157 | ab1eb3f8 | Christos Stathis | permTable.getFlexCellFormatter().setStyleName(i, 0, "props-labels"); |
158 | ab1eb3f8 | Christos Stathis | permTable.getFlexCellFormatter().setHorizontalAlignment(i, 0, HasHorizontalAlignment.ALIGN_CENTER);
|
159 | ab1eb3f8 | Christos Stathis | permTable.getFlexCellFormatter().setHorizontalAlignment(i, 1, HasHorizontalAlignment.ALIGN_CENTER);
|
160 | ab1eb3f8 | Christos Stathis | permTable.getFlexCellFormatter().setColSpan(i, 1, 2); |
161 | ab1eb3f8 | Christos Stathis | permTable.getFlexCellFormatter().setHorizontalAlignment(i, 2, HasHorizontalAlignment.ALIGN_CENTER);
|
162 | ab1eb3f8 | Christos Stathis | permTable.getFlexCellFormatter().setHorizontalAlignment(i, 3, HasHorizontalAlignment.ALIGN_CENTER);
|
163 | ab1eb3f8 | Christos Stathis | i++; |
164 | ab1eb3f8 | Christos Stathis | } |
165 | ab1eb3f8 | Christos Stathis | for (; i < permTable.getRowCount(); i++)
|
166 | ab1eb3f8 | Christos Stathis | permTable.removeRow(i); |
167 | ab1eb3f8 | Christos Stathis | } |
168 | ab1eb3f8 | Christos Stathis | |
169 | ab1eb3f8 | Christos Stathis | void removeVersion(final FileResource version) { |
170 | ab1eb3f8 | Christos Stathis | DeleteCommand df = new DeleteCommand(version.getUri()){
|
171 | ab1eb3f8 | Christos Stathis | |
172 | ab1eb3f8 | Christos Stathis | @Override
|
173 | ab1eb3f8 | Christos Stathis | public void onComplete() { |
174 | ab1eb3f8 | Christos Stathis | toRemove = version; |
175 | ab1eb3f8 | Christos Stathis | updateTable(); |
176 | ab1eb3f8 | Christos Stathis | GSS.get().getTreeView().refreshCurrentNode(false);
|
177 | ab1eb3f8 | Christos Stathis | } |
178 | ab1eb3f8 | Christos Stathis | |
179 | ab1eb3f8 | Christos Stathis | @Override
|
180 | ab1eb3f8 | Christos Stathis | public void onError(Throwable t) { |
181 | ab1eb3f8 | Christos Stathis | GWT.log("", t);
|
182 | ab1eb3f8 | Christos Stathis | if(t instanceof RestException){ |
183 | ab1eb3f8 | Christos Stathis | int statusCode = ((RestException)t).getHttpStatusCode();
|
184 | ab1eb3f8 | Christos Stathis | if(statusCode == 405) |
185 | ab1eb3f8 | Christos Stathis | GSS.get().displayError("You don't have the necessary permissions");
|
186 | ab1eb3f8 | Christos Stathis | else if(statusCode == 404) |
187 | ab1eb3f8 | Christos Stathis | GSS.get().displayError("Versions does not exist");
|
188 | ab1eb3f8 | Christos Stathis | else
|
189 | ab1eb3f8 | Christos Stathis | GSS.get().displayError("Unable to remove version:"+((RestException)t).getHttpStatusText());
|
190 | ab1eb3f8 | Christos Stathis | } |
191 | ab1eb3f8 | Christos Stathis | else
|
192 | ab1eb3f8 | Christos Stathis | GSS.get().displayError("System error removing version:"+t.getMessage());
|
193 | ab1eb3f8 | Christos Stathis | } |
194 | ab1eb3f8 | Christos Stathis | }; |
195 | ab1eb3f8 | Christos Stathis | DeferredCommand.addCommand(df); |
196 | ab1eb3f8 | Christos Stathis | |
197 | ab1eb3f8 | Christos Stathis | } |
198 | ab1eb3f8 | Christos Stathis | |
199 | ab1eb3f8 | Christos Stathis | void restoreVersion(final FileResource version) { |
200 | ab1eb3f8 | Christos Stathis | FileResource selectedFile = (FileResource) GSS.get().getCurrentSelection(); |
201 | ab1eb3f8 | Christos Stathis | PostCommand ep = new PostCommand(selectedFile.getUri()+"?restoreVersion="+version.getVersion(),"",200){ |
202 | ab1eb3f8 | Christos Stathis | |
203 | ab1eb3f8 | Christos Stathis | |
204 | ab1eb3f8 | Christos Stathis | @Override
|
205 | ab1eb3f8 | Christos Stathis | public void onComplete() { |
206 | ab1eb3f8 | Christos Stathis | container.hide(); |
207 | ab1eb3f8 | Christos Stathis | GSS.get().getTreeView().refreshCurrentNode(false);
|
208 | ab1eb3f8 | Christos Stathis | } |
209 | ab1eb3f8 | Christos Stathis | |
210 | ab1eb3f8 | Christos Stathis | @Override
|
211 | ab1eb3f8 | Christos Stathis | public void onError(Throwable t) { |
212 | ab1eb3f8 | Christos Stathis | GWT.log("", t);
|
213 | ab1eb3f8 | Christos Stathis | if(t instanceof RestException) |
214 | ab1eb3f8 | Christos Stathis | GSS.get().displayError("Unable to restore version:"+((RestException)t).getHttpStatusText());
|
215 | ab1eb3f8 | Christos Stathis | else
|
216 | ab1eb3f8 | Christos Stathis | GSS.get().displayError("System error restoring version:"+t.getMessage());
|
217 | ab1eb3f8 | Christos Stathis | } |
218 | ab1eb3f8 | Christos Stathis | |
219 | ab1eb3f8 | Christos Stathis | }; |
220 | ab1eb3f8 | Christos Stathis | DeferredCommand.addCommand(ep); |
221 | ab1eb3f8 | Christos Stathis | } |
222 | ab1eb3f8 | Christos Stathis | |
223 | ab1eb3f8 | Christos Stathis | private String formatDate(Date date){ |
224 | ab1eb3f8 | Christos Stathis | DateTimeFormat format = DateTimeFormat.getFormat("dd/MM/yyyy : HH:mm");
|
225 | ab1eb3f8 | Christos Stathis | return format.format(date);
|
226 | ab1eb3f8 | Christos Stathis | } |
227 | ab1eb3f8 | Christos Stathis | |
228 | ab1eb3f8 | Christos Stathis | /**
|
229 | ab1eb3f8 | Christos Stathis | * Copies the input List to a new List
|
230 | ab1eb3f8 | Christos Stathis | * @param input
|
231 | ab1eb3f8 | Christos Stathis | */
|
232 | ab1eb3f8 | Christos Stathis | private void copyListAndContinue(List<FileResource> input){ |
233 | ab1eb3f8 | Christos Stathis | List<FileResource> copiedInput = new ArrayList<FileResource>(); |
234 | ab1eb3f8 | Christos Stathis | for(FileResource dto : input) {
|
235 | ab1eb3f8 | Christos Stathis | copiedInput.add(dto); |
236 | ab1eb3f8 | Christos Stathis | } |
237 | ab1eb3f8 | Christos Stathis | handleFullNames(copiedInput); |
238 | ab1eb3f8 | Christos Stathis | } |
239 | ab1eb3f8 | Christos Stathis | |
240 | ab1eb3f8 | Christos Stathis | /**
|
241 | ab1eb3f8 | Christos Stathis | * Examines whether or not the user's full name exists in the
|
242 | ab1eb3f8 | Christos Stathis | * userFullNameMap in the GSS.java for every element of the input list.
|
243 | ab1eb3f8 | Christos Stathis | * If the user's full name does not exist in the map then a request is being made
|
244 | ab1eb3f8 | Christos Stathis | * for the specific username.
|
245 | ab1eb3f8 | Christos Stathis | *
|
246 | ab1eb3f8 | Christos Stathis | * @param input
|
247 | ab1eb3f8 | Christos Stathis | */
|
248 | ab1eb3f8 | Christos Stathis | private void handleFullNames(List<FileResource> input){ |
249 | ab1eb3f8 | Christos Stathis | if(input.isEmpty()){
|
250 | ab1eb3f8 | Christos Stathis | showVersionsTable(); |
251 | ab1eb3f8 | Christos Stathis | return;
|
252 | ab1eb3f8 | Christos Stathis | } |
253 | ab1eb3f8 | Christos Stathis | |
254 | ab1eb3f8 | Christos Stathis | if(GSS.get().findUserFullName(input.get(0).getOwner()) == null){ |
255 | ab1eb3f8 | Christos Stathis | findFullNameAndUpdate(input); |
256 | ab1eb3f8 | Christos Stathis | return;
|
257 | ab1eb3f8 | Christos Stathis | } |
258 | ab1eb3f8 | Christos Stathis | |
259 | ab1eb3f8 | Christos Stathis | if(input.size() >= 1){ |
260 | ab1eb3f8 | Christos Stathis | input.remove(input.get(0));
|
261 | ab1eb3f8 | Christos Stathis | if(input.isEmpty()){
|
262 | ab1eb3f8 | Christos Stathis | showVersionsTable(); |
263 | ab1eb3f8 | Christos Stathis | }else{
|
264 | ab1eb3f8 | Christos Stathis | handleFullNames(input); |
265 | ab1eb3f8 | Christos Stathis | } |
266 | ab1eb3f8 | Christos Stathis | } |
267 | ab1eb3f8 | Christos Stathis | } |
268 | ab1eb3f8 | Christos Stathis | |
269 | ab1eb3f8 | Christos Stathis | /**
|
270 | ab1eb3f8 | Christos Stathis | * Makes a request to search for full name from a given username
|
271 | ab1eb3f8 | Christos Stathis | * and continues checking the next element of the List.
|
272 | ab1eb3f8 | Christos Stathis | *
|
273 | ab1eb3f8 | Christos Stathis | * @param input
|
274 | ab1eb3f8 | Christos Stathis | */
|
275 | ab1eb3f8 | Christos Stathis | |
276 | ab1eb3f8 | Christos Stathis | private void findFullNameAndUpdate(final List<FileResource> input){ |
277 | ab1eb3f8 | Christos Stathis | final String aUserName = input.get(0).getOwner(); |
278 | ab1eb3f8 | Christos Stathis | String path = GSS.get().getApiPath() + "users/" + aUserName; |
279 | ab1eb3f8 | Christos Stathis | |
280 | ab1eb3f8 | Christos Stathis | GetCommand<UserSearchResource> gg = new GetCommand<UserSearchResource>(UserSearchResource.class, path, false,null) { |
281 | ab1eb3f8 | Christos Stathis | @Override
|
282 | ab1eb3f8 | Christos Stathis | public void onComplete() { |
283 | ab1eb3f8 | Christos Stathis | final UserSearchResource result = getResult();
|
284 | ab1eb3f8 | Christos Stathis | for (UserResource user : result.getUsers()){
|
285 | ab1eb3f8 | Christos Stathis | String username = user.getUsername();
|
286 | ab1eb3f8 | Christos Stathis | String userFullName = user.getName();
|
287 | ab1eb3f8 | Christos Stathis | GSS.get().putUserToMap(username, userFullName); |
288 | ab1eb3f8 | Christos Stathis | if(input.size() >= 1){ |
289 | ab1eb3f8 | Christos Stathis | input.remove(input.get(0));
|
290 | ab1eb3f8 | Christos Stathis | if(input.isEmpty()){
|
291 | ab1eb3f8 | Christos Stathis | showVersionsTable(); |
292 | ab1eb3f8 | Christos Stathis | return;
|
293 | ab1eb3f8 | Christos Stathis | } |
294 | ab1eb3f8 | Christos Stathis | handleFullNames(input); |
295 | ab1eb3f8 | Christos Stathis | } |
296 | ab1eb3f8 | Christos Stathis | } |
297 | ab1eb3f8 | Christos Stathis | } |
298 | ab1eb3f8 | Christos Stathis | @Override
|
299 | ab1eb3f8 | Christos Stathis | public void onError(Throwable t) { |
300 | ab1eb3f8 | Christos Stathis | GSS.get().displayError("Unable to fetch user's full name from the given username " + aUserName);
|
301 | ab1eb3f8 | Christos Stathis | if(input.size() >= 1){ |
302 | ab1eb3f8 | Christos Stathis | input.remove(input.get(0));
|
303 | ab1eb3f8 | Christos Stathis | handleFullNames(input); |
304 | ab1eb3f8 | Christos Stathis | } |
305 | ab1eb3f8 | Christos Stathis | } |
306 | ab1eb3f8 | Christos Stathis | }; |
307 | ab1eb3f8 | Christos Stathis | DeferredCommand.addCommand(gg); |
308 | ab1eb3f8 | Christos Stathis | |
309 | ab1eb3f8 | Christos Stathis | } |
310 | ab1eb3f8 | Christos Stathis | |
311 | ab1eb3f8 | Christos Stathis | } |