X-Git-Url: https://code.grnet.gr/git/pithos-web-client/blobdiff_plain/fa68c84d23b624c6d652086a54408f06d4e45cf4..28e270f9709fc94aea24d3cc6cc855af8e4003da:/src/gr/grnet/pithos/web/client/Pithos.java?ds=sidebyside diff --git a/src/gr/grnet/pithos/web/client/Pithos.java b/src/gr/grnet/pithos/web/client/Pithos.java index 16eef94..f3e6f4b 100644 --- a/src/gr/grnet/pithos/web/client/Pithos.java +++ b/src/gr/grnet/pithos/web/client/Pithos.java @@ -1,5 +1,5 @@ /* - * Copyright 2011-2012 GRNET S.A. All rights reserved. + * Copyright 2011-2013 GRNET S.A. All rights reserved. * * Redistribution and use in source and binary forms, with or * without modification, are permitted provided that the following @@ -78,8 +78,76 @@ import java.util.*; * Entry point classes define onModuleLoad(). */ public class Pithos implements EntryPoint, ResizeHandler { + private static final boolean IsLOGEnabled = true; + public static final boolean IsDetailedHTTPLOGEnabled = true; + public static final boolean IsFullResponseBodyLOGEnabled = true; + + 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 getFromOtherPropertiesOrNull(String key) { + try { + return otherProperties.get(key); + } + catch(Exception e) { + LOGError(e); + return null; + } + } + 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"); + } + } + 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("USER_CATALOGS_API_URL = ", USER_CATALOGS_API_URL); + } + } public interface Style extends CssResource { String commandAnchor(); @@ -129,25 +197,29 @@ public class Pithos implements EntryPoint, ResizeHandler { return displayName == null ? getUserID() : displayName; } - public boolean hasUserDisplayNameForID(String userID) { + public boolean hasDisplayNameForUserID(String userID) { return userCatalogs.getDisplayName(userID) != null; } - public String getUserDisplayNameForID(String userID) { + public boolean hasIDForUserDisplayName(String userDisplayName) { + return userCatalogs.getID(userDisplayName) != null; + } + + public String getDisplayNameForUserID(String userID) { return userCatalogs.getDisplayName(userID); } - public String getUserIDForDisplayName(String displayName) { - return userCatalogs.getUserID(displayName); + public String getIDForUserDisplayName(String userDisplayName) { + return userCatalogs.getID(userDisplayName); } - public List getUserDisplayNamesForIDs(List userIDs) { + public List getDisplayNamesForUserIDs(List userIDs) { if(userIDs == null) { userIDs = new ArrayList(); } final List userDisplayNames = new ArrayList(); for(String userID : userIDs) { - final String displayName = getUserDisplayNameForID(userID); + final String displayName = getDisplayNameForUserID(userID); userDisplayNames.add(displayName); } @@ -270,7 +342,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(); @@ -326,27 +398,76 @@ 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 LOG(String ...args) { + public static void LOGError(Throwable error, StringBuilder sb) { + if(!isLOGEnabled()) { return; } + + sb.append("\nException: [" + error.toString().replace("\n", "\n ") + "]"); + Throwable cause = error.getCause(); + if(cause != null) { + sb.append("\nCauses:\n"); + while(cause != null) { + sb.append(" "); + sb.append("[" + cause.toString().replace("\n", "\n ") + "]"); + sb.append("\n"); + cause = cause.getCause(); + } + } + else { + sb.append("\n"); + } + + StackTraceElement[] stackTrace = error.getStackTrace(); + sb.append("Stack trace (" + stackTrace.length + " elements):\n"); + for(int i = 0; i < stackTrace.length; i++) { + StackTraceElement errorElem = stackTrace[i]; + sb.append(" [" + i + "] "); + sb.append(errorElem.toString()); + sb.append("\n"); + } + } + + public static void LOGError(Throwable error) { + if(!isLOGEnabled()) { return; } + + final StringBuilder sb = new StringBuilder(); + LOGError(error, sb); + if(sb.length() > 0) { + __ConsoleLog(sb.toString()); + } + } + + public static boolean isLOGEnabled() { + return IsLOGEnabled; + } + + public static void LOG(Object ...args) { + if(!isLOGEnabled()) { return; } + final StringBuilder sb = new StringBuilder(); - for(String arg : args) { - sb.append(arg); + for(Object arg : args) { + if(arg instanceof Throwable) { + LOGError((Throwable) arg, sb); + } + else { + sb.append(arg); + } } + if(sb.length() > 0) { __ConsoleLog(sb.toString()); } } private void initialize() { + userCatalogs.updateWithIDAndName("*", "All Pithos users"); + lastModified = new Date(); //Initialize if-modified-since value with now. resources.pithosCss().ensureInjected(); boolean bareContent = Window.Location.getParameter("noframe") != null; - String contentWidth = bareContent ? Const.PERCENT_100 : "75%"; + String contentWidth = bareContent ? Const.PERCENT_100 : Const.PERCENT_75; VerticalPanel outer = new VerticalPanel(); outer.setWidth(Const.PERCENT_100); @@ -496,6 +617,7 @@ public class Pithos implements EntryPoint, ResizeHandler { Scheduler.get().scheduleDeferred(new ScheduledCommand() { @Override public void execute() { + LOG("Pithos::initialize() Calling Pithos::fetchAccount()"); fetchAccount(new Command() { @Override @@ -549,7 +671,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) { @@ -584,7 +706,7 @@ public class Pithos implements EntryPoint, ResizeHandler { scheduleResfresh(); } else if(retries >= MAX_RETRIES) { - GWT.log("Error heading folder", t); + LOG("Error heading folder. ", t); setError(t); if(t instanceof RestException) { displayError("Error heading folder: " + ((RestException) t).getHttpStatusText()); @@ -594,7 +716,7 @@ public class Pithos implements EntryPoint, ResizeHandler { } } else {//retry - GWT.log("Retry " + retries); + LOG("Retry ", retries); Scheduler.get().scheduleDeferred(this); } } @@ -667,9 +789,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(); @@ -681,13 +801,13 @@ 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) { @@ -708,20 +828,30 @@ 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 _result) { - account = _result; + public void onSuccess(AccountResource accountResource) { + account = accountResource; if(callback != null) { callback.execute(); } + + final List memberIDs = new ArrayList(); + final List groups = account.getGroups(); + for(Group group : groups) { + memberIDs.addAll(group.getMemberIDs()); + } + memberIDs.add(Pithos.this.getUserID()); + + final List theUnknown = Pithos.this.filterUserIDsWithUnknownDisplayName(memberIDs); // Initialize the user catalog - new UpdateUserCatalogs(Pithos.this, Pithos.this.getUserID()).scheduleDeferred(); + new UpdateUserCatalogs(Pithos.this, theUnknown).scheduleDeferred(); + LOG("Called new UpdateUserCatalogs(Pithos.this, theUnknown).scheduleDeferred();"); } @Override public void onError(Throwable t) { - GWT.log("Error getting account", t); + LOG("Error getting account", t); setError(t); if(t instanceof RestException) { displayError("Error getting account: " + ((RestException) t).getHttpStatusText()); @@ -741,7 +871,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) { @@ -750,7 +880,7 @@ public class Pithos implements EntryPoint, ResizeHandler { @Override public void onError(Throwable t) { - GWT.log("Error getting account", t); + LOG("Error getting account", t); setError(t); if(t instanceof RestException) { displayError("Error getting account: " + ((RestException) t).getHttpStatusText()); @@ -771,7 +901,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()) { @@ -784,7 +914,7 @@ public class Pithos implements EntryPoint, ResizeHandler { @Override public void onError(Throwable t) { - GWT.log("Error creating pithos", t); + LOG("Error creating pithos", t); setError(t); if(t instanceof RestException) { displayError("Error creating pithos: " + ((RestException) t).getHttpStatusText()); @@ -805,7 +935,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); @@ -813,7 +943,7 @@ public class Pithos implements EntryPoint, ResizeHandler { @Override public void onError(Throwable t) { - GWT.log("Error creating pithos", t); + LOG("Error creating pithos", t); setError(t); if(t instanceof RestException) { displayError("Error creating pithos: " + ((RestException) t).getHttpStatusText()); @@ -946,12 +1076,12 @@ 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 getUserCatalogsURL() { + return USER_CATALOGS_API_URL; } /** @@ -972,7 +1102,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) { @@ -998,7 +1128,7 @@ public class Pithos implements EntryPoint, ResizeHandler { @Override public void onError(Throwable t) { - GWT.log("", t); + LOG(t); setError(t); if(t instanceof RestException) { if(((RestException) t).getHttpStatusCode() != Response.SC_NOT_FOUND) { @@ -1026,7 +1156,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); @@ -1034,7 +1164,7 @@ public class Pithos implements EntryPoint, ResizeHandler { @Override public void onError(Throwable t) { - GWT.log("", t); + LOG(t); setError(t); if(t instanceof RestException) { displayError("Unable to copy file: " + ((RestException) t).getHttpStatusText()); @@ -1064,7 +1194,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) { @@ -1074,7 +1204,7 @@ public class Pithos implements EntryPoint, ResizeHandler { @Override public void onError(Throwable t) { - GWT.log("", t); + LOG(t); setError(t); if(t instanceof RestException) { displayError("Unable to copy folder: " + ((RestException) t).getHttpStatusText()); @@ -1165,6 +1295,7 @@ public class Pithos implements EntryPoint, ResizeHandler { } void createMySharedTree() { + LOG("Pithos::createMySharedTree()"); mysharedTreeSelectionModel = new SingleSelectionModel(); mysharedTreeSelectionModel.addSelectionChangeHandler(new Handler() { @Override @@ -1201,6 +1332,7 @@ public class Pithos implements EntryPoint, ResizeHandler { } void createOtherSharedTree() { + LOG("Pithos::createOtherSharedTree()"); otherSharedTreeSelectionModel = new SingleSelectionModel(); otherSharedTreeSelectionModel.addSelectionChangeHandler(new Handler() { @Override @@ -1223,10 +1355,17 @@ public class Pithos implements EntryPoint, ResizeHandler { }); selectionModels.add(otherSharedTreeSelectionModel); otherSharedTreeViewModel = new OtherSharedTreeViewModel(Pithos.this, otherSharedTreeSelectionModel); - otherSharedTreeViewModel.initialize(new Command() { + // #3784 We show it empty... + otherSharedTreeView = new OtherSharedTreeView(otherSharedTreeViewModel); + trees.insert(otherSharedTreeView, 1); + LOG("Pithos::createOtherSharedTree(), initializing otherSharedTreeViewModel with a callback"); + otherSharedTreeViewModel.initialize(new Command() { @Override public void execute() { + // #3784 ... then remove the empty stuff and add a new view with the populated model + trees.remove(otherSharedTreeView); + otherSharedTreeView = new OtherSharedTreeView(otherSharedTreeViewModel); trees.insert(otherSharedTreeView, 1); treeViews.add(otherSharedTreeView); @@ -1235,19 +1374,35 @@ public class Pithos implements EntryPoint, ResizeHandler { }); } - public native void log1(String message)/*-{ - $wnd.console.log(message); - }-*/; - public String getErrorData() { - if(error != null) { - return error.toString(); + final StringBuilder sb = new StringBuilder(); + final String NL = Const.NL; + Throwable t = this.error; + while(t != null) { + sb.append(t.toString()); + sb.append(NL); + StackTraceElement[] traces = t.getStackTrace(); + for(StackTraceElement trace : traces) { + sb.append(" ["); + sb.append(trace.getClassName()); + sb.append("::"); + sb.append(trace.getMethodName()); + sb.append("() at "); + sb.append(trace.getFileName()); + sb.append(":"); + sb.append(trace.getLineNumber()); + sb.append("]"); + sb.append(NL); + } + t = t.getCause(); } - return ""; + + return sb.toString(); } public void setError(Throwable t) { error = t; + LOG(t); } public void showRelevantToolbarButtons() { @@ -1278,7 +1433,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) { @@ -1292,7 +1447,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); @@ -1300,7 +1455,6 @@ public class Pithos implements EntryPoint, ResizeHandler { @Override public void onError(Throwable _t) { - GWT.log("", _t); setError(_t); if(_t instanceof RestException) { displayError("Unable to create folder: " + ((RestException) _t).getHttpStatusText()); @@ -1332,7 +1486,7 @@ public class Pithos implements EntryPoint, ResizeHandler { displayError("System error heading folder: " + t.getMessage()); } - GWT.log("Error heading folder", t); + LOG("Error heading folder", t); setError(t); } @@ -1347,7 +1501,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) { @@ -1358,7 +1512,7 @@ public class Pithos implements EntryPoint, ResizeHandler { @Override public void onError(Throwable t) { - GWT.log("Error heading file", t); + LOG("Error heading file", t); setError(t); if(t instanceof RestException) { displayError("Error heading file: " + ((RestException) t).getHttpStatusText()); @@ -1459,9 +1613,9 @@ public class Pithos implements EntryPoint, ResizeHandler { fileList.selectByUrl(selectedUrls); } - public void emptyContainer(final Folder container) { + 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) { @@ -1475,7 +1629,7 @@ public class Pithos implements EntryPoint, ResizeHandler { @Override public void onError(Throwable t) { - GWT.log("Error deleting trash", t); + LOG("Error deleting trash", t); setError(t); if(t instanceof RestException) { displayError("Error deleting trash: " + ((RestException) t).getHttpStatusText());