Java tutorial
/******************************************************************************* * Educational Online Test Delivery System * Copyright (c) 2013 American Institutes for Research * * Distributed under the AIR Open Source License, Version 1.0 * See accompanying file AIR-License-1_0.txt or at * http://www.smarterapp.org/documents/American_Institutes_for_Research_Open_Source_Software_License.pdf ******************************************************************************/ package org.opentestsystem.delivery; import java.util.List; import javax.annotation.PostConstruct; import org.joda.time.DateTimeZone; import org.joda.time.tz.CachedDateTimeZone; import org.opentestsystem.delivery.testreg.domain.ClientEntity; import org.opentestsystem.delivery.testreg.service.TestRegPersister; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; public class Sb11TimeZoneBuilder { private static final Logger LOGGER = LoggerFactory.getLogger(Sb11TimeZoneBuilder.class); private CachedDateTimeZone cachedDateTimeZone; @Autowired private TestRegPersister entityService; public DateTimeZone getDateTimeZone() { return cachedDateTimeZone; } public Sb11TimeZoneBuilder() { } public Sb11TimeZoneBuilder(final String timeZone) { cachedDateTimeZone = CachedDateTimeZone.forZone(DateTimeZone.forID(timeZone)); } @PostConstruct public void init() { //default to 'user' timezone which would be local server time, which gets replaced with the client's configured TZ if found. cachedDateTimeZone = CachedDateTimeZone.forZone(DateTimeZone.forID(System.getProperty("user.timezone"))); List<ClientEntity> clientEntityList = entityService.findAll(ClientEntity.FORMAT_TYPE); if (clientEntityList != null && !clientEntityList.isEmpty()) { ClientEntity clientEntity = clientEntityList.get(0); if (clientEntity.getTimeZone() != null && !clientEntity.getTimeZone().isEmpty()) { if (!DateTimeZone.getAvailableIDs().contains(clientEntity.getTimeZone())) { LOGGER.error("misconfiguration (invalid timezone id): " + clientEntity.getTimeZone()); } else { cachedDateTimeZone = CachedDateTimeZone.forZone(DateTimeZone.forID(clientEntity.getTimeZone())); } } } } }