Author: ludovic
Date: 2008-02-15 01:08:54 +0100 (Fri, 15 Feb 2008)
New Revision: 7733

Modified:
   
xwiki-products/curriki/trunk/gwt/src/main/java/org/curriki/gwt/client/CurrikiService.java
   
xwiki-products/curriki/trunk/gwt/src/main/java/org/curriki/gwt/client/CurrikiServiceAsync.java
   
xwiki-products/curriki/trunk/gwt/src/main/java/org/curriki/gwt/client/MenuPanel.java
   
xwiki-products/curriki/trunk/gwt/src/main/java/org/curriki/gwt/client/editor/Editor.java
   
xwiki-products/curriki/trunk/gwt/src/main/java/org/curriki/gwt/client/widgets/currikiitem/CurrikiItemImpl.java
   
xwiki-products/curriki/trunk/gwt/src/main/java/org/curriki/gwt/client/widgets/moveasset/MoveAsset.java
   
xwiki-products/curriki/trunk/gwt/src/main/java/org/curriki/gwt/client/wizard/AddAssetWizard.java
   
xwiki-products/curriki/trunk/gwt/src/main/java/org/curriki/gwt/server/CurrikiServiceImpl.java
Log:
CURRIKI-1264 Added checking version of asset on remove/move/add to not desync 
asset ordering

Modified: 
xwiki-products/curriki/trunk/gwt/src/main/java/org/curriki/gwt/client/CurrikiService.java
===================================================================
--- 
xwiki-products/curriki/trunk/gwt/src/main/java/org/curriki/gwt/client/CurrikiService.java
   2008-02-14 18:18:12 UTC (rev 7732)
+++ 
xwiki-products/curriki/trunk/gwt/src/main/java/org/curriki/gwt/client/CurrikiService.java
   2008-02-15 00:08:54 UTC (rev 7733)
@@ -53,7 +53,6 @@
     public String createCollection(String space, String pageName, String 
pageTitle) throws XWikiGWTException;
     public Document createCollectionDocument(String space, String pageName, 
String pageTitle) throws XWikiGWTException;
 
-
     // Composite Assets and SubAssets
     public List getCompositeAsset(String compositeAssetPage) throws 
XWikiGWTException;
     public List removeSubAsset(String compositeAssetPage, long position) 
throws XWikiGWTException;
@@ -73,6 +72,9 @@
     // Zip Assets
     public List getFileTreeList(String pageName, String fileName) throws 
XWikiGWTException;
 
+    // Check version
+    public boolean checkVersion(String pageName, String version) throws 
XWikiGWTException;
+
     /**
      * Utility/Convinience class.
      * Use CurrikiService.App.getInstance() to access static instance of 
CurrikiServiceAsync

Modified: 
xwiki-products/curriki/trunk/gwt/src/main/java/org/curriki/gwt/client/CurrikiServiceAsync.java
===================================================================
--- 
xwiki-products/curriki/trunk/gwt/src/main/java/org/curriki/gwt/client/CurrikiServiceAsync.java
      2008-02-14 18:18:12 UTC (rev 7732)
+++ 
xwiki-products/curriki/trunk/gwt/src/main/java/org/curriki/gwt/client/CurrikiServiceAsync.java
      2008-02-15 00:08:54 UTC (rev 7733)
@@ -46,7 +46,7 @@
 
     void finalizeAssetCreation(String assetPage, String compositeAssetPage, 
long position, AsyncCallback async);
 
-    void updateViditalk(String fullName, String videoId, AsyncCallback async); 
+    void updateViditalk(String fullName, String videoId, AsyncCallback async);
 
     // Collections
     void isDefaultCollectionExists(String space, AsyncCallback async);
@@ -70,6 +70,7 @@
 
     // Lucene search
     void luceneSearch(String terms, int start, int nb, AsyncCallback async);
+
     void luceneSearch(String terms, int start, int nb, String sortBy, 
AsyncCallback async);
 
     // Templates
@@ -83,4 +84,7 @@
 
     // Zip Assets
     void getFileTreeList(String pageName, String fileName, AsyncCallback 
async);
+
+    // Check version
+    void checkVersion(String pageName, String version, AsyncCallback async);
 }

Modified: 
xwiki-products/curriki/trunk/gwt/src/main/java/org/curriki/gwt/client/MenuPanel.java
===================================================================
--- 
xwiki-products/curriki/trunk/gwt/src/main/java/org/curriki/gwt/client/MenuPanel.java
        2008-02-14 18:18:12 UTC (rev 7732)
+++ 
xwiki-products/curriki/trunk/gwt/src/main/java/org/curriki/gwt/client/MenuPanel.java
        2008-02-15 00:08:54 UTC (rev 7733)
@@ -28,6 +28,7 @@
 import com.xpn.xwiki.gwt.api.client.Document;
 import org.curriki.gwt.client.widgets.browseasset.AssetTreeItem;
 import org.curriki.gwt.client.widgets.browseasset.BrowseAsset;
+import org.curriki.gwt.client.widgets.moveasset.MoveModalBox;
 import org.curriki.gwt.client.pages.EditPage;
 import org.curriki.gwt.client.pages.AbstractPage;
 import org.curriki.gwt.client.editor.Editor;
@@ -197,7 +198,30 @@
                 return;
             }
 
-            Main.getSingleton().getEditor().launchInsertWizard();
+            final Editor editor =  Main.getSingleton().getEditor();
+            
CurrikiService.App.getInstance().checkVersion(editor.getCurrentAssetPageName(), 
editor.getCurrentAsset().getVersion(), new CurrikiAsyncCallback() {
+                public void onFailure(Throwable caught) {
+                    super.onFailure(caught);
+                    // The action failed but we want to reload anyway in case 
something happened
+                    editor.setCurrentAssetInvalid(true);
+                    editor.setTreeContentInvalid(true);
+                    editor.refreshState();
+                }
+
+                public void onSuccess(Object result) {
+                    super.onSuccess(result);
+
+                    if (!((Boolean) result).booleanValue()){
+                        
Window.alert(Main.getSingleton().getTranslator().getTranslation("checkversion.versionhaschanged"));
+                        editor.setCurrentAssetInvalid(true);
+                        editor.setTreeContentInvalid(true);
+                        editor.refreshState();
+                        return;
+                    }
+
+                    Main.getSingleton().getEditor().launchInsertWizard();
+                };
+            });
         }
     }
 

Modified: 
xwiki-products/curriki/trunk/gwt/src/main/java/org/curriki/gwt/client/editor/Editor.java
===================================================================
--- 
xwiki-products/curriki/trunk/gwt/src/main/java/org/curriki/gwt/client/editor/Editor.java
    2008-02-14 18:18:12 UTC (rev 7732)
+++ 
xwiki-products/curriki/trunk/gwt/src/main/java/org/curriki/gwt/client/editor/Editor.java
    2008-02-15 00:08:54 UTC (rev 7733)
@@ -458,7 +458,32 @@
     }
 
 
-    public void removeAsset(long index) {
+    public void removeAsset(final long index) {
+        CurrikiService.App.getInstance().checkVersion(currentAssetPageName, 
currentAsset.getVersion(), new CurrikiAsyncCallback() {
+            public void onFailure(Throwable caught) {
+                super.onFailure(caught);
+                // The action failed but we want to reload anyway in case 
something happened
+                setCurrentAssetInvalid(true);
+                setTreeContentInvalid(true);
+                refreshState();
+            }
+
+            public void onSuccess(Object result) {
+                super.onSuccess(result);
+
+                if (!((Boolean) result).booleanValue()){
+                    
Window.alert(Main.getSingleton().getTranslator().getTranslation("checkversion.versionhaschanged"));
+                    setCurrentAssetInvalid(true);
+                    setTreeContentInvalid(true);
+                    refreshState();
+                    return;
+                }
+                removeAsset2(index);
+            }
+        });
+    }
+
+    public void removeAsset2(final long index) {
         CurrikiService.App.getInstance().removeSubAsset(currentAssetPageName, 
index, new CurrikiAsyncCallback() {
             public void onFailure(Throwable caught) {
                 super.onFailure(caught);

Modified: 
xwiki-products/curriki/trunk/gwt/src/main/java/org/curriki/gwt/client/widgets/currikiitem/CurrikiItemImpl.java
===================================================================
--- 
xwiki-products/curriki/trunk/gwt/src/main/java/org/curriki/gwt/client/widgets/currikiitem/CurrikiItemImpl.java
      2008-02-14 18:18:12 UTC (rev 7732)
+++ 
xwiki-products/curriki/trunk/gwt/src/main/java/org/curriki/gwt/client/widgets/currikiitem/CurrikiItemImpl.java
      2008-02-15 00:08:54 UTC (rev 7733)
@@ -467,8 +467,30 @@
     }
 
     public void onMoveClick() {
-        MoveModalBox box = new 
MoveModalBox(Main.getSingleton().getEditor().getRootAssetPageName(), 
getItem().getDocumentFullName(), getParentAsset(), getIndex());
-        box.show();
+        final Editor editor =  Main.getSingleton().getEditor();
+        
CurrikiService.App.getInstance().checkVersion(editor.getCurrentAssetPageName(), 
editor.getCurrentAsset().getVersion(), new CurrikiAsyncCallback() {
+            public void onFailure(Throwable caught) {
+                super.onFailure(caught);
+                // The action failed but we want to reload anyway in case 
something happened
+                editor.setCurrentAssetInvalid(true);
+                editor.setTreeContentInvalid(true);
+                editor.refreshState();
+            }
+
+            public void onSuccess(Object result) {
+                super.onSuccess(result);
+
+                if (!((Boolean) result).booleanValue()){
+                    
Window.alert(Main.getSingleton().getTranslator().getTranslation("checkversion.versionhaschanged"));
+                    editor.setCurrentAssetInvalid(true);
+                    editor.setTreeContentInvalid(true);
+                    editor.refreshState();
+                    return;
+                }
+                MoveModalBox box = new 
MoveModalBox(Main.getSingleton().getEditor().getRootAssetPageName(), 
getItem().getDocumentFullName(), getParentAsset(), getIndex());
+                box.show();
+            };
+        });
     }
 
     public String getType() {

Modified: 
xwiki-products/curriki/trunk/gwt/src/main/java/org/curriki/gwt/client/widgets/moveasset/MoveAsset.java
===================================================================
--- 
xwiki-products/curriki/trunk/gwt/src/main/java/org/curriki/gwt/client/widgets/moveasset/MoveAsset.java
      2008-02-14 18:18:12 UTC (rev 7732)
+++ 
xwiki-products/curriki/trunk/gwt/src/main/java/org/curriki/gwt/client/widgets/moveasset/MoveAsset.java
      2008-02-15 00:08:54 UTC (rev 7733)
@@ -1,6 +1,7 @@
 package org.curriki.gwt.client.widgets.moveasset;
 
 import com.google.gwt.user.client.WindowResizeListener;
+import com.google.gwt.user.client.Window;
 import com.google.gwt.user.client.ui.TreeItem;
 import com.google.gwt.user.client.ui.TreeListener;
 import com.google.gwt.user.client.ui.Widget;
@@ -82,6 +83,7 @@
 
     }
 
+
     private void initListener(){
         addTreeListener(new TreeListener(){
             public void onTreeItemSelected(TreeItem item) {
@@ -99,36 +101,7 @@
                     */
                     final String newParent = 
((AssetTreeItem)parent).getPageName();
                     final boolean isNewParentDifferent = 
!fromParent.equals(newParent);
-                    CurrikiService.App.getInstance().moveAsset(assetName, 
fromParent, fromPosition, newParent, newPosition, new CurrikiAsyncCallback(){
-
-                        public void onSuccess(Object result) {
-                            super.onSuccess(result);
-                            // If parent has changed we need to reload the 
parent one
-                            // If the moved asset is a source asset then we 
need to select the source asset
-                            // If the moved asset is a folder then we need to 
select the parent folder
-                            Editor editor =  Main.getSingleton().getEditor();
-                            if (isNewParentDifferent) {
-                                // Parent has changed, switch to that new 
parent
-                                editor.setCurrentAssetPageName(newParent);
-                                // If it was not the asset selected then we 
will select the new parent asset
-                                // If not we don't need to change anything as 
the asset will be selected
-                                if 
(!editor.getSelectedDocumentName().equals(assetName)) {
-                                    editor.setSelectedDocumentName(newParent);
-                                }
-                            } else {
-                                // If the parent has not changed force the 
current asset reload
-                                editor.setCurrentAssetInvalid(true);
-                            }
-                            // The tree is invalid with a move. We need to 
reload it.
-                            editor.setTreeContentInvalid(true);
-                            // Let's launch the refresh
-                            editor.refreshState();
-
-                            if (parentDialog instanceof MoveModalBox){
-                                ((MoveModalBox)parentDialog).hide();
-                            }
-                        }
-                    });
+                    moveAsset(newPosition, newParent, isNewParentDifferent);
                     return ;
                 }
 
@@ -161,6 +134,40 @@
                 }                
             }
 
+            private void moveAsset(final long newPosition, final String 
newParent, final boolean newParentDifferent) {
+                            
CurrikiService.App.getInstance().moveAsset(assetName, fromParent, fromPosition, 
newParent, newPosition, new CurrikiAsyncCallback(){
+
+                                public void onSuccess(Object result) {
+                                    super.onSuccess(result);
+                                    // If parent has changed we need to reload 
the parent one
+                                    // If the moved asset is a source asset 
then we need to select the source asset
+                                    // If the moved asset is a folder then we 
need to select the parent folder
+                                    Editor editor =  
Main.getSingleton().getEditor();
+                                    if (newParentDifferent) {
+                                        // Parent has changed, switch to that 
new parent
+                                        
editor.setCurrentAssetPageName(newParent);
+                                        // If it was not the asset selected 
then we will select the new parent asset
+                                        // If not we don't need to change 
anything as the asset will be selected
+                                        if 
(!editor.getSelectedDocumentName().equals(assetName)) {
+                                            
editor.setSelectedDocumentName(newParent);
+                                        }
+                                    } else {
+                                        // If the parent has not changed force 
the current asset reload
+                                        editor.setCurrentAssetInvalid(true);
+                                    }
+                                    // The tree is invalid with a move. We 
need to reload it.
+                                    editor.setTreeContentInvalid(true);
+                                    // Let's launch the refresh
+                                    editor.refreshState();
+
+                                    if (parentDialog instanceof MoveModalBox){
+                                        ((MoveModalBox)parentDialog).hide();
+                                    }
+                                }
+                            });
+                        }
+
+
             public void onTreeItemStateChanged(TreeItem item) {
 
             }

Modified: 
xwiki-products/curriki/trunk/gwt/src/main/java/org/curriki/gwt/client/wizard/AddAssetWizard.java
===================================================================
--- 
xwiki-products/curriki/trunk/gwt/src/main/java/org/curriki/gwt/client/wizard/AddAssetWizard.java
    2008-02-14 18:18:12 UTC (rev 7732)
+++ 
xwiki-products/curriki/trunk/gwt/src/main/java/org/curriki/gwt/client/wizard/AddAssetWizard.java
    2008-02-15 00:08:54 UTC (rev 7733)
@@ -24,6 +24,7 @@
 import asquare.gwt.tk.client.ui.BasicPanel;
 import com.google.gwt.user.client.DOM;
 import com.google.gwt.user.client.Event;
+import com.google.gwt.user.client.Window;
 import com.google.gwt.user.client.rpc.AsyncCallback;
 import com.google.gwt.user.client.ui.*;
 import com.xpn.xwiki.gwt.api.client.Document;
@@ -162,7 +163,34 @@
     }
 
     private void finishWizard() {
-        // finishWizard() should only be called when a new asset is created 
(does a rename from AssetTemp)
+              final Editor editor =  Main.getSingleton().getEditor();
+            
CurrikiService.App.getInstance().checkVersion(editor.getCurrentAssetPageName(), 
editor.getCurrentAsset().getVersion(), new CurrikiAsyncCallback() {
+                public void onFailure(Throwable caught) {
+                    super.onFailure(caught);
+                    // The action failed but we want to reload anyway in case 
something happened
+                    editor.setCurrentAssetInvalid(true);
+                    editor.setTreeContentInvalid(true);
+                    editor.refreshState();
+                }
+
+                public void onSuccess(Object result) {
+                    super.onSuccess(result);
+
+                    if (!((Boolean) result).booleanValue()){
+                        
Window.alert(Main.getSingleton().getTranslator().getTranslation("checkversion.versionhaschanged"));
+                        editor.setCurrentAssetInvalid(true);
+                        editor.setTreeContentInvalid(true);
+                        editor.refreshState();
+                        return;
+                    }
+
+                    finishWizard2();
+                };
+            });
+    }
+
+    private void finishWizard2() {
+           // finishWizard() should only be called when a new asset is created 
(does a rename from AssetTemp)
         
CurrikiService.App.getInstance().finalizeAssetCreation(newDoc.getFullName(),
                 Main.getSingleton().getEditor().getCurrentAssetPageName(), 
EditPage.getSingleton().getSelectedIndex() + 1,
                 new CurrikiAsyncCallback(){

Modified: 
xwiki-products/curriki/trunk/gwt/src/main/java/org/curriki/gwt/server/CurrikiServiceImpl.java
===================================================================
--- 
xwiki-products/curriki/trunk/gwt/src/main/java/org/curriki/gwt/server/CurrikiServiceImpl.java
       2008-02-14 18:18:12 UTC (rev 7732)
+++ 
xwiki-products/curriki/trunk/gwt/src/main/java/org/curriki/gwt/server/CurrikiServiceImpl.java
       2008-02-15 00:08:54 UTC (rev 7733)
@@ -643,7 +643,6 @@
                     break;
                 }
             }
-
             return getCompositeAsset(compositeAssetPage);
 
         } catch (Exception e) {
@@ -1092,6 +1091,16 @@
         }
     }
 
+    // Check version
+    public boolean checkVersion(String pageName, String version) throws 
XWikiGWTException {
+        try {
+            XWikiContext context = getXWikiContext();
+            return version.equals(context.getWiki().getDocument(pageName, 
context).getVersion());       
+        } catch (Exception e) {
+            throw getXWikiGWTException(e);
+        }
+    }
+
     private boolean replaceSubAsset(XWikiDocument compositeAssetDoc, String 
previousAssetPageName, String newAssetPageName, long position) throws 
XWikiGWTException {
         List objs = compositeAssetDoc.getObjects(Constants.SUBASSET_CLASS);
         if (objs==null)

_______________________________________________
notifications mailing list
[email protected]
http://lists.xwiki.org/mailman/listinfo/notifications

Reply via email to