View Javadoc

1   package de.tivsource.page.admin.backup;
2   
3   import java.io.BufferedWriter;
4   import java.io.File;
5   import java.io.FileWriter;
6   import java.io.IOException;
7   import java.text.SimpleDateFormat;
8   import java.util.Iterator;
9   
10  import org.apache.logging.log4j.LogManager;
11  import org.apache.logging.log4j.Logger;
12  
13  import de.tivsource.page.dao.gallery.GalleryDaoLocal;
14  import de.tivsource.page.entity.enumeration.Language;
15  import de.tivsource.page.entity.gallery.Gallery;
16  
17  public class BackupGallery {
18  
19      /**
20       * Statischer Logger der Klasse.
21       */
22      private static final Logger LOGGER = LogManager.getLogger(BackupGallery.class);
23  
24  	private static GalleryDaoLocal galleryDaoLocal;
25  
26      public static void setGalleryDaoLocal(GalleryDaoLocal galleryDaoLocal) {
27  		BackupGallery.galleryDaoLocal = galleryDaoLocal;
28  	}
29  
30  	public static File getBackupFile() throws IOException {
31          LOGGER.info("getBackupFile() aufgerufen.");
32  		// Datei Kram
33  		File backupFile = new File("/tmp/gallery.csv");
34      	FileWriter backupFileWriter = new FileWriter(backupFile);
35      	BufferedWriter backupFileWriterOut = new BufferedWriter(backupFileWriter);
36  
37      	// Format Definition 
38      	backupFileWriterOut.write("[Format Definition] => uuid|uuid(de)|name(de)|description(de)|keywords(de)|uuid(en)|name(en)|description(en)|keywords(en)|visible|created|modified|modifiedBy|modifiedAddress|picture|technical|orderNumber|pictureOnPage|type|");
39  
40      	Iterator<Gallery> typeIterator = galleryDaoLocal.findAll(0, galleryDaoLocal.countAll()).iterator();
41      	while(typeIterator.hasNext()) {
42      		Gallery next = typeIterator.next();
43      		backupFileWriterOut.write("\n");
44      		backupFileWriterOut.write(convertToCsvLine(next));
45      	}
46      	backupFileWriterOut.close();
47      	backupFileWriter.close();
48  
49      	return backupFile;
50  	}// Ende getBackupFiles()
51  
52  	private static String convertToCsvLine(Gallery next) {
53  
54  	    SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
55  
56  		// uuid|
57  	    // uuid(de)|name(de)|description(de)|keywords(de)|
58  	    // uuid(en)|name(en)|description(en)|keywords(en)|
59  	    // visible|created|modified|modifiedBy|modifiedAddress|picture|
60  	    // technical|orderNumber|pictureOnPage|type|
61  	    
62  		StringBuffer nextString = new StringBuffer();
63  		
64  		nextString.append(next.getUuid());
65  		nextString.append("|");
66  
67  		
68          nextString.append(next.getDescriptionObject(Language.DE).getUuid());
69          nextString.append("|");
70  
71          nextString.append(next.getDescriptionObject(Language.DE).getName());
72          nextString.append("|");
73  
74          nextString.append(next.getDescriptionObject(Language.DE).getDescription());
75          nextString.append("|");
76  
77          nextString.append(next.getDescriptionObject(Language.DE).getKeywords());
78          nextString.append("|");
79  
80          
81          nextString.append(next.getDescriptionObject(Language.EN).getUuid());
82          nextString.append("|");
83          
84          nextString.append(next.getDescriptionObject(Language.EN).getName());
85          nextString.append("|");
86  
87          nextString.append(next.getDescriptionObject(Language.EN).getDescription());
88          nextString.append("|");
89  
90          nextString.append(next.getDescriptionObject(Language.EN).getKeywords());
91          nextString.append("|");
92  
93          
94          nextString.append(next.getVisible().toString());
95          nextString.append("|");
96          
97          nextString.append(simpleDateFormat.format(next.getCreated()));
98          nextString.append("|");
99  
100         nextString.append(simpleDateFormat.format(next.getModified()));
101         nextString.append("|");
102 
103         nextString.append(next.getModifiedBy());
104         nextString.append("|");
105 
106         nextString.append(next.getModifiedAddress());
107         nextString.append("|");
108 
109         nextString.append(next.getPicture().getUuid());
110         nextString.append("|");
111 
112         
113         nextString.append(next.getTechnical());
114         nextString.append("|");
115 
116         nextString.append(next.getOrderNumber().toString());
117         nextString.append("|");
118 
119         nextString.append(next.getPictureOnPage().toString());
120         nextString.append("|");
121 
122         nextString.append(next.getType().toString());
123         nextString.append("|");
124 
125 		return nextString.toString();
126 	}
127 
128 }// Ende class