Skip to content

Commit

Permalink
CHANGELOG, upgrade AWS java libraries. Fixed unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Yen, David (398B-Affiliate) committed May 11, 2024
1 parent 4d8d683 commit 0488fb9
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 236 deletions.
17 changes: 17 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,23 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]
### Added
- **PODAAC-6181**
- add relatedUrl subType BROWSE IMAGE SOURCE
- Update build to use java 11
- To generate java 11 compatible UMMG schema POJOs, jsonschema2pojo shall make use of command line parameter: --target-version 1.11
### Deprecated
### Removed
### Fixed
- **PODAAC-5857**
- Fixed the issue so footprint and bbx do not always appear together while isoXmlSpatial is configured to footprint only
- remove request.close() statement in CMRLambdaRestClient so the response could be pulled out and logged properly instead of always logging apache chunk read error due to the http channel was closed.
- adding more parameters to Jsonschema2pojo plugin to generate proper pojo from ummg schema
### Security
- Snyk: Security upgrade com.amazonaws:aws-java-sdk-s3 from 1.12.544 to 1.12.641


## [8.6.0]
### Added
- **PODAAC-5876**
Expand Down
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,13 @@
<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-java-sdk-s3</artifactId>
<version>1.12.701</version>
<version>1.12.719</version>
</dependency>
<!-- For AWS Secret Manager -->
<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-java-sdk-secretsmanager</artifactId>
<version>1.12.701</version>
<version>1.12.719</version>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
package gov.nasa.cumulus.metadata.test;

import gov.nasa.cumulus.metadata.aggregator.MetadataAggregatorLambda;
import gov.nasa.cumulus.metadata.aggregator.bo.TaskConfigBO;
import gov.nasa.cumulus.metadata.aggregator.factory.TaskConfigFactory;
import gov.nasa.cumulus.metadata.state.MENDsIsoXMLSpatialTypeEnum;
import org.json.simple.JSONArray;
import org.json.simple.JSONObject;
import org.json.simple.parser.ParseException;
import org.junit.Before;
import org.junit.Test;
Expand Down Expand Up @@ -41,23 +44,17 @@ public void testGetConceptId() throws ParseException {
assertEquals(conceptId, "G1238611022-POCUMULUS");
}

@Test
public void testGetIsoXMLSpatialTypeStr() {
MetadataAggregatorLambda lambda = new MetadataAggregatorLambda();
assertEquals(lambda.getIsoXMLSpatialTypeStr("footprint"), "footprint");
assertEquals(lambda.getIsoXMLSpatialTypeStr("orbit"), "orbit");
assertEquals(lambda.getIsoXMLSpatialTypeStr("bbox"), "bbox");
assertEquals(lambda.getIsoXMLSpatialTypeStr("xxxx"), "");
}

@Test
public void testCreateIsoXMLSpatialTypeSet() {
MetadataAggregatorLambda lambda = new MetadataAggregatorLambda();
org.json.simple.JSONArray array = new JSONArray();
array.add("footprint");
array.add("orbit");
JSONObject config = new JSONObject();
config.put("isoXMLSpatialType", array);
TaskConfigBO taskConfigBO = TaskConfigFactory.createTaskConfigBO(config);
//HashSet<MENDsIsoXMLSpatialTypeEnum> h = lambda.createIsoXMLSpatialTypeSet("[footprint,orbit]");
HashSet<MENDsIsoXMLSpatialTypeEnum> h = lambda.createIsoXMLSpatialTypeSet(array);
HashSet<MENDsIsoXMLSpatialTypeEnum> h = taskConfigBO.getIsoXMLSpatialTypeHashSet();
assertTrue(h.contains(MENDsIsoXMLSpatialTypeEnum.FOOTPRINT));
assertTrue(h.contains(MENDsIsoXMLSpatialTypeEnum.ORBIT));
assertFalse(h.contains(MENDsIsoXMLSpatialTypeEnum.BBOX));
Expand All @@ -69,8 +66,10 @@ public void testCreateIsoXMLSpatialTypeSet() {
array.add("bbox");
array.add("eebb");
array.add("ccmm");
//h = lambda.createIsoXMLSpatialTypeSet("[footprint,orbit,bbox,eebb,ccmm]");
h = lambda.createIsoXMLSpatialTypeSet(array);
config = new JSONObject();
config.put("isoXMLSpatialType", array);
taskConfigBO = TaskConfigFactory.createTaskConfigBO(config);
h = taskConfigBO.getIsoXMLSpatialTypeHashSet();
assertTrue(h.contains(MENDsIsoXMLSpatialTypeEnum.FOOTPRINT));
assertTrue(h.contains(MENDsIsoXMLSpatialTypeEnum.ORBIT));
assertTrue(h.contains(MENDsIsoXMLSpatialTypeEnum.BBOX));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -994,209 +994,4 @@ public void testCreateJsonSwotCalVal() throws IOException, ParseException, XPath
// load pre-saved file and perform json comparison
assertTrue(UnitTestUtil.compareFileWithGranuleJson("ummgResults/swotCalVal/SWOTCalVal_WM_ADCP_L0_RiverRay1_20220727T191701_20220727T192858_20220920T142800_swotCalVal_ummg.json", granule));
}
@Test
public void testSWOTCreateJsonSWOTIsoXMLSpatialType() throws IOException, ParseException, XPathExpressionException, ParserConfigurationException, SAXException, URISyntaxException {
// Create isoXmlSpatial Hashtable which contains footprint, orbit then passed the hashtable to MetadataFilesToEcho contructor
MetadataAggregatorLambda lambda = new MetadataAggregatorLambda();
org.json.simple.JSONArray array = new JSONArray();
array.add("footprint");
array.add("orbit");
array.add("bbox");

HashSet<MENDsIsoXMLSpatialTypeEnum> h = lambda.createIsoXMLSpatialTypeSet(array);
assertTrue(h.contains(MENDsIsoXMLSpatialTypeEnum.FOOTPRINT));
assertTrue(h.contains(MENDsIsoXMLSpatialTypeEnum.ORBIT));
assertTrue(h.contains(MENDsIsoXMLSpatialTypeEnum.BBOX));
assertFalse(h.contains(MENDsIsoXMLSpatialTypeEnum.NONE));

ClassLoader classLoader = getClass().getClassLoader();
File file = new File(classLoader.getResource("swotIsoXMLSpatialTypeTestData/SWOT_L2_LR_SSH_Basic_006_143_20231107T150730_20231107T155607_PIB0_01.nc.iso.xml").getFile());

// constructor to set isIso =true and the isoXmlSpatialHashtable
MetadataFilesToEcho mfte = new MetadataFilesToEcho(true, h);
mfte.getGranule().setName("SWOT_L2_LR_SSH_Basic_006_143_20231107T150730_20231107T155607_PIB0_01");
File cfgFile = new File(classLoader.getResource("MODIS_T-JPL-L2P-v2014.0.cmr.cfg").getFile());
mfte.readConfiguration(cfgFile.getAbsolutePath());
mfte.readIsoMetadataFile(file.getAbsolutePath(), "s3://fake_bucket/fake_dir/fake.nc.iso.xml");

JSONObject granule = mfte.createJson();
JSONArray polygonPoints =((JSONArray)((JSONObject) ((JSONObject)((JSONArray)((JSONObject)((JSONObject)((JSONObject)granule
.get("SpatialExtent"))
.get("HorizontalSpatialDomain"))
.get("Geometry"))
.get("GPolygons")).get(0)).get("Boundary")).get("Points"));
Double latitude=(Double)((JSONObject)polygonPoints.get(0)).get("Latitude");
Double longitude=(Double)((JSONObject)polygonPoints.get(0)).get("Longitude");
assert latitude.doubleValue() ==-77.089598228;
assert longitude.doubleValue() == -121.56652283899999;

latitude=(Double)((JSONObject)polygonPoints.get(27)).get("Latitude");
longitude=(Double)((JSONObject)polygonPoints.get(27)).get("Longitude");
assert latitude.doubleValue()==56.734470077;
assert longitude.doubleValue()==-21.668558564000023;

latitude=(Double)((JSONObject)polygonPoints.get(64)).get("Latitude");
longitude=(Double)((JSONObject)polygonPoints.get(64)).get("Longitude");
assert latitude.doubleValue()==-77.089598228;
assert longitude.doubleValue()== -121.56652283899999;

JSONObject orbit = ((JSONObject)((JSONObject)((JSONObject)granule
.get("SpatialExtent"))
.get("HorizontalSpatialDomain"))
.get("Orbit"));
assert ((Double)orbit.get("StartLatitude"))==-77.66; //-77.66
assert ((Double)orbit.get("EndLatitude"))==77.66;// -> {Double@5567} 77.66
assert ((Double)orbit.get("AscendingCrossing"))==-38.05; //-> {Double@5569} -38.05
assertTrue(StringUtils.equals((String)orbit.get("StartDirection"), "A")); //-> A
assertTrue(StringUtils.equals((String)orbit.get("EndDirection"), "A")); //EndDirection -> A

JSONObject bbox = (JSONObject)((JSONArray)((JSONObject)((JSONObject)((JSONObject)granule
.get("SpatialExtent"))
.get("HorizontalSpatialDomain"))
.get("Geometry"))
.get("BoundingRectangles")).get(0);
assert ((BigDecimal)bbox.get("WestBoundingCoordinate")).compareTo(new BigDecimal("-121.76947499999999990905052982270717620849609375")) ==0;
assert ((BigDecimal)bbox.get("SouthBoundingCoordinate")).compareTo(new BigDecimal("-78.271941999999995687176124192774295806884765625"))==0;
assert ((BigDecimal)bbox.get("EastBoundingCoordinate")).compareTo(new BigDecimal("45.675058000000035463017411530017852783203125"))==0;
assert ((BigDecimal)bbox.get("NorthBoundingCoordinate")).compareTo(new BigDecimal("78.272067999999990206561051309108734130859375"))==0;


// verify the pre-saved ummg.json file is equal to the granule json just built
assertTrue(UnitTestUtil.compareFileWithGranuleJson("ummgResults/swotIsoXMLSpatialType/SWOT_L2_LR_SSH_Basic_006_143_20231107T150730_20231107T155607_PIB0_01_footprintOrbitBBox.json", granule));
/**
* Test isoXMLSpatial:[footprint]
*/
clearVariables4IsoXMLSpatialTest(array, h, granule); // clear variables first
array.add("footprint");
h = lambda.createIsoXMLSpatialTypeSet(array);
assertTrue(h.contains(MENDsIsoXMLSpatialTypeEnum.FOOTPRINT));
assertFalse(h.contains(MENDsIsoXMLSpatialTypeEnum.ORBIT));
assertFalse(h.contains(MENDsIsoXMLSpatialTypeEnum.BBOX));
assertFalse(h.contains(MENDsIsoXMLSpatialTypeEnum.NONE));
mfte = new MetadataFilesToEcho(true, h);
mfte.getGranule().setName("SWOT_L2_LR_SSH_Basic_006_143_20231107T150730_20231107T155607_PIB0_01");
cfgFile = new File(classLoader.getResource("MODIS_T-JPL-L2P-v2014.0.cmr.cfg").getFile());
mfte.readConfiguration(cfgFile.getAbsolutePath());
mfte.readIsoMetadataFile(file.getAbsolutePath(), "s3://fake_bucket/fake_dir/fake.nc.iso.xml");
granule = mfte.createJson();
polygonPoints =((JSONArray)((JSONObject) ((JSONObject)((JSONArray)((JSONObject)((JSONObject)((JSONObject)granule
.get("SpatialExtent"))
.get("HorizontalSpatialDomain"))
.get("Geometry"))
.get("GPolygons")).get(0)).get("Boundary")).get("Points"));
latitude=(Double)((JSONObject)polygonPoints.get(0)).get("Latitude");
longitude=(Double)((JSONObject)polygonPoints.get(0)).get("Longitude");
assert latitude.doubleValue() ==-77.089598228;
assert longitude.doubleValue() == -121.56652283899999;

latitude=(Double)((JSONObject)polygonPoints.get(27)).get("Latitude");
longitude=(Double)((JSONObject)polygonPoints.get(27)).get("Longitude");
assert latitude.doubleValue()==56.734470077;
assert longitude.doubleValue()==-21.668558564000023;

latitude=(Double)((JSONObject)polygonPoints.get(64)).get("Latitude");
longitude=(Double)((JSONObject)polygonPoints.get(64)).get("Longitude");
assert latitude.doubleValue()==-77.089598228;
assert longitude.doubleValue()== -121.56652283899999;

orbit = ((JSONObject)((JSONObject)((JSONObject)granule
.get("SpatialExtent"))
.get("HorizontalSpatialDomain"))
.get("Orbit"));
assert orbit==null;

bbox = (JSONObject) (((JSONObject)((JSONObject)((JSONObject) granule
.get("SpatialExtent"))
.get("HorizontalSpatialDomain"))
.get("Geometry"))
.get("BoundingRectangles"));
assert bbox == null;
// load pre-saved file and perform json comparison
assertTrue(UnitTestUtil.compareFileWithGranuleJson("ummgResults/swotIsoXMLSpatialType/SWOT_L2_LR_SSH_Basic_006_143_20231107T150730_20231107T155607_PIB0_01_footprint.json", granule));
/**
* Test isoXMLSpatial:[bbox]
*/
clearVariables4IsoXMLSpatialTest(array, h, granule); // clear variables first
array.add("bbox");
h = lambda.createIsoXMLSpatialTypeSet(array);
assertFalse(h.contains(MENDsIsoXMLSpatialTypeEnum.FOOTPRINT));
assertFalse(h.contains(MENDsIsoXMLSpatialTypeEnum.ORBIT));
assertTrue(h.contains(MENDsIsoXMLSpatialTypeEnum.BBOX));
assertFalse(h.contains(MENDsIsoXMLSpatialTypeEnum.NONE));
mfte = new MetadataFilesToEcho(true, h);
mfte.getGranule().setName("SWOT_L2_LR_SSH_Basic_006_143_20231107T150730_20231107T155607_PIB0_01");
cfgFile = new File(classLoader.getResource("MODIS_T-JPL-L2P-v2014.0.cmr.cfg").getFile());
mfte.readConfiguration(cfgFile.getAbsolutePath());
mfte.readIsoMetadataFile(file.getAbsolutePath(), "s3://fake_bucket/fake_dir/fake.nc.iso.xml");
granule = mfte.createJson();
JSONArray GPolygons = (JSONArray)((JSONObject)((JSONObject)((JSONObject)granule
.get("SpatialExtent"))
.get("HorizontalSpatialDomain"))
.get("Geometry"))
.get("GPolygons");
assert GPolygons ==null;

orbit = ((JSONObject)((JSONObject)((JSONObject)granule
.get("SpatialExtent"))
.get("HorizontalSpatialDomain"))
.get("Orbit"));
assert orbit==null;

bbox = (JSONObject)((JSONArray)((JSONObject)((JSONObject)((JSONObject)granule
.get("SpatialExtent"))
.get("HorizontalSpatialDomain"))
.get("Geometry"))
.get("BoundingRectangles")).get(0);
assert ((BigDecimal)bbox.get("WestBoundingCoordinate")).compareTo(new BigDecimal("-121.76947499999999990905052982270717620849609375")) ==0;
assert ((BigDecimal)bbox.get("SouthBoundingCoordinate")).compareTo(new BigDecimal("-78.271941999999995687176124192774295806884765625"))==0;
assert ((BigDecimal)bbox.get("EastBoundingCoordinate")).compareTo(new BigDecimal("45.675058000000035463017411530017852783203125"))==0;
assert ((BigDecimal)bbox.get("NorthBoundingCoordinate")).compareTo(new BigDecimal("78.272067999999990206561051309108734130859375"))==0;
// load pre-saved file and perform json comparison
assertTrue(UnitTestUtil.compareFileWithGranuleJson("ummgResults/swotIsoXMLSpatialType/SWOT_L2_LR_SSH_Basic_006_143_20231107T150730_20231107T155607_PIB0_01_bbox.json", granule));
/**
* Test isoXMLSpatial:[orbit]
*/
clearVariables4IsoXMLSpatialTest(array, h, granule); // clear variables first
array.add("orbit");
h = lambda.createIsoXMLSpatialTypeSet(array);
assertFalse(h.contains(MENDsIsoXMLSpatialTypeEnum.FOOTPRINT));
assertTrue(h.contains(MENDsIsoXMLSpatialTypeEnum.ORBIT));
assertFalse(h.contains(MENDsIsoXMLSpatialTypeEnum.BBOX));
assertFalse(h.contains(MENDsIsoXMLSpatialTypeEnum.NONE));
mfte = new MetadataFilesToEcho(true, h);
mfte.getGranule().setName("SWOT_L2_LR_SSH_Basic_006_143_20231107T150730_20231107T155607_PIB0_01");
cfgFile = new File(classLoader.getResource("MODIS_T-JPL-L2P-v2014.0.cmr.cfg").getFile());
mfte.readConfiguration(cfgFile.getAbsolutePath());
mfte.readIsoMetadataFile(file.getAbsolutePath(), "s3://fake_bucket/fake_dir/fake.nc.iso.xml");
granule = mfte.createJson();
JSONObject geometry = ((JSONObject)((JSONObject)((JSONObject)granule
.get("SpatialExtent"))
.get("HorizontalSpatialDomain"))
.get("Geometry"));
assert geometry ==null;

orbit = ((JSONObject)((JSONObject)((JSONObject)granule
.get("SpatialExtent"))
.get("HorizontalSpatialDomain"))
.get("Orbit"));
assert ((Double)orbit.get("StartLatitude"))==-77.66; //-77.66
assert ((Double)orbit.get("EndLatitude"))==77.66;// -> {Double@5567} 77.66
assert ((Double)orbit.get("AscendingCrossing"))==-38.05; //-> {Double@5569} -38.05
assertTrue(StringUtils.equals((String)orbit.get("StartDirection"), "A")); //-> A
assertTrue(StringUtils.equals((String)orbit.get("EndDirection"), "A")); //EndDirection -> A
// No Geometry object since there is neither footprint nor bbox
bbox = (((JSONObject)((JSONObject)((JSONObject) granule
.get("SpatialExtent"))
.get("HorizontalSpatialDomain"))
.get("Geometry")));
assert bbox == null;
// load pre-saved file and perform json comparison
assertTrue(UnitTestUtil.compareFileWithGranuleJson("ummgResults/swotIsoXMLSpatialType/SWOT_L2_LR_SSH_Basic_006_143_20231107T150730_20231107T155607_PIB0_01_orbit.json", granule));
}

private void clearVariables4IsoXMLSpatialTest(JSONArray isoXMLSpatialArray, HashSet isoXMLSpatialHashSet, JSONObject granule) {
isoXMLSpatialArray.clear();
isoXMLSpatialHashSet.clear();
granule.clear();
}
}
Loading

0 comments on commit 0488fb9

Please sign in to comment.