Merge "Issue #2864 - Change how saved subset files are stored." into development

Former-commit-id: 8a682a5e23 [formerly 05fed9ffbd4c61601d6a42b2ef3dadefde7e1a3c]
Former-commit-id: 695878c6aa
This commit is contained in:
Richard Peter 2014-04-11 09:41:31 -05:00 committed by Gerrit Code Review
commit 0fa4180959
6 changed files with 406 additions and 73 deletions

View file

@ -19,8 +19,6 @@
**/
package com.raytheon.uf.viz.datadelivery.actions;
import java.io.File;
import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
@ -30,20 +28,20 @@ import org.eclipse.ui.PlatformUI;
import com.raytheon.uf.common.auth.AuthException;
import com.raytheon.uf.common.auth.user.IUser;
import com.raytheon.uf.common.datadelivery.registry.DataSet;
import com.raytheon.uf.common.datadelivery.registry.DataType;
import com.raytheon.uf.common.datadelivery.request.DataDeliveryPermission;
import com.raytheon.uf.common.localization.LocalizationFile;
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.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.viz.ui.dialogs.ICloseCallback;
import com.raytheon.viz.ui.dialogs.ListSelectionDlg;
/**
* Handler for launching the Subset Manager Dialog.
@ -56,12 +54,13 @@ import com.raytheon.viz.ui.dialogs.ICloseCallback;
* ------------ ---------- ----------- --------------------------
* Apr 02, 2012 mpduff Initial creation
* Aug 06, 2012 955 djohnson Change to accept {@link DataSet}.
* Aug 10, 2012 1022 djohnson Store provider name in {@link SubsetXml}, use GriddedDataSet.
* Aug 10, 2012 1022 djohnson Store provider name in {@link SubsetXML}, use GriddedDataSet.
* Aug 21, 2012 0743 djohnson Change getMetaData to getDataSet.
* Oct 03, 2012 1241 djohnson Use {@link DataDeliveryPermission}.
* Jul 26, 2013 2232 mpduff Refactored Data Delivery permissions.
* Sep 04, 2013 2314 mpduff LoadSave dialog now non-blocking.
* Oct 11, 2013 2386 mpduff Refactor DD Front end.
* Apr 10, 2014 2864 mpduff Changed how saved subset files are stored.
*
* </pre>
*
@ -74,15 +73,11 @@ public class SubsetAction extends AbstractHandler {
private final IUFStatusHandler statusHandler = UFStatus
.getHandler(SubsetAction.class);
/** Saved subset path */
private final String SUBSET_PATH = "dataDelivery" + File.separator
+ "subset" + File.separator;
/** Dialog instance */
private SubsetManagerDlg dlg = null;
/** Dialog instance */
private LoadSaveConfigDlg loadDlg = null;
private ListSelectionDlg selectionDlg = null;
private final String permission = DataDeliveryPermission.SUBSCRIPTION_EDIT
.toString();
@ -97,37 +92,55 @@ public class SubsetAction extends AbstractHandler {
+ permission;
if (DataDeliveryServices.getPermissionsService()
.checkPermissions(user, msg, permission).isAuthorized()) {
String[] choices = SubsetFileManager.getInstance()
.getAllLocalizationFileNames();
final Shell shell = PlatformUI.getWorkbench()
.getActiveWorkbenchWindow().getShell();
if (loadDlg == null || loadDlg.isDisposed()) {
loadDlg = new LoadSaveConfigDlg(shell, DialogType.OPEN,
SUBSET_PATH, "", true);
loadDlg.setCloseCallback(new ICloseCallback() {
if (selectionDlg == null || selectionDlg.isDisposed()) {
selectionDlg = new ListSelectionDlg(shell, choices);
selectionDlg.setCloseCallback(new ICloseCallback() {
@Override
public void dialogClosed(Object returnValue) {
if (returnValue instanceof LocalizationFile) {
LocalizationFile locFile = (LocalizationFile) returnValue;
SubsetXML subset = SubsetFileManager
.getInstance().loadSubset(
locFile.getFile().getName());
if (returnValue instanceof String[]) {
String[] selection = (String[]) returnValue;
if (selection.length == 1) {
String[] parts = selection[0].split(":");
DataSet data = MetaDataManager.getInstance()
.getDataSet(subset.getDatasetName(),
SubsetFileManager sfm = SubsetFileManager
.getInstance();
LocalizationFile locFile = sfm.getFile(
parts[1],
DataType.valueOf(parts[0]));
SubsetXML subset = SubsetFileManager
.getInstance().loadSubset(locFile);
DataSet data = MetaDataManager
.getInstance().getDataSet(
subset.getDatasetName(),
subset.getProviderName());
if (dlg == null || dlg.isDisposed()) {
dlg = SubsetManagerDlg.fromSubsetXML(shell,
data, true, subset);
dlg = SubsetManagerDlg.fromSubsetXML(
shell, data, true, subset);
dlg.open();
} else {
dlg.bringToTop();
}
} else {
throw new IllegalArgumentException(
"Expected 1 item, received "
+ selection.length
+ " items.");
}
} else {
throw new IllegalArgumentException(
"Invalid return type from ListSelectionDlg");
}
}
});
loadDlg.open();
selectionDlg.open();
} else {
loadDlg.bringToTop();
selectionDlg.bringToTop();
}
}
} catch (AuthException e) {

View file

@ -29,6 +29,7 @@ import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.List;
import org.eclipse.swt.widgets.Text;
import com.raytheon.uf.common.datadelivery.registry.DataType;
import com.raytheon.uf.common.localization.LocalizationFile;
import com.raytheon.uf.viz.datadelivery.subscription.subset.xml.SubsetXML;
import com.raytheon.uf.viz.datadelivery.utils.DataDeliveryUtils;
@ -45,6 +46,7 @@ import com.raytheon.uf.viz.datadelivery.utils.DataDeliveryUtils;
* Mar 30, 2012 mpduff Initial creation.
* Jun 4, 2012 645 jpiatt Added tooltips.
* Nov 1, 2012 1278 mpduff Formatted to meet coding standard.
* Apr 10, 2014 2864 mpduff Changed how saved subset files are stored.
*
* </pre>
*
@ -72,17 +74,23 @@ public class SavedSubsetTab extends SubsetTab {
/** File extension */
String extension = ".xml";
/** The type of data loaded in the dialog */
private final DataType dataType;
/**
* Constructor.
*
* @param comp
* Composite holding these controls
* @param dataType
* The datatype of the loaded data
* @param callback
* The class for callbacks
*/
public SavedSubsetTab(Composite comp, ITabAction callback) {
public SavedSubsetTab(Composite comp, DataType dataType, ITabAction callback) {
this.comp = comp;
this.callback = callback;
this.dataType = dataType;
init();
}
@ -155,7 +163,7 @@ public class SavedSubsetTab extends SubsetTab {
subsetList.removeAll();
// Get the subset data
for (LocalizationFile locFile : SubsetFileManager.getInstance()
.getSubsets()) {
.getLocalizationFiles(this.dataType)) {
String locFileName = locFile.getFile().getName();
subsetList.add(SubsetXML.getBaseSubsetName(locFileName));
}
@ -170,7 +178,8 @@ public class SavedSubsetTab extends SubsetTab {
.getSelectionIndex());
subsetName = subsetName + extension;
if (response == SWT.YES) {
SubsetFileManager.getInstance().deleteSubset(subsetName);
SubsetFileManager.getInstance().deleteSubset(subsetName,
this.dataType);
loadList();
}
} else {

View file

@ -20,6 +20,12 @@
package com.raytheon.uf.viz.datadelivery.subscription.subset;
import java.io.File;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.TreeSet;
import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;
@ -29,6 +35,7 @@ import javax.xml.bind.Unmarshaller;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Shell;
import com.raytheon.uf.common.datadelivery.registry.DataType;
import com.raytheon.uf.common.localization.IPathManager;
import com.raytheon.uf.common.localization.LocalizationContext;
import com.raytheon.uf.common.localization.LocalizationContext.LocalizationLevel;
@ -65,6 +72,7 @@ import com.raytheon.uf.viz.datadelivery.utils.DataDeliveryUtils;
* Nov 19, 2012 1289 bgonzale Added deleteArea(String) method.
* Jun 04, 2013 223 mpduff Added PointTimeXML to JaxB context.
* Oct 11, 2013 2386 mpduff Refactor DD Front end.
* Apr 10, 2014 2864 mpduff Changed how saved subset files are stored.
*
* </pre>
*
@ -97,14 +105,15 @@ public class SubsetFileManager {
/** Unmarshaller object */
private Unmarshaller unmarshaller;
/** Array of subset files */
private LocalizationFile[] subsetFiles;
private final Map<DataType, Set<LocalizationFile>> subsetFiles = new HashMap<DataType, Set<LocalizationFile>>();
/**
* Private constructor.
* Constructor.
*/
private SubsetFileManager() {
createContext();
populate();
}
/**
@ -172,7 +181,6 @@ public class SubsetFileManager {
return true;
} catch (JAXBException e) {
statusHandler.handle(Priority.ERROR, e.getLocalizedMessage(), e);
e.printStackTrace();
} catch (LocalizationOpFailedException e) {
statusHandler.handle(Priority.ERROR, e.getLocalizedMessage(), e);
}
@ -241,18 +249,40 @@ public class SubsetFileManager {
/**
* Get all the saved subset files
*
* @return LocalizationFile[]
* @param type
* Data type of files to retrieve
*
* @return LocalizationFile[] Array of files of DataType type
*/
public LocalizationFile[] getSubsets() {
private Set<LocalizationFile> getSubsetFiles(DataType type) {
IPathManager pm = PathManagerFactory.getPathManager();
LocalizationContext context = pm.getContext(
LocalizationType.CAVE_STATIC, LocalizationLevel.USER);
String[] extensions = new String[] { "xml" };
this.subsetFiles = pm.listFiles(context, SUBSET_PATH, extensions,
false, true);
String path = null;
return subsetFiles;
path = SUBSET_PATH + type.toString() + File.separator;
LocalizationFile[] fileArr = pm.listFiles(context, path, extensions,
false, true);
Set<LocalizationFile> files = new TreeSet<LocalizationFile>();
for (LocalizationFile file : fileArr) {
files.add(file);
}
return files;
}
private void populate() {
subsetFiles.clear();
for (DataType type : DataType.values()) {
subsetFiles.put(type, getSubsetFiles(type));
}
}
public Set<LocalizationFile> getLocalizationFiles(DataType type) {
return subsetFiles.get(type);
}
/**
@ -260,17 +290,20 @@ public class SubsetFileManager {
*
* @param subset
* the object to save
* @param type
* DataType
* @param shell
* The calling dialog's shell
* @return true if successfully saved
*/
public boolean saveSubset(SubsetXML subset, Shell shell) {
public boolean saveSubset(SubsetXML subset, DataType type, Shell shell) {
IPathManager pm = PathManagerFactory.getPathManager();
LocalizationContext context = pm.getContext(
LocalizationType.CAVE_STATIC, LocalizationLevel.USER);
LocalizationFile subsetLocFile = pm.getLocalizationFile(context,
SUBSET_PATH + subset.getSubsetName());
SUBSET_PATH + File.separator + type.toString() + File.separator
+ subset.getSubsetName());
if (subsetLocFile.getFile().exists()) {
String msg = "The file "
@ -286,7 +319,7 @@ public class SubsetFileManager {
try {
marshaller.marshal(subset, subsetLocFile.getFile());
subsetLocFile.save();
subsetFiles.get(type).add(subsetLocFile);
return true;
} catch (JAXBException e) {
statusHandler.handle(Priority.ERROR, e.getLocalizedMessage(), e);
@ -302,16 +335,13 @@ public class SubsetFileManager {
*
* @param subsetName
* The subset name
* @param type
* The data type
*
* @return The SubsetXML object
* @return The SubsetXML object or null if none exist
*/
public SubsetXML loadSubset(String subsetName) {
// Load the subset files if not already loaded
if (subsetFiles == null || subsetFiles.length == 0) {
getSubsets();
}
for (LocalizationFile lf : subsetFiles) {
public SubsetXML loadSubset(String subsetName, DataType type) {
for (LocalizationFile lf : subsetFiles.get(type)) {
if (lf.getFile().getName().equals(subsetName)) {
try {
return (SubsetXML) unmarshaller.unmarshal(lf.getFile());
@ -325,27 +355,77 @@ public class SubsetFileManager {
return null;
}
/**
* Load a saved subset into memory
*
* @param file
* The subset name
*
* @return The SubsetXML object or null if none exist
*/
public SubsetXML loadSubset(LocalizationFile file) {
if (file.exists()) {
try {
return (SubsetXML) unmarshaller.unmarshal(file.getFile());
} catch (JAXBException e) {
statusHandler.handle(Priority.PROBLEM, e.getLocalizedMessage(),
e);
}
}
return null;
}
/**
* Delete the subset
*
* @param subsetName
* The name of the subset to delete
* @param type
* The data type
*/
public void deleteSubset(String subsetName) {
// Load the subset files if not already loaded
if (subsetFiles == null || subsetFiles.length == 0) {
getSubsets();
}
for (LocalizationFile lf : subsetFiles) {
public void deleteSubset(String subsetName, DataType type) {
LocalizationFile file = null;
for (LocalizationFile lf : subsetFiles.get(type)) {
if (lf.getFile().getName().equals(subsetName)) {
try {
lf.delete();
file = lf;
break;
} catch (LocalizationOpFailedException e) {
statusHandler.handle(Priority.PROBLEM,
e.getLocalizedMessage(), e);
}
}
}
if (file != null) {
subsetFiles.get(type).remove(file);
}
}
public String[] getAllLocalizationFileNames() {
List<String> fileList = new ArrayList<String>();
for (DataType type : DataType.values()) {
Set<LocalizationFile> files = getLocalizationFiles(type);
for (LocalizationFile file : files) {
fileList.add(type.toString() + ":" + file.getFile().getName());
}
}
return fileList.toArray(new String[fileList.size()]);
}
public LocalizationFile getFile(String fileName, DataType dataType) {
Set<LocalizationFile> files = subsetFiles.get(dataType);
for (LocalizationFile file : files) {
if (file.getFile().getName().equals(fileName)) {
return file;
}
}
return null;
}
}

View file

@ -147,6 +147,8 @@ import com.raytheon.viz.ui.presenter.IDisplay;
* disappearing when the Subscription button is double clicked.
* Added dispose check for subscription button.
* Mar 31, 2014 2889 dhladky Added username for notification center tracking.
* Apr 10, 2014 2864 mpduff Changed how saved subset files are stored.
*
* </pre>
*
* @author mpduff
@ -382,7 +384,8 @@ public abstract class SubsetManagerDlg extends CaveSWTDialog implements
savedSetsTab.setText("Saved Subsets");
Composite savedSetsComp = new Composite(tabFolder, SWT.NONE);
savedSetsTab.setControl(savedSetsComp);
subsetTab = new SavedSubsetTab(savedSetsComp, this);
subsetTab = new SavedSubsetTab(savedSetsComp, dataSet.getDataSetType(),
this);
}
/** Create the information composite */
@ -553,9 +556,9 @@ public abstract class SubsetManagerDlg extends CaveSWTDialog implements
}
try {
as.setSubscriptionType(SubscriptionType.QUERY);
SubscriptionServiceResult result = subscriptionService.store(LocalizationManager.getInstance()
.getCurrentUser(),
as, this);
SubscriptionServiceResult result = subscriptionService.store(
LocalizationManager.getInstance().getCurrentUser(), as,
this);
if (result.hasMessageToDisplay()) {
DataDeliveryUtils.showMessage(getShell(), SWT.OK,
@ -746,7 +749,8 @@ public abstract class SubsetManagerDlg extends CaveSWTDialog implements
populateSubsetXML(subset);
// Have all the info, now save the file
SubsetFileManager.getInstance().saveSubset(subset, this.shell);
SubsetFileManager.getInstance().saveSubset(subset,
this.dataSet.getDataSetType(), this.shell);
setClean();
subsetTab.enableButtons(nameText);
}
@ -835,7 +839,7 @@ public abstract class SubsetManagerDlg extends CaveSWTDialog implements
@Override
public void handleLoadSubset(String subsetName) {
SubsetXML loadedSubsetXml = SubsetFileManager.getInstance().loadSubset(
subsetName);
subsetName, dataSet.getDataSetType());
loadFromSubsetXML(loadedSubsetXml);
}

View file

@ -0,0 +1,184 @@
/**
* 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.viz.ui.dialogs;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.MouseEvent;
import org.eclipse.swt.events.MouseListener;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
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.Layout;
import org.eclipse.swt.widgets.List;
import org.eclipse.swt.widgets.Shell;
/**
* Dialog allowing the user to select one or more items from the provided list.
*
* <pre>
*
* SOFTWARE HISTORY
*
* Date Ticket# Engineer Description
* ------------ ---------- ----------- --------------------------
* Apr 09, 2014 2864 mpduff Initial creation
*
* </pre>
*
* @author mpduff
* @version 1.0
*/
public class ListSelectionDlg extends CaveSWTDialog {
/** Stings to populate the list */
private final String[] textChoices;
/** Single/Multiple select flag */
private final boolean singleSelect;
/** The list widget */
private List selectList;
/**
* Constructor.
*
* @param parent
* Parent shell
* @param textChoices
* Items for the list
* @param singleSelect
* true if only a single selection allowed
*/
public ListSelectionDlg(Shell parent, String[] textChoices,
boolean singleSelect) {
super(parent, SWT.TITLE | SWT.RESIZE | SWT.APPLICATION_MODAL,
CAVE.DO_NOT_BLOCK);
this.textChoices = textChoices;
this.singleSelect = singleSelect;
if (singleSelect) {
setText("Select One");
} else {
setText("Select Items");
}
}
/**
* Single select list.
*
* @param parent
* Parent shell
* @param textChoices
* Items for the list
*/
public ListSelectionDlg(Shell parent, String[] textChoices) {
this(parent, textChoices, true);
}
@Override
protected Layout constructShellLayout() {
// Create the main layout for the shell.
GridLayout mainLayout = new GridLayout(1, false);
mainLayout.marginHeight = 2;
mainLayout.marginWidth = 2;
mainLayout.verticalSpacing = 2;
return mainLayout;
}
@Override
protected Object constructShellLayoutData() {
return new GridData(SWT.FILL, SWT.DEFAULT, true, false);
}
@Override
protected void initializeComponents(Shell shell) {
GridData gd = new GridData(SWT.FILL, SWT.FILL, true, true);
Composite mainComp = new Composite(shell, SWT.NONE);
mainComp.setLayout(new GridLayout(1, false));
mainComp.setLayoutData(gd);
int style = SWT.SINGLE;
if (!this.singleSelect) {
style = SWT.MULTI;
}
style |= SWT.V_SCROLL | SWT.H_SCROLL;
gd = new GridData(SWT.FILL, SWT.FILL, true, true);
selectList = new List(mainComp, SWT.BORDER | style);
selectList.setLayoutData(gd);
selectList.addMouseListener(new MouseListener() {
@Override
public void mouseUp(MouseEvent e) {
// No op
}
@Override
public void mouseDown(MouseEvent e) {
// No op
}
@Override
public void mouseDoubleClick(MouseEvent e) {
action();
}
});
gd = new GridData(SWT.CENTER, SWT.DEFAULT, true, false);
Composite btnComp = new Composite(shell, SWT.NONE);
btnComp.setLayout(new GridLayout(2, false));
btnComp.setLayoutData(gd);
Button selectBtn = new Button(btnComp, SWT.PUSH);
selectBtn.setLayoutData(new GridData(75, SWT.DEFAULT));
selectBtn.setText("Select");
selectBtn.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
action();
}
});
Button cancelBtn = new Button(btnComp, SWT.PUSH);
cancelBtn.setLayoutData(new GridData(75, SWT.DEFAULT));
cancelBtn.setText("Cancel");
cancelBtn.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
close();
}
});
selectList.setItems(textChoices);
this.shell.setMinimumSize(225, 275);
}
/**
* Action handler.
*/
private void action() {
setReturnValue(selectList.getSelection());
close();
}
}

View file

@ -0,0 +1,43 @@
#!/bin/bash
# DR 2864 - update the location of saved subset files
echo "Updating saved subset file locations"
startDir=/awips2/edex/data/utility/cave_static/user
cd $startDir
users=$(ls -1)
for i in $users
do
cd $i
if [ -e dataDelivery/subset ]
then
cd dataDelivery/subset
if [ ! -e GRID ]
then
mkdir GRID
fi
if [ ! -e POINT ]
then
mkdir POINT
fi
gridFiles=$(grep providerName *.xml | grep NOMADS | cut -d: -f1)
pointFiles=$(grep providerName *.xml | grep MADIS | cut -d: -f1)
for j in $gridFiles
do
mv $j* GRID
done
for j in $pointFiles
do
mv $j* POINT
done
fi
cd $startDir
done
echo "Update complete"