| 62 |
naveen |
1 |
/**
|
|
|
2 |
*
|
|
|
3 |
*/
|
|
|
4 |
package in.shop2020.util;
|
|
|
5 |
|
| 102 |
naveen |
6 |
import in.shop2020.metamodel.core.Bullet;
|
| 63 |
naveen |
7 |
import in.shop2020.metamodel.core.Entity;
|
|
|
8 |
import in.shop2020.metamodel.core.Feature;
|
| 102 |
naveen |
9 |
import in.shop2020.metamodel.core.PrimitiveDataObject;
|
| 63 |
naveen |
10 |
import in.shop2020.metamodel.core.Slide;
|
| 102 |
naveen |
11 |
import in.shop2020.metamodel.definitions.BulletDefinition;
|
| 63 |
naveen |
12 |
import in.shop2020.metamodel.definitions.Catalog;
|
| 64 |
naveen |
13 |
import in.shop2020.metamodel.definitions.Category;
|
| 83 |
naveen |
14 |
import in.shop2020.metamodel.definitions.DatatypeDefinition;
|
| 63 |
naveen |
15 |
import in.shop2020.metamodel.definitions.DefinitionsContainer;
|
|
|
16 |
import in.shop2020.metamodel.definitions.EntityContainer;
|
| 82 |
naveen |
17 |
import in.shop2020.metamodel.definitions.FacetDefinition;
|
| 88 |
naveen |
18 |
import in.shop2020.metamodel.definitions.FacetRuleDefinition;
|
| 63 |
naveen |
19 |
import in.shop2020.metamodel.definitions.FeatureDefinition;
|
|
|
20 |
import in.shop2020.metamodel.definitions.SlideDefinition;
|
| 67 |
naveen |
21 |
import in.shop2020.metamodel.util.ExpandedBullet;
|
| 83 |
naveen |
22 |
import in.shop2020.metamodel.util.ExpandedBulletDefinition;
|
| 63 |
naveen |
23 |
import in.shop2020.metamodel.util.ExpandedCategoryFacetDefinition;
|
| 64 |
naveen |
24 |
import in.shop2020.metamodel.util.ExpandedEntity;
|
| 82 |
naveen |
25 |
import in.shop2020.metamodel.util.ExpandedFacetDefinition;
|
| 81 |
naveen |
26 |
import in.shop2020.metamodel.util.ExpandedFacetRuleDefinition;
|
| 65 |
naveen |
27 |
import in.shop2020.metamodel.util.ExpandedFeature;
|
| 83 |
naveen |
28 |
import in.shop2020.metamodel.util.ExpandedFeatureDefinition;
|
| 65 |
naveen |
29 |
import in.shop2020.metamodel.util.ExpandedSlide;
|
| 451 |
rajveer |
30 |
import in.shop2020.model.v1.catalog.CatalogService.Client;
|
|
|
31 |
import in.shop2020.model.v1.catalog.Item;
|
|
|
32 |
import in.shop2020.thrift.clients.CatalogServiceClient;
|
| 63 |
naveen |
33 |
|
| 341 |
rajveer |
34 |
import java.io.File;
|
|
|
35 |
import java.io.FileOutputStream;
|
| 81 |
naveen |
36 |
import java.util.ArrayList;
|
| 91 |
naveen |
37 |
import java.util.HashMap;
|
| 81 |
naveen |
38 |
import java.util.List;
|
| 82 |
naveen |
39 |
import java.util.Map;
|
| 451 |
rajveer |
40 |
import java.util.Map.Entry;
|
| 81 |
naveen |
41 |
|
| 341 |
rajveer |
42 |
import javax.xml.transform.TransformerConfigurationException;
|
|
|
43 |
import javax.xml.transform.TransformerFactory;
|
|
|
44 |
import javax.xml.transform.Transformer;
|
|
|
45 |
import javax.xml.transform.stream.StreamResult;
|
|
|
46 |
import javax.xml.transform.stream.StreamSource;
|
|
|
47 |
|
| 81 |
naveen |
48 |
import org.apache.commons.lang.ArrayUtils;
|
|
|
49 |
import org.apache.commons.lang.StringEscapeUtils;
|
|
|
50 |
import org.apache.commons.lang.StringUtils;
|
|
|
51 |
|
| 341 |
rajveer |
52 |
|
| 62 |
naveen |
53 |
/**
|
|
|
54 |
* Command line utility to convert IR Definitions into IR Data and IR Meta-data
|
|
|
55 |
*
|
| 81 |
naveen |
56 |
* Usage: IR [irmetadata|irdata] {Category ID}
|
|
|
57 |
*
|
| 62 |
naveen |
58 |
* @author naveen
|
|
|
59 |
*
|
|
|
60 |
*/
|
|
|
61 |
public class IR {
|
| 63 |
naveen |
62 |
|
| 62 |
naveen |
63 |
/**
|
| 64 |
naveen |
64 |
*
|
|
|
65 |
*/
|
| 63 |
naveen |
66 |
private long categoryID;
|
|
|
67 |
|
|
|
68 |
/**
|
| 64 |
naveen |
69 |
* Level - 4, 8, 12, 16
|
|
|
70 |
*/
|
|
|
71 |
private String[] xmlIndentation = {"", " ", " ", " ",
|
|
|
72 |
" "};
|
| 83 |
naveen |
73 |
|
|
|
74 |
private String[] xmlTabIndentation = {"", "\t", "\t\t", "\t\t\t",
|
|
|
75 |
"\t\t\t\t", "\t\t\t\t\t", "\t\t\t\t\t\t"};
|
| 91 |
naveen |
76 |
|
|
|
77 |
private Map<Long, List<String>> facetIDFacetValues =
|
|
|
78 |
new HashMap<Long, List<String>>();
|
| 733 |
rajveer |
79 |
|
|
|
80 |
CatalogServiceClient catalogServiceClient = null;
|
|
|
81 |
in.shop2020.model.v1.catalog.InventoryService.Client client = null;
|
| 64 |
naveen |
82 |
|
|
|
83 |
/**
|
| 62 |
naveen |
84 |
* @param args
|
| 63 |
naveen |
85 |
* @throws Exception
|
| 62 |
naveen |
86 |
*/
|
| 63 |
naveen |
87 |
public static void main(String[] args) throws Exception {
|
| 81 |
naveen |
88 |
String[] commands = new String[] {"irmetadata", "irdata"};
|
| 62 |
naveen |
89 |
|
| 81 |
naveen |
90 |
String usage = "Usage: IR ["+ StringUtils.join(commands, "|") +
|
|
|
91 |
"] {Category ID}\n";
|
|
|
92 |
|
|
|
93 |
if(args.length < 1) {
|
| 63 |
naveen |
94 |
System.out.println(usage);
|
|
|
95 |
System.exit(-1);
|
|
|
96 |
}
|
| 81 |
naveen |
97 |
|
|
|
98 |
String inputCommand = args[0];
|
|
|
99 |
|
|
|
100 |
if(!ArrayUtils.contains(commands, inputCommand)) {
|
|
|
101 |
System.out.println(usage);
|
|
|
102 |
System.exit(-1);
|
|
|
103 |
}
|
| 64 |
naveen |
104 |
|
|
|
105 |
long categoryID = 0L;
|
| 81 |
naveen |
106 |
if(args.length > 1) {
|
| 64 |
naveen |
107 |
try {
|
| 81 |
naveen |
108 |
categoryID = Long.parseLong(args[1]);
|
| 64 |
naveen |
109 |
}
|
|
|
110 |
catch (NumberFormatException nfe) {
|
|
|
111 |
System.out.println(usage);
|
|
|
112 |
System.exit(-1);
|
|
|
113 |
}
|
| 63 |
naveen |
114 |
}
|
|
|
115 |
|
|
|
116 |
IR ir = new IR(categoryID);
|
| 81 |
naveen |
117 |
|
|
|
118 |
if (inputCommand.equals("irdata")) {
|
|
|
119 |
ir.exportIRData();
|
| 341 |
rajveer |
120 |
ir.transformIrDataXMLtoSolrXML();
|
| 81 |
naveen |
121 |
return;
|
|
|
122 |
}
|
|
|
123 |
|
|
|
124 |
if (inputCommand.equals("irmetadata")) {
|
|
|
125 |
ir.exportIRMetaData();
|
| 341 |
rajveer |
126 |
ir.transformIrMetaDataXMLSolrSchemaXML();
|
| 81 |
naveen |
127 |
return;
|
|
|
128 |
}
|
|
|
129 |
|
| 62 |
naveen |
130 |
}
|
| 63 |
naveen |
131 |
|
|
|
132 |
/**
|
|
|
133 |
*
|
|
|
134 |
* @param categoryID
|
| 733 |
rajveer |
135 |
* @throws Exception
|
| 63 |
naveen |
136 |
*/
|
| 733 |
rajveer |
137 |
public IR(long categoryID) throws Exception {
|
| 63 |
naveen |
138 |
this.categoryID = categoryID;
|
| 733 |
rajveer |
139 |
catalogServiceClient = new CatalogServiceClient();
|
|
|
140 |
client = catalogServiceClient.getClient();
|
| 63 |
naveen |
141 |
}
|
|
|
142 |
|
| 341 |
rajveer |
143 |
|
| 63 |
naveen |
144 |
/**
|
| 81 |
naveen |
145 |
*
|
| 341 |
rajveer |
146 |
* @param inXMLFilename
|
|
|
147 |
* @param xslFilename
|
|
|
148 |
* @param outXMLFilename
|
|
|
149 |
* @throws Exception
|
|
|
150 |
*/
|
|
|
151 |
|
|
|
152 |
public void xsltTransformation(String inXMLFilename, String xslFilename, String outXMLFilename) throws Exception{
|
|
|
153 |
// Use the static TransformerFactory.newInstance() method to instantiate
|
|
|
154 |
// a TransformerFactory. The javax.xml.transform.TransformerFactory
|
|
|
155 |
// system property setting determines the actual class to instantiate --
|
|
|
156 |
// org.apache.xalan.transformer.TransformerImpl.
|
|
|
157 |
TransformerFactory tFactory = TransformerFactory.newInstance();
|
|
|
158 |
|
|
|
159 |
// Use the TransformerFactory to instantiate a Transformer that will work with
|
|
|
160 |
// the stylesheet you specify. This method call also processes the stylesheet
|
|
|
161 |
// into a compiled Templates object.
|
|
|
162 |
Transformer transformer = tFactory.newTransformer(new StreamSource(xslFilename));
|
|
|
163 |
|
|
|
164 |
// Use the Transformer to apply the associated Templates object to an XML document
|
|
|
165 |
// (foo.xml) and write the output to a file (foo.out).
|
|
|
166 |
transformer.transform(new StreamSource(inXMLFilename), new StreamResult(new FileOutputStream(outXMLFilename)));
|
|
|
167 |
|
|
|
168 |
}
|
|
|
169 |
|
|
|
170 |
/**
|
|
|
171 |
*
|
| 81 |
naveen |
172 |
* @throws Exception
|
|
|
173 |
*/
|
| 341 |
rajveer |
174 |
public void transformIrDataXMLtoSolrXML() throws Exception {
|
|
|
175 |
String irDataFilename = Utils.EXPORT_IR_PATH + "irdata.xml";
|
|
|
176 |
String irSolrDataFilename = Utils.EXPORT_SOLR_PATH + "irdata_solr.xml";
|
|
|
177 |
String irXslFilename = "src/xsl/irdata_solrdata.xsl";
|
|
|
178 |
System.out.println(irSolrDataFilename);
|
|
|
179 |
File solrFile = new File(irSolrDataFilename);
|
|
|
180 |
if(!solrFile.exists()){
|
|
|
181 |
solrFile.createNewFile();
|
|
|
182 |
}
|
|
|
183 |
xsltTransformation(irDataFilename, irXslFilename, irSolrDataFilename);
|
|
|
184 |
}
|
|
|
185 |
|
|
|
186 |
|
|
|
187 |
/**
|
|
|
188 |
*
|
|
|
189 |
* @throws Exception
|
|
|
190 |
*/
|
|
|
191 |
public void transformIrMetaDataXMLSolrSchemaXML() throws Exception {
|
|
|
192 |
String irDataFilename = Utils.EXPORT_IR_PATH + "irmetadata.xml";
|
|
|
193 |
String irSolrDataFilename = Utils.EXPORT_SOLR_PATH + "irmetadata_solrschema.xml";
|
|
|
194 |
String irXslFilename = "src/xsl/irmetadata_solrschema.xsl";
|
|
|
195 |
System.out.println(irSolrDataFilename);
|
|
|
196 |
File solrFile = new File(irSolrDataFilename);
|
|
|
197 |
if(!solrFile.exists()){
|
|
|
198 |
solrFile.createNewFile();
|
|
|
199 |
}
|
|
|
200 |
xsltTransformation(irDataFilename, irXslFilename, irSolrDataFilename);
|
|
|
201 |
}
|
|
|
202 |
|
|
|
203 |
|
|
|
204 |
|
|
|
205 |
/**
|
|
|
206 |
*
|
|
|
207 |
* @throws Exception
|
|
|
208 |
*/
|
| 81 |
naveen |
209 |
public void exportIRMetaData() throws Exception {
|
|
|
210 |
DefinitionsContainer defs =
|
|
|
211 |
Catalog.getInstance().getDefinitionsContainer();
|
| 82 |
naveen |
212 |
|
| 81 |
naveen |
213 |
// <IRMetaData>
|
| 82 |
naveen |
214 |
List<String> xmlSnippets = new ArrayList<String>();
|
|
|
215 |
xmlSnippets.add("<IRMetaData>");
|
| 83 |
naveen |
216 |
xmlSnippets.add("\t<Facets>");
|
| 81 |
naveen |
217 |
|
| 82 |
naveen |
218 |
IRMetaDataJythonWrapper jy = new IRMetaDataJythonWrapper();
|
| 81 |
naveen |
219 |
|
| 83 |
naveen |
220 |
List<Long> facetFeatures = new ArrayList<Long>();
|
|
|
221 |
|
| 81 |
naveen |
222 |
// Iterate over all facet definitions
|
| 82 |
naveen |
223 |
Map<Long, FacetDefinition> facetDefs = defs.getFacetDefinitions();
|
|
|
224 |
for(FacetDefinition facetDef : facetDefs.values()) {
|
|
|
225 |
|
|
|
226 |
jy.reset();
|
|
|
227 |
jy.initialize();
|
|
|
228 |
|
|
|
229 |
ExpandedFacetDefinition expFacetDef =
|
|
|
230 |
new ExpandedFacetDefinition(facetDef);
|
|
|
231 |
|
|
|
232 |
jy.setExpandedFacetDefinition(expFacetDef);
|
|
|
233 |
|
|
|
234 |
jy.executeRule();
|
|
|
235 |
|
|
|
236 |
String facetXMLSnip = jy.getXMLSnippet();
|
|
|
237 |
Utils.info("facetXMLSnip=" + facetXMLSnip);
|
|
|
238 |
|
|
|
239 |
xmlSnippets.add(facetXMLSnip);
|
| 83 |
naveen |
240 |
|
|
|
241 |
facetFeatures.add(new Long(expFacetDef.getFeatureDefinitionID()));
|
| 82 |
naveen |
242 |
}
|
| 83 |
naveen |
243 |
xmlSnippets.add("\t</Facets>");
|
| 81 |
naveen |
244 |
|
| 83 |
naveen |
245 |
Utils.info("facetFeatures=" + facetFeatures);
|
|
|
246 |
|
|
|
247 |
xmlSnippets.add("\n\t<Properties>");
|
|
|
248 |
|
| 81 |
naveen |
249 |
// Iterate over all feature definitions
|
| 83 |
naveen |
250 |
Map<Long, FeatureDefinition> featureDefs = defs.getFeatureDefinitions();
|
|
|
251 |
for(FeatureDefinition featureDef : featureDefs.values()) {
|
|
|
252 |
if(facetFeatures.contains(new Long(featureDef.getID()))) {
|
|
|
253 |
// Ignore, is already covered as facet
|
|
|
254 |
continue;
|
|
|
255 |
}
|
|
|
256 |
String propertyXMLSnip = this.getPropertyXMLSnippet(featureDef);
|
|
|
257 |
Utils.info("propertyXMLSnip=" + propertyXMLSnip);
|
|
|
258 |
|
|
|
259 |
xmlSnippets.add(propertyXMLSnip);
|
|
|
260 |
}
|
| 81 |
naveen |
261 |
|
| 83 |
naveen |
262 |
xmlSnippets.add("\t</Properties>");
|
|
|
263 |
|
|
|
264 |
xmlSnippets.add("\n\t<Categories>");
|
|
|
265 |
|
|
|
266 |
// Iterate over all categories
|
| 580 |
rajveer |
267 |
/*
|
| 83 |
naveen |
268 |
Category rootCategory = defs.getCategory(10000);
|
|
|
269 |
List<Category> children = rootCategory.getChildrenCategory();
|
|
|
270 |
for (Category child : children) {
|
| 516 |
rajveer |
271 |
|
| 83 |
naveen |
272 |
String categoryXMLSnip = this.getCategoryXMLSnippet(child, 2);
|
|
|
273 |
Utils.info("categoryXMLSnip=" + categoryXMLSnip);
|
|
|
274 |
|
|
|
275 |
xmlSnippets.add(categoryXMLSnip);
|
|
|
276 |
}
|
| 580 |
rajveer |
277 |
*/
|
|
|
278 |
|
|
|
279 |
Category rootCategory = defs.getCategory(10000);
|
|
|
280 |
String categoryXMLSnip = this.getCategoryXMLSnippet(rootCategory, 2);
|
|
|
281 |
Utils.info("categoryXMLSnip=" + categoryXMLSnip);
|
|
|
282 |
|
|
|
283 |
xmlSnippets.add(categoryXMLSnip);
|
|
|
284 |
|
|
|
285 |
|
| 83 |
naveen |
286 |
xmlSnippets.add("\t</Categories>");
|
|
|
287 |
|
| 81 |
naveen |
288 |
// </IRMetaData>
|
| 82 |
naveen |
289 |
xmlSnippets.add("</IRMetaData>");
|
| 81 |
naveen |
290 |
|
| 82 |
naveen |
291 |
String irMetaDataXML = StringUtils.join(xmlSnippets, "\n");
|
| 81 |
naveen |
292 |
Utils.info(irMetaDataXML);
|
|
|
293 |
|
|
|
294 |
// Write it to file
|
|
|
295 |
String irMetaDataFilename = Utils.EXPORT_IR_PATH + "irmetadata.xml";
|
|
|
296 |
DBUtils.store(irMetaDataXML, irMetaDataFilename);
|
|
|
297 |
}
|
|
|
298 |
|
|
|
299 |
/**
|
| 83 |
naveen |
300 |
*
|
|
|
301 |
* @param category
|
|
|
302 |
* @return
|
| 63 |
naveen |
303 |
* @throws Exception
|
| 83 |
naveen |
304 |
*/
|
|
|
305 |
private String getCategoryXMLSnippet(Category category, int indent)
|
|
|
306 |
throws Exception {
|
|
|
307 |
|
|
|
308 |
DefinitionsContainer defs =
|
|
|
309 |
Catalog.getInstance().getDefinitionsContainer();
|
|
|
310 |
|
|
|
311 |
String xmlSnip = this.xmlTabIndentation[indent] + "<Category";
|
|
|
312 |
|
|
|
313 |
xmlSnip += " ID=\"" + category.getID() + "\"";
|
|
|
314 |
xmlSnip += " label=\"" + category.getLabel() + "\"";
|
|
|
315 |
xmlSnip += ">\n";
|
|
|
316 |
|
|
|
317 |
List<Category> children = category.getChildrenCategory();
|
|
|
318 |
|
|
|
319 |
if(children != null) {
|
|
|
320 |
for(Category child : children) {
|
|
|
321 |
xmlSnip += this.getCategoryXMLSnippet(child, indent+1);
|
|
|
322 |
}
|
|
|
323 |
}
|
|
|
324 |
else {
|
|
|
325 |
// Only leaf category will have entities
|
|
|
326 |
// Facet IDs
|
|
|
327 |
xmlSnip += this.xmlTabIndentation[indent+1] + "<Facets>\n";
|
|
|
328 |
|
|
|
329 |
List<Long> facetDefIDs =
|
|
|
330 |
defs.getFacetDefinitionIDs(category.getID());
|
|
|
331 |
Utils.info("facetDefIDs=" + facetDefIDs);
|
|
|
332 |
|
| 516 |
rajveer |
333 |
|
|
|
334 |
|
|
|
335 |
if( facetDefIDs != null && !facetDefIDs.isEmpty() ){
|
|
|
336 |
for(Long facetDefID : facetDefIDs) {
|
|
|
337 |
xmlSnip += this.xmlTabIndentation[indent+2] +
|
|
|
338 |
"<FacetID>" + facetDefID + "</FacetID>\n";
|
|
|
339 |
}
|
| 83 |
naveen |
340 |
}
|
|
|
341 |
|
| 516 |
rajveer |
342 |
|
| 83 |
naveen |
343 |
xmlSnip += this.xmlTabIndentation[indent+1] + "</Facets>\n\n";
|
|
|
344 |
|
|
|
345 |
// Feature IDs
|
|
|
346 |
xmlSnip += this.xmlTabIndentation[indent+1] + "<Properties>\n";
|
|
|
347 |
|
|
|
348 |
List<Long> featureDefIDs =
|
|
|
349 |
defs.getFeatureDefinitionIDs(category.getID());
|
|
|
350 |
Utils.info("featureDefIDs=" + featureDefIDs);
|
|
|
351 |
|
|
|
352 |
for(Long featureDefID : featureDefIDs) {
|
|
|
353 |
xmlSnip += this.xmlTabIndentation[indent+2] +
|
|
|
354 |
"<FeatureID>" + featureDefID + "</FeatureID>\n";
|
|
|
355 |
}
|
|
|
356 |
|
|
|
357 |
xmlSnip += this.xmlTabIndentation[indent+1] + "</Properties>\n";
|
|
|
358 |
}
|
|
|
359 |
|
|
|
360 |
xmlSnip += this.xmlTabIndentation[indent] + "</Category>\n";
|
|
|
361 |
|
|
|
362 |
return xmlSnip;
|
|
|
363 |
}
|
|
|
364 |
|
|
|
365 |
/**
|
| 63 |
naveen |
366 |
*
|
| 83 |
naveen |
367 |
* @param featureDef
|
|
|
368 |
* @return
|
|
|
369 |
* @throws Exception
|
| 63 |
naveen |
370 |
*/
|
| 83 |
naveen |
371 |
private String getPropertyXMLSnippet(FeatureDefinition featureDef)
|
|
|
372 |
throws Exception {
|
|
|
373 |
String xmlSnip = "\t\t<Property";
|
|
|
374 |
|
|
|
375 |
xmlSnip += " ID=\"" + featureDef.getID() + "\"";
|
|
|
376 |
xmlSnip += " label=\"" + featureDef.getLabel() + "\"";
|
|
|
377 |
|
|
|
378 |
ExpandedFeatureDefinition expFeatureDef =
|
|
|
379 |
new ExpandedFeatureDefinition(featureDef);
|
|
|
380 |
|
|
|
381 |
ExpandedBulletDefinition expBulletDef =
|
|
|
382 |
expFeatureDef.getExpandedBulletDefinition();
|
|
|
383 |
|
|
|
384 |
String datatype = "string";
|
|
|
385 |
if(expBulletDef.isComposite() || expBulletDef.isEnumerated()) {
|
|
|
386 |
datatype = "string";
|
|
|
387 |
}
|
|
|
388 |
else {
|
|
|
389 |
DatatypeDefinition datatypeDef =
|
|
|
390 |
expBulletDef.getDatatypeDefinition();
|
|
|
391 |
|
|
|
392 |
datatype = datatypeDef.getName();
|
|
|
393 |
|
|
|
394 |
// REVISIT
|
|
|
395 |
if(datatype.equals("hours_mins") || datatype.equals("days_hours") ||
|
|
|
396 |
datatype.equals("hours_mins") ||
|
|
|
397 |
datatype.equals("days_hours")) {
|
|
|
398 |
datatype = "string";
|
|
|
399 |
}
|
|
|
400 |
}
|
|
|
401 |
xmlSnip += " datatype=\"" + datatype + "\"";
|
|
|
402 |
|
|
|
403 |
String multivalue = "false";
|
|
|
404 |
if (expBulletDef.isMultivalue()) {
|
|
|
405 |
multivalue = "true";
|
|
|
406 |
}
|
|
|
407 |
xmlSnip += " isMultivalue=\"" + multivalue + "\"";
|
|
|
408 |
|
|
|
409 |
xmlSnip += "/>";
|
|
|
410 |
return xmlSnip;
|
|
|
411 |
}
|
|
|
412 |
|
|
|
413 |
/**
|
|
|
414 |
* @throws Exception
|
|
|
415 |
*
|
|
|
416 |
*/
|
| 63 |
naveen |
417 |
public void exportIRData() throws Exception {
|
|
|
418 |
DefinitionsContainer defs =
|
|
|
419 |
Catalog.getInstance().getDefinitionsContainer();
|
|
|
420 |
|
|
|
421 |
EntityContainer ents =
|
|
|
422 |
Catalog.getInstance().getEntityContainer();
|
|
|
423 |
|
| 733 |
rajveer |
424 |
|
|
|
425 |
|
| 64 |
naveen |
426 |
// <IRData>
|
|
|
427 |
List<String> entityXMLSnippets = new ArrayList<String>();
|
|
|
428 |
entityXMLSnippets.add("<IRData>");
|
| 63 |
naveen |
429 |
|
| 64 |
naveen |
430 |
List<Category> categories = null;
|
|
|
431 |
if(this.categoryID != 0L) {
|
|
|
432 |
categories = new ArrayList<Category>();
|
|
|
433 |
categories.add(defs.getCategory(this.categoryID));
|
|
|
434 |
}
|
|
|
435 |
else {
|
|
|
436 |
// Get all categories
|
|
|
437 |
categories = defs.getChildrenCategories(10001);
|
|
|
438 |
}
|
| 63 |
naveen |
439 |
|
| 580 |
rajveer |
440 |
int i=0;
|
| 64 |
naveen |
441 |
for(Category cat : categories) {
|
|
|
442 |
long catID = cat.getID();
|
| 580 |
rajveer |
443 |
if(i>0){
|
|
|
444 |
continue;
|
|
|
445 |
}
|
|
|
446 |
i++;
|
| 64 |
naveen |
447 |
// Get all facets for the category
|
|
|
448 |
ExpandedCategoryFacetDefinition expCategoryFacetDef =
|
|
|
449 |
defs.getExpandedCategoryFacetDefinition(catID);
|
|
|
450 |
|
| 81 |
naveen |
451 |
List<ExpandedFacetRuleDefinition> expFacetRuleDefs =
|
|
|
452 |
expCategoryFacetDef.getExpandedFacetRuleDefinitions();
|
| 64 |
naveen |
453 |
|
|
|
454 |
// Get all entities for the category
|
|
|
455 |
List<Entity> entities = ents.getEntities(catID);
|
|
|
456 |
|
|
|
457 |
if(entities == null) {
|
|
|
458 |
continue;
|
|
|
459 |
}
|
|
|
460 |
|
| 516 |
rajveer |
461 |
|
|
|
462 |
//Modified by Rajveer, Now it will search according to each catalog item.
|
|
|
463 |
// For each entity in catalog
|
|
|
464 |
|
| 733 |
rajveer |
465 |
|
| 516 |
rajveer |
466 |
List<Item> items = client.getAllItems(false);
|
|
|
467 |
|
|
|
468 |
for(Item item : items){
|
|
|
469 |
long entityID = item.getCatalogItemId();
|
|
|
470 |
ExpandedEntity expEntity =
|
|
|
471 |
ents.getExpandedEntity(entityID);
|
|
|
472 |
//Skip if entity doesnt exist
|
|
|
473 |
if(expEntity == null){
|
|
|
474 |
continue;
|
|
|
475 |
}
|
|
|
476 |
List<String> facetXMLSnippets = new ArrayList<String>();
|
|
|
477 |
|
|
|
478 |
// Collect features which have become FACETs
|
|
|
479 |
List<Long> facetFeatureIDs = new ArrayList<Long>();
|
|
|
480 |
|
|
|
481 |
// For each facet execute Rule
|
|
|
482 |
for(ExpandedFacetRuleDefinition expFacetRuleDef :
|
|
|
483 |
expFacetRuleDefs) {
|
|
|
484 |
String facetXMLSnip =
|
|
|
485 |
this.processFacet(expEntity, expFacetRuleDef);
|
|
|
486 |
|
|
|
487 |
if(facetXMLSnip != null &&
|
|
|
488 |
!StringUtils.trim(facetXMLSnip).isEmpty()) {
|
|
|
489 |
facetXMLSnippets.add(facetXMLSnip);
|
|
|
490 |
Utils.info("1 facetXMLSnip=" + facetXMLSnip);
|
|
|
491 |
}
|
|
|
492 |
|
|
|
493 |
// Collect features already covered as Facet
|
|
|
494 |
if(expFacetRuleDef.getFeatureDefinition() != null) {
|
|
|
495 |
facetFeatureIDs.add(new Long(
|
|
|
496 |
expFacetRuleDef.getFeatureDefinitionID()));
|
|
|
497 |
}
|
|
|
498 |
}
|
|
|
499 |
Entity entity = Catalog.getInstance().getEntityContainer().getEntity(entityID);
|
|
|
500 |
// Handle borrowed slides
|
|
|
501 |
List<Slide> borrowedSlides = ents.getBorrowedSlides(entity);
|
|
|
502 |
|
|
|
503 |
for (Slide borrowedSlide : borrowedSlides) {
|
|
|
504 |
if(borrowedSlide.getBorrowedCategoryID() == -1){
|
|
|
505 |
continue;
|
|
|
506 |
}
|
|
|
507 |
String facetXMLSnip = this.processBorrowedSlide(expEntity,
|
|
|
508 |
borrowedSlide);
|
|
|
509 |
|
|
|
510 |
if(facetXMLSnip != null &&
|
|
|
511 |
!StringUtils.trim(facetXMLSnip).isEmpty()) {
|
|
|
512 |
facetXMLSnippets.add(facetXMLSnip);
|
|
|
513 |
}
|
|
|
514 |
|
|
|
515 |
Utils.info("2 facetXMLSnip=" + facetXMLSnip);
|
|
|
516 |
}
|
|
|
517 |
|
|
|
518 |
String facetXMLSnippetsStr =
|
|
|
519 |
StringUtils.join(facetXMLSnippets, "\n");
|
|
|
520 |
|
|
|
521 |
Utils.info("facetXMLSnippetsStr=" + facetXMLSnippetsStr);
|
|
|
522 |
|
|
|
523 |
// Collect PROPERTIES
|
|
|
524 |
String propertiesXMLSnippetsStr =
|
|
|
525 |
this.getPropertiesXMLSnippet(expEntity, facetFeatureIDs, 2);
|
|
|
526 |
|
|
|
527 |
Utils.info(propertiesXMLSnippetsStr);
|
|
|
528 |
|
|
|
529 |
String entityXMLSnip = this.getEntityXMLSnippet(expEntity,
|
|
|
530 |
facetXMLSnippetsStr, propertiesXMLSnippetsStr, 1);
|
|
|
531 |
|
|
|
532 |
Utils.info(entityXMLSnip);
|
|
|
533 |
|
|
|
534 |
entityXMLSnippets.add(entityXMLSnip);
|
|
|
535 |
}
|
|
|
536 |
}
|
|
|
537 |
|
|
|
538 |
|
|
|
539 |
/*
|
| 64 |
naveen |
540 |
// For each entity
|
| 63 |
naveen |
541 |
for(Entity entity : entities) {
|
| 64 |
naveen |
542 |
ExpandedEntity expEntity =
|
|
|
543 |
ents.getExpandedEntity(entity.getID());
|
| 346 |
rajveer |
544 |
//Skip if entity doesnt exist
|
|
|
545 |
if(expEntity == null){
|
|
|
546 |
continue;
|
|
|
547 |
}
|
| 64 |
naveen |
548 |
List<String> facetXMLSnippets = new ArrayList<String>();
|
|
|
549 |
|
| 88 |
naveen |
550 |
// Collect features which have become FACETs
|
| 67 |
naveen |
551 |
List<Long> facetFeatureIDs = new ArrayList<Long>();
|
|
|
552 |
|
| 63 |
naveen |
553 |
// For each facet execute Rule
|
| 81 |
naveen |
554 |
for(ExpandedFacetRuleDefinition expFacetRuleDef :
|
|
|
555 |
expFacetRuleDefs) {
|
| 64 |
naveen |
556 |
String facetXMLSnip =
|
| 81 |
naveen |
557 |
this.processFacet(expEntity, expFacetRuleDef);
|
| 63 |
naveen |
558 |
|
| 88 |
naveen |
559 |
if(facetXMLSnip != null &&
|
|
|
560 |
!StringUtils.trim(facetXMLSnip).isEmpty()) {
|
| 64 |
naveen |
561 |
facetXMLSnippets.add(facetXMLSnip);
|
| 88 |
naveen |
562 |
Utils.info("1 facetXMLSnip=" + facetXMLSnip);
|
| 63 |
naveen |
563 |
}
|
| 67 |
naveen |
564 |
|
|
|
565 |
// Collect features already covered as Facet
|
| 81 |
naveen |
566 |
if(expFacetRuleDef.getFeatureDefinition() != null) {
|
| 88 |
naveen |
567 |
facetFeatureIDs.add(new Long(
|
|
|
568 |
expFacetRuleDef.getFeatureDefinitionID()));
|
| 67 |
naveen |
569 |
}
|
| 63 |
naveen |
570 |
}
|
|
|
571 |
|
| 88 |
naveen |
572 |
// Handle borrowed slides
|
|
|
573 |
List<Slide> borrowedSlides = ents.getBorrowedSlides(entity);
|
|
|
574 |
|
|
|
575 |
for (Slide borrowedSlide : borrowedSlides) {
|
|
|
576 |
String facetXMLSnip = this.processBorrowedSlide(expEntity,
|
|
|
577 |
borrowedSlide);
|
|
|
578 |
|
|
|
579 |
if(facetXMLSnip != null &&
|
|
|
580 |
!StringUtils.trim(facetXMLSnip).isEmpty()) {
|
|
|
581 |
facetXMLSnippets.add(facetXMLSnip);
|
|
|
582 |
}
|
|
|
583 |
|
|
|
584 |
Utils.info("2 facetXMLSnip=" + facetXMLSnip);
|
|
|
585 |
}
|
|
|
586 |
|
| 64 |
naveen |
587 |
String facetXMLSnippetsStr =
|
|
|
588 |
StringUtils.join(facetXMLSnippets, "\n");
|
|
|
589 |
|
| 88 |
naveen |
590 |
Utils.info("facetXMLSnippetsStr=" + facetXMLSnippetsStr);
|
| 64 |
naveen |
591 |
|
| 67 |
naveen |
592 |
// Collect PROPERTIES
|
|
|
593 |
String propertiesXMLSnippetsStr =
|
|
|
594 |
this.getPropertiesXMLSnippet(expEntity, facetFeatureIDs, 2);
|
| 64 |
naveen |
595 |
|
| 67 |
naveen |
596 |
Utils.info(propertiesXMLSnippetsStr);
|
|
|
597 |
|
|
|
598 |
String entityXMLSnip = this.getEntityXMLSnippet(expEntity,
|
|
|
599 |
facetXMLSnippetsStr, propertiesXMLSnippetsStr, 1);
|
|
|
600 |
|
| 64 |
naveen |
601 |
Utils.info(entityXMLSnip);
|
|
|
602 |
|
|
|
603 |
entityXMLSnippets.add(entityXMLSnip);
|
| 63 |
naveen |
604 |
}
|
|
|
605 |
}
|
| 516 |
rajveer |
606 |
*/
|
|
|
607 |
|
| 64 |
naveen |
608 |
// </IRData>
|
|
|
609 |
entityXMLSnippets.add("</IRData>");
|
|
|
610 |
|
|
|
611 |
String irDataXML = StringUtils.join(entityXMLSnippets, "\n");
|
|
|
612 |
Utils.info(irDataXML);
|
|
|
613 |
|
|
|
614 |
// Write it to file
|
| 70 |
naveen |
615 |
String irDataFilename = Utils.EXPORT_IR_PATH + "irdata.xml";
|
| 64 |
naveen |
616 |
DBUtils.store(irDataXML, irDataFilename);
|
| 91 |
naveen |
617 |
|
|
|
618 |
// Store facet values
|
| 457 |
rajveer |
619 |
String facetValuesFilename = Utils.CONTENT_DB_PATH + "entities" + File.separator + "facetvalues.ser";
|
| 91 |
naveen |
620 |
|
|
|
621 |
Utils.info("this.facetIDFacetValues=" + this.facetIDFacetValues);
|
|
|
622 |
DBUtils.store(this.facetIDFacetValues, facetValuesFilename);
|
| 63 |
naveen |
623 |
}
|
| 64 |
naveen |
624 |
|
|
|
625 |
/**
|
|
|
626 |
*
|
| 88 |
naveen |
627 |
* @param borrowedSlides
|
|
|
628 |
* @return
|
|
|
629 |
*/
|
|
|
630 |
private String processBorrowedSlide(ExpandedEntity expEntity,
|
|
|
631 |
Slide borrowedSlide) throws Exception {
|
|
|
632 |
// Borrowed category ID
|
|
|
633 |
long borrowedCategoryID = borrowedSlide.getBorrowedCategoryID();
|
|
|
634 |
Utils.info("borrowedCategoryID=" + borrowedCategoryID);
|
|
|
635 |
|
|
|
636 |
// Slide definition ID
|
|
|
637 |
long slideDefID = borrowedSlide.getSlideDefinitionID();
|
|
|
638 |
Utils.info("borrowed slideDefID=" + slideDefID);
|
|
|
639 |
|
|
|
640 |
DefinitionsContainer defs =
|
|
|
641 |
Catalog.getInstance().getDefinitionsContainer();
|
|
|
642 |
|
|
|
643 |
// Get IR Data Rule
|
|
|
644 |
FacetRuleDefinition facetRuleDef =
|
|
|
645 |
defs.getFacetRuleDefinitionForSlide(borrowedCategoryID, slideDefID);
|
|
|
646 |
|
|
|
647 |
Utils.info("borrowed facetRuleDef=" + facetRuleDef);
|
|
|
648 |
String facetXMLSnippet = null;
|
|
|
649 |
|
|
|
650 |
// If there is direct IR data rule defined for borrowed slide
|
|
|
651 |
if(facetRuleDef != null) {
|
|
|
652 |
ExpandedFacetRuleDefinition expFacetRuleDef =
|
|
|
653 |
new ExpandedFacetRuleDefinition(facetRuleDef);
|
|
|
654 |
|
|
|
655 |
// Return XML snippet
|
|
|
656 |
facetXMLSnippet = this.processFacet(expEntity, expFacetRuleDef);
|
|
|
657 |
}
|
|
|
658 |
else {
|
|
|
659 |
List<String> facetXMLSnippets = new ArrayList<String>();
|
|
|
660 |
|
|
|
661 |
// Get FacetRuleDefinition objects for all features in
|
|
|
662 |
// borrowed slide for which IR rule is defined
|
|
|
663 |
List<Feature> features = borrowedSlide.getFeatures();
|
|
|
664 |
for (Feature feature : features) {
|
|
|
665 |
String featureFacetXMLSnippet =
|
|
|
666 |
this.processBorrowedFeature(borrowedCategoryID, expEntity,
|
|
|
667 |
feature);
|
|
|
668 |
|
|
|
669 |
if(featureFacetXMLSnippet != null && !StringUtils.trim(
|
|
|
670 |
featureFacetXMLSnippet).isEmpty()) {
|
|
|
671 |
facetXMLSnippets.add(featureFacetXMLSnippet);
|
|
|
672 |
}
|
|
|
673 |
}
|
|
|
674 |
|
|
|
675 |
// Get FacetRuleDefinition objects for all children slides in
|
|
|
676 |
// borrowed slide for which IR rule is defined
|
|
|
677 |
if(borrowedSlide.hasChildrenSlides()) {
|
|
|
678 |
String childrenSlidesFacetXMLSnippet =
|
|
|
679 |
this.processBorrowedChildrenSlides(borrowedCategoryID,
|
|
|
680 |
expEntity, borrowedSlide);
|
|
|
681 |
|
|
|
682 |
if(childrenSlidesFacetXMLSnippet != null && !StringUtils.trim(
|
|
|
683 |
childrenSlidesFacetXMLSnippet).isEmpty()) {
|
|
|
684 |
facetXMLSnippets.add(childrenSlidesFacetXMLSnippet);
|
|
|
685 |
}
|
|
|
686 |
}
|
|
|
687 |
|
|
|
688 |
facetXMLSnippet = StringUtils.join(facetXMLSnippets, "\n");
|
|
|
689 |
}
|
|
|
690 |
|
|
|
691 |
if(StringUtils.trim(facetXMLSnippet).isEmpty()) {
|
|
|
692 |
return null;
|
|
|
693 |
}
|
|
|
694 |
|
|
|
695 |
return facetXMLSnippet;
|
|
|
696 |
}
|
|
|
697 |
|
|
|
698 |
/**
|
|
|
699 |
*
|
|
|
700 |
* @param borrowedCategoryID
|
| 64 |
naveen |
701 |
* @param expEntity
|
| 88 |
naveen |
702 |
* @param feature
|
|
|
703 |
* @return
|
|
|
704 |
* @throws Exception
|
|
|
705 |
*/
|
|
|
706 |
private String processBorrowedFeature(long borrowedCategoryID,
|
|
|
707 |
ExpandedEntity expEntity, Feature feature) throws Exception {
|
|
|
708 |
|
|
|
709 |
long featureDefID = feature.getFeatureDefinitionID();
|
|
|
710 |
Utils.info("borrowed featureDefID=" + featureDefID);
|
|
|
711 |
|
|
|
712 |
DefinitionsContainer defs =
|
|
|
713 |
Catalog.getInstance().getDefinitionsContainer();
|
|
|
714 |
|
|
|
715 |
FacetRuleDefinition facetRuleDefForFeature =
|
|
|
716 |
defs.getFacetRuleDefinitionForFeature(borrowedCategoryID,
|
|
|
717 |
featureDefID);
|
|
|
718 |
|
|
|
719 |
List<String> facetXMLSnippets = new ArrayList<String>();
|
|
|
720 |
|
|
|
721 |
Utils.info("borrowed facetRuleDefForFeature=" +
|
|
|
722 |
facetRuleDefForFeature);
|
|
|
723 |
|
|
|
724 |
if(facetRuleDefForFeature != null) {
|
|
|
725 |
ExpandedFacetRuleDefinition expFacetRuleDefForFeature =
|
|
|
726 |
new ExpandedFacetRuleDefinition(facetRuleDefForFeature);
|
|
|
727 |
|
|
|
728 |
String snip = this.processFacet(expEntity,
|
|
|
729 |
expFacetRuleDefForFeature);
|
|
|
730 |
|
|
|
731 |
if(snip != null) {
|
|
|
732 |
facetXMLSnippets.add(snip);
|
|
|
733 |
}
|
|
|
734 |
}
|
|
|
735 |
|
|
|
736 |
|
|
|
737 |
String xmlSnip = StringUtils.join(facetXMLSnippets, "\n");
|
|
|
738 |
|
|
|
739 |
if(StringUtils.trim(xmlSnip).isEmpty()) {
|
|
|
740 |
return null;
|
|
|
741 |
}
|
|
|
742 |
|
|
|
743 |
return xmlSnip;
|
|
|
744 |
}
|
|
|
745 |
|
|
|
746 |
/**
|
|
|
747 |
*
|
|
|
748 |
* @param expEntity
|
|
|
749 |
* @param borrowedSlide
|
|
|
750 |
* @return
|
|
|
751 |
* @throws Exception
|
|
|
752 |
*/
|
|
|
753 |
private String processBorrowedChildrenSlides(long borrowedCategoryID,
|
|
|
754 |
ExpandedEntity expEntity, Slide borrowedSlide) throws Exception {
|
|
|
755 |
DefinitionsContainer defs =
|
|
|
756 |
Catalog.getInstance().getDefinitionsContainer();
|
|
|
757 |
|
|
|
758 |
List<Slide> childrenSlides = borrowedSlide.getChildrenSlides();
|
|
|
759 |
List<String> facetXMLSnippets = new ArrayList<String>();
|
|
|
760 |
|
|
|
761 |
for (Slide childSlide : childrenSlides) {
|
|
|
762 |
long childSlideDefID = childSlide.getSlideDefinitionID();
|
|
|
763 |
Utils.info("borrowed childSlideDefID=" + childSlideDefID);
|
|
|
764 |
|
|
|
765 |
FacetRuleDefinition facetRuleDefForSlide =
|
|
|
766 |
defs.getFacetRuleDefinitionForSlide(borrowedCategoryID,
|
|
|
767 |
childSlideDefID);
|
|
|
768 |
|
|
|
769 |
Utils.info("borrowed facetRuleDefForSlide=" +
|
|
|
770 |
facetRuleDefForSlide);
|
|
|
771 |
|
|
|
772 |
if(facetRuleDefForSlide != null) {
|
|
|
773 |
ExpandedFacetRuleDefinition expFacetRuleDefForSlide =
|
|
|
774 |
new ExpandedFacetRuleDefinition(
|
|
|
775 |
facetRuleDefForSlide);
|
|
|
776 |
|
|
|
777 |
String snip = this.processFacet(expEntity,
|
|
|
778 |
expFacetRuleDefForSlide);
|
|
|
779 |
|
|
|
780 |
if(snip != null && !StringUtils.trim(snip).isEmpty()) {
|
|
|
781 |
facetXMLSnippets.add(snip);
|
|
|
782 |
}
|
|
|
783 |
}
|
|
|
784 |
|
|
|
785 |
// Features?
|
|
|
786 |
if(childSlide.hasFeatures()) {
|
|
|
787 |
List<Feature> features = childSlide.getFeatures();
|
|
|
788 |
for(Feature feature : features) {
|
|
|
789 |
String childrenSlideFeatureFacetXMLSnippet =
|
|
|
790 |
this.processBorrowedFeature(borrowedCategoryID, expEntity,
|
|
|
791 |
feature);
|
|
|
792 |
|
|
|
793 |
if(childrenSlideFeatureFacetXMLSnippet != null &&
|
|
|
794 |
!StringUtils.trim(childrenSlideFeatureFacetXMLSnippet).
|
|
|
795 |
isEmpty()) {
|
|
|
796 |
|
|
|
797 |
facetXMLSnippets.add(
|
|
|
798 |
childrenSlideFeatureFacetXMLSnippet);
|
|
|
799 |
|
|
|
800 |
}
|
|
|
801 |
}
|
|
|
802 |
}
|
|
|
803 |
|
|
|
804 |
// Children slides
|
|
|
805 |
if(childSlide.hasChildrenSlides()) {
|
|
|
806 |
String childrenSlidesFacetXMLSnippet =
|
|
|
807 |
this.processBorrowedChildrenSlides(borrowedCategoryID,
|
|
|
808 |
expEntity, childSlide);
|
|
|
809 |
|
|
|
810 |
if(childrenSlidesFacetXMLSnippet != null &&
|
|
|
811 |
!StringUtils.trim(childrenSlidesFacetXMLSnippet).
|
|
|
812 |
isEmpty()) {
|
|
|
813 |
|
|
|
814 |
facetXMLSnippets.add(childrenSlidesFacetXMLSnippet);
|
|
|
815 |
}
|
|
|
816 |
}
|
|
|
817 |
}
|
|
|
818 |
|
|
|
819 |
String xmlSnip = StringUtils.join(facetXMLSnippets, "\n");
|
|
|
820 |
|
|
|
821 |
if(StringUtils.trim(xmlSnip).isEmpty()) {
|
|
|
822 |
return null;
|
|
|
823 |
}
|
|
|
824 |
|
|
|
825 |
return xmlSnip;
|
|
|
826 |
}
|
|
|
827 |
|
|
|
828 |
|
|
|
829 |
/**
|
|
|
830 |
*
|
|
|
831 |
* @param expEntity
|
| 64 |
naveen |
832 |
* @param expFacetDef
|
|
|
833 |
* @return
|
|
|
834 |
* @throws Exception
|
|
|
835 |
*/
|
|
|
836 |
@SuppressWarnings("unchecked")
|
|
|
837 |
private String processFacet(ExpandedEntity expEntity,
|
| 81 |
naveen |
838 |
ExpandedFacetRuleDefinition expFacetRuleDef) throws Exception {
|
| 64 |
naveen |
839 |
|
| 81 |
naveen |
840 |
Utils.info("expFacetRuleDef=" + expFacetRuleDef);
|
| 516 |
rajveer |
841 |
|
|
|
842 |
Utils.info("expEntity.getID()=" + expEntity.getID());
|
| 81 |
naveen |
843 |
|
| 451 |
rajveer |
844 |
// to get the price from services and pass it on to fill in solr
|
|
|
845 |
|
| 733 |
rajveer |
846 |
// CatalogServiceClient catalogServiceClient = new CatalogServiceClient();
|
|
|
847 |
// in.shop2020.model.v1.catalog.InventoryService.Client client = catalogServiceClient.getClient();
|
| 451 |
rajveer |
848 |
|
| 516 |
rajveer |
849 |
double itemPrice = 0;
|
| 638 |
rajveer |
850 |
List<Item> items = client.getItemsByCatalogId(expEntity.getID());
|
|
|
851 |
for(Item item: items){
|
|
|
852 |
if(itemPrice == 0){
|
|
|
853 |
itemPrice = item.getSellingPrice();
|
|
|
854 |
}else if(itemPrice>item.getSellingPrice()){
|
|
|
855 |
itemPrice = item.getSellingPrice();
|
|
|
856 |
}
|
| 516 |
rajveer |
857 |
|
| 451 |
rajveer |
858 |
}
|
|
|
859 |
|
| 64 |
naveen |
860 |
EntityContainer ents =
|
|
|
861 |
Catalog.getInstance().getEntityContainer();
|
|
|
862 |
|
| 102 |
naveen |
863 |
DefinitionsContainer defs =
|
|
|
864 |
Catalog.getInstance().getDefinitionsContainer();
|
|
|
865 |
|
| 81 |
naveen |
866 |
IRDataJythonWrapper jw = new IRDataJythonWrapper();
|
| 64 |
naveen |
867 |
|
|
|
868 |
jw.setExpandedEntity(expEntity);
|
| 82 |
naveen |
869 |
jw.setExpandedFacetRuleDefinition(expFacetRuleDef);
|
| 451 |
rajveer |
870 |
jw.setEntityPrice(itemPrice);
|
| 64 |
naveen |
871 |
|
|
|
872 |
// Set FeatureDefinition
|
|
|
873 |
FeatureDefinition featureDef =
|
| 81 |
naveen |
874 |
expFacetRuleDef.getFeatureDefinition();
|
|
|
875 |
|
| 64 |
naveen |
876 |
if(featureDef != null) {
|
|
|
877 |
jw.setFeatureDefinition(featureDef);
|
|
|
878 |
|
|
|
879 |
// Set Feature
|
|
|
880 |
Utils.info("featureDef.getID()=" + featureDef.getID());
|
|
|
881 |
|
|
|
882 |
Feature feature =
|
|
|
883 |
ents.getFeature(expEntity.getID(), featureDef.getID());
|
|
|
884 |
|
| 90 |
naveen |
885 |
// Special case for Brand
|
| 580 |
rajveer |
886 |
if(expFacetRuleDef.getFacetDefinitionID() == 50001 ||
|
|
|
887 |
expFacetRuleDef.getFacetDefinitionID() == 50010 ||
|
|
|
888 |
expFacetRuleDef.getFacetDefinitionID() == 50011) {
|
| 90 |
naveen |
889 |
|
|
|
890 |
// Execute Python script
|
|
|
891 |
jw.executeRule();
|
|
|
892 |
|
|
|
893 |
}
|
|
|
894 |
|
|
|
895 |
// Can happen when to slide's feature which is dropped in favor
|
|
|
896 |
// of a borrowed slide
|
|
|
897 |
else if(feature != null) {
|
| 102 |
naveen |
898 |
|
|
|
899 |
// Normalize
|
|
|
900 |
if(defs.needsNormalization(feature.getFeatureDefinitionID())) {
|
|
|
901 |
Utils.info("needsNormalization feature=" + feature);
|
|
|
902 |
|
|
|
903 |
feature = this.normalize(feature);
|
|
|
904 |
}
|
|
|
905 |
|
| 81 |
naveen |
906 |
ExpandedFeature expFeature = new ExpandedFeature(feature);
|
|
|
907 |
|
|
|
908 |
jw.setExpandedFeature(expFeature);
|
| 88 |
naveen |
909 |
|
|
|
910 |
// Execute Python script
|
|
|
911 |
jw.executeRule();
|
| 81 |
naveen |
912 |
}
|
| 64 |
naveen |
913 |
}
|
|
|
914 |
|
| 346 |
rajveer |
915 |
|
|
|
916 |
|
|
|
917 |
|
| 64 |
naveen |
918 |
// Set SlideDefinition
|
| 81 |
naveen |
919 |
SlideDefinition slideDef = expFacetRuleDef.getSlideDefinition();
|
| 64 |
naveen |
920 |
if(slideDef != null) {
|
|
|
921 |
jw.setSlideDefinition(slideDef);
|
|
|
922 |
|
|
|
923 |
// Set Slide
|
|
|
924 |
Utils.info("slideDef.getID()=" + slideDef.getID());
|
|
|
925 |
|
|
|
926 |
Slide slide = ents.getSlide(expEntity.getID(), slideDef.getID());
|
| 88 |
naveen |
927 |
|
|
|
928 |
// Slide may not have been included infavor of a borrowed slide
|
|
|
929 |
if(slide == null) {
|
|
|
930 |
return null;
|
|
|
931 |
}
|
|
|
932 |
|
| 65 |
naveen |
933 |
ExpandedSlide expSlide = new ExpandedSlide(slide);
|
| 64 |
naveen |
934 |
|
| 65 |
naveen |
935 |
jw.setExpandedSlide(expSlide);
|
| 88 |
naveen |
936 |
|
|
|
937 |
// Execute Python script
|
|
|
938 |
jw.executeRule();
|
| 64 |
naveen |
939 |
}
|
|
|
940 |
|
| 346 |
rajveer |
941 |
//
|
| 64 |
naveen |
942 |
|
| 346 |
rajveer |
943 |
if(slideDef == null && featureDef == null){
|
|
|
944 |
if(expFacetRuleDef.getIRDataRuleDefinition().getScript() != null){
|
|
|
945 |
jw.executeRule();
|
|
|
946 |
}
|
|
|
947 |
}
|
|
|
948 |
|
|
|
949 |
|
| 64 |
naveen |
950 |
List<Object> values = (List<Object>)jw.getValues();
|
|
|
951 |
Utils.info("values=" + values);
|
|
|
952 |
|
| 91 |
naveen |
953 |
// Append to facet values
|
|
|
954 |
long facetDefID = expFacetRuleDef.getFacetDefinitionID();
|
|
|
955 |
Utils.info("facetDefID=" + facetDefID);
|
|
|
956 |
|
|
|
957 |
List<String> facetValues = this.facetIDFacetValues.get(
|
|
|
958 |
new Long(facetDefID));
|
|
|
959 |
|
|
|
960 |
if(facetValues == null) {
|
|
|
961 |
facetValues = new ArrayList<String>();
|
|
|
962 |
this.facetIDFacetValues.put(new Long(facetDefID), facetValues);
|
|
|
963 |
}
|
|
|
964 |
|
|
|
965 |
if(values != null) {
|
|
|
966 |
for(Object value : values) {
|
|
|
967 |
String strValue = value.toString();
|
|
|
968 |
|
|
|
969 |
if(!facetValues.contains(strValue)) {
|
|
|
970 |
facetValues.add(strValue);
|
|
|
971 |
}
|
|
|
972 |
}
|
|
|
973 |
}
|
|
|
974 |
|
|
|
975 |
// Parse returned Python list
|
| 88 |
naveen |
976 |
String facetXMLSnip = null;
|
| 64 |
naveen |
977 |
if(values != null) {
|
|
|
978 |
|
|
|
979 |
// Get IR Data XML snippet for this entity and facet
|
| 81 |
naveen |
980 |
facetXMLSnip = this.getFacetXMLSnippet(expFacetRuleDef, values, 2);
|
| 64 |
naveen |
981 |
}
|
|
|
982 |
|
| 88 |
naveen |
983 |
Utils.info("0 facetXMLSnip=" + facetXMLSnip);
|
| 64 |
naveen |
984 |
return facetXMLSnip;
|
|
|
985 |
}
|
| 102 |
naveen |
986 |
|
|
|
987 |
/**
|
|
|
988 |
*
|
|
|
989 |
* @param feature
|
|
|
990 |
* @return Feature
|
|
|
991 |
* @throws Exception
|
|
|
992 |
*/
|
|
|
993 |
private Feature normalize(Feature feature) throws Exception {
|
|
|
994 |
ExpandedFeature expFeature = new ExpandedFeature(feature);
|
| 67 |
naveen |
995 |
|
| 102 |
naveen |
996 |
BulletDefinition bulletDef =
|
|
|
997 |
expFeature.getFeatureDefinition().getBulletDefinition();
|
|
|
998 |
|
|
|
999 |
ExpandedBulletDefinition expBulletDef = new ExpandedBulletDefinition(
|
|
|
1000 |
bulletDef);
|
|
|
1001 |
|
|
|
1002 |
if(expBulletDef.isPrimitive()) {
|
|
|
1003 |
PrimitiveNormalizationJythonWrapper jy =
|
|
|
1004 |
new PrimitiveNormalizationJythonWrapper();
|
|
|
1005 |
|
|
|
1006 |
jy.setExpandedFeature(expFeature);
|
|
|
1007 |
|
|
|
1008 |
jy.excuteRule();
|
|
|
1009 |
|
|
|
1010 |
String newValue = jy.getNewValue();
|
|
|
1011 |
long newUnitID = jy.getNewUnitID();
|
|
|
1012 |
|
|
|
1013 |
List<Bullet> newBullets = new ArrayList<Bullet>();
|
|
|
1014 |
Bullet newBullet = new Bullet(new PrimitiveDataObject(newValue));
|
|
|
1015 |
newBullet.setUnitID(newUnitID);
|
|
|
1016 |
|
|
|
1017 |
newBullets.add(newBullet);
|
|
|
1018 |
|
|
|
1019 |
feature.setBullets(newBullets);
|
|
|
1020 |
}
|
|
|
1021 |
else {
|
|
|
1022 |
Utils.severe("Normalization not defined for non-primitives");
|
|
|
1023 |
}
|
|
|
1024 |
|
|
|
1025 |
return feature;
|
|
|
1026 |
}
|
|
|
1027 |
|
| 67 |
naveen |
1028 |
/**
|
|
|
1029 |
*
|
|
|
1030 |
* @param expEntity
|
|
|
1031 |
* @param facetFeatureIDs
|
|
|
1032 |
* @param indent
|
|
|
1033 |
* @return
|
|
|
1034 |
*/
|
|
|
1035 |
private String getPropertiesXMLSnippet(ExpandedEntity expEntity,
|
|
|
1036 |
List<Long> facetFeatureIDs, int indent) {
|
|
|
1037 |
|
|
|
1038 |
List<String> xmlSnippet = new ArrayList<String>();
|
|
|
1039 |
|
|
|
1040 |
// Collect all free-form content here
|
|
|
1041 |
List<String> ffc = new ArrayList<String>();
|
|
|
1042 |
|
|
|
1043 |
// Features
|
|
|
1044 |
List<ExpandedSlide> expSlides = expEntity.getExpandedSlides();
|
|
|
1045 |
|
|
|
1046 |
for(ExpandedSlide expSlide : expSlides) {
|
|
|
1047 |
List<ExpandedFeature> expFeatures = expSlide.getExpandedFeatures();
|
|
|
1048 |
|
|
|
1049 |
if(expSlide.getFreeformContent() != null) {
|
| 199 |
naveen |
1050 |
ffc.add(expSlide.getFreeformContent().getFreeformText());
|
| 67 |
naveen |
1051 |
}
|
|
|
1052 |
|
|
|
1053 |
if(expFeatures == null) {
|
|
|
1054 |
continue;
|
|
|
1055 |
}
|
|
|
1056 |
|
|
|
1057 |
for(ExpandedFeature expFeature : expFeatures) {
|
|
|
1058 |
Long featureDefID =
|
|
|
1059 |
new Long(expFeature.getFeatureDefinitionID());
|
|
|
1060 |
|
|
|
1061 |
// FFC at feature level
|
|
|
1062 |
if(expFeature.getFreeformContent() != null) {
|
| 199 |
naveen |
1063 |
ffc.add(expFeature.getFreeformContent().getFreeformText());
|
| 67 |
naveen |
1064 |
}
|
|
|
1065 |
|
|
|
1066 |
// Exclude those who are already covered as facets
|
|
|
1067 |
if(facetFeatureIDs.contains(featureDefID)) {
|
|
|
1068 |
continue;
|
|
|
1069 |
}
|
|
|
1070 |
|
|
|
1071 |
List<ExpandedBullet> expBullets =
|
|
|
1072 |
expFeature.getExpandedBullets();
|
|
|
1073 |
|
|
|
1074 |
if(expBullets == null) {
|
|
|
1075 |
continue;
|
|
|
1076 |
}
|
|
|
1077 |
|
|
|
1078 |
//<Property Label="">
|
|
|
1079 |
xmlSnippet.add(this.xmlIndentation[indent] +
|
| 83 |
naveen |
1080 |
"<Property ID=\"" + expFeature.getFeatureDefinitionID()
|
|
|
1081 |
+ "\" Label=\"" + StringEscapeUtils.escapeXml(
|
| 67 |
naveen |
1082 |
expFeature.getFeatureDefinition().getLabel()) +
|
|
|
1083 |
"\">");
|
|
|
1084 |
|
|
|
1085 |
//<Value></Value>
|
|
|
1086 |
for(ExpandedBullet bullet : expBullets) {
|
|
|
1087 |
|
|
|
1088 |
// FFC at bullet level
|
|
|
1089 |
if(bullet.getFreeformContent() != null) {
|
| 199 |
naveen |
1090 |
ffc.add(bullet.getFreeformContent().getFreeformText());
|
| 67 |
naveen |
1091 |
}
|
|
|
1092 |
|
|
|
1093 |
xmlSnippet.add(this.xmlIndentation[indent + 1] + "<Value>" +
|
|
|
1094 |
StringEscapeUtils.escapeXml(bullet.getValue()) +
|
|
|
1095 |
"</Value>");
|
|
|
1096 |
}
|
|
|
1097 |
|
|
|
1098 |
//</Property>
|
|
|
1099 |
xmlSnippet.add(this.xmlIndentation[indent] + "</Property>");
|
|
|
1100 |
}
|
|
|
1101 |
}
|
|
|
1102 |
|
|
|
1103 |
// FFC as Label="Free-form Content"
|
|
|
1104 |
if(!ffc.isEmpty()) {
|
|
|
1105 |
xmlSnippet.add(this.xmlIndentation[indent] +
|
| 108 |
naveen |
1106 |
"<Property ID=\"000000\" Label=\"Free-form Content\">");
|
| 67 |
naveen |
1107 |
|
|
|
1108 |
for(String f : ffc) {
|
|
|
1109 |
if(f != null) {
|
|
|
1110 |
f = StringEscapeUtils.escapeXml(f);
|
|
|
1111 |
|
|
|
1112 |
xmlSnippet.add(this.xmlIndentation[indent + 1] + "<Value>" +
|
|
|
1113 |
f + "</Value>");
|
|
|
1114 |
}
|
|
|
1115 |
}
|
|
|
1116 |
|
|
|
1117 |
xmlSnippet.add(this.xmlIndentation[indent] + "</Property>");
|
|
|
1118 |
}
|
|
|
1119 |
|
|
|
1120 |
// Children slides
|
|
|
1121 |
// TODO
|
|
|
1122 |
|
|
|
1123 |
return StringUtils.join(xmlSnippet, "\n");
|
|
|
1124 |
}
|
| 64 |
naveen |
1125 |
|
|
|
1126 |
/**
|
|
|
1127 |
*
|
|
|
1128 |
* @param expEntity
|
|
|
1129 |
* @param facetXMLSnippets
|
|
|
1130 |
* @param indent
|
|
|
1131 |
* @return
|
|
|
1132 |
*/
|
|
|
1133 |
private String getEntityXMLSnippet(ExpandedEntity expEntity,
|
| 67 |
naveen |
1134 |
String facetXMLSnippets, String propertiesXMLSnippets, int indent) {
|
| 64 |
naveen |
1135 |
|
|
|
1136 |
//<Entity ID="40001">
|
|
|
1137 |
List<String> xmlSnippet = new ArrayList<String>();
|
|
|
1138 |
|
|
|
1139 |
String entityID = new Long(expEntity.getID()).toString();
|
|
|
1140 |
xmlSnippet.add(this.xmlIndentation[indent] + "<Entity ID=\""+ entityID +
|
|
|
1141 |
"\">");
|
|
|
1142 |
|
|
|
1143 |
//<Category>Business Phones</Category>
|
| 580 |
rajveer |
1144 |
String parentCategory = expEntity.getCategory().getLabel();
|
| 64 |
naveen |
1145 |
xmlSnippet.add(this.xmlIndentation[indent + 1] + "<Category>" +
|
| 580 |
rajveer |
1146 |
StringEscapeUtils.escapeXml(parentCategory) + "</Category>");
|
| 64 |
naveen |
1147 |
|
| 580 |
rajveer |
1148 |
/*
|
|
|
1149 |
//<Category>Business Phones</Category>
|
|
|
1150 |
String category = expEntity.getCategory().getLabel();
|
|
|
1151 |
xmlSnippet.add(this.xmlIndentation[indent + 1] + "<SubCategory>" +
|
|
|
1152 |
StringEscapeUtils.escapeXml(category) + "</SubCategory>");
|
|
|
1153 |
*/
|
|
|
1154 |
|
| 64 |
naveen |
1155 |
//<Title>Nokia E71</Title>
|
| 67 |
naveen |
1156 |
String title = StringEscapeUtils.escapeXml(expEntity.getBrand()) + " " +
|
|
|
1157 |
StringEscapeUtils.escapeXml(expEntity.getModelName()) +
|
| 64 |
naveen |
1158 |
((expEntity.getModelNumber() != null) ?
|
| 67 |
naveen |
1159 |
(" " +
|
|
|
1160 |
StringEscapeUtils.escapeXml(expEntity.getModelNumber()))
|
| 64 |
naveen |
1161 |
: "");
|
|
|
1162 |
|
|
|
1163 |
xmlSnippet.add(this.xmlIndentation[indent + 1] +
|
| 67 |
naveen |
1164 |
"<Title>" + StringEscapeUtils.escapeXml(title) + "</Title>");
|
| 64 |
naveen |
1165 |
|
|
|
1166 |
xmlSnippet.add(facetXMLSnippets);
|
| 67 |
naveen |
1167 |
|
|
|
1168 |
xmlSnippet.add(propertiesXMLSnippets);
|
| 64 |
naveen |
1169 |
|
|
|
1170 |
//</Entity>
|
|
|
1171 |
xmlSnippet.add(this.xmlIndentation[indent] + "</Entity>");
|
|
|
1172 |
|
|
|
1173 |
return StringUtils.join(xmlSnippet, "\n");
|
|
|
1174 |
}
|
|
|
1175 |
|
|
|
1176 |
/**
|
|
|
1177 |
*
|
|
|
1178 |
* @param expFacetDef
|
|
|
1179 |
* @param values
|
|
|
1180 |
* @param indent
|
|
|
1181 |
* @return String XML Snippet
|
|
|
1182 |
*/
|
| 81 |
naveen |
1183 |
private String getFacetXMLSnippet(
|
|
|
1184 |
ExpandedFacetRuleDefinition expFacetRuleDef,
|
| 64 |
naveen |
1185 |
List<Object> values, int indent) {
|
| 81 |
naveen |
1186 |
|
| 64 |
naveen |
1187 |
// <Facet Label="Form Factor">
|
|
|
1188 |
List<String> xmlSnippet = new ArrayList<String>();
|
| 81 |
naveen |
1189 |
String target = expFacetRuleDef.getFacetDefinition().getTarget();
|
|
|
1190 |
|
| 83 |
naveen |
1191 |
xmlSnippet.add(this.xmlIndentation[indent] + "<Facet ID=\"" +
|
|
|
1192 |
expFacetRuleDef.getFacetDefinitionID() + "\" Label=\"" +
|
| 64 |
naveen |
1193 |
target + "\">");
|
|
|
1194 |
|
|
|
1195 |
//<Value>Candybar</Value>
|
|
|
1196 |
for(Object value : values) {
|
|
|
1197 |
xmlSnippet.add(this.xmlIndentation[indent + 1] + "<Value>" +
|
|
|
1198 |
value.toString() + "</Value>");
|
|
|
1199 |
}
|
|
|
1200 |
|
|
|
1201 |
//</Facet>
|
|
|
1202 |
xmlSnippet.add(this.xmlIndentation[indent] + "</Facet>");
|
|
|
1203 |
|
|
|
1204 |
return StringUtils.join(xmlSnippet, "\n");
|
|
|
1205 |
}
|
| 62 |
naveen |
1206 |
}
|