d45feb9674d1ea53bb9fa68adcd9c306e89228f2
[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 ProducerStartPage().handle(htmlout, user, force,sync);
38                 new ProducerContent().handle(htmlout, user, force,sync);
39                 new ProducerOpenPosting().handle(htmlout, user, force,sync);
40                 new ProducerTopics().handle(htmlout, user, force,sync);
41     new ProducerNavigation().handle(htmlout, user, force,sync);
42
43                 // Finish
44                 sessionConnectTime = new java.util.Date().getTime() - startTime;
45                 logHTML(htmlout, "Producer.All finished: " + sessionConnectTime + " ms.");
46
47                 // do we have to rsync the site
48                 if (sync==true){
49                         sessionConnectTime = 0;
50                         if (Helper.rsync()!=0){
51                                 sessionConnectTime = new java.util.Date().getTime() - startTime;
52                                 logHTML(htmlout, "Rsync failed: " + sessionConnectTime + " ms.");
53                         } else {
54                                 sessionConnectTime = new java.util.Date().getTime() - startTime;
55                                 logHTML(htmlout, "Rsync succeded: " + sessionConnectTime + " ms.");
56                         }
57                 }
58         }
59
60         // handle all
61         public void handle2(PrintWriter htmlout, EntityUsers user, boolean force,boolean sync)
62                 throws StorageObjectException, ModuleException {
63                 printHTML(htmlout, "Producer.All: started");
64
65                 long                sessionConnectTime = 0;
66                 long                startTime = (new java.util.Date()).getTime();
67                 EntityContent   currentContent;
68                 HashMap         currentContentValues;
69
70                 //get all new unproduced content-entities
71                 String whereClause="is_produced='0' && to_article_type>0";
72                 String orderBy="date desc";
73                 EntityList entityList = contentModule.getContent(whereClause,orderBy,0,-1,null);
74
75                 //get their values
76                 while (entityList != null) {
77                         for(int i=0;i<entityList.size();i++) {
78                                 currentContent = (EntityContent)entityList.elementAt(i);
79                                 currentContentValues = currentContent.getValues();
80                                 EntityList topicEntityList = DatabaseContentToTopics.getInstance().getTopics(currentContent);
81                                 SimpleHash topicHash = HTMLTemplateProcessor.makeSimpleHash(topicEntityList);
82
83                                 try {
84                                         //check if this content item is related to a topic
85                                         if(currentContent.getId().equals(topicHash.get("content_id"))){
86                                                 // produce the ToicsList
87                                                 new ProducerTopics().handle(htmlout, user, force,sync,topicHash.get("topic_id").toString());
88                                         }
89                                 } catch (TemplateModelException e) {
90                                         logHTML(htmlout, e.toString());
91                                 }
92                         }
93                 }
94
95                 new ProducerContent().handle(htmlout, user, force,sync);
96                 new ProducerOpenPosting().handle(htmlout, user, force,sync);
97                 new ProducerStartPage().handle(htmlout, user, force,sync);
98                 new ProducerTopics().handle(htmlout, user, force,sync);
99
100                 // Finish
101                 sessionConnectTime = new java.util.Date().getTime() - startTime;
102                 logHTML(htmlout, "Producer.All finished: " + sessionConnectTime + " ms.");
103         }
104 }
105