| 2838 |
mandeep.dh |
1 |
/**
|
|
|
2 |
*
|
|
|
3 |
*/
|
|
|
4 |
package in.shop2020.ui.util;
|
|
|
5 |
|
| 22640 |
amit.gupta |
6 |
import in.shop2020.metamodel.core.Entity;
|
|
|
7 |
import in.shop2020.metamodel.core.Media;
|
|
|
8 |
import in.shop2020.metamodel.core.Slide;
|
| 2838 |
mandeep.dh |
9 |
import in.shop2020.metamodel.core.SpecialPage;
|
| 22647 |
amit.gupta |
10 |
import in.shop2020.metamodel.definitions.Catalog;
|
| 2838 |
mandeep.dh |
11 |
import in.shop2020.metamodel.util.CreationUtils;
|
| 22640 |
amit.gupta |
12 |
import in.shop2020.metamodel.util.MediaPojo;
|
| 2838 |
mandeep.dh |
13 |
|
|
|
14 |
import java.io.BufferedWriter;
|
|
|
15 |
import java.io.File;
|
|
|
16 |
import java.io.FileWriter;
|
|
|
17 |
import java.io.IOException;
|
| 22640 |
amit.gupta |
18 |
import java.text.MessageFormat;
|
|
|
19 |
import java.util.Arrays;
|
|
|
20 |
import java.util.Collection;
|
|
|
21 |
import java.util.List;
|
| 2838 |
mandeep.dh |
22 |
import java.util.Map;
|
|
|
23 |
|
|
|
24 |
import org.apache.commons.logging.Log;
|
|
|
25 |
import org.apache.commons.logging.LogFactory;
|
|
|
26 |
import org.json.JSONException;
|
|
|
27 |
|
|
|
28 |
import com.google.gson.Gson;
|
|
|
29 |
|
|
|
30 |
/**
|
|
|
31 |
* @author mandeep
|
|
|
32 |
*
|
|
|
33 |
*/
|
|
|
34 |
public class SpecialPageJSONConvertor {
|
|
|
35 |
private static Log LOG = LogFactory.getLog(SpecialPageJSONConvertor.class);
|
|
|
36 |
|
|
|
37 |
public void writeToJSONFile(File file) throws JSONException, IOException {
|
| 2839 |
mandeep.dh |
38 |
Map<Long, SpecialPage> specialPages = CreationUtils.getSpecialPages();
|
|
|
39 |
if (specialPages == null) {
|
|
|
40 |
return;
|
|
|
41 |
}
|
|
|
42 |
|
| 2838 |
mandeep.dh |
43 |
FileWriter fileWriter = new FileWriter(file);
|
|
|
44 |
BufferedWriter bufferedWriter = new BufferedWriter(fileWriter);
|
| 2839 |
mandeep.dh |
45 |
for (SpecialPage specialPage : specialPages.values()) {
|
|
|
46 |
LOG.info("Writing specialPage: " + specialPage);
|
|
|
47 |
bufferedWriter.write(new Gson().toJson(specialPage));
|
| 2838 |
mandeep.dh |
48 |
bufferedWriter.newLine();
|
|
|
49 |
}
|
|
|
50 |
|
|
|
51 |
bufferedWriter.close();
|
|
|
52 |
fileWriter.close();
|
|
|
53 |
}
|
|
|
54 |
|
| 22640 |
amit.gupta |
55 |
public static void main(String[] args) throws Exception {
|
| 22647 |
amit.gupta |
56 |
Long creationTime = CreationUtils.getLastContentGenerationTime();
|
| 22648 |
amit.gupta |
57 |
for (Long entityId : CreationUtils.getEntitiesMarkedReady(creationTime - 86400*1000*10)) {
|
|
|
58 |
LOG.info("entityId - " + entityId);
|
| 22640 |
amit.gupta |
59 |
Entity e = CreationUtils.getEntity(entityId);
|
|
|
60 |
List<Slide> slides = e.getSlides();
|
|
|
61 |
if (slides != null) {
|
|
|
62 |
for (Slide slide: slides){
|
|
|
63 |
if(slide.getFreeformContent() !=null && slide.getFreeformContent().getMedias() !=null){
|
| 22647 |
amit.gupta |
64 |
String slideName = Catalog.getInstance().getDefinitionsContainer().getSlideDefinition(slide.getSlideDefinitionID()).getLabel();
|
| 22640 |
amit.gupta |
65 |
Collection<Media> medias = slide.getFreeformContent().getMedias().values();
|
|
|
66 |
for (Media media : medias){
|
| 22647 |
amit.gupta |
67 |
if(media.getFileName()==null){
|
|
|
68 |
LOG.info("Slide ID - for media:" + slide.getSlideDefinitionID() + "Slide name is " + slideName);
|
|
|
69 |
LOG.info("Media label -- " + media.getLabel());
|
|
|
70 |
LOG.info("Media file name -- " + media.getFileName());
|
|
|
71 |
}
|
| 22640 |
amit.gupta |
72 |
}
|
|
|
73 |
}
|
|
|
74 |
|
|
|
75 |
}
|
|
|
76 |
}
|
|
|
77 |
}
|
| 2838 |
mandeep.dh |
78 |
}
|
|
|
79 |
}
|