Subversion Repositories SmartDukaan

Rev

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

Rev Author Line No. Line
479 rajveer 1
package in.shop2020.metamodel.util;
2
 
2838 mandeep.dh 3
import in.shop2020.metamodel.core.SpecialPage;
479 rajveer 4
import in.shop2020.metamodel.core.Entity;
1050 rajveer 5
import in.shop2020.metamodel.core.EntityState;
1153 rajveer 6
import in.shop2020.metamodel.core.Feature;
2275 rajveer 7
import in.shop2020.metamodel.core.Helpdoc;
1153 rajveer 8
import in.shop2020.metamodel.core.Slide;
1165 rajveer 9
import in.shop2020.metamodel.definitions.Catalog;
10
import in.shop2020.metamodel.definitions.Category;
11
import in.shop2020.metamodel.definitions.CategorySlideDefinition;
479 rajveer 12
import in.shop2020.metamodel.util.CN;
1050 rajveer 13
import in.shop2020.storage.bdb.StorageManager;
1584 chandransh 14
import in.shop2020.util.Utils;
479 rajveer 15
 
1584 chandransh 16
import java.io.File;
479 rajveer 17
import java.io.PrintWriter;
18
import java.io.StringWriter;
19
import java.io.Writer;
1153 rajveer 20
import java.util.ArrayList;
1050 rajveer 21
import java.util.Collection;
479 rajveer 22
import java.util.List;
23
import java.util.Map;
24
 
25
/**
1154 rajveer 26
 * All storage and retrival utility methods
1050 rajveer 27
 * @author rajveer
479 rajveer 28
 *
29
 */
30
public class CreationUtils {
1050 rajveer 31
 
32
	private static final String LEARNED_BULLETS = "LEARNED_BULLETS";
33
	private static final String DEFAULT_ENTITY_SCORES = "DEFAULT_ENTITY_SCORES";
34
	private static final String FACET_VALUES = "FACET_VALUES";
35
	private static final String SLIDE_SCORES = "SLIDE_SCORES";
1443 rajveer 36
	private static final String CONTENT_GENERATION_TIME = "CONTENT_GENERATION_TIME";
2094 rajveer 37
	private static final String INCONSISTENT_ENTITIES = "INCONSISTENT_ENTITIES";
2471 rajveer 38
	private static final String HELPDOC_ENTITYIDS = "HELPDOC_ENTITYIDS";
2651 rajveer 39
	private static final String RELATED_ACCESSORIES = "RELATED_ACCESSORIES";
2733 rajveer 40
	private static final String COMPARISON_STATS = "COMPARISON_STATS";
5074 amit.gupta 41
	private static final String SYNONYMS = "SYNONYMS";
2275 rajveer 42
	private static long helpDocId;
2838 mandeep.dh 43
    private static long specialPageId;
479 rajveer 44
 
45
	/**
46
	 * 
1050 rajveer 47
	 * @param aThrowable
479 rajveer 48
	 * @return
49
	 */
1050 rajveer 50
	public static String getStackTrace(Throwable aThrowable) {
51
	    final Writer result = new StringWriter();
52
	    final PrintWriter printWriter = new PrintWriter(result);
53
	    aThrowable.printStackTrace(printWriter);
54
	    return result.toString();
479 rajveer 55
	}
56
 
2094 rajveer 57
    /**
58
     * 
59
     * @param entity
60
     * @throws Exception
61
     */
62
    public static void storeInconsistentEntities(List<Long> inconsistentEntities) throws Exception {
63
        StorageManager.getStorageManager().storeDataObject(CreationUtils.INCONSISTENT_ENTITIES, inconsistentEntities);      
64
    }
65
 
66
    /**
67
     * 
68
     * @return
69
     * @throws Exception
70
     */
71
    @SuppressWarnings("unchecked")
72
    public static List<Long> getInconsistentEntities() throws Exception {
73
        return (List<Long>) StorageManager.getStorageManager().getDataObject(CreationUtils.INCONSISTENT_ENTITIES);       
74
    }
75
 
76
    /**
77
     * 
78
     * @param entity
79
     * @throws Exception
80
     */
81
    public static void storeLearnedBullets(Map<Long, List<ExpandedBullet>> learnedBullets) throws Exception {
82
        StorageManager.getStorageManager().storeDataObject(CreationUtils.LEARNED_BULLETS, learnedBullets);      
83
    }
84
 
85
    /**
86
     * 
87
     * @return
88
     * @throws Exception
89
     */
90
    @SuppressWarnings("unchecked")
91
    public static Map<Long, List<ExpandedBullet>> getLearnedBullets() throws Exception {
92
        return (Map<Long, List<ExpandedBullet>>) StorageManager.getStorageManager().getDataObject(CreationUtils.LEARNED_BULLETS);       
93
    }
94
 
2471 rajveer 95
    /**
96
     * 
97
     * @param entity
98
     * @throws Exception
99
     */
100
    public static void storeHelpdocEntityIds(Map<Long, List<Long>> helpdocEntityIds) throws Exception {
101
        StorageManager.getStorageManager().storeDataObject(CreationUtils.HELPDOC_ENTITYIDS, helpdocEntityIds);      
102
    }
103
 
104
    /**
105
     * 
106
     * @return
107
     * @throws Exception
108
     */
109
    @SuppressWarnings("unchecked")
110
    public static Map<Long, List<Long>> getHelpdocEntityIds() throws Exception {
111
        return (Map<Long, List<Long>>) StorageManager.getStorageManager().getDataObject(CreationUtils.HELPDOC_ENTITYIDS);       
112
    }
113
 
2651 rajveer 114
 
115
    /**
116
     * 
117
     * @param entity
118
     * @throws Exception
119
     */
120
    public static void storeRelatedAccessories(Map<Long, Map<Long, List<Long>>> relatedAccessories) throws Exception {
121
        StorageManager.getStorageManager().storeDataObject(CreationUtils.RELATED_ACCESSORIES, relatedAccessories);      
122
    }
2471 rajveer 123
 
5074 amit.gupta 124
    /**
125
     * 
126
     * @param Synonym that contains map of brand/category name as keys and their synonyms as values. 
127
     * @throws Exception
128
     */
129
    @SuppressWarnings("unchecked")
130
    public static Map<String, Map<String, String>> getSynonyms() throws Exception {
131
    	return (Map<String, Map<String,String>>)StorageManager.getStorageManager().getDataObject(CreationUtils.SYNONYMS);      
132
    }
133
 
134
    /**
135
     * 
136
     * @param Synonym that contains map of brand/category name as keys and their synonyms as values. 
137
     * @throws Exception
138
     */
139
    public static void storeSynonyms(Map<String, Map<String, String>> synonyms) throws Exception {
140
    	StorageManager.getStorageManager().storeDataObject(CreationUtils.SYNONYMS, synonyms);      
141
    }
142
 
2651 rajveer 143
 
144
    /**
145
     * 
146
     * @return
147
     * @throws Exception
148
     */
149
    @SuppressWarnings("unchecked")
150
    public static Map<Long, Map<Long, List<Long>>> getRelatedAccessories() throws Exception {
151
        return (Map<Long, Map<Long, List<Long>>>) StorageManager.getStorageManager().getDataObject(CreationUtils.RELATED_ACCESSORIES);       
152
    }
153
 
2733 rajveer 154
 
155
    /**
156
     * 
157
     * @param entity
158
     * @throws Exception
159
     */
160
    public static void storeComparisonStats(Map<Long, Map<Long, Long>> comparisonStats) throws Exception {
161
        StorageManager.getStorageManager().storeDataObject(CreationUtils.COMPARISON_STATS, comparisonStats);      
162
    }
2651 rajveer 163
 
2733 rajveer 164
 
165
    /**
166
     * 
167
     * @return
168
     * @throws Exception
169
     */
170
    @SuppressWarnings("unchecked")
171
    public static Map<Long, Map<Long, Long>> getComparisonStats() throws Exception {
172
        return (Map<Long, Map<Long, Long>>) StorageManager.getStorageManager().getDataObject(CreationUtils.COMPARISON_STATS);       
173
    }
174
 
479 rajveer 175
	/**
176
	 * 
1154 rajveer 177
	 * @param featureDefinitionID
178
	 * @return
179
	 * @throws Exception
180
	 */
1050 rajveer 181
	@SuppressWarnings("unchecked")
182
	public static List<ExpandedBullet> getLearnedBullets(long featureDefinitionID) throws Exception {
183
		Map<Long, List<ExpandedBullet>> learnedBullets = (Map<Long, List<ExpandedBullet>>) StorageManager.getStorageManager().getDataObject(CreationUtils.LEARNED_BULLETS);
184
		if(learnedBullets==null){
185
			return null;
479 rajveer 186
		}
1050 rajveer 187
		return learnedBullets.get(featureDefinitionID);
479 rajveer 188
	}
1050 rajveer 189
 
1154 rajveer 190
	/**
191
	 * 
192
	 * @param facetIDFacetValues
193
	 * @throws Exception
194
	 */
1050 rajveer 195
	public static void storeFacetValues(Map<Long, List<String>> facetIDFacetValues) throws Exception {
196
		StorageManager.getStorageManager().storeDataObject(CreationUtils.FACET_VALUES, facetIDFacetValues);
479 rajveer 197
	}
1050 rajveer 198
 
1154 rajveer 199
	/**
200
	 * 
201
	 * @return
202
	 * @throws Exception
203
	 */
1050 rajveer 204
	@SuppressWarnings("unchecked")
205
	public static Map<Long, List<String>>  getFacetValues() throws Exception {
206
		return (Map<Long, List<String>>) StorageManager.getStorageManager().getDataObject(CreationUtils.FACET_VALUES);
479 rajveer 207
	}
208
 
1154 rajveer 209
	/**
210
	 * 
211
	 * @param facetDefinitionID
212
	 * @return
213
	 * @throws Exception
214
	 */
1050 rajveer 215
	@SuppressWarnings("unchecked")
216
	public static List<String>  getFacetValues(long facetDefinitionID) throws Exception {
217
		Map<Long, List<String>> facetValues = (Map<Long, List<String>>) StorageManager.getStorageManager().getDataObject(CreationUtils.FACET_VALUES);
218
		return facetValues.get(facetDefinitionID);
479 rajveer 219
	}
1050 rajveer 220
 
1154 rajveer 221
	/**
222
	 * 
223
	 * @param slideScoresByEntity
224
	 * @throws Exception
225
	 */
1929 rajveer 226
	public static void storeSlideScores( Map<Long, Map<Long, Double>> slideScoresByEntity) throws Exception {
1050 rajveer 227
		StorageManager.getStorageManager().storeDataObject(CreationUtils.SLIDE_SCORES, slideScoresByEntity);
228
	}
229
 
1154 rajveer 230
	/**
231
	 * 
232
	 * @return
233
	 * @throws Exception
234
	 */
479 rajveer 235
	@SuppressWarnings("unchecked")
1929 rajveer 236
	public static Map<Long, Map<Long, Double>> getSlideScores() throws Exception {
237
		return (Map<Long, Map<Long, Double>>) StorageManager.getStorageManager().getDataObject(CreationUtils.SLIDE_SCORES);
479 rajveer 238
	}
239
 
1154 rajveer 240
	/**
241
	 * 
242
	 * @param entityID
243
	 * @return
244
	 * @throws Exception
245
	 */
1050 rajveer 246
	@SuppressWarnings("unchecked")
1929 rajveer 247
	public static Map<Long, Double> getSlideComparisonScores(long entityID) throws Exception{
248
		Map<Long, Map<Long, Double>> slideScores = (Map<Long, Map<Long, Double>>) StorageManager.getStorageManager().getDataObject(CreationUtils.SLIDE_SCORES);
1050 rajveer 249
		return slideScores.get(entityID);
479 rajveer 250
	}
251
 
1050 rajveer 252
 
1154 rajveer 253
	/**
254
	 * 
255
	 * @param finalScoreByEntityID
256
	 * @throws Exception
257
	 */
1929 rajveer 258
	public static void storeDefaultEntityScores(Map<Long, Double> finalScoreByEntityID) throws Exception {
1050 rajveer 259
		StorageManager.getStorageManager().storeDataObject(CreationUtils.DEFAULT_ENTITY_SCORES, finalScoreByEntityID);
479 rajveer 260
	}
261
 
1154 rajveer 262
	/**
263
	 * 
264
	 * @return
265
	 * @throws Exception
266
	 */
1050 rajveer 267
	@SuppressWarnings("unchecked")
268
	public static Map<Long, Integer> getDefaultEntityScores() throws Exception {
269
		return (Map<Long, Integer>) StorageManager.getStorageManager().getDataObject(CreationUtils.DEFAULT_ENTITY_SCORES);
479 rajveer 270
	}
271
 
1154 rajveer 272
	/**
273
	 * 
274
	 * @param entityID
275
	 * @return
276
	 * @throws Exception
277
	 */
1050 rajveer 278
	@SuppressWarnings("unchecked")
279
	public static Integer getEntityComparisonScores(long entityID) throws Exception {
280
		Map<Long, Integer> scoresMap =  (Map<Long, Integer>) StorageManager.getStorageManager().getDataObject(CreationUtils.DEFAULT_ENTITY_SCORES);
281
		Integer objScore = scoresMap.get(entityID);
282
		if(objScore==null){
283
			return -1;
479 rajveer 284
		}
1050 rajveer 285
		return objScore;
479 rajveer 286
	}
287
 
288
 
1443 rajveer 289
	/**
290
	 * 
291
	 * @return
292
	 * @throws Exception
293
	 */
294
	public static Long getLastContentGenerationTime() throws Exception {
295
		return (Long) StorageManager.getStorageManager().getDataObject(CreationUtils.CONTENT_GENERATION_TIME);
296
	}
479 rajveer 297
 
298
	/**
1443 rajveer 299
	 * 
300
	 * @param storageTime
301
	 * @throws Exception
302
	 */
303
	public static void storeLastContentGenerationTime(Long storageTime) throws Exception {
304
		StorageManager.getStorageManager().storeDataObject(CreationUtils.CONTENT_GENERATION_TIME, storageTime);
305
	}
306
	/**
1050 rajveer 307
	 * Resolves Entity ID into Entity object
479 rajveer 308
	 * 
309
	 * @param entityID
1050 rajveer 310
	 * @return Entity
311
	 * @throws Exception 
479 rajveer 312
	 */
1050 rajveer 313
	public static Entity getEntity(long entityID) throws Exception{
314
		return StorageManager.getStorageManager().getEntity(entityID);
479 rajveer 315
	}
316
 
1154 rajveer 317
	/**
318
	 * 
319
	 * @param entity
320
	 * @throws Exception
321
	 */
1050 rajveer 322
	public static void updateEntity(Entity entity) throws Exception {
2471 rajveer 323
		//FIXME This should not happen here. 
1379 rajveer 324
		entity.reorderSlides(entity.getSlideSequence());
2471 rajveer 325
		CreationUtils.learn(entity);
1050 rajveer 326
		StorageManager.getStorageManager().updateEntity(entity);
1226 rajveer 327
 
1379 rajveer 328
 
2471 rajveer 329
 
479 rajveer 330
	}
331
 
1154 rajveer 332
	/**
333
	 * 
334
	 * @param entity
335
	 * @param entityMetadata
336
	 * @throws Exception
337
	 */
1050 rajveer 338
	public static void createEntity(Entity entity, EntityState entityMetadata) throws Exception {
1584 chandransh 339
		/*
340
		 * Creating media directory by default. Even if there is no media uploaded yet.
341
		 */
342
		String mediaDirPath = Utils.CONTENT_DB_PATH + "media" + File.separator + entity.getID();
343
		File mediaDir = new File(mediaDirPath);
344
		if(!mediaDir.exists()) {
345
			mediaDir.mkdir();
346
		}
1050 rajveer 347
		StorageManager.getStorageManager().createEntity(entity, entityMetadata);
479 rajveer 348
	}
1050 rajveer 349
 
1154 rajveer 350
	/**
351
	 * 
352
	 * @param entityId
353
	 * @throws Exception
354
	 */
1050 rajveer 355
	public static void deleteEntity(long entityId) throws Exception  {
356
		StorageManager.getStorageManager().deleteEntity(entityId);
479 rajveer 357
	}
358
 
1050 rajveer 359
 
1154 rajveer 360
	/**
361
	 * 
362
	 * @return
363
	 * @throws Exception
364
	 */
1050 rajveer 365
	public static Map<Long, EntityState> getEntitiesState() throws Exception {
366
		return StorageManager.getStorageManager().getEntitiesMetadata();
479 rajveer 367
	}
368
 
1154 rajveer 369
	/**
370
	 * 
371
	 * @param entityId
372
	 * @return
373
	 * @throws Exception
374
	 */
1050 rajveer 375
	public static EntityState getEntityState(long entityId) throws Exception {
376
		return StorageManager.getStorageManager().getEntityMetadata(entityId);
377
	}
479 rajveer 378
 
1154 rajveer 379
	/**
380
	 * 
381
	 * @param entityMetadata
382
	 * @throws Exception
383
	 */
1050 rajveer 384
	public static void updateEntityState(EntityState entityMetadata) throws Exception {
385
		StorageManager.getStorageManager().updateEntityMetadata(entityMetadata);
479 rajveer 386
	}
1050 rajveer 387
 
1154 rajveer 388
	/**
389
	 * 
390
	 * @param entity
391
	 * @throws Exception
392
	 */
1050 rajveer 393
	private static void learn(Entity entity) throws Exception{
394
		CN cn = new CN();
2471 rajveer 395
		cn.learn(entity);
396
		cn.learnHelpdocs(entity);
1050 rajveer 397
	}
398
 
1154 rajveer 399
	/**
400
	 * 
401
	 * @return
402
	 * @throws Exception
403
	 */
1050 rajveer 404
	public static Map<Long, Entity> getEntities() throws Exception {
405
		return StorageManager.getStorageManager().getEntities();
406
	}
407
 
1154 rajveer 408
	/**
409
	 * 
410
	 * @param categoryId
411
	 * @return
412
	 * @throws Exception
413
	 */
1050 rajveer 414
	public static Collection<Entity> getEntities(long categoryId) throws Exception {
415
		return StorageManager.getStorageManager().getEntitisByCategory(categoryId);
416
	}
1153 rajveer 417
 
2275 rajveer 418
 
419
	public static void storeHelpdoc(Helpdoc helpdoc) throws Exception {
420
		StorageManager.getStorageManager().updateHelpdoc(helpdoc);
421
	}
422
 
423
	public static Helpdoc getHelpdoc(Long helpdocId) throws Exception {
424
		return StorageManager.getStorageManager().getHelpdoc(helpdocId);
425
	}
426
 
427
	public static Map<Long, Helpdoc> getHelpdocs() throws Exception {
428
		return StorageManager.getStorageManager().getHelpdocs();
429
	}
3485 rajveer 430
 
431
	public static void deleteHelpdoc(Long helpdocId) throws Exception {
432
		StorageManager.getStorageManager().deleteHelpdoc(helpdocId);
433
	}
434
 
2275 rajveer 435
	public static long getNewHelpdocId() {
436
		if(helpDocId == 0){
437
			helpDocId = 200000;
438
			Map<Long, Helpdoc> helpdocs = StorageManager.getStorageManager().getHelpdocs();
439
			if(helpdocs != null){
440
				for(long id : StorageManager.getStorageManager().getHelpdocs().keySet()){
441
					if(helpDocId <= id){
442
						helpDocId = id;
443
					}
444
				}
445
			}	
446
		}
447
		return ++helpDocId;
448
	}
449
 
450
 
1153 rajveer 451
	/**
452
	 * 
453
	 * @param slide
454
	 * @param featureDefinitionID
455
	 * @return Feature
456
	 */
457
	public static Feature getFeature(Slide slide, long featureDefinitionID) {
458
		List<Feature> features = slide.getFeatures();
459
 
460
		if(features != null) {
461
			for(Feature feature : features) {
462
				if(feature.getFeatureDefinitionID() == featureDefinitionID) {
463
					return feature;
464
				}
465
			}
466
		}
467
 
468
		Feature feature = null;
469
 
470
		List<Slide> childrenSlides = slide.getChildrenSlides();
471
		if(childrenSlides != null) {
472
			for(Slide childSlide : childrenSlides) {
473
 
474
				feature = CreationUtils.getFeature(childSlide, featureDefinitionID);
475
				if(feature == null) {
476
					continue;
477
				}
478
				else {
479
					break;
480
				}
481
			}
482
		}
483
 
484
		return feature;
485
	}
479 rajveer 486
 
1153 rajveer 487
 
488
	/**
489
	 * Utility method to find out Slide object in Entity instance
490
	 * 
491
	 * @param entityID
492
	 * @param slideDefinitionID
493
	 * @return
494
	 * @throws Exception 
495
	 */
496
	public static Slide getSlide(long entityID, long slideDefinitionID) 
497
		throws Exception {
498
		Entity entity = CreationUtils.getEntity(entityID);
499
 
500
		List<Slide> slides = entity.getSlides();
501
 
502
		Slide resultSlide = null;
503
 
504
		if(slides != null) {
505
			for(Slide slide : slides) {
506
 
507
				if(slide.getSlideDefinitionID() == slideDefinitionID) {
508
					return slide;
509
				}
510
 
511
				resultSlide = CreationUtils.getSlide(slide, slideDefinitionID);
512
 
513
				if(resultSlide == null) {
514
					continue;
515
				}
516
				else {
517
					break;
518
				}
519
			}
520
		}
521
 
522
		return resultSlide;
523
	}
524
 
525
 
526
	/**
527
	 * 
528
	 * @param slide
529
	 * @param slideDefinitionID
530
	 * @return
531
	 */
532
	public static Slide getSlide(Slide slide, long slideDefinitionID) {
533
 
534
		List<Slide> childrenSlides = slide.getChildrenSlides();
535
 
536
		Slide resultSlide = null;
537
 
538
		if(childrenSlides != null) {
539
			for(Slide childSlide : childrenSlides) {
540
				if(childSlide.getSlideDefinitionID() == slideDefinitionID) {
541
					return childSlide;
542
				}
543
 
544
				resultSlide = CreationUtils.getSlide(childSlide, slideDefinitionID);
545
				if(resultSlide == null) {
546
					continue;
547
				}
548
				else {
549
					break;
550
				}
551
			}
552
		}
553
 
554
		return resultSlide;
555
	}
556
 
557
	/**
558
	 * Utility method to find out Feature object in Entity instance
559
	 * 
560
	 * @param entityID
561
	 * @param featureDefinitionID
562
	 * @return Feature
563
	 * @throws Exception 
564
	 */
565
	public static Feature getFeature(long entityID, long featureDefinitionID) 
566
		throws Exception {
567
		Entity entity = CreationUtils.getEntity(entityID);
568
 
569
		Feature feature = null;
570
 
571
		List<Slide> slides = entity.getSlides();
572
		for(Slide slide : slides) {
573
			feature = CreationUtils.getFeature(slide, featureDefinitionID);
574
 
575
			// Until all slides are searched
576
			if(feature == null) {
577
				continue;
578
			}
579
			else {
580
				break;
581
			}
582
		}
583
 
584
		return feature;
585
	}
586
 
587
 
588
	/**
589
	 * Returns expand form of entity object. All references are resolved into 
590
	 * corresponding detail object
591
	 * 
592
	 * @param entityID
593
	 * @return ExpandedEntity 
594
	 * @throws Exception 
595
	 */
596
	public static ExpandedEntity getExpandedEntity(long entityID) throws Exception {
597
		Entity entity = CreationUtils.getEntity(entityID);
598
		if(entity==null){
599
			System.out.println("Entity is null");
600
			return null;
601
		}
602
		System.out.println( entity.getCategoryID());
603
		ExpandedEntity expEntity = new ExpandedEntity(entity);
604
		return expEntity;
605
	}
606
 
607
 
608
	/**
609
	 * Returns list of borrowed slides
610
	 * 
611
	 * @param entity
612
	 * @return list of borrowed slides
613
	 */
614
	public static List<Slide> getBorrowedSlides(Entity entity) {
615
		List<Slide> borrowedSlides = new ArrayList<Slide>();
616
 
617
		List<Slide> slides = entity.getSlides();
618
 
619
		for(Slide slide : slides) {
1165 rajveer 620
			if(CreationUtils.isBorrowedSlide(slide.getSlideDefinitionID(), entity.getCategoryID())) {
1153 rajveer 621
				borrowedSlides.add(slide);
622
			}
623
		}
624
 
625
		return borrowedSlides;
626
	}
627
 
628
	/**
629
	 * Returns first parent slide with matching label
630
	 * 
631
	 * @param expEntity2
632
	 * @param slideLabel
633
	 * @return Null if not found
634
	 */
635
	public static ExpandedSlide getParentExpandedSlide(ExpandedEntity expEntity2, String slideLabel) {
636
 
637
		ExpandedSlide matchingSlide = null;
638
		List<ExpandedSlide> expSlides = expEntity2.getExpandedSlides();
639
 
640
		for(ExpandedSlide expSlide : expSlides) {
641
			if(expSlide.getSlideDefinition().getLabel().equals(slideLabel)) {
642
				matchingSlide = expSlide;
643
				break;
644
			}
645
		}
646
 
647
		return matchingSlide;
648
	}
1165 rajveer 649
 
650
	/**
651
	 * 
652
	 * @param slideDefinitionID
653
	 * @param categoryID
654
	 * @return
655
	 */
656
	public static boolean isBorrowedSlide(long slideDefinitionID,long categoryID) {
1226 rajveer 657
		List<CategorySlideDefinition> slideDefinitions;
1165 rajveer 658
		try {
1226 rajveer 659
			slideDefinitions = Catalog.getInstance().getDefinitionsContainer().getCategorySlideDefinitions(categoryID);
660
			for(CategorySlideDefinition slideDef: slideDefinitions){
661
				if(slideDefinitionID == slideDef.getSlideDefintionID()){
662
					return false;
663
				}
1165 rajveer 664
			}
665
		} catch (Exception e) {
666
			// TODO Auto-generated catch block
667
			e.printStackTrace();
668
		}
1226 rajveer 669
		return true;
1165 rajveer 670
	}
671
 
672
	/**
673
	 * 
674
	 * @param slideDefinitionID
675
	 * @param categoryID
676
	 * @return
677
	 */
678
	public static long getBorrowedCategoryID(long slideDefinitionID, long categoryID) {
679
		try {
1226 rajveer 680
			List<CategorySlideDefinition> slideDefinitions = Catalog.getInstance().getDefinitionsContainer().getCategorySlideDefinitions(categoryID);
681
			for(CategorySlideDefinition slideDef: slideDefinitions){
682
				if(slideDefinitionID == slideDef.getSlideDefintionID()){
683
					return categoryID;
684
				}
685
			}
686
 
687
 
688
			List<Category> cats =  Catalog.getInstance().getDefinitionsContainer().getCategory(categoryID).getParentCategory().getChildrenCategory();
689
			for(Category cat: cats){
690
				if(cat.getID() == categoryID){
691
					continue;
692
				}else{
693
					List<CategorySlideDefinition> slideDefs = Catalog.getInstance().getDefinitionsContainer().getCategorySlideDefinitions(cat.getID());
694
					for(CategorySlideDefinition slideDef: slideDefs){
695
						if(slideDefinitionID == slideDef.getSlideDefintionID()){
1165 rajveer 696
							return cat.getID();
697
						}
698
					}
1226 rajveer 699
 
1165 rajveer 700
				}
701
			}
1226 rajveer 702
 
1165 rajveer 703
		} catch (Exception e) {
704
			// TODO Auto-generated catch block
705
			e.printStackTrace();
706
		}
1226 rajveer 707
		return categoryID;
1165 rajveer 708
	}
709
 
2768 mandeep.dh 710
	/**
2838 mandeep.dh 711
	 * Special page ids start from 300000. Here, we pick the last one used and return
2768 mandeep.dh 712
     * a value one more than it.
713
	 */
2838 mandeep.dh 714
    public static long getNewSpecialPageId() {
715
        if (specialPageId == 0) {
716
            specialPageId = 300000;
717
            Map<Long, SpecialPage> specialPages = StorageManager.getStorageManager().getSpecialPages();
718
            if (specialPages != null) {
719
                for (long id : StorageManager.getStorageManager().getSpecialPages().keySet()) {
720
                    if (specialPageId <= id) {
721
                        specialPageId = id;
2768 mandeep.dh 722
                    }
723
                }
724
            }
725
        }
726
 
2838 mandeep.dh 727
        return ++specialPageId;
2768 mandeep.dh 728
    }
729
 
730
    /**
2838 mandeep.dh 731
     * Updates a given special page object in database.
2768 mandeep.dh 732
     */
2838 mandeep.dh 733
    public static void storeSpecialPage(SpecialPage specialPage) {
734
        StorageManager.getStorageManager().updateSpecialPage(specialPage);        
2768 mandeep.dh 735
    }
736
 
737
    /**
2838 mandeep.dh 738
     * Looks up a special page given its Id from database and returns the same.
2768 mandeep.dh 739
     */
2838 mandeep.dh 740
    public static SpecialPage getSpecialPage(long specialPageId) {
741
        return StorageManager.getStorageManager().getSpecialPage(specialPageId);
2768 mandeep.dh 742
    }
743
 
744
    /**
2838 mandeep.dh 745
     * Returns all special pages in the database.
2768 mandeep.dh 746
     */
2838 mandeep.dh 747
    public static Map<Long, SpecialPage> getSpecialPages() {
748
        return StorageManager.getStorageManager().getSpecialPages();
2768 mandeep.dh 749
    }
3356 rajveer 750
 
751
    /**
752
     * delete the special pages from database.
753
     */
754
    public static void deleteSpecialPage(long specialPageId) {
755
        StorageManager.getStorageManager().deleteSpecialPage(specialPageId);
756
    }
5074 amit.gupta 757
 
758
 
479 rajveer 759
}