X-Git-Url: https://code.grnet.gr/git/pithos-web-client/blobdiff_plain/f0ff407d83d979f9feae4232c6b9c410cd095e43..87487bbf9d41275ad0ccbb9d2150d8f36617fa8f:/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 d3f7b8c..d809732 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 @@ -79,9 +79,7 @@ import java.util.*; */ public class Pithos implements EntryPoint, ResizeHandler { - public static final String HOME_CONTAINER = "pithos"; - - public static final String TRASH_CONTAINER = "trash"; + private static final boolean IsLOGEnabled = true; public static final Configuration config = GWT.create(Configuration.class); @@ -133,25 +131,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); } @@ -336,11 +338,61 @@ public class Pithos implements EntryPoint, ResizeHandler { } }-*/; - 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(); - for(String arg : args) { - sb.append(arg); + 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(Object arg : args) { + if(arg instanceof Throwable) { + LOGError((Throwable) arg, sb); + } + else { + sb.append(arg); + } + } + if(sb.length() > 0) { __ConsoleLog(sb.toString()); } @@ -350,17 +402,17 @@ public class Pithos implements EntryPoint, ResizeHandler { lastModified = new Date(); //Initialize if-modified-since value with now. resources.pithosCss().ensureInjected(); boolean bareContent = Window.Location.getParameter("noframe") != null; - String contentWidth = bareContent ? "100%" : "75%"; + String contentWidth = bareContent ? Const.PERCENT_100 : "75%"; VerticalPanel outer = new VerticalPanel(); - outer.setWidth("100%"); + outer.setWidth(Const.PERCENT_100); if(!bareContent) { outer.addStyleName("pithos-outer"); } if(!bareContent) { topPanel = new TopPanel(this, Pithos.images); - topPanel.setWidth("100%"); + topPanel.setWidth(Const.PERCENT_100); outer.add(topPanel); outer.setCellHorizontalAlignment(topPanel, HasHorizontalAlignment.ALIGN_CENTER); } @@ -410,7 +462,7 @@ public class Pithos implements EntryPoint, ResizeHandler { outer.setCellHorizontalAlignment(header, HasHorizontalAlignment.ALIGN_CENTER); // Inner contains the various lists inner.sinkEvents(Event.ONCONTEXTMENU); - inner.setWidth("100%"); + inner.setWidth(Const.PERCENT_100); folderTreeSelectionModel = new SingleSelectionModel(); folderTreeSelectionModel.addSelectionChangeHandler(new SelectionChangeEvent.Handler() { @@ -449,7 +501,7 @@ public class Pithos implements EntryPoint, ResizeHandler { inner.add(fileList); trees = new VerticalPanel(); - trees.setWidth("100%"); + trees.setWidth(Const.PERCENT_100); // Add the left and right panels to the split panel. splitPanel.setLeftWidget(trees); @@ -458,7 +510,7 @@ public class Pithos implements EntryPoint, ResizeHandler { right.add(inner); splitPanel.setRightWidget(right); splitPanel.setSplitPosition("219px"); - splitPanel.setSize("100%", "100%"); + splitPanel.setSize(Const.PERCENT_100, Const.PERCENT_100); splitPanel.addStyleName("pithos-splitPanel"); splitPanel.setWidth(contentWidth); outer.add(splitPanel); @@ -466,7 +518,7 @@ public class Pithos implements EntryPoint, ResizeHandler { if(!bareContent) { statusPanel = new StatusPanel(); - statusPanel.setWidth("100%"); + statusPanel.setWidth(Const.PERCENT_100); outer.add(statusPanel); outer.setCellHorizontalAlignment(statusPanel, HasHorizontalAlignment.ALIGN_CENTER); } @@ -500,6 +552,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 @@ -512,7 +565,7 @@ public class Pithos implements EntryPoint, ResizeHandler { } else { for(Folder f : account.getContainers()) { - if(f.getName().equals(Pithos.TRASH_CONTAINER)) { + if(f.getName().equals(Const.TRASH_CONTAINER)) { trash = f; break; } @@ -588,7 +641,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()); @@ -598,7 +651,7 @@ public class Pithos implements EntryPoint, ResizeHandler { } } else {//retry - GWT.log("Retry " + retries); + LOG("Retry ", retries); Scheduler.get().scheduleDeferred(this); } } @@ -614,8 +667,8 @@ public class Pithos implements EntryPoint, ResizeHandler { } } }; - head.setHeader("X-Auth-Token", getUserToken()); - head.setHeader("If-Modified-Since", DateTimeFormat.getFormat("EEE, dd MMM yyyy HH:mm:ss").format(lastModified, TimeZone.createTimeZone(0)) + " GMT"); + head.setHeader(Const.X_AUTH_TOKEN, getUserToken()); + head.setHeader(Const.IF_MODIFIED_SINCE, DateTimeFormat.getFormat(Const.DATE_FORMAT_1).format(lastModified, TimeZone.createTimeZone(0)) + " GMT"); Scheduler.get().scheduleDeferred(head); return false; @@ -672,8 +725,8 @@ public class Pithos implements EntryPoint, ResizeHandler { */ private boolean parseUserCredentials() { Configuration conf = (Configuration) GWT.create(Configuration.class); - Dictionary otherProperties = Dictionary.getDictionary("otherProperties"); - String cookie = otherProperties.get("authCookie"); + Dictionary otherProperties = Dictionary.getDictionary(Const.OTHER_PROPERTIES); + String cookie = otherProperties.get(Const.AUTH_COOKIE); String auth = Cookies.getCookie(cookie); if(auth == null) { authenticateUser(); @@ -705,8 +758,8 @@ public class Pithos implements EntryPoint, ResizeHandler { * Redirect the user to the login page for authentication. */ protected void authenticateUser() { - Dictionary otherProperties = Dictionary.getDictionary("otherProperties"); - Window.Location.assign(otherProperties.get("loginUrl") + Window.Location.getHref()); + Dictionary otherProperties = Dictionary.getDictionary(Const.OTHER_PROPERTIES); + Window.Location.assign(otherProperties.get(Const.LOGIN_URL) + Window.Location.getHref()); } public void fetchAccount(final Command callback) { @@ -714,18 +767,28 @@ public class Pithos implements EntryPoint, ResizeHandler { GetRequest getAccount = new GetRequest(AccountResource.class, getApiPath(), 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()); @@ -740,7 +803,7 @@ public class Pithos implements EntryPoint, ResizeHandler { sessionExpired(); } }; - getAccount.setHeader("X-Auth-Token", userToken); + getAccount.setHeader(Const.X_AUTH_TOKEN, userToken); Scheduler.get().scheduleDeferred(getAccount); } @@ -754,7 +817,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()); @@ -769,12 +832,12 @@ public class Pithos implements EntryPoint, ResizeHandler { sessionExpired(); } }; - headAccount.setHeader("X-Auth-Token", userToken); + headAccount.setHeader(Const.X_AUTH_TOKEN, userToken); Scheduler.get().scheduleDeferred(headAccount); } protected void createHomeContainer(final AccountResource _account, final Command callback) { - String path = "/" + Pithos.HOME_CONTAINER; + String path = "/" + Const.HOME_CONTAINER; PutRequest createPithos = new PutRequest(getApiPath(), getUserID(), path) { @Override public void onSuccess(Resource result) { @@ -788,7 +851,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()); @@ -803,12 +866,12 @@ public class Pithos implements EntryPoint, ResizeHandler { sessionExpired(); } }; - createPithos.setHeader("X-Auth-Token", getUserToken()); + createPithos.setHeader(Const.X_AUTH_TOKEN, getUserToken()); Scheduler.get().scheduleDeferred(createPithos); } protected void createTrashContainer(final Command callback) { - String path = "/" + Pithos.TRASH_CONTAINER; + String path = "/" + Const.TRASH_CONTAINER; PutRequest createPithos = new PutRequest(getApiPath(), getUserID(), path) { @Override public void onSuccess(Resource result) { @@ -817,7 +880,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()); @@ -832,7 +895,7 @@ public class Pithos implements EntryPoint, ResizeHandler { sessionExpired(); } }; - createPithos.setHeader("X-Auth-Token", getUserToken()); + createPithos.setHeader(Const.X_AUTH_TOKEN, getUserToken()); Scheduler.get().scheduleDeferred(createPithos); } @@ -1002,7 +1065,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) { @@ -1018,7 +1081,7 @@ public class Pithos implements EntryPoint, ResizeHandler { pwp.hide(); } }; - deleteFolder.setHeader("X-Auth-Token", getUserToken()); + deleteFolder.setHeader(Const.X_AUTH_TOKEN, getUserToken()); Scheduler.get().scheduleDeferred(deleteFolder); } @@ -1038,7 +1101,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()); @@ -1053,12 +1116,12 @@ public class Pithos implements EntryPoint, ResizeHandler { sessionExpired(); } }; - copyFile.setHeader("X-Auth-Token", getUserToken()); - copyFile.setHeader("X-Copy-From", URL.encodePathSegment(file.getUri())); + copyFile.setHeader(Const.X_AUTH_TOKEN, getUserToken()); + copyFile.setHeader(Const.X_COPY_FROM, URL.encodePathSegment(file.getUri())); if(!file.getOwnerID().equals(targetUsername)) { - copyFile.setHeader("X-Source-Account", URL.encodePathSegment(file.getOwnerID())); + copyFile.setHeader(Const.X_SOURCE_ACCOUNT, URL.encodePathSegment(file.getOwnerID())); } - copyFile.setHeader("Content-Type", file.getContentType()); + copyFile.setHeader(Const.CONTENT_TYPE, file.getContentType()); Scheduler.get().scheduleDeferred(copyFile); } else if(callback != null) { @@ -1078,7 +1141,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()); @@ -1093,18 +1156,18 @@ public class Pithos implements EntryPoint, ResizeHandler { sessionExpired(); } }; - copyFolder.setHeader("X-Auth-Token", getUserToken()); - copyFolder.setHeader("Accept", "*/*"); - copyFolder.setHeader("Content-Length", "0"); - copyFolder.setHeader("Content-Type", "application/directory"); + copyFolder.setHeader(Const.X_AUTH_TOKEN, getUserToken()); + copyFolder.setHeader(Const.ACCEPT, "*/*"); + copyFolder.setHeader(Const.CONTENT_LENGTH, "0"); + copyFolder.setHeader(Const.CONTENT_TYPE, "application/directory"); if(!f.getOwnerID().equals(targetUsername)) { - copyFolder.setHeader("X-Source-Account", f.getOwnerID()); + copyFolder.setHeader(Const.X_SOURCE_ACCOUNT, f.getOwnerID()); } if(move) { - copyFolder.setHeader("X-Move-From", URL.encodePathSegment(f.getUri())); + copyFolder.setHeader(Const.X_MOVE_FROM, URL.encodePathSegment(f.getUri())); } else { - copyFolder.setHeader("X-Copy-From", URL.encodePathSegment(f.getUri())); + copyFolder.setHeader(Const.X_COPY_FROM, URL.encodePathSegment(f.getUri())); } Scheduler.get().scheduleDeferred(copyFolder); } @@ -1169,6 +1232,7 @@ public class Pithos implements EntryPoint, ResizeHandler { } void createMySharedTree() { + LOG("Pithos::createMySharedTree()"); mysharedTreeSelectionModel = new SingleSelectionModel(); mysharedTreeSelectionModel.addSelectionChangeHandler(new Handler() { @Override @@ -1205,6 +1269,7 @@ public class Pithos implements EntryPoint, ResizeHandler { } void createOtherSharedTree() { + LOG("Pithos::createOtherSharedTree()"); otherSharedTreeSelectionModel = new SingleSelectionModel(); otherSharedTreeSelectionModel.addSelectionChangeHandler(new Handler() { @Override @@ -1227,8 +1292,8 @@ public class Pithos implements EntryPoint, ResizeHandler { }); selectionModels.add(otherSharedTreeSelectionModel); otherSharedTreeViewModel = new OtherSharedTreeViewModel(Pithos.this, otherSharedTreeSelectionModel); + LOG("Pithos::createOtherSharedTree(), initializing otherSharedTreeViewModel with a callback"); otherSharedTreeViewModel.initialize(new Command() { - @Override public void execute() { otherSharedTreeView = new OtherSharedTreeView(otherSharedTreeViewModel); @@ -1239,19 +1304,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() { @@ -1304,7 +1385,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()); @@ -1319,10 +1399,10 @@ public class Pithos implements EntryPoint, ResizeHandler { sessionExpired(); } }; - newFolder.setHeader("X-Auth-Token", getUserToken()); - newFolder.setHeader("Content-Type", "application/folder"); - newFolder.setHeader("Accept", "*/*"); - newFolder.setHeader("Content-Length", "0"); + newFolder.setHeader(Const.X_AUTH_TOKEN, getUserToken()); + newFolder.setHeader(Const.CONTENT_TYPE, "application/folder"); + newFolder.setHeader(Const.ACCEPT, "*/*"); + newFolder.setHeader(Const.CONTENT_LENGTH, "0"); Scheduler.get().scheduleDeferred(newFolder); } else if(((RestException) t).getHttpStatusCode() == Response.SC_FORBIDDEN) { @@ -1336,7 +1416,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); } @@ -1345,7 +1425,7 @@ public class Pithos implements EntryPoint, ResizeHandler { sessionExpired(); } }; - headFolder.setHeader("X-Auth-Token", getUserToken()); + headFolder.setHeader(Const.X_AUTH_TOKEN, getUserToken()); Scheduler.get().scheduleDeferred(headFolder); } } @@ -1362,7 +1442,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()); @@ -1377,7 +1457,7 @@ public class Pithos implements EntryPoint, ResizeHandler { sessionExpired(); } }; - headFile.setHeader("X-Auth-Token", getUserToken()); + headFile.setHeader(Const.X_AUTH_TOKEN, getUserToken()); Scheduler.get().scheduleDeferred(headFile); } @@ -1463,7 +1543,7 @@ 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) { @@ -1479,7 +1559,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()); @@ -1489,7 +1569,7 @@ public class Pithos implements EntryPoint, ResizeHandler { } } }; - delete.setHeader("X-Auth-Token", getUserToken()); + delete.setHeader(Const.X_AUTH_TOKEN, getUserToken()); Scheduler.get().scheduleDeferred(delete); } }