Subversion Repositories SmartDukaan

Rev

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