Skip to content

Commit

Permalink
Fix bug introduced from #149 fix
Browse files Browse the repository at this point in the history
Row counter needs to be reset after each collection is read

Commit also include regression test.

Resolves #173
  • Loading branch information
jordanpadams committed Jan 22, 2020
1 parent 3b79ba3 commit 581af7f
Show file tree
Hide file tree
Showing 20 changed files with 1,976 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,6 @@ public class CollectionReferentialIntegrityRule extends AbstractValidationRule {

private String lid = null;

private int numOfCollections = 0;

@Override
public boolean isApplicable(String location) {
if (Utility.isDir(location)) {
Expand Down Expand Up @@ -103,10 +101,13 @@ public void collectionReferentialIntegrityRule() {

private void getCollectionMembers(URL collection) {
try {
int numOfCollectionMembers = 0;
numOfCollectionMembers = 0;

InventoryTableReader reader = new InventoryTableReader(collection);
for (InventoryEntry entry = new InventoryEntry(); entry != null;) {
if (!entry.isEmpty()) {
numOfCollections++;
numOfCollectionMembers++;
String identifier = entry.getIdentifier();
if (!identifier.equals("")) {
//Check for a LID or LIDVID
Expand Down Expand Up @@ -190,10 +191,10 @@ private void getCollectionMembers(URL collection) {
entry = reader.getNext();
}
int records = reader.getNumRecords();
if (this.numOfCollections>0 && records>0 && this.numOfCollections!=records) {
if (numOfCollectionMembers>0 && records>0 && numOfCollectionMembers!=records) {
String message = "Number of records read is not equal "
+ "to the defined number of records in the collection (expected "
+ records + ", got " + this.numOfCollections + ").";
+ records + ", got " + numOfCollectionMembers + ").";
getListener().addProblem(new ValidationProblem(
new ProblemDefinition(ExceptionType.ERROR,
ProblemType.RECORDS_MISMATCH,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -705,6 +705,61 @@ void testGithub137() {
}
}

@Test
void testGithub173() {
try {
// Setup paths
String testPath = Utility.getAbsolutePath(TestConstants.TEST_DATA_DIR + "/github173");
String outFilePath = TestConstants.TEST_OUT_DIR;
File report = new File(outFilePath + File.separator + "report_github173_1.json");

String[] args = {
"-r", report.getAbsolutePath(),
"-s", "json",
"-R", "pds4.bundle",
"-t" , testPath + File.separator + "valid" + File.separator,
"--skip-content-validation"

};
this.launcher.processMain(args);

Gson gson = new Gson();
JsonObject reportJson = gson.fromJson(new FileReader(report), JsonObject.class);

reportJson = gson.fromJson(new FileReader(report), JsonObject.class);

int count = this.getMessageCount(reportJson, ProblemType.RECORDS_MISMATCH.getKey());

assertEquals(count, 0, ProblemType.RECORDS_MISMATCH.getKey() + " info/error messages expected.");

// Now test with added context products
report = new File(outFilePath + File.separator + "report_github173_2.json");
String[] args2 = {
"-r", report.getAbsolutePath(),
"-s", "json",
"-R", "pds4.bundle",
"-t" , testPath + File.separator + "invalid" + File.separator,
"--skip-content-validation"
};
this.launcher = new ValidateLauncher();
this.launcher.processMain(args2);

gson = new Gson();

reportJson = gson.fromJson(new FileReader(report), JsonObject.class);

count = this.getMessageCount(reportJson, ProblemType.RECORDS_MISMATCH.getKey());

assertEquals(count, 1, ProblemType.RECORDS_MISMATCH.getKey() + " info/error messages not expected.");

} catch (ExitException e) {
assertEquals(0, e.status, "Exit status");
} catch (Exception e) {
e.printStackTrace();
fail("Test Failed Due To Exception: " + e.getMessage());
}
}

int getMessageCount(JsonObject reportJson, String messageTypeName) {
int i = 0;
JsonObject message = null;
Expand Down
130 changes: 130 additions & 0 deletions src/test/resources/github173/invalid/bundle_kaguya_derived.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
<?xml version="1.0" encoding="UTF-8"?>
<?xml-model href="https://pds.nasa.gov/pds4/pds/v1/PDS4_PDS_1B00.sch" schematypens="http://purl.oclc.org/dsdl/schematron"?>

<Product_Bundle xmlns="http://pds.nasa.gov/pds4/pds/v1"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://pds.nasa.gov/pds4/pds/v1 https://pds.nasa.gov/pds4/pds/v1/PDS4_PDS_1B00.xsd">
<Identification_Area>
<logical_identifier>urn:nasa:pds:kaguya_grs_spectra</logical_identifier>
<version_id>1.1</version_id>
<title>Kaguya Gamma-Ray Spectrometer Corrected Spectra Bundle</title>
<information_model_version>1.11.0.0</information_model_version>
<product_class>Product_Bundle</product_class>
<Citation_Information>
<publication_year>2019</publication_year>
<description>
This archive contains Kaguya Gamma-Ray Spectrometer (KGRS) corrected and calibrated time-series
spectra and ephemerides, pointing, and geometry (EPG) data for the nominal and extended observation
periods of JAXA's SELENE (Kaguya) mission.

The SELENE mission was the Japanese mission to the Moon with a main orbiter “Kaguya” and
two daughter relay satellites launched on Sep. 14, 2007. KGRS was mounted on the deck of the
main orbiter. It employed a high-purity Ge (HPGe) crystal as a main detector, and surrounding
BGO and plastic scintillators as anti-coincidence detectors to reduce backgrounds. The
Ge crystal was cooled by a Sterling refrigerator. It made close-proximity observations of the
Moon from Dec. 14, 2007 to Dec. 11, 2008 at the high circular orbital altitude of 100 km, and
from Feb. 10 to May 28 in 2009 at the low elliptical orbital altitude of ~30 x 50 km.

KGRS recorded energy spectra of gamma rays in two gain modes simultaneously; high gain (0.1
to 3 MeV) and low gain (0.1 to 13 MeV), each of which was analyzed by the 13-bit (8192 ch)
analog-to-digital converter (ADC). While the former has a higher spectral resolution over the
energy range of radioactive elements, the latter has better statistics and covers the whole energy
range of major rock-forming elements, including the Fe neutron capture line at 7.6 MeV. The
accumulation time of each spectrum was 17 s. Both modes of spectra are included in this archive.

The observation epochs of KGRS consists of three regular measurement periods (Period 1 to 3),
background measurements, and the annealing of the Ge crystal. The HPGe detector was annealed
from 16 to 25, December 2008, which improved energy resolution by a factor of two.
Period 1 and 2 lasted two and five months, respectively, with limited spatial or spectral
resolutions. Period 3 lasted ~3.5 months (including dead time) with the best spatial and spectral
resolutions. In addition, spectra from the background measurement when the satellite was flipped
and the detector faced deep space can be analyzed to estimate the background gamma-ray intensity
from the satellite due to the exposure to galactic cosmic rays.

This archive consists of three spectrum files (each corresponding to one KGRS epoch) and one unified
EPG file. The spectrum files contain a time series of corrected and calibrated pulse height spectra
acquired by KGRS's HPGe detector in the lunar orbit. In the spectrum files, each row contains the
spacecraft clock (sclk) ticks and UTC time corresponding to the end of the accumulation interval
(17 s), with the two sets of the 8192-channel HPGe spectra accumulated. In the EPG file, each row
starts with sclk recorded at the end of the accumulation interval to match spacecraft positions,
pointing, and correction factors with the corrected spectra. Note that the UTC time and ephemeris time
included in the EPG file correspond to the midpoint of the accumulation interval.

The Kaguya Gamma-Ray Spectrometer Corrected Spectra bundle was created by Naoyuki Yamashita at Planetary
Science Institute, AZ, USA, with the permission of JAXA and the KGRS instrument PI Prof. Nobuyuki Hasebe.
This work was supported by the NASA under Grant No. NNX16AG54G issued through the Planetary Data Archiving,
Restoration, and Tools Program (PDART), Research Opportunities in Space and Earth Sciences (ROSES) 2015.
</description>
</Citation_Information>
<Modification_History>
<Modification_Detail>
<modification_date>2019-09-30</modification_date>
<version_id>1.0</version_id>
<description>Peer reviewed version of Kaguya Gamma-Ray Spectrometer Corrected Spectra PDS4</description>
</Modification_Detail>
</Modification_History>
</Identification_Area>
<Context_Area>
<Time_Coordinates>
<start_date_time>2007-12-14T04:15:35Z</start_date_time>
<stop_date_time>2009-05-28T07:43:22Z</stop_date_time>
</Time_Coordinates>
<Primary_Result_Summary>
<purpose>Science</purpose>
<processing_level>Derived</processing_level>
</Primary_Result_Summary>
<Investigation_Area>
<name>Kaguya</name>
<type>Mission</type>
<Internal_Reference>
<lid_reference>urn:nasa:pds:context:investigation:mission.kaguya</lid_reference>
<reference_type>bundle_to_investigation</reference_type>
</Internal_Reference>
</Investigation_Area>
<Observing_System>
<name>Kaguya</name>
<Observing_System_Component>
<name>Kaguya</name>
<type>Spacecraft</type>
<Internal_Reference>
<lid_reference>urn:nasa:pds:context:instrument_host:spacecraft.kaguya</lid_reference>
<reference_type>is_instrument_host</reference_type>
</Internal_Reference>
</Observing_System_Component>
<Observing_System_Component>
<name>GRS</name>
<type>Instrument</type>
<Internal_Reference>
<lid_reference>urn:nasa:pds:context:instrument:kaguya.grs</lid_reference>
<reference_type>is_instrument</reference_type>
</Internal_Reference>
</Observing_System_Component>
</Observing_System>
<Target_Identification>
<name>Moon</name>
<type>Satellite</type>
<Internal_Reference>
<lid_reference>urn:nasa:pds:context:target:satellite.earth.moon</lid_reference>
<reference_type>collection_to_target</reference_type>
</Internal_Reference>
</Target_Identification>
</Context_Area>
<Reference_List>
<Internal_Reference>
<lid_reference>urn:nasa:pds:kaguya_grs_spectra:document:kgrs_calibrated_spectra</lid_reference>
<reference_type>bundle_to_document</reference_type>
</Internal_Reference>
<Internal_Reference>
<lid_reference>urn:nasa:pds:kaguya_grs_spectra:document:kgrs_ephemerides_doc</lid_reference>
<reference_type>bundle_to_document</reference_type>
</Internal_Reference>
</Reference_List>
<Bundle>
<bundle_type>Archive</bundle_type>
</Bundle>
<Bundle_Member_Entry>
<lid_reference>urn:nasa:pds:kaguya_grs_spectra:data_spectra</lid_reference>
<member_status>Primary</member_status>
<reference_type>bundle_has_data_collection</reference_type>
</Bundle_Member_Entry>
</Product_Bundle>
Empty file.
Loading

0 comments on commit 581af7f

Please sign in to comment.