Issue #1966 Interim changes Brad needs for his work.
Change-Id: If0e1c5d3eec25a42d4dcd31fe324de07d45276ac Former-commit-id:16c7de874a
[formerly16c7de874a
[formerly 57a43dfefb79d49895beace44930db630cd502be]] Former-commit-id:dfd586fca6
Former-commit-id:c9e6e367fe
This commit is contained in:
parent
fbdcd29129
commit
7bf7c508b0
10 changed files with 529 additions and 389 deletions
|
@ -5,10 +5,13 @@ Bundle-SymbolicName: com.raytheon.uf.viz.archive;singleton:=true
|
|||
Bundle-Version: 1.0.0.qualifier
|
||||
Bundle-Activator: com.raytheon.uf.viz.archive.Activator
|
||||
Bundle-Vendor: RAYTHEON
|
||||
Require-Bundle: org.eclipse.core.runtime,
|
||||
Require-Bundle: org.eclipse.ui;bundle-version="3.8.2",
|
||||
org.eclipse.core.runtime,
|
||||
com.raytheon.viz.ui;bundle-version="1.12.1174",
|
||||
com.raytheon.uf.common.serialization;bundle-version="1.12.1174",
|
||||
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.time;bundle-version="1.12.1174",
|
||||
com.raytheon.uf.common.util;bundle-version="1.12.1174"
|
||||
Bundle-RequiredExecutionEnvironment: JavaSE-1.6
|
||||
Bundle-ActivationPolicy: lazy
|
||||
|
|
|
@ -0,0 +1,112 @@
|
|||
/**
|
||||
* 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.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.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 FileInfo {
|
||||
private static final SizeJob sizeJob = new FileInfo.SizeJob();
|
||||
|
||||
private File file;
|
||||
|
||||
private long size = -1L;
|
||||
|
||||
public FileInfo(File file) {
|
||||
this.file = file;
|
||||
FileInfo.sizeJob.queue(this);
|
||||
}
|
||||
|
||||
public long getSize() {
|
||||
return size;
|
||||
}
|
||||
|
||||
static private class SizeJob extends Job {
|
||||
private LinkedList<FileInfo> queueList = new LinkedList<FileInfo>();
|
||||
|
||||
List<IUpdateListener> listeners = new ArrayList<IUpdateListener>();
|
||||
|
||||
protected void queue(FileInfo fileInfo) {
|
||||
synchronized (queueList) {
|
||||
queueList.add(fileInfo);
|
||||
if (getJobManager().currentJob() == null) {
|
||||
schedule();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public SizeJob() {
|
||||
super("Size Job");
|
||||
setSystem(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected IStatus run(IProgressMonitor monitor) {
|
||||
while (!queueList.isEmpty()) {
|
||||
FileInfo[] list = null;
|
||||
synchronized (queueList) {
|
||||
list = queueList.toArray(new FileInfo[0]);
|
||||
queueList.clear();
|
||||
}
|
||||
|
||||
for (FileInfo fileInfo : list) {
|
||||
File file = fileInfo.file;
|
||||
if (file.isDirectory()) {
|
||||
fileInfo.size = FileUtil.sizeOfDirectory(file);
|
||||
} else {
|
||||
fileInfo.size = file.length();
|
||||
}
|
||||
}
|
||||
|
||||
for (IUpdateListener listener : listeners) {
|
||||
listener.update(list);
|
||||
}
|
||||
}
|
||||
|
||||
return Status.OK_STATUS;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -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;
|
||||
|
||||
/**
|
||||
* A listener to update file/directory information.
|
||||
*
|
||||
* <pre>
|
||||
*
|
||||
* SOFTWARE HISTORY
|
||||
*
|
||||
* Date Ticket# Engineer Description
|
||||
* ------------ ---------- ----------- --------------------------
|
||||
* May 16, 2013 1966 rferrel Initial creation
|
||||
*
|
||||
* </pre>
|
||||
*
|
||||
* @author rferrel
|
||||
* @version 1.0
|
||||
*/
|
||||
|
||||
public interface IUpdateListener {
|
||||
/**
|
||||
* List of files/directories with updated information
|
||||
*
|
||||
* @param fileInfoArray
|
||||
*/
|
||||
public void update(FileInfo[] fileInfoArray);
|
||||
}
|
|
@ -6,5 +6,6 @@
|
|||
<classpathentry combineaccessrules="false" kind="src" path="/com.raytheon.uf.common.status"/>
|
||||
<classpathentry combineaccessrules="false" kind="src" path="/org.junit"/>
|
||||
<classpathentry combineaccessrules="false" kind="src" path="/com.raytheon.uf.viz.core"/>
|
||||
<classpathentry combineaccessrules="false" kind="src" path="/com.raytheon.uf.common.util"/>
|
||||
<classpathentry kind="output" path="bin"/>
|
||||
</classpath>
|
||||
|
|
|
@ -5,6 +5,10 @@ Bundle-SymbolicName: com.raytheon.uf.common.archive
|
|||
Bundle-Version: 1.0.0.qualifier
|
||||
Bundle-Vendor: RAYTHEON
|
||||
Bundle-RequiredExecutionEnvironment: JavaSE-1.6
|
||||
Export-Package: com.raytheon.uf.common.archive
|
||||
Require-Bundle: com.raytheon.uf.common.localization;bundle-version="1.12.1174",
|
||||
com.raytheon.uf.viz.core;bundle-version="1.12.1174"
|
||||
Export-Package: com.raytheon.uf.common.archive,
|
||||
com.raytheon.uf.common.archive.config,
|
||||
com.raytheon.uf.common.archive.exception,
|
||||
com.raytheon.uf.common.archive.file
|
||||
Require-Bundle: com.raytheon.uf.common.util;bundle-version="1.12.1174",
|
||||
com.raytheon.uf.common.localization;bundle-version="1.12.1174",
|
||||
com.raytheon.uf.common.status;bundle-version="1.12.1174"
|
||||
|
|
|
@ -0,0 +1,302 @@
|
|||
/**
|
||||
* This software was developed and / or modified by Raytheon Company,
|
||||
* pursuant to Contract DG133W-05-CQ-1067 with the US Government.
|
||||
*
|
||||
* U.S. EXPORT CONTROLLED TECHNICAL DATA
|
||||
* This software product contains export-restricted data whose
|
||||
* export/transfer/disclosure is restricted by U.S. law. Dissemination
|
||||
* to non-U.S. persons whether in the United States or abroad requires
|
||||
* an export license or other authorization.
|
||||
*
|
||||
* Contractor Name: Raytheon Company
|
||||
* Contractor Address: 6825 Pine Street, Suite 340
|
||||
* Mail Stop B8
|
||||
* Omaha, NE 68106
|
||||
* 402.291.0100
|
||||
*
|
||||
* See the AWIPS II Master Rights File ("Master Rights File.pdf") for
|
||||
* further licensing information.
|
||||
**/
|
||||
package com.raytheon.uf.common.archive.config;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileFilter;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Calendar;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.TreeSet;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import javax.xml.bind.JAXB;
|
||||
|
||||
import com.raytheon.uf.common.localization.IPathManager;
|
||||
import com.raytheon.uf.common.localization.LocalizationContext;
|
||||
import com.raytheon.uf.common.localization.LocalizationContext.LocalizationLevel;
|
||||
import com.raytheon.uf.common.localization.LocalizationContext.LocalizationType;
|
||||
import com.raytheon.uf.common.localization.LocalizationFile;
|
||||
import com.raytheon.uf.common.localization.PathManagerFactory;
|
||||
import com.raytheon.uf.common.localization.exception.LocalizationException;
|
||||
import com.raytheon.uf.common.status.IUFStatusHandler;
|
||||
import com.raytheon.uf.common.status.UFStatus;
|
||||
import com.raytheon.uf.common.util.FileUtil;
|
||||
|
||||
/**
|
||||
* Manager for access to archive data information.
|
||||
*
|
||||
* <pre>
|
||||
*
|
||||
* SOFTWARE HISTORY
|
||||
*
|
||||
* Date Ticket# Engineer Description
|
||||
* ------------ ---------- ----------- --------------------------
|
||||
* May 1, 2013 1966 rferrel Initial creation
|
||||
*
|
||||
* </pre>
|
||||
*
|
||||
* @author rferrel
|
||||
* @version 1.0
|
||||
*/
|
||||
public class ArchiveConfigManager {
|
||||
private final static ArchiveConfigManager instance = new ArchiveConfigManager();
|
||||
|
||||
private final IUFStatusHandler statusHandler = UFStatus
|
||||
.getHandler(ArchiveConfigManager.class);
|
||||
|
||||
public final String ARCHIVE_DIR = "archive";
|
||||
|
||||
private IPathManager pathMgr;
|
||||
|
||||
private final Map<String, ArchiveConfig> archiveMap = new HashMap<String, ArchiveConfig>();
|
||||
|
||||
private DirectoryFilter directoryFilter = new DirectoryFilter();
|
||||
|
||||
private Pattern subPatterns[] = new Pattern[] { Pattern.compile("\\1"),
|
||||
Pattern.compile("\\2"), Pattern.compile("\\3"),
|
||||
Pattern.compile("\\4"), Pattern.compile("\\5"),
|
||||
Pattern.compile("\\6"), Pattern.compile("\\7"),
|
||||
Pattern.compile("\\8"), Pattern.compile("\\9"), };
|
||||
|
||||
private Pattern yearPattern = Pattern.compile("$\\{YYYY}");
|
||||
|
||||
private Pattern monthPattern = Pattern.compile("$\\{MM}");
|
||||
|
||||
private Pattern dayPattern = Pattern.compile("$\\{DD}");
|
||||
|
||||
private Pattern hourPattern = Pattern.compile("$\\{HH}");
|
||||
|
||||
public final static ArchiveConfigManager getInstance() {
|
||||
return instance;
|
||||
}
|
||||
|
||||
private ArchiveConfigManager() {
|
||||
pathMgr = PathManagerFactory.getPathManager();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get list of site's archive data configuration files.
|
||||
*
|
||||
* @return archiveConfigList
|
||||
*/
|
||||
private LocalizationFile[] getArchiveConfigFiles() {
|
||||
|
||||
Map<String, LocalizationFile> confFileMap = new HashMap<String, LocalizationFile>();
|
||||
LocalizationContext ctx = pathMgr.getContext(
|
||||
LocalizationType.COMMON_STATIC, LocalizationLevel.BASE);
|
||||
|
||||
LocalizationFile[] files = pathMgr.listFiles(ctx, ARCHIVE_DIR,
|
||||
new String[] { ".xml" }, false, true);
|
||||
|
||||
for (LocalizationFile lf : files) {
|
||||
confFileMap.put(lf.getName().trim(), lf);
|
||||
}
|
||||
|
||||
ctx = pathMgr.getContext(LocalizationType.COMMON_STATIC,
|
||||
LocalizationLevel.SITE);
|
||||
|
||||
files = pathMgr.listFiles(ctx, ARCHIVE_DIR, new String[] { ".xml" },
|
||||
false, true);
|
||||
for (LocalizationFile lf : files) {
|
||||
confFileMap.put(lf.getName().trim(), lf);
|
||||
}
|
||||
|
||||
files = new LocalizationFile[confFileMap.size()];
|
||||
int i = 0;
|
||||
for (String key : confFileMap.keySet()) {
|
||||
files[i] = confFileMap.get(key);
|
||||
++i;
|
||||
}
|
||||
return files;
|
||||
}
|
||||
|
||||
public String[] getArchiveDataNamesList() throws IOException,
|
||||
LocalizationException {
|
||||
if (archiveMap.size() == 0) {
|
||||
LocalizationFile[] files = getArchiveConfigFiles();
|
||||
for (LocalizationFile lFile : files) {
|
||||
ArchiveConfig archiveConfig = unmarshalArhiveConfigFromXmlFile(lFile);
|
||||
archiveMap.put(archiveConfig.getName(), archiveConfig);
|
||||
}
|
||||
}
|
||||
String[] names = archiveMap.keySet().toArray(new String[0]);
|
||||
Arrays.sort(names, 0, names.length, String.CASE_INSENSITIVE_ORDER);
|
||||
|
||||
return names;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param archiveConfig
|
||||
* @return
|
||||
*/
|
||||
public String[] getCategoryNames(ArchiveConfig archiveConfig) {
|
||||
List<CategoryConfig> categories = archiveConfig.getCategoryList();
|
||||
List<String> nameList = new ArrayList<String>(categories.size());
|
||||
for (CategoryConfig category : archiveConfig.getCategoryList()) {
|
||||
String name = category.getName();
|
||||
nameList.add(name);
|
||||
}
|
||||
String[] names = nameList.toArray(new String[0]);
|
||||
Arrays.sort(names, 0, names.length, String.CASE_INSENSITIVE_ORDER);
|
||||
return names;
|
||||
}
|
||||
|
||||
public ArchiveConfig loadArchiveData(LocalizationFile lFile)
|
||||
throws IOException, LocalizationException {
|
||||
return unmarshalArhiveConfigFromXmlFile(lFile);
|
||||
}
|
||||
|
||||
public void saveArchiveConfig(LocalizationFile lFile,
|
||||
ArchiveConfig archiveConfig) throws IOException,
|
||||
LocalizationException {
|
||||
marshalArchiveConfigToXmlFile(archiveConfig, lFile);
|
||||
}
|
||||
|
||||
private void marshalArchiveConfigToXmlFile(ArchiveConfig archiveConfig,
|
||||
LocalizationFile lFile) throws IOException, LocalizationException {
|
||||
OutputStream stream = null;
|
||||
try {
|
||||
stream = lFile.openOutputStream();
|
||||
JAXB.marshal(archiveConfig, stream);
|
||||
} finally {
|
||||
if (stream != null) {
|
||||
try {
|
||||
stream.close();
|
||||
} catch (IOException ex) {
|
||||
// ignore
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public File[] getDisplayFiles(String archiveName, String categoryName,
|
||||
List<String> dispalyList, Calendar startTime, Calendar endTime) {
|
||||
// TODO implement
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 sorted array of display labels
|
||||
*/
|
||||
public String[] getDisplayLabels(String archiveName, String categoryName) {
|
||||
ArchiveConfig archiveConfig = archiveMap.get(archiveName);
|
||||
CategoryConfig category = findCategory(archiveConfig, categoryName);
|
||||
|
||||
File rootFile = new File(archiveConfig.getRootDir());
|
||||
|
||||
List<File> dirList = findDirs(rootFile);
|
||||
|
||||
Pattern pattern = Pattern.compile(category.getDirPattern());
|
||||
TreeSet<String> displays = new TreeSet<String>(
|
||||
String.CASE_INSENSITIVE_ORDER);
|
||||
|
||||
StringBuffer sb = new StringBuffer();
|
||||
for (File dir : dirList) {
|
||||
Matcher matcher = pattern.matcher(dir.getAbsolutePath());
|
||||
if (matcher.matches()) {
|
||||
String display = category.getDisplay();
|
||||
int groupCnt = matcher.groupCount();
|
||||
|
||||
for (int i = 0; i < groupCnt; ++i) {
|
||||
Matcher subMatcher = subPatterns[i].matcher(display);
|
||||
sb.setLength(0);
|
||||
while (subMatcher.find()) {
|
||||
subMatcher.appendReplacement(sb, matcher.group(i));
|
||||
}
|
||||
subMatcher.appendTail(sb);
|
||||
display = sb.toString();
|
||||
}
|
||||
displays.add(display);
|
||||
}
|
||||
}
|
||||
|
||||
return displays.toArray(new String[0]);
|
||||
}
|
||||
|
||||
private List<File> findDirs(File parentDir) {
|
||||
return FileUtil.listDirFiles(parentDir, directoryFilter, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Obtain the category with the given name.
|
||||
*
|
||||
* @param archiveConfig
|
||||
* @param categoryName
|
||||
* @return
|
||||
*/
|
||||
private CategoryConfig findCategory(ArchiveConfig archiveConfig,
|
||||
String categoryName) {
|
||||
for (CategoryConfig category : archiveConfig.getCategoryList()) {
|
||||
if (category.getName().equals(categoryName)) {
|
||||
return category;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private ArchiveConfig unmarshalArhiveConfigFromXmlFile(
|
||||
LocalizationFile lFile) throws IOException, LocalizationException {
|
||||
ArchiveConfig archiveConfig = null;
|
||||
InputStream stream = null;
|
||||
try {
|
||||
stream = lFile.openInputStream();
|
||||
archiveConfig = JAXB.unmarshal(stream, ArchiveConfig.class);
|
||||
} finally {
|
||||
if (stream != null) {
|
||||
try {
|
||||
stream.close();
|
||||
} catch (IOException ex) {
|
||||
// ignore
|
||||
}
|
||||
}
|
||||
}
|
||||
return archiveConfig;
|
||||
}
|
||||
|
||||
private class DirectoryFilter implements FileFilter {
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see java.io.FileFilter#accept(java.io.File)
|
||||
*/
|
||||
@Override
|
||||
public boolean accept(File pathname) {
|
||||
if (pathname.isDirectory() && !pathname.getName().startsWith(".")) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -19,10 +19,6 @@
|
|||
**/
|
||||
package com.raytheon.uf.common.archive.config;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
import javax.xml.bind.annotation.XmlAccessType;
|
||||
import javax.xml.bind.annotation.XmlAccessorType;
|
||||
import javax.xml.bind.annotation.XmlElement;
|
||||
|
@ -142,13 +138,6 @@ public class CategoryConfig implements Comparable<CategoryConfig> {
|
|||
@XmlElement(name = "saveFiles")
|
||||
private String saveFiles;
|
||||
|
||||
/**
|
||||
* This is list of selected directories. To be used to specify which
|
||||
* processed directories to move to /awips2/edex/data/archive.
|
||||
*/
|
||||
@XmlElement(name = "selectList")
|
||||
private final List<String> selectList = new ArrayList<String>();
|
||||
|
||||
/*
|
||||
* Constructor.
|
||||
*/
|
||||
|
@ -265,43 +254,6 @@ public class CategoryConfig implements Comparable<CategoryConfig> {
|
|||
this.saveFiles = saveFiles;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get list of selected directories.
|
||||
*
|
||||
* @return selectList
|
||||
*/
|
||||
public List<String> getSelectList() {
|
||||
return new ArrayList<String>(selectList);
|
||||
}
|
||||
|
||||
/**
|
||||
* Rest set the list of selected directories.
|
||||
*
|
||||
* @param selectDir
|
||||
*/
|
||||
public void setSelectList(Collection<String> selectDir) {
|
||||
this.selectList.clear();
|
||||
this.selectList.addAll(selectDir);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add an entry to the select list.
|
||||
*
|
||||
* @param select
|
||||
*/
|
||||
public void addSelectList(String select) {
|
||||
selectList.add(select);
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove an entry from the select list.
|
||||
*
|
||||
* @param select
|
||||
*/
|
||||
public void removeSelectList(String select) {
|
||||
selectList.remove(select);
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
|
@ -326,14 +278,7 @@ public class CategoryConfig implements Comparable<CategoryConfig> {
|
|||
sb.append(", display: ").append(getDisplay());
|
||||
sb.append(", saveDir: ").append(getSaveDir());
|
||||
sb.append(", saveFiles: ").append(getSaveFiles());
|
||||
sb.append(", selectList: [");
|
||||
String prefix = "\"";
|
||||
for (String sel : selectList) {
|
||||
sb.append(prefix).append(sel).append("\"");
|
||||
prefix = ", \"";
|
||||
}
|
||||
|
||||
sb.append("]]");
|
||||
sb.append("]");
|
||||
return sb.toString();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,324 +0,0 @@
|
|||
/**
|
||||
* This software was developed and / or modified by Raytheon Company,
|
||||
* pursuant to Contract DG133W-05-CQ-1067 with the US Government.
|
||||
*
|
||||
* U.S. EXPORT CONTROLLED TECHNICAL DATA
|
||||
* This software product contains export-restricted data whose
|
||||
* export/transfer/disclosure is restricted by U.S. law. Dissemination
|
||||
* to non-U.S. persons whether in the United States or abroad requires
|
||||
* an export license or other authorization.
|
||||
*
|
||||
* Contractor Name: Raytheon Company
|
||||
* Contractor Address: 6825 Pine Street, Suite 340
|
||||
* Mail Stop B8
|
||||
* Omaha, NE 68106
|
||||
* 402.291.0100
|
||||
*
|
||||
* See the AWIPS II Master Rights File ("Master Rights File.pdf") for
|
||||
* further licensing information.
|
||||
**/
|
||||
package com.raytheon.uf.common.archive.manager;
|
||||
|
||||
import java.io.BufferedInputStream;
|
||||
import java.io.BufferedOutputStream;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.xml.bind.JAXB;
|
||||
|
||||
import com.raytheon.uf.common.archive.config.ArchiveConfig;
|
||||
import com.raytheon.uf.common.archive.config.CategoryConfig;
|
||||
import com.raytheon.uf.common.localization.IPathManager;
|
||||
import com.raytheon.uf.common.localization.LocalizationContext;
|
||||
import com.raytheon.uf.common.localization.LocalizationContext.LocalizationLevel;
|
||||
import com.raytheon.uf.common.localization.LocalizationContext.LocalizationType;
|
||||
import com.raytheon.uf.common.localization.LocalizationFile;
|
||||
import com.raytheon.uf.common.localization.PathManagerFactory;
|
||||
import com.raytheon.uf.common.localization.exception.LocalizationException;
|
||||
import com.raytheon.uf.common.status.IUFStatusHandler;
|
||||
import com.raytheon.uf.common.status.UFStatus;
|
||||
import com.raytheon.uf.common.status.UFStatus.Priority;
|
||||
import com.raytheon.uf.viz.core.localization.LocalizationManager;
|
||||
|
||||
/**
|
||||
* Manager for access to archive data information.
|
||||
*
|
||||
* <pre>
|
||||
*
|
||||
* SOFTWARE HISTORY
|
||||
*
|
||||
* Date Ticket# Engineer Description
|
||||
* ------------ ---------- ----------- --------------------------
|
||||
* May 1, 2013 1966 rferrel Initial creation
|
||||
*
|
||||
* </pre>
|
||||
*
|
||||
* @author rferrel
|
||||
* @version 1.0
|
||||
*/
|
||||
|
||||
public class ArchiveDataManager {
|
||||
private final static ArchiveDataManager instance = new ArchiveDataManager();
|
||||
|
||||
private final IUFStatusHandler statusHandler = UFStatus
|
||||
.getHandler(ArchiveDataManager.class);
|
||||
|
||||
private final String ARCHIVE_DIR = "archive";
|
||||
|
||||
private String site;
|
||||
|
||||
private IPathManager pathMgr;
|
||||
|
||||
private LocalizationContext siteCtx;
|
||||
|
||||
private LocalizationFile archiveDir;
|
||||
|
||||
private final Map<String, ArchiveConfig> archiveMap = new HashMap<String, ArchiveConfig>();
|
||||
|
||||
public final static ArchiveDataManager getInstance() {
|
||||
return instance;
|
||||
}
|
||||
|
||||
private ArchiveDataManager() {
|
||||
site = LocalizationManager.getInstance().getCurrentSite();
|
||||
pathMgr = PathManagerFactory.getPathManager();
|
||||
|
||||
siteCtx = pathMgr.getContext(LocalizationType.COMMON_STATIC,
|
||||
LocalizationLevel.SITE);
|
||||
|
||||
archiveDir = pathMgr.getLocalizationFile(siteCtx, ARCHIVE_DIR);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get list of site's archive data configuration files.
|
||||
*
|
||||
* @return archiveDataList
|
||||
*/
|
||||
private LocalizationFile[] getArchiveDataFiles() {
|
||||
String path = archiveDir.getName().trim();
|
||||
LocalizationFile[] files = pathMgr.listFiles(siteCtx, path,
|
||||
new String[] { "*.xml" }, false, true);
|
||||
return files;
|
||||
}
|
||||
|
||||
public String[] getArchiveDataNamesList() throws IOException,
|
||||
LocalizationException {
|
||||
if (archiveMap.size() == 0) {
|
||||
LocalizationFile[] files = getArchiveDataFiles();
|
||||
for (LocalizationFile lFile : files) {
|
||||
ArchiveConfig archiveData = unmarshalArhiveDataFromXmlFile(lFile);
|
||||
archiveMap.put(archiveData.getName(), archiveData);
|
||||
}
|
||||
}
|
||||
String[] names = archiveMap.keySet().toArray(new String[0]);
|
||||
Arrays.sort(names, 0, names.length, String.CASE_INSENSITIVE_ORDER);
|
||||
|
||||
return names;
|
||||
}
|
||||
|
||||
public String[] getCategoryNames(ArchiveConfig archiveData) {
|
||||
List<CategoryConfig> categories = archiveData.getCategoryList();
|
||||
List<String> nameList = new ArrayList<String>(categories.size());
|
||||
for (CategoryConfig category : archiveData.getCategoryList()) {
|
||||
String name = category.getName();
|
||||
nameList.add(name);
|
||||
}
|
||||
String[] names = nameList.toArray(new String[0]);
|
||||
Arrays.sort(names, 0, names.length, String.CASE_INSENSITIVE_ORDER);
|
||||
return names;
|
||||
}
|
||||
|
||||
public ArchiveConfig loadArchiveData(LocalizationFile lFile)
|
||||
throws IOException, LocalizationException {
|
||||
return unmarshalArhiveDataFromXmlFile(lFile);
|
||||
}
|
||||
|
||||
public void saveArchiveData(LocalizationFile lFile, ArchiveConfig archiveData)
|
||||
throws IOException, LocalizationException {
|
||||
marshalArchiveDataToXmlFile(archiveData, lFile);
|
||||
}
|
||||
|
||||
private void marshalArchiveDataToXmlFile(ArchiveConfig archiveData,
|
||||
LocalizationFile lFile) throws IOException, LocalizationException {
|
||||
OutputStream stream = null;
|
||||
try {
|
||||
stream = lFile.openOutputStream();
|
||||
JAXB.marshal(archiveData, stream);
|
||||
} finally {
|
||||
if (stream != null) {
|
||||
try {
|
||||
stream.close();
|
||||
} catch (IOException ex) {
|
||||
// ignore
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private ArchiveConfig unmarshalArhiveDataFromXmlFile(LocalizationFile lFile)
|
||||
throws IOException, LocalizationException {
|
||||
ArchiveConfig archiveData = null;
|
||||
InputStream stream = null;
|
||||
try {
|
||||
stream = lFile.openInputStream();
|
||||
archiveData = JAXB.unmarshal(stream, ArchiveConfig.class);
|
||||
} finally {
|
||||
if (stream != null) {
|
||||
try {
|
||||
stream.close();
|
||||
} catch (IOException ex) {
|
||||
// ignore
|
||||
}
|
||||
}
|
||||
}
|
||||
return archiveData;
|
||||
}
|
||||
|
||||
// TODO for testing to be removed
|
||||
private void marshalArchiveDataToXmlFile(ArchiveConfig category, File file)
|
||||
throws IOException, LocalizationException {
|
||||
// TODO use lFile
|
||||
OutputStream stream = null;
|
||||
try {
|
||||
stream = new BufferedOutputStream(new FileOutputStream(file));
|
||||
JAXB.marshal(category, stream);
|
||||
} finally {
|
||||
if (stream != null) {
|
||||
try {
|
||||
stream.close();
|
||||
} catch (IOException ex) {
|
||||
// ignore
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// TODO for testing to be removed
|
||||
private ArchiveConfig unmarshalArhiveDataFromXmlFile(File file)
|
||||
throws IOException, LocalizationException {
|
||||
ArchiveConfig archiveData = null;
|
||||
InputStream stream = null;
|
||||
try {
|
||||
// stream = new BufferedInputStream(new FileInputStream(new File(
|
||||
// "/home/rferrel/Desktop/RAW_DATA.xml")));
|
||||
stream = new BufferedInputStream(new FileInputStream(file));
|
||||
archiveData = JAXB.unmarshal(stream, ArchiveConfig.class);
|
||||
} finally {
|
||||
if (stream != null) {
|
||||
try {
|
||||
stream.close();
|
||||
} catch (IOException ex) {
|
||||
// ignore
|
||||
}
|
||||
}
|
||||
}
|
||||
return archiveData;
|
||||
}
|
||||
|
||||
// TODO remove main
|
||||
public static void main(String[] args) {
|
||||
ArchiveConfig rawArchiveData = new ArchiveConfig();
|
||||
rawArchiveData.setName("Raw");
|
||||
rawArchiveData.setRootDir("/data_store/");
|
||||
rawArchiveData.setRetentionHours(7 * 24);
|
||||
List<CategoryConfig> scList = new ArrayList<CategoryConfig>();
|
||||
CategoryConfig category = new CategoryConfig();
|
||||
category.setName("Model grib");
|
||||
category.setDirPattern("grib/[^/]*/[^/]*/(.*\\)");
|
||||
category.setDisplay("\\1");
|
||||
category.setSaveDir("grib/${YYYY}${MM}${DD}/${HH}/(.*)");
|
||||
category.setSaveFiles(".*");
|
||||
category.addSelectList("grib/${YYYY}${MM}${DD}/${HH}/NCEP_QPF/");
|
||||
scList.add(category);
|
||||
|
||||
category = new CategoryConfig();
|
||||
category.setName("Model grib2");
|
||||
category.setDirPattern("grib2/[^/]*/[^/]*/(.*\\)");
|
||||
category.setDisplay("\\1");
|
||||
category.setSaveDir("grib2/${YYYY}${MM}${DD}/${HH}/.*");
|
||||
category.setSaveFiles(".*");
|
||||
scList.add(category);
|
||||
|
||||
category = new CategoryConfig();
|
||||
category.setName("Model other");
|
||||
category.setDirPattern("(acars|airmet|binlighting|bufrmos|bufrua|bufsigwx|convsigmet|goessndg|manual|mdlsndg|poessndg|profiler|shef|text)/[^/]*/[^/]*/(.*)");
|
||||
category.setDisplay("\\1 - \\2");
|
||||
category.setSaveDir("(acars|airmet|binlighting|bufrmos|bufrua|bufsigwx|convsigmet|goessndg|manual|mdlsndg|poessndg|profiler|shef|text)/YYYYMMDD/HH/.*");
|
||||
category.setSaveFiles(".*");
|
||||
scList.add(category);
|
||||
|
||||
category = new CategoryConfig();
|
||||
category.setName("Observations");
|
||||
category.setDirPattern("(aircraft|metar|sfcobs)/[^/]*/[^/]*/(.*)");
|
||||
category.setDisplay("\\1 - \\2");
|
||||
category.setSaveDir("(aircraft|metar|sfcobs)/${YYYY}${MM}${DD}/${HH}/");
|
||||
category.setSaveFiles(".*");
|
||||
category.addSelectList("metar/)${YYYY}${MM}${DD}/${HH}/");
|
||||
|
||||
category = new CategoryConfig();
|
||||
category.setName("Satellilte");
|
||||
category.setRetentionHours(4 * 24 + 5);
|
||||
category.setDirPattern("sat/[^/]*/[^/]*/(.*)");
|
||||
category.setDisplay("\\1");
|
||||
category.setSaveDir("sat/${YYYY}${MM}${DD}/${HH}/.*");
|
||||
category.setSaveFiles(".*");
|
||||
scList.add(category);
|
||||
|
||||
rawArchiveData.setCategoryList(scList);
|
||||
|
||||
ArchiveConfig procArchiveData = new ArchiveConfig();
|
||||
procArchiveData.setName("Processed");
|
||||
procArchiveData.setRootDir("/awips2/edex/data/archive/");
|
||||
procArchiveData.setRetentionHours(7 * 24);
|
||||
scList = new ArrayList<CategoryConfig>();
|
||||
category = new CategoryConfig();
|
||||
category.setName("redbook");
|
||||
category.setDirPattern("hdf5/redbook/([^/]*)/");
|
||||
category.setDisplay("redbook - \\1");
|
||||
category.setSaveDir("hdf5/redbook/([^/]*)/");
|
||||
category.setSaveFiles("redbook-${YYYY}-${MM}-${DD}-${HH}\\..*");
|
||||
scList.add(category);
|
||||
|
||||
category = new CategoryConfig();
|
||||
category.setName("obs");
|
||||
category.setDirPattern("hdf5/(obs)/");
|
||||
category.setSaveDir("hdf5/(obs)/");
|
||||
category.setDisplay("\\1");
|
||||
category.setSaveFiles("metar-${YYYY}-${MM}-${DD}-${HH}\\.*");
|
||||
scList.add(category);
|
||||
procArchiveData.setCategoryList(scList);
|
||||
|
||||
try {
|
||||
System.out.println("marshal raw archiveData: "
|
||||
+ rawArchiveData.toString());
|
||||
File rawFile = new File("/home/rferrel/Desktop/RAW_DATA.xml");
|
||||
instance.marshalArchiveDataToXmlFile(rawArchiveData, rawFile);
|
||||
ArchiveConfig umCategory = instance
|
||||
.unmarshalArhiveDataFromXmlFile(rawFile);
|
||||
System.out.println("unmarshal raw archiveData: "
|
||||
+ umCategory.toString());
|
||||
System.out.println("marshal processed archiveData: "
|
||||
+ rawArchiveData.toString());
|
||||
File procFile = new File("/home/rferrel/Desktop/PROCESSED_DATA.xml");
|
||||
instance.marshalArchiveDataToXmlFile(procArchiveData, procFile);
|
||||
umCategory = instance.unmarshalArhiveDataFromXmlFile(procFile);
|
||||
System.out.println("unmarshal processed archiveData: "
|
||||
+ umCategory.toString());
|
||||
} catch (IOException e) {
|
||||
instance.statusHandler.handle(Priority.PROBLEM,
|
||||
e.getLocalizedMessage(), e);
|
||||
} catch (LocalizationException e) {
|
||||
instance.statusHandler.handle(Priority.PROBLEM,
|
||||
e.getLocalizedMessage(), e);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -23,6 +23,7 @@ package com.raytheon.uf.common.util;
|
|||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.Closeable;
|
||||
import java.io.File;
|
||||
import java.io.FileFilter;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.FilenameFilter;
|
||||
|
@ -57,6 +58,7 @@ import java.util.zip.GZIPOutputStream;
|
|||
* Feb 15, 2013 1638 mschenke Moved EOL field from edex.common Util
|
||||
* Mar 11, 2013 1645 djohnson Added file modification watcher.
|
||||
* Mar 14, 2013 1794 djohnson FileUtil.listFiles now returns List.
|
||||
* May 16, 2013 1966 rferrel Add sizeOfDirectory and listDirFiles method.
|
||||
*
|
||||
* </pre>
|
||||
*
|
||||
|
@ -116,8 +118,8 @@ public class FileUtil {
|
|||
* whether or not to go into subdirectories
|
||||
* @return the files that match the filter
|
||||
*/
|
||||
public static List<File> listFiles(File directory,
|
||||
FilenameFilter filter, boolean recurse) {
|
||||
public static List<File> listFiles(File directory, FilenameFilter filter,
|
||||
boolean recurse) {
|
||||
// List of files / directories
|
||||
ArrayList<File> files = new ArrayList<File>();
|
||||
|
||||
|
@ -146,6 +148,37 @@ public class FileUtil {
|
|||
return files;
|
||||
}
|
||||
|
||||
/**
|
||||
* List files/directories that match a FileFilter.
|
||||
*
|
||||
* @param directory
|
||||
* @param filter
|
||||
* @param recurse
|
||||
* @return
|
||||
*/
|
||||
public static List<File> listDirFiles(File directory, FileFilter filter,
|
||||
boolean recurse) {
|
||||
// List of files / directories
|
||||
List<File> files = new ArrayList<File>();
|
||||
|
||||
// Get files / directories in the directory accepted by the filter.
|
||||
File[] entries = directory.listFiles(filter);
|
||||
|
||||
if (entries == null) {
|
||||
entries = new File[0];
|
||||
}
|
||||
|
||||
// Go over entries
|
||||
for (File entry : entries) {
|
||||
files.add(entry);
|
||||
if (recurse && filter != null && entry.isDirectory()) {
|
||||
files.addAll(listDirFiles(entry, filter, recurse));
|
||||
}
|
||||
}
|
||||
|
||||
return files;
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete a directory. Also deletes any sub-directories. This method fails
|
||||
* early if any problem is detected. That is, if a directory containing 10
|
||||
|
@ -873,4 +906,23 @@ public class FileUtil {
|
|||
public static IFileModifiedWatcher getFileModifiedWatcher(File file) {
|
||||
return new FileLastModifiedTimeWatcher(file);
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine the size of the contents of a directory.
|
||||
*
|
||||
* @param directory
|
||||
* @return size
|
||||
*/
|
||||
public static long sizeOfDirectory(File directory) {
|
||||
long size = 0;
|
||||
for (File file : directory.listFiles()) {
|
||||
if (file.isDirectory()) {
|
||||
size += sizeOfDirectory(file);
|
||||
} else {
|
||||
size += file.length();
|
||||
}
|
||||
}
|
||||
return size;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -10,7 +10,6 @@
|
|||
<display>\1</display>
|
||||
<saveDir>grib/${YYYY}${MM}${DD}/${HH}/(.*)</saveDir>
|
||||
<saveFiles>.*</saveFiles>
|
||||
<selectList>grib/${YYYY}${MM}${DD}/${HH}/NCEP_QPF/</selectList>
|
||||
</category>
|
||||
<category>
|
||||
<name>Model grib2</name>
|
||||
|
@ -29,7 +28,7 @@
|
|||
<saveFiles>.*</saveFiles>
|
||||
</category>
|
||||
<category>
|
||||
<name>Satellilte</name>
|
||||
<name>Satellite</name>
|
||||
<retentionHours>101</retentionHours>
|
||||
<dirPattern>sat/[^/]*/[^/]*/(.*)</dirPattern>
|
||||
<display>\1</display>
|
||||
|
|
Loading…
Add table
Reference in a new issue