Subversion Repositories SmartDukaan

Rev

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

Rev 83 Rev 88
Line 10... Line 10...
10
import in.shop2020.metamodel.definitions.Category;
10
import in.shop2020.metamodel.definitions.Category;
11
import in.shop2020.metamodel.definitions.DatatypeDefinition;
11
import in.shop2020.metamodel.definitions.DatatypeDefinition;
12
import in.shop2020.metamodel.definitions.DefinitionsContainer;
12
import in.shop2020.metamodel.definitions.DefinitionsContainer;
13
import in.shop2020.metamodel.definitions.EntityContainer;
13
import in.shop2020.metamodel.definitions.EntityContainer;
14
import in.shop2020.metamodel.definitions.FacetDefinition;
14
import in.shop2020.metamodel.definitions.FacetDefinition;
-
 
15
import in.shop2020.metamodel.definitions.FacetRuleDefinition;
15
import in.shop2020.metamodel.definitions.FeatureDefinition;
16
import in.shop2020.metamodel.definitions.FeatureDefinition;
16
import in.shop2020.metamodel.definitions.SlideDefinition;
17
import in.shop2020.metamodel.definitions.SlideDefinition;
17
import in.shop2020.metamodel.util.ExpandedBullet;
18
import in.shop2020.metamodel.util.ExpandedBullet;
18
import in.shop2020.metamodel.util.ExpandedBulletDefinition;
19
import in.shop2020.metamodel.util.ExpandedBulletDefinition;
19
import in.shop2020.metamodel.util.ExpandedCategoryFacetDefinition;
20
import in.shop2020.metamodel.util.ExpandedCategoryFacetDefinition;
Line 353... Line 354...
353
				ExpandedEntity expEntity = 
354
				ExpandedEntity expEntity = 
354
					ents.getExpandedEntity(entity.getID());
355
					ents.getExpandedEntity(entity.getID());
355
				
356
				
356
				List<String> facetXMLSnippets = new ArrayList<String>();
357
				List<String> facetXMLSnippets = new ArrayList<String>();
357
				
358
				
358
				// Collect FACETs
359
				// Collect features which have become FACETs
359
				
-
 
360
				List<Long> facetFeatureIDs = new ArrayList<Long>();
360
				List<Long> facetFeatureIDs = new ArrayList<Long>();
361
				
361
				
362
				// For each facet execute Rule
362
				// For each facet execute Rule
363
				for(ExpandedFacetRuleDefinition expFacetRuleDef : 
363
				for(ExpandedFacetRuleDefinition expFacetRuleDef : 
364
						expFacetRuleDefs) {
364
						expFacetRuleDefs) {
365
					String facetXMLSnip = 
365
					String facetXMLSnip = 
366
						this.processFacet(expEntity, expFacetRuleDef);
366
						this.processFacet(expEntity, expFacetRuleDef);
367
					
367
					
368
					if(!facetXMLSnip.isEmpty()) {
368
					if(facetXMLSnip != null && 
-
 
369
							!StringUtils.trim(facetXMLSnip).isEmpty()) {
369
						facetXMLSnippets.add(facetXMLSnip);
370
						facetXMLSnippets.add(facetXMLSnip);
370
						Utils.info("facetXMLSnip=" + facetXMLSnip);
371
						Utils.info("1 facetXMLSnip=" + facetXMLSnip);
371
					}
372
					}
372
					
373
					
373
					// Collect features already covered as Facet
374
					// Collect features already covered as Facet
374
					if(expFacetRuleDef.getFeatureDefinition() != null) {
375
					if(expFacetRuleDef.getFeatureDefinition() != null) {
375
						facetFeatureIDs.add(
376
						facetFeatureIDs.add(new Long(
376
								new Long(expFacetRuleDef.getFeatureDefinitionID()));
377
								expFacetRuleDef.getFeatureDefinitionID()));
377
					}
378
					}
378
				}
379
				}
379
				
380
				
-
 
381
				// Handle borrowed slides
-
 
382
				List<Slide> borrowedSlides = ents.getBorrowedSlides(entity);
-
 
383
				
-
 
384
				for (Slide borrowedSlide : borrowedSlides) {
-
 
385
					String facetXMLSnip = this.processBorrowedSlide(expEntity,
-
 
386
							borrowedSlide);
-
 
387
					
-
 
388
					if(facetXMLSnip != null && 
-
 
389
							!StringUtils.trim(facetXMLSnip).isEmpty()) {
-
 
390
						facetXMLSnippets.add(facetXMLSnip);
-
 
391
					}
-
 
392
					
-
 
393
					Utils.info("2 facetXMLSnip=" + facetXMLSnip);
-
 
394
				}
-
 
395
				
380
				String facetXMLSnippetsStr = 
396
				String facetXMLSnippetsStr = 
381
					StringUtils.join(facetXMLSnippets, "\n");
397
					StringUtils.join(facetXMLSnippets, "\n");
382
					
398
					
383
				Utils.info("facetXMLSnippets=" + facetXMLSnippetsStr);
399
				Utils.info("facetXMLSnippetsStr=" + facetXMLSnippetsStr);
384
				
400
				
385
				// Collect PROPERTIES
401
				// Collect PROPERTIES
386
				String propertiesXMLSnippetsStr = 
402
				String propertiesXMLSnippetsStr = 
387
					this.getPropertiesXMLSnippet(expEntity, facetFeatureIDs, 2);
403
					this.getPropertiesXMLSnippet(expEntity, facetFeatureIDs, 2);
388
				
404
				
Line 408... Line 424...
408
		DBUtils.store(irDataXML, irDataFilename);
424
		DBUtils.store(irDataXML, irDataFilename);
409
	}
425
	}
410
	
426
	
411
	/**
427
	/**
412
	 * 
428
	 * 
-
 
429
	 * @param borrowedSlides
-
 
430
	 * @return
-
 
431
	 */
-
 
432
	private String processBorrowedSlide(ExpandedEntity expEntity, 
-
 
433
			Slide borrowedSlide) throws Exception {
-
 
434
		// Borrowed category ID
-
 
435
		long borrowedCategoryID = borrowedSlide.getBorrowedCategoryID();
-
 
436
		Utils.info("borrowedCategoryID=" + borrowedCategoryID);
-
 
437
			
-
 
438
		// Slide definition ID
-
 
439
		long slideDefID = borrowedSlide.getSlideDefinitionID();
-
 
440
		Utils.info("borrowed slideDefID=" + slideDefID);
-
 
441
		
-
 
442
		DefinitionsContainer defs = 
-
 
443
			Catalog.getInstance().getDefinitionsContainer();
-
 
444
		
-
 
445
		// Get IR Data Rule
-
 
446
		FacetRuleDefinition facetRuleDef = 
-
 
447
			defs.getFacetRuleDefinitionForSlide(borrowedCategoryID, slideDefID);
-
 
448
		
-
 
449
		Utils.info("borrowed facetRuleDef=" + facetRuleDef);
-
 
450
		String facetXMLSnippet = null; 
-
 
451
		
-
 
452
		// If there is direct IR data rule defined for borrowed slide
-
 
453
		if(facetRuleDef != null) {
-
 
454
			ExpandedFacetRuleDefinition expFacetRuleDef = 
-
 
455
				new ExpandedFacetRuleDefinition(facetRuleDef);
-
 
456
			
-
 
457
			// Return XML snippet
-
 
458
			facetXMLSnippet = this.processFacet(expEntity, expFacetRuleDef);
-
 
459
		}
-
 
460
		else {
-
 
461
			List<String> facetXMLSnippets = new ArrayList<String>();
-
 
462
			
-
 
463
			// Get FacetRuleDefinition objects for all features in 
-
 
464
			// borrowed slide for which IR rule is defined
-
 
465
			List<Feature> features = borrowedSlide.getFeatures();
-
 
466
			for (Feature feature : features) {
-
 
467
				String featureFacetXMLSnippet = 
-
 
468
					this.processBorrowedFeature(borrowedCategoryID, expEntity, 
-
 
469
						feature);
-
 
470
				
-
 
471
				if(featureFacetXMLSnippet != null && !StringUtils.trim(
-
 
472
						featureFacetXMLSnippet).isEmpty()) {
-
 
473
					facetXMLSnippets.add(featureFacetXMLSnippet);
-
 
474
				}
-
 
475
			}
-
 
476
			
-
 
477
			// Get FacetRuleDefinition objects for all children slides in 
-
 
478
			// borrowed slide for which IR rule is defined
-
 
479
			if(borrowedSlide.hasChildrenSlides()) {
-
 
480
				String childrenSlidesFacetXMLSnippet = 
-
 
481
					this.processBorrowedChildrenSlides(borrowedCategoryID, 
-
 
482
							expEntity, borrowedSlide);
-
 
483
 
-
 
484
				if(childrenSlidesFacetXMLSnippet != null && !StringUtils.trim(
-
 
485
						childrenSlidesFacetXMLSnippet).isEmpty()) {
-
 
486
					facetXMLSnippets.add(childrenSlidesFacetXMLSnippet);
-
 
487
				}
-
 
488
			}
-
 
489
			
-
 
490
			facetXMLSnippet = StringUtils.join(facetXMLSnippets, "\n");
-
 
491
		}
-
 
492
 
-
 
493
		if(StringUtils.trim(facetXMLSnippet).isEmpty()) {
-
 
494
			return null;
-
 
495
		}
-
 
496
		
-
 
497
		return facetXMLSnippet;
-
 
498
	}
-
 
499
	
-
 
500
	/**
-
 
501
	 * 
-
 
502
	 * @param borrowedCategoryID
-
 
503
	 * @param expEntity
-
 
504
	 * @param feature
-
 
505
	 * @return
-
 
506
	 * @throws Exception 
-
 
507
	 */
-
 
508
	private String processBorrowedFeature(long borrowedCategoryID, 
-
 
509
			ExpandedEntity expEntity, Feature feature) throws Exception {
-
 
510
	
-
 
511
		long featureDefID = feature.getFeatureDefinitionID();
-
 
512
		Utils.info("borrowed featureDefID=" + featureDefID);
-
 
513
		
-
 
514
		DefinitionsContainer defs = 
-
 
515
			Catalog.getInstance().getDefinitionsContainer();
-
 
516
		
-
 
517
		FacetRuleDefinition facetRuleDefForFeature = 
-
 
518
			defs.getFacetRuleDefinitionForFeature(borrowedCategoryID, 
-
 
519
				featureDefID);
-
 
520
		
-
 
521
		List<String> facetXMLSnippets = new ArrayList<String>();
-
 
522
		
-
 
523
		Utils.info("borrowed facetRuleDefForFeature=" + 
-
 
524
				facetRuleDefForFeature);
-
 
525
		
-
 
526
		if(facetRuleDefForFeature != null) {
-
 
527
			ExpandedFacetRuleDefinition expFacetRuleDefForFeature = 
-
 
528
				new ExpandedFacetRuleDefinition(facetRuleDefForFeature);
-
 
529
			
-
 
530
			String snip = this.processFacet(expEntity, 
-
 
531
					expFacetRuleDefForFeature);
-
 
532
			
-
 
533
			if(snip != null) {
-
 
534
				facetXMLSnippets.add(snip);
-
 
535
			}
-
 
536
		}
-
 
537
 
-
 
538
 
-
 
539
		String xmlSnip =  StringUtils.join(facetXMLSnippets, "\n");
-
 
540
		
-
 
541
		if(StringUtils.trim(xmlSnip).isEmpty()) {
-
 
542
			return null;
-
 
543
		}
-
 
544
		
-
 
545
		return xmlSnip;
-
 
546
	}
-
 
547
	
-
 
548
	/**
-
 
549
	 * 
-
 
550
	 * @param expEntity
-
 
551
	 * @param borrowedSlide
-
 
552
	 * @return
-
 
553
	 * @throws Exception 
-
 
554
	 */
-
 
555
	private String processBorrowedChildrenSlides(long borrowedCategoryID, 
-
 
556
			ExpandedEntity expEntity, Slide borrowedSlide) throws Exception {
-
 
557
		DefinitionsContainer defs = 
-
 
558
			Catalog.getInstance().getDefinitionsContainer();
-
 
559
	
-
 
560
		List<Slide> childrenSlides = borrowedSlide.getChildrenSlides();
-
 
561
		List<String> facetXMLSnippets = new ArrayList<String>();
-
 
562
		
-
 
563
		for (Slide childSlide : childrenSlides) {
-
 
564
			long childSlideDefID = childSlide.getSlideDefinitionID();
-
 
565
			Utils.info("borrowed childSlideDefID=" + childSlideDefID);
-
 
566
			
-
 
567
			FacetRuleDefinition facetRuleDefForSlide = 
-
 
568
				defs.getFacetRuleDefinitionForSlide(borrowedCategoryID, 
-
 
569
						childSlideDefID);
-
 
570
			
-
 
571
			Utils.info("borrowed facetRuleDefForSlide=" + 
-
 
572
					facetRuleDefForSlide);
-
 
573
			
-
 
574
			if(facetRuleDefForSlide != null) {
-
 
575
				ExpandedFacetRuleDefinition expFacetRuleDefForSlide = 
-
 
576
					new ExpandedFacetRuleDefinition(
-
 
577
							facetRuleDefForSlide);
-
 
578
				
-
 
579
				String snip = this.processFacet(expEntity, 
-
 
580
						expFacetRuleDefForSlide);
-
 
581
				
-
 
582
				if(snip != null && !StringUtils.trim(snip).isEmpty()) {
-
 
583
					facetXMLSnippets.add(snip);
-
 
584
				}
-
 
585
			}
-
 
586
			
-
 
587
			// Features?
-
 
588
			if(childSlide.hasFeatures()) {
-
 
589
				List<Feature> features = childSlide.getFeatures();
-
 
590
				for(Feature feature : features) {
-
 
591
					String childrenSlideFeatureFacetXMLSnippet = 
-
 
592
						this.processBorrowedFeature(borrowedCategoryID, expEntity, 
-
 
593
							feature);
-
 
594
					
-
 
595
					if(childrenSlideFeatureFacetXMLSnippet != null &&
-
 
596
						!StringUtils.trim(childrenSlideFeatureFacetXMLSnippet).
-
 
597
							isEmpty()) {
-
 
598
						
-
 
599
						facetXMLSnippets.add(
-
 
600
								childrenSlideFeatureFacetXMLSnippet);
-
 
601
						
-
 
602
					}
-
 
603
				}
-
 
604
			}
-
 
605
			
-
 
606
			// Children slides
-
 
607
			if(childSlide.hasChildrenSlides()) {
-
 
608
				String childrenSlidesFacetXMLSnippet = 
-
 
609
					this.processBorrowedChildrenSlides(borrowedCategoryID, 
-
 
610
							expEntity, childSlide);
-
 
611
 
-
 
612
				if(childrenSlidesFacetXMLSnippet != null &&
-
 
613
					!StringUtils.trim(childrenSlidesFacetXMLSnippet).
-
 
614
						isEmpty()) {
-
 
615
					
-
 
616
					facetXMLSnippets.add(childrenSlidesFacetXMLSnippet);
-
 
617
				}
-
 
618
			}
-
 
619
		}
-
 
620
 
-
 
621
		String xmlSnip =  StringUtils.join(facetXMLSnippets, "\n");
-
 
622
		
-
 
623
		if(StringUtils.trim(xmlSnip).isEmpty()) {
-
 
624
			return null;
-
 
625
		}
-
 
626
		
-
 
627
		return xmlSnip;
-
 
628
	}
-
 
629
 
-
 
630
	
-
 
631
	/**
-
 
632
	 * 
413
	 * @param expEntity
633
	 * @param expEntity
414
	 * @param expFacetDef
634
	 * @param expFacetDef
415
	 * @return
635
	 * @return
416
	 * @throws Exception 
636
	 * @throws Exception 
417
	 */
637
	 */
Line 437... Line 657...
437
			jw.setFeatureDefinition(featureDef);
657
			jw.setFeatureDefinition(featureDef);
438
			
658
			
439
			// Set Feature
659
			// Set Feature
440
			Utils.info("featureDef.getID()=" + featureDef.getID());
660
			Utils.info("featureDef.getID()=" + featureDef.getID());
441
			
661
			
442
			
-
 
443
			Feature feature = 
662
			Feature feature = 
444
				ents.getFeature(expEntity.getID(), featureDef.getID());
663
				ents.getFeature(expEntity.getID(), featureDef.getID());
445
			
664
			
446
			// Can happen with un-referred features like Brand
665
			// Can happen with un-referred features like Brand
-
 
666
			// or a slide's feature which is dropped in favor of a borrowed 
-
 
667
			// slide
447
			if(feature != null) {
668
			if(feature != null) {
448
				ExpandedFeature expFeature = new ExpandedFeature(feature);
669
				ExpandedFeature expFeature = new ExpandedFeature(feature);
449
				
670
				
450
				jw.setExpandedFeature(expFeature);
671
				jw.setExpandedFeature(expFeature);
-
 
672
				
-
 
673
				// Execute Python script
-
 
674
				jw.executeRule();
451
			}
675
			}
452
		}
676
		}
453
		
677
		
454
		// Set SlideDefinition
678
		// Set SlideDefinition
455
		SlideDefinition slideDef = expFacetRuleDef.getSlideDefinition();
679
		SlideDefinition slideDef = expFacetRuleDef.getSlideDefinition();
Line 458... Line 682...
458
			
682
			
459
			// Set Slide
683
			// Set Slide
460
			Utils.info("slideDef.getID()=" + slideDef.getID());
684
			Utils.info("slideDef.getID()=" + slideDef.getID());
461
			
685
			
462
			Slide slide = ents.getSlide(expEntity.getID(), slideDef.getID());
686
			Slide slide = ents.getSlide(expEntity.getID(), slideDef.getID());
-
 
687
			
-
 
688
			// Slide may not have been included infavor of a borrowed slide
-
 
689
			if(slide == null) {
-
 
690
				return null;
-
 
691
			}
-
 
692
			
463
			ExpandedSlide expSlide = new ExpandedSlide(slide);
693
			ExpandedSlide expSlide = new ExpandedSlide(slide);
464
			
694
			
465
			jw.setExpandedSlide(expSlide);
695
			jw.setExpandedSlide(expSlide);
-
 
696
			
-
 
697
			// Execute Python script
-
 
698
			jw.executeRule();
466
		}
699
		}
467
		
700
		
468
		// Execute Python script
-
 
469
		jw.executeRule();
-
 
470
		
701
		
471
		// Parse returned Python list
702
		// Parse returned Python list
472
		List<Object> values = (List<Object>)jw.getValues();
703
		List<Object> values = (List<Object>)jw.getValues();
473
		Utils.info("values=" + values);
704
		Utils.info("values=" + values);
474
		
705
		
475
		String facetXMLSnip = "";
706
		String facetXMLSnip = null;
476
		if(values != null) {
707
		if(values != null) {
477
			
708
			
478
			// Get IR Data XML snippet for this entity and facet
709
			// Get IR Data XML snippet for this entity and facet
479
			facetXMLSnip = this.getFacetXMLSnippet(expFacetRuleDef, values, 2);
710
			facetXMLSnip = this.getFacetXMLSnippet(expFacetRuleDef, values, 2);
480
		}
711
		}
481
		Utils.info(facetXMLSnip);
-
 
482
		
712
		
-
 
713
		Utils.info("0 facetXMLSnip=" + facetXMLSnip);
483
		return facetXMLSnip;
714
		return facetXMLSnip;
484
	}
715
	}
485
 
716
 
486
	/**
717
	/**
487
	 * 
718
	 *