Index: lams_tool_images/conf/language/lams/ApplicationResources_en_AU.properties =================================================================== diff -u -rfd6a44adca1e0d4ee031b0b8b442de4ee8974d74 -r5d9ada1b3b139591dc6f1fffec04990beb727522 --- lams_tool_images/conf/language/lams/ApplicationResources_en_AU.properties (.../ApplicationResources_en_AU.properties) (revision fd6a44adca1e0d4ee031b0b8b442de4ee8974d74) +++ lams_tool_images/conf/language/lams/ApplicationResources_en_AU.properties (.../ApplicationResources_en_AU.properties) (revision 5d9ada1b3b139591dc6f1fffec04990beb727522) @@ -78,6 +78,10 @@ label.learning.new.file =New file details: label.learning.new.url =New URL details: label.learning.ratings =ratings +label.learning.average.rating =Average rating : +label.learning.vote.here =Vote here +label.learning.unvote =Unvote +label.learning.already.voted =Already voted label.learning.add.comment =Add comment label.learning.post =Post label.learning.by =By @@ -109,6 +113,7 @@ error.resource.image.not.alowed.format =Allowed file formats: gif, png, jpg error.resource.item.url.blank =URL can not be blank. error.resource.item.file.blank =File can not be blank. +error.resource.image.comment.blank =Comment can not be blank. error.resource.item.invalid.url =Invalid URL format. error.upload.failed =Upload file failed: {0} error.msg.upload.file.not.found =Could not find upload file {0}. @@ -117,6 +122,7 @@ error.msg.ims.application =ImscpApplicationException occurs when uploading original size image. error.msg.io.exception =IOException occurs when uploading file. error.msg.repository.checked.exception =Repository checked exception occurs when creating a smaller scale image. +error.msg.number.format.exception =Number format exception occurs when parsing config property. Please set it up correctly in image tool config page. error.msg.item.not.found.exception =Item not found exception occurs when creating a smaller scale image. error.msg.file.exception =File exception occurs when creating a smaller scale image. error.msg.invaid.param.upload =InvalidParameterException occured while trying to upload File. Index: lams_tool_images/conf/xdoclet/struts-actions.xml =================================================================== diff -u -rfd6a44adca1e0d4ee031b0b8b442de4ee8974d74 -r5d9ada1b3b139591dc6f1fffec04990beb727522 --- lams_tool_images/conf/xdoclet/struts-actions.xml (.../struts-actions.xml) (revision fd6a44adca1e0d4ee031b0b8b442de4ee8974d74) +++ lams_tool_images/conf/xdoclet/struts-actions.xml (.../struts-actions.xml) (revision 5d9ada1b3b139591dc6f1fffec04990beb727522) @@ -177,9 +177,9 @@ - + parameter="loadImageData"> - + + + + + + + - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
- + @@ -191,8 +377,8 @@ - + @@ -497,7 +683,7 @@
- + @@ -571,6 +757,13 @@ + + + + + + + @@ -589,7 +782,7 @@
- + Index: lams_tool_images/db/sql/create_lams_tool_imageGallery.sql =================================================================== diff -u -rcfd6a77839edfa64b3e7d320a6d9ed85e9c99f9a -r5d9ada1b3b139591dc6f1fffec04990beb727522 --- lams_tool_images/db/sql/create_lams_tool_imageGallery.sql (.../create_lams_tool_imageGallery.sql) (revision cfd6a77839edfa64b3e7d320a6d9ed85e9c99f9a) +++ lams_tool_images/db/sql/create_lams_tool_imageGallery.sql (.../create_lams_tool_imageGallery.sql) (revision 5d9ada1b3b139591dc6f1fffec04990beb727522) @@ -3,6 +3,7 @@ drop table if exists tl_laimag10_imageGallery; drop table if exists tl_laimag10_imageGallery_item; drop table if exists tl_laimag10_image_comment; +drop table if exists tl_laimag10_image_rating; drop table if exists tl_laimag10_imageGallery_item_visit_log; drop table if exists tl_laimag10_session; drop table if exists tl_laimag10_user; @@ -37,6 +38,7 @@ allow_share_images tinyint, number_columns integer DEFAULT 3, allow_vote tinyint, + voted_image_uid bigint DEFAULT 0, reflect_instructions varchar(255), reflect_on_activity smallint, allow_rank tinyint, @@ -59,6 +61,8 @@ file_version_id bigint, file_type varchar(255), file_name varchar(255), + average_rating FLOAT(7,1) DEFAULT 0, + number_ratings integer DEFAULT 0, primary key (uid) )type=innodb; create table tl_laimag10_image_comment ( @@ -69,6 +73,13 @@ create_date datetime, primary key (uid) )TYPE=InnoDB; +create table tl_laimag10_image_rating ( + uid bigint not null auto_increment, + rating integer, + imageGallery_item_uid bigint, + create_by bigint, + primary key (uid) +)TYPE=InnoDB; create table tl_laimag10_item_log ( uid bigint not null auto_increment, access_date datetime, @@ -113,6 +124,8 @@ alter table tl_laimag10_imageGallery_item add index FK_NEW_1821149711_F52D1F93EC0D3147 (session_uid), add constraint FK_NEW_1821149711_F52D1F93EC0D3147 foreign key (session_uid) references tl_laimag10_session (uid); alter table tl_laimag10_image_comment add index FK_tl_laimag10_image_comment_3 (imageGallery_item_uid), add constraint FK_tl_laimag10_image_comment_3 foreign key (imageGallery_item_uid) references tl_laimag10_imageGallery_item (uid); alter table tl_laimag10_image_comment add index FK_tl_laimag10_image_comment_2 (create_by), add constraint FK_tl_laimag10_image_comment_2 foreign key (create_by) references tl_laimag10_user (uid); +alter table tl_laimag10_image_rating add index FK_tl_laimag10_image_rating_3 (imageGallery_item_uid), add constraint FK_tl_laimag10_image_rating_3 foreign key (imageGallery_item_uid) references tl_laimag10_imageGallery_item (uid); +alter table tl_laimag10_image_rating add index FK_tl_laimag10_image_rating_2 (create_by), add constraint FK_tl_laimag10_image_rating_2 foreign key (create_by) references tl_laimag10_user (uid); alter table tl_laimag10_item_log add index FK_NEW_1821149711_693580A438BF8DFE (imageGallery_item_uid), add constraint FK_NEW_1821149711_693580A438BF8DFE foreign key (imageGallery_item_uid) references tl_laimag10_imageGallery_item (uid); alter table tl_laimag10_item_log add index FK_NEW_1821149711_693580A441F9365D (user_uid), add constraint FK_NEW_1821149711_693580A441F9365D foreign key (user_uid) references tl_laimag10_user (uid); alter table tl_laimag10_session add index FK_NEW_1821149711_24AA78C530E79035 (imageGallery_uid), add constraint FK_NEW_1821149711_24AA78C530E79035 foreign key (imageGallery_uid) references tl_laimag10_imageGallery (uid); Index: lams_tool_images/db/sql/table-schema.sql =================================================================== diff -u -rcfd6a77839edfa64b3e7d320a6d9ed85e9c99f9a -r5d9ada1b3b139591dc6f1fffec04990beb727522 --- lams_tool_images/db/sql/table-schema.sql (.../table-schema.sql) (revision cfd6a77839edfa64b3e7d320a6d9ed85e9c99f9a) +++ lams_tool_images/db/sql/table-schema.sql (.../table-schema.sql) (revision 5d9ada1b3b139591dc6f1fffec04990beb727522) @@ -7,6 +7,8 @@ alter table tl_laimag10_imageGallery_item drop foreign key FK_NEW_1821149711_F52D1F93758092FB; alter table tl_laimag10_image_comment drop foreign key FK_tl_laimag10_image_comment_2; alter table tl_laimag10_image_comment drop foreign key FK_tl_laimag10_image_comment_3; +alter table tl_laimag10_image_rating drop foreign key FK_tl_laimag10_image_rating_2; +alter table tl_laimag10_image_rating drop foreign key FK_tl_laimag10_image_rating_3; alter table tl_laimag10_session drop foreign key FK_NEW_1821149711_24AA78C530E79035; alter table tl_laimag10_user drop foreign key FK_NEW_1821149711_30113BFC30E79035; alter table tl_laimag10_user drop foreign key FK_NEW_1821149711_30113BFCEC0D3147; @@ -15,14 +17,16 @@ drop table if exists tl_laimag10_imageGallery; drop table if exists tl_laimag10_imageGallery_item; drop table if exists tl_laimag10_image_comment; +drop table if exists tl_laimag10_image_rating; drop table if exists tl_laimag10_session; drop table if exists tl_laimag10_user; drop table if exists tl_laimag10_configuration; create table tl_laimag10_attachment (uid bigint not null auto_increment, file_version_id bigint, file_type varchar(255), file_name varchar(255), file_uuid bigint, create_date datetime, imageGallery_uid bigint, primary key (uid)); create table tl_laimag10_item_log (uid bigint not null auto_increment, access_date datetime, imageGallery_item_uid bigint, user_uid bigint, complete bit, session_id bigint, primary key (uid)); -create table tl_laimag10_imageGallery (uid bigint not null auto_increment, create_date datetime, update_date datetime, create_by bigint, title varchar(255), run_offline bit, lock_on_finished bit, instructions text, next_image_title bigint, online_instructions text, offline_instructions text, content_in_use bit, define_later bit, content_id bigint unique, allow_comment_images bit, allow_share_images bit, number_columns integer DEFAULT 3, allow_vote bit, reflect_instructions varchar(255), reflect_on_activity bit,allow_rank tinyint DEFAULT 0, primary key (uid)); -create table tl_laimag10_imageGallery_item (uid bigint not null auto_increment, description text, title varchar(255), create_by bigint, create_date datetime, create_by_author bit, sequence_id integer, is_hide bit, imageGallery_uid bigint, session_uid bigint, original_file_uuid bigint, medium_file_uuid bigint, thumbnail_file_uuid bigint, file_version_id bigint, file_type varchar(255), file_name varchar(255), primary key (uid)); +create table tl_laimag10_imageGallery (uid bigint not null auto_increment, create_date datetime, update_date datetime, create_by bigint, title varchar(255), run_offline bit, lock_on_finished bit, instructions text, next_image_title bigint, online_instructions text, offline_instructions text, content_in_use bit, define_later bit, content_id bigint unique, allow_comment_images bit, allow_share_images bit, number_columns integer DEFAULT 3, allow_vote bit, voted_image_uid bigint DEFAULT 0, reflect_instructions varchar(255), reflect_on_activity bit,allow_rank tinyint DEFAULT 0, primary key (uid)); +create table tl_laimag10_imageGallery_item (uid bigint not null auto_increment, description text, title varchar(255), create_by bigint, create_date datetime, create_by_author bit, sequence_id integer, is_hide bit, imageGallery_uid bigint, session_uid bigint, original_file_uuid bigint, medium_file_uuid bigint, thumbnail_file_uuid bigint, file_version_id bigint, file_type varchar(255), file_name varchar(255), average_rating FLOAT(7,1) DEFAULT 0, number_ratings integer DEFAULT 0, primary key (uid)); create table tl_laimag10_image_comment (uid bigint not null auto_increment, comment text, imageGallery_item_uid bigint, create_by bigint, create_date datetime, primary key (uid)); +create table tl_laimag10_image_rating (uid bigint not null auto_increment, rating integer, imageGallery_item_uid bigint, create_by bigint, primary key (uid)); create table tl_laimag10_session (uid bigint not null auto_increment, session_end_date datetime, session_start_date datetime, status integer, imageGallery_uid bigint, session_id bigint, session_name varchar(250), primary key (uid)); create table tl_laimag10_user (uid bigint not null auto_increment, user_id bigint, last_name varchar(255), first_name varchar(255), login_name varchar(255), session_uid bigint, imageGallery_uid bigint, session_finished bit, primary key (uid)); create table tl_laimag10_configuration (uid bigint not null auto_increment, config_key varchar(30) unique, config_value varchar(255), primary key (uid)); @@ -35,6 +39,8 @@ alter table tl_laimag10_imageGallery_item add index FK_NEW_1821149711_F52D1F93758092FB (create_by), add constraint FK_NEW_1821149711_F52D1F93758092FB foreign key (create_by) references tl_laimag10_user (uid); alter table tl_laimag10_image_comment add index FK_tl_laimag10_image_comment_3 (imageGallery_item_uid), add constraint FK_tl_laimag10_image_comment_3 foreign key (imageGallery_item_uid) references tl_laimag10_imageGallery_item (uid); alter table tl_laimag10_image_comment add index FK_tl_laimag10_image_comment_2 (create_by), add constraint FK_tl_laimag10_image_comment_2 foreign key (create_by) references tl_laimag10_user (uid); +alter table tl_laimag10_image_rating add index FK_tl_laimag10_image_rating_3 (imageGallery_item_uid), add constraint FK_tl_laimag10_image_rating_3 foreign key (imageGallery_item_uid) references tl_laimag10_imageGallery_item (uid); +alter table tl_laimag10_image_rating add index FK_tl_laimag10_image_rating_2 (create_by), add constraint FK_tl_laimag10_image_rating_2 foreign key (create_by) references tl_laimag10_user (uid); alter table tl_laimag10_session add index FK_NEW_1821149711_24AA78C530E79035 (imageGallery_uid), add constraint FK_NEW_1821149711_24AA78C530E79035 foreign key (imageGallery_uid) references tl_laimag10_imageGallery (uid); alter table tl_laimag10_user add index FK_NEW_1821149711_30113BFC30E79035 (imageGallery_uid), add constraint FK_NEW_1821149711_30113BFC30E79035 foreign key (imageGallery_uid) references tl_laimag10_imageGallery (uid); alter table tl_laimag10_user add index FK_NEW_1821149711_30113BFCEC0D3147 (session_uid), add constraint FK_NEW_1821149711_30113BFCEC0D3147 foreign key (session_uid) references tl_laimag10_session (uid); Fisheye: Tag 5d9ada1b3b139591dc6f1fffec04990beb727522 refers to a dead (removed) revision in file `lams_tool_images/licenses/Jaxen LICENSE.txt'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 5d9ada1b3b139591dc6f1fffec04990beb727522 refers to a dead (removed) revision in file `lams_tool_images/licenses/castor license.txt'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 5d9ada1b3b139591dc6f1fffec04990beb727522 refers to a dead (removed) revision in file `lams_tool_images/licenses/jdom licence.txt'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 5d9ada1b3b139591dc6f1fffec04990beb727522 refers to a dead (removed) revision in file `lams_tool_images/licenses/library_licenses.txt'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 5d9ada1b3b139591dc6f1fffec04990beb727522 refers to a dead (removed) revision in file `lams_tool_images/licenses/reload licence.txt'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 5d9ada1b3b139591dc6f1fffec04990beb727522 refers to a dead (removed) revision in file `lams_tool_images/licenses/xerces licence.txt'. Fisheye: No comparison available. Pass `N' to diff? Index: lams_tool_images/src/java/org/lamsfoundation/lams/tool/imageGallery/ImageGalleryConstants.java =================================================================== diff -u -rfd6a44adca1e0d4ee031b0b8b442de4ee8974d74 -r5d9ada1b3b139591dc6f1fffec04990beb727522 --- lams_tool_images/src/java/org/lamsfoundation/lams/tool/imageGallery/ImageGalleryConstants.java (.../ImageGalleryConstants.java) (revision fd6a44adca1e0d4ee031b0b8b442de4ee8974d74) +++ lams_tool_images/src/java/org/lamsfoundation/lams/tool/imageGallery/ImageGalleryConstants.java (.../ImageGalleryConstants.java) (revision 5d9ada1b3b139591dc6f1fffec04990beb727522) @@ -63,6 +63,10 @@ public static final String PARAM_COMMENTS = "comments"; public static final String PARAM_CURRENT_IMAGE = "currentImage"; + + public static final String PARAM_CURRENT_RATING = "currentRating"; + + public static final String PARAM_VOTED_IMAGE_UID = "votedImageUid"; // for request attribute name public static final String ATTR_TOOL_CONTENT_ID = "toolContentID"; @@ -125,7 +129,9 @@ public static final String ERROR_MSG_DESC_BLANK = "error.resource.item.desc.blank"; public static final String ERROR_MSG_FILE_BLANK = "error.resource.item.file.blank"; - + + public static final String ERROR_MSG_COMMENT_BLANK = "error.resource.image.comment.blank"; + public static final String ERROR_MSG_INVALID_URL = "error.resource.item.invalid.url"; public static final String ERROR_MSG_UPLOAD_FAILED = "error.upload.failed"; Index: lams_tool_images/src/java/org/lamsfoundation/lams/tool/imageGallery/dao/ImageRatingDAO.java =================================================================== diff -u --- lams_tool_images/src/java/org/lamsfoundation/lams/tool/imageGallery/dao/ImageRatingDAO.java (revision 0) +++ lams_tool_images/src/java/org/lamsfoundation/lams/tool/imageGallery/dao/ImageRatingDAO.java (revision 5d9ada1b3b139591dc6f1fffec04990beb727522) @@ -0,0 +1,45 @@ +/**************************************************************** + * Copyright (C) 2005 LAMS Foundation (http://lamsfoundation.org) + * ============================================================= + * License Information: http://lamsfoundation.org/licensing/lams/2.0/ + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2.0 + * as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 * USA + * + * http://www.gnu.org/licenses/gpl.txt + * **************************************************************** + */ + +/* $Id$ */ +package org.lamsfoundation.lams.tool.imageGallery.dao; + +import org.lamsfoundation.lams.tool.imageGallery.model.ImageRating; + +/** + * DAO interface for ImageRating. + * + * @author Andrey Balan + * @see org.lamsfoundation.lams.tool.imageGallery.model.ImageRating + */ +public interface ImageRatingDAO extends DAO { + + /** + * Return imageRating by the given imageUid. + * @param imageUid + * @param userId + * @return + */ + public ImageRating getImageRatingByImageAndUser(Long imageUid, Long userId); + +} + \ No newline at end of file Index: lams_tool_images/src/java/org/lamsfoundation/lams/tool/imageGallery/dao/hibernate/ImageGalleryItemDAOHibernate.java =================================================================== diff -u -r8a7c47632a6a93892f015f068d12adb376c0ae2d -r5d9ada1b3b139591dc6f1fffec04990beb727522 --- lams_tool_images/src/java/org/lamsfoundation/lams/tool/imageGallery/dao/hibernate/ImageGalleryItemDAOHibernate.java (.../ImageGalleryItemDAOHibernate.java) (revision 8a7c47632a6a93892f015f068d12adb376c0ae2d) +++ lams_tool_images/src/java/org/lamsfoundation/lams/tool/imageGallery/dao/hibernate/ImageGalleryItemDAOHibernate.java (.../ImageGalleryItemDAOHibernate.java) (revision 5d9ada1b3b139591dc6f1fffec04990beb727522) @@ -28,17 +28,16 @@ import org.lamsfoundation.lams.tool.imageGallery.dao.ImageGalleryItemDAO; import org.lamsfoundation.lams.tool.imageGallery.model.ImageGalleryItem; -public class ImageGalleryItemDAOHibernate extends BaseDAOHibernate implements ImageGalleryItemDAO{ - - private static final String FIND_AUTHORING_ITEMS = "from " + ImageGalleryItem.class.getName() + " where imageGallery_uid = ? order by create_date asc"; - - public List getAuthoringItems(Long imageGalleryUid) { - - return this.getHibernateTemplate().find(FIND_AUTHORING_ITEMS,imageGalleryUid); - } +public class ImageGalleryItemDAOHibernate extends BaseDAOHibernate implements ImageGalleryItemDAO { - public ImageGalleryItem getByUid(Long imageGalleryItemUid) { - return (ImageGalleryItem) this.getObject(ImageGalleryItem.class,imageGalleryItemUid); - } + private static final String FIND_AUTHORING_ITEMS = "from " + ImageGalleryItem.class.getName() + + " where imageGallery_uid = ? order by create_date asc"; + public List getAuthoringItems(Long imageGalleryUid) { + return this.getHibernateTemplate().find(FIND_AUTHORING_ITEMS, imageGalleryUid); + } + + public ImageGalleryItem getByUid(Long imageGalleryItemUid) { + return (ImageGalleryItem) this.getObject(ImageGalleryItem.class, imageGalleryItemUid); + } } Index: lams_tool_images/src/java/org/lamsfoundation/lams/tool/imageGallery/dao/hibernate/ImageGalleryItemVisitDAOHibernate.java =================================================================== diff -u -rfd6a44adca1e0d4ee031b0b8b442de4ee8974d74 -r5d9ada1b3b139591dc6f1fffec04990beb727522 --- lams_tool_images/src/java/org/lamsfoundation/lams/tool/imageGallery/dao/hibernate/ImageGalleryItemVisitDAOHibernate.java (.../ImageGalleryItemVisitDAOHibernate.java) (revision fd6a44adca1e0d4ee031b0b8b442de4ee8974d74) +++ lams_tool_images/src/java/org/lamsfoundation/lams/tool/imageGallery/dao/hibernate/ImageGalleryItemVisitDAOHibernate.java (.../ImageGalleryItemVisitDAOHibernate.java) (revision 5d9ada1b3b139591dc6f1fffec04990beb727522) @@ -32,57 +32,54 @@ import org.lamsfoundation.lams.tool.imageGallery.model.ImageGalleryItemVisitLog; import org.lamsfoundation.lams.tool.imageGallery.model.ImageGallerySession; -public class ImageGalleryItemVisitDAOHibernate extends BaseDAOHibernate implements ImageGalleryItemVisitDAO{ - - private static final String FIND_BY_ITEM_AND_USER = "from " + ImageGalleryItemVisitLog.class.getName() - + " as r where r.user.userId = ? and r.imageGalleryItem.uid=?"; +public class ImageGalleryItemVisitDAOHibernate extends BaseDAOHibernate implements ImageGalleryItemVisitDAO { - private static final String FIND_BY_ITEM_BYSESSION = "from " + ImageGalleryItemVisitLog.class.getName() - + " as r where r.sessionId = ? and r.imageGalleryItem.uid=?"; - - private static final String FIND_VIEW_COUNT_BY_USER = "select count(*) from " + ImageGalleryItemVisitLog.class.getName() - + " as r where r.sessionId=? and r.user.userId =?"; + private static final String FIND_BY_ITEM_AND_USER = "from " + ImageGalleryItemVisitLog.class.getName() + + " as r where r.user.userId = ? and r.imageGalleryItem.uid=?"; - private static final String FIND_SUMMARY = "select v.imageGalleryItem.uid, count(v.imageGalleryItem) from " - + ImageGalleryItemVisitLog.class.getName() + " as v , " - + ImageGallerySession.class.getName() + " as s, " - + ImageGallery.class.getName() + " as r " - +" where v.sessionId = s.sessionId " - +" and s.imageGallery.uid = r.uid " - +" and r.contentId =? " - +" group by v.sessionId, v.imageGalleryItem.uid "; - - public ImageGalleryItemVisitLog getImageGalleryItemLog(Long itemUid,Long userId){ - List list = getHibernateTemplate().find(FIND_BY_ITEM_AND_USER,new Object[]{userId,itemUid}); - if(list == null || list.size() ==0) - return null; - return (ImageGalleryItemVisitLog) list.get(0); - } + private static final String FIND_BY_ITEM_BYSESSION = "from " + ImageGalleryItemVisitLog.class.getName() + + " as r where r.sessionId = ? and r.imageGalleryItem.uid=?"; - public int getUserViewLogCount(Long toolSessionId ,Long userUid) { - List list = getHibernateTemplate().find(FIND_VIEW_COUNT_BY_USER,new Object[]{toolSessionId, userUid}); - if(list == null || list.size() ==0) - return 0; - return ((Number) list.get(0)).intValue(); - } + private static final String FIND_VIEW_COUNT_BY_USER = "select count(*) from " + + ImageGalleryItemVisitLog.class.getName() + " as r where r.sessionId=? and r.user.userId =?"; - public Map getSummary(Long contentId) { + private static final String FIND_SUMMARY = "select v.imageGalleryItem.uid, count(v.imageGalleryItem) from " + + ImageGalleryItemVisitLog.class.getName() + " as v , " + ImageGallerySession.class.getName() + " as s, " + + ImageGallery.class.getName() + " as r " + " where v.sessionId = s.sessionId " + + " and s.imageGallery.uid = r.uid " + " and r.contentId =? " + + " group by v.sessionId, v.imageGalleryItem.uid "; - // Note: Hibernate 3.1 query.uniqueResult() returns Integer, Hibernate 3.2 query.uniqueResult() returns Long - List result = getHibernateTemplate().find(FIND_SUMMARY,contentId); - Map summaryList = new HashMap (result.size()); - for(Object[] list : result){ - if ( list[1] != null ) { - summaryList.put((Long)list[0],new Integer(((Number)list[1]).intValue())); - } - } - return summaryList; - - } + public ImageGalleryItemVisitLog getImageGalleryItemLog(Long itemUid, Long userId) { + List list = getHibernateTemplate().find(FIND_BY_ITEM_AND_USER, new Object[] { userId, itemUid }); + if (list == null || list.size() == 0) + return null; + return (ImageGalleryItemVisitLog) list.get(0); + } - public List getImageGalleryItemLogBySession(Long sessionId, Long itemUid) { - - return getHibernateTemplate().find(FIND_BY_ITEM_BYSESSION,new Object[]{sessionId,itemUid}); + public int getUserViewLogCount(Long toolSessionId, Long userUid) { + List list = getHibernateTemplate().find(FIND_VIEW_COUNT_BY_USER, new Object[] { toolSessionId, userUid }); + if (list == null || list.size() == 0) + return 0; + return ((Number) list.get(0)).intValue(); + } + + public Map getSummary(Long contentId) { + + // Note: Hibernate 3.1 query.uniqueResult() returns Integer, Hibernate 3.2 query.uniqueResult() returns Long + List result = getHibernateTemplate().find(FIND_SUMMARY, contentId); + Map summaryList = new HashMap(result.size()); + for (Object[] list : result) { + if (list[1] != null) { + summaryList.put((Long) list[0], new Integer(((Number) list[1]).intValue())); + } } + return summaryList; + } + + public List getImageGalleryItemLogBySession(Long sessionId, Long itemUid) { + + return getHibernateTemplate().find(FIND_BY_ITEM_BYSESSION, new Object[] { sessionId, itemUid }); + } + } Index: lams_tool_images/src/java/org/lamsfoundation/lams/tool/imageGallery/dao/hibernate/ImageRatingDAOHibernate.java =================================================================== diff -u --- lams_tool_images/src/java/org/lamsfoundation/lams/tool/imageGallery/dao/hibernate/ImageRatingDAOHibernate.java (revision 0) +++ lams_tool_images/src/java/org/lamsfoundation/lams/tool/imageGallery/dao/hibernate/ImageRatingDAOHibernate.java (revision 5d9ada1b3b139591dc6f1fffec04990beb727522) @@ -0,0 +1,49 @@ +/**************************************************************** + * Copyright (C) 2005 LAMS Foundation (http://lamsfoundation.org) + * ============================================================= + * License Information: http://lamsfoundation.org/licensing/lams/2.0/ + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2.0 + * as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 * USA + * + * http://www.gnu.org/licenses/gpl.txt + * **************************************************************** + */ + +/* $Id$ */ +package org.lamsfoundation.lams.tool.imageGallery.dao.hibernate; + +import java.util.List; + +import org.lamsfoundation.lams.tool.imageGallery.dao.ImageRatingDAO; +import org.lamsfoundation.lams.tool.imageGallery.model.ImageRating; + +/** + * Hibernate implementation of ImageCommentDAO. + * + * @author Andrey Balan + * @see org.lamsfoundation.lams.tool.imageGallery.dao.ImageCommentDAO + */ +public class ImageRatingDAOHibernate extends BaseDAOHibernate implements ImageRatingDAO { + + private static final String FIND_BY_IMAGE_AND_USER = "from " + ImageRating.class.getName() + + " as r where r.createBy.userId = ? and r.imageGalleryItem.uid=?"; + + public ImageRating getImageRatingByImageAndUser(Long imageUid, Long userId) { + List list = getHibernateTemplate().find(FIND_BY_IMAGE_AND_USER, new Object[] { userId, imageUid }); + if (list == null || list.size() == 0) + return null; + return (ImageRating) list.get(0); + } + +} Index: lams_tool_images/src/java/org/lamsfoundation/lams/tool/imageGallery/imageGalleryApplicationContext.xml =================================================================== diff -u -rfd6a44adca1e0d4ee031b0b8b442de4ee8974d74 -r5d9ada1b3b139591dc6f1fffec04990beb727522 --- lams_tool_images/src/java/org/lamsfoundation/lams/tool/imageGallery/imageGalleryApplicationContext.xml (.../imageGalleryApplicationContext.xml) (revision fd6a44adca1e0d4ee031b0b8b442de4ee8974d74) +++ lams_tool_images/src/java/org/lamsfoundation/lams/tool/imageGallery/imageGalleryApplicationContext.xml (.../imageGalleryApplicationContext.xml) (revision 5d9ada1b3b139591dc6f1fffec04990beb727522) @@ -22,7 +22,8 @@ org/lamsfoundation/lams/tool/imageGallery/model/ImageGalleryUser.hbm.xml org/lamsfoundation/lams/tool/imageGallery/model/ImageGallery.hbm.xml org/lamsfoundation/lams/tool/imageGallery/model/ImageGalleryItem.hbm.xml - org/lamsfoundation/lams/tool/imageGallery/model/ImageComment.hbm.xml + org/lamsfoundation/lams/tool/imageGallery/model/ImageComment.hbm.xml + org/lamsfoundation/lams/tool/imageGallery/model/ImageRating.hbm.xml org/lamsfoundation/lams/tool/imageGallery/model/ImageGalleryItemVisitLog.hbm.xml org/lamsfoundation/lams/tool/imageGallery/model/ImageGalleryAttachment.hbm.xml org/lamsfoundation/lams/tool/imageGallery/model/ImageGallerySession.hbm.xml @@ -46,7 +47,12 @@ - + + + + + + @@ -90,6 +96,12 @@ + + + + + + Index: lams_tool_images/src/java/org/lamsfoundation/lams/tool/imageGallery/model/ImageComment.java =================================================================== diff -u -rfd6a44adca1e0d4ee031b0b8b442de4ee8974d74 -r5d9ada1b3b139591dc6f1fffec04990beb727522 --- lams_tool_images/src/java/org/lamsfoundation/lams/tool/imageGallery/model/ImageComment.java (.../ImageComment.java) (revision fd6a44adca1e0d4ee031b0b8b442de4ee8974d74) +++ lams_tool_images/src/java/org/lamsfoundation/lams/tool/imageGallery/model/ImageComment.java (.../ImageComment.java) (revision 5d9ada1b3b139591dc6f1fffec04990beb727522) @@ -87,6 +87,18 @@ // ********************************************************** /** + * @hibernate.id generator-class="native" type="java.lang.Long" column="uid" + * @return Returns the log Uid. + */ + public Long getUid() { + return uid; + } + + public void setUid(Long uid) { + this.uid = uid; + } + + /** * @hibernate.property column="create_date" * @return */ @@ -99,18 +111,6 @@ } /** - * @hibernate.id generator-class="native" type="java.lang.Long" column="uid" - * @return Returns the log Uid. - */ - public Long getUid() { - return uid; - } - - public void setUid(Long uid) { - this.uid = uid; - } - - /** * @hibernate.many-to-one column="create_by" cascade="none" * @return */ Index: lams_tool_images/src/java/org/lamsfoundation/lams/tool/imageGallery/model/ImageGallery.hbm.xml =================================================================== diff -u -r8a7c47632a6a93892f015f068d12adb376c0ae2d -r5d9ada1b3b139591dc6f1fffec04990beb727522 --- lams_tool_images/src/java/org/lamsfoundation/lams/tool/imageGallery/model/ImageGallery.hbm.xml (.../ImageGallery.hbm.xml) (revision 8a7c47632a6a93892f015f068d12adb376c0ae2d) +++ lams_tool_images/src/java/org/lamsfoundation/lams/tool/imageGallery/model/ImageGallery.hbm.xml (.../ImageGallery.hbm.xml) (revision 5d9ada1b3b139591dc6f1fffec04990beb727522) @@ -205,6 +205,14 @@ /> + + getOfflineFileList() { return offlineFileList; } Index: lams_tool_images/src/java/org/lamsfoundation/lams/tool/imageGallery/model/ImageGalleryItem.hbm.xml =================================================================== diff -u -rcfd6a77839edfa64b3e7d320a6d9ed85e9c99f9a -r5d9ada1b3b139591dc6f1fffec04990beb727522 --- lams_tool_images/src/java/org/lamsfoundation/lams/tool/imageGallery/model/ImageGalleryItem.hbm.xml (.../ImageGalleryItem.hbm.xml) (revision cfd6a77839edfa64b3e7d320a6d9ed85e9c99f9a) +++ lams_tool_images/src/java/org/lamsfoundation/lams/tool/imageGallery/model/ImageGalleryItem.hbm.xml (.../ImageGalleryItem.hbm.xml) (revision 5d9ada1b3b139591dc6f1fffec04990beb727522) @@ -152,6 +152,22 @@ + + + + + + + + + + + + + + + + + + Index: lams_tool_images/src/java/org/lamsfoundation/lams/tool/imageGallery/model/ImageRating.java =================================================================== diff -u --- lams_tool_images/src/java/org/lamsfoundation/lams/tool/imageGallery/model/ImageRating.java (revision 0) +++ lams_tool_images/src/java/org/lamsfoundation/lams/tool/imageGallery/model/ImageRating.java (revision 5d9ada1b3b139591dc6f1fffec04990beb727522) @@ -0,0 +1,139 @@ +/**************************************************************** + * Copyright (C) 2005 LAMS Foundation (http://lamsfoundation.org) + * ============================================================= + * License Information: http://lamsfoundation.org/licensing/lams/2.0/ + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2.0 + * as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 * USA + * + * http://www.gnu.org/licenses/gpl.txt + * **************************************************************** + */ + +/* $Id$ */ +package org.lamsfoundation.lams.tool.imageGallery.model; + +import java.util.Date; + +import org.apache.commons.lang.builder.EqualsBuilder; +import org.apache.commons.lang.builder.HashCodeBuilder; +import org.apache.log4j.Logger; + +/** + * ImageRating + * + * @author Andrey Balan + * + * @hibernate.class table="tl_laimag10_image_rating" + */ +public class ImageRating implements Cloneable { + + private static final Logger log = Logger.getLogger(ImageRating.class); + + private Long uid; + private int rating; + private ImageGalleryUser createBy; + private ImageGalleryItem imageGalleryItem; + + // ********************************************************** + // Function method for ImageRating + // ********************************************************** + + public Object clone() { + ImageRating imageComment = null; + try { + imageComment = (ImageRating) super.clone(); + ((ImageRating) imageComment).setUid(null); + + // clone ImageGalleryUser as well + if (this.createBy != null) { + imageComment.setCreateBy((ImageGalleryUser) this.createBy.clone()); + } + } catch (CloneNotSupportedException e) { + log.error("When clone " + ImageRating.class + " failed"); + } + + return imageComment; + } + + public boolean equals(Object o) { + if (this == o) + return true; + if (!(o instanceof ImageRating)) + return false; + + final ImageRating genericEntity = (ImageRating) o; + + return new EqualsBuilder().append(this.uid, genericEntity.uid).append(this.rating, genericEntity.rating) + .append(this.createBy, genericEntity.createBy).isEquals(); + } + + public int hashCode() { + return new HashCodeBuilder().append(uid).append(rating).append(createBy).toHashCode(); + } + + // ********************************************************** + // Get/Set methods + // ********************************************************** + + /** + * @hibernate.id generator-class="native" type="java.lang.Long" column="uid" + * @return Returns the log Uid. + */ + public Long getUid() { + return uid; + } + + public void setUid(Long uid) { + this.uid = uid; + } + + /** + * @hibernate.many-to-one column="create_by" cascade="none" + * @return + */ + public ImageGalleryUser getCreateBy() { + return createBy; + } + + public void setCreateBy(ImageGalleryUser createBy) { + this.createBy = createBy; + } + + /** + * @hibernate.property column="rating" + * @return + */ + public int getRating() { + return rating; + } + + public void setRating(int rating) { + this.rating = rating; + } + + /** + * @hibernate.many-to-one column="imageGallery_item_uid" cascade="none" + * @return + */ + public ImageGalleryItem getImageGalleryItem() { + return imageGalleryItem; + } + + public void setImageGalleryItem(ImageGalleryItem item) { + this.imageGalleryItem = item; + } + +} + + \ No newline at end of file Index: lams_tool_images/src/java/org/lamsfoundation/lams/tool/imageGallery/service/IImageGalleryService.java =================================================================== diff -u -rfd6a44adca1e0d4ee031b0b8b442de4ee8974d74 -r5d9ada1b3b139591dc6f1fffec04990beb727522 --- lams_tool_images/src/java/org/lamsfoundation/lams/tool/imageGallery/service/IImageGalleryService.java (.../IImageGalleryService.java) (revision fd6a44adca1e0d4ee031b0b8b442de4ee8974d74) +++ lams_tool_images/src/java/org/lamsfoundation/lams/tool/imageGallery/service/IImageGalleryService.java (.../IImageGalleryService.java) (revision 5d9ada1b3b139591dc6f1fffec04990beb727522) @@ -39,6 +39,7 @@ import org.lamsfoundation.lams.tool.imageGallery.model.ImageGalleryItem; import org.lamsfoundation.lams.tool.imageGallery.model.ImageGallerySession; import org.lamsfoundation.lams.tool.imageGallery.model.ImageGalleryUser; +import org.lamsfoundation.lams.tool.imageGallery.model.ImageRating; /** * @author Dapeng.Ni @@ -48,14 +49,6 @@ public interface IImageGalleryService { /** - * Get ImageGallery by toolContentID. - * - * @param contentId - * @return - */ - ImageGallery getImageGalleryByContentId(Long contentId); - - /** * Get a cloned copy of tool default tool content (ImageGallery) and assign the toolContentId of that copy as the * given contentId * @@ -159,6 +152,16 @@ * @return */ void saveOrUpdateImageGalleryItem(ImageGalleryItem item); + + /** + * Save/update ImageRating. + * + * @param rating + * ImageRating + * @return + */ + void saveOrUpdateImageRating(ImageRating rating); + /** * Get imageGallery which is relative with the special toolSession. @@ -175,6 +178,23 @@ * @return */ ImageGallerySession getImageGallerySessionBySessionId(Long sessionId); + + /** + * Get ImageGallery by toolContentID. + * + * @param contentId + * @return + */ + ImageGallery getImageGalleryByContentId(Long contentId); + + /** + * Returns imageRating by the given imageUid and userId + * + * @param imageUid + * @param userId + * @return + */ + ImageRating getImageRatingByImageAndUser(Long imageUid, Long userId); /** * Save or update imageGallery session. Index: lams_tool_images/src/java/org/lamsfoundation/lams/tool/imageGallery/service/ImageGalleryServiceImpl.java =================================================================== diff -u -rfd6a44adca1e0d4ee031b0b8b442de4ee8974d74 -r5d9ada1b3b139591dc6f1fffec04990beb727522 --- lams_tool_images/src/java/org/lamsfoundation/lams/tool/imageGallery/service/ImageGalleryServiceImpl.java (.../ImageGalleryServiceImpl.java) (revision fd6a44adca1e0d4ee031b0b8b442de4ee8974d74) +++ lams_tool_images/src/java/org/lamsfoundation/lams/tool/imageGallery/service/ImageGalleryServiceImpl.java (.../ImageGalleryServiceImpl.java) (revision 5d9ada1b3b139591dc6f1fffec04990beb727522) @@ -90,6 +90,7 @@ import org.lamsfoundation.lams.tool.imageGallery.dao.ImageGalleryItemVisitDAO; import org.lamsfoundation.lams.tool.imageGallery.dao.ImageGallerySessionDAO; import org.lamsfoundation.lams.tool.imageGallery.dao.ImageGalleryUserDAO; +import org.lamsfoundation.lams.tool.imageGallery.dao.ImageRatingDAO; import org.lamsfoundation.lams.tool.imageGallery.dto.ReflectDTO; import org.lamsfoundation.lams.tool.imageGallery.dto.Summary; import org.lamsfoundation.lams.tool.imageGallery.model.ImageGallery; @@ -99,9 +100,11 @@ import org.lamsfoundation.lams.tool.imageGallery.model.ImageGalleryItemVisitLog; import org.lamsfoundation.lams.tool.imageGallery.model.ImageGallerySession; import org.lamsfoundation.lams.tool.imageGallery.model.ImageGalleryUser; +import org.lamsfoundation.lams.tool.imageGallery.model.ImageRating; import org.lamsfoundation.lams.tool.imageGallery.util.CircularByteBuffer; import org.lamsfoundation.lams.tool.imageGallery.util.ImageGalleryToolContentHandler; import org.lamsfoundation.lams.tool.imageGallery.util.ReflectDTOComparator; +import org.lamsfoundation.lams.tool.imageGallery.util.ResizePictureUtil; import org.lamsfoundation.lams.tool.service.ILamsToolService; import org.lamsfoundation.lams.usermanagement.User; import org.lamsfoundation.lams.usermanagement.dto.UserDTO; @@ -123,17 +126,19 @@ private ImageGalleryDAO imageGalleryDao; private ImageGalleryItemDAO imageGalleryItemDao; - + private ImageCommentDAO imageCommentDao; - + + private ImageRatingDAO imageRatingDao; + private ImageGalleryAttachmentDAO imageGalleryAttachmentDao; private ImageGalleryUserDAO imageGalleryUserDao; private ImageGallerySessionDAO imageGallerySessionDao; private ImageGalleryItemVisitDAO imageGalleryItemVisitDao; - + private ImageGalleryConfigItemDAO imageGalleryConfigItemDAO; // tool service @@ -157,7 +162,7 @@ private ICoreNotebookService coreNotebookService; private IEventNotificationService eventNotificationService; - + // ******************************************************************************* // Service method // ******************************************************************************* @@ -245,7 +250,7 @@ // save default content by given ID. ImageGallery content = new ImageGallery(); content = ImageGallery.newInstance(defaultContent, contentId, imageGalleryToolContentHandler); -// content.setNextImageTitle(new Long(1)); + // content.setNextImageTitle(new Long(1)); return content; } @@ -305,10 +310,14 @@ } - public void saveOrUpdateImageGalleryItem(ImageGalleryItem item) { - imageGalleryItemDao.saveObject(item); + public void saveOrUpdateImageGalleryItem(ImageGalleryItem image) { + imageGalleryItemDao.saveObject(image); } + public void saveOrUpdateImageRating(ImageRating rating) { + imageRatingDao.saveObject(rating); + } + public void deleteImageGalleryItem(Long uid) { imageGalleryItemDao.removeObject(ImageGalleryItem.class, uid); } @@ -330,6 +339,10 @@ return items; } + public ImageRating getImageRatingByImageAndUser(Long imageUid, Long userId) { + return imageRatingDao.getImageRatingByImageAndUser(imageUid, userId); + } + public List exportBySessionId(Long sessionId, boolean skipHide) { ImageGallerySession session = imageGallerySessionDao.getSessionBySessionId(sessionId); if (session == null) { @@ -649,32 +662,49 @@ return contentId; } - public void uploadImageGalleryItemFile(ImageGalleryItem image, FormFile file) throws UploadImageGalleryFileException { + public void uploadImageGalleryItemFile(ImageGalleryItem image, FormFile file) + throws UploadImageGalleryFileException { + try { + // upload file + NodeKey nodeKey = uploadFormFile(file, IToolContentHandler.TYPE_ONLINE); + image.setFileName(file.getFileName()); + image.setFileType(file.getContentType()); + image.setFileVersionId(nodeKey.getVersion()); + image.setOriginalFileUuid(nodeKey.getUuid()); - // upload file - NodeKey nodeKey = uploadFormFile(file, IToolContentHandler.TYPE_ONLINE); - image.setFileName(file.getFileName()); - image.setFileType(file.getContentType()); - image.setFileVersionId(nodeKey.getVersion()); - image.setOriginalFileUuid(nodeKey.getUuid()); + String fileName = file.getFileName(); + + ImageGalleryConfigItem mediumImageDimensionsKey = getConfigItem(ImageGalleryConfigItem.KEY_MEDIUM_IMAGE_DIMENSIONS); + int mediumImageDimensions = Integer.parseInt(mediumImageDimensionsKey.getConfigValue()); - ImageGalleryConfigItem mediumImageDimensionsKey = getConfigItem(ImageGalleryConfigItem.KEY_MEDIUM_IMAGE_DIMENSIONS); - int mediumImageDimensions = 640; - if (mediumImageDimensionsKey != null && mediumImageDimensionsKey.getConfigValue() != null) { - mediumImageDimensions = Integer.parseInt(mediumImageDimensionsKey.getConfigValue()); - } - NodeKey mediumNodeKey = createScaledImage(nodeKey, "medium_" + file.getFileName(), file.getContentType(), mediumImageDimensions); - image.setMediumFileUuid(mediumNodeKey.getUuid()); + // Read the original image from the repository + InputStream originalIS = imageGalleryToolContentHandler.getFileNode(nodeKey.getUuid()).getFile(); + InputStream mediumIS = ResizePictureUtil.resizePicture(originalIS, mediumImageDimensions); + String mediumFileName = "medium_" + fileName.substring(0, fileName.indexOf('.')) + ".jpg"; + NodeKey mediumNodeKey = imageGalleryToolContentHandler.uploadFile(mediumIS, mediumFileName, + file.getContentType(), IToolContentHandler.TYPE_ONLINE); + image.setMediumFileUuid(mediumNodeKey.getUuid()); + + ImageGalleryConfigItem thumbnailImageDimensionsKey = getConfigItem(ImageGalleryConfigItem.KEY_THUMBNAIL_IMAGE_DIMENSIONS); + int thumbnailImageDimensions = Integer.parseInt(thumbnailImageDimensionsKey.getConfigValue()); - ImageGalleryConfigItem thumbnailImageDimensionsKey = getConfigItem(ImageGalleryConfigItem.KEY_THUMBNAIL_IMAGE_DIMENSIONS); - int thumbnailImageDimensions = 80; - if (thumbnailImageDimensionsKey != null && thumbnailImageDimensionsKey.getConfigValue() != null) { - thumbnailImageDimensions = Integer.parseInt(thumbnailImageDimensionsKey.getConfigValue()); + // Read the original image from the repository + InputStream mediumIS2 = imageGalleryToolContentHandler.getFileNode(mediumNodeKey.getUuid()).getFile(); + InputStream thumbnailIS = ResizePictureUtil.resizePicture(mediumIS2, thumbnailImageDimensions); + String thumbnailFileName = "thumbnail_" + fileName.substring(0, fileName.indexOf('.')) + ".jpg"; + NodeKey thumbnailNodeKey = imageGalleryToolContentHandler.uploadFile(thumbnailIS, thumbnailFileName, + file.getContentType(), IToolContentHandler.TYPE_ONLINE); + image.setThumbnailFileUuid(thumbnailNodeKey.getUuid()); + + } catch (RepositoryCheckedException e) { + ImageGalleryServiceImpl.log.error(messageService.getMessage("error.msg.repository.checked.exception") + ":" + e.toString()); + throw new UploadImageGalleryFileException(messageService.getMessage("error.msg.repository.checked.exception")); + } catch (NumberFormatException e) { + ImageGalleryServiceImpl.log.error(messageService.getMessage("error.msg.number.format.exception") + ":" + e.toString()); + throw new UploadImageGalleryFileException(messageService.getMessage("error.msg.number.format.exception")); } - NodeKey thumbnailNodeKey = createScaledImage(mediumNodeKey, "thumbnail_" + file.getFileName(), file.getContentType(), thumbnailImageDimensions); - image.setThumbnailFileUuid(thumbnailNodeKey.getUuid()); } - + /** * Process an uploaded file. * @@ -704,144 +734,6 @@ throw new UploadImageGalleryFileException(messageService.getMessage("error.msg.io.exception")); } return node; - } - - /** - * Reads an image in a file and creates a thumbnail in another file. - * - * @param orig - * The name of image file. - * @param thumb - * The name of thumbnail file. Will be created if necessary. - * @param maxDim - * The width and height of the thumbnail must be maxDim pixels or less. - * @throws UploadImageGalleryFileException - */ - /** - * Reads an image in a file and creates a thumbnail in another file. largestDimension is the largest dimension of - * the thumbnail, the other dimension is scaled accordingly. Utilises weighted stepping method to gradually reduce - * the image size for better results, i.e. larger steps to start with then smaller steps to finish with. Note: - * always writes a JPEG because GIF is protected or something - so always make your outFilename end in 'jpg' PNG's - * with transparency are given white backgrounds - */ - private NodeKey createScaledImage(NodeKey nodeKey, String fileName, String contentType, int largestDimension) - throws UploadImageGalleryFileException { - NodeKey scaledNodeKey = null; - try { - double scale; - int sizeDifference, originalImageLargestDim; - - // Read the original image from the repository - InputStream is = imageGalleryToolContentHandler.getFileNode(nodeKey.getUuid()).getFile(); - BufferedImage inImage = ImageIO.read(is); - - // find biggest dimension - if (inImage.getWidth(null) > inImage.getHeight(null)) { - scale = (double) largestDimension / (double) inImage.getWidth(null); - sizeDifference = inImage.getWidth(null) - largestDimension; - originalImageLargestDim = inImage.getWidth(null); - } else { - scale = (double) largestDimension / (double) inImage.getHeight(null); - sizeDifference = inImage.getHeight(null) - largestDimension; - originalImageLargestDim = inImage.getHeight(null); - } - // create an image buffer to draw to - BufferedImage outImage = new BufferedImage(100, 100, BufferedImage.TYPE_INT_RGB); // arbitrary init so - // code compiles - Graphics2D g2d; - AffineTransform tx; - if (scale < 1.0d) // only scale if desired size is smaller than original - { - int numSteps = ((sizeDifference / 200) != 0) ? (sizeDifference / 200) : 1; - int stepSize = sizeDifference / numSteps; - int stepWeight = stepSize / 2; - int heavierStepSize = stepSize + stepWeight; - int lighterStepSize = stepSize - stepWeight; - int currentStepSize, centerStep; - double scaledW = inImage.getWidth(null); - double scaledH = inImage.getHeight(null); - if (numSteps % 2 == 1) { - centerStep = (int) Math.ceil(numSteps / 2d); // find the center step - } else { - centerStep = -1; // set it to -1 so it's ignored later - } - Integer intermediateSize = originalImageLargestDim, previousIntermediateSize = originalImageLargestDim; - Integer calculatedDim; - for (Integer i = 0; i < numSteps; i++) { - if (i + 1 != centerStep) // if this isn't the center step - { - if (i == numSteps - 1) // if this is the last step - { - // fix the stepsize to account for decimal place errors previously - currentStepSize = previousIntermediateSize - largestDimension; - } else { - if (numSteps - i > numSteps / 2) { - currentStepSize = heavierStepSize; - } else { - currentStepSize = lighterStepSize; - } - } - } else // center step, use natural step size - { - currentStepSize = stepSize; - } - intermediateSize = previousIntermediateSize - currentStepSize; - scale = (double) intermediateSize / (double) previousIntermediateSize; - scaledW = (int) scaledW * scale; - scaledH = (int) scaledH * scale; - outImage = new BufferedImage((int) scaledW, (int) scaledH, BufferedImage.TYPE_INT_RGB); - g2d = outImage.createGraphics(); - g2d.setBackground(Color.WHITE); - g2d.clearRect(0, 0, outImage.getWidth(), outImage.getHeight()); - g2d.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY); - g2d.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BICUBIC); - - tx = new AffineTransform(); - tx.scale(scale, scale); - g2d.drawImage(inImage, tx, null); - g2d.dispose(); - inImage = outImage; - previousIntermediateSize = intermediateSize; - } - } else { - // just copy the original - outImage = new BufferedImage(inImage.getWidth(null), inImage.getHeight(null), - BufferedImage.TYPE_INT_RGB); - g2d = outImage.createGraphics(); - g2d.setBackground(Color.WHITE); - g2d.clearRect(0, 0, outImage.getWidth(), outImage.getHeight()); - tx = new AffineTransform(); - tx.setToIdentity(); // use identity matrix so image is copied exactly - g2d.drawImage(inImage, tx, null); - g2d.dispose(); - } - - // buffer all data in a circular buffer of infinite size - CircularByteBuffer cbb = new CircularByteBuffer(CircularByteBuffer.INFINITE_SIZE); - ImageIO.write(outImage, "JPG", cbb.getOutputStream()); - cbb.getOutputStream().close(); - - scaledNodeKey = imageGalleryToolContentHandler.uploadFile(cbb.getInputStream(), fileName, contentType, - IToolContentHandler.TYPE_ONLINE); - - } catch (FileException e) { - ImageGalleryServiceImpl.log.error(messageService.getMessage("error.msg.file.exception") + ":" - + e.toString()); - throw new UploadImageGalleryFileException(messageService.getMessage("error.msg.file.exception")); - } catch (ItemNotFoundException e) { - ImageGalleryServiceImpl.log.error(messageService.getMessage("error.msg.item.not.found.exception") + ":" - + e.toString()); - throw new UploadImageGalleryFileException(messageService.getMessage("error.msg.item.not.found.exception")); - } catch (RepositoryCheckedException e) { - ImageGalleryServiceImpl.log.error(messageService.getMessage("error.msg.repository.checked.exception") + ":" - + e.toString()); - throw new UploadImageGalleryFileException(messageService - .getMessage("error.msg.repository.checked.exception")); - } catch (IOException e) { - ImageGalleryServiceImpl.log.error(messageService.getMessage("error.msg.io.exception") + ":" + e.toString()); - throw new UploadImageGalleryFileException(messageService.getMessage("error.msg.io.exception")); - } - return scaledNodeKey; } // ***************************************************************************** @@ -878,8 +770,11 @@ public void setImageCommentDao(ImageCommentDAO imageCommentDao) { this.imageCommentDao = imageCommentDao; } - + public void setImageRatingDao(ImageRatingDAO imageRatingDao) { + this.imageRatingDao = imageRatingDao; + } + public void setImageGallerySessionDao(ImageGallerySessionDAO imageGallerySessionDao) { this.imageGallerySessionDao = imageGallerySessionDao; } @@ -903,14 +798,14 @@ public void setImageGalleryItemVisitDao(ImageGalleryItemVisitDAO imageGalleryItemVisitDao) { this.imageGalleryItemVisitDao = imageGalleryItemVisitDao; } - + public ImageGalleryConfigItemDAO getImageGalleryConfigItemDAO() { return imageGalleryConfigItemDAO; } public void setImageGalleryConfigItemDAO(ImageGalleryConfigItemDAO imageGalleryConfigItemDAO) { this.imageGalleryConfigItemDAO = imageGalleryConfigItemDAO; - } + } // ******************************************************************************* // ToolContentManager, ToolSessionManager methods @@ -1132,7 +1027,8 @@ /** * Import the data for a 1.0.2 Noticeboard or HTMLNoticeboard */ - public void import102ToolContent(Long toolContentId, UserDTO user, Hashtable importValues) {} + public void import102ToolContent(Long toolContentId, UserDTO user, Hashtable importValues) { + } /** Set the description, throws away the title value as this is not supported in 2.0 */ public void setReflectiveData(Long toolContentId, String title, String description) throws ToolException, @@ -1192,6 +1088,6 @@ public void saveOrUpdateImageGalleryConfigItem(ImageGalleryConfigItem item) { imageGalleryConfigItemDAO.saveOrUpdate(item); - } + } } Fisheye: Tag 5d9ada1b3b139591dc6f1fffec04990beb727522 refers to a dead (removed) revision in file `lams_tool_images/src/java/org/lamsfoundation/lams/tool/imageGallery/util/ImageUtil.java'. Fisheye: No comparison available. Pass `N' to diff? Index: lams_tool_images/src/java/org/lamsfoundation/lams/tool/imageGallery/util/ResizePictureUtil.java =================================================================== diff -u --- lams_tool_images/src/java/org/lamsfoundation/lams/tool/imageGallery/util/ResizePictureUtil.java (revision 0) +++ lams_tool_images/src/java/org/lamsfoundation/lams/tool/imageGallery/util/ResizePictureUtil.java (revision 5d9ada1b3b139591dc6f1fffec04990beb727522) @@ -0,0 +1,164 @@ +/**************************************************************** + * Copyright (C) 2005 LAMS Foundation (http://lamsfoundation.org) + * ============================================================= + * License Information: http://lamsfoundation.org/licensing/lams/2.0/ + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2.0 + * as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 * USA + * + * http://www.gnu.org/licenses/gpl.txt + * **************************************************************** + */ + +/* $Id$ */ +package org.lamsfoundation.lams.tool.imageGallery.util; + +import java.awt.Color; +import java.awt.Graphics2D; +import java.awt.RenderingHints; +import java.awt.geom.AffineTransform; +import java.awt.image.BufferedImage; +import java.io.IOException; +import java.io.InputStream; + +import javax.imageio.ImageIO; + +import org.apache.log4j.Logger; + +/** + * @author Andrey Balan + */ +public class ResizePictureUtil { + + private static Logger log = Logger.getLogger(ResizePictureUtil.class); + + /** + * Reads the original image, creates a thumbnail and returns its input stream. + * largestDimension is the largest dimension of the thumbnail, the other dimension is scaled accordingly. Utilises + * weighted stepping method to gradually reduce the image size for better results, i.e. larger steps to start with + * then smaller steps to finish with. Note: always writes a JPEG because GIF is protected or something - so always + * make your outFilename end in 'jpg' PNG's with transparency are given white backgrounds + * + * @param is + * original image's input stream + * @param largestDimension + * the largest dimension of the thumbnail, the other dimension is scaled accordingly + * @return + * @throws UploadImageGalleryFileException + */ + public static InputStream resizePicture(InputStream is, int largestDimension) { + InputStream thumbnailInputStream = null; + try { + double scale; + int sizeDifference; + int originalImageLargestDim; + + BufferedImage inImage = ImageIO.read(is); + + // find biggest dimension + if (inImage.getWidth(null) > inImage.getHeight(null)) { + scale = (double) largestDimension / (double) inImage.getWidth(null); + sizeDifference = inImage.getWidth(null) - largestDimension; + originalImageLargestDim = inImage.getWidth(null); + } else { + scale = (double) largestDimension / (double) inImage.getHeight(null); + sizeDifference = inImage.getHeight(null) - largestDimension; + originalImageLargestDim = inImage.getHeight(null); + } + // create an image buffer to draw to + BufferedImage outImage = new BufferedImage(100, 100, BufferedImage.TYPE_INT_RGB); // arbitrary init so + // code compiles + Graphics2D g2d; + AffineTransform tx; + if (scale < 1.0d) // only scale if desired size is smaller than original + { + int numSteps = ((sizeDifference / 200) != 0) ? (sizeDifference / 200) : 1; + int stepSize = sizeDifference / numSteps; + int stepWeight = stepSize / 2; + int heavierStepSize = stepSize + stepWeight; + int lighterStepSize = stepSize - stepWeight; + int currentStepSize, centerStep; + double scaledW = inImage.getWidth(null); + double scaledH = inImage.getHeight(null); + if (numSteps % 2 == 1) { + centerStep = (int) Math.ceil(numSteps / 2d); // find the center step + } else { + centerStep = -1; // set it to -1 so it's ignored later + } + Integer intermediateSize = originalImageLargestDim, previousIntermediateSize = originalImageLargestDim; + Integer calculatedDim; + for (Integer i = 0; i < numSteps; i++) { + if (i + 1 != centerStep) // if this isn't the center step + { + if (i == numSteps - 1) // if this is the last step + { + // fix the stepsize to account for decimal place errors previously + currentStepSize = previousIntermediateSize - largestDimension; + } else { + if (numSteps - i > numSteps / 2) { + currentStepSize = heavierStepSize; + } else { + currentStepSize = lighterStepSize; + } + } + } else // center step, use natural step size + { + currentStepSize = stepSize; + } + intermediateSize = previousIntermediateSize - currentStepSize; + scale = (double) intermediateSize / (double) previousIntermediateSize; + scaledW = (int) scaledW * scale; + scaledH = (int) scaledH * scale; + outImage = new BufferedImage((int) scaledW, (int) scaledH, BufferedImage.TYPE_INT_RGB); + g2d = outImage.createGraphics(); + g2d.setBackground(Color.WHITE); + g2d.clearRect(0, 0, outImage.getWidth(), outImage.getHeight()); + g2d.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY); + g2d.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BICUBIC); + + tx = new AffineTransform(); + tx.scale(scale, scale); + g2d.drawImage(inImage, tx, null); + g2d.dispose(); + inImage = outImage; + previousIntermediateSize = intermediateSize; + } + } else { + // just copy the original + outImage = new BufferedImage(inImage.getWidth(null), inImage.getHeight(null), + BufferedImage.TYPE_INT_RGB); + g2d = outImage.createGraphics(); + g2d.setBackground(Color.WHITE); + g2d.clearRect(0, 0, outImage.getWidth(), outImage.getHeight()); + tx = new AffineTransform(); + tx.setToIdentity(); // use identity matrix so image is copied exactly + g2d.drawImage(inImage, tx, null); + g2d.dispose(); + } + + // buffer all data in a circular buffer of infinite size + CircularByteBuffer cbb = new CircularByteBuffer(CircularByteBuffer.INFINITE_SIZE); + ImageIO.write(outImage, "JPG", cbb.getOutputStream()); + cbb.getOutputStream().close(); + + thumbnailInputStream = cbb.getInputStream(); + + } catch (IOException e) { + ResizePictureUtil.log.error(e.getStackTrace()); + return null; + } + return thumbnailInputStream; + } + +} + \ No newline at end of file Index: lams_tool_images/src/java/org/lamsfoundation/lams/tool/imageGallery/web/action/LearningAction.java =================================================================== diff -u -rfd6a44adca1e0d4ee031b0b8b442de4ee8974d74 -r5d9ada1b3b139591dc6f1fffec04990beb727522 --- lams_tool_images/src/java/org/lamsfoundation/lams/tool/imageGallery/web/action/LearningAction.java (.../LearningAction.java) (revision fd6a44adca1e0d4ee031b0b8b442de4ee8974d74) +++ lams_tool_images/src/java/org/lamsfoundation/lams/tool/imageGallery/web/action/LearningAction.java (.../LearningAction.java) (revision 5d9ada1b3b139591dc6f1fffec04990beb727522) @@ -59,12 +59,14 @@ import org.lamsfoundation.lams.tool.imageGallery.model.ImageGalleryItem; import org.lamsfoundation.lams.tool.imageGallery.model.ImageGallerySession; import org.lamsfoundation.lams.tool.imageGallery.model.ImageGalleryUser; +import org.lamsfoundation.lams.tool.imageGallery.model.ImageRating; import org.lamsfoundation.lams.tool.imageGallery.service.IImageGalleryService; import org.lamsfoundation.lams.tool.imageGallery.service.UploadImageGalleryFileException; import org.lamsfoundation.lams.tool.imageGallery.util.ImageCommentComparator; import org.lamsfoundation.lams.tool.imageGallery.util.ImageGalleryItemComparator; import org.lamsfoundation.lams.tool.imageGallery.web.form.ImageCommentForm; import org.lamsfoundation.lams.tool.imageGallery.web.form.ImageGalleryItemForm; +import org.lamsfoundation.lams.tool.imageGallery.web.form.ImageRatingForm; import org.lamsfoundation.lams.tool.imageGallery.web.form.ReflectionForm; import org.lamsfoundation.lams.usermanagement.dto.UserDTO; import org.lamsfoundation.lams.util.FileUtil; @@ -107,12 +109,18 @@ } // ================ Comments ======================= - if (param.equals("showComments")) { - return showComments(mapping, form, request, response); + if (param.equals("loadImageData")) { + return loadImageData(mapping, form, request, response); } if (param.equals("addNewComment")) { return addNewComment(mapping, form, request, response); } + if (param.equals("saveOrUpdateRating")) { + return saveOrUpdateRating(mapping, form, request, response); + } + if (param.equals("vote")) { + return vote(mapping, form, request, response); + } // ================ Reflection ======================= if (param.equals("newReflection")) { @@ -389,29 +397,46 @@ return mapping.findForward(ImageGalleryConstants.SUCCESS); } - /** - * Move down current item. + * Sets Image data to session variable, to be shown on main learning page. * * @param mapping * @param form * @param request * @param response * @return */ - private ActionForward showComments(ActionMapping mapping, ActionForm form, HttpServletRequest request, + private ActionForward loadImageData(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) { // get back sessionMAP String sessionMapID = WebUtil.readStrParam(request, ImageGalleryConstants.ATTR_SESSION_MAP_ID); SessionMap sessionMap = (SessionMap) request.getSession().getAttribute(sessionMapID); - + Long sessionId = (Long) sessionMap.get(ImageGalleryConstants.ATTR_TOOL_SESSION_ID); + IImageGalleryService service = getImageGalleryService(); + ImageGallery imageGallery = service.getImageGalleryBySessionId(sessionId); + Long imageUid = new Long(request.getParameter(ImageGalleryConstants.PARAM_IMAGE_UID)); - ImageGalleryItem image = getImageGalleryService().getImageGalleryItemByUid(imageUid); - TreeSet comments = new TreeSet(new ImageCommentComparator()); - comments.addAll(image.getComments()); - sessionMap.put(ImageGalleryConstants.PARAM_COMMENTS, comments); + ImageGalleryItem image = service.getImageGalleryItemByUid(imageUid); sessionMap.put(ImageGalleryConstants.PARAM_CURRENT_IMAGE, image); + if (imageGallery.isAllowCommentImages()) { + TreeSet comments = new TreeSet(new ImageCommentComparator()); + comments.addAll(image.getComments()); + sessionMap.put(ImageGalleryConstants.PARAM_COMMENTS, comments); + } + + if (imageGallery.isAllowRank()) { + UserDTO user = (UserDTO) SessionManager.getSession().getAttribute(AttributeNames.USER); + ImageGalleryUser imageGalleryUser = service.getUserByIDAndSession(new Long(user.getUserID().intValue()),sessionId); + ImageRating imageRating = service.getImageRatingByImageAndUser(imageUid, imageGalleryUser.getUserId()); + int rating = (imageRating == null) ? 0 : imageRating.getRating(); + sessionMap.put(ImageGalleryConstants.PARAM_CURRENT_RATING, rating); + } + + if (imageGallery.isAllowVote()) { + sessionMap.put(ImageGalleryConstants.PARAM_VOTED_IMAGE_UID, imageGallery.getVotedImageUid()); + } + request.setAttribute(ImageGalleryConstants.ATTR_SESSION_MAP_ID, sessionMapID); return mapping.findForward(ImageGalleryConstants.SUCCESS); } @@ -429,25 +454,16 @@ HttpServletResponse response) { String sessionMapID = WebUtil.readStrParam(request, ImageGalleryConstants.ATTR_SESSION_MAP_ID); SessionMap sessionMap = (SessionMap) request.getSession().getAttribute(sessionMapID); - - Long sessionId = (Long) sessionMap.get(ImageGalleryConstants.ATTR_TOOL_SESSION_ID); - - String commentMessage = WebUtil.readStrParam(request, ImageGalleryConstants.ATTR_COMMENT); - if(commentMessage == null || StringUtils.isBlank(commentMessage)) - return mapping.findForward(ImageGalleryConstants.SUCCESS); + String commentMessage = WebUtil.readStrParam(request, ImageGalleryConstants.ATTR_COMMENT, true); - //TODO fix error system -// ActionErrors errors = validateImageGalleryItem(itemForm); -// if (!errors.isEmpty()) { -// ActionErrors errors = new ActionErrors(); -// errors.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage(ImageGalleryConstants.ERROR_MSG_FILE_BLANK)); -// -// this.addErrors(request, errors); -// return mapping.findForward("file"); -// } + if (StringUtils.isBlank(commentMessage)) { + ActionErrors errors = new ActionErrors(); + errors.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage(ImageGalleryConstants.ERROR_MSG_COMMENT_BLANK)); + this.addErrors(request, errors); + return mapping.findForward(ImageGalleryConstants.SUCCESS); + } - ImageComment comment = new ImageComment(); comment.setComment(commentMessage); UserDTO user = (UserDTO) SessionManager.getSession().getAttribute(AttributeNames.USER); @@ -463,21 +479,101 @@ dbComments.add(comment); service.saveOrUpdateImageGalleryItem(dbItem); -// //to make available new changes be visible in jsp page -// sessionMap.put(TaskListConstants.ATTR_TASK_LIST_ITEM, dbItem); - + //to make available new changes be visible in jsp page TreeSet comments = new TreeSet(new ImageCommentComparator()); comments.addAll(dbItem.getComments()); sessionMap.put(ImageGalleryConstants.PARAM_COMMENTS, comments); -// form.reset(mapping, request); + form.reset(mapping, request); request.setAttribute(ImageGalleryConstants.ATTR_SESSION_MAP_ID, sessionMapID); return mapping.findForward(ImageGalleryConstants.SUCCESS); } - + + /** + * Move down current item. + * + * @param mapping + * @param form + * @param request + * @param response + * @return + */ + private ActionForward saveOrUpdateRating(ActionMapping mapping, ActionForm form, HttpServletRequest request, + HttpServletResponse response) { + String sessionMapID = WebUtil.readStrParam(request, ImageGalleryConstants.ATTR_SESSION_MAP_ID); + SessionMap sessionMap = (SessionMap) request.getSession().getAttribute(sessionMapID); + Long sessionId = (Long) sessionMap.get(ImageGalleryConstants.ATTR_TOOL_SESSION_ID); + IImageGalleryService service = getImageGalleryService(); + int rating = NumberUtils.stringToInt(((ImageRatingForm)form).getRating()); + Long imageUid = new Long(request.getParameter(ImageGalleryConstants.PARAM_IMAGE_UID)); + UserDTO user = (UserDTO) SessionManager.getSession().getAttribute(AttributeNames.USER); + ImageGalleryUser imageGalleryUser = service.getUserByIDAndSession(new Long(user.getUserID().intValue()),sessionId); + ImageRating imageRating = service.getImageRatingByImageAndUser(imageUid, imageGalleryUser.getUserId()); + + //persist ImageGalleryItem changes in DB + ImageGalleryItem dbImage = service.getImageGalleryItemByUid(imageUid); + int numberRatings; + float summary; + if (imageRating == null) { + summary = dbImage.getAverageRating()*dbImage.getNumberRatings() + rating; + numberRatings = dbImage.getNumberRatings() + 1; + } else { + summary = dbImage.getAverageRating()*dbImage.getNumberRatings() + rating - imageRating.getRating(); + numberRatings = dbImage.getNumberRatings(); + } + float newAverageRating = summary / numberRatings; + + dbImage.setNumberRatings(numberRatings); + dbImage.setAverageRating(newAverageRating); + service.saveOrUpdateImageGalleryItem(dbImage); + + if (imageRating == null) { // add + imageRating = new ImageRating(); + imageRating.setCreateBy(imageGalleryUser); + imageRating.setImageGalleryItem(dbImage); + } + imageRating.setRating(rating); + service.saveOrUpdateImageRating(imageRating); + + //to make available new changes be visible in jsp page + sessionMap.put(ImageGalleryConstants.PARAM_CURRENT_IMAGE, dbImage); + sessionMap.put(ImageGalleryConstants.PARAM_CURRENT_RATING, rating); + + request.setAttribute(ImageGalleryConstants.ATTR_SESSION_MAP_ID, sessionMapID); + return mapping.findForward(ImageGalleryConstants.SUCCESS); + } + /** + * Move down current item. + * + * @param mapping + * @param form + * @param request + * @param response + * @return + */ + private ActionForward vote(ActionMapping mapping, ActionForm form, HttpServletRequest request, + HttpServletResponse response) { + String sessionMapID = WebUtil.readStrParam(request, ImageGalleryConstants.ATTR_SESSION_MAP_ID); + SessionMap sessionMap = (SessionMap) request.getSession().getAttribute(sessionMapID); + Long sessionId = (Long) sessionMap.get(ImageGalleryConstants.ATTR_TOOL_SESSION_ID); + IImageGalleryService service = getImageGalleryService(); + Long imageUid = new Long(request.getParameter(ImageGalleryConstants.PARAM_IMAGE_UID)); + + //persist ImageGalleryItem changes in DB + boolean vote = (((ImageRatingForm)form).getVote()); + Long votedImageUid = vote ? imageUid : 0; + ImageGallery imageGallery = service.getImageGalleryBySessionId(sessionId); + imageGallery.setVotedImageUid(votedImageUid); + service.saveOrUpdateImageGallery(imageGallery); + + request.setAttribute(ImageGalleryConstants.ATTR_SESSION_MAP_ID, sessionMapID); + return mapping.findForward(ImageGalleryConstants.SUCCESS); + } + + /** * Display empty reflection form. * * @param mapping Index: lams_tool_images/src/java/org/lamsfoundation/lams/tool/imageGallery/web/form/ImageCommentForm.java =================================================================== diff -u -rfd6a44adca1e0d4ee031b0b8b442de4ee8974d74 -r5d9ada1b3b139591dc6f1fffec04990beb727522 --- lams_tool_images/src/java/org/lamsfoundation/lams/tool/imageGallery/web/form/ImageCommentForm.java (.../ImageCommentForm.java) (revision fd6a44adca1e0d4ee031b0b8b442de4ee8974d74) +++ lams_tool_images/src/java/org/lamsfoundation/lams/tool/imageGallery/web/form/ImageCommentForm.java (.../ImageCommentForm.java) (revision 5d9ada1b3b139591dc6f1fffec04990beb727522) @@ -26,7 +26,10 @@ import java.util.Set; import java.util.TreeSet; +import javax.servlet.http.HttpServletRequest; + import org.apache.struts.action.ActionForm; +import org.apache.struts.action.ActionMapping; import org.apache.struts.upload.FormFile; import org.lamsfoundation.lams.tool.imageGallery.model.ImageComment; import org.lamsfoundation.lams.tool.imageGallery.model.ImageGalleryItem; @@ -45,6 +48,10 @@ private ImageGalleryItem image; private String sessionMapID; private String comment; + + public void reset(ActionMapping mapping, HttpServletRequest request){ + comment = ""; + } /** * Returns ImageGallery order index. Index: lams_tool_images/src/java/org/lamsfoundation/lams/tool/imageGallery/web/form/ImageRatingForm.java =================================================================== diff -u --- lams_tool_images/src/java/org/lamsfoundation/lams/tool/imageGallery/web/form/ImageRatingForm.java (revision 0) +++ lams_tool_images/src/java/org/lamsfoundation/lams/tool/imageGallery/web/form/ImageRatingForm.java (revision 5d9ada1b3b139591dc6f1fffec04990beb727522) @@ -0,0 +1,72 @@ +/**************************************************************** + * Copyright (C) 2005 LAMS Foundation (http://lamsfoundation.org) + * ============================================================= + * License Information: http://lamsfoundation.org/licensing/lams/2.0/ + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2.0 + * as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 * USA + * + * http://www.gnu.org/licenses/gpl.txt + * **************************************************************** + */ + +/* $Id$ */ +package org.lamsfoundation.lams.tool.imageGallery.web.form; + +import javax.servlet.http.HttpServletRequest; + +import org.apache.struts.action.ActionForm; +import org.apache.struts.action.ActionMapping; +import org.lamsfoundation.lams.tool.imageGallery.model.ImageGalleryItem; + +/** + * Image star rating Form. + * + * @struts.form name="imageRatingForm" + * @author Andrey Balan + */ +public class ImageRatingForm extends ActionForm { + + private static final long serialVersionUID = -8962161058929959289L; + + private String sessionMapID; + private String rating; + private boolean vote; + + public String getSessionMapID() { + return sessionMapID; + } + + public void setSessionMapID(String sessionMapID) { + this.sessionMapID = sessionMapID; + } + + public String getRating() { + return rating; + } + + public void setRating(String rating) { + this.rating = rating; + } + + public boolean getVote() { + return vote; + } + + public void setVote(boolean vote) { + this.vote = vote; + } +} + + + \ No newline at end of file Index: lams_tool_images/web/includes/css/jquery.rating.css =================================================================== diff -u -rfd6a44adca1e0d4ee031b0b8b442de4ee8974d74 -r5d9ada1b3b139591dc6f1fffec04990beb727522 --- lams_tool_images/web/includes/css/jquery.rating.css (.../jquery.rating.css) (revision fd6a44adca1e0d4ee031b0b8b442de4ee8974d74) +++ lams_tool_images/web/includes/css/jquery.rating.css (.../jquery.rating.css) (revision 5d9ada1b3b139591dc6f1fffec04990beb727522) @@ -1,10 +1,10 @@ /* jQuery.Rating Plugin CSS - http://www.fyneworks.com/jquery/star-rating/ */ div.rating{cursor:pointer;margin:2em;clear:both;display:block} div.rating:after{content:'.';display:block;height:0;width:0;clear:both;visibility:hidden} -div.cancel,div.star{float:left;width:17px;height:15px;text-indent:-999em;cursor:pointer;display:block;background:transparent;overflow:hidden} -div.cancel,div.cancel a{background:url('../images/delete.gif') no-repeat 0 -16px} +div.star{float:left;width:17px;height:15px;text-indent:-999em;cursor:pointer;display:block;background:transparent;overflow:hidden} +div.cancel,div.cancel a{display:none;background:url('../images/delete.gif') no-repeat 0 -16px} div.star,div.star a{background:url('../images/star.gif') no-repeat 0 0px} -div.cancel a,div.star a{display:block;width:16px;height:100%;background-position:0 0px;border:1 solid #FF0000} +div.star a{display:block;width:16px;height:100%;background-position:0 0px;border:1 solid #FF0000} div.star_on a{background-position:0 -16px!important} div.star_hover a,div.star_live a:hover{background-position:0 -32px} /* Read Only CSS */ Index: lams_tool_images/web/includes/javascript/jquery.form.js =================================================================== diff -u --- lams_tool_images/web/includes/javascript/jquery.form.js (revision 0) +++ lams_tool_images/web/includes/javascript/jquery.form.js (revision 5d9ada1b3b139591dc6f1fffec04990beb727522) @@ -0,0 +1,632 @@ +/* + * jQuery Form Plugin + * version: 2.17 (06-NOV-2008) + * @requires jQuery v1.2.2 or later + * + * Examples and documentation at: http://malsup.com/jquery/form/ + * Dual licensed under the MIT and GPL licenses: + * http://www.opensource.org/licenses/mit-license.php + * http://www.gnu.org/licenses/gpl.html + * + * Revision: $Id$ + */ +;(function($) { + +/* + Usage Note: + ----------- + Do not use both ajaxSubmit and ajaxForm on the same form. These + functions are intended to be exclusive. Use ajaxSubmit if you want + to bind your own submit handler to the form. For example, + + $(document).ready(function() { + $('#myForm').bind('submit', function() { + $(this).ajaxSubmit({ + target: '#output' + }); + return false; // <-- important! + }); + }); + + Use ajaxForm when you want the plugin to manage all the event binding + for you. For example, + + $(document).ready(function() { + $('#myForm').ajaxForm({ + target: '#output' + }); + }); + + When using ajaxForm, the ajaxSubmit function will be invoked for you + at the appropriate time. +*/ + +/** + * ajaxSubmit() provides a mechanism for immediately submitting + * an HTML form using AJAX. + */ +$.fn.ajaxSubmit = function(options) { + // fast fail if nothing selected (http://dev.jquery.com/ticket/2752) + if (!this.length) { + log('ajaxSubmit: skipping submit process - no element selected'); + return this; + } + + if (typeof options == 'function') + options = { success: options }; + + options = $.extend({ + url: this.attr('action') || window.location.toString(), + type: this.attr('method') || 'GET' + }, options || {}); + + // hook for manipulating the form data before it is extracted; + // convenient for use with rich editors like tinyMCE or FCKEditor + var veto = {}; + this.trigger('form-pre-serialize', [this, options, veto]); + if (veto.veto) { + log('ajaxSubmit: submit vetoed via form-pre-serialize trigger'); + return this; + } + + // provide opportunity to alter form data before it is serialized + if (options.beforeSerialize && options.beforeSerialize(this, options) === false) { + log('ajaxSubmit: submit aborted via beforeSerialize callback'); + return this; + } + + var a = this.formToArray(options.semantic); + if (options.data) { + options.extraData = options.data; + for (var n in options.data) { + if(options.data[n] instanceof Array) { + for (var k in options.data[n]) + a.push( { name: n, value: options.data[n][k] } ) + } + else + a.push( { name: n, value: options.data[n] } ); + } + } + + // give pre-submit callback an opportunity to abort the submit + if (options.beforeSubmit && options.beforeSubmit(a, this, options) === false) { + log('ajaxSubmit: submit aborted via beforeSubmit callback'); + return this; + } + + // fire vetoable 'validate' event + this.trigger('form-submit-validate', [a, this, options, veto]); + if (veto.veto) { + log('ajaxSubmit: submit vetoed via form-submit-validate trigger'); + return this; + } + + var q = $.param(a); + + if (options.type.toUpperCase() == 'GET') { + options.url += (options.url.indexOf('?') >= 0 ? '&' : '?') + q; + options.data = null; // data is null for 'get' + } + else + options.data = q; // data is the query string for 'post' + + var $form = this, callbacks = []; + if (options.resetForm) callbacks.push(function() { $form.resetForm(); }); + if (options.clearForm) callbacks.push(function() { $form.clearForm(); }); + + // perform a load on the target only if dataType is not provided + if (!options.dataType && options.target) { + var oldSuccess = options.success || function(){}; + callbacks.push(function(data) { + $(options.target).html(data).each(oldSuccess, arguments); + }); + } + else if (options.success) + callbacks.push(options.success); + + options.success = function(data, status) { + for (var i=0, max=callbacks.length; i < max; i++) + callbacks[i].apply(options, [data, status, $form]); + }; + + // are there files to upload? + var files = $('input:file', this).fieldValue(); + var found = false; + for (var j=0; j < files.length; j++) + if (files[j]) + found = true; + + // options.iframe allows user to force iframe mode + if (options.iframe || found) { + // hack to fix Safari hang (thanks to Tim Molendijk for this) + // see: http://groups.google.com/group/jquery-dev/browse_thread/thread/36395b7ab510dd5d + if ($.browser.safari && options.closeKeepAlive) + $.get(options.closeKeepAlive, fileUpload); + else + fileUpload(); + } + else + $.ajax(options); + + // fire 'notify' event + this.trigger('form-submit-notify', [this, options]); + return this; + + + // private function for handling file uploads (hat tip to YAHOO!) + function fileUpload() { + var form = $form[0]; + + if ($(':input[@name=submit]', form).length) { + alert('Error: Form elements must not be named "submit".'); + return; + } + + var opts = $.extend({}, $.ajaxSettings, options); + var s = jQuery.extend(true, {}, $.extend(true, {}, $.ajaxSettings), opts); + + var id = 'jqFormIO' + (new Date().getTime()); + var $io = $('