| 9218 |
amit.gupta |
1 |
package in.shop2020.util;
|
|
|
2 |
|
|
|
3 |
import in.shop2020.metamodel.core.Entity;
|
| 9280 |
amit.gupta |
4 |
import in.shop2020.metamodel.core.ExpertReview;
|
| 9218 |
amit.gupta |
5 |
import in.shop2020.metamodel.core.Feature;
|
|
|
6 |
import in.shop2020.metamodel.core.Media;
|
|
|
7 |
import in.shop2020.metamodel.core.Slide;
|
|
|
8 |
import in.shop2020.metamodel.definitions.Catalog;
|
|
|
9 |
import in.shop2020.metamodel.definitions.DefinitionsContainer;
|
|
|
10 |
import in.shop2020.metamodel.definitions.SlideDefinition;
|
|
|
11 |
import in.shop2020.metamodel.util.ContentPojo;
|
|
|
12 |
import in.shop2020.metamodel.util.ExpandedBullet;
|
| 9280 |
amit.gupta |
13 |
import in.shop2020.metamodel.util.ExpandedEntity;
|
| 9218 |
amit.gupta |
14 |
import in.shop2020.metamodel.util.ExpandedFeature;
|
| 9280 |
amit.gupta |
15 |
import in.shop2020.metamodel.util.ExpertReviewPojo;
|
| 9218 |
amit.gupta |
16 |
import in.shop2020.metamodel.util.ItemPojo;
|
| 9280 |
amit.gupta |
17 |
import in.shop2020.metamodel.util.MediaPojo;
|
| 9218 |
amit.gupta |
18 |
import in.shop2020.metamodel.util.Specification;
|
|
|
19 |
import in.shop2020.metamodel.util.SpecificationGroup;
|
|
|
20 |
import in.shop2020.storage.mongo.StorageManager;
|
|
|
21 |
import in.shop2020.ui.util.NewVUI;
|
|
|
22 |
|
|
|
23 |
import java.text.MessageFormat;
|
|
|
24 |
import java.util.ArrayList;
|
|
|
25 |
import java.util.Arrays;
|
|
|
26 |
import java.util.Collection;
|
|
|
27 |
import java.util.List;
|
|
|
28 |
|
|
|
29 |
import org.apache.commons.lang.StringUtils;
|
|
|
30 |
import org.apache.commons.logging.Log;
|
|
|
31 |
import org.apache.commons.logging.LogFactory;
|
|
|
32 |
|
|
|
33 |
public class PojoCreator {
|
|
|
34 |
private static final String IMG_URL_TEMPLATE ="http://static{0}.saholic.com/images/media/{1}/{2}";
|
|
|
35 |
private static Log log = LogFactory.getLog(PojoCreator.class);
|
|
|
36 |
private static DefinitionsContainer defs = Catalog.getInstance().getDefinitionsContainer();
|
|
|
37 |
|
| 9280 |
amit.gupta |
38 |
public void createAndStoreContentPojo(ExpandedEntity expEntity, List<ExpertReview> expertReviews, String warranty){
|
| 9218 |
amit.gupta |
39 |
try {
|
| 9280 |
amit.gupta |
40 |
ContentPojo cp = new ContentPojo(EntityUtils.getProductName(expEntity), getKeySpecs(expEntity), getDetailedSpecs(expEntity), getWarranty());
|
|
|
41 |
if(expertReviews != null && expertReviews.size()!=0){
|
|
|
42 |
List<ExpertReviewPojo> erPojos = new ArrayList<ExpertReviewPojo>();
|
|
|
43 |
for(ExpertReview er : expertReviews){
|
|
|
44 |
ExpertReviewPojo erPojo = new ExpertReviewPojo();
|
|
|
45 |
erPojo.setSource(er.getSource());
|
|
|
46 |
erPojo.setReview(er.getReviewContent());
|
|
|
47 |
erPojos.add(erPojo);
|
|
|
48 |
}
|
|
|
49 |
cp.setExpertReviews(erPojos);
|
|
|
50 |
}
|
|
|
51 |
cp.setPackageContents(getPackageContents(expEntity));
|
|
|
52 |
cp.setWarranty(warranty);
|
|
|
53 |
cp.setUrl(EntityUtils.getEntityNoSlashURL(expEntity));
|
|
|
54 |
setImagesAndVideos(expEntity, cp);
|
| 9218 |
amit.gupta |
55 |
//StorageManager sm = StorageManager.getStorageManager();
|
| 9280 |
amit.gupta |
56 |
StorageManager.insertOrUpdateById(StorageManager.views.siteContent, expEntity.getID(), cp);
|
| 9218 |
amit.gupta |
57 |
} catch (Exception e){
|
| 9280 |
amit.gupta |
58 |
log.info("Could not generate Pojo for entity:" + expEntity.getID());
|
| 9218 |
amit.gupta |
59 |
e.printStackTrace();
|
|
|
60 |
}
|
|
|
61 |
}
|
|
|
62 |
|
|
|
63 |
private List<SpecificationGroup> getDetailedSpecs(Entity entity) throws Exception {
|
|
|
64 |
List<SpecificationGroup> spGroups = new ArrayList<SpecificationGroup>();
|
|
|
65 |
for (Slide slide : entity.getSlides()){
|
|
|
66 |
if(slide != null) {
|
|
|
67 |
long slideDefinitionId = slide.getSlideDefinitionID();
|
|
|
68 |
if(slideDefinitionId == 130054l || slideDefinitionId == 130001l || slideDefinitionId == 130025l) continue;
|
|
|
69 |
|
|
|
70 |
SlideDefinition slideDef = defs.getSlideDefinition(slideDefinitionId);
|
|
|
71 |
List<Specification> specs = new ArrayList<Specification>();
|
|
|
72 |
SpecificationGroup spGroup = new SpecificationGroup(slideDef.getLabel(), specs);
|
|
|
73 |
|
|
|
74 |
if(slideDefinitionId == 130043l){
|
|
|
75 |
List<String> values = new ArrayList<String>();
|
|
|
76 |
List<Slide> slides= slide.getChildrenSlides();
|
|
|
77 |
if(slides != null){
|
|
|
78 |
for(Slide sl : slides){
|
|
|
79 |
//For capacity slide
|
|
|
80 |
if ( sl.getSlideDefinitionID() == 130046l){
|
|
|
81 |
String one = "";
|
|
|
82 |
String two = "";
|
|
|
83 |
String three = "";
|
|
|
84 |
List<Slide> capacityChildren = sl.getChildrenSlides();
|
|
|
85 |
if(capacityChildren != null && capacityChildren.size()>0){
|
|
|
86 |
for(Slide capSlide : capacityChildren){
|
|
|
87 |
if (capSlide != null){
|
|
|
88 |
if(capSlide.getSlideDefinitionID() == 130048l){
|
|
|
89 |
one = "Talk time";
|
|
|
90 |
}else if (capSlide.getSlideDefinitionID() == 130049l){
|
|
|
91 |
one = "Standby time";
|
|
|
92 |
}
|
|
|
93 |
List<Feature> fs = capSlide.getFeatures();
|
|
|
94 |
List<String> values1 = new ArrayList<String>();
|
|
|
95 |
if(fs!=null){
|
|
|
96 |
for(Feature f: fs){
|
|
|
97 |
if (f != null){
|
|
|
98 |
ExpandedFeature expFeature = new ExpandedFeature(f);
|
|
|
99 |
two = expFeature.getFeatureDefinition().getLabel();
|
|
|
100 |
List<ExpandedBullet> expBullets = expFeature.getExpandedBullets();
|
|
|
101 |
if(expBullets != null){
|
|
|
102 |
for(ExpandedBullet bullet : expBullets){
|
|
|
103 |
if(bullet != null) {
|
|
|
104 |
three = bullet.displayText();
|
|
|
105 |
values1.add(MessageFormat.format(Utils.CAPACITY_TEMPLATE, one,two, three));
|
|
|
106 |
}
|
|
|
107 |
}
|
|
|
108 |
}
|
|
|
109 |
}
|
|
|
110 |
}
|
|
|
111 |
}
|
|
|
112 |
if(values1.size()>0){
|
|
|
113 |
values.add(StringUtils.join(values1,","));
|
|
|
114 |
}
|
|
|
115 |
}
|
|
|
116 |
}
|
|
|
117 |
}
|
|
|
118 |
List<Feature> capacityFeatures = sl.getFeatures();
|
|
|
119 |
if(capacityFeatures != null){
|
|
|
120 |
for(Feature f: capacityFeatures){
|
|
|
121 |
if (f != null){
|
|
|
122 |
ExpandedFeature expFeature = new ExpandedFeature(f);
|
|
|
123 |
String fLabel = expFeature.getFeatureDefinition().getLabel();
|
|
|
124 |
List<ExpandedBullet> expBullets = expFeature.getExpandedBullets();
|
|
|
125 |
List<String> bulletValuesList = new ArrayList<String>();
|
|
|
126 |
if(expBullets != null){
|
|
|
127 |
for(ExpandedBullet bullet : expBullets){
|
|
|
128 |
if(bullet != null) {
|
|
|
129 |
String value = bullet.displayText();
|
|
|
130 |
if(value != null && !value.trim().equals("")){
|
|
|
131 |
bulletValuesList.add(bullet.displayText());
|
|
|
132 |
}
|
|
|
133 |
}
|
|
|
134 |
}
|
|
|
135 |
}
|
|
|
136 |
if(bulletValuesList.size() > 0){
|
|
|
137 |
values.add(fLabel + " - " + StringUtils.join(bulletValuesList, ","));
|
|
|
138 |
}
|
|
|
139 |
}
|
|
|
140 |
}
|
|
|
141 |
}
|
|
|
142 |
if(values.size()>0){
|
|
|
143 |
Specification spec = new Specification("Capacity", values);
|
|
|
144 |
specs.add(spec);
|
|
|
145 |
}
|
|
|
146 |
}
|
|
|
147 |
}
|
|
|
148 |
}
|
|
|
149 |
}
|
|
|
150 |
for(Feature f : slide.getFeatures()) {
|
|
|
151 |
List<String> sb = new ArrayList<String>();
|
|
|
152 |
if (f != null){
|
|
|
153 |
ExpandedFeature expFeature = new ExpandedFeature(f);
|
|
|
154 |
expFeature.getFeatureDefinition().getLabel();
|
|
|
155 |
List<ExpandedBullet> expBullets = expFeature.getExpandedBullets();
|
|
|
156 |
if(expBullets != null){
|
|
|
157 |
for(ExpandedBullet bullet : expBullets){
|
|
|
158 |
if(bullet != null) {
|
|
|
159 |
String displayText = bullet.displayText();
|
|
|
160 |
if(!displayText.trim().equals("")){
|
|
|
161 |
sb.add(bullet.displayText());
|
|
|
162 |
}
|
|
|
163 |
}
|
|
|
164 |
}
|
|
|
165 |
}
|
|
|
166 |
if(sb.size()>0){
|
|
|
167 |
Specification spec = new Specification(expFeature.getFeatureDefinition().getLabel(), Arrays.asList(StringUtils.join(sb,",")));
|
|
|
168 |
specs.add(spec);
|
|
|
169 |
}
|
|
|
170 |
}
|
|
|
171 |
}
|
|
|
172 |
spGroups.add(spGroup);
|
|
|
173 |
}
|
|
|
174 |
}
|
|
|
175 |
return spGroups;
|
|
|
176 |
}
|
|
|
177 |
|
| 9280 |
amit.gupta |
178 |
private void setImagesAndVideos(Entity entity, ContentPojo cp) {
|
| 9218 |
amit.gupta |
179 |
|
|
|
180 |
String fileNamePrefix = EntityUtils.getMediaPrefix(entity);
|
| 9280 |
amit.gupta |
181 |
List<MediaPojo> images = new ArrayList<MediaPojo>();
|
|
|
182 |
List<MediaPojo> videos = new ArrayList<MediaPojo>();
|
| 9218 |
amit.gupta |
183 |
List<Slide> slides = entity.getSlides();
|
|
|
184 |
String entityNumber = entity.getID() + "";
|
|
|
185 |
if(slides!=null){
|
|
|
186 |
|
|
|
187 |
for(Slide slide : slides){
|
|
|
188 |
if (slide != null){
|
|
|
189 |
if(slide.getSlideDefinitionID() == 130054l){
|
|
|
190 |
Media m = slide.getFreeformContent().getMedias().get("default");
|
|
|
191 |
cp.setDefaultImageUrl(MessageFormat.format(IMG_URL_TEMPLATE, entity.getID()%3, entityNumber, NewVUI.computeNewFileName(fileNamePrefix, NewVUI.DEFAULT_JPG, String.valueOf(m.getCreationTime().getTime()))));
|
|
|
192 |
cp.setThumbnailImageUrl(MessageFormat.format(IMG_URL_TEMPLATE, entity.getID()%3, entityNumber, NewVUI.computeNewFileName(fileNamePrefix, NewVUI.THUMBNAIL_JPG, String.valueOf(m.getCreationTime().getTime()))));
|
|
|
193 |
cp.setIconImageUrl(MessageFormat.format(IMG_URL_TEMPLATE, entity.getID()%3, entityNumber, NewVUI.computeNewFileName(fileNamePrefix, NewVUI.ICON_JPG, String.valueOf(m.getCreationTime().getTime()))));
|
|
|
194 |
}
|
|
|
195 |
else if(slide.getFreeformContent() !=null && slide.getFreeformContent().getMedias() !=null){
|
|
|
196 |
Collection<Media> medias = slide.getFreeformContent().getMedias().values();
|
|
|
197 |
for (Media media : medias){
|
|
|
198 |
if(media.getType().equals(Media.Type.IMAGE)){
|
| 9280 |
amit.gupta |
199 |
MediaPojo ip = new MediaPojo(media.getLabel(), MessageFormat.format(IMG_URL_TEMPLATE, entity.getID()%3, entityNumber, NewVUI.computeNewFileName(fileNamePrefix, media.getFileName(), String.valueOf(media.getCreationTime().getTime()))));
|
| 9218 |
amit.gupta |
200 |
images.add(ip);
|
| 9280 |
amit.gupta |
201 |
}else if(media.getType().equals(Media.Type.VIDEO_WITH_SKIN) || media.getType().equals(Media.Type.VIDEO_WITH_SKIN)){
|
|
|
202 |
MediaPojo vp = new MediaPojo(media.getLabel(), media.getYoutubeId());
|
|
|
203 |
videos.add(vp);
|
| 9218 |
amit.gupta |
204 |
}
|
|
|
205 |
}
|
|
|
206 |
}
|
|
|
207 |
}
|
|
|
208 |
}
|
|
|
209 |
}
|
|
|
210 |
cp.setImages(images);
|
| 9280 |
amit.gupta |
211 |
cp.setVideos(videos);
|
| 9218 |
amit.gupta |
212 |
}
|
|
|
213 |
|
|
|
214 |
private String getWarranty() {
|
|
|
215 |
// TODO Auto-generated method stub
|
|
|
216 |
return null;
|
|
|
217 |
}
|
|
|
218 |
|
|
|
219 |
private List<String> getKeySpecs(Entity entity) throws Exception {
|
|
|
220 |
List<String> keySpecs = new ArrayList<String>();
|
|
|
221 |
Slide summarySlide = entity.getSlide(130054l);
|
|
|
222 |
List<Feature> summaryFeatures = summarySlide.getFeatures();
|
|
|
223 |
if(summaryFeatures != null){
|
|
|
224 |
for(Feature f : summaryFeatures) {
|
|
|
225 |
if(f.getFeatureDefinitionID()==120081l){
|
|
|
226 |
ExpandedFeature expFeature = new ExpandedFeature(f);
|
|
|
227 |
expFeature.getFeatureDefinition().getLabel();
|
|
|
228 |
List<ExpandedBullet> expBullets = expFeature.getExpandedBullets();
|
|
|
229 |
if(expBullets != null){
|
|
|
230 |
for(ExpandedBullet bullet : expBullets){
|
|
|
231 |
if(bullet != null) {
|
|
|
232 |
keySpecs.add(bullet.displayText());
|
|
|
233 |
}
|
|
|
234 |
}
|
|
|
235 |
}
|
|
|
236 |
break;
|
|
|
237 |
}
|
|
|
238 |
}
|
|
|
239 |
}
|
|
|
240 |
return keySpecs;
|
|
|
241 |
}
|
|
|
242 |
|
|
|
243 |
private List<String> getPackageContents(Entity entity){
|
|
|
244 |
List<String> packageContents = null;
|
|
|
245 |
Slide summarySlide = entity.getSlide(130025l);
|
|
|
246 |
List<String> freeformTexts = summarySlide.getFreeformContent().getFreeformTexts();
|
|
|
247 |
if(freeformTexts.size()>0){
|
|
|
248 |
packageContents = Arrays.asList(StringUtils.join(freeformTexts, "\r\n").split("\r\n"));
|
|
|
249 |
}
|
|
|
250 |
return packageContents;
|
|
|
251 |
}
|
|
|
252 |
|
|
|
253 |
public static void main (String [] args) throws Exception{
|
|
|
254 |
PojoCreator creator = new PojoCreator();
|
|
|
255 |
//System.out.println(creator.getShortContent(1007425l));
|
|
|
256 |
}
|
|
|
257 |
|
| 9280 |
amit.gupta |
258 |
public void updateCatalogInfo(long entityId, double sellingPrice, double mrp, String offerText, Double minEmi, List<ItemPojo> items) {
|
| 9218 |
amit.gupta |
259 |
ContentPojo cp = new ContentPojo(entityId);
|
|
|
260 |
cp.setPrice(sellingPrice);
|
| 9280 |
amit.gupta |
261 |
cp.setMinEmi(minEmi);
|
| 9218 |
amit.gupta |
262 |
cp.setMrp(mrp);
|
|
|
263 |
cp.setOfferText(offerText);
|
|
|
264 |
cp.setItems(items);
|
|
|
265 |
|
|
|
266 |
StorageManager.addById(StorageManager.views.siteContent, entityId, cp);
|
|
|
267 |
}
|
|
|
268 |
}
|