From 7bf7c508b008d22cd07f027377258ce9f793bbc7 Mon Sep 17 00:00:00 2001 From: Roger Ferrel Date: Mon, 20 May 2013 10:26:40 -0500 Subject: [PATCH] Issue #1966 Interim changes Brad needs for his work. Change-Id: If0e1c5d3eec25a42d4dcd31fe324de07d45276ac Former-commit-id: 16c7de874ae7cea591bbdc8c3111a0a67aadf8e6 [formerly 16c7de874ae7cea591bbdc8c3111a0a67aadf8e6 [formerly 57a43dfefb79d49895beace44930db630cd502be]] Former-commit-id: dfd586fca6f665876dd74c8b8d16bf648f147c2c Former-commit-id: c9e6e367fefafeb4190b0bf18011c386def4066c --- .../META-INF/MANIFEST.MF | 7 +- .../uf/viz/archive/data/FileInfo.java | 112 ++++++ .../uf/viz/archive/data/IUpdateListener.java | 46 +++ .../com.raytheon.uf.common.archive/.classpath | 1 + .../META-INF/MANIFEST.MF | 10 +- .../archive/config/ArchiveConfigManager.java | 302 ++++++++++++++++ .../common/archive/config/CategoryConfig.java | 57 +-- .../archive/manager/ArchiveDataManager.java | 324 ------------------ .../com/raytheon/uf/common/util/FileUtil.java | 56 ++- .../common_static/site/archive/RAW_DATA.xml | 3 +- 10 files changed, 529 insertions(+), 389 deletions(-) create mode 100644 cave/com.raytheon.uf.viz.archive/src/com/raytheon/uf/viz/archive/data/FileInfo.java create mode 100644 cave/com.raytheon.uf.viz.archive/src/com/raytheon/uf/viz/archive/data/IUpdateListener.java create mode 100644 edexOsgi/com.raytheon.uf.common.archive/src/com/raytheon/uf/common/archive/config/ArchiveConfigManager.java delete mode 100644 edexOsgi/com.raytheon.uf.common.archive/src/com/raytheon/uf/common/archive/manager/ArchiveDataManager.java diff --git a/cave/com.raytheon.uf.viz.archive/META-INF/MANIFEST.MF b/cave/com.raytheon.uf.viz.archive/META-INF/MANIFEST.MF index 6a5ad2d5c8..5da8bf4ad4 100644 --- a/cave/com.raytheon.uf.viz.archive/META-INF/MANIFEST.MF +++ b/cave/com.raytheon.uf.viz.archive/META-INF/MANIFEST.MF @@ -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 diff --git a/cave/com.raytheon.uf.viz.archive/src/com/raytheon/uf/viz/archive/data/FileInfo.java b/cave/com.raytheon.uf.viz.archive/src/com/raytheon/uf/viz/archive/data/FileInfo.java new file mode 100644 index 0000000000..6be0cfc1df --- /dev/null +++ b/cave/com.raytheon.uf.viz.archive/src/com/raytheon/uf/viz/archive/data/FileInfo.java @@ -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. + * + *
+ * 
+ * SOFTWARE HISTORY
+ * 
+ * Date         Ticket#    Engineer    Description
+ * ------------ ---------- ----------- --------------------------
+ * May 15, 2013 1966       rferrel     Initial creation
+ * 
+ * 
+ * + * @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 queueList = new LinkedList(); + + List listeners = new ArrayList(); + + 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; + } + } +} diff --git a/cave/com.raytheon.uf.viz.archive/src/com/raytheon/uf/viz/archive/data/IUpdateListener.java b/cave/com.raytheon.uf.viz.archive/src/com/raytheon/uf/viz/archive/data/IUpdateListener.java new file mode 100644 index 0000000000..f8c5cefff7 --- /dev/null +++ b/cave/com.raytheon.uf.viz.archive/src/com/raytheon/uf/viz/archive/data/IUpdateListener.java @@ -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. + * + *
+ * 
+ * SOFTWARE HISTORY
+ * 
+ * Date         Ticket#    Engineer    Description
+ * ------------ ---------- ----------- --------------------------
+ * May 16, 2013 1966       rferrel     Initial creation
+ * 
+ * 
+ * + * @author rferrel + * @version 1.0 + */ + +public interface IUpdateListener { + /** + * List of files/directories with updated information + * + * @param fileInfoArray + */ + public void update(FileInfo[] fileInfoArray); +} diff --git a/edexOsgi/com.raytheon.uf.common.archive/.classpath b/edexOsgi/com.raytheon.uf.common.archive/.classpath index 1dc1d15857..692796b71b 100644 --- a/edexOsgi/com.raytheon.uf.common.archive/.classpath +++ b/edexOsgi/com.raytheon.uf.common.archive/.classpath @@ -6,5 +6,6 @@ + diff --git a/edexOsgi/com.raytheon.uf.common.archive/META-INF/MANIFEST.MF b/edexOsgi/com.raytheon.uf.common.archive/META-INF/MANIFEST.MF index 5cbb2754df..37386310a6 100644 --- a/edexOsgi/com.raytheon.uf.common.archive/META-INF/MANIFEST.MF +++ b/edexOsgi/com.raytheon.uf.common.archive/META-INF/MANIFEST.MF @@ -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" diff --git a/edexOsgi/com.raytheon.uf.common.archive/src/com/raytheon/uf/common/archive/config/ArchiveConfigManager.java b/edexOsgi/com.raytheon.uf.common.archive/src/com/raytheon/uf/common/archive/config/ArchiveConfigManager.java new file mode 100644 index 0000000000..384e698f91 --- /dev/null +++ b/edexOsgi/com.raytheon.uf.common.archive/src/com/raytheon/uf/common/archive/config/ArchiveConfigManager.java @@ -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. + * + *
+ * 
+ * SOFTWARE HISTORY
+ * 
+ * Date         Ticket#    Engineer    Description
+ * ------------ ---------- ----------- --------------------------
+ * May 1, 2013  1966       rferrel     Initial creation
+ * 
+ * 
+ * + * @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 archiveMap = new HashMap(); + + 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 confFileMap = new HashMap(); + 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 categories = archiveConfig.getCategoryList(); + List nameList = new ArrayList(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 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 dirList = findDirs(rootFile); + + Pattern pattern = Pattern.compile(category.getDirPattern()); + TreeSet displays = new TreeSet( + 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 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; + } + } +} diff --git a/edexOsgi/com.raytheon.uf.common.archive/src/com/raytheon/uf/common/archive/config/CategoryConfig.java b/edexOsgi/com.raytheon.uf.common.archive/src/com/raytheon/uf/common/archive/config/CategoryConfig.java index 1ccfec57c8..418833d348 100644 --- a/edexOsgi/com.raytheon.uf.common.archive/src/com/raytheon/uf/common/archive/config/CategoryConfig.java +++ b/edexOsgi/com.raytheon.uf.common.archive/src/com/raytheon/uf/common/archive/config/CategoryConfig.java @@ -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 { @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 selectList = new ArrayList(); - /* * Constructor. */ @@ -265,43 +254,6 @@ public class CategoryConfig implements Comparable { this.saveFiles = saveFiles; } - /** - * Get list of selected directories. - * - * @return selectList - */ - public List getSelectList() { - return new ArrayList(selectList); - } - - /** - * Rest set the list of selected directories. - * - * @param selectDir - */ - public void setSelectList(Collection 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 { 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(); } } diff --git a/edexOsgi/com.raytheon.uf.common.archive/src/com/raytheon/uf/common/archive/manager/ArchiveDataManager.java b/edexOsgi/com.raytheon.uf.common.archive/src/com/raytheon/uf/common/archive/manager/ArchiveDataManager.java deleted file mode 100644 index f77c8d2ffe..0000000000 --- a/edexOsgi/com.raytheon.uf.common.archive/src/com/raytheon/uf/common/archive/manager/ArchiveDataManager.java +++ /dev/null @@ -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. - * - *
- * 
- * SOFTWARE HISTORY
- * 
- * Date         Ticket#    Engineer    Description
- * ------------ ---------- ----------- --------------------------
- * May 1, 2013  1966       rferrel     Initial creation
- * 
- * 
- * - * @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 archiveMap = new HashMap(); - - 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 categories = archiveData.getCategoryList(); - List nameList = new ArrayList(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 scList = new ArrayList(); - 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(); - 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); - } - } -} diff --git a/edexOsgi/com.raytheon.uf.common.util/src/com/raytheon/uf/common/util/FileUtil.java b/edexOsgi/com.raytheon.uf.common.util/src/com/raytheon/uf/common/util/FileUtil.java index 8b812e98a8..f8def3954c 100644 --- a/edexOsgi/com.raytheon.uf.common.util/src/com/raytheon/uf/common/util/FileUtil.java +++ b/edexOsgi/com.raytheon.uf.common.util/src/com/raytheon/uf/common/util/FileUtil.java @@ -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. * * * @@ -116,8 +118,8 @@ public class FileUtil { * whether or not to go into subdirectories * @return the files that match the filter */ - public static List listFiles(File directory, - FilenameFilter filter, boolean recurse) { + public static List listFiles(File directory, FilenameFilter filter, + boolean recurse) { // List of files / directories ArrayList files = new ArrayList(); @@ -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 listDirFiles(File directory, FileFilter filter, + boolean recurse) { + // List of files / directories + List files = new ArrayList(); + + // 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; + } + } diff --git a/edexOsgi/com.raytheon.uf.edex.archive/utility/common_static/site/archive/RAW_DATA.xml b/edexOsgi/com.raytheon.uf.edex.archive/utility/common_static/site/archive/RAW_DATA.xml index ed68a7f589..11538cbd80 100644 --- a/edexOsgi/com.raytheon.uf.edex.archive/utility/common_static/site/archive/RAW_DATA.xml +++ b/edexOsgi/com.raytheon.uf.edex.archive/utility/common_static/site/archive/RAW_DATA.xml @@ -10,7 +10,6 @@ \1 grib/${YYYY}${MM}${DD}/${HH}/(.*) .* - grib/${YYYY}${MM}${DD}/${HH}/NCEP_QPF/ Model grib2 @@ -29,7 +28,7 @@ .* - Satellilte + Satellite 101 sat/[^/]*/[^/]*/(.*) \1