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