Subversion Repositories SmartDukaan

Rev

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

Rev 964 Rev 1051
Line 1... Line 1...
1
package in.shop2020.creation.controllers;
1
package in.shop2020.creation.controllers;
2
 
2
 
-
 
3
import in.shop2020.content.security.User;
3
import in.shop2020.creation.util.ContentValidator;
4
import in.shop2020.content.security.UserManager;
4
import in.shop2020.metamodel.util.CreationUtils;
5
import in.shop2020.metamodel.util.CreationUtils;
5
import in.shop2020.metamodel.core.Bullet;
6
import in.shop2020.metamodel.core.Bullet;
6
import in.shop2020.metamodel.core.CompositeDataObject;
7
import in.shop2020.metamodel.core.CompositeDataObject;
7
import in.shop2020.metamodel.core.Entity;
8
import in.shop2020.metamodel.core.Entity;
-
 
9
import in.shop2020.metamodel.core.EntityState;
8
import in.shop2020.metamodel.core.EnumDataObject;
10
import in.shop2020.metamodel.core.EnumDataObject;
9
import in.shop2020.metamodel.core.Feature;
11
import in.shop2020.metamodel.core.Feature;
10
import in.shop2020.metamodel.core.FreeformContent;
12
import in.shop2020.metamodel.core.FreeformContent;
11
import in.shop2020.metamodel.core.PrimitiveDataObject;
13
import in.shop2020.metamodel.core.PrimitiveDataObject;
12
import in.shop2020.metamodel.core.Slide;
14
import in.shop2020.metamodel.core.Slide;
Line 18... Line 20...
18
import in.shop2020.metamodel.definitions.EditorialImportance;
20
import in.shop2020.metamodel.definitions.EditorialImportance;
19
import in.shop2020.metamodel.definitions.EntityContainer;
21
import in.shop2020.metamodel.definitions.EntityContainer;
20
import in.shop2020.metamodel.definitions.FeatureDefinition;
22
import in.shop2020.metamodel.definitions.FeatureDefinition;
21
import in.shop2020.metamodel.definitions.SlideDefinition;
23
import in.shop2020.metamodel.definitions.SlideDefinition;
22
import in.shop2020.metamodel.definitions.SlideFeatureDefinition;
24
import in.shop2020.metamodel.definitions.SlideFeatureDefinition;
23
import in.shop2020.metamodel.util.CN;
-
 
24
import in.shop2020.metamodel.util.ExpandedBullet;
25
import in.shop2020.metamodel.util.ExpandedBullet;
25
import in.shop2020.metamodel.util.ExpandedBulletDefinition;
26
import in.shop2020.metamodel.util.ExpandedBulletDefinition;
26
import in.shop2020.metamodel.util.ExpandedEntity;
27
import in.shop2020.metamodel.util.ExpandedEntity;
27
import in.shop2020.metamodel.util.ExpandedFeature;
28
import in.shop2020.metamodel.util.ExpandedFeature;
28
import in.shop2020.metamodel.util.ExpandedFeatureDefinition;
29
import in.shop2020.metamodel.util.ExpandedFeatureDefinition;
Line 38... Line 39...
38
import java.util.Arrays;
39
import java.util.Arrays;
39
import java.util.Collection;
40
import java.util.Collection;
40
import java.util.HashMap;
41
import java.util.HashMap;
41
import java.util.List;
42
import java.util.List;
42
import java.util.Map;
43
import java.util.Map;
-
 
44
import java.util.Set;
43
import java.util.StringTokenizer;
45
import java.util.StringTokenizer;
44
 
46
 
45
import org.apache.commons.lang.StringUtils;
47
import org.apache.commons.lang.StringUtils;
46
import org.apache.juli.logging.Log;
48
import org.apache.juli.logging.Log;
47
import org.apache.juli.logging.LogFactory;
49
import org.apache.juli.logging.LogFactory;
-
 
50
import org.apache.struts2.convention.annotation.InterceptorRef;
-
 
51
import org.apache.struts2.convention.annotation.InterceptorRefs;
48
import org.apache.struts2.convention.annotation.Result;
52
import org.apache.struts2.convention.annotation.Result;
49
import org.apache.struts2.convention.annotation.Results;
53
import org.apache.struts2.convention.annotation.Results;
50
import org.apache.struts2.interceptor.ParameterAware;
-
 
-
 
54
 
51
import org.apache.struts2.rest.DefaultHttpHeaders;
55
import org.apache.struts2.rest.DefaultHttpHeaders;
52
import org.apache.struts2.rest.HttpHeaders;
56
import org.apache.struts2.rest.HttpHeaders;
53
 
57
 
-
 
58
 
-
 
59
@InterceptorRefs({
54
import com.opensymphony.xwork2.ValidationAwareSupport;
60
    @InterceptorRef("myDefault"),
-
 
61
    @InterceptorRef("login")
-
 
62
})
55
 
63
 
56
@Results({
64
@Results({
57
    @Result(name="success", type="redirectAction", 
65
    @Result(name="success", type="redirectAction", 
58
    		params = {"actionName" , "entity"}),
66
    		params = {"actionName" , "entity"}),
59
    @Result(name="redirect", location="${url}", type="redirect")
67
    @Result(name="redirect", location="${url}", type="redirect")
60
})
68
})
61
 
69
 
62
public class EntityController extends ValidationAwareSupport 
70
public class EntityController extends BaseController {
63
	implements ParameterAware {
-
 
64
	
71
	
65
	/**
72
	/**
66
	 * 
73
	 * 
67
	 */
74
	 */
68
	private static final long serialVersionUID = 1L;
75
	private static final long serialVersionUID = 1L;
Line 77... Line 84...
77
	 */
84
	 */
78
	private String id;
85
	private String id;
79
	
86
	
80
	private ExpandedEntity expEntity;
87
	private ExpandedEntity expEntity;
81
	
88
	
82
	private Entity entity;
89
	private Entity entity = null;
83
	
90
	
84
	private Collection<Entity> entities;
91
	private Collection<Entity> entities;
85
 
92
 
86
	private Map<String, String[]> reqparams;
93
	private Map<Long, EntityState> entitiesState;
87
	
94
	
88
	private EntityContainer ents;
95
	private EntityContainer ents = Catalog.getInstance().getEntityContainer();
89
	
96
	
90
	private DefinitionsContainer defs;
97
	private DefinitionsContainer defs = Catalog.getInstance().getDefinitionsContainer();
91
	
98
	
92
	private long firstSlideDefID;
99
	private long firstSlideDefID;
93
	
100
	
94
	private ExpandedSlideDefinition expSlideDef;
101
	private ExpandedSlideDefinition expSlideDef;
95
 
102
 
Line 108... Line 115...
108
	private long newPrevSlideDefinitionID;
115
	private long newPrevSlideDefinitionID;
109
 
116
 
110
	private Map<Long, List<Long>> catSlides;
117
	private Map<Long, List<Long>> catSlides;
111
	
118
	
112
	private Map<Long, List<Entity>> catEntities;
119
	private Map<Long, List<Entity>> catEntities;
113
 
120
	
114
    // GET /entity/1
121
		// GET /entity/1
115
    public String show() {
122
    public String show() {
116
    	log.info("EntityController.show");
123
    	log.info("EntityController.show");
117
    	
124
    	
118
    	try {
125
    	try {
119
    		long entityID = Long.parseLong(this.getId());
126
    		long entityID = Long.parseLong(this.getId());
120
    		log.info("entityID:" + entityID);
127
    		log.info("entityID:" + entityID);
121
    		
128
    		
-
 
129
    		if(!UserManager.getUserManager().canView(getUsername(), entityID)){
-
 
130
    			return "fatel";
-
 
131
    		}
-
 
132
    		
122
			this.expEntity = this.getExpandedEntity(entityID);
133
			this.expEntity = this.getExpandedEntity(entityID);
123
			
134
			
124
			return "show";
135
			return "show";
125
		} catch (Exception e) {
136
		} catch (Exception e) {
126
			log.error(CreationUtils.getStackTrace(e));
137
			log.error(CreationUtils.getStackTrace(e));
Line 130... Line 141...
130
    }
141
    }
131
	
142
	
132
    // GET /entity
143
    // GET /entity
133
    public HttpHeaders index() {
144
    public HttpHeaders index() {
134
    	log.info("EntityController.index");
145
    	log.info("EntityController.index");
135
    	
-
 
136
    	EntityContainer ents = new EntityContainer();
-
 
137
    	createEntitiesForItemsInProcess();
146
    	createEntitiesForItemsInProcess();
138
    	try {
147
    	try {
139
			this.entities = ents.getEntities().values();
148
			this.entities = CreationUtils.getEntities().values();
140
			this.catEntities = ents.getEntitiesbyCategory();
149
			this.entitiesState = CreationUtils.getEntitiesState();
-
 
150
			
141
		} catch (Exception e) {
151
		} catch (Exception e) {
142
			log.error(CreationUtils.getStackTrace(e));
152
			log.error(CreationUtils.getStackTrace(e));
143
			this.setErrorString(CreationUtils.getStackTrace(e));
153
			this.setErrorString(CreationUtils.getStackTrace(e));
144
			return new DefaultHttpHeaders("fatal");
154
			return new DefaultHttpHeaders("fatal");
145
		}
155
		}
Line 149... Line 159...
149
 
159
 
150
    // GET /entity
160
    // GET /entity
151
    public String create() {
161
    public String create() {
152
    	log.info("EntityController.create");
162
    	log.info("EntityController.create");
153
    	
163
    	
-
 
164
    	if(!UserManager.getUserManager().canCreate(getUsername())){
-
 
165
			return "success";
-
 
166
		}
-
 
167
    	
154
		SequenceGenerator sg;
168
		SequenceGenerator sg;
155
		try {
169
		try {
156
			sg = SequenceGenerator.getInstance();
170
			sg = SequenceGenerator.getInstance();
157
			long entityID = sg.getNextSequence(SequenceGenerator.ENTITY);
171
			long entityID = sg.getNextSequence(SequenceGenerator.ENTITY);
158
 
172
 
Line 161... Line 175...
161
 
175
 
162
			entity.setBrand(this.reqparams.get("brand")[0]);
176
			entity.setBrand(this.reqparams.get("brand")[0]);
163
			entity.setModelName(this.reqparams.get("modelname")[0]);
177
			entity.setModelName(this.reqparams.get("modelname")[0]);
164
			entity.setModelNumber(this.reqparams.get("modelnumber")[0]);
178
			entity.setModelNumber(this.reqparams.get("modelnumber")[0]);
165
			
179
			
-
 
180
			EntityState entityState = new EntityState(entityID, getUsername());
-
 
181
			
166
			this.addEntity(entity);
182
			CreationUtils.createEntity(entity, entityState);
167
			
183
			
168
	    	this.setId(new Long(entityID).toString());
184
	    	this.setId(new Long(entityID).toString());
169
		} catch (Exception e) {
185
		} catch (Exception e) {
170
			log.error(CreationUtils.getStackTrace(e));
186
			log.error(CreationUtils.getStackTrace(e));
171
			this.setErrorString(CreationUtils.getStackTrace(e));
187
			this.setErrorString(CreationUtils.getStackTrace(e));
Line 181... Line 197...
181
    public String edit() {
197
    public String edit() {
182
    	log.info("EntityController.edit");
198
    	log.info("EntityController.edit");
183
    	
199
    	
184
    	long entityID = Long.parseLong(this.getId());
200
    	long entityID = Long.parseLong(this.getId());
185
    	log.info("entityID:" + entityID);
201
    	log.info("entityID:" + entityID);
186
    	
-
 
-
 
202
    	if(!UserManager.getUserManager().canEdit(getUsername(), entityID)){
187
    	DefinitionsContainer defs = this.getDefinitionsContainer();
203
    		addActionError("You can not edit as this entity is not assigned to you");
-
 
204
			return "success";
-
 
205
		}
188
    	
206
    	
189
    	try {
207
    	try {
190
			this.expEntity = this.getExpandedEntity(entityID);
208
			this.expEntity = this.getExpandedEntity(entityID);
191
			//log.info("this.expEntity:" + this.expEntity);
209
			//log.info("this.expEntity:" + this.expEntity);
192
 
210
 
Line 195... Line 213...
195
			if(inputSlideDefIDs != null && inputSlideDefIDs.length > 0) {
213
			if(inputSlideDefIDs != null && inputSlideDefIDs.length > 0) {
196
				try {
214
				try {
197
					inputSlideDefID = Long.parseLong(inputSlideDefIDs[0]);
215
					inputSlideDefID = Long.parseLong(inputSlideDefIDs[0]);
198
				} catch (NumberFormatException nfe) {}
216
				} catch (NumberFormatException nfe) {}
199
			}
217
			}
200
			long categoryID = this.getEntity(entityID).getCategoryID();
218
			long categoryID = CreationUtils.getEntity(entityID).getCategoryID();
201
			
219
			
202
			log.info("Entity ID:" + entityID + "   CategoryID " + categoryID );
220
			log.info("Entity ID:" + entityID + "   CategoryID " + categoryID );
-
 
221
			
203
			//Changed to make correct order of borrowed slides 
222
			//Changed to make correct order of borrowed slides 
204
			List<Long> slideDefIDs = CreationUtils.getSlideSequence(entityID, categoryID);
223
			//List<Long> slideDefIDs = CreationUtils.getSlideSequence(entityID, categoryID);
-
 
224
			
-
 
225
			List<Long> slideDefIDs = expEntity.getSlideSequence();
-
 
226
			log.info("slideDefIDs:" + slideDefIDs);
-
 
227
			if(slideDefIDs == null){
-
 
228
				slideDefIDs = Catalog.getInstance().getDefinitionsContainer().getCategorySlideSequence(categoryID);
-
 
229
			}
205
			
230
			
206
			log.info("slideDefIDs:" + slideDefIDs);
231
			log.info("slideDefIDs:" + slideDefIDs);
207
			
232
			
208
			// Edit the entity from a specific slide
233
			// Edit the entity from a specific slide
209
			if(slideDefIDs != null && inputSlideDefID != 0L) {
234
			if(slideDefIDs != null && inputSlideDefID != 0L) {
Line 268... Line 293...
268
     */
293
     */
269
    // GET /entity/new
294
    // GET /entity/new
270
    public String editNew() {
295
    public String editNew() {
271
    	log.info("EntityController.editNew");
296
    	log.info("EntityController.editNew");
272
 
297
 
-
 
298
    	if(!UserManager.getUserManager().canCreate(getUsername())){
-
 
299
    		addActionError("You do not have rights to create an entity.");
-
 
300
			return "success";
-
 
301
		}
-
 
302
    	
273
        return "editNew";
303
        return "editNew";
274
    }
304
    }
275
    
305
    
276
    /**
306
    /**
277
     * 
307
     * 
Line 282... Line 312...
282
    	log.info("EntityController.update");
312
    	log.info("EntityController.update");
283
 
313
 
284
    	long entityID = Long.parseLong(this.getId());
314
    	long entityID = Long.parseLong(this.getId());
285
    	log.info("entityID:" + entityID);
315
    	log.info("entityID:" + entityID);
286
    	
316
    	
287
    	DefinitionsContainer defs = this.getDefinitionsContainer();
317
    	if(!UserManager.getUserManager().canEdit(getUsername(), entityID)){
-
 
318
			return "success";
-
 
319
		}
288
    	
320
    	
289
    	try {
321
    	try {
290
			this.expEntity = this.getExpandedEntity(entityID);
322
			this.expEntity = this.getExpandedEntity(entityID);
291
			//log.info("this.expEntity:" + this.expEntity);
323
			//log.info("this.expEntity:" + this.expEntity);
-
 
324
			log.info("p0");
292
 
325
 
293
			// Save and Go to slides selection page
326
			// Save and Go to slides selection page
294
			if (this.reqparams.containsKey("slides")) {
327
			if (this.reqparams.containsKey("slides")) {
295
				log.info("Slides");
328
				log.info("p1");
296
				
329
				
297
				Entity entity = this.expEntity.getEntity();
330
				Entity entity = this.expEntity.getEntity();
-
 
331
				log.info("p2");
298
 
332
				
299
				String categoryID = this.reqparams.get("category")[0];
333
				String categoryID = this.reqparams.get("category")[0];
300
				
334
				
301
				entity.setCategoryID(Long.parseLong(categoryID));
335
				entity.setCategoryID(Long.parseLong(categoryID));
302
				entity.setBrand(this.reqparams.get("brand")[0]);
336
				entity.setBrand(this.reqparams.get("brand")[0]);
303
				entity.setModelName(this.reqparams.get("modelname")[0]);
337
				entity.setModelName(this.reqparams.get("modelname")[0]);
304
				entity.setModelNumber(this.reqparams.get("modelnumber")[0]);
338
				entity.setModelNumber(this.reqparams.get("modelnumber")[0]);
305
				
339
				
-
 
340
				log.info("p3");
-
 
341
				CreationUtils.updateEntity(entity);
306
				this.updateEntity(entity);
342
				//this.updateEntity(entity);
307
				
343
				
308
				this.redirectURL = "/slides/" + this.getId() + "/edit";
344
				this.redirectURL = "/slides/" + this.getId() + "/edit";
309
				return "redirect";
345
				return "redirect";
310
			}
346
			}
311
			
347
			
Line 382... Line 418...
382
				entity.setCategoryID(Long.parseLong(categoryID));
418
				entity.setCategoryID(Long.parseLong(categoryID));
383
				entity.setBrand(this.reqparams.get("brand")[0]);
419
				entity.setBrand(this.reqparams.get("brand")[0]);
384
				entity.setModelName(this.reqparams.get("modelname")[0]);
420
				entity.setModelName(this.reqparams.get("modelname")[0]);
385
				entity.setModelNumber(this.reqparams.get("modelnumber")[0]);
421
				entity.setModelNumber(this.reqparams.get("modelnumber")[0]);
386
				
422
				
387
				this.updateEntity(entity);
423
				CreationUtils.updateEntity(entity);
388
				
424
				
389
				return "success";
425
				return "success";
390
			}
426
			}
391
			
427
			
392
			List<Long> slideIDs = this.getSlideSequence(entityID);
428
			List<Long> slideIDs = this.getSlideSequence(entityID);
Line 394... Line 430...
394
			if(slideIDs == null) {
430
			if(slideIDs == null) {
395
				this.setErrorString("Slides need to be picked first!");
431
				this.setErrorString("Slides need to be picked first!");
396
				return "fatal";
432
				return "fatal";
397
			}
433
			}
398
			
434
			
-
 
435
			log.info("p4");
-
 
436
			
399
			boolean skip = false;
437
			boolean skip = false;
400
			if(this.reqparams.containsKey("skipprev") || 
438
			if(this.reqparams.containsKey("skipprev") || 
401
					this.reqparams.containsKey("skipnext")) {
439
					this.reqparams.containsKey("skipnext")) {
402
				skip = true;
440
				skip = true;
403
			}
441
			}
Line 413... Line 451...
413
			// Save or Next or Prev or Go - When editing a slide
451
			// Save or Next or Prev or Go - When editing a slide
414
			int currentSlideIndex = 0;
452
			int currentSlideIndex = 0;
415
			currentSlideIndex = slideIDs.indexOf(new Long(currentSlideDefID));
453
			currentSlideIndex = slideIDs.indexOf(new Long(currentSlideDefID));
416
			log.info("currentSlideIndex:" + currentSlideIndex);
454
			log.info("currentSlideIndex:" + currentSlideIndex);
417
 
455
 
-
 
456
			log.info("p5");
418
			if(!skip && currentSlideDefID != 0L) {
457
			if(!skip && currentSlideDefID != 0L) {
419
				Entity entity = this.expEntity.getEntity();
458
				Entity entity = this.expEntity.getEntity();
420
				
459
				
-
 
460
				log.info("p6");
421
				// Create new instance and override existing
461
				// Create new instance and override existing
422
				Slide currentSlide = this.createSlide(currentSlideDefID);
462
				Slide currentSlide = this.createSlide(currentSlideDefID);
423
				
463
				
424
				entity.addSlide(currentSlide);
464
				entity.addSlide(currentSlide);
425
				long categoryID = this.getEntity().getCategoryID();
465
				long categoryID = this.getEntity().getCategoryID();
426
				List<Long> orderedSlideIDs = 
466
				//List<Long> orderedSlideIDs = CreationUtils.getSlideSequence(entityID, categoryID);
-
 
467
				
427
					CreationUtils.getSlideSequence(entityID, categoryID);
468
				List<Long> orderedSlideIDs = entity.getSlideSequence();
428
				
469
				
429
				if(orderedSlideIDs != null) {
470
				if(orderedSlideIDs != null) {
430
					entity.reorderSlides(orderedSlideIDs);
471
					//entity.reorderSlides(orderedSlideIDs);
431
				}
472
				}
432
				
473
				log.info("p7");
433
				// Store
474
				// Store
434
				this.updateEntity(entity);
475
				CreationUtils.updateEntity(entity);
435
				//log.info("entity:" + entity);
476
				//log.info("entity:" + entity);
436
			}
477
			}
437
			
478
			
438
			// Skip will delete current slide from entity
479
			// Skip will delete current slide from entity
439
			else if(skip && currentSlideDefID != 0L) {
480
			else if(skip && currentSlideDefID != 0L) {
440
				Entity entity = this.expEntity.getEntity();
481
				Entity entity = this.expEntity.getEntity();
441
				entity.removeSlide(currentSlideDefID);
482
				entity.removeSlide(currentSlideDefID);
442
				long categoryID = this.getEntity().getCategoryID();
483
				long categoryID = this.getEntity().getCategoryID();
443
				List<Long> orderedSlideIDs = 
-
 
444
					CreationUtils.getSlideSequence(entityID, categoryID);
484
				//List<Long> orderedSlideIDs = CreationUtils.getSlideSequence(entityID, categoryID);
445
				
485
				
-
 
486
				log.info("p8");
-
 
487
				
-
 
488
				List<Long> orderedSlideIDs = entity.getSlideSequence();
446
				if(orderedSlideIDs != null) {
489
				if(orderedSlideIDs != null) {
447
					entity.reorderSlides(orderedSlideIDs);
490
					//entity.reorderSlides(orderedSlideIDs);
448
				}
491
				}
449
				
492
				
450
				// Store
493
				// Store
451
				this.updateEntity(entity);
494
				CreationUtils.updateEntity(entity);
452
				//log.info("entity:" + entity);
495
				//log.info("entity:" + entity);
-
 
496
				
-
 
497
				log.info("p9");
453
			}
498
			}
454
			
499
			
455
			boolean showAnotherSlide = false;
500
			boolean showAnotherSlide = false;
456
			
501
			
457
			// -2 : Not set
502
			// -2 : Not set
Line 461... Line 506...
461
			int newPrevIndex = -2;
506
			int newPrevIndex = -2;
462
				
507
				
463
			// Next
508
			// Next
464
			if(next && nextSlideDefID != 0L) {
509
			if(next && nextSlideDefID != 0L) {
465
				log.info("Next");
510
				log.info("Next");
466
				
511
				log.info("p10");
467
				// Decide on next slide ID
512
				// Decide on next slide ID
468
				int nextSlideIndex = slideIDs.indexOf(new Long(nextSlideDefID));
513
				int nextSlideIndex = slideIDs.indexOf(new Long(nextSlideDefID));
469
				log.info("nextSlideIndex:"+nextSlideIndex);
514
				log.info("nextSlideIndex:"+nextSlideIndex);
470
				
515
				
471
				// New Current
516
				// New Current
Line 491... Line 536...
491
			}
536
			}
492
			
537
			
493
			// Prev
538
			// Prev
494
			if(prev && prevSlideDefID != 0L) {
539
			if(prev && prevSlideDefID != 0L) {
495
				log.info("Prev");
540
				log.info("Prev");
496
				
541
				log.info("p11");
497
				// Decide on prev slide ID
542
				// Decide on prev slide ID
498
				int prevSlideIndex = slideIDs.indexOf(new Long(prevSlideDefID));
543
				int prevSlideIndex = slideIDs.indexOf(new Long(prevSlideDefID));
499
				log.info("prevSlideIndex:" + prevSlideIndex);
544
				log.info("prevSlideIndex:" + prevSlideIndex);
500
				
545
				
501
				if (prevSlideIndex == -1) {
546
				if (prevSlideIndex == -1) {
Line 521... Line 566...
521
			}
566
			}
522
			
567
			
523
			// Go to
568
			// Go to
524
			if(go && gotoSlideDefID != 0) {
569
			if(go && gotoSlideDefID != 0) {
525
				log.info("Goto");
570
				log.info("Goto");
-
 
571
				log.info("p12");
526
				int gotoSlideIndex = slideIDs.indexOf(new Long(gotoSlideDefID));
572
				int gotoSlideIndex = slideIDs.indexOf(new Long(gotoSlideDefID));
527
				log.info("gotoSlideIndex:" + gotoSlideIndex);
573
				log.info("gotoSlideIndex:" + gotoSlideIndex);
528
				
574
				
529
				if (gotoSlideIndex == -1) {
575
				if (gotoSlideIndex == -1) {
530
					this.setErrorString("Invalid Go to slide ID " + 
576
					this.setErrorString("Invalid Go to slide ID " + 
Line 551... Line 597...
551
			if(showAnotherSlide) {
597
			if(showAnotherSlide) {
552
 				log.info("newCurrentIndex:" + newCurrentIndex);
598
 				log.info("newCurrentIndex:" + newCurrentIndex);
553
				log.info("newNextIndex:" + newNextIndex);
599
				log.info("newNextIndex:" + newNextIndex);
554
				log.info("newPrevIndex:" + newPrevIndex);
600
				log.info("newPrevIndex:" + newPrevIndex);
555
 
601
 
-
 
602
				log.info("p13");
-
 
603
				
556
				if(newCurrentIndex != -2) {
604
				if(newCurrentIndex != -2) {
557
					this.setNewCurrentSlideDefinitionID(
605
					this.setNewCurrentSlideDefinitionID(
558
							slideIDs.get(newCurrentIndex).longValue());
606
							slideIDs.get(newCurrentIndex).longValue());
559
				}
607
				}
560
				
608
				
Line 600... Line 648...
600
     * @return
648
     * @return
601
     * @throws Exception 
649
     * @throws Exception 
602
     */
650
     */
603
    public long getBorrowedCategoryID(long slideDefID) throws Exception {
651
    public long getBorrowedCategoryID(long slideDefID) throws Exception {
604
    	long entityID = Long.parseLong(this.getId());
652
    	long entityID = Long.parseLong(this.getId());
605
    	Entity entity = this.getEntity(entityID);
653
    	entity = CreationUtils.getEntity(entityID);
606
    	Long entityCatID = new Long(entity.getCategoryID());
654
    	Long entityCatID = new Long(entity.getCategoryID());
607
    	
655
    	
608
    	Map<Long, List<Long>> catSlides = this.getRawSlideSequence(entityID);
656
    	Map<Long, List<Long>> catSlides = this.getRawSlideSequence(entityID);
609
    	
657
    	
610
    	Long lSlideDefID = new Long(slideDefID);
658
    	Long lSlideDefID = new Long(slideDefID);
Line 626... Line 674...
626
     * @param entityID
674
     * @param entityID
627
     * @return
675
     * @return
628
     * @throws Exception 
676
     * @throws Exception 
629
     */
677
     */
630
    private List<Long> getSlideSequence(long entityID) throws Exception {
678
    private List<Long> getSlideSequence(long entityID) throws Exception {
631
    	this.catSlides = this.getRawSlideSequence(entityID);
679
    	//this.catSlides = this.getRawSlideSequence(entityID);
632
    	return CreationUtils.getSlideSequence(this.catSlides);
680
    	//return CreationUtils.getSlideSequence(this.catSlides);
-
 
681
    	return entity.getSlideSequence();
633
	}
682
	}
634
    
683
    
635
    /**
684
    /**
636
     * 
685
     * 
637
     * @param entityID
686
     * @param entityID
Line 639... Line 688...
639
     * @throws Exception
688
     * @throws Exception
640
     */
689
     */
641
	private Map<Long, List<Long>> getRawSlideSequence(long entityID) 
690
	private Map<Long, List<Long>> getRawSlideSequence(long entityID) 
642
		throws Exception {
691
		throws Exception {
643
		if(this.catSlides == null) {
692
		if(this.catSlides == null) {
644
			this.catSlides = CreationUtils.getRawSlideSequence(entityID);
693
			this.catSlides = defs.getCategorySlideSequence();
645
		}
694
		}
646
		
695
		
647
		return this.catSlides;
696
		return this.catSlides;
648
	}
697
	}
649
 
698
 
Line 678... Line 727...
678
		log.info("features:" + features);
727
		log.info("features:" + features);
679
		
728
		
680
		slide.setFeatures(features);
729
		slide.setFeatures(features);
681
		
730
		
682
		// Collect children slides
731
		// Collect children slides
683
		SlideDefinition slideDef = 
-
 
684
			this.getDefinitionsContainer().getSlideDefinition(slideDefID);
732
		SlideDefinition slideDef = this.defs.getSlideDefinition(slideDefID);
685
 
733
 
686
		List<Long> childrenSlideIDs = slideDef.getChildrenSlideDefinitionIDs();
734
		List<Long> childrenSlideIDs = slideDef.getChildrenSlideDefinitionIDs();
687
		if(childrenSlideIDs != null) {
735
		if(childrenSlideIDs != null) {
688
			List<Slide> childrenSlides = new ArrayList<Slide>();
736
			List<Slide> childrenSlides = new ArrayList<Slide>();
689
			for (Long childSlideID : childrenSlideIDs) {
737
			for (Long childSlideID : childrenSlideIDs) {
Line 711... Line 759...
711
		SlideDefinition slideDef = defs.getSlideDefinition(slideDefID);
759
		SlideDefinition slideDef = defs.getSlideDefinition(slideDefID);
712
		
760
		
713
		List<SlideFeatureDefinition> slideFeatureDefs = 
761
		List<SlideFeatureDefinition> slideFeatureDefs = 
714
			slideDef.getSlideFeatureDefinitions();
762
			slideDef.getSlideFeatureDefinitions();
715
		
763
		
716
		DefinitionsContainer defs = this.getDefinitionsContainer();
-
 
717
		
-
 
718
		List<Feature> features = new ArrayList<Feature>();	
764
		List<Feature> features = new ArrayList<Feature>();	
719
		for(SlideFeatureDefinition slideFeatureDef : slideFeatureDefs) {
765
		for(SlideFeatureDefinition slideFeatureDef : slideFeatureDefs) {
720
			long featureDefinitionID = slideFeatureDef.getFeatureDefintionID();
766
			long featureDefinitionID = slideFeatureDef.getFeatureDefintionID();
721
			log.info("featureDefinitionID:" + featureDefinitionID);
767
			log.info("featureDefinitionID:" + featureDefinitionID);
722
			
768
			
Line 901... Line 947...
901
    	log.info("#### EntityController.destroy ####");
947
    	log.info("#### EntityController.destroy ####");
902
    	
948
    	
903
    	long entityID = Long.parseLong(this.getId());
949
    	long entityID = Long.parseLong(this.getId());
904
    	log.info("entityID:" + entityID);
950
    	log.info("entityID:" + entityID);
905
	
951
	
-
 
952
    	if(!UserManager.getUserManager().canDelete(getUsername(), entityID)){
-
 
953
    		addActionError("You do not have rights to delete an entity");
-
 
954
    		return "success";
-
 
955
		}
-
 
956
    	
906
		// Store
957
		// Store
907
		try {
958
		try {
908
	    	Entity entity = this.getEntity(entityID);
-
 
909
	    	EntityContainer ents = this.getEntityContainer();
-
 
910
	    	
-
 
911
	    	Map<Long, Entity> entities = ents.getEntities();
-
 
912
	    	Map<Long, List<Entity>> entitiesbycat = 
-
 
913
	    		ents.getEntitiesbyCategory();
-
 
914
	    	
-
 
915
	    	entities.remove(new Long(entityID));
-
 
916
	    	
-
 
917
	    	List<Entity> catentities = 
-
 
918
	    		entitiesbycat.get(new Long(entity.getCategoryID()));
-
 
919
	    	
-
 
920
	    	Entity entitytodelete = null;
-
 
921
	    	for(Entity catentity : catentities) {
-
 
922
	    		if(catentity.getID() == entityID) {
-
 
923
	    			entitytodelete = catentity;
-
 
924
	    			break;
-
 
925
	    		}
-
 
926
	    	}
-
 
927
	    	
-
 
928
	    	if(entitytodelete != null) {
-
 
929
	    		catentities.remove(entitytodelete);
-
 
930
	    	}
-
 
931
	    	
-
 
932
	    	CreationUtils.deleteFromIncomplete(entity);
-
 
933
	    	
-
 
934
	    	CreationUtils.deleteEntity(entityID);
959
	    	CreationUtils.deleteEntity(entityID);
935
	    	
-
 
936
	    	CreationUtils.rewriteRepository(entities, entitiesbycat);
-
 
937
			// Added automatic learning once someone rewrites repository
-
 
938
			CN cn = new CN();
-
 
939
			cn.learn();
-
 
940
		} catch (Exception e) {
960
		} catch (Exception e) {
941
			log.error(CreationUtils.getStackTrace(e));
961
			log.error(CreationUtils.getStackTrace(e));
942
			this.setErrorString(CreationUtils.getStackTrace(e));
962
			this.setErrorString(CreationUtils.getStackTrace(e));
943
			return "fatal";
963
			return "fatal";
944
		}
964
		}
945
		
-
 
946
        addActionMessage("Entity deleted successfully");
965
        addActionMessage("Entity deleted successfully");
947
        return "success";
966
        return "success";
948
    }
967
    }
949
	/**
968
	/**
950
     * 
969
     * 
Line 967... Line 986...
967
    		long slideId = Long.parseLong(tokenizer.nextToken());
986
    		long slideId = Long.parseLong(tokenizer.nextToken());
968
    		FreeformContent old_ffc = null;
987
    		FreeformContent old_ffc = null;
969
    		if(this.entity.getSlide(slideId) != null){
988
    		if(this.entity.getSlide(slideId) != null){
970
    			old_ffc = this.entity.getSlide(slideId).getFreeformContent();
989
    			old_ffc = this.entity.getSlide(slideId).getFreeformContent();
971
    			if(old_ffc != null){
990
    			if(old_ffc != null){
972
    				ffc.setMedia("image", old_ffc.getImageRefs());
-
 
973
    				ffc.setMedia("youtube", old_ffc.getYoutubeRefs());    			
991
    				ffc.setMedias(old_ffc.getMedias());    			
974
    			}
992
    			}
975
    		}
993
    		}
976
    	}
994
    	}
977
		
995
		
978
		
996
		
Line 1051... Line 1069...
1051
	 */
1069
	 */
1052
	public Map<Long, List<Entity>> getEntitiesByCategory() {
1070
	public Map<Long, List<Entity>> getEntitiesByCategory() {
1053
		return catEntities;
1071
		return catEntities;
1054
	}
1072
	}
1055
 
1073
 
1056
	/**
1074
		/**
1057
	 * 
-
 
1058
	 * @return
-
 
1059
	 */
-
 
1060
	public List<Entity> getIncompleteEntities() {
-
 
1061
		try {
-
 
1062
			return CreationUtils.getIncomplete();
-
 
1063
		} catch (Exception e) {
-
 
1064
			log.error(CreationUtils.getStackTrace(e));
-
 
1065
			this.setErrorString(CreationUtils.getStackTrace(e));
-
 
1066
			return null;
-
 
1067
		}
-
 
1068
	}
-
 
1069
 
-
 
1070
	/**
-
 
1071
	 * Inquires about items in the IN_PROCESS state with the Catalog service and
1075
	 * Inquires about items in the IN_PROCESS state with the Catalog service and
1072
	 * creates those entities which do not exist in the CMS already.
1076
	 * creates those entities which do not exist in the CMS already.
1073
	 * 
1077
	 * 
1074
	 * @return A List of entities fetched from the catalog.
1078
	 * @return A List of entities fetched from the catalog.
1075
	 */
1079
	 */
Line 1084... Line 1088...
1084
					log.info("#### Going to add the entity with id: ####" + entityID);
1088
					log.info("#### Going to add the entity with id: ####" + entityID);
1085
					Entity entity = new Entity(entityID, -1);
1089
					Entity entity = new Entity(entityID, -1);
1086
					entity.setBrand(item.getBrand());
1090
					entity.setBrand(item.getBrand());
1087
					entity.setModelNumber(item.getModelNumber() + " (" + item.getProductGroup() + ")");
1091
					entity.setModelNumber(item.getModelNumber() + " (" + item.getProductGroup() + ")");
1088
					entity.setModelName((item.getModelName()==null) ? "" : item.getModelName());
1092
					entity.setModelName((item.getModelName()==null) ? "" : item.getModelName());
-
 
1093
					EntityState entityState = new EntityState(entityID, UserManager.getUserManager().getAdminName());
1089
					addEntity(entity);
1094
					CreationUtils.createEntity(entity, entityState);
1090
				}else
1095
				}else
1091
					log.info("###Everything went all right and we got an entity");
1096
					log.info("###Everything went all right and we got an entity");
1092
			}
1097
			}
1093
		} catch (Exception e) {
1098
		} catch (Exception e) {
1094
			e.printStackTrace();
1099
			e.printStackTrace();
Line 1113... Line 1118...
1113
	 * 
1118
	 * 
1114
	 * @param slideDefID
1119
	 * @param slideDefID
1115
	 * @return
1120
	 * @return
1116
	 */
1121
	 */
1117
	public ExpandedSlideDefinition getExpandedSlideDefinition(long slideDefID) {
1122
	public ExpandedSlideDefinition getExpandedSlideDefinition(long slideDefID) {
1118
		DefinitionsContainer defs = this.getDefinitionsContainer();
-
 
1119
		
-
 
1120
		try {
1123
		try {
1121
			return defs.getExpandedSlideDefinition(slideDefID);
1124
			return defs.getExpandedSlideDefinition(slideDefID);
1122
		} catch (Exception e) {
1125
		} catch (Exception e) {
1123
			return null;
1126
			return null;
1124
		}
1127
		}
Line 1144... Line 1147...
1144
	 */
1147
	 */
1145
	public long getFirstSlideDefID() {
1148
	public long getFirstSlideDefID() {
1146
		return firstSlideDefID;
1149
		return firstSlideDefID;
1147
	}
1150
	}
1148
 
1151
 
1149
	@Override
-
 
1150
	public void setParameters(Map<String, String[]> reqmap) {
-
 
1151
		log.info("setParameters:" + reqmap);
-
 
1152
		
-
 
1153
		this.reqparams = reqmap;
-
 
1154
	}
-
 
1155
 
-
 
1156
	public String getCategoriesTree()  throws Exception {
1152
	public String getCategoriesTree()  throws Exception {
1157
		DefinitionsContainer defs = this.getDefinitionsContainer();
-
 
1158
		Map<String, String> cats = new HashMap<String, String>();
1153
		Map<String, String> cats = new HashMap<String, String>();
1159
		
1154
		
1160
		List<Category> children = defs.getChildrenCategories(10000L);
1155
		List<Category> children = defs.getChildrenCategories(Catalog.getInstance().getRootCategory().getID());
1161
		
-
 
1162
		for(Category child : children) {
1156
		for(Category child : children) {
1163
			cats.put(new Long(child.getID()).toString(), child.getLabel());
1157
			cats.put(new Long(child.getID()).toString(), child.getLabel());
1164
		}
1158
		}
1165
		return "";
1159
		return "";
1166
	}
1160
	}
1167
	
1161
	
1168
	public Map<String, String> getCategories() throws Exception {
1162
	public Map<String, String> getCategories() throws Exception {
1169
		DefinitionsContainer defs = this.getDefinitionsContainer();
-
 
1170
		Map<String, String> cats = new HashMap<String, String>();
1163
		Map<String, String> cats = new HashMap<String, String>();
1171
 
1164
 
1172
		List<Category> children = defs.getChildrenCategories(10000L);
1165
		List<Category> children = defs.getChildrenCategories(Catalog.getInstance().getRootCategory().getID());
1173
		for(Category child : children) {
1166
		for(Category child : children) {
1174
			cats.put(new Long(child.getID()).toString(), child.getLabel());
1167
			cats.put(new Long(child.getID()).toString(), child.getLabel());
1175
		}
1168
		}
1176
		
1169
		
1177
		return cats;
1170
		return cats;
1178
	}
1171
	}
1179
 
1172
 
1180
	public Map<String, String> getSubcategories() throws Exception {
1173
	public Map<String, String> getSubcategories() throws Exception {
1181
		DefinitionsContainer defs = this.getDefinitionsContainer();
-
 
1182
		Map<String, String> cats = new HashMap<String, String>();
1174
		Map<String, String> cats = new HashMap<String, String>();
1183
 
1175
 
1184
		List<Category> children = defs.getChildrenCategories(10000L);
1176
		List<Category> children = defs.getChildrenCategories(Catalog.getInstance().getRootCategory().getID());
1185
		for(Category child : children) {
1177
		for(Category child : children) {
1186
			List<Category> grandChildren = defs.getChildrenCategories(child.getID());
1178
			List<Category> grandChildren = defs.getChildrenCategories(child.getID());
1187
			for(Category grandchild : grandChildren) {
1179
			for(Category grandchild : grandChildren) {
1188
				cats.put(new Long(grandchild.getID()).toString(), grandchild.getLabel());
1180
				cats.put(new Long(grandchild.getID()).toString(), grandchild.getLabel());
1189
			}
1181
			}
1190
		}
1182
		}
1191
		
1183
		
1192
		return cats;
1184
		return cats;
1193
	}
1185
	}
1194
	public String getCategoriesString() throws Exception {
1186
	public String getCategoriesString() throws Exception {
1195
		DefinitionsContainer defs = this.getDefinitionsContainer();
-
 
1196
		StringBuilder categoryString = new StringBuilder();
1187
		StringBuilder categoryString = new StringBuilder();
1197
		
1188
		
1198
		categoryString.append("<label for=\"basecategory\">Category: </label>");
1189
		categoryString.append("<label for=\"basecategory\">Category: </label>");
1199
		categoryString.append("\n");
1190
		categoryString.append("\n");
1200
		categoryString.append("<select id=\"basecategory\"  name=\"basecategory\" >"); 
1191
		categoryString.append("<select id=\"basecategory\"  name=\"basecategory\" >"); 
1201
		categoryString.append("\n");
1192
		categoryString.append("\n");
1202
		List<Category> children = defs.getChildrenCategories(10000L);
1193
		List<Category> children = defs.getChildrenCategories(Catalog.getInstance().getRootCategory().getID());
1203
		for(Category child : children) {
1194
		for(Category child : children) {
1204
			categoryString.append("<option value=\"" + new Long(child.getID()).toString() + "\">" + child.getLabel() + "</option>");
1195
			categoryString.append("<option value=\"" + new Long(child.getID()).toString() + "\">" + child.getLabel() + "</option>");
1205
			categoryString.append("\n");
1196
			categoryString.append("\n");
1206
		}
1197
		}
1207
		categoryString.append("</select>");
1198
		categoryString.append("</select>");
Line 1243... Line 1234...
1243
	 * 
1234
	 * 
1244
	 * @return
1235
	 * @return
1245
	 * @throws Exception
1236
	 * @throws Exception
1246
	 */
1237
	 */
1247
	public List<String> getBrands() throws Exception {
1238
	public List<String> getBrands() throws Exception {
1248
		EntityContainer ents = this.getEntityContainer();
-
 
-
 
1239
		
1249
		List<String> brands = new ArrayList<String>();
1240
		List<String> brands = new ArrayList<String>();
1250
		
1241
		
1251
		List<ExpandedBullet> expBullets;
1242
		List<ExpandedBullet> expBullets;
1252
 
1243
 
1253
		expBullets = ents.getLearnedBullets(
1244
		expBullets = CreationUtils.getLearnedBullets(Utils.BRAND_FEATURE_DEFINITION_ID);
1254
				Utils.BRAND_FEATURE_DEFINITION_ID);
1245
		if(expBullets!=null){
1255
		
-
 
1256
		for(ExpandedBullet expBullet : expBullets) {
1246
			for(ExpandedBullet expBullet : expBullets) {
1257
			brands.add(expBullet.getValue());
1247
				brands.add(expBullet.getValue());
-
 
1248
			}
1258
		}
1249
		}
1259
 
-
 
1260
		return brands;
1250
		return brands;
1261
	}
1251
	}
1262
 
1252
 
1263
	/**
-
 
1264
	 * 
-
 
1265
	 * @return
-
 
1266
	 */
-
 
1267
    protected EntityContainer getEntityContainer() {
-
 
1268
    	if(this.ents == null) {
-
 
1269
    		this.ents = Catalog.getInstance().getEntityContainer();
-
 
1270
    	}
-
 
1271
    	
-
 
1272
	    return this.ents;
-
 
1273
    }
-
 
1274
    
-
 
1275
    /**
-
 
1276
     * 
-
 
1277
     * @return
-
 
1278
     */
-
 
1279
    protected DefinitionsContainer getDefinitionsContainer() {
-
 
1280
    	if(this.defs == null) {
-
 
1281
    		this.defs = Catalog.getInstance().getDefinitionsContainer();
-
 
1282
    	}
-
 
1283
    	
-
 
1284
	    return this.defs;
-
 
1285
    }
-
 
1286
 
-
 
1287
    /**
-
 
1288
     * 
-
 
1289
     * @param entity
-
 
1290
     * @throws Exception
-
 
1291
     */
-
 
1292
	private void addEntity(Entity entity) throws Exception {
-
 
1293
		log.info("#### EntityController.addEntity ####");
-
 
1294
		EntityContainer entContainer = this.getEntityContainer();
-
 
1295
 
-
 
1296
		entContainer.addEntity(entity);
-
 
1297
		
-
 
1298
		CreationUtils.storeEntity(entity);
-
 
1299
		
-
 
1300
		ContentValidator validator = new ContentValidator();
-
 
1301
		if(!validator.validate(entity)) {
-
 
1302
			CreationUtils.addToIncomplete(entity);
-
 
1303
		}
-
 
1304
		// Add to repository only if validations succeed
-
 
1305
		else {
-
 
1306
			CreationUtils.deleteFromIncomplete(entity);
-
 
1307
			
-
 
1308
			this.updateRepository();
-
 
1309
			// Added automatic learning once someone rewrites repository
-
 
1310
			CN cn = new CN();
-
 
1311
			cn.learn();
-
 
1312
		}
-
 
1313
	}
-
 
1314
 
-
 
1315
    /**
-
 
1316
     * 
-
 
1317
     * @param entity
-
 
1318
     * @throws Exception
-
 
1319
     */
-
 
1320
	private void updateEntity(Entity entity) throws Exception {		
-
 
1321
		log.info("#### EntityController.updateEntity ####");
-
 
1322
		EntityContainer entContainer = this.getEntityContainer();
-
 
1323
		
-
 
1324
		ContentValidator validator = new ContentValidator();
-
 
1325
		if(!validator.validate(entity)) {
-
 
1326
			CreationUtils.addToIncomplete(entity);
-
 
1327
			
-
 
1328
			// Delete from repository if incomplete
-
 
1329
			entContainer.deleteEntity(entity);
-
 
1330
		}
-
 
1331
		else {
-
 
1332
			CreationUtils.deleteFromIncomplete(entity);
-
 
1333
			
-
 
1334
			entContainer.updateEntity(entity);
-
 
1335
			
-
 
1336
 
-
 
1337
		}
-
 
1338
		
-
 
1339
		CreationUtils.storeEntity(entity);
-
 
1340
		
-
 
1341
		this.updateRepository();
-
 
1342
		
-
 
1343
		if(validator.validate(entity)) {
-
 
1344
			// Added automatic learning once someone rewrites repository
-
 
1345
			CN cn = new CN();
-
 
1346
			cn.learn();
-
 
1347
		}
-
 
1348
	}
-
 
1349
 
1253
 
1350
	
-
 
1351
	
-
 
1352
	/**
-
 
1353
	 * 
-
 
1354
	 * @throws Exception
-
 
1355
	 */
-
 
1356
	private void updateRepository() throws Exception {	
-
 
1357
		EntityContainer entContainer = this.getEntityContainer();
-
 
1358
		
-
 
1359
		Map<Long, Entity> entities = entContainer.getEntities();
-
 
1360
		log.info("entities.size():" + entities.size());
-
 
1361
		
-
 
1362
		Map<Long, List<Entity>> entitiesByCategory = 
-
 
1363
			entContainer.getEntitiesbyCategory();
-
 
1364
		log.info("entitiesByCategory.size():" + entitiesByCategory.size());
-
 
1365
		
-
 
1366
		CreationUtils.rewriteRepository(entities, entitiesByCategory);
-
 
1367
	}
-
 
1368
	
-
 
1369
	/**
1254
	/**
1370
	 * @param exception the exception to set
1255
	 * @param exception the exception to set
1371
	 */
1256
	 */
1372
	public void setException(Exception exception) {
1257
	public void setException(Exception exception) {
1373
		this.exception = exception;
1258
		this.exception = exception;
Line 1407... Line 1292...
1407
	 */
1292
	 */
1408
	public long getNewCurrentSlideDefinitionID() {
1293
	public long getNewCurrentSlideDefinitionID() {
1409
		return newCurrentSlideDefinitionID;
1294
		return newCurrentSlideDefinitionID;
1410
	}
1295
	}
1411
 
1296
 
-
 
1297
	
1412
	/**
1298
	/**
1413
	 * @param newNextSlideID the newNextSlideID to set
1299
	 * @param newNextSlideID the newNextSlideID to set
1414
	 */
1300
	 */
1415
	public void setNewNextSlideDefinitionID(long newNextSlideDefinitionID) {
1301
	public void setNewNextSlideDefinitionID(long newNextSlideDefinitionID) {
1416
		this.newNextSlideDefinitionID = newNextSlideDefinitionID;
1302
		this.newNextSlideDefinitionID = newNextSlideDefinitionID;
Line 1473... Line 1359...
1473
	 * @return
1359
	 * @return
1474
	 * @throws Exception
1360
	 * @throws Exception
1475
	 */
1361
	 */
1476
	public List<String> getLearnedValues(long featureDefinitionID) 
1362
	public List<String> getLearnedValues(long featureDefinitionID) 
1477
			throws Exception {
1363
			throws Exception {
1478
		EntityContainer ents = this.getEntityContainer();
-
 
1479
		List<ExpandedBullet> learnedBullets = 
-
 
1480
			ents.getLearnedBullets(featureDefinitionID);
1364
		List<ExpandedBullet> learnedBullets = CreationUtils.getLearnedBullets(featureDefinitionID);
1481
		
1365
		
1482
		if(learnedBullets == null) {
1366
		if(learnedBullets == null) {
1483
			return null;
1367
			return null;
1484
		}
1368
		}
1485
		
1369
		
Line 1497... Line 1381...
1497
	 * @return
1381
	 * @return
1498
	 * @throws Exception
1382
	 * @throws Exception
1499
	 */
1383
	 */
1500
	public ExpandedFeature getFeature(long featureDefinitionID) 
1384
	public ExpandedFeature getFeature(long featureDefinitionID) 
1501
		throws Exception {
1385
		throws Exception {
1502
		EntityContainer ents = this.getEntityContainer();
-
 
1503
		
-
 
1504
		if(this.expSlide != null) {
1386
		if(this.expSlide != null) {
1505
			Feature feature = ents.getFeature(
1387
			Feature feature = ents.getFeature(
1506
					this.expSlide, featureDefinitionID);
1388
					this.expSlide, featureDefinitionID);
1507
			
1389
			
1508
			if(feature == null) {
1390
			if(feature == null) {
Line 1540... Line 1422...
1540
		
1422
		
1541
		return "";
1423
		return "";
1542
		*/
1424
		*/
1543
	}
1425
	}
1544
	
1426
	
1545
	/**
-
 
1546
	 * 
-
 
1547
	 * @return
-
 
1548
	 * @throws Exception 
-
 
1549
	 * @throws NumberFormatException 
-
 
1550
	 */
-
 
1551
	public List<String> getMediaLabels(String type) {
-
 
1552
		try {
-
 
1553
			return CreationUtils.getMediaLabels(Long.parseLong(this.getId()), 
-
 
1554
					type);
-
 
1555
		}
-
 
1556
		catch(Exception nfe) {
-
 
1557
			return null;
-
 
1558
		}
-
 
1559
	}
1427
 
1560
 
1428
 
1561
	/**
1429
	/**
1562
	 * 
1430
	 * 
1563
	 * @return
1431
	 * @return
1564
	 */
1432
	 */
1565
	public String getCategoryName(long categoryID) {
1433
	public String getCategoryName(long categoryID) {
1566
		if(categoryID==-1)
1434
		if(categoryID==-1)
1567
			return "Yet to be Asssigned";
1435
			return "Yet to be Asssigned";
1568
		try {
1436
		try {
1569
			return this.getDefinitionsContainer().getCategory(categoryID).
1437
			return this.defs.getCategory(categoryID).getLabel();
1570
				getLabel();
1438
			
1571
		} catch (Exception e) {
1439
		} catch (Exception e) {
1572
			return null;
1440
			return null;
1573
		}
1441
		}
1574
	}
1442
	}
1575
	
1443
	
Line 1579... Line 1447...
1579
	 */
1447
	 */
1580
	public List<String[]> getSlides() {
1448
	public List<String[]> getSlides() {
1581
		try {
1449
		try {
1582
			long entityID = Long.parseLong(this.getId());
1450
			long entityID = Long.parseLong(this.getId());
1583
			long categoryID = this.getEntity().getCategoryID();
1451
			long categoryID = this.getEntity().getCategoryID();
1584
			List<Long> slideDefIDs = CreationUtils.getSlideSequence(entityID, categoryID);
1452
			//List<Long> slideDefIDs = CreationUtils.getSlideSequence(entityID, categoryID);
-
 
1453
			List<Long> slideDefIDs = CreationUtils.getEntity(entityID).getSlideSequence();
1585
			
1454
			
1586
			List<String[]> slideData = new ArrayList<String[]>();
1455
			List<String[]> slideData = new ArrayList<String[]>();
1587
			
1456
	
1588
			DefinitionsContainer defs = this.getDefinitionsContainer();
-
 
1589
			for(Long slideDefID : slideDefIDs) {
1457
			for(Long slideDefID : slideDefIDs) {
1590
				SlideDefinition slideDef = defs.getSlideDefinition(slideDefID);
1458
				SlideDefinition slideDef = defs.getSlideDefinition(slideDefID);
1591
				String label = slideDef.getLabel();
1459
				String label = slideDef.getLabel();
1592
				
1460
				
1593
				slideData.add(new String[] {slideDefID.toString(), label});
1461
				slideData.add(new String[] {slideDefID.toString(), label});
Line 1608... Line 1476...
1608
     * @throws Exception 
1476
     * @throws Exception 
1609
     */
1477
     */
1610
    private ExpandedEntity getExpandedEntity(long entityID) throws Exception {
1478
    private ExpandedEntity getExpandedEntity(long entityID) throws Exception {
1611
    	if(this.expEntity == null) {
1479
    	if(this.expEntity == null) {
1612
    		if(this.entity == null) {
1480
    		if(this.entity == null) {
1613
    			this.entity = this.getEntity(entityID);
1481
    			this.entity = CreationUtils.getEntity(entityID);
1614
    		}
1482
    		}
1615
    		
-
 
1616
	    	this.expEntity = new ExpandedEntity(entity);
1483
    		this.expEntity = new ExpandedEntity(entity);
1617
    	}
1484
    	}
1618
    	
1485
    	
1619
    	return this.expEntity;
1486
    	return this.expEntity;
1620
    }
1487
    }
1621
 
1488
 
-
 
1489
    public Map<Long, EntityState> getEntitiesState(){
-
 
1490
    	return this.entitiesState;
1622
    /**
1491
    }
1623
     * 
1492
    
1624
     * @param entityID
1493
    public Set<String> getAllUserNames(){
-
 
1494
    	return UserManager.getUserManager().getAllUserNames();
1625
     * @return
1495
    }
1626
     * @throws Exception 
-
 
1627
     */
1496
    
1628
    private Entity getEntity(long entityID) throws Exception {
1497
    public Collection<User> getAllUsers(){
1629
    	log.info("Getting entity with id : " + entityID);
1498
    	return UserManager.getUserManager().getAllUsers();
1630
		if(this.entity == null) {
-
 
1631
			this.entity = CreationUtils.getEntity(entityID);
-
 
1632
		}
1499
    }
1633
		
1500
    
1634
		return this.entity;
-
 
1635
	}
1501
    
1636
 
-
 
1637
 
1502
	
1638
}
1503
}
-
 
1504