Issue #1441 Cleaned up editing/deleting groups and handling of user permissions

Amend:
  Split creation and edit group dialogs.
  Add some javadoc and remove sysouts.
  Add missing test data causing broken tests.
  Rebased.

Change-Id: I00d48f2a97bf8398b74bf8ed568cb19126d2c185

Former-commit-id: 4ae1a9645c [formerly 797f570e28086b43b5d851275fba457c5920f57e]
Former-commit-id: 446f65776e
This commit is contained in:
Dustin Johnson 2013-01-08 13:12:46 -06:00
parent 7e4a0f1377
commit 64ececeda1
37 changed files with 2196 additions and 1073 deletions

View file

@ -4,17 +4,30 @@
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd">
<bean id="subscriptionService"
class="com.raytheon.uf.viz.datadelivery.subscription.SubscriptionService" />
<bean id="bandwidthService"
class="com.raytheon.uf.common.datadelivery.bandwidth.BandwidthService" />
<bean id="subscriptionNotificationService"
class="com.raytheon.uf.viz.datadelivery.subscription.SendToServerSubscriptionNotificationService" />
<bean id="permissionsService"
class="com.raytheon.uf.viz.datadelivery.subscription.RequestFromServerPermissionsService" />
<bean id="subscriptionService"
class="com.raytheon.uf.viz.datadelivery.subscription.SubscriptionService"
factory-method="newInstance">
<constructor-arg ref="subscriptionNotificationService" />
<constructor-arg ref="bandwidthService" />
<constructor-arg ref="permissionsService" />
</bean>
<bean name="dataDeliveryServices"
class="com.raytheon.uf.viz.datadelivery.services.DataDeliveryServices"
factory-method="getInstance">
<property name="subscriptionService" ref="subscriptionService" />
<property name="subscriptionNotificationService" ref="subscriptionNotificationService" />
<property name="bandwidthService" ref="bandwidthService" />
<property name="permissionsService" ref="permissionsService" />
</bean>
<bean id="systemRuleManager"

View file

@ -26,7 +26,6 @@ import org.eclipse.swt.widgets.Shell;
import org.eclipse.ui.PlatformUI;
import com.raytheon.uf.common.auth.user.IUser;
import com.raytheon.uf.common.datadelivery.request.DataDeliveryAuthRequest;
import com.raytheon.uf.common.datadelivery.request.DataDeliveryPermission;
import com.raytheon.uf.common.status.IUFStatusHandler;
import com.raytheon.uf.common.status.UFStatus;
@ -34,7 +33,7 @@ import com.raytheon.uf.common.status.UFStatus.Priority;
import com.raytheon.uf.viz.core.auth.UserController;
import com.raytheon.uf.viz.core.exception.VizException;
import com.raytheon.uf.viz.datadelivery.browser.DataBrowserDlg;
import com.raytheon.uf.viz.datadelivery.utils.DataDeliveryUtils;
import com.raytheon.uf.viz.datadelivery.services.DataDeliveryServices;
/**
* Action class. This is called when the Data Browser is selected from the CAVE
@ -72,19 +71,16 @@ public class DataBrowserAction extends AbstractHandler {
String msg = user.uniqueId()
+ " is not authorized to access the Dataset Discovery Browser\nPermission: "
+ permission;
DataDeliveryAuthRequest request = new DataDeliveryAuthRequest();
request.setUser(user);
request.addRequestedPermissions(permission);
request.setNotAuthorizedMessage(msg);
DataDeliveryAuthRequest response = DataDeliveryUtils.sendAuthorizationRequest(request);
if (response != null && response.isAuthorized()) {
if (DataDeliveryServices.getPermissionsService()
.checkPermission(user, msg, permission)
.isAuthorized()) {
if ((dlg == null) || (dlg.isDisposed() == true)) {
Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell();
Shell shell = PlatformUI.getWorkbench()
.getActiveWorkbenchWindow().getShell();
dlg = new DataBrowserDlg(shell);
dlg.open();
}
else {
} else {
dlg.bringToTop();
}
}

View file

@ -26,7 +26,6 @@ import org.eclipse.swt.widgets.Shell;
import org.eclipse.ui.PlatformUI;
import com.raytheon.uf.common.auth.user.IUser;
import com.raytheon.uf.common.datadelivery.request.DataDeliveryAuthRequest;
import com.raytheon.uf.common.datadelivery.request.DataDeliveryPermission;
import com.raytheon.uf.common.status.IUFStatusHandler;
import com.raytheon.uf.common.status.UFStatus;
@ -34,7 +33,7 @@ import com.raytheon.uf.common.status.UFStatus.Priority;
import com.raytheon.uf.viz.core.auth.UserController;
import com.raytheon.uf.viz.core.exception.VizException;
import com.raytheon.uf.viz.datadelivery.notification.NotificationDlg;
import com.raytheon.uf.viz.datadelivery.utils.DataDeliveryUtils;
import com.raytheon.uf.viz.datadelivery.services.DataDeliveryServices;
/**
* Notification Action to launch notification dialog.
@ -61,7 +60,7 @@ public class NotificationAction extends AbstractHandler {
/** Dialog instance */
private NotificationDlg dlg = null;
/** Permission string */
private final DataDeliveryPermission permission = DataDeliveryPermission.NOTIFICATION_VIEW;
@ -70,17 +69,15 @@ public class NotificationAction extends AbstractHandler {
try {
// Check if user is authorized
IUser user = UserController.getUserObject();
String msg = user.uniqueId() + " is not authorized to access the Notification Center\nPermission: " + permission;
DataDeliveryAuthRequest request = new DataDeliveryAuthRequest();
request.setUser(user);
request.addRequestedPermissions(permission);
request.setNotAuthorizedMessage(msg);
String msg = user.uniqueId()
+ " is not authorized to access the Notification Center\nPermission: "
+ permission;
DataDeliveryAuthRequest response = DataDeliveryUtils.sendAuthorizationRequest(request);
if (response != null && response.isAuthorized()) {
if (DataDeliveryServices.getPermissionsService()
.checkPermission(user, msg, permission).isAuthorized()) {
if ((dlg == null) || (dlg.isDisposed() == true)) {
Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow()
.getShell();
Shell shell = PlatformUI.getWorkbench()
.getActiveWorkbenchWindow().getShell();
dlg = new NotificationDlg(shell);
dlg.open();
} else {
@ -90,7 +87,7 @@ public class NotificationAction extends AbstractHandler {
} catch (VizException e) {
statusHandler.handle(Priority.PROBLEM, e.getLocalizedMessage(), e);
}
return null;
}
}

View file

@ -26,15 +26,14 @@ import org.eclipse.swt.widgets.Shell;
import org.eclipse.ui.PlatformUI;
import com.raytheon.uf.common.auth.user.IUser;
import com.raytheon.uf.common.datadelivery.request.DataDeliveryAuthRequest;
import com.raytheon.uf.common.datadelivery.request.DataDeliveryPermission;
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.core.auth.UserController;
import com.raytheon.uf.viz.core.exception.VizException;
import com.raytheon.uf.viz.datadelivery.services.DataDeliveryServices;
import com.raytheon.uf.viz.datadelivery.subscription.SubscriptionManagerDlg;
import com.raytheon.uf.viz.datadelivery.utils.DataDeliveryUtils;
/**
* Subscription Manager Dialog Action class.
@ -61,7 +60,7 @@ public class SubscriptionManagerAction extends AbstractHandler {
/** Dialog instance */
private SubscriptionManagerDlg dlg = null;
/** Permission String */
private final DataDeliveryPermission permission = DataDeliveryPermission.SUBSCRIPTION_VIEW;
@ -70,15 +69,15 @@ public class SubscriptionManagerAction extends AbstractHandler {
try {
// check if user is authorized
IUser user = UserController.getUserObject();
String msg = user.uniqueId() + " is not authorized to access Data Delivery\nPermission: " + permission;
DataDeliveryAuthRequest request = new DataDeliveryAuthRequest();
request.setUser(user);
request.addRequestedPermissions(permission);
request.setNotAuthorizedMessage(msg);
DataDeliveryAuthRequest response = DataDeliveryUtils.sendAuthorizationRequest(request);
if (response != null && response.isAuthorized()) {
String msg = user.uniqueId()
+ " is not authorized to access Data Delivery\nPermission: "
+ permission;
if (DataDeliveryServices.getPermissionsService()
.checkPermission(user, msg, permission).isAuthorized()) {
if ((dlg == null) || (dlg.isDisposed() == true)) {
Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell();
Shell shell = PlatformUI.getWorkbench()
.getActiveWorkbenchWindow().getShell();
dlg = new SubscriptionManagerDlg(shell);
dlg.open();
} else {

View file

@ -29,7 +29,6 @@ import org.eclipse.ui.PlatformUI;
import com.raytheon.uf.common.auth.user.IUser;
import com.raytheon.uf.common.datadelivery.registry.DataSet;
import com.raytheon.uf.common.datadelivery.request.DataDeliveryAuthRequest;
import com.raytheon.uf.common.datadelivery.request.DataDeliveryPermission;
import com.raytheon.uf.common.localization.LocalizationFile;
import com.raytheon.uf.common.status.IUFStatusHandler;
@ -40,10 +39,10 @@ import com.raytheon.uf.viz.core.exception.VizException;
import com.raytheon.uf.viz.datadelivery.common.ui.LoadSaveConfigDlg;
import com.raytheon.uf.viz.datadelivery.common.ui.LoadSaveConfigDlg.DialogType;
import com.raytheon.uf.viz.datadelivery.filter.MetaDataManager;
import com.raytheon.uf.viz.datadelivery.services.DataDeliveryServices;
import com.raytheon.uf.viz.datadelivery.subscription.subset.SubsetFileManager;
import com.raytheon.uf.viz.datadelivery.subscription.subset.SubsetManagerDlg;
import com.raytheon.uf.viz.datadelivery.subscription.subset.xml.SubsetXML;
import com.raytheon.uf.viz.datadelivery.utils.DataDeliveryUtils;
/**
* Handler for launching the Subset Manager Dialog.
@ -72,14 +71,15 @@ public class SubsetAction extends AbstractHandler {
.getHandler(SubsetAction.class);
/** Saved subset path */
private final String SUBSET_PATH = "dataDelivery" + File.separator + "subset" + File.separator;
private final String SUBSET_PATH = "dataDelivery" + File.separator
+ "subset" + File.separator;
/** Dialog instance */
private SubsetManagerDlg<?, ?, ?> dlg = null;
/** Dialog instance */
private LoadSaveConfigDlg loadDlg = null;
private final DataDeliveryPermission permission = DataDeliveryPermission.SUBSCRIPTION_EDIT;
@Override
@ -87,29 +87,29 @@ public class SubsetAction extends AbstractHandler {
try {
// Check subscription.edit permissions
IUser user = UserController.getUserObject();
String msg = user.uniqueId() + " is not authorized to edit subscriptions\nPermission: " + permission;
DataDeliveryAuthRequest request = new DataDeliveryAuthRequest();
request.setUser(user);
request.addRequestedPermissions(permission);
request.setNotAuthorizedMessage(msg);
DataDeliveryAuthRequest response = DataDeliveryUtils.sendAuthorizationRequest(request);
if (response != null && response.isAuthorized()) {
Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell();
String msg = user.uniqueId()
+ " is not authorized to edit subscriptions\nPermission: "
+ permission;
if (DataDeliveryServices.getPermissionsService()
.checkPermissions(user, msg, permission).isAuthorized()) {
Shell shell = PlatformUI.getWorkbench()
.getActiveWorkbenchWindow().getShell();
if (loadDlg == null || loadDlg.isDisposed()) {
loadDlg = new LoadSaveConfigDlg(shell, DialogType.OPEN, SUBSET_PATH, "", true);
loadDlg = new LoadSaveConfigDlg(shell, DialogType.OPEN,
SUBSET_PATH, "", true);
loadDlg.open();
} else {
loadDlg.bringToTop();
}
LocalizationFile locFile = (LocalizationFile) loadDlg.getReturnValue();
LocalizationFile locFile = (LocalizationFile) loadDlg
.getReturnValue();
if (locFile == null) {
return null;
}
SubsetXML<?> subset = SubsetFileManager.getInstance()
.loadSubset(locFile.getFile().getName());
DataSet data = MetaDataManager
.getInstance().getDataSet(
DataSet data = MetaDataManager.getInstance().getDataSet(
subset.getDatasetName(), subset.getProviderName());
if (dlg == null || dlg.isDisposed()) {

View file

@ -26,15 +26,14 @@ import org.eclipse.swt.widgets.Shell;
import org.eclipse.ui.PlatformUI;
import com.raytheon.uf.common.auth.user.IUser;
import com.raytheon.uf.common.datadelivery.request.DataDeliveryAuthRequest;
import com.raytheon.uf.common.datadelivery.request.DataDeliveryPermission;
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.core.auth.UserController;
import com.raytheon.uf.viz.core.exception.VizException;
import com.raytheon.uf.viz.datadelivery.services.DataDeliveryServices;
import com.raytheon.uf.viz.datadelivery.system.SystemManagementDlg;
import com.raytheon.uf.viz.datadelivery.utils.DataDeliveryUtils;
/**
* Handler for launching the System Management Dialog.
@ -56,8 +55,8 @@ import com.raytheon.uf.viz.datadelivery.utils.DataDeliveryUtils;
public class SystemManagementAction extends AbstractHandler {
/** Status Handler */
private final IUFStatusHandler statusHandler =
UFStatus.getHandler(SystemManagementAction.class);
private final IUFStatusHandler statusHandler = UFStatus
.getHandler(SystemManagementAction.class);
/** Dialog instance */
private SystemManagementDlg dlg;
@ -67,19 +66,15 @@ public class SystemManagementAction extends AbstractHandler {
final DataDeliveryPermission permission = DataDeliveryPermission.SYSTEM_MANAGEMENT_VIEW;
IUser user = UserController.getUserObject();
String msg =
user.uniqueId() + " is not authorized to view Data Delivery System Management\nPermission: "
+ permission;
DataDeliveryAuthRequest request = new DataDeliveryAuthRequest();
request.setUser(user);
request.addRequestedPermissions(permission);
request.setNotAuthorizedMessage(msg);
String msg = user.uniqueId()
+ " is not authorized to view Data Delivery System Management\nPermission: "
+ permission;
try {
DataDeliveryAuthRequest auth = DataDeliveryUtils.sendAuthorizationRequest(request);
if (auth != null && auth.isAuthorized()) {
Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell();
if (DataDeliveryServices.getPermissionsService()
.checkPermission(user, msg, permission).isAuthorized()) {
Shell shell = PlatformUI.getWorkbench()
.getActiveWorkbenchWindow().getShell();
if (dlg == null || dlg.isDisposed()) {
dlg = new SystemManagementDlg(shell);
@ -87,7 +82,7 @@ public class SystemManagementAction extends AbstractHandler {
} else {
dlg.bringToTop();
}
}
} catch (VizException e) {
statusHandler.handle(Priority.PROBLEM, e.getLocalizedMessage(), e);
@ -95,5 +90,5 @@ public class SystemManagementAction extends AbstractHandler {
return null;
}
}

View file

@ -57,7 +57,6 @@ import org.geotools.geometry.jts.ReferencedEnvelope;
import com.raytheon.uf.common.auth.user.IUser;
import com.raytheon.uf.common.datadelivery.registry.DataSet;
import com.raytheon.uf.common.datadelivery.registry.EnvelopeUtils;
import com.raytheon.uf.common.datadelivery.request.DataDeliveryAuthRequest;
import com.raytheon.uf.common.datadelivery.request.DataDeliveryPermission;
import com.raytheon.uf.common.localization.LocalizationFile;
import com.raytheon.uf.common.localization.exception.LocalizationOpFailedException;
@ -78,9 +77,9 @@ import com.raytheon.uf.viz.datadelivery.filter.MetaDataManager;
import com.raytheon.uf.viz.datadelivery.filter.config.FilterManager;
import com.raytheon.uf.viz.datadelivery.filter.config.xml.FilterSettingsXML;
import com.raytheon.uf.viz.datadelivery.filter.config.xml.FilterTypeXML;
import com.raytheon.uf.viz.datadelivery.services.DataDeliveryServices;
import com.raytheon.uf.viz.datadelivery.subscription.subset.SubsetManagerDlg;
import com.raytheon.uf.viz.datadelivery.utils.DataDeliveryGUIUtils;
import com.raytheon.uf.viz.datadelivery.utils.DataDeliveryUtils;
import com.raytheon.uf.viz.datadelivery.utils.DataDeliveryUtils.TABLE_TYPE;
import com.raytheon.viz.ui.dialogs.CaveSWTDialog;
import com.raytheon.viz.ui.widgets.duallist.DualList;
@ -636,14 +635,10 @@ public class DataBrowserDlg extends CaveSWTDialog implements IDataTableUpdate,
String msg = user.uniqueId()
+ " is not authorized to Create Subscriptions/Queries\nPermission: "
+ permission;
DataDeliveryAuthRequest request = new DataDeliveryAuthRequest();
request.setUser(user);
request.addRequestedPermissions(permission);
request.setNotAuthorizedMessage(msg);
try {
if (DataDeliveryUtils.sendAuthorizationRequest(request)
.isAuthorized()) {
if (DataDeliveryServices.getPermissionsService()
.checkPermission(user, msg, permission).isAuthorized()) {
DataSet data = dataTableComp.getSelectedDataset();

View file

@ -38,6 +38,7 @@ package com.raytheon.uf.viz.datadelivery.common.ui;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import com.raytheon.uf.viz.datadelivery.common.ui.SortImages.SortDirection;
import com.raytheon.uf.viz.datadelivery.utils.DataDeliveryUtils;
@ -48,7 +49,7 @@ public class TableDataManager<T extends ITableData<T>> implements ISortTable {
/**
* Array of data.
*/
private ArrayList<T> tableData;
private final ArrayList<T> tableData;
/**
* Column name.
@ -116,10 +117,8 @@ public class TableDataManager<T extends ITableData<T>> implements ISortTable {
* @param removeList
* The list of data to remove.
*/
public void removeAll(ArrayList<T> removeList) {
System.out.println(tableData.size() + " items");
public void removeAll(List<T> removeList) {
tableData.removeAll(removeList);
System.out.println(tableData.size() + " items2");
}
/**

View file

@ -22,8 +22,10 @@ package com.raytheon.uf.viz.datadelivery.common.ui;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
@ -34,35 +36,32 @@ import org.eclipse.swt.widgets.Combo;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Group;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Shell;
import com.raytheon.uf.common.auth.user.IUser;
import com.google.common.collect.Sets;
import com.raytheon.uf.common.datadelivery.registry.Coverage;
import com.raytheon.uf.common.datadelivery.registry.DataSet;
import com.raytheon.uf.common.datadelivery.registry.GriddedCoverage;
import com.raytheon.uf.common.datadelivery.registry.GroupDefinition;
import com.raytheon.uf.common.datadelivery.registry.InitialPendingSubscription;
import com.raytheon.uf.common.datadelivery.registry.PendingSubscription;
import com.raytheon.uf.common.datadelivery.registry.Subscription;
import com.raytheon.uf.common.datadelivery.registry.handlers.DataDeliveryHandlers;
import com.raytheon.uf.common.datadelivery.registry.handlers.IPendingSubscriptionHandler;
import com.raytheon.uf.common.datadelivery.registry.handlers.ISubscriptionHandler;
import com.raytheon.uf.common.datadelivery.request.DataDeliveryAuthRequest;
import com.raytheon.uf.common.datadelivery.request.DataDeliveryPermission;
import com.raytheon.uf.common.datadelivery.retrieval.util.DataSizeUtils;
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.core.auth.UserController;
import com.raytheon.uf.viz.core.exception.VizException;
import com.raytheon.uf.common.time.util.ITimer;
import com.raytheon.uf.common.time.util.TimeUtil;
import com.raytheon.uf.viz.core.localization.LocalizationManager;
import com.raytheon.uf.viz.datadelivery.filter.MetaDataManager;
import com.raytheon.uf.viz.datadelivery.services.DataDeliveryServices;
import com.raytheon.uf.viz.datadelivery.subscription.CancelForceApplyAndIncreaseLatencyDisplayText;
import com.raytheon.uf.viz.datadelivery.subscription.GroupDefinitionManager;
import com.raytheon.uf.viz.datadelivery.subscription.ISubscriptionService;
import com.raytheon.uf.viz.datadelivery.subscription.ISubscriptionService.ISubscriptionServiceResult;
import com.raytheon.uf.viz.datadelivery.subscription.SubscriptionService.ForceApplyPromptResponse;
import com.raytheon.uf.viz.datadelivery.subscription.SubscriptionService.IForceApplyPromptDisplayText;
import com.raytheon.uf.viz.datadelivery.utils.DataDeliveryUtils;
import com.raytheon.viz.ui.presenter.IDisplay;
import com.raytheon.viz.ui.widgets.duallist.DualList;
@ -99,7 +98,8 @@ import com.raytheon.viz.ui.widgets.duallist.IUpdate;
* @author jpiatt
* @version 1.0
*/
public class UserSelectComp extends Composite implements IUpdate, IDisplay {
public class UserSelectComp extends Composite implements IUpdate, IDisplay,
IForceApplyPromptDisplayText {
/** Status Handler */
private final IUFStatusHandler statusHandler = UFStatus
@ -133,12 +133,11 @@ public class UserSelectComp extends Composite implements IUpdate, IDisplay {
/** DualListConfig object */
private DualListConfig dualConfig;
/** Map to hold subscriptions */
private final Map<String, Map<String, Subscription>> addedMap = new HashMap<String, Map<String, Subscription>>();
/** map to hold user subscriptions */
private final Map<String, Map<String, Subscription>> userMap = new HashMap<String, Map<String, Subscription>>();
private final Set<String> initiallySelectedSubscriptions = new HashSet<String>();
/**
* Registry handler for pending subscriptions.
*/
@ -281,60 +280,82 @@ public class UserSelectComp extends Composite implements IUpdate, IDisplay {
* @param groupName
* The name of the group
*/
public void getSuscriptionNames(String groupName) {
public void getSubscriptionNames(String groupName) {
String owner = userNameCombo.getText();
Map<String, Subscription> ownerSubs = userMap.get(owner);
Map<String, Subscription> selectedSubs = null;
if (addedMap.containsKey(owner)) {
selectedSubs = addedMap.get(owner);
} else {
selectedSubs = new HashMap<String, Subscription>();
addedMap.put(owner, selectedSubs);
}
Set<String> selectedSubscriptionNames = Sets.newHashSet(dualList
.getSelectedListItems());
String[] selectedList = dualList.getSelectedListItems();
Set<String> differences = Sets.symmetricDifference(
selectedSubscriptionNames,
initiallySelectedSubscriptions);
// Clear list
selectedSubs.clear();
Set<Subscription> addedToGroup = new HashSet<Subscription>();
Set<Subscription> removedFromGroup = new HashSet<Subscription>();
// Re-add to list
for (String subName : selectedList) {
selectedSubs.put(subName, ownerSubs.get(subName));
}
if (selectedSubs != null) {
addedMap.put(owner, selectedSubs);
}
// Get subscriptions that use the modified group
List<Subscription> results = Collections.emptyList();
try {
results = subHandler.getByGroupName(groupName);
} catch (RegistryHandlerException e) {
statusHandler.handle(Priority.PROBLEM,
"Unable to retrieve subscriptions for group " + groupName,
e);
}
for (Subscription subscription : results) {
if (addedMap.containsKey(subscription.getOwner())) {
addedMap.get(subscription.getOwner()).put(
subscription.getName(), subscription);
for (String subscriptionName : differences) {
final Subscription subscription = ownerSubs.get(subscriptionName);
if (selectedSubscriptionNames.contains(subscriptionName)) {
addedToGroup.add(subscription);
} else {
HashMap<String, Subscription> ownerMap = new HashMap<String, Subscription>();
ownerMap.put(subscription.getName(), subscription);
addedMap.put(subscription.getOwner(), ownerMap);
removedFromGroup.add(subscription);
}
}
if (addedMap.size() > 0) {
populateSelectedSubscriptions(groupName);
updateGroupDefinition(groupName, addedToGroup, removedFromGroup);
}
/**
* Updates the group definition, the subscriptions added to the group, and
* the subscriptions removed from the group.
*
* @param groupName
* @param addedToGroup
* @param removedFromGroup
*/
private void updateGroupDefinition(String groupName,
Set<Subscription> addedToGroup, Set<Subscription> removedFromGroup) {
ITimer timer = TimeUtil.getPriorityEnabledTimer(statusHandler,
Priority.DEBUG);
timer.start();
for (Subscription subscription : removedFromGroup) {
subscription.setGroupName(GroupDefinition.NO_GROUP);
}
for (Subscription subscription : addedToGroup) {
subscription.setGroupName(groupName);
}
Set<Subscription> groupSubscriptionsForUpdate = Collections.emptySet();
try {
groupSubscriptionsForUpdate = new HashSet<Subscription>(
DataDeliveryHandlers.getSubscriptionHandler()
.getByGroupName(groupName));
// Remove any that are set to be removed from the group
groupSubscriptionsForUpdate.removeAll(removedFromGroup);
// Add those that are being added to the group
groupSubscriptionsForUpdate.addAll(addedToGroup);
} catch (RegistryHandlerException e) {
statusHandler.handle(Priority.PROBLEM,
"Unable to retrieve group subscriptions.", e);
}
updateGroupDefinitionForSubscriptions(groupName,
groupSubscriptionsForUpdate,
removedFromGroup);
timer.stop();
if (statusHandler.isPriorityEnabled(Priority.DEBUG)) {
statusHandler.debug("Took [" + timer.getElapsedTime()
+ "] to update group definition");
}
}
/**
@ -345,174 +366,83 @@ public class UserSelectComp extends Composite implements IUpdate, IDisplay {
* @param groupName
* The name of the group
*/
private void populateSelectedSubscriptions(String groupName) {
private void updateGroupDefinitionForSubscriptions(String groupName,
Set<Subscription> groupSubscriptions,
Set<Subscription> removeFromGroupSubscriptions) {
// Get Group Definition
GroupDefinition groupDefinition = GroupDefinitionManager
.getGroup(groupName);
// loop over hash map -- once over each hash map
for (String owner : addedMap.keySet()) {
for (Subscription subscription : groupSubscriptions) {
Map<String, Subscription> ownerMap = addedMap.get(owner);
// Apply group properties to subscription definition
subscription.setNotify(groupDefinition.getOption() == 1);
for (String subName : ownerMap.keySet()) {
subscription.setGroupName(groupName);
Subscription subscription = ownerMap.get(subName);
// Apply group properties to subscription definition
subscription.setNotify(groupDefinition.getOption() == 1);
subscription.setGroupName(groupName);
// Set duration
if (groupDefinition.getSubscriptionStart() != null) {
subscription.setSubscriptionStart(groupDefinition
.getSubscriptionStart());
subscription.setSubscriptionEnd(groupDefinition
.getSubscriptionEnd());
} else {
subscription.setSubscriptionStart(null);
subscription.setSubscriptionEnd(null);
}
// Set active period
if (groupDefinition.getActivePeriodStart() != null) {
subscription.setActivePeriodStart(groupDefinition
.getActivePeriodStart());
subscription.setActivePeriodEnd(groupDefinition
.getActivePeriodEnd());
} else {
subscription.setActivePeriodStart(null);
subscription.setActivePeriodEnd(null);
}
if (subscription.getCoverage() != null
&& groupDefinition.isArealDataSet()) {
DataSet dataset = MetaDataManager.getInstance().getDataSet(
subscription.getDataSetName(),
subscription.getProvider());
DataSizeUtils u = new DataSizeUtils(dataset);
u.setEnvelope(groupDefinition.getEnvelope());
u.setNumFcstHours(subscription.getTime()
.getSelectedTimeIndices().size());
u.determineNumberRequestedGrids(subscription.getParameter());
Coverage cov = new GriddedCoverage();
cov.setEnvelope(groupDefinition.getEnvelope());
subscription.setDataSetSize(u.getDataSetSize());
subscription.setCoverage(cov);
}
subscription.setOfficeID(LocalizationManager.getInstance()
.getCurrentSite());
final String username = UserController.getUserObject()
.uniqueId().toString();
final Shell shell = getShell();
try {
InitialPendingSubscription pending = pendingSubHandler
.getBySubscription(subscription);
if (pending != null) {
DataDeliveryUtils.showMessage(shell,
SWT.ICON_INFORMATION, "Pending",
ALREADY_PENDING_SUBSCRIPTION);
return;
}
} catch (RegistryHandlerException e1) {
statusHandler
.handle(Priority.PROBLEM,
DataDeliveryUtils.UNABLE_TO_RETRIEVE_PENDING_SUBSCRIPTIONS,
e1);
return;
}
// check to see if user if authorized to approve. If so then
// auto-approve
IUser user = UserController.getUserObject();
try {
boolean autoApprove = false;
DataDeliveryAuthRequest request = new DataDeliveryAuthRequest();
request.setUser(user);
request.addRequestedPermissions(
DataDeliveryPermission.SUBSCRIPTION_APPROVE_USER,
DataDeliveryPermission.SUBSCRIPTION_APPROVE_SITE);
request.setNotAuthorizedMessage("The subscription is awaiting approval.\n\n"
+ "A notification message will be generated upon approval.");
PendingSubscription pendingSub = new PendingSubscription(
subscription, LocalizationManager.getInstance()
.getCurrentUser());
pendingSub.setChangeReason("Group Definition Changed");
DataDeliveryAuthRequest r = DataDeliveryUtils
.sendAuthorizationRequest(request);
if (r != null && r.isAuthorized()) {
if (r.isAuthorized(DataDeliveryPermission.SUBSCRIPTION_APPROVE_SITE)) {
autoApprove = true;
} else if (r
.isAuthorized(DataDeliveryPermission.SUBSCRIPTION_APPROVE_USER)) {
if (subscription.getOwner().equals(
user.uniqueId().toString())) {
autoApprove = true;
}
}
if (autoApprove) {
try {
ISubscriptionServiceResult response = subscriptionService
.update(subscription,
new CancelForceApplyAndIncreaseLatencyDisplayText(
"update", shell));
if (response.hasMessageToDisplay()) {
DataDeliveryUtils.showMessage(shell,
SWT.OK, "Subscription Updated",
response.getMessageToDisplay());
}
subscriptionService
.sendUpdatedSubscriptionNotification(
subscription, username);
} catch (RegistryHandlerException e) {
statusHandler.handle(Priority.PROBLEM,
"Unable to update subscription.", e);
}
} else {
savePendingSub(pendingSub, username);
}
} else {
savePendingSub(pendingSub, username);
}
} catch (VizException e) {
statusHandler.handle(Priority.PROBLEM,
e.getLocalizedMessage(), e);
}
// Set duration
if (groupDefinition.getSubscriptionStart() != null) {
subscription.setSubscriptionStart(groupDefinition
.getSubscriptionStart());
subscription.setSubscriptionEnd(groupDefinition
.getSubscriptionEnd());
} else {
subscription.setSubscriptionStart(null);
subscription.setSubscriptionEnd(null);
}
// Set active period
if (groupDefinition.getActivePeriodStart() != null) {
subscription.setActivePeriodStart(groupDefinition
.getActivePeriodStart());
subscription.setActivePeriodEnd(groupDefinition
.getActivePeriodEnd());
} else {
subscription.setActivePeriodStart(null);
subscription.setActivePeriodEnd(null);
}
if (subscription.getCoverage() != null
&& groupDefinition.isArealDataSet()) {
DataSet dataset = MetaDataManager.getInstance().getDataSet(
subscription.getDataSetName(),
subscription.getProvider());
DataSizeUtils u = new DataSizeUtils(dataset);
u.setEnvelope(groupDefinition.getEnvelope());
u.setNumFcstHours(subscription.getTime()
.getSelectedTimeIndices().size());
u.determineNumberRequestedGrids(subscription.getParameter());
Coverage cov = new GriddedCoverage();
cov.setEnvelope(groupDefinition.getEnvelope());
subscription.setDataSetSize(u.getDataSetSize());
subscription.setCoverage(cov);
}
subscription.setOfficeID(LocalizationManager.getInstance()
.getCurrentSite());
}
}
/**
* Save a pending subscription.
*/
private void savePendingSub(PendingSubscription pendingSub, String username) {
try {
pendingSubHandler.store(pendingSub);
final String msg = "The subscription is awaiting approval.\n\n"
+ "A notification message will be generated upon approval.";
DataDeliveryUtils.showMessage(getShell(), SWT.OK,
"Subscription Pending", msg);
subscriptionService
.sendCreatedPendingSubscriptionForSubscriptionNotification(
pendingSub, username);
final ISubscriptionServiceResult result = DataDeliveryServices
.getSubscriptionService().updateWithPendingCheck(
new ArrayList<Subscription>(Sets.union(
groupSubscriptions,
removeFromGroupSubscriptions)),
this);
if (result.hasMessageToDisplay()) {
DataDeliveryUtils.showMessage(getShell(), SWT.ICON_INFORMATION,
"Edit Group", result.getMessageToDisplay());
}
} catch (RegistryHandlerException e) {
statusHandler.handle(Priority.PROBLEM,
"Unable to store pending subscription.", e);
"Unable to update the group definition for subscriptions.",
e);
}
}
@ -536,31 +466,7 @@ public class UserSelectComp extends Composite implements IUpdate, IDisplay {
*/
@Override
public void hasEntries(boolean entries) {
String owner = userNameCombo.getText();
Map<String, Subscription> ownerSubs = userMap.get(owner);
Map<String, Subscription> selectedSubs = addedMap.get(owner);
if (selectedSubs != null) {
if (entries) {
String[] selectedList = dualList.getSelectedListItems();
// Clear list
selectedSubs.clear();
// Re-add to list
for (String subName : selectedList) {
selectedSubs.put(subName, ownerSubs.get(subName));
}
addedMap.put(owner, selectedSubs);
} else {
selectedSubs.clear();
addedMap.put(owner, selectedSubs);
}
}
// unused
}
@Override
@ -579,7 +485,7 @@ public class UserSelectComp extends Composite implements IUpdate, IDisplay {
// clear the selected list
dualList.clearAvailableList(true);
ArrayList<String> selectedGroupSubscriptions = new ArrayList<String>();
initiallySelectedSubscriptions.clear();
Map<String, Subscription> sMap = userMap.get(userNameCombo.getText());
for (String subscriptionName : sMap.keySet()) {
@ -587,14 +493,13 @@ public class UserSelectComp extends Composite implements IUpdate, IDisplay {
Subscription sub = sMap.get(subscriptionName);
if (groupName.equals(sub.getGroupName())) {
selectedGroupSubscriptions.add(subscriptionName);
initiallySelectedSubscriptions.add(subscriptionName);
}
}
// set the selected list
dualList.selectItems(selectedGroupSubscriptions
.toArray(new String[selectedGroupSubscriptions.size()]));
dualList.selectItems(initiallySelectedSubscriptions
.toArray(new String[0]));
}
/**
@ -604,4 +509,29 @@ public class UserSelectComp extends Composite implements IUpdate, IDisplay {
public boolean displayYesNoPopup(String title, String message) {
return DataDeliveryUtils.showYesNoMessage(getShell(), title, message) == SWT.YES;
}
/**
* {@inheritDoc}
*/
@Override
public String getOptionDisplayText(ForceApplyPromptResponse option,
int requiredLatency, Subscription subscription,
Set<String> wouldBeUnscheduledSubscriptions) {
switch (option) {
case CANCEL:
return "Do not update the group definition.";
case FORCE_APPLY:
if (wouldBeUnscheduledSubscriptions.size() == 1) {
return "Update the group definition and unschedule "
+ wouldBeUnscheduledSubscriptions.iterator().next();
}
return "Update the group definition and unschedule the subscriptions";
case INCREASE_LATENCY:
// Signifies it should not be an option
return null;
default:
throw new IllegalArgumentException(
"Don't know how to handle option [" + option + "]");
}
}
}

View file

@ -20,6 +20,8 @@
package com.raytheon.uf.viz.datadelivery.services;
import com.raytheon.uf.common.datadelivery.bandwidth.IBandwidthService;
import com.raytheon.uf.viz.datadelivery.subscription.IPermissionsService;
import com.raytheon.uf.viz.datadelivery.subscription.ISubscriptionNotificationService;
import com.raytheon.uf.viz.datadelivery.subscription.ISubscriptionService;
/**
@ -49,6 +51,10 @@ public final class DataDeliveryServices {
private ISubscriptionService subscriptionService;
private ISubscriptionNotificationService subscriptionNotificationService;
private IPermissionsService permissionsService;
/**
* Disabled constructor.
*/
@ -102,4 +108,43 @@ public final class DataDeliveryServices {
public void setBandwidthService(IBandwidthService bandwidthService) {
this.bandwidthService = bandwidthService;
}
/**
* Get the subscription service.
*
* @return the subscription notification service
*/
public static ISubscriptionNotificationService getSubscriptionNotificationService() {
return INSTANCE.subscriptionNotificationService;
}
/**
* Set the subscription notification service.
*
* @param subscriptionNotificationService
* the subscription notification service to set
*/
public void setSubscriptionNotificationService(
ISubscriptionNotificationService subscriptionNotificationService) {
this.subscriptionNotificationService = subscriptionNotificationService;
}
/**
* Get the permissions service.
*
* @return the permissions service
*/
public static IPermissionsService getPermissionsService() {
return INSTANCE.permissionsService;
}
/**
* Set the permissions service.
*
* @param permissionsService
* the permissionsService to set
*/
public void setPermissionsService(IPermissionsService permissionsService) {
this.permissionsService = permissionsService;
}
}

View file

@ -29,15 +29,11 @@ import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Group;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Layout;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;
import com.raytheon.uf.common.datadelivery.registry.GroupDefinition;
import com.raytheon.uf.common.datadelivery.registry.ebxml.DataSetQuery;
import com.raytheon.uf.common.datadelivery.registry.handlers.DataDeliveryHandlers;
import com.raytheon.uf.common.datadelivery.request.DataDeliveryPermission;
import com.raytheon.uf.common.registry.handler.RegistryHandlerException;
import com.raytheon.uf.common.status.IUFStatusHandler;
@ -48,11 +44,9 @@ import com.raytheon.uf.viz.datadelivery.common.ui.ActivePeriodComp;
import com.raytheon.uf.viz.datadelivery.common.ui.AreaControlComp;
import com.raytheon.uf.viz.datadelivery.common.ui.DeliveryOptionsComp;
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.IGroupAction;
import com.raytheon.uf.viz.datadelivery.common.ui.UserSelectComp;
import com.raytheon.uf.viz.datadelivery.utils.DataDeliveryGUIUtils;
import com.raytheon.uf.viz.datadelivery.utils.DataDeliveryUtils;
import com.raytheon.viz.ui.dialogs.CaveSWTDialog;
import com.raytheon.viz.ui.presenter.components.ComboBoxConf;
import com.raytheon.viz.ui.presenter.components.WidgetConf;
@ -76,17 +70,19 @@ import com.raytheon.viz.ui.presenter.components.WidgetConf;
* Dec 18, 2012 1440 mpduff Made non-blocking
* Dec 10, 2012 1259 bsteffen Switch Data Delivery from LatLon to referenced envelopes.
* Jan 02, 2013 1441 djohnson Access GroupDefinitionManager in a static fashion.
* Jan 08, 2013 1453 djohnson Split creation and edit dialogs.
*
* </pre>
*
* @author jpiatt
* @version 1.0
*/
public class CreateGroupDlg extends CaveSWTDialog implements IGroupAction {
public abstract class BaseGroupDefinitionDlg extends CaveSWTDialog implements
IGroupAction {
/** Status Handler */
private final IUFStatusHandler statusHandler = UFStatus
.getHandler(CreateGroupDlg.class);
.getHandler(BaseGroupDefinitionDlg.class);
/** Delivery options strings */
protected final String[] DELIVERY_OPTIONS = new String[] {
@ -97,10 +93,7 @@ public class CreateGroupDlg extends CaveSWTDialog implements IGroupAction {
"Select delivery method", WidgetConf.DO_NOTHING);
/** The Main Composite */
private Composite mainComp;
/** The Subscription Group Information Composite */
private GroupSelectComp groupSelectComp;
protected Composite mainComp;
/** The Subscription Delivery Options Composite */
private DeliveryOptionsComp deliverComp;
@ -117,15 +110,9 @@ public class CreateGroupDlg extends CaveSWTDialog implements IGroupAction {
/** The User Selection Composite */
private UserSelectComp userSelectComp;
/** Description text field */
private Text groupNameTxt;
/** IGroupAction callback */
private final IGroupAction callback;
/** Flag to determine create or edit */
private final boolean create;
/**
* Constructor.
*
@ -135,29 +122,11 @@ public class CreateGroupDlg extends CaveSWTDialog implements IGroupAction {
* @param callback
* callback to subscription manager
*/
public CreateGroupDlg(Shell parent, boolean create, IGroupAction callback) {
public BaseGroupDefinitionDlg(Shell parent, IGroupAction callback) {
super(parent, SWT.DIALOG_TRIM, CAVE.INDEPENDENT_SHELL
| CAVE.DO_NOT_BLOCK);
if (create) {
setText("Create Group");
} else {
setText("Edit Group");
}
setText(getDialogTitle());
this.callback = callback;
this.create = create;
}
/**
* Constructor.
*
* @param parent
* The parent shell
* @param create
* @param callback
* callback to subscription manager
*/
public CreateGroupDlg(Shell parent, IGroupAction callback) {
this(parent, true, callback);
}
/*
@ -175,11 +144,9 @@ public class CreateGroupDlg extends CaveSWTDialog implements IGroupAction {
mainComp.setLayout(gl);
mainComp.setLayoutData(gd);
if (create) {
createGroupInfo();
} else {
groupSelectComp = new GroupSelectComp(mainComp, true);
}
deliverComp = new DeliveryOptionsComp(mainComp);
durComp = new DurationComp(mainComp);
@ -197,18 +164,6 @@ public class CreateGroupDlg extends CaveSWTDialog implements IGroupAction {
*/
@Override
protected void preOpened() {
Runnable populate = new Runnable() {
@Override
public void run() {
populate(groupSelectComp.getGroupName());
}
};
if (!create) {
ComboBoxConf groupComboConf = new ComboBoxConf(create,
"Select a Group", populate);
groupSelectComp.setGroupNameComboConf(groupComboConf);
}
deliverComp.setDeliveryOptions(DELIVERY_OPTIONS);
deliverComp.setDeliveryConfig(DELIVERY_COMBO_CONF);
}
@ -228,32 +183,6 @@ public class CreateGroupDlg extends CaveSWTDialog implements IGroupAction {
return mainLayout;
}
/**
* Create the Group information.
*/
private void createGroupInfo() {
GridData gd = new GridData(SWT.FILL, SWT.DEFAULT, true, false);
GridLayout gl = new GridLayout(2, false);
Group groupNameInfo = new Group(mainComp, SWT.NONE);
groupNameInfo.setLayout(gl);
groupNameInfo.setLayoutData(gd);
groupNameInfo.setText(" Group Information ");
Label groupName = new Label(groupNameInfo, SWT.NONE);
groupName.setText("Group Name: ");
Composite groupComp = new Composite(groupNameInfo, SWT.NONE);
gd = new GridData(SWT.FILL, SWT.DEFAULT, true, false);
groupComp.setLayoutData(gd);
groupComp.setLayout(gl);
groupNameTxt = new Text(groupComp, SWT.BORDER);
groupNameTxt.setLayoutData(new GridData(285, SWT.DEFAULT));
groupName.setToolTipText("Enter Group name");
}
/**
* Create buttons at the bottom of the dialog.
*/
@ -301,32 +230,20 @@ public class CreateGroupDlg extends CaveSWTDialog implements IGroupAction {
private boolean handleOK() {
boolean valid = false;
boolean nameValid = false;
boolean datesValid = false;
boolean activeDatesValid = false;
String groupName = null;
if (create) {
groupName = groupNameTxt.getText().trim();
} else {
groupName = groupSelectComp.getGroupName();
}
// Check for a group name
if (groupName == null || groupName.isEmpty()) {
DataDeliveryUtils.showMessage(shell, SWT.ERROR,
"Invalid Group Name", "No Group Name detected. \n\n"
+ "Please enter a Group Name.\n");
} else {
nameValid = true;
String groupName = getGroupName();
if (!validateGroupName(groupName)) {
return false;
}
// Validate the date entries
datesValid = durComp.isValidChk();
activeDatesValid = activePeriodComp.isValidChk();
if (nameValid && datesValid && activeDatesValid) {
if (datesValid && activeDatesValid) {
valid = true;
}
@ -389,13 +306,7 @@ public class CreateGroupDlg extends CaveSWTDialog implements IGroupAction {
}
try {
if (this.create) {
DataDeliveryHandlers.getGroupDefinitionHandler().store(
groupDefinition);
} else {
DataDeliveryHandlers.getGroupDefinitionHandler().update(
groupDefinition);
}
saveGroupDefinition(groupDefinition);
} catch (RegistryHandlerException e) {
statusHandler.handle(Priority.PROBLEM,
"Unable to save Group object", e);
@ -407,7 +318,7 @@ public class CreateGroupDlg extends CaveSWTDialog implements IGroupAction {
}
// Save group properties to selected subscriptions
userSelectComp.getSuscriptionNames(groupName);
userSelectComp.getSubscriptionNames(groupName);
if (callback != null) {
// Re-load the group combo box
@ -515,4 +426,41 @@ public class CreateGroupDlg extends CaveSWTDialog implements IGroupAction {
return null;
}
/**
* Get the dialog title.
*
* @return
*/
protected abstract String getDialogTitle();
/**
* Create the group name section.
*/
protected abstract void createGroupInfo();
/**
* Return the group name.
*
* @return
*/
protected abstract String getGroupName();
/**
* Save the group definition.
*
* @param groupDefinition
* the group definition
* @throws RegistryHandlerException
*/
protected abstract void saveGroupDefinition(GroupDefinition groupDefinition)
throws RegistryHandlerException;
/**
* Validate the group name.
*
* @param groupName
* the group name
* @return
*/
protected abstract boolean validateGroupName(String groupName);
}

View file

@ -0,0 +1,139 @@
/**
* 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;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Group;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;
import com.raytheon.uf.common.datadelivery.registry.GroupDefinition;
import com.raytheon.uf.common.datadelivery.registry.handlers.DataDeliveryHandlers;
import com.raytheon.uf.common.registry.handler.RegistryHandlerException;
import com.raytheon.uf.viz.datadelivery.common.ui.IGroupAction;
import com.raytheon.uf.viz.datadelivery.utils.DataDeliveryUtils;
/**
* The Data Delivery Create and Edit Subscription Group Dialog.
*
* <pre>
*
* SOFTWARE HISTORY
*
* Date Ticket# Engineer Description
* ------------ ---------- ----------- -------------------------
* Jan 08, 2013 1453 djohnson Split creation and edit dialogs.
*
* </pre>
*
* @author jpiatt
* @version 1.0
*/
public class CreateGroupDefinitionDlg extends BaseGroupDefinitionDlg {
/** Group name text field */
private Text groupNameTxt;
/**
* Constructor.
*
* @param parent
* The parent shell
* @param create
* @param callback
* callback to subscription manager
*/
public CreateGroupDefinitionDlg(Shell parent,
IGroupAction callback) {
super(parent, callback);
}
@Override
protected String getDialogTitle() {
return "Create Group";
}
/**
* Create the Group information.
*/
@Override
protected void createGroupInfo() {
GridData gd = new GridData(SWT.FILL, SWT.DEFAULT, true, false);
GridLayout gl = new GridLayout(2, false);
Group groupNameInfo = new Group(mainComp, SWT.NONE);
groupNameInfo.setLayout(gl);
groupNameInfo.setLayoutData(gd);
groupNameInfo.setText(" Group Information ");
Label groupName = new Label(groupNameInfo, SWT.NONE);
groupName.setText("Group Name: ");
Composite groupComp = new Composite(groupNameInfo, SWT.NONE);
gd = new GridData(SWT.FILL, SWT.DEFAULT, true, false);
groupComp.setLayoutData(gd);
groupComp.setLayout(gl);
groupNameTxt = new Text(groupComp, SWT.BORDER);
groupNameTxt.setLayoutData(new GridData(285, SWT.DEFAULT));
groupName.setToolTipText("Enter Group name");
}
/**
* {@inheritDoc}
*/
@Override
protected String getGroupName() {
return groupNameTxt.getText().trim();
}
/**
* {@inheritDoc}
*/
@Override
protected void saveGroupDefinition(GroupDefinition groupDefinition)
throws RegistryHandlerException {
DataDeliveryHandlers.getGroupDefinitionHandler().store(groupDefinition);
}
/**
* {@inheritDoc}
*/
@Override
protected boolean validateGroupName(String groupName) {
// Check for a group name
if (groupName == null || groupName.isEmpty()) {
DataDeliveryUtils.showMessage(shell, SWT.ERROR,
"Invalid Group Name", "No Group Name detected. \n\n"
+ "Please enter a Group Name.\n");
return false;
} else if (GroupDefinition.NO_GROUP.equals(groupName)) {
DataDeliveryUtils.showMessage(shell, SWT.ERROR,
"Invalid Group Name", "Invalid Group Name detected. \n\n"
+ "Please enter a valid Group Name.\n");
return false;
}
return true;
}
}

View file

@ -0,0 +1,148 @@
/**
* 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;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Shell;
import com.raytheon.uf.common.datadelivery.registry.GroupDefinition;
import com.raytheon.uf.common.datadelivery.registry.ebxml.DataSetQuery;
import com.raytheon.uf.common.datadelivery.registry.handlers.DataDeliveryHandlers;
import com.raytheon.uf.common.datadelivery.request.DataDeliveryPermission;
import com.raytheon.uf.common.registry.handler.RegistryHandlerException;
import com.raytheon.uf.viz.datadelivery.common.ui.GroupSelectComp;
import com.raytheon.uf.viz.datadelivery.common.ui.IGroupAction;
import com.raytheon.uf.viz.datadelivery.utils.DataDeliveryUtils;
import com.raytheon.viz.ui.presenter.components.ComboBoxConf;
/**
* The Data Delivery Create and Edit Subscription Group Dialog.
*
* <pre>
*
* SOFTWARE HISTORY
*
* Date Ticket# Engineer Description
* ------------ ---------- ----------- -------------------------
* Jul 2, 2012 702 jpiatt Initial creation.
* Aug 02, 2012 955 djohnson Type-safe registry query/responses.
* Aug 10, 2012 1022 djohnson {@link DataSetQuery} requires provider name.
* Aug 20, 2012 0743 djohnson Finish making registry type-safe.
* Aug 29, 2012 223 mpduff Renamed some methods.
* Aug 31, 2012 702 jpiatt Correct group data population.
* Oct 03, 2012 1241 djohnson Use {@link DataDeliveryPermission} and registry handlers.
* Dec 18, 2012 1440 mpduff Made non-blocking
* Dec 10, 2012 1259 bsteffen Switch Data Delivery from LatLon to referenced envelopes.
* Jan 02, 2013 1441 djohnson Access GroupDefinitionManager in a static fashion.
* Jan 08, 2013 1453 djohnson Split creation and edit dialogs.
*
* </pre>
*
* @author jpiatt
* @version 1.0
*/
public class EditGroupDefinitionDlg extends BaseGroupDefinitionDlg {
/** The Subscription Group Information Composite */
private GroupSelectComp groupSelectComp;
/**
* Constructor.
*
* @param parent
* The parent shell
* @param create
* @param callback
* callback to subscription manager
*/
public EditGroupDefinitionDlg(Shell parent, IGroupAction callback) {
super(parent, callback);
}
/*
* (non-Javadoc)
*
* @see com.raytheon.viz.ui.dialogs.CaveSWTDialog#preOpened()
*/
@Override
protected void preOpened() {
super.preOpened();
Runnable populate = new Runnable() {
@Override
public void run() {
populate(groupSelectComp.getGroupName());
}
};
ComboBoxConf groupComboConf = new ComboBoxConf(true,
"Select a Group", populate);
groupSelectComp.setGroupNameComboConf(groupComboConf);
}
/**
* {@inheritDoc}
*/
@Override
protected String getGroupName() {
return groupSelectComp.getGroupName();
}
/**
* {@inheritDoc}
*/
@Override
protected String getDialogTitle() {
return "Edit Group";
}
/**
* {@inheritDoc}
*/
@Override
protected void createGroupInfo() {
groupSelectComp = new GroupSelectComp(mainComp, true);
}
/**
* {@inheritDoc}
*/
@Override
protected void saveGroupDefinition(GroupDefinition groupDefinition)
throws RegistryHandlerException {
DataDeliveryHandlers.getGroupDefinitionHandler()
.update(groupDefinition);
}
/**
* {@inheritDoc}
*/
@Override
protected boolean validateGroupName(String groupName) {
// Check for a group name
if (GroupDefinition.NO_GROUP.equals(groupName)) {
DataDeliveryUtils.showMessage(shell, SWT.ERROR,
"Invalid Group Name", "No Group Name detected. \n\n"
+ "Please select a Group Name.\n");
return false;
}
return true;
}
}

View file

@ -84,8 +84,8 @@ public class GroupAddDlg extends CaveSWTDialog {
/** IGroupAction callback */
private final IGroupAction callback;
private final ISubscriptionService subscriptionService = DataDeliveryServices
.getSubscriptionService();
private final ISubscriptionNotificationService subscriptionNotificationService = DataDeliveryServices
.getSubscriptionNotificationService();
/**
* Constructor.
@ -259,7 +259,8 @@ public class GroupAddDlg extends CaveSWTDialog {
return false;
}
subscriptionService.sendCreatedSubscriptionNotification(subscription,
subscriptionNotificationService.sendCreatedSubscriptionNotification(
subscription,
username);
// refresh table

View file

@ -0,0 +1,118 @@
/**
* 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;
import com.raytheon.uf.common.auth.user.IUser;
import com.raytheon.uf.common.datadelivery.registry.Subscription;
import com.raytheon.uf.common.datadelivery.request.DataDeliveryPermission;
import com.raytheon.uf.viz.core.exception.VizException;
/**
* Interface that defines the service to work with permissions.
*
* <pre>
*
* SOFTWARE HISTORY
*
* Date Ticket# Engineer Description
* ------------ ---------- ----------- --------------------------
* Jan 04, 2013 1441 djohnson Initial creation
*
* </pre>
*
* @author djohnson
* @version 1.0
*/
public interface IPermissionsService {
/**
* Interface for an authorized permission response.
*/
public static interface IAuthorizedPermissionResponse {
/**
* True if the user had one of the specified permissions.
*
* @return true if the user had one of the specified permissions
*/
boolean isAuthorized();
/**
* Returns true if the user had the specific permission.
*
* @param permission
* the permission
* @return true if the user had the specific permission
*/
boolean hasPermission(DataDeliveryPermission permission);
}
/**
* Check whether a user has the permissions to change a subscription.
*
* @param user
* the user requesting to change the subscription
* @param notAuthorizedMessage
* the message that should be displayed if they are not
* authorized
* @param subscription
* the subscription they are attempting to change
* @return the response
* @throws VizException
*/
public IAuthorizedPermissionResponse checkPermissionToChangeSubscription(
final IUser user, String notAuthorizedMessage,
final Subscription subscription) throws VizException;
/**
* Check whether a user has the specified permissions.
*
* @param user
* the user to check permissions for
* @param notAuthorizedMessage
* the not authorized message that should be displayed if they
* are not authorized
* @param permission
* the permission to check
* @return IAuthorizedPermissionResponse the response
* @throws VizException
* on error checking permissions
*/
public IAuthorizedPermissionResponse checkPermission(IUser user,
String notAuthorizedMessage, DataDeliveryPermission permission)
throws VizException;
/**
* Check whether a user has one of the specified permissions.
*
* @param user
* the user to check permissions for
* @param notAuthorizedMessage
* the not authorized message that should be displayed if they
* are not authorized
* @param permissions
* the permissions to check
* @return IAuthorizedPermissionResponse the response
* @throws VizException
* on error checking permissions
*/
public IAuthorizedPermissionResponse checkPermissions(IUser user,
String notAuthorizedMessage, DataDeliveryPermission... permissions)
throws VizException;
}

View file

@ -0,0 +1,156 @@
/**
* 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;
import com.raytheon.uf.common.datadelivery.registry.InitialPendingSubscription;
import com.raytheon.uf.common.datadelivery.registry.Subscription;
/**
* Service to notify about subscription events.
*
* <pre>
*
* SOFTWARE HISTORY
*
* Date Ticket# Engineer Description
* ------------ ---------- ----------- --------------------------
* Jan 04, 2013 1441 djohnson Initial creation
*
* </pre>
*
* @author djohnson
* @version 1.0
*/
public interface ISubscriptionNotificationService {
/**
* Send a notification that pending subscription was created.
*
* @param subscription
* the subscription
* @param username
* the username
*/
void sendCreatedPendingSubscriptionNotification(
InitialPendingSubscription subscription, String username);
/**
* Send a notification that a subscription was created.
*
* @param subscription
* the subscription
* @param username
* the username
*/
void sendCreatedSubscriptionNotification(Subscription subscription,
String username);
/**
* Send a notification that a subscription was updated.
*
* @param subscription
* the subscription
* @param username
* the username
*/
void sendUpdatedSubscriptionNotification(Subscription subscription,
String username);
/**
* Send a notification that a pending subscription was updated.
*
* @param subscription
* the subscription
* @param username
* the username
*/
void sendUpdatedPendingSubscriptionNotification(
InitialPendingSubscription subscription, String username);
/**
* Send a notification that a subscription update is pending.
*
* @param subscription
* the subscription
* @param username
* the username
*/
void sendCreatedPendingSubscriptionForSubscriptionNotification(
InitialPendingSubscription pendingSub, String username);
/**
* Send a notification that a pending subscription was approved.
*
* @param subscription
* the subscription
* @param username
* the username
*/
void sendApprovedPendingSubscriptionNotification(
InitialPendingSubscription subscription, String username);
/**
* Send a notification that a pending subscription was denied.
*
* @param subscription
* the subscription
* @param username
* the username
* @param denyMessage
* the reason for denying
*/
void sendDeniedPendingSubscriptionNotification(
InitialPendingSubscription subscription, String username,
String denyMessage);
/**
* Send a notification that the subscription was deleted.
*
* @param subscription
* the subscription
* @param username
* the username
*/
void sendDeletedSubscriptionNotification(Subscription subscription,
String username);
/**
* Send a notification that the subscription was activated.
*
* @param subscription
* the subscription
* @param username
* the username
*/
void sendSubscriptionActivatedNotification(Subscription subscription,
String username);
/**
* Send a notification that the subscription was deactivated.
*
* @param subscription
* the subscription
* @param username
* the username
*/
void sendSubscriptionDeactivatedNotification(Subscription subscription,
String username);
}

View file

@ -22,7 +22,6 @@ package com.raytheon.uf.viz.datadelivery.subscription;
import java.util.List;
import com.raytheon.uf.common.datadelivery.registry.AdhocSubscription;
import com.raytheon.uf.common.datadelivery.registry.InitialPendingSubscription;
import com.raytheon.uf.common.datadelivery.registry.Subscription;
import com.raytheon.uf.common.registry.handler.RegistryHandlerException;
import com.raytheon.uf.viz.datadelivery.subscription.SubscriptionService.IForceApplyPromptDisplayText;
@ -108,11 +107,26 @@ public interface ISubscriptionService {
* the subscriptions to update
* @param displayTextStrategy
* @return the result object
* @throws RegistryHandlerException
*/
ISubscriptionServiceResult update(List<Subscription> subscriptions,
IForceApplyPromptDisplayText displayTextStrategy)
throws RegistryHandlerException;
/**
* Update the subscriptions, checking for an existing pending change
* already.
*
* @param subscriptions
* @param displayTextStrategy
* @return the result
* @throws RegistryHandlerException
*/
ISubscriptionServiceResult updateWithPendingCheck(
List<Subscription> subscriptions,
IForceApplyPromptDisplayText displayTextStrategy)
throws RegistryHandlerException;
/**
* Store the adhoc subscription.
*
@ -127,117 +141,4 @@ public interface ISubscriptionService {
public ISubscriptionServiceResult store(AdhocSubscription sub,
IForceApplyPromptDisplayText displayTextStrategy)
throws RegistryHandlerException;
/**
* Send a notification that pending subscription was created.
*
* @param subscription
* the subscription
* @param username
* the username
*/
void sendCreatedPendingSubscriptionNotification(
InitialPendingSubscription subscription, String username);
/**
* Send a notification that a subscription was created.
*
* @param subscription
* the subscription
* @param username
* the username
*/
void sendCreatedSubscriptionNotification(Subscription subscription,
String username);
/**
* Send a notification that a subscription was updated.
*
* @param subscription
* the subscription
* @param username
* the username
*/
void sendUpdatedSubscriptionNotification(Subscription subscription,
String username);
/**
* Send a notification that a pending subscription was updated.
*
* @param subscription
* the subscription
* @param username
* the username
*/
void sendUpdatedPendingSubscriptionNotification(
InitialPendingSubscription subscription, String username);
/**
* Send a notification that a subscription update is pending.
*
* @param subscription
* the subscription
* @param username
* the username
*/
void sendCreatedPendingSubscriptionForSubscriptionNotification(
InitialPendingSubscription pendingSub, String username);
/**
* Send a notification that a pending subscription was approved.
*
* @param subscription
* the subscription
* @param username
* the username
*/
void sendApprovedPendingSubscriptionNotification(
InitialPendingSubscription subscription, String username);
/**
* Send a notification that a pending subscription was denied.
*
* @param subscription
* the subscription
* @param username
* the username
* @param denyMessage
* the reason for denying
*/
void sendDeniedPendingSubscriptionNotification(
InitialPendingSubscription subscription, String username,
String denyMessage);
/**
* Send a notification that the subscription was deleted.
*
* @param subscription
* the subscription
* @param username
* the username
*/
void sendDeletedSubscriptionNotification(Subscription subscription,
String username);
/**
* Send a notification that the subscription was activated.
*
* @param subscription
* the subscription
* @param username
* the username
*/
void sendSubscriptionActivatedMessage(Subscription subscription,
String username);
/**
* Send a notification that the subscription was deactivated.
*
* @param subscription
* the subscription
* @param username
* the username
*/
void sendSubscriptionDeactivatedMessage(Subscription subscription,
String username);
}

View file

@ -0,0 +1,164 @@
/**
* 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;
import com.raytheon.uf.common.auth.user.IUser;
import com.raytheon.uf.common.datadelivery.registry.Subscription;
import com.raytheon.uf.common.datadelivery.request.DataDeliveryAuthRequest;
import com.raytheon.uf.common.datadelivery.request.DataDeliveryPermission;
import com.raytheon.uf.viz.core.exception.VizException;
import com.raytheon.uf.viz.core.requests.ThriftClient;
/**
* {@link IPermissionsService} implementation that requests permissions from the
* server.
*
* <pre>
*
* SOFTWARE HISTORY
*
* Date Ticket# Engineer Description
* ------------ ---------- ----------- --------------------------
* Jan 04, 2013 1441 djohnson Initial creation
*
* </pre>
*
* @author djohnson
* @version 1.0
*/
public class RequestFromServerPermissionsService implements IPermissionsService {
/**
* Adapts the {@link DataDeliveryAuthRequestAdapter} to match the
* {@link IAuthorizedPermissionResponse} interface.
*/
private class DataDeliveryAuthRequestAdapter implements
IAuthorizedPermissionResponse {
private final DataDeliveryAuthRequest response;
/**
* The response to adapt.
*
* @param response
*/
private DataDeliveryAuthRequestAdapter(DataDeliveryAuthRequest response) {
this.response = response;
}
/**
* {@inheritDoc}
*/
@Override
public boolean isAuthorized() {
return response != null && response.isAuthorized();
}
/**
* {@inheritDoc}
*/
@Override
public boolean hasPermission(DataDeliveryPermission permission) {
return (isAuthorized()) ? response.isAuthorized(permission) : false;
}
}
/**
* Send an authorization request. Private because the method of constructing
* an authorization request and processing the response should remain
* isolated to this utility class.
*
* @param request
* The request object
* @return DataDeliveryAuthReqeust object
* @throws VizException
*/
private DataDeliveryAuthRequest sendAuthorizationRequest(
DataDeliveryAuthRequest request) throws VizException {
return (DataDeliveryAuthRequest) ThriftClient
.sendPrivilegedRequest(request);
}
/**
* {@inheritDoc}
*/
@Override
public IAuthorizedPermissionResponse checkPermissionToChangeSubscription(
final IUser user, String notAuthorizedMessage,
final Subscription subscription) throws VizException {
final IAuthorizedPermissionResponse r = checkPermissions(user,
notAuthorizedMessage,
DataDeliveryPermission.SUBSCRIPTION_APPROVE_SITE,
DataDeliveryPermission.SUBSCRIPTION_APPROVE_USER);
// If they have site permissions, then yes they can approve the
// subscription
if (r.hasPermission(DataDeliveryPermission.SUBSCRIPTION_APPROVE_SITE)) {
return r;
} else {
// Otherwise they must have user approval permission and be the
// owner
return new IAuthorizedPermissionResponse() {
@Override
public boolean isAuthorized() {
return r.isAuthorized()
&& user.uniqueId().toString()
.equals(subscription.getOwner());
}
@Override
public boolean hasPermission(DataDeliveryPermission permission) {
return r.hasPermission(permission);
}
};
}
}
/**
* {@inheritDoc}
*/
@Override
public IAuthorizedPermissionResponse checkPermission(IUser user,
String notAuthorizedMessage, DataDeliveryPermission permission)
throws VizException {
return checkPermissions(user, notAuthorizedMessage,
new DataDeliveryPermission[] { permission });
}
/**
* {@inheritDoc}
*/
@Override
public IAuthorizedPermissionResponse checkPermissions(IUser user,
String notAuthorizedMessage, DataDeliveryPermission... permissions)
throws VizException {
DataDeliveryAuthRequest request = new DataDeliveryAuthRequest();
request.setUser(user);
request.addRequestedPermissions(permissions);
request.setNotAuthorizedMessage(notAuthorizedMessage);
DataDeliveryAuthRequest r = sendAuthorizationRequest(request);
return new DataDeliveryAuthRequestAdapter(r);
}
}

View file

@ -0,0 +1,249 @@
/**
* 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;
import com.raytheon.uf.common.datadelivery.event.notification.ApprovedPendingSubscriptionNotificationRequest;
import com.raytheon.uf.common.datadelivery.event.notification.BaseSubscriptionNotificationRequest;
import com.raytheon.uf.common.datadelivery.event.notification.DeniedPendingSubscriptionNotificationRequest;
import com.raytheon.uf.common.datadelivery.event.notification.PendingSubscriptionNotificationRequest;
import com.raytheon.uf.common.datadelivery.event.notification.SubscriptionNotificationRequest;
import com.raytheon.uf.common.datadelivery.registry.InitialPendingSubscription;
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.core.exception.VizException;
import com.raytheon.uf.viz.core.requests.ThriftClient;
/**
* Implementation of {@link ISubscriptionNotificationService} that sends the
* notification to the server for processing.
*
* <pre>
*
* SOFTWARE HISTORY
*
* Date Ticket# Engineer Description
* ------------ ---------- ----------- --------------------------
* Jan 4, 2013 1441 djohnson Initial creation
*
* </pre>
*
* @author djohnson
* @version 1.0
*/
public class SendToServerSubscriptionNotificationService implements
ISubscriptionNotificationService {
private final IUFStatusHandler statusHandler = UFStatus
.getHandler(SendToServerSubscriptionNotificationService.class);
/**
* Send a notification that a subscription has been created.
*
* @param subscription
* the subscription
* @param username
* the username
*/
@Override
public void sendCreatedSubscriptionNotification(Subscription subscription,
String username) {
BaseSubscriptionNotificationRequest<Subscription> req = new SubscriptionNotificationRequest();
req.setUserId(username);
req.setCategory("Subscription");
String msg = "Subscription " + subscription.getName()
+ " has been created.";
req.setMessage(msg);
req.setSubscription(subscription);
req.setPriority(3);
sendRequest(req);
}
/**
* {@inheritDoc}
*/
@Override
public void sendCreatedPendingSubscriptionNotification(
InitialPendingSubscription subscription, String username) {
BaseSubscriptionNotificationRequest<InitialPendingSubscription> req = new PendingSubscriptionNotificationRequest();
req.setUserId(username);
req.setCategory("Subscription");
req.setSubscription(subscription);
req.setPriority(2);
req.setMessage("Pending Subscription " + subscription.getName()
+ " has been created.");
sendRequest(req);
}
/**
* {@inheritDoc}
*/
@Override
public void sendUpdatedSubscriptionNotification(Subscription subscription,
String username) {
BaseSubscriptionNotificationRequest<Subscription> req = new SubscriptionNotificationRequest();
req.setUserId(username);
req.setCategory("Subscription");
String msg = "Subscription " + subscription.getName()
+ " has been updated.";
req.setMessage(msg);
req.setSubscription(subscription);
req.setPriority(3);
sendRequest(req);
}
/**
* {@inheritDoc}
*/
@Override
public void sendUpdatedPendingSubscriptionNotification(
InitialPendingSubscription subscription, String username) {
BaseSubscriptionNotificationRequest<InitialPendingSubscription> req = new PendingSubscriptionNotificationRequest();
req.setUserId(username);
req.setCategory("Subscription");
req.setMessage("Edited subscription " + subscription.getName());
req.setSubscription(subscription);
req.setPriority(2);
sendRequest(req);
}
/**
* {@inheritDoc}
*/
@Override
public void sendCreatedPendingSubscriptionForSubscriptionNotification(
InitialPendingSubscription subscription, String username) {
BaseSubscriptionNotificationRequest<InitialPendingSubscription> req = new PendingSubscriptionNotificationRequest();
req.setUserId(username);
req.setCategory("Subscription");
req.setMessage("Edited subscription " + subscription.getName());
req.setSubscription(subscription);
req.setPriority(2);
sendRequest(req);
}
/**
* {@inheritDoc}
*/
@Override
public void sendApprovedPendingSubscriptionNotification(
InitialPendingSubscription subscription, String username) {
ApprovedPendingSubscriptionNotificationRequest req = new ApprovedPendingSubscriptionNotificationRequest();
req.setMessage("Approved subscription " + subscription.getName());
req.setUserId(username);
req.setCategory("Subscription Approved");
req.setPriority(2);
req.setSubscription(subscription);
sendRequest(req);
}
/**
* {@inheritDoc}
*/
@Override
public void sendDeniedPendingSubscriptionNotification(
InitialPendingSubscription subscription, String username,
String denyMessage) {
DeniedPendingSubscriptionNotificationRequest req = new DeniedPendingSubscriptionNotificationRequest();
req.setMessage(denyMessage);
req.setUserId(username);
req.setCategory("Subscription Approval Denied");
req.setPriority(2);
req.setId(subscription.getId());
sendRequest(req);
}
/**
* {@inheritDoc}
*/
@Override
public void sendDeletedSubscriptionNotification(Subscription subscription,
String username) {
SubscriptionNotificationRequest req = new SubscriptionNotificationRequest();
req.setUserId(username);
req.setCategory("Subscription");
req.setPriority(3);
req.setMessage(subscription.getName() + " Deleted");
subscription.setDeleted(true);
req.setSubscription(subscription);
sendRequest(req);
}
/**
* {@inheritDoc}
*/
@Override
public void sendSubscriptionActivatedNotification(
Subscription subscription,
String username) {
SubscriptionNotificationRequest req = new SubscriptionNotificationRequest();
req.setUserId(username);
req.setCategory("Subscription");
req.setPriority(3);
req.setMessage(subscription.getName() + " Activated");
sendRequest(req);
}
/**
* {@inheritDoc}
*/
@Override
public void sendSubscriptionDeactivatedNotification(
Subscription subscription,
String username) {
SubscriptionNotificationRequest req = new SubscriptionNotificationRequest();
req.setUserId(username);
req.setCategory("Subscription");
req.setPriority(3);
req.setMessage(subscription.getName() + " Deactivated");
sendRequest(req);
}
/**
* Send the notification request.
*
* @param req
*/
private void sendRequest(BaseSubscriptionNotificationRequest<?> req) {
try {
ThriftClient.sendRequest(req);
} catch (VizException e) {
statusHandler.handle(Priority.PROBLEM, e.getLocalizedMessage(), e);
}
}
}

View file

@ -57,7 +57,6 @@ import org.eclipse.swt.widgets.TableColumn;
import com.raytheon.uf.common.auth.user.IUser;
import com.raytheon.uf.common.datadelivery.registry.Subscription;
import com.raytheon.uf.common.datadelivery.registry.handlers.ISubscriptionHandler;
import com.raytheon.uf.common.datadelivery.request.DataDeliveryAuthRequest;
import com.raytheon.uf.common.datadelivery.request.DataDeliveryPermission;
import com.raytheon.uf.common.localization.IPathManager;
import com.raytheon.uf.common.localization.LocalizationContext;
@ -235,17 +234,22 @@ public class SubscriptionManagerDlg extends CaveSWTDialog implements
private SubscriptionApprovalDlg dlg = null;
/** Create Group Dialog */
private CreateGroupDlg createGroupDlg;
private CreateGroupDefinitionDlg createGroupDlg;
/** Edit Group Dialog */
private CreateGroupDlg editGroupDlg;
private EditGroupDefinitionDlg editGroupDlg;
/** Delete Group Dialog */
private DeleteGroupDlg deleteGroupDlg;
/** The subscription service */
private final ISubscriptionService subscriptionService = DataDeliveryServices
.getSubscriptionService();
/** The subscription notification service */
private final ISubscriptionNotificationService subscriptionNotificationService = DataDeliveryServices
.getSubscriptionNotificationService();
/**
* Constructor
*
@ -658,13 +662,8 @@ public class SubscriptionManagerDlg extends CaveSWTDialog implements
IUser user = UserController.getUserObject();
String msg = user.uniqueId()
+ " is not authorized to create subscriptions";
DataDeliveryAuthRequest request = new DataDeliveryAuthRequest();
request.setUser(user);
request.addRequestedPermissions(permission);
request.setNotAuthorizedMessage(msg);
try {
if (DataDeliveryUtils.sendAuthorizationRequest(request)
if (DataDeliveryServices.getPermissionsService().checkPermission(user, msg, permission)
.isAuthorized()) {
DataBrowserAction action = new DataBrowserAction();
Map<String, String> params = new HashMap<String, String>();
@ -786,24 +785,21 @@ public class SubscriptionManagerDlg extends CaveSWTDialog implements
String msg = user.uniqueId()
+ " is not authorized to access the Dataset Discovery Browser\nPermission: "
+ permission;
DataDeliveryAuthRequest request = new DataDeliveryAuthRequest();
request.setUser(user);
request.addRequestedPermissions(permission);
request.setNotAuthorizedMessage(msg);
try {
if (DataDeliveryUtils.sendAuthorizationRequest(request)
if (DataDeliveryServices.getPermissionsService().checkPermission(user, msg, permission)
.isAuthorized()) {
if (create) {
if (createGroupDlg == null) {
createGroupDlg = new CreateGroupDlg(this.shell, this);
createGroupDlg = new CreateGroupDefinitionDlg(
this.shell, this);
}
createGroupDlg.open();
} else {
if (thereAreGroupsAvailable()) {
if (editGroupDlg == null) {
editGroupDlg = new CreateGroupDlg(this.shell,
false, this);
editGroupDlg = new EditGroupDefinitionDlg(
this.shell, this);
}
editGroupDlg.open();
} else {
@ -911,15 +907,10 @@ public class SubscriptionManagerDlg extends CaveSWTDialog implements
String msg = user.uniqueId()
+ " is not authorized to Delete subscriptions.\nPermission: "
+ permission;
DataDeliveryAuthRequest request = new DataDeliveryAuthRequest();
request.setUser(user);
request.addRequestedPermissions(permission);
request.setNotAuthorizedMessage(msg);
try {
DataDeliveryAuthRequest authReq = DataDeliveryUtils
.sendAuthorizationRequest(request);
if (authReq != null && authReq.isAuthorized()) {
if (DataDeliveryServices.getPermissionsService().checkPermission(user, msg, permission)
.isAuthorized()) {
String message = null;
if (selectionCount > 1) {
@ -1004,15 +995,9 @@ public class SubscriptionManagerDlg extends CaveSWTDialog implements
+ ((activate) ? "Activate" : "Deactivate")
+ " Subscriptions\nPermission: " + permission;
DataDeliveryAuthRequest request = new DataDeliveryAuthRequest();
request.setUser(user);
request.addRequestedPermissions(permission);
request.setNotAuthorizedMessage(msg);
try {
DataDeliveryAuthRequest authReq = DataDeliveryUtils
.sendAuthorizationRequest(request);
if (authReq != null && authReq.isAuthorized()) {
if (DataDeliveryServices.getPermissionsService().checkPermission(user, msg, permission)
.isAuthorized()) {
final List<Subscription> updatedList = new ArrayList<Subscription>();
int count = tableComp.getTable().getSelectionCount();
@ -1049,13 +1034,14 @@ public class SubscriptionManagerDlg extends CaveSWTDialog implements
updatedList.add(sub);
if (activate) {
subscriptionService
.sendSubscriptionActivatedMessage(sub,
subscriptionNotificationService
.sendSubscriptionActivatedNotification(
sub,
username);
} else {
subscriptionService
.sendSubscriptionDeactivatedMessage(
subscriptionNotificationService
.sendSubscriptionDeactivatedNotification(
sub, username);
}
@ -1257,23 +1243,17 @@ public class SubscriptionManagerDlg extends CaveSWTDialog implements
}
private boolean isApproved() {
// check to see if user if authorized to see pending changes
// check to see if user is authorized to see pending changes
IUser user = UserController.getUserObject();
try {
DataDeliveryAuthRequest request = new DataDeliveryAuthRequest();
request.setUser(user);
request.addRequestedPermissions(
String msg = user.uniqueId()
+ " is not authorized to access Subscription Approval";
return DataDeliveryServices.getPermissionsService().checkPermissions(user, msg,
DataDeliveryPermission.SUBSCRIPTION_APPROVE_SITE,
DataDeliveryPermission.SUBSCRIPTION_APPROVE_USER,
DataDeliveryPermission.SUBSCRIPTION_APPROVE_VIEW);
request.setNotAuthorizedMessage(user.uniqueId()
+ " is not authorized to access Subscription Approval");
DataDeliveryAuthRequest response = DataDeliveryUtils
.sendAuthorizationRequest(request);
if (response != null && response.isAuthorized()) {
return true;
}
DataDeliveryPermission.SUBSCRIPTION_APPROVE_VIEW)
.isAuthorized();
} catch (VizException e) {
statusHandler.handle(Priority.PROBLEM, e.getLocalizedMessage(), e);
}
@ -1301,7 +1281,8 @@ public class SubscriptionManagerDlg extends CaveSWTDialog implements
handler.delete(username, subscriptions);
for (Subscription subscription : subscriptions) {
subscriptionService.sendDeletedSubscriptionNotification(
subscriptionNotificationService
.sendDeletedSubscriptionNotification(
subscription, username);
}
} catch (RegistryHandlerException e) {

View file

@ -21,25 +21,27 @@ package com.raytheon.uf.viz.datadelivery.subscription;
import java.text.SimpleDateFormat;
import java.util.Arrays;
import java.util.Collection;
import java.util.Date;
import java.util.List;
import java.util.Set;
import java.util.SortedSet;
import java.util.TimeZone;
import java.util.TreeSet;
import java.util.concurrent.Callable;
import org.eclipse.swt.widgets.Shell;
import com.google.common.annotations.VisibleForTesting;
import com.raytheon.uf.common.auth.user.IUser;
import com.raytheon.uf.common.datadelivery.bandwidth.IBandwidthService;
import com.raytheon.uf.common.datadelivery.bandwidth.IProposeScheduleResponse;
import com.raytheon.uf.common.datadelivery.event.notification.ApprovedPendingSubscriptionNotificationRequest;
import com.raytheon.uf.common.datadelivery.event.notification.BaseSubscriptionNotificationRequest;
import com.raytheon.uf.common.datadelivery.event.notification.DeniedPendingSubscriptionNotificationRequest;
import com.raytheon.uf.common.datadelivery.event.notification.PendingSubscriptionNotificationRequest;
import com.raytheon.uf.common.datadelivery.event.notification.SubscriptionNotificationRequest;
import com.raytheon.uf.common.datadelivery.registry.AdhocSubscription;
import com.raytheon.uf.common.datadelivery.registry.InitialPendingSubscription;
import com.raytheon.uf.common.datadelivery.registry.PendingSubscription;
import com.raytheon.uf.common.datadelivery.registry.Subscription;
import com.raytheon.uf.common.datadelivery.registry.handlers.DataDeliveryHandlers;
import com.raytheon.uf.common.datadelivery.registry.handlers.IPendingSubscriptionHandler;
import com.raytheon.uf.common.datadelivery.registry.handlers.ISubscriptionHandler;
import com.raytheon.uf.common.registry.handler.RegistryHandlerException;
import com.raytheon.uf.common.status.IUFStatusHandler;
@ -47,9 +49,9 @@ import com.raytheon.uf.common.status.UFStatus;
import com.raytheon.uf.common.status.UFStatus.Priority;
import com.raytheon.uf.common.util.StringUtil;
import com.raytheon.uf.viz.core.VizApp;
import com.raytheon.uf.viz.core.auth.UserController;
import com.raytheon.uf.viz.core.exception.VizException;
import com.raytheon.uf.viz.core.requests.ThriftClient;
import com.raytheon.uf.viz.datadelivery.services.DataDeliveryServices;
import com.raytheon.uf.viz.datadelivery.utils.DataDeliveryUtils;
/**
* Basic implementation of the {@link ISubscriptionService}.
@ -67,6 +69,7 @@ import com.raytheon.uf.viz.datadelivery.services.DataDeliveryServices;
* Dec 11, 2012 1403 djohnson Adhoc subscriptions no longer go to the registry.
* Dec 18, 2012 1443 bgonzale Open force apply prompt pop-up on the UI thread.
* Dec 20, 2012 1413 bgonzale Added new pending approve and denied request and responses.
* Jan 04, 2013 1441 djohnson Separated out notification methods into their own service.
*
* </pre>
*
@ -75,11 +78,15 @@ import com.raytheon.uf.viz.datadelivery.services.DataDeliveryServices;
*/
public class SubscriptionService implements ISubscriptionService {
private static final String PENDING_SUBSCRIPTION_AWAITING_APPROVAL = "The subscription is awaiting approval.\n\n"
+ "A notification message will be generated upon approval.";
/**
* Implementation of {@link IDisplayForceApplyPrompt} that uses an SWT
* dialog.
*/
public class DisplayForceApplyPrompt implements IDisplayForceApplyPrompt {
private static class DisplayForceApplyPrompt implements
IDisplayForceApplyPrompt {
private ForceApplyPromptResponse forceApplyPromptResponse = ForceApplyPromptResponse.CANCEL;
@ -118,6 +125,14 @@ public class SubscriptionService implements ISubscriptionService {
@VisibleForTesting
final String TITLE = "Subscription";
private final ISubscriptionNotificationService notificationService;
private final IBandwidthService bandwidthService;
private final IPermissionsService permissionsService;
private final IDisplayForceApplyPrompt forceApplyPrompt;
/**
* Implementation of {@link ISubscriptionServiceResult}.
*/
@ -193,10 +208,12 @@ public class SubscriptionService implements ISubscriptionService {
}
/**
* Used to represent a runnable that can throw a registry exception.
* A service interaction.
*/
private interface RegistryRunnable {
void run() throws RegistryHandlerException;
private interface ServiceInteraction extends Callable<String> {
// Throws only one exception
@Override
String call() throws RegistryHandlerException;
}
/**
@ -263,6 +280,44 @@ public class SubscriptionService implements ISubscriptionService {
Shell getShell();
}
/**
* Private constructor. Use
* {@link #newInstance(ISubscriptionNotificationService)} instead.
*
* @param notificationService
* the subscription notification service
* @param bandwidthService
* the bandwidth service
*/
@VisibleForTesting
SubscriptionService(ISubscriptionNotificationService notificationService,
IBandwidthService bandwidthService,
IPermissionsService permissionsService,
IDisplayForceApplyPrompt displayForceApplyPrompt) {
this.notificationService = notificationService;
this.bandwidthService = bandwidthService;
this.permissionsService = permissionsService;
this.forceApplyPrompt = displayForceApplyPrompt;
}
/**
* Factory method to create an {@link ISubscriptionService}. Allows for
* changing to use sub-classes or different implementations later, without
* tying specifically to the implementation class.
*
* @param notificationService
* @param permissionsService
* @param bandwidthService
* @return the subscription service
*/
public static ISubscriptionService newInstance(
ISubscriptionNotificationService notificationService,
IBandwidthService bandwidthService,
IPermissionsService permissionsService) {
return new SubscriptionService(notificationService, bandwidthService,
permissionsService, new DisplayForceApplyPrompt());
}
/**
* {@inheritDoc}
*/
@ -272,19 +327,19 @@ public class SubscriptionService implements ISubscriptionService {
throws RegistryHandlerException {
final List<Subscription> subscriptions = Arrays.asList(subscription);
final RegistryRunnable action = new RegistryRunnable() {
final String successMessage = "Subscription " + subscription.getName()
+ " has been created.";
final ServiceInteraction action = new ServiceInteraction() {
@Override
public void run() throws RegistryHandlerException {
public String call() throws RegistryHandlerException {
DataDeliveryHandlers.getSubscriptionHandler().store(
subscription);
return successMessage;
}
};
final String successMessage = "Subscription " + subscription.getName()
+ " has been created.";
return performAction(subscriptions, action, successMessage,
displayTextStrategy);
return performAction(subscriptions, action, displayTextStrategy);
}
/**
@ -297,18 +352,18 @@ public class SubscriptionService implements ISubscriptionService {
throws RegistryHandlerException {
final List<Subscription> subscriptions = Arrays.asList(subscription);
final RegistryRunnable action = new RegistryRunnable() {
@Override
public void run() throws RegistryHandlerException {
DataDeliveryHandlers.getSubscriptionHandler().update(
subscription);
}
};
final String successMessage = "Subscription " + subscription.getName()
+ " has been updated.";
final ServiceInteraction action = new ServiceInteraction() {
@Override
public String call() throws RegistryHandlerException {
DataDeliveryHandlers.getSubscriptionHandler().update(
subscription);
return successMessage;
}
};
return performAction(subscriptions, action, successMessage,
displayTextStrategy);
return performAction(subscriptions, action, displayTextStrategy);
}
/**
@ -319,18 +374,114 @@ public class SubscriptionService implements ISubscriptionService {
IForceApplyPromptDisplayText displayTextStrategy)
throws RegistryHandlerException {
final RegistryRunnable action = new RegistryRunnable() {
final String successMessage = "The subscriptions have been updated.";
final ServiceInteraction action = new ServiceInteraction() {
@Override
public void run() throws RegistryHandlerException {
public String call() throws RegistryHandlerException {
for (Subscription sub : subs) {
DataDeliveryHandlers.getSubscriptionHandler().update(sub);
}
return successMessage;
}
};
final String successMessage = "The subscriptions have been updated.";
return performAction(subs, action, displayTextStrategy);
}
return performAction(subs, action, successMessage, displayTextStrategy);
/**
* {@inheritDoc}
*/
@Override
public ISubscriptionServiceResult updateWithPendingCheck(
final List<Subscription> subscriptions,
IForceApplyPromptDisplayText displayTextStrategy)
throws RegistryHandlerException {
final ServiceInteraction action = new ServiceInteraction() {
@Override
public String call() throws RegistryHandlerException {
final SortedSet<String> alreadyPending = new TreeSet<String>();
final SortedSet<String> pendingCreated = new TreeSet<String>();
final SortedSet<String> unableToUpdate = new TreeSet<String>();
final StringBuilder successMessage = new StringBuilder(
"The subscriptions have been updated.");
final IPendingSubscriptionHandler pendingSubscriptionHandler = DataDeliveryHandlers
.getPendingSubscriptionHandler();
for (Subscription subscription : subscriptions) {
try {
InitialPendingSubscription pending = pendingSubscriptionHandler
.getBySubscription(subscription);
if (pending != null) {
alreadyPending.add(subscription.getName());
continue;
}
} catch (RegistryHandlerException e1) {
statusHandler
.handle(Priority.INFO,
DataDeliveryUtils.UNABLE_TO_RETRIEVE_PENDING_SUBSCRIPTIONS,
e1);
unableToUpdate.add(subscription.getName());
continue;
}
IUser user = UserController.getUserObject();
final String username = user.uniqueId().toString();
try {
boolean authorized = permissionsService
.checkPermissionToChangeSubscription(user,
PENDING_SUBSCRIPTION_AWAITING_APPROVAL,
subscription).isAuthorized();
try {
if (authorized) {
DataDeliveryHandlers.getSubscriptionHandler()
.update(subscription);
} else {
PendingSubscription pendingSub = new PendingSubscription(
subscription, username);
pendingSub
.setChangeReason("Group Definition Changed");
savePendingSub(pendingSub, username);
pendingCreated.add(subscription.getName());
}
} catch (RegistryHandlerException e1) {
statusHandler
.handle(Priority.INFO,
DataDeliveryUtils.UNABLE_TO_RETRIEVE_PENDING_SUBSCRIPTIONS,
e1);
unableToUpdate.add(subscription.getName());
continue;
}
} catch (VizException e) {
statusHandler.handle(Priority.INFO,
e.getLocalizedMessage(), e);
}
}
appendCollectionPortion(
successMessage,
"\n\nThe following subscriptions have pending changes awaiting approval:",
pendingCreated);
appendCollectionPortion(
successMessage,
"\n\nThe following subscriptions already had pending changes and were not modified:",
alreadyPending);
appendCollectionPortion(
successMessage,
"\n\nThe following subscriptions were unable to be modified:",
unableToUpdate);
return successMessage.toString();
}
};
return performAction(subscriptions, action, displayTextStrategy);
}
/**
@ -343,19 +494,20 @@ public class SubscriptionService implements ISubscriptionService {
final List<Subscription> subscriptions = Arrays
.<Subscription> asList(sub);
final RegistryRunnable action = new RegistryRunnable() {
final String successMessage = "The query was successfully stored.";
final ServiceInteraction action = new ServiceInteraction() {
@Override
public void run() throws RegistryHandlerException {
public String call() {
// Adhoc subscriptions don't interact with the registry any
// longer, so it gets a blank implementation
return successMessage;
}
};
final String successMessage = "The query was successfully stored.";
SubscriptionServiceResult result = performAction(subscriptions, action,
successMessage, displayTextStrategy);
displayTextStrategy);
if (!result.allowFurtherEditing) {
Date date = getBandwidthService().getEstimatedCompletionTime(sub);
Date date = bandwidthService.getEstimatedCompletionTime(sub);
if (date != null) {
SimpleDateFormat sdf = new SimpleDateFormat(
"MM/dd/yyyy HH:mm zzz");
@ -379,25 +531,22 @@ public class SubscriptionService implements ISubscriptionService {
*
* @param subscriptions
* @param action
* @param successMessage
* @param displayTextStrategy
* @return the result object
* @throws RegistryHandlerException
*/
private SubscriptionServiceResult performAction(
List<Subscription> subscriptions, RegistryRunnable action,
String successMessage,
List<Subscription> subscriptions, ServiceInteraction action,
final IForceApplyPromptDisplayText displayTextStrategy)
throws RegistryHandlerException {
try {
final ProposeResult result = proposeScheduleAndAction(
subscriptions, action, successMessage);
subscriptions, action);
if (result.promptUser) {
final Subscription subscription = (subscriptions.size() == 1) ? subscriptions
.get(0) : null;
final IDisplayForceApplyPrompt forceApplyPrompt = getForceApplyPromptDisplay();
VizApp.runSync(new Runnable() {
@Override
@ -418,9 +567,9 @@ public class SubscriptionService implements ISubscriptionService {
for (Subscription temp : subscriptions) {
temp.setUnscheduled(false);
}
action.run();
String successMessage = action.call();
final Set<String> unscheduled = getBandwidthService()
final Set<String> unscheduled = bandwidthService
.schedule(subscriptions);
updateSubscriptionsByNameToUnscheduled(unscheduled);
@ -440,48 +589,39 @@ public class SubscriptionService implements ISubscriptionService {
} catch (RegistryHandlerException e) {
// The in-memory objects must be corrupted since we schedule first,
// then store to the registry, so a reinitialize is called for
getBandwidthService().reinitialize();
bandwidthService.reinitialize();
throw e;
}
}
/**
* Get the force apply prompt for display
*
* @return the force apply prompt display
*/
IDisplayForceApplyPrompt getForceApplyPromptDisplay() {
return new DisplayForceApplyPrompt();
}
/**
* Proposes scheduling the subscriptions (with any modifications that have
* been made) in the bandwidth manager. If subscriptions would be
* unscheduled as a result, then a message is returned designating such.
*
* @param subscriptions
* @param registryAction
* @param successMessage
* @param serviceInteraction
* @return the result
* @throws RegistryHandlerException
*/
private ProposeResult proposeScheduleAndAction(
List<Subscription> subscriptions, RegistryRunnable registryAction,
String successMessage) throws RegistryHandlerException {
List<Subscription> subscriptions,
ServiceInteraction serviceInteraction)
throws RegistryHandlerException {
IProposeScheduleResponse proposeScheduleresponse = getBandwidthService()
IProposeScheduleResponse proposeScheduleresponse = bandwidthService
.proposeSchedule(subscriptions);
Set<String> unscheduledSubscriptions = proposeScheduleresponse
.getUnscheduledSubscriptions();
boolean wouldUnscheduleSubs = !unscheduledSubscriptions.isEmpty();
String response = successMessage;
String response = null;
if (wouldUnscheduleSubs) {
response = getWouldCauseUnscheduledSubscriptionsPortion(
unscheduledSubscriptions, subscriptions);
} else {
registryAction.run();
response = serviceInteraction.call();
}
return new ProposeResult(wouldUnscheduleSubs, response,
@ -532,212 +672,42 @@ public class SubscriptionService implements ISubscriptionService {
*/
private void getUnscheduledSubscriptionsPortion(StringBuilder msg,
Set<String> unscheduledSubscriptions) {
if (unscheduledSubscriptions.isEmpty()) {
appendCollectionPortion(
msg,
"\n\nThe following subscriptions did not fully schedule with the bandwidth management system:",
unscheduledSubscriptions);
}
/**
* Append a collection of items underneath a preamble text.
*
* @param msg
* the current text
* @param preamble
* the preamble
* @param collection
* the collection of items
*/
private void appendCollectionPortion(StringBuilder msg, String preamble,
Collection<String> collection) {
if (collection.isEmpty()) {
return;
}
msg.append(StringUtil
.createMessage(
"\n\nThe following subscriptions did not fully schedule with the bandwidth management system:",
unscheduledSubscriptions));
msg.append(StringUtil.createMessage(preamble, collection));
}
/**
* Get the bandwidth service to use.
* Save a pending subscription.
*
* @return the bandwidth service
* @throws RegistryHandlerException
*/
@VisibleForTesting
IBandwidthService getBandwidthService() {
return DataDeliveryServices.getBandwidthService();
}
private void savePendingSub(PendingSubscription pendingSub, String username)
throws RegistryHandlerException {
DataDeliveryHandlers.getPendingSubscriptionHandler().store(pendingSub);
/**
* Send a notification that a subscription has been created.
*
* @param subscription
* the subscription
* @param username
* the username
*/
@Override
public void sendCreatedSubscriptionNotification(Subscription subscription,
String username) {
BaseSubscriptionNotificationRequest<Subscription> req = new SubscriptionNotificationRequest();
req.setUserId(username);
req.setCategory("Subscription");
String msg = "Subscription " + subscription.getName()
+ " has been created.";
req.setMessage(msg);
req.setSubscription(subscription);
req.setPriority(3);
sendRequest(req);
}
/**
* {@inheritDoc}
*/
@Override
public void sendCreatedPendingSubscriptionNotification(
InitialPendingSubscription subscription, String username) {
BaseSubscriptionNotificationRequest<InitialPendingSubscription> req = new PendingSubscriptionNotificationRequest();
req.setUserId(username);
req.setCategory("Subscription");
req.setSubscription(subscription);
req.setPriority(2);
req.setMessage("Pending Subscription " + subscription.getName()
+ " has been created.");
sendRequest(req);
}
/**
* {@inheritDoc}
*/
@Override
public void sendUpdatedSubscriptionNotification(Subscription subscription,
String username) {
BaseSubscriptionNotificationRequest<Subscription> req = new SubscriptionNotificationRequest();
req.setUserId(username);
req.setCategory("Subscription");
String msg = "Subscription " + subscription.getName()
+ " has been updated.";
req.setMessage(msg);
req.setSubscription(subscription);
req.setPriority(3);
sendRequest(req);
}
/**
* {@inheritDoc}
*/
@Override
public void sendUpdatedPendingSubscriptionNotification(
InitialPendingSubscription subscription, String username) {
BaseSubscriptionNotificationRequest<InitialPendingSubscription> req = new PendingSubscriptionNotificationRequest();
req.setUserId(username);
req.setCategory("Subscription");
req.setMessage("Edited subscription " + subscription.getName());
req.setSubscription(subscription);
req.setPriority(2);
sendRequest(req);
}
/**
* {@inheritDoc}
*/
@Override
public void sendCreatedPendingSubscriptionForSubscriptionNotification(
InitialPendingSubscription subscription, String username) {
BaseSubscriptionNotificationRequest<InitialPendingSubscription> req = new PendingSubscriptionNotificationRequest();
req.setUserId(username);
req.setCategory("Subscription");
req.setMessage("Edited subscription " + subscription.getName());
req.setSubscription(subscription);
req.setPriority(2);
sendRequest(req);
}
/**
* {@inheritDoc}
*/
@Override
public void sendApprovedPendingSubscriptionNotification(
InitialPendingSubscription subscription, String username) {
ApprovedPendingSubscriptionNotificationRequest req = new ApprovedPendingSubscriptionNotificationRequest();
req.setMessage("Approved subscription " + subscription.getName());
req.setUserId(username);
req.setCategory("Subscription Approved");
req.setPriority(2);
req.setSubscription(subscription);
sendRequest(req);
}
/**
* {@inheritDoc}
*/
@Override
public void sendDeniedPendingSubscriptionNotification(
InitialPendingSubscription subscription, String username,
String denyMessage) {
DeniedPendingSubscriptionNotificationRequest req = new DeniedPendingSubscriptionNotificationRequest();
req.setMessage(denyMessage);
req.setUserId(username);
req.setCategory("Subscription Approval Denied");
req.setPriority(2);
req.setId(subscription.getId());
sendRequest(req);
}
/**
* {@inheritDoc}
*/
@Override
public void sendDeletedSubscriptionNotification(Subscription subscription,
String username) {
SubscriptionNotificationRequest req = new SubscriptionNotificationRequest();
req.setUserId(username);
req.setCategory("Subscription");
req.setPriority(3);
req.setMessage(subscription.getName() + " Deleted");
subscription.setDeleted(true);
req.setSubscription(subscription);
sendRequest(req);
}
/**
* {@inheritDoc}
*/
@Override
public void sendSubscriptionActivatedMessage(Subscription subscription,
String username) {
SubscriptionNotificationRequest req = new SubscriptionNotificationRequest();
req.setUserId(username);
req.setCategory("Subscription");
req.setPriority(3);
req.setMessage(subscription.getName() + " Activated");
sendRequest(req);
}
/**
* {@inheritDoc}
*/
@Override
public void sendSubscriptionDeactivatedMessage(Subscription subscription,
String username) {
SubscriptionNotificationRequest req = new SubscriptionNotificationRequest();
req.setUserId(username);
req.setCategory("Subscription");
req.setPriority(3);
req.setMessage(subscription.getName() + " Deactivated");
sendRequest(req);
}
/**
* Send the notification request.
*
* @param req
*/
private void sendRequest(BaseSubscriptionNotificationRequest<?> req) {
try {
ThriftClient.sendRequest(req);
} catch (VizException e) {
statusHandler.handle(Priority.PROBLEM, e.getLocalizedMessage(), e);
}
notificationService
.sendCreatedPendingSubscriptionForSubscriptionNotification(
pendingSub, username);
}
private void updateSubscriptionsByNameToUnscheduled(

View file

@ -52,7 +52,6 @@ import com.raytheon.uf.common.datadelivery.registry.PendingSubscription;
import com.raytheon.uf.common.datadelivery.registry.Subscription;
import com.raytheon.uf.common.datadelivery.registry.handlers.DataDeliveryHandlers;
import com.raytheon.uf.common.datadelivery.registry.handlers.ISubscriptionHandler;
import com.raytheon.uf.common.datadelivery.request.DataDeliveryAuthRequest;
import com.raytheon.uf.common.datadelivery.request.DataDeliveryPermission;
import com.raytheon.uf.common.registry.handler.RegistryHandlerException;
import com.raytheon.uf.common.registry.handler.RegistryObjectHandlers;
@ -71,6 +70,7 @@ import com.raytheon.uf.viz.datadelivery.common.ui.TableCompConfig;
import com.raytheon.uf.viz.datadelivery.common.ui.TableDataManager;
import com.raytheon.uf.viz.datadelivery.common.ui.ViewDetailsDlg;
import com.raytheon.uf.viz.datadelivery.common.xml.ColumnXML;
import com.raytheon.uf.viz.datadelivery.services.DataDeliveryServices;
import com.raytheon.uf.viz.datadelivery.subscription.subset.SubsetManagerDlg;
import com.raytheon.uf.viz.datadelivery.subscription.xml.SubscriptionManagerConfigXML;
import com.raytheon.uf.viz.datadelivery.utils.DataDeliveryGUIUtils;
@ -148,7 +148,7 @@ public class SubscriptionTableComp extends TableComp implements IGroupAction {
/**
* Constructor.
*
*
* @param parent
* Parent composite.
* @param tableConfig
@ -217,19 +217,16 @@ public class SubscriptionTableComp extends TableComp implements IGroupAction {
String msg = user.uniqueId()
+ " is not authorized to access the Dataset Discovery Browser\nPermission: "
+ permission;
DataDeliveryAuthRequest request = new DataDeliveryAuthRequest();
request.setUser(user);
request.addRequestedPermissions(permission);
request.setNotAuthorizedMessage(msg);
try {
if (DataDeliveryUtils.sendAuthorizationRequest(request)
.isAuthorized()) {
if (DataDeliveryServices.getPermissionsService()
.checkPermissions(user, msg, permission).isAuthorized()) {
// Get the subscription data
int idx = table.getSelectionIndex();
SubscriptionManagerRowData row = subManagerData.getDataRow(idx);
SubsetManagerDlg dlg = SubsetManagerDlg.fromSubscription(
this.getShell(), true, row.getSubscription());
SubsetManagerDlg<?, ?, ?> dlg = SubsetManagerDlg
.fromSubscription(this.getShell(), true,
row.getSubscription());
dlg.open();
}
@ -271,14 +268,10 @@ public class SubscriptionTableComp extends TableComp implements IGroupAction {
String msg = user.uniqueId()
+ " is not authorized to access Group Add\nPermission: "
+ permission;
DataDeliveryAuthRequest request = new DataDeliveryAuthRequest();
request.setUser(user);
request.addRequestedPermissions(permission);
request.setNotAuthorizedMessage(msg);
try {
if (DataDeliveryUtils.sendAuthorizationRequest(request)
.isAuthorized()) {
if (DataDeliveryServices.getPermissionsService()
.checkPermissions(user, msg, permission).isAuthorized()) {
// Get the subscription data
int idx = table.getSelectionIndex();
SubscriptionManagerRowData row = subManagerData.getDataRow(idx);
@ -329,7 +322,7 @@ public class SubscriptionTableComp extends TableComp implements IGroupAction {
/**
* Get the table.
*
*
* @return The table.
*/
public Table getTable() {
@ -338,7 +331,7 @@ public class SubscriptionTableComp extends TableComp implements IGroupAction {
/**
* Action performed when the column is selected.
*
*
* @param tc
* Table column.
*/
@ -359,10 +352,10 @@ public class SubscriptionTableComp extends TableComp implements IGroupAction {
/**
* Populate the table data according to the filter selections, .
*
*
* @param groupName
* name of subscription group
*
*
* @param officeId
* Office identifier, such as OAX
*/
@ -391,10 +384,10 @@ public class SubscriptionTableComp extends TableComp implements IGroupAction {
/**
* Populate the table data according to the filter selections, .
*
*
* @param datasetName
* name of dataset. e.g. gfs
*
*
* @param provider
* name of provider. e.g. NOMADS
*/
@ -468,7 +461,7 @@ public class SubscriptionTableComp extends TableComp implements IGroupAction {
/**
* Add a subscription to the list of subscriptions.
*
*
* @param subscription
* Subscription to add to the subscription list.
*/
@ -480,7 +473,7 @@ public class SubscriptionTableComp extends TableComp implements IGroupAction {
/**
* Get the column data XML class.
*
*
* @param colName
* Column name.
* @return The column data XML class.
@ -500,7 +493,7 @@ public class SubscriptionTableComp extends TableComp implements IGroupAction {
/**
* Get the table cell text
*
*
* @param name
* The column name
* @param rd
@ -568,7 +561,7 @@ public class SubscriptionTableComp extends TableComp implements IGroupAction {
/**
* Update the table with the list of subscriptions.
*
*
* @param updatedSubscriptions
* List of updated subscriptions.
*/
@ -616,7 +609,7 @@ public class SubscriptionTableComp extends TableComp implements IGroupAction {
/**
* Get the data manager for the subscription data.
*
*
* @return The data manager.
*/
public TableDataManager<SubscriptionManagerRowData> getSubscriptionData() {
@ -625,7 +618,7 @@ public class SubscriptionTableComp extends TableComp implements IGroupAction {
/**
* Get the sorted table column.
*
*
* @return The table column that is sorted.
*/
public TableColumn getSortedTableColumn() {
@ -634,7 +627,7 @@ public class SubscriptionTableComp extends TableComp implements IGroupAction {
/*
* (non-Javadoc)
*
*
* @see
* com.raytheon.uf.viz.datadelivery.common.ui.TableComp#getCurrentSortDirection
* ()
@ -646,7 +639,7 @@ public class SubscriptionTableComp extends TableComp implements IGroupAction {
/*
* (non-Javadoc)
*
*
* @see com.raytheon.uf.viz.datadelivery.common.ui.TableComp#createColumns()
*/
@Override
@ -683,7 +676,7 @@ public class SubscriptionTableComp extends TableComp implements IGroupAction {
/*
* (non-Javadoc)
*
*
* @see com.raytheon.uf.viz.datadelivery.common.ui.TableComp#populateTable()
*/
@Override
@ -726,7 +719,7 @@ public class SubscriptionTableComp extends TableComp implements IGroupAction {
/*
* (non-Javadoc)
*
*
* @see
* com.raytheon.uf.viz.datadelivery.common.ui.TableComp#handleTableMouseClick
* (org.eclipse.swt.events.MouseEvent)
@ -782,7 +775,7 @@ public class SubscriptionTableComp extends TableComp implements IGroupAction {
/*
* (non-Javadoc)
*
*
* @see com.raytheon.uf.viz.datadelivery.common.ui.TableComp#
* handleTableSelectionChange(org.eclipse.swt.events.SelectionEvent)
*/
@ -867,7 +860,7 @@ public class SubscriptionTableComp extends TableComp implements IGroupAction {
/**
* Set the subscription list.
*
*
* @param subscriptionNameList
*/
public void setSubscriptionNameList(List<String> subscriptionNameList) {

View file

@ -39,7 +39,6 @@ import com.raytheon.uf.common.datadelivery.registry.InitialPendingSubscription;
import com.raytheon.uf.common.datadelivery.registry.PendingSubscription;
import com.raytheon.uf.common.datadelivery.registry.Subscription;
import com.raytheon.uf.common.datadelivery.registry.handlers.IPendingSubscriptionHandler;
import com.raytheon.uf.common.datadelivery.request.DataDeliveryAuthRequest;
import com.raytheon.uf.common.datadelivery.request.DataDeliveryPermission;
import com.raytheon.uf.common.registry.handler.RegistryHandlerException;
import com.raytheon.uf.common.registry.handler.RegistryObjectHandlers;
@ -56,6 +55,9 @@ import com.raytheon.uf.viz.datadelivery.common.ui.TableCompConfig;
import com.raytheon.uf.viz.datadelivery.common.ui.TableDataManager;
import com.raytheon.uf.viz.datadelivery.services.DataDeliveryServices;
import com.raytheon.uf.viz.datadelivery.subscription.CancelForceApplyAndIncreaseLatencyDisplayText;
import com.raytheon.uf.viz.datadelivery.subscription.IPermissionsService;
import com.raytheon.uf.viz.datadelivery.subscription.IPermissionsService.IAuthorizedPermissionResponse;
import com.raytheon.uf.viz.datadelivery.subscription.ISubscriptionNotificationService;
import com.raytheon.uf.viz.datadelivery.subscription.ISubscriptionService;
import com.raytheon.uf.viz.datadelivery.subscription.ISubscriptionService.ISubscriptionServiceResult;
import com.raytheon.uf.viz.datadelivery.subscription.SubscriptionService.ForceApplyPromptResponse;
@ -130,10 +132,17 @@ public class SubscriptionApprovalDlg extends CaveSWTDialog implements
private final ISubscriptionService subscriptionService = DataDeliveryServices
.getSubscriptionService();
private final ISubscriptionNotificationService subscriptionNotificationService = DataDeliveryServices
.getSubscriptionNotificationService();
private final IPermissionsService permissionsService = DataDeliveryServices
.getPermissionsService();
private SubApprovalTableComp tableComp;
private String denyMessage;
/**
* Constructor.
*
@ -317,14 +326,17 @@ public class SubscriptionApprovalDlg extends CaveSWTDialog implements
return;
}
getShell().setCursor(getDisplay().getSystemCursor(SWT.CURSOR_WAIT));
DataDeliveryAuthRequest response = allowed();
if (response != null && response.isAuthorized()) {
IUser user = UserController.getUserObject();
IAuthorizedPermissionResponse response = allowed(user);
if (response.isAuthorized()) {
// Check if user or site permissions, compare to owner of sub if user permission
IUser user = UserController.getUserObject();
boolean site = false;
if (response
.isAuthorized(DataDeliveryPermission.SUBSCRIPTION_APPROVE_SITE)) {
.hasPermission(DataDeliveryPermission.SUBSCRIPTION_APPROVE_SITE)) {
site = true;
}
@ -362,6 +374,34 @@ public class SubscriptionApprovalDlg extends CaveSWTDialog implements
getShell().setCursor(null);
}
/**
* @return
*/
private IAuthorizedPermissionResponse allowed(IUser user) {
try {
String msg = user.uniqueId()
+ " is not authorized to Approve/Deny subscriptions.";
return permissionsService.checkPermissions(user, msg,
DataDeliveryPermission.SUBSCRIPTION_APPROVE_SITE,
DataDeliveryPermission.SUBSCRIPTION_APPROVE_USER);
} catch (VizException e) {
statusHandler.handle(Priority.PROBLEM,
"Unable to check user permissions.", e);
return new IAuthorizedPermissionResponse() {
@Override
public boolean isAuthorized() {
return false;
}
@Override
public boolean hasPermission(DataDeliveryPermission permission) {
return false;
}
};
}
}
@Override
public void handleDeny() {
if (tableComp.getTable().getSelectionCount() == 0) {
@ -370,15 +410,16 @@ public class SubscriptionApprovalDlg extends CaveSWTDialog implements
return;
}
getShell().setCursor(getDisplay().getSystemCursor(SWT.CURSOR_WAIT));
DataDeliveryAuthRequest response = allowed();
if (response != null && response.isAuthorized()) {
IUser user = UserController.getUserObject();
IAuthorizedPermissionResponse response = allowed(user);
if (response.isAuthorized()) {
if (confirm()) {
// Check if user or site permissions, compare to owner of sub if user permission
IUser user = UserController.getUserObject();
boolean site = false;
if (response
.isAuthorized(DataDeliveryPermission.SUBSCRIPTION_APPROVE_SITE)) {
.hasPermission(DataDeliveryPermission.SUBSCRIPTION_APPROVE_SITE)) {
site = true;
}
@ -409,7 +450,7 @@ public class SubscriptionApprovalDlg extends CaveSWTDialog implements
try {
handler.delete(username, sub);
subscriptionService
subscriptionNotificationService
.sendDeniedPendingSubscriptionNotification(
sub, username, denyMessage);
} catch (RegistryHandlerException e) {
@ -443,22 +484,6 @@ public class SubscriptionApprovalDlg extends CaveSWTDialog implements
return false;
}
private DataDeliveryAuthRequest allowed() {
IUser user = UserController.getUserObject();
String msg = user.uniqueId() + " is not authorized to Approve/Deny subscriptions.";
DataDeliveryAuthRequest request = new DataDeliveryAuthRequest();
request.setUser(user);
request.addRequestedPermissions(DataDeliveryPermission.SUBSCRIPTION_APPROVE_SITE,
DataDeliveryPermission.SUBSCRIPTION_APPROVE_USER);
request.setNotAuthorizedMessage(msg);
try {
return DataDeliveryUtils.sendAuthorizationRequest(request);
} catch (VizException e) {
statusHandler.handle(Priority.PROBLEM, e.getLocalizedMessage(), e);
return null;
}
}
private void approveSubs(ArrayList<SubscriptionApprovalRowData> subList) {
tableComp.getPendingSubData().removeAll(subList);
@ -485,7 +510,7 @@ public class SubscriptionApprovalDlg extends CaveSWTDialog implements
exceptionMessage = "Unable to delete pending subscription.";
pendingSubHandler.delete(username, ps);
subscriptionService
subscriptionNotificationService
.sendApprovedPendingSubscriptionNotification(ps,
username);
}

View file

@ -48,7 +48,6 @@ import com.raytheon.uf.common.datadelivery.registry.Subscription;
import com.raytheon.uf.common.datadelivery.registry.Utils.SubscriptionStatus;
import com.raytheon.uf.common.datadelivery.registry.handlers.IPendingSubscriptionHandler;
import com.raytheon.uf.common.datadelivery.registry.handlers.ISubscriptionHandler;
import com.raytheon.uf.common.datadelivery.request.DataDeliveryAuthRequest;
import com.raytheon.uf.common.datadelivery.request.DataDeliveryPermission;
import com.raytheon.uf.common.registry.ebxml.RegistryUtil;
import com.raytheon.uf.common.registry.handler.RegistryHandlerException;
@ -64,11 +63,11 @@ import com.raytheon.uf.viz.core.localization.LocalizationManager;
import com.raytheon.uf.viz.datadelivery.services.DataDeliveryServices;
import com.raytheon.uf.viz.datadelivery.subscription.CancelForceApplyAndIncreaseLatencyDisplayText;
import com.raytheon.uf.viz.datadelivery.subscription.GroupDefinitionManager;
import com.raytheon.uf.viz.datadelivery.subscription.ISubscriptionNotificationService;
import com.raytheon.uf.viz.datadelivery.subscription.ISubscriptionService;
import com.raytheon.uf.viz.datadelivery.subscription.ISubscriptionService.ISubscriptionServiceResult;
import com.raytheon.uf.viz.datadelivery.subscription.view.ICreateSubscriptionDlgView;
import com.raytheon.uf.viz.datadelivery.utils.DataDeliveryGUIUtils;
import com.raytheon.uf.viz.datadelivery.utils.DataDeliveryUtils;
import com.raytheon.viz.ui.presenter.components.ButtonConf;
import com.raytheon.viz.ui.presenter.components.CheckBoxConf;
import com.raytheon.viz.ui.presenter.components.ComboBoxConf;
@ -107,6 +106,9 @@ import com.raytheon.viz.ui.presenter.components.WidgetConf;
*/
public class CreateSubscriptionDlgPresenter {
private static final String PENDING_APPROVAL_MESSAGE = "The subscription is awaiting approval.\n\n"
+ "A notification message will be generated upon approval.";
/** Status Handler */
private final IUFStatusHandler statusHandler = UFStatus
.getHandler(CreateSubscriptionDlgPresenter.class);
@ -166,6 +168,9 @@ public class CreateSubscriptionDlgPresenter {
@VisibleForTesting
Set<Integer> cycleTimes;
private final ISubscriptionNotificationService subscriptionNotificationService = DataDeliveryServices
.getSubscriptionNotificationService();
/**
* Constructor.
*
@ -436,8 +441,6 @@ public class CreateSubscriptionDlgPresenter {
if (groupValid && view.isGroupSelected()) {
subscription.setGroupName(view.getGroupName());
} else {
subscription.setGroupName(GroupDefinition.NO_GROUP);
}
if (view.isNoExpirationDate()) {
@ -518,21 +521,13 @@ public class CreateSubscriptionDlgPresenter {
if (this.create) {
try {
boolean autoApprove = false;
boolean autoApprove = DataDeliveryServices
.getPermissionsService()
.checkPermissionToChangeSubscription(user,
PENDING_APPROVAL_MESSAGE, subscription)
.isAuthorized();
DataDeliveryAuthRequest r = getApproval();
if (r != null && r.isAuthorized()) {
if (r.isAuthorized(DataDeliveryPermission.SUBSCRIPTION_APPROVE_SITE)) {
autoApprove = true;
} else if (r
.isAuthorized(DataDeliveryPermission.SUBSCRIPTION_APPROVE_USER)) {
if (subscription.getOwner().equals(username)) {
autoApprove = true;
}
}
setSubscriptionId(subscription);
}
setSubscriptionId(subscription);
if (autoApprove) {
final Shell jobShell = view.getShell();
@ -558,7 +553,7 @@ public class CreateSubscriptionDlgPresenter {
job.addJobChangeListener(new JobChangeAdapter() {
@Override
public void done(final IJobChangeEvent event) {
subscriptionService
subscriptionNotificationService
.sendCreatedSubscriptionNotification(
subscription, username);
@ -599,7 +594,7 @@ public class CreateSubscriptionDlgPresenter {
this.subscription = pendingSub;
subscriptionService
subscriptionNotificationService
.sendCreatedPendingSubscriptionNotification(
pendingSub, username);
} catch (RegistryHandlerException e) {
@ -642,79 +637,55 @@ public class CreateSubscriptionDlgPresenter {
// check to see if user is authorized to approve. If so then
// auto-approve
try {
boolean autoApprove = false;
DataDeliveryAuthRequest r = getApproval();
boolean autoApprove = DataDeliveryServices
.getPermissionsService()
.checkPermissionToChangeSubscription(user,
PENDING_APPROVAL_MESSAGE, subscription)
.isAuthorized();
if (r != null && r.isAuthorized()) {
if (r.isAuthorized(DataDeliveryPermission.SUBSCRIPTION_APPROVE_SITE)) {
autoApprove = true;
} else if (r
.isAuthorized(DataDeliveryPermission.SUBSCRIPTION_APPROVE_USER)) {
if (subscription.getOwner().equals(username)) {
autoApprove = true;
if (autoApprove) {
try {
final ISubscriptionServiceResult response = subscriptionService
.update(subscription,
new CancelForceApplyAndIncreaseLatencyDisplayText(
"update", view.getShell()));
if (response.hasMessageToDisplay()) {
view.displayPopup(UPDATED_TITLE,
response.getMessageToDisplay());
}
}
if (autoApprove) {
try {
final ISubscriptionServiceResult response = subscriptionService
.update(subscription,
new CancelForceApplyAndIncreaseLatencyDisplayText(
"update", view.getShell()));
if (response.hasMessageToDisplay()) {
view.displayPopup(UPDATED_TITLE,
response.getMessageToDisplay());
}
// If there was a force apply prompt, and the user
// selects no, then we want to allow them to
// continue editing the subscription
if (response.isAllowFurtherEditing()) {
return false;
}
subscriptionService
.sendUpdatedSubscriptionNotification(
subscription, username);
} catch (RegistryHandlerException e) {
statusHandler.handle(Priority.PROBLEM,
"Unable to update subscription.", e);
// If there was a force apply prompt, and the user
// selects no, then we want to allow them to
// continue editing the subscription
if (response.isAllowFurtherEditing()) {
return false;
}
} else {
setSubscriptionId(subscription);
try {
handler.update(pendingSub);
subscriptionService
.sendCreatedPendingSubscriptionForSubscriptionNotification(
pendingSub, username);
subscriptionNotificationService
.sendUpdatedSubscriptionNotification(
subscription, username);
final String msg = "The subscription is awaiting approval.\n\n"
+ "A notification message will be generated upon approval.";
view.displayPopup("Subscription Pending", msg);
} catch (RegistryHandlerException e) {
statusHandler
.handle(Priority.PROBLEM,
"Unable to create pending subscription.",
e);
}
} catch (RegistryHandlerException e) {
statusHandler.handle(Priority.PROBLEM,
"Unable to update subscription.", e);
}
} else {
setSubscriptionId(pendingSub);
setSubscriptionId(subscription);
try {
handler.update(pendingSub);
subscriptionService
.sendUpdatedPendingSubscriptionNotification(
subscriptionNotificationService
.sendCreatedPendingSubscriptionForSubscriptionNotification(
pendingSub, username);
this.subscription = pendingSub;
final String msg = PENDING_APPROVAL_MESSAGE;
view.displayPopup("Subscription Pending", msg);
} catch (RegistryHandlerException e) {
statusHandler.handle(Priority.PROBLEM,
"Unable to create pending subscription.", e);
}
}
} catch (VizException e) {
statusHandler.handle(Priority.PROBLEM, e.getLocalizedMessage(),
e);
@ -758,8 +729,8 @@ public class CreateSubscriptionDlgPresenter {
*/
@VisibleForTesting
void sendSubscriptionNotification(Subscription subscription, String username) {
subscriptionService.sendCreatedSubscriptionNotification(subscription,
username);
subscriptionNotificationService.sendCreatedSubscriptionNotification(
subscription, username);
}
/**
@ -1093,19 +1064,6 @@ public class CreateSubscriptionDlgPresenter {
return activeDatesValid;
}
private DataDeliveryAuthRequest getApproval() throws VizException {
IUser user = UserController.getUserObject();
DataDeliveryAuthRequest request = new DataDeliveryAuthRequest();
request.setUser(user);
request.addRequestedPermissions(
DataDeliveryPermission.SUBSCRIPTION_APPROVE_SITE,
DataDeliveryPermission.SUBSCRIPTION_APPROVE_USER);
request.setNotAuthorizedMessage("The subscription is awaiting approval.\n\n"
+ "A notification message will be generated upon approval.");
return DataDeliveryUtils.sendAuthorizationRequest(request);
}
public int getStatus() {
return view.getStatus();
}

View file

@ -31,13 +31,13 @@ import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.List;
import com.raytheon.uf.common.auth.user.IUser;
import com.raytheon.uf.common.datadelivery.request.DataDeliveryAuthRequest;
import com.raytheon.uf.common.datadelivery.request.DataDeliveryPermission;
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.core.auth.UserController;
import com.raytheon.uf.viz.core.exception.VizException;
import com.raytheon.uf.viz.datadelivery.services.DataDeliveryServices;
import com.raytheon.uf.viz.datadelivery.utils.DataDeliveryUtils;
/**
@ -221,16 +221,10 @@ public class SystemLatencyTab {
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()) {
if (DataDeliveryServices.getPermissionsService()
.checkPermission(user, msg, permission).isAuthorized()) {
if (ruleDlg == null || ruleDlg.isDisposed()) {
@ -278,16 +272,11 @@ public class SystemLatencyTab {
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 (DataDeliveryServices.getPermissionsService()
.checkPermission(user, msg, permission).isAuthorized()) {
if (auth != null && auth.isAuthorized()) {
String ruleName = null;
int selectedIdx = latencyList.getSelectionIndex();
if (selectedIdx > -1) {

View file

@ -31,13 +31,13 @@ import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.List;
import com.raytheon.uf.common.auth.user.IUser;
import com.raytheon.uf.common.datadelivery.request.DataDeliveryAuthRequest;
import com.raytheon.uf.common.datadelivery.request.DataDeliveryPermission;
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.core.auth.UserController;
import com.raytheon.uf.viz.core.exception.VizException;
import com.raytheon.uf.viz.datadelivery.services.DataDeliveryServices;
import com.raytheon.uf.viz.datadelivery.utils.DataDeliveryUtils;
/**
@ -230,16 +230,11 @@ public class SystemPriorityTab {
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 (DataDeliveryServices.getPermissionsService()
.checkPermission(user, msg, permission).isAuthorized()) {
if (auth != null && auth.isAuthorized()) {
if (ruleDlg == null || ruleDlg.isDisposed()) {
// New
if (create) {
@ -286,16 +281,11 @@ public class SystemPriorityTab {
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 (DataDeliveryServices.getPermissionsService()
.checkPermission(user, msg, permission).isAuthorized()) {
if (auth != null && auth.isAuthorized()) {
String ruleName = null;
int selectedIdx = priorityList.getSelectionIndex();
if (selectedIdx > -1) {

View file

@ -33,10 +33,7 @@ import com.raytheon.uf.common.datadelivery.registry.DataLevelType;
import com.raytheon.uf.common.datadelivery.registry.Parameter;
import com.raytheon.uf.common.datadelivery.registry.Subscription;
import com.raytheon.uf.common.datadelivery.registry.Time;
import com.raytheon.uf.common.datadelivery.request.DataDeliveryAuthRequest;
import com.raytheon.uf.common.util.CollectionUtil;
import com.raytheon.uf.viz.core.exception.VizException;
import com.raytheon.uf.viz.core.requests.ThriftClient;
import com.vividsolutions.jts.geom.Coordinate;
/**
@ -308,7 +305,7 @@ public class DataDeliveryUtils {
/**
* Get the column titles (column names).
*
*
* @param tableType
* Table type.
* @return String array of column titles.
@ -524,17 +521,4 @@ public class DataDeliveryUtils {
return fmtStr.toString();
}
/**
* Send an authorization request
*
* @param request
* The request object
* @return DataDeliveryAuthReqeust object
* @throws VizException
*/
public static DataDeliveryAuthRequest sendAuthorizationRequest(
DataDeliveryAuthRequest request) throws VizException {
return (DataDeliveryAuthRequest) ThriftClient
.sendPrivilegedRequest(request);
}
}

View file

@ -47,8 +47,9 @@ import com.raytheon.uf.common.time.util.TimeUtil;
* Oct 26, 2012 1286 djohnson Add toString, equals, hashcode.
* Nov 19, 2012 1166 djohnson Clean up JAXB representation of registry objects.
* Nov 20, 2012 1166 djohnson Use attributes for Subscription fields.
* Nov 20, 2012 1286 djohnson Add unscheduled.
* Dec 12, 2012 1433 bgonzale Refactored Subscription copy ctor into two ctors.
* Nov 20, 2012 1286 djohnson Add unscheduled.
* Dec 12, 2012 1433 bgonzale Refactored Subscription copy ctor into two ctors.
* Jan 03, 2013 1441 djohnson Default to no group.
*
* </pre>
*
@ -146,7 +147,7 @@ public class Subscription implements ISerializableObject, Serializable {
@XmlAttribute
@DynamicSerializeElement
@SlotAttribute
private String groupName;
private String groupName = GroupDefinition.NO_GROUP;
@XmlAttribute
@DynamicSerializeElement

View file

@ -66,5 +66,6 @@
<classpathentry combineaccessrules="false" kind="src" path="/com.raytheon.uf.common.datadelivery.request"/>
<classpathentry combineaccessrules="false" kind="src" path="/com.raytheon.uf.common.stats"/>
<classpathentry combineaccessrules="false" kind="src" path="/com.raytheon.uf.edex.stats"/>
<classpathentry combineaccessrules="false" kind="src" path="/com.raytheon.uf.viz.plugin.nwsauth"/>
<classpathentry kind="output" path="bin"/>
</classpath>

View file

@ -0,0 +1 @@
com.raytheon.uf.common.util.ThisWillBeLoadedFromConfigFile

View file

@ -0,0 +1 @@
com.raytheon.uf.viz.core.auth.TestUserManagerLoader

View file

@ -0,0 +1,43 @@
/**
* 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.common.util;
import org.junit.Ignore;
/**
*
* Marker interface used in {@link ServiceLoaderUtilTest}.
*
* <pre>
*
* SOFTWARE HISTORY
*
* Date Ticket# Engineer Description
* ------------ ---------- ----------- --------------------------
* Jan 04, 2013 1441 djohnson Initial creation
*
* </pre>
*
* @author djohnson
* @version 1.0
*/
@Ignore
public interface HasServiceLoaderConfigFile {
}

View file

@ -0,0 +1,77 @@
/**
* 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.common.util;
import static org.hamcrest.CoreMatchers.equalTo;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.CoreMatchers.not;
import static org.hamcrest.CoreMatchers.sameInstance;
import static org.junit.Assert.assertThat;
import org.junit.Test;
/**
* Test {@link ServiceLoaderUtil}.
*
* <pre>
*
* SOFTWARE HISTORY
*
* Date Ticket# Engineer Description
* ------------ ---------- ----------- --------------------------
* Jan 04, 2013 1441 djohnson Initial creation
*
* </pre>
*
* @author djohnson
* @version 1.0
*/
public class ServiceLoaderUtilTest {
public static interface NoServiceLoaderConfigFile {
}
@Test
public void testUsesDefaultWhenNoImplementationConfigFilePresent() {
NoServiceLoaderConfigFile defaultImplementation = new NoServiceLoaderConfigFile() {
};
NoServiceLoaderConfigFile loaded = ServiceLoaderUtil.load(
NoServiceLoaderConfigFile.class,
defaultImplementation);
assertThat(loaded, is(sameInstance(defaultImplementation)));
}
@Test
public void testUsesServiceLoaderVersionWhenImplementationConfigFilePresent() {
HasServiceLoaderConfigFile defaultImplementation = new HasServiceLoaderConfigFile() {
};
HasServiceLoaderConfigFile loaded = ServiceLoaderUtil.load(
HasServiceLoaderConfigFile.class,
defaultImplementation);
assertThat(loaded, is(not(sameInstance(defaultImplementation))));
assertThat(loaded.getClass().getName(),
is(equalTo(ThisWillBeLoadedFromConfigFile.class.getName())));
}
}

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.common.util;
import org.junit.Ignore;
/**
*
* Class used in {@link ServiceLoaderUtilTest}.
*
* <pre>
*
* SOFTWARE HISTORY
*
* Date Ticket# Engineer Description
* ------------ ---------- ----------- --------------------------
* Jan 04, 2013 1441 djohnson Initial creation
*
* </pre>
*
* @author djohnson
* @version 1.0
*/
@Ignore
public class ThisWillBeLoadedFromConfigFile implements
HasServiceLoaderConfigFile {
}

View file

@ -0,0 +1,109 @@
/**
* 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.core.auth;
import java.util.Collections;
import java.util.List;
import com.raytheon.uf.common.auth.user.IAuthenticationData;
import com.raytheon.uf.common.auth.user.IPermission;
import com.raytheon.uf.common.auth.user.IRole;
import com.raytheon.uf.common.auth.user.IUser;
import com.raytheon.uf.common.plugin.nwsauth.user.User;
import com.raytheon.uf.viz.core.requests.INotAuthHandler;
import com.raytheon.uf.viz.plugin.nwsauth.NwsNotAuthHandler;
/**
* An {@link IUserManagerLoader} that can be used in tests.
*
* <pre>
*
* SOFTWARE HISTORY
*
* Date Ticket# Engineer Description
* ------------ ---------- ----------- --------------------------
* Jan 04, 2013 1441 djohnson Initial creation
*
* </pre>
*
* @author djohnson
* @version 1.0
*/
public class TestUserManagerLoader implements IUserManagerLoader {
public static class TestUserManager implements IUserManager {
private static final User USER = new User("testuser");
private static final INotAuthHandler NOT_AUTH_HANDLER = new NwsNotAuthHandler();
/**
* {@inheritDoc}
*/
@Override
public IUser getUserObject() {
return USER;
}
/**
* {@inheritDoc}
*/
@Override
public void updateUserObject(IUser user, IAuthenticationData authData) {
// Currently unused
}
/**
* {@inheritDoc}
*/
@Override
public INotAuthHandler getNotAuthHandler() {
return NOT_AUTH_HANDLER;
}
/**
* {@inheritDoc}
*/
@Override
public List<IPermission> getPermissions(String application) {
return Collections.emptyList();
}
/**
* {@inheritDoc}
*/
@Override
public List<IRole> getRoles(String application) {
return Collections.emptyList();
}
}
private static final TestUserManager USER_MANAGER = new TestUserManager();
/**
* {@inheritDoc}
*/
@Override
public IUserManager getUserManager() {
return USER_MANAGER;
}
}

View file

@ -98,27 +98,17 @@ public abstract class AbstractSubscriptionServiceTest {
subNameResults.add(sub2Name);
}
final ISubscriptionNotificationService notificationService = mock(ISubscriptionNotificationService.class);
final IBandwidthService mockBandwidthService = mock(IBandwidthService.class);
final IPermissionsService permissionsService = mock(IPermissionsService.class);
final IDisplayForceApplyPrompt mockDisplay = mock(IDisplayForceApplyPrompt.class);
final SubscriptionService service = new SubscriptionService() {
/**
* {@inheritDoc}
*/
@Override
IBandwidthService getBandwidthService() {
return mockBandwidthService;
}
/**
* {@inheritDoc}
*/
@Override
IDisplayForceApplyPrompt getForceApplyPromptDisplay() {
return mockDisplay;
}
};
final SubscriptionService service = new SubscriptionService(
notificationService, mockBandwidthService, permissionsService,
mockDisplay);
final IProposeScheduleResponse mockProposeScheduleResponse = mock(IProposeScheduleResponse.class);
@ -350,7 +340,7 @@ public abstract class AbstractSubscriptionServiceTest {
/**
* When the force apply prompt is displayed, the user selects no.
*/
private void whenForceApplyPromptedUserSelectsCancel() {
protected void whenForceApplyPromptedUserSelectsCancel() {
when(mockDisplay.getForceApplyPromptResponse()).thenReturn(
ForceApplyPromptResponse.CANCEL);
}
@ -358,7 +348,7 @@ public abstract class AbstractSubscriptionServiceTest {
/**
* When the force apply prompt is displayed, the user selects yes.
*/
private void whenForceApplyPromptedUserSelectsForceApply() {
protected void whenForceApplyPromptedUserSelectsForceApply() {
when(mockDisplay.getForceApplyPromptResponse()).thenReturn(
ForceApplyPromptResponse.FORCE_APPLY);
}

View file

@ -19,16 +19,34 @@
**/
package com.raytheon.uf.viz.datadelivery.subscription;
import static org.hamcrest.CoreMatchers.equalTo;
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat;
import static org.mockito.Matchers.any;
import static org.mockito.Matchers.anyString;
import static org.mockito.Matchers.same;
import static org.mockito.Mockito.doThrow;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.verifyZeroInteractions;
import static org.mockito.Mockito.when;
import java.util.Collections;
import org.junit.Before;
import org.junit.Test;
import com.raytheon.uf.common.auth.user.IUser;
import com.raytheon.uf.common.datadelivery.registry.InitialPendingSubscription;
import com.raytheon.uf.common.datadelivery.registry.Subscription;
import com.raytheon.uf.common.datadelivery.registry.handlers.DataDeliveryHandlers;
import com.raytheon.uf.common.datadelivery.registry.handlers.ISubscriptionHandler;
import com.raytheon.uf.common.datadelivery.request.DataDeliveryPermission;
import com.raytheon.uf.common.registry.handler.RegistryHandlerException;
import com.raytheon.uf.common.registry.handler.RegistryObjectHandlersUtil;
import com.raytheon.uf.common.util.CollectionUtil;
import com.raytheon.uf.viz.core.exception.VizException;
import com.raytheon.uf.viz.datadelivery.subscription.IPermissionsService.IAuthorizedPermissionResponse;
import com.raytheon.uf.viz.datadelivery.subscription.ISubscriptionService.ISubscriptionServiceResult;
/**
@ -51,6 +69,130 @@ import com.raytheon.uf.viz.datadelivery.subscription.ISubscriptionService.ISubsc
public class SubscriptionServiceMassUpdateTest extends
AbstractSubscriptionServiceTest {
private final IAuthorizedPermissionResponse authorizedPermissionsResponse = mock(IAuthorizedPermissionResponse.class);
@Before
public void setUpPermissionsResponse() throws VizException {
userHasAllPermissions();
}
@Test
public void testUpdateWithPendingCheckCancelingForceApplyDoesNotUpdateSubscriptions()
throws RegistryHandlerException {
RegistryObjectHandlersUtil.initMocks();
returnTwoSubscriptionNamesWhenProposeScheduleCalled();
whenForceApplyPromptedUserSelectsCancel();
service.updateWithPendingCheck(subs, mockPromptDisplayText);
verifyZeroInteractions(DataDeliveryHandlers.getSubscriptionHandler());
}
@Test
public void testUpdateWithPendingCheckForceApplyUpdatesSubscriptions()
throws RegistryHandlerException {
RegistryObjectHandlersUtil.initMocks();
returnTwoSubscriptionNamesWhenProposeScheduleCalled();
whenForceApplyPromptedUserSelectsForceApply();
service.updateWithPendingCheck(subs, mockPromptDisplayText);
final ISubscriptionHandler subscriptionHandler = DataDeliveryHandlers
.getSubscriptionHandler();
for (Subscription sub : subs) {
verify(subscriptionHandler).update(sub);
}
}
@Test
public void testUpdateWithPendingCheckNotifiesOfSubscriptionsAlreadyPending()
throws RegistryHandlerException {
RegistryObjectHandlersUtil.initMocks();
returnZeroSubscriptionNamesWhenProposeScheduleCalled();
subscriptionAlreadyHasPendingChanges(sub1);
final ISubscriptionServiceResult response = service
.updateWithPendingCheck(subs, mockPromptDisplayText);
final String expectedMessage = "The subscriptions have been updated.\n\nThe following subscriptions already had pending changes and were not modified:\n"
+ sub1.getName();
assertThat(response.getMessageToDisplay(), is(equalTo(expectedMessage)));
}
@Test
public void testUpdateWithPendingCheckNotifiesOfSubscriptionsUnableToBeUpdated()
throws RegistryHandlerException, VizException {
RegistryObjectHandlersUtil.initMocks();
returnZeroSubscriptionNamesWhenProposeScheduleCalled();
subscriptionThrowsErrorOnUpdate(sub2);
final ISubscriptionServiceResult response = service
.updateWithPendingCheck(subs, mockPromptDisplayText);
final String expectedMessage = "The subscriptions have been updated.\n\nThe following subscriptions were unable to be modified:\n"
+ sub2.getName();
assertThat(response.getMessageToDisplay(), is(equalTo(expectedMessage)));
}
@Test
public void testUpdateWithPendingCheckNotifiesOfPendingSubscriptionsCreated()
throws RegistryHandlerException, VizException {
RegistryObjectHandlersUtil.initMocks();
returnZeroSubscriptionNamesWhenProposeScheduleCalled();
subscriptionCantBeChangedByUser(sub2);
final ISubscriptionServiceResult response = service
.updateWithPendingCheck(subs, mockPromptDisplayText);
final String expectedMessage = "The subscriptions have been updated.\n\nThe following subscriptions have pending changes awaiting approval:\n"
+ sub2.getName();
assertThat(response.getMessageToDisplay(), is(equalTo(expectedMessage)));
}
/**
* When the user requests to change the specified subscription, the registry
* throws an exception.
*
* @param subscription
* the subscription
* @throws RegistryHandlerException
*/
private void subscriptionThrowsErrorOnUpdate(Subscription sub2)
throws RegistryHandlerException {
doThrow(new RegistryHandlerException("thrown on purpose")).when(
DataDeliveryHandlers.getSubscriptionHandler()).update(sub2);
}
/**
* When the user requests to change the specified subscription, they will
* not have permission.
*
* @param subscription
* the subscription
* @throws VizException
*/
private void subscriptionCantBeChangedByUser(Subscription subscription)
throws VizException {
IAuthorizedPermissionResponse noPermission = mock(IAuthorizedPermissionResponse.class);
when(
permissionsService
.checkPermissionToChangeSubscription(any(IUser.class),
any(String.class), same(subscription)))
.thenReturn(noPermission);
when(noPermission.isAuthorized()).thenReturn(false);
}
/**
* {@inheritDoc}
*/
@ -65,7 +207,8 @@ public class SubscriptionServiceMassUpdateTest extends
*/
@Override
void returnTwoSubscriptionNamesWhenProposeScheduleCalled() {
when(mockBandwidthService.proposeSchedule(subs)).thenReturn(mockProposeScheduleResponse);
when(mockBandwidthService.proposeSchedule(subs)).thenReturn(
mockProposeScheduleResponse);
when(mockProposeScheduleResponse.getUnscheduledSubscriptions())
.thenReturn(subNameResults);
}
@ -169,4 +312,34 @@ public class SubscriptionServiceMassUpdateTest extends
// This test does expect a null argument to be passed, not an error
return null;
}
private void userHasAllPermissions() throws VizException {
when(
permissionsService.checkPermission(any(IUser.class),
anyString(), any(DataDeliveryPermission.class)))
.thenReturn(authorizedPermissionsResponse);
when(
permissionsService.checkPermissions(any(IUser.class),
anyString(), any(DataDeliveryPermission.class)))
.thenReturn(authorizedPermissionsResponse);
when(
permissionsService.checkPermissionToChangeSubscription(
any(IUser.class), anyString(), any(Subscription.class)))
.thenReturn(authorizedPermissionsResponse);
when(authorizedPermissionsResponse.isAuthorized()).thenReturn(true);
}
/**
* Sets a subscription to already have pending changes.
*
* @param subscription
* @throws RegistryHandlerException
*/
private void subscriptionAlreadyHasPendingChanges(Subscription subscription)
throws RegistryHandlerException {
when(
DataDeliveryHandlers.getPendingSubscriptionHandler()
.getBySubscription(subscription)).thenReturn(
new InitialPendingSubscription());
}
}