Subversion Repositories SmartDukaan

Rev

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

Rev 6359 Rev 7037
Line 39... Line 39...
39
import java.io.ObjectInputStream;
39
import java.io.ObjectInputStream;
40
import java.io.ObjectOutputStream;
40
import java.io.ObjectOutputStream;
41
import java.io.OutputStream;
41
import java.io.OutputStream;
42
import java.text.MessageFormat;
42
import java.text.MessageFormat;
43
import java.util.ArrayList;
43
import java.util.ArrayList;
-
 
44
import java.util.Arrays;
44
import java.util.Collection;
45
import java.util.Collection;
45
import java.util.Collections;
46
import java.util.Collections;
46
import java.util.HashMap;
47
import java.util.HashMap;
47
import java.util.Iterator;
48
import java.util.Iterator;
48
import java.util.List;
49
import java.util.List;
Line 75... Line 76...
75
		// destinationDbPath = args[1];
76
		// destinationDbPath = args[1];
76
		// dryRun = args[2];
77
		// dryRun = args[2];
77
		// }
78
		// }
78
		//
79
		//
79
		ContentMigrator contentmigrator = new ContentMigrator(sourceDbPath,destinationDbPath);
80
		ContentMigrator contentmigrator = new ContentMigrator(sourceDbPath,destinationDbPath);
80
		List<Long> l = CreationUtils.getInconsistentEntities();
-
 
81
		Iterator<Long> s = l.iterator();
81
		contentmigrator.migrateTablets();
82
		while (s.hasNext()){
-
 
83
			Long s1 = s.next();
-
 
84
			if (s1== 1004315) {
-
 
85
				System.out.println("Got unwanted id");
-
 
86
				s.remove();
-
 
87
			} else {
-
 
88
				
-
 
89
				System.out.println(s1);
-
 
90
			}
-
 
91
			CreationUtils.storeInconsistentEntities(l);
-
 
92
		}
-
 
93
 
82
 
94
	}
83
	}
95
 
84
 
96
	private void migrateWarrantyForCategory(Long catgoryId) throws Exception {
85
	private void migrateWarrantyForCategory(Long catgoryId) throws Exception {
97
		Collection<Entity> entities = CreationUtils.getEntities(catgoryId);
86
		Collection<Entity> entities = CreationUtils.getEntities(catgoryId);
Line 1935... Line 1924...
1935
    		categoryName = expEntity.getCategory().getLabel();
1924
    		categoryName = expEntity.getCategory().getLabel();
1936
    	}
1925
    	}
1937
    	String template = "Buy {0} {1} {2} at $minPriceItem.getSellingPrice(). All {3} are 100% Original and carry full Manufacturers Warranty since we procure directly from the Brand. Free Next Day Delivery.";
1926
    	String template = "Buy {0} {1} {2} at $minPriceItem.getSellingPrice(). All {3} are 100% Original and carry full Manufacturers Warranty since we procure directly from the Brand. Free Next Day Delivery.";
1938
    	return MessageFormat.format(template, expEntity.getBrand(), expEntity.getModelName(), expEntity.getModelNumber(), categoryName.toLowerCase());
1927
    	return MessageFormat.format(template, expEntity.getBrand(), expEntity.getModelName(), expEntity.getModelNumber(), categoryName.toLowerCase());
1939
    }
1928
    }
-
 
1929
    
-
 
1930
public void migrateTablets() throws Exception {
-
 
1931
		
-
 
1932
		//Starting entity id for new Category with 10000
-
 
1933
		Collection<Entity> entities = CreationUtils.getEntities(10010);
-
 
1934
		long newCounter;
-
 
1935
		//entities = (List<Entity>)this.clone(entities);
-
 
1936
		for (Entity entity : entities) {
-
 
1937
			long entityId = entity.getID();
-
 
1938
			newCounter = Long.parseLong("1" + String.valueOf(entityId));
-
 
1939
			Entity newEntity = new Entity(newCounter, 20010);
-
 
1940
			try {
-
 
1941
				List<Slide> entitySlides = entity.getSlides();
-
 
1942
				if (entity == null || entitySlides == null) {
-
 
1943
					continue;
-
 
1944
				}
-
 
1945
				List<Slide> newEntitySlides = new ArrayList<Slide>();
-
 
1946
				/*Slide introSlide = entity.getSlide(130001);
-
 
1947
				Slide summarySlide = entity.getSlide(130054);
-
 
1948
				Slide packageContents = entity.getSlide(130025);*/
-
 
1949
				for (Slide slide : entitySlides) {
-
 
1950
					if (Arrays.asList(130054L, 130025L, 130001L).contains(slide.getSlideDefinitionID())) {
-
 
1951
						slide=(Slide)this.clone(slide); 
-
 
1952
						newEntitySlides.add(slide);
-
 
1953
					}
-
 
1954
					FreeformContent ffc1 = slide.getFreeformContent();
-
 
1955
					if(ffc1 != null){
-
 
1956
						Map<String, Media> mediaMap = ffc1.getMedias();
-
 
1957
						if(mediaMap==null){
-
 
1958
							continue;
-
 
1959
						}
-
 
1960
						for(Media media : mediaMap.values()){
-
 
1961
							if(media.getType().equals(Type.IMAGE) || media.getType().equals(Type.DOCUMENT)){
-
 
1962
								copyMedia(String.valueOf(newCounter), String.valueOf(entityId),media);
-
 
1963
							}
-
 
1964
						}
-
 
1965
					}
-
 
1966
				}
-
 
1967
				
-
 
1968
				List<Long> newSlideSequence = new ArrayList<Long>();
-
 
1969
				newSlideSequence.add(130001L);
-
 
1970
				newSlideSequence.add(130054L);
-
 
1971
				newSlideSequence.add(130172L);
-
 
1972
				newSlideSequence.add(130173L);
-
 
1973
				newSlideSequence.add(130174L);
-
 
1974
				newSlideSequence.add(130175L);
-
 
1975
				newSlideSequence.add(130176L);
-
 
1976
				newSlideSequence.add(130177L);
-
 
1977
				newSlideSequence.add(130178L);
-
 
1978
				newSlideSequence.add(130180L);
-
 
1979
				newSlideSequence.add(130183L);
-
 
1980
				newSlideSequence.add(130025L);
-
 
1981
				
-
 
1982
				newEntity.setSlideSequence(newSlideSequence);
-
 
1983
				newEntity.setBrand(entity.getBrand());
-
 
1984
				newEntity.setModelName(entity.getModelName());
-
 
1985
				newEntity.setModelNumber(entity.getModelNumber());
-
 
1986
				//entitySlides.remove(featureSlide);
-
 
1987
				newEntity.setSlides(newEntitySlides);
-
 
1988
				EntityState es = new EntityState(newCounter, 20010, "admin");
-
 
1989
				es.setBrand(entity.getBrand());
-
 
1990
				es.setModelName(entity.getModelName());
-
 
1991
				es.setModelNumber(entity.getModelNumber());
-
 
1992
				CreationUtils.createEntity(newEntity, es);
-
 
1993
				System.out.println("New entity : " + newCounter + " created using : " + entityId);
-
 
1994
				System.out.println(CreationUtils.getEntity(newCounter));
-
 
1995
				newCounter++;
-
 
1996
			}catch(Exception e){
-
 
1997
				System.out.println("Could not migrate " + entityId);
-
 
1998
			}
-
 
1999
		}
-
 
2000
		
-
 
2001
	}
-
 
2002
 
1940
 
2003
 
1941
}
2004
}
1942
 
2005