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