changeset 887:6a27949c7022

Issue234/266: Added feature for duplicating projects. flys-client/trunk@2721 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Raimund Renkert <raimund.renkert@intevation.de>
date Tue, 13 Sep 2011 16:51:26 +0000
parents 2161d3acc83f
children d6b88f8f88dd
files flys-client/ChangeLog flys-client/src/main/java/de/intevation/flys/client/client/FLYSConstants.java flys-client/src/main/java/de/intevation/flys/client/client/FLYSConstants.properties flys-client/src/main/java/de/intevation/flys/client/client/FLYSConstants_de.properties flys-client/src/main/java/de/intevation/flys/client/client/FLYSConstants_en.properties flys-client/src/main/java/de/intevation/flys/client/client/ui/ProjectList.java
diffstat 6 files changed, 180 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/flys-client/ChangeLog	Tue Sep 13 12:47:54 2011 +0000
+++ b/flys-client/ChangeLog	Tue Sep 13 16:51:26 2011 +0000
@@ -1,3 +1,16 @@
+2011-09-13  Raimund Renkert <raimund.renkert@intevation.de>
+
+	Issue234/266
+
+	* src/main/java/de/intevation/flys/client/client/ui/ProjectList.java:
+	  Added feature for duplicating projects.
+
+	* src/main/java/de/intevation/flys/client/client/FLYSConstants_en.properties,
+	  src/main/java/de/intevation/flys/client/client/FLYSConstants.java,
+	  src/main/java/de/intevation/flys/client/client/FLYSConstants.properties,
+	  src/main/java/de/intevation/flys/client/client/FLYSConstants_de.properties:
+	  Added i18n string for context menu and project name.
+
 2011-09-13  Raimund Renkert <raimund.renkert@intevation.de>
 
 	Issue239
--- a/flys-client/src/main/java/de/intevation/flys/client/client/FLYSConstants.java	Tue Sep 13 12:47:54 2011 +0000
+++ b/flys-client/src/main/java/de/intevation/flys/client/client/FLYSConstants.java	Tue Sep 13 16:51:26 2011 +0000
@@ -26,6 +26,10 @@
 
     String rename_project();
 
+    String clone_project();
+
+    String copy_of ();
+
     String manage_projects();
 
     String favorite_tooltip();
--- a/flys-client/src/main/java/de/intevation/flys/client/client/FLYSConstants.properties	Tue Sep 13 12:47:54 2011 +0000
+++ b/flys-client/src/main/java/de/intevation/flys/client/client/FLYSConstants.properties	Tue Sep 13 16:51:26 2011 +0000
@@ -7,6 +7,8 @@
 open_project = Open Project
 delete_project = Delete Project
 rename_project = Rename Project
+clone_project = Clone Project
+copy_of = Copy
 manage_projects = Manage Projects
 favorite_tooltip = Permanently store?
 favorite_tooltip_meaning = Golden star: stored
--- a/flys-client/src/main/java/de/intevation/flys/client/client/FLYSConstants_de.properties	Tue Sep 13 12:47:54 2011 +0000
+++ b/flys-client/src/main/java/de/intevation/flys/client/client/FLYSConstants_de.properties	Tue Sep 13 16:51:26 2011 +0000
@@ -7,6 +7,8 @@
 open_project = Projekt \u00f6ffnen
 delete_project = Projekt l\u00f6schen
 rename_project = Projekt umbenennen
+clone_project = Projekt duplizieren
+copy_of = Kopie
 manage_projects = Projekte verwalten
 favorite_tooltip = Dauerhaft speichern?
 favorite_tooltip_meaning = Goldener Stern: gespeichert
--- a/flys-client/src/main/java/de/intevation/flys/client/client/FLYSConstants_en.properties	Tue Sep 13 12:47:54 2011 +0000
+++ b/flys-client/src/main/java/de/intevation/flys/client/client/FLYSConstants_en.properties	Tue Sep 13 16:51:26 2011 +0000
@@ -7,6 +7,8 @@
 open_project = Open Project
 delete_project = Delete Project
 rename_project = Rename Project
+clone_project = Copy Project
+copy_of = Copy
 manage_projects = Manage Projects
 favorite_tooltip = Permanently store?
 favorite_tooltip_meaning = Golden star: stored
--- a/flys-client/src/main/java/de/intevation/flys/client/client/ui/ProjectList.java	Tue Sep 13 12:47:54 2011 +0000
+++ b/flys-client/src/main/java/de/intevation/flys/client/client/ui/ProjectList.java	Tue Sep 13 16:51:26 2011 +0000
@@ -12,8 +12,6 @@
 import com.google.gwt.user.client.rpc.AsyncCallback;
 
 import com.smartgwt.client.data.Criteria;
-import de.intevation.flys.client.client.event.FilterHandler;
-import de.intevation.flys.client.client.event.StringFilterEvent;
 import com.smartgwt.client.types.Alignment;
 import com.smartgwt.client.types.ListGridEditEvent;
 import com.smartgwt.client.types.ListGridFieldType;
@@ -48,12 +46,19 @@
 import de.intevation.flys.client.shared.model.Collection;
 import de.intevation.flys.client.shared.model.CollectionRecord;
 import de.intevation.flys.client.shared.model.User;
+import de.intevation.flys.client.shared.model.Artifact;
+import de.intevation.flys.client.shared.model.Recommendation;
+
+import de.intevation.flys.client.client.event.FilterHandler;
+import de.intevation.flys.client.client.event.StringFilterEvent;
 
 import de.intevation.flys.client.client.Config;
 import de.intevation.flys.client.client.FLYS;
 import de.intevation.flys.client.client.FLYSConstants;
 import de.intevation.flys.client.client.event.CollectionChangeEvent;
 import de.intevation.flys.client.client.event.CollectionChangeHandler;
+import de.intevation.flys.client.client.services.ArtifactService;
+import de.intevation.flys.client.client.services.ArtifactServiceAsync;
 import de.intevation.flys.client.client.services.DeleteCollectionService;
 import de.intevation.flys.client.client.services.DeleteCollectionServiceAsync;
 import de.intevation.flys.client.client.services.SetCollectionNameService;
@@ -62,6 +67,12 @@
 import de.intevation.flys.client.client.services.SetCollectionTTLServiceAsync;
 import de.intevation.flys.client.client.services.UserCollectionsService;
 import de.intevation.flys.client.client.services.UserCollectionsServiceAsync;
+import de.intevation.flys.client.client.services.DescribeCollectionService;
+import de.intevation.flys.client.client.services.DescribeCollectionServiceAsync;
+import de.intevation.flys.client.client.services.AddArtifactService;
+import de.intevation.flys.client.client.services.AddArtifactServiceAsync;
+import de.intevation.flys.client.client.services.CreateCollectionService;
+import de.intevation.flys.client.client.services.CreateCollectionServiceAsync;
 
 
 /**
@@ -110,6 +121,22 @@
     protected DeleteCollectionServiceAsync deleteService =
         GWT.create(DeleteCollectionService.class);
 
+    /** The DescribeCollectionService used to update the existing collection. */
+    protected DescribeCollectionServiceAsync describeCollectionService =
+        GWT.create(DescribeCollectionService.class);
+
+    /** The ArtifactService used to communicate with the Artifact server. */
+    protected ArtifactServiceAsync createArtifactService =
+        GWT.create(ArtifactService.class);
+
+    /** The ArtifactService used to communicate with the Artifact server. */
+    protected CreateCollectionServiceAsync createCollectionService =
+        GWT.create(CreateCollectionService.class);
+
+    /** The AddArtifactService used to add an artifact to a collection. */
+    protected AddArtifactServiceAsync addArtifactService =
+        GWT.create(AddArtifactService.class);
+
     /** A pointer to the FLYS instance.*/
     protected FLYS flys;
 
@@ -125,6 +152,9 @@
     /** The collections visible in the grid.*/
     protected List<Collection> filteredCollections;
 
+    /** The collection to clone*/
+    protected Collection cloneCollection;
+
     /**
      * The default constructor that creates a new ProjectList for a specific
      * user.
@@ -277,8 +307,16 @@
             }
         });
 
+        MenuItem clone = new MenuItem(messages.clone_project());
+        clone.addClickHandler(new ClickHandler() {
+            public void onClick(MenuItemClickEvent evt) {
+                cloneProject(record.getCollection());
+            }
+        });
+
         menu.addItem(open);
         menu.addItem(rename);
+        menu.addItem(clone);
         menu.addItem(new MenuItemSeparator());
         menu.addItem(del);
 
@@ -680,5 +718,122 @@
 
         return fav;
     }
+
+
+    protected void cloneProject(Collection c) {
+        Config config = Config.getInstance();
+        String url    = config.getServerUrl();
+        String locale = config.getLocale();
+
+        cloneCollection = c;
+
+        describeCollectionService.describe(c.identifier(), url, locale,
+            new AsyncCallback<Collection>() {
+                public void onFailure(Throwable caught) {
+                    GWT.log("Could not DESCRIBE collection.");
+                    SC.warn(messages.getString(caught.getMessage()));
+                }
+
+
+                public void onSuccess(Collection newCollection) {
+                    GWT.log("Successfully DESCRIBED collection.");
+                    String uuid = getMasterArtifact(newCollection);
+                    cloneArtifact(uuid);
+                }
+            }
+        );
+    }
+
+
+    protected String getMasterArtifact(Collection newCollection) {
+        String uuid = newCollection.getItem(0).identifier();
+        // The master artifact uuid.
+        return uuid;
+    }
+
+
+    protected void cloneArtifact(String uuid) {
+        Config config               = Config.getInstance();
+        final String url            = config.getServerUrl();
+        final String locale         = config.getLocale();
+
+        Recommendation recommendation = new Recommendation(
+            "winfo",
+            null,
+            uuid,
+            null);
+
+        String factory = recommendation.getFactory();
+        createArtifactService.create(
+            url, locale, factory, recommendation,
+            new AsyncCallback<Artifact>() {
+                public void onFailure(Throwable caught) {
+                    GWT.log("Error loading recommendations: " +
+                        caught.getMessage());
+                }
+
+                public void onSuccess(Artifact artifact) {
+                    GWT.log("Created new artifact: " + artifact.getUuid());
+                    createCollection(artifact);
+                }
+            }
+        );
+    }
+
+
+    protected void createCollection(final Artifact artifact) {
+        Config config        = Config.getInstance();
+        final String url     = config.getServerUrl();
+        final String locale  = config.getLocale();
+        final String ownerid = user.identifier();
+
+        createCollectionService.create(
+            url, locale, ownerid,
+            new AsyncCallback<Collection>() {
+                public void onFailure(Throwable caught) {
+                    GWT.log("Could not create the new collection.");
+                    SC.warn(messages.getString(caught.getMessage()));
+                }
+
+                public void onSuccess(Collection collection) {
+                    GWT.log("Successfully created a new collection.");
+                    addArtifactToCollection(artifact, collection);
+                }
+            }
+        );
+    }
+
+
+    protected void addArtifactToCollection(Artifact a, Collection c) {
+        Config config               = Config.getInstance();
+        final String url            = config.getServerUrl();
+        final String locale         = config.getLocale();
+
+        addArtifactService.add(
+            c, a, url, locale,
+            new AsyncCallback<Collection>() {
+                public void onFailure(Throwable caught) {
+                    GWT.log("An error occured while adding artifact.");
+                    SC.warn(messages.getString(caught.getMessage()));
+                }
+
+                public void onSuccess(Collection newColl) {
+                    String name = cloneCollection.getName();
+                    if(name == null || name.equals("")) {
+                        name = cloneCollection.identifier();
+                    }
+
+                    newColl.setName("(" + messages.copy_of() + ")" + name);
+
+                    updateCollectionName(newColl);
+                    if(cloneCollection.getTTL() == 0) {
+                        newColl.setTTL(0);
+                        updateCollectionTTL(newColl);
+                    }
+                    updateUserCollections();
+                }
+            }
+        );
+    }
 }
 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org