526ae37b54c37ac13929e8e64727be6b742eac72
[mir.git] / source / mircoders / producer / ProducerImages.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 webdb.misc.*;
10 import webdb.storage.*;
11 import webdb.module.*;
12 import webdb.entity.*;
13
14 import mir.module.*;
15 import mir.entity.*;
16 import mir.storage.*;
17
18
19
20 public class ProducerImages extends Producer {
21
22         public static void main(String argv[]){
23                 try {
24                         new ProducerContent().handle(new PrintWriter(System.out), null, false,false);
25                 } catch(Exception e) { System.err.println(e.toString()); }
26         }
27
28         public void handle(PrintWriter htmlout, EntityUsers user, boolean force, boolean sync)
29                 throws StorageObjectException, ModuleException {
30                 handle(htmlout,user,force,sync,null);
31         }
32
33         public void handle(PrintWriter htmlout, EntityUsers user, boolean force, boolean sync, String id)
34                 throws StorageObjectException, ModuleException
35         {
36                 long                sessionConnectTime = 0;
37                 long                startTime = (new java.util.Date()).getTime();
38                 String              whereClause;
39                 String              iconFilename;
40                 String              imageFilename;
41                 String              productionPath;
42                 EntityImage         currentImage;
43                 EntityList          batchEntityList;
44
45     int contentBatchsize = Integer.parseInt(Configuration.getProperty("Producer.Content.Batchsize"));
46     String imageHost = Configuration.getProperty("Producer.Image.Host");
47           String imagePath = Configuration.getProperty("Producer.Image.Path");
48           String iconPath = Configuration.getProperty("Producer.Image.IconPath");
49
50                 // get batch of non-produced images, that are to be published
51                 whereClause="is_published='1'";
52                 if (id!= null)
53                         whereClause += " and id="+id;
54                 if (force==false) whereClause += " and icon_is_produced='0'";
55
56                 batchEntityList = imageModule.getByWhereClause(whereClause, null, 0, contentBatchsize);
57                 theLog.printDebugInfo("whereclause: " + whereClause);
58
59
60                 while (batchEntityList != null) {
61                         for(int i=0;i<batchEntityList.size();i++) {
62                                 theLog.printDebugInfo("trying image: " + i);
63                                 currentImage = (EntityImage)batchEntityList.elementAt(i);
64
65                                 // make filenames
66                                 String date = currentImage.getValue("date");
67
68                                 iconFilename = producerDocRoot + iconPath + StringUtil.webdbDate2path(date) +
69                                         currentImage.getId() + (( currentImage.getValue("to_img_type").equals("0") ) ? ".jpg":".gif");
70
71                                 imageFilename = currentImage.getId() + (( currentImage.getValue("to_img_type").equals("0") ) ? ".jpg":".gif");
72                                 productionPath = imagePath + "/" + imageFilename ;
73
74                                 currentImage.setValueForProperty("icon_path",iconFilename);
75                                 //currentImage.setValueForProperty("publish_path","imc/germany/" + imageFilename);
76         currentImage.setValueForProperty("publish_path",imageFilename);
77                                 currentImage.setValueForProperty("publish_server", imageHost);
78
79                                 if (currentImage.getValue("icon_data")!= null && currentImage.getValue("image_data")!= null) {
80                                         // make icon
81                                         boolean iconProduced = produceFile(iconFilename, currentImage.getIcon(), htmlout, true);
82                                         logHTML(htmlout,"icon : " + iconFilename + (( iconProduced==true )? " succeded":" <font color=\"Red\" failed!</font>"));
83                                         // make image
84                                         boolean imageProduced = produceFile(productionPath, currentImage.getImage(), htmlout, false);
85                                         logHTML(htmlout,"image: " + productionPath + ((imageProduced==true)?" succeded":" <font color=\"Red\" failed!</font>"));
86
87                                         // update image-data
88                                         if (iconProduced && imageProduced) {
89                                                 currentImage.setValueForProperty("icon_is_produced", "1");
90                                                 currentImage.update();
91                                         }
92
93                                 }
94                         }
95
96                         // if next batch get it...
97                         if (batchEntityList.hasNextBatch()){
98                                 batchEntityList = imageModule.getByWhereClause(whereClause, null, batchEntityList.getNextBatch(),contentBatchsize);
99                         } else {
100                                 batchEntityList=null;
101                         }
102                 }
103                 // Finish
104                 sessionConnectTime = new java.util.Date().getTime() - startTime;
105                 logHTML(htmlout, "Producer.Images finished: " + sessionConnectTime + " ms.");
106
107         }
108
109 }