X-Git-Url: https://code.grnet.gr/git/pithos-web-client/blobdiff_plain/59aa2375e72560e67d9ba6646df8ec115ac8b0e8..7a8d27050a8fcd289cabb2338496308807668d13:/src/gr/grnet/pithos/web/client/Pithos.java diff --git a/src/gr/grnet/pithos/web/client/Pithos.java b/src/gr/grnet/pithos/web/client/Pithos.java index 814ca84..053afd3 100644 --- a/src/gr/grnet/pithos/web/client/Pithos.java +++ b/src/gr/grnet/pithos/web/client/Pithos.java @@ -78,17 +78,107 @@ import java.util.*; * Entry point classes define onModuleLoad(). */ public class Pithos implements EntryPoint, ResizeHandler { - private static final boolean IsLOGEnabled = true; + private static final boolean IsLOGEnabled = false; public static final boolean IsDetailedHTTPLOGEnabled = true; + public static final boolean IsFullResponseBodyLOGEnabled = true; + private static final boolean EnableScheduledRefresh = true; // Make false only for debugging purposes. + public static final Set HTTPHeadersToIgnoreInLOG = new HashSet(); static { HTTPHeadersToIgnoreInLOG.add(Const.HTTP_HEADER_CONNECTION); HTTPHeadersToIgnoreInLOG.add(Const.HTTP_HEADER_DATE); HTTPHeadersToIgnoreInLOG.add(Const.HTTP_HEADER_KEEP_ALIVE); HTTPHeadersToIgnoreInLOG.add(Const.HTTP_HEADER_SERVER); + HTTPHeadersToIgnoreInLOG.add(Const.HTTP_HEADER_VARY); + HTTPHeadersToIgnoreInLOG.add(Const.IF_MODIFIED_SINCE); } public static final Configuration config = GWT.create(Configuration.class); + public static final String CONFIG_API_PATH = config.apiPath(); + static { + LOG("CONFIG_API_PATH = ", CONFIG_API_PATH); + } + + public static final Dictionary otherProperties = Dictionary.getDictionary(Const.OTHER_PROPERTIES); + public static String getFromOtherPropertiesOrDefault(String key, String def) { + try { + final String value = otherProperties.get(key); + return value == null ? def : value; + } + catch(Exception e) { + return def; + } + } + + public static String getFromOtherPropertiesOrNull(String key) { + return getFromOtherPropertiesOrDefault(key, null); + } + + private static final boolean SHOW_COPYRIGHT; + static { + final String valueStr = getFromOtherPropertiesOrDefault("SHOW_COPYRIGHT", "true").trim().toLowerCase(); + SHOW_COPYRIGHT = "true".equals(valueStr); + LOG("SHOW_COPYRIGHT = '", valueStr, "' ==> ", SHOW_COPYRIGHT); + } + + public static final String OTHERPROPS_STORAGE_API_URL = getFromOtherPropertiesOrNull("STORAGE_API_URL"); + public static final String OTHERPROPS_USER_CATALOGS_API_URL = getFromOtherPropertiesOrNull("USER_CATALOGS_API_URL"); + static { + LOG("STORAGE_API_URL = ", OTHERPROPS_STORAGE_API_URL); + LOG("USER_CATALOGS_API_URL = ", OTHERPROPS_USER_CATALOGS_API_URL); + } + + public static final String STORAGE_API_URL; + static { + if(OTHERPROPS_STORAGE_API_URL != null) { + STORAGE_API_URL = OTHERPROPS_STORAGE_API_URL; + } + else if(CONFIG_API_PATH != null) { + STORAGE_API_URL = CONFIG_API_PATH; + } + else { + throw new RuntimeException("Unknown STORAGE_API_URL"); + } + + LOG("Computed STORAGE_API_URL = ", STORAGE_API_URL); + } + + public static final String STORAGE_VIEW_URL; + static { + final String viewURL = getFromOtherPropertiesOrNull("STORAGE_VIEW_URL"); + if(viewURL != null) { + STORAGE_VIEW_URL = viewURL; + } + else { + STORAGE_VIEW_URL = STORAGE_API_URL; + } + + LOG("Computed STORAGE_VIEW_URL = ", STORAGE_VIEW_URL); + } + + public static final String PUBLIC_LINK_VIEW_PREFIX = getFromOtherPropertiesOrDefault("PUBLIC_LINK_VIEW_PREFIX", ""); + + public static final String USER_CATALOGS_API_URL; + static { + if(OTHERPROPS_USER_CATALOGS_API_URL != null) { + USER_CATALOGS_API_URL = OTHERPROPS_USER_CATALOGS_API_URL; + } + else if(OTHERPROPS_STORAGE_API_URL != null) { + throw new RuntimeException("STORAGE_API_URL is defined but USER_CATALOGS_API_URL is not"); + } + else { + // https://server.com/v1/ --> https://server.com + String url = CONFIG_API_PATH; + url = Helpers.stripTrailing(url, "/"); + url = Helpers.upToIncludingLastPart(url, "/"); + url = Helpers.stripTrailing(url, "/"); + url = url + "/user_catalogs"; + + USER_CATALOGS_API_URL = url; + + LOG("Computed USER_CATALOGS_API_URL = ", USER_CATALOGS_API_URL); + } + } public interface Style extends CssResource { String commandAnchor(); @@ -283,7 +373,7 @@ public class Pithos implements EntryPoint, ResizeHandler { private String userID = null; /** - * Hold mappings from user UUIDs to emails and vice-versa. + * Holds mappings from user UUIDs to emails and vice-versa. */ private UserCatalogs userCatalogs = new UserCatalogs(); @@ -339,14 +429,11 @@ public class Pithos implements EntryPoint, ResizeHandler { } static native void __ConsoleLog(String message) /*-{ - try { - console.log(message); - } catch (e) { - } + try { console.log(message); } catch (e) {} }-*/; public static void LOGError(Throwable error, StringBuilder sb) { - if(!IsLOGEnabled) { return; } + if(!isLOGEnabled()) { return; } sb.append("\nException: [" + error.toString().replace("\n", "\n ") + "]"); Throwable cause = error.getCause(); @@ -374,7 +461,7 @@ public class Pithos implements EntryPoint, ResizeHandler { } public static void LOGError(Throwable error) { - if(!IsLOGEnabled) { return; } + if(!isLOGEnabled()) { return; } final StringBuilder sb = new StringBuilder(); LOGError(error, sb); @@ -383,12 +470,12 @@ public class Pithos implements EntryPoint, ResizeHandler { } } - public static boolean isLogEnabled() { + public static boolean isLOGEnabled() { return IsLOGEnabled; } public static void LOG(Object ...args) { - if(!IsLOGEnabled) { return; } + if(!isLOGEnabled()) { return; } final StringBuilder sb = new StringBuilder(); for(Object arg : args) { @@ -605,7 +692,9 @@ public class Pithos implements EntryPoint, ResizeHandler { }); } - public void scheduleResfresh() { + public void scheduleRefresh() { + if(!Pithos.EnableScheduledRefresh) { return; } + Scheduler.get().scheduleFixedDelay(new RepeatingCommand() { @Override @@ -615,7 +704,7 @@ public class Pithos implements EntryPoint, ResizeHandler { return true; } - HeadRequest head = new HeadRequest(Folder.class, getApiPath(), f.getOwnerID(), "/" + f.getContainer()) { + HeadRequest head = new HeadRequest(Folder.class, getStorageAPIURL(), f.getOwnerID(), "/" + f.getContainer()) { @Override public void onSuccess(Folder _result) { @@ -625,7 +714,7 @@ public class Pithos implements EntryPoint, ResizeHandler { @Override public void execute() { - scheduleResfresh(); + scheduleRefresh(); } }, false); @@ -635,19 +724,19 @@ public class Pithos implements EntryPoint, ResizeHandler { @Override public void execute() { - scheduleResfresh(); + scheduleRefresh(); } }); } else { - scheduleResfresh(); + scheduleRefresh(); } } @Override public void onError(Throwable t) { if(t instanceof RestException && ((RestException) t).getHttpStatusCode() == HttpStatus.SC_NOT_MODIFIED) { - scheduleResfresh(); + scheduleRefresh(); } else if(retries >= MAX_RETRIES) { LOG("Error heading folder. ", t); @@ -733,9 +822,7 @@ public class Pithos implements EntryPoint, ResizeHandler { * Parse and store the user credentials to the appropriate fields. */ private boolean parseUserCredentials() { - Configuration conf = (Configuration) GWT.create(Configuration.class); - Dictionary otherProperties = Dictionary.getDictionary(Const.OTHER_PROPERTIES); - String cookie = otherProperties.get(Const.AUTH_COOKIE); + final String cookie = otherProperties.get(Const.AUTH_COOKIE); String auth = Cookies.getCookie(cookie); if(auth == null) { authenticateUser(); @@ -747,19 +834,14 @@ public class Pithos implements EntryPoint, ResizeHandler { if(auth.endsWith("\"")) { auth = auth.substring(0, auth.length() - 1); } - String[] authSplit = auth.split("\\" + conf.cookieSeparator(), 2); + String[] authSplit = auth.split("\\" + config.cookieSeparator(), 2); if(authSplit.length != 2) { authenticateUser(); return false; } - userID = authSplit[0]; - userToken = authSplit[1]; + this.userID = authSplit[0]; + this.userToken = authSplit[1]; - String gotoUrl = Window.Location.getParameter("goto"); - if(gotoUrl != null && gotoUrl.length() > 0) { - Window.Location.assign(gotoUrl); - return false; - } return true; } @@ -774,7 +856,7 @@ public class Pithos implements EntryPoint, ResizeHandler { public void fetchAccount(final Command callback) { String path = "?format=json"; - GetRequest getAccount = new GetRequest(AccountResource.class, getApiPath(), userID, path) { + GetRequest getAccount = new GetRequest(AccountResource.class, getStorageAPIURL(), userID, path) { @Override public void onSuccess(AccountResource accountResource) { account = accountResource; @@ -817,7 +899,7 @@ public class Pithos implements EntryPoint, ResizeHandler { } public void updateStatistics() { - HeadRequest headAccount = new HeadRequest(AccountResource.class, getApiPath(), userID, "", account) { + HeadRequest headAccount = new HeadRequest(AccountResource.class, getStorageAPIURL(), userID, "", account) { @Override public void onSuccess(AccountResource _result) { @@ -847,7 +929,7 @@ public class Pithos implements EntryPoint, ResizeHandler { protected void createHomeContainer(final AccountResource _account, final Command callback) { String path = "/" + Const.HOME_CONTAINER; - PutRequest createPithos = new PutRequest(getApiPath(), getUserID(), path) { + PutRequest createPithos = new PutRequest(getStorageAPIURL(), getUserID(), path) { @Override public void onSuccess(Resource result) { if(!_account.hasTrashContainer()) { @@ -881,7 +963,7 @@ public class Pithos implements EntryPoint, ResizeHandler { protected void createTrashContainer(final Command callback) { String path = "/" + Const.TRASH_CONTAINER; - PutRequest createPithos = new PutRequest(getApiPath(), getUserID(), path) { + PutRequest createPithos = new PutRequest(getStorageAPIURL(), getUserID(), path) { @Override public void onSuccess(Resource result) { fetchAccount(callback); @@ -1022,12 +1104,28 @@ public class Pithos implements EntryPoint, ResizeHandler { $doc.body.onselectstart = null; }-*/; - /** - * @return the absolute path of the API root URL - */ - public String getApiPath() { - Configuration conf = (Configuration) GWT.create(Configuration.class); - return conf.apiPath(); + public static String getStorageAPIURL() { + return STORAGE_API_URL; + } + + public static String getStorageViewURL() { + return STORAGE_VIEW_URL; + } + + public static boolean isShowCopyrightMessage() { + return SHOW_COPYRIGHT; + } + + public static String getUserCatalogsURL() { + return USER_CATALOGS_API_URL; + } + + public static String getFileViewURL(File file) { + return Pithos.getStorageViewURL() + file.getOwnerID() + file.getUri(); + } + + public static String getVersionedFileViewURL(File file, int version) { + return getFileViewURL(file) + "?version=" + version; } /** @@ -1048,7 +1146,7 @@ public class Pithos implements EntryPoint, ResizeHandler { final PleaseWaitPopup pwp = new PleaseWaitPopup(); pwp.center(); String path = "/" + folder.getContainer() + "/" + folder.getPrefix() + "?delimiter=/" + "&t=" + System.currentTimeMillis(); - DeleteRequest deleteFolder = new DeleteRequest(getApiPath(), folder.getOwnerID(), path) { + DeleteRequest deleteFolder = new DeleteRequest(getStorageAPIURL(), folder.getOwnerID(), path) { @Override protected void onUnauthorized(Response response) { @@ -1102,7 +1200,7 @@ public class Pithos implements EntryPoint, ResizeHandler { if(iter.hasNext()) { File file = iter.next(); String path = targetUri + "/" + file.getName(); - PutRequest copyFile = new PutRequest(getApiPath(), targetUsername, path) { + PutRequest copyFile = new PutRequest(getStorageAPIURL(), targetUsername, path) { @Override public void onSuccess(Resource result) { copyFiles(iter, targetUsername, targetUri, callback); @@ -1140,7 +1238,7 @@ public class Pithos implements EntryPoint, ResizeHandler { public void copyFolder(final Folder f, final String targetUsername, final String targetUri, boolean move, final Command callback) { String path = targetUri + "?delimiter=/"; - PutRequest copyFolder = new PutRequest(getApiPath(), targetUsername, path) { + PutRequest copyFolder = new PutRequest(getStorageAPIURL(), targetUsername, path) { @Override public void onSuccess(Resource result) { if(callback != null) { @@ -1301,14 +1399,21 @@ public class Pithos implements EntryPoint, ResizeHandler { }); selectionModels.add(otherSharedTreeSelectionModel); otherSharedTreeViewModel = new OtherSharedTreeViewModel(Pithos.this, otherSharedTreeSelectionModel); + // #3784 We show it empty... + otherSharedTreeView = new OtherSharedTreeView(otherSharedTreeViewModel, true); + trees.insert(otherSharedTreeView, 1); + LOG("Pithos::createOtherSharedTree(), initializing otherSharedTreeViewModel with a callback"); otherSharedTreeViewModel.initialize(new Command() { @Override public void execute() { - otherSharedTreeView = new OtherSharedTreeView(otherSharedTreeViewModel); + // #3784 ... then remove the empty stuff and add a new view with the populated model + trees.remove(otherSharedTreeView); + + otherSharedTreeView = new OtherSharedTreeView(otherSharedTreeViewModel, false); trees.insert(otherSharedTreeView, 1); treeViews.add(otherSharedTreeView); - scheduleResfresh(); + scheduleRefresh(); } }); } @@ -1372,7 +1477,7 @@ public class Pithos implements EntryPoint, ResizeHandler { } } else { - HeadRequest headFolder = new HeadRequest(Folder.class, getApiPath(), folder.getOwnerID(), folder.getUri(), folder) { + HeadRequest headFolder = new HeadRequest(Folder.class, getStorageAPIURL(), folder.getOwnerID(), folder.getUri(), folder) { @Override public void onSuccess(Folder _result) { @@ -1386,7 +1491,7 @@ public class Pithos implements EntryPoint, ResizeHandler { if(t instanceof RestException) { if(((RestException) t).getHttpStatusCode() == Response.SC_NOT_FOUND) { final String path = folder.getUri(); - PutRequest newFolder = new PutRequest(getApiPath(), folder.getOwnerID(), path) { + PutRequest newFolder = new PutRequest(getStorageAPIURL(), folder.getOwnerID(), path) { @Override public void onSuccess(Resource _result) { scheduleFolderHeadCommand(folder, callback); @@ -1440,7 +1545,7 @@ public class Pithos implements EntryPoint, ResizeHandler { } public void scheduleFileHeadCommand(File f, final Command callback) { - HeadRequest headFile = new HeadRequest(File.class, getApiPath(), f.getOwnerID(), f.getUri(), f) { + HeadRequest headFile = new HeadRequest(File.class, getStorageAPIURL(), f.getOwnerID(), f.getUri(), f) { @Override public void onSuccess(File _result) { @@ -1554,7 +1659,7 @@ public class Pithos implements EntryPoint, ResizeHandler { public void purgeContainer(final Folder container) { String path = "/" + container.getName() + "?delimiter=/"; - DeleteRequest delete = new DeleteRequest(getApiPath(), getUserID(), path) { + DeleteRequest delete = new DeleteRequest(getStorageAPIURL(), getUserID(), path) { @Override protected void onUnauthorized(Response response) {