Revision 28e270f9

b/src/gr/grnet/pithos/web/client/AddUserDialog.java
173 173
        final String userID = app.getIDForUserDisplayName(userDisplayName);
174 174
        group.addMemberID(userID);
175 175
        String path = "?update=";
176
        PostRequest updateGroup = new PostRequest(app.getApiPath(), app.getUserID(), path) {
176
        PostRequest updateGroup = new PostRequest(Pithos.getStorageAPIURL(), app.getUserID(), path) {
177 177

  
178 178
            @Override
179 179
            public void onSuccess(Resource result) {
b/src/gr/grnet/pithos/web/client/DeleteFileDialog.java
135 135
        if (iter.hasNext()) {
136 136
            File f = iter.next();
137 137
            String path = f.getUri();
138
            DeleteRequest deleteFile = new DeleteRequest(app.getApiPath(), f.getOwnerID(), URL.encode(path)) {
138
            DeleteRequest deleteFile = new DeleteRequest(Pithos.getStorageAPIURL(), f.getOwnerID(), URL.encode(path)) {
139 139
                @Override
140 140
                public void onSuccess(Resource result) {
141 141
                    deleteFile(iter);
b/src/gr/grnet/pithos/web/client/FileContextMenu.java
41 41
import gr.grnet.pithos.web.client.commands.PropertiesCommand;
42 42
import gr.grnet.pithos.web.client.commands.RestoreTrashCommand;
43 43
import gr.grnet.pithos.web.client.commands.ToTrashCommand;
44
import gr.grnet.pithos.web.client.commands.UploadFileCommand;
45 44
import gr.grnet.pithos.web.client.foldertree.File;
46 45
import gr.grnet.pithos.web.client.foldertree.Folder;
47 46

  
......
250 249
			@Override
251 250
			public void execute() {
252 251
				for (File f : selectedFiles)
253
					Window.open(app.getApiPath() + f.getOwnerID() + f.getUri(), "_blank", "");
252
					Window.open(Pithos.getStorageAPIURL() + f.getOwnerID() + f.getUri(), "_blank", "");
254 253
			}
255 254
		}));
256 255

  
b/src/gr/grnet/pithos/web/client/FileList.java
288 288
				sb.append(Templates.INSTANCE.filenameSpan(object.getName()));
289 289
				if (object.getContentType() != null && (object.getContentType().endsWith("png") || object.getContentType().endsWith("gif") || object.getContentType().endsWith("jpeg"))) {
290 290
        			sb.appendHtmlConstant(" ")
291
                      .append(Templates.INSTANCE.viewLink(app.getApiPath() + object.getOwnerID() + object.getUri(), object.getName()));
291
                      .append(Templates.INSTANCE.viewLink(Pithos.getStorageAPIURL() + object.getOwnerID() + object.getUri(), object.getName()));
292 292
				}
293 293
				
294 294
				return sb.toSafeHtml();
......
415 415
		if (DOM.eventGetType(event) == Event.ONDBLCLICK)
416 416
			if (getSelectedFiles().size() == 1) {
417 417
				File file = getSelectedFiles().get(0);
418
				Window.open(app.getApiPath() + file.getOwnerID() + file.getUri(), "_blank", "");
418
				Window.open(Pithos.getStorageAPIURL() + file.getOwnerID() + file.getUri(), "_blank", "");
419 419
				event.preventDefault();
420 420
				return;
421 421
			}
......
647 647
		int i = 0;
648 648
		boolean scrolled = false;
649 649
		for (File f : files) {
650
			if (selectedUrls.contains(app.getApiPath() + f.getOwnerID() + f.getUri())) {
650
			if (selectedUrls.contains(Pithos.getStorageAPIURL() + f.getOwnerID() + f.getUri())) {
651 651
				selectionModel.setSelected(f, true);
652 652
				if (!scrolled) {
653 653
					celltable.getRowElement(i).getCells().getItem(0).scrollIntoView();
b/src/gr/grnet/pithos/web/client/FilePermissionsDialog.java
240 240
    void showLinkIfShared() {
241 241
		if (file.isShared()) {
242 242
			UrlBuilder b = Window.Location.createUrlBuilder();
243
			b.setPath(app.getApiPath() + file.getOwnerID() + file.getUri());
243
			b.setPath(Pithos.getStorageAPIURL() + file.getOwnerID() + file.getUri());
244 244
			String href = Window.Location.getHref();
245 245
			boolean hasParameters = href.contains(Const.QUESTION_MARK);
246 246
			path.setText(href + (hasParameters ? Const.AMPERSAND : Const.QUESTION_MARK) + Const.GOTO_EQ + b.buildString());
......
257 257
	@Override
258 258
	protected boolean accept() {
259 259
        updateMetaData(
260
            app.getApiPath(),
260
            Pithos.getStorageAPIURL(),
261 261
            app.getUserID(),
262 262
            file.getUri() + Const.QUESTION_MARK_UPDATE_EQ,
263 263
            permList.getPermissions()
......
270 270
            PostRequest updateFile = new PostRequest(api, owner, path) {
271 271
                @Override
272 272
                public void onSuccess(Resource result) {
273
                	HeadRequest<File> headFile = new HeadRequest<File>(File.class, app.getApiPath(), file.getOwnerID(), path, file) {
273
                	HeadRequest<File> headFile = new HeadRequest<File>(File.class, Pithos.getStorageAPIURL(), file.getOwnerID(), path, file) {
274 274

  
275 275
						@Override
276 276
						public void onSuccess(File _result) {
b/src/gr/grnet/pithos/web/client/FilePropertiesDialog.java
261 261

  
262 262
        if (newFilename != null) {
263 263
            final String path = file.getParent().getUri() + "/" + newFilename;
264
            PutRequest updateFile = new PutRequest(app.getApiPath(), app.getUserID(), path) {
264
            PutRequest updateFile = new PutRequest(Pithos.getStorageAPIURL(), app.getUserID(), path) {
265 265
                @Override
266 266
                public void onSuccess(Resource result) {
267
                    updateMetaData(app.getApiPath(), file.getOwnerID(), path, newMeta);
267
                    updateMetaData(Pithos.getStorageAPIURL(), file.getOwnerID(), path, newMeta);
268 268
                }
269 269

  
270 270
                @Override
......
313 313
            Scheduler.get().scheduleDeferred(updateFile);
314 314
        }
315 315
        else
316
            updateMetaData(app.getApiPath(), app.getUserID(), file.getUri(), newMeta);
316
            updateMetaData(Pithos.getStorageAPIURL(), app.getUserID(), file.getUri(), newMeta);
317 317
        return true;
318 318
	}
319 319

  
b/src/gr/grnet/pithos/web/client/FileShareDialog.java
436 436
    private void showLinkForPrivateSharing() {
437 437
        if (isFilePrivatelyShared()) {
438 438
            UrlBuilder b = Window.Location.createUrlBuilder();
439
            b.setPath(app.getApiPath() + file.getOwnerID() + file.getUri());
439
            b.setPath(Pithos.getStorageAPIURL() + file.getOwnerID() + file.getUri());
440 440
            String href = Window.Location.getHref();
441 441
            boolean hasParameters = href.contains(Const.QUESTION_MARK);
442 442
            privatePathText.setText(href + (hasParameters ? Const.AMPERSAND : Const.QUESTION_MARK) + Const.GOTO_EQ + b.buildString());
......
452 452
            PostRequest updateFile = new PostRequest(api, owner, path) {
453 453
                @Override
454 454
                public void onSuccess(Resource result) {
455
                	HeadRequest<File> headFile = new HeadRequest<File>(File.class, app.getApiPath(), file.getOwnerID(), path, file) {
455
                	HeadRequest<File> headFile = new HeadRequest<File>(File.class, Pithos.getStorageAPIURL(), file.getOwnerID(), path, file) {
456 456

  
457 457
						@Override
458 458
						public void onSuccess(File _result) {
......
515 515
    }
516 516
    protected void updateMetaDataForPublicSharing(Boolean published) {
517 517
        updateMetaDataForPublicSharing(
518
            app.getApiPath(),
518
            Pithos.getStorageAPIURL(),
519 519
            app.getUserID(),
520 520
            file.getUri() + Const.QUESTION_MARK_UPDATE_EQ,
521 521
            published
......
527 527
            PostRequest updateFile = new PostRequest(api, owner, path) {
528 528
                @Override
529 529
                public void onSuccess(Resource result) {
530
                    HeadRequest<File> headFile = new HeadRequest<File>(File.class, app.getApiPath(), file.getOwnerID(), path, file) {
530
                    HeadRequest<File> headFile = new HeadRequest<File>(File.class, Pithos.getStorageAPIURL(), file.getOwnerID(), path, file) {
531 531

  
532 532
                        @Override
533 533
                        public void onSuccess(File _result) {
......
621 621
    }
622 622
    protected void updateMetaDataForPrivateSharing() {
623 623
        updateMetaDataForPrivateSharing(
624
            app.getApiPath(),
624
            Pithos.getStorageAPIURL(),
625 625
            app.getUserID(),
626 626
            file.getUri() + Const.QUESTION_MARK_UPDATE_EQ,
627 627
            permList.getPermissions()
b/src/gr/grnet/pithos/web/client/FileUploadDialog.java
198 198
				
199 199
				init: {
200 200
					FilesAdded: function(up, files) {
201
						var api = app.@gr.grnet.pithos.web.client.Pithos::getApiPath()();
201
						var api = @gr.grnet.pithos.web.client.Pithos::getStorageAPIURL()();
202 202
						var folder = app.@gr.grnet.pithos.web.client.Pithos::getUploadFolder()();
203 203
						var owner = folder.@gr.grnet.pithos.web.client.foldertree.Folder::getOwnerID()();
204 204
						var uri = folder.@gr.grnet.pithos.web.client.foldertree.Folder::getUri()();
b/src/gr/grnet/pithos/web/client/FileVersionsDialog.java
146 146

  
147 147
    protected void fetchVersions() {
148 148
    	String path = file.getUri() + "?format=json&version=list";
149
    	GetRequest<FileVersions> getVersions = new GetRequest<FileVersions>(FileVersions.class, app.getApiPath(), file.getOwnerID(), path) {
149
    	GetRequest<FileVersions> getVersions = new GetRequest<FileVersions>(FileVersions.class, Pithos.getStorageAPIURL(), file.getOwnerID(), path) {
150 150

  
151 151
			@Override
152 152
			public void onSuccess(FileVersions _result) {
b/src/gr/grnet/pithos/web/client/FolderPermissionsDialog.java
214 214

  
215 215
    private void updateMetadataForPrivateSharing(final String path, final Map<String, Boolean[]> newPermissions) {
216 216
        if(newPermissions != null) {
217
            PostRequest updateFolder = new PostRequest(app.getApiPath(), folder.getOwnerID(), path) {
217
            PostRequest updateFolder = new PostRequest(Pithos.getStorageAPIURL(), folder.getOwnerID(), path) {
218 218
                @Override
219 219
                public void onSuccess(Resource result) {
220 220
                    app.updateFolder(folder.getParent(), false, new Command() {
......
231 231
                    if(t instanceof RestException) {
232 232
                        if(((RestException) t).getHttpStatusCode() == Response.SC_NOT_FOUND) { //Probably a virtual folder
233 233
                            final String path1 = folder.getUri();
234
                            PutRequest newFolder = new PutRequest(app.getApiPath(), folder.getOwnerID(), path1) {
234
                            PutRequest newFolder = new PutRequest(Pithos.getStorageAPIURL(), folder.getOwnerID(), path1) {
235 235
                                @Override
236 236
                                public void onSuccess(Resource result) {
237 237
                                    updateMetadataForPrivateSharing(path, newPermissions);
b/src/gr/grnet/pithos/web/client/FolderPropertiesDialog.java
249 249
            return;
250 250
        }
251 251
        String path = folder.getUri() + "/" + name;
252
        PutRequest createFolder = new PutRequest(app.getApiPath(), folder.getOwnerID(), path) {
252
        PutRequest createFolder = new PutRequest(Pithos.getStorageAPIURL(), folder.getOwnerID(), path) {
253 253
            @Override
254 254
            public void onSuccess(Resource result) {
255 255
                app.updateFolder(folder, true, new Command() {
b/src/gr/grnet/pithos/web/client/Pithos.java
78 78
 * Entry point classes define <code>onModuleLoad()</code>.
79 79
 */
80 80
public class Pithos implements EntryPoint, ResizeHandler {
81
    private static final boolean IsLOGEnabled = false;
81
    private static final boolean IsLOGEnabled = true;
82 82
    public static final boolean IsDetailedHTTPLOGEnabled = true;
83 83
    public static final boolean IsFullResponseBodyLOGEnabled = true;
84 84

  
......
93 93
    }
94 94

  
95 95
    public static final Configuration config = GWT.create(Configuration.class);
96
    public static final String CONFIG_API_PATH = config.apiPath();
97
    static {
98
        LOG("CONFIG_API_PATH = ", CONFIG_API_PATH);
99
    }
100

  
101
    public static final Dictionary otherProperties = Dictionary.getDictionary(Const.OTHER_PROPERTIES);
102
    public static String getFromOtherPropertiesOrNull(String key) {
103
        try {
104
            return otherProperties.get(key);
105
        }
106
        catch(Exception e) {
107
            LOGError(e);
108
            return null;
109
        }
110
    }
111
    public static final String OTHERPROPS_STORAGE_API_URL = getFromOtherPropertiesOrNull("STORAGE_API_URL");
112
    public static final String OTHERPROPS_USER_CATALOGS_API_URL = getFromOtherPropertiesOrNull("USER_CATALOGS_API_URL");
113
    static {
114
        LOG("STORAGE_API_URL = ", OTHERPROPS_STORAGE_API_URL);
115
        LOG("USER_CATALOGS_API_URL = ", OTHERPROPS_USER_CATALOGS_API_URL);
116
    }
117

  
118
    public static final String STORAGE_API_URL;
119
    static {
120
        if(OTHERPROPS_STORAGE_API_URL != null) {
121
            STORAGE_API_URL = OTHERPROPS_STORAGE_API_URL;
122
        }
123
        else if(CONFIG_API_PATH != null) {
124
            STORAGE_API_URL = CONFIG_API_PATH;
125
        }
126
        else {
127
            throw new RuntimeException("Unknown STORAGE_API_URL");
128
        }
129
    }
130
    public static final String USER_CATALOGS_API_URL;
131
    static {
132
        if(OTHERPROPS_USER_CATALOGS_API_URL != null) {
133
            USER_CATALOGS_API_URL = OTHERPROPS_USER_CATALOGS_API_URL;
134
        }
135
        else if(OTHERPROPS_STORAGE_API_URL != null) {
136
            throw new RuntimeException("STORAGE_API_URL is defined but USER_CATALOGS_API_URL is not");
137
        }
138
        else {
139
            // https://server.com/v1/ --> https://server.com
140
            String url = CONFIG_API_PATH;
141
            url = Helpers.stripTrailing(url, "/");
142
            url = Helpers.upToIncludingLastPart(url, "/");
143
            url = Helpers.stripTrailing(url, "/");
144
            url = url + "/user_catalogs";
145

  
146
            USER_CATALOGS_API_URL = url;
147

  
148
            LOG("USER_CATALOGS_API_URL = ", USER_CATALOGS_API_URL);
149
        }
150
    }
96 151

  
97 152
    public interface Style extends CssResource {
98 153
        String commandAnchor();
......
616 671
                    return true;
617 672
                }
618 673

  
619
                HeadRequest<Folder> head = new HeadRequest<Folder>(Folder.class, getApiPath(), f.getOwnerID(), "/" + f.getContainer()) {
674
                HeadRequest<Folder> head = new HeadRequest<Folder>(Folder.class, getStorageAPIURL(), f.getOwnerID(), "/" + f.getContainer()) {
620 675

  
621 676
                    @Override
622 677
                    public void onSuccess(Folder _result) {
......
734 789
     * Parse and store the user credentials to the appropriate fields.
735 790
     */
736 791
    private boolean parseUserCredentials() {
737
        Configuration conf = (Configuration) GWT.create(Configuration.class);
738
        Dictionary otherProperties = Dictionary.getDictionary(Const.OTHER_PROPERTIES);
739
        String cookie = otherProperties.get(Const.AUTH_COOKIE);
792
        final String cookie = otherProperties.get(Const.AUTH_COOKIE);
740 793
        String auth = Cookies.getCookie(cookie);
741 794
        if(auth == null) {
742 795
            authenticateUser();
......
748 801
        if(auth.endsWith("\"")) {
749 802
            auth = auth.substring(0, auth.length() - 1);
750 803
        }
751
        String[] authSplit = auth.split("\\" + conf.cookieSeparator(), 2);
804
        String[] authSplit = auth.split("\\" + config.cookieSeparator(), 2);
752 805
        if(authSplit.length != 2) {
753 806
            authenticateUser();
754 807
            return false;
755 808
        }
756
        userID = authSplit[0];
757
        userToken = authSplit[1];
809
        this.userID = authSplit[0];
810
        this.userToken = authSplit[1];
758 811

  
759 812
        String gotoUrl = Window.Location.getParameter("goto");
760 813
        if(gotoUrl != null && gotoUrl.length() > 0) {
......
775 828
    public void fetchAccount(final Command callback) {
776 829
        String path = "?format=json";
777 830

  
778
        GetRequest<AccountResource> getAccount = new GetRequest<AccountResource>(AccountResource.class, getApiPath(), userID, path) {
831
        GetRequest<AccountResource> getAccount = new GetRequest<AccountResource>(AccountResource.class, getStorageAPIURL(), userID, path) {
779 832
            @Override
780 833
            public void onSuccess(AccountResource accountResource) {
781 834
                account = accountResource;
......
818 871
    }
819 872

  
820 873
    public void updateStatistics() {
821
        HeadRequest<AccountResource> headAccount = new HeadRequest<AccountResource>(AccountResource.class, getApiPath(), userID, "", account) {
874
        HeadRequest<AccountResource> headAccount = new HeadRequest<AccountResource>(AccountResource.class, getStorageAPIURL(), userID, "", account) {
822 875

  
823 876
            @Override
824 877
            public void onSuccess(AccountResource _result) {
......
848 901

  
849 902
    protected void createHomeContainer(final AccountResource _account, final Command callback) {
850 903
        String path = "/" + Const.HOME_CONTAINER;
851
        PutRequest createPithos = new PutRequest(getApiPath(), getUserID(), path) {
904
        PutRequest createPithos = new PutRequest(getStorageAPIURL(), getUserID(), path) {
852 905
            @Override
853 906
            public void onSuccess(Resource result) {
854 907
                if(!_account.hasTrashContainer()) {
......
882 935

  
883 936
    protected void createTrashContainer(final Command callback) {
884 937
        String path = "/" + Const.TRASH_CONTAINER;
885
        PutRequest createPithos = new PutRequest(getApiPath(), getUserID(), path) {
938
        PutRequest createPithos = new PutRequest(getStorageAPIURL(), getUserID(), path) {
886 939
            @Override
887 940
            public void onSuccess(Resource result) {
888 941
                fetchAccount(callback);
......
1023 1076
        $doc.body.onselectstart = null;
1024 1077
    }-*/;
1025 1078

  
1026
    /**
1027
     * @return the absolute path of the API root URL
1028
     */
1029
    public String getApiPath() {
1030
        Configuration conf = (Configuration) GWT.create(Configuration.class);
1031
        return conf.apiPath();
1079
    public static String getStorageAPIURL() {
1080
        return STORAGE_API_URL;
1081
    }
1082

  
1083
    public static String getUserCatalogsURL() {
1084
        return USER_CATALOGS_API_URL;
1032 1085
    }
1033 1086

  
1034 1087
    /**
......
1049 1102
        final PleaseWaitPopup pwp = new PleaseWaitPopup();
1050 1103
        pwp.center();
1051 1104
        String path = "/" + folder.getContainer() + "/" + folder.getPrefix() + "?delimiter=/" + "&t=" + System.currentTimeMillis();
1052
        DeleteRequest deleteFolder = new DeleteRequest(getApiPath(), folder.getOwnerID(), path) {
1105
        DeleteRequest deleteFolder = new DeleteRequest(getStorageAPIURL(), folder.getOwnerID(), path) {
1053 1106

  
1054 1107
            @Override
1055 1108
            protected void onUnauthorized(Response response) {
......
1103 1156
        if(iter.hasNext()) {
1104 1157
            File file = iter.next();
1105 1158
            String path = targetUri + "/" + file.getName();
1106
            PutRequest copyFile = new PutRequest(getApiPath(), targetUsername, path) {
1159
            PutRequest copyFile = new PutRequest(getStorageAPIURL(), targetUsername, path) {
1107 1160
                @Override
1108 1161
                public void onSuccess(Resource result) {
1109 1162
                    copyFiles(iter, targetUsername, targetUri, callback);
......
1141 1194

  
1142 1195
    public void copyFolder(final Folder f, final String targetUsername, final String targetUri, boolean move, final Command callback) {
1143 1196
        String path = targetUri + "?delimiter=/";
1144
        PutRequest copyFolder = new PutRequest(getApiPath(), targetUsername, path) {
1197
        PutRequest copyFolder = new PutRequest(getStorageAPIURL(), targetUsername, path) {
1145 1198
            @Override
1146 1199
            public void onSuccess(Resource result) {
1147 1200
                if(callback != null) {
......
1380 1433
            }
1381 1434
        }
1382 1435
        else {
1383
            HeadRequest<Folder> headFolder = new HeadRequest<Folder>(Folder.class, getApiPath(), folder.getOwnerID(), folder.getUri(), folder) {
1436
            HeadRequest<Folder> headFolder = new HeadRequest<Folder>(Folder.class, getStorageAPIURL(), folder.getOwnerID(), folder.getUri(), folder) {
1384 1437

  
1385 1438
                @Override
1386 1439
                public void onSuccess(Folder _result) {
......
1394 1447
                    if(t instanceof RestException) {
1395 1448
                        if(((RestException) t).getHttpStatusCode() == Response.SC_NOT_FOUND) {
1396 1449
                            final String path = folder.getUri();
1397
                            PutRequest newFolder = new PutRequest(getApiPath(), folder.getOwnerID(), path) {
1450
                            PutRequest newFolder = new PutRequest(getStorageAPIURL(), folder.getOwnerID(), path) {
1398 1451
                                @Override
1399 1452
                                public void onSuccess(Resource _result) {
1400 1453
                                    scheduleFolderHeadCommand(folder, callback);
......
1448 1501
    }
1449 1502

  
1450 1503
    public void scheduleFileHeadCommand(File f, final Command callback) {
1451
        HeadRequest<File> headFile = new HeadRequest<File>(File.class, getApiPath(), f.getOwnerID(), f.getUri(), f) {
1504
        HeadRequest<File> headFile = new HeadRequest<File>(File.class, getStorageAPIURL(), f.getOwnerID(), f.getUri(), f) {
1452 1505

  
1453 1506
            @Override
1454 1507
            public void onSuccess(File _result) {
......
1562 1615

  
1563 1616
    public void purgeContainer(final Folder container) {
1564 1617
        String path = "/" + container.getName() + "?delimiter=/";
1565
        DeleteRequest delete = new DeleteRequest(getApiPath(), getUserID(), path) {
1618
        DeleteRequest delete = new DeleteRequest(getStorageAPIURL(), getUserID(), path) {
1566 1619

  
1567 1620
            @Override
1568 1621
            protected void onUnauthorized(Response response) {
b/src/gr/grnet/pithos/web/client/ToolsMenu.java
172 172
							@Override
173 173
							public void execute() {
174 174
					        	for (File f: files)
175
					        		Window.open(app.getApiPath() + f.getOwnerID() + f.getUri(), "_blank", "");
175
					        		Window.open(Pithos.getStorageAPIURL() + f.getOwnerID() + f.getUri(), "_blank", "");
176 176
							}
177 177
						}));
178 178
			        	empty = false;
b/src/gr/grnet/pithos/web/client/VersionsList.java
116 116
			downloadHtml.addClickHandler(new ClickHandler() {
117 117
				@Override
118 118
				public void onClick(ClickEvent event) {
119
					String fileUrl = app.getApiPath() + file.getOwnerID() + file.getUri() + "?version=" + v.getVersion();
119
					String fileUrl = Pithos.getStorageAPIURL() + file.getOwnerID() + file.getUri() + "?version=" + v.getVersion();
120 120
					Window.open(fileUrl, "_BLANK", "");
121 121
				}
122 122
			});
......
132 132

  
133 133
	void restoreVersion(int version) {
134 134
		String path = file.getUri() + "?update=";
135
		PostRequest restoreVersion = new PostRequest(app.getApiPath(), file.getOwnerID(), path) {
135
		PostRequest restoreVersion = new PostRequest(Pithos.getStorageAPIURL(), file.getOwnerID(), path) {
136 136
			
137 137
			@Override
138 138
			public void onSuccess(Resource result) {
b/src/gr/grnet/pithos/web/client/catalog/GetUserCatalogs.java
35 35

  
36 36
package gr.grnet.pithos.web.client.catalog;
37 37

  
38
import com.google.gwt.core.client.GWT;
39 38
import com.google.gwt.core.client.Scheduler;
40 39
import com.google.gwt.http.client.*;
41 40
import com.google.gwt.json.client.JSONArray;
......
52 51
 * The request via which we obtain user catalog info.
53 52
 */
54 53
public class GetUserCatalogs implements Scheduler.ScheduledCommand {
55
    private final Pithos app;
56 54
    private final String url;
57 55
    private final String userToken;
58 56
    private final List<String> ids;
59 57
    private final List<String> names;
60 58

  
61 59
    public static final int SuccessCode = 200;
62
    public static final String CallEndPoint = "/user_catalogs";
63 60
    public static final String RequestField_uuids = "uuids";
64 61
    public static final String RequestField_displaynames = "displaynames";
65 62
    public static final String ResponseField_displayname_catalog = "displayname_catalog";
66 63
    public static final String ResponseField_uuid_catalog = "uuid_catalog";
67 64

  
68
    public GetUserCatalogs(Pithos app) {
69
        this(app, null, null);
70
    }
71

  
72
    public GetUserCatalogs(Pithos app, String userID) {
73
        this(app, Helpers.toList(userID), null);
74
    }
75

  
76
    public GetUserCatalogs(Pithos app, List<String> ids) {
77
        this(app, ids, null);
78
    }
79

  
80
    public GetUserCatalogs(Pithos app, List<String> ids, List<String> names) {
81
        assert app != null;
82

  
83
        this.app = app;
84

  
85
        // FIXME: Probably use Window.Location.getHost()
86
        // https://server.com/v1/ --> https://server.com
87
        String path = app.getApiPath();
88
        path = Helpers.stripTrailing(path, "/");
89
        path = Helpers.upToIncludingLastPart(path, "/");
90
        path = Helpers.stripTrailing(path, "/");
91

  
92
        // https://server.com/user_catalogs
93
        this.url = path + CallEndPoint;
94

  
65
    public GetUserCatalogs(String userToken, List<String> ids, List<String> names) {
66
        this.url = Pithos.getUserCatalogsURL();
67
        this.userToken = userToken;
95 68
        this.ids = Helpers.safeList(ids);
96 69
        this.names = Helpers.safeList(names);
97
        this.userToken = app.getUserToken();
98 70
    }
99 71

  
100 72
    public String getURL() {
......
137 109
    }
138 110

  
139 111
    public void onError(Request request, Throwable t) {
140
        app.LOG("GetUserCatalogs", t);
112
        Pithos.LOG("GetUserCatalogs", t);
141 113
    }
142 114

  
143 115
    @Override
......
145 117
        final RequestBuilder rb = new RequestBuilder(RequestBuilder.POST, getURL());
146 118
        rb.setHeader(Const.X_AUTH_TOKEN, userToken);
147 119
        final String requestData = makeRequestData().toString();
148
        app.LOG("GetUserCatalogs => ", requestData);
120
        Pithos.LOG("GetUserCatalogs => ", requestData);
149 121
        Pithos.LOG("POST ", getURL());
150 122

  
151 123
        try {
......
155 127
                    final int statusCode = response.getStatusCode();
156 128

  
157 129
                    if(statusCode != SuccessCode) {
158
                        app.LOG("GetUserCatalogs <= [", statusCode, " ", response.getStatusText(), "]");
130
                        Pithos.LOG("GetUserCatalogs <= [", statusCode, " ", response.getStatusText(), "]");
159 131
                        GetUserCatalogs.this.onBadStatusCode(request, response);
160 132
                        return;
161 133
                    }
162 134

  
163 135
                    final String responseText = response.getText();
164 136
                    final JSONValue jsonValue = JSONParser.parseStrict(responseText);
165
                    app.LOG("GetUserCatalogs <= ", jsonValue.toString());
137
                    Pithos.LOG("GetUserCatalogs <= ", jsonValue.toString());
166 138
                    final JSONObject result = jsonValue.isObject();
167 139

  
168 140
                    if(result == null) {
......
182 154
            });
183 155
        }
184 156
        catch(Exception e) {
185
            app.LOG("GetUserCatalogs", e);
157
            Pithos.LOG("GetUserCatalogs", e);
186 158
        }
187 159
    }
188 160

  
b/src/gr/grnet/pithos/web/client/catalog/UpdateUserCatalogs.java
42 42
import gr.grnet.pithos.web.client.Helpers;
43 43
import gr.grnet.pithos.web.client.Pithos;
44 44

  
45
import java.util.Iterator;
46 45
import java.util.List;
47 46
import java.util.Map;
48 47

  
......
78 77

  
79 78
    public UpdateUserCatalogs(Pithos app, List<String> ids, List<String> names) {
80 79
        this.app = app;
81
        this.getUserCatalogs = new GetUserCatalogs(app, ids, names) {
80
        this.getUserCatalogs = new GetUserCatalogs(app.getUserToken(), ids, names) {
82 81
            @Override
83 82
            public void onSuccess(Request request, Response response, JSONObject result, UserCatalogs userCatalogs) {
84 83
                UpdateUserCatalogs.this.app.getUserCatalogs().updateFrom(userCatalogs);
b/src/gr/grnet/pithos/web/client/commands/DeleteGroupCommand.java
75 75
    		containerPanel.hide();
76 76
        if (Window.confirm("Are you sure you want to delete group " + group.getName())) {
77 77
        	String path = "?update=";
78
        	PostRequest updateGroup = new PostRequest(app.getApiPath(), app.getUserID(), path) {
78
        	PostRequest updateGroup = new PostRequest(Pithos.getStorageAPIURL(), app.getUserID(), path) {
79 79
				
80 80
				@Override
81 81
				public void onSuccess(Resource result) {
b/src/gr/grnet/pithos/web/client/commands/PasteCommand.java
137 137
        if (iter.hasNext()) {
138 138
            File file = iter.next();
139 139
            String path = folder.getUri() + "/" + file.getName();
140
            PutRequest copyFile = new PutRequest(app.getApiPath(), folder.getOwnerID(), path) {
140
            PutRequest copyFile = new PutRequest(Pithos.getStorageAPIURL(), folder.getOwnerID(), path) {
141 141
                @Override
142 142
                public void onSuccess(Resource result) {
143 143
                    moveFiles(iter, callback);
b/src/gr/grnet/pithos/web/client/commands/RemoveUserCommand.java
78 78
    		return;
79 79
    	group.removeMemberID(user.getUserID());
80 80
    	String path = "?update=";
81
    	PostRequest updateGroup = new PostRequest(app.getApiPath(), app.getUserID(), path) {
81
    	PostRequest updateGroup = new PostRequest(Pithos.getStorageAPIURL(), app.getUserID(), path) {
82 82
			
83 83
			@Override
84 84
			public void onSuccess(Resource result) {
b/src/gr/grnet/pithos/web/client/commands/RestoreTrashCommand.java
117 117
        if (iter.hasNext()) {
118 118
            File file = iter.next();
119 119
            String path = "/" + Const.HOME_CONTAINER + "/" + file.getPath();
120
            PutRequest untrashFile = new PutRequest(app.getApiPath(), app.getUserID(), path) {
120
            PutRequest untrashFile = new PutRequest(Pithos.getStorageAPIURL(), app.getUserID(), path) {
121 121
                @Override
122 122
                public void onSuccess(Resource result) {
123 123
                    untrashFiles(iter, callback);
b/src/gr/grnet/pithos/web/client/commands/ToTrashCommand.java
127 127
        if (iter.hasNext()) {
128 128
            File file = iter.next();
129 129
            String path = "/" + Const.TRASH_CONTAINER + "/" + file.getPath();
130
            PutRequest trashFile = new PutRequest(app.getApiPath(), app.getUserID(), path) {
130
            PutRequest trashFile = new PutRequest(Pithos.getStorageAPIURL(), app.getUserID(), path) {
131 131
                @Override
132 132
                public void onSuccess(Resource result) {
133 133
                    trashFiles(iter, callback);
b/src/gr/grnet/pithos/web/client/foldertree/FolderTreeViewModel.java
152 152
            final Folder f = iter.next();
153 153

  
154 154
            String path = "/" + f.getContainer() + "?format=json&delimiter=/&prefix=" + URL.encodeQueryString(f.getPrefix());
155
            GetRequest<Folder> getFolder = new GetRequest<Folder>(Folder.class, app.getApiPath(), f.getOwnerID(), path, f) {
155
            GetRequest<Folder> getFolder = new GetRequest<Folder>(Folder.class, Pithos.getStorageAPIURL(), f.getOwnerID(), path, f) {
156 156
                @Override
157 157
                public void onSuccess(Folder _result) {
158 158
                    fetchFolder(iter, callback);
......
236 236

  
237 237
    public void fetchFolder(final Folder f, final ListDataProvider<Folder> dataProvider, final boolean showfiles, final Command callback) {
238 238
        String path = "/" + f.getContainer() + "?format=json&delimiter=/&prefix=" + URL.encodeQueryString(f.getPrefix());
239
        GetRequest<Folder> getFolder = new GetRequest<Folder>(Folder.class, app.getApiPath(), f.getOwnerID(), path, f) {
239
        GetRequest<Folder> getFolder = new GetRequest<Folder>(Folder.class, Pithos.getStorageAPIURL(), f.getOwnerID(), path, f) {
240 240
            @Override
241 241
            public void onSuccess(final Folder _result) {
242 242
                if (showfiles)
b/src/gr/grnet/pithos/web/client/mysharedtree/MysharedTreeViewModel.java
121 121
	private void fetchSharedContainers(final Command callback) {
122 122
        app.LOG("MysharedTreeViewModel::fetchSharedContainers(), callback=", callback);
123 123
        String path = "?format=json&shared=&public=";
124
        GetRequest<AccountResource> getAccount = new GetRequest<AccountResource>(AccountResource.class, app.getApiPath(), app.getUserID(), path) {
124
        GetRequest<AccountResource> getAccount = new GetRequest<AccountResource>(AccountResource.class, Pithos.getStorageAPIURL(), app.getUserID(), path) {
125 125
            @Override
126 126
            public void onSuccess(final AccountResource _result) {
127 127
				firstLevelDataProvider.getList().clear();
......
171 171
            final Folder f = iter.next();
172 172

  
173 173
            String path = "/" + f.getContainer() + "?format=json&shared=&public=&delimiter=/&prefix=" + URL.encodeQueryString(f.getPrefix());
174
            GetRequest<Folder> getFolder = new GetRequest<Folder>(Folder.class, app.getApiPath(), f.getOwnerID(), path, f) {
174
            GetRequest<Folder> getFolder = new GetRequest<Folder>(Folder.class, Pithos.getStorageAPIURL(), f.getOwnerID(), path, f) {
175 175
                @Override
176 176
                public void onSuccess(Folder _result) {
177 177
                    fetchFolder(iter, callback);
......
211 211
    public void fetchFolder(final Folder f, final boolean showfiles, final Command callback) {
212 212
        app.LOG("MysharedTreeViewModel::fetchFolder(), folder=", f, ", showfiles=", showfiles, ", callback=", callback);
213 213
        String path = "/" + f.getContainer() + "?format=json&shared=&public=" + URL.encodeQueryString(f.getPrefix());
214
        GetRequest<Folder> getFolder = new GetRequest<Folder>(Folder.class, app.getApiPath(), f.getOwnerID(), path, f) {
214
        GetRequest<Folder> getFolder = new GetRequest<Folder>(Folder.class, Pithos.getStorageAPIURL(), f.getOwnerID(), path, f) {
215 215
            @Override
216 216
            public void onSuccess(final Folder _result) {
217 217
            	for (File file : _result.getFiles()) {
b/src/gr/grnet/pithos/web/client/othersharedtree/OtherSharedTreeViewModel.java
171 171

  
172 172
    private void fetchSharingUsers(final Command callback) {
173 173
        app.LOG("OtherSharedTreeViewModel::fetchSharingUsers() callback=", callback);
174
        GetRequest<SharingUsers> getSharingUsers = new GetRequest<SharingUsers>(SharingUsers.class, app.getApiPath(), "", "?format=json") {
174
        GetRequest<SharingUsers> getSharingUsers = new GetRequest<SharingUsers>(SharingUsers.class, Pithos.getStorageAPIURL(), "", "?format=json") {
175 175
            @Override
176 176
            public void onSuccess(final SharingUsers _result) {
177 177
                userLevelDataProviderForIDs.getList().clear();
......
282 282

  
283 283
    private void fetchSharedContainers(final String userID, final ListDataProvider<Folder> dataProvider, final Command callback) {
284 284
        app.LOG("OtherSharedTreeViewModel::fetchSharedContainers(), userID=", userID, ", callback=", callback);
285
        GetRequest<AccountResource> getUserSharedContainers = new GetRequest<AccountResource>(AccountResource.class, app.getApiPath(), userID, "?format=json") {
285
        GetRequest<AccountResource> getUserSharedContainers = new GetRequest<AccountResource>(AccountResource.class, Pithos.getStorageAPIURL(), userID, "?format=json") {
286 286

  
287 287
            @Override
288 288
            public void onSuccess(AccountResource _result) {
......
328 328
            final Folder f = folderIterator.next();
329 329

  
330 330
            String path = "/" + f.getContainer() + "?format=json&delimiter=/&prefix=" + URL.encodeQueryString(f.getPrefix());
331
            GetRequest<Folder> getFolder = new GetRequest<Folder>(Folder.class, app.getApiPath(), userID, path, f) {
331
            GetRequest<Folder> getFolder = new GetRequest<Folder>(Folder.class, Pithos.getStorageAPIURL(), userID, path, f) {
332 332
                @Override
333 333
                public void onSuccess(Folder _result) {
334 334
                    dataProvider.getList().add(_result);
......
376 376
    public void fetchFolder(final Folder f, final ListDataProvider<Folder> dataProvider, final boolean showfiles, final Command callback) {
377 377
        app.LOG("OtherSharedTreeViewModel::fetchFolder(), folder=", f, ", showfiles=", showfiles, ", callback=", callback);
378 378
        String path = "/" + f.getContainer() + "?format=json&delimiter=/&prefix=" + URL.encodeQueryString(f.getPrefix());
379
        GetRequest<Folder> getFolder = new GetRequest<Folder>(Folder.class, app.getApiPath(), f.getOwnerID(), path, f) {
379
        GetRequest<Folder> getFolder = new GetRequest<Folder>(Folder.class, Pithos.getStorageAPIURL(), f.getOwnerID(), path, f) {
380 380
            @Override
381 381
            public void onSuccess(final Folder _result) {
382 382
                if(showfiles) {
b/src/gr/grnet/pithos/web/client/tagtree/TagTreeViewModel.java
147 147
        if (iter.hasNext()) {
148 148
            Folder f = iter.next();
149 149
            String path = f.getUri() + "?format=json&meta=" + t.getName();
150
            GetRequest<Folder> getFolder = new GetRequest<Folder>(Folder.class, app.getApiPath(), app.getUserID(), path) {
150
            GetRequest<Folder> getFolder = new GetRequest<Folder>(Folder.class, Pithos.getStorageAPIURL(), app.getUserID(), path) {
151 151
                @Override
152 152
                public void onSuccess(Folder _result) {
153 153
                    files.addAll(_result.getFiles());

Also available in: Unified diff