Subversion Repositories SmartDukaan

Rev

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