root / src / gr / grnet / pithos / web / client / FilePropertiesDialog.java @ fa68c84d
History | View | Annotate | Download (14.2 kB)
1 | a57faaf0 | Christos Stathis | /*
|
---|---|---|---|
2 | cae2a8db | Christos Stathis | * Copyright 2011-2012 GRNET S.A. All rights reserved.
|
3 | 63366925 | Christos Stathis | *
|
4 | 63366925 | Christos Stathis | * Redistribution and use in source and binary forms, with or
|
5 | 63366925 | Christos Stathis | * without modification, are permitted provided that the following
|
6 | 63366925 | Christos Stathis | * conditions are met:
|
7 | 63366925 | Christos Stathis | *
|
8 | 63366925 | Christos Stathis | * 1. Redistributions of source code must retain the above
|
9 | 63366925 | Christos Stathis | * copyright notice, this list of conditions and the following
|
10 | 63366925 | Christos Stathis | * disclaimer.
|
11 | 63366925 | Christos Stathis | *
|
12 | 63366925 | Christos Stathis | * 2. Redistributions in binary form must reproduce the above
|
13 | 63366925 | Christos Stathis | * copyright notice, this list of conditions and the following
|
14 | 63366925 | Christos Stathis | * disclaimer in the documentation and/or other materials
|
15 | 63366925 | Christos Stathis | * provided with the distribution.
|
16 | 63366925 | Christos Stathis | *
|
17 | 63366925 | Christos Stathis | * THIS SOFTWARE IS PROVIDED BY GRNET S.A. ``AS IS'' AND ANY EXPRESS
|
18 | 63366925 | Christos Stathis | * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
19 | 63366925 | Christos Stathis | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
20 | 63366925 | Christos Stathis | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GRNET S.A OR
|
21 | 63366925 | Christos Stathis | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
22 | 63366925 | Christos Stathis | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
23 | 63366925 | Christos Stathis | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
|
24 | 63366925 | Christos Stathis | * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
25 | 63366925 | Christos Stathis | * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
26 | 63366925 | Christos Stathis | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
27 | 63366925 | Christos Stathis | * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
28 | 63366925 | Christos Stathis | * POSSIBILITY OF SUCH DAMAGE.
|
29 | 63366925 | Christos Stathis | *
|
30 | 63366925 | Christos Stathis | * The views and conclusions contained in the software and
|
31 | 63366925 | Christos Stathis | * documentation are those of the authors and should not be
|
32 | 63366925 | Christos Stathis | * interpreted as representing official policies, either expressed
|
33 | 63366925 | Christos Stathis | * or implied, of GRNET S.A.
|
34 | a57faaf0 | Christos Stathis | */
|
35 | a57faaf0 | Christos Stathis | package gr.grnet.pithos.web.client; |
36 | a57faaf0 | Christos Stathis | |
37 | 31997f49 | Christos Stathis | import gr.grnet.pithos.web.client.foldertree.File; |
38 | ef5b664d | Christos Stathis | import gr.grnet.pithos.web.client.rest.PostRequest; |
39 | 31997f49 | Christos Stathis | import gr.grnet.pithos.web.client.rest.PutRequest; |
40 | 7811b9d1 | Christos Stathis | |
41 | d26e2ef7 | Christos Stathis | import java.util.Arrays; |
42 | 947da718 | Christos Stathis | import java.util.HashMap; |
43 | 7811b9d1 | Christos Stathis | import java.util.Map; |
44 | a57faaf0 | Christos Stathis | |
45 | a57faaf0 | Christos Stathis | import com.google.gwt.core.client.GWT; |
46 | 7811b9d1 | Christos Stathis | import com.google.gwt.core.client.Scheduler; |
47 | a57faaf0 | Christos Stathis | import com.google.gwt.event.dom.client.ClickEvent; |
48 | a57faaf0 | Christos Stathis | import com.google.gwt.event.dom.client.ClickHandler; |
49 | 9539e23d | Christos Stathis | import com.google.gwt.http.client.Response; |
50 | ea94470a | Christos Stathis | import com.google.gwt.http.client.URL; |
51 | a57faaf0 | Christos Stathis | import com.google.gwt.i18n.client.DateTimeFormat; |
52 | 3601b114 | Christos Stathis | import com.google.gwt.user.client.Command; |
53 | 7811b9d1 | Christos Stathis | import com.google.gwt.user.client.ui.Anchor; |
54 | a57faaf0 | Christos Stathis | import com.google.gwt.user.client.ui.Button; |
55 | a57faaf0 | Christos Stathis | import com.google.gwt.user.client.ui.FlexTable; |
56 | a57faaf0 | Christos Stathis | import com.google.gwt.user.client.ui.HasHorizontalAlignment; |
57 | a57faaf0 | Christos Stathis | import com.google.gwt.user.client.ui.HorizontalPanel; |
58 | 7811b9d1 | Christos Stathis | import com.google.gwt.user.client.ui.Label; |
59 | a57faaf0 | Christos Stathis | import com.google.gwt.user.client.ui.TextBox; |
60 | a57faaf0 | Christos Stathis | import com.google.gwt.user.client.ui.VerticalPanel; |
61 | a57faaf0 | Christos Stathis | |
62 | a57faaf0 | Christos Stathis | /**
|
63 | a57faaf0 | Christos Stathis | * The 'File properties' dialog box implementation.
|
64 | a57faaf0 | Christos Stathis | *
|
65 | a57faaf0 | Christos Stathis | */
|
66 | a57faaf0 | Christos Stathis | public class FilePropertiesDialog extends AbstractPropertiesDialog { |
67 | a57faaf0 | Christos Stathis | |
68 | a57faaf0 | Christos Stathis | /**
|
69 | a57faaf0 | Christos Stathis | * The widget that holds the name of the file.
|
70 | a57faaf0 | Christos Stathis | */
|
71 | a57faaf0 | Christos Stathis | private TextBox name = new TextBox(); |
72 | a57faaf0 | Christos Stathis | |
73 | 31997f49 | Christos Stathis | final File file; |
74 | a57faaf0 | Christos Stathis | |
75 | 904447e4 | Christos Stathis | FlexTable metaTable; |
76 | a57faaf0 | Christos Stathis | /**
|
77 | a57faaf0 | Christos Stathis | * The widget's constructor.
|
78 | a57faaf0 | Christos Stathis | */
|
79 | 749068ba | Christos Stathis | public FilePropertiesDialog(Pithos _app, File _file) { |
80 | a7c43f26 | Christos Stathis | super(_app);
|
81 | 31997f49 | Christos Stathis | file = _file; |
82 | a57faaf0 | Christos Stathis | |
83 | 96705b13 | Christos Stathis | Anchor close = new Anchor("close"); |
84 | 4420a247 | Christos Stathis | close.addStyleName("close");
|
85 | 4420a247 | Christos Stathis | close.addClickHandler(new ClickHandler() {
|
86 | 4420a247 | Christos Stathis | |
87 | 4420a247 | Christos Stathis | @Override
|
88 | ebead1b5 | Christos Stathis | public void onClick(ClickEvent event) { |
89 | 4420a247 | Christos Stathis | hide(); |
90 | 4420a247 | Christos Stathis | } |
91 | 4420a247 | Christos Stathis | }); |
92 | a57faaf0 | Christos Stathis | // Set the dialog's caption.
|
93 | a57faaf0 | Christos Stathis | setText("File properties");
|
94 | 4420a247 | Christos Stathis | setGlassEnabled(true);
|
95 | 4420a247 | Christos Stathis | setStyleName("pithos-DialogBox");
|
96 | a57faaf0 | Christos Stathis | |
97 | a57faaf0 | Christos Stathis | // Outer contains inner and buttons.
|
98 | a57faaf0 | Christos Stathis | final VerticalPanel outer = new VerticalPanel(); |
99 | 4420a247 | Christos Stathis | outer.add(close); |
100 | a57faaf0 | Christos Stathis | // Inner contains generalPanel and permPanel.
|
101 | 9326b841 | Christos Stathis | inner = new VerticalPanel();
|
102 | 4420a247 | Christos Stathis | inner.addStyleName("inner");
|
103 | a57faaf0 | Christos Stathis | |
104 | 9326b841 | Christos Stathis | inner.add(createGeneralPanel()); |
105 | a57faaf0 | Christos Stathis | |
106 | 31997f49 | Christos Stathis | outer.add(inner); |
107 | 31997f49 | Christos Stathis | |
108 | a57faaf0 | Christos Stathis | // Create the 'OK' button, along with a listener that hides the dialog
|
109 | a57faaf0 | Christos Stathis | // when the button is clicked.
|
110 | a57faaf0 | Christos Stathis | final Button ok = new Button("OK", new ClickHandler() { |
111 | a57faaf0 | Christos Stathis | @Override
|
112 | ebead1b5 | Christos Stathis | public void onClick(ClickEvent event) { |
113 | 0099339a | Christos Stathis | if (accept())
|
114 | 0099339a | Christos Stathis | closeDialog(); |
115 | a57faaf0 | Christos Stathis | } |
116 | a57faaf0 | Christos Stathis | }); |
117 | 4420a247 | Christos Stathis | ok.addStyleName("button");
|
118 | 31997f49 | Christos Stathis | |
119 | 4420a247 | Christos Stathis | outer.add(ok); |
120 | 4420a247 | Christos Stathis | outer.setCellHorizontalAlignment(inner, HasHorizontalAlignment.ALIGN_CENTER); |
121 | 31997f49 | Christos Stathis | |
122 | 31997f49 | Christos Stathis | setWidget(outer); |
123 | a57faaf0 | Christos Stathis | } |
124 | a57faaf0 | Christos Stathis | |
125 | 611de529 | Christos Stathis | private VerticalPanel createGeneralPanel() {
|
126 | 31997f49 | Christos Stathis | final VerticalPanel generalPanel = new VerticalPanel(); |
127 | 31997f49 | Christos Stathis | final FlexTable generalTable = new FlexTable(); |
128 | 31997f49 | Christos Stathis | generalTable.setText(0, 0, "Name"); |
129 | 31997f49 | Christos Stathis | generalTable.setText(1, 0, "Folder"); |
130 | 31997f49 | Christos Stathis | generalTable.setText(2, 0, "Owner"); |
131 | 31997f49 | Christos Stathis | generalTable.setText(3, 0, "Last modified"); |
132 | 31997f49 | Christos Stathis | |
133 | 31997f49 | Christos Stathis | name.setWidth("100%");
|
134 | 31997f49 | Christos Stathis | name.setText(file.getName()); |
135 | 31997f49 | Christos Stathis | generalTable.setWidget(0, 1, name); |
136 | cde22209 | Christos KK Loverdos | if(file.getParent() != null) { |
137 | 31997f49 | Christos Stathis | generalTable.setText(1, 1, file.getParent().getName()); |
138 | cde22209 | Christos KK Loverdos | } |
139 | cde22209 | Christos KK Loverdos | else {
|
140 | 31997f49 | Christos Stathis | generalTable.setText(1, 1, "-"); |
141 | cde22209 | Christos KK Loverdos | } |
142 | cde22209 | Christos KK Loverdos | |
143 | cde22209 | Christos KK Loverdos | final String ownerID = file.getOwnerID(); |
144 | b9a1049a | Christos KK Loverdos | final String displayName = app.getUserDisplayNameForID(ownerID); |
145 | cde22209 | Christos KK Loverdos | final String ownerDisplayName; |
146 | cde22209 | Christos KK Loverdos | if(displayName == null) { |
147 | cde22209 | Christos KK Loverdos | // FIXME: Get the actual display name and do not use the id
|
148 | cde22209 | Christos KK Loverdos | ownerDisplayName = ownerID; |
149 | cde22209 | Christos KK Loverdos | } |
150 | cde22209 | Christos KK Loverdos | else {
|
151 | cde22209 | Christos KK Loverdos | ownerDisplayName = displayName; |
152 | cde22209 | Christos KK Loverdos | } |
153 | cde22209 | Christos KK Loverdos | generalTable.setText(2, 1, ownerDisplayName); |
154 | 31997f49 | Christos Stathis | |
155 | 31997f49 | Christos Stathis | final DateTimeFormat formatter = DateTimeFormat.getFormat("d/M/yyyy h:mm a"); |
156 | f3c8bd5b | Christos Stathis | generalTable.setText(3, 1, file.getLastModified() != null ? formatter.format(file.getLastModified()) : ""); |
157 | 31997f49 | Christos Stathis | |
158 | 31997f49 | Christos Stathis | generalTable.getFlexCellFormatter().setStyleName(0, 0, "props-labels"); |
159 | 31997f49 | Christos Stathis | generalTable.getFlexCellFormatter().setStyleName(1, 0, "props-labels"); |
160 | 31997f49 | Christos Stathis | generalTable.getFlexCellFormatter().setStyleName(2, 0, "props-labels"); |
161 | 31997f49 | Christos Stathis | generalTable.getFlexCellFormatter().setStyleName(3, 0, "props-labels"); |
162 | ef5b664d | Christos Stathis | generalTable.getFlexCellFormatter().setStyleName(4, 0, "props-labels"); |
163 | 31997f49 | Christos Stathis | generalTable.getFlexCellFormatter().setStyleName(0, 1, "props-values"); |
164 | 31997f49 | Christos Stathis | generalTable.getFlexCellFormatter().setStyleName(1, 1, "props-values"); |
165 | 31997f49 | Christos Stathis | generalTable.getFlexCellFormatter().setStyleName(2, 1, "props-values"); |
166 | 31997f49 | Christos Stathis | generalTable.getFlexCellFormatter().setStyleName(3, 1, "props-values"); |
167 | 31997f49 | Christos Stathis | generalTable.setCellSpacing(4);
|
168 | 31997f49 | Christos Stathis | |
169 | 31997f49 | Christos Stathis | generalPanel.add(generalTable); |
170 | 31997f49 | Christos Stathis | |
171 | 904447e4 | Christos Stathis | HorizontalPanel metaTitlePanel = new HorizontalPanel();
|
172 | 904447e4 | Christos Stathis | metaTitlePanel.setSpacing(5);
|
173 | 947da718 | Christos Stathis | Label meta = new Label("Meta data"); |
174 | 904447e4 | Christos Stathis | meta.addStyleName("pithos-metaTitle");
|
175 | 904447e4 | Christos Stathis | metaTitlePanel.add(meta); |
176 | 904447e4 | Christos Stathis | |
177 | 5d2050bf | Christos Stathis | Anchor plus = new Anchor("add"); |
178 | 5d2050bf | Christos Stathis | plus.addStyleName(Pithos.resources.pithosCss().commandAnchor()); |
179 | 904447e4 | Christos Stathis | metaTitlePanel.add(plus); |
180 | 904447e4 | Christos Stathis | |
181 | 904447e4 | Christos Stathis | generalPanel.add(metaTitlePanel); |
182 | 947da718 | Christos Stathis | |
183 | 947da718 | Christos Stathis | metaTable = new FlexTable();
|
184 | 947da718 | Christos Stathis | metaTable.setCellSpacing(0);
|
185 | 947da718 | Christos Stathis | metaTable.setHTML(0, 0, "Name"); |
186 | 947da718 | Christos Stathis | metaTable.getFlexCellFormatter().setStyleName(0, 0, "props-labels"); |
187 | 947da718 | Christos Stathis | metaTable.setText(0, 1, "Value"); |
188 | 947da718 | Christos Stathis | metaTable.getFlexCellFormatter().setStyleName(0, 1, "props-labels"); |
189 | 947da718 | Christos Stathis | int rows = 1; |
190 | 947da718 | Christos Stathis | for (String metaKey : file.getMeta().keySet()) { |
191 | 947da718 | Christos Stathis | addFormLine(metaTable, rows++, metaKey, file.getMeta().get(metaKey)); |
192 | 947da718 | Christos Stathis | } |
193 | 904447e4 | Christos Stathis | if (rows == 1) //If no meta add an empty line |
194 | 904447e4 | Christos Stathis | addFormLine(metaTable, rows++, "", ""); |
195 | 947da718 | Christos Stathis | |
196 | 947da718 | Christos Stathis | plus.addClickHandler(new ClickHandler() {
|
197 | 947da718 | Christos Stathis | |
198 | 947da718 | Christos Stathis | @Override
|
199 | ebead1b5 | Christos Stathis | public void onClick(ClickEvent event) { |
200 | 947da718 | Christos Stathis | addFormLine(metaTable, metaTable.getRowCount(), "", ""); |
201 | 947da718 | Christos Stathis | } |
202 | 947da718 | Christos Stathis | }); |
203 | ef5b664d | Christos Stathis | |
204 | 947da718 | Christos Stathis | generalPanel.add(metaTable); |
205 | 31997f49 | Christos Stathis | generalPanel.setSpacing(4);
|
206 | 31997f49 | Christos Stathis | return generalPanel;
|
207 | 31997f49 | Christos Stathis | } |
208 | 31997f49 | Christos Stathis | |
209 | 904447e4 | Christos Stathis | void addFormLine(final FlexTable table, int row, String _name, String _value) { |
210 | 947da718 | Christos Stathis | TextBox nameBox = new TextBox();
|
211 | 904447e4 | Christos Stathis | nameBox.setText(_name); |
212 | 904447e4 | Christos Stathis | nameBox.addStyleName("pithos-metaName");
|
213 | 947da718 | Christos Stathis | table.setWidget(row, 0, nameBox);
|
214 | 947da718 | Christos Stathis | table.getFlexCellFormatter().setStyleName(1, 0, "props-values"); |
215 | 947da718 | Christos Stathis | |
216 | 947da718 | Christos Stathis | TextBox valueBox = new TextBox();
|
217 | 904447e4 | Christos Stathis | valueBox.setText(_value); |
218 | 904447e4 | Christos Stathis | valueBox.addStyleName("pithos-metaValue");
|
219 | 947da718 | Christos Stathis | table.setWidget(row, 1, valueBox);
|
220 | 947da718 | Christos Stathis | table.getFlexCellFormatter().setStyleName(1, 1, "props-values"); |
221 | 947da718 | Christos Stathis | |
222 | 5d2050bf | Christos Stathis | Anchor delete = new Anchor("remove"); |
223 | 5d2050bf | Christos Stathis | delete.addStyleName(Pithos.resources.pithosCss().commandAnchor()); |
224 | 947da718 | Christos Stathis | delete.addClickHandler(new ClickHandler() {
|
225 | 947da718 | Christos Stathis | |
226 | 947da718 | Christos Stathis | @Override
|
227 | 947da718 | Christos Stathis | public void onClick(ClickEvent event) { |
228 | 947da718 | Christos Stathis | int rowIndex = table.getCellForEvent(event).getRowIndex();
|
229 | 947da718 | Christos Stathis | table.removeRow(rowIndex); |
230 | 947da718 | Christos Stathis | } |
231 | 947da718 | Christos Stathis | }); |
232 | 947da718 | Christos Stathis | table.setWidget(row, 2, delete);
|
233 | 947da718 | Christos Stathis | } |
234 | 947da718 | Christos Stathis | |
235 | a57faaf0 | Christos Stathis | /**
|
236 | a57faaf0 | Christos Stathis | * Accepts any change and updates the file
|
237 | a57faaf0 | Christos Stathis | *
|
238 | a57faaf0 | Christos Stathis | */
|
239 | a57faaf0 | Christos Stathis | @Override
|
240 | 0099339a | Christos Stathis | protected boolean accept() { |
241 | a57faaf0 | Christos Stathis | String newFilename = null; |
242 | ecf95c9e | Christos Stathis | |
243 | ef5b664d | Christos Stathis | if (!name.getText().trim().equals(file.getName())) {
|
244 | ef5b664d | Christos Stathis | newFilename = name.getText().trim(); |
245 | 0099339a | Christos Stathis | if (newFilename.length() == 0) |
246 | 0099339a | Christos Stathis | newFilename = null;
|
247 | a57faaf0 | Christos Stathis | } |
248 | 0099339a | Christos Stathis | |
249 | ecf95c9e | Christos Stathis | |
250 | 947da718 | Christos Stathis | final Map<String, String> newMeta = new HashMap<String, String>(); |
251 | 947da718 | Christos Stathis | for (int row = 1; row < metaTable.getRowCount(); row++) { |
252 | 947da718 | Christos Stathis | String key = ((TextBox) metaTable.getWidget(row, 0)).getText().trim(); |
253 | 947da718 | Christos Stathis | String value = ((TextBox) metaTable.getWidget(row, 1)).getText().trim(); |
254 | 904447e4 | Christos Stathis | if (key.length() > 0 && value.length() > 0) |
255 | 904447e4 | Christos Stathis | newMeta.put(key, value); |
256 | 0099339a | Christos Stathis | else if ((key.length() > 0 && value.length() == 0) || (key.length() == 0 && value.length() > 0)) { |
257 | 0099339a | Christos Stathis | app.displayError("You have empty keys or values");
|
258 | 0099339a | Christos Stathis | return false; |
259 | 0099339a | Christos Stathis | } |
260 | 947da718 | Christos Stathis | } |
261 | ef5b664d | Christos Stathis | |
262 | ef5b664d | Christos Stathis | if (newFilename != null) { |
263 | b51c628b | Christos Stathis | final String path = file.getParent().getUri() + "/" + newFilename; |
264 | cc0120ab | Christos KK Loverdos | PutRequest updateFile = new PutRequest(app.getApiPath(), app.getUserID(), path) {
|
265 | ef5b664d | Christos Stathis | @Override
|
266 | ebead1b5 | Christos Stathis | public void onSuccess(Resource result) { |
267 | cde22209 | Christos KK Loverdos | updateMetaData(app.getApiPath(), file.getOwnerID(), path, newMeta); |
268 | ef5b664d | Christos Stathis | } |
269 | ef5b664d | Christos Stathis | |
270 | ef5b664d | Christos Stathis | @Override
|
271 | ef5b664d | Christos Stathis | public void onError(Throwable t) { |
272 | ef5b664d | Christos Stathis | GWT.log("", t);
|
273 | 3f8622d4 | Christos Stathis | app.setError(t); |
274 | ef5b664d | Christos Stathis | app.displayError("System error modifying file:" + t.getMessage());
|
275 | ef5b664d | Christos Stathis | } |
276 | 9539e23d | Christos Stathis | |
277 | 9539e23d | Christos Stathis | @Override
|
278 | ebead1b5 | Christos Stathis | protected void onUnauthorized(Response response) { |
279 | 9539e23d | Christos Stathis | app.sessionExpired(); |
280 | 9539e23d | Christos Stathis | } |
281 | ef5b664d | Christos Stathis | }; |
282 | cc0120ab | Christos KK Loverdos | updateFile.setHeader("X-Auth-Token", app.getUserToken());
|
283 | a2411896 | Christos Stathis | updateFile.setHeader("X-Move-From", URL.encodePathSegment(file.getUri())); |
284 | ef5b664d | Christos Stathis | updateFile.setHeader("Content-Type", file.getContentType());
|
285 | 3601b114 | Christos Stathis | for (String key : file.getMeta().keySet()) |
286 | 3601b114 | Christos Stathis | updateFile.setHeader("X-Object-Meta-" + URL.encodePathSegment(key.trim()), URL.encodePathSegment(newMeta.get(key))); |
287 | 3601b114 | Christos Stathis | if (file.isPublished())
|
288 | 3601b114 | Christos Stathis | updateFile.setHeader("X-Object-Public", "true"); |
289 | 3601b114 | Christos Stathis | String readPermHeader = "read="; |
290 | 3601b114 | Christos Stathis | String writePermHeader = "write="; |
291 | 3601b114 | Christos Stathis | for (String u : file.getPermissions().keySet()) { |
292 | 3601b114 | Christos Stathis | Boolean[] p = file.getPermissions().get(u); |
293 | 3601b114 | Christos Stathis | if (p[0] != null && p[0]) |
294 | 3601b114 | Christos Stathis | readPermHeader += u + ",";
|
295 | 3601b114 | Christos Stathis | if (p[1] != null && p[1]) |
296 | 3601b114 | Christos Stathis | writePermHeader += u + ",";
|
297 | 3601b114 | Christos Stathis | } |
298 | 3601b114 | Christos Stathis | if (readPermHeader.endsWith("=")) |
299 | 3601b114 | Christos Stathis | readPermHeader = "";
|
300 | 3601b114 | Christos Stathis | else if (readPermHeader.endsWith(",")) |
301 | 3601b114 | Christos Stathis | readPermHeader = readPermHeader.substring(0, readPermHeader.length() - 1); |
302 | 3601b114 | Christos Stathis | if (writePermHeader.endsWith("=")) |
303 | 3601b114 | Christos Stathis | writePermHeader = "";
|
304 | 3601b114 | Christos Stathis | else if (writePermHeader.endsWith(",")) |
305 | 3601b114 | Christos Stathis | writePermHeader = writePermHeader.substring(0, writePermHeader.length() - 1); |
306 | 3601b114 | Christos Stathis | String permHeader = readPermHeader + ((readPermHeader.length() > 0 && writePermHeader.length() > 0) ? ";" : "") + writePermHeader; |
307 | 3601b114 | Christos Stathis | if (permHeader.length() == 0) |
308 | 3601b114 | Christos Stathis | permHeader="~";
|
309 | 3601b114 | Christos Stathis | else
|
310 | 3601b114 | Christos Stathis | permHeader = URL.encodePathSegment(permHeader);
|
311 | 3601b114 | Christos Stathis | updateFile.setHeader("X-Object-Sharing", permHeader);
|
312 | 3601b114 | Christos Stathis | |
313 | ef5b664d | Christos Stathis | Scheduler.get().scheduleDeferred(updateFile); |
314 | ef5b664d | Christos Stathis | } |
315 | ecf95c9e | Christos Stathis | else
|
316 | cc0120ab | Christos KK Loverdos | updateMetaData(app.getApiPath(), app.getUserID(), file.getUri(), newMeta); |
317 | 0099339a | Christos Stathis | return true; |
318 | ef5b664d | Christos Stathis | } |
319 | a57faaf0 | Christos Stathis | |
320 | d26e2ef7 | Christos Stathis | protected void updateMetaData(final String api, final String owner, final String path, Map<String, String> newMeta) { |
321 | 9326b841 | Christos Stathis | if (newMeta != null) { |
322 | d26e2ef7 | Christos Stathis | PostRequest updateFile = new PostRequest(api, owner, path + "?update=") { |
323 | ecf95c9e | Christos Stathis | @Override
|
324 | ebead1b5 | Christos Stathis | public void onSuccess(Resource result) { |
325 | 5d18aa82 | Christos Stathis | if (!app.isMySharedSelected())
|
326 | 5d18aa82 | Christos Stathis | app.updateFolder(file.getParent(), true, new Command() { |
327 | 5d18aa82 | Christos Stathis | |
328 | 5d18aa82 | Christos Stathis | @Override
|
329 | 5d18aa82 | Christos Stathis | public void execute() { |
330 | d26e2ef7 | Christos Stathis | app.getFileList().selectByUrl(Arrays.asList(api + owner + path));
|
331 | 5d18aa82 | Christos Stathis | app.updateMySharedRoot(); |
332 | 5d18aa82 | Christos Stathis | } |
333 | 5d18aa82 | Christos Stathis | }, true);
|
334 | d26e2ef7 | Christos Stathis | else {
|
335 | d26e2ef7 | Christos Stathis | app.updateSharedFolder(file.getParent(), true, new Command() { |
336 | d26e2ef7 | Christos Stathis | |
337 | d26e2ef7 | Christos Stathis | @Override
|
338 | d26e2ef7 | Christos Stathis | public void execute() { |
339 | d26e2ef7 | Christos Stathis | app.getFileList().selectByUrl(Arrays.asList(api + owner + path));
|
340 | d26e2ef7 | Christos Stathis | } |
341 | d26e2ef7 | Christos Stathis | }); |
342 | d26e2ef7 | Christos Stathis | } |
343 | ecf95c9e | Christos Stathis | } |
344 | 31997f49 | Christos Stathis | |
345 | ecf95c9e | Christos Stathis | @Override
|
346 | ecf95c9e | Christos Stathis | public void onError(Throwable t) { |
347 | ecf95c9e | Christos Stathis | GWT.log("", t);
|
348 | 3f8622d4 | Christos Stathis | app.setError(t); |
349 | ecf95c9e | Christos Stathis | app.displayError("System error modifying file:" + t.getMessage());
|
350 | ecf95c9e | Christos Stathis | } |
351 | 9539e23d | Christos Stathis | |
352 | 9539e23d | Christos Stathis | @Override
|
353 | ebead1b5 | Christos Stathis | protected void onUnauthorized(Response response) { |
354 | 9539e23d | Christos Stathis | app.sessionExpired(); |
355 | 9539e23d | Christos Stathis | } |
356 | ecf95c9e | Christos Stathis | }; |
357 | cc0120ab | Christos KK Loverdos | updateFile.setHeader("X-Auth-Token", app.getUserToken());
|
358 | 904447e4 | Christos Stathis | |
359 | 9326b841 | Christos Stathis | for (String t : file.getMeta().keySet()) { |
360 | 9326b841 | Christos Stathis | updateFile.setHeader("X-Object-Meta-" + URL.encodePathSegment(t.trim()), "~"); |
361 | ea94470a | Christos Stathis | } |
362 | 947da718 | Christos Stathis | |
363 | 9326b841 | Christos Stathis | for (String key : newMeta.keySet()) |
364 | 9326b841 | Christos Stathis | updateFile.setHeader("X-Object-Meta-" + URL.encodePathSegment(key.trim()), URL.encodePathSegment(newMeta.get(key))); |
365 | 9326b841 | Christos Stathis | |
366 | ecf95c9e | Christos Stathis | Scheduler.get().scheduleDeferred(updateFile); |
367 | ecf95c9e | Christos Stathis | } |
368 | 5d18aa82 | Christos Stathis | else if (!app.isMySharedSelected()) |
369 | 3601b114 | Christos Stathis | app.updateFolder(file.getParent(), true, new Command() { |
370 | 3601b114 | Christos Stathis | |
371 | 3601b114 | Christos Stathis | @Override
|
372 | 3601b114 | Christos Stathis | public void execute() { |
373 | d26e2ef7 | Christos Stathis | app.getFileList().selectByUrl(Arrays.asList(api + owner + path));
|
374 | 71875b42 | Christos Stathis | if (file.isSharedOrPublished())
|
375 | 3601b114 | Christos Stathis | app.updateMySharedRoot(); |
376 | 3601b114 | Christos Stathis | } |
377 | 6acd4df3 | Christos Stathis | }, true);
|
378 | d26e2ef7 | Christos Stathis | else {
|
379 | d26e2ef7 | Christos Stathis | app.getFileList().selectByUrl(Arrays.asList(api + owner + path));
|
380 | 5d18aa82 | Christos Stathis | app.updateSharedFolder(file.getParent(), true);
|
381 | d26e2ef7 | Christos Stathis | } |
382 | ef5b664d | Christos Stathis | } |
383 | a57faaf0 | Christos Stathis | } |