Subversion Repositories SmartDukaan

Rev

Rev 8873 | Rev 8913 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 8873 Rev 8909
Line 1... Line 1...
1
package in.shop2020.util;
1
package in.shop2020.util;
2
 
2
 
3
import in.shop2020.metamodel.core.Bullet;
3
import in.shop2020.metamodel.core.Bullet;
-
 
4
import in.shop2020.metamodel.core.BulletDataObject;
4
import in.shop2020.metamodel.core.Entity;
5
import in.shop2020.metamodel.core.Entity;
5
import in.shop2020.metamodel.core.EntityState;
6
import in.shop2020.metamodel.core.EntityState;
6
import in.shop2020.metamodel.core.EntityStatus;
7
import in.shop2020.metamodel.core.EntityStatus;
7
import in.shop2020.metamodel.core.EnumDataObject;
8
import in.shop2020.metamodel.core.EnumDataObject;
8
import in.shop2020.metamodel.core.ExpertReview;
9
import in.shop2020.metamodel.core.ExpertReview;
Line 51... Line 52...
51
import java.util.Calendar;
52
import java.util.Calendar;
52
import java.util.Collection;
53
import java.util.Collection;
53
import java.util.Collections;
54
import java.util.Collections;
54
import java.util.Date;
55
import java.util.Date;
55
import java.util.HashMap;
56
import java.util.HashMap;
-
 
57
import java.util.HashSet;
56
import java.util.Iterator;
58
import java.util.Iterator;
57
import java.util.LinkedHashMap;
59
import java.util.LinkedHashMap;
58
import java.util.List;
60
import java.util.List;
59
import java.util.Map;
61
import java.util.Map;
60
import java.util.Set;
62
import java.util.Set;
61
import java.util.TreeMap;
63
import java.util.TreeMap;
62
 
64
 
63
import org.apache.commons.collections.CollectionUtils;
65
import org.apache.commons.collections.CollectionUtils;
64
import org.apache.commons.io.IOUtils;
66
import org.apache.commons.io.IOUtils;
65
import org.apache.commons.lang.ArrayUtils;
-
 
66
import org.apache.commons.lang.StringUtils;
67
import org.apache.commons.lang.StringUtils;
67
 
68
 
68
import com.google.gson.Gson;
69
import com.google.gson.Gson;
69
import com.google.gson.reflect.TypeToken;
70
import com.google.gson.reflect.TypeToken;
70
 
71
 
Line 115... Line 116...
115
		contentmigrator.touchEntityState(1008711l);
116
		contentmigrator.touchEntityState(1008711l);
116
		contentmigrator.touchEntityState(1008714l);
117
		contentmigrator.touchEntityState(1008714l);
117
		contentmigrator.touchEntityState(1008715l);
118
		contentmigrator.touchEntityState(1008715l);
118
		contentmigrator.touchEntityState(1005505l);
119
		contentmigrator.touchEntityState(1005505l);
119
		contentmigrator.touchEntityState(1006864l);*/
120
		contentmigrator.touchEntityState(1006864l);*/
-
 
121
		contentmigrator.clearEmptyPrimitiveBullets();
120
		contentmigrator.getTablets();
122
		contentmigrator.migrateSoftCategories();
121
	}
123
	}
122
	
124
	
123
	private void changeKeys() throws Exception {
125
	private void changeKeys() throws Exception {
124
		Map<Long, Entity>  e = CreationUtils.getEntities();
126
		Map<Long, Entity>  e = CreationUtils.getEntities();
125
		for (Map.Entry<Long, Entity> entry : e.entrySet()) {
127
		for (Map.Entry<Long, Entity> entry : e.entrySet()) {
Line 2582... Line 2584...
2582
			sb.append(entity.getID() + "\t").append(StringUtils.join(as, "\t")).append("\n");
2584
			sb.append(entity.getID() + "\t").append(StringUtils.join(as, "\t")).append("\n");
2583
		}
2585
		}
2584
		System.out.println(sb);
2586
		System.out.println(sb);
2585
	}
2587
	}
2586
	
2588
	
-
 
2589
	private void migrateSoftCategories() throws Exception{
-
 
2590
		Long ANDROID = 110614l;
-
 
2591
		Long WINDOWS = 110615l;
-
 
2592
		Long DUALSIM = 110616l;
-
 
2593
		Long TRISIM = 110617l;
-
 
2594
		Long CDMA = 110618l;
-
 
2595
		Long BASIC = 110619l;
-
 
2596
		Long TOUCH = 110620l;
-
 
2597
		Long PHABLET = 110621l;
-
 
2598
		Long IOS = 110622l;
-
 
2599
		Set<Long> softSet = new HashSet<Long>();
-
 
2600
		DefinitionsContainer defc = Catalog.getInstance().getDefinitionsContainer();
-
 
2601
		Collection<Entity> entities = CreationUtils.getEntities(10006l);
-
 
2602
		for(Entity entity : entities){
-
 
2603
			EntityState es = CreationUtils.getEntityState(entity.getID());
-
 
2604
			if (es.getStatus().equals(EntityStatus.READY)) {
-
 
2605
				softSet.clear();
-
 
2606
				System.out.println("Entity ID : " + es.getID());
-
 
2607
				List <Slide> slides = entity.getSlides();
-
 
2608
				if(slides != null) {
-
 
2609
					for(Slide slide : slides){
-
 
2610
						if(slide.getSlideDefinitionID() == 130020l)  {
-
 
2611
							List<Feature> fs = slide.getFeatures();
-
 
2612
							if (fs!=null){
-
 
2613
								for (Feature f1 : fs){
-
 
2614
									if(f1.getFeatureDefinitionID()==120043l){
-
 
2615
										List <Bullet> bullets = f1.getBullets();
-
 
2616
										if(bullets != null) {
-
 
2617
											for(Bullet b : bullets){
-
 
2618
												String bulletString = defc.getEnumValue(((EnumDataObject)b.getDataObject()).getEnumValueID()).getValue();
-
 
2619
												if (bulletString.contains("Android")){
-
 
2620
													softSet.add(ANDROID);
-
 
2621
													System.out.println("Added android");
-
 
2622
													break;
-
 
2623
												} 
-
 
2624
												else if (bulletString.contains("Windows")){
-
 
2625
													softSet.add(WINDOWS);
-
 
2626
													System.out.println("Added Windows");
-
 
2627
													break;
-
 
2628
												}
-
 
2629
												else if (bulletString.contains("iOS")){
-
 
2630
													softSet.add(IOS);
-
 
2631
													System.out.println("Added Apple");
-
 
2632
													break;
-
 
2633
												}
-
 
2634
											}
-
 
2635
										}
-
 
2636
									}
-
 
2637
								}
-
 
2638
							}
-
 
2639
						}
-
 
2640
						
-
 
2641
						if(slide.getSlideDefinitionID() == 130005l)  {
-
 
2642
							List<Feature> fs = slide.getFeatures();
-
 
2643
							if (fs!=null){
-
 
2644
								for (Feature f1 : fs){
-
 
2645
									if(f1.getFeatureDefinitionID()==120127l){
-
 
2646
										List <Bullet> bullets = f1.getBullets();
-
 
2647
										if(bullets != null) {
-
 
2648
											for(Bullet b : bullets){
-
 
2649
												String bulletString = defc.getEnumValue(((EnumDataObject)b.getDataObject()).getEnumValueID()).getValue();
-
 
2650
												if (bulletString.equals("Dual-SIM")){
-
 
2651
													softSet.add(DUALSIM);
-
 
2652
													System.out.println("Added Dual-SIM");
-
 
2653
													break;
-
 
2654
												} 
-
 
2655
												else if (bulletString.equals("Tri-SIM")){
-
 
2656
													softSet.add(TRISIM);
-
 
2657
													System.out.println("Added Tri-SIM");
-
 
2658
													break;
-
 
2659
												}
-
 
2660
											}
-
 
2661
										}
-
 
2662
									}
-
 
2663
									else if(f1.getFeatureDefinitionID()==120012l){
-
 
2664
										List <Bullet> bullets = f1.getBullets();
-
 
2665
										if(bullets != null) {
-
 
2666
											for(Bullet b : bullets){
-
 
2667
												String bulletString = ""; 
-
 
2668
												try{
-
 
2669
													bulletString = defc.getEnumValue(((EnumDataObject)b.getDataObject()).getEnumValueID()).getValue();
-
 
2670
												}catch (Exception e){
-
 
2671
													//b.	
-
 
2672
												}
-
 
2673
												if (bulletString.contains("CDMA")){
-
 
2674
													softSet.add(CDMA);
-
 
2675
													System.out.println("Added CDMA for 2G");
-
 
2676
													break;
-
 
2677
												} 
-
 
2678
											}
-
 
2679
										}
-
 
2680
									}
-
 
2681
									else if(f1.getFeatureDefinitionID()==120013l){
-
 
2682
										List <Bullet> bullets = f1.getBullets();
-
 
2683
										if(bullets != null) {
-
 
2684
											for(Bullet b : bullets){
-
 
2685
												String bulletString = ((PrimitiveDataObject)b.getDataObject()).getValue();
-
 
2686
												if (bulletString.contains("CDMA")){
-
 
2687
													softSet.add(CDMA);
-
 
2688
													System.out.println("Added CDMA for 3G");
-
 
2689
													break;
-
 
2690
												} 
-
 
2691
											}
-
 
2692
										}
-
 
2693
									}
-
 
2694
								}
-
 
2695
							}
-
 
2696
						}
-
 
2697
						
-
 
2698
						if(slide.getSlideDefinitionID() == 130002l)  {
-
 
2699
							List<Feature> fs = slide.getFeatures();
-
 
2700
							if (fs!=null){
-
 
2701
								for (Feature f1 : fs){
-
 
2702
									if(f1.getFeatureDefinitionID()==120009l){
-
 
2703
										List <Bullet> bullets = f1.getBullets();
-
 
2704
										if(bullets != null) {
-
 
2705
											for(Bullet b : bullets){
-
 
2706
												String bulletString = defc.getEnumValue(((EnumDataObject)b.getDataObject()).getEnumValueID()).getValue();
-
 
2707
												if(bulletString.equals("T9 keyboard")){
-
 
2708
													softSet.add(BASIC);
-
 
2709
													System.out.println("Added Basic phone");
-
 
2710
													break;
-
 
2711
												}
-
 
2712
											}
-
 
2713
										}
-
 
2714
									}
-
 
2715
								}
-
 
2716
							}
-
 
2717
						}
-
 
2718
						
-
 
2719
						if(slide.getSlideDefinitionID() == 130003l)  {
-
 
2720
							List<Feature> fs = slide.getFeatures();
-
 
2721
							if (fs!=null){
-
 
2722
								for (Feature f1 : fs){
-
 
2723
									if(f1.getFeatureDefinitionID()==120005l){
-
 
2724
										List <Bullet> bullets = f1.getBullets();
-
 
2725
										if(bullets != null) {
-
 
2726
											for(Bullet b : bullets){
-
 
2727
												String bulletString = ((PrimitiveDataObject)b.getDataObject()).getValue();
-
 
2728
												float f = Float.valueOf(bulletString);
-
 
2729
												if(f >= 5f ){
-
 
2730
													softSet.add(PHABLET);
-
 
2731
													System.out.println("Added Basic phone");
-
 
2732
													break;
-
 
2733
												}
-
 
2734
											}
-
 
2735
										}
-
 
2736
									}
-
 
2737
									else if(f1.getFeatureDefinitionID() == 120082l){
-
 
2738
										softSet.add(TOUCH);
-
 
2739
										System.out.println("Added Touch phone");
-
 
2740
									}
-
 
2741
								}
-
 
2742
							}
-
 
2743
						}
-
 
2744
					}
-
 
2745
				}
-
 
2746
				if(softSet.size()>0){
-
 
2747
					Slide summarySlide = entity.getSlide(130054l);
-
 
2748
					Feature f = new Feature(120513l);
-
 
2749
					List<Feature> features = summarySlide.getFeatures();
-
 
2750
					List<Bullet> softBullets = new ArrayList<Bullet>();
-
 
2751
					features.add(f);
-
 
2752
					for(Long enumId : softSet){
-
 
2753
						softBullets.add(new Bullet(new EnumDataObject(enumId)));
-
 
2754
					}
-
 
2755
					f.setBullets(softBullets);
-
 
2756
					CreationUtils.updateEntity(entity);
-
 
2757
				}
-
 
2758
			}
-
 
2759
		}
-
 
2760
	}
-
 
2761
	
-
 
2762
	private void clearEmptyPrimitiveBullets() throws Exception{
-
 
2763
		Map<Long, Entity> es = CreationUtils.getEntities();
-
 
2764
		for( Map.Entry<Long, Entity> entry : es.entrySet()){
-
 
2765
			Entity e = entry.getValue();
-
 
2766
			List<Slide> slides = e.getSlides();
-
 
2767
			if(slides != null){
-
 
2768
				for (Slide slide : slides){
-
 
2769
					List<Feature> features = slide.getFeatures();
-
 
2770
					if (features != null){
-
 
2771
						for(Feature feature : features){
-
 
2772
							List<Bullet> bullets = feature.getBullets();
-
 
2773
							if(bullets != null){
-
 
2774
								Iterator<Bullet> bIterator = bullets.iterator();
-
 
2775
								while (bIterator.hasNext()){
-
 
2776
									BulletDataObject b = bIterator.next().getDataObject();
-
 
2777
									if(b.getClass().equals(PrimitiveDataObject.class)){
-
 
2778
										PrimitiveDataObject pdo = (PrimitiveDataObject)b;
-
 
2779
										if(pdo.getValue().equals("")){
-
 
2780
											bIterator.remove();
-
 
2781
											System.out.println("Removed empty Primitive from slide :" + slide.getSlideDefinitionID() + " and entity: " + e.getID());
-
 
2782
										}
-
 
2783
									}
-
 
2784
								}
-
 
2785
							}
-
 
2786
						}
-
 
2787
					}
-
 
2788
				}
-
 
2789
				CreationUtils.updateEntity(e);
-
 
2790
			}
-
 
2791
		}
-
 
2792
	}
-
 
2793
	
2587
}
2794
}
2588
 
2795