Issue #1966 Changes to make manger stateless and updates for Case Creation.

Change-Id: I62118209fad2a28d6dd3cac4abf7bb86cc782387

Former-commit-id: 3f43fdc896ff616915a8aa5ef986d3a82e52aa51
This commit is contained in:
Roger Ferrel 2013-05-30 12:38:35 -05:00
parent e4578ca7ba
commit 3c875a6f44
17 changed files with 964 additions and 286 deletions

View file

@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<feature
id="com.raytheon.uf.viz.archive.feature"
label="Feature"
label="CAVE Archive Feature"
version="1.0.0.qualifier"
provider-name="RAYTHEON">
@ -36,4 +36,11 @@
version="0.0.0"
unpack="false"/>
<plugin
id="com.raytheon.uf.common.archive"
download-size="0"
install-size="0"
version="0.0.0"
unpack="false"/>
</feature>

View file

@ -12,6 +12,8 @@ Require-Bundle: org.eclipse.ui;bundle-version="3.8.2",
com.raytheon.uf.common.localization;bundle-version="1.12.1174",
com.raytheon.uf.common.archive;bundle-version="1.0.0",
com.raytheon.uf.common.time;bundle-version="1.12.1174",
com.raytheon.uf.common.util;bundle-version="1.12.1174"
com.raytheon.uf.common.util;bundle-version="1.12.1174",
com.raytheon.uf.viz.core;bundle-version="1.12.1174",
com.raytheon.uf.common.units;bundle-version="1.0.0"
Bundle-RequiredExecutionEnvironment: JavaSE-1.6
Bundle-ActivationPolicy: lazy

View file

@ -0,0 +1,62 @@
/**
* 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.data;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
/**
* This class maintains the state of the archive selection so it can be restored
* by the GUI.
*
* <pre>
*
* SOFTWARE HISTORY
*
* Date Ticket# Engineer Description
* ------------ ---------- ----------- --------------------------
* May 24, 2013 1966 rferrel Initial creation
*
* </pre>
*
* @author rferrel
* @version 1.0
*/
public class ArchiveInfo {
private final Map<String, CategoryInfo> categoryInfoMap = new HashMap<String, CategoryInfo>();
public void add(CategoryInfo categoryInfo) {
categoryInfoMap.put(categoryInfo.getCategoryName(), categoryInfo);
}
public CategoryInfo get(String categoryName) {
return categoryInfoMap.get(categoryName);
}
public void clear() {
categoryInfoMap.clear();
}
public Set<String> getCategoryNames() {
return categoryInfoMap.keySet();
}
}

View file

@ -0,0 +1,69 @@
/**
* 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.data;
import java.util.List;
import com.raytheon.uf.common.archive.config.ArchiveConfigManager;
/**
* This class used to maintain the state of a category so it can be restored
* when reselected.
*
* <pre>
*
* SOFTWARE HISTORY
*
* Date Ticket# Engineer Description
* ------------ ---------- ----------- --------------------------
* May 24, 2013 1966 rferrel Initial creation
*
* </pre>
*
* @author rferrel
* @version 1.0
*/
public class CategoryInfo {
private final String archiveName;
private final String categoryName;
private final List<ArchiveConfigManager.DisplayData> displayInfoList;
public CategoryInfo(String archiveName, String categoryName,
List<ArchiveConfigManager.DisplayData> displayInfoList) {
this.archiveName = archiveName;
this.categoryName = categoryName;
this.displayInfoList = displayInfoList;
}
public String getArchiveName() {
return archiveName;
}
public String getCategoryName() {
return categoryName;
}
public List<ArchiveConfigManager.DisplayData> getDisplayInfoList() {
return displayInfoList;
}
}

View file

@ -0,0 +1,186 @@
/**
* 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.data;
import java.io.File;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.LinkedList;
import java.util.List;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.core.runtime.jobs.Job;
import com.raytheon.uf.common.archive.config.ArchiveConfigManager;
import com.raytheon.uf.common.archive.config.ArchiveConfigManager.DisplayData;
import com.raytheon.uf.common.util.FileUtil;
/**
* This class uses a obtains information on a File in a Job in order to remove
* from the UI thread.
*
* <pre>
*
* SOFTWARE HISTORY
*
* Date Ticket# Engineer Description
* ------------ ---------- ----------- --------------------------
* May 15, 2013 1966 rferrel Initial creation
*
* </pre>
*
* @author rferrel
* @version 1.0
*/
public class DirInfo {
private static final SizeJob sizeJob = new DirInfo.SizeJob();
final private DisplayData displayInfo;
private final List<File> files = new ArrayList<File>();
private Calendar startCal;
private Calendar endCal;
public static void clearQueue() {
sizeJob.clearQueue();
}
public static void addUpdateListener(IUpdateListener listener) {
sizeJob.listeners.add(listener);
}
public static void removeUpdateListener(IUpdateListener listener) {
sizeJob.listeners.remove(listener);
}
public DirInfo(DisplayData displayInfo, Calendar startCal, Calendar endCal) {
this.displayInfo = displayInfo;
this.startCal = startCal;
this.endCal = endCal;
displayInfo.setSize(-1);
DirInfo.sizeJob.queue(this);
}
public DisplayData getDisplayInfo() {
return displayInfo;
}
static private class SizeJob extends Job {
private LinkedList<DirInfo> queueList = new LinkedList<DirInfo>();
private boolean isShutdown = false;
List<IUpdateListener> listeners = new ArrayList<IUpdateListener>();
protected void queue(DirInfo fileInfo) {
synchronized (queueList) {
queueList.add(fileInfo);
if (getState() == Job.NONE) {
System.out.println("schedule queue size: "
+ queueList.size());
schedule();
}
}
}
protected void clearQueue() {
synchronized (queueList) {
queueList.clear();
if (getState() != Job.NONE) {
isShutdown = true;
}
}
}
public SizeJob() {
super("Size Job");
setSystem(true);
}
@Override
protected IStatus run(IProgressMonitor monitor) {
ArchiveConfigManager manager = ArchiveConfigManager.getInstance();
System.out.println("starting SizeJob");
long startTime = System.currentTimeMillis();
while (!isShutdown && !queueList.isEmpty()) {
List<DirInfo> list = null;
synchronized (queueList) {
list = new ArrayList<DirInfo>(queueList);
queueList.clear();
}
System.out.println("sizeJob Processing: " + list.size());
long t1 = System.currentTimeMillis();
for (DirInfo dirInfo : list) {
long t2 = System.currentTimeMillis();
if (isShutdown) {
break;
}
DisplayData displayInfo = dirInfo.displayInfo;
Calendar startCal = dirInfo.startCal;
Calendar endCal = dirInfo.endCal;
displayInfo.setSize(-1);
List<File> files = manager.getDisplayFiles(displayInfo,
startCal, endCal);
dirInfo.files.clear();
dirInfo.files.addAll(files);
long size = 0L;
for (File file : dirInfo.files) {
if (isShutdown) {
break;
}
if (file.isDirectory()) {
size += FileUtil.sizeOfDirectory(file);
} else {
size += file.length();
}
}
long t3 = System.currentTimeMillis();
System.out.println("-- \"" + displayInfo.getDisplayLabel()
+ "\": oldSize: " + displayInfo.getSize()
+ ", newSize: " + size + ", time: " + (t3 - t2)
+ " ms");
displayInfo.setSize(size);
}
if (!isShutdown) {
for (IUpdateListener listener : listeners) {
listener.update(list);
}
} else {
synchronized (queueList) {
isShutdown = false;
}
}
}
System.out.println("Ending SizeJob");
return Status.OK_STATUS;
}
}
}

View file

@ -33,7 +33,7 @@ import com.raytheon.uf.common.util.FileUtil;
/**
* This class uses a obtains information on a File in a Job in order to remove
* from the UI thread.
* from the UI thread. Use DirInfo instead.
*
* <pre>
*
@ -48,7 +48,7 @@ import com.raytheon.uf.common.util.FileUtil;
* @author rferrel
* @version 1.0
*/
@Deprecated
public class FileInfo {
private static final SizeJob sizeJob = new FileInfo.SizeJob();
@ -103,7 +103,7 @@ public class FileInfo {
}
for (IUpdateListener listener : listeners) {
listener.update(list);
// listener.update(list);
}
}

View file

@ -0,0 +1,46 @@
/**
* This software was developed and / or modified by Raytheon Company,
* pursuant to Contract DG133W-05-CQ-1067 with the US Government.
*
* U.S. EXPORT CONTROLLED TECHNICAL DATA
* This software product contains export-restricted data whose
* export/transfer/disclosure is restricted by U.S. law. Dissemination
* to non-U.S. persons whether in the United States or abroad requires
* an export license or other authorization.
*
* Contractor Name: Raytheon Company
* Contractor Address: 6825 Pine Street, Suite 340
* Mail Stop B8
* Omaha, NE 68106
* 402.291.0100
*
* See the AWIPS II Master Rights File ("Master Rights File.pdf") for
* further licensing information.
**/
package com.raytheon.uf.viz.archive.data;
/**
* Interface for methods for getting totals needed by the ArchiveTableComp.
*
* <pre>
*
* SOFTWARE HISTORY
*
* Date Ticket# Engineer Description
* ------------ ---------- ----------- --------------------------
* May 29, 2013 1996 rferrel Initial creation
*
* </pre>
*
* @author rferrel
* @version 1.0
*/
public interface IArchiveTotals {
/**
* Total selected items from all tables.
*
* @return totalSelectedItems.
*/
public int getTotalSelectedItems();
}

View file

@ -19,6 +19,8 @@
**/
package com.raytheon.uf.viz.archive.data;
import java.util.List;
/**
* A listener to update file/directory information.
*
@ -35,12 +37,11 @@ package com.raytheon.uf.viz.archive.data;
* @author rferrel
* @version 1.0
*/
public interface IUpdateListener {
/**
* List of files/directories with updated information
* Table display state entries with updated information.
*
* @param fileInfoArray
* @param dirInfos
*/
public void update(FileInfo[] fileInfoArray);
public void update(List<DirInfo> dirInfos);
}

View file

@ -32,6 +32,7 @@ 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;
@ -51,7 +52,7 @@ import com.raytheon.viz.ui.dialogs.CaveSWTDialog;
* @author lvenable
* @version 1.0
*/
public class ArchiveRetentionDlg extends CaveSWTDialog {
public class ArchiveRetentionDlg extends CaveSWTDialog implements IArchiveTotals {
/** Table composite that holds the table controls. */
private ArchiveTableComp tableComp;
@ -218,7 +219,7 @@ public class ArchiveRetentionDlg extends CaveSWTDialog {
* Create the table control.
*/
private void createTable() {
tableComp = new ArchiveTableComp(shell, TableType.Case);
tableComp = new ArchiveTableComp(shell, TableType.Case, this);
}
/**
@ -346,4 +347,10 @@ public class ArchiveRetentionDlg extends CaveSWTDialog {
categoryCbo.add("Satellite");
categoryCbo.select(0);
}
@Override
public int getTotalSelectedItems() {
// TODO Auto-generated method stub
return 0;
}
}

View file

@ -19,6 +19,8 @@
**/
package com.raytheon.uf.viz.archive.ui;
import java.util.List;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.MouseAdapter;
import org.eclipse.swt.events.MouseEvent;
@ -35,6 +37,10 @@ import org.eclipse.swt.widgets.Table;
import org.eclipse.swt.widgets.TableColumn;
import org.eclipse.swt.widgets.TableItem;
import com.raytheon.uf.common.archive.config.ArchiveConfigManager.DisplayData;
import com.raytheon.uf.common.util.SizeUtil;
import com.raytheon.uf.viz.archive.data.IArchiveTotals;
/**
* Archive table composite that contains the SWT table.
*
@ -53,6 +59,9 @@ import org.eclipse.swt.widgets.TableItem;
*/
public class ArchiveTableComp extends Composite {
/** Key for getting Display Information state. */
private final String DISPLAY_INFO_KEY = "displayInfo";
/** Table control. */
private Table table;
@ -62,6 +71,9 @@ public class ArchiveTableComp extends Composite {
/** Number of selected items label. */
private Label selectedLbl;
/** Total selected items for all tables */
private Label totalSelectedLbl;
/** Size label. */
private Label sizeLbl;
@ -73,6 +85,8 @@ public class ArchiveTableComp extends Composite {
/** Current table type. */
private TableType tableType = TableType.Retention;
private IArchiveTotals iTotalSelectedSize;
/**
* Constructor.
*
@ -81,10 +95,12 @@ public class ArchiveTableComp extends Composite {
* @param type
* Table type.
*/
public ArchiveTableComp(Composite parent, TableType type) {
public ArchiveTableComp(Composite parent, TableType type,
IArchiveTotals iTotalSelectedSize) {
super(parent, 0);
tableType = type;
this.iTotalSelectedSize = iTotalSelectedSize;
init();
}
@ -103,41 +119,35 @@ public class ArchiveTableComp extends Composite {
createTable();
createTableLabels();
updateSelectionLabel();
updateSelectionLabels();
}
/**
* Create the table control.
*/
private void createTable() {
GridData gd = null;
table = new Table(this, SWT.CHECK | SWT.BORDER | SWT.V_SCROLL
| SWT.H_SCROLL | SWT.MULTI);
GridData gd = new GridData(SWT.FILL, SWT.DEFAULT, true, true);
gd = new GridData(SWT.FILL, SWT.DEFAULT, true, true);
gd.widthHint = 730;
gd.heightHint = 270;
table.setLayoutData(gd);
table.setHeaderVisible(true);
table.setLinesVisible(true);
TableColumn pathColumn = new TableColumn(table, SWT.CENTER);
pathColumn.setText("Path");
TableColumn pathColumn = new TableColumn(table, SWT.LEFT);
pathColumn.setText("Label");
TableColumn sizeColumn = new TableColumn(table, SWT.CENTER);
if (tableType == TableType.Retention) {
sizeColumn.setText("Current Size (MB)");
sizeColumn.setText("Current Size");
} else if (tableType == TableType.Case) {
sizeColumn.setText("Size (MB)");
sizeColumn.setText("Size");
}
populateTable();
for (int i = 0; i < 2; i++) {
table.getColumn(i).setResizable(false);
table.getColumn(i).setMoveable(false);
table.getColumn(i).pack();
}
table.getColumn(1).setWidth(100);
table.getColumn(0).setWidth(500);
table.addMouseListener(new MouseAdapter() {
@Override
@ -152,7 +162,7 @@ public class ArchiveTableComp extends Composite {
table.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
updateSelectionLabel();
updateSelectionLabels();
}
});
}
@ -162,7 +172,7 @@ public class ArchiveTableComp extends Composite {
*/
private void createTableLabels() {
Composite lblComp = new Composite(this, SWT.NONE);
GridLayout gl = new GridLayout(2, true);
GridLayout gl = new GridLayout(3, true);
GridData gd = new GridData(SWT.FILL, SWT.DEFAULT, true, false);
lblComp.setLayout(gl);
lblComp.setLayoutData(gd);
@ -171,30 +181,51 @@ public class ArchiveTableComp extends Composite {
selectedLbl = new Label(lblComp, SWT.NONE);
selectedLbl.setLayoutData(gd);
/*
* TODO : keep for future use. This will be used to show the total size
* of the selected items in the table.
*/
// gd = new GridData(SWT.FILL, SWT.DEFAULT, true, false);
// sizeLbl = new Label(lblComp, SWT.NONE);
// sizeLbl.setLayoutData(gd);
// sizeLbl.setText("Size of Selected items: 0" + sizeSuffix);
gd = new GridData(SWT.FILL, SWT.DEFAULT, true, false);
sizeLbl = new Label(lblComp, SWT.NONE);
sizeLbl.setLayoutData(gd);
gd = new GridData(SWT.FILL, SWT.DEFAULT, true, false);
totalSelectedLbl = new Label(lblComp, SWT.NONE);
totalSelectedLbl.setLayoutData(gd);
}
/**
* Update the selection items label.
* Update the selection items labels.
*/
private void updateSelectionLabel() {
private void updateSelectionLabels() {
TableItem[] itemArray = table.getItems();
int count = 0;
long tableTotalSize = 0;
for (TableItem ti : itemArray) {
DisplayData displayInfo = (DisplayData) ti
.getData(DISPLAY_INFO_KEY);
if (ti.getChecked()) {
count++;
++count;
displayInfo.setSelected(true);
if (tableTotalSize >= 0) {
long diSize = displayInfo.getSize();
if (diSize < 0) {
tableTotalSize = diSize;
} else {
tableTotalSize += diSize;
}
}
} else {
displayInfo.setSelected(false);
}
}
selectedLbl.setText("Selected Items: " + count);
selectedLbl.setText("Table Selected Items: " + count);
int totalSelectedSize = iTotalSelectedSize.getTotalSelectedItems();
totalSelectedLbl.setText("Total Selected Items: " + totalSelectedSize);
String sizeString = "????";
if (tableTotalSize >= 0) {
sizeString = SizeUtil.prettyByteSize(tableTotalSize);
}
sizeLbl.setText("Table Selected Size: " + sizeString);
}
/**
@ -260,12 +291,12 @@ public class ArchiveTableComp extends Composite {
*/
private void handleCheckSelectedRow(boolean check) {
TableItem[] itemArray = table.getSelection();
System.out.println("handleCheckSelectedRow: " + check);
for (TableItem ti : itemArray) {
ti.setChecked(check);
}
updateSelectionLabel();
updateSelectionLabels();
}
/**
@ -281,23 +312,51 @@ public class ArchiveTableComp extends Composite {
ti.setChecked(check);
}
updateSelectionLabel();
updateSelectionLabels();
}
public void updateSize(List<DisplayData> displayInfos) {
TableItem[] itemArray = table.getItems();
for (DisplayData displayInfo : displayInfos) {
for (TableItem ti : itemArray) {
if (displayInfo.equals(ti.getData(DISPLAY_INFO_KEY))) {
setItemSize(ti);
}
}
}
}
/*
* TODO : this is just for display purposes. This will go away when the
* functionality is implemented.
*/
private void populateTable() {
for (int i = 0; i < 150; i++) {
protected void populateTable(List<DisplayData> displayInfoArray) {
table.removeAll();
for (DisplayData displayInfo : displayInfoArray) {
TableItem item = new TableItem(table, SWT.NONE);
item.setText(0,
"/home/lvenable/caveData/configuration/base/com.raytheon.uf.viz.gisdatastore/"
+ i + " ");
if (i % 5 == 0) {
item.setChecked(true);
}
item.setText(1, "?????");
item.setData(DISPLAY_INFO_KEY, displayInfo);
item.setChecked(displayInfo.isSelected());
item.setText(0, displayInfo.getDisplayLabel());
item.setChecked(displayInfo.isSelected());
setItemSize(item);
}
for (int i = 0; i < 2; i++) {
table.getColumn(i).setResizable(false);
table.getColumn(i).setMoveable(false);
table.getColumn(i).pack();
}
table.getColumn(0).setWidth(600);
updateSelectionLabels();
}
private void setItemSize(TableItem item) {
long size = ((DisplayData) item.getData(DISPLAY_INFO_KEY)).getSize();
if (size < 0L) {
item.setText(1, "????");
} else {
item.setText(1, SizeUtil.prettyByteSize(size));
}
}
}

View file

@ -19,12 +19,20 @@
**/
package com.raytheon.uf.viz.archive.ui;
import java.io.File;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
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.Color;
import org.eclipse.swt.graphics.Cursor;
import org.eclipse.swt.graphics.GC;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.layout.GridData;
@ -33,14 +41,24 @@ import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Combo;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.DirectoryDialog;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Layout;
import org.eclipse.swt.widgets.MessageBox;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Spinner;
import com.raytheon.uf.common.archive.config.ArchiveConfigManager;
import com.raytheon.uf.common.archive.config.ArchiveConfigManager.DisplayData;
import com.raytheon.uf.common.time.util.TimeUtil;
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.data.IUpdateListener;
import com.raytheon.uf.viz.archive.ui.ArchiveTableComp.TableType;
import com.raytheon.uf.viz.core.VizApp;
import com.raytheon.viz.ui.dialogs.AwipsCalendar;
import com.raytheon.viz.ui.dialogs.CaveSWTDialog;
@ -61,7 +79,8 @@ import com.raytheon.viz.ui.dialogs.CaveSWTDialog;
* @author lvenable
* @version 1.0
*/
public class CaseCreationDlg extends CaveSWTDialog {
public class CaseCreationDlg extends CaveSWTDialog implements IArchiveTotals,
IUpdateListener {
/** Table control */
private ArchiveTableComp tableComp;
@ -102,6 +121,9 @@ public class CaseCreationDlg extends CaveSWTDialog {
/** Directory location label. */
private Label locationLbl;
/** Directory location state. */
private Label locationStateLbl;
/** Uncompressed file size label. */
private Label uncompressSizeLbl;
@ -109,6 +131,14 @@ public class CaseCreationDlg extends CaveSWTDialog {
private SimpleDateFormat dateFmt = new SimpleDateFormat(
"E MMM dd yyyy HH:00 z");
/** Archive configuration manager */
private ArchiveConfigManager manager = ArchiveConfigManager.getInstance();
/** Information for populating the various table displays. */
private final Map<String, ArchiveInfo> archiveInfoMap = new HashMap<String, ArchiveInfo>();
private Cursor busyCursor;
/**
* Constructor.
*
@ -132,7 +162,8 @@ public class CaseCreationDlg extends CaveSWTDialog {
@Override
protected void initializeComponents(Shell shell) {
setText("Case Creation");
busyCursor = shell.getDisplay().getSystemCursor(SWT.CURSOR_WAIT);
setText("Archive Case Creation");
Composite mainComp = new Composite(shell, SWT.NONE);
GridLayout gl = new GridLayout(1, false);
gl.marginHeight = 0;
@ -140,14 +171,21 @@ public class CaseCreationDlg extends CaveSWTDialog {
gl.horizontalSpacing = 0;
mainComp.setLayout(gl);
manager.reset();
init();
}
@Override
protected void disposed() {
DirInfo.removeUpdateListener(this);
}
/**
* Initialize method to create all of the composite & controls.
*/
private void init() {
DirInfo.addUpdateListener(this);
createTimeControls();
addSeparator(shell, SWT.HORIZONTAL);
createCaseCompressionControls();
@ -199,9 +237,10 @@ public class CaseCreationDlg extends CaveSWTDialog {
endTimeLbl = new Label(timeComp, SWT.BORDER);
endTimeLbl.setLayoutData(gd);
Date date = TimeUtil.newDate();
startDate = date;
endDate = date;
endDate = TimeUtil.newDate();
long time = endDate.getTime();
time -= TimeUtil.MILLIS_PER_DAY;
startDate = new Date(time);
startTimeLbl.setText(dateFmt.format(startDate));
endTimeLbl.setText(dateFmt.format(endDate));
}
@ -244,9 +283,9 @@ public class CaseCreationDlg extends CaveSWTDialog {
archCfgCbo.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
/*
* TODO - add code to update the category combo box
*/
String archiveName = archCfgCbo.getItem(archCfgCbo
.getSelectionIndex());
populateCategoryCbo(archiveName);
}
});
@ -260,9 +299,11 @@ public class CaseCreationDlg extends CaveSWTDialog {
categoryCbo.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
/*
* TODO - add code to update the information in the table
*/
String archiveName = archCfgCbo.getItem(archCfgCbo
.getSelectionIndex());
String categoryName = categoryCbo.getItem(categoryCbo
.getSelectionIndex());
populateTableComp(archiveName, categoryName);
}
});
}
@ -294,9 +335,9 @@ public class CaseCreationDlg extends CaveSWTDialog {
gd = new GridData(SWT.FILL, SWT.DEFAULT, true, false);
uncompressSizeLbl = new Label(compressionLblComp, SWT.NONE);
uncompressSizeLbl.setText("1024 MB");
// uncompressSizeLbl.setText("1024 MB");
uncompressSizeLbl.setLayoutData(gd);
updateUncompressSizeLbl();
/*
* Compression controls
*/
@ -358,7 +399,7 @@ public class CaseCreationDlg extends CaveSWTDialog {
*/
private void createFileBrowserControls() {
Composite fileBrowserComp = new Composite(shell, SWT.NONE);
GridLayout gl = new GridLayout(4, false);
GridLayout gl = new GridLayout(6, false);
GridData gd = new GridData(SWT.FILL, SWT.DEFAULT, true, false);
fileBrowserComp.setLayout(gl);
fileBrowserComp.setLayoutData(gd);
@ -378,13 +419,20 @@ public class CaseCreationDlg extends CaveSWTDialog {
handleBrowserSelection();
}
});
Label stateLbl = new Label(fileBrowserComp, SWT.NONE);
stateLbl.setText("Full - Avaliable:");
locationStateLbl = new Label(fileBrowserComp, SWT.BORDER);
gd = new GridData(200, SWT.DEFAULT);
locationStateLbl.setLayoutData(gd);
}
/**
* Create the table control.
*/
private void createTable() {
tableComp = new ArchiveTableComp(shell, TableType.Case);
tableComp = new ArchiveTableComp(shell, TableType.Case, this);
}
/**
@ -494,6 +542,38 @@ public class CaseCreationDlg extends CaveSWTDialog {
locationLbl.setText(trimDirectoryName(dirName));
locationLbl.setToolTipText(dirName);
locationLbl.setData(dirName);
File dir = new File(dirName);
long totSpace = dir.getTotalSpace();
long freeSpace = dir.getUsableSpace();
long percentFull = (long) Math
.round(((totSpace - freeSpace) * 100.0) / totSpace);
String state = null;
Color bgColor = null;
Color fgColor = null;
Display display = shell.getDisplay();
if (percentFull <= 84) {
state = "GOOD";
bgColor = display.getSystemColor(SWT.COLOR_GREEN);
fgColor = display.getSystemColor(SWT.COLOR_BLACK);
} else if (percentFull <= 94) {
state = "CAUTION";
bgColor = display.getSystemColor(SWT.COLOR_YELLOW);
fgColor = display.getSystemColor(SWT.COLOR_BLACK);
} else if (percentFull <= 97) {
state = "DANGER";
bgColor = display.getSystemColor(SWT.COLOR_RED);
fgColor = display.getSystemColor(SWT.COLOR_BLACK);
} else {
state = "FATAL";
bgColor = display.getSystemColor(SWT.COLOR_DARK_MAGENTA);
fgColor = display.getSystemColor(SWT.COLOR_WHITE);
}
String text = String.format("%1$3d%% %2$s - %3$s", percentFull,
state, SizeUtil.prettyByteSize(freeSpace));
locationStateLbl.setText(text);
locationStateLbl.setBackground(bgColor);
locationStateLbl.setForeground(fgColor);
}
}
@ -526,9 +606,16 @@ public class CaseCreationDlg extends CaveSWTDialog {
* True for start time, false for end time.
*/
private void displayDateTimeControls(boolean startTimeFlag) {
AwipsCalendar ac = new AwipsCalendar(shell, 1);
Date acDate = startTimeFlag ? startDate : endDate;
AwipsCalendar ac = new AwipsCalendar(shell, acDate, 1);
ac.setTimeZone(TimeUtil.newCalendar().getTimeZone());
Date date = (Date) ac.open();
if (date == null) {
return;
}
if (startTimeFlag) {
if (date.after(endDate)) {
MessageBox mb = new MessageBox(shell, SWT.ICON_QUESTION
@ -538,6 +625,12 @@ public class CaseCreationDlg extends CaveSWTDialog {
mb.open();
return;
}
if (!startDate.equals(date)) {
startDate = date;
// TODO update all information not just the current table.
populateTableComp();
}
} else {
if (date.before(startDate)) {
MessageBox mb = new MessageBox(shell, SWT.ICON_QUESTION
@ -547,6 +640,11 @@ public class CaseCreationDlg extends CaveSWTDialog {
mb.open();
return;
}
if (!endDate.equals(date)) {
endDate = date;
// TODO update all information not just the current table.
populateTableComp();
}
}
if (startTimeFlag) {
@ -587,18 +685,21 @@ public class CaseCreationDlg extends CaveSWTDialog {
return str;
}
/********************************************************
* TEST METHODS ******************************************************
/**
* Initial set up of the combo boxes.
*/
private void populateComboBoxes() {
archCfgCbo.add("Raw");
archCfgCbo.add("Processed");
archCfgCbo.select(0);
boolean doSelect = false;
for (String archiveName : manager.getArchiveDataNamesList()) {
archCfgCbo.add(archiveName);
doSelect = true;
}
categoryCbo.add("Radar");
categoryCbo.add("Point");
categoryCbo.add("Satellite");
categoryCbo.select(0);
if (doSelect) {
archCfgCbo.select(0);
String archiveName = archCfgCbo.getItem(0);
populateCategoryCbo(archiveName);
}
fileSizeCbo.add("MB");
fileSizeCbo.add("GB");
@ -606,4 +707,130 @@ public class CaseCreationDlg extends CaveSWTDialog {
fileSizeCbo
.setData(fileSizeCbo.getItem(fileSizeCbo.getSelectionIndex()));
}
/**
* Populate the category combo based on the archive name and populate the
* table.
*
* @param archiveName
*/
private void populateCategoryCbo(String archiveName) {
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 = archCfgCbo.getItem(archCfgCbo.getSelectionIndex());
String categoryName = categoryCbo.getItem(categoryCbo
.getSelectionIndex());
populateTableComp(archiveName, categoryName);
}
private void populateTableComp(String archiveName, String categoryName) {
setBusy(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) {
List<DisplayData> displayInfos = manager.getDisplayInfo(
archiveName, categoryName);
categoryInfo = new CategoryInfo(archiveName, categoryName,
displayInfos);
archiveInfo.add(categoryInfo);
}
// TODO investigate using just Date or long values for start/end
Calendar startCal = TimeUtil.newCalendar();
startCal.setTimeInMillis(startDate.getTime());
Calendar endCal = TimeUtil.newCalendar();
endCal.setTimeInMillis(endDate.getTime());
for (DisplayData displayInfo : categoryInfo.getDisplayInfoList()) {
new DirInfo(displayInfo, startCal, endCal);
}
tableComp.populateTable(categoryInfo.getDisplayInfoList());
updateUncompressSizeLbl();
setBusy(false);
}
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;
}
}
}
}
updateUncompressSizeLbl();
return totalSelected;
}
private void setBusy(boolean state) {
Cursor cursor = null;
if (state) {
cursor = busyCursor;
}
shell.setCursor(cursor);
}
@Override
public void update(List<DirInfo> dirInfos) {
final List<DisplayData> displayInfos = new ArrayList<ArchiveConfigManager.DisplayData>();
for (DirInfo dirInfo : dirInfos) {
displayInfos.add(dirInfo.getDisplayInfo());
}
VizApp.runAsync(new Runnable() {
@Override
public void run() {
tableComp.updateSize(displayInfos);
updateUncompressSizeLbl();
}
});
}
/**
* Updates the estimated uncompressed size of selected entries.
*/
private void updateUncompressSizeLbl() {
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.
uncompressSizeLbl.setText("????MB");
return;
} else {
totalSize += size;
}
}
}
}
}
uncompressSizeLbl.setText(SizeUtil.prettyByteSize(totalSize));
}
}

View file

@ -19,6 +19,7 @@
**/
package com.raytheon.uf.common.archive.config;
import java.io.File;
import java.util.ArrayList;
import java.util.List;
@ -128,11 +129,16 @@ public class ArchiveConfig implements Comparable<ArchiveConfig> {
/**
* Set the fully qualified name of the directory all components are relative
* to.
*
* @param rootDir
*/
public void setRootDir(String rootDir) {
this.rootDir = rootDir;
if (rootDir != null && !rootDir.endsWith(File.separator)) {
this.rootDir = rootDir + File.separator;
} else {
this.rootDir = rootDir;
}
}
/**

View file

@ -22,8 +22,6 @@ package com.raytheon.uf.common.archive.config;
import java.io.File;
import java.io.FileFilter;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.text.FieldPosition;
import java.text.MessageFormat;
import java.util.ArrayList;
@ -49,6 +47,8 @@ import org.apache.commons.io.filefilter.RegexFileFilter;
import com.raytheon.uf.common.archive.exception.ArchiveException;
import com.raytheon.uf.common.localization.IPathManager;
import com.raytheon.uf.common.localization.LocalizationFile;
import com.raytheon.uf.common.localization.LocalizationFileInputStream;
import com.raytheon.uf.common.localization.LocalizationFileOutputStream;
import com.raytheon.uf.common.localization.PathManagerFactory;
import com.raytheon.uf.common.localization.exception.LocalizationException;
import com.raytheon.uf.common.status.IUFStatusHandler;
@ -86,8 +86,6 @@ public class ArchiveConfigManager {
private final Map<String, ArchiveConfig> archiveMap = new HashMap<String, ArchiveConfig>();
private Map<ArchiveConfig, Map<CategoryConfig, Map<String, List<File>>>> displayDirMap = new HashMap<ArchiveConfig, Map<CategoryConfig, Map<String, List<File>>>>();
public final static ArchiveConfigManager getInstance() {
return instance;
}
@ -128,7 +126,7 @@ public class ArchiveConfigManager {
}
/**
* Obtain the names of the categories for the named archive data.
* Get a sorted array of the archive's categories.
*
* @param archiveConfigName
* @return categoryNames
@ -138,8 +136,10 @@ public class ArchiveConfigManager {
}
/**
* Get a sorted array of the archive's categories.
*
* @param archiveConfig
* @return
* @return categoryNames
*/
public String[] getCategoryNames(ArchiveConfig archiveConfig) {
List<CategoryConfig> categories = archiveConfig.getCategoryList();
@ -154,7 +154,7 @@ public class ArchiveConfigManager {
}
/**
* Load the archiveConfig information form the localized file.
* Load the archiveConfig information from the localized file.
*
* @param lFile
* @return archiveConfig
@ -201,11 +201,12 @@ public class ArchiveConfigManager {
if (archiveDir.exists() || archiveDir.mkdirs()) {
Collection<File> filesToArchive = new ArrayList<File>();
for (String displayLabel : displaysSelectedForArchive) {
File[] files = getDisplayFiles(archive.getName(),
category.getName(), displayLabel, start, end);
filesToArchive.addAll(Arrays.asList(files));
}
// TODO Brad will fix.
// for (String displayLabel : displaysSelectedForArchive) {
// File[] files = getDisplayFiles(archive.getName(),
// category.getName(), displayLabel, start, end);
// filesToArchive.addAll(Arrays.asList(files));
// }
String rootDirString = archive.getRootDir();
String archiveDirString = archiveDir.getAbsolutePath();
@ -244,8 +245,7 @@ public class ArchiveConfigManager {
}
private File getDirRelativeToArchiveDirFromRoot(boolean fileIsDir,
String fileAbsPath,
String rootDirString, String archiveDirString) {
String fileAbsPath, String rootDirString, String archiveDirString) {
String path = null;
if (fileIsDir) {
path = fileAbsPath;
@ -270,21 +270,22 @@ public class ArchiveConfigManager {
for (CategoryConfig category : archive.getCategoryList()) {
Calendar purgeTime = calculateExpiration(archive, category);
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);
}
}
// 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);
// }
// }
}
return filesPurged;
}
@ -325,99 +326,26 @@ public class ArchiveConfigManager {
}
}
/**
* Add the file entry to the desired display map.
*
* @param file
* @param archiveConfig
* @param categoryConfig
* @param displayLabel
*/
private void addDirToDisplayMap(File file, ArchiveConfig archiveConfig,
CategoryConfig categoryConfig, String displayLabel) {
Map<CategoryConfig, Map<String, List<File>>> cMap = displayDirMap
.get(archiveConfig);
if (cMap == null) {
cMap = new HashMap<CategoryConfig, Map<String, List<File>>>();
displayDirMap.put(archiveConfig, cMap);
}
Map<String, List<File>> dirMap = cMap.get(categoryConfig);
if (dirMap == null) {
dirMap = new HashMap<String, List<File>>();
cMap.put(categoryConfig, dirMap);
}
List<File> fileList = dirMap.get(displayLabel);
if (fileList == null) {
fileList = new ArrayList<File>();
dirMap.put(displayLabel, fileList);
}
fileList.add(file);
}
/**
* Get a list of directories associated with the display label.
*
* @param archiveConfig
* @param categoryConfig
* @param displayLabel
* @return
*/
private File[] getDirFromDisplayMap(ArchiveConfig archiveConfig,
CategoryConfig categoryConfig, String displayLabel) {
Map<CategoryConfig, Map<String, List<File>>> cMap = displayDirMap
.get(archiveConfig);
File[] result = new File[0];
if (cMap == null) {
return result;
}
Map<String, List<File>> dirMap = cMap.get(categoryConfig);
if (dirMap == null) {
return result;
}
List<File> fileList = dirMap.get(displayLabel);
if (fileList == null) {
return result;
}
return fileList.toArray(result);
}
/**
* Clear maps and reloads the maps from the configuration information.
*
* @throws IOException
* @throws LocalizationException
*/
public void reset() throws IOException, LocalizationException {
clearDisplayMap();
public void reset() {
archiveMap.clear();
LocalizationFile[] files = getArchiveConfigFiles();
for (LocalizationFile lFile : files) {
ArchiveConfig archiveConfig = unmarshalArhiveConfigFromXmlFile(lFile);
archiveMap.put(archiveConfig.getName(), archiveConfig);
}
}
/**
* Walk the display directory maps clearing all entries.
*/
private void clearDisplayMap() {
for (ArchiveConfig archiveConfig : displayDirMap.keySet()) {
Map<CategoryConfig, Map<String, List<File>>> cMap = displayDirMap
.get(archiveConfig);
for (CategoryConfig categoryConfig : cMap.keySet()) {
Map<String, List<File>> dirMap = cMap.get(categoryConfig);
dirMap.remove(categoryConfig);
for (String displayLabel : dirMap.keySet()) {
List<File> fileList = dirMap.get(displayLabel);
fileList.clear();
}
dirMap.clear();
try {
ArchiveConfig archiveConfig;
archiveConfig = unmarshalArhiveConfigFromXmlFile(lFile);
archiveMap.put(archiveConfig.getName(), archiveConfig);
} catch (IOException e) {
statusHandler.handle(Priority.PROBLEM, e.getLocalizedMessage(),
e);
} catch (LocalizationException e) {
statusHandler.handle(Priority.PROBLEM, e.getLocalizedMessage(),
e);
}
}
}
@ -426,20 +354,13 @@ public class ArchiveConfigManager {
* Get a list of directories/files for the desired display label bounded by
* the start and end time inclusive.
*
* @param archiveName
* - name of the ArchiveConfig containing the category
* @param categoryName
* - name of the CategoryConfig containing the display
* @param displayLabel
* - the display label
* @param displayInfo
* @param startCal
* - Start time if null epoch time is used
* @param endCal
* - End time if null current simulated time is used.
* @return files
*/
public File[] getDisplayFiles(String archiveName, String categoryName,
String displayLabel, Calendar startCal, Calendar endCal) {
public List<File> getDisplayFiles(DisplayData displayInfo,
Calendar startCal, Calendar endCal) {
long startTime = 0L;
if (startCal != null) {
// Set to beginning of the hour
@ -464,8 +385,7 @@ public class ArchiveConfigManager {
cal.add(Calendar.HOUR_OF_DAY, 1);
long endTime = cal.getTimeInMillis();
return getDisplayFiles(archiveName, categoryName, displayLabel,
startTime, endTime);
return getDisplayFiles(displayInfo, startTime, endTime);
}
/**
@ -476,10 +396,8 @@ public class ArchiveConfigManager {
* @param displayLabel
* @return files
*/
public File[] getDisplayFiles(String archiveName, String categoryName,
String displayLabel) {
return getDisplayFiles(archiveName, categoryName, displayLabel, null,
null);
public List<File> getDisplayFiles(DisplayData displayInfo) {
return getDisplayFiles(displayInfo, null, null);
}
/**
@ -493,11 +411,10 @@ public class ArchiveConfigManager {
* @param endTime
* @return files
*/
private File[] getDisplayFiles(String archiveName, String categoryName,
String displayLabel, long startTime, long endTime) {
ArchiveConfig archiveConfig = archiveMap.get(archiveName);
CategoryConfig categoryConfig = findCategory(archiveConfig,
categoryName);
private List<File> getDisplayFiles(DisplayData displayInfo, long startTime,
long endTime) {
ArchiveConfig archiveConfig = displayInfo.archiveConfig;
CategoryConfig categoryConfig = displayInfo.categoryConfig;
String[] indexValues = categoryConfig.getDateGroupIndices().split(
"\\s*,\\s*");
@ -511,8 +428,7 @@ public class ArchiveConfigManager {
boolean dirOnly = (filePatternStr == null)
|| ".*".equals(filePatternStr);
File dirs[] = getDirFromDisplayMap(archiveConfig, categoryConfig,
displayLabel);
List<File> dirs = displayInfo.dirs;
int beginIndex = archiveConfig.getRootDir().length();
@ -573,23 +489,19 @@ public class ArchiveConfigManager {
}
}
File[] files = fileList.toArray(new File[0]);
return files;
return fileList;
}
/**
* Get the Display labels matching the pattern for the archive data's
* category. Assumes the archive data's root directory is the mount point to
* start the search.
* Get a list of directories matching the categories directory pattern that
* are sub-directories of the archive's root directory.
*
* @param archiveName
* @param categoryName
* @return sorted array of display labels
* @param archiveConfig
* @param categoryConfig
* @return dirs
*/
public String[] getDisplayLabels(String archiveName, String categoryName) {
ArchiveConfig archiveConfig = archiveMap.get(archiveName);
CategoryConfig categoryConfig = findCategory(archiveConfig,
categoryName);
private List<File> getDirs(ArchiveConfig archiveConfig,
CategoryConfig categoryConfig) {
String dirPattern = categoryConfig.getDirPattern();
File rootFile = new File(archiveConfig.getRootDir());
@ -618,8 +530,31 @@ public class ArchiveConfigManager {
tmpDirs = swpDirs;
tmpDirs.clear();
}
return dirs;
}
/**
* Get the Display labels matching the pattern for the archive data's
* category. Assumes the archive data's root directory is the mount point to
* start the search.
*
* @param archiveName
* @param categoryName
* @return displayInfoList order by display label
*/
public List<DisplayData> getDisplayInfo(String archiveName,
String categoryName) {
Map<String, List<File>> displayMap = new HashMap<String, List<File>>();
ArchiveConfig archiveConfig = archiveMap.get(archiveName);
CategoryConfig categoryConfig = findCategory(archiveConfig,
categoryName);
String dirPattern = categoryConfig.getDirPattern();
// index for making directory paths' relative to the root path.
List<File> dirs = getDirs(archiveConfig, categoryConfig);
File rootFile = new File(archiveMap.get(archiveName).getRootDir());
int beginIndex = rootFile.getAbsolutePath().length() + 1;
Pattern pattern = Pattern.compile("^" + dirPattern + "$");
TreeSet<String> displays = new TreeSet<String>(
@ -629,8 +564,8 @@ public class ArchiveConfigManager {
StringBuffer sb = new StringBuffer();
FieldPosition pos0 = new FieldPosition(0);
for (File file : dirs) {
String path = file.getAbsolutePath().substring(beginIndex);
for (File dir : dirs) {
String path = dir.getAbsolutePath().substring(beginIndex);
Matcher matcher = pattern.matcher(path);
if (matcher.matches()) {
sb.setLength(0);
@ -640,13 +575,25 @@ public class ArchiveConfigManager {
args[i] = matcher.group(i);
}
String displayLabel = msgfmt.format(args, sb, pos0).toString();
addDirToDisplayMap(file, archiveConfig, categoryConfig,
displayLabel);
List<File> displayDirs = displayMap.get(displayLabel);
if (displayDirs == null) {
displayDirs = new ArrayList<File>();
displayMap.put(displayLabel, displayDirs);
}
displayDirs.add(dir);
displays.add(displayLabel);
}
}
return displays.toArray(new String[0]);
List<DisplayData> displayInfoList = new ArrayList<ArchiveConfigManager.DisplayData>();
for (String displayLabel : displays) {
DisplayData displayInfo = new DisplayData(archiveConfig,
categoryConfig, displayLabel, displayMap.get(displayLabel));
displayInfoList.add(displayInfo);
}
return displayInfoList;
}
/**
@ -654,7 +601,7 @@ public class ArchiveConfigManager {
*
* @param archiveConfig
* @param categoryName
* @return
* @return categoryConfig
*/
private CategoryConfig findCategory(ArchiveConfig archiveConfig,
String categoryName) {
@ -677,11 +624,10 @@ public class ArchiveConfigManager {
*/
private void marshalArchiveConfigToXmlFile(ArchiveConfig archiveConfig,
LocalizationFile lFile) throws IOException, LocalizationException {
OutputStream stream = null;
LocalizationFileOutputStream stream = null;
stream = lFile.openOutputStream();
JAXB.marshal(archiveConfig, stream);
stream.close();
lFile.save();
stream.closeAndSave();
}
/**
@ -696,7 +642,7 @@ public class ArchiveConfigManager {
private ArchiveConfig unmarshalArhiveConfigFromXmlFile(
LocalizationFile lFile) throws IOException, LocalizationException {
ArchiveConfig archiveConfig = null;
InputStream stream = null;
LocalizationFileInputStream stream = null;
try {
stream = lFile.openInputStream();
archiveConfig = JAXB.unmarshal(stream, ArchiveConfig.class);
@ -711,4 +657,66 @@ public class ArchiveConfigManager {
}
return archiveConfig;
}
/**
* This class contains the information on directories that are associated
* with a display label. Allows a GUI to maintain the state of the display
* instead of the manager.
*/
public class DisplayData {
protected final ArchiveConfig archiveConfig;
protected final CategoryConfig categoryConfig;
protected final String displayLabel;
protected final List<File> dirs;
private boolean selected = false;
private long size = -1L;
public DisplayData(ArchiveConfig archiveConfig,
CategoryConfig categoryConfig, String displayLabel,
List<File> dirs) {
this.archiveConfig = archiveConfig;
this.categoryConfig = categoryConfig;
this.displayLabel = displayLabel;
this.dirs = dirs;
}
public boolean isSelected() {
return selected;
}
public void setSelected(boolean selected) {
this.selected = selected;
}
public String getDisplayLabel() {
return displayLabel;
}
public long getSize() {
return size;
}
public void setSize(long size) {
this.size = size;
}
public boolean equals(Object object) {
if (this == object) {
return true;
}
if (object instanceof DisplayData) {
DisplayData displayInfo = (DisplayData) object;
return (archiveConfig == displayInfo.archiveConfig
&& categoryConfig == displayInfo.categoryConfig && displayLabel
.equals(displayInfo.displayLabel));
}
return false;
}
}
}

View file

@ -35,7 +35,7 @@ import javax.xml.bind.annotation.XmlRootElement;
* &lt;!-- When 0 default to the parent archive's retentionHours -->
* &lt;retentionHours>0&lt;/retentionHours>
* &lt;dirPattern>hdf5/(redbook)&lt;/dirPattern>
* &lt;display>{1}&lt;/display>
* &lt;displayLabel>{1}&lt;/displayLabel>
* &lt;filePattern>redbook-(\d{4})-(\d{2})-(\d{2})-(\d{2})\..*&lt;/filePattern>
* &lt;dateGroupIndices>2,3,4,5&lt;/dateGroupIndices>
* &lt;/category>
@ -48,7 +48,7 @@ import javax.xml.bind.annotation.XmlRootElement;
* &lt;name>Model grib&lt;/name>
* &lt;retentionHours>0&lt;/retentionHours>
* &lt;dirPattern>grib/(\d{4})(\d{2})(\d{2})/(\d{2})/(.*)&lt;/dirPattern>
* &lt;display>{5}&lt;/display>
* &lt;displayLabel>{5}&lt;/displayLabel>
* &lt;dateGroupIndices>1,2,3,4&lt;/dateGroupIndices>
* &lt;/category>
* </pre>
@ -101,14 +101,14 @@ public class CategoryConfig implements Comparable<CategoryConfig> {
*
* <pre>
* &lt;dirName>(grib2)/(\d{4})(\d{2})(\d{2})/(\d{2})/(.*)&lt;/dirName>
* &lt;display>{1} - {6}&lt;/display>
* &lt;displayLabel>{1} - {6}&lt;/displayLabel>
* </pre>
*
* The {1} will be replaced by the first group (grib2) in the regex
* expression in dirName. The {6} is the sixth group (.*). {0} is the whole
* expression match.
*/
@XmlElement(name = "display")
@XmlElement(name = "displayLabel")
private String display;
/**
@ -120,7 +120,7 @@ public class CategoryConfig implements Comparable<CategoryConfig> {
*
* <pre>
* &lt;dirPattern>hdf5/(redbook)&lt;/dirPattern>
* &lt;display>{1}&lt;/display>
* &lt;displayLabel>{1}&lt;/displayLabel>
* &lt;filePattern>redbook-(\d{4})-(\d{2})-(\d{2})-(\d{2})\..*&lt;/filePattern>
* &lt;dateGroupIndices>2,3,4,5&lt;/dateGroupIndices>
* </pre>
@ -199,7 +199,7 @@ public class CategoryConfig implements Comparable<CategoryConfig> {
}
/**
* Get the diaplay pattern.
* Get the display label pattern.
*
* @return display
*/
@ -208,7 +208,7 @@ public class CategoryConfig implements Comparable<CategoryConfig> {
}
/**
* Set the display pattern.
* Set the display label pattern.
*
* @param display
*/
@ -274,7 +274,7 @@ public class CategoryConfig implements Comparable<CategoryConfig> {
sb.append(", retentionHours: ").append(getRetentionHours());
sb.append(", dirPattern: ").append(getDirPattern());
sb.append(", filePattern: ").append(getFilePattern());
sb.append(", display: ").append(getDisplay());
sb.append(", displayLabel: ").append(getDisplay());
sb.append(", dateGroupIndices: ").append(getDateGroupIndices());
sb.append("]");
return sb.toString();

View file

@ -23,26 +23,25 @@
<name> - Required tag. The id for the archive such as Raw or Processed.
Used in the GUIs to filter which archive to display.
<rootDir> - Required tag. The root directory on the edex server for the archive.
<retentionHours> - Required tag. The default number of hour to retain data in the <rootDir>
<category> - Detail information for display information in the archive GUIs and
overriding the default retention hours. There can be several of these tags.
<retentionHours> - Required tag. The default number of hours to retain data in the <rootDir>
<category> - Logical grouping of archive's sub-directories.
The <category> has six types of tags:
<name> - Required tag. The id for the category such as grib2 or redbook.
Used in the GUIs to filter what is the display in the table.
<retentionHours> - Optional tag. The retentionHours for this category.
Default is the archive's <retentionHours>.
<dirPattern> - Required tag. A pattern for finding directories for this category.
<dirPattern> - Required tag. A regex pattern for finding directories for this category.
The pattern is relative to the archive's <rootDir>. Wildcard patterns do not cross directory
delimiter /. Thus to match 3 levels of directories you would need .*/.*/.* .
See patterns and groups section.
<filePattern> - Optional tag. A pattern to find files in the directories that match the <dirPattern>.
Default is everything in the directories that match <dirPattern>.
See patterns and groups section.
<display> - Required tag. The label to display for directories that match <dirPattern>. Any group in the
<displayLabel> - Required tag. The label to display for directories that match <dirPattern>. Any group in the
<dirPattern> may be made part of the label by placing the group's index inside parenthesis, {1}.
More then one directory may match the <dirPattern>. The archive GUIs may clapse them into a single
table entry.
More then one directory may match the <dirPattern>. The archive GUIs may collapse them into a
single table entry.
<dateGroupIndicies> - Required tag. A comma separated list of 4 numbers which are the index of the groups in
<dirPattern> and/or <filePattern> that contain in order the year, mouth, day and hour information.
This is used to determine what files/directories to retain or a range of directories/files to copy
@ -52,9 +51,9 @@
The <dirPattern> and <filePattern> use Java regex expressions; similar to the ldm's pqact.conf file.
For more details see http://docs.oracle.com/javase/tutorial/essential/regex/
The groupings index start at one. The groups in the <dirPattern> can be used in the <display>. For example:
The groupings index start at one. The groups in the <dirPattern> can be used in the <displayLabel>. For example:
<dirPattern>(grib2)/(\d{4})(\d{2})(\d{2})/(\d{2})/(.*)</dirPattern>
<display>{1} - {6}</display>
<displayLabel>{1} - {6}</displayLabel>
<dateGroupIndices>2,3,4,5</dateGroupIndices>
Here the <dirPattern> contains six groups. The first group is the literal grib2 which matches only a directory named grib2
@ -68,7 +67,7 @@
Example with <filePattern>:
<dirPattern>hdf5/(redbook)</dirPattern>
<display>{1}</display>
<displayLabel>{1}</displayLabel>
<filePattern>redbook-(\d{4})-(\d{2})-(\d{2})-(\d{2})\..*</filePattern>
<dateGroupIndices>2,3,4,5</dateGroupIndices>
@ -76,7 +75,7 @@
come from the <filePattern> since there is one group in the <dirPattern> the groups in the <filePattern> start at two. This
matches file names redbook-YYYY-MM-DD-HH.<extension>. Thus the file name redbook-2013-05-28-00.hd5 would match the <filePattern>.
NOTE group {0} is a string that matches the whole <dirPattern>. If this is used in the <display> would see every directory that
NOTE group {0} is a string that matches the whole <dirPattern>. If this is used in the <displayLabel> would see every directory that
matches the pattern.
-->
<archive>
@ -87,7 +86,7 @@
<name>redbook</name>
<retentionHours>0</retentionHours>
<dirPattern>hdf5/(redbook)</dirPattern>
<display>{1}</display>
<displayLabel>{1}</displayLabel>
<filePattern>redbook-(\d{4})-(\d{2})-(\d{2})-(\d{2})\..*</filePattern>
<dateGroupIndices>2,3,4,5</dateGroupIndices>
</category>
@ -95,7 +94,7 @@
<name>obs</name>
<retentionHours>0</retentionHours>
<dirPattern>hdf5/(obs)</dirPattern>
<display>{1}</display>
<displayLabel>{1}</displayLabel>
<filePattern>metar-(\d{4})-(\d{2})-(\d{2})-(\d{2})\.*</filePattern>
<dateGroupIndices>2,3,4,5</dateGroupIndices>
</category>

View file

@ -23,26 +23,25 @@
<name> - Required tag. The id for the archive such as Raw or Processed.
Used in the GUIs to filter which archive to display.
<rootDir> - Required tag. The root directory on the edex server for the archive.
<retentionHours> - Required tag. The default number of hour to retain data in the <rootDir>
<category> - Detail information for display information in the archive GUIs and
overriding the default retention hours. There can be several of these tags.
<retentionHours> - Required tag. The default number of hours to retain data in the <rootDir>
<category> - Logical grouping of archive's sub-directories.
The <category> has six types of tags:
<name> - Required tag. The id for the category such as grib2 or redbook.
Used in the GUIs to filter what is the display in the table.
<retentionHours> - Optional tag. The retentionHours for this category.
Default is the archive's <retentionHours>.
<dirPattern> - Required tag. A pattern for finding directories for this category.
<dirPattern> - Required tag. A regex pattern for finding directories for this category.
The pattern is relative to the archive's <rootDir>. Wildcard patterns do not cross directory
delimiter /. Thus to match 3 levels of directories you would need .*/.*/.* .
See patterns and groups section.
<filePattern> - Optional tag. A pattern to find files in the directories that match the <dirPattern>.
Default is everything in the directories that match <dirPattern>.
See patterns and groups section.
<display> - Required tag. The label to display for directories that match <dirPattern>. Any group in the
<displayLabel> - Required tag. The label to display for directories that match <dirPattern>. Any group in the
<dirPattern> may be made part of the label by placing the group's index inside parenthesis, {1}.
More then one directory may match the <dirPattern>. The archive GUIs may clapse them into a single
table entry.
More then one directory may match the <dirPattern>. The archive GUIs may collapse them into a
single table entry.
<dateGroupIndicies> - Required tag. A comma separated list of 4 numbers which are the index of the groups in
<dirPattern> and/or <filePattern> that contain in order the year, mouth, day and hour information.
This is used to determine what files/directories to retain or a range of directories/files to copy
@ -52,9 +51,9 @@
The <dirPattern> and <filePattern> use Java regex expressions; similar to the ldm's pqact.conf file.
For more details see http://docs.oracle.com/javase/tutorial/essential/regex/
The groupings index start at one. The groups in the <dirPattern> can be used in the <display>. For example:
The groupings index start at one. The groups in the <dirPattern> can be used in the <displayLabel>. For example:
<dirPattern>(grib2)/(\d{4})(\d{2})(\d{2})/(\d{2})/(.*)</dirPattern>
<display>{1} - {6}</display>
<displayLabel>{1} - {6}</displayLabel>
<dateGroupIndices>2,3,4,5</dateGroupIndices>
Here the <dirPattern> contains six groups. The first group is the literal grib2 which matches only a directory named grib2
@ -68,7 +67,7 @@
Example with <filePattern>:
<dirPattern>hdf5/(redbook)</dirPattern>
<display>{1}</display>
<displayLabel>{1}</displayLabel>
<filePattern>redbook-(\d{4})-(\d{2})-(\d{2})-(\d{2})\..*</filePattern>
<dateGroupIndices>2,3,4,5</dateGroupIndices>
@ -76,7 +75,7 @@
come from the <filePattern> since there is one group in the <dirPattern> the groups in the <filePattern> start at two. This
matches file names redbook-YYYY-MM-DD-HH.<extension>. Thus the file name redbook-2013-05-28-00.hd5 would match the <filePattern>.
NOTE group {0} is a string that matches the whole <dirPattern>. If this is used in the <display> would see every directory that
NOTE group {0} is a string that matches the whole <dirPattern>. If this is used in the <displayLabel> would see every directory that
matches the pattern.
-->
<archive>
@ -87,28 +86,28 @@
<name>Model grib</name>
<retentionHours>0</retentionHours>
<dirPattern>grib/(\d{4})(\d{2})(\d{2})/(\d{2})/(.*)</dirPattern>
<display>{5}</display>
<displayLabel>{5}</displayLabel>
<dateGroupIndices>1,2,3,4</dateGroupIndices>
</category>
<category>
<name>Model grib2</name>
<retentionHours>0</retentionHours>
<dirPattern>(grib2)/(\d{4})(\d{2})(\d{2})/(\d{2})/(.*)</dirPattern>
<display>{1} - {6}</display>
<displayLabel>{1} - {6}</displayLabel>
<dateGroupIndices>2,3,4,5</dateGroupIndices>
</category>
<category>
<name>Model other</name>
<retentionHours>0</retentionHours>
<dirPattern>(acars|airmet|binlightning|bufrmos|bufrua|bufrsigwx|convsigmet|goessndg|manual|mdlsndg|poessndg|profiler|shef|text)/(\d{4})(\d{2})(\d{2})/(\d{2})</dirPattern>
<display>{1}</display>
<displayLabel>{1}</displayLabel>
<dateGroupIndices>2,3,4,5</dateGroupIndices>
</category>
<category>
<name>Satellite</name>
<retentionHours>101</retentionHours>
<dirPattern>sat/(\d{4})(\d{2})(\d{2})/(\d{2})/(.*)</dirPattern>
<display>{5}</display>
<displayLabel>{5}</displayLabel>
<dateGroupIndices>1,2,3,4</dateGroupIndices>
</category>
</archive>

View file

@ -87,7 +87,7 @@ public class ArchiveConfigManagerTest {
private ArchiveConfigManager manager;
private ArchiveConfig archive;
private Collection<File> archiveFiles = new ArrayList<File>();
private Collection<File> expiredFiles = new ArrayList<File>();
@ -97,7 +97,7 @@ public class ArchiveConfigManagerTest {
private Calendar referenceCalendar;
private Calendar archiveStart;
private Calendar archiveEnd;
private List<String> selectedForArchive;
@ -149,7 +149,8 @@ public class ArchiveConfigManagerTest {
createTestFiles(grib1Format, getRetentionHours(archive, grib1Cat),
false, archiveStart, archiveEnd);
// manager is not configured internally until this is called...
manager.getDisplayLabels(archive.getName(), grib1Cat.getName());
// TODO Brad will fix.
// manager.getDisplayLabels(archive.getName(), grib1Cat.getName());
// **** sat ****
CategoryConfig satCat = getCategory(archive, SAT_CAT_NAME);
@ -158,7 +159,8 @@ public class ArchiveConfigManagerTest {
createTestFiles(satFormat, getRetentionHours(archive, satCat), true,
archiveStart, archiveEnd);
// manager is not configured internally until this is called...
manager.getDisplayLabels(archive.getName(), satCat.getName());
// TODO Brad will fix.
// manager.getDisplayLabels(archive.getName(), satCat.getName());
// **** acars ****
CategoryConfig otherCat = getCategory(archive, "Model other");
@ -180,7 +182,8 @@ public class ArchiveConfigManagerTest {
createTestFiles(bufrsigwxFormat, otherCatRetentionHours, false,
archiveStart, archiveEnd);
// manager is not configured internally until this is called...
manager.getDisplayLabels(archive.getName(), otherCat.getName());
// TODO Brad will fix.
// manager.getDisplayLabels(archive.getName(), otherCat.getName());
// create test archive data dir
archiveDir = new File(TEST_DIR, TEST_ARCHIVE_DIR);
@ -224,12 +227,9 @@ public class ArchiveConfigManagerTest {
createDataFile(moreThanOneDayOld, dataFileNameFormat);
// create data file older than purge time
Calendar lessThanExpiredCalendar = (Calendar) referenceCalendar
.clone();
lessThanExpiredCalendar.add(Calendar.HOUR, (-1
* retentionHours - 1));
dataFile = createDataFile(lessThanExpiredCalendar,
dataFileNameFormat);
Calendar lessThanExpiredCalendar = (Calendar) referenceCalendar.clone();
lessThanExpiredCalendar.add(Calendar.HOUR, (-1 * retentionHours - 1));
dataFile = createDataFile(lessThanExpiredCalendar, dataFileNameFormat);
expiredFiles.add(dataFile);
purgeFiles.add(dataFile);
@ -250,7 +250,7 @@ public class ArchiveConfigManagerTest {
archiveStart.add(Calendar.HOUR, -20);
archiveEnd.add(Calendar.HOUR, -3);
yyyyMMFormat.setCalendar(referenceCalendar);
ddFormat.setCalendar(referenceCalendar);
hhFormat.setCalendar(referenceCalendar);