Issue #1420 - More Rules changes.

Peer review comments

Change-Id: I3ed89b332764bba2d995a248e361d20c1eec6edf

Former-commit-id: 1df1b5a94d [formerly 2a31447d6d] [formerly 1df1b5a94d [formerly 2a31447d6d] [formerly 8d0a79703f [formerly 84f2d0ed39e11059359558676c988a0bf1e989b9]]]
Former-commit-id: 8d0a79703f
Former-commit-id: 72a70a6eaf [formerly c6924b6920]
Former-commit-id: 7a750e72e3
This commit is contained in:
Mike Duff 2013-01-16 12:24:37 -06:00
parent 90d7ef6fc3
commit fc87600adb
10 changed files with 319 additions and 113 deletions

View file

@ -27,8 +27,6 @@ import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement; import javax.xml.bind.annotation.XmlElement;
import com.raytheon.uf.common.datadelivery.registry.Subscription; 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.viz.datadelivery.system.CreateEditRuleDlg.FreqUnitOptions; import com.raytheon.uf.viz.datadelivery.system.CreateEditRuleDlg.FreqUnitOptions;
import com.raytheon.uf.viz.datadelivery.system.Operator; import com.raytheon.uf.viz.datadelivery.system.Operator;
import com.raytheon.uf.viz.datadelivery.system.OpsNetFieldNames; import com.raytheon.uf.viz.datadelivery.system.OpsNetFieldNames;
@ -54,11 +52,6 @@ import com.raytheon.uf.viz.datadelivery.utils.DataSizeUnit;
@SuppressWarnings({ "unchecked", "rawtypes" }) @SuppressWarnings({ "unchecked", "rawtypes" })
@XmlAccessorType(XmlAccessType.NONE) @XmlAccessorType(XmlAccessType.NONE)
public abstract class RuleXML { public abstract class RuleXML {
/** Status Handler */
private final IUFStatusHandler statusHandler = UFStatus
.getHandler(RuleXML.class);
/** Rule name */ /** Rule name */
@XmlElement @XmlElement
protected String ruleName; protected String ruleName;

View file

@ -19,6 +19,7 @@
**/ **/
package com.raytheon.uf.viz.datadelivery.system; package com.raytheon.uf.viz.datadelivery.system;
import java.util.List;
import java.util.regex.Pattern; import java.util.regex.Pattern;
import org.eclipse.swt.SWT; import org.eclipse.swt.SWT;
@ -227,6 +228,9 @@ public class CreateEditRuleDlg extends CaveSWTDialog {
this(parent, create, null, ruleType); this(parent, create, null, ruleType);
} }
/**
* Create the rule header.
*/
private void createRuleHeader() { private void createRuleHeader() {
if (create) { if (create) {
if (PRIORITY_TYPE.equals(ruleType)) { if (PRIORITY_TYPE.equals(ruleType)) {
@ -269,9 +273,9 @@ public class CreateEditRuleDlg extends CaveSWTDialog {
protected void initializeComponents(Shell shell) { protected void initializeComponents(Shell shell) {
if (!create) { if (!create) {
if (PRIORITY_TYPE.equals(ruleType)) { if (PRIORITY_TYPE.equals(ruleType)) {
ruleXml = srm.loadPriorityRule(ruleName); ruleXml = srm.getPriorityRule(ruleName);
} else { } else {
ruleXml = srm.loadLatencyRule(ruleName); ruleXml = srm.getLatencyRule(ruleName);
} }
if (DATASET_SIZE.equals(ruleXml.getRuleField())) { if (DATASET_SIZE.equals(ruleXml.getRuleField())) {
@ -411,7 +415,6 @@ public class CreateEditRuleDlg extends CaveSWTDialog {
String item = fieldCombo.getItem(index); String item = fieldCombo.getItem(index);
updateSelectionFields(item); updateSelectionFields(item);
} }
}); });
OpsNetFieldNames[] fieldItems = OpsNetFieldNames.values(); OpsNetFieldNames[] fieldItems = OpsNetFieldNames.values();
@ -450,7 +453,6 @@ public class CreateEditRuleDlg extends CaveSWTDialog {
createFreqUnitItems(); createFreqUnitItems();
} }
unitsCombo.select(0); unitsCombo.select(0);
} }
if (PRIORITY_TYPE.equals(ruleType)) { if (PRIORITY_TYPE.equals(ruleType)) {
@ -481,7 +483,6 @@ public class CreateEditRuleDlg extends CaveSWTDialog {
} }
priorityCombo.select(0); priorityCombo.select(0);
} else { } else {
gd = new GridData(SWT.FILL, SWT.DEFAULT, true, false); gd = new GridData(SWT.FILL, SWT.DEFAULT, true, false);
gl = new GridLayout(3, false); gl = new GridLayout(3, false);
@ -507,19 +508,16 @@ public class CreateEditRuleDlg extends CaveSWTDialog {
Label minutesLbl = new Label(latencySelectionComp, SWT.NONE); Label minutesLbl = new Label(latencySelectionComp, SWT.NONE);
minutesLbl.setLayoutData(gd); minutesLbl.setLayoutData(gd);
minutesLbl.setText("Minutes"); minutesLbl.setText("Minutes");
} }
populateFields(); populateFields();
ruleDefinitionGroup.pack(); ruleDefinitionGroup.pack();
} }
/** /**
* Upon edit, populate the fields. * Upon edit, populate the fields.
*/ */
private void populateFields() { private void populateFields() {
if (!create) { if (!create) {
String field = ruleXml.getRuleField(); String field = ruleXml.getRuleField();
if (!field.isEmpty()) { if (!field.isEmpty()) {
@ -602,7 +600,6 @@ public class CreateEditRuleDlg extends CaveSWTDialog {
close(); close();
} }
}); });
} }
/** /**
@ -651,6 +648,13 @@ public class CreateEditRuleDlg extends CaveSWTDialog {
Operator operator = OperatorAdapter.fromString(operationCombo Operator operator = OperatorAdapter.fromString(operationCombo
.getItem(operationCombo.getSelectionIndex())); .getItem(operationCombo.getSelectionIndex()));
List<String> ruleNames = null;
if (PRIORITY_TYPE.equals(ruleType)) {
ruleNames = srm.getPriorityRuleNames();
} else {
ruleNames = srm.getLatencyRuleNames();
}
if (create) { if (create) {
valid = DataDeliveryGUIUtils.hasText(ruleNameText); valid = DataDeliveryGUIUtils.hasText(ruleNameText);
@ -663,13 +667,29 @@ public class CreateEditRuleDlg extends CaveSWTDialog {
} }
ruleName = ruleNameText.getText(); ruleName = ruleNameText.getText();
if (INVALID_PATTERN.matcher(ruleName.trim()).find()) {
DataDeliveryUtils.showMessage(getShell(), SWT.ERROR,
INVALID_CHARS_TITLE, INVALID_CHARS_MESSAGE);
return false;
}
// Check for duplicate rule name
if (ruleNames.contains(ruleName)) {
DataDeliveryUtils
.showMessage(
shell,
SWT.ERROR,
"Duplicate Rule",
"A rule titled "
+ ruleName
+ " already exists.\n\nPlease select a different name.");
ruleNameText.selectAll();
return false;
}
} }
if (INVALID_PATTERN.matcher(ruleName.trim()).find()) {
DataDeliveryUtils.showMessage(getShell(), SWT.ERROR,
INVALID_CHARS_TITLE, INVALID_CHARS_MESSAGE);
return false;
}
String value = null; String value = null;
if (DataDeliveryGUIUtils.hasText(ruleValue)) { if (DataDeliveryGUIUtils.hasText(ruleValue)) {
value = ruleValue.getText(); value = ruleValue.getText();
@ -770,21 +790,12 @@ public class CreateEditRuleDlg extends CaveSWTDialog {
} }
setReturnValue(saved); 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; return saved;
} }
/**
* Populate the units combo.
*/
private void createSizeUnitItems() { private void createSizeUnitItems() {
unitsCombo.removeAll(); unitsCombo.removeAll();
DataSizeUnit[] sizeUnits = DataSizeUnit.values(); DataSizeUnit[] sizeUnits = DataSizeUnit.values();
@ -793,6 +804,9 @@ public class CreateEditRuleDlg extends CaveSWTDialog {
} }
} }
/**
* Populate the operation combo.
*/
private void createSizeOpItems() { private void createSizeOpItems() {
operationCombo.removeAll(); operationCombo.removeAll();
OperatorTypes[] sizeOps = OperatorTypes.values(); OperatorTypes[] sizeOps = OperatorTypes.values();
@ -801,6 +815,9 @@ public class CreateEditRuleDlg extends CaveSWTDialog {
} }
} }
/**
* Populate the frequency units combo.
*/
private void createFreqUnitItems() { private void createFreqUnitItems() {
FreqUnitOptions[] freqUnits = FreqUnitOptions.values(); FreqUnitOptions[] freqUnits = FreqUnitOptions.values();
for (FreqUnitOptions fuo : freqUnits) { for (FreqUnitOptions fuo : freqUnits) {
@ -808,6 +825,9 @@ public class CreateEditRuleDlg extends CaveSWTDialog {
} }
} }
/**
* populate the operation combo.
*/
private void createNameOpItems() { private void createNameOpItems() {
operationCombo.removeAll(); operationCombo.removeAll();
NameOperationItems[] nameOperation = NameOperationItems.values(); NameOperationItems[] nameOperation = NameOperationItems.values();

View file

@ -0,0 +1,44 @@
/**
* 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;
/**
* Rules file update notifier interface.
*
* <pre>
*
* SOFTWARE HISTORY
*
* Date Ticket# Engineer Description
* ------------ ---------- ----------- --------------------------
* Jan 16, 2013 1420 mpduff Initial creation
*
* </pre>
*
* @author mpduff
* @version 1.0
*/
public interface IRulesUpdateListener {
/**
* Update rules.
*/
void update();
}

View file

@ -263,10 +263,7 @@ public class SystemLatencyTab {
ruleDlg = new CreateEditRuleDlg(parentComp.getShell(), ruleDlg = new CreateEditRuleDlg(parentComp.getShell(),
create, ruleName, LATENCY_TYPE); create, ruleName, LATENCY_TYPE);
} }
boolean reloadFlag = (Boolean) ruleDlg.open(); ruleDlg.open();
if (reloadFlag) {
loadList();
}
} else { } else {
ruleDlg.bringToTop(); ruleDlg.bringToTop();
} }

View file

@ -45,6 +45,7 @@ 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.core.VizApp;
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;
@ -71,7 +72,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,
IForceApplyPromptDisplayText { IForceApplyPromptDisplayText, IRulesUpdateListener {
/** Status Handler */ /** Status Handler */
private final IUFStatusHandler statusHandler = UFStatus private final IUFStatusHandler statusHandler = UFStatus
@ -128,10 +129,18 @@ public class SystemManagementDlg extends CaveSWTDialog implements IDisplay,
/** OK button */ /** OK button */
private Button okBtn; private Button okBtn;
/** Available bandwidth modified flag */
private boolean availableBandwidthModified; private boolean availableBandwidthModified;
/** Available bandwidth spinner widget */
private Spinner availBandwidthSpinner; private Spinner availBandwidthSpinner;
/** The system latency tab */
private SystemLatencyTab lTab;
/** The system priority tab */
private SystemPriorityTab pTab;
/** /**
* Constructor. * Constructor.
* *
@ -141,6 +150,7 @@ public class SystemManagementDlg extends CaveSWTDialog implements IDisplay,
public SystemManagementDlg(Shell parent) { public SystemManagementDlg(Shell parent) {
super(parent, SWT.DIALOG_TRIM, CAVE.NONE); super(parent, SWT.DIALOG_TRIM, CAVE.NONE);
setText("Data Delivery System Management"); setText("Data Delivery System Management");
SystemRuleManager.getInstance().registerAsListener(this);
} }
@ -181,6 +191,17 @@ public class SystemManagementDlg extends CaveSWTDialog implements IDisplay,
} }
/*
* (non-Javadoc)
*
* @see com.raytheon.viz.ui.dialogs.CaveSWTDialogBase#disposed()
*/
@Override
protected void disposed() {
super.disposed();
SystemRuleManager.getInstance().deregisterAsListener(this);
}
/** /**
* Create top bar route information. * Create top bar route information.
*/ */
@ -283,7 +304,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); 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);
@ -296,7 +317,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); 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);
@ -309,6 +330,9 @@ public class SystemManagementDlg extends CaveSWTDialog implements IDisplay,
routingComp.setLayoutData(gd); routingComp.setLayoutData(gd);
routingTab.setControl(routingComp); routingTab.setControl(routingComp);
SystemRoutingTab rTab = new SystemRoutingTab(routingComp); SystemRoutingTab rTab = new SystemRoutingTab(routingComp);
lTab.loadList();
pTab.loadList();
} }
/** /**
@ -466,4 +490,17 @@ public class SystemManagementDlg extends CaveSWTDialog implements IDisplay,
"Don't know how to handle option [" + option + "]"); "Don't know how to handle option [" + option + "]");
} }
} }
@Override
public void update() {
VizApp.runAsync(new Runnable() {
@Override
public void run() {
if (!shell.isDisposed()) {
lTab.loadList();
pTab.loadList();
}
}
});
}
} }

View file

@ -268,10 +268,7 @@ public class SystemPriorityTab {
create, ruleName, PRIORITY_TYPE); create, ruleName, PRIORITY_TYPE);
} }
boolean reloadFlag = (Boolean) ruleDlg.open(); ruleDlg.open();
if (reloadFlag) {
loadList();
}
} else { } else {
ruleDlg.bringToTop(); ruleDlg.bringToTop();
} }

View file

@ -32,6 +32,8 @@ import javax.xml.bind.Unmarshaller;
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;
import com.raytheon.uf.common.localization.FileUpdatedMessage;
import com.raytheon.uf.common.localization.ILocalizationFileObserver;
import com.raytheon.uf.common.localization.IPathManager; import com.raytheon.uf.common.localization.IPathManager;
import com.raytheon.uf.common.localization.LocalizationContext; import com.raytheon.uf.common.localization.LocalizationContext;
import com.raytheon.uf.common.localization.LocalizationContext.LocalizationLevel; import com.raytheon.uf.common.localization.LocalizationContext.LocalizationLevel;
@ -89,6 +91,12 @@ public class SystemRuleManager {
private final IUFStatusHandler statusHandler = UFStatus private final IUFStatusHandler statusHandler = UFStatus
.getHandler(SystemRuleManager.class); .getHandler(SystemRuleManager.class);
/** Latency Rules Localization File */
private LocalizationFile latencyRulesLocFile;
/** Priority Rules Localization File */
private LocalizationFile priorityRulesLocFile;
/** JAXB context */ /** JAXB context */
private JAXBContext jax; private JAXBContext jax;
@ -101,11 +109,21 @@ public class SystemRuleManager {
/** Bandwidth service */ /** Bandwidth service */
private IBandwidthService bandwidthService; private IBandwidthService bandwidthService;
/** Latency Rules XML object */
private LatencyRulesXML latencyRules;
/** Priority Rules XML object */
private PriorityRulesXML priorityRules;
private final List<IRulesUpdateListener> listeners = new ArrayList<IRulesUpdateListener>();
/** /**
* Constructor. * Constructor.
*/ */
private SystemRuleManager() { private SystemRuleManager() {
createContext(); createContext();
loadLatencyRules();
loadPriorityRules();
} }
/** /**
@ -144,7 +162,7 @@ public class SystemRuleManager {
* @throws JAXBException * @throws JAXBException
*/ */
public List<String> getPriorityRuleNames() { public List<String> getPriorityRuleNames() {
return getPriorityRules().getRuleNames(); return getPriorityRules(false).getRuleNames();
} }
/** /**
@ -154,8 +172,8 @@ public class SystemRuleManager {
* the name of the rule * the name of the rule
* @return the PriorityRuleXML object * @return the PriorityRuleXML object
*/ */
public PriorityRuleXML loadPriorityRule(String name) { public PriorityRuleXML getPriorityRule(String name) {
PriorityRulesXML priorityRules = getPriorityRules(); PriorityRulesXML priorityRules = getPriorityRules(false);
for (PriorityRuleXML rule : priorityRules.getRules()) { for (PriorityRuleXML rule : priorityRules.getRules()) {
if (rule.getRuleName().equals(name)) { if (rule.getRuleName().equals(name)) {
return rule; return rule;
@ -172,8 +190,8 @@ public class SystemRuleManager {
* the name of the rule * the name of the rule
* @return the LatencyRuleXML object * @return the LatencyRuleXML object
*/ */
public LatencyRuleXML loadLatencyRule(String name) { public LatencyRuleXML getLatencyRule(String name) {
LatencyRulesXML latencyRules = getLatencyRules(); LatencyRulesXML latencyRules = getLatencyRules(false);
for (LatencyRuleXML rule : latencyRules.getRules()) { for (LatencyRuleXML rule : latencyRules.getRules()) {
if (rule.getRuleName().equals(name)) { if (rule.getRuleName().equals(name)) {
return rule; return rule;
@ -190,7 +208,7 @@ public class SystemRuleManager {
* @throws JAXBException * @throws JAXBException
*/ */
public List<String> getLatencyRuleNames() { public List<String> getLatencyRuleNames() {
return getLatencyRules().getRuleNames(); return getLatencyRules(false).getRuleNames();
} }
/** /**
@ -203,15 +221,22 @@ public class SystemRuleManager {
public boolean savePriorityRules(PriorityRulesXML xmlObj) { public boolean savePriorityRules(PriorityRulesXML xmlObj) {
IPathManager pm = PathManagerFactory.getPathManager(); IPathManager pm = PathManagerFactory.getPathManager();
LocalizationContext context = pm.getContext(
LocalizationType.COMMON_STATIC, LocalizationLevel.SITE);
LocalizationFile priorityRulesLocFile = pm.getLocalizationFile(context,
this.PRIORITY_RULE_FILE);
try { try {
marshaller.marshal(xmlObj, priorityRulesLocFile.getFile()); // If site, then write out, otherwise save it as site.
priorityRulesLocFile.save(); if (priorityRulesLocFile.getContext().getLocalizationLevel()
return true; .equals(LocalizationLevel.SITE)) {
marshaller.marshal(xmlObj, priorityRulesLocFile.getFile());
return priorityRulesLocFile.save();
} else {
LocalizationContext context = pm.getContext(
LocalizationType.COMMON_STATIC, LocalizationLevel.SITE);
priorityRulesLocFile = pm.getLocalizationFile(context,
this.PRIORITY_RULE_FILE);
addPriorityRulesFileObserver();
marshaller.marshal(xmlObj, priorityRulesLocFile.getFile());
return priorityRulesLocFile.save();
}
} catch (JAXBException e) { } catch (JAXBException e) {
statusHandler.handle(Priority.ERROR, e.getLocalizedMessage(), e); statusHandler.handle(Priority.ERROR, e.getLocalizedMessage(), e);
} catch (LocalizationOpFailedException e) { } catch (LocalizationOpFailedException e) {
@ -231,15 +256,22 @@ public class SystemRuleManager {
public boolean saveLatencyRules(LatencyRulesXML xmlObj) { public boolean saveLatencyRules(LatencyRulesXML xmlObj) {
IPathManager pm = PathManagerFactory.getPathManager(); IPathManager pm = PathManagerFactory.getPathManager();
LocalizationContext context = pm.getContext(
LocalizationType.COMMON_STATIC, LocalizationLevel.SITE);
LocalizationFile latencyRulesLocFile = pm.getLocalizationFile(context,
this.LATENCY_RULE_FILE);
try { try {
marshaller.marshal(xmlObj, latencyRulesLocFile.getFile()); // If site, then write out, otherwise save it as site.
latencyRulesLocFile.save(); if (latencyRulesLocFile.getContext().getLocalizationLevel()
return true; .equals(LocalizationLevel.SITE)) {
marshaller.marshal(xmlObj, latencyRulesLocFile.getFile());
return latencyRulesLocFile.save();
} else {
LocalizationContext context = pm.getContext(
LocalizationType.COMMON_STATIC, LocalizationLevel.SITE);
latencyRulesLocFile = pm.getLocalizationFile(context,
this.LATENCY_RULE_FILE);
addLatencyRulesFileObserver();
marshaller.marshal(xmlObj, latencyRulesLocFile.getFile());
return latencyRulesLocFile.save();
}
} catch (JAXBException e) { } catch (JAXBException e) {
statusHandler.handle(Priority.ERROR, e.getLocalizedMessage(), e); statusHandler.handle(Priority.ERROR, e.getLocalizedMessage(), e);
} catch (LocalizationOpFailedException e) { } catch (LocalizationOpFailedException e) {
@ -256,7 +288,7 @@ public class SystemRuleManager {
* the rule name to delete * the rule name to delete
*/ */
public void deleteLatencyRule(String ruleName) { public void deleteLatencyRule(String ruleName) {
LatencyRulesXML latencyRules = getLatencyRules(); LatencyRulesXML latencyRules = getLatencyRules(false);
for (LatencyRuleXML rule : latencyRules.getRules()) { for (LatencyRuleXML rule : latencyRules.getRules()) {
if (rule.getRuleName().equals(ruleName)) { if (rule.getRuleName().equals(ruleName)) {
@ -274,7 +306,7 @@ public class SystemRuleManager {
* the rule name to delete * the rule name to delete
*/ */
public void deletePriorityRule(String ruleName) { public void deletePriorityRule(String ruleName) {
PriorityRulesXML priorityRules = getPriorityRules(); PriorityRulesXML priorityRules = getPriorityRules(false);
for (PriorityRuleXML rule : priorityRules.getRules()) { for (PriorityRuleXML rule : priorityRules.getRules()) {
if (rule.getRuleName().equals(ruleName)) { if (rule.getRuleName().equals(ruleName)) {
@ -293,7 +325,7 @@ public class SystemRuleManager {
* @return true if updated * @return true if updated
*/ */
public boolean updateRule(LatencyRuleXML rule) { public boolean updateRule(LatencyRuleXML rule) {
LatencyRulesXML rulesXml = getLatencyRules(); LatencyRulesXML rulesXml = getLatencyRules(false);
boolean saved = rulesXml.updateRule(rule); boolean saved = rulesXml.updateRule(rule);
if (saved) { if (saved) {
return saveLatencyRules(rulesXml); return saveLatencyRules(rulesXml);
@ -310,7 +342,7 @@ public class SystemRuleManager {
* @return true if updated * @return true if updated
*/ */
public boolean updateRule(PriorityRuleXML rule) { public boolean updateRule(PriorityRuleXML rule) {
PriorityRulesXML rulesXml = getPriorityRules(); PriorityRulesXML rulesXml = getPriorityRules(false);
boolean saved = rulesXml.updateRule(rule); boolean saved = rulesXml.updateRule(rule);
if (saved) { if (saved) {
saved = savePriorityRules(rulesXml); saved = savePriorityRules(rulesXml);
@ -331,7 +363,7 @@ public class SystemRuleManager {
* @return true if updated * @return true if updated
*/ */
public boolean saveRule(PriorityRuleXML rule) { public boolean saveRule(PriorityRuleXML rule) {
PriorityRulesXML rulesXml = getPriorityRules(); PriorityRulesXML rulesXml = getPriorityRules(false);
boolean saved = rulesXml.addRule(rule); boolean saved = rulesXml.addRule(rule);
if (saved) { if (saved) {
saved = savePriorityRules(rulesXml); saved = savePriorityRules(rulesXml);
@ -352,7 +384,7 @@ public class SystemRuleManager {
* @return true if updated * @return true if updated
*/ */
public boolean saveRule(LatencyRuleXML rule) { public boolean saveRule(LatencyRuleXML rule) {
LatencyRulesXML rulesXml = getLatencyRules(); LatencyRulesXML rulesXml = getLatencyRules(false);
boolean saved = rulesXml.addRule(rule); boolean saved = rulesXml.addRule(rule);
if (saved) { if (saved) {
saved = saveLatencyRules(rulesXml); saved = saveLatencyRules(rulesXml);
@ -368,19 +400,23 @@ public class SystemRuleManager {
/** /**
* Get the latency rules. * Get the latency rules.
* *
* @param reread
* true to reread the file from disk
*
* @return The latency rules xml object * @return The latency rules xml object
*/ */
private LatencyRulesXML getLatencyRules() { private LatencyRulesXML getLatencyRules(boolean reread) {
LocalizationFile lfile = getRules(this.LATENCY_RULE_FILE); if (latencyRules == null || reread) {
if (this.latencyRulesLocFile != null
LatencyRulesXML latencyRules = new LatencyRulesXML(); && latencyRulesLocFile.exists()) {
if (lfile != null && lfile.exists()) { try {
try { latencyRules = (LatencyRulesXML) unmarshaller
latencyRules = (LatencyRulesXML) unmarshaller.unmarshal(lfile .unmarshal(latencyRulesLocFile.getFile());
.getFile()); } catch (JAXBException e) {
} catch (JAXBException e) { statusHandler.handle(Priority.ERROR,
statusHandler e.getLocalizedMessage(), e);
.handle(Priority.ERROR, e.getLocalizedMessage(), e); latencyRules = new LatencyRulesXML();
}
} }
} }
@ -390,34 +426,26 @@ public class SystemRuleManager {
/** /**
* Get the priority rules * Get the priority rules
* *
* @param reread
* true to reread the file from disk
*
* @return The priority rules xml object * @return The priority rules xml object
*/ */
private PriorityRulesXML getPriorityRules() { private PriorityRulesXML getPriorityRules(boolean reread) {
LocalizationFile lfile = getRules(this.PRIORITY_RULE_FILE); if (priorityRules == null || reread)
if (this.priorityRulesLocFile != null
PriorityRulesXML priorityRules = new PriorityRulesXML(); && priorityRulesLocFile.exists()) {
if (lfile != null && lfile.exists()) { try {
try { priorityRules = (PriorityRulesXML) unmarshaller
priorityRules = (PriorityRulesXML) unmarshaller.unmarshal(lfile .unmarshal(priorityRulesLocFile.getFile());
.getFile()); } catch (JAXBException e) {
} catch (JAXBException e) { statusHandler.handle(Priority.ERROR,
statusHandler e.getLocalizedMessage(), e);
.handle(Priority.ERROR, e.getLocalizedMessage(), e); priorityRules = new PriorityRulesXML();
}
} }
}
return priorityRules;
}
/** return priorityRules;
* Get the rules files
*
* @param name
* Rules file name to get
* @return The localization file
*/
private LocalizationFile getRules(String name) {
IPathManager pm = PathManagerFactory.getPathManager();
return pm.getStaticLocalizationFile(name);
} }
/** /**
@ -442,7 +470,7 @@ public class SystemRuleManager {
* @return * @return
*/ */
public int getLatency(Subscription sub, Set<Integer> cycleTimes) { public int getLatency(Subscription sub, Set<Integer> cycleTimes) {
LatencyRulesXML rulesXml = this.getLatencyRules(); LatencyRulesXML rulesXml = this.getLatencyRules(false);
int latency = 999; int latency = 999;
boolean found = false; boolean found = false;
for (LatencyRuleXML rule : rulesXml.getRules()) { for (LatencyRuleXML rule : rulesXml.getRules()) {
@ -471,7 +499,7 @@ public class SystemRuleManager {
* @return * @return
*/ */
public int getPriority(Subscription sub, Set<Integer> cycleTimes) { public int getPriority(Subscription sub, Set<Integer> cycleTimes) {
PriorityRulesXML rulesXml = this.getPriorityRules(); PriorityRulesXML rulesXml = this.getPriorityRules(false);
int priority = 3; int priority = 3;
boolean found = false; boolean found = false;
for (PriorityRuleXML rule : rulesXml.getRules()) { for (PriorityRuleXML rule : rulesXml.getRules()) {
@ -546,4 +574,87 @@ public class SystemRuleManager {
return getInstance().bandwidthService return getInstance().bandwidthService
.setBandwidthForNetworkInKilobytes(network, bandwidth); .setBandwidthForNetworkInKilobytes(network, bandwidth);
} }
/**
* Read the latency rules file.
*/
private void loadLatencyRules() {
IPathManager pm = PathManagerFactory.getPathManager();
this.latencyRulesLocFile = pm
.getStaticLocalizationFile(this.LATENCY_RULE_FILE);
addLatencyRulesFileObserver();
getLatencyRules(true);
}
/**
* Load the priority rules file.
*/
private void loadPriorityRules() {
IPathManager pm = PathManagerFactory.getPathManager();
this.priorityRulesLocFile = pm
.getStaticLocalizationFile(this.PRIORITY_RULE_FILE);
addPriorityRulesFileObserver();
getPriorityRules(true);
}
/**
* Add a file observer to the latency rules file to get notified when the
* file changes.
*/
private void addLatencyRulesFileObserver() {
latencyRulesLocFile
.addFileUpdatedObserver(new ILocalizationFileObserver() {
@Override
public void fileUpdated(FileUpdatedMessage message) {
loadLatencyRules();
fireUpdates();
}
});
}
/**
* Add a file observer to the priority rules file to get notified when the
* file changes.
*/
private void addPriorityRulesFileObserver() {
priorityRulesLocFile
.addFileUpdatedObserver(new ILocalizationFileObserver() {
@Override
public void fileUpdated(FileUpdatedMessage message) {
loadPriorityRules();
fireUpdates();
}
});
}
/**
* Notify the listeners the files changed.
*/
private void fireUpdates() {
for (IRulesUpdateListener listener : listeners) {
listener.update();
}
}
/**
* Register as a listener for rules file changes.
*
* @param listener
*/
public void registerAsListener(IRulesUpdateListener listener) {
if (!listeners.contains(listener)) {
listeners.add(listener);
}
}
/**
* Unregister as a listener for rules files changed.
*
* @param listener
*/
public void deregisterAsListener(IRulesUpdateListener listener) {
if (listeners.contains(listener)) {
listeners.remove(listener);
}
}
} }

View file

@ -1,19 +1,19 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?> <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<latencyRules> <latencyRules>
<latencyRule> <rule xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="latencyRuleXML">
<ruleField>Dataset Frequency</ruleField> <ruleField>Dataset Frequency</ruleField>
<ruleName>Hourly-Products</ruleName> <ruleName>Hourly-Products</ruleName>
<ruleOperator>&lt;=</ruleOperator> <ruleOperator>&lt;=</ruleOperator>
<ruleUnit>Hrs</ruleUnit> <ruleUnit>Hrs</ruleUnit>
<ruleValue>1</ruleValue> <ruleValue>1</ruleValue>
<latency>40</latency> <latency>40</latency>
</latencyRule> </rule>
<latencyRule> <rule xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="latencyRuleXML">
<ruleField>Dataset Frequency</ruleField> <ruleField>Dataset Frequency</ruleField>
<ruleName>MultiHour-Products</ruleName> <ruleName>MultiHour-Products</ruleName>
<ruleOperator>&gt;</ruleOperator> <ruleOperator>&gt;</ruleOperator>
<ruleUnit>Hrs</ruleUnit> <ruleUnit>Hrs</ruleUnit>
<ruleValue>1</ruleValue> <ruleValue>1</ruleValue>
<latency>115</latency> <latency>115</latency>
</latencyRule> </rule>
</latencyRules> </latencyRules>

View file

@ -0,0 +1,4 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<priorityRules>
</priorityRules>

View file

@ -89,6 +89,8 @@
<permission id="com.raytheon.localization.site/common_static/roles"> <permission id="com.raytheon.localization.site/common_static/roles">
</permission> </permission>
<permission id="com.raytheon.localization.site/common_static/datadelivery"/>
<user userId="ALL"> <user userId="ALL">
<userPermission>com.raytheon.localization.site/common_static/purge</userPermission> <userPermission>com.raytheon.localization.site/common_static/purge</userPermission>
<userPermission>com.raytheon.localization.site/cave_static/colormaps</userPermission> <userPermission>com.raytheon.localization.site/cave_static/colormaps</userPermission>
@ -119,6 +121,7 @@
<userPermission>com.raytheon.localization.site/common_static/radar/rmr/rmrAvailableRequests.xml</userPermission> <userPermission>com.raytheon.localization.site/common_static/radar/rmr/rmrAvailableRequests.xml</userPermission>
<userPermission>com.raytheon.localization.site/common_static/shef</userPermission> <userPermission>com.raytheon.localization.site/common_static/shef</userPermission>
<userPermission>com.raytheon.localization.site/common_static/roles</userPermission> <userPermission>com.raytheon.localization.site/common_static/roles</userPermission>
<userPermission>com.raytheon.localization.site/common_static/datadelivery</userPermission>
</user> </user>
</nwsRoleData> </nwsRoleData>