Subversion Repositories SmartDukaan

Rev

Rev 9900 | Rev 10699 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
457 rajveer 1
package in.shop2020.util;
2
 
1226 rajveer 3
import in.shop2020.metamodel.core.Bullet;
8909 amit.gupta 4
import in.shop2020.metamodel.core.BulletDataObject;
479 rajveer 5
import in.shop2020.metamodel.core.Entity;
1226 rajveer 6
import in.shop2020.metamodel.core.EntityState;
7129 amit.gupta 7
import in.shop2020.metamodel.core.EntityStatus;
3873 mandeep.dh 8
import in.shop2020.metamodel.core.EnumDataObject;
7590 amit.gupta 9
import in.shop2020.metamodel.core.ExpertReview;
10692 amit.gupta 10
import in.shop2020.metamodel.core.ExpertReviewStatus;
1226 rajveer 11
import in.shop2020.metamodel.core.Feature;
479 rajveer 12
import in.shop2020.metamodel.core.FreeformContent;
5370 amit.gupta 13
import in.shop2020.metamodel.core.Media;
14
import in.shop2020.metamodel.core.Media.Type;
1226 rajveer 15
import in.shop2020.metamodel.core.PrimitiveDataObject;
479 rajveer 16
import in.shop2020.metamodel.core.Slide;
580 rajveer 17
import in.shop2020.metamodel.definitions.BulletDefinition;
457 rajveer 18
import in.shop2020.metamodel.definitions.Catalog;
580 rajveer 19
import in.shop2020.metamodel.definitions.Category;
20
import in.shop2020.metamodel.definitions.CategorySlideDefinition;
457 rajveer 21
import in.shop2020.metamodel.definitions.DefinitionsContainer;
580 rajveer 22
import in.shop2020.metamodel.definitions.FeatureDefinition;
23
import in.shop2020.metamodel.definitions.SlideDefinition;
24
import in.shop2020.metamodel.definitions.SlideFeatureDefinition;
479 rajveer 25
import in.shop2020.metamodel.util.CreationUtils;
8749 amit.gupta 26
import in.shop2020.metamodel.util.CreationUtils1;
2720 mandeep.dh 27
import in.shop2020.metamodel.util.ExpandedBullet;
1739 rajveer 28
import in.shop2020.metamodel.util.ExpandedEntity;
5945 mandeep.dh 29
import in.shop2020.model.v1.catalog.CatalogService.Client;
2287 rajveer 30
import in.shop2020.model.v1.catalog.Item;
31
import in.shop2020.model.v1.catalog.status;
3127 rajveer 32
import in.shop2020.thrift.clients.CatalogClient;
4706 amit.gupta 33
import in.shop2020.utils.Logger;
457 rajveer 34
 
2720 mandeep.dh 35
import java.io.BufferedReader;
5370 amit.gupta 36
import java.io.ByteArrayInputStream;
37
import java.io.ByteArrayOutputStream;
2720 mandeep.dh 38
import java.io.DataInputStream;
39
import java.io.File;
40
import java.io.FileInputStream;
8014 amit.gupta 41
import java.io.FileNotFoundException;
5370 amit.gupta 42
import java.io.FileOutputStream;
8014 amit.gupta 43
import java.io.FileReader;
5370 amit.gupta 44
import java.io.InputStream;
2720 mandeep.dh 45
import java.io.InputStreamReader;
5370 amit.gupta 46
import java.io.ObjectInputStream;
47
import java.io.ObjectOutputStream;
48
import java.io.OutputStream;
8014 amit.gupta 49
import java.io.Reader;
5760 amit.gupta 50
import java.text.MessageFormat;
2720 mandeep.dh 51
import java.util.ArrayList;
7037 amit.gupta 52
import java.util.Arrays;
8749 amit.gupta 53
import java.util.Calendar;
5370 amit.gupta 54
import java.util.Collection;
3873 mandeep.dh 55
import java.util.Collections;
7129 amit.gupta 56
import java.util.Date;
4706 amit.gupta 57
import java.util.HashMap;
8909 amit.gupta 58
import java.util.HashSet;
5671 amit.gupta 59
import java.util.Iterator;
7123 amit.gupta 60
import java.util.LinkedHashMap;
9171 amit.gupta 61
import java.util.LinkedHashSet;
2720 mandeep.dh 62
import java.util.List;
63
import java.util.Map;
7111 amit.gupta 64
import java.util.Set;
2720 mandeep.dh 65
import java.util.TreeMap;
580 rajveer 66
 
7932 amit.gupta 67
import org.apache.commons.collections.CollectionUtils;
5370 amit.gupta 68
import org.apache.commons.io.IOUtils;
4818 amit.gupta 69
import org.apache.commons.lang.StringUtils;
70
 
8014 amit.gupta 71
import com.google.gson.Gson;
72
import com.google.gson.reflect.TypeToken;
73
 
457 rajveer 74
/*
7997 amit.gupta 75
 * @author rajveer 	
457 rajveer 76
 * 
77
 *
78
 */
79
 
80
public class ContentMigrator {
81
	private String sourceDbPath;
82
	private String destinationDbPath;
4964 amit.gupta 83
 
457 rajveer 84
	public static void main(String[] args) throws Exception {
85
		String usage = "Usage: ContentMigrator {source db path}{destination db path}";
8749 amit.gupta 86
 
4964 amit.gupta 87
		String sourceDbPath = null, destinationDbPath = null;
88
		String dryRun = null;
89
		// if(args.length < 2) {
90
		// System.out.println(usage);
91
		// System.exit(-1);
92
		// }else{
93
		// sourceDbPath = args[0];
94
		// destinationDbPath = args[1];
95
		// dryRun = args[2];
96
		// }
97
		//
7186 amit.gupta 98
		ContentMigrator contentmigrator = new ContentMigrator(sourceDbPath,destinationDbPath);
8841 amit.gupta 99
 
100
 
7590 amit.gupta 101
		/*List<Long> entityId = Arrays.asList(1001674l,1002575l,1005331l,1005165l,1005164l,1005111l,1005109l,1004952l,1004940l,1004871l,1004701l,1004429l,1004197l,1006174l,1006077l,1005901l,1005757l,1005754l,1005724l,1005704l,1005598l,1005576l,1005558l,1007394l,1007230l,1007226l,1007218l,1007089l,1006925l,1006822l,1006814l,1006175l);
7507 amit.gupta 102
		for (Long eId : entityId){
7590 amit.gupta 103
		}*/
8262 amit.gupta 104
		//contentmigrator.reorderPhones();
8014 amit.gupta 105
		//System.out.println(contentmigrator.getItems().size());
8268 amit.gupta 106
		/*contentmigrator.touchEntityState(1008423l);
8262 amit.gupta 107
		contentmigrator.touchEntityState(1008424l);
108
		contentmigrator.touchEntityState(1008427l);
8268 amit.gupta 109
		contentmigrator.touchEntityState(1008428l);*/
4964 amit.gupta 110
 
8869 amit.gupta 111
		//contentmigrator.migrateToMongo();
8865 amit.gupta 112
		//contentmigrator.getEditedEntities();
113
		/*contentmigrator.touchEntityState(1008706l);
114
		contentmigrator.touchEntityState(1008707l);
115
		contentmigrator.touchEntityState(1008708l);
116
		contentmigrator.touchEntityState(1008709l);
117
		contentmigrator.touchEntityState(1008710l);
118
		contentmigrator.touchEntityState(1008711l);
119
		contentmigrator.touchEntityState(1008714l);
120
		contentmigrator.touchEntityState(1008715l);
121
		contentmigrator.touchEntityState(1005505l);
122
		contentmigrator.touchEntityState(1006864l);*/
8913 amit.gupta 123
		//contentmigrator.clearEmptyPrimitiveBullets();
9171 amit.gupta 124
		//contentmigrator.migrateSoftCategories();
9051 amit.gupta 125
		//contentmigrator.updateSummaryMediaLabel();
10692 amit.gupta 126
		//contentmigrator.migrateReviews();
127
		contentmigrator.test();
128
 
4964 amit.gupta 129
	}
7398 amit.gupta 130
 
10692 amit.gupta 131
	private void test() throws Exception{
132
		PojoCreator pc = new PojoCreator();
133
		List<ExpertReview> expertReviews = getExpertReviews(1007379);
134
		ExpandedEntity ee = CreationUtils.getExpandedEntity(1007379);
135
		pc.createAndStoreContentPojo(ee, expertReviews, "Some warranty");
136
	}
137
 
8841 amit.gupta 138
	private void changeKeys() throws Exception {
139
		Map<Long, Entity>  e = CreationUtils.getEntities();
140
		for (Map.Entry<Long, Entity> entry : e.entrySet()) {
141
			CreationUtils.updateEntity(entry.getValue());
142
			System.out.println("updated " + entry.getValue().getID());
143
		}
144
		//CreationUtils.updateEntity(e);
145
		//CreationUtils.
146
	}
147
 
148
	public void getEditedEntities() throws Exception {
149
		Collection<EntityState> es = CreationUtils1.getEntitiesState().values();
150
		for (EntityState es1 : es) {
8843 amit.gupta 151
			if(es1.getStatus().equals(EntityStatus.READY)){
152
				long mongotime = CreationUtils.getEntityState(es1.getID()).getMerkedReadyOn().getTime()/1000;
153
				long bdbtime = es1.getMerkedReadyOn().getTime()/1000;
154
				if(bdbtime!=mongotime){
155
					System.out.println(es1.getID());
156
				}
8841 amit.gupta 157
			}
158
		}
159
	}
160
 
8749 amit.gupta 161
	private void migrateToMongo() throws Exception{
8841 amit.gupta 162
		long counter = 0;
163
		Collection<EntityState> es = CreationUtils1.getEntitiesState().values();
164
		boolean updated = false;
8865 amit.gupta 165
		StringBuffer buffer = new StringBuffer();
8841 amit.gupta 166
		for (EntityState es1 : es) {
167
			if(es1.getStatus().equals(EntityStatus.READY)){
8865 amit.gupta 168
				long mongotime = CreationUtils.getEntityState(es1.getID()).getMerkedReadyOn().getTime()/1000;
169
				long bdbtime = es1.getMerkedReadyOn().getTime()/1000;
170
				if(bdbtime==mongotime){
171
					updated = false;
172
					Entity e = CreationUtils1.getEntity(es1.getID());
173
					List<Slide> slides = e.getSlides();
174
					for(Slide slide:slides) {
175
						FreeformContent ffc = slide.getFreeformContent();
176
						if (ffc !=null){
177
							Map<String,Media> m1 = ffc.getMedias();
178
							if (m1!=null){
179
								Map<String,Media> m = new LinkedHashMap<String, Media>(m1);
180
								for (Map.Entry<String, Media> m2 : m.entrySet()){
181
									m1.put(Long.toString(++counter), m1.remove(m2.getKey()));
182
									updated = true;
183
								}
8841 amit.gupta 184
							}
185
						}
186
					}
8865 amit.gupta 187
					if(updated){
188
						CreationUtils.updateEntity(e);
189
						System.out.println(e.getID());
190
					}
191
				} else {
192
					buffer.append(es1.getID() + "\n");
8841 amit.gupta 193
				}
8749 amit.gupta 194
			}
195
		}
8865 amit.gupta 196
		System.out.println("Entities counldnt be updated are :\n" + buffer.toString());
8749 amit.gupta 197
	}
198
 
199
	private void migrateContentStore() throws Exception {
200
		for (Map.Entry<Long, Entity> entry :CreationUtils.getEntities().entrySet()){
201
			Entity e = entry.getValue();
202
			Iterator<Slide> it = e.getSlides().iterator();
203
			while(it.hasNext()){
204
				Slide sl = it.next();
205
				//sl.getFreeformContent().me
206
			}
207
		}
208
 
209
	}
210
 
7590 amit.gupta 211
	private void updateSources() throws Exception{
212
		Map<Long,List<ExpertReview>> erMap = CreationUtils.getExpertReviews();
213
		for(Map.Entry<Long, List<ExpertReview>> erEntry : erMap.entrySet()){
214
			List<ExpertReview> erList = erEntry.getValue();
215
			Iterator<ExpertReview> iter = erList.iterator();
216
			while (iter.hasNext()){
217
				ExpertReview er = iter.next();
218
				if (er.getSource().equals("iGyan")){
219
					er.setSource("iGyaan");
220
					System.out.println("changed to iGyaan in entity : " + erEntry.getKey());
221
				}else if(er.getSource().equals("TheMobileIndian")){
222
					er.setSource("The Mobile Indian");
223
					System.out.println("changed to The Mobile Indian in entity : " + erEntry.getKey());
224
				}
225
			}
226
			CreationUtils.storeExpertReview(erEntry.getKey(), erList);
227
		}
228
	}
7507 amit.gupta 229
	private void touchEntityState(Long eId) throws Exception {
230
		EntityState es = CreationUtils.getEntityState(eId);
231
		es.setMerkedReadyOn(new Date());
232
		CreationUtils.updateEntityState(es);
9051 amit.gupta 233
		System.out.println("Entity touched:" + eId);
7507 amit.gupta 234
	}
8798 amit.gupta 235
 
236
	private void touchEntityStates() throws Exception {
237
		Map<Long, EntityState> ess = CreationUtils.getEntitiesState();
238
		Calendar calReady = Calendar.getInstance();
239
		Calendar cal5daysBack = Calendar.getInstance();
240
		Date today = new Date();
241
		cal5daysBack.add(Calendar.DATE, -5);
242
		for (Map.Entry<Long, EntityState> es : ess.entrySet()) {
243
			EntityState est = es.getValue();
244
			if(est.getMerkedReadyOn()!=null){
245
				calReady.setTime(est.getMerkedReadyOn());
246
				if(calReady.compareTo(cal5daysBack) > 0){
247
					est.setMerkedReadyOn(today);
248
					CreationUtils.updateEntityState(est);
249
					System.out.println("Entity touched:" + est.getID());
250
				}
251
			}
252
		}
253
	}
7398 amit.gupta 254
	private void updateModelForBBQ10() throws Exception{
255
		Long entityId = 1007315l;
256
		EntityState e1 = CreationUtils.getEntityState(entityId);
257
		Entity e2 = CreationUtils.getEntity(entityId);
7403 amit.gupta 258
		e1.setModelName("Blackkberry Q10");
259
		e2.setModelName("Blackberry Q10");
7398 amit.gupta 260
		CreationUtils.updateEntity(e2);
261
		CreationUtils.updateEntityState(e1);
262
	}
4964 amit.gupta 263
 
5671 amit.gupta 264
	private void migrateWarrantyForCategory(Long catgoryId) throws Exception {
265
		Collection<Entity> entities = CreationUtils.getEntities(catgoryId);
266
		int count = 0;
267
		for (Entity entity : entities) {
268
			Slide slide = entity.getSlide(130054l);
269
			if(slide!=null){
270
				List<Slide> childrenSlide = slide.getChildrenSlides();
5672 amit.gupta 271
				if(childrenSlide != null){
272
					Iterator<Slide> it = childrenSlide.iterator();
273
					while (it.hasNext()){
274
						Slide sl = it.next();
275
						if (130105l == sl.getSlideDefinitionID()){
276
							it.remove();
277
							System.out.println("Removed warranty slide from entity:" + entity.getID());
278
							break;
279
						}
5671 amit.gupta 280
					}
5672 amit.gupta 281
					CreationUtils.updateEntity(entity);
5671 amit.gupta 282
				}
283
			}
284
		}
285
	}
286
 
287
	private void checkYouTube() throws Exception {
288
		// TODO Auto-generated method stub
289
		Collection<Entity> entities = CreationUtils.getEntities().values();
290
		//entities = (List<Entity>)this.clone(entities);
291
		for (Entity entity : entities) {
292
			long entityId = entity.getID();
293
			try {
294
				List<Slide> entitySlides = entity.getSlides();
295
				if (entity == null || entitySlides == null) {
296
					continue;
297
				}
298
				Slide summarySlide = null;
299
				FreeformContent ffc = null;
300
 
301
				List<Slide> newEntitySlides = new ArrayList<Slide>(); 
302
				Slide connectivitySlide = new Slide(130129);
303
				Slide looknfeelSlide = new Slide(130128);
304
				for (Slide slide : entitySlides) {
305
						ffc = slide.getFreeformContent();
306
						if(ffc != null){
307
							Map<String, Media> mediaMap = ffc.getMedias();
308
							if(mediaMap!=null){
309
								for(Media media : mediaMap.values()){
310
									if(media.getType().equals(Type.VIDEO_WITHOUT_SKIN) || media.getType().equals(Type.VIDEO_WITH_SKIN)){
311
										if(media.getYoutubeId().contains("&"))
312
										System.out.println(entityId + " : " + media.getLabel() + ":" + media.getYoutubeId());
313
									}
314
								}
315
							}
316
						}
317
				}
318
 
319
			}catch(Exception e){
320
				System.out.println("Could not migrate " + entityId);
321
			}
322
		}
323
 
324
 
325
	}
326
 
4964 amit.gupta 327
	private void renameTitles() throws Exception {
328
		Map<Long, Entity> map = CreationUtils.getEntities();
329
		for (Long entityId : map.keySet()) {
330
			Entity entity = map.get(entityId);
331
			if (entity == null || entity.getSlides() == null) {
332
				continue;
1314 rajveer 333
			}
4964 amit.gupta 334
			Slide summarySlide = entity.getSlide(130054);
335
			if(summarySlide != null){
5760 amit.gupta 336
				boolean isupdated = false;
4964 amit.gupta 337
				for(Feature f : summarySlide.getFeatures()){
5760 amit.gupta 338
					if(f.getFeatureDefinitionID()==120132l){
339
						if(f.getBullets() == null){
340
							f.setBullets(new ArrayList<Bullet>());
341
						}else {
342
							f.getBullets().clear();
4964 amit.gupta 343
						}
5760 amit.gupta 344
						Bullet titleBullet = new Bullet(new PrimitiveDataObject(getTitle(entity)));
345
						f.getBullets().add(titleBullet);
346
						isupdated = true;
4964 amit.gupta 347
						continue;
348
					}
5760 amit.gupta 349
					if(f.getFeatureDefinitionID()==120133l){
350
						if(f.getBullets() == null){
351
							f.setBullets(new ArrayList<Bullet>());
352
						}else {
353
							f.getBullets().clear();
354
						}
355
						Bullet metaDescBullet = new Bullet(new PrimitiveDataObject(getMetaDescription(new ExpandedEntity(entity))));
356
						f.getBullets().add(metaDescBullet);
357
						isupdated = true;
358
						continue;
359
					}
4964 amit.gupta 360
				}
5760 amit.gupta 361
				if(isupdated){ 
362
					CreationUtils.updateEntity(entity);
363
					System.out.println("Updated entity : " + entity.getID());
364
				}
4964 amit.gupta 365
			}
1314 rajveer 366
		}
457 rajveer 367
	}
368
 
4818 amit.gupta 369
	private void migrateNetwork() throws Exception {
370
		Map<Long, Entity> map = CreationUtils.getEntities();
4964 amit.gupta 371
		for (Long entityId : map.keySet()) {
372
			Entity entity = map.get(entityId);
373
			if (entity == null || entity.getSlides() == null) {
374
				continue;
375
			}
4818 amit.gupta 376
 
4964 amit.gupta 377
			for (Slide slide : entity.getSlides()) {
5281 amit.gupta 378
				if (slide.getSlideDefinitionID() == 130095) {
379
					List<Slide> slides = slide.getChildrenSlides();
380
					for(Slide slide1  : slides){
381
						if(slide1.getSlideDefinitionID() == 130096){							
382
							List<Feature> features = slide1.getFeatures();
383
							for (Feature f : features) {
384
								if (f.getFeatureDefinitionID() == 120175) {
385
									List<Bullet> bs = f.getBullets();
386
									for (Bullet b : bs) {
387
										Long enumValueId = ((EnumDataObject) b
388
												.getDataObject()).getEnumValueID();
389
										String value = Catalog.getInstance().getDefinitionsContainer().getEnumValue(enumValueId).getValue(); 
390
										if (value.trim().equals("")) {
391
											continue;
392
										}
393
										System.out.println(value);
394
 
395
									}
4964 amit.gupta 396
								}
397
							}
398
						}
399
					}
400
				}
401
 
402
			}
403
 
404
			CreationUtils.updateEntity(entity);
405
		}
4818 amit.gupta 406
	}
5370 amit.gupta 407
	private void migrateHeadSet() throws Exception {
408
 
409
		//Starting entity id for new Category with 10000
410
		long newCounter = 77777000;
411
		Collection<Entity> entities = CreationUtils.getEntities(10015);
412
 
413
		//entities = (List<Entity>)this.clone(entities);
414
		for (Entity entity : entities) {
415
			long entityId = entity.getID();
416
			try {
417
				List<Slide> entitySlides = entity.getSlides();
418
				if (entity == null || entitySlides == null) {
419
					continue;
420
				}
421
				Slide summarySlide = null;
422
				FreeformContent ffc = null;
423
 
424
				List<Slide> newEntitySlides = new ArrayList<Slide>(); 
425
				Slide connectivitySlide = new Slide(130129);
426
				Slide looknfeelSlide = new Slide(130128);
427
				for (Slide slide : entitySlides) {
428
					slide=(Slide)this.clone(slide);
429
					if (slide.getSlideDefinitionID() == 130068) {
430
						List<Feature> connectivityFeatures = new ArrayList<Feature>();
431
						List<Feature> looknfeelFeatures = new ArrayList<Feature>();
432
						List<Feature> features = slide.getFeatures();
433
						for (Feature f : features) {
434
							if (f.getFeatureDefinitionID() == 120105) {
435
								connectivityFeatures.add(f);
436
							}
437
							if (f.getFeatureDefinitionID() == 120106) {
438
								looknfeelFeatures.add(f);
439
							}
440
						}
441
						ffc = slide.getFreeformContent();
442
						if(ffc != null){
443
							Map<String, Media> mediaMap = ffc.getMedias();
444
							if(mediaMap!=null){
445
								for(Media media : mediaMap.values()){
446
									if(media.getType().equals(Type.IMAGE) || media.getType().equals(Type.DOCUMENT)){
447
										copyMedia(String.valueOf(newCounter), String.valueOf(entityId),media);
448
									}
449
								}
450
							}
451
						}
452
						connectivitySlide.setFeatures(connectivityFeatures);
453
						looknfeelSlide.setFeatures(looknfeelFeatures);
454
						looknfeelSlide.setFreeformContent(ffc);
455
					} 
456
					//Summary slide
457
					if(slide.getSlideDefinitionID() == 130054) {
458
						summarySlide = slide; 
459
						FreeformContent ffc1 = slide.getFreeformContent();
460
						if(ffc1 != null){
461
							Map<String, Media> mediaMap = ffc1.getMedias();
462
							if(mediaMap==null){
463
								continue;
464
							}
465
							for(Media media : mediaMap.values()){
466
								if(media.getType().equals(Type.IMAGE) || media.getType().equals(Type.DOCUMENT)){
467
									copyMedia(String.valueOf(newCounter), String.valueOf(entityId),media);
468
								}
469
							}
470
						}
471
					}
472
 
473
				}
474
 
475
				Entity newEntity = new Entity(newCounter, 10099);
5374 amit.gupta 476
				List<Long> newSlideSequence = new ArrayList<Long>();
477
				newSlideSequence.add(130128L);
478
				newSlideSequence.add(130129L);
479
				newSlideSequence.add(130054L);
480
				newEntity.setSlideSequence(newSlideSequence);
5370 amit.gupta 481
				newEntity.setBrand(entity.getBrand());
482
				newEntity.setModelName(entity.getModelName());
483
				newEntity.setModelNumber(entity.getModelNumber());
484
				//entitySlides.remove(featureSlide);
485
				newEntitySlides.add(connectivitySlide);
486
				newEntitySlides.add(looknfeelSlide);
487
				newEntitySlides.add(summarySlide);
488
				newEntity.setSlides(newEntitySlides);
489
				EntityState es = new EntityState(newCounter, 10099, "admin");
490
				es.setBrand(entity.getBrand());
491
				es.setModelName(entity.getModelName());
492
				es.setModelNumber(entity.getModelNumber());
493
				CreationUtils.createEntity(newEntity, es);
494
				System.out.println("New entity : " + newCounter + " created using : " + entityId);
495
				System.out.println(CreationUtils.getEntity(newCounter));
496
				newCounter++;
497
			}catch(Exception e){
498
				System.out.println("Could not migrate " + entityId);
499
			}
500
		}
501
 
502
	}
4818 amit.gupta 503
 
504
	private long getEnumValueForNetwork(String value, Long entityLong) {
505
		value = value.toLowerCase().replaceAll(" ", "");
506
		Map<String, Long> map = new HashMap<String, Long>();
4964 amit.gupta 507
		map.put("quadband(gsm850/900/1800/1900)", 110382L);
4818 amit.gupta 508
		map.put("quadband(gsm850/900/1800/1900)-sim1", 110383l);
509
		map.put("quadband(gsm850/900/1800/1900)-sim2", 110384l);
510
		map.put("triband(gsm900/1800/1900)", 110385l);
511
		map.put("triband(gsm900/1800/1900)-sim1", 110386l);
512
		map.put("triband(gsm900/1800/1900)-sim2", 110387l);
513
		map.put("dualband(gsm900/1800)", 110388l);
514
		map.put("dualband(gsm900/1800)-sim1", 110389l);
515
		map.put("dualband(gsm900/1800)-sim2", 110390l);
4964 amit.gupta 516
		map.put("cdma800", 110391l); // CDMA 800
517
		map.put("cdma800-sim2", 110392l); // CDMA 800-SIM 2
518
		map.put("cdma800-sim3", 110393l); // CDMA 800-SIM 3
519
 
520
		if (!StringUtils.contains(value, "sim")
521
				&& StringUtils.contains(value, "850/900/1800/1900")) {
4818 amit.gupta 522
			return map.get("quadband(gsm850/900/1800/1900)");
523
		}
4964 amit.gupta 524
		if (StringUtils.contains(value, "sim1")
525
				&& StringUtils.contains(value, "850/900/1800/1900")) {
4818 amit.gupta 526
			return map.get("quadband(gsm850/900/1800/1900)-sim1");
527
		}
4964 amit.gupta 528
		if (StringUtils.contains(value, "sim2")
529
				&& StringUtils.contains(value, "850/900/1800/1900")) {
4818 amit.gupta 530
			return map.get("quadband(gsm850/900/1800/1900)-sim2");
531
		}
4964 amit.gupta 532
		if (!StringUtils.contains(value, "sim")
533
				&& StringUtils.contains(value, "900/1800/1900")) {
4818 amit.gupta 534
			return map.get("triband(gsm900/1800/1900)");
535
		}
4964 amit.gupta 536
		if (StringUtils.contains(value, "sim1")
537
				&& StringUtils.contains(value, "900/1800/1900")) {
4818 amit.gupta 538
			return map.get("triband(gsm900/1800/1900)-sim1");
539
		}
4964 amit.gupta 540
		if (StringUtils.contains(value, "sim2")
541
				&& StringUtils.contains(value, "900/1800/1900")) {
4818 amit.gupta 542
			return map.get("triband(gsm900/1800/1900)-sim2");
543
		}
4964 amit.gupta 544
		if (!StringUtils.contains(value, "sim")
545
				&& StringUtils.contains(value, "900/1800")) {
4818 amit.gupta 546
			return map.get("dualband(gsm900/1800)");
547
		}
4964 amit.gupta 548
		if (StringUtils.contains(value, "sim1")
549
				&& StringUtils.contains(value, "900/1800")) {
4818 amit.gupta 550
			return map.get("dualband(gsm900/1800)-sim1");
551
		}
4964 amit.gupta 552
		if (StringUtils.contains(value, "sim2")
553
				&& StringUtils.contains(value, "900/1800")) {
4818 amit.gupta 554
			return map.get("dualband(gsm900/1800)-sim2");
555
		}
4964 amit.gupta 556
		if (StringUtils.contains(value, "cdma")) {
557
			if (StringUtils.contains(value, "sim2")) {
4818 amit.gupta 558
				return map.get("cdma800-sim2");
559
			}
4964 amit.gupta 560
			if (StringUtils.contains(value, "sim3")) {
4818 amit.gupta 561
				return map.get("cdma800-sim3");
562
			}
563
			return map.get("cdma800");
4964 amit.gupta 564
		} else {
565
			System.out.println("Unknown networks: " + value + " : "
566
					+ entityLong);
4818 amit.gupta 567
			return 0;
568
		}
569
	}
570
 
457 rajveer 571
	public ContentMigrator(String sourceDbPath, String destinationDbPath) {
4964 amit.gupta 572
		this.sourceDbPath = sourceDbPath;
457 rajveer 573
		this.destinationDbPath = destinationDbPath;
574
	}
2720 mandeep.dh 575
 
3873 mandeep.dh 576
	public void migrateWarrantyType() throws Exception {
4964 amit.gupta 577
		Map<Long, Entity> map = CreationUtils.getEntities();
578
		for (Long entityId : map.keySet()) {
579
			Entity entity = map.get(entityId);
580
			if (entity == null || entity.getSlides() == null) {
581
				continue;
582
			}
583
			for (Slide slide : entity.getSlides()) {
584
				if (slide.getSlideDefinitionID() == 130054) {
585
					Slide warrantySlide = new Slide(130105);
586
					warrantySlide.setFeatures(new ArrayList<Feature>());
3873 mandeep.dh 587
 
4964 amit.gupta 588
					Feature feature = new Feature(120219);
589
					feature.setBullets(Collections.singletonList(new Bullet(
590
							new EnumDataObject(110299))));
591
					warrantySlide.getFeatures().add(feature);
3873 mandeep.dh 592
 
4964 amit.gupta 593
					Feature existingWarrantyFeature = null;
594
					for (Feature summaryFeature : slide.getFeatures()) {
595
						if (summaryFeature.getFeatureDefinitionID() == 120125) {
596
							existingWarrantyFeature = summaryFeature;
597
							warrantySlide.getFeatures().add(summaryFeature);
598
							break;
599
						}
600
					}
3873 mandeep.dh 601
 
4964 amit.gupta 602
					slide.getFeatures().remove(existingWarrantyFeature);
603
					slide.addChild(warrantySlide);
604
					break;
605
				}
606
 
607
			}
608
 
609
			CreationUtils.updateEntity(entity);
610
		}
3873 mandeep.dh 611
	}
612
 
2720 mandeep.dh 613
	public void migrateMedia() throws Exception {
4964 amit.gupta 614
		Map<Long, Entity> map = CreationUtils.getEntities();
615
		for (Long entityId : map.keySet()) {
616
			Entity entity = map.get(entityId);
617
			if (entity == null || entity.getSlides() == null) {
618
				continue;
619
			}
620
			for (Slide slide : entity.getSlides()) {
621
				FreeformContent ffc = slide.getFreeformContent();
2720 mandeep.dh 622
 
4964 amit.gupta 623
				// if (ffc == null || ffc.getMediasNew() == null) {
624
				// continue;
625
				// }
626
				//
627
				// Map<String, Media> newMap = new LinkedHashMap<String,
628
				// Media>();
629
				// Media media = null;
630
				// for (String label : ffc.getMediasNew().keySet()) {
631
				// MediaNew m = ffc.getMediasNew().get(label);
632
				// media = new Media(m.getLabel(), Media.Type.valueOf(m
633
				// .getType().name()), m.getLocation());
634
				// media.setTitle(m.getTitle());
635
				// media.setFileName(m.getFileName());
636
				// newMap.put(label, media);
637
				// }
638
				// ffc.setMedias(newMap);
639
				// ffc.setMediasNew(null);
2720 mandeep.dh 640
 
4964 amit.gupta 641
				// if (ffc == null || ffc.getMedias() == null) {
642
				// continue;
643
				// }
644
				// Map<String, MediaNew> newMap = new LinkedHashMap<String,
645
				// MediaNew>();
646
				// MediaNew mediaNew = null;
647
				// for (String label : ffc.getMedias().keySet()) {
648
				// Media m = ffc.getMedias().get(label);
649
				// if (m.getType().equalsIgnoreCase("image")) {
650
				// mediaNew = new MediaNew(m.getLabel(),
651
				// MediaNew.Type.IMAGE, m.getLocation());
652
				// mediaNew.setFileName(m.getFileName());
653
				// } else if (m.getType().equalsIgnoreCase("youtube")) {
654
				// if (m.getVideoType().equalsIgnoreCase("withskin")) {
655
				// mediaNew = new MediaNew(m.getLabel(),
656
				// MediaNew.Type.VIDEO_WITH_SKIN,
657
				// m.getLocation());
658
				// } else {
659
				// mediaNew = new MediaNew(m.getLabel(),
660
				// MediaNew.Type.VIDEO_WITHOUT_SKIN,
661
				// m.getLocation());
662
				// }
663
				// }
664
				//
665
				// if (mediaNew != null) {
666
				// mediaNew.setTitle(m.getTitle());
667
				// newMap.put(label, mediaNew);
668
				// }
669
				// }
670
				// ffc.setMediasNew(newMap);
671
				// ffc.setMedias(null);
672
			}
673
		}
2720 mandeep.dh 674
	}
675
 
4964 amit.gupta 676
	public boolean populateHelpdocEntityIds() throws Exception {
677
		for (Entity entity : CreationUtils.getEntities().values()) {
2471 rajveer 678
			CreationUtils.updateEntity(entity);
679
		}
680
		return true;
681
	}
2720 mandeep.dh 682
 
4964 amit.gupta 683
	public boolean migrateBrandModel(String dryRun) throws Exception {
3127 rajveer 684
		CatalogClient catalogServiceClient = new CatalogClient();
2287 rajveer 685
		Client client = catalogServiceClient.getClient();
686
		List<Item> items = client.getAllItemsByStatus(status.ACTIVE);
687
		items.addAll(client.getAllItemsByStatus(status.PAUSED));
688
		items.addAll(client.getAllItemsByStatus(status.CONTENT_COMPLETE));
689
		Map<Long, Entity> entities = CreationUtils.getEntities();
690
		long count = 0;
691
		StringBuffer sb = new StringBuffer();
4964 amit.gupta 692
		for (Item item : items) {
2287 rajveer 693
			long entityId = item.getCatalogItemId();
694
			Entity entity = entities.get(entityId);
4964 amit.gupta 695
			if (entity == null) {
2292 rajveer 696
				continue;
697
			}
2294 rajveer 698
			String itemBrand = item.getBrand().trim();
2287 rajveer 699
			String itemModelName = item.getModelName();
4964 amit.gupta 700
			if (itemModelName != null) {
2294 rajveer 701
				itemModelName = itemModelName.trim();
702
			}
703
			String itemModelNumber = item.getModelNumber().trim();
704
			String entityBrand = entity.getBrand().trim();
705
			String entityModelName = entity.getModelName().trim();
4964 amit.gupta 706
			if (entityModelName != null) {
2294 rajveer 707
				entityModelName = entityModelName.trim();
708
			}
709
			String entityModelNumber = entity.getModelNumber().trim();
4964 amit.gupta 710
 
711
			if (itemBrand.equals(entityBrand)
712
					&& itemModelNumber.equals(entityModelNumber)) {
713
				if (itemModelName != null && entityModelName != null
714
						&& itemModelName.equals(entityModelName)) {
2292 rajveer 715
					continue;
4964 amit.gupta 716
				} else if (itemModelName == null && entityModelName == null) {
717
					continue;
2292 rajveer 718
				}
4964 amit.gupta 719
 
2287 rajveer 720
			}
721
			count++;
4964 amit.gupta 722
			sb.append(count + ") Item:   " + itemBrand + "\t" + itemModelName
723
					+ "\t" + itemModelNumber + "\t" + item.getId() + "\n");
724
			sb.append(count + ") Entity: " + entityBrand + "\t"
725
					+ entityModelName + "\t" + entityModelNumber + "\t"
726
					+ entity.getID() + "\n");
727
 
728
			if (dryRun.equals("false")) {
2294 rajveer 729
				item.setBrand(entityBrand);
730
				item.setModelName(entityModelName);
731
				item.setModelNumber(entityModelNumber);
4964 amit.gupta 732
				client.updateItem(item);
2287 rajveer 733
			}
734
		}
735
		System.out.println(sb.toString());
736
		return true;
737
	}
2720 mandeep.dh 738
 
473 rajveer 739
	/**
4964 amit.gupta 740
	 * this function will read source definition and source entities, and will
741
	 * convert source entities to destination entities according to destination
742
	 * definitions.
473 rajveer 743
	 * 
744
	 * @return boolean
4964 amit.gupta 745
	 * @throws Exception
473 rajveer 746
	 */
1226 rajveer 747
 
4964 amit.gupta 748
	public void printSlides() throws Exception {
749
		DefinitionsContainer defc = Catalog.getInstance()
750
				.getDefinitionsContainer();
751
		for (Category category : defc.getCategories().values()) {
752
			if (category.getChildrenCategory() != null)
753
				continue;
754
			System.out.println(category.getID() + "\t" + category.getLabel());
755
			for (CategorySlideDefinition defs : defc
756
					.getCategorySlideDefinitions(category.getID())) {
757
				System.out.println(defs.getSlideDefintionID()
758
						+ "\t"
759
						+ defs.getEditorialImportance()
760
						+ "\t"
761
						+ defc.getSlideDefinition(defs.getSlideDefintionID())
762
								.getLabel()
763
						+ "\t"
764
						+ defc.getSlideDefinition(defs.getSlideDefintionID())
765
								.getChildrenSlideDefinitionIDs());
1226 rajveer 766
			}
767
		}
768
	}
4964 amit.gupta 769
 
770
	public void removeBrowserBullets() throws Exception {
771
		Map<Long, List<ExpandedBullet>> learnedBullets = CreationUtils
772
				.getLearnedBullets();
1226 rajveer 773
		learnedBullets.get(new Long(120076));
774
		learnedBullets.remove(new Long(120076));
775
		CreationUtils.storeLearnedBullets(learnedBullets);
4964 amit.gupta 776
 
1226 rajveer 777
	}
4964 amit.gupta 778
 
779
	public boolean changeEntityState() throws Exception {
1226 rajveer 780
		Map<Long, EntityState> entitiesState = CreationUtils.getEntitiesState();
8548 amit.gupta 781
		Entity entity;
4964 amit.gupta 782
		for (Long entityId : entitiesState.keySet()) {
1226 rajveer 783
			EntityState state = entitiesState.get(entityId);
8548 amit.gupta 784
			entity = CreationUtils.getEntity(entityId);
785
			if (state.getCategoryID() == 10006) {
786
				//state.setCategoryID(10006);
787
				entity.setCategoryID(10006);
788
				//CreationUtils.updateEntityState(state);
789
				CreationUtils.updateEntity(entity);
8510 amit.gupta 790
				touchEntityState(entityId);
1226 rajveer 791
			}
792
		}
793
		return true;
794
	}
1739 rajveer 795
 
4964 amit.gupta 796
	public boolean migrateDataBack() throws Exception {
1226 rajveer 797
		Map<Long, Entity> entities = CreationUtils.getEntities();
4964 amit.gupta 798
		for (Entity entity : entities.values()) {
799
			if (entity == null) {
800
				continue;
801
			}
1226 rajveer 802
			List<Slide> slides = entity.getSlides();
4964 amit.gupta 803
			if (slides != null) {
804
				for (Slide slide : slides) {
805
					if (slide.getSlideDefinitionID() == 130054) {
806
						List<Feature> features = slide.getFeatures();
807
						int length = features.size();
808
						features.remove(length - 1);
809
						features.remove(length - 2);
810
						features.remove(length - 3);
811
						/*
812
						 * boolean a = false,b=false,c=false; for(Feature
813
						 * feature: features){ switch
814
						 * ((int)feature.getFeatureDefinitionID()) { case
815
						 * 120132: if(a){
816
						 * 
817
						 * }else{ a=true; } break; case 120133: break; case
818
						 * 120134: break; default: break; } }
819
						 */
820
						CreationUtils.updateEntity(entity);
1226 rajveer 821
					}
822
				}
823
			}
824
		}
4964 amit.gupta 825
		return true;
1226 rajveer 826
	}
4964 amit.gupta 827
 
828
	public boolean migrateData() throws Exception {
1226 rajveer 829
		Map<Long, Entity> entities = CreationUtils.getEntities();
4964 amit.gupta 830
		for (Entity entity : entities.values()) {
831
			ExpandedEntity expEntity = new ExpandedEntity(entity);
1226 rajveer 832
			List<Slide> slides = entity.getSlides();
4964 amit.gupta 833
			if (slides != null) {
834
				for (Slide slide : slides) {
835
					if (slide.getSlideDefinitionID() == 130054) {
836
						List<Feature> features = slide.getFeatures();
837
						String title = expEntity.getBrand() + " "
838
								+ expEntity.getModelName() + " "
839
								+ expEntity.getModelNumber();
840
						if (expEntity.getCategory().getParentCategory().getID() == 10001) {
841
							title += " | " + expEntity.getBrand()
842
									+ " Mobile Phones";
1226 rajveer 843
						}
4964 amit.gupta 844
						if (expEntity.getCategory().getParentCategory().getID() == 10011) {
845
							title += " " + expEntity.getCategory().getLabel()
846
									+ " | " + expEntity.getBrand()
847
									+ " Mobile Phone Accessories";
1226 rajveer 848
						}
4964 amit.gupta 849
						title += " | Saholic.com";
850
 
851
						// Add page title
852
						Feature feature1 = new Feature(120132);
853
						PrimitiveDataObject pdo1 = new PrimitiveDataObject(
854
								title);
855
						List<Bullet> bullets1 = new ArrayList<Bullet>();
856
						Bullet bullet1 = new Bullet(pdo1);
857
						bullets1.add(bullet1);
858
						feature1.setBullets(bullets1);
859
						features.add(feature1);
860
 
861
						String description = "Best Price "
862
								+ expEntity.getBrand() + " "
863
								+ expEntity.getModelName() + " "
864
								+ expEntity.getModelNumber() + " ";
865
 
866
						if (expEntity.getCategory().getParentCategory().getID() == 10011) {
867
							description += expEntity.getCategory().getLabel()
868
									+ " in India.";
869
						} else {
870
							description += ".";
1226 rajveer 871
						}
4964 amit.gupta 872
						description += " Experience n' buy online. FREE Next Day delivery."
873
								+ " Original product - Full manufacturer warranty. Comprehensive reviews.";
1226 rajveer 874
 
4964 amit.gupta 875
						description = description.replaceAll("--", "-");
876
 
877
						// Add meta description
878
						Feature feature2 = new Feature(120133);
879
						PrimitiveDataObject pdo2 = new PrimitiveDataObject(
880
								description);
881
						List<Bullet> bullets2 = new ArrayList<Bullet>();
882
						Bullet bullet2 = new Bullet(pdo2);
883
						bullets2.add(bullet2);
884
						feature2.setBullets(bullets2);
885
 
886
						features.add(feature2);
887
 
888
						String keywords = expEntity.getBrand() + " "
889
								+ expEntity.getModelName() + " "
890
								+ expEntity.getModelNumber() + ", ";
891
						if (expEntity.getCategory().getParentCategory().getID() == 10001) {
892
							keywords += expEntity.getBrand()
893
									+ " mobile phones, ";
1226 rajveer 894
						}
4964 amit.gupta 895
						if (expEntity.getCategory().getParentCategory().getID() == 10011) {
896
							keywords += "phone accessories, ";
1226 rajveer 897
						}
4964 amit.gupta 898
						keywords += expEntity.getBrand() + " "
899
								+ expEntity.getModelName() + " "
900
								+ expEntity.getModelNumber() + " Price, ";
901
						keywords += expEntity.getBrand() + " "
902
								+ expEntity.getModelName() + " "
903
								+ expEntity.getModelNumber() + " India, ";
904
						if (expEntity.getCategory().getParentCategory().getID() == 10001) {
905
							keywords += expEntity.getBrand() + " "
906
									+ expEntity.getModelName() + " "
907
									+ expEntity.getModelNumber() + " Review, ";
1226 rajveer 908
						}
4964 amit.gupta 909
						// Add meta keyborad
910
						Feature feature3 = new Feature(120134);
911
						PrimitiveDataObject pdo3 = new PrimitiveDataObject(
912
								keywords);
913
						List<Bullet> bullets3 = new ArrayList<Bullet>();
914
						Bullet bullet3 = new Bullet(pdo3);
915
						bullets3.add(bullet3);
916
						feature3.setBullets(bullets3);
917
 
918
						features.add(feature3);
919
 
920
						CreationUtils.updateEntity(entity);
921
					}
922
				}
923
			}
924
		}
925
		return true;
926
	}
927
 
928
	public boolean migrateModel2() throws Exception {
929
		Map<Long, Entity> entities = CreationUtils.getEntities();
930
		for (Entity entity : entities.values()) {
931
			List<Slide> slides = entity.getSlides();
932
			if (slides != null) {
933
				for (Slide slide : slides) {
934
					if (slide.getSlideDefinitionID() == 130011) {
935
						for (Feature feature : slide.getFeatures()) {
936
							if (feature.getFeatureDefinitionID() == 120054) {
937
								// feature.setFeatureDefinitionID(120030);
938
								System.out.println("* " + entity.getID() + ":"
939
										+ entity.getCategoryID());
1226 rajveer 940
							}
941
						}
4964 amit.gupta 942
					}
1226 rajveer 943
 
4964 amit.gupta 944
					if (slide.getSlideDefinitionID() == 130029) {
945
						// System.out.println("** " + entity.getID() + ":" +
946
						// entity.getCategoryID());
947
						if (entity.getCategoryID() == 10002) {
948
							Feature feature = new Feature(120051);
949
							slide.getFeatures().add(feature);
950
							System.out.println("** " + entity.getID() + ":"
951
									+ entity.getCategoryID());
1226 rajveer 952
						}
953
					}
954
 
955
				}
956
			}
4964 amit.gupta 957
			CreationUtils.updateEntity(entity);
1226 rajveer 958
		}
959
		return true;
960
	}
4964 amit.gupta 961
 
962
	/*
963
	 * public boolean migrateModel1() throws Exception{ //DefinitionsContainer
964
	 * oldDfc = new DefinitionsContainer(Utils.CONTENT_DB_PATH +
965
	 * "olddefinitions" + File.separator); //DefinitionsContainer newDfc = new
966
	 * DefinitionsContainer(Utils.CONTENT_DB_PATH + "olddefinitions" +
967
	 * File.separator);
968
	 * 
969
	 * Map<Long, Entity> entities = CreationUtils.getEntities(); for(Entity
970
	 * entity: entities.values()){ List<Long> slideSequence =
971
	 * entity.getSlideSequence(); Map<Long,Long> removeMap = new HashMap<Long,
972
	 * Long>(); List<Slide> slides = entity.getSlides(); if(slides!=null){
973
	 * for(Slide slide: slides){ List<Feature> features; Slide childSlide;
974
	 * switch ((int)slide.getSlideDefinitionID()) {
975
	 * 
976
	 * //Keyboard case 130004: case 130026: case 130027: case 130057:
977
	 * removeMap.put(slide.getSlideDefinitionID(), (long)130026);
978
	 * slide.setSlideDefinitionID(130026); break;
979
	 * 
980
	 * //Voice Calling case 130005: removeMap.put(slide.getSlideDefinitionID(),
981
	 * (long)130005); slide.setSlideDefinitionID(130005); features = new
982
	 * ArrayList<Feature>(); features.addAll(slide.getFeatures()); childSlide =
983
	 * slide.getChildrenSlides().get(0);
984
	 * features.addAll(childSlide.getFeatures());
985
	 * if(childSlide.getFreeformContent()!=null){
986
	 * System.out.println("Voice Calling : HAS FFC : " +
987
	 * childSlide.getFreeformContent().getFreeformText() +
988
	 * childSlide.getFreeformContent().getMedias()); }
989
	 * slide.setChildrenSlides(null); slide.setFeatures(features); break; case
990
	 * 130035: removeMap.put(slide.getSlideDefinitionID(), (long)130005);
991
	 * slide.setSlideDefinitionID(130005); for(Feature feata:
992
	 * slide.getFeatures()){ if(feata.getFeatureDefinitionID()==120055){
993
	 * feata.setFeatureDefinitionID(120012); } } break;
994
	 * 
995
	 * //Data Connectivity case 130007: case 130028:
996
	 * removeMap.put(slide.getSlideDefinitionID(), (long)130007);
997
	 * slide.setSlideDefinitionID(130007); break;
998
	 * 
999
	 * //Music case 130029: case 130030: case 130008:
1000
	 * removeMap.put(slide.getSlideDefinitionID(), (long)130029);
1001
	 * slide.setSlideDefinitionID(130029); break;
1002
	 * 
1003
	 * //Video case 130031: case 130009:
1004
	 * removeMap.put(slide.getSlideDefinitionID(), (long)130031);
1005
	 * slide.setSlideDefinitionID(130031); break;
1006
	 * 
1007
	 * //Camera case 130010: case 130036: case 130037:
1008
	 * removeMap.put(slide.getSlideDefinitionID(), (long)130010);
1009
	 * slide.setSlideDefinitionID(130010); break; case 130060:
1010
	 * removeMap.put(slide.getSlideDefinitionID(), (long)130010);
1011
	 * slide.setSlideDefinitionID(130010);
1012
	 * 
1013
	 * features = slide.getFeatures(); // Just to add camera feature in basic
1014
	 * phones Feature feature = new Feature(120056); List<Bullet> bullets = new
1015
	 * ArrayList<Bullet>(); PrimitiveDataObject pdo = new
1016
	 * PrimitiveDataObject("1"); Bullet bullet = new Bullet(pdo);
1017
	 * bullets.add(bullet); feature.setBullets(bullets); features.add(feature);
1018
	 * //Created new feature break;
1019
	 * 
1020
	 * //Memory case 130011: removeMap.put(slide.getSlideDefinitionID(),
1021
	 * (long)130011); slide.setSlideDefinitionID(130011); break; case 130032:
1022
	 * case 130061: removeMap.put(slide.getSlideDefinitionID(), (long)130011);
1023
	 * slide.setSlideDefinitionID(130011); features = slide.getFeatures();
1024
	 * for(Feature feat: features){ if(feat.getFeatureDefinitionID() == 120054){
1025
	 * feat.setFeatureDefinitionID(120030); } } break;
1026
	 * 
1027
	 * //Battery case 130044: removeMap.put(slide.getSlideDefinitionID(),
1028
	 * (long)130043); slide.setSlideDefinitionID(130043);
1029
	 * if(slide.getChildrenSlides().get(0).getSlideDefinitionID() == 130047){
1030
	 * slide.getChildrenSlides().get(0).setSlideDefinitionID(130046); } break;
1031
	 * 
1032
	 * case 130042: removeMap.put(slide.getSlideDefinitionID(), (long)130043);
1033
	 * slide.setSlideDefinitionID(130043); childSlide =
1034
	 * slide.getChildrenSlides().get(0); if(childSlide.getSlideDefinitionID() ==
1035
	 * 130045){ childSlide.setSlideDefinitionID(130046); }
1036
	 * 
1037
	 * List<Feature> childFeatures1 = new ArrayList<Feature>(); List<Feature>
1038
	 * childFeatures2 = new ArrayList<Feature>(); Slide childChildSlide1 = new
1039
	 * Slide(130048); Slide childChildSlide2 = new Slide(130049);
1040
	 * 
1041
	 * childChildSlide1.setFeatures(childFeatures1);
1042
	 * childChildSlide2.setFeatures(childFeatures2);
1043
	 * 
1044
	 * childSlide.addChild(childChildSlide1);
1045
	 * childSlide.addChild(childChildSlide2);
1046
	 * 
1047
	 * 
1048
	 * for(Feature f: childSlide.getFeatures()){ if(f.getFeatureDefinitionID()
1049
	 * == 120063){ f.setFeatureDefinitionID(120068); childFeatures1.add(f); }
1050
	 * if(f.getFeatureDefinitionID() == 120064){
1051
	 * f.setFeatureDefinitionID(120069); childFeatures2.add(f); } }
1052
	 * 
1053
	 * childSlide.setFeatures(null);
1054
	 * 
1055
	 * break;
1056
	 * 
1057
	 * case 130062: removeMap.put(slide.getSlideDefinitionID(), (long)130043);
1058
	 * slide.setSlideDefinitionID(130043);
1059
	 * 
1060
	 * childSlide = new Slide(130046); features = new ArrayList<Feature>();
1061
	 * 
1062
	 * slide.addChild(childSlide);
1063
	 * 
1064
	 * List<Feature> childFeatures11 = new ArrayList<Feature>(); List<Feature>
1065
	 * childFeatures21 = new ArrayList<Feature>(); Slide childChildSlide11 = new
1066
	 * Slide(130048); Slide childChildSlide21 = new Slide(130049);
1067
	 * 
1068
	 * childChildSlide11.setFeatures(childFeatures11);
1069
	 * childChildSlide21.setFeatures(childFeatures21);
1070
	 * 
1071
	 * childSlide.addChild(childChildSlide11);
1072
	 * childSlide.addChild(childChildSlide21); for(Feature f:
1073
	 * slide.getFeatures()){ if(f.getFeatureDefinitionID() == 120072){
1074
	 * features.add(f); } if(f.getFeatureDefinitionID() == 120073){
1075
	 * features.add(f); } if(f.getFeatureDefinitionID() == 120063){
1076
	 * f.setFeatureDefinitionID(120068); childFeatures11.add(f); }
1077
	 * if(f.getFeatureDefinitionID() == 120064){
1078
	 * f.setFeatureDefinitionID(120069); childFeatures21.add(f); } }
1079
	 * slide.setFeatures(features); break;
1080
	 * 
1081
	 * 
1082
	 * //Mail n Msg case 130041: case 130063:
1083
	 * removeMap.put(slide.getSlideDefinitionID(), (long)130039);
1084
	 * slide.setSlideDefinitionID(130039); break; case 130039:
1085
	 * removeMap.put(slide.getSlideDefinitionID(), (long)130039);
1086
	 * slide.setSlideDefinitionID(130039);
1087
	 * 
1088
	 * childSlide = slide.getChildrenSlides().get(0);
1089
	 * slide.setFeatures(childSlide.getFeatures());
1090
	 * if(childSlide.getFreeformContent()!=null){
1091
	 * System.out.println("Mail n Msg : HAS FFC : " +
1092
	 * childSlide.getFreeformContent().getFreeformText() +
1093
	 * childSlide.getFreeformContent().getMedias()); }
1094
	 * slide.setChildrenSlides(null); break;
1095
	 * 
1096
	 * //Software case 130020: case 130034:
1097
	 * removeMap.put(slide.getSlideDefinitionID(), (long)130020);
1098
	 * slide.setSlideDefinitionID(130020); break;
1099
	 * 
1100
	 * 
1101
	 * //Internet case 130050: removeMap.put(slide.getSlideDefinitionID(),
1102
	 * (long)130050); slide.setSlideDefinitionID(130050);
1103
	 * slide.setFeatures(slide.getChildrenSlides().get(0).getFeatures());
1104
	 * 
1105
	 * if(slide.getChildrenSlides().get(0).getFreeformContent()!=null){ String
1106
	 * ffc = slide.getFreeformContent().getFreeformText();
1107
	 * if(slide.getChildrenSlides
1108
	 * ().get(0).getFreeformContent().getFreeformText()!=null){
1109
	 * if(slide.getChildrenSlides
1110
	 * ().get(0).getFreeformContent().getFreeformText().trim()!=""){ ffc = ffc +
1111
	 * "\n *********    " +
1112
	 * slide.getChildrenSlides().get(0).getFreeformContent().getFreeformText();
1113
	 * System.out.println("**************" +
1114
	 * slide.getChildrenSlides().get(0).getFreeformContent().getFreeformText());
1115
	 * } }
1116
	 * 
1117
	 * List<String> ffcs = new ArrayList<String>(); ffcs.add(ffc);
1118
	 * slide.getFreeformContent().setFreeformTexts(ffcs); }
1119
	 * 
1120
	 * slide.setChildrenSlides(null); //System.out.println("Slide: 130050");
1121
	 * //printSlideContent(slide); break;
1122
	 * 
1123
	 * case 130052: removeMap.put(slide.getSlideDefinitionID(), (long)130050);
1124
	 * slide.setSlideDefinitionID(130050);
1125
	 * 
1126
	 * for(Feature f2: slide.getFeatures()){ if(f2.getFeatureDefinitionID() ==
1127
	 * 120077){ f2.setFeatureDefinitionID(120074); // List<Bullet> newBullets =
1128
	 * new ArrayList<Bullet>(); // for(Bullet bul: f2.getBullets()){ //
1129
	 * CompositeDataObject cdo = (CompositeDataObject) bul.getDataObject(); //
1130
	 * for(PrimitiveDataObject pdo1: cdo.getPrimitiveDataObjects()){ //
1131
	 * pdo1.getValue(); // BulletDataObject bdo2 = new
1132
	 * EnumDataObject(enumValueID); // Bullet newbul = new Bullet(bdo2); //
1133
	 * newBullets.add(newbul); // } // // } // f2.setBullets(newBullets); }
1134
	 * if(f2.getFeatureDefinitionID() == 120078){
1135
	 * f2.setFeatureDefinitionID(120075); } } //
1136
	 * slide.setFeatures(slide.getChildrenSlides().get(0).getFeatures()); //
1137
	 * slide.setChildrenSlides(null); //System.out.println("Slide: 130052");
1138
	 * 
1139
	 * //printSlideContent(slide); break;
1140
	 * 
1141
	 * case 130051: removeMap.put(slide.getSlideDefinitionID(), (long)130050);
1142
	 * slide.setSlideDefinitionID(130050); // System.out.println(slide);
1143
	 * //System.out.println("Slide 130051:"); // printSlideContent(slide);
1144
	 * break;
1145
	 * 
1146
	 * default: break; }
1147
	 * 
1148
	 * } List<Long> newSequence = new ArrayList<Long>(); for(Long id:
1149
	 * slideSequence){ if(removeMap.containsKey(id)){
1150
	 * newSequence.add(removeMap.get(id)); }else{ newSequence.add(id); } }
1151
	 * entity.setSlideSequence(newSequence); CreationUtils.updateEntity(entity);
1152
	 * } }
1153
	 * 
1154
	 * return true; }
1155
	 */
1156
 
1157
	public void printSlideContent(Slide slide) {
1158
 
1159
		System.out.println("Slide: "
1160
				+ slide.getFreeformContent().getFreeformText());
1161
		if (slide.getFeatures() != null) {
1162
			for (Feature feature : slide.getFeatures()) {
1163
				if (feature.getBullets() != null) {
1164
					for (Bullet bullet : feature.getBullets()) {
1165
						// System.out.println(bullet.getDataObject().toString());
1166
						// System.out.println(bullet.getFreeformContent());
1226 rajveer 1167
					}
1168
				}
4964 amit.gupta 1169
				if (feature.getFreeformContent() != null) {
1170
					System.out.println("Feature: "
1171
							+ feature.getFreeformContent().getFreeformText());
1226 rajveer 1172
				}
1173
			}
1174
		}
4964 amit.gupta 1175
		if (slide.getChildrenSlides() != null) {
1176
			for (Slide sl : slide.getChildrenSlides()) {
1226 rajveer 1177
				System.out.println("Child1: ");
1178
				printSlideContent(sl);
1179
				System.out.println("Child2: ");
1180
			}
1181
		}
4964 amit.gupta 1182
 
1226 rajveer 1183
	}
4964 amit.gupta 1184
 
1230 rajveer 1185
	/*
4964 amit.gupta 1186
	 * public boolean migrateModel() throws Exception{ //DefinitionsContainer
1187
	 * oldDfc = new DefinitionsContainer(Utils.CONTENT_DB_PATH +
1188
	 * "olddefinitions" + File.separator); //DefinitionsContainer newDfc = new
1189
	 * DefinitionsContainer(Utils.CONTENT_DB_PATH + "olddefinitions" +
1190
	 * File.separator);
1191
	 * 
1192
	 * Map<Long, Entity> entities = CreationUtils.getEntities(); for(Entity
1193
	 * entity: entities.values()){ List<Slide> slides = entity.getSlides();
1194
	 * if(slides!=null){ List<Slide> newSlides = new ArrayList<Slide>();
1195
	 * for(Slide slide: slides){ Slide newSlide; List<Feature> features; Slide
1196
	 * childSlide; switch ((int)slide.getSlideDefinitionID()) {
1197
	 * 
1198
	 * //Keyboard case 130004: case 130026: case 130027: case 130057: newSlide =
1199
	 * new Slide(130026); newSlide.setChildrenSlides(slide.getChildrenSlides());
1200
	 * newSlide.setFeatures(slide.getFeatures());
1201
	 * newSlide.setFreeformContent(slide.getFreeformContent());
1202
	 * newSlides.add(newSlide); break;
1203
	 * 
1204
	 * //Voice Calling case 130005: newSlide = new Slide(130005);
1205
	 * newSlide.setChildrenSlides(null); features = new ArrayList<Feature>();
1206
	 * features.addAll(slide.getFeatures()); childSlide =
1207
	 * slide.getChildrenSlides().get(0);
1208
	 * features.addAll(childSlide.getFeatures());
1209
	 * if(childSlide.getFreeformContent()!=null){
1210
	 * System.out.println("Voice Calling : HAS FFC : " +
1211
	 * childSlide.getFreeformContent().getFreeformText() +
1212
	 * childSlide.getFreeformContent().getMedias()); }
1213
	 * newSlide.setFeatures(features);
1214
	 * newSlide.setFreeformContent(slide.getFreeformContent());
1215
	 * newSlides.add(newSlide); break; case 130035: newSlide = new
1216
	 * Slide(130035); newSlide.setChildrenSlides(slide.getChildrenSlides());
1217
	 * for(Feature feata: slide.getFeatures()){
1218
	 * if(feata.getFeatureDefinitionID()==120055){
1219
	 * feata.setFeatureDefinitionID(120012); } }
1220
	 * newSlide.setFeatures(slide.getFeatures());
1221
	 * newSlide.setFreeformContent(slide.getFreeformContent());
1222
	 * newSlides.add(newSlide); break;
1223
	 * 
1224
	 * //Data Connectivity case 130007: case 130028: newSlide = new
1225
	 * Slide(130007); newSlide.setChildrenSlides(slide.getChildrenSlides());
1226
	 * newSlide.setFeatures(slide.getFeatures());
1227
	 * newSlide.setFreeformContent(slide.getFreeformContent());
1228
	 * newSlides.add(newSlide); break;
1229
	 * 
1230
	 * //Music case 130029: case 130030: case 130008: newSlide = new
1231
	 * Slide(130029); newSlide.setChildrenSlides(slide.getChildrenSlides());
1232
	 * newSlide.setFeatures(slide.getFeatures());
1233
	 * newSlide.setFreeformContent(slide.getFreeformContent());
1234
	 * newSlides.add(newSlide); break;
1235
	 * 
1236
	 * //Video case 130031: case 130009: newSlide = new Slide(130031);
1237
	 * newSlide.setChildrenSlides(slide.getChildrenSlides());
1238
	 * newSlide.setFeatures(slide.getFeatures());
1239
	 * newSlide.setFreeformContent(slide.getFreeformContent());
1240
	 * newSlides.add(newSlide); break;
1241
	 * 
1242
	 * //Camera case 130010: case 130036: case 130037: newSlide = new
1243
	 * Slide(130010); newSlide.setChildrenSlides(slide.getChildrenSlides());
1244
	 * newSlide.setFeatures(slide.getFeatures());
1245
	 * newSlide.setFreeformContent(slide.getFreeformContent());
1246
	 * newSlides.add(newSlide); break; case 130060: newSlide = new
1247
	 * Slide(130010); newSlide.setChildrenSlides(slide.getChildrenSlides());
1248
	 * features = slide.getFeatures(); // Just to add camera feature in basic
1249
	 * phones Feature feature = new Feature(120056); List<Bullet> bullets = new
1250
	 * ArrayList<Bullet>(); PrimitiveDataObject pdo = new
1251
	 * PrimitiveDataObject("1"); Bullet bullet = new Bullet(pdo);
1252
	 * bullets.add(bullet); feature.setBullets(bullets); features.add(feature);
1253
	 * //Created new feature newSlide.setFeatures(features);
1254
	 * newSlide.setFreeformContent(slide.getFreeformContent());
1255
	 * newSlides.add(newSlide); break;
1256
	 * 
1257
	 * //Memory case 130011: newSlide = new Slide(130011);
1258
	 * newSlide.setChildrenSlides(slide.getChildrenSlides());
1259
	 * newSlide.setFeatures(slide.getFeatures());
1260
	 * newSlide.setFreeformContent(slide.getFreeformContent());
1261
	 * newSlides.add(newSlide); break; case 130032: case 130061: newSlide = new
1262
	 * Slide(130011); newSlide.setChildrenSlides(slide.getChildrenSlides());
1263
	 * features = slide.getFeatures(); for(Feature feat: features){
1264
	 * if(feat.getFeatureDefinitionID() == 130054){
1265
	 * feat.setFeatureDefinitionID(120030); } }
1266
	 * newSlide.setFeatures(slide.getFeatures());
1267
	 * newSlide.setFreeformContent(slide.getFreeformContent());
1268
	 * newSlides.add(newSlide); break;
1269
	 * 
1270
	 * //Battery case 130044: newSlide = new Slide(130043);
1271
	 * if(slide.getChildrenSlides().get(0).getSlideDefinitionID() == 130047){
1272
	 * slide.getChildrenSlides().get(0).setSlideDefinitionID(130046); }
1273
	 * newSlide.setChildrenSlides(slide.getChildrenSlides());
1274
	 * newSlide.setFeatures(slide.getFeatures());
1275
	 * newSlide.setFreeformContent(slide.getFreeformContent());
1276
	 * newSlides.add(newSlide); break;
1277
	 * 
1278
	 * case 130042: newSlide = new Slide(130043); childSlide =
1279
	 * slide.getChildrenSlides().get(0); if(childSlide.getSlideDefinitionID() ==
1280
	 * 130045){ childSlide.setSlideDefinitionID(130046); }
1281
	 * newSlide.setChildrenSlides(slide.getChildrenSlides());
1282
	 * 
1283
	 * List<Feature> childFeatures1 = new ArrayList<Feature>(); List<Feature>
1284
	 * childFeatures2 = new ArrayList<Feature>(); Slide childChildSlide1 = new
1285
	 * Slide(130048); Slide childChildSlide2 = new Slide(130049);
1286
	 * 
1287
	 * childChildSlide1.setFeatures(childFeatures1);
1288
	 * childChildSlide2.setFeatures(childFeatures2);
1289
	 * 
1290
	 * childSlide.addChild(childChildSlide1);
1291
	 * childSlide.addChild(childChildSlide2);
1292
	 * 
1293
	 * 
1294
	 * for(Feature f: childSlide.getFeatures()){ if(f.getFeatureDefinitionID()
1295
	 * == 120063){ f.setFeatureDefinitionID(120068); childFeatures1.add(f); }
1296
	 * if(f.getFeatureDefinitionID() == 120064){
1297
	 * f.setFeatureDefinitionID(120069); childFeatures2.add(f); } }
1298
	 * 
1299
	 * childSlide.setFeatures(null);
1300
	 * 
1301
	 * newSlide.setFeatures(slide.getFeatures());
1302
	 * newSlide.setFreeformContent(slide.getFreeformContent());
1303
	 * newSlides.add(newSlide); break;
1304
	 * 
1305
	 * case 130062: newSlide = new Slide(130043);
1306
	 * newSlide.setChildrenSlides(slide.getChildrenSlides()); childSlide = new
1307
	 * Slide(130046); features = new ArrayList<Feature>();
1308
	 * newSlide.setFeatures(features); newSlide.addChild(childSlide);
1309
	 * 
1310
	 * List<Feature> childFeatures11 = new ArrayList<Feature>(); List<Feature>
1311
	 * childFeatures21 = new ArrayList<Feature>(); Slide childChildSlide11 = new
1312
	 * Slide(130048); Slide childChildSlide21 = new Slide(130049);
1313
	 * 
1314
	 * childChildSlide11.setFeatures(childFeatures11);
1315
	 * childChildSlide21.setFeatures(childFeatures21);
1316
	 * 
1317
	 * childSlide.addChild(childChildSlide11);
1318
	 * childSlide.addChild(childChildSlide21); for(Feature f:
1319
	 * slide.getFeatures()){ if(f.getFeatureDefinitionID() == 120072){
1320
	 * features.add(f); } if(f.getFeatureDefinitionID() == 120073){
1321
	 * features.add(f); } if(f.getFeatureDefinitionID() == 120063){
1322
	 * f.setFeatureDefinitionID(120068); childFeatures11.add(f); }
1323
	 * if(f.getFeatureDefinitionID() == 120064){
1324
	 * f.setFeatureDefinitionID(120069); childFeatures21.add(f); } }
1325
	 * 
1326
	 * newSlide.setFeatures(slide.getFeatures());
1327
	 * newSlide.setFreeformContent(slide.getFreeformContent());
1328
	 * newSlides.add(newSlide); break;
1329
	 * 
1330
	 * 
1331
	 * //Mail n Msg case 130041: case 130063: newSlide = new Slide(130039);
1332
	 * newSlide.setChildrenSlides(slide.getChildrenSlides());
1333
	 * newSlide.setFeatures(slide.getFeatures());
1334
	 * newSlide.setFreeformContent(slide.getFreeformContent());
1335
	 * newSlides.add(newSlide); break; case 130039: newSlide = new
1336
	 * Slide(130039); //newSlide.setChildrenSlides(slide.getChildrenSlides());
1337
	 * childSlide = slide.getChildrenSlides().get(0);
1338
	 * newSlide.setFeatures(childSlide.getFeatures());
1339
	 * if(childSlide.getFreeformContent()!=null){
1340
	 * System.out.println("Mail n Msg : HAS FFC : " +
1341
	 * childSlide.getFreeformContent().getFreeformText() +
1342
	 * childSlide.getFreeformContent().getMedias()); }
1343
	 * newSlide.setFreeformContent(slide.getFreeformContent());
1344
	 * newSlides.add(newSlide); break;
1345
	 * 
1346
	 * //Software case 130020: case 130034: newSlide = new Slide(130034);
1347
	 * newSlide.setChildrenSlides(slide.getChildrenSlides()); features =
1348
	 * slide.getFeatures(); newSlide.setFeatures(slide.getFeatures());
1349
	 * newSlide.setFreeformContent(slide.getFreeformContent());
1350
	 * newSlides.add(newSlide); break;
1351
	 * 
1352
	 * 
1353
	 * default: newSlides.add(slide); break; } } entity.setSlides(newSlides);
1354
	 * CreationUtils.updateEntity(entity); } }
1355
	 * 
1356
	 * return true; }
1357
	 */
1358
	public boolean migrateRemoveBorrowedCategoryIdFromSlide() throws Exception {
1226 rajveer 1359
		Map<Long, Entity> entities = CreationUtils.getEntities();
4964 amit.gupta 1360
		for (Entity entity : entities.values()) {
1361
			if (entity.getID() == 0) {
1226 rajveer 1362
				CreationUtils.deleteEntity(entity.getID());
1363
			}
1364
			List<Slide> slides = entity.getSlides();
4964 amit.gupta 1365
			if (slides != null) {
1226 rajveer 1366
				List<Slide> newSlides = new ArrayList<Slide>();
4964 amit.gupta 1367
				for (Slide slide : slides) {
1226 rajveer 1368
					Slide newSlide = new Slide(slide.getSlideDefinitionID());
1369
					newSlide.setChildrenSlides(slide.getChildrenSlides());
1370
					newSlide.setFeatures(slide.getFeatures());
1371
					newSlide.setFreeformContent(slide.getFreeformContent());
1372
					newSlides.add(newSlide);
1373
				}
1374
				entity.setSlides(newSlides);
1375
				CreationUtils.updateEntity(entity);
1376
			}
1377
		}
1378
		return true;
1379
	}
479 rajveer 1380
 
4964 amit.gupta 1381
	public boolean migrate() throws Exception {
580 rajveer 1382
		/*
4964 amit.gupta 1383
		 * DefinitionsContainer sourceDefs = new
1384
		 * DefinitionsContainer(sourceDbPath); DefinitionsContainer
1385
		 * destinationDefs = new DefinitionsContainer(destinationDbPath);
1386
		 * EntityContainer sourceEnts = new EntityContainer(sourceDbPath);
1387
		 * EntityContainer destinationEnts = new
1388
		 * EntityContainer(destinationDbPath);
1389
		 * 
1390
		 * Map<Long, Entity> entities = sourceEnts.getEntities();
1391
		 * 
1392
		 * File f = new File("/home/rajveer/Desktop/info.txt"); FileWriter
1393
		 * fstream = new FileWriter(f); BufferedWriter out = new
1394
		 * BufferedWriter(fstream); StringBuilder sb = new StringBuilder();
1395
		 * 
1396
		 * 
1397
		 * for(Entity entity: entities.values()){ List<Slide> slides =
1398
		 * entity.getSlides();
1399
		 * 
1400
		 * //List<String> vidLabels =
1401
		 * CreationUtils.getMediaLabels(entity.getID(),"youtube");
1402
		 * //List<String> imgLabels =
1403
		 * CreationUtils.getMediaLabels(entity.getID(),"image");
1404
		 * 
1405
		 * //Map<String, Media> rawMedia =
1406
		 * CreationUtils.getRawMedia(entity.getID());
1407
		 * 
1408
		 * 
1409
		 * // List<String> vidLabels =
1410
		 * OldCreationUtils.getMediaLabels(entity.getID(),"youtube"); //
1411
		 * List<String> imgLabels =
1412
		 * OldCreationUtils.getMediaLabels(entity.getID(),"image");
1413
		 * 
1414
		 * Entity newEntity = new Entity(entity.getID(),
1415
		 * entity.getCategoryID()); newEntity.setBrand(entity.getBrand());
1416
		 * newEntity.setModelName(entity.getModelName());
1417
		 * newEntity.setModelNumber(entity.getModelNumber());
1418
		 * 
1419
		 * 
1420
		 * Map<String, in.shop2020.creation.util.Media> rawMedia =
1421
		 * OldCreationUtils.getRawMedia(entity.getID());
1422
		 * 
1423
		 * Map<String, Media> newrawMedia = new HashMap<String, Media>();
1424
		 * 
1425
		 * 
1426
		 * int totalRawVideos = 0; int totalRawImages = 0;
1427
		 * 
1428
		 * if(rawMedia!=null){ for(String label: rawMedia.keySet()){
1429
		 * in.shop2020.creation.util.Media media = rawMedia.get(label);
1430
		 * 
1431
		 * label = media.getLabel(); String type = media.getType(); String
1432
		 * location = media.getLocation();
1433
		 * 
1434
		 * Media newMedia = new Media(label, type, location);
1435
		 * 
1436
		 * newMedia.setTitle("Title"); if(type.equals("image")){
1437
		 * totalRawImages++; newMedia.setFileName(media.getFileName());
1438
		 * newMedia.setVideoType(""); }else{ totalRawVideos++;
1439
		 * newMedia.setVideoType("withoutskin"); newMedia.setFileName(""); }
1440
		 * 
1441
		 * newrawMedia.put(label, newMedia); System.out.println("old " +
1442
		 * media.toString()); // System.out.println("new " +
1443
		 * newMedia.toString()); // OldCreationUtils.removeMedia(entity.getID(),
1444
		 * label); // CreationUtils.addMedia(entity.getID(), newMedia); } }
1445
		 * 
1446
		 * int totalVideos = 0; int totalImages = 0; if(rawMedia==null){
1447
		 * for(Slide slide: slides ){
1448
		 */
1449
		/*
1450
		 * FreeformContent ffc = slide.getFreeformContent(); List<String>
1451
		 * vidList = new ArrayList<String>(); List<String> imgList = new
1452
		 * ArrayList<String>();
1453
		 * 
1454
		 * if(ffc!=null){ List<String> vidFfcLabels = ffc.getYoutubeRefs();
1455
		 * if(vidFfcLabels!=null){ for(String vidFfcLabel: vidFfcLabels){
1456
		 * StringTokenizer strTkn = new StringTokenizer(vidFfcLabel,"~!~");
1457
		 * String vidLabel = null; if(strTkn.hasMoreTokens()){ vidLabel =
1458
		 * strTkn.nextToken(); vidList.add(vidFfcLabel);
1459
		 * 
1460
		 * // ffc.removeMedia("youtube", vidFfcLabel); //
1461
		 * ffc.addMedia("youtube", vidLabel); } if(vidLabel == null){
1462
		 * System.out.println("Something is really breaking .. bu ha ha !!!"); }
1463
		 * totalVideos++; } } List<String> imgFfcLabels = ffc.getImageRefs();
1464
		 * if(imgFfcLabels!=null){ for(String imgFfcLabel: imgFfcLabels){
1465
		 * StringTokenizer strTkn = new StringTokenizer(imgFfcLabel,"~!~");
1466
		 * String imgLabel = null; if(strTkn.hasMoreTokens()){ imgLabel =
1467
		 * strTkn.nextToken(); imgList.add(imgFfcLabel);
1468
		 * 
1469
		 * // ffc.removeMedia("image", imgFfcLabel); // ffc.addMedia("image",
1470
		 * imgLabel); } if(imgLabel == null){
1471
		 * System.out.println("Something is really breaking .. bu ha ha !!!"); }
1472
		 * totalImages++; } }
1473
		 * 
1474
		 * for(String vidlab : vidList){ ffc.removeMedia("youtube", vidlab);
1475
		 * ffc.addMedia("youtube", (new StringTokenizer(vidlab,
1476
		 * "~!~")).nextToken()); } for(String imglab : imgList){
1477
		 * ffc.removeMedia("image",imglab); ffc.addMedia("image", (new
1478
		 * StringTokenizer(imglab, "~!~")).nextToken()); }
1479
		 * slide.setFreeformContent(ffc); System.out.println("Slide id is " +
1480
		 * slide.getSlideDefinitionID() + "   vid labels:  " + vidFfcLabels +
1481
		 * "   img labels" + imgFfcLabels); }
1482
		 */
1483
		/*
1484
		 * newEntity.addSlide(slide); }
1485
		 * 
1486
		 * // System.out.println("entity:"+ entity.getID() + ":trv:" +
1487
		 * totalRawVideos + ":tri:" + totalRawImages +":tv:" + totalVideos
1488
		 * +":ti:" + totalImages); // sb.append("entity:"+ entity.getID() +
1489
		 * ":trv:" + totalRawVideos + ":tri:" + totalRawImages +":tv:" +
1490
		 * totalVideos +":ti:" + totalImages+ ":tr:"
1491
		 * +(totalRawVideos+totalRawImages) + ":t:" +(totalVideos+totalImages) +
1492
		 * ":vd:" +(totalRawVideos-totalVideos) + ":id:"
1493
		 * +(totalRawImages-totalImages) + "\n"); sb.append(entity.getID() +
1494
		 * "\n");
1495
		 * 
1496
		 * 
1497
		 * destinationEnts.updateEntity(newEntity);
1498
		 * CreationUtils.storeEntity(newEntity);
1499
		 * 
1500
		 * Map<Long, List<Entity>> entitiesByCategory =
1501
		 * sourceEnts.getEntitiesbyCategory();
1502
		 * 
1503
		 * Map<Long, Entity> xentities = destinationEnts.getEntities();
1504
		 * 
1505
		 * CreationUtils.rewriteRepository(xentities, entitiesByCategory); }
1506
		 * else{ sb.append("				" + entity.getID() + "\n"); } }
1507
		 * 
1508
		 * 
1509
		 * out.write(sb.toString()); out.close();
1510
		 */
457 rajveer 1511
		return true;
1512
	}
4964 amit.gupta 1513
 
1514
	private boolean makeEntitiesObject() throws Exception {
1515
		// DefinitionsContainer sourceDefs = new
1516
		// DefinitionsContainer(sourceDbPath);
1517
		// DefinitionsContainer destinationDefs = new
1518
		// DefinitionsContainer(destinationDbPath);
1519
		// EntityContainer sourceEnts = new EntityContainer(sourceDbPath);
1520
		// EntityContainer destinationEnts = new
1521
		// EntityContainer(destinationDbPath);
1522
 
1523
		/*
1524
		 * Map<Long, List<Entity>> catEntities =
1525
		 * sourceEnts.getEntitiesbyCategory();
1526
		 * 
1527
		 * Map<Long, Entity> entities = sourceEnts.getEntities(); for(Long
1528
		 * catId: catEntities.keySet()){ List<Entity> ents =
1529
		 * catEntities.get(catId); for(Entity entity: ents){
1530
		 * entities.put(entity.getID(), entity);
1531
		 * System.out.println(entity.getID() + ":" + entity.getCategoryID() +
1532
		 * ":"+ entity.getBrand() + " "+ entity.getModelName() + " " +
1533
		 * entity.getModelNumber()); } }
1534
		 */
1535
 
791 rajveer 1536
		Map<Long, List<Entity>> catEntities = new TreeMap<Long, List<Entity>>();
1537
		Map<Long, Entity> entities = new TreeMap<Long, Entity>();
2720 mandeep.dh 1538
 
4964 amit.gupta 1539
		FileInputStream fstream = new FileInputStream("/home/rajveer/Desktop/1");
1540
		DataInputStream in = new DataInputStream(fstream);
1541
		BufferedReader br = new BufferedReader(new InputStreamReader(in));
1542
		String strLine;
2720 mandeep.dh 1543
 
4964 amit.gupta 1544
		while ((strLine = br.readLine()) != null) {
1545
			long entityID = Long.parseLong(strLine);
1546
			String entityDBFile = sourceDbPath + "entities" + File.separator
1547
					+ entityID + "/entity.ser";
1548
			System.out.println(entityDBFile);
1549
			Entity entity = (Entity) DBUtils.read(entityDBFile);
1550
			entities.put(entityID, entity);
2720 mandeep.dh 1551
 
4964 amit.gupta 1552
			List<Entity> catent = catEntities.get(entity.getCategoryID());
1553
			if (catent == null) {
1554
				catent = new ArrayList<Entity>();
1555
			}
1556
			catent.add(entity);
1557
			catEntities.put(entity.getCategoryID(), catent);
1558
		}
1559
		in.close();
1560
 
1561
		String entitiesDBFile = sourceDbPath + "entities" + File.separator
1562
				+ "entities.ser";
1563
		String entitiesbycategoryDBFile = sourceDbPath + "entities"
1564
				+ File.separator + "entitiesbycategory.ser";
1565
 
791 rajveer 1566
		DBUtils.delete(entitiesDBFile);
1567
		DBUtils.store(entities, entitiesDBFile);
2720 mandeep.dh 1568
 
4964 amit.gupta 1569
		// Remove existing
791 rajveer 1570
		DBUtils.delete(entitiesbycategoryDBFile);
1571
		DBUtils.store(catEntities, entitiesbycategoryDBFile);
2720 mandeep.dh 1572
 
4964 amit.gupta 1573
		return false;
791 rajveer 1574
	}
2720 mandeep.dh 1575
 
4964 amit.gupta 1576
	private boolean printDataModel() throws Exception {
1577
		DefinitionsContainer dfc = Catalog.getInstance()
1578
				.getDefinitionsContainer();
1226 rajveer 1579
		StringBuilder sb = new StringBuilder();
2720 mandeep.dh 1580
 
1226 rajveer 1581
		Map<Long, SlideDefinition> allSlideDefs = dfc.getSlideDefinitions();
4964 amit.gupta 1582
		for (Long slideDefId : allSlideDefs.keySet()) {
1226 rajveer 1583
			SlideDefinition slideDef = allSlideDefs.get(slideDefId);
1584
			sb.append(slideDefId + " - " + slideDef.getLabel() + "\n");
4964 amit.gupta 1585
			if (!slideDef.getChildrenSlideDefinitionIDs().isEmpty()) {
1586
				sb.append("Child Slides are: \t"
1587
						+ slideDef.getChildrenSlideDefinitionIDs() + "\n");
1226 rajveer 1588
			}
4964 amit.gupta 1589
			List<SlideFeatureDefinition> featureDefs = slideDef
1590
					.getSlideFeatureDefinitions();
1591
			for (SlideFeatureDefinition featureDef : featureDefs) {
1592
				sb.append("\t"
1593
						+ featureDef.getFeatureDefintionID()
1594
						+ "\t"
1595
						+ dfc.getFeatureDefinition(
1596
								featureDef.getFeatureDefintionID()).getLabel()
1597
						+ "\t" + featureDef.getEditorialImportance() + "\n");
1226 rajveer 1598
			}
1599
		}
1600
		System.out.println(sb.toString());
580 rajveer 1601
		Map<Long, Category> categories = dfc.getCategories();
4964 amit.gupta 1602
		if (categories != null) {
1226 rajveer 1603
			return true;
1604
		}
4964 amit.gupta 1605
		for (Category category : categories.values()) {
1606
			if (category.getChildrenCategory() != null) {
580 rajveer 1607
				continue;
1608
			}
1226 rajveer 1609
			sb.append(category.getLabel() + "\n");
4964 amit.gupta 1610
			List<CategorySlideDefinition> slideDefs = dfc
1611
					.getCategorySlideDefinitions(category.getID());
1612
			List<Long> slideSequence = dfc.getCategorySlideSequence(category
1613
					.getID());
1614
			for (CategorySlideDefinition slideDef : slideDefs) {
1615
				sb.append("\t"
1616
						+ dfc.getSlideDefinition(slideDef.getSlideDefintionID())
1617
								.getLabel() + "\t"
1618
						+ slideDef.getEditorialImportance() + "\n");
1619
				// List<FeatureDefinition> featureDefs =
1620
				// dfc.getFeatureDefinitions(slideDef.getSlideDefintionID());
1621
 
1622
				List<SlideFeatureDefinition> slideFeatureDefs = dfc
1623
						.getSlideDefinition(slideDef.getSlideDefintionID())
1624
						.getSlideFeatureDefinitions();
1625
 
1626
				for (SlideFeatureDefinition slideFeatureDef : slideFeatureDefs) {
1627
					FeatureDefinition featureDef = dfc
1628
							.getFeatureDefinition(slideFeatureDef
1629
									.getFeatureDefintionID());
1630
					BulletDefinition bulletDef = featureDef
1631
							.getBulletDefinition();
1632
					sb.append("\t\t\t" + featureDef.getLabel() + "\t"
1633
							+ slideFeatureDef.getEditorialImportance() + "\t"
1634
							+ featureDef.allowsBlank() + "\t"
1635
							+ bulletDef.isLearned() + "\t"
1636
							+ bulletDef.isMultivalue());
580 rajveer 1637
					List<Long> units = bulletDef.getUnitIDs();
4964 amit.gupta 1638
					if (bulletDef.getDatatypeDefinitionID() != null) {
1639
						sb.append("\t"
1640
								+ dfc.getDatatypeDefinition(
1641
										bulletDef.getDatatypeDefinitionID())
1642
										.getName());
1643
 
1226 rajveer 1644
					}
4964 amit.gupta 1645
					if (units != null) {
1646
						for (Long unit : units) {
1647
							sb.append("\t" + dfc.getUnit(unit).getFullForm()
1648
									+ "\t" + dfc.getUnit(unit).getShortForm());
580 rajveer 1649
						}
1650
					}
1226 rajveer 1651
					sb.append("\n");
580 rajveer 1652
				}
4964 amit.gupta 1653
 
580 rajveer 1654
				/*
4964 amit.gupta 1655
				 * for(FeatureDefinition featureDef: featureDefs){
1656
				 * BulletDefinition bulletDef =
1657
				 * featureDef.getBulletDefinition(); System.out.println("			" +
1658
				 * featureDef.getLabel() + " 	" + featureDef.allowsBlank() + "	"
1659
				 * + bulletDef.isLearned() + "	" + bulletDef.isMultivalue());
1660
				 * List<Long> units = bulletDef.getUnitIDs(); if(units!=null){
1661
				 * for(Long unit: units){ System.out.println("								"+
1662
				 * dfc.getUnit(unit).getFullForm() + "	"+
1663
				 * dfc.getUnit(unit).getShortForm()); } }
1664
				 * if(bulletDef.getDatatypeDefinitionID()!=null){
1665
				 * System.out.println("										" +
1666
				 * dfc.getDatatypeDefinition(bulletDef
1667
				 * .getDatatypeDefinitionID()).getName());
1668
				 * 
1669
				 * } }
1670
				 */
580 rajveer 1671
			}
1672
		}
1226 rajveer 1673
		System.out.println(sb.toString());
580 rajveer 1674
		return true;
1675
	}
4964 amit.gupta 1676
 
1677
	public boolean migrateOS() throws Exception {
4706 amit.gupta 1678
		Map<Long, Entity> map = CreationUtils.getEntities();
4964 amit.gupta 1679
		for (Long entityId : map.keySet()) {
1680
			Entity entity = map.get(entityId);
1681
			if (entity == null || entity.getSlides() == null) {
1682
				continue;
1683
			}
1684
 
1685
			for (Slide slide : entity.getSlides()) {
1686
				if (slide.getSlideDefinitionID() == 130020) {
1687
					List<Feature> features = slide.getFeatures();
1688
					for (Feature f : features) {
1689
						if (f.getFeatureDefinitionID() == 120043) {
1690
							Bullet b = f.getBullets().get(0);
1691
							String value = ((PrimitiveDataObject) b
1692
									.getDataObject()).getValue();
1693
							long enumValueID = getEnumValueForOS(value);
1694
							if (enumValueID == 110371L) {
1695
								Logger.log("Set entity:" + entityId
1696
										+ " as proprietary software", entity);
1697
							}
4706 amit.gupta 1698
							b.setDataObject(new EnumDataObject(enumValueID));
4964 amit.gupta 1699
						}
1700
					}
1701
				}
4706 amit.gupta 1702
 
4964 amit.gupta 1703
			}
1704
 
1705
			CreationUtils.updateEntity(entity);
1706
		}
1707
		return true;
4706 amit.gupta 1708
	}
1709
 
1710
	private long getEnumValueForOS(String value) {
1711
		value = value.toLowerCase();
1712
		Map<String, Long> map = getOSEnumMap();
4964 amit.gupta 1713
		String os = "Proprietary software";
1714
		if (value.contains("android")) {
1715
			if (value.contains("1.5")) {
1716
				os = "Android v1.5 (Cupcake)";
1717
			}
1718
			if (value.contains("1.6")) {
1719
				os = "Android v1.6 (Donut)";
1720
			}
1721
			if (value.contains("2.1")) {
1722
				os = "Android v2.1 (Eclair)";
1723
			}
1724
			if (value.contains("2.2")) {
1725
				os = "Android v2.2 (Froyo)";
1726
			}
1727
			if (value.contains("2.3")) {
1728
				os = "Android v2.3 (Gingerbread)";
1729
			}
1730
			if (value.contains("3.0")) {
1731
				os = "Android v3.0 (Honeycomb)";
1732
			}
1733
			if (value.contains("3.1")) {
1734
				os = "Android v3.1 (Honeycomb)";
1735
			}
1736
			if (value.contains("3.2")) {
1737
				os = "Android v3.2 (Honeycomb)";
1738
			}
4706 amit.gupta 1739
		}
4964 amit.gupta 1740
		if (value.contains("blackberry")) {
1741
			if (value.contains("os")) {
4706 amit.gupta 1742
				os = "BlackBerry OS";
1743
			}
4964 amit.gupta 1744
			if (value.contains("5.0")) {
4706 amit.gupta 1745
				os = "BlackBerry OS 5.0";
1746
			}
4964 amit.gupta 1747
			if (value.contains("6.0")) {
4706 amit.gupta 1748
				os = "BlackBerry OS 6.0";
1749
			}
4964 amit.gupta 1750
			if (value.contains("7.0")) {
4706 amit.gupta 1751
				os = "BlackBerry OS 7.0";
1752
			}
4964 amit.gupta 1753
			if (value.contains("tablet os")) {
4706 amit.gupta 1754
				os = "BlackBerry Tablet OS";
1755
			}
1756
		}
4964 amit.gupta 1757
		if (value.contains("brew mobile platform")) {
4706 amit.gupta 1758
			os = "Brew Mobile Platform";
1759
		}
4964 amit.gupta 1760
		if (value.contains("maemo 5")) {
4706 amit.gupta 1761
			os = "Maemo 5";
1762
		}
4964 amit.gupta 1763
		if (value.contains("windows phone 7")) {
4706 amit.gupta 1764
			os = "Windows Phone 7";
1765
		}
4964 amit.gupta 1766
		if (value.contains("windows phone 7.5 mango")) {
4706 amit.gupta 1767
			os = "Windows Phone 7.5 Mango";
1768
		}
4964 amit.gupta 1769
		if (value.contains("proprietary")) {
1770
			if (value.contains("lg"))
4706 amit.gupta 1771
				os = "Proprietary LG software";
4964 amit.gupta 1772
			else if (value.contains("micromax")) {
4706 amit.gupta 1773
				os = "Proprietary Micromax software";
4964 amit.gupta 1774
			} else if (value.contains("samsung")) {
4706 amit.gupta 1775
				os = "Proprietary Samsung software";
4964 amit.gupta 1776
			} else if (value.contains("sony ericsson")) {
4706 amit.gupta 1777
				os = "Proprietary Sony Ericsson software";
4964 amit.gupta 1778
			} else if (value.contains("spice")) {
4706 amit.gupta 1779
				os = "Proprietary Spice software";
4964 amit.gupta 1780
			} else if (value.contains("lava")) {
4706 amit.gupta 1781
				os = "Proprietary Lava software";
4964 amit.gupta 1782
			} else if (value.contains("alcatel")) {
4706 amit.gupta 1783
				os = "Proprietary Alcatel software";
4964 amit.gupta 1784
			} else if (value.contains("motorola")) {
4706 amit.gupta 1785
				os = "Proprietary Motorola software";
4964 amit.gupta 1786
			} else if (value.contains("karbonn")) {
4706 amit.gupta 1787
				os = "Proprietary Karbonn software";
4964 amit.gupta 1788
			} else {
4706 amit.gupta 1789
				os = "Proprietary software";
1790
			}
1791
		}
4964 amit.gupta 1792
		if (value.contains("mmp")) {
4706 amit.gupta 1793
			os = "Proprietary Samsung software";
1794
		}
4964 amit.gupta 1795
		if (value.contains("samsung")) {
1796
			if (value.contains("bada")) {
1797
				os = "Samsung bada";
1798
			}
1799
			if (value.contains("bada 1.2")) {
1800
				os = "Samsung bada 1.2";
1801
			}
4706 amit.gupta 1802
		}
4964 amit.gupta 1803
		if (value.contains("sony ericsson java platform 8")) {
4706 amit.gupta 1804
			os = "Proprietary Sony Ericsson software";
1805
		}
4964 amit.gupta 1806
		if (value.contains("s60")) {
4706 amit.gupta 1807
			os = "Symbian 60";
1808
		}
4964 amit.gupta 1809
		if (value.contains("symbian")) {
1810
			if (value.contains("40")) {
4706 amit.gupta 1811
				os = "Symbian 40";
1812
			}
4964 amit.gupta 1813
			if (value.contains("60")) {
4706 amit.gupta 1814
				os = "Symbian 60";
1815
			}
4964 amit.gupta 1816
			if (value.contains("^3")) {
4706 amit.gupta 1817
				os = "Symbian^3";
1818
			}
4964 amit.gupta 1819
			if (value.contains("anna")) {
4706 amit.gupta 1820
				os = "Symbian Anna";
1821
			}
4964 amit.gupta 1822
			if (value.contains("belle")) {
4706 amit.gupta 1823
				os = "Symbian Belle";
1824
			}
1825
		}
4964 amit.gupta 1826
		if (value.contains("ios 4")) {
4706 amit.gupta 1827
			os = "iOS 4";
1828
		}
4964 amit.gupta 1829
		if (value.contains("ios 5")) {
4706 amit.gupta 1830
			os = "iOS 5";
1831
		}
1832
		return map.get(os);
1833
	}
4964 amit.gupta 1834
 
1835
	private Map<String, Long> getOSEnumMap() {
4706 amit.gupta 1836
		Map<String, Long> map = new HashMap<String, Long>();
1837
		map.put("Android v1.5 (Cupcake)", 110335L);
1838
		map.put("Android v1.6 (Donut)", 110336L);
1839
		map.put("Android v2.1 (Eclair)", 110337L);
1840
		map.put("Android v2.2 (Froyo)", 110338L);
1841
		map.put("Android v2.3 (Gingerbread)", 110339L);
1842
		map.put("Android v3.0 (Honeycomb)", 110340L);
1843
		map.put("Android v3.1 (Honeycomb)", 110341L);
4964 amit.gupta 1844
		map.put("Android v3.2 (Honeycomb)", 110342L);
4706 amit.gupta 1845
		map.put("BlackBerry OS", 110343L);
1846
		map.put("BlackBerry OS 5.0", 110344L);
1847
		map.put("BlackBerry OS 6.0", 110345L);
1848
		map.put("BlackBerry OS 7.0", 110346L);
1849
		map.put("BlackBerry Tablet OS", 110347L);
1850
		map.put("Brew Mobile Platform", 110348L);
1851
		map.put("Maemo 5", 110349L);
1852
		map.put("Windows Phone 7", 110350L);
1853
		map.put("Windows Phone 7.5 Mango", 110351L);
1854
		map.put("Proprietary LG software", 110352L);
1855
		map.put("Proprietary Micromax software", 110353L);
1856
		map.put("Proprietary Samsung software", 110354L);
1857
		map.put("Proprietary Sony Ericsson software", 110355L);
1858
		map.put("Proprietary Spice software", 110356L);
1859
		map.put("Proprietary Lava software", 110367L);
1860
		map.put("Proprietary Karbonn software", 110368L);
1861
		map.put("Proprietary Motorola software", 110369L);
1862
		map.put("Proprietary Alcatel software", 110370L);
4964 amit.gupta 1863
		map.put("Proprietary software", 110371L);
4706 amit.gupta 1864
		map.put("Samsung bada", 110357L);
1865
		map.put("Samsung bada 1.2", 110358L);
1866
		map.put("Symbian 40", 110360L);
1867
		map.put("Symbian 60", 110361L);
1868
		map.put("Symbian^3", 110362L);
1869
		map.put("Symbian Anna", 110363L);
1870
		map.put("Symbian Belle", 110364L);
1871
		map.put("iOS 4", 110365L);
1872
		map.put("iOS 5", 110366L);
4964 amit.gupta 1873
 
4706 amit.gupta 1874
		return map;
4964 amit.gupta 1875
 
4706 amit.gupta 1876
	}
5370 amit.gupta 1877
 
1878
	private Object clone(Object object) throws Exception{
1879
		// Serializing and deserializing to clone the slide
1880
		// serialize
1881
		ByteArrayOutputStream bos = new ByteArrayOutputStream();
1882
		ObjectOutputStream out = new ObjectOutputStream(bos);
1883
		out.writeObject(object);
4964 amit.gupta 1884
 
5370 amit.gupta 1885
		// De-serialization
1886
		ByteArrayInputStream bis = new ByteArrayInputStream(
1887
				bos.toByteArray());
1888
		ObjectInputStream in = new ObjectInputStream(bis);
1889
		return in.readObject();
1890
 
1891
	}
1892
 
1893
	/**
1894
	 * 
1895
	 * @throws Exception
1896
	 */
1897
	private void copyMedia(String newEntityId, String oldEntityId, Media media) throws Exception {
1898
		String mediaDirPath = Utils.CONTENT_DB_PATH + "media" + File.separator + newEntityId;
1899
		File mediaDir = new File(mediaDirPath);
1900
		if(!mediaDir.exists()) {
1901
			mediaDir.mkdir();
1902
		} 
1903
 
1904
		String mediaFilePath = mediaDirPath + File.separator + media.getFileName();
1905
		String oldMediaFilePath = media.getLocation();
1906
 
1907
		File mediaFile = new File(mediaFilePath);
1908
		mediaFile.createNewFile();
1909
 
1910
		File oldMediaFile = new File(oldMediaFilePath);
1911
 
1912
		InputStream in = new FileInputStream(oldMediaFile);
1913
 
1914
		// appending output stream
1915
		// @rajveer : replacing the existing file 
1916
		OutputStream out = new FileOutputStream(mediaFile); 
1917
 
1918
		try {
1919
			IOUtils.copy(in, out);
1920
		}
1921
		finally {
1922
			IOUtils.closeQuietly(in);
1923
			IOUtils.closeQuietly(out);
1924
		}
1925
		media.setLocation(mediaFilePath);
1926
	}
5396 amit.gupta 1927
 
1928
	private void migrateHeadSetBack() throws Exception {
1929
		Map<Long, Long>migratorMap = new HashMap<Long, Long>();
1930
		migratorMap.put(77777000L,1000291L);
1931
		migratorMap.put(77777001L,1000292L);
1932
		migratorMap.put(77777002L,1000293L);
1933
		migratorMap.put(77777003L,1000294L);
1934
		migratorMap.put(77777004L,1000295L);
1935
		migratorMap.put(77777005L,1000296L);
1936
		migratorMap.put(77777006L,1000297L);
1937
		migratorMap.put(77777007L,1000298L);
1938
		migratorMap.put(77777008L,1000299L);
1939
		migratorMap.put(77777009L,1000300L);
1940
		migratorMap.put(77777010L,1000301L);
1941
		migratorMap.put(77777011L,1000302L);
1942
		migratorMap.put(77777012L,1000303L);
1943
		migratorMap.put(77777013L,1000304L);
1944
		migratorMap.put(77777014L,1000305L);
1945
		migratorMap.put(77777015L,1000306L);
1946
		migratorMap.put(77777016L,1000351L);
1947
		migratorMap.put(77777017L,1000352L);
1948
		migratorMap.put(77777018L,1000353L);
1949
		migratorMap.put(77777019L,1000363L);
1950
		migratorMap.put(77777020L,1000364L);
1951
		migratorMap.put(77777021L,1000365L);
1952
		migratorMap.put(77777022L,1000425L);
1953
		migratorMap.put(77777023L,1000426L);
1954
		migratorMap.put(77777024L,1000430L);
1955
		migratorMap.put(77777025L,1000434L);
1956
		migratorMap.put(77777026L,1000435L);
1957
		migratorMap.put(77777027L,1000436L);
1958
		migratorMap.put(77777028L,1000437L);
1959
		migratorMap.put(77777029L,1000438L);
1960
		migratorMap.put(77777030L,1000439L);
1961
		migratorMap.put(77777031L,1000440L);
1962
		migratorMap.put(77777032L,1000441L);
1963
		migratorMap.put(77777033L,1000442L);
1964
		migratorMap.put(77777034L,1000443L);
1965
		migratorMap.put(77777035L,1000444L);
1966
		migratorMap.put(77777036L,1000445L);
1967
		migratorMap.put(77777037L,1000446L);
1968
		migratorMap.put(77777038L,1000447L);
1969
		migratorMap.put(77777039L,1000449L);
1970
		migratorMap.put(77777040L,1000450L);
1971
		migratorMap.put(77777041L,1000451L);
1972
		migratorMap.put(77777042L,1000452L);
1973
		migratorMap.put(77777043L,1000453L);
1974
		migratorMap.put(77777044L,1000454L);
1975
		migratorMap.put(77777045L,1000455L);
1976
		migratorMap.put(77777046L,1000518L);
1977
		migratorMap.put(77777047L,1000521L);
1978
		migratorMap.put(77777048L,1000572L);
1979
		migratorMap.put(77777049L,1000575L);
1980
		migratorMap.put(77777050L,1000623L);
1981
		migratorMap.put(77777051L,1000625L);
1982
		migratorMap.put(77777052L,1000626L);
1983
		migratorMap.put(77777053L,1000627L);
1984
		migratorMap.put(77777054L,1000628L);
1985
		migratorMap.put(77777055L,1000874L);
1986
		migratorMap.put(77777056L,1001200L);
1987
		migratorMap.put(77777057L,1001375L);
1988
		migratorMap.put(77777058L,1001376L);
1989
		migratorMap.put(77777059L,1001378L);
1990
		migratorMap.put(77777060L,1001382L);
1991
		migratorMap.put(77777061L,1001808L);
1992
		migratorMap.put(77777062L,1001809L);
1993
		migratorMap.put(77777063L,1001810L);
1994
		migratorMap.put(77777064L,1001811L);
1995
		migratorMap.put(77777065L,1001812L);
1996
		migratorMap.put(77777066L,1001814L);
1997
		migratorMap.put(77777067L,1001815L);
1998
		migratorMap.put(77777068L,1001816L);
1999
		migratorMap.put(77777069L,1001817L);
2000
		migratorMap.put(77777070L,1001818L);
2001
		migratorMap.put(77777071L,1001819L);
2002
		migratorMap.put(77777072L,1001820L);
2003
		migratorMap.put(77777073L,1001821L);
2004
		migratorMap.put(77777074L,1001822L);
2005
		migratorMap.put(77777075L,1001823L);
2006
		migratorMap.put(77777076L,1001824L);
2007
		migratorMap.put(77777077L,1001825L);
2008
		migratorMap.put(77777078L,1002318L);
2009
		migratorMap.put(77777079L,1002320L);
2010
		migratorMap.put(77777080L,1003852L);
2011
		migratorMap.put(77777081L,1003853L);
2012
		migratorMap.put(77777082L,1003854L);
2013
		migratorMap.put(77777083L,1003855L);
2014
		migratorMap.put(77777084L,1003856L);
2015
		migratorMap.put(77777085L,1003857L);
2016
		migratorMap.put(77777086L,1003916L);
2017
		migratorMap.put(77777087L,1003917L);
2018
		migratorMap.put(77777088L,1003918L);
2019
		migratorMap.put(77777089L,1003919L);
2020
		migratorMap.put(77777090L,1003920L);
2021
		migratorMap.put(77777091L,1003921L);
2022
		migratorMap.put(77777092L,1003922L);
2023
		migratorMap.put(77777093L,1003923L);
2024
		migratorMap.put(77777094L,1003924L);
2025
		migratorMap.put(77777095L,1003925L);
2026
		migratorMap.put(77777096L,1003926L);
2027
		migratorMap.put(77777097L,1003927L);
2028
		migratorMap.put(77777098L,1004087L);
2029
		migratorMap.put(77777099L,1004088L);
2030
		migratorMap.put(77777100L,1004089L);
2031
		migratorMap.put(77777101L,1004134L);
2032
		migratorMap.put(77777102L,1004135L);
2033
		migratorMap.put(77777103L,1004139L);
2034
 
2035
		for(Map.Entry<Long, Long> entry : migratorMap.entrySet()) {
2036
			Long newId  = entry.getKey();
2037
			Long validId  = entry.getValue();
2038
			Entity entity  = CreationUtils.getEntity(newId);
2039
			EntityState es = CreationUtils.getEntityState(newId);
2040
			Slide sl = entity.getSlide(130130);
5397 amit.gupta 2041
			/*entity.setID(validId);
2042
			es.setID(validId);*/
5396 amit.gupta 2043
 
7129 amit.gupta 2044
 
5370 amit.gupta 2045
 
5396 amit.gupta 2046
			CreationUtils.updateEntity(entity);
2047
			CreationUtils.updateEntityState(es);
2048
			CreationUtils.deleteEntity(newId);
2049
			System.out.println(validId + " : " + es.getCategoryID() + ", removed entity id:" + newId);
2050
 
2051
		}
2052
 
2053
	}
7129 amit.gupta 2054
 
2055
	private void migrateTabletsBack() throws Exception {
7131 amit.gupta 2056
		//This entity is created after migration have to be deleted. Vrinda have to rmk it
2057
		CreationUtils.deleteEntity(1006812);
7129 amit.gupta 2058
		Date now = new Date();
2059
		Collection<Entity> entities = CreationUtils.getEntities(20010);
2060
		//entities = (List<Entity>)this.clone(entities);
2061
		for (Entity entity : entities) {
2062
			long entityId = entity.getID();
2063
			if(entityId>9999999){
2064
				long oldEntityId = entityId%10000000;
2065
				System.out.println(oldEntityId);
2066
				EntityState es = CreationUtils.getEntityState(entityId);
2067
				if(es != null) {
2068
					if (es.getStatus().equals(EntityStatus.READY) || es.getStatus().equals(EntityStatus.COMPLETE)){
2069
						es.setStatus(EntityStatus.READY);
2070
						es.setMerkedReadyOn(now);
2071
					}
2072
					es.setID(oldEntityId);
2073
					entity.setID(oldEntityId);
2074
					entity.setCategoryID(10010);
2075
					es.setCategoryID(10010);
2076
					CreationUtils.updateEntity(entity);
2077
					CreationUtils.updateEntityState(es);
2078
					CreationUtils.deleteEntity(entityId);
2079
					System.out.println(entityId + " moved back");
2080
 
2081
				} else {
2082
					CreationUtils.deleteEntity(entityId);
2083
					System.out.println("Deleted " + entityId + " due to incomplete tablets");
2084
				}
2085
			}else {
2086
				entity.setCategoryID(10010);
2087
				EntityState es = CreationUtils.getEntityState(entityId);
2088
				es.setCategoryID(10010);
2089
				CreationUtils.updateEntity(entity);
2090
				CreationUtils.updateEntityState(es);
2091
			}
2092
 
2093
 
2094
		}
2095
 
2096
	}
5760 amit.gupta 2097
 
2098
    public String getTitle(Entity entity){
2099
    	String brand = entity.getBrand();
2100
    	String modelName = entity.getModelName();
2101
    	String modelNumber = entity.getModelNumber();
2102
    	String titleString = "";
2103
    	if(StringUtils.isEmpty(modelName)){
2104
    		titleString = brand + " " + modelNumber + " Price in India | Specifications, Features and Reviews";
2105
    	}else {
2106
    		titleString = brand + " " + modelName + " Price in India | " + modelNumber + " Specifications, Features and Reviews";
2107
    	}
2108
    	return titleString;
2109
    }
2110
 
2111
    public String getMetaDescription(ExpandedEntity expEntity){
2112
    	Category parentCategory= expEntity.getCategory().getParentCategory();
2113
    	String categoryName = parentCategory.getLabel();
2114
    	if (parentCategory.getID()== Utils.MOBILE_ACCESSORIES_CATEGORY){
2115
    		categoryName = expEntity.getCategory().getLabel();
2116
    	}
2117
    	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.";
2118
    	return MessageFormat.format(template, expEntity.getBrand(), expEntity.getModelName(), expEntity.getModelNumber(), categoryName.toLowerCase());
2119
    }
7037 amit.gupta 2120
 
2121
public void migrateTablets() throws Exception {
2122
 
2123
		//Starting entity id for new Category with 10000
2124
		Collection<Entity> entities = CreationUtils.getEntities(10010);
2125
		long newCounter;
2126
		//entities = (List<Entity>)this.clone(entities);
2127
		for (Entity entity : entities) {
2128
			long entityId = entity.getID();
2129
			newCounter = Long.parseLong("1" + String.valueOf(entityId));
2130
			Entity newEntity = new Entity(newCounter, 20010);
2131
			try {
2132
				List<Slide> entitySlides = entity.getSlides();
2133
				if (entity == null || entitySlides == null) {
2134
					continue;
2135
				}
2136
				List<Slide> newEntitySlides = new ArrayList<Slide>();
2137
				/*Slide introSlide = entity.getSlide(130001);
2138
				Slide summarySlide = entity.getSlide(130054);
2139
				Slide packageContents = entity.getSlide(130025);*/
2140
				for (Slide slide : entitySlides) {
2141
					if (Arrays.asList(130054L, 130025L, 130001L).contains(slide.getSlideDefinitionID())) {
2142
						slide=(Slide)this.clone(slide); 
2143
						newEntitySlides.add(slide);
2144
					}
2145
					FreeformContent ffc1 = slide.getFreeformContent();
2146
					if(ffc1 != null){
2147
						Map<String, Media> mediaMap = ffc1.getMedias();
2148
						if(mediaMap==null){
2149
							continue;
2150
						}
2151
						for(Media media : mediaMap.values()){
2152
							if(media.getType().equals(Type.IMAGE) || media.getType().equals(Type.DOCUMENT)){
2153
								copyMedia(String.valueOf(newCounter), String.valueOf(entityId),media);
2154
							}
2155
						}
2156
					}
2157
				}
2158
 
2159
				List<Long> newSlideSequence = new ArrayList<Long>();
2160
				newSlideSequence.add(130001L);
2161
				newSlideSequence.add(130054L);
2162
				newSlideSequence.add(130172L);
2163
				newSlideSequence.add(130173L);
2164
				newSlideSequence.add(130174L);
2165
				newSlideSequence.add(130175L);
2166
				newSlideSequence.add(130176L);
2167
				newSlideSequence.add(130177L);
2168
				newSlideSequence.add(130178L);
2169
				newSlideSequence.add(130180L);
2170
				newSlideSequence.add(130183L);
2171
				newSlideSequence.add(130025L);
2172
 
2173
				newEntity.setSlideSequence(newSlideSequence);
2174
				newEntity.setBrand(entity.getBrand());
2175
				newEntity.setModelName(entity.getModelName());
2176
				newEntity.setModelNumber(entity.getModelNumber());
2177
				//entitySlides.remove(featureSlide);
2178
				newEntity.setSlides(newEntitySlides);
2179
				EntityState es = new EntityState(newCounter, 20010, "admin");
2180
				es.setBrand(entity.getBrand());
2181
				es.setModelName(entity.getModelName());
2182
				es.setModelNumber(entity.getModelNumber());
2183
				CreationUtils.createEntity(newEntity, es);
2184
				System.out.println("New entity : " + newCounter + " created using : " + entityId);
2185
				System.out.println(CreationUtils.getEntity(newCounter));
2186
				newCounter++;
2187
			}catch(Exception e){
2188
				System.out.println("Could not migrate " + entityId);
2189
			}
2190
		}
2191
 
2192
	}
5396 amit.gupta 2193
 
7111 amit.gupta 2194
public void migrateImagesInTablets() throws Exception {
2195
 
2196
	//Starting entity id for new Category with 10000
2197
	Collection<Entity> entities = CreationUtils.getEntities(10010);
2198
	long newCounter;
2199
	//entities = (List<Entity>)this.clone(entities);
2200
	for (Entity entity : entities) {
2201
		long entityId = entity.getID();
2202
		newCounter = Long.parseLong("1" + String.valueOf(entityId));
2203
		Entity newEntity = CreationUtils.getEntity(newCounter);
2204
		try {
2205
			if (newEntity == null) {
2206
				continue;
2207
			}
2208
			Slide introSlide = newEntity.getSlide(130001L);
2209
			Slide looknfeelSlide = entity.getSlide(130002L);
2210
			/*
2211
			 * Slide introSlide = entity.getSlide(130001); Slide
2212
			 * summarySlide = entity.getSlide(130054); Slide packageContents
2213
			 * = entity.getSlide(130025);
2214
			 */
7037 amit.gupta 2215
 
7111 amit.gupta 2216
			if (looknfeelSlide != null) {
2217
				FreeformContent ffc1 = looknfeelSlide.getFreeformContent();
2218
				if (ffc1 != null) {
2219
					Map<String, Media> mediaMap = ffc1.getMedias();
2220
					if (mediaMap == null) {
2221
						continue;
2222
					}
2223
					FreeformContent introFfc = introSlide
2224
							.getFreeformContent();
7123 amit.gupta 2225
					Map<String, Media> introMediaMap = new LinkedHashMap<String, Media>();
2226
					introFfc.setMedias(introMediaMap);
7111 amit.gupta 2227
					Set<String> introMediaMapKeys = introMediaMap.keySet();
7123 amit.gupta 2228
					for (Map.Entry<String, Media> entry : mediaMap.entrySet()) {
7111 amit.gupta 2229
						Media entryValue = entry.getValue();
2230
						String entryKey = entry.getKey();
2231
						if (!introMediaMapKeys.contains(entryKey)) {
2232
							introMediaMap.put(entryKey,
2233
									(Media) clone(entryValue));
2234
							if (entryValue.getType().equals(Type.IMAGE)
2235
									|| entryValue.equals(Type.DOCUMENT)) {
2236
								try {
2237
									copyMedia(String.valueOf(newCounter),
2238
											String.valueOf(entityId),
2239
											entryValue);
2240
								} catch (Exception e) {
2241
									System.out
2242
											.println("could not copy file "
2243
													+ entityId);
2244
								}
2245
							}
2246
						}
2247
					}
2248
				}
2249
			}
2250
 
2251
			CreationUtils.updateEntity(newEntity);
2252
			System.out.println("New entity : " + newCounter
2253
					+ " created using : " + entityId);
2254
		} catch (Exception e) {
2255
			e.printStackTrace();
2256
			System.out.println("Could not migrate " + entityId);
2257
		}
2258
	}
2259
 
7917 amit.gupta 2260
 
457 rajveer 2261
}
7917 amit.gupta 2262
private void miscilleniousPopulate() throws Exception{
2263
 
2264
	DefinitionsContainer defContainer = Catalog.getInstance().getDefinitionsContainer();
2265
 
2266
	//Get All Enum Values of Communication facilities 70114;
2267
	Map <Long, Entity> allEntities = CreationUtils.getEntities();
2268
	/*Map <Long, Entity> allEntities =new HashMap<Long, Entity>();
2269
	allEntities.put(1000069l, CreationUtils.getEntity(1000069l));*/
2270
	for (Map.Entry<Long, Entity> entry:allEntities.entrySet()){
2271
		Entity entity = entry.getValue();
2272
		Long categoryId = entity.getCategoryID();
2273
		EntityState es = CreationUtils.getEntityState(entity.getID());
2274
		if ((categoryId == 10002 || categoryId == 10003 || categoryId == 10004 || categoryId == 10005) 
2275
				&& (es != null && es.getStatus().equals(EntityStatus.READY))) {
2276
			ExpandedEntity expEntity = new ExpandedEntity(entity);
2277
			Slide miscSlide = expEntity.getSlide(130024l);
7932 amit.gupta 2278
			if(miscSlide != null) {
2279
				List<Feature> miscFeatures = miscSlide.getFeatures();
2280
				if(CollectionUtils.isNotEmpty(miscFeatures)){
7933 amit.gupta 2281
					Iterator<Feature> iter = miscFeatures.iterator();
2282
					while(iter.hasNext()) {
2283
						Feature f =iter.next();
2284
						if (f.getFeatureDefinitionID() == 120484l || f.getFeatureDefinitionID() == 120483l || f.getFeatureDefinitionID() == 1204821 || f.getFeatureDefinitionID() == 120481l){
7932 amit.gupta 2285
							List<Bullet> bulletList  = f.getBullets();
2286
							PrimitiveDataObject b = (PrimitiveDataObject)bulletList.get(0).getDataObject();
2287
							String bulletValue = b.getValue();
2288
							String newString = bulletValue;
7933 amit.gupta 2289
							if(bulletValue.startsWith(", ") || bulletValue.contains(",,") || bulletValue.contains("<li>")){
7932 amit.gupta 2290
								System.out.println(entity.getID());
2291
								bulletList = new ArrayList<Bullet>();
7933 amit.gupta 2292
								newString = bulletValue.replaceAll("<li>|</li>|<ul>|</ul>", ",").replaceAll(",,", ",").replaceAll(", ,", ", ").replaceAll(", $", "");
2293
 
2294
								System.out.println(newString);
7932 amit.gupta 2295
								if(newString.startsWith(", ") ){
2296
									newString = newString.replaceFirst(", ", "");
7917 amit.gupta 2297
								}
7932 amit.gupta 2298
								bulletList.add(new Bullet(new PrimitiveDataObject(newString)));
2299
								f.setBullets(bulletList);
2300
								System.out.println(newString);
7917 amit.gupta 2301
							}
7932 amit.gupta 2302
							if ( newString.equals(" ") || newString.equals("") || newString.equals("  ") || newString.equals("   ")){
7933 amit.gupta 2303
								iter.remove();
7917 amit.gupta 2304
							}
2305
						}
7932 amit.gupta 2306
					}
7933 amit.gupta 2307
					CreationUtils.updateEntity(entity);
2308
					touchEntityState(entity.getID());
7917 amit.gupta 2309
				}
2310
			}
7932 amit.gupta 2311
			//touchEntityState(entity.getID());
2312
			}
7917 amit.gupta 2313
		}
2314
	}
7973 amit.gupta 2315
 
2316
	private void step2() throws Exception {
2317
		//Get All Enum Values of Communication facilities 70114;
7975 amit.gupta 2318
		//Map <Long, Entity> allEntities = CreationUtils.getEntities();
2319
		Map <Long, Entity> allEntities =new HashMap<Long, Entity>();
2320
		allEntities.put(1007937l, CreationUtils.getEntity(1007937l));
2321
		allEntities.put(1007932l, CreationUtils.getEntity(1007932l));
2322
		allEntities.put(1007930l, CreationUtils.getEntity(1007930l));
2323
		allEntities.put(1007934l, CreationUtils.getEntity(1007934l));
2324
		allEntities.put(1007936l, CreationUtils.getEntity(1007936l));
2325
		allEntities.put(1007935l, CreationUtils.getEntity(1007935l));
7973 amit.gupta 2326
		for (Map.Entry<Long, Entity> entry:allEntities.entrySet()){
2327
			Entity entity = entry.getValue();
2328
			Long categoryId = entity.getCategoryID();
2329
			EntityState es = CreationUtils.getEntityState(entity.getID());
7975 amit.gupta 2330
			if ((categoryId == 10002 || categoryId == 10003 || categoryId == 10004 || categoryId == 10005) && es != null ) {
7973 amit.gupta 2331
				List<Slide> allSlides = entity.getSlides();
2332
				Slide slMaps = entity.getSlide(130022l);
2333
				Slide slConnectivity = (categoryId == 10005 ? entity.getSlide(130058l) : entity.getSlide(130007l));
2334
				if(slConnectivity != null){
2335
					if(slConnectivity.getSlideDefinitionID() ==130058l){
2336
						Slide newSlide = new Slide(130007l);
2337
						newSlide.setFeatures(slConnectivity.getFeatures());
2338
						allSlides.remove(slConnectivity);
2339
						allSlides.add(newSlide);
2340
						slConnectivity = newSlide;
2341
 
2342
						List<Long> slideSequence = entity.getSlideSequence();
2343
						int index =slideSequence.indexOf(130058l);
2344
						slideSequence.remove(index);;
2345
						slideSequence.add(index, 130007l);
2346
					}
2347
					if(slMaps != null) {
2348
						List<Feature> mapsFeatures = slMaps.getFeatures();
2349
						allSlides.remove(slMaps);
2350
						if(mapsFeatures != null){
2351
							for (Feature mapsFeature : mapsFeatures){
2352
								if(mapsFeature.getFeatureDefinitionID() == 120046l){
2353
									slConnectivity.getFeatures().add(mapsFeature);
2354
									break;
2355
								}
2356
							}
2357
 
2358
						}
2359
					}
2360
 
2361
				}
2362
 
2363
				Slide slKeyBoard = entity.getSlide(130026l);
2364
				Slide slDisplay = entity.getSlide(130003l);
2365
				Slide slSummary = entity.getSlide(130054l);
2366
				Slide slLookNFeel = entity.getSlide(130002l);
2367
				Feature hardkeysFeature = null;
2368
				if (slKeyBoard != null) {
2369
					List<Feature> keyBoardFeatures = slKeyBoard.getFeatures();
2370
					Iterator<Feature> iter = keyBoardFeatures.iterator();
2371
					while(iter.hasNext()){
2372
						Feature feature = iter.next();
2373
						if(feature.getFeatureDefinitionID() == 120010l){
7975 amit.gupta 2374
							if(slSummary!=null){
7984 amit.gupta 2375
							slSummary.getFeatures().add(feature);
7975 amit.gupta 2376
							}
7973 amit.gupta 2377
							iter.remove();
2378
						}
2379
						if(feature.getFeatureDefinitionID() == 120082l){
2380
							slDisplay.getFeatures().add(feature);
2381
							iter.remove();
2382
						}
2383
						if(feature.getFeatureDefinitionID() == 120009l){
2384
							slLookNFeel.getFeatures().add(feature);
2385
							iter.remove();
2386
						}
2387
						if(feature.getFeatureDefinitionID() == 120048l ){
2388
							if(hardkeysFeature == null) {
2389
								hardkeysFeature = feature;
2390
							}else {
2391
								if(feature.getBullets() != null){
2392
									hardkeysFeature.getBullets().addAll(feature.getBullets());
2393
									slLookNFeel.getFeatures().add(hardkeysFeature);
2394
								}
2395
							}
2396
							iter.remove();
2397
						}
2398
						if(feature.getFeatureDefinitionID() == 120049l ){
2399
							if(hardkeysFeature == null){
2400
								hardkeysFeature = new Feature(120048l);
2401
								hardkeysFeature.setBullets(feature.getBullets());
2402
							} else {
2403
								if(feature.getBullets() != null){
2404
									hardkeysFeature.getBullets().addAll(feature.getBullets());
2405
									slLookNFeel.getFeatures().add(hardkeysFeature);
2406
								}
2407
							}
2408
							iter.remove();
2409
						}
2410
					}
2411
 
2412
					allSlides.remove(slKeyBoard);
2413
				}
2414
				CreationUtils.updateEntity(entity);
7975 amit.gupta 2415
				//touchEntityState(entity.getID());
7973 amit.gupta 2416
			}
2417
		}
2418
 
2419
	}
7984 amit.gupta 2420
 
2421
	private void step4() throws Exception {
2422
		//Get All Enum Values of Communication facilities 70114;
2423
		Map <Long, Entity> allEntities = CreationUtils.getEntities();
2424
		/*Map <Long, Entity> allEntities = new HashMap<Long, Entity>();
2425
		allEntities.put(1002529l, CreationUtils.getEntity(1002529l));
2426
		allEntities.put(1007932l, CreationUtils.getEntity(1007932l));
2427
		allEntities.put(1007930l, CreationUtils.getEntity(1007930l));
2428
		allEntities.put(1007934l, CreationUtils.getEntity(1007934l));
2429
		allEntities.put(1007936l, CreationUtils.getEntity(1007936l));
2430
		allEntities.put(1007935l, CreationUtils.getEntity(1007935l));*/
2431
		for (Map.Entry<Long, Entity> entry:allEntities.entrySet()){
2432
			Entity entity = entry.getValue();
2433
			Long categoryId = entity.getCategoryID();
2434
			EntityState es = CreationUtils.getEntityState(entity.getID());
2435
			if ((categoryId == 10002 || categoryId == 10003 || categoryId == 10004 || categoryId == 10005) && es != null && !es.getStatus().equals(EntityStatus.UNASSIGNED)) {
2436
				List<Slide> allSlides = entity.getSlides();
2437
				if(allSlides != null){
2438
					for(Slide slide:allSlides) {
2439
						if(slide!=null){
2440
							List <Feature> features = slide.getFeatures();
2441
							Iterator<Feature> fIterator = features.iterator();
2442
							while (fIterator.hasNext()){
2443
								Feature f = fIterator.next();
2444
								long fId = f.getFeatureDefinitionID();
2445
								if(fId == 120011 || fId == 120020 || fId == 120051 || fId == 120025 || fId == 120056 || fId == 120216 || fId == 120045 || fId == 120010){
2446
									fIterator.remove();
2447
								}
2448
								if(fId==120144){
2449
									String  value = "Adobe flash player";
2450
									List<Bullet> flashb = f.getBullets();
2451
									if(flashb !=null && flashb.size() > 0){
2452
										value = ((PrimitiveDataObject)flashb.get(0).getDataObject()).getValue();
2453
									}
2454
									Slide miscSlide1 = entity.getSlide(130024l);
2455
									if(miscSlide1 != null){
2456
										List <Feature> mfeatures = miscSlide1.getFeatures();
2457
										Iterator<Feature> mIterator = mfeatures.iterator();
2458
										while (mIterator.hasNext()){
2459
											Feature mf = mIterator.next();
2460
											if(mf != null){
2461
												if(mf.getFeatureDefinitionID() == 120484l){
2462
													Bullet b = mf.getBullets().get(0);
2463
													String finalValue = ((PrimitiveDataObject)b.getDataObject()).getValue() + ", " + value;
2464
													b.setDataObject(new PrimitiveDataObject(finalValue));
2465
												}
2466
											}
2467
										}
2468
									} else {
2469
										System.out.println("no misc for entity : " + entity.getID());
2470
									}
2471
									fIterator.remove();
2472
								}
2473
							}
2474
						}
2475
					}
2476
					try{
2477
						CreationUtils.updateEntity(entity);
2478
					}catch (Exception e){
2479
						System.out.println("Could not update entity : " + entity.getID());
2480
					}
2481
					touchEntityState(entity.getID());
2482
				}
2483
			}
2484
		}
2485
	}
7997 amit.gupta 2486
	private void step6() throws Exception {
2487
		//Get All Enum Values of Communication facilities 70114;
8014 amit.gupta 2488
		DefinitionsContainer defc = Catalog.getInstance().getDefinitionsContainer();
2489
		Map <Long, Long> allEntities = getValues();
2490
		for (Map.Entry<Long, Long> entry:allEntities.entrySet()){
2491
			Long entityId = entry.getKey();
2492
			Entity entity = CreationUtils.getEntity(entityId); 
7997 amit.gupta 2493
			Long categoryId = entity.getCategoryID();
8014 amit.gupta 2494
			boolean found = false;
7997 amit.gupta 2495
			//System.out.println("entity : " + entity.getID());
2496
			EntityState es = CreationUtils.getEntityState(entity.getID());
2497
			if(!es.getStatus().equals(EntityStatus.UNASSIGNED)) {
2498
				if ((categoryId == 10002 || categoryId == 10003 || categoryId == 10004 || categoryId == 10005) 
2499
						&& es != null) {
8009 amit.gupta 2500
 
7997 amit.gupta 2501
					Slide videoSlide = entity.getSlide(130031l);
2502
					if(videoSlide != null){
8014 amit.gupta 2503
						List<Feature> features = videoSlide.getFeatures();
2504
						if(features != null) {
2505
							Iterator<Feature> iter = features.iterator();
2506
							while(iter.hasNext()){
2507
								Feature f = iter.next();
2508
								if(f.getFeatureDefinitionID() == 120475l){
2509
									found = true;
2510
									if(!entry.getValue().equals(((EnumDataObject)f.getBullets().get(0).getDataObject()).getEnumValueID())){
2511
										f.getBullets().get(0).setDataObject(new EnumDataObject(entry.getValue()));
2512
										try{
2513
											System.out.println("Recording feature updated:" + entityId);
2514
											CreationUtils.updateEntity(entity);
2515
											touchEntityState(entityId);
2516
										}catch (Exception e){
2517
											System.out.println("Could not update entity : " + entity.getID());
2518
										}
2519
									}
2520
									break;
2521
								}
8009 amit.gupta 2522
							}
8014 amit.gupta 2523
 
2524
							if(!found){
2525
								Feature f = new Feature(120475l);
2526
								f.setBullets(Arrays.asList(new Bullet(new EnumDataObject(entry.getValue()))));
2527
								features.add(f);
2528
								try{
2529
									System.out.println("Recording feature created:" + entityId);
2530
									CreationUtils.updateEntity(entity);
2531
									touchEntityState(entityId);
2532
								}catch (Exception e){
2533
									System.out.println("Could not update entity : " + entity.getID());
2534
								}
2535
							}
7997 amit.gupta 2536
						}
2537
					}
2538
				}
2539
 
2540
			}
2541
		}
2542
	}
8014 amit.gupta 2543
 
2544
	private Map<Long,Long> getValues() {
2545
		try {
2546
			Reader reader = new FileReader("/root/sample.json");
2547
			return new Gson().fromJson(reader, new TypeToken<Map<Long,Long>>() {}.getType());
2548
		} catch (FileNotFoundException e) {
2549
			e.printStackTrace();
2550
			return new HashMap<Long, Long>();
2551
		}
2552
	}
8077 amit.gupta 2553
 
2554
	private void reorderPhones() throws Exception {
2555
		DefinitionsContainer defc = Catalog.getInstance().getDefinitionsContainer();
2556
		List<Long> slideSequence = defc.getCategorySlideSequence().get(10003l);
2557
		Map <Long, Entity> allEntities = CreationUtils.getEntities();
2558
		for (Map.Entry<Long, Entity> entry:allEntities.entrySet()){
2559
			Long entityId = entry.getKey();
2560
			Entity entity = entry.getValue(); 
2561
			Long categoryId = entity.getCategoryID();
2562
			//System.out.println("entity : " + entity.getID());
2563
			EntityState es = CreationUtils.getEntityState(entity.getID());
2564
			if(!es.getStatus().equals(EntityStatus.UNASSIGNED)) {
2565
				if ((categoryId == 10002 || categoryId == 10003 || categoryId == 10004 || categoryId == 10005) 
2566
						&& es != null) {
2567
					entity.setSlideSequence(slideSequence);
2568
					CreationUtils.updateEntity(entity);
2569
					touchEntityState(entityId);
2570
				}
2571
			}
2572
		}
2573
	}
8798 amit.gupta 2574
 
8869 amit.gupta 2575
	private void getTablets() throws Exception {
2576
		StringBuffer sb = new StringBuffer();
2577
		DefinitionsContainer defs = Catalog.getInstance().getDefinitionsContainer();
2578
		Map<Long,FeatureDefinition> allFeatureDefs  = defs.getFeatureDefinitions();
2579
		List<Long> tabletFds = defs.getFeatureDefinitionIDs(10010l);
2580
 
2581
		Collection<Entity> es = CreationUtils.getEntities(10010l);
2582
		String header[] = new String[tabletFds.size()];
2583
		int index = 0;
2584
		for(Long fd : tabletFds) {
2585
			header[index++] = allFeatureDefs.get(fd).getLabel();
2586
		}
2587
		sb.append(StringUtils.join(header, "\t")).append("\n");
2588
		for (Entity entity:es){
2589
			String as[] = new String[tabletFds.size()];
2590
			Map<Long, String> m = AmazonSCDataGenerator.extractFeatureValuesForEntity(entity);
2591
			for(Map.Entry<Long, String> entry : m.entrySet()) {
2592
				if(tabletFds.indexOf(entry.getKey())==-1){
2593
					continue;
2594
				}
2595
				as[tabletFds.indexOf(entry.getKey())] = entry.getValue(); 
2596
			}
8873 amit.gupta 2597
			sb.append(entity.getID() + "\t").append(StringUtils.join(as, "\t")).append("\n");
8869 amit.gupta 2598
		}
2599
		System.out.println(sb);
2600
	}
2601
 
8909 amit.gupta 2602
	private void migrateSoftCategories() throws Exception{
2603
		Long ANDROID = 110614l;
2604
		Long WINDOWS = 110615l;
2605
		Long DUALSIM = 110616l;
2606
		Long TRISIM = 110617l;
2607
		Long CDMA = 110618l;
2608
		Long BASIC = 110619l;
2609
		Long TOUCH = 110620l;
2610
		Long PHABLET = 110621l;
2611
		Long IOS = 110622l;
2612
		Set<Long> softSet = new HashSet<Long>();
2613
		DefinitionsContainer defc = Catalog.getInstance().getDefinitionsContainer();
2614
		Collection<Entity> entities = CreationUtils.getEntities(10006l);
2615
		for(Entity entity : entities){
2616
			EntityState es = CreationUtils.getEntityState(entity.getID());
2617
			if (es.getStatus().equals(EntityStatus.READY)) {
2618
				softSet.clear();
2619
				System.out.println("Entity ID : " + es.getID());
2620
				List <Slide> slides = entity.getSlides();
2621
				if(slides != null) {
2622
					for(Slide slide : slides){
2623
						if(slide.getSlideDefinitionID() == 130020l)  {
2624
							List<Feature> fs = slide.getFeatures();
2625
							if (fs!=null){
2626
								for (Feature f1 : fs){
2627
									if(f1.getFeatureDefinitionID()==120043l){
2628
										List <Bullet> bullets = f1.getBullets();
2629
										if(bullets != null) {
2630
											for(Bullet b : bullets){
2631
												String bulletString = defc.getEnumValue(((EnumDataObject)b.getDataObject()).getEnumValueID()).getValue();
2632
												if (bulletString.contains("Android")){
2633
													softSet.add(ANDROID);
2634
													System.out.println("Added android");
2635
													break;
2636
												} 
2637
												else if (bulletString.contains("Windows")){
2638
													softSet.add(WINDOWS);
2639
													System.out.println("Added Windows");
2640
													break;
2641
												}
2642
												else if (bulletString.contains("iOS")){
2643
													softSet.add(IOS);
2644
													System.out.println("Added Apple");
2645
													break;
2646
												}
2647
											}
2648
										}
2649
									}
2650
								}
2651
							}
2652
						}
2653
 
2654
						if(slide.getSlideDefinitionID() == 130005l)  {
2655
							List<Feature> fs = slide.getFeatures();
2656
							if (fs!=null){
2657
								for (Feature f1 : fs){
2658
									if(f1.getFeatureDefinitionID()==120127l){
2659
										List <Bullet> bullets = f1.getBullets();
2660
										if(bullets != null) {
2661
											for(Bullet b : bullets){
2662
												String bulletString = defc.getEnumValue(((EnumDataObject)b.getDataObject()).getEnumValueID()).getValue();
2663
												if (bulletString.equals("Dual-SIM")){
2664
													softSet.add(DUALSIM);
2665
													System.out.println("Added Dual-SIM");
2666
													break;
2667
												} 
2668
												else if (bulletString.equals("Tri-SIM")){
2669
													softSet.add(TRISIM);
2670
													System.out.println("Added Tri-SIM");
2671
													break;
2672
												}
2673
											}
2674
										}
2675
									}
2676
									else if(f1.getFeatureDefinitionID()==120012l){
2677
										List <Bullet> bullets = f1.getBullets();
2678
										if(bullets != null) {
2679
											for(Bullet b : bullets){
2680
												String bulletString = ""; 
2681
												try{
2682
													bulletString = defc.getEnumValue(((EnumDataObject)b.getDataObject()).getEnumValueID()).getValue();
2683
												}catch (Exception e){
2684
													//b.	
2685
												}
2686
												if (bulletString.contains("CDMA")){
9051 amit.gupta 2687
													if(bulletString.contains("WCDMA")){
2688
														touchEntityState(entity.getID());
2689
													} else {
2690
														softSet.add(CDMA);
2691
														System.out.println("Added CDMA for 2G");
2692
														break;
2693
													}
8909 amit.gupta 2694
												} 
2695
											}
2696
										}
2697
									}
2698
									else if(f1.getFeatureDefinitionID()==120013l){
2699
										List <Bullet> bullets = f1.getBullets();
2700
										if(bullets != null) {
2701
											for(Bullet b : bullets){
2702
												String bulletString = ((PrimitiveDataObject)b.getDataObject()).getValue();
2703
												if (bulletString.contains("CDMA")){
9051 amit.gupta 2704
													if(bulletString.contains("WCDMA")){
2705
														touchEntityState(entity.getID());
2706
													} else {
2707
														softSet.add(CDMA);
2708
														System.out.println("Added CDMA for 3G");
2709
														break;
2710
													}
8909 amit.gupta 2711
												} 
2712
											}
2713
										}
2714
									}
2715
								}
2716
							}
2717
						}
2718
 
2719
						if(slide.getSlideDefinitionID() == 130002l)  {
2720
							List<Feature> fs = slide.getFeatures();
2721
							if (fs!=null){
2722
								for (Feature f1 : fs){
2723
									if(f1.getFeatureDefinitionID()==120009l){
2724
										List <Bullet> bullets = f1.getBullets();
2725
										if(bullets != null) {
2726
											for(Bullet b : bullets){
2727
												String bulletString = defc.getEnumValue(((EnumDataObject)b.getDataObject()).getEnumValueID()).getValue();
2728
												if(bulletString.equals("T9 keyboard")){
2729
													softSet.add(BASIC);
2730
													System.out.println("Added Basic phone");
2731
													break;
2732
												}
2733
											}
2734
										}
2735
									}
2736
								}
2737
							}
2738
						}
2739
 
2740
						if(slide.getSlideDefinitionID() == 130003l)  {
2741
							List<Feature> fs = slide.getFeatures();
2742
							if (fs!=null){
2743
								for (Feature f1 : fs){
2744
									if(f1.getFeatureDefinitionID()==120005l){
2745
										List <Bullet> bullets = f1.getBullets();
2746
										if(bullets != null) {
2747
											for(Bullet b : bullets){
2748
												String bulletString = ((PrimitiveDataObject)b.getDataObject()).getValue();
2749
												float f = Float.valueOf(bulletString);
2750
												if(f >= 5f ){
2751
													softSet.add(PHABLET);
2752
													System.out.println("Added Basic phone");
2753
													break;
2754
												}
2755
											}
2756
										}
2757
									}
2758
									else if(f1.getFeatureDefinitionID() == 120082l){
2759
										softSet.add(TOUCH);
2760
										System.out.println("Added Touch phone");
2761
									}
2762
								}
2763
							}
2764
						}
2765
					}
2766
				}
2767
				if(softSet.size()>0){
2768
					Slide summarySlide = entity.getSlide(130054l);
2769
					Feature f = new Feature(120513l);
2770
					List<Feature> features = summarySlide.getFeatures();
2771
					List<Bullet> softBullets = new ArrayList<Bullet>();
9051 amit.gupta 2772
					for(Feature f1 : features){
2773
						if(f.getFeatureDefinitionID()==120513l){
2774
							features.remove(f1);
2775
							break;
2776
						}
2777
					}
8909 amit.gupta 2778
					features.add(f);
2779
					for(Long enumId : softSet){
2780
						softBullets.add(new Bullet(new EnumDataObject(enumId)));
2781
					}
2782
					f.setBullets(softBullets);
2783
					CreationUtils.updateEntity(entity);
2784
				}
2785
			}
2786
		}
2787
	}
2788
 
2789
	private void clearEmptyPrimitiveBullets() throws Exception{
2790
		Map<Long, Entity> es = CreationUtils.getEntities();
2791
		for( Map.Entry<Long, Entity> entry : es.entrySet()){
2792
			Entity e = entry.getValue();
2793
			List<Slide> slides = e.getSlides();
2794
			if(slides != null){
2795
				for (Slide slide : slides){
2796
					List<Feature> features = slide.getFeatures();
2797
					if (features != null){
2798
						for(Feature feature : features){
2799
							List<Bullet> bullets = feature.getBullets();
2800
							if(bullets != null){
2801
								Iterator<Bullet> bIterator = bullets.iterator();
2802
								while (bIterator.hasNext()){
2803
									BulletDataObject b = bIterator.next().getDataObject();
2804
									if(b.getClass().equals(PrimitiveDataObject.class)){
2805
										PrimitiveDataObject pdo = (PrimitiveDataObject)b;
2806
										if(pdo.getValue().equals("")){
2807
											bIterator.remove();
2808
											System.out.println("Removed empty Primitive from slide :" + slide.getSlideDefinitionID() + " and entity: " + e.getID());
2809
										}
2810
									}
2811
								}
2812
							}
2813
						}
2814
					}
2815
				}
2816
				CreationUtils.updateEntity(e);
2817
			}
2818
		}
2819
	}
2820
 
8913 amit.gupta 2821
	private void updateSummaryMediaLabel() throws Exception{
2822
		Map<Long, Entity> es = CreationUtils.getEntities();
2823
		for( Map.Entry<Long, Entity> entry : es.entrySet()){
2824
			Entity e = entry.getValue();
2825
			Slide summarySlide = e.getSlide(130054l);
2826
			if(summarySlide!=null){
2827
			FreeformContent ffc = summarySlide.getFreeformContent();
2828
				if (ffc !=null){
2829
					Map<String, Media> mediaMap = ffc.getMedias();
2830
					if(mediaMap != null){
2831
						for(Map.Entry<String, Media> mediaEntry : mediaMap.entrySet()) {
2832
							if(mediaEntry.getValue().getLabel().equals("default") && !mediaEntry.getKey().equals("default")){
2833
								mediaMap.put("default", mediaMap.remove(mediaEntry.getKey()));
2834
								CreationUtils.updateEntity(e);
2835
								System.out.println("Upated summary media for:" + e.getID());
9171 amit.gupta 2836
								break;	
8913 amit.gupta 2837
							}
2838
						}
2839
					}
2840
				}
2841
			}
2842
		}
2843
	}
9171 amit.gupta 2844
 
2845
	private void updateCommunication() throws Exception{
2846
		Map<Long,Entity> es = CreationUtils.getEntities();
2847
		for( Map.Entry<Long, Entity> entry: es.entrySet()){
2848
			Entity e = entry.getValue();
2849
			//Slide commSlide = e.getSlide(130005l);
2850
			List<Slide> slides = e.getSlides();
2851
			if(slides != null){
2852
				for(Slide slide : slides){
2853
					List<Feature> features = slide.getFeatures();
2854
					if (features  != null){
2855
						slide.setFeatures(new ArrayList<Feature>(new LinkedHashSet<Feature>(features)));
2856
						if(slide.getFeatures().size() != features.size()){
2857
							System.out.println(e.getCategoryID() + ":" + e.getID() + ":" + slide.getFeatures() + "," + features);
2858
							CreationUtils.updateEntity(e);
2859
						}
2860
					}
2861
				}
2862
			}
2863
		}
2864
	}
8913 amit.gupta 2865
 
9900 amit.gupta 2866
	private void migrateReviews() throws Exception{
2867
		Map<Long, List<ExpertReview>> a =  CreationUtils.getExpertReviews();
2868
		for(Map.Entry<Long, List<ExpertReview>> entry : a.entrySet()) {
2869
			List<ExpertReview> ers = entry.getValue();
2870
			Iterator<ExpertReview> ersIterator = ers.iterator();
2871
			while (ersIterator.hasNext()){
2872
				ExpertReview er = ersIterator.next();
2873
				String review = er.getReviewContent();
2874
				String review1 = review.replaceAll("<[^>]+>", "");
2875
				if(review.equals("")){
2876
					ersIterator.remove();
2877
				} else if(!review.equals(review1)) {
2878
					er.setReviewContent(review1);
2879
				}
2880
			}
2881
			CreationUtils.storeExpertReview(entry.getKey(), ers);
2882
		}
2883
	}
2884
 
10692 amit.gupta 2885
    private List<ExpertReview> getExpertReviews(long catalogId) throws Exception {
2886
		List<ExpertReview> expertReviews = CreationUtils.getExpertReviewByEntity(catalogId);
2887
		if(expertReviews != null) {
2888
			Iterator<ExpertReview> iter = expertReviews.iterator();
2889
			while (iter.hasNext()){
2890
				ExpertReview er = iter.next();
2891
				if(!er.getStatus().equals(ExpertReviewStatus.PUBLISHED)){
2892
					iter.remove();
2893
				}
2894
			}
2895
			if(expertReviews.size()==0){
2896
				expertReviews = null;
2897
			}
2898
 
2899
		}
2900
		return expertReviews;
2901
	}
2902
 
7111 amit.gupta 2903
}
2904