| 11992 |
vikram.rag |
1 |
package in.shop2020.creation.controllers;
|
|
|
2 |
|
|
|
3 |
import in.shop2020.metamodel.util.ContentPojo;
|
|
|
4 |
import in.shop2020.metamodel.util.ItemPojo;
|
|
|
5 |
import in.shop2020.metamodel.util.PrivateDealPojo;
|
|
|
6 |
import in.shop2020.model.v1.catalog.CatalogService.Client;
|
|
|
7 |
import in.shop2020.model.v1.catalog.Item;
|
|
|
8 |
import in.shop2020.storage.mongo.StorageManager;
|
|
|
9 |
import in.shop2020.thrift.clients.CatalogClient;
|
|
|
10 |
import in.shop2020.thrift.clients.config.ConfigClient;
|
|
|
11 |
|
|
|
12 |
import java.io.BufferedWriter;
|
|
|
13 |
import java.io.File;
|
|
|
14 |
import java.io.FileNotFoundException;
|
|
|
15 |
import java.io.FileWriter;
|
|
|
16 |
import java.io.IOException;
|
|
|
17 |
import java.net.UnknownHostException;
|
|
|
18 |
import java.util.HashMap;
|
|
|
19 |
import java.util.List;
|
|
|
20 |
import java.util.Map;
|
|
|
21 |
import java.util.Scanner;
|
|
|
22 |
|
|
|
23 |
import org.apache.thrift.TException;
|
|
|
24 |
import org.apache.thrift.transport.TTransportException;
|
|
|
25 |
import org.bson.BasicBSONObject;
|
|
|
26 |
|
|
|
27 |
import com.mongodb.BasicDBObject;
|
|
|
28 |
import com.mongodb.DB;
|
|
|
29 |
import com.mongodb.DBCollection;
|
|
|
30 |
import com.mongodb.DBObject;
|
|
|
31 |
import com.mongodb.MongoClient;
|
|
|
32 |
import com.mongodb.MongoClientURI;
|
|
|
33 |
|
|
|
34 |
public class NewsLetterController {
|
|
|
35 |
List<Item> privateDealItems;
|
|
|
36 |
public List<Item> getPrivateDealItems() {
|
|
|
37 |
return privateDealItems;
|
|
|
38 |
}
|
|
|
39 |
public void setPrivateDealItems(List<Item> privateDealItems) {
|
|
|
40 |
this.privateDealItems = privateDealItems;
|
|
|
41 |
}
|
|
|
42 |
List<Item> aliveItems;
|
|
|
43 |
public Map<Long, Item> privateDealItemMap = new HashMap<Long,Item>();
|
|
|
44 |
public NewsLetterController() {
|
|
|
45 |
try {
|
|
|
46 |
Client CatalogClient = new CatalogClient().getClient();
|
|
|
47 |
privateDealItems = CatalogClient.getPrivateDealItems(0,0);
|
|
|
48 |
System.out.println("Init Private Deals Map");
|
|
|
49 |
for(Item privateDealItem:privateDealItems){
|
|
|
50 |
System.out.println("Putting "+ privateDealItem.getId());
|
|
|
51 |
privateDealItemMap.put(privateDealItem.getId(),privateDealItem);
|
|
|
52 |
}
|
|
|
53 |
aliveItems = CatalogClient.getAllAliveItems();
|
|
|
54 |
setPrivateDealItems(privateDealItems);
|
|
|
55 |
} catch (TTransportException e) {
|
|
|
56 |
e.printStackTrace();
|
|
|
57 |
} catch (TException e) {
|
|
|
58 |
e.printStackTrace();
|
|
|
59 |
}
|
|
|
60 |
}
|
|
|
61 |
public String index() {
|
|
|
62 |
return "index";
|
|
|
63 |
}
|
|
|
64 |
public ContentPojo getProductAttributes(long catalog_item_id){
|
|
|
65 |
return StorageManager.getById(StorageManager.views.siteContent, new Long(catalog_item_id),ContentPojo.class);
|
|
|
66 |
}
|
|
|
67 |
public void createPrivateDealsNewsLetter(String[] itemids) throws IOException{
|
|
|
68 |
File file = new File("/home/vikram/Desktop/newsletter.html");
|
|
|
69 |
BufferedWriter fileWriter = new BufferedWriter(new FileWriter(file));
|
|
|
70 |
ContentPojo cp;
|
|
|
71 |
Map<Long,ItemPojo> ItemPojoMap = new HashMap<Long,ItemPojo>();
|
|
|
72 |
Map<Long,ContentPojo> ContentPojoMap = new HashMap<Long,ContentPojo>();
|
|
|
73 |
for(String itemid:itemids){
|
|
|
74 |
System.out.println("Item ID "+itemid);
|
|
|
75 |
System.out.println("Catalog Item ID "+privateDealItemMap.get(Long.parseLong(itemid)).getCatalogItemId());
|
|
|
76 |
cp = getProductAttributes(privateDealItemMap.get(Long.parseLong(itemid)).getCatalogItemId());
|
|
|
77 |
if(cp==null){
|
|
|
78 |
continue;
|
|
|
79 |
}
|
|
|
80 |
System.out.println("Content Pojo "+cp.getTitle());
|
|
|
81 |
for(ItemPojo itemPojo:cp.getItems()){
|
|
|
82 |
System.out.println("Item ID in list "+Long.parseLong(itemid) +" Item ID in item pojo "+itemPojo.getId().longValue());
|
|
|
83 |
if(Long.parseLong(itemid)==itemPojo.getId().longValue()){
|
|
|
84 |
ItemPojoMap.put(itemPojo.getId(),itemPojo);
|
|
|
85 |
}
|
|
|
86 |
}
|
|
|
87 |
ContentPojoMap.put(new Long(itemid),cp);
|
|
|
88 |
}
|
|
|
89 |
CreateHeader(fileWriter);
|
|
|
90 |
int i=1;
|
|
|
91 |
fileWriter.write("<div id=\"partition\" style=\"width:652; float:left; background-color: white;\">");
|
|
|
92 |
for(ItemPojo itemPojo:ItemPojoMap.values()){
|
|
|
93 |
cp = ContentPojoMap.get(itemPojo.getId());
|
|
|
94 |
|
|
|
95 |
itemPojo.getColor();
|
|
|
96 |
|
|
|
97 |
cp.getIconImageUrl();
|
|
|
98 |
cp.getUrl();
|
|
|
99 |
if(i%2==1){
|
|
|
100 |
//fileWriter.write("<div class=\"box\">");
|
|
|
101 |
fileWriter.write("<div class=\"box\">");
|
|
|
102 |
fileWriter.write("<div><a style=\"text-decoration: none; color:#0088cc;\" target=\"_blank\" href=\""+cp.getUrl()+"\">");
|
|
|
103 |
fileWriter.write("<h1 style=\"padding: 12px 0px 0px 66px; font-family:Lucida Grande, sans-serif; font-size:18px; font-style:regular; color:black;\">"+cp.getTitle()+"</h1>");
|
|
|
104 |
fileWriter.write("<p style=\"padding: 0px 0px 0px 0px; font-family:Lucida Grande, sans-serif; font-size:14px; font-style:regular; color:#666666; text-align:center;\">");
|
|
|
105 |
fileWriter.write("<strike>MRP</strike> | <strike>Regular Price</strike> |<span class=\"special\"> Special Price</span>");
|
|
|
106 |
fileWriter.write("<br>");
|
|
|
107 |
fileWriter.write("<strike> <img src=\"http://static0.saholic.com/images/rupee-icon-6427.png\" alt=\"rupees\" style=\"height:11px\">"+itemPojo.getMrp()+"</strike> | <strike><img src=\"http://static0.saholic.com/images/rupee-icon-6427.png\" alt=\"rupees\" style=\"height:11px\">"+itemPojo.getSellingPrice()+"</strike> | <img src=\"http://static0.saholic.com/images/rupee-icon-6427.png\" alt=\"rupees\" style=\"height:11px\"> <span class=\"special\">"+itemPojo.getDealPojo().getDealPrice()+"</span><br>");
|
|
|
108 |
fileWriter.write("Use Coupon:<b><span class=\"coupon\"> ASDFG</span></b></p>");
|
|
|
109 |
fileWriter.write("<img height=\"140\" style=\"padding: 8px 0px 0px 112px;\" alt=\"headphones\" src=\""+cp.getIconImageUrl()+"\">");
|
|
|
110 |
fileWriter.write("</a></div><a style=\"text-decoration: none; color:#0088cc;\" target=\"_blank\" href=\""+cp.getUrl()+"/\">");
|
|
|
111 |
fileWriter.write("</a></div>");
|
|
|
112 |
}
|
|
|
113 |
else{
|
|
|
114 |
//fileWriter.write("<div class=\"box\">");
|
|
|
115 |
fileWriter.write("<div class=\"box\">");
|
|
|
116 |
fileWriter.write("<div><a style=\"text-decoration: none; color:#0088cc;\" target=\"_blank\" href=\""+cp.getUrl()+"\">");
|
|
|
117 |
fileWriter.write("<h1 style=\"padding: 12px 0px 0px 66px; font-family:Lucida Grande, sans-serif; font-size:18px; font-style:regular; color:black;\">"+cp.getTitle()+"</h1>");
|
|
|
118 |
fileWriter.write("<p style=\"padding: 0px 0px 0px 0px; font-family:Lucida Grande, sans-serif; font-size:14px; font-style:regular; color:#666666; text-align:center;\">");
|
|
|
119 |
fileWriter.write("<strike>MRP</strike> | <strike>Regular Price</strike> |<span class=\"special\"> Special Price</span>");
|
|
|
120 |
fileWriter.write("<br>");
|
|
|
121 |
fileWriter.write("<strike> <img src=\"http://static0.saholic.com/images/rupee-icon-6427.png\" alt=\"rupees\" style=\"height:11px\">"+itemPojo.getMrp()+"</strike> | <strike><img src=\"http://static0.saholic.com/images/rupee-icon-6427.png\" alt=\"rupees\" style=\"height:11px\">"+itemPojo.getSellingPrice()+"</strike> | <img src=\"http://static0.saholic.com/images/rupee-icon-6427.png\" alt=\"rupees\" style=\"height:11px\"> <span class=\"special\">"+itemPojo.getDealPojo().getDealPrice()+"</span><br>");
|
|
|
122 |
fileWriter.write("Use Coupon:<b><span class=\"coupon\"> ASDFG</span></b></p>");
|
|
|
123 |
fileWriter.write("<img height=\"140\" style=\"padding: 8px 0px 0px 112px;\" alt=\"headphones\" src=\""+cp.getIconImageUrl()+"\">");
|
|
|
124 |
fileWriter.write("</a></div><a style=\"text-decoration: none; color:#0088cc;\" target=\"_blank\" href=\""+cp.getUrl()+"/\">");
|
|
|
125 |
fileWriter.write("</a></div>");
|
|
|
126 |
}
|
|
|
127 |
}
|
|
|
128 |
fileWriter.write("</div>");
|
|
|
129 |
CreateFooter(fileWriter);
|
|
|
130 |
fileWriter.close();
|
|
|
131 |
|
|
|
132 |
}
|
|
|
133 |
public void CreateHeader(BufferedWriter fileWriter) throws IOException{
|
|
|
134 |
File input = new File("/home/vikram/Desktop/header.html");
|
|
|
135 |
Scanner sc = new Scanner(input);
|
|
|
136 |
while (sc.hasNextLine()) {
|
|
|
137 |
String s = sc.nextLine();
|
|
|
138 |
fileWriter.write(s);
|
|
|
139 |
}
|
|
|
140 |
}
|
|
|
141 |
public void CreateFooter(BufferedWriter fileWriter) throws IOException{
|
|
|
142 |
File input = new File("/home/vikram/Desktop/footer.html");
|
|
|
143 |
Scanner sc = new Scanner(input);
|
|
|
144 |
while (sc.hasNextLine()) {
|
|
|
145 |
String s = sc.nextLine();
|
|
|
146 |
fileWriter.write(s);
|
|
|
147 |
}
|
|
|
148 |
}
|
|
|
149 |
public static void main(String... str) throws IOException{
|
|
|
150 |
String [] itemids = {"2287","5880","7940","8577","8603"};
|
|
|
151 |
NewsLetterController newsLetterController = new NewsLetterController();
|
|
|
152 |
newsLetterController.createPrivateDealsNewsLetter(itemids);
|
|
|
153 |
}
|
|
|
154 |
}
|