Issue #1965 Initial archive retention dialog work.

updated archive creation, purge, and test cases after Roger's last checkin.
added edex plugin for feature.
added an abstract base archive dialog.

Change-Id: I7c9ca3df40a7591815a1aae4fabf660217d44574

Former-commit-id: f53d6bf4ff [formerly 64b75031afaecd74649392a19cc0b10dcdb79a2b]
Former-commit-id: b952eee030
This commit is contained in:
Roger Ferrel 2013-06-04 13:08:05 -05:00
parent 7a1c08bb13
commit dcc56ad5d3
10 changed files with 683 additions and 177 deletions

View file

@ -0,0 +1,430 @@
/**
* 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.archive.ui;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.graphics.Cursor;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Combo;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Shell;
import com.raytheon.uf.common.archive.config.ArchiveConfig;
import com.raytheon.uf.common.archive.config.ArchiveConfigManager;
import com.raytheon.uf.common.archive.config.ArchiveConfigManager.DisplayData;
import com.raytheon.uf.common.archive.config.CategoryConfig;
import com.raytheon.uf.common.util.SizeUtil;
import com.raytheon.uf.viz.archive.data.ArchiveInfo;
import com.raytheon.uf.viz.archive.data.CategoryInfo;
import com.raytheon.uf.viz.archive.data.DirInfo;
import com.raytheon.uf.viz.archive.data.IArchiveTotals;
import com.raytheon.uf.viz.archive.ui.ArchiveTableComp.TableType;
import com.raytheon.viz.ui.dialogs.CaveSWTDialog;
import com.raytheon.viz.ui.dialogs.ICloseCallback;
/**
* Abstract base class for Archive dialogs. Contains and manages information
* needed for the archive and category selectors and populates the selection
* table of display labels elements.
*
* <pre>
*
* SOFTWARE HISTORY
*
* Date Ticket# Engineer Description
* ------------ ---------- ----------- --------------------------
* May 30, 2013 1965 bgonzale Initial creation
*
* </pre>
*
* @author bgonzale
* @version 1.0
*/
public abstract class AbstractArchiveDlg extends CaveSWTDialog implements
IArchiveTotals {
private static final String UNKNOWN_SIZE_TEXT = "????MB";
/** Table composite that holds the table controls. */
private ArchiveTableComp tableComp;
/** Archive config combo box. */
private Combo archCfgCbo;
/** Category combo box. */
private Combo categoryCbo;
/** Information for populating the various table displays. */
private final Map<String, ArchiveInfo> archiveInfoMap = new HashMap<String, ArchiveInfo>();
private Cursor busyCursor;
/**
* @param parentShell
*/
public AbstractArchiveDlg(Shell parentShell) {
super(parentShell);
setupCursor();
}
/**
* @param parentShell
* @param swtStyle
*/
public AbstractArchiveDlg(Shell parentShell, int swtStyle) {
super(parentShell, swtStyle);
setupCursor();
}
/**
* @param parentShell
* @param style
* @param caveStyle
*/
public AbstractArchiveDlg(Shell parentShell, int style, int caveStyle) {
super(parentShell, style, caveStyle);
setupCursor();
}
/* (non-Javadoc)
* @see com.raytheon.uf.viz.archive.data.IArchiveTotals#getTotalSelectedItems()
*/
@Override
public int getTotalSelectedItems() {
int totalSelected = 0;
for (ArchiveInfo archiveInfo : archiveInfoMap.values()) {
for (String categoryName : archiveInfo.getCategoryNames()) {
CategoryInfo categoryInfo = archiveInfo.get(categoryName);
for (DisplayData displayInfo : categoryInfo
.getDisplayInfoList()) {
if (displayInfo.isSelected()) {
++totalSelected;
}
}
}
}
updateTotalSizeLabel();
return totalSelected;
}
public List<DisplayData> getAllSelected() {
List<DisplayData> allSelected = new ArrayList<ArchiveConfigManager.DisplayData>();
for (String archiveName : archiveInfoMap.keySet()) {
ArchiveInfo archiveInfo = archiveInfoMap.get(archiveName);
for (String categoryName : archiveInfo.getCategoryNames()) {
CategoryInfo categoryInfo = archiveInfo.get(categoryName);
for (DisplayData displayData : categoryInfo
.getDisplayInfoList()) {
if (displayData.isSelected()) {
allSelected.add(displayData);
}
}
}
}
return allSelected;
}
/**
* @return the name of the currently selected archive in the dialog; null if
* none found
*/
public String getSelectedArchiveName() {
int archiveSelection = archCfgCbo.getSelectionIndex();
String archiveName = archiveSelection == -1 ? null : archCfgCbo
.getItem(archiveSelection);
return archiveName;
}
/**
* @return the name of the currently selected category in the dialog; null
* if none found
*/
public String getSelectedCategoryName() {
int categorySelection = categoryCbo.getSelectionIndex();
String categoryName = categorySelection == -1 ? null : categoryCbo
.getItem(categorySelection);
return categoryName;
}
/**
* @return the currently selected archive in the dialog; null if none found
*/
public ArchiveConfig getSelectedArchive() {
int archiveSelection = archCfgCbo.getSelectionIndex();
String archiveName = archiveSelection == -1 ? null : archCfgCbo
.getItem(archiveSelection);
return ArchiveConfigManager.getInstance().getArchive(archiveName);
}
/**
* @return the currently selected category in the dialog; null if none found
*/
public CategoryConfig getSelectedCategory() {
String archiveName = getSelectedArchiveName();
ArchiveConfig archive = ArchiveConfigManager.getInstance().getArchive(
archiveName);
if (archive != null) {
String categoryName = getSelectedCategoryName();
return archive.getCategory(categoryName);
}
return null;
}
protected void updateTotalSizeLabel() {
long totalSize = 0;
for (String archiveName : archiveInfoMap.keySet()) {
ArchiveInfo archiveInfo = archiveInfoMap.get(archiveName);
for (String categoryName : archiveInfo.getCategoryNames()) {
CategoryInfo categoryInfo = archiveInfo.get(categoryName);
for (DisplayData displayData : categoryInfo
.getDisplayInfoList()) {
if (displayData.isSelected()) {
long size = displayData.getSize();
if (size < 0) {
// Size still being computed.
setTotalSizeText(UNKNOWN_SIZE_TEXT);
return;
} else {
totalSize += size;
}
}
}
}
}
setTotalSizeText(SizeUtil.prettyByteSize(totalSize));
}
/**
* This method is called by the AbstractArchiveDlg to set the size text.
*
* @param prettyByteSize
*/
protected abstract void setTotalSizeText(String sizeStringText);
/**
* This method is called by the AbstractArchiveDlg to get the start of the
* time frame that bounds the data for the dialog.
*
* @return GMT Calendar
*/
protected abstract Calendar getStart();
/**
* This method is called by the AbstractArchiveDlg to get the end of the
* time frame that bounds the data for the dialog.
*
* @return GMT Calendar
*/
protected abstract Calendar getEnd();
/**
* This method is called by the AbstractArchiveDlg when the combo boxes are
* updated.
*/
protected abstract void selectionsUpdated();
/**
* Create the Archive and Category combo controls.
*
* @param comp
* Composite to put the controls in.
*/
protected void createComboControls(Composite comp) {
Composite comboComp = new Composite(comp, SWT.NONE);
GridLayout gl = new GridLayout(2, false);
GridData gd = new GridData(SWT.FILL, SWT.DEFAULT, true, false);
comboComp.setLayout(gl);
comboComp.setLayoutData(gd);
Label archCfgLbl = new Label(comboComp, SWT.NONE);
archCfgLbl.setText("Archive Config: ");
gd = new GridData(200, SWT.DEFAULT);
archCfgCbo = new Combo(comboComp, SWT.VERTICAL | SWT.DROP_DOWN
| SWT.BORDER | SWT.READ_ONLY);
archCfgCbo.setLayoutData(gd);
archCfgCbo.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
String archiveName = archCfgCbo.getItem(archCfgCbo
.getSelectionIndex());
populateCategoryCbo(archiveName);
}
});
Label catLbl = new Label(comboComp, SWT.NONE);
catLbl.setText("Category: ");
gd = new GridData(200, SWT.DEFAULT);
categoryCbo = new Combo(comboComp, SWT.VERTICAL | SWT.DROP_DOWN
| SWT.BORDER | SWT.READ_ONLY);
categoryCbo.setLayoutData(gd);
categoryCbo.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
String archiveName = archCfgCbo.getItem(archCfgCbo
.getSelectionIndex());
String categoryName = categoryCbo.getItem(categoryCbo
.getSelectionIndex());
populateTableComp(archiveName, categoryName);
}
});
ArchiveConfigManager.getInstance().reset();
createTable();
populateComboBoxes();
updateTableComp();
}
/**
* Create the table control.
*/
protected void createTable() {
tableComp = new ArchiveTableComp(shell, TableType.Case, this);
}
/**
* Update table based on current item selections in archive and category.
*/
protected void updateTableComp() {
populateTableComp(getSelectedArchiveName(), getSelectedCategoryName());
}
/**
* Add a separator line to the provided container.
*
* @param container
* Composite.
* @param orientation
* Vertical or horizontal orientation.
*/
protected void addSeparator(Composite container, int orientation) {
// Separator label
GridData gd;
if (orientation == SWT.HORIZONTAL) {
gd = new GridData(SWT.FILL, SWT.DEFAULT, true, false);
} else {
gd = new GridData(SWT.DEFAULT, SWT.FILL, false, true);
}
Label sepLbl = new Label(container, SWT.SEPARATOR | orientation);
sepLbl.setLayoutData(gd);
}
/**
* Init busyCursor. On close, make sure that cursor reverts back to unbusy
* state if it isn't already.
*/
private void setupCursor() {
busyCursor = getParent().getDisplay().getSystemCursor(SWT.CURSOR_WAIT);
this.setCloseCallback(new ICloseCallback() {
@Override
public void dialogClosed(Object returnValue) {
setCursorBusy(false);
}
});
}
/**
* Initial population up of the combo boxes.
*/
private void populateComboBoxes() {
ArchiveConfigManager manager = ArchiveConfigManager.getInstance();
boolean doSelect = false;
for (String archiveName : manager.getArchiveDataNamesList()) {
archCfgCbo.add(archiveName);
doSelect = true;
}
if (doSelect) {
archCfgCbo.select(0);
String archiveName = archCfgCbo.getItem(0);
populateCategoryCbo(archiveName);
}
}
/**
* Populate the category combo based on the archive name and populate the
* table.
*
* @param archiveName
*/
private void populateCategoryCbo(String archiveName) {
ArchiveConfigManager manager = ArchiveConfigManager.getInstance();
categoryCbo.removeAll();
for (String categoryName : manager.getCategoryNames(archiveName)) {
categoryCbo.add(categoryName);
}
categoryCbo.select(0);
String categoryName = categoryCbo.getItem(0);
populateTableComp(archiveName, categoryName);
}
private void populateTableComp(String archiveName, String categoryName) {
setCursorBusy(true);
DirInfo.clearQueue();
ArchiveInfo archiveInfo = archiveInfoMap.get(archiveName);
if (archiveInfo == null) {
archiveInfo = new ArchiveInfo();
archiveInfoMap.put(archiveName, archiveInfo);
}
CategoryInfo categoryInfo = archiveInfo.get(categoryName);
if (categoryInfo == null) {
ArchiveConfigManager manager = ArchiveConfigManager.getInstance();
List<DisplayData> displayInfos = manager.getDisplayInfo(
archiveName, categoryName);
categoryInfo = new CategoryInfo(archiveName, categoryName,
displayInfos);
archiveInfo.add(categoryInfo);
}
for (DisplayData displayInfo : categoryInfo.getDisplayInfoList()) {
new DirInfo(displayInfo, getStart(), getEnd());
}
tableComp.populateTable(categoryInfo.getDisplayInfoList());
selectionsUpdated();
setCursorBusy(false);
}
private void setCursorBusy(boolean state) {
Cursor cursor = null;
if (state) {
cursor = busyCursor;
}
shell.setCursor(cursor);
}
}

View file

@ -19,6 +19,8 @@
**/
package com.raytheon.uf.viz.archive.ui;
import java.util.Calendar;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
@ -32,9 +34,11 @@ import org.eclipse.swt.widgets.Layout;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Spinner;
import com.raytheon.uf.viz.archive.data.IArchiveTotals;
import com.raytheon.uf.viz.archive.ui.ArchiveTableComp.TableType;
import com.raytheon.viz.ui.dialogs.CaveSWTDialog;
import com.raytheon.uf.common.archive.config.ArchiveConfig;
import com.raytheon.uf.common.archive.config.ArchiveConfigManager;
import com.raytheon.uf.common.archive.config.CategoryConfig;
import com.raytheon.uf.common.status.IUFStatusHandler;
import com.raytheon.uf.common.status.UFStatus;
/**
* Archive retention dialog.
@ -46,22 +50,24 @@ import com.raytheon.viz.ui.dialogs.CaveSWTDialog;
* Date Ticket# Engineer Description
* ------------ ---------- ----------- --------------------------
* May 23, 2013 #1964 lvenable Initial creation
* May 31, 2013 #1965 bgonzale Initial work for updating retention configurations.
*
* </pre>
*
* @author lvenable
* @version 1.0
*/
public class ArchiveRetentionDlg extends CaveSWTDialog implements IArchiveTotals {
public class ArchiveRetentionDlg extends AbstractArchiveDlg {
/** Table composite that holds the table controls. */
private ArchiveTableComp tableComp;
private final transient IUFStatusHandler statusHandler = UFStatus
.getHandler(ArchiveRetentionDlg.class);
/** Archive config combo box. */
private Combo archCfgCbo;
private Spinner minRetentionSpnr;
/** Category combo box. */
private Combo categoryCbo;
private Spinner extRetentionSpnr;
// TODO in the future, get this value from a user text box
protected static final String ARCHIVE_DIR = "/archive_dir";
/**
* Constructor.
@ -80,7 +86,6 @@ public class ArchiveRetentionDlg extends CaveSWTDialog implements IArchiveTotals
GridLayout mainLayout = new GridLayout(1, false);
mainLayout.marginHeight = 2;
mainLayout.marginWidth = 2;
return mainLayout;
}
@ -93,7 +98,6 @@ public class ArchiveRetentionDlg extends CaveSWTDialog implements IArchiveTotals
gl.marginWidth = 0;
gl.horizontalSpacing = 0;
mainComp.setLayout(gl);
init();
}
@ -102,12 +106,9 @@ public class ArchiveRetentionDlg extends CaveSWTDialog implements IArchiveTotals
*/
private void init() {
createRetentionControls();
createTable();
addSeparator(shell, SWT.HORIZONTAL);
createBottomActionButtons();
// TODO : Remove this when functionality is implemented
populateComboBoxes();
selectionsUpdated();
}
/**
@ -123,42 +124,41 @@ public class ArchiveRetentionDlg extends CaveSWTDialog implements IArchiveTotals
/*
* Top row of controls.
*/
Label archCfgLbl = new Label(retentionComp, SWT.NONE);
archCfgLbl.setText("Archive Config: ");
createComboControls(retentionComp);
gd = new GridData(200, SWT.DEFAULT);
archCfgCbo = new Combo(retentionComp, SWT.VERTICAL | SWT.DROP_DOWN
| SWT.BORDER | SWT.READ_ONLY);
archCfgCbo.setLayoutData(gd);
archCfgCbo.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
/*
* TODO - add code to update the category combo box
*/
}
});
// composite for retention time selection
Composite selectionComp = new Composite(retentionComp, SWT.NONE);
selectionComp.setLayout(new GridLayout(3, true));
selectionComp.setLayoutData(new GridData(SWT.FILL, SWT.DEFAULT, true,
false));
gd = new GridData();
gd.horizontalIndent = 20;
Label minRetentionLbl = new Label(retentionComp, SWT.NONE);
Label minRetentionLbl = new Label(selectionComp, SWT.NONE);
minRetentionLbl.setText("Minimum Retention: ");
minRetentionLbl.setLayoutData(gd);
gd = new GridData(60, SWT.DEFAULT);
final Spinner minRetentionSpnr = new Spinner(retentionComp, SWT.BORDER);
minRetentionSpnr = new Spinner(selectionComp, SWT.BORDER);
minRetentionSpnr.setIncrement(1);
minRetentionSpnr.setPageIncrement(5);
minRetentionSpnr.setMaximum(Integer.MAX_VALUE);
minRetentionSpnr.setMinimum(1);
minRetentionSpnr.setLayoutData(gd);
final Combo minRetentionCbo = new Combo(retentionComp, SWT.VERTICAL
final Combo minRetentionCbo = new Combo(selectionComp, SWT.VERTICAL
| SWT.DROP_DOWN | SWT.BORDER | SWT.READ_ONLY);
minRetentionCbo.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
handleRetentionSelection(minRetentionCbo, minRetentionSpnr);
int retentionHours = handleRetentionSelection(minRetentionCbo,
minRetentionSpnr);
if (retentionHours != -1) {
ArchiveConfig archive = getSelectedArchive();
if (archive != null) {
archive.setRetentionHours(retentionHours);
}
}
}
});
minRetentionCbo.add("Hours");
@ -170,42 +170,34 @@ public class ArchiveRetentionDlg extends CaveSWTDialog implements IArchiveTotals
/*
* Bottom row of controls.
*/
Label catLbl = new Label(retentionComp, SWT.NONE);
catLbl.setText("Category: ");
gd = new GridData(200, SWT.DEFAULT);
categoryCbo = new Combo(retentionComp, SWT.VERTICAL | SWT.DROP_DOWN
| SWT.BORDER | SWT.READ_ONLY);
categoryCbo.setLayoutData(gd);
categoryCbo.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
/*
* TODO - add code to update the information in the table
*/
}
});
gd = new GridData();
gd.horizontalIndent = 20;
Label extRetentionLbl = new Label(retentionComp, SWT.NONE);
Label extRetentionLbl = new Label(selectionComp, SWT.NONE);
extRetentionLbl.setText("Extended Retention: ");
extRetentionLbl.setLayoutData(gd);
gd = new GridData(60, SWT.DEFAULT);
final Spinner extRetentionSpnr = new Spinner(retentionComp, SWT.BORDER);
extRetentionSpnr = new Spinner(selectionComp, SWT.BORDER);
extRetentionSpnr.setIncrement(1);
extRetentionSpnr.setPageIncrement(5);
extRetentionSpnr.setMaximum(Integer.MAX_VALUE);
extRetentionSpnr.setMinimum(1);
extRetentionSpnr.setLayoutData(gd);
final Combo extRetentionCbo = new Combo(retentionComp, SWT.VERTICAL
final Combo extRetentionCbo = new Combo(selectionComp, SWT.VERTICAL
| SWT.DROP_DOWN | SWT.BORDER | SWT.READ_ONLY);
extRetentionCbo.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
handleRetentionSelection(extRetentionCbo, extRetentionSpnr);
int retentionHours = handleRetentionSelection(extRetentionCbo,
extRetentionSpnr);
if (retentionHours != -1) {
CategoryConfig category = getSelectedCategory();
if (category != null) {
category.setRetentionHours(retentionHours);
}
}
}
});
extRetentionCbo.add("Hours");
@ -215,13 +207,6 @@ public class ArchiveRetentionDlg extends CaveSWTDialog implements IArchiveTotals
.getSelectionIndex()));
}
/**
* Create the table control.
*/
private void createTable() {
tableComp = new ArchiveTableComp(shell, TableType.Case, this);
}
/**
* Create the bottom action buttons.
*/
@ -239,6 +224,8 @@ public class ArchiveRetentionDlg extends CaveSWTDialog implements IArchiveTotals
@Override
public void widgetSelected(SelectionEvent e) {
// TODO : add calculate size functionality
// With Roger's automated size calculation code, this doesn't
// seem relevant unless it is for calculating compressed size
}
});
@ -246,8 +233,12 @@ public class ArchiveRetentionDlg extends CaveSWTDialog implements IArchiveTotals
saveBtn.setText(" Save... ");
saveBtn.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
// TODO : add save functionality
public void widgetSelected(SelectionEvent selectionEvent) {
ArchiveConfigManager manager = ArchiveConfigManager
.getInstance();
// TODO
// List<DisplayData> allSelected = getAllSelected();
// manager.save();
}
});
@ -270,12 +261,13 @@ public class ArchiveRetentionDlg extends CaveSWTDialog implements IArchiveTotals
* Retention combo box.
* @param spinner
* Retention spinner.
* @return hours entered if changed; -1 if not changed
*/
private void handleRetentionSelection(Combo comboBox, Spinner spinner) {
private int handleRetentionSelection(Combo comboBox, Spinner spinner) {
// If the selection didn't change then just return.
if (comboBox.getItem(comboBox.getSelectionIndex()).equals(
(String) comboBox.getData())) {
return;
return -1;
}
int time = 0;
@ -288,6 +280,7 @@ public class ArchiveRetentionDlg extends CaveSWTDialog implements IArchiveTotals
spinner.setSelection(time);
comboBox.setData(comboBox.getItem(comboBox.getSelectionIndex()));
return time;
}
/**
@ -307,50 +300,48 @@ public class ArchiveRetentionDlg extends CaveSWTDialog implements IArchiveTotals
} else {
convertedTime = time / 24;
}
return convertedTime;
}
/**
* Add a separator line to the provided container.
*
* @param container
* Composite.
* @param orientation
* Vertical or horizontal orientation.
*/
private void addSeparator(Composite container, int orientation) {
// Separator label
GridData gd;
if (orientation == SWT.HORIZONTAL) {
gd = new GridData(SWT.FILL, SWT.DEFAULT, true, false);
} else {
gd = new GridData(SWT.DEFAULT, SWT.FILL, false, true);
}
Label sepLbl = new Label(container, SWT.SEPARATOR | orientation);
sepLbl.setLayoutData(gd);
@Override
protected void setTotalSizeText(String sizeStringText) {
// TODO Auto-generated method stub
}
/********************************************************
* TEST METHODS - to be removed when functionality is implemented.
* ******************************************************
/*
* (non-Javadoc)
*
* @see com.raytheon.uf.viz.archive.ui.AbstractArchiveDlg#getStart()
*/
private void populateComboBoxes() {
archCfgCbo.add("Raw");
archCfgCbo.add("Processed");
archCfgCbo.select(0);
@Override
protected Calendar getStart() {
// display all elements so no start bound
return null;
}
categoryCbo.add("Radar");
categoryCbo.add("Point");
categoryCbo.add("Satellite");
categoryCbo.select(0);
/*
* (non-Javadoc)
*
* @see com.raytheon.uf.viz.archive.ui.AbstractArchiveDlg#getEnd()
*/
@Override
protected Calendar getEnd() {
// display all elements so no end bound
return null;
}
@Override
public int getTotalSelectedItems() {
// TODO Auto-generated method stub
return 0;
protected void selectionsUpdated() {
ArchiveConfig archive = getSelectedArchive();
if (archive != null) {
if (minRetentionSpnr != null) {
minRetentionSpnr.setSelection(archive.getRetentionHours());
CategoryConfig category = getSelectedCategory();
if (category != null) {
extRetentionSpnr.setSelection(category.getRetentionHours());
}
}
}
}
}

View file

@ -0,0 +1,4 @@
source.. = src/
output.. = bin/
bin.includes = META-INF/,\
.,\

View file

@ -56,6 +56,7 @@ import javax.xml.bind.annotation.XmlRootElement;
* Date Ticket# Engineer Description
* ------------ ---------- ----------- --------------------------
* May 1, 2013 1966 rferrel Initial creation
* May 31, 2013 1965 bgonzale Added getCategory(categoryName)
*
* </pre>
*
@ -167,6 +168,19 @@ public class ArchiveConfig implements Comparable<ArchiveConfig> {
public List<CategoryConfig> getCategoryList() {
return new ArrayList<CategoryConfig>(categoryList);
}
/**
* @param categoryName
* @return The named CategoryConfig; null if not found
*/
public CategoryConfig getCategory(String categoryName) {
for (CategoryConfig category : categoryList) {
if (category.getName().equals(categoryName)) {
return category;
}
}
return null;
}
/**
* Set the category list.

View file

@ -67,7 +67,7 @@ import com.raytheon.uf.common.util.FileUtil;
* Date Ticket# Engineer Description
* ------------ ---------- ----------- --------------------------
* May 1, 2013 1966 rferrel Initial creation
* May 29, 2013 1965 bgonzale Added archive creation method and purge.
* May 29, 2013 1965 bgonzale Added archive creation, purge, and save methods.
*
* </pre>
*
@ -84,6 +84,8 @@ public class ArchiveConfigManager {
private IPathManager pathMgr;
private final Map<String, LocalizationFile> archiveNameToLocalizationFileMap = new HashMap<String, LocalizationFile>();
private final Map<String, ArchiveConfig> archiveMap = new HashMap<String, ArchiveConfig>();
public final static ArchiveConfigManager getInstance() {
@ -175,12 +177,9 @@ public class ArchiveConfigManager {
/**
* Create an archive in the given archive directory from the Files filtered
* by the given Archive out of the ArchiveElements.
* by the ArchiveElements that are within the start and end time frame
* parameters.
*
* @param archive
* Archive configuration to create Archive from
* @param category
* Archive Category configuration
* @param archiveDir
* Destination directory of the Archive
* @param displaysSelectedForArchive
@ -193,52 +192,48 @@ public class ArchiveConfigManager {
* @throws IOException
* @throws ArchiveException
*/
public Collection<File> createArchive(ArchiveConfig archive,
CategoryConfig category, File archiveDir,
Collection<String> displaysSelectedForArchive, Calendar start,
public Collection<File> createArchive(File archiveDir,
Collection<DisplayData> displaysSelectedForArchive, Calendar start,
Calendar end) throws IOException, ArchiveException {
Collection<File> archivedFiles = null;
if (archiveDir.exists() || archiveDir.mkdirs()) {
FileUtils.forceMkdir(archiveDir);
if (archiveDir.exists()) {
Collection<File> filesToArchive = new ArrayList<File>();
// TODO Brad will fix.
// for (String displayLabel : displaysSelectedForArchive) {
// File[] files = getDisplayFiles(archive.getName(),
// category.getName(), displayLabel, start, end);
// filesToArchive.addAll(Arrays.asList(files));
// }
for (DisplayData display : displaysSelectedForArchive) {
List<File> files = getDisplayFiles(display, start, end);
filesToArchive.addAll(files);
String rootDirString = display.archiveConfig.getRootDir();
String archiveDirString = archiveDir.getAbsolutePath();
String rootDirString = archive.getRootDir();
String archiveDirString = archiveDir.getAbsolutePath();
archivedFiles = new ArrayList<File>(filesToArchive.size());
rootDirString = (rootDirString.endsWith(File.separator) ? rootDirString
.substring(0,
rootDirString.lastIndexOf(File.separatorChar))
: rootDirString);
for (File srcFile : filesToArchive) {
String fileAbsPath = srcFile.getAbsolutePath();
File newArchiveDir = getDirRelativeToArchiveDirFromRoot(
srcFile.isDirectory(), fileAbsPath, rootDirString,
archiveDirString);
FileUtils.forceMkdir(newArchiveDir);
archivedFiles = new ArrayList<File>(filesToArchive.size());
rootDirString = (rootDirString.endsWith(File.separator) ? rootDirString
.substring(0, rootDirString.lastIndexOf(File.separatorChar))
: rootDirString);
for (File srcFile : filesToArchive) {
String fileAbsPath = srcFile.getAbsolutePath();
File newArchiveDir = getDirRelativeToArchiveDirFromRoot(
srcFile.isDirectory(), fileAbsPath, rootDirString,
archiveDirString);
FileUtils.forceMkdir(newArchiveDir);
if (srcFile.isDirectory()) {
FileUtils.copyDirectory(srcFile, newArchiveDir);
archivedFiles.addAll(Arrays.asList(newArchiveDir
.listFiles()));
} else {
FileUtils.copyFileToDirectory(srcFile, newArchiveDir);
String filename = FilenameUtils.getName(fileAbsPath);
File dstFile = new File(newArchiveDir, filename);
archivedFiles.add(dstFile);
if (srcFile.isDirectory()) {
FileUtils.copyDirectory(srcFile, newArchiveDir);
archivedFiles.addAll(Arrays.asList(newArchiveDir
.listFiles()));
} else {
FileUtils.copyFileToDirectory(srcFile, newArchiveDir);
String filename = FilenameUtils.getName(fileAbsPath);
File dstFile = new File(newArchiveDir, filename);
archivedFiles.add(dstFile);
}
}
}
} else {
StringBuilder sbuff = new StringBuilder(
"Failed to create archive for Archive: ");
sbuff.append(archive);
sbuff.append(" and Category: ");
sbuff.append(category);
"Failed to create archive in: ");
sbuff.append(archiveDir);
throw new ArchiveException(sbuff.toString());
}
return archivedFiles;
@ -270,22 +265,21 @@ public class ArchiveConfigManager {
for (CategoryConfig category : archive.getCategoryList()) {
Calendar purgeTime = calculateExpiration(archive, category);
// TODO Brad will fix.
// for (String displayLabel : getDisplayLabels(archive.getName(),
// category.getName())) {
// File[] displayFiles = getDisplayFiles(archive.getName(),
// category.getName(), displayLabel, null, purgeTime);
// for (File file : displayFiles) {
// if (file.isFile()) {
// filesPurged.add(file);
// } else if (file.isDirectory()) {
// filesPurged.addAll(FileUtils.listFiles(file,
// FileFilterUtils.fileFileFilter(),
// FileFilterUtils.trueFileFilter()));
// }
// FileUtils.deleteQuietly(file);
// }
// }
for (DisplayData display : getDisplayInfo(archive.getName(),
category.getName())) {
List<File> displayFiles = getDisplayFiles(display, null,
purgeTime);
for (File file : displayFiles) {
if (file.isFile()) {
filesPurged.add(file);
} else if (file.isDirectory()) {
filesPurged.addAll(FileUtils.listFiles(file,
FileFilterUtils.fileFileFilter(),
FileFilterUtils.trueFileFilter()));
}
FileUtils.deleteQuietly(file);
}
}
}
return filesPurged;
}
@ -334,11 +328,13 @@ public class ArchiveConfigManager {
*/
public void reset() {
archiveMap.clear();
archiveNameToLocalizationFileMap.clear();
LocalizationFile[] files = getArchiveConfigFiles();
for (LocalizationFile lFile : files) {
try {
ArchiveConfig archiveConfig;
archiveConfig = unmarshalArhiveConfigFromXmlFile(lFile);
ArchiveConfig archiveConfig = unmarshalArhiveConfigFromXmlFile(lFile);
archiveNameToLocalizationFileMap.put(archiveConfig.getName(),
lFile);
archiveMap.put(archiveConfig.getName(), archiveConfig);
} catch (IOException e) {
statusHandler.handle(Priority.PROBLEM, e.getLocalizedMessage(),
@ -350,6 +346,18 @@ public class ArchiveConfigManager {
}
}
/**
* Save the cached configuration.
*/
public void save() {
for (String archiveName : archiveMap.keySet()) {
ArchiveConfig archiveConfig = archiveMap.get(archiveName);
LocalizationFile lFile = archiveNameToLocalizationFileMap
.get(archiveName);
saveArchiveConfig(lFile, archiveConfig);
}
}
/**
* Get a list of directories/files for the desired display label bounded by
* the start and end time inclusive.
@ -719,4 +727,5 @@ public class ArchiveConfigManager {
return false;
}
}
}

View file

@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>com.raytheon.uf.edex.archive.feature</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.pde.FeatureBuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.pde.FeatureNature</nature>
</natures>
</projectDescription>

View file

@ -0,0 +1 @@
bin.includes = feature.xml

View file

@ -0,0 +1,40 @@
<?xml version="1.0" encoding="UTF-8"?>
<feature
id="com.raytheon.uf.edex.archive.feature"
label="Archive Edex feature"
version="1.0.0.qualifier"
provider-name="RAYTHEON">
<description url="http://www.example.com/description">
[Enter Feature Description here.]
</description>
<copyright url="http://www.example.com/copyright">
[Enter Copyright Description here.]
</copyright>
<license url="http://www.example.com/license">
[Enter License Description here.]
</license>
<plugin
id="com.raytheon.uf.common.archive"
download-size="0"
install-size="0"
version="0.0.0"
unpack="false"/>
<plugin
id="com.raytheon.uf.edex.archive"
download-size="0"
install-size="0"
version="0.0.0"
unpack="false"/>
<plugin
id="org.apache.commons.io"
download-size="0"
install-size="0"
version="0.0.0"/>
</feature>

View file

@ -0,0 +1,5 @@
source.. = src/
output.. = bin/
bin.includes = META-INF/,\
.,\
res/

View file

@ -43,6 +43,7 @@ import org.junit.Test;
import com.raytheon.uf.common.archive.config.ArchiveConfig;
import com.raytheon.uf.common.archive.config.ArchiveConfigManager;
import com.raytheon.uf.common.archive.config.ArchiveConfigManager.DisplayData;
import com.raytheon.uf.common.archive.config.CategoryConfig;
import com.raytheon.uf.common.archive.exception.ArchiveException;
import com.raytheon.uf.common.localization.PathManagerFactoryTest;
@ -73,6 +74,8 @@ public class ArchiveConfigManagerTest {
private static final String SAT_CAT_NAME = "Satellite";
private static final String satNameForArchive = "GOES-13";
private static File TEST_DIR = TestUtil
.setupTestClassDir(ArchiveConfigManagerTest.class);
@ -100,8 +103,6 @@ public class ArchiveConfigManagerTest {
private Calendar archiveEnd;
private List<String> selectedForArchive;
private File archiveDir;
private static String TEST_ARCHIVE_DIR = "testArchiveDir";
@ -148,9 +149,6 @@ public class ArchiveConfigManagerTest {
CategoryConfig grib1Cat = getCategory(archive, "Model grib");
createTestFiles(grib1Format, getRetentionHours(archive, grib1Cat),
false, archiveStart, archiveEnd);
// manager is not configured internally until this is called...
// TODO Brad will fix.
// manager.getDisplayLabels(archive.getName(), grib1Cat.getName());
// **** sat ****
CategoryConfig satCat = getCategory(archive, SAT_CAT_NAME);
@ -158,9 +156,6 @@ public class ArchiveConfigManagerTest {
"/sat/{0}{1}/{2}/GOES-13/{2}{3}Z_SOUND-VIS_10km_EAST-CONUS-TIGE59_KNES_128453.satz.{0}{1}{2}");
createTestFiles(satFormat, getRetentionHours(archive, satCat), true,
archiveStart, archiveEnd);
// manager is not configured internally until this is called...
// TODO Brad will fix.
// manager.getDisplayLabels(archive.getName(), satCat.getName());
// **** acars ****
CategoryConfig otherCat = getCategory(archive, "Model other");
@ -181,16 +176,9 @@ public class ArchiveConfigManagerTest {
"/bufrsigwx/{0}{1}/{2}/JUWE96_KKCI_{1}{2}{3}_31368878.bufr.{0}{1}{2}");
createTestFiles(bufrsigwxFormat, otherCatRetentionHours, false,
archiveStart, archiveEnd);
// manager is not configured internally until this is called...
// TODO Brad will fix.
// manager.getDisplayLabels(archive.getName(), otherCat.getName());
// create test archive data dir
archiveDir = new File(TEST_DIR, TEST_ARCHIVE_DIR);
// create archive elements for selected list
selectedForArchive = new ArrayList<String>();
selectedForArchive.add("GOES-13");
}
private int getRetentionHours(ArchiveConfig archive, CategoryConfig category) {
@ -305,9 +293,16 @@ public class ArchiveConfigManagerTest {
public void testArchiveManagerCreateArchive() throws IOException,
ArchiveException {
CategoryConfig satCategory = getCategory(archive, SAT_CAT_NAME);
Collection<File> archivedFiles = manager.createArchive(archive,
satCategory, archiveDir, selectedForArchive, archiveStart,
archiveEnd);
List<DisplayData> displays =
manager.getDisplayInfo(archive.getName(), satCategory.getName());
List<DisplayData> selectedDisplays = new ArrayList<ArchiveConfigManager.DisplayData>();
for (DisplayData displayData : displays) {
if (displayData.getDisplayLabel().equals(satNameForArchive)) {
selectedDisplays.add(displayData);
}
}
Collection<File> archivedFiles = manager.createArchive(archiveDir,
selectedDisplays, archiveStart, archiveEnd);
assertEquals(
"The expected archive files and the archived files are not the same",
createFileNameListNoRootDir(new File(archive.getRootDir()),