From: Christos Stathis Date: Thu, 21 Jul 2011 15:24:43 +0000 (+0300) Subject: Implemented tag assignment to files X-Git-Tag: pithos/v0.7.8~170^2~2^2~1 X-Git-Url: https://code.grnet.gr/git/pithos/commitdiff_plain/a39e5b4726333ec5ff7d625ead9b7773d148b296 Implemented tag assignment to files --- diff --git a/web_client/src/gr/grnet/pithos/web/client/AbstractPropertiesDialog.java b/web_client/src/gr/grnet/pithos/web/client/AbstractPropertiesDialog.java index 33671ef..b63350a 100644 --- a/web_client/src/gr/grnet/pithos/web/client/AbstractPropertiesDialog.java +++ b/web_client/src/gr/grnet/pithos/web/client/AbstractPropertiesDialog.java @@ -90,8 +90,6 @@ public abstract class AbstractPropertiesDialog extends DialogBox { } /** * Retrieves all user tags from the server and updates the FlowPanel - * - * @param userId */ protected void updateTags() { GetCommand tc = new GetCommand(TagsResource.class, Pithos.get().getCurrentUserResource().getTagsPath(),null) { diff --git a/web_client/src/gr/grnet/pithos/web/client/FileList.java b/web_client/src/gr/grnet/pithos/web/client/FileList.java index fd2f876..a43e66e 100644 --- a/web_client/src/gr/grnet/pithos/web/client/FileList.java +++ b/web_client/src/gr/grnet/pithos/web/client/FileList.java @@ -663,6 +663,7 @@ public class FileList extends Composite { Folder selectedItem = treeView.getSelection(); provider.setList(files); + selectionModel.clear(); } /** diff --git a/web_client/src/gr/grnet/pithos/web/client/FilePropertiesDialog.java b/web_client/src/gr/grnet/pithos/web/client/FilePropertiesDialog.java index 86e0d26..380f19c 100644 --- a/web_client/src/gr/grnet/pithos/web/client/FilePropertiesDialog.java +++ b/web_client/src/gr/grnet/pithos/web/client/FilePropertiesDialog.java @@ -35,9 +35,14 @@ package gr.grnet.pithos.web.client; import com.google.gwt.core.client.Scheduler; +import com.google.gwt.json.client.JSONArray; +import com.google.gwt.json.client.JSONString; +import com.google.gwt.user.client.ui.Anchor; +import com.google.gwt.user.client.ui.Label; import gr.grnet.pithos.web.client.foldertree.File; import gr.grnet.pithos.web.client.foldertree.Resource; import gr.grnet.pithos.web.client.rest.PostCommand; +import gr.grnet.pithos.web.client.rest.PostRequest; import gr.grnet.pithos.web.client.rest.PutRequest; import gr.grnet.pithos.web.client.rest.RestException; @@ -62,6 +67,8 @@ import com.google.gwt.user.client.ui.HasHorizontalAlignment; import com.google.gwt.user.client.ui.HorizontalPanel; import com.google.gwt.user.client.ui.TextBox; import com.google.gwt.user.client.ui.VerticalPanel; +import gr.grnet.pithos.web.client.tagtree.Tag; +import java.util.Iterator; /** * The 'File properties' dialog box implementation. @@ -170,15 +177,6 @@ public class FilePropertiesDialog extends AbstractPropertiesDialog { focusPanel.setFocus(true); setWidget(outer); - - // Asynchronously retrieve the tags defined by this user. - DeferredCommand.addCommand(new Command() { - - @Override - public void execute() { -// updateTags(); - } - }); } private VerticalPanel createGeneralPanel() { @@ -188,7 +186,7 @@ public class FilePropertiesDialog extends AbstractPropertiesDialog { generalTable.setText(1, 0, "Folder"); generalTable.setText(2, 0, "Owner"); generalTable.setText(3, 0, "Last modified"); -// generalTable.setText(4, 0, "Tags"); + generalTable.setText(4, 0, "Tags"); name.setWidth("100%"); name.setText(file.getName()); @@ -202,31 +200,26 @@ public class FilePropertiesDialog extends AbstractPropertiesDialog { final DateTimeFormat formatter = DateTimeFormat.getFormat("d/M/yyyy h:mm a"); generalTable.setText(3, 1, formatter.format(file.getLastModified())); - // Get the tags. -// StringBuffer tagsBuffer = new StringBuffer(); -// Iterator i = file.getTags().iterator(); -// while (i.hasNext()) { -// String tag = (String) i.next(); -// tagsBuffer.append(tag).append(", "); -// } -// if (tagsBuffer.length() > 1) -// tagsBuffer.delete(tagsBuffer.length() - 2, tagsBuffer.length() - 1); -// initialTagText = tagsBuffer.toString(); -// tags.setWidth("100%"); -// tags.getElement().setId("filePropertiesDialog.textBox.tags"); -// tags.setText(initialTagText); -// generalTable.setWidget(4, 1, tags); + StringBuffer tagsBuffer = new StringBuffer(); + for (String t : file.getTags()) + tagsBuffer.append(t).append(", "); + if (tagsBuffer.length() > 1) + tagsBuffer.delete(tagsBuffer.length() - 2, tagsBuffer.length() - 1); + initialTagText = tagsBuffer.toString(); + tags.setWidth("100%"); + tags.setText(initialTagText); + generalTable.setWidget(4, 1, tags); generalTable.getFlexCellFormatter().setStyleName(0, 0, "props-labels"); generalTable.getFlexCellFormatter().setStyleName(1, 0, "props-labels"); generalTable.getFlexCellFormatter().setStyleName(2, 0, "props-labels"); generalTable.getFlexCellFormatter().setStyleName(3, 0, "props-labels"); -// generalTable.getFlexCellFormatter().setStyleName(4, 0, "props-labels"); + generalTable.getFlexCellFormatter().setStyleName(4, 0, "props-labels"); generalTable.getFlexCellFormatter().setStyleName(0, 1, "props-values"); generalTable.getFlexCellFormatter().setStyleName(1, 1, "props-values"); generalTable.getFlexCellFormatter().setStyleName(2, 1, "props-values"); generalTable.getFlexCellFormatter().setStyleName(3, 1, "props-values"); -// generalTable.getFlexCellFormatter().setStyleName(4, 1, "props-values"); + generalTable.getFlexCellFormatter().setStyleName(4, 1, "props-values"); generalTable.setCellSpacing(4); generalPanel.add(generalTable); @@ -234,6 +227,28 @@ public class FilePropertiesDialog extends AbstractPropertiesDialog { DisclosurePanel allTags = new DisclosurePanel("All tags"); allTagsContent = new FlowPanel(); allTagsContent.setWidth("100%"); + for (Tag t : app.getAllTags()) { + final Anchor tagAnchor = new Anchor(t.getName(), false); + tagAnchor.addStyleName("pithos-tag"); + allTagsContent.add(tagAnchor); + Label separator = new Label(", "); + separator.addStyleName("pithos-tag"); + allTagsContent.add(separator); + tagAnchor.addClickHandler(new ClickHandler() { + + @Override + public void onClick(ClickEvent event) { + String existing = tags.getText().trim(); + if (MULTIPLE_VALUES_TEXT.equals(existing)) + existing = ""; + String newTag = tagAnchor.getText().trim(); + // insert the new tag only if it is not in the list + // already + if (existing.indexOf(newTag) == -1) + tags.setText(existing + (existing.length() > 0 ? ", " : "") + newTag); + } + }); + } allTags.setContent(allTagsContent); generalPanel.add(allTags); generalPanel.setSpacing(4); @@ -389,8 +404,8 @@ public class FilePropertiesDialog extends AbstractPropertiesDialog { // permList.updatePermissionsAccordingToInput(); // Set perms = permList.getPermissions(); // JSONObject json = new JSONObject(); - if (!name.getText().equals(file.getName())) { - newFilename = name.getText(); + if (!name.getText().trim().equals(file.getName())) { + newFilename = name.getText().trim(); // json.put("name", new JSONString(newFilename)); } // if (versioned.getValue() != file.isVersioned()) @@ -418,28 +433,44 @@ public class FilePropertiesDialog extends AbstractPropertiesDialog { // } // json.put("permissions", perma); // } -// JSONArray taga = new JSONArray(); -// i = 0; -// if (!tags.getText().equals(initialTagText)) { -// String[] tagset = tags.getText().split(","); -// for (String t : tagset) { -// JSONString to = new JSONString(t); -// taga.set(i, to); -// i++; -// } -// json.put("tags", taga); -// } + String[] tagset = null; + if (!tags.getText().equals(initialTagText)) + tagset = tags.getText().split(","); // String jsonString = json.toString(); // if(jsonString.equals("{}")){ // GWT.log("NO CHANGES", null); // return; // } - final String newFilenameFinal = newFilename; + final String[] newTags = tagset; + + if (newFilename != null) { + final String path = app.getApiPath() + app.getUsername() + file.getParent().getUri() + "/" + newFilename; + PutRequest updateFile = new PutRequest(path) { + @Override + public void onSuccess(Resource result) { + if (newTags != null) + updateMetaData(path + "?update=", newTags); + else + app.updateFolder(file.getParent()); + } + + @Override + public void onError(Throwable t) { + GWT.log("", t); + app.displayError("System error modifying file:" + t.getMessage()); + } + }; + updateFile.setHeader("X-Auth-Token", app.getToken()); + updateFile.setHeader("X-Move-From", file.getUri()); + updateFile.setHeader("Content-Type", file.getContentType()); + Scheduler.get().scheduleDeferred(updateFile); + } + else if (newTags != null) + updateMetaData(app.getApiPath() + app.getUsername() + file.getUri() + "?update=", newTags); + } - if (newFilename == null) - return; - String path = app.getApiPath() + app.getUsername() + file.getParent().getUri() + "/" + newFilename; - PutRequest updateFile = new PutRequest(path) { + private void updateMetaData(String path, String[] newTags) { + PostRequest updateFile = new PostRequest(path) { @Override public void onSuccess(Resource result) { app.updateFolder(file.getParent()); @@ -452,10 +483,10 @@ public class FilePropertiesDialog extends AbstractPropertiesDialog { } }; updateFile.setHeader("X-Auth-Token", app.getToken()); - updateFile.setHeader("X-Move-From", file.getUri()); - updateFile.setHeader("Content-Type", file.getContentType()); + for (String t : newTags) + updateFile.setHeader("X-Object-Meta-" + t.trim(), "true"); Scheduler.get().scheduleDeferred(updateFile); - } + } private void removeAllOldVersions() { JSONObject json = new JSONObject(); diff --git a/web_client/src/gr/grnet/pithos/web/client/Pithos.java b/web_client/src/gr/grnet/pithos/web/client/Pithos.java index 9898ccc..7d93af1 100644 --- a/web_client/src/gr/grnet/pithos/web/client/Pithos.java +++ b/web_client/src/gr/grnet/pithos/web/client/Pithos.java @@ -74,6 +74,7 @@ import gr.grnet.pithos.web.client.tagtree.TagTreeView; import gr.grnet.pithos.web.client.tagtree.TagTreeViewModel; import java.util.ArrayList; import java.util.Arrays; +import java.util.Collection; import java.util.Date; import java.util.HashMap; import java.util.Iterator; @@ -141,7 +142,17 @@ public class Pithos implements EntryPoint, ResizeHandler { } public void updateTags() { - tagTreeViewModel.initialize(account); + tagTreeViewModel.initialize(getAllTags()); + } + + public List getAllTags() { + List tagList = new ArrayList(); + for (Folder f : account.getContainers()) { + for (String t : f.getTags()) { + tagList.add(new Tag(t)); + } + } + return tagList; } /** @@ -461,7 +472,7 @@ public class Pithos implements EntryPoint, ResizeHandler { // Window.Location.assign(GWT.getModuleBaseURL() + conf.loginUrl() + "?next=" + Window.Location.getHref()); Cookies.setCookie(conf.authCookie(), "test" + conf.cookieSeparator() + "0000"); - Window.Location.assign(GWT.getModuleBaseURL() + "Pithos.html"); + Window.Location.assign(GWT.getModuleBaseURL() + "pithos.html"); } private void fetchAccount() { diff --git a/web_client/src/gr/grnet/pithos/web/client/foldertree/File.java b/web_client/src/gr/grnet/pithos/web/client/foldertree/File.java index 9a17ba8..a3ce501 100644 --- a/web_client/src/gr/grnet/pithos/web/client/foldertree/File.java +++ b/web_client/src/gr/grnet/pithos/web/client/foldertree/File.java @@ -35,6 +35,7 @@ package gr.grnet.pithos.web.client.foldertree; +import com.google.gwt.http.client.Header; import com.google.gwt.http.client.Response; import com.google.gwt.i18n.client.DateTimeFormat; import com.google.gwt.i18n.client.DateTimeFormat.PredefinedFormat; @@ -42,7 +43,11 @@ import com.google.gwt.i18n.client.NumberFormat; import com.google.gwt.json.client.JSONObject; import com.google.gwt.json.client.JSONParser; import com.google.gwt.json.client.JSONValue; +import java.io.StringWriter; +import java.security.Key; import java.util.Date; +import java.util.HashSet; +import java.util.Set; public class File extends Resource { private String name; @@ -71,6 +76,8 @@ public class File extends Resource { private Folder parent; + private Set tags = new HashSet(); + public String getContentType() { return contentType; } @@ -149,6 +156,10 @@ public class File extends Resource { modifiedBy = unmarshallString(o, "modified_by"); versionTimestamp = unmarshallDate(o, "version_timestamp"); this.container = container; + + for (String key : o.keySet()) + if (key.startsWith("x_object_meta_") && !key.equals("x_object_meta_trash")) + tags.add(key.substring("x_object_meta_".length()).trim().toLowerCase()); } public boolean equals(Object other) { @@ -173,6 +184,12 @@ public class File extends Resource { } private void populate(Response response) { + for (Header h : response.getHeaders()) { + String header = h.getName(); + if (header.startsWith("X-Object-Meta-") && !header.equals("X-Object-Meta-Trash")) + tags.add(header.substring("X-Object-Meta-".length()).trim().toLowerCase()); + + } String header = response.getHeader("X-Object-Meta-Trash"); if (header != null) inTrash = Boolean.valueOf(header); @@ -186,4 +203,8 @@ public class File extends Resource { public Folder getParent() { return parent; } + + public Set getTags() { + return tags; + } } diff --git a/web_client/src/gr/grnet/pithos/web/client/foldertree/Folder.java b/web_client/src/gr/grnet/pithos/web/client/foldertree/Folder.java index 2998336..7c89ab6 100644 --- a/web_client/src/gr/grnet/pithos/web/client/foldertree/Folder.java +++ b/web_client/src/gr/grnet/pithos/web/client/foldertree/Folder.java @@ -142,14 +142,10 @@ public class Folder extends Resource { inTrash = true; header = response.getHeader("X-Container-Object-Meta"); - if (header != null && header.length() > 2) { - String tagStr = header.substring(1, header.length() - 1); - while (tagStr.indexOf(",") > -1) { - String tag = tagStr.substring(2, tagStr.indexOf(",") - 1); - tags.add(tag); - tagStr = tagStr.substring(tagStr.indexOf(",") + 1).trim(); + if (header != null && header.length() > 0) { + for (String t : header.split(",")) { + tags.add(t.toLowerCase().trim()); } - tags.add(tagStr.substring(2, tagStr.length() - 1)); } subfolders.clear(); //This is necessary in case we update a pre-existing Folder so that stale subfolders won't show up diff --git a/web_client/src/gr/grnet/pithos/web/client/tagtree/TagTreeViewModel.java b/web_client/src/gr/grnet/pithos/web/client/tagtree/TagTreeViewModel.java index c74efbd..e0a6bcb 100644 --- a/web_client/src/gr/grnet/pithos/web/client/tagtree/TagTreeViewModel.java +++ b/web_client/src/gr/grnet/pithos/web/client/tagtree/TagTreeViewModel.java @@ -203,12 +203,8 @@ public class TagTreeViewModel implements TreeViewModel { } } - public void initialize(AccountResource account) { - List tagList = tagDataProvider.getList(); - for (Folder f : account.getContainers()) { - for (String t : f.getTags()) - tagList.add(new Tag(t)); - } + public void initialize(List allTags) { + tagDataProvider.getList().addAll(allTags); rootDataProvider.getList().add("Tags"); } }