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