Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix footprint and bbx always appears together issue #70

Merged
merged 2 commits into from
Jan 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### 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

## [8.5.0]
Expand Down
4 changes: 3 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,9 @@
<targetPackage>gov.nasa.cumulus.metadata.umm.generated</targetPackage>
<sourceType>jsonschema</sourceType>
<annotationStyle>GSON</annotationStyle>
<includeConstructors>true</includeConstructors>
<includeConstructors>false</includeConstructors>
<targetVersion>11</targetVersion>
<includeGeneratedAnnotation>false</includeGeneratedAnnotation>
<formatDateTimes>true</formatDateTimes>
<formatDates>true</formatDates>
<formatDateTimes>true</formatDateTimes>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@ public CMRLambdaRestClient(String cert, String pass, String tknHost,
this.echoHost = cmrHost;
URIBuilder uriBuilder = new URIBuilder(tknHost);
this.tokenHost = uriBuilder.setPath(uriBuilder.getPath() + "/gettoken").build().normalize().toString();
AdapterLogger.LogInfo(this.className + " final token url:" + this.tokenHost);
this.validHost = this.tokenHost.replaceAll("gettoken", "validate");
this.region = region;
this.tknBucket = tknBucket;
Expand Down Expand Up @@ -105,15 +104,13 @@ public String getToken()
JSONObject jsonTkn = readToken();
long fileTime = getTokenStartTime(jsonTkn);
if (jsonTkn == null || sessionExpired(fileTime, runTime)) {
AdapterLogger.LogDebug(this.className + " Generating new NAMS token...");
try {
this.token = buildToken(runTime);
} catch (Exception e) {
//ERROR getting new token from NAMS.
throw new IOException("Could not retrieve token..." + e);
}
} else {
AdapterLogger.LogDebug(this.className + " Session active, using saved token");
this.token = (String) jsonTkn.get("token");
}
return this.token;
Expand Down Expand Up @@ -261,7 +258,6 @@ private JSONObject readToken()
}
String localTokenFilePath = s3Utils.download(this.region, this.tknBucket, this.tknFilePath,
Paths.get(this.workingDir, "token.json").toString());
AdapterLogger.LogInfo(this.className + " downloaded token file to local:" + localTokenFilePath);
JSONObject json = null;
try (FileReader reader = new FileReader(String.valueOf(localTokenFilePath))) {
json = (JSONObject) parser.parse(reader);
Expand All @@ -278,7 +274,6 @@ private void writeToken(long timeStamp, String token)
JSONObject json = new JSONObject();
json.put("authTime", timeStamp);
json.put("token", token);
AdapterLogger.LogDebug(this.className + " Writing new token to file");
Path localTknFilePath = Files.write(Paths.get(this.workingDir, "token.json"),
json.toString().getBytes());
s3Utils.upload(region, this.tknBucket, this.tknFilePath, new File(localTknFilePath.toString()) );
Expand All @@ -302,7 +297,6 @@ private HttpResponse send(String url, HttpEntity entity)
request.setHeader("Content-Type", content_type);
// Send the request
HttpResponse response = httpClient.execute(request);
request.releaseConnection();
return response;
}

Expand All @@ -314,7 +308,6 @@ public HttpResponse validateUMMG(String provider, String granuleId, String strU
String validateUMMGUri = uriBuilder.setPath(uriBuilder.getPath() + "/ingest/providers/"
+ provider +"/validate/granule/" + granuleId)
.build().normalize().toString();
AdapterLogger.LogDebug("validateUri:" + validateUMMGUri);
HttpEntity httpEntity = new StringEntity(strUMMG, "utf-8");
HttpResponse httpResponse = send(validateUMMGUri, httpEntity);
return httpResponse;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -191,8 +191,6 @@ private void send(String url, HttpEntity entity) throws IOException {
} else {
logHttpResponse(response, HttpOp.SEND);
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@yenes56 What is the reason for needing to remove the request.releaseConnection() lines? This code has been present for a long time, why did it suddenly start causing the chunk error?

// close the connection
request.releaseConnection();
}

public void closeScrollSession(String scrollJson) throws IOException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public class IsoGranule extends UMMGranule {
private List<String> inputGranules;
private String PGEVersionClass;

private IsoType isoType;


public IsoGranule() {
this.identifiers = new HashMap<>();
Expand Down Expand Up @@ -130,12 +130,4 @@ public String getPGEVersionClass() {
public void setPGEVersionClass(String PGEVersionClass) {
this.PGEVersionClass = PGEVersionClass;
}

public IsoType getIsoType() {
return isoType;
}

public void setIsoType(IsoType isoType) {
this.isoType = isoType;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
import java.util.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.regex.PatternSyntaxException;

import javax.xml.bind.DatatypeConverter;
import javax.xml.parsers.DocumentBuilder;
Expand Down Expand Up @@ -324,12 +323,12 @@ public void readIsoMetadataFile(String file, String s3Location) throws ParserCon
// if we get here, we have the bare minimum fields already populated,
// so try and parse the rest of the granule metadata...
try {
((IsoGranule) this.granule).setIsoType(isoType);
if (isoType == IsoType.MENDS) {
AdapterLogger.LogInfo("Found MENDS file");
readIsoMendsMetadataFile(s3Location, doc, xpath);
} else if (isoType == IsoType.SMAP) {
AdapterLogger.LogInfo("Found SMAP file");
((IsoGranule) this.granule).setIsoType(isoType);
readIsoSmapMetadataFile(s3Location, doc, xpath);
} else {
AdapterLogger.LogWarning(isoType.name() + " didn't match any expected ISO type, skipping optional " +
Expand Down Expand Up @@ -486,7 +485,6 @@ public IsoGranule readIsoMendsMetadataFile(String s3Location, Document doc, XPat

((IsoGranule) granule).setOrbit(MENDsISOXmlUtiils.extractXPathValueSwallowException(doc, xpath, IsoMendsXPath.ORBIT, "IsoMendsXPath.ORBIT"));
((IsoGranule) granule).setSwotTrack(MENDsISOXmlUtiils.extractXPathValueSwallowException(doc, xpath, IsoMendsXPath.SWOT_TRACK, "IsoMendsXPath.SWOT_TRACK"));

Source source = new Source();
source.setSourceShortName(MENDsISOXmlUtiils.extractXPathValueSwallowException(doc, xpath, IsoMendsXPath.PLATFORM, "IsoMendsXPath.PLATFORM"));

Expand All @@ -511,7 +509,7 @@ public IsoGranule readIsoMendsMetadataFile(String s3Location, Document doc, XPat
String cyclePassTileSceneStr =StringUtils.trim(MENDsISOXmlUtiils.extractXPathValueSwallowException(doc, xpath, IsoMendsXPath.CYCLE_PASS_TILE_SCENE, "IsoMendsXPath.CYCLE_PASS_TILE_SCENE"));
if(!StringUtils.isBlank(cyclePassTileSceneStr)) {
try {
createIsoCyclePassTile(cyclePassTileSceneStr);
granule = createIsoCyclePassTile(cyclePassTileSceneStr);
} catch (Exception e) {
// Since TrackType which contains Cycle Pass Tile and Scenes is not a required field
// we catch exception with printStackTrace to know the exact line throwing error
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -420,7 +420,8 @@ private JSONObject exportTemporal() {
*/
private boolean shouldAddBBx(Granule granule) {
boolean shouldAddBBx = false;
if(granule !=null && granule instanceof gov.nasa.cumulus.metadata.aggregator.UMMGranule) {

if(granule !=null && granule.getIsoType() == null) {
shouldAddBBx = true;
}
// if the granule object is IsoGranule type and it is SMAP mission, then we check if polygon was added.
Expand All @@ -430,6 +431,7 @@ private boolean shouldAddBBx(Granule granule) {
&& StringUtils.isNotEmpty(((IsoGranule) granule).getPolygon())) {
shouldAddBBx = false;
}
AdapterLogger.LogInfo(this.className + " shouldAddBBx:" + shouldAddBBx);
return shouldAddBBx;
}

Expand All @@ -453,6 +455,7 @@ private JSONObject exportSpatial() throws ParseException{
AdapterLogger.LogInfo(this.className + " nc.iso.xml footprint processing ... ");
this.isLineFormattedPolygon = true;
geometry = line2Polygons(geometry,polygon);
horizontalSpatialDomain.put("Geometry", geometry);
}
if(this.isoXMLSpatialTypeEnumHashSet.contains(MENDsIsoXMLSpatialTypeEnum.ORBIT)) {
AdapterLogger.LogDebug(this.className + "UMMGranuleFile.exportSpatial ORBIT Processing");
Expand All @@ -478,13 +481,18 @@ private JSONObject exportSpatial() throws ParseException{
isoBBoxAlreadyProcessed = true;
horizontalSpatialDomain = this.appendBoundingRectangles(geometry, horizontalSpatialDomain);
}
// Export track
if (((IsoGranule) granule).getSwotTrack() != "") {
// Export track for isoXML SMAP
// look into : IsoSmapXPath.SWOT_TRACK and how we use it to grab and store coordinate string to granule's
// swotTrack string. We also store swotTrack to MENDs granule and IsoXPath.SWOT_TRACK and IsoMendsXPath.CYCLE_PASS_TILE_SCENE
// these 2 values are being used to "extrac" cycle pass string from eith MENDs or SMAP. However, smap cycle and pass
// are being processed below
if (((IsoGranule) granule).getSwotTrack() != "" && granule.getIsoType() == IsoType.SMAP) {
JSONObject track = new JSONObject();
horizontalSpatialDomain.put("Track", track);
Pattern trackPattern = Pattern.compile("Cycle:\\s(.*)\\sPass:\\s(.*)\\sTile:\\s(.*)");
Matcher trackMatcher = trackPattern.matcher(((IsoGranule) granule).getSwotTrack());
if (trackMatcher.find()) {
AdapterLogger.LogDebug("SWOT track found cycle");
track.put("Cycle", Integer.parseInt(trackMatcher.group(1)));
JSONArray passes = new JSONArray();
track.put("Passes", passes);
Expand All @@ -510,17 +518,15 @@ private JSONObject exportSpatial() throws ParseException{
}
} // end of processing IsoGranule

// following is a large block code to deal with None IsoXML (MENDs or SMAP) bounding box
// We can only include orbital or bounding-box data, not both
// if iso Bounding Box already processed in logic above, then don't enter this block
if (foundOrbitalData == false && !isoBBoxAlreadyProcessed) {

horizontalSpatialDomain.put("Geometry", geometry);

JSONArray boundingRectangles = new JSONArray();
geometry.put("BoundingRectangles", boundingRectangles);

double north = 0, south = 0, east = 0, west = 0;
if(granule !=null && granule instanceof gov.nasa.cumulus.metadata.aggregator.UMMGranule) {
if(granule !=null && granule.getIsoType() == null) {
east = ((UMMGranule) granule).getBbxEasternLongitude() != null ?
((UMMGranule) granule).getBbxEasternLongitude() : 0;
west = ((UMMGranule) granule).getBbxWesternLongitude() != null?
Expand Down Expand Up @@ -565,7 +571,6 @@ private JSONObject exportSpatial() throws ParseException{
// and make sure we turn off the rangeIs360 flag
this.rangeIs360 = false;
}

BigDecimal nrth = new BigDecimal(north);
BigDecimal sth = new BigDecimal(south);
nrth = nrth.setScale(3, RoundingMode.HALF_UP);
Expand Down Expand Up @@ -609,9 +614,17 @@ private JSONObject exportSpatial() throws ParseException{
}
}
}
}

// Export track if cycle and pass exists
if (boundingRectangles.size() > 0) {
geometry.put("BoundingRectangles", boundingRectangles);
}
}
// Export TrackType
// MENDS : ISO
// Or Non-iso track : such as MODIS_A and Sentinel-6
// for instance, iso MENDS and Sentinel-6 and MODIS_A are having TrackType created within MetadataFilesToEcho class
// if cycle and pass exists. MENDs is taking adavangate of UMMG generated pojo : TrackType
// which is stored within the UMMGranule
if (granule instanceof UMMGranule) {
/**
* Track include cycle and passes(array).
Expand Down
Loading
Loading