a bunch of bufixes and also a new ServletModuleUserException so that we
[mir.git] / source / mircoders / producer / ProducerAll.java
1 package mircoders.producer;
2
3 import java.io.*;
4 import java.lang.*;
5 import java.util.*;
6
7 import freemarker.template.*;
8
9 import mir.misc.*;
10 import mir.storage.*;
11 import mir.module.*;
12 import mir.entity.*;
13
14 import mircoders.module.*;
15 import mircoders.entity.*;
16 import mircoders.storage.*;
17
18
19 public class ProducerAll extends Producer{
20
21         private boolean rsync;
22
23         public static void main(String argv[])
24         {
25                 try {   new ProducerAll().handle(new PrintWriter(System.out), null, false,false);       }
26                 catch(Exception e) { System.err.println(e.toString()); }
27         }
28
29         // handle all
30         public void handle(PrintWriter htmlout, EntityUsers user, boolean force,boolean sync)
31                 throws StorageObjectException, ModuleException {
32                 printHTML(htmlout, "Producer.All: started");
33
34                 long                sessionConnectTime = 0;
35                 long                startTime = (new java.util.Date()).getTime();
36                 //new ProducerImages().handle(htmlout, user, force,sync);
37                 new ProducerMedia().handle(htmlout, user, force,sync);
38                 new ProducerStartPage().handle(htmlout, user, force,sync);
39                 new ProducerContent().handle(htmlout, user, force,sync);
40                 new ProducerOpenPosting().handle(htmlout, user, force,sync);
41                 new ProducerTopics().handle(htmlout, user, force,sync);
42     new ProducerNavigation().handle(htmlout, user, force,sync);
43
44                 // Finish
45                 sessionConnectTime = new java.util.Date().getTime() - startTime;
46                 logHTML(htmlout, "Producer.All finished: " + sessionConnectTime + " ms.");
47
48                 // do we have to rsync the site
49                 if (sync==true){
50                         sessionConnectTime = 0;
51                         if (Helper.rsync()!=0){
52                                 sessionConnectTime = new java.util.Date().getTime() - startTime;
53                                 logHTML(htmlout, "Rsync failed: " + sessionConnectTime + " ms.");
54                         } else {
55                                 sessionConnectTime = new java.util.Date().getTime() - startTime;
56                                 logHTML(htmlout, "Rsync succeded: " + sessionConnectTime + " ms.");
57                         }
58                 }
59         }
60
61         // handle all
62         public void handle2(PrintWriter htmlout, EntityUsers user, boolean force,boolean sync)
63                 throws StorageObjectException, ModuleException {
64                 printHTML(htmlout, "Producer.All: started");
65
66                 long                sessionConnectTime = 0;
67                 long                startTime = (new java.util.Date()).getTime();
68                 EntityContent   currentContent;
69                 HashMap         currentContentValues;
70
71                 //get all new unproduced content-entities
72                 String whereClause="is_produced='0' && to_article_type>0";
73                 String orderBy="date desc";
74                 EntityList entityList = contentModule.getContent(whereClause,orderBy,0,-1,null);
75
76                 //get their values
77                 while (entityList != null) {
78                         for(int i=0;i<entityList.size();i++) {
79                                 currentContent = (EntityContent)entityList.elementAt(i);
80                                 currentContentValues = currentContent.getValues();
81                                 EntityList topicEntityList = DatabaseContentToTopics.getInstance().getTopics(currentContent);
82                                 SimpleHash topicHash = HTMLTemplateProcessor.makeSimpleHash(topicEntityList);
83
84                                 try {
85                                         //check if this content item is related to a topic
86                                         if(currentContent.getId().equals(topicHash.get("content_id"))){
87                                                 // produce the ToicsList
88                                                 new ProducerTopics().handle(htmlout, user, force,sync,topicHash.get("topic_id").toString());
89                                         }
90                                 } catch (TemplateModelException e) {
91                                         logHTML(htmlout, e.toString());
92                                 }
93                         }
94                 }
95
96                 new ProducerContent().handle(htmlout, user, force,sync);
97                 new ProducerOpenPosting().handle(htmlout, user, force,sync);
98                 new ProducerStartPage().handle(htmlout, user, force,sync);
99                 new ProducerTopics().handle(htmlout, user, force,sync);
100
101                 // Finish
102                 sessionConnectTime = new java.util.Date().getTime() - startTime;
103                 logHTML(htmlout, "Producer.All finished: " + sessionConnectTime + " ms.");
104         }
105 }
106