Topic administration
authoridfx <idfx>
Tue, 30 Sep 2003 19:29:32 +0000 (19:29 +0000)
committeridfx <idfx>
Tue, 30 Sep 2003 19:29:32 +0000 (19:29 +0000)
etc/hibernate.cfg.xml
etc/struts-config-admin.xml
source/mir/core/ui/action/admin/TopicAction.java [new file with mode: 0755]

index 8dc63c7..78baefe 100755 (executable)
@@ -12,7 +12,7 @@
         <property name="connection.password"></property>
         <property name="connection.pool_size">10</property>
         <property name="statement_cache.size">100</property>
-        <property name="show_sql">false</property>
+        <property name="show_sql">true</property>
         <property name="use_outer_join">true</property>
         <property name="dialect">net.sf.hibernate.dialect.PostgreSQLDialect</property>
         
@@ -22,7 +22,9 @@
         <mapping resource="mir/core/model/Comment.hbm.xml"/>
         <mapping resource="mir/core/model/Content.hbm.xml"/>
         <mapping resource="mir/core/model/CommentStatus.hbm.xml"/>
+        <!--
         <mapping resource="mir/core/model/Feature.hbm.xml"/>
+        -->
         <mapping resource="mir/core/model/Language.hbm.xml"/>
         <mapping resource="mir/core/model/Media.hbm.xml"/>
         <mapping resource="mir/core/model/MediaFolder.hbm.xml"/>
@@ -30,6 +32,9 @@
         <mapping resource="mir/core/model/Message.hbm.xml"/>
         <mapping resource="mir/core/model/Rights.hbm.xml"/>
         <mapping resource="mir/core/model/Topic.hbm.xml"/>
+        <!--
+        <mapping resource="mir/core/model/TopicRich.hbm.xml"/>
+        -->
         <mapping resource="mir/core/model/WebdbUser.hbm.xml"/>
         <mapping resource="mir/core/model/UploadedMedia.hbm.xml"/>
         <mapping resource="mir/core/model/Image.hbm.xml"/>
index fe6fa38..06154f9 100755 (executable)
                <form-property name="cancel" type="java.lang.String"/>
                <form-property name="confirm" type="java.lang.String"/>
         </form-bean>
+        <form-bean dynamic="true" name="topicForm" type="org.apache.struts.action.DynaActionForm">
+               <form-property name="id" type="java.lang.Integer"/>
+               <form-property name="new" type="java.lang.Boolean"/>
+               <form-property name="offset" type="java.lang.String"/>
+               <form-property name="title" type="java.lang.String"/>
+               <form-property name="parentTopic" type="java.lang.Integer"/>
+               <form-property name="archivUrl" type="java.lang.String"/>
+               <form-property name="mainUrl" type="java.lang.String"/>
+               <form-property name="filename" type="java.lang.String"/>
+               <form-property name="description" type="java.lang.String"/>
+        </form-bean>
         <form-bean dynamic="true" name="messageForm" type="org.apache.struts.action.DynaActionForm">
                <form-property name="id" type="java.lang.String"/>
                <form-property name="new" type="java.lang.Boolean"/>
                 name="success"
                 path="/messageList.do"/>
         </action>
+
+        <!-- Topic -->
+        <action
+            parameter="list"
+            path="/topicList"
+            type="mir.core.ui.action.admin.TopicAction">
+            <forward
+                name="success"
+                path="/topiclist.shtml"/>
+        </action>
+        
+        <action
+            parameter="delete"
+            path="/topicDelete"
+            type="mir.core.ui.action.admin.TopicAction">
+            <forward
+                name="success"
+                path="/topicList.do"/>
+            <forward
+                name="failed"
+                path="/topicEdit.do"/>
+        </action>        
+        
+        <action
+            parameter="edit"
+            path="/topicEdit"
+            type="mir.core.ui.action.admin.TopicAction">
+            <forward
+                name="success"
+                path="/topic.shtml"/>
+        </action>
+        
+        <action
+            parameter="add"
+            path="/topicAdd"
+            type="mir.core.ui.action.admin.TopicAction">
+            <forward
+                name="success"
+                path="/topic.shtml"/>
+        </action>
+        
+        <action
+            attribute="topicForm"
+            input="/admin/topic.shtml"
+            name="topicForm"
+            parameter="save"
+            path="/topicSave"
+            scope="request"
+            type="mir.core.ui.action.admin.TopicAction"
+            unknown="false"
+            validate="true">
+            <forward
+                name="failed"
+                path="/topicEdit.do"/>
+            <forward
+                name="success"
+                path="/topicList.do"/>
+        </action>
+
     </action-mappings>
     
     <!-- ========== Controller Configuration ================================ -->
diff --git a/source/mir/core/ui/action/admin/TopicAction.java b/source/mir/core/ui/action/admin/TopicAction.java
new file mode 100755 (executable)
index 0000000..df93a31
--- /dev/null
@@ -0,0 +1,255 @@
+/*
+ * TopicAction.java created on 05.09.2003
+ * 
+ * Copyright (C) 2001, 2002, 2003 The Mir-coders group
+ *
+ * This file is part of Mir.
+ *
+ * Mir is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * Mir 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Mir; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ *
+ * In addition, as a special exception, The Mir-coders gives permission to link
+ * the code of this program with  any library licensed under the Apache Software License,
+ * The Sun (tm) Java Advanced Imaging library (JAI), The Sun JIMI library
+ * (or with modified versions of the above that use the same license as the above),
+ * and distribute linked combinations including the two.  You must obey the
+ * GNU General Public License in all respects for all of the code used other than
+ * the above mentioned libraries.  If you modify this file, you may extend this
+ * exception to your version of the file, but you are not obligated to do so.
+ * If you do not wish to do so, delete this exception statement from your version.
+ */
+package mir.core.ui.action.admin;
+
+import java.util.List;
+
+import javax.servlet.ServletContext;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import mir.config.MirPropertiesConfiguration;
+import mir.config.MirPropertiesConfiguration.PropertiesConfigExc;
+import mir.core.model.Topic;
+import mir.core.service.storage.TopicService;
+import mir.core.ui.action.DispatchAction;
+import mir.core.ui.servlet.ServletConstants;
+import multex.Failure;
+import net.sf.hibernate.SessionFactory;
+import net.sf.hibernate.expression.Order;
+
+import org.apache.struts.action.ActionForm;
+import org.apache.struts.action.ActionForward;
+import org.apache.struts.action.ActionMapping;
+import org.apache.struts.action.DynaActionForm;
+
+/**
+ * TopicAction
+ * @author idefix
+ * @version $Id: TopicAction.java,v 1.1 2003/09/30 19:29:32 idfx Exp $
+ */
+public class TopicAction extends DispatchAction {
+       private MirPropertiesConfiguration _configuration;
+
+       public TopicAction(){
+               super();
+               try {
+                       _configuration = MirPropertiesConfiguration.instance();
+               } catch (PropertiesConfigExc e) {
+                       throw new Failure("could not load config", e);
+               }               
+       }
+
+       private ActionForward add(ActionMapping actionMapping, ActionForm actionForm, 
+               HttpServletRequest request, HttpServletResponse response)
+               throws Exception {
+               //access to persistence
+               ServletContext context = getServlet().getServletContext();
+               TopicService topicService = 
+                       new TopicService((SessionFactory)context
+                               .getAttribute(ServletConstants.SESSION_FACTORY));
+               
+               List topics = topicService.list();
+               Topic defaultParent = new Topic();
+               defaultParent.setId(new Integer(-1));
+               defaultParent.setTitle("----");
+               topics.add(0, defaultParent);
+                                       
+               request.setAttribute(ServletConstants.NEW, new Boolean(true));
+               request.setAttribute(ServletConstants.ID, "");
+               request.setAttribute(ServletConstants.OFFSET, "");
+               request.setAttribute("topics", topics);
+               
+               //setting standard-values
+               Topic topic = new Topic();
+               request.setAttribute("topic", topic);
+               
+               //              show the view
+               return actionMapping.findForward("success");
+       }
+       
+       private ActionForward save(ActionMapping actionMapping, ActionForm actionForm, 
+               HttpServletRequest request, HttpServletResponse response)
+               throws Exception {
+               //access to persistence
+               ServletContext context = getServlet().getServletContext();
+               TopicService topicService = 
+                       new TopicService((SessionFactory)context
+                               .getAttribute(ServletConstants.SESSION_FACTORY));
+               
+               DynaActionForm form = (DynaActionForm) actionForm;
+               if(form == null){
+                       return actionMapping.findForward("failed");     
+               }
+               //check if new
+               Boolean isnew = (Boolean) form.get("new");
+               
+               //retrieve id
+               Topic topic = null;
+               if(isnew.booleanValue()){
+                       topic = new Topic();
+               } else {
+                       Integer id = new Integer(request.getParameter(ServletConstants.ID));
+                       topic = (Topic) topicService.load(id);
+               }
+               
+               if(topic == null){
+                       return actionMapping.findForward("failed");     
+               }
+               
+               topic.setTitle((String)form.get("title"));
+               topic.setDescription((String)form.get("title"));
+               topic.setFilename((String)form.get("filename"));
+               topic.setMainUrl((String)form.get("mainUrl"));
+               topic.setArchivUrl((String)form.get("archivUrl"));
+               topic.setParentTopic(null);
+               
+               Integer parentId = (Integer)form.get("parentTopic");
+               if(parentId != null && parentId.intValue() > -1){
+                       Topic parentTopic = (Topic) topicService.load(parentId);
+                       topic.setParentTopic(parentTopic);
+               } 
+
+               if(isnew.booleanValue()){
+                       System.out.println(topic);
+                       Integer id = topicService.save(topic);
+                       request.setAttribute(ServletConstants.OFFSET, "0");
+               } else {
+                       topicService.update(topic);
+               }
+               
+               //              show the view
+               return actionMapping.findForward("success");
+       }
+               
+       private ActionForward delete(ActionMapping actionMapping, ActionForm actionForm, 
+               HttpServletRequest request, HttpServletResponse response)
+               throws Exception {
+               //access to persistence
+               ServletContext context = getServlet().getServletContext();
+               TopicService topicService = 
+                       new TopicService((SessionFactory)context
+                               .getAttribute(ServletConstants.SESSION_FACTORY));
+               
+               //retrieve id
+               Integer id = new Integer(request.getParameter(ServletConstants.ID));
+               
+               //confirm the request
+               System.out.println(request.getAttribute(ServletConstants.DELETE));
+               if(request.getAttribute(ServletConstants.DELETE) == null){
+                       return actionMapping.findForward("confirm");
+               }
+               //load object
+               Topic topic = (Topic) topicService.load(id);
+               
+               if(topic == null){
+                       return actionMapping.findForward("failed");     
+               }
+                                       
+               topicService.delete(topic);
+               
+               //              show the view
+               return actionMapping.findForward("success");
+       }
+
+       private ActionForward list(ActionMapping actionMapping, ActionForm actionForm, 
+               HttpServletRequest request, HttpServletResponse response)
+               throws Exception {
+               //retrieve parameters
+               String offsetString = request.getParameter(ServletConstants.OFFSET);
+               int offset = 0;
+               if(offsetString != null && !offsetString.equals("")){
+                       offset = new Integer(offsetString).intValue();
+               }
+               
+               //access to persistence
+               ServletContext context = getServlet().getServletContext();
+               TopicService topicService = 
+                       new TopicService((SessionFactory)context
+                               .getAttribute(ServletConstants.SESSION_FACTORY));
+               
+               //retrieve entities
+               Order order = Order.desc("id");
+               List topics = topicService.list(offset, order);
+               
+               //configure the data to send to view
+               int listSize = _configuration.getInt("ServletModule.Default.ListSize");
+               Integer lastOffset;
+               if(offset-listSize < 0){
+                       lastOffset = new Integer(0);
+               } else {
+                       lastOffset = new Integer(offset-listSize);
+               }
+               request.setAttribute(ServletConstants.LAST_OFFSET, lastOffset);
+               request.setAttribute(ServletConstants.NEXT_OFFSET, 
+                       new Integer(offset + listSize));
+               request.setAttribute(ServletConstants.OFFSET, 
+                       new Integer(offset));
+               request.setAttribute("topics", topics);
+               
+               //show the view
+               return actionMapping.findForward("success");    
+       }
+       
+       private ActionForward edit(ActionMapping actionMapping, ActionForm actionForm, 
+               HttpServletRequest request, HttpServletResponse response)
+               throws Exception {
+               //retrieve parameters
+               Integer id = new Integer(request.getParameter(ServletConstants.ID));
+               String offset = request.getParameter(ServletConstants.OFFSET);
+
+               
+               //access to persistence
+               ServletContext context = getServlet().getServletContext();
+               TopicService topicService = 
+                       new TopicService((SessionFactory)context
+                               .getAttribute(ServletConstants.SESSION_FACTORY));
+               
+               //retrieve entities
+               Topic topic = (Topic) topicService.load(id);
+               
+               List topics = topicService.list();
+               Topic defaultParent = new Topic();
+               defaultParent.setId(new Integer(-1));
+               defaultParent.setTitle("----");
+               topics.add(0, defaultParent);
+               
+               //configure the data to send to view
+               request.setAttribute(ServletConstants.OFFSET, offset);
+               request.setAttribute(ServletConstants.NEW,"0");
+               request.setAttribute("topic", topic);
+               request.setAttribute("topics", topics);
+               
+               //show the view
+               return actionMapping.findForward("success");    
+       }
+}