+ |
+ + ${timezoneDto.timeZoneId} + | +
+ |
+
+ |
+ + ${timezoneDto.displayName} + | +
+
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 Timezone
s.
+ *
+ * @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