Subversion Repositories SmartDukaan

Rev

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

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