Subversion Repositories SmartDukaan

Rev

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