diff --git a/cave/com.raytheon.uf.viz.datadelivery/src/com/raytheon/uf/viz/datadelivery/bandwidth/ui/GraphImage.java b/cave/com.raytheon.uf.viz.datadelivery/src/com/raytheon/uf/viz/datadelivery/bandwidth/ui/GraphImage.java
index 3631187ef0..463b077dcb 100644
--- a/cave/com.raytheon.uf.viz.datadelivery/src/com/raytheon/uf/viz/datadelivery/bandwidth/ui/GraphImage.java
+++ b/cave/com.raytheon.uf.viz.datadelivery/src/com/raytheon/uf/viz/datadelivery/bandwidth/ui/GraphImage.java
@@ -50,6 +50,7 @@ import com.raytheon.uf.viz.datadelivery.utils.DataDeliveryGUIUtils.SubscriptionP
* Nov 28, 2012 1269 lvenable Initial creation.
* Dec 13, 2012 1269 lvenable Fixes and updates.
* Jan 07, 2013 1451 djohnson Use TimeUtil.newGmtCalendar().
+ * Jan 04, 2013 1420 mpduff Change default priority to normal priority.
*
*
*
@@ -170,11 +171,11 @@ public class GraphImage extends AbstractCanvasImage {
for (String subName : subscriptionList) {
if (imageMgr.isColorByPriority()) {
- if (graphData.getPriority(subName) == SubscriptionPriority.DEFAULT
+ if (graphData.getPriority(subName) == SubscriptionPriority.NORMAL
.ordinal()) {
c = new Color(
display,
- imageMgr.getPriorityColor(SubscriptionPriority.DEFAULT));
+ imageMgr.getPriorityColor(SubscriptionPriority.NORMAL));
gc.setBackground(c);
} else if (graphData.getPriority(subName) == SubscriptionPriority.HIGH
.ordinal()) {
diff --git a/cave/com.raytheon.uf.viz.datadelivery/src/com/raytheon/uf/viz/datadelivery/common/ui/PriorityComp.java b/cave/com.raytheon.uf.viz.datadelivery/src/com/raytheon/uf/viz/datadelivery/common/ui/PriorityComp.java
index 5c40b5669a..5bd8c6b3ff 100644
--- a/cave/com.raytheon.uf.viz.datadelivery/src/com/raytheon/uf/viz/datadelivery/common/ui/PriorityComp.java
+++ b/cave/com.raytheon.uf.viz.datadelivery/src/com/raytheon/uf/viz/datadelivery/common/ui/PriorityComp.java
@@ -26,9 +26,13 @@ import org.eclipse.swt.widgets.Combo;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Group;
import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.Text;
+
+import com.raytheon.uf.viz.datadelivery.utils.DataDeliveryGUIUtils.SubscriptionPriority;
+
/**
- * This is the priority group information composite. This class is intended
- * to be extended so common classes can be created and shared.
+ * This is the priority group information composite. This class is intended to
+ * be extended so common classes can be created and shared.
*
*
*
@@ -38,6 +42,7 @@ import org.eclipse.swt.widgets.Label;
* ------------ ---------- ----------- --------------------------
* Jun 27, 2012 702 jpiatt Initial creation.
* Aug 21, 2012 712 mpduff Default to Default, and allow for setting the combo box.
+ * Jan 04, 2013 1420 mpduff Add latency.
*
*
*
@@ -47,15 +52,28 @@ import org.eclipse.swt.widgets.Label;
public class PriorityComp extends Composite {
/** Group Name combo box. */
private Combo priorityCombo;
-
+
+ /** Latency Text field */
+ private Text latencyText;
+
+ /** The latency value */
+ private final int latency;
+
+ /** The priority value */
+ private final int priority;
+
/**
* Constructor.
*
* @param parent
* Parent composite.
+ * @param latency
+ * @param priority
*/
- public PriorityComp(Composite parent) {
+ public PriorityComp(Composite parent, int latency, int priority) {
super(parent, SWT.NONE);
+ this.latency = latency;
+ this.priority = priority - 1;
init();
}
@@ -77,36 +95,56 @@ public class PriorityComp extends Composite {
createSubscriptionPriorityGroup();
}
-
+
/**
* Create the Subscriptions Priority Group
*/
private void createSubscriptionPriorityGroup() {
-
+
GridData gd = new GridData(SWT.FILL, SWT.DEFAULT, true, false);
GridLayout gl = new GridLayout(1, false);
-
+
Group subPriorityGroup = new Group(this, SWT.NONE);
subPriorityGroup.setLayout(gl);
subPriorityGroup.setLayoutData(gd);
- subPriorityGroup.setText(" Subscription Priority ");
+ subPriorityGroup.setText(" Priority/Latency ");
Composite priorityComp = new Composite(subPriorityGroup, SWT.NONE);
gd = new GridData(SWT.FILL, SWT.DEFAULT, true, false);
gl = new GridLayout(2, false);
priorityComp.setLayoutData(gd);
priorityComp.setLayout(gl);
-
- Label priority = new Label(priorityComp, SWT.NONE);
- priority.setText(" Priority: ");
-
+
+ Label priorityLbl = new Label(priorityComp, SWT.NONE);
+ priorityLbl.setText(" Priority: ");
+
+ SubscriptionPriority[] prioritiesArr = SubscriptionPriority.values();
+ String[] priorities = new String[prioritiesArr.length];
+ for (int i = 0; i < prioritiesArr.length; i++) {
+ priorities[i] = prioritiesArr[i].getPriorityName();
+ }
gd = new GridData(285, SWT.DEFAULT);
+ gd = new GridData(SWT.FILL, SWT.DEFAULT, true, false);
priorityCombo = new Combo(priorityComp, SWT.READ_ONLY);
- priorityCombo.setItems(new String[] { "High", "Default", "Low" });
- priorityCombo.select(1); // Default to the Default setting
+ priorityCombo.setItems(priorities);
+ priorityCombo.select(this.priority);
priorityCombo.setLayoutData(gd);
priorityCombo.setToolTipText("Select a priority");
+ Composite latencyComp = new Composite(subPriorityGroup, SWT.NONE);
+ gd = new GridData(SWT.FILL, SWT.DEFAULT, true, false);
+ gl = new GridLayout(2, false);
+ latencyComp.setLayout(gl);
+ latencyComp.setLayoutData(gd);
+
+ Label latencyLbl = new Label(latencyComp, SWT.NONE);
+ latencyLbl.setText("Latency (Minutes):");
+
+ latencyText = new Text(latencyComp, SWT.BORDER);
+ latencyText.setLayoutData(new GridData(SWT.FILL, SWT.DEFAULT, true,
+ false));
+ latencyText.setToolTipText("Subscription Latency in Minutes");
+ latencyText.setText(String.valueOf(this.latency));
}
/**
@@ -128,4 +166,22 @@ public class PriorityComp extends Composite {
priorityCombo.select(index);
}
}
+
+ /**
+ * Return the latency value.
+ *
+ * @return The latency value entered, -1 if nothing entered or an invalid
+ * entry entered
+ */
+ public int getLatencyValue() {
+ String latency = latencyText.getText().trim();
+ int intLatency;
+ try {
+ intLatency = Integer.parseInt(latency);
+ } catch (NumberFormatException e) {
+ intLatency = -1;
+ }
+
+ return intLatency;
+ }
}
diff --git a/cave/com.raytheon.uf.viz.datadelivery/src/com/raytheon/uf/viz/datadelivery/subscription/CreateSubscriptionDlg.java b/cave/com.raytheon.uf.viz.datadelivery/src/com/raytheon/uf/viz/datadelivery/subscription/CreateSubscriptionDlg.java
index d16fe1bcb2..72c8531627 100644
--- a/cave/com.raytheon.uf.viz.datadelivery/src/com/raytheon/uf/viz/datadelivery/subscription/CreateSubscriptionDlg.java
+++ b/cave/com.raytheon.uf.viz.datadelivery/src/com/raytheon/uf/viz/datadelivery/subscription/CreateSubscriptionDlg.java
@@ -22,6 +22,7 @@ package com.raytheon.uf.viz.datadelivery.subscription;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
+import java.util.Set;
import org.eclipse.core.runtime.Status;
import org.eclipse.swt.SWT;
@@ -37,6 +38,7 @@ import org.eclipse.swt.widgets.Layout;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;
+import com.raytheon.uf.common.datadelivery.registry.Subscription;
import com.raytheon.uf.common.datadelivery.registry.ebxml.DataSetQuery;
import com.raytheon.uf.viz.datadelivery.common.ui.ActivePeriodComp;
import com.raytheon.uf.viz.datadelivery.common.ui.DeliveryOptionsComp;
@@ -44,6 +46,7 @@ import com.raytheon.uf.viz.datadelivery.common.ui.DurationComp;
import com.raytheon.uf.viz.datadelivery.common.ui.GroupSelectComp;
import com.raytheon.uf.viz.datadelivery.common.ui.PriorityComp;
import com.raytheon.uf.viz.datadelivery.subscription.view.ICreateSubscriptionDlgView;
+import com.raytheon.uf.viz.datadelivery.system.SystemRuleManager;
import com.raytheon.uf.viz.datadelivery.utils.DataDeliveryUtils;
import com.raytheon.viz.ui.dialogs.CaveSWTDialog;
import com.raytheon.viz.ui.presenter.components.ButtonConf;
@@ -75,13 +78,13 @@ import com.raytheon.viz.ui.presenter.components.ComboBoxConf;
* Nov 20, 2012 1286 djohnson Implement IDisplay to display yes/no prompt.
* Dec 13, 2012 1391 bgonzale Added cancel/ok selection status.
* Jan 02, 2013 1441 djohnson Add isGroupSelected().
+ * Jan 04, 2013 1420 mpduff Add latency.
*
*
*
* @author mpduff
* @version 1.0
*/
-
public class CreateSubscriptionDlg extends CaveSWTDialog implements
ICreateSubscriptionDlgView {
@@ -139,9 +142,15 @@ public class CreateSubscriptionDlg extends CaveSWTDialog implements
/** Did the user Status.OK or SWT.CANCEL subscription creation */
private int status = SWT.NONE;
+ /** The subscription object */
+ private Subscription subscription;
+
+ /** Available cycle times */
+ private Set cycleTimes;
+
/**
* Constructor.
- *
+ *
* @param parent
* The parent shell
* @param create
@@ -161,7 +170,7 @@ public class CreateSubscriptionDlg extends CaveSWTDialog implements
/*
* (non-Javadoc)
- *
+ *
* @see
* com.raytheon.viz.ui.dialogs.CaveSWTDialogBase#initializeComponents(org
* .eclipse.swt.widgets.Shell)
@@ -182,7 +191,12 @@ public class CreateSubscriptionDlg extends CaveSWTDialog implements
durComp = new DurationComp(mainComp);
activePeriodComp = new ActivePeriodComp(mainComp);
- priorityComp = new PriorityComp(mainComp);
+
+ // Get latency value
+ SystemRuleManager ruleManager = SystemRuleManager.getInstance();
+ int latency = ruleManager.getLatency(this.subscription, cycleTimes);
+ int priority = ruleManager.getPriority(this.subscription, cycleTimes);
+ priorityComp = new PriorityComp(mainComp, latency, priority);
this.createCycleGroup();
if (create == false) {
@@ -194,7 +208,7 @@ public class CreateSubscriptionDlg extends CaveSWTDialog implements
/*
* (non-Javadoc)
- *
+ *
* @see com.raytheon.viz.ui.dialogs.CaveSWTDialogBase#constructShellLayout()
*/
@Override
@@ -236,7 +250,6 @@ public class CreateSubscriptionDlg extends CaveSWTDialog implements
descNameTxt = new Text(subInfoGroup, SWT.BORDER);
descNameTxt.setLayoutData(new GridData(250, SWT.DEFAULT));
-
}
private void createChangeText() {
@@ -284,6 +297,9 @@ public class CreateSubscriptionDlg extends CaveSWTDialog implements
});
}
+ /**
+ * {@inheritDoc}
+ */
@Override
public void createCycleGroup() {
GridData gd = new GridData(SWT.FILL, SWT.DEFAULT, true, false);
@@ -316,6 +332,9 @@ public class CreateSubscriptionDlg extends CaveSWTDialog implements
cycleComp.setLayoutData(gd);
}
+ /**
+ * {@inheritDoc}
+ */
@Override
protected void preOpened() {
preOpenCallback.run();
@@ -324,16 +343,25 @@ public class CreateSubscriptionDlg extends CaveSWTDialog implements
shell.pack();
}
+ /**
+ * {@inheritDoc}
+ */
@Override
public void openDlg() {
this.open();
}
+ /**
+ * {@inheritDoc}
+ */
@Override
public int getDeliverySelection() {
return this.deliverComp.getDeliverSetting();
}
+ /**
+ * {@inheritDoc}
+ */
@Override
public String getSubscriptionName() {
if (create) {
@@ -343,6 +371,9 @@ public class CreateSubscriptionDlg extends CaveSWTDialog implements
}
}
+ /**
+ * {@inheritDoc}
+ */
@Override
public void setSubscriptionName(String subscriptionName) {
if (subscriptionName != null) {
@@ -354,141 +385,225 @@ public class CreateSubscriptionDlg extends CaveSWTDialog implements
}
}
+ /**
+ * {@inheritDoc}
+ */
@Override
public String getSubscriptionDescription() {
return this.descNameTxt.getText().trim();
}
+ /**
+ * {@inheritDoc}
+ */
@Override
public void setSubscriptionDescription(String subscriptionDescription) {
descNameTxt.setText(subscriptionDescription);
}
+ /**
+ * {@inheritDoc}
+ */
@Override
public String getGroupName() {
return this.groupSelectComp.getGroupName();
}
+ /**
+ * {@inheritDoc}
+ */
@Override
public void setDeliverySelection(int idx) {
deliverComp.setDeliverSetting(idx);
}
+ /**
+ * {@inheritDoc}
+ */
@Override
public boolean isNoExpirationDate() {
return this.durComp.isIndefiniteChk();
}
+ /**
+ * {@inheritDoc}
+ */
@Override
public void setNoExpiration(boolean noExpiration) {
durComp.setNoExpiration(noExpiration);
}
+ /**
+ * {@inheritDoc}
+ */
@Override
public String getStartText() {
return this.durComp.getStartText();
}
+ /**
+ * {@inheritDoc}
+ */
@Override
public void setStartDate(Date startDate) {
durComp.setStartDate(startDate);
}
+ /**
+ * {@inheritDoc}
+ */
@Override
public String getExpirationText() {
return this.durComp.getEndText();
}
+ /**
+ * {@inheritDoc}
+ */
@Override
public void setExpirationDate(Date expDate) {
durComp.setEndDate(expDate);
}
+ /**
+ * {@inheritDoc}
+ */
@Override
public boolean isAlwaysActive() {
return this.activePeriodComp.isAlwaysChk();
}
+ /**
+ * {@inheritDoc}
+ */
@Override
public void setAlwaysActive(boolean active) {
activePeriodComp.setAlwaysActive(active);
}
+ /**
+ * {@inheritDoc}
+ */
@Override
public String getActiveStartText() {
return this.activePeriodComp.getActiveStartText();
}
+ /**
+ * {@inheritDoc}
+ */
@Override
public void setActiveStartDate(Date activeStartDate) {
activePeriodComp.setStartDate(activeStartDate);
}
+ /**
+ * {@inheritDoc}
+ */
@Override
public String getActiveEndText() {
return this.activePeriodComp.getActiveEndText();
}
+ /**
+ * {@inheritDoc}
+ */
@Override
public void setActiveEndDate(Date activeEndDate) {
activePeriodComp.setEndDate(activeEndDate);
}
+ /**
+ * {@inheritDoc}
+ */
@Override
public int getPriority() {
return priorityComp.getPriorityIndex();
}
+ /**
+ * {@inheritDoc}
+ */
@Override
public void setPriority(int i) {
priorityComp.setPriorityIndex(i);
}
+ /**
+ * {@inheritDoc}
+ */
@Override
public void setGroupName(String groupName) {
groupSelectComp.setGroupName(groupName);
}
+ /**
+ * {@inheritDoc}
+ */
@Override
public void setSubscriptionDatesEnabled(boolean enabled) {
this.durComp.resetTextBoxes(enabled);
}
+ /**
+ * {@inheritDoc}
+ */
@Override
public void setStartDateBtnEnabled(boolean enabled) {
durComp.setStartBtnEnabled(enabled);
}
+ /**
+ * {@inheritDoc}
+ */
@Override
public void setEndDateBtnEnabled(boolean enabled) {
durComp.setEndBtnEnabled(enabled);
}
+ /**
+ * {@inheritDoc}
+ */
@Override
public void setActiveDatesEnabled(boolean enabled) {
this.activePeriodComp.resetTextBoxes(enabled);
}
+ /**
+ * {@inheritDoc}
+ */
@Override
public void setActiveEndDateBtnEnabled(boolean enabled) {
this.activePeriodComp.setEndBtnEnabled(enabled);
}
+ /**
+ * {@inheritDoc}
+ */
@Override
public void setActiveStartDateBtnEnabled(boolean enabled) {
this.activePeriodComp.setStartBtnEnabled(enabled);
}
+ /**
+ * {@inheritDoc}
+ */
@Override
public void setDeliveryOptionsComboConf(ComboBoxConf deliveryCombo) {
this.deliverComp.setDeliveryConfig(deliveryCombo);
}
+ /**
+ * {@inheritDoc}
+ */
@Override
public void setDeliveryOptions(String[] deliveryOptions) {
this.deliverComp.setDeliveryOptions(deliveryOptions);
}
+ /**
+ * {@inheritDoc}
+ */
@Override
public void setOkConf(final ButtonConf okConf) {
okBtn.setText(okConf.getDisplayText());
@@ -498,7 +613,8 @@ public class CreateSubscriptionDlg extends CaveSWTDialog implements
@Override
public void widgetSelected(SelectionEvent event) {
status = Status.OK;
- getShell().setCursor(getDisplay().getSystemCursor(SWT.CURSOR_WAIT));
+ getShell().setCursor(
+ getDisplay().getSystemCursor(SWT.CURSOR_WAIT));
okConf.getOnClickAction().run();
if (!getShell().isDisposed()) {
getShell().setCursor(null);
@@ -508,48 +624,73 @@ public class CreateSubscriptionDlg extends CaveSWTDialog implements
}
+ /**
+ * {@inheritDoc}
+ */
@Override
public boolean isCreate() {
return this.create;
}
+ /**
+ * {@inheritDoc}
+ */
@Override
public void selectAllSubscriptionName() {
this.subNameTxt.selectAll();
}
+ /**
+ * {@inheritDoc}
+ */
@Override
public String getChangeReason() {
return this.changeReasonTxt.getText().trim();
}
+ /**
+ * {@inheritDoc}
+ */
@Override
public void closeDlg() {
this.close();
}
+ /**
+ * {@inheritDoc}
+ */
@Override
public void init() {
}
+ /**
+ * {@inheritDoc}
+ */
@Override
public void displayPopup(String title, String message) {
- DataDeliveryUtils.showMessage(getShell(), SWT.OK,
- title, message);
+ DataDeliveryUtils.showMessage(getShell(), SWT.OK, title, message);
}
+ /**
+ * {@inheritDoc}
+ */
@Override
public boolean displayOkCancelPopup(String title, String message) {
return DataDeliveryUtils.showMessage(shell, SWT.CANCEL | SWT.OK, title,
message) == SWT.OK;
}
+ /**
+ * {@inheritDoc}
+ */
@Override
public void displayErrorPopup(String title, String message) {
- DataDeliveryUtils.showMessage(shell, SWT.ERROR,
- title, message);
+ DataDeliveryUtils.showMessage(shell, SWT.ERROR, title, message);
}
+ /**
+ * {@inheritDoc}
+ */
@Override
public List getCycleTimes() {
ArrayList cycleList = new ArrayList();
@@ -562,6 +703,9 @@ public class CreateSubscriptionDlg extends CaveSWTDialog implements
return cycleList;
}
+ /**
+ * {@inheritDoc}
+ */
@Override
public void setCycleConf(List checkboxConfList) {
hourBtnArr = new Button[checkboxConfList.size()];
@@ -580,6 +724,9 @@ public class CreateSubscriptionDlg extends CaveSWTDialog implements
}
}
+ /**
+ * {@inheritDoc}
+ */
@Override
public void setSelectAllButton(ButtonConf selectAllConf) {
selectAllBtn.addSelectionListener(new SelectionAdapter() {
@@ -595,6 +742,9 @@ public class CreateSubscriptionDlg extends CaveSWTDialog implements
selectAllBtn.setEnabled(selectAllConf.isEnabled());
}
+ /**
+ * {@inheritDoc}
+ */
@Override
public void setDeselectAllButton(ButtonConf deselectAllConf) {
deselectAllBtn.setSelection(true);
@@ -611,11 +761,17 @@ public class CreateSubscriptionDlg extends CaveSWTDialog implements
deselectAllBtn.setEnabled(deselectAllConf.isEnabled());
}
+ /**
+ * {@inheritDoc}
+ */
@Override
public void setDateTxtFieldsEnabled(boolean flag) {
this.durComp.resetTextBoxes(flag);
}
+ /**
+ * {@inheritDoc}
+ */
@Override
public void setActiveTextFieldsEnabled(boolean flag) {
this.activePeriodComp.resetTextBoxes(flag);
@@ -623,7 +779,7 @@ public class CreateSubscriptionDlg extends CaveSWTDialog implements
@Override
public void selectCycles(List cycleStrings) {
- for (Button b: this.hourBtnArr) {
+ for (Button b : this.hourBtnArr) {
if (cycleStrings.contains(b.getText())) {
b.setSelection(true);
}
@@ -655,8 +811,7 @@ public class CreateSubscriptionDlg extends CaveSWTDialog implements
}
/**
- * @param status
- * the status to set
+ * {@inheritDoc}
*/
@Override
public void setStatus(int status) {
@@ -670,4 +825,36 @@ public class CreateSubscriptionDlg extends CaveSWTDialog implements
public boolean isGroupSelected() {
return groupSelectComp.isGroupSelected();
}
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public int getLatencyValue() {
+ return priorityComp.getLatencyValue();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void setSubscription(Subscription subscription) {
+ this.subscription = subscription;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public int getPriorityValue() {
+ return priorityComp.getPriorityIndex();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void setCycleTimes(Set cycleTimes) {
+ this.cycleTimes = cycleTimes;
+ }
}
diff --git a/cave/com.raytheon.uf.viz.datadelivery/src/com/raytheon/uf/viz/datadelivery/subscription/presenter/CreateSubscriptionDlgPresenter.java b/cave/com.raytheon.uf.viz.datadelivery/src/com/raytheon/uf/viz/datadelivery/subscription/presenter/CreateSubscriptionDlgPresenter.java
index 9c435334ea..1d05c3d489 100644
--- a/cave/com.raytheon.uf.viz.datadelivery/src/com/raytheon/uf/viz/datadelivery/subscription/presenter/CreateSubscriptionDlgPresenter.java
+++ b/cave/com.raytheon.uf.viz.datadelivery/src/com/raytheon/uf/viz/datadelivery/subscription/presenter/CreateSubscriptionDlgPresenter.java
@@ -22,6 +22,7 @@ package com.raytheon.uf.viz.datadelivery.subscription.presenter;
import java.text.ParseException;
import java.util.ArrayList;
import java.util.Calendar;
+import java.util.Collections;
import java.util.Date;
import java.util.List;
import java.util.Set;
@@ -98,6 +99,7 @@ import com.raytheon.viz.ui.presenter.components.WidgetConf;
* Dec 18, 2012 1439 mpduff Redo subscription name validation.
* Jan 02, 2012 1345 djohnson Use gui thread task executor.
* Jan 02, 2013 1441 djohnson Access GroupDefinitionManager in a static fashion.
+ * Jan 04, 2012 1420 mpduff Add Latency to PriorityComp.
*
*
* @author mpduff
@@ -156,10 +158,14 @@ public class CreateSubscriptionDlgPresenter {
/** Group Definition object */
private GroupDefinition groupDefinition;
+ /** Create subscription flag */
private final boolean create;
private final IGuiThreadTaskExecutor guiThreadTaskExecutor;
+ @VisibleForTesting
+ Set cycleTimes;
+
/**
* Constructor.
*
@@ -216,6 +222,11 @@ public class CreateSubscriptionDlgPresenter {
init();
}
};
+ // Get cycles
+ cycleTimes = Sets.newTreeSet(((OpenDapGriddedDataSet) dataSet)
+ .getCycles());
+ this.view.setCycleTimes(cycleTimes);
+ this.view.setSubscription(this.subscription);
this.view.setPreOpenCallback(callback);
this.view.openDlg();
}
@@ -239,6 +250,15 @@ public class CreateSubscriptionDlgPresenter {
this.subscription = sub;
}
+ /**
+ * Get the subscription.
+ *
+ * @return the subscription
+ */
+ public Subscription getSubscription() {
+ return this.subscription;
+ }
+
/**
* Bring the view dialog to the top
*/
@@ -256,9 +276,6 @@ public class CreateSubscriptionDlgPresenter {
view.setDeliverySelection(0);
view.setOkConf(OK_CONF);
- // Get cycles
- Set cycleTimes = Sets
- .newTreeSet(((OpenDapGriddedDataSet) dataSet).getCycles());
final boolean hasCycleTimes = !cycleTimes.isEmpty();
this.cycleChkList = new ArrayList(cycleTimes.size());
@@ -345,8 +362,6 @@ public class CreateSubscriptionDlgPresenter {
view.setActiveEndDateBtnEnabled(false);
}
- view.setPriority(subscription.getPriority());
-
List cycleTimes = subscription.getTime().getCycleTimes();
if (cycleTimes != null) {
List cycleStrings = new ArrayList();
@@ -492,6 +507,8 @@ public class CreateSubscriptionDlgPresenter {
subscription.getTime().setCycleTimes(view.getCycleTimes());
+ subscription.setLatencyInMinutes(view.getLatencyValue());
+
IUser user = UserController.getUserObject();
ISubscriptionHandler handler = RegistryObjectHandlers
.get(ISubscriptionHandler.class);
@@ -594,9 +611,7 @@ public class CreateSubscriptionDlgPresenter {
statusHandler.handle(Priority.PROBLEM, e.getLocalizedMessage(),
e);
}
-
} else {
-
// Check for pending subscription, can only have one pending change
PendingSubscription pendingSub = new PendingSubscription(
subscription, LocalizationManager.getInstance()
@@ -759,10 +774,20 @@ public class CreateSubscriptionDlgPresenter {
boolean groupDeliverValid = false;
boolean groupDurValid = false;
boolean groupActiveValid = false;
+ boolean latencyValid = false;
// Validate the date entries
datesValid = this.durationValidChk();
activeDatesValid = this.activePeriodValidChk();
+ int maxLatency = getMaxLatency();
+ latencyValid = DataDeliveryGUIUtils.latencyValidChk(
+ view.getLatencyValue(), maxLatency);
+ if (!latencyValid) {
+ view.displayErrorPopup("Invalid Latency",
+ "Invalid latency value entered.\n\n"
+ + "Please enter a value in minutes between 0 and "
+ + maxLatency);
+ }
// Validate the subscription name if entered into text box
String subscriptionName = view.getSubscriptionName();
@@ -802,7 +827,8 @@ public class CreateSubscriptionDlgPresenter {
e);
}
}
- if (activeDatesValid && datesValid) {
+
+ if (activeDatesValid && datesValid && latencyValid) {
valid = true;
}
@@ -1005,6 +1031,27 @@ public class CreateSubscriptionDlgPresenter {
return datesValid && dateOrderValid;
}
+ /**
+ * Get the max latency allowed.
+ *
+ * @return The max latency value allowed
+ */
+ private int getMaxLatency() {
+ List cycles = dataSet.getTime().getCycleTimes();
+ Collections.sort(cycles);
+ int max = 0;
+
+ for (int i = 0; i < cycles.size(); i++) {
+ if (i + 1 <= cycles.size()) {
+ int tempMax = cycles.get(i + 1) - cycles.get(i);
+ if (tempMax > max) {
+ max = tempMax;
+ }
+ }
+ }
+ return max;
+ }
+
/**
* Add the registry id to the subscription object.
*/
diff --git a/cave/com.raytheon.uf.viz.datadelivery/src/com/raytheon/uf/viz/datadelivery/subscription/subset/GriddedSubsetManagerDlg.java b/cave/com.raytheon.uf.viz.datadelivery/src/com/raytheon/uf/viz/datadelivery/subscription/subset/GriddedSubsetManagerDlg.java
index a758a651e5..d83c24addd 100644
--- a/cave/com.raytheon.uf.viz.datadelivery/src/com/raytheon/uf/viz/datadelivery/subscription/subset/GriddedSubsetManagerDlg.java
+++ b/cave/com.raytheon.uf.viz.datadelivery/src/com/raytheon/uf/viz/datadelivery/subscription/subset/GriddedSubsetManagerDlg.java
@@ -75,6 +75,7 @@ import com.raytheon.uf.viz.datadelivery.utils.DataDeliveryUtils;
* Oct 11, 2012 1263 jpiatt Modified for cancel flag.
* Dec 10, 2012 1259 bsteffen Switch Data Delivery from LatLon to referenced envelopes.
* Jan 04, 2013 1299 djohnson Add logging of invalid forecast hour information if it occurs again.
+ * Jan 04, 2013 1420 mpduff Pass cycles in for rules.
*
*
*
@@ -251,6 +252,9 @@ public class GriddedSubsetManagerDlg
new IllegalStateException("Debugging stacktrace"));
}
+ /**
+ * {@inheritDoc}
+ */
@Override
public void updateDataSize() {
if (!initialized) {
@@ -276,8 +280,11 @@ public class GriddedSubsetManagerDlg
+ dataSize.getFullSize() + " KB");
}
+ /**
+ * {@inheritDoc}
+ */
@Override
- protected Time setupDataSpecificTime(Time newTime) {
+ protected Time setupDataSpecificTime(Time newTime, Subscription sub) {
if (asString.isEmpty()) {
SortedSet newestToOldest = new TreeSet(
Ordering.natural().reverse());
@@ -307,7 +314,8 @@ public class GriddedSubsetManagerDlg
}
GriddedTimingSelectionPresenter presenter = new GriddedTimingSelectionPresenter(
- new GriddedTimingSelectionDlg(getShell()), dataSet, asString);
+ new GriddedTimingSelectionDlg(getShell(), dataSet.getCycles(),
+ sub), dataSet, asString);
Integer cycle = presenter.open();
if (presenter.isCancel()) {
diff --git a/cave/com.raytheon.uf.viz.datadelivery/src/com/raytheon/uf/viz/datadelivery/subscription/subset/GriddedTimingSelectionDlg.java b/cave/com.raytheon.uf.viz.datadelivery/src/com/raytheon/uf/viz/datadelivery/subscription/subset/GriddedTimingSelectionDlg.java
index de3db5384b..473bd67b46 100644
--- a/cave/com.raytheon.uf.viz.datadelivery/src/com/raytheon/uf/viz/datadelivery/subscription/subset/GriddedTimingSelectionDlg.java
+++ b/cave/com.raytheon.uf.viz.datadelivery/src/com/raytheon/uf/viz/datadelivery/subscription/subset/GriddedTimingSelectionDlg.java
@@ -19,6 +19,8 @@
**/
package com.raytheon.uf.viz.datadelivery.subscription.subset;
+import java.util.Set;
+
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
@@ -30,7 +32,10 @@ import org.eclipse.swt.widgets.Layout;
import org.eclipse.swt.widgets.List;
import org.eclipse.swt.widgets.Shell;
+import com.raytheon.uf.common.datadelivery.registry.Subscription;
+import com.raytheon.uf.viz.datadelivery.common.ui.PriorityComp;
import com.raytheon.uf.viz.datadelivery.subscription.subset.presenter.IGriddedTimingSelectionDlgView;
+import com.raytheon.uf.viz.datadelivery.system.SystemRuleManager;
import com.raytheon.uf.viz.datadelivery.utils.DataDeliveryUtils;
import com.raytheon.viz.ui.dialogs.CaveSWTDialog;
import com.raytheon.viz.ui.presenter.components.ButtonConf;
@@ -48,7 +53,8 @@ import com.raytheon.viz.ui.presenter.components.ListConf;
* ------------ ---------- ----------- --------------------------
* Sep 12, 2012 223 mpduff Initial creation.
* Oct 11, 2012 1263 jpiatt Modified for cancel button
- * Nov 20, 2012 1286 djohnson Implement displayYesNoPopup..
+ * Nov 20, 2012 1286 djohnson Implement displayYesNoPopup.
+ * Jan 04, 2013 1420 mpduff Add Priority Composite.
*
*
*
@@ -70,21 +76,34 @@ public class GriddedTimingSelectionDlg extends CaveSWTDialog implements
/** OK button */
private Button okBtn;
-
+
/** Cancel button */
private Button cancelBtn;
+ /** Priority Composite */
+ private PriorityComp priorityComp;
+
/** Callback to the presenter at preopen */
private Runnable preOpenCallback;
+ /** The subscription object */
+ private final Subscription subscription;
+
+ /** Cycle times */
+ private final Set cycleTimes;
+
/**
* Constructor
- *
+ *
* @param parentShell
+ * @param cycleTimes
*/
- protected GriddedTimingSelectionDlg(Shell parentShell) {
+ protected GriddedTimingSelectionDlg(Shell parentShell,
+ Set cycleTimes, Subscription subscription) {
super(parentShell);
setText("Select Date/Cycle");
+ this.cycleTimes = cycleTimes;
+ this.subscription = subscription;
}
/**
@@ -100,7 +119,7 @@ public class GriddedTimingSelectionDlg extends CaveSWTDialog implements
*/
@Override
protected void initializeComponents(Shell shell) {
- GridData gd = new GridData(SWT.FILL, SWT.DEFAULT, true, false);
+ GridData gd = new GridData(SWT.CENTER, SWT.DEFAULT, true, false);
GridLayout gl = new GridLayout(1, false);
dateComp = new Composite(shell, SWT.NONE);
@@ -115,6 +134,12 @@ public class GriddedTimingSelectionDlg extends CaveSWTDialog implements
| SWT.V_SCROLL);
dateCycleList.setLayoutData(gd);
+ // Get latency value
+ SystemRuleManager ruleManager = SystemRuleManager.getInstance();
+ int latency = ruleManager.getLatency(this.subscription, cycleTimes);
+ int priority = ruleManager.getPriority(this.subscription, cycleTimes);
+ priorityComp = new PriorityComp(shell, latency, priority);
+
gd = new GridData(SWT.CENTER, SWT.DEFAULT, true, false);
gl = new GridLayout(2, false);
Composite buttonComp = new Composite(shell, SWT.NONE);
@@ -129,7 +154,6 @@ public class GriddedTimingSelectionDlg extends CaveSWTDialog implements
gd = new GridData(btnWidth, SWT.DEFAULT);
cancelBtn = new Button(buttonComp, SWT.PUSH);
cancelBtn.setLayoutData(gd);
-
}
/**
@@ -198,7 +222,7 @@ public class GriddedTimingSelectionDlg extends CaveSWTDialog implements
}
});
}
-
+
/**
* {@inheritDoc}
*/
@@ -301,4 +325,19 @@ public class GriddedTimingSelectionDlg extends CaveSWTDialog implements
close();
}
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public int getLatency() {
+ return priorityComp.getLatencyValue();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public int getPriority() {
+ return priorityComp.getPriorityIndex();
+ }
}
diff --git a/cave/com.raytheon.uf.viz.datadelivery/src/com/raytheon/uf/viz/datadelivery/subscription/subset/SubsetManagerDlg.java b/cave/com.raytheon.uf.viz.datadelivery/src/com/raytheon/uf/viz/datadelivery/subscription/subset/SubsetManagerDlg.java
index 3e5efd4623..0483e92c85 100644
--- a/cave/com.raytheon.uf.viz.datadelivery/src/com/raytheon/uf/viz/datadelivery/subscription/subset/SubsetManagerDlg.java
+++ b/cave/com.raytheon.uf.viz.datadelivery/src/com/raytheon/uf/viz/datadelivery/subscription/subset/SubsetManagerDlg.java
@@ -121,6 +121,7 @@ import com.raytheon.viz.ui.presenter.IDisplay;
* Dec 17, 2012 1434 mpduff Don't allow underscores in name.
* Dec 18, 2012 1439 mpduff Redo subscription name validation.
* Jan 02, 2012 1345 djohnson Use gui thread task executor.
+ * Jan 04, 2012 1420 mpduff Pass the subscription in to the GriddedTimingSelectionDlg.
*
*
* @author mpduff
@@ -609,11 +610,16 @@ public abstract class SubsetManagerDlg
*
@@ -82,7 +86,7 @@ public class GriddedTimingSelectionPresenter {
}
}
};
-
+
/** Cancel button action handler */
@VisibleForTesting
final Runnable cancelBtnAction = new Runnable() {
@@ -91,7 +95,7 @@ public class GriddedTimingSelectionPresenter {
cancel = true;
}
};
-
+
/** Cancel flag */
private boolean cancel = false;
@@ -102,7 +106,7 @@ public class GriddedTimingSelectionPresenter {
/** Ok button conf object */
@VisibleForTesting
final ButtonConf okBtnConf;
-
+
/** Cancel button conf object */
@VisibleForTesting
ButtonConf cancelBtnConf;
@@ -113,9 +117,12 @@ public class GriddedTimingSelectionPresenter {
/** The selected date */
private String selectedDate;
+ /** The Gridded dataset obj */
+ private final GriddedDataSet dataSet;
+
/**
* Constructor.
- *
+ *
* @param view
* The view
* @param dataSet
@@ -126,6 +133,7 @@ public class GriddedTimingSelectionPresenter {
public GriddedTimingSelectionPresenter(IGriddedTimingSelectionDlgView view,
GriddedDataSet dataSet, List dateCycleList) {
this.view = view;
+ this.dataSet = dataSet;
latestDataChkConf = new CheckBoxConf("Get Latest Data", true,
"Use the latest time", latestDataChkAction);
@@ -152,7 +160,7 @@ public class GriddedTimingSelectionPresenter {
/**
* OK Button action method.
- *
+ *
* @return true if everything ok
*/
protected boolean handleOk() {
@@ -164,6 +172,9 @@ public class GriddedTimingSelectionPresenter {
return false;
}
+ DataDeliveryGUIUtils.latencyValidChk(view.getLatency(),
+ getMaxLatency());
+
// parse off the date/cycle time selected
String[] parts = selection.split(" - ");
this.selectedDate = selection;
@@ -177,6 +188,29 @@ public class GriddedTimingSelectionPresenter {
return true;
}
+ /**
+ * Max latency value in minutes.
+ *
+ * @return
+ */
+ private int getMaxLatency() {
+ List cycleList = new ArrayList(dataSet.getCycles());
+ Collections.sort(cycleList);
+
+ int max = 0;
+
+ for (int i = 0; i < cycleList.size(); i++) {
+ if (i + 1 <= cycleList.size()) {
+ int tempMax = cycleList.get(i + 1) - cycleList.get(i);
+ if (tempMax > max) {
+ max = tempMax;
+ }
+ }
+ }
+
+ return max * 60;
+ }
+
/**
* This method is called via the "Use Latest Data" checkbox being
* selected/unselected.
@@ -187,7 +221,7 @@ public class GriddedTimingSelectionPresenter {
/**
* Open the dialog.
- *
+ *
* @return The selected cycle
*/
public Integer open() {
@@ -205,7 +239,7 @@ public class GriddedTimingSelectionPresenter {
/**
* Get the selected date.
- *
+ *
* @return the selected date string
*/
public String getDate() {
@@ -214,7 +248,7 @@ public class GriddedTimingSelectionPresenter {
/**
* Get cancel flag.
- *
+ *
* @return true if cancel selected
*/
public boolean isCancel() {
diff --git a/cave/com.raytheon.uf.viz.datadelivery/src/com/raytheon/uf/viz/datadelivery/subscription/subset/presenter/IGriddedTimingSelectionDlgView.java b/cave/com.raytheon.uf.viz.datadelivery/src/com/raytheon/uf/viz/datadelivery/subscription/subset/presenter/IGriddedTimingSelectionDlgView.java
index b4fc9eb0d6..6d1dd48a5f 100644
--- a/cave/com.raytheon.uf.viz.datadelivery/src/com/raytheon/uf/viz/datadelivery/subscription/subset/presenter/IGriddedTimingSelectionDlgView.java
+++ b/cave/com.raytheon.uf.viz.datadelivery/src/com/raytheon/uf/viz/datadelivery/subscription/subset/presenter/IGriddedTimingSelectionDlgView.java
@@ -26,18 +26,19 @@ import com.raytheon.viz.ui.presenter.components.ListConf;
/**
* IGriddedTimingSelectionDlgView interface
- *
+ *
*
- *
+ *
* SOFTWARE HISTORY
- *
+ *
* Date Ticket# Engineer Description
* ------------ ---------- ----------- --------------------------
* Sep 12, 2012 mpduff Initial creation.
* Oct 11, 2012 1263 jpiatt Modified for cancel flag.
- *
+ * Jan 04, 2013 1420 mpduff Add getters for Latency and Priority.
+ *
*
- *
+ *
* @author mpduff
* @version 1.0
*/
@@ -46,41 +47,42 @@ public interface IGriddedTimingSelectionDlgView extends IPresenterView {
/**
* Open the view dialog.
- *
+ *
* @return the selection
*/
Integer openDlg();
/**
* Set the config object for the latest data check box.
- *
+ *
* @param checkBoxConf
*/
void setLatestDataCheckBox(CheckBoxConf checkBoxConf);
/**
* Set the date/cycle list config object.
- *
+ *
* @param dateCycleListConf
*/
void setDateCycleList(ListConf dateCycleListConf);
/**
* Set the config object for the ok button.
+ *
* @param okBtnConf
*/
void setOkButton(ButtonConf okBtnConf);
/**
* Set the callback to be called at preopen.
- *
+ *
* @param preOpenCallback
*/
void setPreOpenCallback(Runnable preOpenCallback);
/**
* Check if the latest data checkbox is enabled.
- *
+ *
* @return true if enabled.
*/
boolean isLatestDataEnabled();
@@ -92,7 +94,7 @@ public interface IGriddedTimingSelectionDlgView extends IPresenterView {
/**
* Get the list selection.
- *
+ *
* @return the selected item in the list
*/
String getSelection();
@@ -108,5 +110,18 @@ public interface IGriddedTimingSelectionDlgView extends IPresenterView {
* @param cancelBtnConf
*/
void setCancelButton(ButtonConf cancelBtnConf);
-
+
+ /**
+ * Get the latency value.
+ *
+ * @return Latency value
+ */
+ int getLatency();
+
+ /**
+ * Get the priority value.
+ *
+ * @return priority value
+ */
+ int getPriority();
}
diff --git a/cave/com.raytheon.uf.viz.datadelivery/src/com/raytheon/uf/viz/datadelivery/subscription/view/ICreateSubscriptionDlgView.java b/cave/com.raytheon.uf.viz.datadelivery/src/com/raytheon/uf/viz/datadelivery/subscription/view/ICreateSubscriptionDlgView.java
index 0fa5c23a78..8787035a5b 100644
--- a/cave/com.raytheon.uf.viz.datadelivery/src/com/raytheon/uf/viz/datadelivery/subscription/view/ICreateSubscriptionDlgView.java
+++ b/cave/com.raytheon.uf.viz.datadelivery/src/com/raytheon/uf/viz/datadelivery/subscription/view/ICreateSubscriptionDlgView.java
@@ -21,9 +21,11 @@ package com.raytheon.uf.viz.datadelivery.subscription.view;
import java.util.Date;
import java.util.List;
+import java.util.Set;
import org.eclipse.swt.widgets.Shell;
+import com.raytheon.uf.common.datadelivery.registry.Subscription;
import com.raytheon.viz.ui.presenter.IPresenterView;
import com.raytheon.viz.ui.presenter.components.ButtonConf;
import com.raytheon.viz.ui.presenter.components.CheckBoxConf;
@@ -41,6 +43,7 @@ import com.raytheon.viz.ui.presenter.components.ComboBoxConf;
* Aug 24, 2012 0223 mpduff Initial creation
* Dec 13, 2012 1391 bgonzale Added status methods.
* Jan 02, 2013 1441 djohnson Add isGroupSelected.
+ * Jan 04, 2013 1420 mpduff Added getters for latency and priority.
*
*
*
@@ -395,4 +398,33 @@ public interface ICreateSubscriptionDlgView extends IPresenterView {
* @return
*/
boolean isGroupSelected();
+
+ /**
+ * Get the latency value.
+ *
+ * @return the latency value
+ */
+ int getLatencyValue();
+
+ /**
+ * Get the priority value.
+ *
+ * @return
+ */
+ int getPriorityValue();
+
+ /**
+ * Set Subscription.
+ *
+ * @param subscription
+ * the subscription
+ */
+ void setSubscription(Subscription subscription);
+
+ /**
+ * Set the cycle times of the model.
+ *
+ * @param cycleTimes
+ */
+ void setCycleTimes(Set cycleTimes);
}
diff --git a/cave/com.raytheon.uf.viz.datadelivery/src/com/raytheon/uf/viz/datadelivery/subscription/xml/LatencyRuleXML.java b/cave/com.raytheon.uf.viz.datadelivery/src/com/raytheon/uf/viz/datadelivery/subscription/xml/LatencyRuleXML.java
new file mode 100644
index 0000000000..d11cc55f75
--- /dev/null
+++ b/cave/com.raytheon.uf.viz.datadelivery/src/com/raytheon/uf/viz/datadelivery/subscription/xml/LatencyRuleXML.java
@@ -0,0 +1,63 @@
+/**
+ * This software was developed and / or modified by Raytheon Company,
+ * pursuant to Contract DG133W-05-CQ-1067 with the US Government.
+ *
+ * U.S. EXPORT CONTROLLED TECHNICAL DATA
+ * This software product contains export-restricted data whose
+ * export/transfer/disclosure is restricted by U.S. law. Dissemination
+ * to non-U.S. persons whether in the United States or abroad requires
+ * an export license or other authorization.
+ *
+ * Contractor Name: Raytheon Company
+ * Contractor Address: 6825 Pine Street, Suite 340
+ * Mail Stop B8
+ * Omaha, NE 68106
+ * 402.291.0100
+ *
+ * See the AWIPS II Master Rights File ("Master Rights File.pdf") for
+ * further licensing information.
+ **/
+package com.raytheon.uf.viz.datadelivery.subscription.xml;
+
+import javax.xml.bind.annotation.XmlAccessType;
+import javax.xml.bind.annotation.XmlAccessorType;
+import javax.xml.bind.annotation.XmlElement;
+import javax.xml.bind.annotation.XmlRootElement;
+
+/**
+ * Latency Rule XML Object.
+ *
+ *
+ *
+ * SOFTWARE HISTORY
+ *
+ * Date Ticket# Engineer Description
+ * ------------ ---------- ----------- --------------------------
+ * Dec 19, 2012 1420 mpduff Initial creation.
+ *
+ *
+ *
+ * @author mpduff
+ * @version 1.0
+ */
+@XmlAccessorType(XmlAccessType.NONE)
+@XmlRootElement
+public class LatencyRuleXML extends RuleXML {
+ @XmlElement(name = "latency")
+ private Integer latency;
+
+ /**
+ * @return the latency
+ */
+ public Integer getLatency() {
+ return latency;
+ }
+
+ /**
+ * @param latency
+ * the latency to set
+ */
+ public void setLatency(Integer latency) {
+ this.latency = latency;
+ }
+}
diff --git a/cave/com.raytheon.uf.viz.datadelivery/src/com/raytheon/uf/viz/datadelivery/subscription/xml/LatencyRulesXML.java b/cave/com.raytheon.uf.viz.datadelivery/src/com/raytheon/uf/viz/datadelivery/subscription/xml/LatencyRulesXML.java
new file mode 100644
index 0000000000..8e797b9288
--- /dev/null
+++ b/cave/com.raytheon.uf.viz.datadelivery/src/com/raytheon/uf/viz/datadelivery/subscription/xml/LatencyRulesXML.java
@@ -0,0 +1,46 @@
+/**
+ * This software was developed and / or modified by Raytheon Company,
+ * pursuant to Contract DG133W-05-CQ-1067 with the US Government.
+ *
+ * U.S. EXPORT CONTROLLED TECHNICAL DATA
+ * This software product contains export-restricted data whose
+ * export/transfer/disclosure is restricted by U.S. law. Dissemination
+ * to non-U.S. persons whether in the United States or abroad requires
+ * an export license or other authorization.
+ *
+ * Contractor Name: Raytheon Company
+ * Contractor Address: 6825 Pine Street, Suite 340
+ * Mail Stop B8
+ * Omaha, NE 68106
+ * 402.291.0100
+ *
+ * See the AWIPS II Master Rights File ("Master Rights File.pdf") for
+ * further licensing information.
+ **/
+package com.raytheon.uf.viz.datadelivery.subscription.xml;
+
+import javax.xml.bind.annotation.XmlAccessType;
+import javax.xml.bind.annotation.XmlAccessorType;
+import javax.xml.bind.annotation.XmlRootElement;
+
+/**
+ * Latency Rules XML object.
+ *
+ *
+ *
+ * SOFTWARE HISTORY
+ *
+ * Date Ticket# Engineer Description
+ * ------------ ---------- ----------- --------------------------
+ * Dec 19, 2012 1420 mpduff Initial creation.
+ *
+ *
+ *
+ * @author mpduff
+ * @version 1.0
+ */
+@XmlAccessorType(XmlAccessType.NONE)
+@XmlRootElement(name = "latencyRules")
+public class LatencyRulesXML extends RulesXML {
+
+}
diff --git a/cave/com.raytheon.uf.viz.datadelivery/src/com/raytheon/uf/viz/datadelivery/subscription/xml/OperatorAdapter.java b/cave/com.raytheon.uf.viz.datadelivery/src/com/raytheon/uf/viz/datadelivery/subscription/xml/OperatorAdapter.java
new file mode 100644
index 0000000000..f30006ca1c
--- /dev/null
+++ b/cave/com.raytheon.uf.viz.datadelivery/src/com/raytheon/uf/viz/datadelivery/subscription/xml/OperatorAdapter.java
@@ -0,0 +1,75 @@
+/**
+ * This software was developed and / or modified by Raytheon Company,
+ * pursuant to Contract DG133W-05-CQ-1067 with the US Government.
+ *
+ * U.S. EXPORT CONTROLLED TECHNICAL DATA
+ * This software product contains export-restricted data whose
+ * export/transfer/disclosure is restricted by U.S. law. Dissemination
+ * to non-U.S. persons whether in the United States or abroad requires
+ * an export license or other authorization.
+ *
+ * Contractor Name: Raytheon Company
+ * Contractor Address: 6825 Pine Street, Suite 340
+ * Mail Stop B8
+ * Omaha, NE 68106
+ * 402.291.0100
+ *
+ * See the AWIPS II Master Rights File ("Master Rights File.pdf") for
+ * further licensing information.
+ **/
+package com.raytheon.uf.viz.datadelivery.subscription.xml;
+
+import javax.xml.bind.annotation.adapters.XmlAdapter;
+
+import com.raytheon.uf.viz.datadelivery.system.Operator;
+import com.raytheon.uf.viz.datadelivery.system.OperatorTypes;
+import com.raytheon.uf.viz.datadelivery.utils.NameOperationItems;
+import com.raytheon.uf.viz.datadelivery.utils.TypeOperationItems;
+
+/**
+ * Operator adapter class.
+ *
+ *
+ *
+ * SOFTWARE HISTORY
+ *
+ * Date Ticket# Engineer Description
+ * ------------ ---------- ----------- --------------------------
+ * Jan 7, 2013 1420 mpduff Initial creation.
+ *
+ *
+ *
+ * @author mpduff
+ * @version 1.0
+ */
+
+public class OperatorAdapter extends XmlAdapter> {
+ @Override
+ public Operator> unmarshal(String v) throws Exception {
+ for (OperatorTypes ot : OperatorTypes.values()) {
+ if (ot.toString().equals(v)) {
+ return ot;
+ }
+ }
+
+ for (NameOperationItems noi : NameOperationItems.values()) {
+ if (noi.toString().equals(v)) {
+ return noi;
+ }
+ }
+
+ for (TypeOperationItems toi : TypeOperationItems.values()) {
+ if (toi.toString().equals(v)) {
+ return toi;
+ }
+ }
+
+ return null;
+ }
+
+ @Override
+ public String marshal(Operator> v) throws Exception {
+ return v.toString();
+ }
+
+}
diff --git a/cave/com.raytheon.uf.viz.datadelivery/src/com/raytheon/uf/viz/datadelivery/subscription/xml/PriorityRuleXML.java b/cave/com.raytheon.uf.viz.datadelivery/src/com/raytheon/uf/viz/datadelivery/subscription/xml/PriorityRuleXML.java
new file mode 100644
index 0000000000..a8c341b811
--- /dev/null
+++ b/cave/com.raytheon.uf.viz.datadelivery/src/com/raytheon/uf/viz/datadelivery/subscription/xml/PriorityRuleXML.java
@@ -0,0 +1,63 @@
+/**
+ * This software was developed and / or modified by Raytheon Company,
+ * pursuant to Contract DG133W-05-CQ-1067 with the US Government.
+ *
+ * U.S. EXPORT CONTROLLED TECHNICAL DATA
+ * This software product contains export-restricted data whose
+ * export/transfer/disclosure is restricted by U.S. law. Dissemination
+ * to non-U.S. persons whether in the United States or abroad requires
+ * an export license or other authorization.
+ *
+ * Contractor Name: Raytheon Company
+ * Contractor Address: 6825 Pine Street, Suite 340
+ * Mail Stop B8
+ * Omaha, NE 68106
+ * 402.291.0100
+ *
+ * See the AWIPS II Master Rights File ("Master Rights File.pdf") for
+ * further licensing information.
+ **/
+package com.raytheon.uf.viz.datadelivery.subscription.xml;
+
+import javax.xml.bind.annotation.XmlAccessType;
+import javax.xml.bind.annotation.XmlAccessorType;
+import javax.xml.bind.annotation.XmlElement;
+import javax.xml.bind.annotation.XmlRootElement;
+
+/**
+ * TODO Add Description
+ *
+ *
+ *
+ * SOFTWARE HISTORY
+ *
+ * Date Ticket# Engineer Description
+ * ------------ ---------- ----------- --------------------------
+ * Dec 19, 2012 1420 mpduff Initial creation.
+ *
+ *
+ *
+ * @author mpduff
+ * @version 1.0
+ */
+@XmlAccessorType(XmlAccessType.NONE)
+@XmlRootElement
+public class PriorityRuleXML extends RuleXML {
+ @XmlElement(name = "priority")
+ private Integer priority;
+
+ /**
+ * @param priority
+ * the priority to set
+ */
+ public void setPriority(Integer priority) {
+ this.priority = priority;
+ }
+
+ /**
+ * @return the priority
+ */
+ public Integer getPriority() {
+ return priority;
+ }
+}
diff --git a/cave/com.raytheon.uf.viz.datadelivery/src/com/raytheon/uf/viz/datadelivery/subscription/xml/PriorityRulesXML.java b/cave/com.raytheon.uf.viz.datadelivery/src/com/raytheon/uf/viz/datadelivery/subscription/xml/PriorityRulesXML.java
new file mode 100644
index 0000000000..191fa11c6c
--- /dev/null
+++ b/cave/com.raytheon.uf.viz.datadelivery/src/com/raytheon/uf/viz/datadelivery/subscription/xml/PriorityRulesXML.java
@@ -0,0 +1,46 @@
+/**
+ * This software was developed and / or modified by Raytheon Company,
+ * pursuant to Contract DG133W-05-CQ-1067 with the US Government.
+ *
+ * U.S. EXPORT CONTROLLED TECHNICAL DATA
+ * This software product contains export-restricted data whose
+ * export/transfer/disclosure is restricted by U.S. law. Dissemination
+ * to non-U.S. persons whether in the United States or abroad requires
+ * an export license or other authorization.
+ *
+ * Contractor Name: Raytheon Company
+ * Contractor Address: 6825 Pine Street, Suite 340
+ * Mail Stop B8
+ * Omaha, NE 68106
+ * 402.291.0100
+ *
+ * See the AWIPS II Master Rights File ("Master Rights File.pdf") for
+ * further licensing information.
+ **/
+package com.raytheon.uf.viz.datadelivery.subscription.xml;
+
+import javax.xml.bind.annotation.XmlAccessType;
+import javax.xml.bind.annotation.XmlAccessorType;
+import javax.xml.bind.annotation.XmlRootElement;
+
+/**
+ * Priority Rules XML object.
+ *
+ *
+ *
+ * SOFTWARE HISTORY
+ *
+ * Date Ticket# Engineer Description
+ * ------------ ---------- ----------- --------------------------
+ * Dec 19, 2012 1420 mpduff Initial creation.
+ *
+ *
+ *
+ * @author mpduff
+ * @version 1.0
+ */
+@XmlAccessorType(XmlAccessType.NONE)
+@XmlRootElement(name = "priorityRules")
+public class PriorityRulesXML extends RulesXML {
+
+}
diff --git a/cave/com.raytheon.uf.viz.datadelivery/src/com/raytheon/uf/viz/datadelivery/subscription/xml/RuleXML.java b/cave/com.raytheon.uf.viz.datadelivery/src/com/raytheon/uf/viz/datadelivery/subscription/xml/RuleXML.java
new file mode 100644
index 0000000000..0c6cf996a4
--- /dev/null
+++ b/cave/com.raytheon.uf.viz.datadelivery/src/com/raytheon/uf/viz/datadelivery/subscription/xml/RuleXML.java
@@ -0,0 +1,301 @@
+/**
+ * This software was developed and / or modified by Raytheon Company,
+ * pursuant to Contract DG133W-05-CQ-1067 with the US Government.
+ *
+ * U.S. EXPORT CONTROLLED TECHNICAL DATA
+ * This software product contains export-restricted data whose
+ * export/transfer/disclosure is restricted by U.S. law. Dissemination
+ * to non-U.S. persons whether in the United States or abroad requires
+ * an export license or other authorization.
+ *
+ * Contractor Name: Raytheon Company
+ * Contractor Address: 6825 Pine Street, Suite 340
+ * Mail Stop B8
+ * Omaha, NE 68106
+ * 402.291.0100
+ *
+ * See the AWIPS II Master Rights File ("Master Rights File.pdf") for
+ * further licensing information.
+ **/
+package com.raytheon.uf.viz.datadelivery.subscription.xml;
+
+import java.util.Iterator;
+import java.util.Set;
+
+import javax.xml.bind.annotation.XmlAccessType;
+import javax.xml.bind.annotation.XmlAccessorType;
+import javax.xml.bind.annotation.XmlElement;
+
+import com.raytheon.uf.common.datadelivery.registry.Subscription;
+import com.raytheon.uf.common.status.IUFStatusHandler;
+import com.raytheon.uf.common.status.UFStatus;
+import com.raytheon.uf.common.status.UFStatus.Priority;
+import com.raytheon.uf.viz.datadelivery.system.Operator;
+import com.raytheon.uf.viz.datadelivery.system.OpsNetFieldNames;
+import com.raytheon.uf.viz.datadelivery.utils.DataSizeUtil;
+
+/**
+ * Parent Rules xml class
+ *
+ *
+ *
+ * SOFTWARE HISTORY
+ *
+ * Date Ticket# Engineer Description
+ * ------------ ---------- ----------- --------------------------
+ * Dec 19, 2012 1420 mpduff Initial creation.
+ *
+ *
+ *
+ * @author mpduff
+ * @version 1.0
+ */
+@SuppressWarnings({ "unchecked", "rawtypes" })
+@XmlAccessorType(XmlAccessType.NONE)
+public abstract class RuleXML {
+
+ /** Status Handler */
+ private final IUFStatusHandler statusHandler = UFStatus
+ .getHandler(RuleXML.class);
+
+ /** Rule name */
+ @XmlElement
+ protected String ruleName;
+
+ /** Rule field */
+ @XmlElement
+ protected String ruleField;
+
+ /** Rule operator */
+ @XmlElement
+ protected String ruleOperator;
+
+ /** Rule value */
+ @XmlElement
+ protected String ruleValue;
+
+ /** Rule unit */
+ @XmlElement
+ protected String ruleUnit;
+
+ /**
+ * Get the name of the rule.
+ *
+ * @return the ruleName
+ */
+ public String getRuleName() {
+ return ruleName;
+ }
+
+ /**
+ * Set the field name of the rule.
+ *
+ * @param ruleName
+ * The name of the rule
+ */
+ public void setRuleName(String ruleName) {
+ this.ruleName = ruleName;
+ }
+
+ /**
+ * Get the field name of the rule.
+ *
+ * @return the ruleField
+ */
+ public String getRuleField() {
+ return ruleField;
+ }
+
+ /**
+ * Set the rule field name.
+ *
+ * @param ruleField
+ * The field value of the rule
+ */
+ public void setRuleField(String ruleField) {
+ this.ruleField = ruleField;
+ }
+
+ /**
+ * Get the operator of the rule.
+ *
+ * @return the ruleOperator
+ */
+ public String getRuleOperator() {
+ return ruleOperator;
+ }
+
+ /**
+ * Set the rule rule operator.
+ *
+ * @param ruleOperator
+ * The operator value of the rule
+ */
+ public void setRuleOperator(String ruleOperator) {
+ this.ruleOperator = ruleOperator;
+ }
+
+ /**
+ * Get the value of the rule.
+ *
+ * @return the ruleValue
+ */
+ public String getRuleValue() {
+ return ruleValue;
+ }
+
+ /**
+ * Set the rule value.
+ *
+ * @param ruleValue
+ * The value of the rule
+ */
+ public void setRuleValue(String ruleValue) {
+ this.ruleValue = ruleValue;
+ }
+
+ /**
+ * Get the unit of the value of the rule.
+ *
+ * @return the ruleUnit
+ */
+ public String getRuleUnit() {
+ return ruleUnit;
+ }
+
+ /**
+ * Set the rule unit.
+ *
+ * @param ruleUnit
+ * The unit value of the rule
+ */
+ public void setRuleUnit(String ruleUnit) {
+ this.ruleUnit = ruleUnit;
+ }
+
+ /**
+ * Check to see if a subscription to a data set with the given cycles
+ * matches this rule.
+ *
+ * @param sub
+ * The subscription
+ * @param cycles
+ * The available cycles
+ * @return true if the subscription matches this rule
+ */
+
+ public boolean matches(Subscription sub, Set cycles) {
+ String unit = null;
+
+ if (OpsNetFieldNames.SIZE.toString().equals(ruleField)
+ || OpsNetFieldNames.FREQUENCY.toString().equals(ruleField)) {
+ unit = getRuleUnit();
+ }
+
+ OperatorAdapter oa = new OperatorAdapter();
+ Operator oper = null;
+ try {
+ oper = oa.unmarshal(ruleOperator);
+ } catch (Exception e) {
+ statusHandler.handle(Priority.PROBLEM, e.getLocalizedMessage(), e);
+ return false;
+ }
+
+ // If Data Name
+ if (OpsNetFieldNames.NAME.toString().equals(ruleField)) {
+
+ String dsName = sub.getDataSetName();
+
+ return oper.evaluate(dsName, ruleValue);
+ }
+
+ // If Data Type
+ if (OpsNetFieldNames.TYPE.toString().equals(ruleField)) {
+ String dsType = sub.getDataSetType().toString();
+
+ return oper.evaluate(ruleValue, dsType);
+ }
+
+ // If Data Size
+ if (OpsNetFieldNames.SIZE.toString().equals(ruleField)) {
+ long dsSizeKb = sub.getDataSetSize(); // Size in KB
+ long ruleValueInt = Integer.parseInt(ruleValue);
+
+ if (unit.equals(DataSizeUtil.MB.getUnit())) {
+ ruleValueInt = DataSizeUtil.MB.toKB(ruleValueInt);
+ } else if (unit.equals(DataSizeUtil.GB.getUnit())) {
+ ruleValueInt = DataSizeUtil.GB.toKB(ruleValueInt);
+ }
+ System.out.println(dsSizeKb + " == " + ruleValueInt);
+ return oper.evaluate(Long.valueOf(dsSizeKb),
+ Long.valueOf(ruleValueInt));
+ }
+
+ // If Data Frequency
+ if (OpsNetFieldNames.FREQUENCY.toString().equals(ruleField)) {
+ // Calculate frequency
+ int ruleValueInt = Integer.parseInt(this.ruleValue);
+ if (unit.equalsIgnoreCase("Mins")) {
+ ruleValueInt /= 60;
+ }
+ int freq = 0;
+ Iterator iter = cycles.iterator();
+ int tmp = 0;
+ if (iter.hasNext()) {
+ tmp = iter.next();
+ }
+
+ if (iter.hasNext()) {
+ int val = iter.next();
+ freq = val - tmp;
+ }
+
+ if (oper.evaluate(Long.valueOf(freq), Long.valueOf(ruleValueInt))) {
+ return true;
+ }
+ }
+
+ return false;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see java.lang.Object#hashCode()
+ */
+ @Override
+ public int hashCode() {
+ final int prime = 31;
+ int result = 1;
+ result = prime * result
+ + ((ruleName == null) ? 0 : ruleName.hashCode());
+ return result;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see java.lang.Object#equals(java.lang.Object)
+ */
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj) {
+ return true;
+ }
+ if (obj == null) {
+ return false;
+ }
+ if (getClass() != obj.getClass()) {
+ return false;
+ }
+ RuleXML other = (RuleXML) obj;
+ if (ruleName == null) {
+ if (other.ruleName != null) {
+ return false;
+ }
+ } else if (!ruleName.equals(other.ruleName)) {
+ return false;
+ }
+ return true;
+ }
+}
diff --git a/cave/com.raytheon.uf.viz.datadelivery/src/com/raytheon/uf/viz/datadelivery/subscription/xml/RulesXML.java b/cave/com.raytheon.uf.viz.datadelivery/src/com/raytheon/uf/viz/datadelivery/subscription/xml/RulesXML.java
new file mode 100644
index 0000000000..2647fe35a7
--- /dev/null
+++ b/cave/com.raytheon.uf.viz.datadelivery/src/com/raytheon/uf/viz/datadelivery/subscription/xml/RulesXML.java
@@ -0,0 +1,129 @@
+/**
+ * This software was developed and / or modified by Raytheon Company,
+ * pursuant to Contract DG133W-05-CQ-1067 with the US Government.
+ *
+ * U.S. EXPORT CONTROLLED TECHNICAL DATA
+ * This software product contains export-restricted data whose
+ * export/transfer/disclosure is restricted by U.S. law. Dissemination
+ * to non-U.S. persons whether in the United States or abroad requires
+ * an export license or other authorization.
+ *
+ * Contractor Name: Raytheon Company
+ * Contractor Address: 6825 Pine Street, Suite 340
+ * Mail Stop B8
+ * Omaha, NE 68106
+ * 402.291.0100
+ *
+ * See the AWIPS II Master Rights File ("Master Rights File.pdf") for
+ * further licensing information.
+ **/
+package com.raytheon.uf.viz.datadelivery.subscription.xml;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.xml.bind.annotation.XmlAccessType;
+import javax.xml.bind.annotation.XmlAccessorType;
+import javax.xml.bind.annotation.XmlElement;
+import javax.xml.bind.annotation.XmlElements;
+
+import com.google.common.base.Function;
+import com.google.common.collect.Lists;
+
+/**
+ * RulesXML base class
+ *
+ *
+ *
+ * SOFTWARE HISTORY
+ *
+ * Date Ticket# Engineer Description
+ * ------------ ---------- ----------- --------------------------
+ * Jan 7, 2013 1420 mpduff Initial creation.
+ *
+ *
+ *
+ * @author mpduff
+ * @version 1.0
+ */
+@XmlAccessorType(XmlAccessType.NONE)
+public abstract class RulesXML {
+ private static final Function GET_RULE_NAMES_FUNCTION = new Function() {
+ @Override
+ public String apply(RuleXML rule) {
+ return rule.getRuleName();
+ }
+ };
+
+ @XmlElements({ @XmlElement(name = "rule") })
+ protected List rules = new ArrayList();
+
+ /**
+ * Add a rule.
+ *
+ * @param ruleXml
+ * The rule to add
+ * @return true if added, false if rule name already exists
+ */
+ public boolean addRule(T ruleXml) {
+ if (rules.contains(ruleXml)) {
+ return false;
+ }
+
+ this.rules.add(ruleXml);
+ return true;
+ }
+
+ /**
+ * @return the rules
+ */
+ public List getRules() {
+ return rules;
+ }
+
+ /**
+ * Get the list of rule names.
+ *
+ * @return List of rule names
+ */
+ public List getRuleNames() {
+ return new ArrayList(Lists.transform(getRules(),
+ GET_RULE_NAMES_FUNCTION));
+ }
+
+ /**
+ * @param rules
+ * the rules to set
+ */
+ public void setRules(List rules) {
+ this.rules = rules;
+ }
+
+ /**
+ * Remove a rule.
+ *
+ * @param ruleName
+ * The rule to remove
+ */
+ public void removeRuleByName(String ruleName) {
+ for (T rule : rules) {
+ if (rule.getRuleName().equals(ruleName)) {
+ this.rules.remove(rule);
+ return;
+ }
+ }
+ }
+
+ public boolean updateRule(T updatedRule) {
+ for (int i = 0; i < rules.size(); i++) {
+ T rule = rules.get(i);
+ if (rule.equals(updatedRule)) {
+ rules.remove(i);
+ rules.add(i, updatedRule);
+ return true;
+ }
+ }
+
+ return false;
+ }
+}
diff --git a/cave/com.raytheon.uf.viz.datadelivery/src/com/raytheon/uf/viz/datadelivery/subscription/xml/SubscriptionRuleXML.java b/cave/com.raytheon.uf.viz.datadelivery/src/com/raytheon/uf/viz/datadelivery/subscription/xml/SubscriptionRuleXML.java
deleted file mode 100644
index 119b9ef16e..0000000000
--- a/cave/com.raytheon.uf.viz.datadelivery/src/com/raytheon/uf/viz/datadelivery/subscription/xml/SubscriptionRuleXML.java
+++ /dev/null
@@ -1,198 +0,0 @@
-/**
- * This software was developed and / or modified by Raytheon Company,
- * pursuant to Contract DG133W-05-CQ-1067 with the US Government.
- *
- * U.S. EXPORT CONTROLLED TECHNICAL DATA
- * This software product contains export-restricted data whose
- * export/transfer/disclosure is restricted by U.S. law. Dissemination
- * to non-U.S. persons whether in the United States or abroad requires
- * an export license or other authorization.
- *
- * Contractor Name: Raytheon Company
- * Contractor Address: 6825 Pine Street, Suite 340
- * Mail Stop B8
- * Omaha, NE 68106
- * 402.291.0100
- *
- * See the AWIPS II Master Rights File ("Master Rights File.pdf") for
- * further licensing information.
- **/
-package com.raytheon.uf.viz.datadelivery.subscription.xml;
-
-import javax.xml.bind.annotation.XmlAccessType;
-import javax.xml.bind.annotation.XmlAccessorType;
-import javax.xml.bind.annotation.XmlRootElement;
-
-import com.raytheon.uf.common.serialization.ISerializableObject;
-
-/**
- * Subscription Rules XML Object.
- *
- *
- *
- * SOFTWARE HISTORY
- *
- * Date Ticket# Engineer Description
- * ------------ ---------- ----------- --------------------------
- * Sep 10, 2012 730 jpiatt Initial creation
- * Oct 30, 2012 1286 djohnson Latency is an integer, remove unnecessary jaxb stuff.
- *
- *
- *
- * @author jpiatt
- * @version 1.0
- */
-
-@XmlRootElement(name = "SubscriptionRule")
-@XmlAccessorType(XmlAccessType.PROPERTY)
-public class SubscriptionRuleXML implements ISerializableObject {
-
- private String ruleName;
-
- private String ruleField;
-
- private String ruleOperator;
-
- private String ruleValue;
-
- private String ruleUnit;
-
- private Integer rulePriority;
-
- private Integer ruleLatency;
-
- /**
- * Get the name of the rule.
- *
- * @return the ruleName
- */
- public String getRuleName() {
- return ruleName;
- }
-
- /**
- * Set the field name of the rule.
- *
- * @param ruleName
- * The name of the rule
- */
- public void setRuleName(String ruleName) {
- this.ruleName = ruleName;
- }
-
- /**
- * Get the field name of the rule.
- *
- * @return the ruleField
- */
- public String getRuleField() {
- return ruleField;
- }
-
- /**
- * Set the rule field name.
- *
- * @param ruleField
- * The field value of the rule
- */
- public void setRuleField(String ruleField) {
- this.ruleField = ruleField;
- }
-
- /**
- * Get the operator of the rule.
- *
- * @return the ruleOperator
- */
- public String getRuleOperator() {
- return ruleOperator;
- }
-
- /**
- * Set the rule rule operator.
- *
- * @param ruleOperator
- * The operator value of the rule
- */
- public void setRuleOperator(String ruleOperator) {
- this.ruleOperator = ruleOperator;
- }
-
- /**
- * Get the value of the rule.
- *
- * @return the ruleValue
- */
- public String getRuleValue() {
- return ruleValue;
- }
-
- /**
- * Set the rule value.
- *
- * @param ruleValue
- * The value of the rule
- */
- public void setRuleValue(String ruleValue) {
- this.ruleValue = ruleValue;
- }
-
- /**
- * Get the unit of the value of the rule.
- *
- * @return the ruleUnit
- */
- public String getRuleUnit() {
- return ruleUnit;
- }
-
- /**
- * Set the rule unit.
- *
- * @param ruleUnit
- * The unit value of the rule
- */
- public void setRuleUnit(String ruleUnit) {
- this.ruleUnit = ruleUnit;
- }
-
- /**
- * Get the priority of the rule.
- *
- * @return the rulePriority
- */
- public Integer getRulePriority() {
- return rulePriority;
- }
-
- /**
- * Set the rule priority.
- *
- * @param rulePriority
- * The priority value of the rule
- */
- public void setRulePriority(Integer rulePriority) {
- this.rulePriority = rulePriority;
- }
-
- /**
- * Get the latency of the rule.
- *
- * @return the ruleLatency
- */
- public Integer getRuleLatency() {
- return ruleLatency;
- }
-
- /**
- * Set the rule latency.
- *
- * @param ruleLatency
- * The latency value in min or hours of the rule
- */
- public void setRuleLatency(Integer ruleLatency) {
- this.ruleLatency = ruleLatency;
- }
-
-}
-
diff --git a/cave/com.raytheon.uf.viz.datadelivery/src/com/raytheon/uf/viz/datadelivery/system/CreateEditRuleDlg.java b/cave/com.raytheon.uf.viz.datadelivery/src/com/raytheon/uf/viz/datadelivery/system/CreateEditRuleDlg.java
index a4075e4458..7be0c01c1a 100644
--- a/cave/com.raytheon.uf.viz.datadelivery/src/com/raytheon/uf/viz/datadelivery/system/CreateEditRuleDlg.java
+++ b/cave/com.raytheon.uf.viz.datadelivery/src/com/raytheon/uf/viz/datadelivery/system/CreateEditRuleDlg.java
@@ -19,6 +19,8 @@
**/
package com.raytheon.uf.viz.datadelivery.system;
+import java.util.regex.Pattern;
+
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
@@ -33,12 +35,17 @@ import org.eclipse.swt.widgets.Layout;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;
-import com.raytheon.uf.viz.datadelivery.subscription.xml.SubscriptionRuleXML;
+import com.raytheon.uf.common.status.IUFStatusHandler;
+import com.raytheon.uf.common.status.UFStatus;
+import com.raytheon.uf.viz.datadelivery.subscription.xml.LatencyRuleXML;
+import com.raytheon.uf.viz.datadelivery.subscription.xml.PriorityRuleXML;
+import com.raytheon.uf.viz.datadelivery.subscription.xml.RuleXML;
import com.raytheon.uf.viz.datadelivery.utils.DataDeliveryGUIUtils;
-import com.raytheon.uf.viz.datadelivery.utils.DataDeliveryGUIUtils.NameOperationItems;
import com.raytheon.uf.viz.datadelivery.utils.DataDeliveryGUIUtils.SubscriptionPriority;
-import com.raytheon.uf.viz.datadelivery.utils.DataDeliveryGUIUtils.TypeOperationItems;
import com.raytheon.uf.viz.datadelivery.utils.DataDeliveryUtils;
+import com.raytheon.uf.viz.datadelivery.utils.DataSizeUtil;
+import com.raytheon.uf.viz.datadelivery.utils.NameOperationItems;
+import com.raytheon.uf.viz.datadelivery.utils.TypeOperationItems;
import com.raytheon.viz.ui.dialogs.CaveSWTDialog;
/**
@@ -56,6 +63,8 @@ import com.raytheon.viz.ui.dialogs.CaveSWTDialog;
* Dec 18, 2012 1419 bgonzale Fixed overwrite of values in updatSelectionFields().
* Dec 18, 2012 1439 mpduff Redo rule name validation.
* Dec 18, 2012 1417 bgonzale Changed value initialization in handleSave().
+ * Jan 04, 2013 1420 mpduff Remove code to apply rules changes to existing subscription,
+ * rules are only for future subscriptions.
*
*
*
@@ -63,6 +72,9 @@ import com.raytheon.viz.ui.dialogs.CaveSWTDialog;
* @version 1.0
*/
public class CreateEditRuleDlg extends CaveSWTDialog {
+ /** Status Handler */
+ private final IUFStatusHandler statusHandler = UFStatus
+ .getHandler(CreateEditRuleDlg.class);
/** Enumeration to use for Dataset Frequency */
public static enum FreqUnitOptions {
@@ -93,36 +105,14 @@ public class CreateEditRuleDlg extends CaveSWTDialog {
}
}
- /** Enumeration to use for Dataset Size units */
- public static enum SizeUnitOptions {
- /** Kilobytes */
- KB("KB"),
- /** Megabytes */
- MB("MB"),
- /** Gigabytes */
- GB("GB");
+ private static final Pattern INVALID_PATTERN = Pattern
+ .compile("[^a-zA-Z0-9-_]+");
- /** Dataset Size units */
- private final String sizeUnitOptions;
+ /** Invalid Character Message Title */
+ private static final String INVALID_CHARS_TITLE = "Invalid Characters";
- private SizeUnitOptions(String sizeUnitOptions) {
- this.sizeUnitOptions = sizeUnitOptions;
- }
-
- /**
- * Get size unit options.
- *
- * @return sizeUnitOptions
- */
- public String getOperation() {
- return sizeUnitOptions;
- }
-
- @Override
- public String toString() {
- return sizeUnitOptions;
- }
- }
+ /** Invalid Character Message */
+ private static final String INVALID_CHARS_MESSAGE = "Invalid characters.\nThe Rule Name may only contain letters/numbers/dashes/underscores.";
/** Instance of SystemRuleManager */
private final SystemRuleManager srm = SystemRuleManager.getInstance();
@@ -134,7 +124,7 @@ public class CreateEditRuleDlg extends CaveSWTDialog {
private Group ruleDefinitionGroup;
/** SubscriptionRuleXML object */
- private SubscriptionRuleXML ruleXml;
+ private RuleXML ruleXml;
/** Save button */
private Button saveBtn;
@@ -199,10 +189,8 @@ public class CreateEditRuleDlg extends CaveSWTDialog {
/** Frequency constant */
private final String DATASET_FREQ = OpsNetFieldNames.FREQUENCY.toString();
- private final IRulesNeedApplying rulesNeedApplying;
-
/**
- * Constructor.
+ * Constructor for edit rule.
*
* @param parent
* The parent shell
@@ -212,22 +200,19 @@ public class CreateEditRuleDlg extends CaveSWTDialog {
* Name of the rule
* @param ruleType
* type of rule
- * @param rulesNeedApplying
*/
public CreateEditRuleDlg(Shell parent, boolean create, String ruleName,
- String ruleType, IRulesNeedApplying rulesNeedApplying) {
+ String ruleType) {
super(parent, SWT.RESIZE | SWT.DIALOG_TRIM, CAVE.NONE);
this.create = create;
this.ruleName = ruleName;
this.ruleType = ruleType;
- this.rulesNeedApplying = rulesNeedApplying;
createRuleHeader();
-
}
/**
- * Constructor.
+ * Constructor for new rule.
*
* @param parent
* The parent shell
@@ -236,15 +221,8 @@ public class CreateEditRuleDlg extends CaveSWTDialog {
* @param ruleType
* type of rule
*/
- public CreateEditRuleDlg(Shell parent, boolean create, String ruleType,
- IRulesNeedApplying rulesNeedApplying) {
- super(parent, SWT.RESIZE | SWT.DIALOG_TRIM, CAVE.NONE);
- this.create = create;
- this.ruleType = ruleType;
- this.rulesNeedApplying = rulesNeedApplying;
-
- createRuleHeader();
-
+ public CreateEditRuleDlg(Shell parent, boolean create, String ruleType) {
+ this(parent, create, null, ruleType);
}
private void createRuleHeader() {
@@ -254,7 +232,6 @@ public class CreateEditRuleDlg extends CaveSWTDialog {
} else {
setText("Create Latency Rule");
}
-
} else {
if (PRIORITY_TYPE.equals(ruleType)) {
setText("Edit Priority Rule");
@@ -262,7 +239,6 @@ public class CreateEditRuleDlg extends CaveSWTDialog {
setText("Edit Latency Rule");
}
}
-
}
/*
@@ -289,6 +265,19 @@ public class CreateEditRuleDlg extends CaveSWTDialog {
*/
@Override
protected void initializeComponents(Shell shell) {
+ if (!create) {
+ if (PRIORITY_TYPE.equals(ruleType)) {
+ ruleXml = srm.loadPriorityRule(ruleName);
+ } else {
+ ruleXml = srm.loadLatencyRule(ruleName);
+ }
+
+ if (DATASET_SIZE.equals(ruleXml.getRuleField())) {
+ sizeFlag = true;
+ } else if (DATASET_FREQ.equals(ruleXml.getRuleField())) {
+ frequencyFlag = true;
+ }
+ }
initial = true;
createRuleNameArea();
@@ -308,11 +297,8 @@ public class CreateEditRuleDlg extends CaveSWTDialog {
GridData gd = new GridData(SWT.FILL, SWT.DEFAULT, true, false);
GridLayout gl = new GridLayout(1, true);
- // Create Rule
if (create) {
-
gl = new GridLayout(2, false);
-
Composite textComp = new Composite(shell, SWT.NONE);
textComp.setLayoutData(gd);
textComp.setLayout(gl);
@@ -326,24 +312,12 @@ public class CreateEditRuleDlg extends CaveSWTDialog {
ruleNameText = new Text(textComp, SWT.BORDER);
ruleNameText.setLayoutData(gd);
ruleNameText.setTextLimit(32);
- ruleNameText.setToolTipText("Enter rule text");
-
- // Edit Rule
+ ruleNameText.setToolTipText("Enter rule name");
} else {
-
Label ruleLbl = new Label(shell, SWT.NONE);
ruleLbl.setText("Rule Name: " + ruleName);
- ruleXml = srm.loadRule(ruleName);
-
- if (DATASET_SIZE.equals(ruleXml.getRuleField())) {
- sizeFlag = true;
- } else if (DATASET_FREQ.equals(ruleXml.getRuleField())) {
- frequencyFlag = true;
- }
-
}
-
}
/**
@@ -555,11 +529,7 @@ public class CreateEditRuleDlg extends CaveSWTDialog {
updateSelectionFields(field);
String operator = ruleXml.getRuleOperator();
- if (!operator.isEmpty()) {
- operationCombo.select(operationCombo.indexOf(operator));
- } else {
- operationCombo.select(0);
- }
+ operationCombo.select(operationCombo.indexOf(operator));
String value = ruleXml.getRuleValue();
if (!value.isEmpty()) {
@@ -571,8 +541,9 @@ public class CreateEditRuleDlg extends CaveSWTDialog {
unitsCombo.select(unitsCombo.indexOf(unit));
}
- Integer priority = ruleXml.getRulePriority();
if (PRIORITY_TYPE.equals(ruleType)) {
+ Integer priority = ((PriorityRuleXML) ruleXml).getPriority();
+
int o = 0;
SubscriptionPriority[] priorityOptions = SubscriptionPriority
.values();
@@ -584,7 +555,7 @@ public class CreateEditRuleDlg extends CaveSWTDialog {
o++;
}
} else {
- Integer latency = ruleXml.getRuleLatency();
+ Integer latency = ((LatencyRuleXML) ruleXml).getLatency();
if (latency != null) {
latencyMax.setText(latency.toString());
}
@@ -674,6 +645,9 @@ public class CreateEditRuleDlg extends CaveSWTDialog {
private boolean handleSave() {
boolean valid = false;
+ String fieldName = fieldCombo.getItem(fieldCombo.getSelectionIndex());
+ String operator = operationCombo.getItem(operationCombo
+ .getSelectionIndex());
if (create) {
valid = DataDeliveryGUIUtils.hasText(ruleNameText);
@@ -689,65 +663,14 @@ public class CreateEditRuleDlg extends CaveSWTDialog {
ruleName = ruleNameText.getText();
}
- if (DataDeliveryGUIUtils.INVALID_CHAR_PATTERN.matcher(ruleName.trim())
- .find()) {
+ if (INVALID_PATTERN.matcher(ruleName.trim()).find()) {
DataDeliveryUtils.showMessage(getShell(), SWT.ERROR,
- DataDeliveryGUIUtils.INVALID_CHARS_TITLE,
- DataDeliveryGUIUtils.INVALID_CHARS_MESSAGE);
+ INVALID_CHARS_TITLE, INVALID_CHARS_MESSAGE);
return false;
}
-
- SubscriptionPriority priorityVal = null;
- Integer priority = null;
- Integer latency = null;
- String unit = null;
- String fieldName = fieldCombo.getItem(fieldCombo.getSelectionIndex());
- String operator = operationCombo.getItem(operationCombo
- .getSelectionIndex());
-
- if (frequencyFlag || sizeFlag) {
- unit = unitsCombo.getItem(unitsCombo.getSelectionIndex());
- }
-
- if (priorityCombo != null) {
- priorityVal = SubscriptionPriority.valueOf(priorityCombo.getText()
- .toUpperCase());
- for (SubscriptionPriority pri : SubscriptionPriority.values()) {
- if (pri.equals(priorityVal)) {
- priority = pri.getPriorityValue();
- break;
- }
- }
-
- }
-
- if (latencyMax != null) {
- if (!DataDeliveryGUIUtils.hasText(latencyMax)) {
- DataDeliveryUtils
- .showMessage(shell, SWT.ERROR,
- "Invalid Maximum Latency",
- "Maximum Latency invalid. Please enter a value for Maximum Latency.");
- return false;
- }
-
- String latencyString = latencyMax.getText().trim();
-
- // Don't allow if text contains non-digit characters
- if (!DataDeliveryGUIUtils.DIGIT_PATTERN.matcher(latencyString)
- .matches()) {
- DataDeliveryUtils
- .showMessage(shell, SWT.ERROR,
- "Invalid Maximum Latency",
- "Maximum Latency invalid. Maximum Latency must be entered as digits only.");
- return false;
- }
- latency = Integer.parseInt(latencyString);
- }
-
- SubscriptionRuleXML rule = new SubscriptionRuleXML();
+ String value = null;
if (DataDeliveryGUIUtils.hasText(ruleValue)) {
-
- String value = ruleValue.getText();
+ value = ruleValue.getText();
if (DATASET_SIZE.equals(fieldName)
|| DATASET_FREQ.equals(fieldName)) {
@@ -765,8 +688,6 @@ public class CreateEditRuleDlg extends CaveSWTDialog {
return false;
}
}
- rule.setRuleValue(value);
-
} else {
DataDeliveryUtils.showMessage(getShell(), SWT.ERROR,
"Invalid Value",
@@ -775,32 +696,98 @@ public class CreateEditRuleDlg extends CaveSWTDialog {
return false;
}
- rule.setRuleName(ruleName);
- rule.setRuleField(fieldName);
- rule.setRuleOperator(operator);
- rule.setRuleUnit(unit);
- rule.setRulePriority(priority);
- rule.setRuleLatency(latency);
+ SubscriptionPriority priorityVal = null;
+ Integer priority = null;
+ Integer latency = null;
+ String unit = null;
- // Save the rule file
- boolean saved = srm.saveRule(rule, shell);
+ if (frequencyFlag || sizeFlag) {
+ unit = unitsCombo.getItem(unitsCombo.getSelectionIndex());
+ }
+ boolean saved = false;
- if (saved) {
- setReturnValue(true);
- rulesNeedApplying.flagRulesAsNeedApplying();
+ if (PRIORITY_TYPE.equals(ruleType)) {
+ PriorityRuleXML rule = new PriorityRuleXML();
+ priorityVal = SubscriptionPriority.valueOf(priorityCombo.getText()
+ .toUpperCase());
+ for (SubscriptionPriority pri : SubscriptionPriority.values()) {
+ if (pri.equals(priorityVal)) {
+ priority = pri.getPriorityValue();
+ (rule).setPriority(priority);
+ break;
+ }
+ }
+ rule.setRuleName(ruleName);
+ rule.setRuleField(fieldName);
+ rule.setRuleOperator(operator);
+ rule.setRuleUnit(unit);
+ rule.setRuleValue(value);
+ if (create) {
+ saved = srm.saveRule(rule);
+ } else {
+ saved = srm.updateRule(rule);
+ }
+
+ } else {
+ if (!DataDeliveryGUIUtils.hasText(latencyMax)) {
+ DataDeliveryUtils
+ .showMessage(shell, SWT.ERROR,
+ "Invalid Maximum Latency",
+ "Maximum Latency invalid. Please enter a value for Maximum Latency.");
+ return false;
+ }
+
+ String latencyString = latencyMax.getText().trim();
+
+ // Don't allow if text contains non-digit characters
+ if (!DataDeliveryGUIUtils.DIGIT_PATTERN.matcher(latencyString)
+ .matches()) {
+ DataDeliveryUtils
+ .showMessage(
+ shell,
+ SWT.ERROR,
+ "Invalid Maximum Latency",
+ "Maximum Latency invalid. Maximum Latency must be a positive number of minutes.");
+ return false;
+ }
+ LatencyRuleXML rule = new LatencyRuleXML();
+ latency = Integer.parseInt(latencyString);
+ rule.setLatency(latency);
+ rule.setRuleName(ruleName);
+ rule.setRuleField(fieldName);
+ rule.setRuleOperator(operator);
+ rule.setRuleUnit(unit);
+ rule.setRuleValue(value);
+
+ if (create) {
+ saved = srm.saveRule(rule);
+ } else {
+ saved = srm.updateRule(rule);
+ }
}
- return true;
+ setReturnValue(saved);
+ if (!saved) {
+ DataDeliveryUtils
+ .showMessage(
+ getShell(),
+ SWT.OK,
+ "Duplicate Name",
+ "A rule named "
+ + ruleName
+ + " already exists\n\nPlease select a different name.");
+ ruleNameText.selectAll();
+ }
+ return saved;
}
private void createSizeUnitItems() {
unitsCombo.removeAll();
- SizeUnitOptions[] sizeUnits = SizeUnitOptions.values();
- for (SizeUnitOptions suo : sizeUnits) {
- unitsCombo.add(suo.getOperation());
+ DataSizeUtil[] sizeUnits = DataSizeUtil.values();
+ for (DataSizeUtil suo : sizeUnits) {
+ unitsCombo.add(suo.getUnit());
}
-
}
private void createSizeOpItems() {
@@ -809,7 +796,6 @@ public class CreateEditRuleDlg extends CaveSWTDialog {
for (OperatorTypes suo : sizeOps) {
operationCombo.add(suo.getOperation());
}
-
}
private void createFreqUnitItems() {
@@ -817,7 +803,6 @@ public class CreateEditRuleDlg extends CaveSWTDialog {
for (FreqUnitOptions fuo : freqUnits) {
unitsCombo.add(fuo.getOperation());
}
-
}
private void createNameOpItems() {
@@ -826,7 +811,5 @@ public class CreateEditRuleDlg extends CaveSWTDialog {
for (NameOperationItems nop : nameOperation) {
operationCombo.add(nop.getOperation());
}
-
}
-
}
diff --git a/cave/com.raytheon.uf.viz.datadelivery/src/com/raytheon/uf/viz/datadelivery/system/Operator.java b/cave/com.raytheon.uf.viz.datadelivery/src/com/raytheon/uf/viz/datadelivery/system/Operator.java
new file mode 100644
index 0000000000..fb5fe9ed72
--- /dev/null
+++ b/cave/com.raytheon.uf.viz.datadelivery/src/com/raytheon/uf/viz/datadelivery/system/Operator.java
@@ -0,0 +1,66 @@
+/**
+ * This software was developed and / or modified by Raytheon Company,
+ * pursuant to Contract DG133W-05-CQ-1067 with the US Government.
+ *
+ * U.S. EXPORT CONTROLLED TECHNICAL DATA
+ * This software product contains export-restricted data whose
+ * export/transfer/disclosure is restricted by U.S. law. Dissemination
+ * to non-U.S. persons whether in the United States or abroad requires
+ * an export license or other authorization.
+ *
+ * Contractor Name: Raytheon Company
+ * Contractor Address: 6825 Pine Street, Suite 340
+ * Mail Stop B8
+ * Omaha, NE 68106
+ * 402.291.0100
+ *
+ * See the AWIPS II Master Rights File ("Master Rights File.pdf") for
+ * further licensing information.
+ **/
+package com.raytheon.uf.viz.datadelivery.system;
+
+/**
+ * TODO Add Description
+ *
+ *
+ *
+ * SOFTWARE HISTORY
+ *
+ * Date Ticket# Engineer Description
+ * ------------ ---------- ----------- --------------------------
+ * Jan 7, 2013 mpduff Initial creation
+ *
+ *
+ *
+ * @author mpduff
+ * @version 1.0
+ */
+
+public interface Operator {
+ /**
+ * Evaluate whether the operator would return true when comparing operandOne
+ * to operandTwo.
+ *
+ *
+ *
+ * OperatorTypes operator = OperatorTypes.GREATER_THAN;
+ * long operandOne = 1;
+ * long operandTwo = 2;
+ *
+ * boolean result = operator.evaluate(operandOne, operandTwo); // Returns false
+ *
+ *
+ *
+ * @param operandOne
+ * @param operandTwo
+ * @return true or false
+ */
+ boolean evaluate(T operandOne, T operandTwo);
+
+ /**
+ * Get the name.
+ *
+ * @return the name
+ */
+ String name();
+}
\ No newline at end of file
diff --git a/cave/com.raytheon.uf.viz.datadelivery/src/com/raytheon/uf/viz/datadelivery/system/OperatorTypes.java b/cave/com.raytheon.uf.viz.datadelivery/src/com/raytheon/uf/viz/datadelivery/system/OperatorTypes.java
index 4e5184bd46..9e6a6e5dc7 100644
--- a/cave/com.raytheon.uf.viz.datadelivery/src/com/raytheon/uf/viz/datadelivery/system/OperatorTypes.java
+++ b/cave/com.raytheon.uf.viz.datadelivery/src/com/raytheon/uf/viz/datadelivery/system/OperatorTypes.java
@@ -19,6 +19,10 @@
**/
package com.raytheon.uf.viz.datadelivery.system;
+import javax.xml.bind.annotation.XmlEnum;
+import javax.xml.bind.annotation.XmlEnumValue;
+import javax.xml.bind.annotation.XmlType;
+
/**
* Operator type enumeration.
*
@@ -37,52 +41,60 @@ package com.raytheon.uf.viz.datadelivery.system;
*/
/** Enumeration to use for Dataset Size operations */
-public enum OperatorTypes {
+@XmlType(name = "operatorType")
+@XmlEnum
+public enum OperatorTypes implements Operator {
/** Greater than operation */
+ @XmlEnumValue(">")
GREATER_THAN(">") {
@Override
- public boolean evaluate(long operandOne, long operandTwo) {
+ public boolean evaluate(Long operandOne, Long operandTwo) {
return operandOne > operandTwo;
}
},
/** Less than operation */
+ @XmlEnumValue("<")
LESS_THAN("<") {
@Override
- public boolean evaluate(long operandOne, long operandTwo) {
+ public boolean evaluate(Long operandOne, Long operandTwo) {
return operandOne < operandTwo;
}
},
/** Greater than or equal operation */
+ @XmlEnumValue(">=")
GREATER_THAN_EQUAL(">=") {
@Override
- public boolean evaluate(long operandOne, long operandTwo) {
+ public boolean evaluate(Long operandOne, Long operandTwo) {
return operandOne >= operandTwo;
}
},
/** Less than or equal operation */
+ @XmlEnumValue("<=")
LESS_THAN_EQUAL("<=") {
@Override
- public boolean evaluate(long operandOne, long operandTwo) {
+ public boolean evaluate(Long operandOne, Long operandTwo) {
return operandOne <= operandTwo;
}
},
/** Greater than operation */
+ @XmlEnumValue("Equal")
EQUAL("Equal") {
@Override
- public boolean evaluate(long operandOne, long operandTwo) {
- return operandOne == operandTwo;
+ public boolean evaluate(Long operandOne, Long operandTwo) {
+ return operandOne.longValue() == operandTwo.longValue();
}
},
/** Greater than operation */
+ @XmlEnumValue("Not Equal")
NOT_EQUAL("Not Equal") {
@Override
- public boolean evaluate(long operandOne, long operandTwo) {
- return operandOne != operandTwo;
+ public boolean evaluate(Long operandOne, Long operandTwo) {
+ return operandOne.longValue() != operandTwo.longValue();
}
};
/** Datatype operation */
- private final String operator;
+ private String operator;
private OperatorTypes(String sizeOperation) {
this.operator = sizeOperation;
@@ -101,33 +113,15 @@ public enum OperatorTypes {
public String toString() {
return operator;
}
-
- /**
- * Evaluate whether the operator would return true when comparing operandOne to operandTwo.
- *
- *
- *
- * OperatorTypes operator = OperatorTypes.GREATER_THAN;
- * long operandOne = 1;
- * long operandTwo = 2;
- *
- * boolean result = operator.evaluate(operandOne, operandTwo); // Returns false
- *
- *
- *
- * @param operandOne
- * @param operandTwo
- * @return true or false
- */
- public abstract boolean evaluate(long operandOne, long operandTwo);
+
+ // public abstract boolean evaluate(Long operandOne, Long operandTwo);
/**
* Return the type from its toString() value.
*
* @param string
- * the string
- * @return
- * the type
+ * the string
+ * @return the type
*/
public static OperatorTypes fromString(String string) {
for (OperatorTypes operator : OperatorTypes.values()) {
@@ -136,6 +130,6 @@ public enum OperatorTypes {
}
}
return null;
- }
+ }
}
diff --git a/cave/com.raytheon.uf.viz.datadelivery/src/com/raytheon/uf/viz/datadelivery/system/SystemLatencyTab.java b/cave/com.raytheon.uf.viz.datadelivery/src/com/raytheon/uf/viz/datadelivery/system/SystemLatencyTab.java
index 78a0af2dd1..cbb5b1b2f6 100644
--- a/cave/com.raytheon.uf.viz.datadelivery/src/com/raytheon/uf/viz/datadelivery/system/SystemLatencyTab.java
+++ b/cave/com.raytheon.uf.viz.datadelivery/src/com/raytheon/uf/viz/datadelivery/system/SystemLatencyTab.java
@@ -19,9 +19,7 @@
**/
package com.raytheon.uf.viz.datadelivery.system;
-import java.util.Arrays;
-
-import javax.xml.bind.JAXBException;
+import java.util.Collections;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
@@ -52,7 +50,8 @@ import com.raytheon.uf.viz.datadelivery.utils.DataDeliveryUtils;
* Date Ticket# Engineer Description
* ------------ ---------- ----------- --------------------------
* Sep 17, 2012 730 jpiatt Initial creation.
- * Oct 03, 2012 1241 djohnson Use {@link DataDeliveryPermission} and registry handlers.
+ * Oct 03, 2012 1241 djohnson Use {@link DataDeliveryPermission} and registry handlers.
+ * Jan 04, 2012 1420 mpduff Add delete rule function.
*
*
*
@@ -65,6 +64,8 @@ public class SystemLatencyTab {
private final IUFStatusHandler statusHandler = UFStatus
.getHandler(SystemLatencyTab.class);
+ private final String notAuthorizedMsg = " is not authorized to create, edit, or delete rules using the Data Delivery System Management\nPermission: ";
+
/** Parent Composite */
private final Composite parentComp;
@@ -83,34 +84,29 @@ public class SystemLatencyTab {
/** Flag for create and edit. */
private boolean create;
- /** Edit a selected item in the selected list down in the list. */
+ /** Edit rule button. */
private Button editBtn;
- /** New button. */
+ /** New rule button. */
private Button newBtn;
+ /** Delete rule button. */
+ private Button deleteBtn;
+
/** Button Height. */
private final int buttonHeight = SWT.DEFAULT;
/** Button Width. */
- private final int buttonWidth = 55;
-
- private final IRulesNeedApplying rulesNeedApplying;
+ private final int buttonWidth = 70;
/**
* Constructor.
*
* @param parentComp
* The Composite holding these controls
- * @param systemManagementDlg
- *
- * @param dataSet
- * The DataSet object
*/
- public SystemLatencyTab(Composite parentComp,
- IRulesNeedApplying rulesNeedApplying) {
+ public SystemLatencyTab(Composite parentComp) {
this.parentComp = parentComp;
- this.rulesNeedApplying = rulesNeedApplying;
init();
}
@@ -140,16 +136,20 @@ public class SystemLatencyTab {
latencyList = new List(latencyComp, SWT.BORDER | SWT.MULTI
| SWT.V_SCROLL | SWT.H_SCROLL);
latencyList.setLayoutData(gd);
+ latencyList.addSelectionListener(new SelectionAdapter() {
+ @Override
+ public void widgetSelected(SelectionEvent e) {
+ enableButtons(latencyList.getSelectionCount() > 0);
+ }
+ });
loadList();
-
}
/**
* Create the move up/down controls
*/
private void createSideButtons() {
-
GridData actionData = new GridData(SWT.DEFAULT, SWT.CENTER, false, true);
GridLayout actionLayout = new GridLayout(1, false);
Composite actionComp = new Composite(latencyComp, SWT.NONE);
@@ -168,6 +168,12 @@ public class SystemLatencyTab {
public void widgetSelected(SelectionEvent event) {
create = true;
handleLatencyRule();
+ if (latencyList.getItemCount() > 0) {
+ latencyList.select(0);
+ enableButtons(true);
+ } else {
+ enableButtons(false);
+ }
}
});
@@ -175,25 +181,46 @@ public class SystemLatencyTab {
editBtn = new Button(actionComp, SWT.PUSH);
editBtn.setText("Edit...");
editBtn.setLayoutData(btnData);
- editBtn.setEnabled(true);
+ editBtn.setEnabled(false);
editBtn.setToolTipText("Edit item selected in the list");
editBtn.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent event) {
create = false;
+ int idx = latencyList.getSelectionIndex();
handleLatencyRule();
+ if (!latencyList.isDisposed()) {
+ latencyList.select(idx);
+ }
}
});
+ btnData = new GridData(buttonWidth, buttonHeight);
+ deleteBtn = new Button(actionComp, SWT.PUSH);
+ deleteBtn.setText("Delete...");
+ deleteBtn.setLayoutData(btnData);
+ deleteBtn.setEnabled(false);
+ deleteBtn.setToolTipText("Delete item selected in the list");
+ deleteBtn.addSelectionListener(new SelectionAdapter() {
+ @Override
+ public void widgetSelected(SelectionEvent event) {
+ handleDeleteRule();
+ if (latencyList.getItemCount() > 0) {
+ latencyList.select(0);
+ }
+ }
+ });
+ }
+
+ private void enableButtons(boolean enable) {
+ deleteBtn.setEnabled(enable);
+ editBtn.setEnabled(enable);
}
private void handleLatencyRule() {
-
final DataDeliveryPermission permission = DataDeliveryPermission.SYSTEM_MANAGEMENT_CREATE;
IUser user = UserController.getUserObject();
- String msg = user.uniqueId()
- + " is not authorized to create or edit rules using the"
- + " Data Delivery System Management\nPermission: " + permission;
+ String msg = user.uniqueId() + notAuthorizedMsg + permission;
DataDeliveryAuthRequest request = new DataDeliveryAuthRequest();
request.setUser(user);
request.addRequestedPermissions(permission);
@@ -210,7 +237,7 @@ public class SystemLatencyTab {
// New
if (create) {
ruleDlg = new CreateEditRuleDlg(parentComp.getShell(),
- create, LATENCY_TYPE, rulesNeedApplying);
+ create, LATENCY_TYPE);
} else {
// Edit
String ruleName = null;
@@ -230,8 +257,7 @@ public class SystemLatencyTab {
return;
}
ruleDlg = new CreateEditRuleDlg(parentComp.getShell(),
- create, ruleName, LATENCY_TYPE,
- rulesNeedApplying);
+ create, ruleName, LATENCY_TYPE);
}
boolean reloadFlag = (Boolean) ruleDlg.open();
if (reloadFlag) {
@@ -246,7 +272,48 @@ public class SystemLatencyTab {
statusHandler.handle(Priority.PROBLEM,
"Error occurred in authorization request", e);
}
+ }
+ private void handleDeleteRule() {
+ final DataDeliveryPermission permission = DataDeliveryPermission.SYSTEM_MANAGEMENT_CREATE;
+ IUser user = UserController.getUserObject();
+ String msg = user.uniqueId() + notAuthorizedMsg + permission;
+ DataDeliveryAuthRequest request = new DataDeliveryAuthRequest();
+ request.setUser(user);
+ request.addRequestedPermissions(permission);
+ request.setNotAuthorizedMessage(msg);
+
+ try {
+ DataDeliveryAuthRequest auth = DataDeliveryUtils
+ .sendAuthorizationRequest(request);
+
+ if (auth != null && auth.isAuthorized()) {
+ String ruleName = null;
+ int selectedIdx = latencyList.getSelectionIndex();
+ if (selectedIdx > -1) {
+ int answer = DataDeliveryUtils.showYesNoMessage(
+ parentComp.getShell(), "Delete?",
+ "Are you sure you want to delete this rule?");
+ if (answer == SWT.YES) {
+ ruleName = latencyList.getItem(selectedIdx);
+ SystemRuleManager.getInstance().deleteLatencyRule(
+ ruleName);
+ loadList();
+ if (latencyList.getItemCount() == 0) {
+ enableButtons(false);
+ }
+ }
+ } else {
+ DataDeliveryUtils.showMessage(parentComp.getShell(),
+ SWT.ERROR, "Select Rule",
+ "Please select a rule for delete.");
+ return;
+ }
+ }
+ } catch (VizException e) {
+ statusHandler.handle(Priority.PROBLEM,
+ "Error occurred in authorization request", e);
+ }
}
/**
@@ -256,27 +323,10 @@ public class SystemLatencyTab {
latencyList.removeAll();
// Get the list of latency rule names
- String[] rules = null;
- try {
- rules = SystemRuleManager.getInstance().getLatencyRules();
- } catch (JAXBException e) {
- statusHandler.handle(Priority.PROBLEM,
- "Error occurred in loading rule list", e);
- }
-
- String[] ruleDisplayArray = null;
- if (rules != null && rules.length > 0) {
- ruleDisplayArray = new String[rules.length];
- for (int i = 0; i < rules.length; i++) {
- int extensionIndex = rules[i].lastIndexOf(".");
- ruleDisplayArray[i] = rules[i].substring(0, extensionIndex);
- }
- } else {
- ruleDisplayArray = new String[0];
- }
-
- Arrays.sort(ruleDisplayArray, String.CASE_INSENSITIVE_ORDER);
- latencyList.setItems(ruleDisplayArray);
+ java.util.List rules = null;
+ rules = SystemRuleManager.getInstance().getLatencyRuleNames();
+ Collections.sort(rules, String.CASE_INSENSITIVE_ORDER);
+ latencyList.setItems(rules.toArray(new String[rules.size()]));
}
}
\ No newline at end of file
diff --git a/cave/com.raytheon.uf.viz.datadelivery/src/com/raytheon/uf/viz/datadelivery/system/SystemManagementDlg.java b/cave/com.raytheon.uf.viz.datadelivery/src/com/raytheon/uf/viz/datadelivery/system/SystemManagementDlg.java
index 3a87f4ae0e..441f9eb9fa 100644
--- a/cave/com.raytheon.uf.viz.datadelivery/src/com/raytheon/uf/viz/datadelivery/system/SystemManagementDlg.java
+++ b/cave/com.raytheon.uf.viz.datadelivery/src/com/raytheon/uf/viz/datadelivery/system/SystemManagementDlg.java
@@ -45,7 +45,6 @@ import com.raytheon.uf.common.status.IUFStatusHandler;
import com.raytheon.uf.common.status.UFStatus;
import com.raytheon.uf.common.status.UFStatus.Priority;
import com.raytheon.uf.common.util.StringUtil;
-import com.raytheon.uf.viz.datadelivery.subscription.ISubscriptionService.ISubscriptionServiceResult;
import com.raytheon.uf.viz.datadelivery.subscription.SubscriptionService.ForceApplyPromptResponse;
import com.raytheon.uf.viz.datadelivery.subscription.SubscriptionService.IForceApplyPromptDisplayText;
import com.raytheon.uf.viz.datadelivery.utils.DataDeliveryUtils;
@@ -64,6 +63,7 @@ import com.raytheon.viz.ui.presenter.IDisplay;
* Sep 17, 2012 730 jpiatt Initial creation.
* Oct 23, 2012 1286 djohnson Hook into bandwidth management.
* Nov 20, 2012 1286 djohnson Implement IDisplay.
+ * Jan 04, 2013 1420 mpduff Remove applying of rules.
*
*
*
@@ -71,7 +71,7 @@ import com.raytheon.viz.ui.presenter.IDisplay;
* @version 1.0
*/
public class SystemManagementDlg extends CaveSWTDialog implements IDisplay,
- IRulesNeedApplying, IForceApplyPromptDisplayText {
+ IForceApplyPromptDisplayText {
/** Status Handler */
private final IUFStatusHandler statusHandler = UFStatus
@@ -132,8 +132,6 @@ public class SystemManagementDlg extends CaveSWTDialog implements IDisplay,
private Spinner availBandwidthSpinner;
- private boolean needToApplyRules;
-
/**
* Constructor.
*
@@ -285,7 +283,7 @@ public class SystemManagementDlg extends CaveSWTDialog implements IDisplay,
priorityComp.setLayout(gl);
priorityComp.setLayoutData(gd);
priorityTab.setControl(priorityComp);
- SystemPriorityTab pTab = new SystemPriorityTab(priorityComp, this);
+ SystemPriorityTab pTab = new SystemPriorityTab(priorityComp);
gd = new GridData(SWT.FILL, SWT.DEFAULT, true, false);
gl = new GridLayout(1, false);
@@ -298,7 +296,7 @@ public class SystemManagementDlg extends CaveSWTDialog implements IDisplay,
latencyComp.setLayout(gl);
latencyComp.setLayoutData(gd);
latencyTab.setControl(latencyComp);
- SystemLatencyTab lTab = new SystemLatencyTab(latencyComp, this);
+ SystemLatencyTab lTab = new SystemLatencyTab(latencyComp);
gd = new GridData(SWT.CENTER, SWT.DEFAULT, true, false);
gl = new GridLayout(1, false);
@@ -310,7 +308,7 @@ public class SystemManagementDlg extends CaveSWTDialog implements IDisplay,
routingComp.setLayout(gl);
routingComp.setLayoutData(gd);
routingTab.setControl(routingComp);
- SystemRoutingTab rTab = new SystemRoutingTab(routingComp, this);
+ SystemRoutingTab rTab = new SystemRoutingTab(routingComp);
}
/**
@@ -433,23 +431,6 @@ public class SystemManagementDlg extends CaveSWTDialog implements IDisplay,
}
}
- if (needToApplyRules) {
- ISubscriptionServiceResult ruleApplyResult = SystemRuleApplication
- .applyRules(this, this);
- if (ruleApplyResult != null) {
- if (ruleApplyResult.hasMessageToDisplay()) {
- DataDeliveryUtils.showMessage(getShell(), SWT.OK,
- "Rules Applied",
- ruleApplyResult.getMessageToDisplay());
- }
-
- if (ruleApplyResult.isAllowFurtherEditing()) {
- return false;
- }
- }
-
- needToApplyRules = false;
- }
return true;
}
@@ -461,14 +442,6 @@ public class SystemManagementDlg extends CaveSWTDialog implements IDisplay,
return DataDeliveryUtils.showYesNoMessage(shell, title, message) == SWT.YES;
}
- /**
- * {@inheritDoc}
- */
- @Override
- public void flagRulesAsNeedApplying() {
- needToApplyRules = true;
- }
-
/**
* {@inheritDoc}
*/
diff --git a/cave/com.raytheon.uf.viz.datadelivery/src/com/raytheon/uf/viz/datadelivery/system/SystemPriorityTab.java b/cave/com.raytheon.uf.viz.datadelivery/src/com/raytheon/uf/viz/datadelivery/system/SystemPriorityTab.java
index 3a70f63f00..5e9e2f07fe 100644
--- a/cave/com.raytheon.uf.viz.datadelivery/src/com/raytheon/uf/viz/datadelivery/system/SystemPriorityTab.java
+++ b/cave/com.raytheon.uf.viz.datadelivery/src/com/raytheon/uf/viz/datadelivery/system/SystemPriorityTab.java
@@ -19,9 +19,7 @@
**/
package com.raytheon.uf.viz.datadelivery.system;
-import java.util.Arrays;
-
-import javax.xml.bind.JAXBException;
+import java.util.Collections;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
@@ -52,7 +50,8 @@ import com.raytheon.uf.viz.datadelivery.utils.DataDeliveryUtils;
* Date Ticket# Engineer Description
* ------------ ---------- ----------- --------------------------
* Sep 17, 2012 730 jpiatt Initial creation.
- * Oct 03, 2012 1241 djohnson Use {@link DataDeliveryPermission} and registry handlers.
+ * Oct 03, 2012 1241 djohnson Use {@link DataDeliveryPermission} and registry handlers.
+ * Jan 04, 2013 1420 mpduff Add delete function.
*
*
*
@@ -80,22 +79,25 @@ public class SystemPriorityTab {
/** Available List widget */
private List priorityList;
- /** Edit a selected item in the selected list. */
+ /** Edit rule button. */
private Button editBtn;
- /** New button. */
+ /** New rule button. */
private Button newBtn;
+ /** Delete rule button */
+ private Button deleteBtn;
+
/** Button Height. */
private final int buttonHeight = SWT.DEFAULT;
/** Button Width. */
- private final int buttonWidth = 55;
+ private final int buttonWidth = 70;
/** Flag for create and edit. */
private boolean create;
- private final IRulesNeedApplying rulesNeedApplying;
+ private final String notAuthorizedMsg = " is not authorized to create, edit, or delete rules using the Data Delivery System Management\nPermission: ";
/**
* Constructor.
@@ -107,10 +109,8 @@ public class SystemPriorityTab {
* @param dataSet
* The DataSet object
*/
- public SystemPriorityTab(Composite parentComp,
- IRulesNeedApplying rulesNeedApplying) {
+ public SystemPriorityTab(Composite parentComp) {
this.parentComp = parentComp;
- this.rulesNeedApplying = rulesNeedApplying;
init();
}
@@ -140,9 +140,18 @@ public class SystemPriorityTab {
priorityList = new List(priorityComp, SWT.BORDER | SWT.MULTI
| SWT.V_SCROLL | SWT.H_SCROLL);
priorityList.setLayoutData(gd);
+ priorityList.addSelectionListener(new SelectionAdapter() {
+ @Override
+ public void widgetSelected(SelectionEvent e) {
+ if (priorityList.getSelectionCount() > 0) {
+ enableButtons(true);
+ } else {
+ enableButtons(false);
+ }
+ }
+ });
loadList();
-
}
/**
@@ -168,6 +177,11 @@ public class SystemPriorityTab {
public void widgetSelected(SelectionEvent event) {
create = true;
handlePriorityRule();
+ if (priorityList.getItemCount() > 0) {
+ priorityList.select(0);
+ } else {
+ enableButtons(false);
+ }
}
});
@@ -175,28 +189,47 @@ public class SystemPriorityTab {
editBtn = new Button(actionComp, SWT.PUSH);
editBtn.setText("Edit...");
editBtn.setLayoutData(btnData);
- editBtn.setEnabled(true);
+ editBtn.setEnabled(false);
editBtn.setToolTipText("Edit item selected in the list");
editBtn.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent event) {
create = false;
+ int idx = priorityList.getSelectionIndex();
handlePriorityRule();
+ priorityList.select(idx);
}
});
+ btnData = new GridData(buttonWidth, buttonHeight);
+ deleteBtn = new Button(actionComp, SWT.PUSH);
+ deleteBtn.setText("Delete...");
+ deleteBtn.setLayoutData(btnData);
+ deleteBtn.setEnabled(false);
+ deleteBtn.setToolTipText("Edit item selected in the list");
+ deleteBtn.addSelectionListener(new SelectionAdapter() {
+ @Override
+ public void widgetSelected(SelectionEvent event) {
+ handleDeleteRule();
+ if (priorityList.getItemCount() > 0) {
+ priorityList.select(0);
+ }
+ }
+ });
+ }
+
+ private void enableButtons(boolean enable) {
+ deleteBtn.setEnabled(enable);
+ editBtn.setEnabled(enable);
}
/**
* Handle create and edit rules.
*/
private void handlePriorityRule() {
-
final DataDeliveryPermission permission = DataDeliveryPermission.SYSTEM_MANAGEMENT_CREATE;
IUser user = UserController.getUserObject();
- String msg = user.uniqueId()
- + " is not authorized to create or edit rules using the"
- + " Data Delivery System Management\nPermission: " + permission;
+ String msg = user.uniqueId() + notAuthorizedMsg + permission;
DataDeliveryAuthRequest request = new DataDeliveryAuthRequest();
request.setUser(user);
request.addRequestedPermissions(permission);
@@ -207,13 +240,11 @@ public class SystemPriorityTab {
.sendAuthorizationRequest(request);
if (auth != null && auth.isAuthorized()) {
-
if (ruleDlg == null || ruleDlg.isDisposed()) {
-
// New
if (create) {
ruleDlg = new CreateEditRuleDlg(parentComp.getShell(),
- create, PRIORITY_TYPE, rulesNeedApplying);
+ create, PRIORITY_TYPE);
} else {
// Edit
String ruleName = null;
@@ -233,19 +264,16 @@ public class SystemPriorityTab {
return;
}
ruleDlg = new CreateEditRuleDlg(parentComp.getShell(),
- create, ruleName, PRIORITY_TYPE,
- rulesNeedApplying);
+ create, ruleName, PRIORITY_TYPE);
}
boolean reloadFlag = (Boolean) ruleDlg.open();
if (reloadFlag) {
loadList();
}
-
} else {
ruleDlg.bringToTop();
}
-
}
} catch (VizException e) {
statusHandler.handle(Priority.PROBLEM,
@@ -254,6 +282,48 @@ public class SystemPriorityTab {
}
+ private void handleDeleteRule() {
+ final DataDeliveryPermission permission = DataDeliveryPermission.SYSTEM_MANAGEMENT_CREATE;
+ IUser user = UserController.getUserObject();
+ String msg = user.uniqueId() + notAuthorizedMsg + permission;
+ DataDeliveryAuthRequest request = new DataDeliveryAuthRequest();
+ request.setUser(user);
+ request.addRequestedPermissions(permission);
+ request.setNotAuthorizedMessage(msg);
+
+ try {
+ DataDeliveryAuthRequest auth = DataDeliveryUtils
+ .sendAuthorizationRequest(request);
+
+ if (auth != null && auth.isAuthorized()) {
+ String ruleName = null;
+ int selectedIdx = priorityList.getSelectionIndex();
+ if (selectedIdx > -1) {
+ int answer = DataDeliveryUtils.showYesNoMessage(
+ parentComp.getShell(), "Delete?",
+ "Are you sure you want to delete this rule?");
+ if (answer == SWT.YES) {
+ ruleName = priorityList.getItem(selectedIdx);
+ SystemRuleManager.getInstance().deletePriorityRule(
+ ruleName);
+ loadList();
+ if (priorityList.getItemCount() == 0) {
+ enableButtons(false);
+ }
+ }
+ } else {
+ DataDeliveryUtils.showMessage(parentComp.getShell(),
+ SWT.ERROR, "Select Rule",
+ "Please select a rule for delete.");
+ return;
+ }
+ }
+ } catch (VizException e) {
+ statusHandler.handle(Priority.PROBLEM,
+ "Error occurred in authorization request", e);
+ }
+ }
+
/**
* Load the rule list.
*/
@@ -261,27 +331,11 @@ public class SystemPriorityTab {
priorityList.removeAll();
// Get the list of priority rule names
- String[] rules = null;
- try {
- rules = SystemRuleManager.getInstance().getPriorityRules();
- } catch (JAXBException e) {
- statusHandler.handle(Priority.PROBLEM,
- "Error occurred in loading rule list", e);
- }
+ java.util.List rules = SystemRuleManager.getInstance()
+ .getPriorityRuleNames();
- String[] ruleDisplayArray = null;
- if (rules != null && rules.length > 0) {
- ruleDisplayArray = new String[rules.length];
- for (int i = 0; i < rules.length; i++) {
- int extensionIndex = rules[i].lastIndexOf(".");
- ruleDisplayArray[i] = rules[i].substring(0, extensionIndex);
- }
- } else {
- ruleDisplayArray = new String[0];
- }
- Arrays.sort(ruleDisplayArray, String.CASE_INSENSITIVE_ORDER);
- priorityList.setItems(ruleDisplayArray);
+ Collections.sort(rules);
+ priorityList.setItems(rules.toArray(new String[rules.size()]));
}
-
}
diff --git a/cave/com.raytheon.uf.viz.datadelivery/src/com/raytheon/uf/viz/datadelivery/system/SystemRoutingTab.java b/cave/com.raytheon.uf.viz.datadelivery/src/com/raytheon/uf/viz/datadelivery/system/SystemRoutingTab.java
index 11f6ab0654..7cc513f364 100644
--- a/cave/com.raytheon.uf.viz.datadelivery/src/com/raytheon/uf/viz/datadelivery/system/SystemRoutingTab.java
+++ b/cave/com.raytheon.uf.viz.datadelivery/src/com/raytheon/uf/viz/datadelivery/system/SystemRoutingTab.java
@@ -35,6 +35,7 @@ import org.eclipse.swt.widgets.Label;
* Date Ticket# Engineer Description
* ------------ ---------- ----------- --------------------------
* Sep 17, 2012 730 jpiatt Initial creation.
+ * Jan 04, 2013 1420 mpduff Remove autoApply of rules.
*
*
*
@@ -46,21 +47,14 @@ public class SystemRoutingTab {
/** Parent Composite */
private final Composite parentComp;
- private final IRulesNeedApplying rulesNeedApplying;
-
/**
* Constructor.
*
* @param parentComp
* The Composite holding these controls
- *
- * @param dataSet
- * The DataSet object
*/
- public SystemRoutingTab(Composite parentComp,
- IRulesNeedApplying rulesNeedApplying) {
+ public SystemRoutingTab(Composite parentComp) {
this.parentComp = parentComp;
- this.rulesNeedApplying = rulesNeedApplying;
init();
}
diff --git a/cave/com.raytheon.uf.viz.datadelivery/src/com/raytheon/uf/viz/datadelivery/system/SystemRuleApplication.java b/cave/com.raytheon.uf.viz.datadelivery/src/com/raytheon/uf/viz/datadelivery/system/SystemRuleApplication.java
deleted file mode 100644
index 65a0915e5e..0000000000
--- a/cave/com.raytheon.uf.viz.datadelivery/src/com/raytheon/uf/viz/datadelivery/system/SystemRuleApplication.java
+++ /dev/null
@@ -1,268 +0,0 @@
-/**
- * This software was developed and / or modified by Raytheon Company,
- * pursuant to Contract DG133W-05-CQ-1067 with the US Government.
- *
- * U.S. EXPORT CONTROLLED TECHNICAL DATA
- * This software product contains export-restricted data whose
- * export/transfer/disclosure is restricted by U.S. law. Dissemination
- * to non-U.S. persons whether in the United States or abroad requires
- * an export license or other authorization.
- *
- * Contractor Name: Raytheon Company
- * Contractor Address: 6825 Pine Street, Suite 340
- * Mail Stop B8
- * Omaha, NE 68106
- * 402.291.0100
- *
- * See the AWIPS II Master Rights File ("Master Rights File.pdf") for
- * further licensing information.
- **/
-package com.raytheon.uf.viz.datadelivery.system;
-
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.List;
-
-import javax.xml.bind.JAXBContext;
-import javax.xml.bind.JAXBException;
-import javax.xml.bind.Marshaller;
-import javax.xml.bind.Unmarshaller;
-
-import com.raytheon.uf.common.datadelivery.registry.Subscription;
-import com.raytheon.uf.common.datadelivery.registry.handlers.DataDeliveryHandlers;
-import com.raytheon.uf.common.localization.LocalizationFile;
-import com.raytheon.uf.common.registry.handler.RegistryHandlerException;
-import com.raytheon.uf.common.status.IUFStatusHandler;
-import com.raytheon.uf.common.status.UFStatus;
-import com.raytheon.uf.common.status.UFStatus.Priority;
-import com.raytheon.uf.viz.datadelivery.services.DataDeliveryServices;
-import com.raytheon.uf.viz.datadelivery.subscription.ISubscriptionService.ISubscriptionServiceResult;
-import com.raytheon.uf.viz.datadelivery.subscription.SubscriptionService.IForceApplyPromptDisplayText;
-import com.raytheon.uf.viz.datadelivery.subscription.xml.SubscriptionRuleXML;
-import com.raytheon.uf.viz.datadelivery.utils.DataDeliveryGUIUtils.NameOperationItems;
-import com.raytheon.uf.viz.datadelivery.utils.DataDeliveryGUIUtils.TypeOperationItems;
-import com.raytheon.viz.ui.presenter.IDisplay;
-
-/**
- * Class to apply saved system rules to subscriptions.
- *
- *
- *
- * SOFTWARE HISTORY
- *
- * Date Ticket# Engineer Description
- * ------------ ---------- ----------- --------------------------
- * Sep 17, 2012 0730 jpiatt Initial creation.
- * Nov 09, 2012 1286 djohnson Hook into bandwidth management.
- * Nov 20, 2012 1286 djohnson Use IDisplay for subscription service.
- *
- *
- *
- * @author jpiatt
- * @version 1.0
- */
-public class SystemRuleApplication {
-
- /** Status Handler */
- private final static IUFStatusHandler statusHandler = UFStatus
- .getHandler(SystemRuleApplication.class);
-
- /** Marshaller object */
- private static Marshaller marshaller;
-
- /** Unmarshaller object */
- private static Unmarshaller unmarshaller;
-
- /** JAXB context */
- private static JAXBContext jax;
-
- /** Size constant */
- private final static String DATASET_SIZE = OpsNetFieldNames.SIZE.toString();
-
- /** Frequency constant */
- private final static String DATASET_FREQ = OpsNetFieldNames.FREQUENCY
- .toString();
-
- /**
- * Get the rule list.
- *
- * @param display
- * @param displayPromptStrategy
- *
- * @return a message to display, or null if no message should be displayed
- */
- public static ISubscriptionServiceResult applyRules(IDisplay display,
- IForceApplyPromptDisplayText displayPromptStrategy) {
- LocalizationFile[] ruleFiles = null;
-
- try {
- ruleFiles = SystemRuleManager.getInstance().getRules();
- } catch (JAXBException e) {
- statusHandler.handle(Priority.PROBLEM,
- "Error applying rules to subscriptions", e);
- }
-
- createContext();
-
- // get all subscriptions
- List subscriptions = Collections.emptyList();
- try {
- subscriptions = DataDeliveryHandlers.getSubscriptionHandler()
- .getAll();
- } catch (RegistryHandlerException t) {
- statusHandler.handle(Priority.PROBLEM, t.getMessage(), t);
- }
-
- // need to determine which are latency files
- if (ruleFiles != null) {
- List subscriptionsModified = new ArrayList();
- for (LocalizationFile lf : ruleFiles) {
- try {
- SubscriptionRuleXML xml = (SubscriptionRuleXML) unmarshaller
- .unmarshal(lf.getFile());
- Integer priority = xml.getRulePriority();
- Integer latency = xml.getRuleLatency();
- // search subscriptions for criteria
- List matchingSubscriptions = getMatchingSubscriptions(
- xml, subscriptions);
- // replace subscriptions with the rule value
- applyRule(matchingSubscriptions, priority, latency);
- for (Subscription subscription : matchingSubscriptions) {
- if (!subscriptionsModified.contains(subscription)) {
- subscriptionsModified.add(subscription);
- }
- }
- } catch (JAXBException e) {
- statusHandler.handle(Priority.PROBLEM,
- e.getLocalizedMessage(), e);
- }
- }
-
- try {
- final ISubscriptionServiceResult result = DataDeliveryServices
- .getSubscriptionService().update(subscriptionsModified,
- displayPromptStrategy);
- return result;
- } catch (RegistryHandlerException e) {
- statusHandler.handle(Priority.PROBLEM,
- "Unable to apply the rules files to subscriptions.", e);
- }
- }
-
- return null;
-
- }
-
- /**
- * Get a list of the subscriptions matching the rule criteria.
- *
- * @param subscriptions
- */
- private static List getMatchingSubscriptions(
- SubscriptionRuleXML xml, List subscriptions) {
- List modifyList = new ArrayList();
-
- String field = xml.getRuleField();
- String operator = xml.getRuleOperator();
- String value = xml.getRuleValue();
-
- if (DATASET_SIZE.equals(field) || DATASET_FREQ.equals(field)) {
- String unit = xml.getRuleUnit();
- }
-
- for (Subscription sub : subscriptions) {
- // If Data Name
- if (OpsNetFieldNames.NAME.toString().equals(field)) {
- // get subscription names matching criteria
- if (NameOperationItems.LIKE.toString().equals(operator)) {
- String dsName = sub.getDataSetName();
- if (dsName.contains(value)) {
- modifyList.add(sub);
- }
- }
-
- }
-
- // If Data Type
- if (OpsNetFieldNames.TYPE.toString().equals(field)) {
- String dsType = sub.getDataSetType().toString();
- // get subscription names matching criteria
- if (TypeOperationItems.IN.toString().equals(operator)) {
- if (dsType.contains(value)) {
- modifyList.add(sub);
- }
- } else if (!TypeOperationItems.NOT_IN.toString().equals(
- operator)) {
- if (!dsType.contains(value)) {
- modifyList.add(sub);
- }
- }
- }
-
- // If Data Size
- if (DATASET_SIZE.equals(field)) {
- long dsSize = sub.getDataSetSize();
- int ruleValue = Integer.parseInt(value);
- OperatorTypes operatorType = OperatorTypes.fromString(operator);
- // get subscription names matching criteria
- if (operatorType.evaluate(dsSize, ruleValue)) {
- modifyList.add(sub);
- }
- }
-
- // If Data Frequency
- if (DATASET_FREQ.equals(field)) {
- // TODO Determine Dataset Frequency
- }
- }
-
- return modifyList;
-
- }
-
- /**
- * Get a list of the subscriptions matching the rule criteria.
- *
- * @param modifyList
- * @return the set of subscription names that are unscheduled after applying
- * the rules
- */
- private static void applyRule(List modifyList,
- Integer priority, Integer latency) {
- // Apply the priority to the subscriptions returned
- if ((priority != null || latency != null) && !modifyList.isEmpty()) {
- for (Subscription subscription : modifyList) {
- if (priority != null) {
- // replace the priority
- subscription.setPriority(priority - 1);
- }
-
- if (latency != null) {
- subscription.setLatencyInMinutes(latency);
- }
- }
-
- }
- }
-
- /**
- * Create the JAXB context
- */
- @SuppressWarnings("rawtypes")
- private static void createContext() {
- Class[] classes = new Class[] { SubscriptionRuleXML.class };
-
- try {
- jax = JAXBContext.newInstance(classes);
- unmarshaller = jax.createUnmarshaller();
- marshaller = jax.createMarshaller();
-
- // format the output xml file
- marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
-
- } catch (JAXBException e) {
- statusHandler.handle(Priority.PROBLEM, e.getLocalizedMessage(), e);
- }
- }
-
-}
diff --git a/cave/com.raytheon.uf.viz.datadelivery/src/com/raytheon/uf/viz/datadelivery/system/SystemRuleManager.java b/cave/com.raytheon.uf.viz.datadelivery/src/com/raytheon/uf/viz/datadelivery/system/SystemRuleManager.java
index 645851c00c..9044331486 100644
--- a/cave/com.raytheon.uf.viz.datadelivery/src/com/raytheon/uf/viz/datadelivery/system/SystemRuleManager.java
+++ b/cave/com.raytheon.uf.viz.datadelivery/src/com/raytheon/uf/viz/datadelivery/system/SystemRuleManager.java
@@ -21,6 +21,7 @@ package com.raytheon.uf.viz.datadelivery.system;
import java.io.File;
import java.util.ArrayList;
+import java.util.List;
import java.util.Set;
import javax.xml.bind.JAXBContext;
@@ -28,9 +29,6 @@ import javax.xml.bind.JAXBException;
import javax.xml.bind.Marshaller;
import javax.xml.bind.Unmarshaller;
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.widgets.Shell;
-
import com.raytheon.uf.common.datadelivery.bandwidth.IBandwidthService;
import com.raytheon.uf.common.datadelivery.registry.Network;
import com.raytheon.uf.common.datadelivery.registry.Subscription;
@@ -44,8 +42,15 @@ import com.raytheon.uf.common.localization.exception.LocalizationOpFailedExcepti
import com.raytheon.uf.common.status.IUFStatusHandler;
import com.raytheon.uf.common.status.UFStatus;
import com.raytheon.uf.common.status.UFStatus.Priority;
-import com.raytheon.uf.viz.datadelivery.subscription.xml.SubscriptionRuleXML;
-import com.raytheon.uf.viz.datadelivery.utils.DataDeliveryUtils;
+import com.raytheon.uf.viz.datadelivery.subscription.xml.LatencyRuleXML;
+import com.raytheon.uf.viz.datadelivery.subscription.xml.LatencyRulesXML;
+import com.raytheon.uf.viz.datadelivery.subscription.xml.PriorityRuleXML;
+import com.raytheon.uf.viz.datadelivery.subscription.xml.PriorityRulesXML;
+import com.raytheon.uf.viz.datadelivery.subscription.xml.RuleXML;
+import com.raytheon.uf.viz.datadelivery.subscription.xml.RulesXML;
+import com.raytheon.uf.viz.datadelivery.utils.DataSetFrequency;
+import com.raytheon.uf.viz.datadelivery.utils.NameOperationItems;
+import com.raytheon.uf.viz.datadelivery.utils.TypeOperationItems;
/**
* System Rule Manager.
@@ -57,7 +62,8 @@ import com.raytheon.uf.viz.datadelivery.utils.DataDeliveryUtils;
* Date Ticket# Engineer Description
* ------------ ---------- ----------- --------------------------
* Sep 17, 2012 730 jpiatt Initial creation.
- * Oct 23, 2012 1286 djohnson Hook into bandwidth management.
+ * Oct 23, 2012 1286 djohnson Hook into bandwidth management.
+ * Jan 04, 2013 1420 mpduff Move rules into a single file.
*
*
*
@@ -67,13 +73,19 @@ import com.raytheon.uf.viz.datadelivery.utils.DataDeliveryUtils;
public class SystemRuleManager {
/** SystemRuleManager instance */
- private static SystemRuleManager instance = new SystemRuleManager();
+ private static final SystemRuleManager instance = new SystemRuleManager();
/** Directory Path to rules */
- private final String RULE_PATH = "dataDelivery" + File.separator + "rules" + File.separator;
+ private final String RULE_PATH = "datadelivery" + File.separator
+ + "systemManagement" + File.separator + "rules" + File.separator;
+
+ private final String LATENCY_RULE_FILE = RULE_PATH + "latencyRules.xml";
+
+ private final String PRIORITY_RULE_FILE = RULE_PATH + "priorityRules.xml";
/** Status Handler */
- private final IUFStatusHandler statusHandler = UFStatus.getHandler(SystemRuleManager.class);
+ private final IUFStatusHandler statusHandler = UFStatus
+ .getHandler(SystemRuleManager.class);
/** JAXB context */
private JAXBContext jax;
@@ -84,9 +96,6 @@ public class SystemRuleManager {
/** Unmarshaller object */
private Unmarshaller unmarshaller;
- /** Array of rule localization files */
- private LocalizationFile[] ruleFiles;
-
private IBandwidthService bandwidthService;
/**
@@ -95,7 +104,7 @@ public class SystemRuleManager {
private SystemRuleManager() {
createContext();
}
-
+
/**
* Get an instance of the SystemRuleManager.
*
@@ -110,178 +119,74 @@ public class SystemRuleManager {
*/
@SuppressWarnings("rawtypes")
private void createContext() {
- Class[] classes = new Class[] { SubscriptionRuleXML.class };
+ Class[] classes = new Class[] { RuleXML.class, PriorityRuleXML.class,
+ LatencyRuleXML.class, LatencyRulesXML.class,
+ PriorityRulesXML.class, RulesXML.class, OperatorTypes.class,
+ TypeOperationItems.class, NameOperationItems.class };
try {
jax = JAXBContext.newInstance(classes);
this.unmarshaller = jax.createUnmarshaller();
this.marshaller = jax.createMarshaller();
this.marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
- } catch (JAXBException e) {
+ } catch (Exception e) {
statusHandler.handle(Priority.ERROR, e.getLocalizedMessage(), e);
}
}
/**
- * Get priority file names
+ * Get the names of the priority rules
*
- * @return String[]
- * Array of priority rule names
- * @throws JAXBException
+ * @return String[] of names
+ * @throws JAXBException
*/
- public String[] getPriorityRules() throws JAXBException {
+ public List getPriorityRuleNames() {
+ return getPriorityRules().getRuleNames();
+ }
- ArrayList priorityList = new ArrayList();
- ruleFiles = getRules();
-
- //determine which are priority files
- for (LocalizationFile lf : ruleFiles) {
- try {
- SubscriptionRuleXML xml = (SubscriptionRuleXML) unmarshaller.unmarshal(lf.getFile());
- Integer priority = xml.getRulePriority();
-
- if (priority != null) {
- String lfName = lf.getFile().getName();
- priorityList.add(lfName);
- }
-
- } catch (JAXBException e) {
- statusHandler.handle(Priority.PROBLEM, e.getLocalizedMessage(), e);
+ public PriorityRuleXML loadPriorityRule(String name) {
+ PriorityRulesXML priorityRules = getPriorityRules();
+ for (PriorityRuleXML rule : priorityRules.getRules()) {
+ if (rule.getRuleName().equals(name)) {
+ return rule;
}
}
- String[] priorityRules = null;
+ return new PriorityRuleXML();
+ }
- if (priorityList.size() > 0) {
- priorityRules = priorityList.toArray(new String[priorityList.size()]);
+ public LatencyRuleXML loadLatencyRule(String name) {
+ LatencyRulesXML latencyRules = getLatencyRules();
+ for (LatencyRuleXML rule : latencyRules.getRules()) {
+ if (rule.getRuleName().equals(name)) {
+ return rule;
+ }
}
- return priorityRules;
-
+ return new LatencyRuleXML();
}
/**
* Get latency file names
*
- * @return String[]
- * Array of latency rule names
- * @throws JAXBException
+ * @return String[] Array of latency rule names
+ * @throws JAXBException
*/
- public String[] getLatencyRules() throws JAXBException {
-
- ArrayList latencyList = new ArrayList();
- ruleFiles = getRules();
-
- //need to determine which are latency files
- for (LocalizationFile lf : ruleFiles) {
- try {
- SubscriptionRuleXML xml = (SubscriptionRuleXML) unmarshaller.unmarshal(lf.getFile());
- Integer latency = xml.getRuleLatency();
-
- if (latency != null) {
- String lfName = lf.getFile().getName();
- latencyList.add(lfName);
- }
-
-
- } catch (JAXBException e) {
- statusHandler.handle(Priority.PROBLEM, e.getLocalizedMessage(), e);
- }
- }
-
- String[] latencyRules = null;
-
- if (!latencyList.isEmpty()) {
- latencyRules = latencyList.toArray(new String[latencyList.size()]);
- }
-
- return latencyRules;
-
+ public List getLatencyRuleNames() {
+ return getLatencyRules().getRuleNames();
}
- /**
- * Get rule files
- *
- * @return String[]
- * Array of latency rule names
- * @throws JAXBException
- */
- public LocalizationFile[] getRules() throws JAXBException {
+ public boolean savePriorityRules(PriorityRulesXML xmlObj) {
IPathManager pm = PathManagerFactory.getPathManager();
- LocalizationContext context = pm.getContext(LocalizationType.CAVE_STATIC, LocalizationLevel.USER);
- String[] extensions = new String[] { "xml" };
- ruleFiles = pm.listFiles(context, RULE_PATH, extensions, false, true);
-
- return ruleFiles;
-
- }
-
- /**
- * Load a saved rule into memory
- *
- * @param ruleName
- * The subset name
- *
- * @return The SubscriptionRuleXML object
- */
- public SubscriptionRuleXML loadRule(String ruleName) {
- // Load the rule file
- if (ruleFiles == null || ruleFiles.length == 0) {
- try {
- getRules();
- } catch (JAXBException e) {
- statusHandler.handle(Priority.PROBLEM, e.getLocalizedMessage(), e);
- }
- }
-
- for (LocalizationFile lf : ruleFiles) {
- if (lf.getFile().getName().equals(ruleName + ".xml")) {
- try {
- return (SubscriptionRuleXML) unmarshaller.unmarshal(lf.getFile());
- } catch (JAXBException e) {
- statusHandler.handle(Priority.PROBLEM, e.getLocalizedMessage(), e);
- }
- }
- }
-
- return null;
- }
-
- /**
- * Save a rule xml object.
- *
- * @param rule
- * the object to save
- * @param shell
- * @param create false for edit
- * @return true if successfully saved
- */
- public boolean saveRule(SubscriptionRuleXML rule, Shell shell) {
-
- String ruleName = rule.getRuleName();
-
- if (!ruleName.endsWith("xml")) {
- rule.setRuleName((ruleName) + ".xml");
- }
-
- IPathManager pm = PathManagerFactory.getPathManager();
-
- LocalizationContext context = pm.getContext(LocalizationType.CAVE_STATIC, LocalizationLevel.USER);
- LocalizationFile subscriptionRuleLocFile = pm.getLocalizationFile(context, RULE_PATH + rule.getRuleName());
-
- if (subscriptionRuleLocFile.getFile().exists()) {
- String msg = "The file " + subscriptionRuleLocFile.getFile().getName()
- + " already exists.\n\nWould you like to overwrite the file?";
- int response = DataDeliveryUtils.showMessage(shell, SWT.YES | SWT.NO, "File Exists", msg);
- if (response == SWT.NO) {
- return false;
- }
- }
+ LocalizationContext context = pm.getContext(
+ LocalizationType.COMMON_STATIC, LocalizationLevel.SITE);
+ LocalizationFile priorityRulesLocFile = pm.getLocalizationFile(context,
+ this.PRIORITY_RULE_FILE);
try {
- marshaller.marshal(rule, subscriptionRuleLocFile.getFile());
- subscriptionRuleLocFile.save();
+ marshaller.marshal(xmlObj, priorityRulesLocFile.getFile());
+ priorityRulesLocFile.save();
return true;
} catch (JAXBException e) {
statusHandler.handle(Priority.ERROR, e.getLocalizedMessage(), e);
@@ -292,6 +197,234 @@ public class SystemRuleManager {
return false;
}
+ public boolean saveLatencyRules(LatencyRulesXML xmlObj) {
+ IPathManager pm = PathManagerFactory.getPathManager();
+
+ LocalizationContext context = pm.getContext(
+ LocalizationType.COMMON_STATIC, LocalizationLevel.SITE);
+ LocalizationFile latencyRulesLocFile = pm.getLocalizationFile(context,
+ this.LATENCY_RULE_FILE);
+
+ try {
+ marshaller.marshal(xmlObj, latencyRulesLocFile.getFile());
+ latencyRulesLocFile.save();
+ return true;
+ } catch (JAXBException e) {
+ statusHandler.handle(Priority.ERROR, e.getLocalizedMessage(), e);
+ } catch (LocalizationOpFailedException e) {
+ statusHandler.handle(Priority.ERROR, e.getLocalizedMessage(), e);
+ }
+
+ return false;
+ }
+
+ public void deleteLatencyRule(String ruleName) {
+ LatencyRulesXML latencyRules = getLatencyRules();
+
+ for (LatencyRuleXML rule : latencyRules.getRules()) {
+ if (rule.getRuleName().equals(ruleName)) {
+ latencyRules.removeRuleByName(ruleName);
+ saveLatencyRules(latencyRules);
+ return;
+ }
+ }
+ }
+
+ public void deletePriorityRule(String ruleName) {
+ PriorityRulesXML priorityRules = getPriorityRules();
+
+ for (PriorityRuleXML rule : priorityRules.getRules()) {
+ if (rule.getRuleName().equals(ruleName)) {
+ priorityRules.removeRuleByName(ruleName);
+ savePriorityRules(priorityRules);
+ return;
+ }
+ }
+ }
+
+ public boolean updateRule(LatencyRuleXML rule) {
+ LatencyRulesXML rulesXml = getLatencyRules();
+ boolean saved = rulesXml.updateRule(rule);
+ if (saved) {
+ return saveLatencyRules(rulesXml);
+ }
+
+ return false;
+ }
+
+ public boolean updateRule(PriorityRuleXML rule) {
+ PriorityRulesXML rulesXml = getPriorityRules();
+ boolean saved = rulesXml.updateRule(rule);
+ if (saved) {
+ saved = savePriorityRules(rulesXml);
+ }
+
+ if (!saved) {
+ this.statusHandler.warn("Error saving rules.");
+ }
+
+ return saved;
+ }
+
+ public boolean saveRule(PriorityRuleXML rule) {
+ PriorityRulesXML rulesXml = getPriorityRules();
+ boolean saved = rulesXml.addRule(rule);
+ if (saved) {
+ saved = savePriorityRules(rulesXml);
+ }
+
+ if (!saved) {
+ this.statusHandler.warn("Error saving Priority rules.");
+ }
+
+ return saved;
+ }
+
+ public boolean saveRule(LatencyRuleXML rule) {
+ LatencyRulesXML rulesXml = getLatencyRules();
+ boolean saved = rulesXml.addRule(rule);
+ if (saved) {
+ saved = saveLatencyRules(rulesXml);
+ }
+
+ if (!saved) {
+ this.statusHandler.warn("Error saving Latency rules.");
+ }
+
+ return saved;
+ }
+
+ private LatencyRulesXML getLatencyRules() {
+ LocalizationFile lfile = getRules(this.LATENCY_RULE_FILE);
+
+ LatencyRulesXML latencyRules = new LatencyRulesXML();
+ if (lfile != null && lfile.exists()) {
+ try {
+ latencyRules = (LatencyRulesXML) unmarshaller.unmarshal(lfile
+ .getFile());
+ } catch (JAXBException e) {
+ statusHandler
+ .handle(Priority.ERROR, e.getLocalizedMessage(), e);
+ }
+ }
+
+ return latencyRules;
+ }
+
+ private PriorityRulesXML getPriorityRules() {
+ LocalizationFile lfile = getRules(this.PRIORITY_RULE_FILE);
+
+ PriorityRulesXML priorityRules = new PriorityRulesXML();
+ if (lfile != null && lfile.exists()) {
+ try {
+ priorityRules = (PriorityRulesXML) unmarshaller.unmarshal(lfile
+ .getFile());
+ } catch (JAXBException e) {
+ statusHandler
+ .handle(Priority.ERROR, e.getLocalizedMessage(), e);
+ }
+ }
+ return priorityRules;
+ }
+
+ private LocalizationFile getRules(String name) {
+ IPathManager pm = PathManagerFactory.getPathManager();
+ return pm.getStaticLocalizationFile(name);
+ }
+
+ /**
+ * Get the default latency.
+ *
+ * @param DataSetFrequency
+ * Frequency of the data
+ *
+ * @return The default latency
+ */
+ public int getDefaultLatency(DataSetFrequency freq) {
+ int frequency = 40;
+ switch (freq) {
+ case HOURLY:
+ frequency = 40;
+ break;
+ case SIX_HOURLY:
+ frequency = 115;
+ break;
+ }
+
+ return frequency;
+ }
+
+ /**
+ * Get the default latency value given the cycleTimes.
+ *
+ * @param cycleTimes
+ * @return
+ */
+ public int getDefaultLatency(List cycleTimes) {
+ DataSetFrequency freq = DataSetFrequency.fromCycleTimes(cycleTimes);
+
+ return getDefaultLatency(freq);
+ }
+
+ /**
+ * Return the lowest latency value defined by the rules.
+ *
+ * @param sub
+ * The subscription
+ * @param cycleTimes
+ * The available cycle times
+ * @return
+ */
+ public int getLatency(Subscription sub, Set cycleTimes) {
+ LatencyRulesXML rulesXml = this.getLatencyRules();
+ int latency = 999;
+ boolean found = false;
+ for (LatencyRuleXML rule : rulesXml.getRules()) {
+ if (rule.matches(sub, cycleTimes)) {
+ if (rule.getLatency() < latency) {
+ latency = rule.getLatency();
+ found = true;
+ }
+ }
+ }
+
+ // Set default if none found
+ if (!found) {
+ latency = this
+ .getDefaultLatency(new ArrayList(cycleTimes));
+ }
+
+ return latency;
+ }
+
+ /**
+ * Return the lowest priority value defined by the rules.
+ *
+ * @param sub
+ * @param cycleTimes
+ * @return
+ */
+ public int getPriority(Subscription sub, Set cycleTimes) {
+ PriorityRulesXML rulesXml = this.getPriorityRules();
+ int priority = 3;
+ boolean found = false;
+ for (PriorityRuleXML rule : rulesXml.getRules()) {
+ if (rule.matches(sub, cycleTimes)) {
+ if (rule.getPriority() < priority) {
+ priority = rule.getPriority();
+ found = true;
+ }
+ }
+ }
+
+ // Default to normal priority
+ if (!found) {
+ priority = 2;
+ }
+
+ return priority;
+ }
+
/**
* Set the {@link IBandwidthService}.
*
diff --git a/cave/com.raytheon.uf.viz.datadelivery/src/com/raytheon/uf/viz/datadelivery/test/subscription/xml/ColumnXML.java b/cave/com.raytheon.uf.viz.datadelivery/src/com/raytheon/uf/viz/datadelivery/test/subscription/xml/ColumnXML.java
deleted file mode 100644
index f509747cad..0000000000
--- a/cave/com.raytheon.uf.viz.datadelivery/src/com/raytheon/uf/viz/datadelivery/test/subscription/xml/ColumnXML.java
+++ /dev/null
@@ -1,103 +0,0 @@
-/**
- * This software was developed and / or modified by Raytheon Company,
- * pursuant to Contract DG133W-05-CQ-1067 with the US Government.
- *
- * U.S. EXPORT CONTROLLED TECHNICAL DATA
- * This software product contains export-restricted data whose
- * export/transfer/disclosure is restricted by U.S. law. Dissemination
- * to non-U.S. persons whether in the United States or abroad requires
- * an export license or other authorization.
- *
- * Contractor Name: Raytheon Company
- * Contractor Address: 6825 Pine Street, Suite 340
- * Mail Stop B8
- * Omaha, NE 68106
- * 402.291.0100
- *
- * See the AWIPS II Master Rights File ("Master Rights File.pdf") for
- * further licensing information.
- **/
-package com.raytheon.uf.viz.datadelivery.test.subscription.xml;
-
-import javax.xml.bind.annotation.XmlAccessType;
-import javax.xml.bind.annotation.XmlAccessorType;
-import javax.xml.bind.annotation.XmlAttribute;
-
-import com.raytheon.uf.common.serialization.ISerializableObject;
-
-/**
- * Subscription Manager Column Element Attributes.
- *
- *
- *
- * SOFTWARE HISTORY
- *
- * Date Ticket# Engineer Description
- * ------------ ---------- ----------- --------------------------
- * Jan 10, 2012 mpduff Initial creation
- *
- *
- *
- * @author mpduff
- * @version 1.0
- */
-
-@XmlAccessorType(XmlAccessType.NONE)
-public class ColumnXML implements ISerializableObject {
-
- @XmlAttribute(name = "name")
- protected String name;
-
- @XmlAttribute(name = "visible")
- protected boolean visible;
-
- public ColumnXML() {
-
- }
-
- public ColumnXML(String name, boolean visible) {
- this.name = name;
- this.visible = visible;
- }
-
- /**
- * @return the name
- */
- public String getName() {
- return name;
- }
-
- /**
- * @param name
- * the name to set
- */
- public void setName(String name) {
- this.name = name;
- }
-
- /**
- * @return the visible
- */
- public boolean isVisible() {
- return visible;
- }
-
- /**
- * @param visible
- * the visible to set
- */
- public void setVisible(boolean visible) {
- this.visible = visible;
- }
-
- /*
- * (non-Javadoc)
- *
- * @see java.lang.Object#toString()
- */
- @Override
- public String toString() {
- String s = "Name: " + name + ", Visible: " + visible;
- return s;
- }
-}
diff --git a/cave/com.raytheon.uf.viz.datadelivery/src/com/raytheon/uf/viz/datadelivery/utils/DataDeliveryGUIUtils.java b/cave/com.raytheon.uf.viz.datadelivery/src/com/raytheon/uf/viz/datadelivery/utils/DataDeliveryGUIUtils.java
index 21aad6a028..516e1f0b59 100644
--- a/cave/com.raytheon.uf.viz.datadelivery/src/com/raytheon/uf/viz/datadelivery/utils/DataDeliveryGUIUtils.java
+++ b/cave/com.raytheon.uf.viz.datadelivery/src/com/raytheon/uf/viz/datadelivery/utils/DataDeliveryGUIUtils.java
@@ -25,6 +25,8 @@ import java.util.Date;
import java.util.TimeZone;
import java.util.regex.Pattern;
+import javax.xml.bind.annotation.XmlEnumValue;
+
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.RGB;
import org.eclipse.swt.widgets.Shell;
@@ -52,6 +54,7 @@ import com.raytheon.uf.viz.core.VizApp;
* Dec 12, 2012 1391 bgonzale Added methods to manage when shells become busy for user interaction.
* Dec 17, 2012 1435 mpduff Fix ThreadLocal implementation.
* Dec 18, 2012 1439 mpduff Change Regex to match invalid chars.
+ * Jan 04, 2013 1420 mpduff Change default priority to normal priority.
*
*
*
@@ -105,69 +108,16 @@ public class DataDeliveryGUIUtils {
/** Name Required Message */
public static final String NAME_REQUIRED_MESSAGE = "Name required.\nA Subscription Name must be entered.";
- /** Enumeration to use for Dataset Name operations */
- public static enum NameOperationItems {
- /** Operation Like */
- LIKE("Like");
-
- /** Dataset Name operation */
- private final String operation;
-
- private NameOperationItems(String operation) {
- this.operation = operation;
- }
-
- /**
- * Get dataset name operation.
- *
- * @return operation
- */
- public String getOperation() {
- return operation;
- }
-
- @Override
- public String toString() {
- return operation;
- }
- }
-
- /** Enumeration to use for Datatype operations */
- public static enum TypeOperationItems {
- /** Operation IN */
- IN("IN"),
- /** Operation NOT IN */
- NOT_IN("NOT IN");
-
- /** Datatype operation */
- private final String typeOperation;
-
- private TypeOperationItems(String typeOperation) {
- this.typeOperation = typeOperation;
- }
-
- /**
- * Get datatype operation.
- *
- * @return typeOperation
- */
- public String getOperation() {
- return typeOperation;
- }
-
- @Override
- public String toString() {
- return typeOperation;
- }
- }
-
/** Enumeration to use for subscription priorities */
public static enum SubscriptionPriority {
/** High Priority */
+ @XmlEnumValue("High")
HIGH("High", 1, new RGB(255, 0, 0)),
/** Default Priority */
- DEFAULT("Default", 2, new RGB(0, 255, 0)),
+ @XmlEnumValue("Normal")
+ NORMAL("Normal", 2, new RGB(0, 255, 0)),
/** Low Priority */
+ @XmlEnumValue("Low")
LOW("Low", 3, new RGB(6, 122, 255));
/** Priority Setting */
@@ -421,4 +371,17 @@ public class DataDeliveryGUIUtils {
}
});
}
+
+ /**
+ * Check the user's latency value.
+ *
+ * @return true if valid
+ */
+ public static boolean latencyValidChk(int latency, int maxLatency) {
+ if (latency > -1 && latency <= maxLatency) {
+ return true;
+ }
+
+ return false;
+ }
}
diff --git a/cave/com.raytheon.uf.viz.datadelivery/src/com/raytheon/uf/viz/datadelivery/utils/DataSetFrequency.java b/cave/com.raytheon.uf.viz.datadelivery/src/com/raytheon/uf/viz/datadelivery/utils/DataSetFrequency.java
new file mode 100644
index 0000000000..a024e1f3e1
--- /dev/null
+++ b/cave/com.raytheon.uf.viz.datadelivery/src/com/raytheon/uf/viz/datadelivery/utils/DataSetFrequency.java
@@ -0,0 +1,59 @@
+/**
+ * This software was developed and / or modified by Raytheon Company,
+ * pursuant to Contract DG133W-05-CQ-1067 with the US Government.
+ *
+ * U.S. EXPORT CONTROLLED TECHNICAL DATA
+ * This software product contains export-restricted data whose
+ * export/transfer/disclosure is restricted by U.S. law. Dissemination
+ * to non-U.S. persons whether in the United States or abroad requires
+ * an export license or other authorization.
+ *
+ * Contractor Name: Raytheon Company
+ * Contractor Address: 6825 Pine Street, Suite 340
+ * Mail Stop B8
+ * Omaha, NE 68106
+ * 402.291.0100
+ *
+ * See the AWIPS II Master Rights File ("Master Rights File.pdf") for
+ * further licensing information.
+ **/
+package com.raytheon.uf.viz.datadelivery.utils;
+
+import java.util.List;
+
+/**
+ * Data Set Frequency Enumeration.
+ *
+ *
+ *
+ * SOFTWARE HISTORY
+ *
+ * Date Ticket# Engineer Description
+ * ------------ ---------- ----------- --------------------------
+ * Jan 8, 2013 1420 mpduff Initial creation.
+ *
+ *
+ *
+ * @author mpduff
+ * @version 1.0
+ */
+
+public enum DataSetFrequency {
+ HOURLY, SIX_HOURLY;
+
+ private DataSetFrequency() {
+
+ }
+
+ public static DataSetFrequency fromCycleTimes(List cycleTimes) {
+ if (cycleTimes.size() > 1) {
+ if ((cycleTimes.get(1) - cycleTimes.get(0)) == 1) {
+ return DataSetFrequency.HOURLY;
+ } else {
+ return DataSetFrequency.SIX_HOURLY;
+ }
+ }
+
+ return DataSetFrequency.SIX_HOURLY;
+ }
+}
diff --git a/cave/com.raytheon.uf.viz.datadelivery/src/com/raytheon/uf/viz/datadelivery/utils/DataSizeUtil.java b/cave/com.raytheon.uf.viz.datadelivery/src/com/raytheon/uf/viz/datadelivery/utils/DataSizeUtil.java
new file mode 100644
index 0000000000..0767382c10
--- /dev/null
+++ b/cave/com.raytheon.uf.viz.datadelivery/src/com/raytheon/uf/viz/datadelivery/utils/DataSizeUtil.java
@@ -0,0 +1,194 @@
+package com.raytheon.uf.viz.datadelivery.utils;
+
+/**
+ * Enumeration for Data Size units and conversions.
+ *
+ *
+ *
+ * SOFTWARE HISTORY
+ *
+ * Date Ticket# Engineer Description
+ * ------------ ---------- ----------- --------------------------
+ * Jan 08, 2013 1420 mpduff Initial creation.
+ *
+ *
+ *
+ * @author mpduff
+ * @version 1.0
+ */
+public enum DataSizeUtil {
+ BYTE("Byte") {
+ @Override
+ public long toByte(long l) {
+ return l;
+ }
+
+ @Override
+ public long toKB(long l) {
+ return l / CONV;
+ }
+
+ @Override
+ public long toMB(long l) {
+ return l / (CONV * CONV);
+ }
+
+ @Override
+ public long toGB(long l) {
+ return l / (CONV * CONV * CONV);
+ }
+
+ @Override
+ public long convert(long l, DataSizeUtil ds) {
+ return ds.toByte(l);
+ }
+ },
+ KB("KB") {
+ @Override
+ public long toByte(long l) {
+ return l * CONV;
+ }
+
+ @Override
+ public long toKB(long l) {
+ return l;
+ }
+
+ @Override
+ public long toMB(long l) {
+ return l / CONV;
+ }
+
+ @Override
+ public long toGB(long l) {
+ return l / (CONV * CONV);
+ }
+
+ @Override
+ public long convert(long l, DataSizeUtil ds) {
+ return ds.toKB(l);
+ }
+ },
+ MB("MB") {
+ @Override
+ public long toByte(long l) {
+ return l * (CONV * CONV);
+ }
+
+ @Override
+ public long toKB(long l) {
+ return l * (CONV);
+ }
+
+ @Override
+ public long toMB(long l) {
+ return l;
+ }
+
+ @Override
+ public long toGB(long l) {
+ return l / CONV;
+ }
+
+ @Override
+ public long convert(long l, DataSizeUtil ds) {
+ return ds.toMB(l);
+ }
+ },
+ GB("GB") {
+ @Override
+ public long toByte(long l) {
+ return l * (CONV * CONV * CONV);
+ }
+
+ @Override
+ public long toKB(long l) {
+ return l * (CONV * CONV);
+ }
+
+ @Override
+ public long toMB(long l) {
+ return l * (CONV);
+ }
+
+ @Override
+ public long toGB(long l) {
+ return l;
+ }
+
+ @Override
+ public long convert(long l, DataSizeUtil ds) {
+ return ds.toGB(l);
+ }
+ };
+
+ private static final long CONV = 1024;
+
+ /** String unit */
+ private String unit;
+
+ private DataSizeUtil(String unit) {
+ this.unit = unit;
+ }
+
+ /**
+ * Get the unit's string representation.
+ *
+ * @return unit
+ */
+ public String getUnit() {
+ return unit;
+ }
+
+ /**
+ * Convert to Bytes.
+ *
+ * @param l
+ * value to convert
+ *
+ * @return converted value
+ */
+ public abstract long toByte(long l);
+
+ /**
+ * Convert to KB.
+ *
+ * @param l
+ * value to convert
+ *
+ * @return converted value
+ */
+ public abstract long toKB(long l);
+
+ /**
+ * Convert to MB.
+ *
+ * @param l
+ * value to convert
+ *
+ * @return converted value
+ */
+ public abstract long toMB(long l);
+
+ /**
+ * Convert to GB.
+ *
+ * @param l
+ * value to convert
+ *
+ * @return converted value
+ */
+ public abstract long toGB(long l);
+
+ /**
+ * Convert a data size value.
+ *
+ * @param l
+ * value to convert
+ * @param ds
+ * DataSizeUtil unit
+ *
+ * @return converted value
+ */
+ public abstract long convert(long l, DataSizeUtil ds);
+}
\ No newline at end of file
diff --git a/cave/com.raytheon.uf.viz.datadelivery/src/com/raytheon/uf/viz/datadelivery/utils/NameOperationItems.java b/cave/com.raytheon.uf.viz.datadelivery/src/com/raytheon/uf/viz/datadelivery/utils/NameOperationItems.java
new file mode 100644
index 0000000000..1ae17ba847
--- /dev/null
+++ b/cave/com.raytheon.uf.viz.datadelivery/src/com/raytheon/uf/viz/datadelivery/utils/NameOperationItems.java
@@ -0,0 +1,45 @@
+package com.raytheon.uf.viz.datadelivery.utils;
+
+import javax.xml.bind.annotation.XmlEnum;
+import javax.xml.bind.annotation.XmlEnumValue;
+import javax.xml.bind.annotation.XmlType;
+
+import com.raytheon.uf.viz.datadelivery.system.Operator;
+
+/** Enumeration to use for Dataset Name operations */
+@XmlType(name = "nameOperationItems")
+@XmlEnum
+public enum NameOperationItems implements Operator {
+ /** Operation Like */
+ @XmlEnumValue("Like")
+ LIKE("Like");
+
+ /** Dataset Name operation */
+ private final String operation;
+
+ private NameOperationItems(String operation) {
+ this.operation = operation;
+ }
+
+ /**
+ * Get dataset name operation.
+ *
+ * @return operation
+ */
+ public String getOperation() {
+ return operation;
+ }
+
+ @Override
+ public String toString() {
+ return operation;
+ }
+
+ @Override
+ public boolean evaluate(String operandOne, String operandTwo) {
+ if (operandOne.toLowerCase().contains(operandTwo.toLowerCase())) {
+ return true;
+ }
+ return false;
+ }
+}
\ No newline at end of file
diff --git a/cave/com.raytheon.uf.viz.datadelivery/src/com/raytheon/uf/viz/datadelivery/utils/TypeOperationItems.java b/cave/com.raytheon.uf.viz.datadelivery/src/com/raytheon/uf/viz/datadelivery/utils/TypeOperationItems.java
new file mode 100644
index 0000000000..22d5e5fae7
--- /dev/null
+++ b/cave/com.raytheon.uf.viz.datadelivery/src/com/raytheon/uf/viz/datadelivery/utils/TypeOperationItems.java
@@ -0,0 +1,55 @@
+package com.raytheon.uf.viz.datadelivery.utils;
+
+import javax.xml.bind.annotation.XmlEnum;
+import javax.xml.bind.annotation.XmlEnumValue;
+import javax.xml.bind.annotation.XmlType;
+
+import com.raytheon.uf.viz.datadelivery.system.Operator;
+
+/** Enumeration to use for Datatype operations */
+@XmlType(name = "typeOperationItems")
+@XmlEnum
+public enum TypeOperationItems implements Operator {
+ /** Operation IN */
+ @XmlEnumValue("IN")
+ IN("IN"),
+ /** Operation NOT IN */
+ @XmlEnumValue("NOT IN")
+ NOT_IN("NOT IN");
+
+ /** Datatype operation */
+ private final String typeOperation;
+
+ private TypeOperationItems(String typeOperation) {
+ this.typeOperation = typeOperation;
+ }
+
+ /**
+ * Get datatype operation.
+ *
+ * @return typeOperation
+ */
+ public String getOperation() {
+ return typeOperation;
+ }
+
+ @Override
+ public String toString() {
+ return typeOperation;
+ }
+
+ @Override
+ public boolean evaluate(String operandOne, String operandTwo) {
+ if (TypeOperationItems.IN == this) {
+ if (operandOne.toLowerCase().contains(operandTwo.toLowerCase())) {
+ return true;
+ }
+ } else if (TypeOperationItems.NOT_IN == this) {
+ if (!operandOne.contains(operandTwo)) {
+ return true;
+ }
+ }
+
+ return false;
+ }
+}
\ No newline at end of file
diff --git a/edexOsgi/com.raytheon.uf.common.datadelivery.bandwidth/utility/common_static/base/datadelivery/systemManagement/rules/latencyRules.xml b/edexOsgi/com.raytheon.uf.common.datadelivery.bandwidth/utility/common_static/base/datadelivery/systemManagement/rules/latencyRules.xml
new file mode 100644
index 0000000000..ab09f88dfb
--- /dev/null
+++ b/edexOsgi/com.raytheon.uf.common.datadelivery.bandwidth/utility/common_static/base/datadelivery/systemManagement/rules/latencyRules.xml
@@ -0,0 +1,19 @@
+
+
+
+ Dataset Frequency
+ Hourly-Products
+ <=
+ Hrs
+ 1
+ 40
+
+
+ Dataset Frequency
+ MultiHour-Products
+ >
+ Hrs
+ 1
+ 115
+
+
diff --git a/tests/unit/com/raytheon/uf/viz/datadelivery/subscription/presenter/CreateSubscriptionPresenterTest.java b/tests/unit/com/raytheon/uf/viz/datadelivery/subscription/presenter/CreateSubscriptionPresenterTest.java
index 529e1e2ac6..8b155b539a 100644
--- a/tests/unit/com/raytheon/uf/viz/datadelivery/subscription/presenter/CreateSubscriptionPresenterTest.java
+++ b/tests/unit/com/raytheon/uf/viz/datadelivery/subscription/presenter/CreateSubscriptionPresenterTest.java
@@ -348,4 +348,15 @@ public class CreateSubscriptionPresenterTest {
verify(view).setActiveEndDate(
argThat(yyyyMmDdMatches(expectedEndCalendar.getTime())));
}
+
+ @Test
+ public void verifySubscriptionSetToView() {
+ verify(view).setSubscription(presenter.getSubscription());
+ }
+
+ @Test
+ public void verifyCycleTimesSetToView() {
+ verify(view).setCycleTimes(presenter.cycleTimes);
+ }
+
}
diff --git a/tests/unit/com/raytheon/uf/viz/datadelivery/subscription/xml/RuleXMLTest.java b/tests/unit/com/raytheon/uf/viz/datadelivery/subscription/xml/RuleXMLTest.java
new file mode 100644
index 0000000000..125cda3238
--- /dev/null
+++ b/tests/unit/com/raytheon/uf/viz/datadelivery/subscription/xml/RuleXMLTest.java
@@ -0,0 +1,182 @@
+/**
+ * This software was developed and / or modified by Raytheon Company,
+ * pursuant to Contract DG133W-05-CQ-1067 with the US Government.
+ *
+ * U.S. EXPORT CONTROLLED TECHNICAL DATA
+ * This software product contains export-restricted data whose
+ * export/transfer/disclosure is restricted by U.S. law. Dissemination
+ * to non-U.S. persons whether in the United States or abroad requires
+ * an export license or other authorization.
+ *
+ * Contractor Name: Raytheon Company
+ * Contractor Address: 6825 Pine Street, Suite 340
+ * Mail Stop B8
+ * Omaha, NE 68106
+ * 402.291.0100
+ *
+ * See the AWIPS II Master Rights File ("Master Rights File.pdf") for
+ * further licensing information.
+ **/
+package com.raytheon.uf.viz.datadelivery.subscription.xml;
+
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+import java.util.Set;
+import java.util.TreeSet;
+
+import org.junit.Before;
+import org.junit.Test;
+
+import com.raytheon.uf.common.datadelivery.registry.DataType;
+import com.raytheon.uf.common.datadelivery.registry.Subscription;
+import com.raytheon.uf.viz.datadelivery.system.CreateEditRuleDlg.FreqUnitOptions;
+import com.raytheon.uf.viz.datadelivery.system.OperatorTypes;
+import com.raytheon.uf.viz.datadelivery.system.OpsNetFieldNames;
+import com.raytheon.uf.viz.datadelivery.utils.DataSizeUtil;
+import com.raytheon.uf.viz.datadelivery.utils.NameOperationItems;
+import com.raytheon.uf.viz.datadelivery.utils.TypeOperationItems;
+
+/**
+ * Test {@link RuleXML}
+ *
+ *
+ *
+ * SOFTWARE HISTORY
+ *
+ * Date Ticket# Engineer Description
+ * ------------ ---------- ----------- --------------------------
+ * Jan 3, 2013 1420 mpduff Initial creation.
+ *
+ *
+ *
+ * @author mpduff
+ * @version 1.0
+ */
+
+public class RuleXMLTest {
+ private Subscription sub;
+
+ @Before
+ public void setUp() {
+ sub = new Subscription();
+ sub.setDataSetName("GFS");
+ sub.setDataSetType(DataType.GRID);
+ sub.setDataSetSize(100);
+ }
+
+ @Test
+ public void testMatchesDataSetNameRule() {
+ LatencyRuleXML rule = new LatencyRuleXML();
+ rule.setRuleValue("GFS");
+ rule.setRuleField(OpsNetFieldNames.NAME.getFieldName());
+ rule.setRuleOperator(NameOperationItems.LIKE.getOperation());
+
+ assertTrue("Matches Data Set Name failed", rule.matches(sub, null));
+ }
+
+ @Test
+ public void testMatchesDataSetNameRuleFails() {
+ LatencyRuleXML rule = new LatencyRuleXML();
+ rule.setRuleValue("GFS2");
+ rule.setRuleField(OpsNetFieldNames.NAME.getFieldName());
+ rule.setRuleOperator(NameOperationItems.LIKE.getOperation());
+
+ assertFalse("Matches Data Set Name false positive",
+ rule.matches(sub, null));
+ }
+
+ @Test
+ public void testMatchesDataSetTypeInRule() {
+ LatencyRuleXML rule = new LatencyRuleXML();
+ rule.setRuleValue("GRID,OBS");
+ rule.setRuleField(OpsNetFieldNames.TYPE.getFieldName());
+ rule.setRuleOperator(TypeOperationItems.IN.getOperation());
+
+ assertTrue("Matches Data Type In Failed", rule.matches(sub, null));
+ }
+
+ @Test
+ public void testMatchesDataSetTypeNotInRule() {
+ LatencyRuleXML rule = new LatencyRuleXML();
+ rule.setRuleValue("FAKE");
+ rule.setRuleField(OpsNetFieldNames.TYPE.getFieldName());
+ rule.setRuleOperator(TypeOperationItems.NOT_IN.getOperation());
+
+ assertTrue("Matches Data Type Not In Failed", rule.matches(sub, null));
+ }
+
+ @Test
+ public void testMatchesSizeEqualsInKB() {
+ LatencyRuleXML rule = new LatencyRuleXML();
+ rule.setRuleValue(String.valueOf(100));
+ rule.setRuleField(OpsNetFieldNames.SIZE.getFieldName());
+ rule.setRuleOperator(OperatorTypes.EQUAL.getOperation());
+ rule.setRuleUnit(DataSizeUtil.KB.getUnit());
+
+ assertTrue("Matches Dataset Size Equals Failed",
+ rule.matches(sub, null));
+ }
+
+ @Test
+ public void testMatchesSizeEqualsInMB() {
+ System.out.println("Here 1");
+ LatencyRuleXML rule = new LatencyRuleXML();
+ rule.setRuleValue(String.valueOf(100));
+ rule.setRuleField(OpsNetFieldNames.SIZE.getFieldName());
+ rule.setRuleOperator(OperatorTypes.EQUAL.getOperation());
+ rule.setRuleUnit(DataSizeUtil.MB.getUnit());
+
+ sub.setDataSetSize(1024 * 100);
+ assertTrue("Matches Dataset Size Equals Failed",
+ rule.matches(sub, null));
+ }
+
+ @Test
+ public void testMatchesSizeEqualsInGB() {
+ System.out.println("Here 2");
+ LatencyRuleXML rule = new LatencyRuleXML();
+ rule.setRuleValue(String.valueOf(100));
+ rule.setRuleField(OpsNetFieldNames.SIZE.getFieldName());
+ rule.setRuleOperator(OperatorTypes.EQUAL.getOperation());
+ rule.setRuleUnit(DataSizeUtil.GB.getUnit());
+
+ sub.setDataSetSize(100 * 1024 * 1024);
+ assertTrue("Matches Dataset Size Equals Failed",
+ rule.matches(sub, null));
+ }
+
+ // The other operator types are tested in OperatorTypesTest.java
+
+ @Test
+ public void testMatchesFrequencyMinutes() {
+ LatencyRuleXML rule = new LatencyRuleXML();
+ rule.setRuleValue(String.valueOf(60));
+ rule.setRuleField(OpsNetFieldNames.FREQUENCY.getFieldName());
+ rule.setRuleOperator(OperatorTypes.EQUAL.getOperation());
+ rule.setRuleUnit(FreqUnitOptions.MIN.getOperation());
+
+ Set cycles = new TreeSet();
+ cycles.add(0);
+ cycles.add(1);
+
+ assertTrue("Matches Dataset Frequency Minutes Equals Failed",
+ rule.matches(sub, cycles));
+ }
+
+ @Test
+ public void testMatchesFrequencyHours() {
+ LatencyRuleXML rule = new LatencyRuleXML();
+ rule.setRuleValue(String.valueOf(1));
+ rule.setRuleField("Dataset Frequency");
+ rule.setRuleOperator(OperatorTypes.EQUAL.getOperation());
+ rule.setRuleUnit(FreqUnitOptions.HOURS.getOperation());
+
+ Set cycles = new TreeSet();
+ cycles.add(0);
+ cycles.add(1);
+
+ assertTrue("Matches Dataset Frequency Minutes Equals Failed",
+ rule.matches(sub, cycles));
+ }
+}
diff --git a/tests/unit/com/raytheon/uf/viz/datadelivery/system/OperatorTypesTest.java b/tests/unit/com/raytheon/uf/viz/datadelivery/system/OperatorTypesTest.java
new file mode 100644
index 0000000000..3b26d3b7f7
--- /dev/null
+++ b/tests/unit/com/raytheon/uf/viz/datadelivery/system/OperatorTypesTest.java
@@ -0,0 +1,134 @@
+package com.raytheon.uf.viz.datadelivery.system;
+
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+import org.junit.Test;
+
+/**
+ * Test {@link OperatorTypes}.
+ *
+ *
+ *
+ * SOFTWARE HISTORY
+ *
+ * Date Ticket# Engineer Description
+ * ------------ ---------- ----------- --------------------------
+ * 01/04/2013 1420 mpduff Initial Creation.
+ *
+ *
+ * @author mpduff
+ * @version 1.0
+ */
+public class OperatorTypesTest {
+
+ @Test
+ public void testGreaterThanWorks() {
+ OperatorTypes operatorType = OperatorTypes.GREATER_THAN;
+ assertTrue("operand1 not greater than operand2",
+ operatorType.evaluate(10l, 5l));
+ }
+
+ @Test
+ public void testGreaterThanFailsWhenValuesEqual() {
+ OperatorTypes operatorType = OperatorTypes.GREATER_THAN;
+ assertFalse("operand1 not greater than operand2",
+ operatorType.evaluate(10l, 10l));
+ }
+
+ @Test
+ public void testGreaterThanFailsWhenValuesNotGreaterThan() {
+ OperatorTypes operatorType = OperatorTypes.GREATER_THAN;
+ assertFalse("operand1 not greater than operand2",
+ operatorType.evaluate(5l, 10l));
+ }
+
+ @Test
+ public void testGreaterThanEqualsWorks() {
+ OperatorTypes operatorType = OperatorTypes.GREATER_THAN_EQUAL;
+ assertTrue("operand1 not greater than operand2",
+ operatorType.evaluate(10l, 5l));
+ }
+
+ @Test
+ public void testGreaterThanEqualsWorksWhenValuesEqual() {
+ OperatorTypes operatorType = OperatorTypes.GREATER_THAN_EQUAL;
+ assertTrue("operand1 not greater than or equal to operand2",
+ operatorType.evaluate(10l, 10l));
+ }
+
+ @Test
+ public void testGreaterThanEqualsFailsWhenValuesNotGreaterThan() {
+ OperatorTypes operatorType = OperatorTypes.GREATER_THAN_EQUAL;
+ assertFalse("operand1 not greater than operand2",
+ operatorType.evaluate(5l, 10l));
+ }
+
+ // //////////////////////
+
+ @Test
+ public void testLessThanWorks() {
+ OperatorTypes operatorType = OperatorTypes.LESS_THAN;
+ assertTrue("operand1 not less than operand2",
+ operatorType.evaluate(10l, 20l));
+ }
+
+ @Test
+ public void testLessThanFailsWhenValuesEqual() {
+ OperatorTypes operatorType = OperatorTypes.LESS_THAN;
+ assertFalse("operand1 not less than operand2",
+ operatorType.evaluate(10l, 10l));
+ }
+
+ @Test
+ public void testLessThanFailsWhenValuesNotLessThan() {
+ OperatorTypes operatorType = OperatorTypes.LESS_THAN;
+ assertFalse("operand1 not less than operand2",
+ operatorType.evaluate(20l, 10l));
+ }
+
+ @Test
+ public void testLessThanEqualsWorks() {
+ OperatorTypes operatorType = OperatorTypes.LESS_THAN_EQUAL;
+ assertTrue("operand1 not less than operand2",
+ operatorType.evaluate(10l, 20l));
+ }
+
+ @Test
+ public void testLessThanEqualsWorksWhenValuesEqual() {
+ OperatorTypes operatorType = OperatorTypes.LESS_THAN_EQUAL;
+ assertTrue("operand1 not less than or equal to operand2",
+ operatorType.evaluate(10l, 10l));
+ }
+
+ @Test
+ public void testLessThanEqualsFailsWhenValuesNotLessThan() {
+ OperatorTypes operatorType = OperatorTypes.LESS_THAN_EQUAL;
+ assertFalse("operand1 not less than operand2",
+ operatorType.evaluate(20l, 10l));
+ }
+
+ @Test
+ public void testEqualsWorks() {
+ OperatorTypes ot = OperatorTypes.EQUAL;
+ assertTrue("operand1 not equal to operand2", ot.evaluate(1l, 1l));
+ }
+
+ @Test
+ public void testEqualsFailsWhenNotEqual() {
+ OperatorTypes ot = OperatorTypes.EQUAL;
+ assertFalse("operand1 not equal to operand2", ot.evaluate(1l, 12l));
+ }
+
+ @Test
+ public void testNotEqualsWorks() {
+ OperatorTypes ot = OperatorTypes.NOT_EQUAL;
+ assertTrue("operand1 equal to operand2", ot.evaluate(1l, 15l));
+ }
+
+ @Test
+ public void testNotEqualsFailsWhenEqual() {
+ OperatorTypes ot = OperatorTypes.NOT_EQUAL;
+ assertFalse("operand1 equal to operand2", ot.evaluate(1l, 1l));
+ }
+}
diff --git a/tests/unit/com/raytheon/uf/viz/datadelivery/utils/DataSizeUtilTest.java b/tests/unit/com/raytheon/uf/viz/datadelivery/utils/DataSizeUtilTest.java
new file mode 100644
index 0000000000..36efe7cd08
--- /dev/null
+++ b/tests/unit/com/raytheon/uf/viz/datadelivery/utils/DataSizeUtilTest.java
@@ -0,0 +1,308 @@
+/**
+ * This software was developed and / or modified by Raytheon Company,
+ * pursuant to Contract DG133W-05-CQ-1067 with the US Government.
+ *
+ * U.S. EXPORT CONTROLLED TECHNICAL DATA
+ * This software product contains export-restricted data whose
+ * export/transfer/disclosure is restricted by U.S. law. Dissemination
+ * to non-U.S. persons whether in the United States or abroad requires
+ * an export license or other authorization.
+ *
+ * Contractor Name: Raytheon Company
+ * Contractor Address: 6825 Pine Street, Suite 340
+ * Mail Stop B8
+ * Omaha, NE 68106
+ * 402.291.0100
+ *
+ * See the AWIPS II Master Rights File ("Master Rights File.pdf") for
+ * further licensing information.
+ **/
+package com.raytheon.uf.viz.datadelivery.utils;
+
+import static org.hamcrest.CoreMatchers.equalTo;
+import static org.hamcrest.CoreMatchers.is;
+import static org.junit.Assert.assertThat;
+
+import org.junit.Test;
+
+/**
+ * Test {@link DataSizeUtil}
+ *
+ *
+ *
+ * SOFTWARE HISTORY
+ *
+ * Date Ticket# Engineer Description
+ * ------------ ---------- ----------- --------------------------
+ * Jan 8, 2013 1420 mpduff Initial creation
+ *
+ *
+ *
+ * @author mpduff
+ * @version 1.0
+ */
+
+public class DataSizeUtilTest {
+ private static long CONV = 1024;
+
+ @Test
+ public void testConvertOneKbInBytesToBytes() {
+ long result = DataSizeUtil.BYTE.toByte(1024l);
+
+ assertThat(result, is(equalTo(1024l)));
+ }
+
+ @Test
+ public void testConvertOneKbInBytesToKB() {
+ long bytes = 1024;
+ long expected = 1;
+ long result = DataSizeUtil.BYTE.toKB(bytes);
+
+ assertThat(result, is(equalTo(expected)));
+ }
+
+ @Test
+ public void testConvertOneMbInBytesToMB() {
+ long bytes = CONV * CONV * 2;
+ long expected = 2;
+ long result = DataSizeUtil.BYTE.toMB(bytes);
+
+ assertThat(result, is(equalTo(expected)));
+ }
+
+ @Test
+ public void testConvertTenBytesToMB() {
+ long bytes = 10;
+ long expected = 0;
+ long result = DataSizeUtil.BYTE.toMB(bytes);
+
+ assertThat(result, is(equalTo(expected)));
+ }
+
+ @Test
+ public void testConvertTwoGbInBytesToGB() {
+ long bytes = CONV * CONV * CONV * 2;
+ long expected = 2;
+ long result = DataSizeUtil.BYTE.toGB(bytes);
+
+ assertThat(result, is(equalTo(expected)));
+ }
+
+ @Test
+ public void testConvertTenBytesToGB() {
+ long bytes = 10;
+ long expected = 0;
+ long result = DataSizeUtil.BYTE.toGB(bytes);
+
+ assertThat(result, is(equalTo(expected)));
+ }
+
+ @Test
+ public void testConvertMethodOneKbToByte() {
+ long kb = 1;
+ long expected = 1024;
+ long result = DataSizeUtil.BYTE.convert(kb, DataSizeUtil.KB);
+
+ assertThat(result, is(equalTo(expected)));
+ }
+
+ // //////////////////////////////////////////////////////////
+
+ @Test
+ public void testConvertOneKBToBytes() {
+ long kb = 1;
+ long expected = 1024;
+ long result = DataSizeUtil.KB.toByte(kb);
+
+ assertThat(result, is(equalTo(expected)));
+ }
+
+ @Test
+ public void testConvertOneKbToKB() {
+ long kb = 1;
+ long expected = 1;
+ long result = DataSizeUtil.KB.toKB(kb);
+
+ assertThat(result, is(equalTo(expected)));
+ }
+
+ @Test
+ public void testConvertOneKbToMB() {
+ long kb = 1;
+ long expected = 0;
+ long result = DataSizeUtil.KB.toMB(kb);
+
+ assertThat(result, is(equalTo(expected)));
+ }
+
+ @Test
+ public void testConvertTwoMbInKbToMB() {
+ long kb = CONV * 2;
+ long expected = 2;
+ long result = DataSizeUtil.KB.toMB(kb);
+
+ assertThat(result, is(equalTo(expected)));
+ }
+
+ @Test
+ public void testConvertOneKbToGB() {
+ long kb = 1;
+ long expected = 0;
+ long result = DataSizeUtil.KB.toGB(kb);
+
+ assertThat(result, is(equalTo(expected)));
+ }
+
+ @Test
+ public void testConvertTwoGbInKbToGB() {
+ long kb = CONV * CONV * 2;
+ long expected = 2;
+ long result = DataSizeUtil.KB.toGB(kb);
+
+ assertThat(result, is(equalTo(expected)));
+ }
+
+ @Test
+ public void testConvertMethodOneMbToKB() {
+ long mb = 1;
+ long expected = 1024;
+ long result = DataSizeUtil.KB.convert(mb, DataSizeUtil.MB);
+
+ assertThat(result, is(equalTo(expected)));
+ }
+
+ // ///////////////////////
+
+ @Test
+ public void testConvertOneMbToBytes() {
+ long mb = 1;
+ long expected = 1024 * 1024;
+ long result = DataSizeUtil.MB.toByte(mb);
+
+ assertThat(result, is(equalTo(expected)));
+ }
+
+ @Test
+ public void testConvertOneMbToKB() {
+ long mb = 1;
+ long expected = 1024;
+ long result = DataSizeUtil.MB.toKB(mb);
+
+ assertThat(result, is(equalTo(expected)));
+ }
+
+ @Test
+ public void testConvertTwoMbToMB() {
+ long mb = 2;
+ long expected = 2;
+ long result = DataSizeUtil.MB.toMB(mb);
+
+ assertThat(result, is(equalTo(expected)));
+ }
+
+ @Test
+ public void testConvertTwoMbToGB() {
+ long mb = 2;
+ long expected = 0;
+ long result = DataSizeUtil.MB.toGB(mb);
+
+ assertThat(result, is(equalTo(expected)));
+ }
+
+ @Test
+ public void testConvertTwoGbInMbToGB() {
+ long mb = 1024 * 2;
+ long expected = 2;
+ long result = DataSizeUtil.MB.toGB(mb);
+
+ assertThat(result, is(equalTo(expected)));
+ }
+
+ @Test
+ public void testConvertMethodOneGbToMB() {
+ long gb = 1;
+ long expected = 1024;
+ long result = DataSizeUtil.MB.convert(gb, DataSizeUtil.GB);
+
+ assertThat(result, is(equalTo(expected)));
+ }
+
+ // ///////////////////////
+
+ @Test
+ public void testConvertOneGbToBytes() {
+ long gb = 1;
+ long expected = 1024 * 1024 * 1024;
+ long result = DataSizeUtil.GB.toByte(gb);
+
+ assertThat(result, is(equalTo(expected)));
+ }
+
+ @Test
+ public void testConvertOneGbToKB() {
+ long gb = 1;
+ long expected = 1024 * 1024;
+ long result = DataSizeUtil.GB.toKB(gb);
+
+ assertThat(result, is(equalTo(expected)));
+ }
+
+ @Test
+ public void testConvertOneGbToMB() {
+ long gb = 1;
+ long expected = 1024;
+ long result = DataSizeUtil.GB.toMB(gb);
+
+ assertThat(result, is(equalTo(expected)));
+ }
+
+ @Test
+ public void testConvertOneGbToGB() {
+ long gb = 1;
+ long expected = 1;
+ long result = DataSizeUtil.GB.toGB(gb);
+
+ assertThat(result, is(equalTo(expected)));
+ }
+
+ @Test
+ public void testConvertMethodTwoGbToGB() {
+ long gb = 2;
+ long expected = 2;
+ long result = DataSizeUtil.GB.convert(gb, DataSizeUtil.GB);
+
+ assertThat(result, is(equalTo(expected)));
+ }
+
+ @Test
+ public void testGetUnitByte() {
+ String expected = "Byte";
+ String result = DataSizeUtil.BYTE.getUnit();
+
+ assertThat(result, is(equalTo(expected)));
+ }
+
+ @Test
+ public void testGetUnitKB() {
+ String expected = "KB";
+ String result = DataSizeUtil.KB.getUnit();
+
+ assertThat(result, is(equalTo(expected)));
+ }
+
+ @Test
+ public void testGetUnitMB() {
+ String expected = "MB";
+ String result = DataSizeUtil.MB.getUnit();
+
+ assertThat(result, is(equalTo(expected)));
+ }
+
+ @Test
+ public void testGetUnitGB() {
+ String expected = "GB";
+ String result = DataSizeUtil.GB.getUnit();
+
+ assertThat(result, is(equalTo(expected)));
+ }
+}