Issue #1420 - Rules Peer review comments

Former-commit-id: 9f6756325c5788dd1b98d8f24ab3437993da7dcd
This commit is contained in:
Mike Duff 2013-01-09 08:38:47 -06:00
parent a836aee481
commit 6e0367cdc7
38 changed files with 2959 additions and 1163 deletions

View file

@ -50,6 +50,7 @@ import com.raytheon.uf.viz.datadelivery.utils.DataDeliveryGUIUtils.SubscriptionP
* Nov 28, 2012 1269 lvenable Initial creation. * Nov 28, 2012 1269 lvenable Initial creation.
* Dec 13, 2012 1269 lvenable Fixes and updates. * Dec 13, 2012 1269 lvenable Fixes and updates.
* Jan 07, 2013 1451 djohnson Use TimeUtil.newGmtCalendar(). * Jan 07, 2013 1451 djohnson Use TimeUtil.newGmtCalendar().
* Jan 04, 2013 1420 mpduff Change default priority to normal priority.
* *
* </pre> * </pre>
* *
@ -170,11 +171,11 @@ public class GraphImage extends AbstractCanvasImage {
for (String subName : subscriptionList) { for (String subName : subscriptionList) {
if (imageMgr.isColorByPriority()) { if (imageMgr.isColorByPriority()) {
if (graphData.getPriority(subName) == SubscriptionPriority.DEFAULT if (graphData.getPriority(subName) == SubscriptionPriority.NORMAL
.ordinal()) { .ordinal()) {
c = new Color( c = new Color(
display, display,
imageMgr.getPriorityColor(SubscriptionPriority.DEFAULT)); imageMgr.getPriorityColor(SubscriptionPriority.NORMAL));
gc.setBackground(c); gc.setBackground(c);
} else if (graphData.getPriority(subName) == SubscriptionPriority.HIGH } else if (graphData.getPriority(subName) == SubscriptionPriority.HIGH
.ordinal()) { .ordinal()) {

View file

@ -26,9 +26,13 @@ import org.eclipse.swt.widgets.Combo;
import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Group; import org.eclipse.swt.widgets.Group;
import org.eclipse.swt.widgets.Label; 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 * This is the priority group information composite. This class is intended to
* to be extended so common classes can be created and shared. * be extended so common classes can be created and shared.
* *
* <pre> * <pre>
* *
@ -38,6 +42,7 @@ import org.eclipse.swt.widgets.Label;
* ------------ ---------- ----------- -------------------------- * ------------ ---------- ----------- --------------------------
* Jun 27, 2012 702 jpiatt Initial creation. * Jun 27, 2012 702 jpiatt Initial creation.
* Aug 21, 2012 712 mpduff Default to Default, and allow for setting the combo box. * Aug 21, 2012 712 mpduff Default to Default, and allow for setting the combo box.
* Jan 04, 2013 1420 mpduff Add latency.
* *
* </pre> * </pre>
* *
@ -47,15 +52,28 @@ import org.eclipse.swt.widgets.Label;
public class PriorityComp extends Composite { public class PriorityComp extends Composite {
/** Group Name combo box. */ /** Group Name combo box. */
private Combo priorityCombo; private Combo priorityCombo;
/** Latency Text field */
private Text latencyText;
/** The latency value */
private final int latency;
/** The priority value */
private final int priority;
/** /**
* Constructor. * Constructor.
* *
* @param parent * @param parent
* Parent composite. * Parent composite.
* @param latency
* @param priority
*/ */
public PriorityComp(Composite parent) { public PriorityComp(Composite parent, int latency, int priority) {
super(parent, SWT.NONE); super(parent, SWT.NONE);
this.latency = latency;
this.priority = priority - 1;
init(); init();
} }
@ -77,36 +95,56 @@ public class PriorityComp extends Composite {
createSubscriptionPriorityGroup(); createSubscriptionPriorityGroup();
} }
/** /**
* Create the Subscriptions Priority Group * Create the Subscriptions Priority Group
*/ */
private void createSubscriptionPriorityGroup() { private void createSubscriptionPriorityGroup() {
GridData gd = new GridData(SWT.FILL, SWT.DEFAULT, true, false); GridData gd = new GridData(SWT.FILL, SWT.DEFAULT, true, false);
GridLayout gl = new GridLayout(1, false); GridLayout gl = new GridLayout(1, false);
Group subPriorityGroup = new Group(this, SWT.NONE); Group subPriorityGroup = new Group(this, SWT.NONE);
subPriorityGroup.setLayout(gl); subPriorityGroup.setLayout(gl);
subPriorityGroup.setLayoutData(gd); subPriorityGroup.setLayoutData(gd);
subPriorityGroup.setText(" Subscription Priority "); subPriorityGroup.setText(" Priority/Latency ");
Composite priorityComp = new Composite(subPriorityGroup, SWT.NONE); Composite priorityComp = new Composite(subPriorityGroup, SWT.NONE);
gd = new GridData(SWT.FILL, SWT.DEFAULT, true, false); gd = new GridData(SWT.FILL, SWT.DEFAULT, true, false);
gl = new GridLayout(2, false); gl = new GridLayout(2, false);
priorityComp.setLayoutData(gd); priorityComp.setLayoutData(gd);
priorityComp.setLayout(gl); priorityComp.setLayout(gl);
Label priority = new Label(priorityComp, SWT.NONE); Label priorityLbl = new Label(priorityComp, SWT.NONE);
priority.setText(" Priority: "); 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(285, SWT.DEFAULT);
gd = new GridData(SWT.FILL, SWT.DEFAULT, true, false);
priorityCombo = new Combo(priorityComp, SWT.READ_ONLY); priorityCombo = new Combo(priorityComp, SWT.READ_ONLY);
priorityCombo.setItems(new String[] { "High", "Default", "Low" }); priorityCombo.setItems(priorities);
priorityCombo.select(1); // Default to the Default setting priorityCombo.select(this.priority);
priorityCombo.setLayoutData(gd); priorityCombo.setLayoutData(gd);
priorityCombo.setToolTipText("Select a priority"); 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); 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;
}
} }

View file

@ -22,6 +22,7 @@ package com.raytheon.uf.viz.datadelivery.subscription;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Date; import java.util.Date;
import java.util.List; import java.util.List;
import java.util.Set;
import org.eclipse.core.runtime.Status; import org.eclipse.core.runtime.Status;
import org.eclipse.swt.SWT; 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.Shell;
import org.eclipse.swt.widgets.Text; 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.common.datadelivery.registry.ebxml.DataSetQuery;
import com.raytheon.uf.viz.datadelivery.common.ui.ActivePeriodComp; import com.raytheon.uf.viz.datadelivery.common.ui.ActivePeriodComp;
import com.raytheon.uf.viz.datadelivery.common.ui.DeliveryOptionsComp; 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.GroupSelectComp;
import com.raytheon.uf.viz.datadelivery.common.ui.PriorityComp; import com.raytheon.uf.viz.datadelivery.common.ui.PriorityComp;
import com.raytheon.uf.viz.datadelivery.subscription.view.ICreateSubscriptionDlgView; 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.uf.viz.datadelivery.utils.DataDeliveryUtils;
import com.raytheon.viz.ui.dialogs.CaveSWTDialog; import com.raytheon.viz.ui.dialogs.CaveSWTDialog;
import com.raytheon.viz.ui.presenter.components.ButtonConf; 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. * Nov 20, 2012 1286 djohnson Implement IDisplay to display yes/no prompt.
* Dec 13, 2012 1391 bgonzale Added cancel/ok selection status. * Dec 13, 2012 1391 bgonzale Added cancel/ok selection status.
* Jan 02, 2013 1441 djohnson Add isGroupSelected(). * Jan 02, 2013 1441 djohnson Add isGroupSelected().
* Jan 04, 2013 1420 mpduff Add latency.
* *
* </pre> * </pre>
* *
* @author mpduff * @author mpduff
* @version 1.0 * @version 1.0
*/ */
public class CreateSubscriptionDlg extends CaveSWTDialog implements public class CreateSubscriptionDlg extends CaveSWTDialog implements
ICreateSubscriptionDlgView { ICreateSubscriptionDlgView {
@ -139,9 +142,15 @@ public class CreateSubscriptionDlg extends CaveSWTDialog implements
/** Did the user Status.OK or SWT.CANCEL subscription creation */ /** Did the user Status.OK or SWT.CANCEL subscription creation */
private int status = SWT.NONE; private int status = SWT.NONE;
/** The subscription object */
private Subscription subscription;
/** Available cycle times */
private Set<Integer> cycleTimes;
/** /**
* Constructor. * Constructor.
* *
* @param parent * @param parent
* The parent shell * The parent shell
* @param create * @param create
@ -161,7 +170,7 @@ public class CreateSubscriptionDlg extends CaveSWTDialog implements
/* /*
* (non-Javadoc) * (non-Javadoc)
* *
* @see * @see
* com.raytheon.viz.ui.dialogs.CaveSWTDialogBase#initializeComponents(org * com.raytheon.viz.ui.dialogs.CaveSWTDialogBase#initializeComponents(org
* .eclipse.swt.widgets.Shell) * .eclipse.swt.widgets.Shell)
@ -182,7 +191,12 @@ public class CreateSubscriptionDlg extends CaveSWTDialog implements
durComp = new DurationComp(mainComp); durComp = new DurationComp(mainComp);
activePeriodComp = new ActivePeriodComp(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(); this.createCycleGroup();
if (create == false) { if (create == false) {
@ -194,7 +208,7 @@ public class CreateSubscriptionDlg extends CaveSWTDialog implements
/* /*
* (non-Javadoc) * (non-Javadoc)
* *
* @see com.raytheon.viz.ui.dialogs.CaveSWTDialogBase#constructShellLayout() * @see com.raytheon.viz.ui.dialogs.CaveSWTDialogBase#constructShellLayout()
*/ */
@Override @Override
@ -236,7 +250,6 @@ public class CreateSubscriptionDlg extends CaveSWTDialog implements
descNameTxt = new Text(subInfoGroup, SWT.BORDER); descNameTxt = new Text(subInfoGroup, SWT.BORDER);
descNameTxt.setLayoutData(new GridData(250, SWT.DEFAULT)); descNameTxt.setLayoutData(new GridData(250, SWT.DEFAULT));
} }
private void createChangeText() { private void createChangeText() {
@ -284,6 +297,9 @@ public class CreateSubscriptionDlg extends CaveSWTDialog implements
}); });
} }
/**
* {@inheritDoc}
*/
@Override @Override
public void createCycleGroup() { public void createCycleGroup() {
GridData gd = new GridData(SWT.FILL, SWT.DEFAULT, true, false); GridData gd = new GridData(SWT.FILL, SWT.DEFAULT, true, false);
@ -316,6 +332,9 @@ public class CreateSubscriptionDlg extends CaveSWTDialog implements
cycleComp.setLayoutData(gd); cycleComp.setLayoutData(gd);
} }
/**
* {@inheritDoc}
*/
@Override @Override
protected void preOpened() { protected void preOpened() {
preOpenCallback.run(); preOpenCallback.run();
@ -324,16 +343,25 @@ public class CreateSubscriptionDlg extends CaveSWTDialog implements
shell.pack(); shell.pack();
} }
/**
* {@inheritDoc}
*/
@Override @Override
public void openDlg() { public void openDlg() {
this.open(); this.open();
} }
/**
* {@inheritDoc}
*/
@Override @Override
public int getDeliverySelection() { public int getDeliverySelection() {
return this.deliverComp.getDeliverSetting(); return this.deliverComp.getDeliverSetting();
} }
/**
* {@inheritDoc}
*/
@Override @Override
public String getSubscriptionName() { public String getSubscriptionName() {
if (create) { if (create) {
@ -343,6 +371,9 @@ public class CreateSubscriptionDlg extends CaveSWTDialog implements
} }
} }
/**
* {@inheritDoc}
*/
@Override @Override
public void setSubscriptionName(String subscriptionName) { public void setSubscriptionName(String subscriptionName) {
if (subscriptionName != null) { if (subscriptionName != null) {
@ -354,141 +385,225 @@ public class CreateSubscriptionDlg extends CaveSWTDialog implements
} }
} }
/**
* {@inheritDoc}
*/
@Override @Override
public String getSubscriptionDescription() { public String getSubscriptionDescription() {
return this.descNameTxt.getText().trim(); return this.descNameTxt.getText().trim();
} }
/**
* {@inheritDoc}
*/
@Override @Override
public void setSubscriptionDescription(String subscriptionDescription) { public void setSubscriptionDescription(String subscriptionDescription) {
descNameTxt.setText(subscriptionDescription); descNameTxt.setText(subscriptionDescription);
} }
/**
* {@inheritDoc}
*/
@Override @Override
public String getGroupName() { public String getGroupName() {
return this.groupSelectComp.getGroupName(); return this.groupSelectComp.getGroupName();
} }
/**
* {@inheritDoc}
*/
@Override @Override
public void setDeliverySelection(int idx) { public void setDeliverySelection(int idx) {
deliverComp.setDeliverSetting(idx); deliverComp.setDeliverSetting(idx);
} }
/**
* {@inheritDoc}
*/
@Override @Override
public boolean isNoExpirationDate() { public boolean isNoExpirationDate() {
return this.durComp.isIndefiniteChk(); return this.durComp.isIndefiniteChk();
} }
/**
* {@inheritDoc}
*/
@Override @Override
public void setNoExpiration(boolean noExpiration) { public void setNoExpiration(boolean noExpiration) {
durComp.setNoExpiration(noExpiration); durComp.setNoExpiration(noExpiration);
} }
/**
* {@inheritDoc}
*/
@Override @Override
public String getStartText() { public String getStartText() {
return this.durComp.getStartText(); return this.durComp.getStartText();
} }
/**
* {@inheritDoc}
*/
@Override @Override
public void setStartDate(Date startDate) { public void setStartDate(Date startDate) {
durComp.setStartDate(startDate); durComp.setStartDate(startDate);
} }
/**
* {@inheritDoc}
*/
@Override @Override
public String getExpirationText() { public String getExpirationText() {
return this.durComp.getEndText(); return this.durComp.getEndText();
} }
/**
* {@inheritDoc}
*/
@Override @Override
public void setExpirationDate(Date expDate) { public void setExpirationDate(Date expDate) {
durComp.setEndDate(expDate); durComp.setEndDate(expDate);
} }
/**
* {@inheritDoc}
*/
@Override @Override
public boolean isAlwaysActive() { public boolean isAlwaysActive() {
return this.activePeriodComp.isAlwaysChk(); return this.activePeriodComp.isAlwaysChk();
} }
/**
* {@inheritDoc}
*/
@Override @Override
public void setAlwaysActive(boolean active) { public void setAlwaysActive(boolean active) {
activePeriodComp.setAlwaysActive(active); activePeriodComp.setAlwaysActive(active);
} }
/**
* {@inheritDoc}
*/
@Override @Override
public String getActiveStartText() { public String getActiveStartText() {
return this.activePeriodComp.getActiveStartText(); return this.activePeriodComp.getActiveStartText();
} }
/**
* {@inheritDoc}
*/
@Override @Override
public void setActiveStartDate(Date activeStartDate) { public void setActiveStartDate(Date activeStartDate) {
activePeriodComp.setStartDate(activeStartDate); activePeriodComp.setStartDate(activeStartDate);
} }
/**
* {@inheritDoc}
*/
@Override @Override
public String getActiveEndText() { public String getActiveEndText() {
return this.activePeriodComp.getActiveEndText(); return this.activePeriodComp.getActiveEndText();
} }
/**
* {@inheritDoc}
*/
@Override @Override
public void setActiveEndDate(Date activeEndDate) { public void setActiveEndDate(Date activeEndDate) {
activePeriodComp.setEndDate(activeEndDate); activePeriodComp.setEndDate(activeEndDate);
} }
/**
* {@inheritDoc}
*/
@Override @Override
public int getPriority() { public int getPriority() {
return priorityComp.getPriorityIndex(); return priorityComp.getPriorityIndex();
} }
/**
* {@inheritDoc}
*/
@Override @Override
public void setPriority(int i) { public void setPriority(int i) {
priorityComp.setPriorityIndex(i); priorityComp.setPriorityIndex(i);
} }
/**
* {@inheritDoc}
*/
@Override @Override
public void setGroupName(String groupName) { public void setGroupName(String groupName) {
groupSelectComp.setGroupName(groupName); groupSelectComp.setGroupName(groupName);
} }
/**
* {@inheritDoc}
*/
@Override @Override
public void setSubscriptionDatesEnabled(boolean enabled) { public void setSubscriptionDatesEnabled(boolean enabled) {
this.durComp.resetTextBoxes(enabled); this.durComp.resetTextBoxes(enabled);
} }
/**
* {@inheritDoc}
*/
@Override @Override
public void setStartDateBtnEnabled(boolean enabled) { public void setStartDateBtnEnabled(boolean enabled) {
durComp.setStartBtnEnabled(enabled); durComp.setStartBtnEnabled(enabled);
} }
/**
* {@inheritDoc}
*/
@Override @Override
public void setEndDateBtnEnabled(boolean enabled) { public void setEndDateBtnEnabled(boolean enabled) {
durComp.setEndBtnEnabled(enabled); durComp.setEndBtnEnabled(enabled);
} }
/**
* {@inheritDoc}
*/
@Override @Override
public void setActiveDatesEnabled(boolean enabled) { public void setActiveDatesEnabled(boolean enabled) {
this.activePeriodComp.resetTextBoxes(enabled); this.activePeriodComp.resetTextBoxes(enabled);
} }
/**
* {@inheritDoc}
*/
@Override @Override
public void setActiveEndDateBtnEnabled(boolean enabled) { public void setActiveEndDateBtnEnabled(boolean enabled) {
this.activePeriodComp.setEndBtnEnabled(enabled); this.activePeriodComp.setEndBtnEnabled(enabled);
} }
/**
* {@inheritDoc}
*/
@Override @Override
public void setActiveStartDateBtnEnabled(boolean enabled) { public void setActiveStartDateBtnEnabled(boolean enabled) {
this.activePeriodComp.setStartBtnEnabled(enabled); this.activePeriodComp.setStartBtnEnabled(enabled);
} }
/**
* {@inheritDoc}
*/
@Override @Override
public void setDeliveryOptionsComboConf(ComboBoxConf deliveryCombo) { public void setDeliveryOptionsComboConf(ComboBoxConf deliveryCombo) {
this.deliverComp.setDeliveryConfig(deliveryCombo); this.deliverComp.setDeliveryConfig(deliveryCombo);
} }
/**
* {@inheritDoc}
*/
@Override @Override
public void setDeliveryOptions(String[] deliveryOptions) { public void setDeliveryOptions(String[] deliveryOptions) {
this.deliverComp.setDeliveryOptions(deliveryOptions); this.deliverComp.setDeliveryOptions(deliveryOptions);
} }
/**
* {@inheritDoc}
*/
@Override @Override
public void setOkConf(final ButtonConf okConf) { public void setOkConf(final ButtonConf okConf) {
okBtn.setText(okConf.getDisplayText()); okBtn.setText(okConf.getDisplayText());
@ -498,7 +613,8 @@ public class CreateSubscriptionDlg extends CaveSWTDialog implements
@Override @Override
public void widgetSelected(SelectionEvent event) { public void widgetSelected(SelectionEvent event) {
status = Status.OK; status = Status.OK;
getShell().setCursor(getDisplay().getSystemCursor(SWT.CURSOR_WAIT)); getShell().setCursor(
getDisplay().getSystemCursor(SWT.CURSOR_WAIT));
okConf.getOnClickAction().run(); okConf.getOnClickAction().run();
if (!getShell().isDisposed()) { if (!getShell().isDisposed()) {
getShell().setCursor(null); getShell().setCursor(null);
@ -508,48 +624,73 @@ public class CreateSubscriptionDlg extends CaveSWTDialog implements
} }
/**
* {@inheritDoc}
*/
@Override @Override
public boolean isCreate() { public boolean isCreate() {
return this.create; return this.create;
} }
/**
* {@inheritDoc}
*/
@Override @Override
public void selectAllSubscriptionName() { public void selectAllSubscriptionName() {
this.subNameTxt.selectAll(); this.subNameTxt.selectAll();
} }
/**
* {@inheritDoc}
*/
@Override @Override
public String getChangeReason() { public String getChangeReason() {
return this.changeReasonTxt.getText().trim(); return this.changeReasonTxt.getText().trim();
} }
/**
* {@inheritDoc}
*/
@Override @Override
public void closeDlg() { public void closeDlg() {
this.close(); this.close();
} }
/**
* {@inheritDoc}
*/
@Override @Override
public void init() { public void init() {
} }
/**
* {@inheritDoc}
*/
@Override @Override
public void displayPopup(String title, String message) { public void displayPopup(String title, String message) {
DataDeliveryUtils.showMessage(getShell(), SWT.OK, DataDeliveryUtils.showMessage(getShell(), SWT.OK, title, message);
title, message);
} }
/**
* {@inheritDoc}
*/
@Override @Override
public boolean displayOkCancelPopup(String title, String message) { public boolean displayOkCancelPopup(String title, String message) {
return DataDeliveryUtils.showMessage(shell, SWT.CANCEL | SWT.OK, title, return DataDeliveryUtils.showMessage(shell, SWT.CANCEL | SWT.OK, title,
message) == SWT.OK; message) == SWT.OK;
} }
/**
* {@inheritDoc}
*/
@Override @Override
public void displayErrorPopup(String title, String message) { public void displayErrorPopup(String title, String message) {
DataDeliveryUtils.showMessage(shell, SWT.ERROR, DataDeliveryUtils.showMessage(shell, SWT.ERROR, title, message);
title, message);
} }
/**
* {@inheritDoc}
*/
@Override @Override
public List<Integer> getCycleTimes() { public List<Integer> getCycleTimes() {
ArrayList<Integer> cycleList = new ArrayList<Integer>(); ArrayList<Integer> cycleList = new ArrayList<Integer>();
@ -562,6 +703,9 @@ public class CreateSubscriptionDlg extends CaveSWTDialog implements
return cycleList; return cycleList;
} }
/**
* {@inheritDoc}
*/
@Override @Override
public void setCycleConf(List<CheckBoxConf> checkboxConfList) { public void setCycleConf(List<CheckBoxConf> checkboxConfList) {
hourBtnArr = new Button[checkboxConfList.size()]; hourBtnArr = new Button[checkboxConfList.size()];
@ -580,6 +724,9 @@ public class CreateSubscriptionDlg extends CaveSWTDialog implements
} }
} }
/**
* {@inheritDoc}
*/
@Override @Override
public void setSelectAllButton(ButtonConf selectAllConf) { public void setSelectAllButton(ButtonConf selectAllConf) {
selectAllBtn.addSelectionListener(new SelectionAdapter() { selectAllBtn.addSelectionListener(new SelectionAdapter() {
@ -595,6 +742,9 @@ public class CreateSubscriptionDlg extends CaveSWTDialog implements
selectAllBtn.setEnabled(selectAllConf.isEnabled()); selectAllBtn.setEnabled(selectAllConf.isEnabled());
} }
/**
* {@inheritDoc}
*/
@Override @Override
public void setDeselectAllButton(ButtonConf deselectAllConf) { public void setDeselectAllButton(ButtonConf deselectAllConf) {
deselectAllBtn.setSelection(true); deselectAllBtn.setSelection(true);
@ -611,11 +761,17 @@ public class CreateSubscriptionDlg extends CaveSWTDialog implements
deselectAllBtn.setEnabled(deselectAllConf.isEnabled()); deselectAllBtn.setEnabled(deselectAllConf.isEnabled());
} }
/**
* {@inheritDoc}
*/
@Override @Override
public void setDateTxtFieldsEnabled(boolean flag) { public void setDateTxtFieldsEnabled(boolean flag) {
this.durComp.resetTextBoxes(flag); this.durComp.resetTextBoxes(flag);
} }
/**
* {@inheritDoc}
*/
@Override @Override
public void setActiveTextFieldsEnabled(boolean flag) { public void setActiveTextFieldsEnabled(boolean flag) {
this.activePeriodComp.resetTextBoxes(flag); this.activePeriodComp.resetTextBoxes(flag);
@ -623,7 +779,7 @@ public class CreateSubscriptionDlg extends CaveSWTDialog implements
@Override @Override
public void selectCycles(List<String> cycleStrings) { public void selectCycles(List<String> cycleStrings) {
for (Button b: this.hourBtnArr) { for (Button b : this.hourBtnArr) {
if (cycleStrings.contains(b.getText())) { if (cycleStrings.contains(b.getText())) {
b.setSelection(true); b.setSelection(true);
} }
@ -655,8 +811,7 @@ public class CreateSubscriptionDlg extends CaveSWTDialog implements
} }
/** /**
* @param status * {@inheritDoc}
* the status to set
*/ */
@Override @Override
public void setStatus(int status) { public void setStatus(int status) {
@ -670,4 +825,36 @@ public class CreateSubscriptionDlg extends CaveSWTDialog implements
public boolean isGroupSelected() { public boolean isGroupSelected() {
return groupSelectComp.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<Integer> cycleTimes) {
this.cycleTimes = cycleTimes;
}
} }

View file

@ -22,6 +22,7 @@ package com.raytheon.uf.viz.datadelivery.subscription.presenter;
import java.text.ParseException; import java.text.ParseException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Calendar; import java.util.Calendar;
import java.util.Collections;
import java.util.Date; import java.util.Date;
import java.util.List; import java.util.List;
import java.util.Set; 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. * Dec 18, 2012 1439 mpduff Redo subscription name validation.
* Jan 02, 2012 1345 djohnson Use gui thread task executor. * Jan 02, 2012 1345 djohnson Use gui thread task executor.
* Jan 02, 2013 1441 djohnson Access GroupDefinitionManager in a static fashion. * Jan 02, 2013 1441 djohnson Access GroupDefinitionManager in a static fashion.
* Jan 04, 2012 1420 mpduff Add Latency to PriorityComp.
* </pre> * </pre>
* *
* @author mpduff * @author mpduff
@ -156,10 +158,14 @@ public class CreateSubscriptionDlgPresenter {
/** Group Definition object */ /** Group Definition object */
private GroupDefinition groupDefinition; private GroupDefinition groupDefinition;
/** Create subscription flag */
private final boolean create; private final boolean create;
private final IGuiThreadTaskExecutor guiThreadTaskExecutor; private final IGuiThreadTaskExecutor guiThreadTaskExecutor;
@VisibleForTesting
Set<Integer> cycleTimes;
/** /**
* Constructor. * Constructor.
* *
@ -216,6 +222,11 @@ public class CreateSubscriptionDlgPresenter {
init(); init();
} }
}; };
// Get cycles
cycleTimes = Sets.newTreeSet(((OpenDapGriddedDataSet) dataSet)
.getCycles());
this.view.setCycleTimes(cycleTimes);
this.view.setSubscription(this.subscription);
this.view.setPreOpenCallback(callback); this.view.setPreOpenCallback(callback);
this.view.openDlg(); this.view.openDlg();
} }
@ -239,6 +250,15 @@ public class CreateSubscriptionDlgPresenter {
this.subscription = sub; this.subscription = sub;
} }
/**
* Get the subscription.
*
* @return the subscription
*/
public Subscription getSubscription() {
return this.subscription;
}
/** /**
* Bring the view dialog to the top * Bring the view dialog to the top
*/ */
@ -256,9 +276,6 @@ public class CreateSubscriptionDlgPresenter {
view.setDeliverySelection(0); view.setDeliverySelection(0);
view.setOkConf(OK_CONF); view.setOkConf(OK_CONF);
// Get cycles
Set<Integer> cycleTimes = Sets
.newTreeSet(((OpenDapGriddedDataSet) dataSet).getCycles());
final boolean hasCycleTimes = !cycleTimes.isEmpty(); final boolean hasCycleTimes = !cycleTimes.isEmpty();
this.cycleChkList = new ArrayList<CheckBoxConf>(cycleTimes.size()); this.cycleChkList = new ArrayList<CheckBoxConf>(cycleTimes.size());
@ -345,8 +362,6 @@ public class CreateSubscriptionDlgPresenter {
view.setActiveEndDateBtnEnabled(false); view.setActiveEndDateBtnEnabled(false);
} }
view.setPriority(subscription.getPriority());
List<Integer> cycleTimes = subscription.getTime().getCycleTimes(); List<Integer> cycleTimes = subscription.getTime().getCycleTimes();
if (cycleTimes != null) { if (cycleTimes != null) {
List<String> cycleStrings = new ArrayList<String>(); List<String> cycleStrings = new ArrayList<String>();
@ -492,6 +507,8 @@ public class CreateSubscriptionDlgPresenter {
subscription.getTime().setCycleTimes(view.getCycleTimes()); subscription.getTime().setCycleTimes(view.getCycleTimes());
subscription.setLatencyInMinutes(view.getLatencyValue());
IUser user = UserController.getUserObject(); IUser user = UserController.getUserObject();
ISubscriptionHandler handler = RegistryObjectHandlers ISubscriptionHandler handler = RegistryObjectHandlers
.get(ISubscriptionHandler.class); .get(ISubscriptionHandler.class);
@ -594,9 +611,7 @@ public class CreateSubscriptionDlgPresenter {
statusHandler.handle(Priority.PROBLEM, e.getLocalizedMessage(), statusHandler.handle(Priority.PROBLEM, e.getLocalizedMessage(),
e); e);
} }
} else { } else {
// Check for pending subscription, can only have one pending change // Check for pending subscription, can only have one pending change
PendingSubscription pendingSub = new PendingSubscription( PendingSubscription pendingSub = new PendingSubscription(
subscription, LocalizationManager.getInstance() subscription, LocalizationManager.getInstance()
@ -759,10 +774,20 @@ public class CreateSubscriptionDlgPresenter {
boolean groupDeliverValid = false; boolean groupDeliverValid = false;
boolean groupDurValid = false; boolean groupDurValid = false;
boolean groupActiveValid = false; boolean groupActiveValid = false;
boolean latencyValid = false;
// Validate the date entries // Validate the date entries
datesValid = this.durationValidChk(); datesValid = this.durationValidChk();
activeDatesValid = this.activePeriodValidChk(); 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 // Validate the subscription name if entered into text box
String subscriptionName = view.getSubscriptionName(); String subscriptionName = view.getSubscriptionName();
@ -802,7 +827,8 @@ public class CreateSubscriptionDlgPresenter {
e); e);
} }
} }
if (activeDatesValid && datesValid) {
if (activeDatesValid && datesValid && latencyValid) {
valid = true; valid = true;
} }
@ -1005,6 +1031,27 @@ public class CreateSubscriptionDlgPresenter {
return datesValid && dateOrderValid; return datesValid && dateOrderValid;
} }
/**
* Get the max latency allowed.
*
* @return The max latency value allowed
*/
private int getMaxLatency() {
List<Integer> 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. * Add the registry id to the subscription object.
*/ */

View file

@ -75,6 +75,7 @@ import com.raytheon.uf.viz.datadelivery.utils.DataDeliveryUtils;
* Oct 11, 2012 1263 jpiatt Modified for cancel flag. * Oct 11, 2012 1263 jpiatt Modified for cancel flag.
* Dec 10, 2012 1259 bsteffen Switch Data Delivery from LatLon to referenced envelopes. * 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 1299 djohnson Add logging of invalid forecast hour information if it occurs again.
* Jan 04, 2013 1420 mpduff Pass cycles in for rules.
* *
* </pre> * </pre>
* *
@ -251,6 +252,9 @@ public class GriddedSubsetManagerDlg
new IllegalStateException("Debugging stacktrace")); new IllegalStateException("Debugging stacktrace"));
} }
/**
* {@inheritDoc}
*/
@Override @Override
public void updateDataSize() { public void updateDataSize() {
if (!initialized) { if (!initialized) {
@ -276,8 +280,11 @@ public class GriddedSubsetManagerDlg
+ dataSize.getFullSize() + " KB"); + dataSize.getFullSize() + " KB");
} }
/**
* {@inheritDoc}
*/
@Override @Override
protected Time setupDataSpecificTime(Time newTime) { protected Time setupDataSpecificTime(Time newTime, Subscription sub) {
if (asString.isEmpty()) { if (asString.isEmpty()) {
SortedSet<ImmutableDate> newestToOldest = new TreeSet<ImmutableDate>( SortedSet<ImmutableDate> newestToOldest = new TreeSet<ImmutableDate>(
Ordering.natural().reverse()); Ordering.natural().reverse());
@ -307,7 +314,8 @@ public class GriddedSubsetManagerDlg
} }
GriddedTimingSelectionPresenter presenter = new GriddedTimingSelectionPresenter( GriddedTimingSelectionPresenter presenter = new GriddedTimingSelectionPresenter(
new GriddedTimingSelectionDlg(getShell()), dataSet, asString); new GriddedTimingSelectionDlg(getShell(), dataSet.getCycles(),
sub), dataSet, asString);
Integer cycle = presenter.open(); Integer cycle = presenter.open();
if (presenter.isCancel()) { if (presenter.isCancel()) {

View file

@ -19,6 +19,8 @@
**/ **/
package com.raytheon.uf.viz.datadelivery.subscription.subset; package com.raytheon.uf.viz.datadelivery.subscription.subset;
import java.util.Set;
import org.eclipse.swt.SWT; import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter; import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent; 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.List;
import org.eclipse.swt.widgets.Shell; 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.subscription.subset.presenter.IGriddedTimingSelectionDlgView;
import com.raytheon.uf.viz.datadelivery.system.SystemRuleManager;
import com.raytheon.uf.viz.datadelivery.utils.DataDeliveryUtils; import com.raytheon.uf.viz.datadelivery.utils.DataDeliveryUtils;
import com.raytheon.viz.ui.dialogs.CaveSWTDialog; import com.raytheon.viz.ui.dialogs.CaveSWTDialog;
import com.raytheon.viz.ui.presenter.components.ButtonConf; 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. * Sep 12, 2012 223 mpduff Initial creation.
* Oct 11, 2012 1263 jpiatt Modified for cancel button * 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.
* *
* </pre> * </pre>
* *
@ -70,21 +76,34 @@ public class GriddedTimingSelectionDlg extends CaveSWTDialog implements
/** OK button */ /** OK button */
private Button okBtn; private Button okBtn;
/** Cancel button */ /** Cancel button */
private Button cancelBtn; private Button cancelBtn;
/** Priority Composite */
private PriorityComp priorityComp;
/** Callback to the presenter at preopen */ /** Callback to the presenter at preopen */
private Runnable preOpenCallback; private Runnable preOpenCallback;
/** The subscription object */
private final Subscription subscription;
/** Cycle times */
private final Set<Integer> cycleTimes;
/** /**
* Constructor * Constructor
* *
* @param parentShell * @param parentShell
* @param cycleTimes
*/ */
protected GriddedTimingSelectionDlg(Shell parentShell) { protected GriddedTimingSelectionDlg(Shell parentShell,
Set<Integer> cycleTimes, Subscription subscription) {
super(parentShell); super(parentShell);
setText("Select Date/Cycle"); setText("Select Date/Cycle");
this.cycleTimes = cycleTimes;
this.subscription = subscription;
} }
/** /**
@ -100,7 +119,7 @@ public class GriddedTimingSelectionDlg extends CaveSWTDialog implements
*/ */
@Override @Override
protected void initializeComponents(Shell shell) { 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); GridLayout gl = new GridLayout(1, false);
dateComp = new Composite(shell, SWT.NONE); dateComp = new Composite(shell, SWT.NONE);
@ -115,6 +134,12 @@ public class GriddedTimingSelectionDlg extends CaveSWTDialog implements
| SWT.V_SCROLL); | SWT.V_SCROLL);
dateCycleList.setLayoutData(gd); 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); gd = new GridData(SWT.CENTER, SWT.DEFAULT, true, false);
gl = new GridLayout(2, false); gl = new GridLayout(2, false);
Composite buttonComp = new Composite(shell, SWT.NONE); Composite buttonComp = new Composite(shell, SWT.NONE);
@ -129,7 +154,6 @@ public class GriddedTimingSelectionDlg extends CaveSWTDialog implements
gd = new GridData(btnWidth, SWT.DEFAULT); gd = new GridData(btnWidth, SWT.DEFAULT);
cancelBtn = new Button(buttonComp, SWT.PUSH); cancelBtn = new Button(buttonComp, SWT.PUSH);
cancelBtn.setLayoutData(gd); cancelBtn.setLayoutData(gd);
} }
/** /**
@ -198,7 +222,7 @@ public class GriddedTimingSelectionDlg extends CaveSWTDialog implements
} }
}); });
} }
/** /**
* {@inheritDoc} * {@inheritDoc}
*/ */
@ -301,4 +325,19 @@ public class GriddedTimingSelectionDlg extends CaveSWTDialog implements
close(); close();
} }
/**
* {@inheritDoc}
*/
@Override
public int getLatency() {
return priorityComp.getLatencyValue();
}
/**
* {@inheritDoc}
*/
@Override
public int getPriority() {
return priorityComp.getPriorityIndex();
}
} }

View file

@ -121,6 +121,7 @@ import com.raytheon.viz.ui.presenter.IDisplay;
* Dec 17, 2012 1434 mpduff Don't allow underscores in name. * Dec 17, 2012 1434 mpduff Don't allow underscores in name.
* Dec 18, 2012 1439 mpduff Redo subscription name validation. * Dec 18, 2012 1439 mpduff Redo subscription name validation.
* Jan 02, 2012 1345 djohnson Use gui thread task executor. * Jan 02, 2012 1345 djohnson Use gui thread task executor.
* Jan 04, 2012 1420 mpduff Pass the subscription in to the GriddedTimingSelectionDlg.
* </pre> * </pre>
* *
* @author mpduff * @author mpduff
@ -609,11 +610,16 @@ public abstract class SubsetManagerDlg<DATASET extends DataSet, PRESENTER extend
newTime.setStepUnit(time.getStepUnit()); newTime.setStepUnit(time.getStepUnit());
if (sub instanceof AdhocSubscription) { if (sub instanceof AdhocSubscription) {
newTime = setupDataSpecificTime(newTime); newTime = setupDataSpecificTime(newTime, sub);
} else if (!create) { } else if (!create) {
newTime.setCycleTimes(this.subscription.getTime().getCycleTimes()); newTime.setCycleTimes(this.subscription.getTime().getCycleTimes());
} }
// Catch the case where the user closes this dialog.
if (this.isDisposed()) {
return null;
}
if (newTime == null) { if (newTime == null) {
return null; return null;
} }
@ -655,7 +661,7 @@ public abstract class SubsetManagerDlg<DATASET extends DataSet, PRESENTER extend
/** /**
* Setup the timing information specific to the data type. * Setup the timing information specific to the data type.
*/ */
protected abstract Time setupDataSpecificTime(Time newTime); protected abstract Time setupDataSpecificTime(Time newTime, Subscription sub);
/** /**
* Display cancel changes message. * Display cancel changes message.

View file

@ -19,10 +19,13 @@
**/ **/
package com.raytheon.uf.viz.datadelivery.subscription.subset.presenter; package com.raytheon.uf.viz.datadelivery.subscription.subset.presenter;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List; import java.util.List;
import com.google.common.annotations.VisibleForTesting; import com.google.common.annotations.VisibleForTesting;
import com.raytheon.uf.common.datadelivery.registry.GriddedDataSet; import com.raytheon.uf.common.datadelivery.registry.GriddedDataSet;
import com.raytheon.uf.viz.datadelivery.utils.DataDeliveryGUIUtils;
import com.raytheon.viz.ui.presenter.components.ButtonConf; import com.raytheon.viz.ui.presenter.components.ButtonConf;
import com.raytheon.viz.ui.presenter.components.CheckBoxConf; import com.raytheon.viz.ui.presenter.components.CheckBoxConf;
import com.raytheon.viz.ui.presenter.components.ComboBoxConf; import com.raytheon.viz.ui.presenter.components.ComboBoxConf;
@ -40,6 +43,7 @@ import com.raytheon.viz.ui.presenter.components.ListConf;
* Sep 12, 2012 mpduff Initial creation * Sep 12, 2012 mpduff Initial creation
* Sep 27, 2012 1202 bgonzale Set selectionDate to date and cycle. * Sep 27, 2012 1202 bgonzale Set selectionDate to date and cycle.
* Oct 11, 2012 1263 jpiatt Modified for cancel flag. * Oct 11, 2012 1263 jpiatt Modified for cancel flag.
* Jan 04, 2013 1420 mpduff Add the dataset object.
* *
* </pre> * </pre>
* *
@ -82,7 +86,7 @@ public class GriddedTimingSelectionPresenter {
} }
} }
}; };
/** Cancel button action handler */ /** Cancel button action handler */
@VisibleForTesting @VisibleForTesting
final Runnable cancelBtnAction = new Runnable() { final Runnable cancelBtnAction = new Runnable() {
@ -91,7 +95,7 @@ public class GriddedTimingSelectionPresenter {
cancel = true; cancel = true;
} }
}; };
/** Cancel flag */ /** Cancel flag */
private boolean cancel = false; private boolean cancel = false;
@ -102,7 +106,7 @@ public class GriddedTimingSelectionPresenter {
/** Ok button conf object */ /** Ok button conf object */
@VisibleForTesting @VisibleForTesting
final ButtonConf okBtnConf; final ButtonConf okBtnConf;
/** Cancel button conf object */ /** Cancel button conf object */
@VisibleForTesting @VisibleForTesting
ButtonConf cancelBtnConf; ButtonConf cancelBtnConf;
@ -113,9 +117,12 @@ public class GriddedTimingSelectionPresenter {
/** The selected date */ /** The selected date */
private String selectedDate; private String selectedDate;
/** The Gridded dataset obj */
private final GriddedDataSet dataSet;
/** /**
* Constructor. * Constructor.
* *
* @param view * @param view
* The view * The view
* @param dataSet * @param dataSet
@ -126,6 +133,7 @@ public class GriddedTimingSelectionPresenter {
public GriddedTimingSelectionPresenter(IGriddedTimingSelectionDlgView view, public GriddedTimingSelectionPresenter(IGriddedTimingSelectionDlgView view,
GriddedDataSet dataSet, List<String> dateCycleList) { GriddedDataSet dataSet, List<String> dateCycleList) {
this.view = view; this.view = view;
this.dataSet = dataSet;
latestDataChkConf = new CheckBoxConf("Get Latest Data", true, latestDataChkConf = new CheckBoxConf("Get Latest Data", true,
"Use the latest time", latestDataChkAction); "Use the latest time", latestDataChkAction);
@ -152,7 +160,7 @@ public class GriddedTimingSelectionPresenter {
/** /**
* OK Button action method. * OK Button action method.
* *
* @return true if everything ok * @return true if everything ok
*/ */
protected boolean handleOk() { protected boolean handleOk() {
@ -164,6 +172,9 @@ public class GriddedTimingSelectionPresenter {
return false; return false;
} }
DataDeliveryGUIUtils.latencyValidChk(view.getLatency(),
getMaxLatency());
// parse off the date/cycle time selected // parse off the date/cycle time selected
String[] parts = selection.split(" - "); String[] parts = selection.split(" - ");
this.selectedDate = selection; this.selectedDate = selection;
@ -177,6 +188,29 @@ public class GriddedTimingSelectionPresenter {
return true; return true;
} }
/**
* Max latency value in minutes.
*
* @return
*/
private int getMaxLatency() {
List<Integer> cycleList = new ArrayList<Integer>(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 * This method is called via the "Use Latest Data" checkbox being
* selected/unselected. * selected/unselected.
@ -187,7 +221,7 @@ public class GriddedTimingSelectionPresenter {
/** /**
* Open the dialog. * Open the dialog.
* *
* @return The selected cycle * @return The selected cycle
*/ */
public Integer open() { public Integer open() {
@ -205,7 +239,7 @@ public class GriddedTimingSelectionPresenter {
/** /**
* Get the selected date. * Get the selected date.
* *
* @return the selected date string * @return the selected date string
*/ */
public String getDate() { public String getDate() {
@ -214,7 +248,7 @@ public class GriddedTimingSelectionPresenter {
/** /**
* Get cancel flag. * Get cancel flag.
* *
* @return true if cancel selected * @return true if cancel selected
*/ */
public boolean isCancel() { public boolean isCancel() {

View file

@ -26,18 +26,19 @@ import com.raytheon.viz.ui.presenter.components.ListConf;
/** /**
* IGriddedTimingSelectionDlgView interface * IGriddedTimingSelectionDlgView interface
* *
* <pre> * <pre>
* *
* SOFTWARE HISTORY * SOFTWARE HISTORY
* *
* Date Ticket# Engineer Description * Date Ticket# Engineer Description
* ------------ ---------- ----------- -------------------------- * ------------ ---------- ----------- --------------------------
* Sep 12, 2012 mpduff Initial creation. * Sep 12, 2012 mpduff Initial creation.
* Oct 11, 2012 1263 jpiatt Modified for cancel flag. * Oct 11, 2012 1263 jpiatt Modified for cancel flag.
* * Jan 04, 2013 1420 mpduff Add getters for Latency and Priority.
*
* </pre> * </pre>
* *
* @author mpduff * @author mpduff
* @version 1.0 * @version 1.0
*/ */
@ -46,41 +47,42 @@ public interface IGriddedTimingSelectionDlgView extends IPresenterView {
/** /**
* Open the view dialog. * Open the view dialog.
* *
* @return the selection * @return the selection
*/ */
Integer openDlg(); Integer openDlg();
/** /**
* Set the config object for the latest data check box. * Set the config object for the latest data check box.
* *
* @param checkBoxConf * @param checkBoxConf
*/ */
void setLatestDataCheckBox(CheckBoxConf checkBoxConf); void setLatestDataCheckBox(CheckBoxConf checkBoxConf);
/** /**
* Set the date/cycle list config object. * Set the date/cycle list config object.
* *
* @param dateCycleListConf * @param dateCycleListConf
*/ */
void setDateCycleList(ListConf dateCycleListConf); void setDateCycleList(ListConf dateCycleListConf);
/** /**
* Set the config object for the ok button. * Set the config object for the ok button.
*
* @param okBtnConf * @param okBtnConf
*/ */
void setOkButton(ButtonConf okBtnConf); void setOkButton(ButtonConf okBtnConf);
/** /**
* Set the callback to be called at preopen. * Set the callback to be called at preopen.
* *
* @param preOpenCallback * @param preOpenCallback
*/ */
void setPreOpenCallback(Runnable preOpenCallback); void setPreOpenCallback(Runnable preOpenCallback);
/** /**
* Check if the latest data checkbox is enabled. * Check if the latest data checkbox is enabled.
* *
* @return true if enabled. * @return true if enabled.
*/ */
boolean isLatestDataEnabled(); boolean isLatestDataEnabled();
@ -92,7 +94,7 @@ public interface IGriddedTimingSelectionDlgView extends IPresenterView {
/** /**
* Get the list selection. * Get the list selection.
* *
* @return the selected item in the list * @return the selected item in the list
*/ */
String getSelection(); String getSelection();
@ -108,5 +110,18 @@ public interface IGriddedTimingSelectionDlgView extends IPresenterView {
* @param cancelBtnConf * @param cancelBtnConf
*/ */
void setCancelButton(ButtonConf cancelBtnConf); void setCancelButton(ButtonConf cancelBtnConf);
/**
* Get the latency value.
*
* @return Latency value
*/
int getLatency();
/**
* Get the priority value.
*
* @return priority value
*/
int getPriority();
} }

View file

@ -21,9 +21,11 @@ package com.raytheon.uf.viz.datadelivery.subscription.view;
import java.util.Date; import java.util.Date;
import java.util.List; import java.util.List;
import java.util.Set;
import org.eclipse.swt.widgets.Shell; 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.IPresenterView;
import com.raytheon.viz.ui.presenter.components.ButtonConf; import com.raytheon.viz.ui.presenter.components.ButtonConf;
import com.raytheon.viz.ui.presenter.components.CheckBoxConf; 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 * Aug 24, 2012 0223 mpduff Initial creation
* Dec 13, 2012 1391 bgonzale Added status methods. * Dec 13, 2012 1391 bgonzale Added status methods.
* Jan 02, 2013 1441 djohnson Add isGroupSelected. * Jan 02, 2013 1441 djohnson Add isGroupSelected.
* Jan 04, 2013 1420 mpduff Added getters for latency and priority.
* *
* </pre> * </pre>
* *
@ -395,4 +398,33 @@ public interface ICreateSubscriptionDlgView extends IPresenterView {
* @return * @return
*/ */
boolean isGroupSelected(); 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<Integer> cycleTimes);
} }

View file

@ -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.
*
* <pre>
*
* SOFTWARE HISTORY
*
* Date Ticket# Engineer Description
* ------------ ---------- ----------- --------------------------
* Dec 19, 2012 1420 mpduff Initial creation.
*
* </pre>
*
* @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;
}
}

View file

@ -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.
*
* <pre>
*
* SOFTWARE HISTORY
*
* Date Ticket# Engineer Description
* ------------ ---------- ----------- --------------------------
* Dec 19, 2012 1420 mpduff Initial creation.
*
* </pre>
*
* @author mpduff
* @version 1.0
*/
@XmlAccessorType(XmlAccessType.NONE)
@XmlRootElement(name = "latencyRules")
public class LatencyRulesXML extends RulesXML<LatencyRuleXML> {
}

View file

@ -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.
*
* <pre>
*
* SOFTWARE HISTORY
*
* Date Ticket# Engineer Description
* ------------ ---------- ----------- --------------------------
* Jan 7, 2013 1420 mpduff Initial creation.
*
* </pre>
*
* @author mpduff
* @version 1.0
*/
public class OperatorAdapter extends XmlAdapter<String, Operator<?>> {
@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();
}
}

View file

@ -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
*
* <pre>
*
* SOFTWARE HISTORY
*
* Date Ticket# Engineer Description
* ------------ ---------- ----------- --------------------------
* Dec 19, 2012 1420 mpduff Initial creation.
*
* </pre>
*
* @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;
}
}

View file

@ -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.
*
* <pre>
*
* SOFTWARE HISTORY
*
* Date Ticket# Engineer Description
* ------------ ---------- ----------- --------------------------
* Dec 19, 2012 1420 mpduff Initial creation.
*
* </pre>
*
* @author mpduff
* @version 1.0
*/
@XmlAccessorType(XmlAccessType.NONE)
@XmlRootElement(name = "priorityRules")
public class PriorityRulesXML extends RulesXML<PriorityRuleXML> {
}

View file

@ -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
*
* <pre>
*
* SOFTWARE HISTORY
*
* Date Ticket# Engineer Description
* ------------ ---------- ----------- --------------------------
* Dec 19, 2012 1420 mpduff Initial creation.
*
* </pre>
*
* @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<Integer> 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<Integer> 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;
}
}

View file

@ -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
*
* <pre>
*
* SOFTWARE HISTORY
*
* Date Ticket# Engineer Description
* ------------ ---------- ----------- --------------------------
* Jan 7, 2013 1420 mpduff Initial creation.
*
* </pre>
*
* @author mpduff
* @version 1.0
*/
@XmlAccessorType(XmlAccessType.NONE)
public abstract class RulesXML<T extends RuleXML> {
private static final Function<RuleXML, String> GET_RULE_NAMES_FUNCTION = new Function<RuleXML, String>() {
@Override
public String apply(RuleXML rule) {
return rule.getRuleName();
}
};
@XmlElements({ @XmlElement(name = "rule") })
protected List<T> rules = new ArrayList<T>();
/**
* 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<T> getRules() {
return rules;
}
/**
* Get the list of rule names.
*
* @return List of rule names
*/
public List<String> getRuleNames() {
return new ArrayList<String>(Lists.transform(getRules(),
GET_RULE_NAMES_FUNCTION));
}
/**
* @param rules
* the rules to set
*/
public void setRules(List<T> 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;
}
}

View file

@ -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.
*
* <pre>
*
* 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.
*
* </pre>
*
* @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;
}
}

View file

@ -19,6 +19,8 @@
**/ **/
package com.raytheon.uf.viz.datadelivery.system; package com.raytheon.uf.viz.datadelivery.system;
import java.util.regex.Pattern;
import org.eclipse.swt.SWT; import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter; import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent; 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.Shell;
import org.eclipse.swt.widgets.Text; 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;
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.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.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; 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 1419 bgonzale Fixed overwrite of values in updatSelectionFields().
* Dec 18, 2012 1439 mpduff Redo rule name validation. * Dec 18, 2012 1439 mpduff Redo rule name validation.
* Dec 18, 2012 1417 bgonzale Changed value initialization in handleSave(). * 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.
* *
* </pre> * </pre>
* *
@ -63,6 +72,9 @@ import com.raytheon.viz.ui.dialogs.CaveSWTDialog;
* @version 1.0 * @version 1.0
*/ */
public class CreateEditRuleDlg extends CaveSWTDialog { public class CreateEditRuleDlg extends CaveSWTDialog {
/** Status Handler */
private final IUFStatusHandler statusHandler = UFStatus
.getHandler(CreateEditRuleDlg.class);
/** Enumeration to use for Dataset Frequency */ /** Enumeration to use for Dataset Frequency */
public static enum FreqUnitOptions { public static enum FreqUnitOptions {
@ -93,36 +105,14 @@ public class CreateEditRuleDlg extends CaveSWTDialog {
} }
} }
/** Enumeration to use for Dataset Size units */ private static final Pattern INVALID_PATTERN = Pattern
public static enum SizeUnitOptions { .compile("[^a-zA-Z0-9-_]+");
/** Kilobytes */
KB("KB"),
/** Megabytes */
MB("MB"),
/** Gigabytes */
GB("GB");
/** Dataset Size units */ /** Invalid Character Message Title */
private final String sizeUnitOptions; private static final String INVALID_CHARS_TITLE = "Invalid Characters";
private SizeUnitOptions(String sizeUnitOptions) { /** Invalid Character Message */
this.sizeUnitOptions = sizeUnitOptions; private static final String INVALID_CHARS_MESSAGE = "Invalid characters.\nThe Rule Name may only contain letters/numbers/dashes/underscores.";
}
/**
* Get size unit options.
*
* @return sizeUnitOptions
*/
public String getOperation() {
return sizeUnitOptions;
}
@Override
public String toString() {
return sizeUnitOptions;
}
}
/** Instance of SystemRuleManager */ /** Instance of SystemRuleManager */
private final SystemRuleManager srm = SystemRuleManager.getInstance(); private final SystemRuleManager srm = SystemRuleManager.getInstance();
@ -134,7 +124,7 @@ public class CreateEditRuleDlg extends CaveSWTDialog {
private Group ruleDefinitionGroup; private Group ruleDefinitionGroup;
/** SubscriptionRuleXML object */ /** SubscriptionRuleXML object */
private SubscriptionRuleXML ruleXml; private RuleXML ruleXml;
/** Save button */ /** Save button */
private Button saveBtn; private Button saveBtn;
@ -199,10 +189,8 @@ public class CreateEditRuleDlg extends CaveSWTDialog {
/** Frequency constant */ /** Frequency constant */
private final String DATASET_FREQ = OpsNetFieldNames.FREQUENCY.toString(); private final String DATASET_FREQ = OpsNetFieldNames.FREQUENCY.toString();
private final IRulesNeedApplying rulesNeedApplying;
/** /**
* Constructor. * Constructor for edit rule.
* *
* @param parent * @param parent
* The parent shell * The parent shell
@ -212,22 +200,19 @@ public class CreateEditRuleDlg extends CaveSWTDialog {
* Name of the rule * Name of the rule
* @param ruleType * @param ruleType
* type of rule * type of rule
* @param rulesNeedApplying
*/ */
public CreateEditRuleDlg(Shell parent, boolean create, String ruleName, public CreateEditRuleDlg(Shell parent, boolean create, String ruleName,
String ruleType, IRulesNeedApplying rulesNeedApplying) { String ruleType) {
super(parent, SWT.RESIZE | SWT.DIALOG_TRIM, CAVE.NONE); super(parent, SWT.RESIZE | SWT.DIALOG_TRIM, CAVE.NONE);
this.create = create; this.create = create;
this.ruleName = ruleName; this.ruleName = ruleName;
this.ruleType = ruleType; this.ruleType = ruleType;
this.rulesNeedApplying = rulesNeedApplying;
createRuleHeader(); createRuleHeader();
} }
/** /**
* Constructor. * Constructor for new rule.
* *
* @param parent * @param parent
* The parent shell * The parent shell
@ -236,15 +221,8 @@ public class CreateEditRuleDlg extends CaveSWTDialog {
* @param ruleType * @param ruleType
* type of rule * type of rule
*/ */
public CreateEditRuleDlg(Shell parent, boolean create, String ruleType, public CreateEditRuleDlg(Shell parent, boolean create, String ruleType) {
IRulesNeedApplying rulesNeedApplying) { this(parent, create, null, ruleType);
super(parent, SWT.RESIZE | SWT.DIALOG_TRIM, CAVE.NONE);
this.create = create;
this.ruleType = ruleType;
this.rulesNeedApplying = rulesNeedApplying;
createRuleHeader();
} }
private void createRuleHeader() { private void createRuleHeader() {
@ -254,7 +232,6 @@ public class CreateEditRuleDlg extends CaveSWTDialog {
} else { } else {
setText("Create Latency Rule"); setText("Create Latency Rule");
} }
} else { } else {
if (PRIORITY_TYPE.equals(ruleType)) { if (PRIORITY_TYPE.equals(ruleType)) {
setText("Edit Priority Rule"); setText("Edit Priority Rule");
@ -262,7 +239,6 @@ public class CreateEditRuleDlg extends CaveSWTDialog {
setText("Edit Latency Rule"); setText("Edit Latency Rule");
} }
} }
} }
/* /*
@ -289,6 +265,19 @@ public class CreateEditRuleDlg extends CaveSWTDialog {
*/ */
@Override @Override
protected void initializeComponents(Shell shell) { 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; initial = true;
createRuleNameArea(); createRuleNameArea();
@ -308,11 +297,8 @@ public class CreateEditRuleDlg extends CaveSWTDialog {
GridData gd = new GridData(SWT.FILL, SWT.DEFAULT, true, false); GridData gd = new GridData(SWT.FILL, SWT.DEFAULT, true, false);
GridLayout gl = new GridLayout(1, true); GridLayout gl = new GridLayout(1, true);
// Create Rule
if (create) { if (create) {
gl = new GridLayout(2, false); gl = new GridLayout(2, false);
Composite textComp = new Composite(shell, SWT.NONE); Composite textComp = new Composite(shell, SWT.NONE);
textComp.setLayoutData(gd); textComp.setLayoutData(gd);
textComp.setLayout(gl); textComp.setLayout(gl);
@ -326,24 +312,12 @@ public class CreateEditRuleDlg extends CaveSWTDialog {
ruleNameText = new Text(textComp, SWT.BORDER); ruleNameText = new Text(textComp, SWT.BORDER);
ruleNameText.setLayoutData(gd); ruleNameText.setLayoutData(gd);
ruleNameText.setTextLimit(32); ruleNameText.setTextLimit(32);
ruleNameText.setToolTipText("Enter rule text"); ruleNameText.setToolTipText("Enter rule name");
// Edit Rule
} else { } else {
Label ruleLbl = new Label(shell, SWT.NONE); Label ruleLbl = new Label(shell, SWT.NONE);
ruleLbl.setText("Rule Name: " + ruleName); 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); updateSelectionFields(field);
String operator = ruleXml.getRuleOperator(); String operator = ruleXml.getRuleOperator();
if (!operator.isEmpty()) { operationCombo.select(operationCombo.indexOf(operator));
operationCombo.select(operationCombo.indexOf(operator));
} else {
operationCombo.select(0);
}
String value = ruleXml.getRuleValue(); String value = ruleXml.getRuleValue();
if (!value.isEmpty()) { if (!value.isEmpty()) {
@ -571,8 +541,9 @@ public class CreateEditRuleDlg extends CaveSWTDialog {
unitsCombo.select(unitsCombo.indexOf(unit)); unitsCombo.select(unitsCombo.indexOf(unit));
} }
Integer priority = ruleXml.getRulePriority();
if (PRIORITY_TYPE.equals(ruleType)) { if (PRIORITY_TYPE.equals(ruleType)) {
Integer priority = ((PriorityRuleXML) ruleXml).getPriority();
int o = 0; int o = 0;
SubscriptionPriority[] priorityOptions = SubscriptionPriority SubscriptionPriority[] priorityOptions = SubscriptionPriority
.values(); .values();
@ -584,7 +555,7 @@ public class CreateEditRuleDlg extends CaveSWTDialog {
o++; o++;
} }
} else { } else {
Integer latency = ruleXml.getRuleLatency(); Integer latency = ((LatencyRuleXML) ruleXml).getLatency();
if (latency != null) { if (latency != null) {
latencyMax.setText(latency.toString()); latencyMax.setText(latency.toString());
} }
@ -674,6 +645,9 @@ public class CreateEditRuleDlg extends CaveSWTDialog {
private boolean handleSave() { private boolean handleSave() {
boolean valid = false; boolean valid = false;
String fieldName = fieldCombo.getItem(fieldCombo.getSelectionIndex());
String operator = operationCombo.getItem(operationCombo
.getSelectionIndex());
if (create) { if (create) {
valid = DataDeliveryGUIUtils.hasText(ruleNameText); valid = DataDeliveryGUIUtils.hasText(ruleNameText);
@ -689,65 +663,14 @@ public class CreateEditRuleDlg extends CaveSWTDialog {
ruleName = ruleNameText.getText(); ruleName = ruleNameText.getText();
} }
if (DataDeliveryGUIUtils.INVALID_CHAR_PATTERN.matcher(ruleName.trim()) if (INVALID_PATTERN.matcher(ruleName.trim()).find()) {
.find()) {
DataDeliveryUtils.showMessage(getShell(), SWT.ERROR, DataDeliveryUtils.showMessage(getShell(), SWT.ERROR,
DataDeliveryGUIUtils.INVALID_CHARS_TITLE, INVALID_CHARS_TITLE, INVALID_CHARS_MESSAGE);
DataDeliveryGUIUtils.INVALID_CHARS_MESSAGE);
return false; return false;
} }
String value = null;
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();
if (DataDeliveryGUIUtils.hasText(ruleValue)) { if (DataDeliveryGUIUtils.hasText(ruleValue)) {
value = ruleValue.getText();
String value = ruleValue.getText();
if (DATASET_SIZE.equals(fieldName) if (DATASET_SIZE.equals(fieldName)
|| DATASET_FREQ.equals(fieldName)) { || DATASET_FREQ.equals(fieldName)) {
@ -765,8 +688,6 @@ public class CreateEditRuleDlg extends CaveSWTDialog {
return false; return false;
} }
} }
rule.setRuleValue(value);
} else { } else {
DataDeliveryUtils.showMessage(getShell(), SWT.ERROR, DataDeliveryUtils.showMessage(getShell(), SWT.ERROR,
"Invalid Value", "Invalid Value",
@ -775,32 +696,98 @@ public class CreateEditRuleDlg extends CaveSWTDialog {
return false; return false;
} }
rule.setRuleName(ruleName); SubscriptionPriority priorityVal = null;
rule.setRuleField(fieldName); Integer priority = null;
rule.setRuleOperator(operator); Integer latency = null;
rule.setRuleUnit(unit); String unit = null;
rule.setRulePriority(priority);
rule.setRuleLatency(latency);
// Save the rule file if (frequencyFlag || sizeFlag) {
boolean saved = srm.saveRule(rule, shell); unit = unitsCombo.getItem(unitsCombo.getSelectionIndex());
}
boolean saved = false;
if (saved) { if (PRIORITY_TYPE.equals(ruleType)) {
setReturnValue(true); PriorityRuleXML rule = new PriorityRuleXML();
rulesNeedApplying.flagRulesAsNeedApplying(); 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() { private void createSizeUnitItems() {
unitsCombo.removeAll(); unitsCombo.removeAll();
SizeUnitOptions[] sizeUnits = SizeUnitOptions.values(); DataSizeUtil[] sizeUnits = DataSizeUtil.values();
for (SizeUnitOptions suo : sizeUnits) { for (DataSizeUtil suo : sizeUnits) {
unitsCombo.add(suo.getOperation()); unitsCombo.add(suo.getUnit());
} }
} }
private void createSizeOpItems() { private void createSizeOpItems() {
@ -809,7 +796,6 @@ public class CreateEditRuleDlg extends CaveSWTDialog {
for (OperatorTypes suo : sizeOps) { for (OperatorTypes suo : sizeOps) {
operationCombo.add(suo.getOperation()); operationCombo.add(suo.getOperation());
} }
} }
private void createFreqUnitItems() { private void createFreqUnitItems() {
@ -817,7 +803,6 @@ public class CreateEditRuleDlg extends CaveSWTDialog {
for (FreqUnitOptions fuo : freqUnits) { for (FreqUnitOptions fuo : freqUnits) {
unitsCombo.add(fuo.getOperation()); unitsCombo.add(fuo.getOperation());
} }
} }
private void createNameOpItems() { private void createNameOpItems() {
@ -826,7 +811,5 @@ public class CreateEditRuleDlg extends CaveSWTDialog {
for (NameOperationItems nop : nameOperation) { for (NameOperationItems nop : nameOperation) {
operationCombo.add(nop.getOperation()); operationCombo.add(nop.getOperation());
} }
} }
} }

View file

@ -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
*
* <pre>
*
* SOFTWARE HISTORY
*
* Date Ticket# Engineer Description
* ------------ ---------- ----------- --------------------------
* Jan 7, 2013 mpduff Initial creation
*
* </pre>
*
* @author mpduff
* @version 1.0
*/
public interface Operator<T> {
/**
* Evaluate whether the operator would return true when comparing operandOne
* to operandTwo.
*
* <pre>
* <code>
* OperatorTypes operator = OperatorTypes.GREATER_THAN;
* long operandOne = 1;
* long operandTwo = 2;
*
* boolean result = operator.evaluate(operandOne, operandTwo); // Returns false
* </code>
* </pre>
*
* @param operandOne
* @param operandTwo
* @return true or false
*/
boolean evaluate(T operandOne, T operandTwo);
/**
* Get the name.
*
* @return the name
*/
String name();
}

View file

@ -19,6 +19,10 @@
**/ **/
package com.raytheon.uf.viz.datadelivery.system; 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. * Operator type enumeration.
* *
@ -37,52 +41,60 @@ package com.raytheon.uf.viz.datadelivery.system;
*/ */
/** Enumeration to use for Dataset Size operations */ /** Enumeration to use for Dataset Size operations */
public enum OperatorTypes { @XmlType(name = "operatorType")
@XmlEnum
public enum OperatorTypes implements Operator<Long> {
/** Greater than operation */ /** Greater than operation */
@XmlEnumValue(">")
GREATER_THAN(">") { GREATER_THAN(">") {
@Override @Override
public boolean evaluate(long operandOne, long operandTwo) { public boolean evaluate(Long operandOne, Long operandTwo) {
return operandOne > operandTwo; return operandOne > operandTwo;
} }
}, },
/** Less than operation */ /** Less than operation */
@XmlEnumValue("<")
LESS_THAN("<") { LESS_THAN("<") {
@Override @Override
public boolean evaluate(long operandOne, long operandTwo) { public boolean evaluate(Long operandOne, Long operandTwo) {
return operandOne < operandTwo; return operandOne < operandTwo;
} }
}, },
/** Greater than or equal operation */ /** Greater than or equal operation */
@XmlEnumValue(">=")
GREATER_THAN_EQUAL(">=") { GREATER_THAN_EQUAL(">=") {
@Override @Override
public boolean evaluate(long operandOne, long operandTwo) { public boolean evaluate(Long operandOne, Long operandTwo) {
return operandOne >= operandTwo; return operandOne >= operandTwo;
} }
}, },
/** Less than or equal operation */ /** Less than or equal operation */
@XmlEnumValue("<=")
LESS_THAN_EQUAL("<=") { LESS_THAN_EQUAL("<=") {
@Override @Override
public boolean evaluate(long operandOne, long operandTwo) { public boolean evaluate(Long operandOne, Long operandTwo) {
return operandOne <= operandTwo; return operandOne <= operandTwo;
} }
}, },
/** Greater than operation */ /** Greater than operation */
@XmlEnumValue("Equal")
EQUAL("Equal") { EQUAL("Equal") {
@Override @Override
public boolean evaluate(long operandOne, long operandTwo) { public boolean evaluate(Long operandOne, Long operandTwo) {
return operandOne == operandTwo; return operandOne.longValue() == operandTwo.longValue();
} }
}, },
/** Greater than operation */ /** Greater than operation */
@XmlEnumValue("Not Equal")
NOT_EQUAL("Not Equal") { NOT_EQUAL("Not Equal") {
@Override @Override
public boolean evaluate(long operandOne, long operandTwo) { public boolean evaluate(Long operandOne, Long operandTwo) {
return operandOne != operandTwo; return operandOne.longValue() != operandTwo.longValue();
} }
}; };
/** Datatype operation */ /** Datatype operation */
private final String operator; private String operator;
private OperatorTypes(String sizeOperation) { private OperatorTypes(String sizeOperation) {
this.operator = sizeOperation; this.operator = sizeOperation;
@ -101,33 +113,15 @@ public enum OperatorTypes {
public String toString() { public String toString() {
return operator; return operator;
} }
/** // public abstract boolean evaluate(Long operandOne, Long operandTwo);
* Evaluate whether the operator would return true when comparing operandOne to operandTwo.
*
* <pre>
* <code>
* OperatorTypes operator = OperatorTypes.GREATER_THAN;
* long operandOne = 1;
* long operandTwo = 2;
*
* boolean result = operator.evaluate(operandOne, operandTwo); // Returns false
* </code>
* </pre>
*
* @param operandOne
* @param operandTwo
* @return true or false
*/
public abstract boolean evaluate(long operandOne, long operandTwo);
/** /**
* Return the type from its toString() value. * Return the type from its toString() value.
* *
* @param string * @param string
* the string * the string
* @return * @return the type
* the type
*/ */
public static OperatorTypes fromString(String string) { public static OperatorTypes fromString(String string) {
for (OperatorTypes operator : OperatorTypes.values()) { for (OperatorTypes operator : OperatorTypes.values()) {
@ -136,6 +130,6 @@ public enum OperatorTypes {
} }
} }
return null; return null;
} }
} }

View file

@ -19,9 +19,7 @@
**/ **/
package com.raytheon.uf.viz.datadelivery.system; package com.raytheon.uf.viz.datadelivery.system;
import java.util.Arrays; import java.util.Collections;
import javax.xml.bind.JAXBException;
import org.eclipse.swt.SWT; import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter; import org.eclipse.swt.events.SelectionAdapter;
@ -52,7 +50,8 @@ import com.raytheon.uf.viz.datadelivery.utils.DataDeliveryUtils;
* Date Ticket# Engineer Description * Date Ticket# Engineer Description
* ------------ ---------- ----------- -------------------------- * ------------ ---------- ----------- --------------------------
* Sep 17, 2012 730 jpiatt Initial creation. * 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.
* *
* </pre> * </pre>
* *
@ -65,6 +64,8 @@ public class SystemLatencyTab {
private final IUFStatusHandler statusHandler = UFStatus private final IUFStatusHandler statusHandler = UFStatus
.getHandler(SystemLatencyTab.class); .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 */ /** Parent Composite */
private final Composite parentComp; private final Composite parentComp;
@ -83,34 +84,29 @@ public class SystemLatencyTab {
/** Flag for create and edit. */ /** Flag for create and edit. */
private boolean create; private boolean create;
/** Edit a selected item in the selected list down in the list. */ /** Edit rule button. */
private Button editBtn; private Button editBtn;
/** New button. */ /** New rule button. */
private Button newBtn; private Button newBtn;
/** Delete rule button. */
private Button deleteBtn;
/** Button Height. */ /** Button Height. */
private final int buttonHeight = SWT.DEFAULT; private final int buttonHeight = SWT.DEFAULT;
/** Button Width. */ /** Button Width. */
private final int buttonWidth = 55; private final int buttonWidth = 70;
private final IRulesNeedApplying rulesNeedApplying;
/** /**
* Constructor. * Constructor.
* *
* @param parentComp * @param parentComp
* The Composite holding these controls * The Composite holding these controls
* @param systemManagementDlg
*
* @param dataSet
* The DataSet object
*/ */
public SystemLatencyTab(Composite parentComp, public SystemLatencyTab(Composite parentComp) {
IRulesNeedApplying rulesNeedApplying) {
this.parentComp = parentComp; this.parentComp = parentComp;
this.rulesNeedApplying = rulesNeedApplying;
init(); init();
} }
@ -140,16 +136,20 @@ public class SystemLatencyTab {
latencyList = new List(latencyComp, SWT.BORDER | SWT.MULTI latencyList = new List(latencyComp, SWT.BORDER | SWT.MULTI
| SWT.V_SCROLL | SWT.H_SCROLL); | SWT.V_SCROLL | SWT.H_SCROLL);
latencyList.setLayoutData(gd); latencyList.setLayoutData(gd);
latencyList.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
enableButtons(latencyList.getSelectionCount() > 0);
}
});
loadList(); loadList();
} }
/** /**
* Create the move up/down controls * Create the move up/down controls
*/ */
private void createSideButtons() { private void createSideButtons() {
GridData actionData = new GridData(SWT.DEFAULT, SWT.CENTER, false, true); GridData actionData = new GridData(SWT.DEFAULT, SWT.CENTER, false, true);
GridLayout actionLayout = new GridLayout(1, false); GridLayout actionLayout = new GridLayout(1, false);
Composite actionComp = new Composite(latencyComp, SWT.NONE); Composite actionComp = new Composite(latencyComp, SWT.NONE);
@ -168,6 +168,12 @@ public class SystemLatencyTab {
public void widgetSelected(SelectionEvent event) { public void widgetSelected(SelectionEvent event) {
create = true; create = true;
handleLatencyRule(); 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 = new Button(actionComp, SWT.PUSH);
editBtn.setText("Edit..."); editBtn.setText("Edit...");
editBtn.setLayoutData(btnData); editBtn.setLayoutData(btnData);
editBtn.setEnabled(true); editBtn.setEnabled(false);
editBtn.setToolTipText("Edit item selected in the list"); editBtn.setToolTipText("Edit item selected in the list");
editBtn.addSelectionListener(new SelectionAdapter() { editBtn.addSelectionListener(new SelectionAdapter() {
@Override @Override
public void widgetSelected(SelectionEvent event) { public void widgetSelected(SelectionEvent event) {
create = false; create = false;
int idx = latencyList.getSelectionIndex();
handleLatencyRule(); 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() { private void handleLatencyRule() {
final DataDeliveryPermission permission = DataDeliveryPermission.SYSTEM_MANAGEMENT_CREATE; final DataDeliveryPermission permission = DataDeliveryPermission.SYSTEM_MANAGEMENT_CREATE;
IUser user = UserController.getUserObject(); IUser user = UserController.getUserObject();
String msg = user.uniqueId() String msg = user.uniqueId() + notAuthorizedMsg + permission;
+ " is not authorized to create or edit rules using the"
+ " Data Delivery System Management\nPermission: " + permission;
DataDeliveryAuthRequest request = new DataDeliveryAuthRequest(); DataDeliveryAuthRequest request = new DataDeliveryAuthRequest();
request.setUser(user); request.setUser(user);
request.addRequestedPermissions(permission); request.addRequestedPermissions(permission);
@ -210,7 +237,7 @@ public class SystemLatencyTab {
// New // New
if (create) { if (create) {
ruleDlg = new CreateEditRuleDlg(parentComp.getShell(), ruleDlg = new CreateEditRuleDlg(parentComp.getShell(),
create, LATENCY_TYPE, rulesNeedApplying); create, LATENCY_TYPE);
} else { } else {
// Edit // Edit
String ruleName = null; String ruleName = null;
@ -230,8 +257,7 @@ public class SystemLatencyTab {
return; return;
} }
ruleDlg = new CreateEditRuleDlg(parentComp.getShell(), ruleDlg = new CreateEditRuleDlg(parentComp.getShell(),
create, ruleName, LATENCY_TYPE, create, ruleName, LATENCY_TYPE);
rulesNeedApplying);
} }
boolean reloadFlag = (Boolean) ruleDlg.open(); boolean reloadFlag = (Boolean) ruleDlg.open();
if (reloadFlag) { if (reloadFlag) {
@ -246,7 +272,48 @@ public class SystemLatencyTab {
statusHandler.handle(Priority.PROBLEM, statusHandler.handle(Priority.PROBLEM,
"Error occurred in authorization request", e); "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(); latencyList.removeAll();
// Get the list of latency rule names // Get the list of latency rule names
String[] rules = null; java.util.List<String> rules = null;
try { rules = SystemRuleManager.getInstance().getLatencyRuleNames();
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);
Collections.sort(rules, String.CASE_INSENSITIVE_ORDER);
latencyList.setItems(rules.toArray(new String[rules.size()]));
} }
} }

View file

@ -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;
import com.raytheon.uf.common.status.UFStatus.Priority; import com.raytheon.uf.common.status.UFStatus.Priority;
import com.raytheon.uf.common.util.StringUtil; 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.ForceApplyPromptResponse;
import com.raytheon.uf.viz.datadelivery.subscription.SubscriptionService.IForceApplyPromptDisplayText; import com.raytheon.uf.viz.datadelivery.subscription.SubscriptionService.IForceApplyPromptDisplayText;
import com.raytheon.uf.viz.datadelivery.utils.DataDeliveryUtils; 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. * 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.
* Nov 20, 2012 1286 djohnson Implement IDisplay. * Nov 20, 2012 1286 djohnson Implement IDisplay.
* Jan 04, 2013 1420 mpduff Remove applying of rules.
* *
* </pre> * </pre>
* *
@ -71,7 +71,7 @@ import com.raytheon.viz.ui.presenter.IDisplay;
* @version 1.0 * @version 1.0
*/ */
public class SystemManagementDlg extends CaveSWTDialog implements IDisplay, public class SystemManagementDlg extends CaveSWTDialog implements IDisplay,
IRulesNeedApplying, IForceApplyPromptDisplayText { IForceApplyPromptDisplayText {
/** Status Handler */ /** Status Handler */
private final IUFStatusHandler statusHandler = UFStatus private final IUFStatusHandler statusHandler = UFStatus
@ -132,8 +132,6 @@ public class SystemManagementDlg extends CaveSWTDialog implements IDisplay,
private Spinner availBandwidthSpinner; private Spinner availBandwidthSpinner;
private boolean needToApplyRules;
/** /**
* Constructor. * Constructor.
* *
@ -285,7 +283,7 @@ public class SystemManagementDlg extends CaveSWTDialog implements IDisplay,
priorityComp.setLayout(gl); priorityComp.setLayout(gl);
priorityComp.setLayoutData(gd); priorityComp.setLayoutData(gd);
priorityTab.setControl(priorityComp); priorityTab.setControl(priorityComp);
SystemPriorityTab pTab = new SystemPriorityTab(priorityComp, this); SystemPriorityTab pTab = new SystemPriorityTab(priorityComp);
gd = new GridData(SWT.FILL, SWT.DEFAULT, true, false); gd = new GridData(SWT.FILL, SWT.DEFAULT, true, false);
gl = new GridLayout(1, false); gl = new GridLayout(1, false);
@ -298,7 +296,7 @@ public class SystemManagementDlg extends CaveSWTDialog implements IDisplay,
latencyComp.setLayout(gl); latencyComp.setLayout(gl);
latencyComp.setLayoutData(gd); latencyComp.setLayoutData(gd);
latencyTab.setControl(latencyComp); latencyTab.setControl(latencyComp);
SystemLatencyTab lTab = new SystemLatencyTab(latencyComp, this); SystemLatencyTab lTab = new SystemLatencyTab(latencyComp);
gd = new GridData(SWT.CENTER, SWT.DEFAULT, true, false); gd = new GridData(SWT.CENTER, SWT.DEFAULT, true, false);
gl = new GridLayout(1, false); gl = new GridLayout(1, false);
@ -310,7 +308,7 @@ public class SystemManagementDlg extends CaveSWTDialog implements IDisplay,
routingComp.setLayout(gl); routingComp.setLayout(gl);
routingComp.setLayoutData(gd); routingComp.setLayoutData(gd);
routingTab.setControl(routingComp); 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; return true;
} }
@ -461,14 +442,6 @@ public class SystemManagementDlg extends CaveSWTDialog implements IDisplay,
return DataDeliveryUtils.showYesNoMessage(shell, title, message) == SWT.YES; return DataDeliveryUtils.showYesNoMessage(shell, title, message) == SWT.YES;
} }
/**
* {@inheritDoc}
*/
@Override
public void flagRulesAsNeedApplying() {
needToApplyRules = true;
}
/** /**
* {@inheritDoc} * {@inheritDoc}
*/ */

View file

@ -19,9 +19,7 @@
**/ **/
package com.raytheon.uf.viz.datadelivery.system; package com.raytheon.uf.viz.datadelivery.system;
import java.util.Arrays; import java.util.Collections;
import javax.xml.bind.JAXBException;
import org.eclipse.swt.SWT; import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter; import org.eclipse.swt.events.SelectionAdapter;
@ -52,7 +50,8 @@ import com.raytheon.uf.viz.datadelivery.utils.DataDeliveryUtils;
* Date Ticket# Engineer Description * Date Ticket# Engineer Description
* ------------ ---------- ----------- -------------------------- * ------------ ---------- ----------- --------------------------
* Sep 17, 2012 730 jpiatt Initial creation. * 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.
* *
* </pre> * </pre>
* *
@ -80,22 +79,25 @@ public class SystemPriorityTab {
/** Available List widget */ /** Available List widget */
private List priorityList; private List priorityList;
/** Edit a selected item in the selected list. */ /** Edit rule button. */
private Button editBtn; private Button editBtn;
/** New button. */ /** New rule button. */
private Button newBtn; private Button newBtn;
/** Delete rule button */
private Button deleteBtn;
/** Button Height. */ /** Button Height. */
private final int buttonHeight = SWT.DEFAULT; private final int buttonHeight = SWT.DEFAULT;
/** Button Width. */ /** Button Width. */
private final int buttonWidth = 55; private final int buttonWidth = 70;
/** Flag for create and edit. */ /** Flag for create and edit. */
private boolean create; 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. * Constructor.
@ -107,10 +109,8 @@ public class SystemPriorityTab {
* @param dataSet * @param dataSet
* The DataSet object * The DataSet object
*/ */
public SystemPriorityTab(Composite parentComp, public SystemPriorityTab(Composite parentComp) {
IRulesNeedApplying rulesNeedApplying) {
this.parentComp = parentComp; this.parentComp = parentComp;
this.rulesNeedApplying = rulesNeedApplying;
init(); init();
} }
@ -140,9 +140,18 @@ public class SystemPriorityTab {
priorityList = new List(priorityComp, SWT.BORDER | SWT.MULTI priorityList = new List(priorityComp, SWT.BORDER | SWT.MULTI
| SWT.V_SCROLL | SWT.H_SCROLL); | SWT.V_SCROLL | SWT.H_SCROLL);
priorityList.setLayoutData(gd); priorityList.setLayoutData(gd);
priorityList.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
if (priorityList.getSelectionCount() > 0) {
enableButtons(true);
} else {
enableButtons(false);
}
}
});
loadList(); loadList();
} }
/** /**
@ -168,6 +177,11 @@ public class SystemPriorityTab {
public void widgetSelected(SelectionEvent event) { public void widgetSelected(SelectionEvent event) {
create = true; create = true;
handlePriorityRule(); 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 = new Button(actionComp, SWT.PUSH);
editBtn.setText("Edit..."); editBtn.setText("Edit...");
editBtn.setLayoutData(btnData); editBtn.setLayoutData(btnData);
editBtn.setEnabled(true); editBtn.setEnabled(false);
editBtn.setToolTipText("Edit item selected in the list"); editBtn.setToolTipText("Edit item selected in the list");
editBtn.addSelectionListener(new SelectionAdapter() { editBtn.addSelectionListener(new SelectionAdapter() {
@Override @Override
public void widgetSelected(SelectionEvent event) { public void widgetSelected(SelectionEvent event) {
create = false; create = false;
int idx = priorityList.getSelectionIndex();
handlePriorityRule(); 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. * Handle create and edit rules.
*/ */
private void handlePriorityRule() { private void handlePriorityRule() {
final DataDeliveryPermission permission = DataDeliveryPermission.SYSTEM_MANAGEMENT_CREATE; final DataDeliveryPermission permission = DataDeliveryPermission.SYSTEM_MANAGEMENT_CREATE;
IUser user = UserController.getUserObject(); IUser user = UserController.getUserObject();
String msg = user.uniqueId() String msg = user.uniqueId() + notAuthorizedMsg + permission;
+ " is not authorized to create or edit rules using the"
+ " Data Delivery System Management\nPermission: " + permission;
DataDeliveryAuthRequest request = new DataDeliveryAuthRequest(); DataDeliveryAuthRequest request = new DataDeliveryAuthRequest();
request.setUser(user); request.setUser(user);
request.addRequestedPermissions(permission); request.addRequestedPermissions(permission);
@ -207,13 +240,11 @@ public class SystemPriorityTab {
.sendAuthorizationRequest(request); .sendAuthorizationRequest(request);
if (auth != null && auth.isAuthorized()) { if (auth != null && auth.isAuthorized()) {
if (ruleDlg == null || ruleDlg.isDisposed()) { if (ruleDlg == null || ruleDlg.isDisposed()) {
// New // New
if (create) { if (create) {
ruleDlg = new CreateEditRuleDlg(parentComp.getShell(), ruleDlg = new CreateEditRuleDlg(parentComp.getShell(),
create, PRIORITY_TYPE, rulesNeedApplying); create, PRIORITY_TYPE);
} else { } else {
// Edit // Edit
String ruleName = null; String ruleName = null;
@ -233,19 +264,16 @@ public class SystemPriorityTab {
return; return;
} }
ruleDlg = new CreateEditRuleDlg(parentComp.getShell(), ruleDlg = new CreateEditRuleDlg(parentComp.getShell(),
create, ruleName, PRIORITY_TYPE, create, ruleName, PRIORITY_TYPE);
rulesNeedApplying);
} }
boolean reloadFlag = (Boolean) ruleDlg.open(); boolean reloadFlag = (Boolean) ruleDlg.open();
if (reloadFlag) { if (reloadFlag) {
loadList(); loadList();
} }
} else { } else {
ruleDlg.bringToTop(); ruleDlg.bringToTop();
} }
} }
} catch (VizException e) { } catch (VizException e) {
statusHandler.handle(Priority.PROBLEM, 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. * Load the rule list.
*/ */
@ -261,27 +331,11 @@ public class SystemPriorityTab {
priorityList.removeAll(); priorityList.removeAll();
// Get the list of priority rule names // Get the list of priority rule names
String[] rules = null; java.util.List<String> rules = SystemRuleManager.getInstance()
try { .getPriorityRuleNames();
rules = SystemRuleManager.getInstance().getPriorityRules();
} catch (JAXBException e) {
statusHandler.handle(Priority.PROBLEM,
"Error occurred in loading rule list", e);
}
String[] ruleDisplayArray = null; Collections.sort(rules);
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);
priorityList.setItems(rules.toArray(new String[rules.size()]));
} }
} }

View file

@ -35,6 +35,7 @@ import org.eclipse.swt.widgets.Label;
* Date Ticket# Engineer Description * Date Ticket# Engineer Description
* ------------ ---------- ----------- -------------------------- * ------------ ---------- ----------- --------------------------
* Sep 17, 2012 730 jpiatt Initial creation. * Sep 17, 2012 730 jpiatt Initial creation.
* Jan 04, 2013 1420 mpduff Remove autoApply of rules.
* *
* </pre> * </pre>
* *
@ -46,21 +47,14 @@ public class SystemRoutingTab {
/** Parent Composite */ /** Parent Composite */
private final Composite parentComp; private final Composite parentComp;
private final IRulesNeedApplying rulesNeedApplying;
/** /**
* Constructor. * Constructor.
* *
* @param parentComp * @param parentComp
* The Composite holding these controls * The Composite holding these controls
*
* @param dataSet
* The DataSet object
*/ */
public SystemRoutingTab(Composite parentComp, public SystemRoutingTab(Composite parentComp) {
IRulesNeedApplying rulesNeedApplying) {
this.parentComp = parentComp; this.parentComp = parentComp;
this.rulesNeedApplying = rulesNeedApplying;
init(); init();
} }

View file

@ -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.
*
* <pre>
*
* 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.
*
* </pre>
*
* @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<Subscription> 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<Subscription> subscriptionsModified = new ArrayList<Subscription>();
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<Subscription> 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<Subscription> getMatchingSubscriptions(
SubscriptionRuleXML xml, List<Subscription> subscriptions) {
List<Subscription> modifyList = new ArrayList<Subscription>();
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<Subscription> 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);
}
}
}

View file

@ -21,6 +21,7 @@ package com.raytheon.uf.viz.datadelivery.system;
import java.io.File; import java.io.File;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List;
import java.util.Set; import java.util.Set;
import javax.xml.bind.JAXBContext; import javax.xml.bind.JAXBContext;
@ -28,9 +29,6 @@ import javax.xml.bind.JAXBException;
import javax.xml.bind.Marshaller; import javax.xml.bind.Marshaller;
import javax.xml.bind.Unmarshaller; 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.bandwidth.IBandwidthService;
import com.raytheon.uf.common.datadelivery.registry.Network; import com.raytheon.uf.common.datadelivery.registry.Network;
import com.raytheon.uf.common.datadelivery.registry.Subscription; 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.IUFStatusHandler;
import com.raytheon.uf.common.status.UFStatus; import com.raytheon.uf.common.status.UFStatus;
import com.raytheon.uf.common.status.UFStatus.Priority; import com.raytheon.uf.common.status.UFStatus.Priority;
import com.raytheon.uf.viz.datadelivery.subscription.xml.SubscriptionRuleXML; import com.raytheon.uf.viz.datadelivery.subscription.xml.LatencyRuleXML;
import com.raytheon.uf.viz.datadelivery.utils.DataDeliveryUtils; 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. * System Rule Manager.
@ -57,7 +62,8 @@ import com.raytheon.uf.viz.datadelivery.utils.DataDeliveryUtils;
* Date Ticket# Engineer Description * Date Ticket# Engineer Description
* ------------ ---------- ----------- -------------------------- * ------------ ---------- ----------- --------------------------
* Sep 17, 2012 730 jpiatt Initial creation. * 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.
* *
* </pre> * </pre>
* *
@ -67,13 +73,19 @@ import com.raytheon.uf.viz.datadelivery.utils.DataDeliveryUtils;
public class SystemRuleManager { public class SystemRuleManager {
/** SystemRuleManager instance */ /** SystemRuleManager instance */
private static SystemRuleManager instance = new SystemRuleManager(); private static final SystemRuleManager instance = new SystemRuleManager();
/** Directory Path to rules */ /** 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 */ /** Status Handler */
private final IUFStatusHandler statusHandler = UFStatus.getHandler(SystemRuleManager.class); private final IUFStatusHandler statusHandler = UFStatus
.getHandler(SystemRuleManager.class);
/** JAXB context */ /** JAXB context */
private JAXBContext jax; private JAXBContext jax;
@ -84,9 +96,6 @@ public class SystemRuleManager {
/** Unmarshaller object */ /** Unmarshaller object */
private Unmarshaller unmarshaller; private Unmarshaller unmarshaller;
/** Array of rule localization files */
private LocalizationFile[] ruleFiles;
private IBandwidthService bandwidthService; private IBandwidthService bandwidthService;
/** /**
@ -95,7 +104,7 @@ public class SystemRuleManager {
private SystemRuleManager() { private SystemRuleManager() {
createContext(); createContext();
} }
/** /**
* Get an instance of the SystemRuleManager. * Get an instance of the SystemRuleManager.
* *
@ -110,178 +119,74 @@ public class SystemRuleManager {
*/ */
@SuppressWarnings("rawtypes") @SuppressWarnings("rawtypes")
private void createContext() { 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 { try {
jax = JAXBContext.newInstance(classes); jax = JAXBContext.newInstance(classes);
this.unmarshaller = jax.createUnmarshaller(); this.unmarshaller = jax.createUnmarshaller();
this.marshaller = jax.createMarshaller(); this.marshaller = jax.createMarshaller();
this.marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); this.marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
} catch (JAXBException e) { } catch (Exception e) {
statusHandler.handle(Priority.ERROR, e.getLocalizedMessage(), e); statusHandler.handle(Priority.ERROR, e.getLocalizedMessage(), e);
} }
} }
/** /**
* Get priority file names * Get the names of the priority rules
* *
* @return String[] * @return String[] of names
* Array of priority rule names * @throws JAXBException
* @throws JAXBException
*/ */
public String[] getPriorityRules() throws JAXBException { public List<String> getPriorityRuleNames() {
return getPriorityRules().getRuleNames();
}
ArrayList<String> priorityList = new ArrayList<String>(); public PriorityRuleXML loadPriorityRule(String name) {
ruleFiles = getRules(); PriorityRulesXML priorityRules = getPriorityRules();
for (PriorityRuleXML rule : priorityRules.getRules()) {
//determine which are priority files if (rule.getRuleName().equals(name)) {
for (LocalizationFile lf : ruleFiles) { return rule;
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);
} }
} }
String[] priorityRules = null; return new PriorityRuleXML();
}
if (priorityList.size() > 0) { public LatencyRuleXML loadLatencyRule(String name) {
priorityRules = priorityList.toArray(new String[priorityList.size()]); LatencyRulesXML latencyRules = getLatencyRules();
for (LatencyRuleXML rule : latencyRules.getRules()) {
if (rule.getRuleName().equals(name)) {
return rule;
}
} }
return priorityRules; return new LatencyRuleXML();
} }
/** /**
* Get latency file names * Get latency file names
* *
* @return String[] * @return String[] Array of latency rule names
* Array of latency rule names * @throws JAXBException
* @throws JAXBException
*/ */
public String[] getLatencyRules() throws JAXBException { public List<String> getLatencyRuleNames() {
return getLatencyRules().getRuleNames();
ArrayList<String> latencyList = new ArrayList<String>();
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 boolean savePriorityRules(PriorityRulesXML xmlObj) {
* Get rule files
*
* @return String[]
* Array of latency rule names
* @throws JAXBException
*/
public LocalizationFile[] getRules() throws JAXBException {
IPathManager pm = PathManagerFactory.getPathManager(); IPathManager pm = PathManagerFactory.getPathManager();
LocalizationContext context = pm.getContext(LocalizationType.CAVE_STATIC, LocalizationLevel.USER); LocalizationContext context = pm.getContext(
String[] extensions = new String[] { "xml" }; LocalizationType.COMMON_STATIC, LocalizationLevel.SITE);
ruleFiles = pm.listFiles(context, RULE_PATH, extensions, false, true); LocalizationFile priorityRulesLocFile = pm.getLocalizationFile(context,
this.PRIORITY_RULE_FILE);
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;
}
}
try { try {
marshaller.marshal(rule, subscriptionRuleLocFile.getFile()); marshaller.marshal(xmlObj, priorityRulesLocFile.getFile());
subscriptionRuleLocFile.save(); priorityRulesLocFile.save();
return true; return true;
} catch (JAXBException e) { } catch (JAXBException e) {
statusHandler.handle(Priority.ERROR, e.getLocalizedMessage(), e); statusHandler.handle(Priority.ERROR, e.getLocalizedMessage(), e);
@ -292,6 +197,234 @@ public class SystemRuleManager {
return false; 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<Integer> 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<Integer> 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<Integer>(cycleTimes));
}
return latency;
}
/**
* Return the lowest priority value defined by the rules.
*
* @param sub
* @param cycleTimes
* @return
*/
public int getPriority(Subscription sub, Set<Integer> 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}. * Set the {@link IBandwidthService}.
* *

View file

@ -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.
*
* <pre>
*
* SOFTWARE HISTORY
*
* Date Ticket# Engineer Description
* ------------ ---------- ----------- --------------------------
* Jan 10, 2012 mpduff Initial creation
*
* </pre>
*
* @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;
}
}

View file

@ -25,6 +25,8 @@ import java.util.Date;
import java.util.TimeZone; import java.util.TimeZone;
import java.util.regex.Pattern; import java.util.regex.Pattern;
import javax.xml.bind.annotation.XmlEnumValue;
import org.eclipse.swt.SWT; import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.RGB; import org.eclipse.swt.graphics.RGB;
import org.eclipse.swt.widgets.Shell; 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 12, 2012 1391 bgonzale Added methods to manage when shells become busy for user interaction.
* Dec 17, 2012 1435 mpduff Fix ThreadLocal implementation. * Dec 17, 2012 1435 mpduff Fix ThreadLocal implementation.
* Dec 18, 2012 1439 mpduff Change Regex to match invalid chars. * Dec 18, 2012 1439 mpduff Change Regex to match invalid chars.
* Jan 04, 2013 1420 mpduff Change default priority to normal priority.
* *
* </pre> * </pre>
* *
@ -105,69 +108,16 @@ public class DataDeliveryGUIUtils {
/** Name Required Message */ /** Name Required Message */
public static final String NAME_REQUIRED_MESSAGE = "Name required.\nA Subscription Name must be entered."; 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 */ /** Enumeration to use for subscription priorities */
public static enum SubscriptionPriority { public static enum SubscriptionPriority {
/** High Priority */ /** High Priority */
@XmlEnumValue("High")
HIGH("High", 1, new RGB(255, 0, 0)), HIGH("High", 1, new RGB(255, 0, 0)),
/** Default Priority */ /** Default Priority */
DEFAULT("Default", 2, new RGB(0, 255, 0)), @XmlEnumValue("Normal")
NORMAL("Normal", 2, new RGB(0, 255, 0)),
/** Low Priority */ /** Low Priority */
@XmlEnumValue("Low")
LOW("Low", 3, new RGB(6, 122, 255)); LOW("Low", 3, new RGB(6, 122, 255));
/** Priority Setting */ /** 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;
}
} }

View file

@ -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.
*
* <pre>
*
* SOFTWARE HISTORY
*
* Date Ticket# Engineer Description
* ------------ ---------- ----------- --------------------------
* Jan 8, 2013 1420 mpduff Initial creation.
*
* </pre>
*
* @author mpduff
* @version 1.0
*/
public enum DataSetFrequency {
HOURLY, SIX_HOURLY;
private DataSetFrequency() {
}
public static DataSetFrequency fromCycleTimes(List<Integer> 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;
}
}

View file

@ -0,0 +1,194 @@
package com.raytheon.uf.viz.datadelivery.utils;
/**
* Enumeration for Data Size units and conversions.
*
* <pre>
*
* SOFTWARE HISTORY
*
* Date Ticket# Engineer Description
* ------------ ---------- ----------- --------------------------
* Jan 08, 2013 1420 mpduff Initial creation.
*
* </pre>
*
* @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);
}

View file

@ -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<String> {
/** 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;
}
}

View file

@ -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<String> {
/** 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;
}
}

View file

@ -0,0 +1,19 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<latencyRules>
<latencyRule>
<ruleField>Dataset Frequency</ruleField>
<ruleName>Hourly-Products</ruleName>
<ruleOperator>&lt;=</ruleOperator>
<ruleUnit>Hrs</ruleUnit>
<ruleValue>1</ruleValue>
<latency>40</latency>
</latencyRule>
<latencyRule>
<ruleField>Dataset Frequency</ruleField>
<ruleName>MultiHour-Products</ruleName>
<ruleOperator>&gt;</ruleOperator>
<ruleUnit>Hrs</ruleUnit>
<ruleValue>1</ruleValue>
<latency>115</latency>
</latencyRule>
</latencyRules>

View file

@ -348,4 +348,15 @@ public class CreateSubscriptionPresenterTest {
verify(view).setActiveEndDate( verify(view).setActiveEndDate(
argThat(yyyyMmDdMatches(expectedEndCalendar.getTime()))); argThat(yyyyMmDdMatches(expectedEndCalendar.getTime())));
} }
@Test
public void verifySubscriptionSetToView() {
verify(view).setSubscription(presenter.getSubscription());
}
@Test
public void verifyCycleTimesSetToView() {
verify(view).setCycleTimes(presenter.cycleTimes);
}
} }

View file

@ -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}
*
* <pre>
*
* SOFTWARE HISTORY
*
* Date Ticket# Engineer Description
* ------------ ---------- ----------- --------------------------
* Jan 3, 2013 1420 mpduff Initial creation.
*
* </pre>
*
* @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<Integer> cycles = new TreeSet<Integer>();
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<Integer> cycles = new TreeSet<Integer>();
cycles.add(0);
cycles.add(1);
assertTrue("Matches Dataset Frequency Minutes Equals Failed",
rule.matches(sub, cycles));
}
}

View file

@ -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}.
*
* <pre>
*
* SOFTWARE HISTORY
*
* Date Ticket# Engineer Description
* ------------ ---------- ----------- --------------------------
* 01/04/2013 1420 mpduff Initial Creation.
* </pre>
*
* @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));
}
}

View file

@ -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}
*
* <pre>
*
* SOFTWARE HISTORY
*
* Date Ticket# Engineer Description
* ------------ ---------- ----------- --------------------------
* Jan 8, 2013 1420 mpduff Initial creation
*
* </pre>
*
* @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)));
}
}