Subversion Repositories SmartDukaan

Rev

Rev 1378 | Rev 5380 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 1378 Rev 2720
Line 1... Line 1...
1
/**
1
/**
2
 * 
2
 * 
3
 */
3
 */
4
package in.shop2020.creation.controllers;
4
package in.shop2020.creation.controllers;
5
 
5
 
6
import in.shop2020.metamodel.util.CreationUtils;
-
 
7
import in.shop2020.metamodel.core.Media;
-
 
8
import in.shop2020.metamodel.core.Entity;
6
import in.shop2020.metamodel.core.Entity;
9
import in.shop2020.metamodel.core.FreeformContent;
7
import in.shop2020.metamodel.core.FreeformContent;
-
 
8
import in.shop2020.metamodel.core.Media;
-
 
9
import in.shop2020.metamodel.core.Media.Type;
10
import in.shop2020.metamodel.core.Slide;
10
import in.shop2020.metamodel.core.Slide;
-
 
11
import in.shop2020.metamodel.util.CreationUtils;
11
import in.shop2020.util.Utils;
12
import in.shop2020.util.Utils;
12
 
13
 
13
import java.io.File;
14
import java.io.File;
14
import java.io.FileInputStream;
15
import java.io.FileInputStream;
15
import java.io.FileOutputStream;
16
import java.io.FileOutputStream;
Line 43... Line 44...
43
    @Result(name="redirect", location="${url}", type="redirect")
44
    @Result(name="redirect", location="${url}", type="redirect")
44
})
45
})
45
public class MediaController extends BaseController {
46
public class MediaController extends BaseController {
46
	
47
	
47
	/**
48
	/**
-
 
49
     * 
-
 
50
     */
-
 
51
    private static final long serialVersionUID = 4482901443477816033L;
-
 
52
 
-
 
53
    /**
48
	 * 
54
	 * 
49
	 */
55
	 */
50
	private static Log log = LogFactory.getLog(MediaController.class);
56
	private static Log log = LogFactory.getLog(MediaController.class);
51
	
57
	
52
	/**
58
	/**
Line 55... Line 61...
55
	private String id;
61
	private String id;
56
	private String entityID;
62
	private String entityID;
57
	private String slideID;
63
	private String slideID;
58
	private String label;
64
	private String label;
59
	private String title;
65
	private String title;
60
	private String videoType;
-
 
61
	private File pic;
66
	private File   upload;
62
	private String picContentType;
67
	private String uploadFileName;
63
	private String picFileName;
68
    private String location;
64
	private String fileSystemPath;
69
	private String fileSystemPath;
65
	private String redirectURL;
70
	private String redirectURL;
66
	private String errorString;
71
	private String errorString;
67
	private String youtubeURL;
72
	private String mediaType;
68
		
73
 
69
    // GET /media
74
    // GET /media
70
    public HttpHeaders index() {
75
    public HttpHeaders index() {
71
    	log.info("MediaController.index");
76
    	log.info("MediaController.index");
72
    	
77
    	
73
        return new DefaultHttpHeaders("index").disableCaching();
78
        return new DefaultHttpHeaders("index").disableCaching();
Line 76... Line 81...
76
    // GET /media
81
    // GET /media
77
    public String create() {
82
    public String create() {
78
    	log.info("MediaController.create");
83
    	log.info("MediaController.create");
79
    	
84
    	
80
    	try {
85
    	try {
-
 
86
    		log.info("Location:" + location);
81
    		log.info("getPicFileName:" + this.getPicFileName());
87
    		log.info("UploadFileName:" + uploadFileName);
-
 
88
    		log.info("Label:" + label);
-
 
89
    		log.info("mediaType:" + mediaType);
82
    		log.info("getFileSystemPath:" + this.getFileSystemPath());
90
    		log.info("getFileSystemPath:" + this.getFileSystemPath());
83
    		log.info("getPicContentType:" + this.getPicContentType());
-
 
84
    		
91
 
85
    		boolean hasdata = false;
92
    		boolean hasdata = false;
86
    		String location = "";
93
    		String location = "";
87
    		String type = "";
-
 
88
    		if(this.getPic() != null) {
94
    		if(this.getUpload() != null) {
89
    			type = "image";
-
 
90
    			location = this.storeFile();
95
    			location = this.storeFile();
91
    			hasdata = true;
96
    			hasdata = true;
92
    		} 
97
    		}
93
    		else if(this.getYoutubeURL() != null) {
98
    		else if(this.getLocation() != null) {
94
    			type = "youtube";
-
 
95
    			location = this.getYoutubeURL();
99
    			location = this.getLocation();
96
    			hasdata = true;
100
    			hasdata = true;
97
    		}
101
    		}
98
    		
102
 
99
    		log.info("location:" + location);
103
    		log.info("location:" + location);
100
    		log.info("label:" + this.getLabel());
104
    		log.info("label:" + this.getLabel());
101
    		log.info("getTitle:" + this.getTitle());
105
    		log.info("getTitle:" + this.getTitle());
102
    		log.info("getVideoType:" + this.getVideoType());
-
 
103
    		
106
    		
104
    		if(hasdata) {
107
    		if(hasdata) {
105
    			Media media = new Media(this.getLabel(), type, location);
108
    			Media media = new Media(this.getLabel(), Media.Type.valueOf(mediaType), location);
106
    			media.setTitle(this.getTitle());
109
    			media.setTitle(this.getTitle());
107
    			if(this.getPic() != null) {
-
 
108
	    			media.setFileName(this.getPicFileName());
110
    			media.setFileName(uploadFileName);
109
	    			media.setContentType(this.getPicContentType());
-
 
110
	    			media.setVideoType("");
-
 
111
    			}
-
 
112
    			else {
-
 
113
	    			media.setFileName("");
-
 
114
	    			media.setContentType("");
-
 
115
	    			media.setVideoType(this.getVideoType());
-
 
116
    			}
-
 
117
    			//CreationUtils.addMedia(Long.parseLong(this.getEntityID()), media);
-
 
118
    			
111
 
119
    			log.info("entity ID:" + this.entityID);
112
    			log.info("entity ID:" + this.entityID);
120
    			log.info("slide ID:" + this.slideID);
113
    			log.info("slide ID:" + this.slideID);
121
    			
-
 
122
    			/*
-
 
123
    			String contentLabel = "";
-
 
124
    			log.info("type filename and location :" + media.getType() + "~!~" + media.getFileName() + media.getLocation());
-
 
125
    			
-
 
126
    			if(media.getType().compareTo("image")==0){
-
 
127
    				contentLabel = media.getLabel() + "~!~" + media.getFileName();
-
 
128
    				log.info("Type is image :" + contentLabel);
-
 
129
        		}
-
 
130
        		if(media.getType().compareTo("youtube")==0){
-
 
131
        			contentLabel = media.getLabel() + "~!~" + media.getLocation();
-
 
132
        			log.info("Type is youtube :" + contentLabel);
-
 
133
        		}
-
 
134
    			*/
-
 
135
    			
-
 
136
        		
114
        		
137
    			Entity entity = CreationUtils.getEntity(Long.parseLong(this.entityID));
115
    			Entity entity = CreationUtils.getEntity(Long.parseLong(this.entityID));
138
    			
116
    			
139
	    		Slide slide = entity.getSlide(Long.parseLong(this.slideID));
117
	    		Slide slide = entity.getSlide(Long.parseLong(this.slideID));
140
    			if(slide == null){
118
    			if(slide == null){
Line 168... Line 146...
168
     * 
146
     * 
169
     */
147
     */
170
    public String destroy() {
148
    public String destroy() {
171
    	log.info("MediaController.destroy");
149
    	log.info("MediaController.destroy");
172
    	try {
150
    	try {
173
    		long entityID = Long.parseLong(this.getEntityID());
-
 
174
    		long slideID = Long.parseLong(this.getSlideID());
151
    		long slideID = Long.parseLong(this.getSlideID());
175
    		
152
    		
176
    		String label = reqparams.get("label")[0];
153
    		String label = reqparams.get("label")[0];
177
    		
154
    		
178
    		label = URLDecoder.decode(label, "UTF-8");
155
    		label = URLDecoder.decode(label, "UTF-8");
179
    		System.out.println("Label is label:" + label);
156
    		System.out.println("Label is label:" + label);
180
//    		String label = this.getId();
-
 
181
//    		log.info("label:" + label);
-
 
182
//    		log.info("slide:" + label);
-
 
183
//    		log.info("entity:" + label);
-
 
184
//    		
-
 
185
//    		label = URLDecoder.decode(label, "UTF-8");
-
 
186
    		
157
    		
187
    		Entity entity = CreationUtils.getEntity(Long.parseLong(this.entityID));
158
    		Entity entity = CreationUtils.getEntity(Long.parseLong(this.entityID));
188
    		
159
    		
189
			FreeformContent freeformContent = entity.getSlide(slideID).getFreeformContent(); 
160
			FreeformContent freeformContent = entity.getSlide(slideID).getFreeformContent(); 
190
			freeformContent.removeMedia(label);
161
			freeformContent.removeMedia(label);
Line 207... Line 178...
207
	 * @param id the id to set
178
	 * @param id the id to set
208
	 */
179
	 */
209
	public void setSlideID(String id) {
180
	public void setSlideID(String id) {
210
		this.slideID = id;
181
		this.slideID = id;
211
		log.info("token 2:" + this.slideID);
182
		log.info("token 2:" + this.slideID);
212
 
-
 
213
//		StringTokenizer tokenizer = new StringTokenizer(id,"_");
-
 
214
//		log.info("id:" + id);
-
 
215
//		log.info("token 1:" + tokenizer.nextToken());
-
 
216
//		log.info("token 2:" + tokenizer.nextToken());
-
 
217
//		this.slideID = tokenizer.nextToken();
-
 
218
//		log.info("token 2:" + this.slideID);
-
 
219
	}
183
	}
220
	/**
184
	/**
221
	 * @return the id
185
	 * @return the id
222
	 */
186
	 */
223
	public String getSlideID() {
187
	public String getSlideID() {
Line 227... Line 191...
227
	 * @param id the id to set
191
	 * @param id the id to set
228
	 */
192
	 */
229
	public void setEntityID(String id) {
193
	public void setEntityID(String id) {
230
		this.entityID = id;
194
		this.entityID = id;
231
		log.info("token 2:" + this.entityID);
195
		log.info("token 2:" + this.entityID);
232
		
-
 
233
//		StringTokenizer tokenizer = new StringTokenizer(id,"_");
-
 
234
//		this.entityID = tokenizer.nextToken();
-
 
235
//		log.info("id:" + id);
-
 
236
//		log.info("token 2:" + this.entityID);
-
 
237
//		log.info("token 2:" + tokenizer.nextToken());
-
 
238
//		this.slideID = tokenizer.nextToken();
-
 
239
//		log.info("token 3:" + this.slideID);
-
 
240
	}
-
 
241
	/**
-
 
242
	 * @return the id
-
 
243
	 */
-
 
244
	public String getEntityID() {
-
 
245
		return entityID;
-
 
246
	}
-
 
247
	/**
-
 
248
	 * @param label the label to set
-
 
249
	 */
-
 
250
	public void setLabel(String label) {
-
 
251
		this.label = label;
-
 
252
	}
196
	}
253
 
197
 
254
	/**
198
	/**
255
	 * @return the label
199
     * @return all media elements for the concerned slide
256
	 */
200
     *
257
	public String getLabel() {
-
 
258
		return label;
-
 
259
	}
-
 
260
 
-
 
261
	public void setTitle(String title) {
-
 
262
		this.title = title;
-
 
263
	}
-
 
264
 
-
 
265
	public String getTitle() {
-
 
266
		return title;
-
 
267
	}
-
 
268
 
-
 
269
	public void setVideoType(String videoType) {
-
 
270
		this.videoType = videoType;
-
 
271
	}
-
 
272
 
-
 
273
	public String getVideoType() {
201
     * @throws NumberFormatException
274
		return videoType;
-
 
275
	}
-
 
276
 
-
 
277
	/**
-
 
278
	 * @param pic the pic to set
202
     * @throws Exception
279
	 */
203
     */
280
	public void setPic(File pic) {
204
    public Map<String, Media> getAllMedia() throws NumberFormatException,
281
		this.pic = pic;
-
 
282
	}
-
 
283
	/**
-
 
284
	 * @return the pic
-
 
285
	 */
-
 
286
	public File getPic() {
205
            Exception {
287
		return pic;
-
 
288
	}
-
 
289
	/**
-
 
290
	 * @param picContentType the picContentType to set
-
 
291
	 */
-
 
292
	public void setPicContentType(String picContentType) {
206
        Slide slide = CreationUtils.getEntity(Long.parseLong(this.entityID))
293
		this.picContentType = picContentType;
-
 
294
	}
-
 
295
	/**
-
 
296
	 * @return the picContentType
-
 
297
	 */
-
 
298
	public String getPicContentType() {
207
                .getSlide(Long.parseLong(this.slideID));
299
		return picContentType;
208
        if (slide != null) {
300
	}
-
 
301
	/**
-
 
302
	 * @param picFileName the picFileName to set
209
            FreeformContent ffc = slide.getFreeformContent();
303
	 */
-
 
304
	public void setPicFileName(String picFileName) {
-
 
305
		this.picFileName = picFileName;
-
 
306
	}
-
 
307
	/**
-
 
308
	 * @return the picFileName
210
            if (ffc != null) {
309
	 */
-
 
310
	public String getPicFileName() {
211
                return ffc.getMedias();
311
		return picFileName;
212
            }
312
	}
-
 
313
	/**
-
 
314
	 * @param fileSystemPath the fileSystemPath to set
-
 
315
	 */
213
        }
316
	public void setFileSystemPath(String fileSystemPath) {
-
 
317
		this.fileSystemPath = fileSystemPath;
-
 
318
	}
-
 
319
	/**
-
 
320
	 * @return the fileSystemPath
214
        return null;
321
	 */
215
    }
322
	public String getFileSystemPath() {
-
 
323
		return fileSystemPath;
-
 
324
	}
-
 
325
 
216
 
326
    /**
217
    /**
327
	 * @param youtubeURL the youtubeURL to set
218
     * Returns all different types of media
328
	 */
219
     *
329
	public void setYoutubeURL(String youtubeURL) {
-
 
330
		this.youtubeURL = youtubeURL;
-
 
331
	}
-
 
332
 
-
 
333
	/**
-
 
334
	 * @return the youtubeURL
220
     * @return
335
	 */
221
     */
336
	public String getYoutubeURL() {
222
    public Type[] getMediaTypes() {
337
		return youtubeURL;
-
 
338
	}
-
 
339
 
-
 
340
	public String getUrl() {
-
 
341
    	return this.redirectURL;
223
        return Type.values();
342
    }
224
    }
343
 
225
 
344
	/**
226
	/**
345
	 * @param errorString the exceptionString to set
-
 
346
	 */
-
 
347
	public void setErrorString(String errorString) {
-
 
348
		this.errorString = errorString;
-
 
349
	}
-
 
350
 
-
 
351
	/**
-
 
352
	 * @return the exceptionString
-
 
353
	 */
-
 
354
	public String getErrorString() {
-
 
355
		return errorString;
-
 
356
	}
-
 
357
	
-
 
358
	    
-
 
359
    
-
 
360
	/**
-
 
361
	 * 
227
	 * 
362
	 * @throws Exception
228
	 * @throws Exception
363
	 */
229
	 */
364
	private String storeFile() throws Exception {
230
	private String storeFile() throws Exception {
365
		String mediaDirPath = Utils.CONTENT_DB_PATH + "media" + File.separator + this.getEntityID();
231
		String mediaDirPath = Utils.CONTENT_DB_PATH + "media" + File.separator + this.getEntityID();
366
		File mediaDir = new File(mediaDirPath);
232
		File mediaDir = new File(mediaDirPath);
367
		if(!mediaDir.exists()) {
233
		if(!mediaDir.exists()) {
368
			mediaDir.mkdir();
234
			mediaDir.mkdir();
369
		}
235
		}
370
		
236
 
371
		String mediaFileName = mediaDirPath + "/" + this.getPicFileName();
237
		String mediaFileName = mediaDirPath + "/" + uploadFileName;
372
		File mediaFile = new File(mediaFileName);
238
		File mediaFile = new File(mediaFileName);
373
		mediaFile.createNewFile();
239
		mediaFile.createNewFile();
374
 
240
 
375
		File uploadedPicFile = this.getPic();
241
		File uploadedPicFile = this.getUpload();
376
 
242
 
377
		InputStream in = new FileInputStream(uploadedPicFile);
243
		InputStream in = new FileInputStream(uploadedPicFile);
378
		
244
		
379
		// appending output stream
245
		// appending output stream
380
		// @rajveer : replacing the existing file 
246
		// @rajveer : replacing the existing file 
Line 393... Line 259...
393
 
259
 
394
	/**
260
	/**
395
	 * @param id the id to set
261
	 * @param id the id to set
396
	 */
262
	 */
397
	public void setId(String id) {
263
	public void setId(String id) {
398
//		StringTokenizer tokenizer = new StringTokenizer(id,"_");
-
 
399
//		log.info("id:" + id);
-
 
400
//		this.id = tokenizer.nextToken();
-
 
401
//		log.info("token 1:" + tokenizer.nextToken());
-
 
402
//		this.slideID = tokenizer.nextToken();
-
 
403
//		log.info("token 2:" + this.slideID);
-
 
404
		log.info("id:" + id);
264
		log.info("id:" + id);
405
		this.id = id;
265
		this.id = id;
406
	}
266
	}
407
 
267
 
408
	/**
268
	/**
409
	 * @return the id
269
	 * @return the id
410
	 */
270
	 */
411
	public String getId() {
271
	public String getId() {
412
		return id;
272
		return id;
413
	}
273
	}
-
 
274
	
-
 
275
	   /**
-
 
276
     * @return the id
-
 
277
     */
-
 
278
    public String getEntityID() {
-
 
279
        return entityID;
-
 
280
    }
-
 
281
    /**
-
 
282
     * @param label the label to set
-
 
283
     */
-
 
284
    public void setLabel(String label) {
-
 
285
        this.label = label;
-
 
286
    }
414
 
287
 
415
    public Map<String,Media> getAllMedia() throws NumberFormatException, Exception {
-
 
416
    	 Slide slide =  CreationUtils.getEntity(Long.parseLong(this.entityID)).getSlide(Long.parseLong(this.slideID));
-
 
417
		 if(slide != null){
-
 
418
			 FreeformContent ffc = slide.getFreeformContent();
-
 
419
			 if(ffc != null){
288
    /**
420
				 return ffc.getMedias();
289
     * @return the label
421
			 }
290
     */
422
		 }
291
    public String getLabel() {
423
		return null;
292
        return label;
424
	}
293
    }
425
 
294
 
-
 
295
    public void setTitle(String title) {
-
 
296
        this.title = title;
-
 
297
    }
-
 
298
 
-
 
299
    public String getTitle() {
-
 
300
        return title;
-
 
301
    }
-
 
302
 
-
 
303
    /**
-
 
304
     * @param File to set
-
 
305
     */
-
 
306
    public void setUpload(File upload) {
-
 
307
        this.upload = upload;
-
 
308
    }
-
 
309
    /**
-
 
310
     * @return the file
-
 
311
     */
-
 
312
    public File getUpload() {
-
 
313
        return upload;
-
 
314
    }
-
 
315
    /**
-
 
316
     * @param location the picFileName to set
-
 
317
     */
-
 
318
    public void setLocation(String location) {
-
 
319
        this.location = location;
-
 
320
    }
-
 
321
    /**
-
 
322
     * @return the picFileName
-
 
323
     */
-
 
324
    public String getLocation() {
-
 
325
        return location;
-
 
326
    }
-
 
327
    /**
-
 
328
     * @param fileSystemPath the fileSystemPath to set
-
 
329
     */
-
 
330
    public void setFileSystemPath(String fileSystemPath) {
-
 
331
        this.fileSystemPath = fileSystemPath;
-
 
332
    }
-
 
333
    /**
-
 
334
     * @return the fileSystemPath
-
 
335
     */
-
 
336
    public String getFileSystemPath() {
-
 
337
        return fileSystemPath;
-
 
338
    }
-
 
339
 
-
 
340
    public String getUrl() {
-
 
341
        return this.redirectURL;
-
 
342
    }
-
 
343
 
-
 
344
    /**
-
 
345
     * @param errorString the exceptionString to set
-
 
346
     */
-
 
347
    public void setErrorString(String errorString) {
-
 
348
        this.errorString = errorString;
-
 
349
    }
-
 
350
 
-
 
351
    /**
-
 
352
     * @return the exceptionString
-
 
353
     */
-
 
354
    public String getErrorString() {
-
 
355
        return errorString;
-
 
356
    }
-
 
357
 
-
 
358
    public String getMediaType() {
-
 
359
        return mediaType;
-
 
360
    }
-
 
361
 
-
 
362
    public void setMediaType(String mediaType) {
-
 
363
        this.mediaType = mediaType;
-
 
364
    }
-
 
365
 
-
 
366
    public String getUploadFileName() {
-
 
367
        return uploadFileName;
426
    
368
    }
427
}
369
 
-
 
370
    public void setUploadFileName(String uploadFileName) {
-
 
371
        this.uploadFileName = uploadFileName;
-
 
372
    }
428
 
373
 
-
 
374
}
429
375