f98c0fa2a854baa251839c0ac6b7bd54acef1c4c
[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     {
32                 printHTML(htmlout, "Producer.All: started");
33
34                 long                sessionConnectTime = 0;
35                 long                startTime = (new java.util.Date()).getTime();
36     
37         try {
38             new ProducerImages().handle(htmlout, user, force,sync);
39         } catch (Exception e) {
40             logHTML(htmlout, "Producer.All <font color=\"red\">ERROR:</font>"
41                 +" in ProducerImages continuing "+ e.toString());
42         }
43         try {
44             new ProducerAudio().handle(htmlout, user, force,sync);
45         } catch (Exception e) {
46             logHTML(htmlout, "Producer.All <font color=\"red\">ERROR:</font>"
47                 +" in ProducerAudio continuing "+ e.toString());
48         }
49         try {
50             new ProducerVideo().handle(htmlout, user, force,sync);
51         } catch (Exception e) {
52             logHTML(htmlout, "Producer.All <font color=\"red\">ERROR:</font>"
53                 +" in ProducerVideo continuing "+ e.toString());
54         }
55         try {
56             new ProducerOther().handle(htmlout, user, force,sync);
57         } catch (Exception e) {
58             logHTML(htmlout, "Producer.All <font color=\"red\">ERROR:</font>"
59                 +" in ProducerOther continuing "+ e.toString());
60         }
61         try {
62             new ProducerStartPage().handle(htmlout, user, force,sync);
63         } catch (Exception e) {
64             logHTML(htmlout, "Producer.All <font color=\"red\">ERROR:</font>"
65                 +" in Producer.StartPage continuing "+ e.toString());
66         }
67         try {
68             new ProducerContent().handle(htmlout, user, force,sync);
69         } catch (Exception e) {
70             logHTML(htmlout, "Producer.All <font color=\"red\">ERROR:</font>"
71                 +" in Producer.Content continuing "+ e.toString());
72         }
73         try {
74             new ProducerOpenPosting().handle(htmlout, user, force,sync);
75         } catch (Exception e) {
76             logHTML(htmlout, "Producer.All <font color=\"red\">ERROR:</font>"
77                 +" in Producer.OpenPosting continuing "+ e.toString());
78         }
79         try {
80             new ProducerTopics().handle(htmlout, user, force,sync);
81         } catch (Exception e) {
82             logHTML(htmlout, "Producer.All <font color=\"red\">ERROR:</font>"
83                 +" in Producer.Topics continuing "+ e.toString());
84         }
85         try {
86             new ProducerNavigation().handle(htmlout, user, force,sync);
87         } catch (Exception e) {
88             logHTML(htmlout, "Producer.All <font color=\"red\">ERROR:</font>"
89                 +" in Producer.Navigation continuing "+ e.toString());
90         }
91
92                 // Finish
93                 sessionConnectTime = new java.util.Date().getTime() - startTime;
94                 logHTML(htmlout, "Producer.All finished: " + sessionConnectTime + " ms.");
95
96                 // do we have to rsync the site
97                 if (sync==true){
98                         sessionConnectTime = 0;
99                         if (Helper.rsync()!=0){
100                                 sessionConnectTime = new java.util.Date().getTime() - startTime;
101                                 logHTML(htmlout, "Rsync failed: " + sessionConnectTime + " ms.");
102                         } else {
103                                 sessionConnectTime = new java.util.Date().getTime() - startTime;
104                                 logHTML(htmlout, "Rsync succeded: " + sessionConnectTime + " ms.");
105                         }
106                 }
107         }
108
109         // handle all
110         public void handle2(PrintWriter htmlout, EntityUsers user, boolean force,boolean sync)
111                 throws StorageObjectException, ModuleException {
112                 printHTML(htmlout, "Producer.All: started");
113
114                 long                sessionConnectTime = 0;
115                 long                startTime = (new java.util.Date()).getTime();
116                 EntityContent   currentContent;
117
118                 //get all new unproduced content-entities
119                 String whereClause="is_produced='0' && to_article_type>0";
120                 String orderBy="date desc";
121                 EntityList entityList = contentModule.getContent(whereClause,orderBy,0,-1,null);
122
123                 //get their values
124                 while (entityList != null) {
125                         for(int i=0;i<entityList.size();i++) {
126                                 currentContent = (EntityContent)entityList.elementAt(i);
127                                 EntityList topicEntityList = DatabaseContentToTopics.getInstance().getTopics(currentContent);
128                                 SimpleHash topicHash = HTMLTemplateProcessor.makeSimpleHash(topicEntityList);
129
130                                 try {
131                                         //check if this content item is related to a topic
132                                         if(currentContent.getId().equals(topicHash.get("content_id"))){
133                                                 // produce the ToicsList
134                                                 new ProducerTopics().handle(htmlout, user, force,sync,topicHash.get("topic_id").toString());
135                                         }
136                                 } catch (TemplateModelException e) {
137                                         logHTML(htmlout, e.toString());
138                                 }
139                         }
140                 }
141
142                 new ProducerContent().handle(htmlout, user, force,sync);
143                 new ProducerOpenPosting().handle(htmlout, user, force,sync);
144                 new ProducerStartPage().handle(htmlout, user, force,sync);
145                 new ProducerTopics().handle(htmlout, user, force,sync);
146
147                 // Finish
148                 sessionConnectTime = new java.util.Date().getTime() - startTime;
149                 logHTML(htmlout, "Producer.All finished: " + sessionConnectTime + " ms.");
150         }
151 }
152