Subversion Repositories SmartDukaan

Rev

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