Subversion Repositories SmartDukaan

Rev

Rev 1229 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 1229 Rev 1314
Line 12... Line 12...
12
import in.shop2020.metamodel.definitions.Catalog;
12
import in.shop2020.metamodel.definitions.Catalog;
13
import in.shop2020.metamodel.definitions.Category;
13
import in.shop2020.metamodel.definitions.Category;
14
import in.shop2020.metamodel.definitions.DatatypeDefinition;
14
import in.shop2020.metamodel.definitions.DatatypeDefinition;
15
import in.shop2020.metamodel.definitions.DefinitionsContainer;
15
import in.shop2020.metamodel.definitions.DefinitionsContainer;
16
import in.shop2020.metamodel.definitions.FacetDefinition;
16
import in.shop2020.metamodel.definitions.FacetDefinition;
17
import in.shop2020.metamodel.definitions.FacetRuleDefinition;
17
import in.shop2020.metamodel.definitions.FacetSlideDefinition;
18
import in.shop2020.metamodel.definitions.FeatureDefinition;
18
import in.shop2020.metamodel.definitions.FeatureDefinition;
19
import in.shop2020.metamodel.definitions.SlideDefinition;
-
 
20
import in.shop2020.metamodel.util.CreationUtils;
19
import in.shop2020.metamodel.util.CreationUtils;
21
import in.shop2020.metamodel.util.ExpandedBullet;
20
import in.shop2020.metamodel.util.ExpandedBullet;
22
import in.shop2020.metamodel.util.ExpandedBulletDefinition;
21
import in.shop2020.metamodel.util.ExpandedBulletDefinition;
23
import in.shop2020.metamodel.util.ExpandedCategoryFacetDefinition;
-
 
24
import in.shop2020.metamodel.util.ExpandedEntity;
22
import in.shop2020.metamodel.util.ExpandedEntity;
25
import in.shop2020.metamodel.util.ExpandedFacetDefinition;
23
import in.shop2020.metamodel.util.ExpandedFacetDefinition;
26
import in.shop2020.metamodel.util.ExpandedFacetRuleDefinition;
24
import in.shop2020.metamodel.util.ExpandedFacetSlideDefinition;
27
import in.shop2020.metamodel.util.ExpandedFeature;
25
import in.shop2020.metamodel.util.ExpandedFeature;
28
import in.shop2020.metamodel.util.ExpandedFeatureDefinition;
26
import in.shop2020.metamodel.util.ExpandedFeatureDefinition;
29
import in.shop2020.metamodel.util.ExpandedSlide;
27
import in.shop2020.metamodel.util.ExpandedSlide;
30
import in.shop2020.model.v1.catalog.CatalogService.Client;
-
 
31
import in.shop2020.model.v1.catalog.Item;
28
import in.shop2020.model.v1.catalog.Item;
32
import in.shop2020.model.v1.catalog.status;
29
import in.shop2020.model.v1.catalog.status;
33
import in.shop2020.thrift.clients.CatalogServiceClient;
30
import in.shop2020.thrift.clients.CatalogServiceClient;
34
 
31
 
35
import java.io.File;
32
import java.io.File;
36
import java.io.FileOutputStream;
33
import java.io.FileOutputStream;
37
import java.util.ArrayList;
34
import java.util.ArrayList;
38
import java.util.Collection;
-
 
39
import java.util.Date;
35
import java.util.Date;
40
import java.util.HashMap;
36
import java.util.HashMap;
41
import java.util.HashSet;
-
 
42
import java.util.List;
37
import java.util.List;
43
import java.util.Map;
38
import java.util.Map;
44
import java.util.Map.Entry;
-
 
45
import java.util.Set;
-
 
46
 
39
 
47
import javax.xml.transform.TransformerConfigurationException;
-
 
48
import javax.xml.transform.TransformerFactory;
40
import javax.xml.transform.TransformerFactory;
49
import javax.xml.transform.Transformer;
41
import javax.xml.transform.Transformer;
50
import javax.xml.transform.stream.StreamResult;
42
import javax.xml.transform.stream.StreamResult;
51
import javax.xml.transform.stream.StreamSource;
43
import javax.xml.transform.stream.StreamSource;
52
 
44
 
53
import org.apache.commons.lang.ArrayUtils;
-
 
54
import org.apache.commons.lang.StringEscapeUtils;
45
import org.apache.commons.lang.StringEscapeUtils;
55
import org.apache.commons.lang.StringUtils;
46
import org.apache.commons.lang.StringUtils;
56
 
47
 
57
 
48
 
58
/**
49
/**
59
 * Command line utility to convert IR Definitions into IR Data and IR Meta-data
50
 * Command line utility to convert IR Definitions into IR Data and IR Meta-data
60
 * 
51
 * 
61
 * Usage: IR [irmetadata|irdata] {Category ID}
-
 
62
 * 
-
 
63
 * @author naveen
52
 * @author rajveer
64
 *
53
 *
65
 */
54
 */
66
public class IR {
55
public class IR {
67
	
56
	
68
	/**
57
	/**
69
	 * 
-
 
70
	 */
-
 
71
	private long categoryID;
-
 
72
	
-
 
73
	/**
-
 
74
	 * Level - 4, 8, 12, 16
58
	 * Level - 4, 8, 12, 16
75
	 */
59
	 */
76
	private String[] xmlIndentation = {"", "    ", "        ", "            ", 
60
	private String[] xmlIndentation = {"", "    ", "        ", "            ","                "};
77
			"                "};
-
 
78
 
61
 
79
	private String[] xmlTabIndentation = {"", "\t", "\t\t", "\t\t\t", 
62
	private String[] xmlTabIndentation = {"", "\t", "\t\t", "\t\t\t", "\t\t\t\t", "\t\t\t\t\t", "\t\t\t\t\t\t"};
80
			"\t\t\t\t", "\t\t\t\t\t", "\t\t\t\t\t\t"};
-
 
81
 
63
 
82
	private Map<Long, List<String>> facetIDFacetValues = 
64
	private Map<Long, List<String>> facetIDFacetValues = new HashMap<Long, List<String>>();
83
		new HashMap<Long, List<String>>();
-
 
84
 
65
 
85
	CatalogServiceClient catalogServiceClient = null;
66
	CatalogServiceClient catalogServiceClient = null;
86
	in.shop2020.model.v1.catalog.InventoryService.Client client = null;
67
	in.shop2020.model.v1.catalog.InventoryService.Client client = null;
87
	
68
	
88
	/**
69
	/**
89
	 * @param args
70
	 * @param args
90
	 * @throws Exception 
71
	 * @throws Exception 
91
	 */
72
	 */
92
	public static void main(String[] args) throws Exception {
73
	public static void main(String[] args) throws Exception {
93
		String[] commands = new String[] {"irmetadata", "irdata"};
-
 
94
		
-
 
95
		String usage = "Usage: IR ["+ StringUtils.join(commands, "|") +
-
 
96
			"] {Category ID}\n";
-
 
97
		
-
 
98
		if(args.length < 1) {
-
 
99
			System.out.println(usage);
-
 
100
			System.exit(-1);
-
 
101
		}
-
 
102
		
-
 
103
		String inputCommand = args[0];
-
 
104
		
-
 
105
		if(!ArrayUtils.contains(commands, inputCommand)) {
-
 
106
			System.out.println(usage);
-
 
107
			System.exit(-1);
-
 
108
		}
-
 
109
 
-
 
110
		long categoryID = 0L;
-
 
111
		if(args.length > 1) {
-
 
112
			try {
-
 
113
				categoryID = Long.parseLong(args[1]);
-
 
114
			}
-
 
115
			catch (NumberFormatException nfe) {
-
 
116
				System.out.println(usage);
-
 
117
				System.exit(-1);
-
 
118
			}
-
 
119
		}
-
 
120
		
-
 
121
		IR ir = new IR(categoryID);
-
 
122
		
74
		
123
		if (inputCommand.equals("irdata")) {
75
		IR ir = new IR();
124
			ir.exportIRData();
76
		ir.exportIRData();
125
			ir.transformIrDataXMLtoSolrXML();
77
		ir.transformIrDataXMLtoSolrXML();
126
			return;
-
 
127
		}
-
 
128
		
-
 
129
		if (inputCommand.equals("irmetadata")) {
-
 
130
			ir.exportIRMetaData();
78
		ir.exportIRMetaData();
131
			ir.transformIrMetaDataXMLSolrSchemaXML();
79
		ir.transformIrMetaDataXMLSolrSchemaXML();
132
			return;
-
 
133
		}
-
 
134
		
80
		
135
	}
81
	}
136
	
82
	
137
	/**
83
	/**
138
	 * 
84
	 * 
139
	 * @param categoryID
85
	 * @param categoryID
-
 
86
	 * @return 
140
	 * @throws Exception 
87
	 * @throws Exception 
141
	 */
88
	 */
142
	public IR(long categoryID) throws Exception {
89
	public IR() throws Exception {
143
		this.categoryID = categoryID;
-
 
144
		catalogServiceClient = new CatalogServiceClient();
90
		catalogServiceClient = new CatalogServiceClient();
145
		client = catalogServiceClient.getClient();
91
		client = catalogServiceClient.getClient();
146
	}
92
	}
147
	
93
	
148
	
94
	
Line 220... Line 166...
220
		xmlSnippets.add("<IRMetaData>");
166
		xmlSnippets.add("<IRMetaData>");
221
		xmlSnippets.add("\t<Facets>");
167
		xmlSnippets.add("\t<Facets>");
222
		
168
		
223
		IRMetaDataJythonWrapper jy = new IRMetaDataJythonWrapper();
169
		IRMetaDataJythonWrapper jy = new IRMetaDataJythonWrapper();
224
		
170
		
225
		List<Long> facetFeatures = new ArrayList<Long>();
-
 
226
		
-
 
227
		// Iterate over all facet definitions
171
		// Iterate over all facet definitions
228
		Map<Long, FacetDefinition> facetDefs = defs.getFacetDefinitions();
172
		Map<Long, FacetDefinition> facetDefs = defs.getFacetDefinitions();
229
		for(FacetDefinition facetDef : facetDefs.values()) {
173
		for(FacetDefinition facetDef : facetDefs.values()) {
230
			
174
			
231
			jy.reset();
175
			jy.reset();
Line 234... Line 178...
234
			ExpandedFacetDefinition expFacetDef = 
178
			ExpandedFacetDefinition expFacetDef = 
235
				new ExpandedFacetDefinition(facetDef);
179
				new ExpandedFacetDefinition(facetDef);
236
			
180
			
237
			jy.setExpandedFacetDefinition(expFacetDef);
181
			jy.setExpandedFacetDefinition(expFacetDef);
238
			
182
			
-
 
183
			jy.setPossibleValues(facetIDFacetValues.get(facetDef.getID()));
-
 
184
			
239
			jy.executeRule();
185
			jy.executeRule();
240
			
186
			
241
			String facetXMLSnip = jy.getXMLSnippet();
187
			String facetXMLSnip = jy.getXMLSnippet();
242
			Utils.info("facetXMLSnip=" + facetXMLSnip);
188
			Utils.info("facetXMLSnip=" + facetXMLSnip);
243
			
189
			
244
			xmlSnippets.add(facetXMLSnip);
190
			xmlSnippets.add(facetXMLSnip);
245
			
191
			
246
			facetFeatures.add(new Long(expFacetDef.getFeatureDefinitionID()));
-
 
247
		}
192
		}
248
		xmlSnippets.add("\t</Facets>");
193
		xmlSnippets.add("\t</Facets>");
249
		
194
		
250
		Utils.info("facetFeatures=" + facetFeatures);
-
 
-
 
195
 
251
		
196
		
252
		xmlSnippets.add("\n\t<Properties>");
197
		xmlSnippets.add("\n\t<Properties>");
253
		
198
		
254
		// Iterate over all feature definitions
199
		// Iterate over all feature definitions
255
		Map<Long, FeatureDefinition> featureDefs = defs.getFeatureDefinitions();
200
		Map<Long, FeatureDefinition> featureDefs = defs.getFeatureDefinitions();
256
		for(FeatureDefinition featureDef : featureDefs.values()) {
201
		for(FeatureDefinition featureDef : featureDefs.values()) {
257
			if(facetFeatures.contains(new Long(featureDef.getID()))) {
-
 
258
				// Ignore, is already covered as facet
-
 
259
				continue;
-
 
260
			}
-
 
261
			String propertyXMLSnip = this.getPropertyXMLSnippet(featureDef);
202
			String propertyXMLSnip = this.getPropertyXMLSnippet(featureDef);
262
			Utils.info("propertyXMLSnip=" + propertyXMLSnip);
203
			Utils.info("propertyXMLSnip=" + propertyXMLSnip);
263
			
204
			
264
			xmlSnippets.add(propertyXMLSnip);
205
			xmlSnippets.add(propertyXMLSnip);
265
		}
206
		}
Line 412... Line 353...
412
		xmlSnip += " isMultivalue=\"" + multivalue + "\"";
353
		xmlSnip += " isMultivalue=\"" + multivalue + "\"";
413
		
354
		
414
		xmlSnip += "/>";
355
		xmlSnip += "/>";
415
		return xmlSnip;
356
		return xmlSnip;
416
	}
357
	}
-
 
358
 
417
	
359
	
418
	/**
360
	
419
	 * @throws Exception 
361
	private String processFacet(FacetDefinition facet, ExpandedSlide expSlide, ExpandedFacetSlideDefinition expFacetSlideDef, Long facetDefID) throws Exception {
420
	 * 
-
 
421
	 */
362
	
422
	public void exportIRData() throws Exception {
-
 
423
		DefinitionsContainer defs = 
-
 
424
			Catalog.getInstance().getDefinitionsContainer();
363
		IRDataJythonWrapper jw = new IRDataJythonWrapper();
425
		
364
		
426
 
-
 
-
 
365
		jw.setExpandedSlide(expSlide);
-
 
366
		jw.setExpandedFacetSlideDefinition(expFacetSlideDef);
427
		
367
		
428
		// <IRData>
368
		// Execute Python script
429
		List<String> entityXMLSnippets = new ArrayList<String>();
-
 
430
		entityXMLSnippets.add("<IRData>");
369
		jw.executeRule();
431
		
370
		
432
		List<Category> categories = null;
371
		//FIXME
433
		if(this.categoryID != 0L) {
372
		// Normalize
434
			categories = new ArrayList<Category>();
373
//		if(defs.needsNormalization(feature.getFeatureDefinitionID())) {
435
			categories.add(defs.getCategory(this.categoryID));
374
//			Utils.info("needsNormalization feature=" + feature.getFeatureDefinitionID());
436
		}
375
//			
437
		else {
-
 
438
			// Get all categories
-
 
439
			categories = defs.getChildrenCategories(10001);
376
//			feature = this.normalize(feature);
440
		}
377
//		}
441
		
378
		
442
		int i=0;
-
 
443
		for(Category cat : categories) {
-
 
444
			long catID = cat.getID();
-
 
445
			if(i>0){
-
 
446
				continue;
-
 
447
			}
-
 
448
			i++;
-
 
449
			// Get all facets for the category
-
 
450
			ExpandedCategoryFacetDefinition expCategoryFacetDef = 
-
 
451
				defs.getExpandedCategoryFacetDefinition(catID);
-
 
452
			System.out.println(expCategoryFacetDef);
-
 
453
			List<ExpandedFacetRuleDefinition> expFacetRuleDefs = 
-
 
454
				expCategoryFacetDef.getExpandedFacetRuleDefinitions();
-
 
455
			System.out.println(expFacetRuleDefs);
-
 
456
			// Get all entities for the category
-
 
457
			//FIXME
-
 
458
			Collection<Entity> entities = CreationUtils.getEntities(catID);
-
 
459
			
-
 
460
			if(entities == null) {
-
 
461
				continue;
-
 
462
			}
-
 
463
 
-
 
464
			
-
 
465
			//Modified by Rajveer, Now it will search according to each catalog item.
-
 
466
			// For each entity in catalog
-
 
467
			
-
 
468
			
-
 
469
			List<Item> items = client.getAllItemsByStatus(status.ACTIVE);
-
 
470
			Set<Long> processedCatalogItems = new HashSet<Long>();
-
 
471
			Date todate = new Date();
-
 
472
			for(Item item : items){
-
 
473
				long entityID = item.getCatalogItemId();
-
 
474
				if(todate.getTime() < item.getStartDate() ){
-
 
475
					continue;
-
 
476
				}
-
 
477
				if(processedCatalogItems.contains(entityID)){
-
 
478
					continue;
-
 
479
				}
-
 
480
				processedCatalogItems.add(entityID);
-
 
481
				
-
 
482
				ExpandedEntity expEntity = 
-
 
483
					CreationUtils.getExpandedEntity(entityID);
-
 
484
				//Skip if entity doesnt exist
-
 
485
				if(expEntity == null){
-
 
486
					continue;
-
 
487
				}
-
 
488
				List<String> facetXMLSnippets = new ArrayList<String>();
-
 
489
				
-
 
490
				// Collect features which have become FACETs
-
 
491
				List<Long> facetFeatureIDs = new ArrayList<Long>();
-
 
492
				
-
 
493
				Set<Long> processedFacets = new HashSet<Long>();
-
 
494
				// For each facet execute Rule
-
 
495
				for(ExpandedFacetRuleDefinition expFacetRuleDef : 
-
 
496
						expFacetRuleDefs) {
-
 
497
					System.out.println(expFacetRuleDef.getFacetDefinitionID());
-
 
498
					String facetXMLSnip = 
-
 
499
						this.processFacet(expEntity, expFacetRuleDef);
-
 
500
					
-
 
501
					if(facetXMLSnip != null && 
-
 
502
							!StringUtils.trim(facetXMLSnip).isEmpty()) {
-
 
503
						facetXMLSnippets.add(facetXMLSnip);
-
 
504
						Utils.info("1 facetXMLSnip=" + facetXMLSnip);
-
 
505
						processedFacets.add(expFacetRuleDef.getFacetDefinitionID());
-
 
506
					}
-
 
507
					
-
 
508
					// Collect features already covered as Facet
-
 
509
					if(expFacetRuleDef.getFeatureDefinition() != null) {
-
 
510
						facetFeatureIDs.add(new Long(
-
 
511
								expFacetRuleDef.getFeatureDefinitionID()));
-
 
512
					}
-
 
513
				}
-
 
514
				Entity entity = CreationUtils.getEntity(entityID);
-
 
515
				// Handle borrowed slides
-
 
516
				List<Slide> borrowedSlides = CreationUtils.getBorrowedSlides(entity);
-
 
517
				
-
 
518
				for (Slide borrowedSlide : borrowedSlides) {
-
 
519
					if(CreationUtils.getBorrowedCategoryID(borrowedSlide.getSlideDefinitionID(), entity.getCategoryID()) == -1){
-
 
520
						continue;
-
 
521
					}
-
 
522
//					if(borrowedSlide.getBorrowedCategoryID() == -1){
-
 
523
//						continue;
-
 
524
//					}
-
 
525
					String facetXMLSnip = this.processBorrowedSlide(expEntity,
-
 
526
							borrowedSlide, processedFacets);
-
 
527
					
-
 
528
					if(facetXMLSnip != null && 
-
 
529
							!StringUtils.trim(facetXMLSnip).isEmpty()) {
-
 
530
						facetXMLSnippets.add(facetXMLSnip);
-
 
531
					}
-
 
532
					
-
 
533
					Utils.info("2 facetXMLSnip=" + facetXMLSnip);
-
 
534
				}
-
 
535
				
-
 
536
				String facetXMLSnippetsStr = 
-
 
537
					StringUtils.join(facetXMLSnippets, "\n");
-
 
538
					
-
 
539
				Utils.info("facetXMLSnippetsStr=" + facetXMLSnippetsStr);
-
 
540
				
-
 
541
				// Collect PROPERTIES
-
 
542
				String propertiesXMLSnippetsStr = 
-
 
543
					this.getPropertiesXMLSnippet(expEntity, facetFeatureIDs, 2);
-
 
544
				
-
 
545
				Utils.info(propertiesXMLSnippetsStr);
-
 
546
				
-
 
547
				String entityXMLSnip = this.getEntityXMLSnippet(expEntity, 
-
 
548
						facetXMLSnippetsStr, propertiesXMLSnippetsStr, 1);
-
 
549
				
-
 
550
				Utils.info(entityXMLSnip);
-
 
551
				
-
 
552
				entityXMLSnippets.add(entityXMLSnip);
-
 
553
			}
-
 
554
		}
-
 
555
		
379
		
556
			
-
 
557
			/*
-
 
558
			// For each entity 
-
 
559
			for(Entity entity : entities) {
-
 
560
				ExpandedEntity expEntity = 
-
 
561
					ents.getExpandedEntity(entity.getID());
-
 
562
				//Skip if entity doesnt exist
-
 
563
				if(expEntity == null){
-
 
564
					continue;
-
 
565
				}
-
 
566
				List<String> facetXMLSnippets = new ArrayList<String>();
-
 
567
				
-
 
568
				// Collect features which have become FACETs
-
 
569
				List<Long> facetFeatureIDs = new ArrayList<Long>();
-
 
570
				
-
 
571
				// For each facet execute Rule
-
 
572
				for(ExpandedFacetRuleDefinition expFacetRuleDef : 
-
 
573
						expFacetRuleDefs) {
-
 
574
					String facetXMLSnip = 
-
 
575
						this.processFacet(expEntity, expFacetRuleDef);
-
 
576
					
-
 
577
					if(facetXMLSnip != null && 
-
 
578
							!StringUtils.trim(facetXMLSnip).isEmpty()) {
-
 
579
						facetXMLSnippets.add(facetXMLSnip);
-
 
580
						Utils.info("1 facetXMLSnip=" + facetXMLSnip);
-
 
581
					}
-
 
582
					
-
 
583
					// Collect features already covered as Facet
-
 
584
					if(expFacetRuleDef.getFeatureDefinition() != null) {
-
 
585
						facetFeatureIDs.add(new Long(
-
 
586
								expFacetRuleDef.getFeatureDefinitionID()));
-
 
587
					}
-
 
588
				}
-
 
589
				
-
 
590
				// Handle borrowed slides
-
 
591
				List<Slide> borrowedSlides = ents.getBorrowedSlides(entity);
-
 
592
				
-
 
593
				for (Slide borrowedSlide : borrowedSlides) {
-
 
594
					String facetXMLSnip = this.processBorrowedSlide(expEntity,
-
 
595
							borrowedSlide);
-
 
596
					
-
 
597
					if(facetXMLSnip != null && 
-
 
598
							!StringUtils.trim(facetXMLSnip).isEmpty()) {
-
 
599
						facetXMLSnippets.add(facetXMLSnip);
-
 
600
					}
-
 
601
					
-
 
602
					Utils.info("2 facetXMLSnip=" + facetXMLSnip);
-
 
603
				}
-
 
604
				
-
 
605
				String facetXMLSnippetsStr = 
-
 
606
					StringUtils.join(facetXMLSnippets, "\n");
-
 
607
					
-
 
608
				Utils.info("facetXMLSnippetsStr=" + facetXMLSnippetsStr);
-
 
609
				
-
 
610
				// Collect PROPERTIES
-
 
611
				String propertiesXMLSnippetsStr = 
-
 
612
					this.getPropertiesXMLSnippet(expEntity, facetFeatureIDs, 2);
-
 
613
				
-
 
614
				Utils.info(propertiesXMLSnippetsStr);
-
 
615
				
-
 
616
				String entityXMLSnip = this.getEntityXMLSnippet(expEntity, 
-
 
617
						facetXMLSnippetsStr, propertiesXMLSnippetsStr, 1);
-
 
618
				
-
 
619
				Utils.info(entityXMLSnip);
-
 
620
				
-
 
621
				entityXMLSnippets.add(entityXMLSnip);
-
 
622
			}
-
 
623
		}
-
 
624
		*/
-
 
625
			
-
 
626
		// </IRData>
-
 
627
		entityXMLSnippets.add("</IRData>");
-
 
628
		
-
 
629
		String irDataXML = StringUtils.join(entityXMLSnippets, "\n");
-
 
630
		Utils.info(irDataXML);
-
 
631
		
380
		
632
		// Write it to file
-
 
633
		String irDataFilename = Utils.EXPORT_IR_PATH + "irdata.xml";
-
 
634
		DBUtils.store(irDataXML, irDataFilename);
-
 
635
		
-
 
636
		//Utils.info("this.facetIDFacetValues=" + this.facetIDFacetValues);
-
 
637
		CreationUtils.storeFacetValues(facetIDFacetValues);
381
		List<Object> values = (List<Object>)jw.getValues();
638
		// Store facet values
382
		Utils.info("values=" + values);
639
		
383
		
640
	}
-
 
641
	
-
 
642
	/**
-
 
643
	 * 
-
 
644
	 * @param borrowedSlides
384
		// Append to facet values
645
	 * @return
-
 
646
	 */
-
 
647
	private String processBorrowedSlide(ExpandedEntity expEntity, 
-
 
648
			Slide borrowedSlide, Set<Long> processedFacets) throws Exception {
-
 
649
		// Borrowed category ID
-
 
650
		long borrowedCategoryID = CreationUtils.getBorrowedCategoryID(borrowedSlide.getSlideDefinitionID(), expEntity.getCategoryID());
-
 
651
		Utils.info("borrowedCategoryID=" + borrowedCategoryID);
-
 
652
			
385
 
653
		// Slide definition ID
-
 
654
		long slideDefID = borrowedSlide.getSlideDefinitionID();
-
 
655
		Utils.info("borrowed slideDefID=" + slideDefID);
386
		Utils.info("facetDefID=" + facetDefID);
656
		
387
		
657
		DefinitionsContainer defs = 
388
		List<String> facetValues = this.facetIDFacetValues.get(
658
			Catalog.getInstance().getDefinitionsContainer();
389
				new Long(facetDefID));
659
		
390
		
660
		// Get IR Data Rule
-
 
661
		FacetRuleDefinition facetRuleDef = 
-
 
662
			defs.getFacetRuleDefinitionForSlide(borrowedCategoryID, slideDefID);
-
 
663
		
-
 
664
		//Utils.info("borrowed facetRuleDef=" + facetRuleDef);
-
 
665
		String facetXMLSnippet = null; 
-
 
666
		
-
 
667
		// If there is direct IR data rule defined for borrowed slide
-
 
668
		if(facetRuleDef != null) {
391
		if(facetValues == null) {
669
			ExpandedFacetRuleDefinition expFacetRuleDef = 
-
 
670
				new ExpandedFacetRuleDefinition(facetRuleDef);
392
			facetValues = new ArrayList<String>();
671
			
-
 
672
 
-
 
673
			if(!processedFacets.contains(expFacetRuleDef.getFacetDefinitionID())){
-
 
674
				// 	Return XML snippet			
-
 
675
				facetXMLSnippet = this.processFacet(expEntity, expFacetRuleDef);
393
			this.facetIDFacetValues.put(new Long(facetDefID), facetValues);
676
				processedFacets.add(expFacetRuleDef.getFacetDefinitionID());
-
 
677
			}
-
 
678
		}
394
		}
679
		else {
-
 
680
			List<String> facetXMLSnippets = new ArrayList<String>();
-
 
681
			
395
		
682
			// Get FacetRuleDefinition objects for all features in 
-
 
683
			// borrowed slide for which IR rule is defined
396
		if(values != null) {
684
			List<Feature> features = borrowedSlide.getFeatures();
-
 
685
			for (Feature feature : features) {
397
			for(Object value : values) {
686
				String featureFacetXMLSnippet = 
398
				String strValue = value.toString();
687
					this.processBorrowedFeature(borrowedCategoryID, expEntity, feature, processedFacets);
-
 
688
				
399
				
689
				if(featureFacetXMLSnippet != null && !StringUtils.trim(
-
 
690
						featureFacetXMLSnippet).isEmpty()) {
400
				if(!facetValues.contains(strValue)) {
691
					facetXMLSnippets.add(featureFacetXMLSnippet);
401
					facetValues.add(strValue);
692
				}
-
 
693
			}
-
 
694
			
-
 
695
			// Get FacetRuleDefinition objects for all children slides in 
-
 
696
			// borrowed slide for which IR rule is defined
-
 
697
			if(borrowedSlide.hasChildrenSlides()) {
-
 
698
				String childrenSlidesFacetXMLSnippet = 
-
 
699
					this.processBorrowedChildrenSlides(borrowedCategoryID, 
-
 
700
							expEntity, borrowedSlide, processedFacets);
-
 
701
 
-
 
702
				if(childrenSlidesFacetXMLSnippet != null && !StringUtils.trim(
-
 
703
						childrenSlidesFacetXMLSnippet).isEmpty()) {
-
 
704
					facetXMLSnippets.add(childrenSlidesFacetXMLSnippet);
-
 
705
				}
402
				}
706
			}
403
			}
707
			
-
 
708
			facetXMLSnippet = StringUtils.join(facetXMLSnippets, "\n");
-
 
709
		}
404
		}
710
 
405
 
711
		
-
 
712
		if(facetXMLSnippet == null || StringUtils.trim(facetXMLSnippet).isEmpty()) {
406
		ExpandedFacetDefinition expFacet = new ExpandedFacetDefinition(facet);
-
 
407
		// Parse returned Python list
-
 
408
		String facetXMLSnip = null;
713
			return null;
409
		if(values != null) {
-
 
410
			facetXMLSnip = this.getFacetXMLSnippet(expFacet, values, 2);
714
		}
411
		}
715
		
412
		
-
 
413
		Utils.info("0 facetXMLSnip=" + facetXMLSnip);
716
		return facetXMLSnippet;
414
		return facetXMLSnip;
717
	}
415
	}
-
 
416
 
-
 
417
	
718
	
418
	
719
	/**
419
	/**
720
	 * 
420
	 * 
721
	 * @param borrowedCategoryID
-
 
722
	 * @param expEntity
421
	 * @param expFacetDef
723
	 * @param feature
422
	 * @param values
724
	 * @return
423
	 * @param indent
725
	 * @throws Exception 
424
	 * @return String XML Snippet
726
	 */
425
	 */
727
	private String processBorrowedFeature(long borrowedCategoryID, 
-
 
728
			ExpandedEntity expEntity, Feature feature, Set<Long> processedFacets) throws Exception {
426
	private String getFacetXMLSnippet(ExpandedFacetDefinition expFacetDef,	List<Object> values, int indent) {
729
	
-
 
730
		long featureDefID = feature.getFeatureDefinitionID();
-
 
731
		Utils.info("borrowed featureDefID=" + featureDefID);
-
 
732
		
427
		
733
		DefinitionsContainer defs = 
428
		// <Facet Label="Form Factor">
-
 
429
		List<String> xmlSnippet = new ArrayList<String>();
734
			Catalog.getInstance().getDefinitionsContainer();
430
		String target = expFacetDef.getTarget();
735
		
431
		
736
		FacetRuleDefinition facetRuleDefForFeature = 
-
 
737
			defs.getFacetRuleDefinitionForFeature(borrowedCategoryID, 
-
 
738
				featureDefID);
-
 
739
		
-
 
740
		List<String> facetXMLSnippets = new ArrayList<String>();
-
 
741
		
-
 
742
		//Utils.info("borrowed facetRuleDefForFeature=" +facetRuleDefForFeature);
-
 
743
		
-
 
744
		if(facetRuleDefForFeature != null) {
-
 
745
			ExpandedFacetRuleDefinition expFacetRuleDefForFeature = 
-
 
746
				new ExpandedFacetRuleDefinition(facetRuleDefForFeature);
-
 
747
			if(!processedFacets.contains(expFacetRuleDefForFeature.getFacetDefinitionID())){
432
		xmlSnippet.add(this.xmlIndentation[indent] + "<Facet ID=\"" + expFacetDef.getID() + "\" Label=\"" + target + "\">");
748
					
-
 
749
				String snip = this.processFacet(expEntity, 
-
 
750
						expFacetRuleDefForFeature);
-
 
751
				
-
 
752
				if(snip != null) {
-
 
753
					facetXMLSnippets.add(snip);
-
 
754
					processedFacets.add(expFacetRuleDefForFeature.getFacetDefinitionID());
-
 
755
				}
-
 
756
			}
-
 
757
		}
-
 
758
 
-
 
759
 
-
 
760
		String xmlSnip =  StringUtils.join(facetXMLSnippets, "\n");
-
 
761
		
433
		
762
		if(StringUtils.trim(xmlSnip).isEmpty()) {
434
		//<Value>Candybar</Value>
763
			return null;
435
		for(Object value : values) {
-
 
436
			xmlSnippet.add(this.xmlIndentation[indent + 1] + "<Value>" + value.toString() + "</Value>");
764
		}
437
		}
765
		
438
		
-
 
439
		//</Facet>
-
 
440
		xmlSnippet.add(this.xmlIndentation[indent] + "</Facet>");
-
 
441
		
766
		return xmlSnip;
442
		return StringUtils.join(xmlSnippet, "\n");
767
	}
443
	}
768
	
444
 
769
	/**
445
	/**
770
	 * 
-
 
771
	 * @param expEntity
-
 
772
	 * @param borrowedSlide
-
 
773
	 * @return
-
 
774
	 * @throws Exception 
446
	 * @throws Exception 
-
 
447
	 * 
775
	 */
448
	 */
776
	private String processBorrowedChildrenSlides(long borrowedCategoryID, 
-
 
777
			ExpandedEntity expEntity, Slide borrowedSlide, Set<Long> processedFacets) throws Exception {
449
	public void exportIRData() throws Exception {
778
		DefinitionsContainer defs = 
-
 
779
			Catalog.getInstance().getDefinitionsContainer();
450
		DefinitionsContainer defs = Catalog.getInstance().getDefinitionsContainer();
780
	
-
 
781
		List<Slide> childrenSlides = borrowedSlide.getChildrenSlides();
451
		Map<Long, List<FacetDefinition>> slideFacets = defs.getSlideFacetDefinitions();
782
		List<String> facetXMLSnippets = new ArrayList<String>();
-
 
783
		
452
		
784
		for (Slide childSlide : childrenSlides) {
-
 
785
			long childSlideDefID = childSlide.getSlideDefinitionID();
-
 
786
			Utils.info("borrowed childSlideDefID=" + childSlideDefID);
-
 
787
			
453
		// <IRData>
788
			FacetRuleDefinition facetRuleDefForSlide = 
-
 
789
				defs.getFacetRuleDefinitionForSlide(borrowedCategoryID, 
454
		List<String> irDataXMLSnippets = new ArrayList<String>();
790
						childSlideDefID);
455
		irDataXMLSnippets.add("<IRData>");
791
			
456
		
792
			//Utils.info("borrowed facetRuleDefForSlide=" +facetRuleDefForSlide);
-
 
793
			
-
 
794
			if(facetRuleDefForSlide != null) {
-
 
795
				ExpandedFacetRuleDefinition expFacetRuleDefForSlide = 
457
		Map<Long, Entity> entities =  CreationUtils.getEntities();
796
					new ExpandedFacetRuleDefinition(
458
		for(Entity entity: entities.values()){
797
							facetRuleDefForSlide);
459
			double itemPrice = 0;
798
				if(!processedFacets.contains(expFacetRuleDefForSlide.getFacetDefinitionID())){
-
 
799
					String snip = this.processFacet(expEntity, 
-
 
800
							expFacetRuleDefForSlide);
460
			long entityID = entity.getID();
801
					
-
 
802
					if(snip != null && !StringUtils.trim(snip).isEmpty()) {
461
			List<Item> items = client.getItemsByCatalogId(entity.getID());
803
						facetXMLSnippets.add(snip);
462
			if(items == null){
804
						processedFacets.add(expFacetRuleDefForSlide.getFacetDefinitionID());
-
 
805
					}
463
				continue;
806
				}
-
 
807
			}
464
			}
808
			
465
			
809
			// Features?
-
 
810
			if(childSlide.hasFeatures()) {
466
			Date todate = new Date();
811
				List<Feature> features = childSlide.getFeatures();
-
 
812
				for(Feature feature : features) {
467
			Boolean hasActiveItem = false;
813
					String childrenSlideFeatureFacetXMLSnippet = 
-
 
814
						this.processBorrowedFeature(borrowedCategoryID, expEntity, 
-
 
815
							feature, processedFacets);
468
			for(Item item: items){
816
					
-
 
817
					if(childrenSlideFeatureFacetXMLSnippet != null &&
-
 
818
						!StringUtils.trim(childrenSlideFeatureFacetXMLSnippet).
469
				if(item.getItemStatus() != status.ACTIVE || todate.getTime() < item.getStartDate()){
819
							isEmpty()) {
470
					continue;
820
						
-
 
821
						facetXMLSnippets.add(
-
 
822
								childrenSlideFeatureFacetXMLSnippet);
-
 
823
						
-
 
824
					}
-
 
825
				}
471
				}
826
			}
-
 
827
			
-
 
828
			// Children slides
472
				hasActiveItem = true;
829
			if(childSlide.hasChildrenSlides()) {
473
				if(itemPrice == 0){
830
				String childrenSlidesFacetXMLSnippet = 
474
					itemPrice = item.getSellingPrice();
831
					this.processBorrowedChildrenSlides(borrowedCategoryID, 
-
 
832
							expEntity, childSlide, processedFacets);
475
				}else if(itemPrice>item.getSellingPrice()){
833
 
-
 
834
				if(childrenSlidesFacetXMLSnippet != null &&
-
 
835
					!StringUtils.trim(childrenSlidesFacetXMLSnippet).
476
					itemPrice = item.getSellingPrice();
836
						isEmpty()) {
-
 
837
					
-
 
838
					facetXMLSnippets.add(childrenSlidesFacetXMLSnippet);
-
 
839
				}
477
				}
840
			}
478
			}
841
		}
-
 
842
 
-
 
843
		String xmlSnip =  StringUtils.join(facetXMLSnippets, "\n");
-
 
844
		
-
 
845
		if(StringUtils.trim(xmlSnip).isEmpty()) {
-
 
846
			return null;
-
 
847
		}
-
 
848
		
-
 
849
		return xmlSnip;
-
 
850
	}
-
 
851
 
-
 
852
	
-
 
853
	/**
-
 
854
	 * 
-
 
855
	 * @param expEntity
-
 
856
	 * @param expFacetDef
-
 
857
	 * @return
-
 
858
	 * @throws Exception 
-
 
859
	 */
-
 
860
	@SuppressWarnings("unchecked")
-
 
861
	private String processFacet(ExpandedEntity expEntity, 
-
 
862
			ExpandedFacetRuleDefinition expFacetRuleDef) throws Exception {
-
 
863
		
-
 
864
		//Utils.info("expFacetRuleDef=" + expFacetRuleDef);
-
 
865
 
-
 
866
		Utils.info("expEntity.getID()=" + expEntity.getID());
-
 
867
		
-
 
868
		// to get the price from services and pass it on to fill in solr
-
 
869
		
-
 
870
//		CatalogServiceClient catalogServiceClient = new CatalogServiceClient();
-
 
871
//		in.shop2020.model.v1.catalog.InventoryService.Client client = catalogServiceClient.getClient();
-
 
872
		
-
 
873
		double itemPrice = 0;
-
 
874
		List<Item> items = client.getItemsByCatalogId(expEntity.getID());
-
 
875
		Date todate = new Date();
-
 
876
		for(Item item: items){
479
			if(!hasActiveItem){
877
			if(item.getItemStatus() != status.ACTIVE || todate.getTime() < item.getStartDate()){
-
 
878
				continue;
480
				continue;
879
			}
481
			}
880
			if(itemPrice == 0){
482
			ExpandedEntity expEntity = new ExpandedEntity(entity);
881
				itemPrice = item.getSellingPrice();
483
			long categoryID = expEntity.getCategoryID();
882
			}else if(itemPrice>item.getSellingPrice()){
484
			if(categoryID == -1){
883
				itemPrice = item.getSellingPrice();
485
				continue;
884
			}
486
			}
885
			
487
			
886
		}
-
 
887
		
-
 
888
		DefinitionsContainer defs = 
-
 
889
			Catalog.getInstance().getDefinitionsContainer();
-
 
890
		
488
 
891
		IRDataJythonWrapper jw = new IRDataJythonWrapper();
-
 
892
		
489
			
893
		jw.setExpandedEntity(expEntity);
-
 
894
		jw.setExpandedFacetRuleDefinition(expFacetRuleDef);
490
			List<ExpandedSlide> expSlides = expEntity.getExpandedSlides();
895
		jw.setEntityPrice(itemPrice);
491
			if(expSlides==null){continue;}
896
		
492
			
897
		// Set FeatureDefinition
-
 
898
		FeatureDefinition featureDef = 
493
			List<String> entityXMLSnippets = new ArrayList<String>();
899
			expFacetRuleDef.getFeatureDefinition();
494
			entityXMLSnippets.add(this.xmlIndentation[1] + "<Entity ID=\""+ entityID +"\">");
900
		
495
			
901
		if(featureDef != null) {
-
 
902
			jw.setFeatureDefinition(featureDef);
496
			String parentCategory = expEntity.getCategory().getLabel();
903
			
-
 
904
			// Set Feature
-
 
905
			Utils.info("featureDef.getID()=" + featureDef.getID());
497
			entityXMLSnippets.add(this.xmlIndentation[2] + "<Category>" + StringEscapeUtils.escapeXml(parentCategory) + "</Category>");
906
			
498
			
907
			Feature feature = 
-
 
908
				CreationUtils.getFeature(expEntity.getID(), featureDef.getID());
-
 
909
			
499
			
910
			// Special case for Brand
-
 
911
			if(expFacetRuleDef.getFacetDefinitionID() == 50001 ||
-
 
912
			   expFacetRuleDef.getFacetDefinitionID() == 50010 ||
500
			String title = StringEscapeUtils.escapeXml(expEntity.getBrand()) + " " + StringEscapeUtils.escapeXml(expEntity.getModelName()) + 
913
				expFacetRuleDef.getFacetDefinitionID() == 50011) {
501
				((expEntity.getModelNumber() != null) ? (" " +	StringEscapeUtils.escapeXml(expEntity.getModelNumber())): "");
914
				
502
 
915
				// Execute Python script
503
			entityXMLSnippets.add(this.xmlIndentation[2] +	"<Title>" + StringEscapeUtils.escapeXml(title) + "</Title>");
916
				jw.executeRule();
-
 
917
				
-
 
918
			}
-
 
919
			
504
			
920
			// Can happen when to slide's feature which is dropped in favor 
-
 
921
			// of a borrowed slide
-
 
922
			else if(feature != null) {
-
 
923
				
-
 
924
				// Normalize
-
 
925
				if(defs.needsNormalization(feature.getFeatureDefinitionID())) {
-
 
926
					Utils.info("needsNormalization feature=" + feature.getFeatureDefinitionID());
-
 
927
					
-
 
928
					feature = this.normalize(feature);
-
 
929
				}
-
 
930
				
-
 
931
				ExpandedFeature expFeature = new ExpandedFeature(feature);
-
 
932
				
-
 
933
				jw.setExpandedFeature(expFeature);
-
 
934
				
-
 
935
				// Execute Python script
-
 
936
				jw.executeRule();
-
 
937
			}
-
 
938
		}
-
 
939
		
-
 
940
		
-
 
941
 
505
 
942
		
-
 
943
		// Set SlideDefinition
-
 
944
		SlideDefinition slideDef = expFacetRuleDef.getSlideDefinition();
-
 
945
		if(slideDef != null) {
-
 
946
			jw.setSlideDefinition(slideDef);
-
 
947
			
-
 
948
			// Set Slide
-
 
949
			Utils.info("slideDef.getID()=" + slideDef.getID());
-
 
950
			
-
 
951
			Slide slide = CreationUtils.getSlide(expEntity.getID(), slideDef.getID());
-
 
952
			
-
 
953
			// Slide may not have been included infavor of a borrowed slide
-
 
954
			if(slide == null) {
-
 
955
				return null;
-
 
956
			}
-
 
957
			
506
			
958
			ExpandedSlide expSlide = new ExpandedSlide(slide);
507
			String subCategory = defs.getCategory(categoryID).getLabel();
-
 
508
			String  mainCategory = defs.getCategory(categoryID).getParentCategory().getLabel();
959
			
509
			
960
			jw.setExpandedSlide(expSlide);
510
			String brand = expEntity.getBrand();
961
			
511
			
962
			// Execute Python script
-
 
963
			jw.executeRule();
-
 
964
		}
512
			
965
		
513
			
966
		//
514
			//Create zero slide
-
 
515
			Slide zeroSlide = createZeroSlide(brand, itemPrice, mainCategory, subCategory);
-
 
516
			ExpandedSlide expandedZeroSlide = new ExpandedSlide(zeroSlide);
-
 
517
			expSlides.add(expandedZeroSlide);
967
		
518
			
-
 
519
			for(ExpandedSlide expSlide: expSlides){
-
 
520
				System.out.println(expSlide.getSlideDefinitionID());
-
 
521
				if(slideFacets.containsKey(expSlide.getSlideDefinitionID())){
-
 
522
					List<FacetDefinition> facets = slideFacets.get(expSlide.getSlideDefinitionID());
968
		if(slideDef == null && featureDef == null){
523
					for(FacetDefinition facet: facets){
969
			if(expFacetRuleDef.getIRDataRuleDefinition().getScript() != null){
524
						for(FacetSlideDefinition facetSlides: facet.getFacetSlideDefinitions()){
-
 
525
							if(facetSlides.getSlideDefinitionID() != expSlide.getSlideDefinitionID()){continue;}
-
 
526
							ExpandedFacetSlideDefinition expFacetSlideDef = new ExpandedFacetSlideDefinition(facetSlides) ;
-
 
527
							for(ExpandedFeature expFeature: expSlide.getExpandedFeatures()){
-
 
528
								if(defs.needsNormalization(expFeature.getFeatureDefinitionID())) {
-
 
529
									Utils.info("needsNormalization feature=" + expFeature.getFeatureDefinitionID());
970
				jw.executeRule();
530
									//expFeature = this.normalize(expFeature);
-
 
531
								}
-
 
532
							}
-
 
533
							entityXMLSnippets.add(processFacet(facet, expSlide, expFacetSlideDef, facet.getID()));
-
 
534
						}
-
 
535
					}
-
 
536
				}
971
			}
537
			}
-
 
538
			
-
 
539
			// Collect PROPERTIES
-
 
540
			String propertiesXMLSnippetsStr = this.getPropertiesXMLSnippet(expEntity, new ArrayList<Long>(), 2);
-
 
541
			entityXMLSnippets.add(propertiesXMLSnippetsStr);
-
 
542
			entityXMLSnippets.add(this.xmlIndentation[1] + "</Entity>");
-
 
543
			System.out.println(entityXMLSnippets);
-
 
544
			irDataXMLSnippets.addAll(entityXMLSnippets);
-
 
545
 
972
		}
546
		}
973
		
547
		
-
 
548
		irDataXMLSnippets.add("</IRData>");
974
		
549
		
975
		List<Object> values = (List<Object>)jw.getValues();
550
		String irDataXML = StringUtils.join(irDataXMLSnippets, "\n");
976
		Utils.info("values=" + values);
551
		Utils.info(irDataXML);
977
		
-
 
978
		// Append to facet values
-
 
979
		long facetDefID = expFacetRuleDef.getFacetDefinitionID();
-
 
980
		Utils.info("facetDefID=" + facetDefID);
-
 
981
		
-
 
982
		List<String> facetValues = this.facetIDFacetValues.get(
-
 
983
				new Long(facetDefID));
-
 
984
		
-
 
985
		if(facetValues == null) {
-
 
986
			facetValues = new ArrayList<String>();
-
 
987
			this.facetIDFacetValues.put(new Long(facetDefID), facetValues);
-
 
988
		}
-
 
989
		
552
		
990
		if(values != null) {
553
		// Write it to file
991
			for(Object value : values) {
554
		String irDataFilename = Utils.EXPORT_IR_PATH + "irdata.xml";
992
				String strValue = value.toString();
555
		DBUtils.store(irDataXML, irDataFilename);
993
				
556
	}
-
 
557
	
-
 
558
	private Slide createZeroSlide(String brand, double price, String mainCategory, String subCategory) {
994
				if(!facetValues.contains(strValue)) {
559
		Slide zeroSlide = new Slide(130000);
995
					facetValues.add(strValue);
560
		List<Feature> zeroSlideFeatures = new ArrayList<Feature>();
996
				}
-
 
997
			}
561
		
-
 
562
		Feature brandFeature = new Feature(120080);
-
 
563
		Bullet brandBullet = new Bullet(new PrimitiveDataObject(brand));
-
 
564
		List<Bullet> brandBullets = new ArrayList<Bullet>();
-
 
565
		brandBullets.add(brandBullet);
-
 
566
		brandFeature.setBullets(brandBullets);
-
 
567
		zeroSlideFeatures.add(brandFeature);
998
		}
568
		
-
 
569
		Feature priceFeature = new Feature(120128);
-
 
570
		Bullet priceBullet = new Bullet(new PrimitiveDataObject((new Double(price)).toString()));
-
 
571
		List<Bullet> priceBullets = new ArrayList<Bullet>();
-
 
572
		priceBullets.add(priceBullet);
-
 
573
		priceFeature.setBullets(priceBullets);
-
 
574
		zeroSlideFeatures.add(priceFeature);
999
 
575
 
1000
		// Parse returned Python list
576
		Feature mainCategoryFeature = new Feature(120123);
-
 
577
		Bullet mainCategoryBullet = new Bullet(new PrimitiveDataObject(mainCategory));
-
 
578
		List<Bullet> mainCategoryBullets = new ArrayList<Bullet>();
1001
		String facetXMLSnip = null;
579
		mainCategoryBullets.add(mainCategoryBullet);
-
 
580
		mainCategoryFeature.setBullets(mainCategoryBullets);
1002
		if(values != null) {
581
		zeroSlideFeatures.add(mainCategoryFeature);
1003
			
582
		
1004
			// Get IR Data XML snippet for this entity and facet
583
		Feature subCategoryFeature = new Feature(120124);
1005
			facetXMLSnip = this.getFacetXMLSnippet(expFacetRuleDef, values, 2);
584
		Bullet subCategoryBullet = new Bullet(new PrimitiveDataObject(subCategory));
1006
		}
-
 
-
 
585
		List<Bullet> subCategoryBullets = new ArrayList<Bullet>();
-
 
586
		subCategoryBullets.add(subCategoryBullet);
-
 
587
		subCategoryFeature.setBullets(subCategoryBullets);
-
 
588
		zeroSlideFeatures.add(subCategoryFeature);
1007
		
589
		
1008
		Utils.info("0 facetXMLSnip=" + facetXMLSnip);
590
		zeroSlide.setFeatures(zeroSlideFeatures);
1009
		return facetXMLSnip;
591
		return zeroSlide;
1010
	}
592
	}
-
 
593
 
1011
	
594
	
1012
	/**
595
	/**
1013
	 * 
596
	 * 
1014
	 * @param feature
597
	 * @param feature
1015
	 * @return Feature
598
	 * @return Feature
1016
	 * @throws Exception 
599
	 * @throws Exception 
1017
	 */
600
	 */
1018
	private Feature normalize(Feature feature) throws Exception {
601
	private ExpandedFeature normalize(ExpandedFeature expFeature) throws Exception {
1019
		ExpandedFeature expFeature = new ExpandedFeature(feature);
-
 
1020
 
-
 
1021
		BulletDefinition bulletDef = 
602
		BulletDefinition bulletDef = 
1022
			expFeature.getFeatureDefinition().getBulletDefinition();
603
			expFeature.getFeatureDefinition().getBulletDefinition();
1023
		
604
		
1024
		ExpandedBulletDefinition expBulletDef = new ExpandedBulletDefinition(
605
		ExpandedBulletDefinition expBulletDef = new ExpandedBulletDefinition(
1025
				bulletDef);
606
				bulletDef);
Line 1039... Line 620...
1039
			Bullet newBullet = new Bullet(new PrimitiveDataObject(newValue));
620
			Bullet newBullet = new Bullet(new PrimitiveDataObject(newValue));
1040
			newBullet.setUnitID(newUnitID);
621
			newBullet.setUnitID(newUnitID);
1041
			
622
			
1042
			newBullets.add(newBullet);
623
			newBullets.add(newBullet);
1043
			
624
			
1044
			feature.setBullets(newBullets);
625
			expFeature.setBullets(newBullets);
1045
		}
626
		}
1046
		else {
627
		else {
1047
			Utils.severe("Normalization not defined for non-primitives");
628
			Utils.severe("Normalization not defined for non-primitives");
1048
		}
629
		}
1049
		
630
		
1050
		return feature;
631
		return expFeature;
1051
	}
632
	}
1052
 
633
 
1053
	/**
634
	/**
1054
	 * 
635
	 * 
1055
	 * @param expEntity
636
	 * @param expEntity
Line 1067... Line 648...
1067
		
648
		
1068
		// Features
649
		// Features
1069
		List<ExpandedSlide> expSlides = expEntity.getExpandedSlides();
650
		List<ExpandedSlide> expSlides = expEntity.getExpandedSlides();
1070
		
651
		
1071
		for(ExpandedSlide expSlide : expSlides) {
652
		for(ExpandedSlide expSlide : expSlides) {
-
 
653
			if(expSlide.getSlideDefinitionID() == 13000){
-
 
654
				continue;
-
 
655
			}
1072
			List<ExpandedFeature> expFeatures = expSlide.getExpandedFeatures();
656
			List<ExpandedFeature> expFeatures = expSlide.getExpandedFeatures();
1073
			
657
			
1074
			if(expSlide.getFreeformContent() != null) {
658
			if(expSlide.getFreeformContent() != null) {
1075
				ffc.add(expSlide.getFreeformContent().getFreeformText());
659
				ffc.add(expSlide.getFreeformContent().getFreeformText());
1076
			}
660
			}
Line 1146... Line 730...
1146
		// TODO
730
		// TODO
1147
		
731
		
1148
		return StringUtils.join(xmlSnippet, "\n");
732
		return StringUtils.join(xmlSnippet, "\n");
1149
	}
733
	}
1150
	
734
	
1151
	/**
-
 
1152
	 * 
-
 
1153
	 * @param expEntity
-
 
1154
	 * @param facetXMLSnippets
-
 
1155
	 * @param indent
-
 
1156
	 * @return
-
 
1157
	 */
-
 
1158
	private String getEntityXMLSnippet(ExpandedEntity expEntity, 
-
 
1159
			String facetXMLSnippets, String propertiesXMLSnippets, int indent) {
-
 
1160
 
-
 
1161
		//<Entity ID="40001">
-
 
1162
		List<String> xmlSnippet = new ArrayList<String>();
-
 
1163
		
-
 
1164
		String entityID = new Long(expEntity.getID()).toString();
-
 
1165
		xmlSnippet.add(this.xmlIndentation[indent] + "<Entity ID=\""+ entityID + 
-
 
1166
				"\">");
-
 
1167
 
-
 
1168
		//<Category>Business Phones</Category>
-
 
1169
		String parentCategory = expEntity.getCategory().getLabel();
-
 
1170
		xmlSnippet.add(this.xmlIndentation[indent + 1] + "<Category>" + 
-
 
1171
				StringEscapeUtils.escapeXml(parentCategory) + "</Category>");
-
 
1172
 
-
 
1173
		/*
-
 
1174
		//<Category>Business Phones</Category>
-
 
1175
		String category = expEntity.getCategory().getLabel();
-
 
1176
		xmlSnippet.add(this.xmlIndentation[indent + 1] + "<SubCategory>" + 
-
 
1177
				StringEscapeUtils.escapeXml(category) + "</SubCategory>");
-
 
1178
		 */
-
 
1179
		
-
 
1180
		//<Title>Nokia E71</Title>
-
 
1181
		String title = StringEscapeUtils.escapeXml(expEntity.getBrand()) + " " +
-
 
1182
		StringEscapeUtils.escapeXml(expEntity.getModelName()) + 
-
 
1183
			((expEntity.getModelNumber() != null) ? 
-
 
1184
					(" " + 
-
 
1185
						StringEscapeUtils.escapeXml(expEntity.getModelNumber()))
-
 
1186
					: "");
-
 
1187
 
-
 
1188
		xmlSnippet.add(this.xmlIndentation[indent + 1] + 
-
 
1189
				"<Title>" + StringEscapeUtils.escapeXml(title) + "</Title>");
-
 
1190
		
-
 
1191
		xmlSnippet.add(facetXMLSnippets);
-
 
1192
 
-
 
1193
		xmlSnippet.add(propertiesXMLSnippets);
-
 
1194
		
-
 
1195
		//</Entity>
-
 
1196
		xmlSnippet.add(this.xmlIndentation[indent] + "</Entity>");
-
 
1197
		
-
 
1198
		return StringUtils.join(xmlSnippet, "\n");
-
 
1199
	}
-
 
1200
	
-
 
1201
	/**
-
 
1202
	 * 
-
 
1203
	 * @param expFacetDef
-
 
1204
	 * @param values
-
 
1205
	 * @param indent
-
 
1206
	 * @return String XML Snippet
-
 
1207
	 */
-
 
1208
	private String getFacetXMLSnippet(
-
 
1209
			ExpandedFacetRuleDefinition expFacetRuleDef, 
-
 
1210
			List<Object> values, int indent) {
-
 
1211
		
-
 
1212
		// <Facet Label="Form Factor">
-
 
1213
		List<String> xmlSnippet = new ArrayList<String>();
-
 
1214
		String target = expFacetRuleDef.getFacetDefinition().getTarget();
-
 
1215
		
-
 
1216
		xmlSnippet.add(this.xmlIndentation[indent] + "<Facet ID=\"" + 
-
 
1217
				expFacetRuleDef.getFacetDefinitionID() + "\" Label=\"" + 
-
 
1218
				target + "\">");
-
 
1219
		
-
 
1220
		//<Value>Candybar</Value>
-
 
1221
		for(Object value : values) {
-
 
1222
			xmlSnippet.add(this.xmlIndentation[indent + 1] + "<Value>" + 
-
 
1223
					value.toString() + "</Value>");
-
 
1224
		}
-
 
1225
		
-
 
1226
		//</Facet>
-
 
1227
		xmlSnippet.add(this.xmlIndentation[indent] + "</Facet>");
-
 
1228
		
-
 
1229
		return StringUtils.join(xmlSnippet, "\n");
-
 
1230
	}
-
 
1231
}
735
}