Index: lams_admin/conf/language/lams/ApplicationResources.properties =================================================================== diff -u -r0f432e857d0ba8120399d48306cf740f9b598522 -r009fbce36f45d0929f8007c4bbc798242f57d3af --- lams_admin/conf/language/lams/ApplicationResources.properties (.../ApplicationResources.properties) (revision 0f432e857d0ba8120399d48306cf740f9b598522) +++ lams_admin/conf/language/lams/ApplicationResources.properties (.../ApplicationResources.properties) (revision 009fbce36f45d0929f8007c4bbc798242f57d3af) @@ -444,6 +444,21 @@ message.check.to.add.monitor =Check the box of each monitor to add as staff to each of the new lessons. label.return.to.group =Return to group config.show.all.my.lesson.link =Show All My Lesson link +admin.timezone.title =Timezone Management +admin.timezone.available.timezones =Available timezones +admin.timezone.select.timezones.you.want.users.choose =Select the timezones you want the users for choose from. The server timezone is: +admin.timezone.select =Select +admin.timezone.time.zone.id =Time zone ID +admin.timezone.raw.offset =Raw offset (Hours : Minutes) +admin.timezone.dst.offset =DST offset (Minutes) +admin.timezone.display.name =Display name +admin.servertimezone.title =Server Timezone Management +admin.servertimezone.server.timezone.management =Server Timezone Management +admin.servertimezone.select.server.timezone =Please, select server timezone +admin.servertimezone.raw.offset =Raw offset: {0} +admin.servertimezone.dst.offset =DST offset: {0} +admin.servertimezone.name =Name: {0} +admin.servertimezone.select =Select #======= End labels: Exported 437 labels for en AU ===== Index: lams_admin/conf/xdoclet/struts-forms.xml =================================================================== diff -u -ra23376f298830f9cb4d3d18e5dc7ef11b907c173 -r009fbce36f45d0929f8007c4bbc798242f57d3af --- lams_admin/conf/xdoclet/struts-forms.xml (.../struts-forms.xml) (revision a23376f298830f9cb4d3d18e5dc7ef11b907c173) +++ lams_admin/conf/xdoclet/struts-forms.xml (.../struts-forms.xml) (revision 009fbce36f45d0929f8007c4bbc798242f57d3af) @@ -89,6 +89,12 @@ + + + + + + Index: lams_admin/src/java/org/lamsfoundation/lams/admin/service/AdminServiceProxy.java =================================================================== diff -u -r389bb9c0679d86c2446517dbe83a46b6ab5dc840 -r009fbce36f45d0929f8007c4bbc798242f57d3af --- lams_admin/src/java/org/lamsfoundation/lams/admin/service/AdminServiceProxy.java (.../AdminServiceProxy.java) (revision 389bb9c0679d86c2446517dbe83a46b6ab5dc840) +++ lams_admin/src/java/org/lamsfoundation/lams/admin/service/AdminServiceProxy.java (.../AdminServiceProxy.java) (revision 009fbce36f45d0929f8007c4bbc798242f57d3af) @@ -31,6 +31,7 @@ import org.lamsfoundation.lams.monitoring.service.IMonitoringService; import org.lamsfoundation.lams.statistics.service.IStatisticsService; import org.lamsfoundation.lams.themes.service.IThemeService; +import org.lamsfoundation.lams.timezone.service.ITimezoneService; import org.lamsfoundation.lams.usermanagement.service.IUserManagementService; import org.lamsfoundation.lams.usermanagement.service.LdapService; import org.lamsfoundation.lams.util.Configuration; @@ -58,6 +59,7 @@ private static ILessonService lessonService; private static IMonitoringService monitoringService; private static IEventNotificationService eventNotificationService; + private static ITimezoneService timezoneService; public static final IUserManagementService getService(ServletContext servletContext) { if (manageService == null) { @@ -148,4 +150,11 @@ WebApplicationContext wac = WebApplicationContextUtils.getRequiredWebApplicationContext(servletContext); return wac.getBean(serviceName); } + + public static final ITimezoneService getTimezoneService(ServletContext servletContext) { + if (timezoneService == null) { + timezoneService = (ITimezoneService)getDomainService(servletContext, "timezoneService"); + } + return timezoneService; + } } Index: lams_admin/src/java/org/lamsfoundation/lams/admin/web/UserAction.java =================================================================== diff -u -r800910cc549e3bdfdb72e8134956c5807a79ece9 -r009fbce36f45d0929f8007c4bbc798242f57d3af --- lams_admin/src/java/org/lamsfoundation/lams/admin/web/UserAction.java (.../UserAction.java) (revision 800910cc549e3bdfdb72e8134956c5807a79ece9) +++ lams_admin/src/java/org/lamsfoundation/lams/admin/web/UserAction.java (.../UserAction.java) (revision 009fbce36f45d0929f8007c4bbc798242f57d3af) @@ -27,6 +27,8 @@ import java.util.ArrayList; import java.util.Collections; import java.util.List; +import java.util.TimeZone; +import java.util.TreeSet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; @@ -42,6 +44,10 @@ import org.lamsfoundation.lams.admin.web.dto.UserOrgRoleDTO; import org.lamsfoundation.lams.themes.Theme; import org.lamsfoundation.lams.themes.service.IThemeService; +import org.lamsfoundation.lams.timezone.Timezone; +import org.lamsfoundation.lams.timezone.dto.TimezoneDTO; +import org.lamsfoundation.lams.timezone.service.ITimezoneService; +import org.lamsfoundation.lams.timezone.util.TimezoneDTOComparator; import org.lamsfoundation.lams.usermanagement.AuthenticationMethod; import org.lamsfoundation.lams.usermanagement.Organisation; import org.lamsfoundation.lams.usermanagement.OrganisationState; Index: lams_admin/src/java/org/lamsfoundation/lams/admin/web/action/SysAdminStartAction.java =================================================================== diff -u -rab19db088359a46353cc92e806c40ff5cff818b9 -r009fbce36f45d0929f8007c4bbc798242f57d3af --- lams_admin/src/java/org/lamsfoundation/lams/admin/web/action/SysAdminStartAction.java (.../SysAdminStartAction.java) (revision ab19db088359a46353cc92e806c40ff5cff818b9) +++ lams_admin/src/java/org/lamsfoundation/lams/admin/web/action/SysAdminStartAction.java (.../SysAdminStartAction.java) (revision 009fbce36f45d0929f8007c4bbc798242f57d3af) @@ -74,6 +74,7 @@ links.add(new LinkBean("libraryManage.do", "sysadmin.library.management")); links.add(new LinkBean("statistics.do", "admin.statistics.title")); links.add(new LinkBean("themeManagement.do", "admin.themes.title")); + links.add(new LinkBean("timezonemanagement.do", "admin.timezone.title")); OpenIDConfig openIDEnabled = (OpenIDConfig)service.findById(OpenIDConfig.class, OpenIDConfig.KEY_ENABLED); if (openIDEnabled != null && Boolean.parseBoolean(openIDEnabled.getConfigValue()) == Boolean.TRUE) { Index: lams_admin/src/java/org/lamsfoundation/lams/admin/web/action/TimezoneManagementAction.java =================================================================== diff -u --- lams_admin/src/java/org/lamsfoundation/lams/admin/web/action/TimezoneManagementAction.java (revision 0) +++ lams_admin/src/java/org/lamsfoundation/lams/admin/web/action/TimezoneManagementAction.java (revision 009fbce36f45d0929f8007c4bbc798242f57d3af) @@ -0,0 +1,165 @@ +/**************************************************************** + * 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.admin.web.action; + +import java.util.ArrayList; +import java.util.LinkedHashSet; +import java.util.List; +import java.util.TimeZone; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.apache.commons.collections.CollectionUtils; +import org.apache.struts.action.ActionForm; +import org.apache.struts.action.ActionForward; +import org.apache.struts.action.ActionMapping; +import org.apache.struts.action.DynaActionForm; +import org.lamsfoundation.lams.admin.service.AdminServiceProxy; +import org.lamsfoundation.lams.timezone.Timezone; +import org.lamsfoundation.lams.timezone.dto.TimezoneDTO; +import org.lamsfoundation.lams.timezone.service.ITimezoneService; +import org.lamsfoundation.lams.util.WebUtil; +import org.lamsfoundation.lams.web.action.LamsDispatchAction; + +/** + * Implements time zone manager. + * + * @author Andrey Balan + * + * @struts.action path="/timezonemanagement" parameter="method" name="TimezoneForm" input=".config" scope="request" + * validate="false" + * @struts.action-forward name="timezoneManagement" path=".timezoneManagement" + * @struts.action-forward name="timezoneServerManagement" path="/timezoneServerManagement.jsp" + * @struts.action-forward name="sysadmin" path="/sysadminstart.do" + */ +public class TimezoneManagementAction extends LamsDispatchAction { + + private final static String FORWARD_BACK = "sysadmin"; + private final static String FORWARD_TIMEZONE_MANAGEMENT = "timezoneManagement"; + private final static String FORWARD_SERVER_TIMEZONE_MANAGEMENT = "timezoneServerManagement"; + + private static ITimezoneService timezoneService; + + /** + * Displays list of all JRE available timezones. + */ + public ActionForward unspecified(ActionMapping mapping, ActionForm form, HttpServletRequest request, + HttpServletResponse response) throws Exception { + + timezoneService = AdminServiceProxy.getTimezoneService(getServlet().getServletContext()); + List defaultTimezones = timezoneService.getDefaultTimezones(); + + ArrayList timezoneDtos = new ArrayList(); + for (String availableTimezoneId : TimeZone.getAvailableIDs()) { + boolean isSelected = defaultTimezones.contains(new Timezone(availableTimezoneId)); + TimeZone timeZone = TimeZone.getTimeZone(availableTimezoneId); + TimezoneDTO timezoneDto = TimezoneDTO.createTimezoneDTO(timeZone, isSelected); + timezoneDtos.add(timezoneDto); + } + + request.setAttribute("timezoneDtos", timezoneDtos); + request.setAttribute("serverTimezone", timezoneService.getServerTimezone().getTimezoneId()); + + return mapping.findForward(FORWARD_TIMEZONE_MANAGEMENT); + } + + /** + * Makes selected timezones default ones. + * + * @param mapping + * @param form + * @param request + * @param response + * @return + * @throws Exception + */ + public ActionForward save(ActionMapping mapping, ActionForm form, HttpServletRequest request, + HttpServletResponse response) throws Exception { + + if (isCancelled(request)) { + return mapping.findForward(FORWARD_BACK); + } + + DynaActionForm timezoneForm = (DynaActionForm) form; + String[] selectedTimezoneIds = (String[]) timezoneForm.get("selected"); + + List selectedTimezones = new ArrayList(); + for (String selectedTimezoneId : selectedTimezoneIds) { + selectedTimezones.add(new Timezone(selectedTimezoneId)); + } + timezoneService.updateTimezones(selectedTimezones); + + return mapping.findForward(FORWARD_BACK); + } + + /** + * Shows page where admin can choose server timezone. + * + * @param mapping + * @param form + * @param request + * @param response + * @return + * @throws Exception + */ + public ActionForward serverTimezoneManagement(ActionMapping mapping, ActionForm form, HttpServletRequest request, + HttpServletResponse response) throws Exception { + + timezoneService = AdminServiceProxy.getTimezoneService(getServlet().getServletContext()); + + ArrayList timezoneDtos = new ArrayList(); + for (String availableTimezoneId : TimeZone.getAvailableIDs()) { + TimeZone timeZone = TimeZone.getTimeZone(availableTimezoneId); + TimezoneDTO timezoneDto = TimezoneDTO.createTimezoneDTO(timeZone, false); + timezoneDtos.add(timezoneDto); + } + + request.setAttribute("timezoneDtos", timezoneDtos); + request.setAttribute("serverTimezone", timezoneService.getServerTimezone().getTimezoneId()); + + return mapping.findForward(FORWARD_SERVER_TIMEZONE_MANAGEMENT); + } + + /** + * Changes server timezone with the one selected by user. + * + * @param mapping + * @param form + * @param request + * @param response + * @return + * @throws Exception + */ + public ActionForward changeServerTimezone(ActionMapping mapping, ActionForm form, HttpServletRequest request, + HttpServletResponse response) throws Exception { + timezoneService = AdminServiceProxy.getTimezoneService(getServlet().getServletContext()); + + String timeZoneId = WebUtil.readStrParam(request, "timeZoneId"); + timezoneService.setServerTimezone(timeZoneId); + + return unspecified(mapping, form, request, response); + } + +} Index: lams_admin/web/WEB-INF/struts/struts-config.xml =================================================================== diff -u -r389bb9c0679d86c2446517dbe83a46b6ab5dc840 -r009fbce36f45d0929f8007c4bbc798242f57d3af --- lams_admin/web/WEB-INF/struts/struts-config.xml (.../struts-config.xml) (revision 389bb9c0679d86c2446517dbe83a46b6ab5dc840) +++ lams_admin/web/WEB-INF/struts/struts-config.xml (.../struts-config.xml) (revision 009fbce36f45d0929f8007c4bbc798242f57d3af) @@ -145,6 +145,11 @@ + + + + + @@ -450,6 +455,32 @@ /> + + + + + + + + + + + + + + + \ No newline at end of file Index: lams_admin/web/timezoneManagement.jsp =================================================================== diff -u --- lams_admin/web/timezoneManagement.jsp (revision 0) +++ lams_admin/web/timezoneManagement.jsp (revision 009fbce36f45d0929f8007c4bbc798242f57d3af) @@ -0,0 +1,65 @@ +<%@ page import="org.lamsfoundation.lams.timezone.Timezone" %> +<%@ include file="/taglibs.jsp"%> + + + + + +

+ +

+ + + ${serverTimezone} + + +
+ +

+
+
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + ${timezoneDto.timeZoneId} + + - + + + + ${timezoneDto.dstOffset} + + + ${timezoneDto.displayName} +
+ +

+ + +

+
\ No newline at end of file Index: lams_admin/web/timezoneServerManagement.jsp =================================================================== diff -u --- lams_admin/web/timezoneServerManagement.jsp (revision 0) +++ lams_admin/web/timezoneServerManagement.jsp (revision 009fbce36f45d0929f8007c4bbc798242f57d3af) @@ -0,0 +1,64 @@ +<%@ include file="/taglibs.jsp"%> + + + + + <fmt:message key="admin.servertimezone.server.timezone"/> + + + + + + + + + + + + +

+
+ + + + + ${timezoneDto.timeZoneId} +   -   + +   -   + ${timezoneDto.dstOffset} +   -   + ${timezoneDto.displayName} + + + + + + + + + + + + +
+ + +
+ Index: lams_build/lib/lams/lams.jar =================================================================== diff -u -rdac4d818380d94154fc66ce00a46ce103d469170 -r009fbce36f45d0929f8007c4bbc798242f57d3af Binary files differ Index: lams_central/conf/xdoclet/struts-forms.xml =================================================================== diff -u -r7998a31f6d7d4f1eef3e866bafef22caa012eb7a -r009fbce36f45d0929f8007c4bbc798242f57d3af --- lams_central/conf/xdoclet/struts-forms.xml (.../struts-forms.xml) (revision 7998a31f6d7d4f1eef3e866bafef22caa012eb7a) +++ lams_central/conf/xdoclet/struts-forms.xml (.../struts-forms.xml) (revision 009fbce36f45d0929f8007c4bbc798242f57d3af) @@ -32,7 +32,7 @@ - + Index: lams_central/src/java/org/lamsfoundation/lams/web/ProfileAction.java =================================================================== diff -u -re7451ceb951ebe7eb0a84fdb0d51487579c6504f -r009fbce36f45d0929f8007c4bbc798242f57d3af --- lams_central/src/java/org/lamsfoundation/lams/web/ProfileAction.java (.../ProfileAction.java) (revision e7451ceb951ebe7eb0a84fdb0d51487579c6504f) +++ lams_central/src/java/org/lamsfoundation/lams/web/ProfileAction.java (.../ProfileAction.java) (revision 009fbce36f45d0929f8007c4bbc798242f57d3af) @@ -26,6 +26,8 @@ import java.util.Collections; import java.util.HashMap; import java.util.List; +import java.util.TimeZone; +import java.util.TreeSet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; @@ -45,6 +47,10 @@ import org.lamsfoundation.lams.lesson.dto.LessonDTO; import org.lamsfoundation.lams.themes.Theme; import org.lamsfoundation.lams.themes.service.IThemeService; +import org.lamsfoundation.lams.timezone.Timezone; +import org.lamsfoundation.lams.timezone.dto.TimezoneDTO; +import org.lamsfoundation.lams.timezone.service.ITimezoneService; +import org.lamsfoundation.lams.timezone.util.TimezoneDTOComparator; import org.lamsfoundation.lams.usermanagement.Organisation; import org.lamsfoundation.lams.usermanagement.OrganisationType; import org.lamsfoundation.lams.usermanagement.SupportedLocale; @@ -88,6 +94,8 @@ private static ICoreLearnerService learnerService; private static IThemeService themeService; + + private static ITimezoneService timezoneService; public ActionForward view(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { @@ -261,6 +269,17 @@ } userForm.set("userFlashTheme", userSelectedFlashTheme); + List availableTimeZones = getTimezoneService().getDefaultTimezones(); + TreeSet timezoneDtos = new TreeSet(new TimezoneDTOComparator()); + for (Timezone availableTimeZone : availableTimeZones) { + String timezoneId = availableTimeZone.getTimezoneId(); + TimezoneDTO timezoneDto = new TimezoneDTO(); + timezoneDto.setTimeZoneId(timezoneId); + timezoneDto.setDisplayName(TimeZone.getTimeZone(timezoneId).getDisplayName()); + timezoneDtos.add(timezoneDto); + } + request.setAttribute("timezoneDtos", timezoneDtos); + return mapping.findForward("edit"); } @@ -292,4 +311,13 @@ } return themeService; } + + private ITimezoneService getTimezoneService() { + if (timezoneService == null) { + WebApplicationContext ctx = WebApplicationContextUtils.getRequiredWebApplicationContext(getServlet() + .getServletContext()); + timezoneService = (ITimezoneService) ctx.getBean("timezoneService"); + } + return timezoneService; + } } Index: lams_central/web/editprofile.jsp =================================================================== diff -u -r6a414b5f0f7756f0376670914c59c84b9ae916ef -r009fbce36f45d0929f8007c4bbc798242f57d3af --- lams_central/web/editprofile.jsp (.../editprofile.jsp) (revision 6a414b5f0f7756f0376670914c59c84b9ae916ef) +++ lams_central/web/editprofile.jsp (.../editprofile.jsp) (revision 009fbce36f45d0929f8007c4bbc798242f57d3af) @@ -132,9 +132,9 @@ : - - - + + + ${timezoneDto.timeZoneId} - ${timezoneDto.displayName} @@ -320,7 +320,7 @@ : - + ${timeZone}" Index: lams_common/build.xml =================================================================== diff -u -r61e7bbf20d65e2ecb5e50f3154e52264003defa1 -r009fbce36f45d0929f8007c4bbc798242f57d3af --- lams_common/build.xml (.../build.xml) (revision 61e7bbf20d65e2ecb5e50f3154e52264003defa1) +++ lams_common/build.xml (.../build.xml) (revision 009fbce36f45d0929f8007c4bbc798242f57d3af) @@ -455,6 +455,7 @@ + Index: lams_common/conf/hibernate/mappings/hibernate.cfg.xml =================================================================== diff -u -r7998a31f6d7d4f1eef3e866bafef22caa012eb7a -r009fbce36f45d0929f8007c4bbc798242f57d3af --- lams_common/conf/hibernate/mappings/hibernate.cfg.xml (.../hibernate.cfg.xml) (revision 7998a31f6d7d4f1eef3e866bafef22caa012eb7a) +++ lams_common/conf/hibernate/mappings/hibernate.cfg.xml (.../hibernate.cfg.xml) (revision 009fbce36f45d0929f8007c4bbc798242f57d3af) @@ -41,6 +41,7 @@ + Index: lams_common/conf/hibernate/mappings/org/lamsfoundation/lams/timezone/Timezone.hbm.xml =================================================================== diff -u --- lams_common/conf/hibernate/mappings/org/lamsfoundation/lams/timezone/Timezone.hbm.xml (revision 0) +++ lams_common/conf/hibernate/mappings/org/lamsfoundation/lams/timezone/Timezone.hbm.xml (revision 009fbce36f45d0929f8007c4bbc798242f57d3af) @@ -0,0 +1,55 @@ + + + + + + + + + + + + + + + + + + + + + + Index: lams_common/conf/hibernate/mappings/org/lamsfoundation/lams/usermanagement/User.hbm.xml =================================================================== diff -u -rab19db088359a46353cc92e806c40ff5cff818b9 -r009fbce36f45d0929f8007c4bbc798242f57d3af --- lams_common/conf/hibernate/mappings/org/lamsfoundation/lams/usermanagement/User.hbm.xml (.../User.hbm.xml) (revision ab19db088359a46353cc92e806c40ff5cff818b9) +++ lams_common/conf/hibernate/mappings/org/lamsfoundation/lams/usermanagement/User.hbm.xml (.../User.hbm.xml) (revision 009fbce36f45d0929f8007c4bbc798242f57d3af) @@ -474,17 +474,18 @@ - - name="timeZone" - type="java.lang.Short" - column="timezone" + @hibernate.property + column="timezone" + length="64" - + classpath:org/lamsfoundation/lams/themes/Theme.hbm.xml + classpath:org/lamsfoundation/lams/timezone/Timezone.hbm.xml + classpath:org/lamsfoundation/lams/notebook/model/NotebookEntry.hbm.xml classpath:org/lamsfoundation/lams/presence/model/PresenceChatMessage.hbm.xml @@ -352,6 +354,22 @@ + + + + + + + + true + + + PROPAGATION_REQUIRED + PROPAGATION_REQUIRED + + + + @@ -542,6 +560,11 @@ + + + + + Index: lams_common/src/java/org/lamsfoundation/lams/dbupdates/patch02040006.sql =================================================================== diff -u -r0f432e857d0ba8120399d48306cf740f9b598522 -r009fbce36f45d0929f8007c4bbc798242f57d3af --- lams_common/src/java/org/lamsfoundation/lams/dbupdates/patch02040006.sql (.../patch02040006.sql) (revision 0f432e857d0ba8120399d48306cf740f9b598522) +++ lams_common/src/java/org/lamsfoundation/lams/dbupdates/patch02040006.sql (.../patch02040006.sql) (revision 009fbce36f45d0929f8007c4bbc798242f57d3af) @@ -9,5 +9,81 @@ insert into lams_configuration (config_key, config_value, description_key, header_name, format, required) values ('ShowAllMyLessonLink','true', 'config.show.all.my.lesson.link', 'config.header.features', 'BOOLEAN', 1); +-- LDEV-2544 Default Timezones +CREATE TABLE lams_timezone ( + id BIGINT(20) NOT NULL AUTO_INCREMENT + , timezone_id VARCHAR(255) NOT NULL + , server_timezone TINYINT DEFAULT 0 + , PRIMARY KEY (id) +)TYPE=InnoDB; + +INSERT INTO lams_timezone (timezone_id) VALUES ('Etc/GMT+12'); +INSERT INTO lams_timezone (timezone_id) VALUES ('Etc/GMT+11'); +INSERT INTO lams_timezone (timezone_id) VALUES ('Etc/GMT+10'); +INSERT INTO lams_timezone (timezone_id) VALUES ('US/Alaska'); +INSERT INTO lams_timezone (timezone_id) VALUES ('America/Vancouver'); +INSERT INTO lams_timezone (timezone_id) VALUES ('America/Denver'); +INSERT INTO lams_timezone (timezone_id) VALUES ('America/Chicago'); +INSERT INTO lams_timezone (timezone_id) VALUES ('America/Detroit'); +INSERT INTO lams_timezone (timezone_id) VALUES ('America/Halifax'); +INSERT INTO lams_timezone (timezone_id) VALUES ('Canada/Newfoundland'); +INSERT INTO lams_timezone (timezone_id) VALUES ('Etc/GMT+3'); +INSERT INTO lams_timezone (timezone_id) VALUES ('Etc/GMT+2'); +INSERT INTO lams_timezone (timezone_id) VALUES ('Etc/GMT+1'); +INSERT INTO lams_timezone (timezone_id) VALUES ('Europe/London'); +INSERT INTO lams_timezone (timezone_id) VALUES ('Europe/Brussels'); +INSERT INTO lams_timezone (timezone_id) VALUES ('Europe/Athens'); +INSERT INTO lams_timezone (timezone_id) VALUES ('Europe/Moscow'); +INSERT INTO lams_timezone (timezone_id) VALUES ('Asia/Tehran'); +INSERT INTO lams_timezone (timezone_id) VALUES ('Etc/GMT-4'); +INSERT INTO lams_timezone (timezone_id) VALUES ('Asia/Kabul'); +INSERT INTO lams_timezone (timezone_id) VALUES ('Etc/GMT-5'); +INSERT INTO lams_timezone (timezone_id) VALUES ('Asia/Calcutta'); +INSERT INTO lams_timezone (timezone_id) VALUES ('Asia/Katmandu'); +INSERT INTO lams_timezone (timezone_id) VALUES ('Etc/GMT-6'); +INSERT INTO lams_timezone (timezone_id) VALUES ('Etc/GMT-7'); +INSERT INTO lams_timezone (timezone_id) VALUES ('Australia/West'); +INSERT INTO lams_timezone (timezone_id) VALUES ('Etc/GMT-9'); +INSERT INTO lams_timezone (timezone_id) VALUES ('Australia/Adelaide'); +INSERT INTO lams_timezone (timezone_id) VALUES ('Australia/Sydney'); +INSERT INTO lams_timezone (timezone_id) VALUES ('Etc/GMT-11'); +INSERT INTO lams_timezone (timezone_id) VALUES ('Pacific/Auckland'); +INSERT INTO lams_timezone (timezone_id) VALUES ('Pacific/Tongatapu'); +INSERT INTO lams_timezone (timezone_id) VALUES ('Pacific/Kiritimati'); + +ALTER TABLE lams_user MODIFY COLUMN timezone VARCHAR(255); + +UPDATE lams_user SET timezone='Etc/GMT+12' WHERE timezone='0'; +UPDATE lams_user SET timezone='Etc/GMT+11' WHERE timezone='1'; +UPDATE lams_user SET timezone='Etc/GMT+10' WHERE timezone='2'; +UPDATE lams_user SET timezone='US/Alaska' WHERE timezone='3'; +UPDATE lams_user SET timezone='America/Vancouver' WHERE timezone='4'; +UPDATE lams_user SET timezone='America/Denver' WHERE timezone='5'; +UPDATE lams_user SET timezone='America/Chicago' WHERE timezone='6'; +UPDATE lams_user SET timezone='America/Detroit' WHERE timezone='7'; +UPDATE lams_user SET timezone='America/Halifax' WHERE timezone='8'; +UPDATE lams_user SET timezone='Canada/Newfoundland' WHERE timezone='9'; +UPDATE lams_user SET timezone='Etc/GMT+3' WHERE timezone='10'; +UPDATE lams_user SET timezone='Etc/GMT+2' WHERE timezone='11'; +UPDATE lams_user SET timezone='Etc/GMT+1' WHERE timezone='12'; +UPDATE lams_user SET timezone='Europe/London' WHERE timezone='13'; +UPDATE lams_user SET timezone='Europe/Brussels' WHERE timezone='14'; +UPDATE lams_user SET timezone='Europe/Athens' WHERE timezone='15'; +UPDATE lams_user SET timezone='Europe/Moscow' WHERE timezone='16'; +UPDATE lams_user SET timezone='Asia/Tehran' WHERE timezone='17'; +UPDATE lams_user SET timezone='Etc/GMT-4' WHERE timezone='18'; +UPDATE lams_user SET timezone='Asia/Kabul' WHERE timezone='19'; +UPDATE lams_user SET timezone='Etc/GMT-5' WHERE timezone='20'; +UPDATE lams_user SET timezone='Asia/Calcutta' WHERE timezone='21'; +UPDATE lams_user SET timezone='Asia/Katmandu' WHERE timezone='22'; +UPDATE lams_user SET timezone='Etc/GMT-6' WHERE timezone='23'; +UPDATE lams_user SET timezone='Etc/GMT-7' WHERE timezone='24'; +UPDATE lams_user SET timezone='Australia/West' WHERE timezone='25'; +UPDATE lams_user SET timezone='Etc/GMT-9' WHERE timezone='26'; +UPDATE lams_user SET timezone='Australia/Adelaide' WHERE timezone='27'; +UPDATE lams_user SET timezone='Australia/Sydney' WHERE timezone='28'; +UPDATE lams_user SET timezone='Etc/GMT-11' WHERE timezone='29'; +UPDATE lams_user SET timezone='Pacific/Auckland' WHERE timezone='30'; + COMMIT; SET AUTOCOMMIT = 1; \ No newline at end of file Index: lams_common/src/java/org/lamsfoundation/lams/timezone/Timezone.java =================================================================== diff -u --- lams_common/src/java/org/lamsfoundation/lams/timezone/Timezone.java (revision 0) +++ lams_common/src/java/org/lamsfoundation/lams/timezone/Timezone.java (revision 009fbce36f45d0929f8007c4bbc798242f57d3af) @@ -0,0 +1,126 @@ +/**************************************************************** + * 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.timezone; + +import java.io.Serializable; + +/** + * Contains timezone id. + * + * @author Andrey Balan + * @see java.util.TimeZone + * + * @hibernate.class table="lams_timezone" + */ +public class Timezone implements Serializable { + + /** + * Link on Lams wiki timezone help page. + */ + public static String TIMEZONE_HELP_PAGE = "LAMS+Configuration"; + + private static final long serialVersionUID = 6736816209131888523L; + + /** identifier field */ + private Long id; + + private String timezoneId; + + private boolean serverTimezone; + + /** default constructor */ + public Timezone() { + this.serverTimezone = false; + } + + /** full constructor */ + public Timezone(String timezoneId) { + this.timezoneId = timezoneId; + this.serverTimezone = false; + } + + /** + * @hibernate.id generator-class="native" type="java.lang.Long" column="id" + */ + public Long getId() { + return this.id; + } + public void setId(Long id) { + this.id = id; + } + + /** + * Timezone id. This value is a copy of java.util.TimeZone ID. + * + * @hibernate.property column="timezone_id" length="255" + */ + public String getTimezoneId() { + return this.timezoneId; + } + public void setTimezoneId(String timezoneId) { + this.timezoneId = timezoneId; + } + + /** + * If this timezone is server's default one. + * + * @hibernate.property column="server_timezone" length="1" not-null="true" + */ + public boolean isServerTimezone() { + return this.serverTimezone; + } + public void setServerTimezone(boolean serverTimezone) { + this.serverTimezone = serverTimezone; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + (serverTimezone ? 1231 : 1237); + result = prime * result + ((timezoneId == null) ? 0 : timezoneId.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + Timezone other = (Timezone) obj; + if (serverTimezone != other.serverTimezone) + return false; + if (timezoneId == null) { + if (other.timezoneId != null) + return false; + } else if (!timezoneId.equals(other.timezoneId)) + return false; + return true; + } + +} + Index: lams_common/src/java/org/lamsfoundation/lams/timezone/dao/ITimezoneDAO.java =================================================================== diff -u --- lams_common/src/java/org/lamsfoundation/lams/timezone/dao/ITimezoneDAO.java (revision 0) +++ lams_common/src/java/org/lamsfoundation/lams/timezone/dao/ITimezoneDAO.java (revision 009fbce36f45d0929f8007c4bbc798242f57d3af) @@ -0,0 +1,74 @@ +/**************************************************************** + * 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.timezone.dao; + +import java.util.List; + +import org.lamsfoundation.lams.config.ConfigurationItem; +import org.lamsfoundation.lams.timezone.Timezone; + +/** + * DAO interface for Timezone. + * + * @author Andrey Balan + * @see org.lamsfoundation.lams.timezone.Timezone + */ +public interface ITimezoneDAO { + + /** + * Returns all timezones stored in database. + * + * @return all timezones + */ + List getDefaultTimezones(); + + /** + * Removes specified time zone from database. + * + * @param timezone time zone to remove + */ + void removeTimezone(Timezone timezone); + + /** + * Adds specified time zone to database. + * + * @param timezone time zone to add + */ + void addTimezone(Timezone timezone); + + /** + * Returns server's timezone stored in DB. + * + * @return + */ + Timezone getServerTimezone(); + + /** + * Sets server timezone. + * + * @return + */ + void setServerTimezone(Timezone serverTimezone); + +} Index: lams_common/src/java/org/lamsfoundation/lams/timezone/dao/hibernate/TimezoneDAO.java =================================================================== diff -u --- lams_common/src/java/org/lamsfoundation/lams/timezone/dao/hibernate/TimezoneDAO.java (revision 0) +++ lams_common/src/java/org/lamsfoundation/lams/timezone/dao/hibernate/TimezoneDAO.java (revision 009fbce36f45d0929f8007c4bbc798242f57d3af) @@ -0,0 +1,73 @@ +/**************************************************************** + * 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.timezone.dao.hibernate; + +import java.util.List; + +import org.lamsfoundation.lams.dao.hibernate.BaseDAO; +import org.lamsfoundation.lams.timezone.Timezone; +import org.lamsfoundation.lams.timezone.dao.ITimezoneDAO; + +/** + * Hibernate implementation of ITimezoneDAO. + * + * @author Andrey Balan + * @see org.lamsfoundation.lams.timezone.dao.ITimezoneDAO + */ +public class TimezoneDAO extends BaseDAO implements ITimezoneDAO { + + private final static String FIND_DEFAULT_TIMEZONES = "from " + Timezone.class.getName() + + " timezone where timezone.serverTimezone=false"; + + private final static String FIND_SERVER_TIMEZONE = "from " + Timezone.class.getName() + + " timezone where timezone.serverTimezone=true"; + + public List getDefaultTimezones() { + List timezones = this.getHibernateTemplate().find(FIND_DEFAULT_TIMEZONES); + return timezones; + } + + public void addTimezone(Timezone timezone) { + super.insert(timezone); + } + + public void removeTimezone(Timezone timezone) { + super.delete(timezone); + } + + public Timezone getServerTimezone() { + List list = getHibernateTemplate().find(FIND_SERVER_TIMEZONE); + if (list.size() > 0) { + return (Timezone) list.get(0); + } else { + return null; + } + } + + public void setServerTimezone(Timezone serverTimezone) { + super.update(serverTimezone); + } + +} + Index: lams_common/src/java/org/lamsfoundation/lams/timezone/dto/TimezoneDTO.java =================================================================== diff -u --- lams_common/src/java/org/lamsfoundation/lams/timezone/dto/TimezoneDTO.java (revision 0) +++ lams_common/src/java/org/lamsfoundation/lams/timezone/dto/TimezoneDTO.java (revision 009fbce36f45d0929f8007c4bbc798242f57d3af) @@ -0,0 +1,127 @@ +/**************************************************************** + * 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.timezone.dto; + +import java.util.Calendar; +import java.util.Date; +import java.util.List; +import java.util.TimeZone; + +import sun.util.calendar.CalendarUtils; + +/** + * DTO object for {@link org.lamsfoundation.lams.timezone.Timezone} + * + * @author Andrey Balan + * + */ +public class TimezoneDTO { + + /** + * timezone id. + */ + private String timeZoneId; + /** + * time zone raw offset + */ + private Date rawOffset; + /** + * if raw offset is negative + */ + private boolean isRawOffsetNegative; + /** + * time zone dst offset + */ + private int dstOffset; + /** + * timezone human readable name + */ + private String displayName; + /** + * If this timezone is selected. + */ + private boolean selected; + + /** + * Returns new Timezone object with populated values. + * + * @param timeZone + * @param selected + * @return + */ + public static TimezoneDTO createTimezoneDTO(TimeZone timeZone, boolean selected) { + TimezoneDTO timezoneDTO = new TimezoneDTO(); + timezoneDTO.timeZoneId = timeZone.getID(); + int timeZoneRawOffset = timeZone.getRawOffset(); + timezoneDTO.rawOffset = new Date(Math.abs(timeZoneRawOffset)); + timezoneDTO.isRawOffsetNegative = timeZoneRawOffset < 0; + timezoneDTO.dstOffset = (int) timeZone.getDSTSavings() /60000; + timezoneDTO.displayName = timeZone.getDisplayName(); + timezoneDTO.selected = selected; + return timezoneDTO; + } + + public String getTimeZoneId() { + return timeZoneId; + } + public void setTimeZoneId(String timeZoneId) { + this.timeZoneId = timeZoneId; + } + + public String getDisplayName() { + return displayName; + } + public void setDisplayName(String displayName) { + this.displayName = displayName; + } + + public boolean isSelected() { + return selected; + } + public void setSelected(boolean selected) { + this.selected = selected; + } + + public Date getRawOffset() { + return rawOffset; + } + public void setRawOffset(Date rawOffset) { + this.rawOffset = rawOffset; + } + + public boolean isRawOffsetNegative() { + return isRawOffsetNegative; + } + public void setRawOffsetNegative(boolean isRawOffsetNegative) { + this.isRawOffsetNegative = isRawOffsetNegative; + } + + public int getDstOffset() { + return dstOffset; + } + public void setDstOffset(int dstOffset) { + this.dstOffset = dstOffset; + } +} + Index: lams_common/src/java/org/lamsfoundation/lams/timezone/service/ITimezoneService.java =================================================================== diff -u --- lams_common/src/java/org/lamsfoundation/lams/timezone/service/ITimezoneService.java (revision 0) +++ lams_common/src/java/org/lamsfoundation/lams/timezone/service/ITimezoneService.java (revision 009fbce36f45d0929f8007c4bbc798242f57d3af) @@ -0,0 +1,66 @@ +/**************************************************************** + * 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.timezone.service; + +import java.util.Collection; +import java.util.List; + +import org.lamsfoundation.lams.timezone.Timezone; + +/** + * Manages Timezones. + * + * @author Andrey Balan + */ +public interface ITimezoneService { + + /** + * Returns list of default time zones. This list is shown to user on his profile page to choose one of those. + * + * @return list of default time zones + */ + List getDefaultTimezones(); + + /** + * Updates list of default time zones. Thus adds new ones and removes ones that are not in specified list. + * + * @param timezones new full list of time zones + */ + void updateTimezones(Collection timezones); + + /** + * Return current server timezone. + * + * @return + */ + Timezone getServerTimezone(); + + /** + * Sets server timezone + * + * @param timeZoneId + */ + void setServerTimezone(String timeZoneId); + +} Index: lams_common/src/java/org/lamsfoundation/lams/timezone/service/TimezoneService.java =================================================================== diff -u --- lams_common/src/java/org/lamsfoundation/lams/timezone/service/TimezoneService.java (revision 0) +++ lams_common/src/java/org/lamsfoundation/lams/timezone/service/TimezoneService.java (revision 009fbce36f45d0929f8007c4bbc798242f57d3af) @@ -0,0 +1,101 @@ +/**************************************************************** + * 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.timezone.service; + +import java.util.Collection; +import java.util.List; +import java.util.TimeZone; + +import org.apache.commons.collections.CollectionUtils; +import org.apache.log4j.Logger; +import org.lamsfoundation.lams.timezone.Timezone; +import org.lamsfoundation.lams.timezone.dao.hibernate.TimezoneDAO; + +/** + * Class implements ITimezoneService. + * + * @author Andrey Balan + * @see org.lamsfoundation.lams.timezone.service.ITimezoneService + */ +public class TimezoneService implements ITimezoneService{ + + protected Logger log = Logger.getLogger(TimezoneService.class); + + /** Required DAO's */ + protected TimezoneDAO timezoneDAO; + + public List getDefaultTimezones() { + return timezoneDAO.getDefaultTimezones(); + } + + public void updateTimezones(Collection newTimezones) { + log.debug("Updating list of available timezones."); + + List oldTimezones = getDefaultTimezones(); + Collection timezonesToDelete = CollectionUtils.subtract(oldTimezones, newTimezones); + Collection timezonesToAdd = CollectionUtils.subtract(newTimezones, oldTimezones); + + for (Timezone timezone : timezonesToDelete) { + timezoneDAO.removeTimezone(timezone); + } + + for (Timezone timezone : timezonesToAdd) { + timezoneDAO.addTimezone(timezone); + } + } + + public Timezone getServerTimezone() { + Timezone serverTimezone = timezoneDAO.getServerTimezone(); + if (serverTimezone == null) { + serverTimezone = new Timezone(); + serverTimezone.setTimezoneId(TimeZone.getDefault().getID()); + serverTimezone.setServerTimezone(true); + timezoneDAO.addTimezone(serverTimezone); + } + + return serverTimezone; + } + + public void setServerTimezone(String timeZoneId) { + Timezone serverTimezone = timezoneDAO.getServerTimezone(); + serverTimezone.setTimezoneId(timeZoneId); + timezoneDAO.setServerTimezone(serverTimezone); + } + + /** + * @return Returns the timezoneDAO. + */ + public TimezoneDAO getTimezoneDAO() { + return timezoneDAO; + } + /** + * + * @param timezoneDAO + * The timezoneDAO to set. + */ + public void setTimezoneDAO(TimezoneDAO timezoneDAO) { + this.timezoneDAO = timezoneDAO; + } + +} Index: lams_common/src/java/org/lamsfoundation/lams/timezone/util/TimezoneComparator.java =================================================================== diff -u --- lams_common/src/java/org/lamsfoundation/lams/timezone/util/TimezoneComparator.java (revision 0) +++ lams_common/src/java/org/lamsfoundation/lams/timezone/util/TimezoneComparator.java (revision 009fbce36f45d0929f8007c4bbc798242f57d3af) @@ -0,0 +1,53 @@ +/**************************************************************** + * 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.timezone.util; + +import java.util.Comparator; +import java.util.TimeZone; + +import org.lamsfoundation.lams.timezone.Timezone; +import org.lamsfoundation.lams.timezone.dto.TimezoneDTO; + +/** + * + * @author Andrey Balan + * @see org.lamsfoundation.lams.timezone.Timezone + */ +public class TimezoneComparator implements Comparator { + + public int compare(Timezone o1, Timezone o2) { + if (o1 != null && o2 != null && o1.getTimezoneId() != null && o2.getTimezoneId() != null) { + TimeZone o1TimeZone = TimeZone.getTimeZone(o1.getTimezoneId()); + TimeZone o2TimeZone = TimeZone.getTimeZone(o2.getTimezoneId()); + int rawOffsetDifference = o1TimeZone.getRawOffset() - o2TimeZone.getRawOffset(); + int compareResult = (rawOffsetDifference != 0) ? rawOffsetDifference : o1TimeZone.getID().compareTo(o2TimeZone.getID()); + return compareResult; + } else if (o1 != null) { + return 1; + } else { + return -1; + } + } + +} Index: lams_common/src/java/org/lamsfoundation/lams/timezone/util/TimezoneDTOComparator.java =================================================================== diff -u --- lams_common/src/java/org/lamsfoundation/lams/timezone/util/TimezoneDTOComparator.java (revision 0) +++ lams_common/src/java/org/lamsfoundation/lams/timezone/util/TimezoneDTOComparator.java (revision 009fbce36f45d0929f8007c4bbc798242f57d3af) @@ -0,0 +1,52 @@ +/**************************************************************** + * 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.timezone.util; + +import java.util.Comparator; +import java.util.TimeZone; + +import org.lamsfoundation.lams.timezone.dto.TimezoneDTO; + +/** + * + * @author Andrey Balan + * @see org.lamsfoundation.lams.timezone.dto.TimezoneDTO + */ +public class TimezoneDTOComparator implements Comparator { + + public int compare(TimezoneDTO o1, TimezoneDTO o2) { + if (o1 != null && o2 != null && o1.getTimeZoneId() != null && o2.getTimeZoneId() != null) { + TimeZone o1TimeZone = TimeZone.getTimeZone(o1.getTimeZoneId()); + TimeZone o2TimeZone = TimeZone.getTimeZone(o2.getTimeZoneId()); + int rawOffsetDifference = o1TimeZone.getRawOffset() - o2TimeZone.getRawOffset(); + int compareResult = (rawOffsetDifference != 0) ? rawOffsetDifference : o1TimeZone.getID().compareTo(o2TimeZone.getID()); + return compareResult; + } else if (o1 != null) { + return 1; + } else { + return -1; + } + } + +} Index: lams_common/src/java/org/lamsfoundation/lams/usermanagement/User.java =================================================================== diff -u -rab19db088359a46353cc92e806c40ff5cff818b9 -r009fbce36f45d0929f8007c4bbc798242f57d3af --- lams_common/src/java/org/lamsfoundation/lams/usermanagement/User.java (.../User.java) (revision ab19db088359a46353cc92e806c40ff5cff818b9) +++ lams_common/src/java/org/lamsfoundation/lams/usermanagement/User.java (.../User.java) (revision 009fbce36f45d0929f8007c4bbc798242f57d3af) @@ -110,7 +110,7 @@ private SupportedLocale locale; /** persistent field */ - private Short timeZone; + private String timeZone; /** persistent field */ private Date createDate; @@ -180,14 +180,6 @@ /** persistent field */ private String openidURL; - - // ------- TIMEZONES (hardcoded, there is no need to put them into database -------------- - - public static String[] timezoneList = new String[] { "GMT-12", "GMT-11", "GMT-10", "GMT-9", "GMT-8", "GMT-7", - "GMT-6", "GMT-5", "GMT-4", "GMT-3:30", "GMT-3", "GMT-2", "GMT-1", "GMT", "GMT+1", "GMT+2", "GMT+3", - "GMT+3:30", "GMT+4", "GMT+4:30", "GMT+5", "GMT+5:30", "GMT+5:45", "GMT+6", "GMT+7", "GMT+8", "GMT+9", - "GMT+9:30", "GMT+10", "GMT+11", "GMT+12" }; - /** full constructor */ public User(String login, String password, String title, String firstName, String lastName, String addressLine1, String addressLine2, String addressLine3, String city, String state, String postcode, String country, @@ -688,15 +680,15 @@ .getFckLanguageMapping(); } - TimeZone tz = TimeZone.getTimeZone(User.timezoneList[getTimeZone()]); + TimeZone timeZone = TimeZone.getTimeZone(getTimeZone()); Set tutorialPages = pagesWithDisabledTutorials == null || pagesWithDisabledTutorials.isEmpty() ? null : pagesWithDisabledTutorials; return new UserDTO(userId, firstName, lastName, login, languageIsoCode, countryIsoCode, direction, email, new CSSThemeBriefDTO(flashTheme), new CSSThemeBriefDTO(htmlTheme), // TimeZone.getTimeZone("Australia/Sydney"), - tz, authenticationMethod.getAuthenticationMethodId(), fckLanguageMapping, enableFlash, + timeZone, authenticationMethod.getAuthenticationMethodId(), fckLanguageMapping, enableFlash, lamsCommunityToken, lamsCommunityUsername, (tutorialsDisabled == null ? false : true), // assume tutorials enabled if not set tutorialPages, @@ -839,38 +831,19 @@ } /** - * Returns user's time zone. If NULL, returns server default time zone. If server default time zone is not in the - * list of supported time zones, returns GMT. + * Returns user's time zone. If NULL, returns server default time zone. * - * @hibernate.property column="timezone" + * @hibernate.property column="timezone" length="255" * */ - public Short getTimeZone() { + public String getTimeZone() { if (timeZone == null) { - TimeZone defaultTimeZone = TimeZone.getDefault(); - int defaultRawOffset = defaultTimeZone.getRawOffset(); - // initial index of GMT time zone, but later it is verified - short fallbackTimeZone = 13; - for (short timeZoneIndex = 0; timeZoneIndex < User.timezoneList.length; timeZoneIndex++) { - TimeZone candidateTimeZone = TimeZone.getTimeZone(User.timezoneList[timeZoneIndex]); - if (defaultRawOffset == candidateTimeZone.getRawOffset()) { - // we found a time zone from the list which has the same offset as the server's one - timeZone = timeZoneIndex; - break; - } else if (candidateTimeZone.getRawOffset() == 0) { - // we found GMT time zone; it will be used if server default time zone is not in the list - fallbackTimeZone = timeZoneIndex; - } - } - if (timeZone == null) { - timeZone = fallbackTimeZone; - } + timeZone = TimeZone.getDefault().getID(); } return timeZone; } - public void setTimeZone(Short timeZone) { - + public void setTimeZone(String timeZone) { this.timeZone = timeZone; } Index: lams_common/src/java/org/lamsfoundation/lams/workspace/dto/FolderContentDTO.java =================================================================== diff -u -re47890c32f932fde18be28fe3f8cedbd781a5219 -r009fbce36f45d0929f8007c4bbc798242f57d3af --- lams_common/src/java/org/lamsfoundation/lams/workspace/dto/FolderContentDTO.java (.../FolderContentDTO.java) (revision e47890c32f932fde18be28fe3f8cedbd781a5219) +++ lams_common/src/java/org/lamsfoundation/lams/workspace/dto/FolderContentDTO.java (.../FolderContentDTO.java) (revision 009fbce36f45d0929f8007c4bbc798242f57d3af) @@ -83,7 +83,7 @@ this.description = design.getDescription(); this.creationDateTime = design.getCreateDateTime(); this.lastModifiedDateTime = design.getLastModifiedDateTime(); - this.formattedLastModifiedDateTime = formatLastModifiedDateTime(TimeZone.getTimeZone(User.timezoneList[user.getTimeZone()])); + this.formattedLastModifiedDateTime = formatLastModifiedDateTime(TimeZone.getTimeZone(user.getTimeZone())); this.resourceType = DESIGN; this.resourceID = design.getLearningDesignId(); this.permissionCode = permissionCode; @@ -98,7 +98,7 @@ this.description = "Folder"; this.creationDateTime = workspaceFolder.getCreationDate(); this.lastModifiedDateTime = workspaceFolder.getLastModifiedDate(); - this.formattedLastModifiedDateTime = formatLastModifiedDateTime(TimeZone.getTimeZone(User.timezoneList[user.getTimeZone()])); + this.formattedLastModifiedDateTime = formatLastModifiedDateTime(TimeZone.getTimeZone(user.getTimeZone())); this.resourceType = FOLDER; this.resourceTypeID = new Long(workspaceFolder.getWorkspaceFolderType().intValue()); this.resourceID = new Long(workspaceFolder.getWorkspaceFolderId().intValue()); @@ -112,7 +112,7 @@ this.description = workspaceFolderContent.getDescription(); this.creationDateTime = workspaceFolderContent.getCreateDate(); this.lastModifiedDateTime = workspaceFolderContent.getLastModified(); - this.formattedLastModifiedDateTime = formatLastModifiedDateTime(TimeZone.getTimeZone(User.timezoneList[user.getTimeZone()])); + this.formattedLastModifiedDateTime = formatLastModifiedDateTime(TimeZone.getTimeZone(user.getTimeZone())); this.resourceID = workspaceFolderContent.getFolderContentID(); this.permissionCode = permissionCode; if(workspaceFolderContent.getContentTypeID().equals(WorkspaceFolderContent.CONTENT_TYPE_FILE)) Index: lams_monitoring/src/java/org/lamsfoundation/lams/monitoring/service/IMonitoringService.java =================================================================== diff -u -r0d3db10064dce04801de82511dda34780ddccc52 -r009fbce36f45d0929f8007c4bbc798242f57d3af --- lams_monitoring/src/java/org/lamsfoundation/lams/monitoring/service/IMonitoringService.java (.../IMonitoringService.java) (revision 0d3db10064dce04801de82511dda34780ddccc52) +++ lams_monitoring/src/java/org/lamsfoundation/lams/monitoring/service/IMonitoringService.java (.../IMonitoringService.java) (revision 009fbce36f45d0929f8007c4bbc798242f57d3af) @@ -209,11 +209,11 @@ * the lesson start date and time. * @param userId * checks that the user is a staff member for this lesson - * @param timeZoneIdx - * the index of the TimeZone to use for the start date + * @param timeZoneId + * Timezone id to use for the start date * @see org.lamsfoundation.lams.monitoring.service#startLesson(long) */ - public void startLessonOnSchedule(long lessonId, Date startDate, Integer userId, Integer timeZoneIdx) throws UserAccessDeniedException; + public void startLessonOnSchedule(long lessonId, Date startDate, Integer userId, String timeZoneId) throws UserAccessDeniedException; /** * Finish a lesson on schedule datetime. Index: lams_monitoring/src/java/org/lamsfoundation/lams/monitoring/service/MonitoringService.java =================================================================== diff -u -r0d3db10064dce04801de82511dda34780ddccc52 -r009fbce36f45d0929f8007c4bbc798242f57d3af --- lams_monitoring/src/java/org/lamsfoundation/lams/monitoring/service/MonitoringService.java (.../MonitoringService.java) (revision 0d3db10064dce04801de82511dda34780ddccc52) +++ lams_monitoring/src/java/org/lamsfoundation/lams/monitoring/service/MonitoringService.java (.../MonitoringService.java) (revision 009fbce36f45d0929f8007c4bbc798242f57d3af) @@ -678,7 +678,7 @@ * @see org.lamsfoundation.lams.monitoring.service.IMonitoringService#startLessonOnSchedule(long * , Date, User) */ - public void startLessonOnSchedule(long lessonId, Date startDate, Integer userId, Integer timeZoneIdx) { + public void startLessonOnSchedule(long lessonId, Date startDate, Integer userId, String timeZoneId) { // we get the lesson just created Lesson requestedLesson = lessonDAO.getLesson(new Long(lessonId)); @@ -708,10 +708,11 @@ TimeZone tz = TimeZone.getDefault(); TimeZone selectedTz; - if(timeZoneIdx != null) - selectedTz = TimeZone.getTimeZone(User.timezoneList[timeZoneIdx]); - else - selectedTz = TimeZone.getTimeZone(User.timezoneList[user.getTimeZone()]); + if (timeZoneId != null) { + selectedTz = TimeZone.getTimeZone(timeZoneId); + } else { + selectedTz = TimeZone.getTimeZone(user.getTimeZone()); + } Date tzStartLessonDate = DateUtil.convertFromTimeZoneToDefault(selectedTz, startDate); @@ -1449,7 +1450,7 @@ LessonDetailsDTO dto = lessonService.getLessonDetails(lessonID); Locale userLocale = new Locale(user.getLocale().getLanguageIsoCode(), user.getLocale().getCountryIsoCode()); - TimeZone tz = TimeZone.getTimeZone(User.timezoneList[user.getTimeZone()]); + TimeZone tz = TimeZone.getTimeZone(user.getTimeZone()); DateFormat indfm = new SimpleDateFormat("EEE, d MMM yyyy HH:mm:ss", userLocale); Index: lams_monitoring/src/java/org/lamsfoundation/lams/monitoring/web/MonitoringAction.java =================================================================== diff -u -r2f21856ec2ab85b47c93cfcc3fa2c8769be65077 -r009fbce36f45d0929f8007c4bbc798242f57d3af --- lams_monitoring/src/java/org/lamsfoundation/lams/monitoring/web/MonitoringAction.java (.../MonitoringAction.java) (revision 2f21856ec2ab85b47c93cfcc3fa2c8769be65077) +++ lams_monitoring/src/java/org/lamsfoundation/lams/monitoring/web/MonitoringAction.java (.../MonitoringAction.java) (revision 009fbce36f45d0929f8007c4bbc798242f57d3af) @@ -30,6 +30,7 @@ import java.util.ArrayList; import java.util.Date; import java.util.TimeZone; +import java.util.TreeSet; import javax.servlet.ServletException; import javax.servlet.http.HttpServletRequest; @@ -44,6 +45,11 @@ import org.lamsfoundation.lams.monitoring.MonitoringConstants; import org.lamsfoundation.lams.monitoring.service.IMonitoringService; import org.lamsfoundation.lams.monitoring.service.MonitoringServiceProxy; +import org.lamsfoundation.lams.timezone.Timezone; +import org.lamsfoundation.lams.timezone.dto.TimezoneDTO; +import org.lamsfoundation.lams.timezone.service.ITimezoneService; +import org.lamsfoundation.lams.timezone.util.TimezoneComparator; +import org.lamsfoundation.lams.timezone.util.TimezoneDTOComparator; import org.lamsfoundation.lams.tool.exception.LamsToolServiceException; import org.lamsfoundation.lams.usermanagement.User; import org.lamsfoundation.lams.usermanagement.dto.UserDTO; @@ -98,6 +104,8 @@ public static final String NUM_DELETED = "numDeleted"; private static IAuditService auditService; + + private static ITimezoneService timezoneService; private Integer getUserId() { HttpSession ss = SessionManager.getSession(); @@ -276,9 +284,9 @@ String dateStr = WebUtil.readStrParam(request, MonitoringConstants.PARAM_LESSON_START_DATE); Date startDate = DateUtil.convertFromLAMSFlashFormat(dateStr); - Integer timeZoneIdx = WebUtil.readIntParam(request, MonitoringConstants.PARAM_SCHEDULE_TIME_ZONE_IDX, true); + String timeZoneId = WebUtil.readStrParam(request, MonitoringConstants.PARAM_SCHEDULE_TIME_ZONE_IDX, true); - monitoringService.startLessonOnSchedule(lessonId,startDate,getUserId(),timeZoneIdx); + monitoringService.startLessonOnSchedule(lessonId,startDate,getUserId(),timeZoneId); flashMessage = new FlashMessage("startOnScheduleLesson",Boolean.TRUE); }catch (Exception e) { flashMessage = handleException(e, "startOnScheduleLesson", monitoringService); @@ -767,16 +775,22 @@ } if(module.equals("wizard")) { - String ids[] = User.timezoneList; - int idx = 0; - for(String id: ids) { - languageOutput += "" + id + "" + TimeZone.getTimeZone(id).getRawOffset() + ""; - idx++; - } - - if(orgName != null) { - languageOutput += "" + orgName + ""; - } + //sort timezones + TreeSet timezones = new TreeSet(new TimezoneComparator()); + timezones.addAll(getTimezoneService().getDefaultTimezones()); + + int i = 0; + for (Timezone timezone : timezones) { + TimeZone timeZone = TimeZone.getTimeZone(timezone.getTimezoneId()); + languageOutput += "" + + "" + timezone.getTimezoneId() + " - " + timeZone.getDisplayName() + "" + + "" + TimeZone.getTimeZone(timezone.getTimezoneId()).getRawOffset() + "" + + ""; + } + + if (orgName != null) { + languageOutput += "" + orgName + ""; + } } languageOutput += ""; @@ -1047,6 +1061,20 @@ } return auditService; } + + /** + * Get TimezoneService bean. + * + * @return + */ + private ITimezoneService getTimezoneService() { + if (timezoneService == null) { + WebApplicationContext ctx = WebApplicationContextUtils.getRequiredWebApplicationContext(getServlet() + .getServletContext()); + timezoneService = (ITimezoneService) ctx.getBean("timezoneService"); + } + return timezoneService; + } /** * Set whether or not the export portfolio button is available in learner. Expects parameters lessonID