templateModelRoot ist now a simplehash with two entries: data and config, bugfix...
[mir.git] / source / mircoders / module / ModuleTopics.java
1 package mircoders.module;
2
3 import java.io.*;
4 import java.lang.*;
5 import java.util.*;
6 import java.sql.*;
7 import javax.servlet.*;
8 import javax.servlet.http.*;
9
10 import freemarker.template.*;
11
12 import mir.servlet.*;
13 import mir.module.*;
14 import mir.entity.*;
15 import mir.misc.*;
16 import mir.storage.*;
17
18 import mircoders.storage.*;
19 import mircoders.entity.*;
20
21 /*
22  *  ThemenModule -
23  *
24  *
25  * @author RK
26  */
27
28 public class ModuleTopics extends AbstractModule
29 {
30
31     static Logfile theLog;
32
33     public ModuleTopics(StorageObject theStorage) {
34             this.theStorage = theStorage;
35             if (theLog == null)
36               theLog = Logfile.getInstance(MirConfig.getProp("Home") + MirConfig.getProp("Module.Themen.Logfile"));
37     }
38
39     public SimpleList getTopicsAsSimpleList() throws ModuleException {
40       try {
41               return ((DatabaseTopics)theStorage).getPopupData();
42       } catch(StorageObjectException e) {
43         throw new ModuleException(e.toString());
44       }
45     }
46
47
48     /**
49      *  Method getTopicList
50      *
51      *  @return SimpleList of all Topics sorted by title
52      *
53      */
54     public EntityList getTopicsList()
55     {
56       EntityList returnList=null;
57       try {
58         returnList=getByWhereClause("","title",-1);
59       }
60       catch (Exception e)
61       {
62         theLog.printWarning("--getTopicsList: topics could not be fetched");
63       }
64       return returnList;
65     }
66         
67         /**
68          * Overrides the AbstractModule.set(),
69          * All dependent ContentEntities are set unproduced.
70          * @param theValues Hash mit Spalte/Wert-Paaren
71          * @return Id des eingefügten Objekts
72          * @exception ModuleException
73          */
74         public String set (HashMap theValues) throws ModuleException {
75                 try {
76                         Entity theEntity = theStorage.selectById((String)theValues.get("id"));
77                         if (theEntity == null){
78                                 throw new ModuleException("Kein Objekt mit id in Datenbank id: " + theValues.get("id"));
79                         }
80                         theEntity.setValues(theValues);
81                         DatabaseContentToTopics db = DatabaseContentToTopics.getInstance();
82         DatabaseContent dbc = DatabaseContent.getInstance();
83                         EntityList contentList = db.getContent((EntityTopics)theEntity);
84                         for (int i = 0; i < contentList.size(); i++){
85                                 dbc.setUnproduced("id="+((EntityContent)contentList.elementAt(i)).getId());
86                         }
87                         theEntity.update();
88                         return theEntity.getId();
89                 } catch (StorageObjectException e){
90                         e.printStackTrace(System.err);
91                         throw new ModuleException(e.toString());
92                 }
93  }
94
95 }