Conditionally enable the scheduled refresh functionality
[pithos-web-client] / src / gr / grnet / pithos / web / client / Pithos.java
index 3d575f9..a304a9b 100644 (file)
@@ -81,6 +81,7 @@ public class Pithos implements EntryPoint, ResizeHandler {
     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<String> HTTPHeadersToIgnoreInLOG = new HashSet<String>();
     static {
@@ -99,16 +100,20 @@ public class Pithos implements EntryPoint, ResizeHandler {
     }
 
     public static final Dictionary otherProperties = Dictionary.getDictionary(Const.OTHER_PROPERTIES);
-    public static String getFromOtherPropertiesOrNull(String key) {
+    public static String getFromOtherPropertiesOrDefault(String key, String def) {
         try {
-            return otherProperties.get(key);
+            final String value = otherProperties.get(key);
+            return value == null ? def : value;
         }
         catch(Exception e) {
-            LOGError(e);
-            return null;
+            return def;
         }
     }
 
+    public static String getFromOtherPropertiesOrNull(String key) {
+        return getFromOtherPropertiesOrDefault(key, 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 {
@@ -130,6 +135,22 @@ public class Pithos implements EntryPoint, ResizeHandler {
 
         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) {
@@ -664,7 +685,9 @@ public class Pithos implements EntryPoint, ResizeHandler {
         });
     }
 
-    public void scheduleResfresh() {
+    public void scheduleRefresh() {
+        if(!Pithos.EnableScheduledRefresh) { return; }
+
         Scheduler.get().scheduleFixedDelay(new RepeatingCommand() {
 
             @Override
@@ -684,7 +707,7 @@ public class Pithos implements EntryPoint, ResizeHandler {
 
                                 @Override
                                 public void execute() {
-                                    scheduleResfresh();
+                                    scheduleRefresh();
                                 }
 
                             }, false);
@@ -694,19 +717,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);
@@ -1083,10 +1106,18 @@ public class Pithos implements EntryPoint, ResizeHandler {
         return STORAGE_API_URL;
     }
 
+    public static String getStorageViewURL() {
+        return STORAGE_VIEW_URL;
+    }
+
     public static String getUserCatalogsURL() {
         return USER_CATALOGS_API_URL;
     }
 
+    public static String getFileViewURL(File file) {
+        return Pithos.getStorageViewURL() + file.getOwnerID() + file.getUri();
+    }
+
     /**
      * History support for folder navigation
      * adds a new browser history entry
@@ -1372,7 +1403,7 @@ public class Pithos implements EntryPoint, ResizeHandler {
                 otherSharedTreeView = new OtherSharedTreeView(otherSharedTreeViewModel, false);
                 trees.insert(otherSharedTreeView, 1);
                 treeViews.add(otherSharedTreeView);
-                scheduleResfresh();
+                scheduleRefresh();
             }
         });
     }