fixed a bug that prevented saving when there are no associated articles
authorbr1 <br1>
Fri, 29 Mar 2002 13:46:22 +0000 (13:46 +0000)
committerbr1 <br1>
Fri, 29 Mar 2002 13:46:22 +0000 (13:46 +0000)
source/mircoders/module/ModuleTopics.java

index 707ce61..ea47863 100755 (executable)
@@ -1,22 +1,21 @@
 package mircoders.module;
 
-import java.io.*;
-import java.lang.*;
-import java.util.*;
-import java.sql.*;
-import javax.servlet.*;
-import javax.servlet.http.*;
+import freemarker.template.SimpleList;
+import mir.entity.Entity;
+import mir.entity.EntityList;
+import mir.misc.Logfile;
+import mir.misc.MirConfig;
+import mir.module.AbstractModule;
+import mir.module.ModuleException;
+import mir.storage.StorageObject;
+import mir.storage.StorageObjectException;
+import mircoders.entity.EntityContent;
+import mircoders.entity.EntityTopics;
+import mircoders.storage.DatabaseContent;
+import mircoders.storage.DatabaseContentToTopics;
+import mircoders.storage.DatabaseTopics;
 
-import freemarker.template.*;
-
-import mir.servlet.*;
-import mir.module.*;
-import mir.entity.*;
-import mir.misc.*;
-import mir.storage.*;
-
-import mircoders.storage.*;
-import mircoders.entity.*;
+import java.util.HashMap;
 
 /*
  *  ThemenModule -
@@ -25,71 +24,72 @@ import mircoders.entity.*;
  * @author RK
  */
 
-public class ModuleTopics extends AbstractModule
-{
+public class ModuleTopics extends AbstractModule {
 
-    static Logfile theLog;
+  static Logfile theLog;
 
-    public ModuleTopics(StorageObject theStorage) {
-           this.theStorage = theStorage;
-           if (theLog == null)
-             theLog = Logfile.getInstance(MirConfig.getProp("Home") + MirConfig.getProp("Module.Themen.Logfile"));
-    }
+  public ModuleTopics(StorageObject theStorage) {
+    this.theStorage = theStorage;
+    if (theLog == null)
+      theLog = Logfile.getInstance(MirConfig.getProp("Home") + MirConfig.getProp("Module.Themen.Logfile"));
+  }
 
-    public SimpleList getTopicsAsSimpleList() throws ModuleException {
-      try {
-             return ((DatabaseTopics)theStorage).getPopupData();
-      } catch(StorageObjectException e) {
-        throw new ModuleException(e.toString());
-      }
+  public SimpleList getTopicsAsSimpleList() throws ModuleException {
+    try {
+      return ((DatabaseTopics) theStorage).getPopupData();
+    }
+    catch (StorageObjectException e) {
+      throw new ModuleException(e.toString());
     }
+  }
 
 
-    /**
-     *  Method getTopicList
-     *
-     *  @return SimpleList of all Topics sorted by title
-     *
-     */
-    public EntityList getTopicsList()
-    {
-      EntityList returnList=null;
-      try {
-        returnList=getByWhereClause("","title",-1);
+  /**
+   *  Method getTopicList
+   *
+   *  @return SimpleList of all Topics sorted by title
+   *
+   */
+  public EntityList getTopicsList() {
+    EntityList returnList = null;
+    try {
+      returnList = getByWhereClause("", "title", -1);
+    }
+    catch (Exception e) {
+      theLog.printWarning("--getTopicsList: topics could not be fetched");
+    }
+    return returnList;
+  }
+
+  /**
+   * Overrides the AbstractModule.set(),
+   * All dependent ContentEntities are set unproduced.
+   * @param theValues Hash mit Spalte/Wert-Paaren
+   * @return Id des eingefügten Objekts
+   * @exception ModuleException
+   */
+  public String set(HashMap theValues) throws ModuleException {
+    try {
+      Entity theEntity = theStorage.selectById((String) theValues.get("id"));
+      if (theEntity == null) {
+        throw new ModuleException("Kein Objekt mit id in Datenbank id: " + theValues.get("id"));
       }
-      catch (Exception e)
-      {
-        theLog.printWarning("--getTopicsList: topics could not be fetched");
+      theEntity.setValues(theValues);
+      DatabaseContentToTopics db = DatabaseContentToTopics.getInstance();
+      DatabaseContent dbc = DatabaseContent.getInstance();
+      EntityList contentList = db.getContent((EntityTopics) theEntity);
+      if (contentList!=null) {
+        for (int i = 0; i < contentList.size(); i++) {
+          dbc.setUnproduced("id=" + ((EntityContent) contentList.elementAt(i)).getId());
+        }
       }
-      return returnList;
+      theEntity.update();
+      return theEntity.getId();
+    }
+    catch (StorageObjectException e) {
+      e.printStackTrace(System.err);
+      throw new ModuleException(e.toString());
     }
-       
-       /**
-        * Overrides the AbstractModule.set(),
-        * All dependent ContentEntities are set unproduced.
-        * @param theValues Hash mit Spalte/Wert-Paaren
-        * @return Id des eingefügten Objekts
-        * @exception ModuleException
-        */
-       public String set (HashMap theValues) throws ModuleException {
-               try {
-                       Entity theEntity = theStorage.selectById((String)theValues.get("id"));
-                       if (theEntity == null){
-                               throw new ModuleException("Kein Objekt mit id in Datenbank id: " + theValues.get("id"));
-                       }
-                       theEntity.setValues(theValues);
-                       DatabaseContentToTopics db = DatabaseContentToTopics.getInstance();
-       DatabaseContent dbc = DatabaseContent.getInstance();
-                       EntityList contentList = db.getContent((EntityTopics)theEntity);
-                       for (int i = 0; i < contentList.size(); i++){
-                               dbc.setUnproduced("id="+((EntityContent)contentList.elementAt(i)).getId());
-                       }
-                       theEntity.update();
-                       return theEntity.getId();
-               } catch (StorageObjectException e){
-                       e.printStackTrace(System.err);
-                       throw new ModuleException(e.toString());
-               }
- }
+  }
 
 }