}
public void execute() {
FacesContext facesContext = FacesContextUtility.getFacesContext();
WebUser user = EnterpriseFacesContextUtility.getWebUser();
MeasurementPreferences preferences = user.getMeasurementPreferences();
MetricRangePreferences rangePreferences = preferences.getMetricRangePreferences();
String metricType = "";
if (this.getIntervalType() == null) {
metricType = getDurationType();
} else {
metricType = getIntervalType();
}
if ((metricType == null) || (metricType.equals(""))) {
facesContext.addMessage(null, new FacesMessage(FacesMessage.SEVERITY_ERROR, "Range select error",
"Please select one option to either setup the duration or the time interval"));
} else if (metricType.equalsIgnoreCase(AdvancedMetricSettingsUIBean.DURATION_TYPE)) {
rangePreferences.readOnly = false;
rangePreferences.lastN = duration;
rangePreferences.unit = unit;
facesContext.addMessage(null, new FacesMessage(FacesMessage.SEVERITY_INFO, "Preferences updated",
"Your preferences have been successfully updated"));
} else if (metricType.equalsIgnoreCase(AdvancedMetricSettingsUIBean.INTERVAL_TYPE)) {
if ((this.getFromTime() == null) || (this.getToTime() == null)) {
facesContext.addMessage(null, new FacesMessage(FacesMessage.SEVERITY_ERROR, "Range select error",
"Please make sure to fill in the from and to dates"));
} else {
Long fromTime = this.getFromTime().getTime();
Long toTime = this.getToTime().getTime();
Long now = Calendar.getInstance().getTime().getTime();
if ((toTime == null) || (fromTime == null)) {
facesContext.addMessage(null, new FacesMessage(FacesMessage.SEVERITY_ERROR, "Timing error",
"Please fill in the required fields"));
} else if (toTime < fromTime) {
facesContext.addMessage(null, new FacesMessage(FacesMessage.SEVERITY_ERROR, "Timing error",
"To time cannot be earlier than before time"));
} else if (toTime > now || fromTime > now) {
facesContext.addMessage(null, new FacesMessage(FacesMessage.SEVERITY_ERROR, "Timing error",
"Cannot set time interval in the future"));
} else {
rangePreferences.readOnly = true;
rangePreferences.begin = fromTime;
rangePreferences.end = toTime;
}
facesContext.addMessage(null, new FacesMessage(FacesMessage.SEVERITY_INFO, "Preferences updated",
"Your preferences have been successfully updated"));
}
}
preferences.setMetricRangePreferences(rangePreferences);
}