r1461 - in xwiki-apps/gelc/gelcv1/trunk/gelcplugins/src: main/java/org/gelc/xwiki/plugins/assets main/java/org/gelc/xwiki/plugins/mdfw test/java/org/gelc/xwiki/plugins/assets

Jeremi Joslin jeremi at users.forge.objectweb.org
Tue Oct 24 18:41:19 CEST 2006


Author: jeremi
Date: 2006-10-24 18:41:18 +0200 (Tue, 24 Oct 2006)
New Revision: 1461

Modified:
   xwiki-apps/gelc/gelcv1/trunk/gelcplugins/src/main/java/org/gelc/xwiki/plugins/assets/AssetConstant.java
   xwiki-apps/gelc/gelcv1/trunk/gelcplugins/src/main/java/org/gelc/xwiki/plugins/assets/AssetManagerPlugin.java
   xwiki-apps/gelc/gelcv1/trunk/gelcplugins/src/main/java/org/gelc/xwiki/plugins/assets/AssetManagerPluginApi.java
   xwiki-apps/gelc/gelcv1/trunk/gelcplugins/src/main/java/org/gelc/xwiki/plugins/mdfw/MetaDataFrameworkPlugin.java
   xwiki-apps/gelc/gelcv1/trunk/gelcplugins/src/test/java/org/gelc/xwiki/plugins/assets/AssetManagerPluginTest.java
Log:
add the moving and validation the assets

Modified: xwiki-apps/gelc/gelcv1/trunk/gelcplugins/src/main/java/org/gelc/xwiki/plugins/assets/AssetConstant.java
===================================================================
--- xwiki-apps/gelc/gelcv1/trunk/gelcplugins/src/main/java/org/gelc/xwiki/plugins/assets/AssetConstant.java	2006-10-24 16:36:39 UTC (rev 1460)
+++ xwiki-apps/gelc/gelcv1/trunk/gelcplugins/src/main/java/org/gelc/xwiki/plugins/assets/AssetConstant.java	2006-10-24 16:41:18 UTC (rev 1461)
@@ -33,6 +33,7 @@
 
     public final static String ASSET_TEMPORARY_SPACE = "AssetTemp";
 
+    public final static String COLLECTION_PREFIX = "Coll_";
 
     /**
      *     Class FrameworkItemAssetClass
@@ -55,6 +56,7 @@
     public static final String ASSET_ITEM_AGGREGATION_LEVEL = "aggregation_level";
     public static final String ASSET_ITEM_AGGREGATION_LEVEL_VALUES = "Asset|Material|Lecture|Unit|Course"; 
     public static final String ASSET_ITEM_CATEGORY = "category";
+    public static final String ASSET_ITEM_FRAMEWORK_ITEMS = "fw_items";
 
     public static final String ASSET_ITEM_STATUS = "status";
     public static final String ASSET_ITEM_STATUS_VALUES = "Draft|Final|Revised|Unavailable";
@@ -85,10 +87,10 @@
     public static final String ASSET_LICENCE_CLASS_FULLNAME = "XWiki.AssetLicenseClass";
     public static final String ASSET_LICENCE_CLASS_NAME = "AssetLicenseClass";
 
-        public static final String ASSET_LICENCE_ITEM_RIGHTS_HOLDER = "rightsHolder";
-        public static final String ASSET_LICENCE_ITEM_EXTERNAL_RIGHTS_HOLDER = "externalRightsHolder";
-        public static final String ASSET_LICENCE_ITEM_LICENCE_TYPE = "licenseType";
-        public static final String ASSET_LICENCE_ITEM_EXPIRY_DATE = "expiryDate";
+    public static final String ASSET_LICENCE_ITEM_RIGHTS_HOLDER = "rightsHolder";
+    public static final String ASSET_LICENCE_ITEM_EXTERNAL_RIGHTS_HOLDER = "externalRightsHolder";
+    public static final String ASSET_LICENCE_ITEM_LICENCE_TYPE = "licenseType";
+    public static final String ASSET_LICENCE_ITEM_EXPIRY_DATE = "expiryDate";
 
 
 

Modified: xwiki-apps/gelc/gelcv1/trunk/gelcplugins/src/main/java/org/gelc/xwiki/plugins/assets/AssetManagerPlugin.java
===================================================================
--- xwiki-apps/gelc/gelcv1/trunk/gelcplugins/src/main/java/org/gelc/xwiki/plugins/assets/AssetManagerPlugin.java	2006-10-24 16:36:39 UTC (rev 1460)
+++ xwiki-apps/gelc/gelcv1/trunk/gelcplugins/src/main/java/org/gelc/xwiki/plugins/assets/AssetManagerPlugin.java	2006-10-24 16:41:18 UTC (rev 1461)
@@ -26,11 +26,14 @@
 import com.xpn.xwiki.XWikiException;
 import com.xpn.xwiki.api.Api;
 import com.xpn.xwiki.api.Document;
+import com.xpn.xwiki.api.Object;
 import com.xpn.xwiki.doc.XWikiDocument;
 import com.xpn.xwiki.objects.classes.BaseClass;
+import com.xpn.xwiki.objects.classes.DBTreeListClass;
 import com.xpn.xwiki.plugin.XWikiDefaultPlugin;
 import com.xpn.xwiki.plugin.XWikiPluginInterface;
 import com.xpn.xwiki.web.XWikiRequest;
+import org.gelc.xwiki.plugins.framework.FrameworkConstant;
 import org.gelc.xwiki.plugins.mime.MimeTypePlugin;
 import org.gelc.xwiki.plugins.mime.MimeTypePluginAPI;
 
@@ -76,9 +79,95 @@
         Asset asset = (Asset) context.getWiki().getDocument(ASSET_TEMPORARY_SPACE, pageName, context).newDocument(Asset.class.getName(), context);
         asset.setTitle(assetName);
         asset.setCustomClass(Asset.class.getName());
+        asset.setContent("#includeForm(\"XWiki.AssetTemplate\")");
+        protectAssetPage(asset, context);
         return asset;
     }
 
+    public Asset publishAsset(Asset asset, XWikiContext context) throws XWikiException {
+        String space = getUserCollection(context);
+        if (!context.getWiki().exists(space + ".WebHome", context))
+            createCollection(getUserName(context), context);
+        return publishAsset(asset, getUserCollection(context), context);
+    }
+
+    public Asset publishAsset(Asset asset, String collection, XWikiContext context) throws XWikiException {
+        if (isComplet(asset, context) && asset.hasAccessLevel("edit") && hasPublishingRight(collection, context)){
+            String fullName = collection + "." + asset.getName();
+            context.getWiki().copyDocument(asset.getFullName(), fullName, context);
+ //           context.getWiki().deleteDocument(asset.getDocument(), context);
+            return (Asset) context.getWiki().getDocument(fullName, context).newDocument(context);
+        }
+        else
+            return null;
+    }
+
+    public boolean hasPublishingRight(String collection, XWikiContext context) throws XWikiException {
+        Document doc = context.getWiki().getDocument(collection, "WebHome", context).newDocument(context);
+        return doc.hasAccessLevel("edit");
+    }
+
+    private String getUserName(XWikiContext context) throws XWikiException {
+        String userName = context.getUser();
+        XWikiDocument doc = context.getWiki().getDocument(userName, context);
+        return doc.getName();
+    }
+
+    public String getUserCollection(XWikiContext context) throws XWikiException {
+        String userName = getUserName(context);
+        return getCollectionSpace(userName, context);
+    }
+
+    public String createCollection(String name, XWikiContext context) throws XWikiException {
+        String space = getCollectionSpace(context.getWiki().clearName(name, context), context);
+        if (context.getWiki().exists(space + ".WebHome", context))
+            return null;
+        Document doc = context.getWiki().getDocument(space + ".WebHome", context).newDocument(context);
+        doc.setContent("#includeForm(\"XWiki.CollectionTemplate\")");
+        doc.setTitle(name);
+        doc.save();
+        protectSpace(space, context);
+        return space;
+    }
+
+    public String getCollectionSpace(String name, XWikiContext context){
+        return COLLECTION_PREFIX + name;
+    }
+
+    private void protectPage(Document doc, XWikiContext context) throws XWikiException {
+        Object obj = doc.newObject("XWiki.XWikiRights");
+        doc.use(obj);
+        doc.set("groups", "XWiki.XWikiAdminGroup");
+        doc.set("levels", "edit");
+        doc.set("allow", 1);
+
+        obj = doc.newObject("XWiki.XWikiRights");
+        doc.use(obj);
+        doc.set("users", context.getUser());
+        doc.set("levels", "edit");
+        doc.set("allow", 1);
+    }
+
+    private void protectSpace(String spaceName, XWikiContext context) throws XWikiException {
+        Document doc = context.getWiki().getDocument(spaceName, "WebPreferences", context).newDocument(context);
+        Object obj = doc.newObject("XWiki.XWikiRights");
+        doc.use(obj);
+        doc.set("groups", "XWiki.XWikiAdminGroup");
+        doc.set("levels", "edit");
+        doc.set("allow", 1);
+
+        obj = doc.newObject("XWiki.XWikiRights");
+        doc.use(obj);
+        doc.set("users", context.getUser());
+        doc.set("levels", "edit");
+        doc.set("allow", 1);
+        doc.save();
+    }
+
+    private void protectAssetPage(Asset asset, XWikiContext context) throws XWikiException {
+        protectPage(asset, context);
+    }
+
     public Asset getTemporaryAssetDocument(String assetName, boolean create, XWikiContext context) throws XWikiException {
         XWikiDocument doc = context.getWiki().getDocument(ASSET_TEMPORARY_SPACE, assetName, context);
         if (doc.isNew() && create){
@@ -159,7 +248,7 @@
         else
             res.put(ASSET_STATUS_EXTERNAL_LINK, 1);
         res.put(ASSET_STATUS_ADDTIONAL_FRAMEWORK_SELECTED, 0);
-        if (getMasterFrameworkItems(asset, context).size() == 0)
+        if (getMasterFrameworkItem(asset, context) == null)
             res.put(ASSET_STATUS_FRAMEWORK_ITEM_SELECTED, 0);
         else
             res.put(ASSET_STATUS_FRAMEWORK_ITEM_SELECTED, 1);
@@ -227,10 +316,10 @@
 
         BaseClass bclass = doc.getxWikiClass();
         bclass.setName(ASSET_LICENCE_CLASS_FULLNAME);
-        needsUpdate |= bclass.addTextField(ASSET_LICENCE_ITEM_RIGHTS_HOLDER, "Right holder", 500);
+        needsUpdate |= bclass.addTextField(ASSET_LICENCE_ITEM_RIGHTS_HOLDER, "Right holder", 60);
         needsUpdate |= bclass.addDateField(ASSET_LICENCE_ITEM_EXPIRY_DATE, "Expiry date");
-        needsUpdate |= bclass.addTextField(ASSET_LICENCE_ITEM_EXTERNAL_RIGHTS_HOLDER, "External right holder", 500);
-        needsUpdate |= bclass.addTextField(ASSET_LICENCE_ITEM_LICENCE_TYPE, "Licence type", 500);
+        needsUpdate |= bclass.addTextField(ASSET_LICENCE_ITEM_EXTERNAL_RIGHTS_HOLDER, "External right holder", 60);
+        needsUpdate |= bclass.addTextField(ASSET_LICENCE_ITEM_LICENCE_TYPE, "Licence type", 60);
 
         String content = doc.getContent();
         if ((content==null)||(content.equals(""))) {
@@ -261,12 +350,16 @@
         BaseClass bclass = doc.getxWikiClass();
         bclass.setName(ASSET_CLASS_FULLNAME);
 
-        needsUpdate |= bclass.addTextField(ASSET_ITEM_TITLE, "title", 1000);
-        needsUpdate |= bclass.addTextAreaField(ASSET_ITEM_DESCRIPTION, "description", 80, 10);
+        needsUpdate |= bclass.addTextField(ASSET_ITEM_TITLE, "title", 60);
+        needsUpdate |= bclass.addTextAreaField(ASSET_ITEM_DESCRIPTION, "description", 60, 10);
         needsUpdate |= bclass.addStaticListField(ASSET_ITEM_KEYWORDS, "keywords", 5, true, "");
         needsUpdate |= bclass.addStaticListField(ASSET_ITEM_AGGREGATION_LEVEL, "Aggregation level", 5, false, ASSET_ITEM_AGGREGATION_LEVEL_VALUES);
         needsUpdate |= bclass.addStaticListField(ASSET_ITEM_STATUS, "Status", 5, false, ASSET_ITEM_STATUS_VALUES);
 
+        String hql = "select doc.fullName, doc.title, doc.parent from XWikiDocument as doc, BaseObject as obj where doc.fullName=obj.name and obj.className='" + FrameworkConstant.FRAMEWORK_CLASS_FULLNAME + "' order by doc.title";
+        needsUpdate |= bclass.addDBTreeListField(ASSET_ITEM_FRAMEWORK_ITEMS, "Framework Items", 10, true, hql);
+        ((DBTreeListClass)bclass.get(ASSET_ITEM_FRAMEWORK_ITEMS)).setPicker(true);        
+
         needsUpdate |= bclass.addStaticListField(ASSET_ITEM_LEARNING_RESOURCE_TYPE, "Learnign resource Type", ASSET_ITEM_LEARNING_RESOURCE_TYPE_VALUES);
         needsUpdate |= bclass.addStaticListField(ASSET_ITEM_DIFICULTY, "Dificulty", ASSET_ITEM_DIFICULTY_VALUES);
         needsUpdate |= bclass.addStaticListField(ASSET_ITEM_EDUCATIONAL_LEVEL, "Educational Level", ASSET_ITEM_EDUCATIONAL_LEVEL_VALUES);
@@ -301,7 +394,7 @@
 
         BaseClass bclass = doc.getxWikiClass();
         bclass.setName(EXTERNAL_ASSET_CLASS_FULLNAME);
-        needsUpdate |= bclass.addTextField(EXTERNAL_ASSET_LINK, "external Link", 200);
+        needsUpdate |= bclass.addTextField(EXTERNAL_ASSET_LINK, "external Link", 60);
 
         String content = doc.getContent();
         if ((content==null)||(content.equals(""))) {
@@ -314,28 +407,11 @@
     }
 
 
-    public boolean addFrameworkItem(Asset asset, String fullName, XWikiContext context) throws XWikiException {
-        List items = getMasterFrameworkItems(asset, context);
-        if (items.contains(fullName))
-            return false;
-        com.xpn.xwiki.api.Object obj = asset.newObject(FRAMEWORK_ASSET_CLASS_FULLNAME);
-        obj.set(CLASS_FRAMEWORK_ITEM, fullName);
-        return true;
+    public String getMasterFrameworkItem(Asset asset, XWikiContext context) {
+        asset.use(ASSET_CLASS_FULLNAME);
+        return (String) asset.get(ASSET_ITEM_FRAMEWORK_ITEMS);
     }
 
-    public List getMasterFrameworkItems(Asset asset, XWikiContext context) {
-        Vector v = asset.getObjects(FRAMEWORK_ASSET_CLASS_FULLNAME);
-        List items = new ArrayList();
-        Iterator it = v.iterator();
-        while(it.hasNext())
-        {
-            com.xpn.xwiki.api.Object obj = (com.xpn.xwiki.api.Object) it.next();
-            if(obj.get(CLASS_FRAMEWORK_ITEM) != null)
-                items.add(obj.get(CLASS_FRAMEWORK_ITEM));
-        }
-        return items;
-    }
-
     public List getExternalAsset(Asset asset, XWikiContext context) {
         Vector v = asset.getObjects(EXTERNAL_ASSET_CLASS_FULLNAME);
         List items = new ArrayList();
@@ -350,7 +426,7 @@
     }
 
     public boolean addExternalAsset(Asset asset, String link, XWikiContext context) throws XWikiException {
-        List items = getMasterFrameworkItems(asset, context);
+        List items = getExternalAsset(asset, context);
         if (items.contains(link))
             return false;
         com.xpn.xwiki.api.Object obj = asset.newObject(EXTERNAL_ASSET_CLASS_FULLNAME);
@@ -359,12 +435,6 @@
     }
 
     public String getTechnicalMetaDataClassName(Asset asset, XWikiContext context) throws XWikiException {
-        /* if (asset.getAttachmentList().size() == 0)
-            return null;
-        String mimeType = ((Attachment)asset.getAttachmentList().get(0)).getMimeType();
-        if (mimeType == null || mimeType.length() == 0){
-            return null;
-        }         */
         asset.use(ASSET_CLASS_FULLNAME);
         String category = (String) asset.get(ASSET_ITEM_CATEGORY);
         MimeTypePluginAPI mtmng = (MimeTypePluginAPI) context.getWiki().getPluginApi(MimeTypePlugin.PLUGIN_NAME, context);

Modified: xwiki-apps/gelc/gelcv1/trunk/gelcplugins/src/main/java/org/gelc/xwiki/plugins/assets/AssetManagerPluginApi.java
===================================================================
--- xwiki-apps/gelc/gelcv1/trunk/gelcplugins/src/main/java/org/gelc/xwiki/plugins/assets/AssetManagerPluginApi.java	2006-10-24 16:36:39 UTC (rev 1460)
+++ xwiki-apps/gelc/gelcv1/trunk/gelcplugins/src/main/java/org/gelc/xwiki/plugins/assets/AssetManagerPluginApi.java	2006-10-24 16:41:18 UTC (rev 1461)
@@ -84,14 +84,10 @@
 
     }
 
-    public boolean addFrameworkItem(Asset asset, String fullName) throws XWikiException {
-        return assetManagerPlugin.addFrameworkItem(asset, fullName, context);
+    public String getMasterFrameworkItem(Asset asset){
+        return assetManagerPlugin.getMasterFrameworkItem(asset, context);
     }
 
-    public List getMasterFrameworkItems(Asset asset){
-        return assetManagerPlugin.getMasterFrameworkItems(asset, context);
-    }
-
     public List getAdditionalFrameworkItems(){
         return null;
     }
@@ -115,4 +111,12 @@
     public String createOrUpdateAssetFromRequest() throws XWikiException {
         return assetManagerPlugin.createOrUpdateAssetFromRequest(context);
     }
+
+    public Asset publishAsset(Asset asset) throws XWikiException {
+        return assetManagerPlugin.publishAsset(asset, context);     
+    }
+
+     public Asset publishAsset(Asset asset, String collection) throws XWikiException {
+        return assetManagerPlugin.publishAsset(asset, collection, context);   
+     }
 }

Modified: xwiki-apps/gelc/gelcv1/trunk/gelcplugins/src/main/java/org/gelc/xwiki/plugins/mdfw/MetaDataFrameworkPlugin.java
===================================================================
--- xwiki-apps/gelc/gelcv1/trunk/gelcplugins/src/main/java/org/gelc/xwiki/plugins/mdfw/MetaDataFrameworkPlugin.java	2006-10-24 16:36:39 UTC (rev 1460)
+++ xwiki-apps/gelc/gelcv1/trunk/gelcplugins/src/main/java/org/gelc/xwiki/plugins/mdfw/MetaDataFrameworkPlugin.java	2006-10-24 16:41:18 UTC (rev 1461)
@@ -1,35 +1,49 @@
-package org.gelc.xwiki.plugins.mdfw;
-
-import com.xpn.xwiki.XWikiContext;
-import com.xpn.xwiki.api.Api;
-import com.xpn.xwiki.plugin.XWikiDefaultPlugin;
-import com.xpn.xwiki.plugin.XWikiPluginInterface;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-
-
-/**
- * Created for GELC (http://www.gelc.org)
- * User: ldubost
- * Date: 15 sept. 2006
- * Time: 13:22:07
- * Copyright (c) 2006-2007 GELC
- */
-public class MetaDataFrameworkPlugin  extends XWikiDefaultPlugin implements XWikiPluginInterface {
-    private static Log mLogger =
-            LogFactory.getFactory().getInstance(MetaDataFrameworkPlugin.class);
-
-
-    public MetaDataFrameworkPlugin(String name, String className, XWikiContext context) {
-        super(name, className, context);
-    }
-
-    public String getName() {
-        return "mdfw";
-    }
-
-    public Api getPluginApi(XWikiPluginInterface plugin, XWikiContext context) {
-        return new MetaDataFrameworkPluginAPI((MetaDataFrameworkPlugin) plugin, context);
-    }
-}
-
+/*
+ * Copyright 2006, XpertNet SARL, and individual contributors as indicated
+ * by the contributors.txt.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ *
+ * @author jeremi
+ */
+package org.gelc.xwiki.plugins.mdfw;
+
+import com.xpn.xwiki.XWikiContext;
+import com.xpn.xwiki.api.Api;
+import com.xpn.xwiki.plugin.XWikiDefaultPlugin;
+import com.xpn.xwiki.plugin.XWikiPluginInterface;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+
+public class MetaDataFrameworkPlugin  extends XWikiDefaultPlugin implements XWikiPluginInterface {
+    private static Log mLogger =
+            LogFactory.getFactory().getInstance(MetaDataFrameworkPlugin.class);
+
+
+    public MetaDataFrameworkPlugin(String name, String className, XWikiContext context) {
+        super(name, className, context);
+    }
+
+    public String getName() {
+        return "mdfw";
+    }
+
+    public Api getPluginApi(XWikiPluginInterface plugin, XWikiContext context) {
+        return new MetaDataFrameworkPluginAPI((MetaDataFrameworkPlugin) plugin, context);
+    }
+}
+

Modified: xwiki-apps/gelc/gelcv1/trunk/gelcplugins/src/test/java/org/gelc/xwiki/plugins/assets/AssetManagerPluginTest.java
===================================================================
--- xwiki-apps/gelc/gelcv1/trunk/gelcplugins/src/test/java/org/gelc/xwiki/plugins/assets/AssetManagerPluginTest.java	2006-10-24 16:36:39 UTC (rev 1460)
+++ xwiki-apps/gelc/gelcv1/trunk/gelcplugins/src/test/java/org/gelc/xwiki/plugins/assets/AssetManagerPluginTest.java	2006-10-24 16:41:18 UTC (rev 1461)
@@ -81,12 +81,10 @@
         FrameworkItem item = getFrameworkItem();
         assertNotNull(item);
 
-        amng.addFrameworkItem(asset, item.getFullName());
+        asset.set(AssetConstant.ASSET_ITEM_FRAMEWORK_ITEMS, item.getFullName());
 
-        List items = amng.getMasterFrameworkItems(asset);
-        assertNotNull(items);
-        assertEquals(1, items.size());
-        String itemName = (String) items.get(0);
+        String itemName = amng.getMasterFrameworkItem(asset);
+        assertNotNull(itemName);
         assertEquals(item.getFullName(), itemName);
 
         assertTrue(amng.getStatus(asset, AssetConstant.ASSET_STATUS_ATTACHEMENT));





More information about the Xwiki-notifications mailing list