Subversion Repositories SmartDukaan

Rev

Rev 249 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 249 Rev 250
Line 1... Line 1...
1
package in.shop2020.creation.controllers;
1
package in.shop2020.creation.controllers;
2
 
2
 
-
 
3
import in.shop2020.creation.util.ContentValidator;
3
import in.shop2020.creation.util.CreationUtils;
4
import in.shop2020.creation.util.CreationUtils;
4
import in.shop2020.metamodel.core.Bullet;
5
import in.shop2020.metamodel.core.Bullet;
5
import in.shop2020.metamodel.core.CompositeDataObject;
6
import in.shop2020.metamodel.core.CompositeDataObject;
6
import in.shop2020.metamodel.core.Entity;
7
import in.shop2020.metamodel.core.Entity;
7
import in.shop2020.metamodel.core.EnumDataObject;
8
import in.shop2020.metamodel.core.EnumDataObject;
Line 9... Line 10...
9
import in.shop2020.metamodel.core.FreeformContent;
10
import in.shop2020.metamodel.core.FreeformContent;
10
import in.shop2020.metamodel.core.PrimitiveDataObject;
11
import in.shop2020.metamodel.core.PrimitiveDataObject;
11
import in.shop2020.metamodel.core.Slide;
12
import in.shop2020.metamodel.core.Slide;
12
import in.shop2020.metamodel.definitions.Catalog;
13
import in.shop2020.metamodel.definitions.Catalog;
13
import in.shop2020.metamodel.definitions.Category;
14
import in.shop2020.metamodel.definitions.Category;
14
import in.shop2020.metamodel.definitions.CategorySlideDefinition;
-
 
15
import in.shop2020.metamodel.definitions.CompositeDefinition;
15
import in.shop2020.metamodel.definitions.CompositeDefinition;
16
import in.shop2020.metamodel.definitions.CompositePartDefinition;
16
import in.shop2020.metamodel.definitions.CompositePartDefinition;
17
import in.shop2020.metamodel.definitions.DefinitionsContainer;
17
import in.shop2020.metamodel.definitions.DefinitionsContainer;
18
import in.shop2020.metamodel.definitions.EntityContainer;
18
import in.shop2020.metamodel.definitions.EntityContainer;
19
import in.shop2020.metamodel.definitions.FeatureDefinition;
19
import in.shop2020.metamodel.definitions.FeatureDefinition;
Line 25... Line 25...
25
import in.shop2020.metamodel.util.ExpandedFeature;
25
import in.shop2020.metamodel.util.ExpandedFeature;
26
import in.shop2020.metamodel.util.ExpandedFeatureDefinition;
26
import in.shop2020.metamodel.util.ExpandedFeatureDefinition;
27
import in.shop2020.metamodel.util.ExpandedSlide;
27
import in.shop2020.metamodel.util.ExpandedSlide;
28
import in.shop2020.metamodel.util.ExpandedSlideDefinition;
28
import in.shop2020.metamodel.util.ExpandedSlideDefinition;
29
import in.shop2020.metamodel.util.SequenceGenerator;
29
import in.shop2020.metamodel.util.SequenceGenerator;
30
import in.shop2020.ui.util.VUI;
-
 
31
import in.shop2020.util.DBUtils;
-
 
32
import in.shop2020.util.Utils;
30
import in.shop2020.util.Utils;
33
 
31
 
34
import java.util.ArrayList;
32
import java.util.ArrayList;
35
import java.util.Arrays;
33
import java.util.Arrays;
36
import java.util.Collection;
34
import java.util.Collection;
Line 73... Line 71...
73
	 */
71
	 */
74
	private String id;
72
	private String id;
75
	
73
	
76
	private ExpandedEntity expEntity;
74
	private ExpandedEntity expEntity;
77
	
75
	
-
 
76
	private Entity entity;
-
 
77
	
78
	private Collection<Entity> entities;
78
	private Collection<Entity> entities;
79
 
79
 
80
	private Map<String, String[]> reqparams;
80
	private Map<String, String[]> reqparams;
81
	
81
	
82
	private EntityContainer ents;
82
	private EntityContainer ents;
Line 99... Line 99...
99
	
99
	
100
	private long newNextSlideDefinitionID;
100
	private long newNextSlideDefinitionID;
101
	
101
	
102
	private long newPrevSlideDefinitionID;
102
	private long newPrevSlideDefinitionID;
103
 
103
 
-
 
104
	private Map<Long, List<Long>> catSlides;
-
 
105
 
104
    // GET /entity/1
106
    // GET /entity/1
105
    public String show() {
107
    public String show() {
106
    	log.info("EntityController.show");
108
    	log.info("EntityController.show");
107
    	
109
    	
108
    	try {
110
    	try {
109
    		long entityID = Long.parseLong(this.getId());
111
    		long entityID = Long.parseLong(this.getId());
110
    		log.info("entityID:" + entityID);
112
    		log.info("entityID:" + entityID);
111
    		
113
    		
112
			EntityContainer ents = this.getEntityContainer();
-
 
113
			this.expEntity = ents.getExpandedEntity(entityID);
114
			this.expEntity = this.getExpandedEntity(entityID);
114
			
115
			
115
			return "show";
116
			return "show";
116
		} catch (Exception e) {
117
		} catch (Exception e) {
117
			log.error(CreationUtils.getStackTrace(e));
118
			log.error(CreationUtils.getStackTrace(e));
118
			this.setErrorString(CreationUtils.getStackTrace(e));
119
			this.setErrorString(CreationUtils.getStackTrace(e));
119
			return "fatal";
120
			return "fatal";
120
		}
121
		}
121
    }
122
    }
122
 
-
 
123
	
123
	
124
    // GET /entity
124
    // GET /entity
125
    public HttpHeaders index() {
125
    public HttpHeaders index() {
126
    	log.info("EntityController.index");
126
    	log.info("EntityController.index");
127
    	
127
    	
Line 173... Line 173...
173
    	log.info("EntityController.edit");
173
    	log.info("EntityController.edit");
174
    	
174
    	
175
    	long entityID = Long.parseLong(this.getId());
175
    	long entityID = Long.parseLong(this.getId());
176
    	log.info("entityID:" + entityID);
176
    	log.info("entityID:" + entityID);
177
    	
177
    	
178
    	EntityContainer ents = this.getEntityContainer();
-
 
179
    	DefinitionsContainer defs = this.getDefinitionsContainer();
178
    	DefinitionsContainer defs = this.getDefinitionsContainer();
180
    	
179
    	
181
    	try {
180
    	try {
182
			this.expEntity = ents.getExpandedEntity(entityID);
181
			this.expEntity = this.getExpandedEntity(entityID);
183
			//log.info("this.expEntity:" + this.expEntity);
182
			//log.info("this.expEntity:" + this.expEntity);
184
 
183
 
185
			String[] inputSlideDefIDs = this.reqparams.get("slideDefID");
184
			String[] inputSlideDefIDs = this.reqparams.get("slideDefID");
186
			long inputSlideDefID = 0L;
185
			long inputSlideDefID = 0L;
187
			if(inputSlideDefIDs != null && inputSlideDefIDs.length > 0) {
186
			if(inputSlideDefIDs != null && inputSlideDefIDs.length > 0) {
Line 241... Line 240...
241
		}
240
		}
242
		
241
		
243
        return "edit";
242
        return "edit";
244
    }
243
    }
245
    
244
    
-
 
245
    /**
-
 
246
     * 
-
 
247
     * @return
246
    
248
     */
247
    public String getUrl() {
249
    public String getUrl() {
248
    	return this.redirectURL;
250
    	return this.redirectURL;
249
    }
251
    }
250
 
252
    
-
 
253
    /**
-
 
254
     * 
-
 
255
     * @return
-
 
256
     */
251
    // GET /entity/new
257
    // GET /entity/new
252
    public String editNew() {
258
    public String editNew() {
253
    	log.info("EntityController.editNew");
259
    	log.info("EntityController.editNew");
254
 
260
 
255
        return "editNew";
261
        return "editNew";
256
    }
262
    }
257
 
263
    
-
 
264
    /**
-
 
265
     * 
-
 
266
     * @return
-
 
267
     */
258
    // GET /entity/1
268
    // GET /entity/1
259
    public String update() {
269
    public String update() {
260
    	log.info("EntityController.update");
270
    	log.info("EntityController.update");
261
 
271
 
262
    	long entityID = Long.parseLong(this.getId());
272
    	long entityID = Long.parseLong(this.getId());
263
    	log.info("entityID:" + entityID);
273
    	log.info("entityID:" + entityID);
264
    	
274
    	
265
    	EntityContainer ents = this.getEntityContainer();
-
 
266
    	DefinitionsContainer defs = this.getDefinitionsContainer();
275
    	DefinitionsContainer defs = this.getDefinitionsContainer();
267
    	
276
    	
268
    	try {
277
    	try {
269
			this.expEntity = ents.getExpandedEntity(entityID);
278
			this.expEntity = this.getExpandedEntity(entityID);
270
			//log.info("this.expEntity:" + this.expEntity);
279
			//log.info("this.expEntity:" + this.expEntity);
271
 
280
 
272
			// Save and Go to slides selection page
281
			// Save and Go to slides selection page
273
			if (this.reqparams.containsKey("slides")) {
282
			if (this.reqparams.containsKey("slides")) {
274
				log.info("Slides");
283
				log.info("Slides");
Line 289... Line 298...
289
			}
298
			}
290
			
299
			
291
			long currentSlideDefID = 0L;
300
			long currentSlideDefID = 0L;
292
			long nextSlideDefID = 0L;
301
			long nextSlideDefID = 0L;
293
			long prevSlideDefID = 0L;
302
			long prevSlideDefID = 0L;
-
 
303
			long gotoSlideDefID = 0L;
294
			
304
			
295
			String[] currentslideDefIDStrings = 
305
			String[] currentslideDefIDStrings = 
296
				this.reqparams.get("currentslideDefID");
306
				this.reqparams.get("currentslideDefID");
297
			
307
			
298
			String[] nextslideDefIDStrings = 
308
			String[] nextslideDefIDStrings = 
299
				this.reqparams.get("nextslideDefID");
309
				this.reqparams.get("nextslideDefID");
300
			
310
			
301
			String[] prevslideDefIDStrings = 
311
			String[] prevslideDefIDStrings = 
302
				this.reqparams.get("prevslideDefID");
312
				this.reqparams.get("prevslideDefID");
303
			
313
			
-
 
314
			String[] gotoslideDefIDStrings = 
-
 
315
				this.reqparams.get("gotoslideDefID");
-
 
316
			log.info("gotoslideDefIDStrings:" + 
-
 
317
					Arrays.toString(gotoslideDefIDStrings));
-
 
318
			
304
			// Current Slide ID
319
			// Current Slide ID
305
			if(currentslideDefIDStrings != null && 
320
			if(currentslideDefIDStrings != null && 
306
					currentslideDefIDStrings.length > 0) {
321
					currentslideDefIDStrings.length > 0) {
307
				try {
322
				try {
308
					currentSlideDefID = Long.parseLong(
323
					currentSlideDefID = Long.parseLong(
Line 326... Line 341...
326
				try {
341
				try {
327
					prevSlideDefID = Long.parseLong(prevslideDefIDStrings[0]);
342
					prevSlideDefID = Long.parseLong(prevslideDefIDStrings[0]);
328
				}
343
				}
329
				catch (NumberFormatException nfe) {}
344
				catch (NumberFormatException nfe) {}
330
			}
345
			}
-
 
346
			
-
 
347
			// Go to Slide ID
-
 
348
			if(gotoslideDefIDStrings != null && 
-
 
349
					gotoslideDefIDStrings.length > 0) {
-
 
350
				try {
-
 
351
					gotoSlideDefID = Long.parseLong(gotoslideDefIDStrings[0]);
-
 
352
				}
-
 
353
				catch (NumberFormatException nfe) {}
-
 
354
			}
-
 
355
			
331
			log.info("currentSlideDefID:" + currentSlideDefID);
356
			log.info("currentSlideDefID:" + currentSlideDefID);
332
			log.info("nextSlideDefID:" + nextSlideDefID);
357
			log.info("nextSlideDefID:" + nextSlideDefID);
333
			log.info("prevSlideDefID:" + prevSlideDefID);
358
			log.info("prevSlideDefID:" + prevSlideDefID);
-
 
359
			log.info("gotoSlideDefID:" + gotoSlideDefID);
334
			
360
			
335
			
361
			
336
			// Save on basic info page
362
			// Save on basic info page
337
			if (this.reqparams.containsKey("save") && currentSlideDefID == 0L) {
363
			if (this.reqparams.containsKey("save") && currentSlideDefID == 0L) {
338
				log.info("Save");
364
				log.info("Save");
Line 349... Line 375...
349
				this.updateEntity(entity);
375
				this.updateEntity(entity);
350
				
376
				
351
				return "success";
377
				return "success";
352
			}
378
			}
353
			
379
			
354
			List<Long> slideIDs = CreationUtils.getSlideSequence(entityID);
380
			List<Long> slideIDs = this.getSlideSequence(entityID);
355
			log.info("slideIDs:"+slideIDs);
381
			log.info("slideIDs:"+slideIDs);
356
			if(slideIDs == null) {
382
			if(slideIDs == null) {
357
				this.setErrorString("Slides need to be picked first!");
383
				this.setErrorString("Slides need to be picked first!");
358
				return "fatal";
384
				return "fatal";
359
			}
385
			}
Line 368... Line 394...
368
				this.reqparams.containsKey("next");
394
				this.reqparams.containsKey("next");
369
 
395
 
370
			boolean prev = this.reqparams.containsKey("skipprev") || 
396
			boolean prev = this.reqparams.containsKey("skipprev") || 
371
				this.reqparams.containsKey("prev");
397
				this.reqparams.containsKey("prev");
372
 
398
 
-
 
399
			boolean go = this.reqparams.containsKey("goto");
373
			
400
				
374
			// Save or Next or Prev - When editing a slide
401
			// Save or Next or Prev or Go - When editing a slide
375
			int currentSlideIndex = 0;
402
			int currentSlideIndex = 0;
376
			currentSlideIndex = slideIDs.indexOf(new Long(currentSlideDefID));
403
			currentSlideIndex = slideIDs.indexOf(new Long(currentSlideDefID));
377
			log.info("currentSlideIndex:" + currentSlideIndex);
404
			log.info("currentSlideIndex:" + currentSlideIndex);
378
 
405
 
379
			if(!skip && currentSlideDefID != 0L) {
406
			if(!skip && currentSlideDefID != 0L) {
Line 382... Line 409...
382
				// Create new instance and override existing
409
				// Create new instance and override existing
383
				Slide currentSlide = this.createSlide(currentSlideDefID);
410
				Slide currentSlide = this.createSlide(currentSlideDefID);
384
				
411
				
385
				entity.addSlide(currentSlide);
412
				entity.addSlide(currentSlide);
386
				
413
				
-
 
414
				List<Long> orderedSlideIDs = 
-
 
415
					CreationUtils.getSlideSequence(entityID);
-
 
416
				
-
 
417
				if(orderedSlideIDs != null) {
-
 
418
					entity.reorderSlides(orderedSlideIDs);
-
 
419
				}
-
 
420
				
387
				// Store
421
				// Store
388
				this.updateEntity(entity);
422
				this.updateEntity(entity);
389
				//log.info("entity:" + entity);
423
				//log.info("entity:" + entity);
390
			}
424
			}
391
			
425
			
392
			// Skip will delete current slide from entity
426
			// Skip will delete current slide from entity
393
			else if(skip && currentSlideDefID != 0L) {
427
			else if(skip && currentSlideDefID != 0L) {
394
				Entity entity = this.expEntity.getEntity();
428
				Entity entity = this.expEntity.getEntity();
395
				entity.removeSlide(currentSlideDefID);
429
				entity.removeSlide(currentSlideDefID);
396
				
430
				
-
 
431
				List<Long> orderedSlideIDs = 
-
 
432
					CreationUtils.getSlideSequence(entityID);
-
 
433
				
-
 
434
				if(orderedSlideIDs != null) {
-
 
435
					entity.reorderSlides(orderedSlideIDs);
-
 
436
				}
-
 
437
				
397
				// Store
438
				// Store
398
				this.updateEntity(entity);
439
				this.updateEntity(entity);
399
				//log.info("entity:" + entity);
440
				//log.info("entity:" + entity);
400
			}
441
			}
401
			
442
			
Line 465... Line 506...
465
				}
506
				}
466
				
507
				
467
				showAnotherSlide = true;
508
				showAnotherSlide = true;
468
			}
509
			}
469
			
510
			
-
 
511
			// Go to
-
 
512
			if(go && gotoSlideDefID != 0) {
-
 
513
				log.info("Goto");
-
 
514
				int gotoSlideIndex = slideIDs.indexOf(new Long(gotoSlideDefID));
-
 
515
				log.info("gotoSlideIndex:" + gotoSlideIndex);
-
 
516
				
-
 
517
				if (gotoSlideIndex == -1) {
-
 
518
					this.setErrorString("Invalid Go to slide ID " + 
-
 
519
							gotoSlideDefID);
-
 
520
					return "fatal";
-
 
521
				}
-
 
522
								
-
 
523
				// New Next
-
 
524
				if(gotoSlideIndex != slideIDs.size()-1) {
-
 
525
					newNextIndex = gotoSlideIndex + 1;
-
 
526
				}
-
 
527
 
-
 
528
				// New Current
-
 
529
				newCurrentIndex = gotoSlideIndex;
-
 
530
				
-
 
531
				// New Prev.
-
 
532
				if (gotoSlideIndex != 0) {
-
 
533
					newPrevIndex = gotoSlideIndex - 1;
-
 
534
				}
-
 
535
				
-
 
536
				showAnotherSlide = true;
-
 
537
			}
-
 
538
			
470
			if(showAnotherSlide) {
539
			if(showAnotherSlide) {
471
 				log.info("newCurrentIndex:" + newCurrentIndex);
540
 				log.info("newCurrentIndex:" + newCurrentIndex);
472
				log.info("newNextIndex:" + newNextIndex);
541
				log.info("newNextIndex:" + newNextIndex);
473
				log.info("newPrevIndex:" + newPrevIndex);
542
				log.info("newPrevIndex:" + newPrevIndex);
474
 
543
 
Line 513... Line 582...
513
        return "success";
582
        return "success";
514
    }
583
    }
515
	
584
	
516
    /**
585
    /**
517
     * 
586
     * 
-
 
587
     * @param entityID
-
 
588
     * @return
-
 
589
     * @throws Exception 
-
 
590
     */
-
 
591
    public long getBorrowedCategoryID(long slideDefID) throws Exception {
-
 
592
    	long entityID = Long.parseLong(this.getId());
-
 
593
    	Entity entity = this.getEntity(entityID);
-
 
594
    	Long entityCatID = new Long(entity.getCategoryID());
-
 
595
    	
-
 
596
    	Map<Long, List<Long>> catSlides = this.getRawSlideSequence(entityID);
-
 
597
    	
-
 
598
    	Long lSlideDefID = new Long(slideDefID);
-
 
599
    	if(catSlides != null) {
-
 
600
    		for(Long catID : catSlides.keySet()) {
-
 
601
    			List<Long> slideDefIDs = catSlides.get(catID);
-
 
602
    			if(slideDefIDs.contains(lSlideDefID) && 
-
 
603
    					!catID.equals(entityCatID)) {
-
 
604
    				return catID.longValue();
-
 
605
    			}
-
 
606
    		}
-
 
607
    	}
-
 
608
    	
-
 
609
    	return 0L;
-
 
610
    }
-
 
611
 
-
 
612
	/**
-
 
613
     * 
-
 
614
     * @param entityID
-
 
615
     * @return
-
 
616
     * @throws Exception 
-
 
617
     */
-
 
618
    private List<Long> getSlideSequence(long entityID) throws Exception {
-
 
619
    	this.catSlides = this.getRawSlideSequence(entityID);
-
 
620
    	return CreationUtils.getSlideSequence(this.catSlides);
-
 
621
	}
-
 
622
    
-
 
623
    /**
-
 
624
     * 
-
 
625
     * @param entityID
-
 
626
     * @return
-
 
627
     * @throws Exception
-
 
628
     */
-
 
629
	private Map<Long, List<Long>> getRawSlideSequence(long entityID) 
-
 
630
		throws Exception {
-
 
631
		if(this.catSlides == null) {
-
 
632
			this.catSlides = CreationUtils.getRawSlideSequence(entityID);
-
 
633
		}
-
 
634
		
-
 
635
		return this.catSlides;
-
 
636
	}
-
 
637
 
-
 
638
 
-
 
639
	/**
-
 
640
     * 
518
     * @param slideDefID
641
     * @param slideDefID
519
     * @return
642
     * @return
520
     * @throws Exception
643
     * @throws Exception
521
     */
644
     */
522
    private Slide createSlide(long slideDefID) throws Exception {
645
    private Slide createSlide(long slideDefID) throws Exception {
523
		Slide slide = new Slide(slideDefID);
646
		Slide slide = new Slide(slideDefID);
524
		
647
		
-
 
648
		long borrowedCategoryID = this.getBorrowedCategoryID(slideDefID);
-
 
649
		log.info("borrowedCategoryID:" + borrowedCategoryID);
-
 
650
		
-
 
651
		if(borrowedCategoryID != 0L) {
-
 
652
			slide.setBorrowedCategoryID(borrowedCategoryID);
-
 
653
		}
-
 
654
		
525
		// Slide free-form content
655
		// Slide free-form content
526
		FreeformContent slideFFC = this.getFreeformContent(
656
		FreeformContent slideFFC = this.getFreeformContent(
527
				"slide_" + slideDefID);
657
				"slide_" + slideDefID);
528
		
658
		
529
		log.info("slideFFC:" + slideFFC);
659
		log.info("slideFFC:" + slideFFC);
Line 710... Line 840...
710
    // DELETE /entity/1000001
840
    // DELETE /entity/1000001
711
    /**
841
    /**
712
     * 
842
     * 
713
     */
843
     */
714
    public String destroy() {
844
    public String destroy() {
715
    	log.info("EntityController.destroy");
845
    	log.info("#### EntityController.destroy ####");
716
    	
846
    	
717
    	long entityID = Long.parseLong(this.getId());
847
    	long entityID = Long.parseLong(this.getId());
718
    	log.info("entityID:" + entityID);
848
    	log.info("entityID:" + entityID);
719
	
849
	
720
		// Store
850
		// Store
721
		try {
851
		try {
-
 
852
	    	Entity entity = this.getEntity(entityID);
722
	    	EntityContainer ents = this.getEntityContainer();
853
	    	EntityContainer ents = this.getEntityContainer();
723
	    	Entity entity = ents.getEntity(entityID);
-
 
724
	    	
854
	    	
725
	    	Map<Long, Entity> entities = ents.getEntities();
855
	    	Map<Long, Entity> entities = ents.getEntities();
726
	    	Map<Long, List<Entity>> entitiesbycat = 
856
	    	Map<Long, List<Entity>> entitiesbycat = 
727
	    		ents.getEntitiesbyCategory();
857
	    		ents.getEntitiesbyCategory();
728
	    	
858
	    	
Line 741... Line 871...
741
	    	
871
	    	
742
	    	if(entitytodelete != null) {
872
	    	if(entitytodelete != null) {
743
	    		catentities.remove(entitytodelete);
873
	    		catentities.remove(entitytodelete);
744
	    	}
874
	    	}
745
	    	
875
	    	
746
			String entitiesDBFile = Utils.ENTITIES_DB_PATH + "entities.ser";
876
	    	CreationUtils.deleteFromIncomplete(entity);
747
			String entitiesbycategoryDBFile = Utils.ENTITIES_DB_PATH + 
-
 
748
				"entitiesbycategory.ser";
-
 
749
 
877
	    	
750
			DBUtils.store(entities, entitiesDBFile);
878
	    	CreationUtils.deleteEntity(entityID);
-
 
879
	    	
751
			DBUtils.store(entitiesbycat, entitiesbycategoryDBFile);
880
	    	CreationUtils.rewriteRepository(entities, entitiesbycat);
752
		} catch (Exception e) {
881
		} catch (Exception e) {
753
			log.error(CreationUtils.getStackTrace(e));
882
			log.error(CreationUtils.getStackTrace(e));
754
			this.setErrorString(CreationUtils.getStackTrace(e));
883
			this.setErrorString(CreationUtils.getStackTrace(e));
755
			return "fatal";
884
			return "fatal";
756
		}
885
		}
Line 838... Line 967...
838
	 */
967
	 */
839
	public Collection<Entity> getEntities() {
968
	public Collection<Entity> getEntities() {
840
		return entities;
969
		return entities;
841
	}
970
	}
842
 
971
 
-
 
972
	/**
-
 
973
	 * 
-
 
974
	 * @return
-
 
975
	 */
-
 
976
	public List<Entity> getIncompleteEntities() {
-
 
977
		try {
-
 
978
			return CreationUtils.getIncomplete();
-
 
979
		} catch (Exception e) {
-
 
980
			log.error(CreationUtils.getStackTrace(e));
-
 
981
			this.setErrorString(CreationUtils.getStackTrace(e));
-
 
982
			return null;
-
 
983
		}
-
 
984
	}
-
 
985
	
843
    /**
986
    /**
844
	 * @return the entities
987
	 * @return the entities
845
	 */
988
	 */
846
	public ExpandedEntity getEntity() {
989
	public ExpandedEntity getEntity() {
847
		return expEntity;
990
		return expEntity;
Line 908... Line 1051...
908
		}
1051
		}
909
		
1052
		
910
		return cats;
1053
		return cats;
911
	}
1054
	}
912
	
1055
	
-
 
1056
	/**
-
 
1057
	 * 
-
 
1058
	 * @return
-
 
1059
	 * @throws Exception
-
 
1060
	 */
913
	public String getBrandString() throws Exception {
1061
	public String getBrandString() throws Exception {
914
		List<String> brands = this.getBrands();
1062
		List<String> brands = this.getBrands();
915
		return "\"" + StringUtils.join(brands, "\", \"") + "\"";
1063
		return "\"" + StringUtils.join(brands, "\", \"") + "\"";
916
	}
1064
	}
917
 
1065
 
-
 
1066
	/**
-
 
1067
	 * 
-
 
1068
	 * @return
-
 
1069
	 * @throws Exception
-
 
1070
	 */
918
	public List<String> getBrands() throws Exception {
1071
	public List<String> getBrands() throws Exception {
919
		EntityContainer ents = this.getEntityContainer();
1072
		EntityContainer ents = this.getEntityContainer();
920
		List<String> brands = new ArrayList<String>();
1073
		List<String> brands = new ArrayList<String>();
921
		
1074
		
922
		List<ExpandedBullet> expBullets;
1075
		List<ExpandedBullet> expBullets;
Line 958... Line 1111...
958
    /**
1111
    /**
959
     * 
1112
     * 
960
     * @param entity
1113
     * @param entity
961
     * @throws Exception
1114
     * @throws Exception
962
     */
1115
     */
963
	private void addEntity(Entity entity) throws Exception {			
1116
	private void addEntity(Entity entity) throws Exception {
-
 
1117
		log.info("#### EntityController.addEntity ####");
964
		EntityContainer entContainer = this.getEntityContainer();
1118
		EntityContainer entContainer = this.getEntityContainer();
965
 
1119
 
966
		entContainer.addEntity(entity);
1120
		entContainer.addEntity(entity);
967
		
1121
		
-
 
1122
		CreationUtils.storeEntity(entity);
-
 
1123
		
-
 
1124
		ContentValidator validator = new ContentValidator();
-
 
1125
		if(!validator.validate(entity)) {
-
 
1126
			CreationUtils.addToIncomplete(entity);
-
 
1127
		}
-
 
1128
		// Add to repository only if validations succeed
-
 
1129
		else {
-
 
1130
			CreationUtils.deleteFromIncomplete(entity);
-
 
1131
			
968
		this.storeEntities();
1132
			this.updateRepository();
-
 
1133
		}
969
	}
1134
	}
970
 
1135
 
971
    /**
1136
    /**
972
     * 
1137
     * 
973
     * @param entity
1138
     * @param entity
974
     * @throws Exception
1139
     * @throws Exception
975
     */
1140
     */
976
	private void updateEntity(Entity entity) throws Exception {			
1141
	private void updateEntity(Entity entity) throws Exception {		
-
 
1142
		log.info("#### EntityController.updateEntity ####");
977
		EntityContainer entContainer = this.getEntityContainer();
1143
		EntityContainer entContainer = this.getEntityContainer();
978
 
-
 
979
		entContainer.updateEntity(entity);
-
 
980
		
1144
		
-
 
1145
		ContentValidator validator = new ContentValidator();
-
 
1146
		if(!validator.validate(entity)) {
-
 
1147
			CreationUtils.addToIncomplete(entity);
-
 
1148
			
-
 
1149
			// Delete from repository if incomplete
-
 
1150
			entContainer.deleteEntity(entity);
-
 
1151
		}
-
 
1152
		else {
-
 
1153
			CreationUtils.deleteFromIncomplete(entity);
-
 
1154
			
-
 
1155
			entContainer.updateEntity(entity);
-
 
1156
		}
-
 
1157
		
-
 
1158
		CreationUtils.storeEntity(entity);
-
 
1159
		
981
		this.storeEntities();
1160
		this.updateRepository();
982
	}
1161
	}
983
 
1162
 
984
	/**
1163
	/**
985
	 * 
1164
	 * 
986
	 * @throws Exception
1165
	 * @throws Exception
987
	 */
1166
	 */
988
	private void storeEntities() throws Exception {	
1167
	private void updateRepository() throws Exception {	
989
		EntityContainer entContainer = this.getEntityContainer();
1168
		EntityContainer entContainer = this.getEntityContainer();
990
		
1169
		
991
		Map<Long, Entity> entities = entContainer.getEntities();
1170
		Map<Long, Entity> entities = entContainer.getEntities();
992
		log.info("entities.size():" + entities.size());
1171
		log.info("entities.size():" + entities.size());
993
		
1172
		
994
		Map<Long, List<Entity>> entitiesByCategory = 
1173
		Map<Long, List<Entity>> entitiesByCategory = 
995
			entContainer.getEntitiesbyCategory();
1174
			entContainer.getEntitiesbyCategory();
996
		log.info("entitiesByCategory.size():" + entitiesByCategory.size());
1175
		log.info("entitiesByCategory.size():" + entitiesByCategory.size());
997
		
1176
		
998
		CreationUtils.rewriteEntityDB(entities, entitiesByCategory);
1177
		CreationUtils.rewriteRepository(entities, entitiesByCategory);
999
	}
1178
	}
1000
	
1179
	
1001
	/**
1180
	/**
1002
	 * @param exception the exception to set
1181
	 * @param exception the exception to set
1003
	 */
1182
	 */
Line 1200... Line 1379...
1200
				getLabel();
1379
				getLabel();
1201
		} catch (Exception e) {
1380
		} catch (Exception e) {
1202
			return null;
1381
			return null;
1203
		}
1382
		}
1204
	}
1383
	}
-
 
1384
	
-
 
1385
	/**
-
 
1386
	 * 
-
 
1387
	 * @return
-
 
1388
	 */
-
 
1389
	public List<String[]> getSlides() {
-
 
1390
		try {
-
 
1391
			long entityID = Long.parseLong(this.getId());
-
 
1392
			List<Long> slideDefIDs = CreationUtils.getSlideSequence(entityID);
-
 
1393
			
-
 
1394
			List<String[]> slideData = new ArrayList<String[]>();
-
 
1395
			
-
 
1396
			DefinitionsContainer defs = this.getDefinitionsContainer();
-
 
1397
			for(Long slideDefID : slideDefIDs) {
-
 
1398
				SlideDefinition slideDef = defs.getSlideDefinition(slideDefID);
-
 
1399
				String label = slideDef.getLabel();
-
 
1400
				
-
 
1401
				slideData.add(new String[] {slideDefID.toString(), label});
-
 
1402
			}
-
 
1403
			
-
 
1404
			return slideData;
-
 
1405
		} catch (Exception e) {
-
 
1406
			log.error(CreationUtils.getStackTrace(e));
-
 
1407
			
-
 
1408
			return null;
-
 
1409
		}
-
 
1410
	} 
-
 
1411
    
-
 
1412
    /**
-
 
1413
     * 
-
 
1414
     * @param entityID
-
 
1415
     * @return
-
 
1416
     * @throws Exception 
-
 
1417
     */
-
 
1418
    private ExpandedEntity getExpandedEntity(long entityID) throws Exception {
-
 
1419
    	if(this.expEntity == null) {
-
 
1420
    		if(this.entity == null) {
-
 
1421
    			this.entity = this.getEntity(entityID);
-
 
1422
    		}
-
 
1423
    		
-
 
1424
	    	this.expEntity = new ExpandedEntity(entity);
-
 
1425
    	}
-
 
1426
    	
-
 
1427
    	return this.expEntity;
-
 
1428
    }
-
 
1429
 
-
 
1430
    /**
-
 
1431
     * 
-
 
1432
     * @param entityID
-
 
1433
     * @return
-
 
1434
     * @throws Exception 
-
 
1435
     */
-
 
1436
    private Entity getEntity(long entityID) throws Exception {
-
 
1437
    	log.info("#### EntityController.getEntity ####");
-
 
1438
		if(this.entity == null) {
-
 
1439
			this.entity = CreationUtils.getEntity(entityID);
-
 
1440
		}
-
 
1441
		
-
 
1442
		return this.entity;
-
 
1443
	}
1205
}
1444
}