Skip to content

Commit

Permalink
fixed footprint and bbx appear together issue - even when isoXmlSpati…
Browse files Browse the repository at this point in the history
…al configured to footprint only
  • Loading branch information
Yen, David (398B-Affiliate) committed Dec 7, 2023
1 parent 4a4a5fc commit 4d1ee54
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 29 deletions.
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);
}
// 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 @@ -324,12 +324,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 +486,7 @@ 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"));

AdapterLogger.LogDebug("1 SWOT track is set as" + ((IsoGranule) granule).getSwotTrack());
Source source = new Source();
source.setSourceShortName(MENDsISOXmlUtiils.extractXPathValueSwallowException(doc, xpath, IsoMendsXPath.PLATFORM, "IsoMendsXPath.PLATFORM"));

Expand All @@ -511,7 +511,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 Expand Up @@ -818,6 +818,7 @@ private void readIsoSmapMetadataFile(String s3Location, Document doc, XPath xpat
((IsoGranule) granule).setOrbit(xpath.evaluate(IsoSmapXPath.ORBIT, doc));

((IsoGranule) granule).setSwotTrack(xpath.evaluate(IsoSmapXPath.SWOT_TRACK, doc));
AdapterLogger.LogDebug("2 SWOT track is set as" + ((IsoGranule) granule).getSwotTrack());
((IsoGranule) granule).setPolygon(xpath.evaluate(IsoSmapXPath.POLYGON, doc));

Source source = new Source();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -420,7 +420,10 @@ private JSONObject exportTemporal() {
*/
private boolean shouldAddBBx(Granule granule) {
boolean shouldAddBBx = false;
if(granule !=null && granule instanceof gov.nasa.cumulus.metadata.aggregator.UMMGranule) {
if(granule.getIsoType() == null) {
AdapterLogger.LogInfo(this.className + " shouldAddBBx detect UMMGranule Object");
}
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 +433,7 @@ private boolean shouldAddBBx(Granule granule) {
&& StringUtils.isNotEmpty(((IsoGranule) granule).getPolygon())) {
shouldAddBBx = false;
}
AdapterLogger.LogInfo(this.className + " shouldAddBBx:" + shouldAddBBx);
return shouldAddBBx;
}

Expand All @@ -440,6 +444,7 @@ private JSONObject exportSpatial() throws ParseException{
Boolean foundOrbitalData = false;
boolean isoBBoxAlreadyProcessed = false;
spatialExtent.put("HorizontalSpatialDomain", horizontalSpatialDomain);
boolean isIsoXMLSpatialProcessed = false;

if (granule instanceof IsoGranule) {
/**
Expand All @@ -448,13 +453,16 @@ private JSONObject exportSpatial() throws ParseException{
* (during MetatdataFilesToEcho.readIsoxxxx()) is not empty or null
*/
if(this.isoXMLSpatialTypeEnumHashSet.contains(MENDsIsoXMLSpatialTypeEnum.FOOTPRINT)) {
isIsoXMLSpatialProcessed =true;
AdapterLogger.LogDebug(this.className + "UMMGranuleFile.exportSpatial FOOTPRINT Processing");
String polygon = ((IsoGranule) granule).getPolygon();
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)) {
isIsoXMLSpatialProcessed =true;
AdapterLogger.LogDebug(this.className + "UMMGranuleFile.exportSpatial ORBIT Processing");
String orbitStr = ((IsoGranule) granule).getOrbit();
if (!StringUtils.isEmpty(orbitStr)) {
Expand All @@ -473,18 +481,21 @@ private JSONObject exportSpatial() throws ParseException{
}
}
if(this.isoXMLSpatialTypeEnumHashSet.contains(MENDsIsoXMLSpatialTypeEnum.BBOX)) {
isIsoXMLSpatialProcessed =true;
// Extract the stored IsoGranule bounding box and put into SpatialExtent
AdapterLogger.LogDebug(this.className + "UMMGranuleFile.exportSpatial BBOX Processing");
isoBBoxAlreadyProcessed = true;
horizontalSpatialDomain = this.appendBoundingRectangles(geometry, horizontalSpatialDomain);
}
// Export track
if (((IsoGranule) granule).getSwotTrack() != "") {
AdapterLogger.LogDebug(this.className + "Swot track string" + ((IsoGranule) granule).getSwotTrack());
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 +521,18 @@ private JSONObject exportSpatial() throws ParseException{
}
} // end of processing IsoGranule

AdapterLogger.LogInfo(this.className + " granule isoType:" + granule.getIsoType());
// 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) {

AdapterLogger.LogInfo(this.className + " Second block");
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) {
AdapterLogger.LogInfo(this.className + " Unexpected block");
east = ((UMMGranule) granule).getBbxEasternLongitude() != null ?
((UMMGranule) granule).getBbxEasternLongitude() : 0;
west = ((UMMGranule) granule).getBbxWesternLongitude() != null?
Expand All @@ -530,6 +542,7 @@ private JSONObject exportSpatial() throws ParseException{
south = ((UMMGranule) granule).getBbxSouthernLatitude() != null?
((UMMGranule) granule).getBbxSouthernLatitude() : 0;
} else {
AdapterLogger.LogInfo(this.className + " BBX Else");
Set<GranuleReal> grs = granule.getGranuleRealSet();

for (GranuleReal gr : grs) {
Expand Down Expand Up @@ -565,7 +578,7 @@ private JSONObject exportSpatial() throws ParseException{
// and make sure we turn off the rangeIs360 flag
this.rangeIs360 = false;
}

AdapterLogger.LogInfo(this.className + " BBX BigDecimal Processing");
BigDecimal nrth = new BigDecimal(north);
BigDecimal sth = new BigDecimal(south);
nrth = nrth.setScale(3, RoundingMode.HALF_UP);
Expand Down Expand Up @@ -609,10 +622,14 @@ private JSONObject exportSpatial() throws ParseException{
}
}
}

if (boundingRectangles.size() > 0) {
geometry.put("BoundingRectangles", boundingRectangles);
}
}

// Export track if cycle and pass exists
if (granule instanceof UMMGranule) {
if (granule.getIsoType() == IsoType.MENDS) {
/**
* Track include cycle and passes(array).
*/
Expand Down
12 changes: 11 additions & 1 deletion src/main/java/gov/nasa/podaac/inventory/model/Granule.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
package gov.nasa.podaac.inventory.model;


import gov.nasa.cumulus.metadata.aggregator.IsoType;
import gov.nasa.podaac.inventory.api.Constant.GranuleStatus;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
Expand Down Expand Up @@ -63,6 +64,8 @@ public class Granule {
private Set<GranuleMetaHistory> metaHistorySet = new HashSet<GranuleMetaHistory>();
private Set<GranuleContact> granuleContactSet = new HashSet<GranuleContact>();
private Dataset dataset;

private IsoType isoType;

private static Log log = LogFactory.getLog(Granule.class);

Expand Down Expand Up @@ -847,7 +850,14 @@ public int compareFields(Object orig, Object inc){
}
}
}


public IsoType getIsoType() {
return isoType;
}

public void setIsoType(IsoType isoType) {
this.isoType = isoType;
}


}

0 comments on commit 4d1ee54

Please sign in to comment.