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