From 2c1d1cb95338696af0f47ed713a0b4a1ec110a4f Mon Sep 17 00:00:00 2001 From: Roger Ferrel Date: Thu, 17 Apr 2014 16:38:57 -0500 Subject: [PATCH] Issue #3045 Code cleanup for CategoryConfig and ArchiveConfig, (cherry picked from commit 1f6c21885dec492442049f3c8045515422aaaedc [formerly aa99ca1708590f17f498651e86fe0ef8ea61e1e0]) Former-commit-id: 4a8a9e7f1af764ec4ee97cd24fd127a755f6b578 --- .../common/archive/config/ArchiveConfig.java | 22 ++++-- .../common/archive/config/CategoryConfig.java | 52 +++++++++++--- .../archive/ArchiveConfigManagerTest.java | 71 ++++++++++--------- 3 files changed, 96 insertions(+), 49 deletions(-) diff --git a/edexOsgi/com.raytheon.uf.common.archive/src/com/raytheon/uf/common/archive/config/ArchiveConfig.java b/edexOsgi/com.raytheon.uf.common.archive/src/com/raytheon/uf/common/archive/config/ArchiveConfig.java index 8aec78e0e0..cb6012c197 100644 --- a/edexOsgi/com.raytheon.uf.common.archive/src/com/raytheon/uf/common/archive/config/ArchiveConfig.java +++ b/edexOsgi/com.raytheon.uf.common.archive/src/com/raytheon/uf/common/archive/config/ArchiveConfig.java @@ -57,6 +57,7 @@ import javax.xml.bind.annotation.XmlRootElement; * ------------ ---------- ----------- -------------------------- * May 1, 2013 1966 rferrel Initial creation * May 31, 2013 1965 bgonzale Added getCategory(categoryName) + * Apr 17, 2014 3045 rferrel Code cleanup to prevent null pointer. * * * @@ -91,7 +92,7 @@ public class ArchiveConfig implements Comparable { * for the archiver. */ @XmlElement(name = "category") - List categoryList; + List categoryList = new ArrayList(); /** * Constructor. @@ -157,7 +158,11 @@ public class ArchiveConfig implements Comparable { * @param retentionHours */ public void setRetentionHours(int retentionHours) { - this.retentionHours = retentionHours; + if (retentionHours > 0) { + this.retentionHours = retentionHours; + } else { + this.retentionHours = 1; + } } /** @@ -166,7 +171,10 @@ public class ArchiveConfig implements Comparable { * @return */ public List getCategoryList() { - return new ArrayList(categoryList); + List list = new ArrayList( + categoryList.size()); + list.addAll(categoryList); + return list; } /** @@ -188,15 +196,17 @@ public class ArchiveConfig implements Comparable { * @param categoryList */ public void setCategoryList(List categoryList) { - this.categoryList = categoryList; + this.categoryList.clear(); + if (categoryList != null) { + this.categoryList.addAll(categoryList); + } } /** * Check for required entries. */ public boolean isValid() { - return (name != null) && (rootDir != null) && (categoryList != null) - && (categoryList.size() > 0); + return (name != null) && (rootDir != null) && (categoryList.size() > 0); } /* 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 b22fadc77b..441b8eacf6 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 @@ -73,6 +73,7 @@ import javax.xml.bind.annotation.XmlRootElement; * May 1, 2013 1966 rferrel Initial creation * Aug 03, 2013 2224 rferrel Changes to include DataSet. * Jan 09, 2014 2603 rferrel Fix bug in setSelectedDisplayNames + * Apr 17, 2014 3045 rferrel Code cleanup to prevent null pointer. * * * @@ -97,7 +98,7 @@ public class CategoryConfig implements Comparable { private int retentionHours; @XmlElement(name = "dataSet") - private List dataSetList; + private List dataSetList = new ArrayList(); @XmlElement(name = "selectedDisplayName") private final Collection selectedDisplayNames = new TreeSet(); @@ -138,31 +139,66 @@ public class CategoryConfig implements Comparable { * Set the retention hours must be greater then zero. */ public void setRetentionHours(int retentionHours) { - this.retentionHours = retentionHours; + if (retentionHours > 0) { + this.retentionHours = retentionHours; + } else { + this.retentionHours = 1; + } } + /** + * + * @return dataSetList + */ public List getDataSetList() { - return new ArrayList(dataSetList); + List list = new ArrayList( + dataSetList.size()); + list.addAll(dataSetList); + return list; } + /** + * + * @param dataSetList + */ public void setDataSetList(List dataSetList) { - this.dataSetList = dataSetList; + this.dataSetList.clear(); + if (dataSetList != null) { + this.dataSetList.addAll(dataSetList); + } } + /** + * + * @return selectedDisplayNames + */ public Collection getSelectedDisplayNames() { return selectedDisplayNames; } - public void setSelectedDisplayNames( - Collection selectedDisplayNameList) { - selectedDisplayNames.clear(); - selectedDisplayNames.addAll(selectedDisplayNameList); + /** + * + * @param selectedDisplayNames + */ + public void setSelectedDisplayNames(Collection selectedDisplayNames) { + this.selectedDisplayNames.clear(); + if (selectedDisplayNames != null) { + this.selectedDisplayNames.addAll(selectedDisplayNames); + } } + /** + * + * @param displayName + */ public void addSelectedDisplayName(String displayName) { selectedDisplayNames.add(displayName); } + /** + * + * @param displayName + */ public void removeSelectedDisplayName(String displayName) { selectedDisplayNames.remove(displayName); } diff --git a/tests/unit/com/raytheon/uf/common/archive/ArchiveConfigManagerTest.java b/tests/unit/com/raytheon/uf/common/archive/ArchiveConfigManagerTest.java index cb69ee496d..504bb2c941 100644 --- a/tests/unit/com/raytheon/uf/common/archive/ArchiveConfigManagerTest.java +++ b/tests/unit/com/raytheon/uf/common/archive/ArchiveConfigManagerTest.java @@ -51,7 +51,6 @@ import com.raytheon.uf.common.localization.PathManagerFactoryTest; import com.raytheon.uf.common.time.util.TimeUtil; import com.raytheon.uf.common.util.FileUtil; import com.raytheon.uf.common.util.TestUtil; -import com.raytheon.uf.edex.archive.purge.ArchivePurgeManager; /** * Test ArchiveConfigManager Archive Ingest Purge and Archive Creation. @@ -68,6 +67,7 @@ import com.raytheon.uf.edex.archive.purge.ArchivePurgeManager; * Aug 28, 2013 2299 rferrel purgeExpiredFromArchive now returns number of files purged. * Apr 14, 2014 3023 rferrel Remove archive purge test no long works with implementation * cluster locks. + * Apr 17, 2014 3045 rferrel Commented out test so no longer have dependence ArchivPurgeManger. * * * @@ -555,39 +555,40 @@ public class ArchiveConfigManagerTest { * awips.cluster_task table to perform the locks. */ // @Test - public void testArchiveManagerPurge() throws IOException { - ArchivePurgeManager manager = ArchivePurgeManager.getInstance(); - Collection filesFoundInPurge = new ArrayList(); - int purgeCount = 0; - - for (ArchiveConfig a : manager.getArchives()) { - purgeCount += manager.purgeExpiredFromArchive(a); - } - - // assertEquals( - // - // "The expected number of purged files and number of purge files not the same", - // purgeCount, purgeFiles.size()); - - for (File file : allFiles) { - if (!file.exists()) { - filesFoundInPurge.add(file); - } - } - System.out.println("purgeCount: " + purgeCount + ", pureFiles.size:" - + purgeFiles.size() + ", filesFoundInPurge.size(): " - + filesFoundInPurge.size()); - - for (File file : purgeFiles) { - if (!filesFoundInPurge.contains(file)) { - System.out.println("not purged: " + file.getAbsolutePath()); - } - } - - assertEquals( - "The expected purge files and the files purged are not the same", - createFileNameListRemoveTestDir(purgeFiles), - createFileNameListRemoveTestDir(filesFoundInPurge)); - } + // public void testArchiveManagerPurge() throws IOException { + // ArchivePurgeManager manager = ArchivePurgeManager.getInstance(); + // Collection filesFoundInPurge = new ArrayList(); + // int purgeCount = 0; + // + // for (ArchiveConfig a : manager.getArchives()) { + // purgeCount += manager.purgeExpiredFromArchive(a); + // } + // + // // assertEquals( + // // + // // + // "The expected number of purged files and number of purge files not the same", + // // purgeCount, purgeFiles.size()); + // + // for (File file : allFiles) { + // if (!file.exists()) { + // filesFoundInPurge.add(file); + // } + // } + // System.out.println("purgeCount: " + purgeCount + ", pureFiles.size:" + // + purgeFiles.size() + ", filesFoundInPurge.size(): " + // + filesFoundInPurge.size()); + // + // for (File file : purgeFiles) { + // if (!filesFoundInPurge.contains(file)) { + // System.out.println("not purged: " + file.getAbsolutePath()); + // } + // } + // + // assertEquals( + // "The expected purge files and the files purged are not the same", + // createFileNameListRemoveTestDir(purgeFiles), + // createFileNameListRemoveTestDir(filesFoundInPurge)); + // } }