X-Git-Url: https://code.grnet.gr/git/pithos-web-client/blobdiff_plain/7c818c14d7a7ecd4d04ff484098304ec60063d23..ae1e8bca41220b840776d93558dc653830cf8eae:/src/gr/grnet/pithos/web/client/foldertree/AccountResource.java diff --git a/src/gr/grnet/pithos/web/client/foldertree/AccountResource.java b/src/gr/grnet/pithos/web/client/foldertree/AccountResource.java index df7aef0..c437598 100644 --- a/src/gr/grnet/pithos/web/client/foldertree/AccountResource.java +++ b/src/gr/grnet/pithos/web/client/foldertree/AccountResource.java @@ -1,11 +1,50 @@ /* - * Copyright (c) 2011 Greek Research and Technology Network + * Copyright 2011-2012 GRNET S.A. All rights reserved. + * + * Redistribution and use in source and binary forms, with or + * without modification, are permitted provided that the following + * conditions are met: + * + * 1. Redistributions of source code must retain the above + * copyright notice, this list of conditions and the following + * disclaimer. + * + * 2. Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY GRNET S.A. ``AS IS'' AND ANY EXPRESS + * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GRNET S.A OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + * The views and conclusions contained in the software and + * documentation are those of the authors and should not be + * interpreted as representing official policies, either expressed + * or implied, of GRNET S.A. */ package gr.grnet.pithos.web.client.foldertree; +import gr.grnet.pithos.web.client.Pithos; +import gr.grnet.pithos.web.client.grouptree.Group; + +import java.util.ArrayList; +import java.util.Date; +import java.util.List; + import com.google.gwt.http.client.Header; import com.google.gwt.http.client.Response; +import com.google.gwt.http.client.URL; import com.google.gwt.i18n.client.DateTimeFormat; import com.google.gwt.i18n.client.DateTimeFormat.PredefinedFormat; import com.google.gwt.i18n.client.NumberFormat; @@ -13,12 +52,6 @@ import com.google.gwt.json.client.JSONArray; import com.google.gwt.json.client.JSONObject; import com.google.gwt.json.client.JSONParser; import com.google.gwt.json.client.JSONValue; -import gr.grnet.pithos.web.client.rest.resource.RestResource; -import java.util.ArrayList; -import java.util.Date; -import java.util.LinkedHashSet; -import java.util.List; -import java.util.Set; /** * Created by IntelliJ IDEA. User: chstath Date: 5/19/11 Time: 2:55 PM To change this template use File | Settings | @@ -32,22 +65,24 @@ public class AccountResource extends Resource { private long bytesUsed = 0; - private long bytesRemaining = 0; + private long quota = 0; private Date lastLogin = null; private Date lastModified = null; - private Set containers = new LinkedHashSet(); + private List containers = new ArrayList(); private Date currentLogin = null; - public long getBytesRemaining() { - return bytesRemaining; + private List groups = new ArrayList(); + + public long getQuota() { + return quota; } - public void setBytesRemaining(long bytesRemaining) { - this.bytesRemaining = bytesRemaining; + public void setQuota(long quota) { + this.quota = quota; } public long getBytesUsed() { @@ -66,7 +101,8 @@ public class AccountResource extends Resource { this.lastLogin = lastLogin; } - public Date getLastModified() { + @Override + public Date getLastModified() { return lastModified; } @@ -90,12 +126,7 @@ public class AccountResource extends Resource { this.numberOfObjects = numberOfObjects; } - @Override - public String getLastModifiedSince() { - return null; - } - - public Set getContainers() { + public List getContainers() { return containers; } @@ -107,49 +138,65 @@ public class AccountResource extends Resource { this.currentLogin = currentLogin; } - public void populate(Response response) { - String header = response.getHeader("X-Account-Container-Count"); - if (header != null) - numberOfContainers = Long.valueOf(header); - - header = response.getHeader("X-Account-Object-Count"); - if (header != null) - numberOfObjects = Long.valueOf(header); - - header = response.getHeader("X-Account-Bytes-Used"); - if (header != null) - bytesUsed = Long.valueOf(header); - - header = response.getHeader("X-Account-Bytes-Remaining"); - if (header != null) - bytesRemaining = Long.valueOf(header); - + public void populate(String owner, Response response) { DateTimeFormat df = DateTimeFormat.getFormat(PredefinedFormat.RFC_2822); - header = response.getHeader("X-Account-Last-Login"); - if (header != null) - lastLogin = df.parse(header); - - header = response.getHeader("Last-Modified"); - if (header != null) - lastModified = df.parse(header); - - JSONValue json = JSONParser.parseStrict(response.getText()); - JSONArray array = json.isArray(); - if (array != null) { - for (int i=0; i 0) { + containers.clear(); + JSONValue json = JSONParser.parseStrict(response.getText()); + JSONArray array = json.isArray(); + if (array != null) { + for (int i=0; i getGroups() { + return groups; + } + + public boolean hasHomeContainer() { + for (Folder f : containers) + if (f.getName().equals(Pithos.HOME_CONTAINER)) + return true; + return false; + } + + public boolean hasTrashContainer() { + for (Folder f : containers) + if (f.getName().equals(Pithos.TRASH_CONTAINER)) + return true; + return false; + } + + public void addGroup(Group newGroup) { + groups.add(newGroup); + } + + public void removeGroup(Group group) { + groups.remove(group); + } + + public Folder getTrash() { + for (Folder c : containers) { + if (c.getName().equals(Pithos.TRASH_CONTAINER)) + return c; + } + return null; + } + + public double getUsedPercentage() { + if (quota == 0) + return 0; + return ((double) bytesUsed) / quota; + } + + public Folder getPithos() { + for (Folder f : containers) + if (f.getName().equals(Pithos.HOME_CONTAINER)) + return f; + return null; + } }