package net.sourceforge.fenixedu.domain.notifications; import java.text.MessageFormat; import java.util.ResourceBundle; import net.sourceforge.fenixedu.domain.RootDomainObject; import net.sourceforge.fenixedu.domain.exceptions.DomainException; import org.joda.time.DateTime; import org.joda.time.DurationFieldType; import org.joda.time.Minutes; import org.joda.time.Period; import pt.utl.ist.fenix.tools.util.i18n.Language; public class SystemNotifier extends SystemNotifier_Base { public SystemNotifier() { super(); if (RootDomainObject.getInstance().getSystemNotifier() != null) { throw new DomainException("There's already a system notifier"); } setRootDomainObject(RootDomainObject.getInstance()); } public Integer getEstimateMinutesForDeploy() { DateTime now = new DateTime(); DateTime timeStamp = getTimeStamp(); return now.isBefore(timeStamp) ? new Period(now, timeStamp) .get(DurationFieldType.minutes()) : Minutes.ZERO.getMinutes(); } public boolean isActive() { return Boolean.TRUE.equals(getNotifyUsers()); } public String getMessage() { Integer estimateMinutesForDeploy = getEstimateMinutesForDeploy(); StringBuilder notifyString = new StringBuilder(); if (estimateMinutesForDeploy > 0) { notifyString.append(getResourceBundle().getString( "label.deploy.warning")); MessageFormat messageFormat = new MessageFormat(notifyString .toString()); return messageFormat.format(new Object[] { estimateMinutesForDeploy, estimateMinutesForDeploy + 1 }); } else { notifyString.append(getResourceBundle().getString( "label.deploy.warning.moment")); return notifyString.toString(); } } private ResourceBundle getResourceBundle() { return ResourceBundle.getBundle("resources.ApplicationResources", Language.getLocale()); } }