modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/components/form/DurationItem.java | 366 ++++++++++ modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/components/form/EnhancedDynamicForm.java | 5 modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/components/form/EnumSelectItem.java | 2 modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/components/form/RadioGroupWithComponentsItem.java | 2 modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/gwt/OperationGWTService.java | 5 modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/common/detail/operation/schedule/AbstractOperationScheduleDataSource.java | 3 modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/common/detail/operation/schedule/AbstractOperationScheduleDetailsView.java | 44 - modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/groups/detail/operation/schedule/GroupOperationScheduleDataSource.java | 30 modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/resource/detail/operation/schedule/ResourceOperationScheduleDataSource.java | 16 modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/util/RecordUtility.java | 66 + modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/server/gwt/OperationGWTServiceImpl.java | 13 modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/operation/OperationManagerBean.java | 20 modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/operation/OperationManagerLocal.java | 18 13 files changed, 564 insertions(+), 26 deletions(-)
New commits: commit 21043546ed5662d821bc58fa6993d743894b3012 Author: Ian Springer ian.springer@redhat.com Date: Wed Feb 2 20:39:40 2011 -0500
write new DurationItem widget and start integrating it into the op schedule views
diff --git a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/components/form/DurationItem.java b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/components/form/DurationItem.java new file mode 100644 index 0000000..d83841f --- /dev/null +++ b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/components/form/DurationItem.java @@ -0,0 +1,366 @@ +/* + * RHQ Management Platform + * Copyright (C) 2005-2011 Red Hat, Inc. + * All rights reserved. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License, version 2, as + * published by the Free Software Foundation, and/or the GNU Lesser + * General Public License, version 2.1, also 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 and the GNU Lesser General Public License + * for more details. + * + * You should have received a copy of the GNU General Public License + * and the GNU Lesser 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. + */ +package org.rhq.enterprise.gui.coregui.client.components.form; + +import com.smartgwt.client.widgets.form.DynamicForm; +import com.smartgwt.client.widgets.form.fields.CanvasItem; +import com.smartgwt.client.widgets.form.fields.ComboBoxItem; +import com.smartgwt.client.widgets.form.fields.IntegerItem; +import com.smartgwt.client.widgets.form.fields.events.ChangedEvent; +import com.smartgwt.client.widgets.form.fields.events.ChangedHandler; +import com.smartgwt.client.widgets.form.validator.IntegerRangeValidator; +import org.rhq.enterprise.gui.coregui.client.util.FormUtility; +import org.rhq.enterprise.gui.coregui.client.util.selenium.Locatable; + +import java.util.LinkedHashMap; +import java.util.Set; +import java.util.TreeSet; + +/** + * A form item for entering a time duration - consists of an IntegerItem for entering the amount of time and a + * ComboBoxItem for entering the time units. + * + * @author Ian Springer + */ +public class DurationItem extends CanvasItem { + + private static final String FIELD_VALUE = "value"; + private static final String FIELD_UNITS = "units"; + + private final DynamicForm form; + private TimeUnit defaultUnit; + private String contextualHelp; + private boolean iterationsSupported; + private TimeUnit valueUnit; + + public DurationItem(String name, String title, Set<TimeUnit> supportedUnits, boolean iterationsSupported, + Locatable parentWidget) { + super(name, title); + + this.iterationsSupported = iterationsSupported; + + this.form = new EnhancedDynamicForm(parentWidget.extendLocatorId(name), false, false); + this.form.setNumCols(4); + this.form.setColWidths("140", "90", "105", "*"); + + final IntegerItem valueItem = new IntegerItem(FIELD_VALUE, title); + valueItem.setShowTitle(getShowTitle()); + valueItem.setValue(getValue()); + IntegerRangeValidator integerRangeValidator = new IntegerRangeValidator(); + integerRangeValidator.setMin(1); + valueItem.setValidators(integerRangeValidator); + valueItem.setValidateOnChange(getValidateOnChange()); + valueItem.setValidateOnExit(getValidateOnExit()); + + valueItem.addChangedHandler(new ChangedHandler() { + public void onChanged(ChangedEvent event) { + updateValue(); + } + }); + + ComboBoxItem unitsItem = new ComboBoxItem(FIELD_UNITS); + unitsItem.setShowTitle(false); + + // TODO: i18n valueMap values + LinkedHashMap<String, String> valueMap = new LinkedHashMap<String, String>(); + if (iterationsSupported) { + valueMap.put("times", "times"); + } + if (supportedUnits != null && !supportedUnits.isEmpty()) { + TreeSet<TimeUnit> sortedSupportedUnits = new TreeSet<TimeUnit>(supportedUnits); + for (TimeUnit unit : sortedSupportedUnits) { + valueMap.put(unit.name().toLowerCase(), unit.name().toLowerCase()); + } + this.valueUnit = sortedSupportedUnits.iterator().next(); + unitsItem.setValueMap(valueMap); + } + + if (this.defaultUnit != null) { + unitsItem.setDefaultValue(this.defaultUnit.name().toLowerCase()); + } else { + unitsItem.setDefaultToFirstOption(true); + } + + if (this.contextualHelp != null) { + FormUtility.addContextualHelp(unitsItem, this.contextualHelp); + } + + unitsItem.addChangedHandler(new ChangedHandler() { + public void onChanged(ChangedEvent event) { + updateValue(); + } + }); + + this.form.setFields(valueItem, unitsItem); + valueItem.setWidth(90); + unitsItem.setWidth(105); + + setCanvas(this.form); + } + + public void setValue(Object value) { + Integer intValue; + if (value instanceof String) { + intValue = Integer.valueOf((String)value); + } else if (value instanceof Integer) { + intValue = (Integer) value; + } else { + intValue = null; + } + + if (intValue != null) { + this.form.setValue(FIELD_VALUE, intValue); + } else { + this.form.setValue(FIELD_VALUE, (String)null); + } + + super.setValue(value); + } + + private void updateValue() { + Integer convertedValue = null; + + IntegerItem valueItem = (IntegerItem) this.form.getItem(FIELD_VALUE); + Object value = valueItem.getValue(); + Integer intValue; + if (value instanceof String) { + intValue = Integer.valueOf((String)value); + } else if (value instanceof Integer) { + intValue = (Integer) value; + } else { + intValue = null; + } + + if (intValue != null) { + TimeUnit unit = getInputTimeUnit(); + if (unit == null) { + convertedValue = intValue; + } else { + if (unit.compareTo(this.valueUnit) < 0) { + throw new IllegalStateException("Input unit is less than target unit."); + } + switch (unit) { + case MILLISECONDS: + switch (this.valueUnit) { + case MILLISECONDS: + convertedValue = intValue; + break; + } + break; + case SECONDS: + switch (this.valueUnit) { + case SECONDS: + convertedValue = intValue; + break; + case MILLISECONDS: + convertedValue = intValue * 1000; + break; + } + break; + case MINUTES: + switch (this.valueUnit) { + case MINUTES: + convertedValue = intValue; + break; + case SECONDS: + convertedValue = intValue * 60; + break; + case MILLISECONDS: + convertedValue = intValue * 60 * 1000; + break; + } + break; + case HOURS: + switch (this.valueUnit) { + case HOURS: + convertedValue = intValue; + break; + case MINUTES: + convertedValue = intValue * 60; + break; + case SECONDS: + convertedValue = intValue * 60 * 60; + break; + case MILLISECONDS: + convertedValue = intValue * 60 * 60 * 1000; + break; + } + break; + case DAYS: + switch (this.valueUnit) { + case DAYS: + convertedValue = intValue; + break; + case HOURS: + convertedValue = intValue * 24; + break; + case MINUTES: + convertedValue = intValue * 24 * 60; + break; + case SECONDS: + convertedValue = intValue * 24 * 60 * 60; + break; + case MILLISECONDS: + convertedValue = intValue * 24 * 60 * 60 * 1000; + break; + } + break; + case WEEKS: + switch (this.valueUnit) { + case WEEKS: + convertedValue = intValue; + break; + case DAYS: + convertedValue = intValue * 7; + break; + case HOURS: + convertedValue = intValue * 7 * 24; + break; + case MINUTES: + convertedValue = intValue * 7 * 24 * 60; + break; + case SECONDS: + convertedValue = intValue * 7 * 24 * 60 * 60; + break; + case MILLISECONDS: + convertedValue = intValue * 7 * 24 * 60 * 60 * 1000; + break; + } + break; + case MONTHS: + switch (this.valueUnit) { + case MONTHS: + convertedValue = intValue; + break; + case WEEKS: + convertedValue = intValue * 4; + break; + case DAYS: + convertedValue = intValue * 30; + break; + case HOURS: + convertedValue = intValue * 30 * 24; + break; + case MINUTES: + convertedValue = intValue * 30 * 24 * 60; + break; + case SECONDS: + convertedValue = intValue * 30 * 24 * 60 * 60; + break; + case MILLISECONDS: + convertedValue = intValue * 30 * 24 * 60 * 60 * 1000; + break; + } + break; + case YEARS: + switch (this.valueUnit) { + case YEARS: + convertedValue = intValue; + break; + case MONTHS: + convertedValue = intValue * 12; + break; + case WEEKS: + convertedValue = intValue * 52; + break; + case DAYS: + convertedValue = intValue * 365; + break; + case HOURS: + convertedValue = intValue * 365 * 24; + break; + case MINUTES: + convertedValue = intValue * 365 * 24 * 60; + break; + case SECONDS: + convertedValue = intValue * 365 * 24 * 60 * 60; + break; + case MILLISECONDS: + convertedValue = intValue * 365 * 24 * 60 * 60 * 1000; + break; + } + break; + } + } + } + + super.setValue(convertedValue); + } + + private TimeUnit getInputTimeUnit() { + ComboBoxItem unitsItem = (ComboBoxItem) this.form.getItem(FIELD_UNITS); + String unitString = unitsItem.getValueAsString(); // this will always be non-null + TimeUnit unit; + try { + unit = TimeUnit.valueOf(unitString.toUpperCase()); + } catch (IllegalArgumentException e) { + // not a time unit, so unit must be "times" (i.e. iterations) + unit = null; + } + return unit; + } + + public Integer getValueAsInteger() { + return (Integer) getValue(); + } + + @Override + public Boolean validate() { + return this.form.validate(); + } + + public void setDefaultUnit(TimeUnit defaultUnit) { + this.defaultUnit = defaultUnit; + } + + public void setContextualHelp(String contextualHelp) { + this.contextualHelp = contextualHelp; + } + + /** + * Returns the time unit of this item's {@link #getValue() value} - if null, the item's value represents an iteration + * count, not a time duration. + * + * @return the time unit of this item's {@link #getValue() value} - if null, the item's value represents an iteration + * count, not a time duration + */ + public TimeUnit getValueUnit() { + return this.valueUnit; + } + + @Override + public String toString() { + Object value = form.getValue(FIELD_VALUE); + String string; + if (value != null) { + TimeUnit timeUnit = getInputTimeUnit(); + String unitString = (timeUnit != null) ? timeUnit.name().toLowerCase() : "times"; + string = value + " " + unitString; + } else { + string = ""; + } + + return string; + } + +} diff --git a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/components/form/EnhancedDynamicForm.java b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/components/form/EnhancedDynamicForm.java index e846a1d..27df563 100644 --- a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/components/form/EnhancedDynamicForm.java +++ b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/components/form/EnhancedDynamicForm.java @@ -101,7 +101,7 @@ public class EnhancedDynamicForm extends LocatableDynamicForm { hasIdField = true; } if (this.isReadOnly) { - if ((item instanceof StaticTextItem) || (item instanceof CanvasItem)) { + if ((item instanceof StaticTextItem) || (item instanceof CanvasItem && !(item instanceof DurationItem))) { // note: EditableFormItem is a subclass of CanvasItem if (item instanceof EditableFormItem) { ((EditableFormItem) item).setReadOnly(true); @@ -110,7 +110,8 @@ public class EnhancedDynamicForm extends LocatableDynamicForm { } else { StaticTextItem staticItem = new StaticTextItem(item.getName(), item.getTitle()); staticItem.setTooltip(item.getTooltip()); - staticItem.setValue(item.getValue()); + Object value = (item instanceof DurationItem) ? item.toString() : item.getValue(); + staticItem.setValue(value); staticItem.setColSpan(item.getAttribute("colSpan")); // TODO: Any other fields we should copy? icons?
diff --git a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/components/form/EnumSelectItem.java b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/components/form/EnumSelectItem.java index e1a09fe..c5404de 100644 --- a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/components/form/EnumSelectItem.java +++ b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/components/form/EnumSelectItem.java @@ -31,7 +31,7 @@ import com.smartgwt.client.types.MultipleAppearance; import com.smartgwt.client.widgets.form.fields.SelectItem;
/** - * A convenients class for exposing an {@link Enum} as a multi-select form item. + * A convenience class for exposing an {@link Enum} as a multi-select form item. * * @author Joseph Marques */ diff --git a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/components/form/RadioGroupWithComponentsItem.java b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/components/form/RadioGroupWithComponentsItem.java index 9412237..e75ee44 100644 --- a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/components/form/RadioGroupWithComponentsItem.java +++ b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/components/form/RadioGroupWithComponentsItem.java @@ -38,6 +38,8 @@ import com.smartgwt.client.widgets.form.fields.events.ChangedHandler; import org.rhq.enterprise.gui.coregui.client.util.selenium.LocatableDynamicForm;
/** + * TODO + * * @author Greg Hinkle */ public class RadioGroupWithComponentsItem extends CanvasItem { diff --git a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/gwt/OperationGWTService.java b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/gwt/OperationGWTService.java index 194c921..a3b402a 100644 --- a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/gwt/OperationGWTService.java +++ b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/gwt/OperationGWTService.java @@ -34,6 +34,7 @@ import org.rhq.core.domain.operation.composite.ResourceOperationScheduleComposit import org.rhq.core.domain.resource.composite.DisambiguationReport; import org.rhq.core.domain.util.PageControl; import org.rhq.core.domain.util.PageList; +import org.rhq.enterprise.gui.coregui.server.util.SerialUtility;
/** * @author Greg Hinkle @@ -61,6 +62,10 @@ public interface OperationGWTService extends RemoteService {
int scheduleGroupOperation(GroupOperationSchedule groupOperationSchedule) throws RuntimeException;
+ ResourceOperationSchedule getResourceOperationSchedule(int scheduleId); + + GroupOperationSchedule getGroupOperationSchedule(int scheduleId); + void unscheduleResourceOperation(ResourceOperationSchedule resourceOperationSchedule) throws RuntimeException;
void unscheduleGroupOperation(GroupOperationSchedule groupOperationSchedule) throws RuntimeException; diff --git a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/common/detail/operation/schedule/AbstractOperationScheduleDataSource.java b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/common/detail/operation/schedule/AbstractOperationScheduleDataSource.java index 56e7d52..f927030 100644 --- a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/common/detail/operation/schedule/AbstractOperationScheduleDataSource.java +++ b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/common/detail/operation/schedule/AbstractOperationScheduleDataSource.java @@ -42,6 +42,7 @@ import org.rhq.core.domain.resource.ResourceType; import org.rhq.enterprise.gui.coregui.client.gwt.GWTServiceLookup; import org.rhq.enterprise.gui.coregui.client.gwt.OperationGWTServiceAsync; import org.rhq.enterprise.gui.coregui.client.util.RPCDataSource; +import org.rhq.enterprise.gui.coregui.client.util.RecordUtility;
/** * @author Ian Springer @@ -134,7 +135,7 @@ public abstract class AbstractOperationScheduleDataSource<T extends OperationSch SubjectRecord subjectRecord = (SubjectRecord) from.getAttributeAsRecord(Field.SUBJECT); to.setSubject(subjectRecord.toSubject()); Configuration parameters = (Configuration) from.getAttributeAsObject(Field.PARAMETERS); - Integer timeout = from.getAttributeAsInt(Field.TIMEOUT); + Integer timeout = RecordUtility.getAttributeAsInteger(from, Field.TIMEOUT); if (timeout != null) { if (parameters == null) { parameters = new Configuration(); diff --git a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/common/detail/operation/schedule/AbstractOperationScheduleDetailsView.java b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/common/detail/operation/schedule/AbstractOperationScheduleDetailsView.java index 1ea15db..7d01228 100644 --- a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/common/detail/operation/schedule/AbstractOperationScheduleDetailsView.java +++ b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/common/detail/operation/schedule/AbstractOperationScheduleDetailsView.java @@ -22,7 +22,7 @@ package org.rhq.enterprise.gui.coregui.client.inventory.common.detail.operation. import java.util.ArrayList; import java.util.Date; import java.util.HashMap; -import java.util.LinkedHashMap; +import java.util.HashSet; import java.util.List; import java.util.Map; import java.util.Set; @@ -31,16 +31,13 @@ import com.smartgwt.client.data.DSRequest; import com.smartgwt.client.data.Record; import com.smartgwt.client.widgets.Canvas; import com.smartgwt.client.widgets.HTMLFlow; -import com.smartgwt.client.widgets.form.fields.ComboBoxItem; import com.smartgwt.client.widgets.form.fields.FormItem; -import com.smartgwt.client.widgets.form.fields.IntegerItem; import com.smartgwt.client.widgets.form.fields.SelectItem; import com.smartgwt.client.widgets.form.fields.StaticTextItem; import com.smartgwt.client.widgets.form.fields.TextAreaItem; import com.smartgwt.client.widgets.form.fields.events.ChangedEvent; import com.smartgwt.client.widgets.form.fields.events.ChangedHandler;
-import com.smartgwt.client.widgets.form.validator.IntegerRangeValidator; import com.smartgwt.client.widgets.grid.ListGridRecord; import com.smartgwt.client.widgets.layout.VLayout; import org.rhq.core.domain.auth.Subject; @@ -52,7 +49,9 @@ import org.rhq.enterprise.gui.coregui.client.UserSessionManager; import org.rhq.enterprise.gui.coregui.client.ViewPath; import org.rhq.enterprise.gui.coregui.client.components.configuration.ConfigurationEditor; import org.rhq.enterprise.gui.coregui.client.components.form.AbstractRecordEditor; +import org.rhq.enterprise.gui.coregui.client.components.form.DurationItem; import org.rhq.enterprise.gui.coregui.client.components.form.EnhancedDynamicForm; +import org.rhq.enterprise.gui.coregui.client.components.form.TimeUnit; import org.rhq.enterprise.gui.coregui.client.components.trigger.JobTriggerEditor; import org.rhq.enterprise.gui.coregui.client.inventory.resource.detail.operation.schedule.ResourceOperationScheduleDataSource; import org.rhq.enterprise.gui.coregui.client.util.FormUtility; @@ -156,7 +155,7 @@ public abstract class AbstractOperationScheduleDetailsView extends AbstractRecor contentPane.addMember(hr); }
- this.timeoutForm = new EnhancedDynamicForm(extendLocatorId("TimeoutForm"), isReadOnly(), isNewRecord()); + /*this.timeoutForm = new EnhancedDynamicForm(extendLocatorId("TimeoutForm"), isReadOnly(), isNewRecord()); this.timeoutForm.setNumCols(4); this.timeoutForm.setColWidths("140", "90", "105", "*");
@@ -177,6 +176,7 @@ public abstract class AbstractOperationScheduleDetailsView extends AbstractRecor timeoutItem.setWidth(90); timeoutUnitsItem.setWidth(105); contentPane.addMember(this.timeoutForm); + */
this.notesForm = new EnhancedDynamicForm(extendLocatorId("NotesForm"), isReadOnly(), isNewRecord()); @@ -184,8 +184,17 @@ public abstract class AbstractOperationScheduleDetailsView extends AbstractRecor
List<FormItem> notesFields = new ArrayList<FormItem>();
+ Set<TimeUnit> supportedUnits = new HashSet<TimeUnit>(3); + supportedUnits.add(TimeUnit.SECONDS); + supportedUnits.add(TimeUnit.MINUTES); + supportedUnits.add(TimeUnit.HOURS); + DurationItem timeoutItem = new DurationItem(AbstractOperationScheduleDataSource.Field.TIMEOUT, "Timeout", + supportedUnits, false, this.notesForm); + notesFields.add(timeoutItem); + if (!isNewRecord()) { - StaticTextItem nextFireTimeItem = new StaticTextItem(AbstractOperationScheduleDataSource.Field.NEXT_FIRE_TIME, "Next Fire Time"); + StaticTextItem nextFireTimeItem = new StaticTextItem(AbstractOperationScheduleDataSource.Field.NEXT_FIRE_TIME, + "Next Fire Time"); notesFields.add(nextFireTimeItem); }
@@ -229,15 +238,21 @@ public abstract class AbstractOperationScheduleDetailsView extends AbstractRecor refreshOperationDescriptionItem(); refreshOperationParametersItem();
- if (!isNewRecord()) { - FormItem nextFireTimeItem = this.notesForm.getField(ResourceOperationScheduleDataSource.Field.NEXT_FIRE_TIME); - nextFireTimeItem.setValue(getForm().getValue(ResourceOperationScheduleDataSource.Field.NEXT_FIRE_TIME)); - } + super.editRecord(record); + } + + @Override + protected void editExistingRecord(Record record) { + FormItem nextFireTimeItem = this.notesForm.getField(ResourceOperationScheduleDataSource.Field.NEXT_FIRE_TIME); + nextFireTimeItem.setValue(getForm().getValue(ResourceOperationScheduleDataSource.Field.NEXT_FIRE_TIME)); + + FormItem timeoutItem = this.notesForm.getField(AbstractOperationScheduleDataSource.Field.TIMEOUT); + timeoutItem.setValue(getForm().getValue(AbstractOperationScheduleDataSource.Field.TIMEOUT));
FormItem notesItem = this.notesForm.getField(ResourceOperationScheduleDataSource.Field.DESCRIPTION); notesItem.setValue(getForm().getValue(ResourceOperationScheduleDataSource.Field.DESCRIPTION));
- super.editRecord(record); + super.editExistingRecord(record); }
@Override @@ -269,8 +284,11 @@ public abstract class AbstractOperationScheduleDetailsView extends AbstractRecor
form.setValue("jobTrigger", jobTriggerRecord);
- FormItem notesItem = this.notesForm.getField(ResourceOperationScheduleDataSource.Field.DESCRIPTION); - form.setValue(ResourceOperationScheduleDataSource.Field.DESCRIPTION, (String)notesItem.getValue()); + DurationItem timeoutItem = (DurationItem)this.notesForm.getItem(AbstractOperationScheduleDataSource.Field.TIMEOUT); + form.setValue(AbstractOperationScheduleDataSource.Field.TIMEOUT, timeoutItem.getValueAsInteger()); + + FormItem notesItem = this.notesForm.getField(AbstractOperationScheduleDataSource.Field.DESCRIPTION); + form.setValue(AbstractOperationScheduleDataSource.Field.DESCRIPTION, (String)notesItem.getValue());
super.save(requestProperties); } diff --git a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/groups/detail/operation/schedule/GroupOperationScheduleDataSource.java b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/groups/detail/operation/schedule/GroupOperationScheduleDataSource.java index 188a892..1aebfec 100644 --- a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/groups/detail/operation/schedule/GroupOperationScheduleDataSource.java +++ b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/groups/detail/operation/schedule/GroupOperationScheduleDataSource.java @@ -60,19 +60,33 @@ public class GroupOperationScheduleDataSource extends AbstractOperationScheduleD
@Override protected void executeFetch(final DSRequest request, final DSResponse response) { - operationService.findScheduledGroupOperations(this.groupComposite.getResourceGroup().getId(), - new AsyncCallback<List<GroupOperationSchedule>>() { - public void onSuccess(List<GroupOperationSchedule> result) { - Record[] records = buildRecords(result); - response.setData(records); - processResponse(request.getRequestId(), response); + final Integer scheduleId = request.getCriteria().getAttributeAsInt(AbstractOperationScheduleDataSource.Field.ID); + if (scheduleId != null) { + operationService.getGroupOperationSchedule(scheduleId, new AsyncCallback<GroupOperationSchedule>() { + public void onSuccess(GroupOperationSchedule result) { + sendSuccessResponse(request, response, result); }
public void onFailure(Throwable caught) { - throw new RuntimeException("Failed to find scheduled operations for " - + groupComposite.getResourceGroup() + ".", caught); + sendFailureResponse(request, response, "Failed to fetch GroupOperationSchedule with id " + + scheduleId + ".", caught); } }); + } else { + operationService.findScheduledGroupOperations(this.groupComposite.getResourceGroup().getId(), + new AsyncCallback<List<GroupOperationSchedule>>() { + public void onSuccess(List<GroupOperationSchedule> result) { + Record[] records = buildRecords(result); + response.setData(records); + processResponse(request.getRequestId(), response); + } + + public void onFailure(Throwable caught) { + throw new RuntimeException("Failed to find scheduled operations for " + + groupComposite.getResourceGroup() + ".", caught); + } + }); + } }
@Override diff --git a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/resource/detail/operation/schedule/ResourceOperationScheduleDataSource.java b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/resource/detail/operation/schedule/ResourceOperationScheduleDataSource.java index 0950a70..cb4f95c 100644 --- a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/resource/detail/operation/schedule/ResourceOperationScheduleDataSource.java +++ b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/resource/detail/operation/schedule/ResourceOperationScheduleDataSource.java @@ -55,7 +55,20 @@ public class ResourceOperationScheduleDataSource extends AbstractOperationSchedu
@Override protected void executeFetch(final DSRequest request, final DSResponse response) { - operationService.findScheduledResourceOperations(this.resourceComposite.getResource().getId(), + final Integer scheduleId = request.getCriteria().getAttributeAsInt(Field.ID); + if (scheduleId != null) { + operationService.getResourceOperationSchedule(scheduleId, new AsyncCallback<ResourceOperationSchedule>() { + public void onSuccess(ResourceOperationSchedule result) { + sendSuccessResponse(request, response, result); + } + + public void onFailure(Throwable caught) { + sendFailureResponse(request, response, "Failed to fetch ResourceOperationSchedule with id " + + scheduleId + ".", caught); + } + }); + } else { + operationService.findScheduledResourceOperations(this.resourceComposite.getResource().getId(), new AsyncCallback<List<ResourceOperationSchedule>>() { public void onSuccess(List<ResourceOperationSchedule> result) { Record[] records = buildRecords(result); @@ -68,6 +81,7 @@ public class ResourceOperationScheduleDataSource extends AbstractOperationSchedu + resourceComposite.getResource() + ".", caught); } }); + } }
@Override diff --git a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/util/RecordUtility.java b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/util/RecordUtility.java new file mode 100644 index 0000000..b8f1e77 --- /dev/null +++ b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/util/RecordUtility.java @@ -0,0 +1,66 @@ +/* + * RHQ Management Platform + * Copyright (C) 2011 Red Hat, Inc. + * All rights reserved. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation version 2 of the License. + * + * 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., 675 Mass Ave, Cambridge, MA 02139, USA. + */ +package org.rhq.enterprise.gui.coregui.client.util; + +import com.smartgwt.client.data.Record; + +/** + * A collection of utility methods for working with SmartGWT {@link Record}s. + * + * @author Ian Springer + */ +public class RecordUtility { + + private RecordUtility() { + // static utility class only + } + + public static Integer getAttributeAsInteger(Record record, String attributeName) { + Object value; + try { + value = record.getAttributeAsInt(attributeName); + } catch (Exception e) { + try { + value = record.getAttributeAsDouble(attributeName); + } catch (Exception e1) { + try { + value = record.getAttributeAsString(attributeName); + } catch (Exception e2) { + throw new RuntimeException("Failed to obtain value of attribute [" + attributeName + "] of Record [" + + record + "]."); + } + } + } + + Integer integerValue; + if (value instanceof Number) { + integerValue = ((Number) value).intValue(); + } else if (value instanceof String) { + integerValue = Integer.parseInt((String) value); + } else if (value == null) { + integerValue = null; + } else { + throw new RuntimeException("Value of attribute [" + attributeName + "] of Record [" + record + + "] is not an integer."); + } + + return integerValue; + } + +} diff --git a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/server/gwt/OperationGWTServiceImpl.java b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/server/gwt/OperationGWTServiceImpl.java index d194adf..0bc70db 100644 --- a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/server/gwt/OperationGWTServiceImpl.java +++ b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/server/gwt/OperationGWTServiceImpl.java @@ -28,6 +28,7 @@ import org.rhq.core.domain.criteria.ResourceOperationHistoryCriteria; import org.rhq.core.domain.operation.GroupOperationHistory; import org.rhq.core.domain.operation.ResourceOperationHistory; import org.rhq.core.domain.operation.bean.GroupOperationSchedule; +import org.rhq.core.domain.operation.bean.OperationSchedule; import org.rhq.core.domain.operation.bean.ResourceOperationSchedule; import org.rhq.core.domain.operation.composite.ResourceOperationLastCompletedComposite; import org.rhq.core.domain.operation.composite.ResourceOperationScheduleComposite; @@ -119,6 +120,18 @@ public class OperationGWTServiceImpl extends AbstractGWTServiceImpl implements O } }
+ public ResourceOperationSchedule getResourceOperationSchedule(int scheduleId) { + ResourceOperationSchedule resourceOperationSchedule = + operationManager.getResourceOperationSchedule(getSessionSubject(), scheduleId); + return SerialUtility.prepare(resourceOperationSchedule, "getResourceOperationSchedule"); + } + + public GroupOperationSchedule getGroupOperationSchedule(int scheduleId) { + GroupOperationSchedule groupOperationSchedule = + operationManager.getGroupOperationSchedule(getSessionSubject(), scheduleId); + return SerialUtility.prepare(groupOperationSchedule, "getGroupOperationSchedule"); + } + public void unscheduleResourceOperation(ResourceOperationSchedule resourceOperationSchedule) throws RuntimeException { try { diff --git a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/operation/OperationManagerBean.java b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/operation/OperationManagerBean.java index 308f459..746b723 100644 --- a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/operation/OperationManagerBean.java +++ b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/operation/OperationManagerBean.java @@ -467,6 +467,26 @@ public class OperationManagerBean implements OperationManagerLocal, OperationMan return operationSchedules; }
+ public ResourceOperationSchedule getResourceOperationSchedule(Subject whoami, int scheduleId) { + OperationScheduleEntity operationScheduleEntity = entityManager.find(OperationScheduleEntity.class, scheduleId); + try { + ResourceOperationSchedule resourceOperationSchedule = getResourceOperationSchedule(whoami, operationScheduleEntity.getJobId().toString()); + return resourceOperationSchedule; + } catch (SchedulerException e) { + throw new RuntimeException("Failed to retrieve ResourceOperationSchedule with id [" + scheduleId + "].", e); + } + } + + public GroupOperationSchedule getGroupOperationSchedule(Subject whoami, int scheduleId) { + OperationScheduleEntity operationScheduleEntity = entityManager.find(OperationScheduleEntity.class, scheduleId); + try { + GroupOperationSchedule groupOperationSchedule = getGroupOperationSchedule(whoami, operationScheduleEntity.getJobId().toString()); + return groupOperationSchedule; + } catch (SchedulerException e) { + throw new RuntimeException("Failed to retrieve GroupOperationSchedule with id [" + scheduleId + "].", e); + } + } + public ResourceOperationSchedule getResourceOperationSchedule(Subject whoami, JobDetail jobDetail) { JobDataMap jobDataMap = jobDetail.getJobDataMap();
diff --git a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/operation/OperationManagerLocal.java b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/operation/OperationManagerLocal.java index 846b54d..e365ee8 100644 --- a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/operation/OperationManagerLocal.java +++ b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/operation/OperationManagerLocal.java @@ -130,6 +130,24 @@ public interface OperationManagerLocal { throws SchedulerException;
/** + * TODO + * + * @param whoami + * @param scheduleId + * @return + */ + ResourceOperationSchedule getResourceOperationSchedule(Subject whoami, int scheduleId); + + /** + * TODO + * + * @param whoami + * @param scheduleId + * @return + */ + GroupOperationSchedule getGroupOperationSchedule(Subject whoami, int scheduleId); + + /** * This will delete an operation schedule entity identified with the given job ID. Note that this does <b>not</b> * actually unschedule the job - it merely removed our schedule tracking entity. This schedule tracking entity is * really just used to provide some additional querying capabilities since it allows us to link a resource or group
rhq-commits@lists.fedorahosted.org