diff --git a/src/main/java/gov/nasa/cumulus/metadata/aggregator/CMRLambdaRestClient.java b/src/main/java/gov/nasa/cumulus/metadata/aggregator/CMRLambdaRestClient.java index a059372..df41d3b 100644 --- a/src/main/java/gov/nasa/cumulus/metadata/aggregator/CMRLambdaRestClient.java +++ b/src/main/java/gov/nasa/cumulus/metadata/aggregator/CMRLambdaRestClient.java @@ -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; @@ -105,7 +104,6 @@ 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) { @@ -113,7 +111,6 @@ public String getToken() 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; @@ -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); @@ -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()) ); @@ -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; } @@ -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; diff --git a/src/main/java/gov/nasa/cumulus/metadata/aggregator/CMRRestClient.java b/src/main/java/gov/nasa/cumulus/metadata/aggregator/CMRRestClient.java index bc91291..a87ce25 100644 --- a/src/main/java/gov/nasa/cumulus/metadata/aggregator/CMRRestClient.java +++ b/src/main/java/gov/nasa/cumulus/metadata/aggregator/CMRRestClient.java @@ -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 { diff --git a/src/main/java/gov/nasa/cumulus/metadata/aggregator/IsoGranule.java b/src/main/java/gov/nasa/cumulus/metadata/aggregator/IsoGranule.java index 44265c2..9de4709 100644 --- a/src/main/java/gov/nasa/cumulus/metadata/aggregator/IsoGranule.java +++ b/src/main/java/gov/nasa/cumulus/metadata/aggregator/IsoGranule.java @@ -20,7 +20,7 @@ public class IsoGranule extends UMMGranule { private List inputGranules; private String PGEVersionClass; - private IsoType isoType; + public IsoGranule() { this.identifiers = new HashMap<>(); @@ -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; - } } diff --git a/src/main/java/gov/nasa/cumulus/metadata/aggregator/MetadataFilesToEcho.java b/src/main/java/gov/nasa/cumulus/metadata/aggregator/MetadataFilesToEcho.java index fd9c0a3..dd90313 100644 --- a/src/main/java/gov/nasa/cumulus/metadata/aggregator/MetadataFilesToEcho.java +++ b/src/main/java/gov/nasa/cumulus/metadata/aggregator/MetadataFilesToEcho.java @@ -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 " + @@ -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")); @@ -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 @@ -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(); diff --git a/src/main/java/gov/nasa/cumulus/metadata/aggregator/UMMGranuleFile.java b/src/main/java/gov/nasa/cumulus/metadata/aggregator/UMMGranuleFile.java index e796080..a8efc04 100644 --- a/src/main/java/gov/nasa/cumulus/metadata/aggregator/UMMGranuleFile.java +++ b/src/main/java/gov/nasa/cumulus/metadata/aggregator/UMMGranuleFile.java @@ -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. @@ -430,6 +433,7 @@ private boolean shouldAddBBx(Granule granule) { && StringUtils.isNotEmpty(((IsoGranule) granule).getPolygon())) { shouldAddBBx = false; } + AdapterLogger.LogInfo(this.className + " shouldAddBBx:" + shouldAddBBx); return shouldAddBBx; } @@ -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) { /** @@ -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)) { @@ -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); @@ -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? @@ -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 grs = granule.getGranuleRealSet(); for (GranuleReal gr : grs) { @@ -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); @@ -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). */ diff --git a/src/main/java/gov/nasa/podaac/inventory/model/Granule.java b/src/main/java/gov/nasa/podaac/inventory/model/Granule.java index 802e90b..0968d4d 100644 --- a/src/main/java/gov/nasa/podaac/inventory/model/Granule.java +++ b/src/main/java/gov/nasa/podaac/inventory/model/Granule.java @@ -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; @@ -63,6 +64,8 @@ public class Granule { private Set metaHistorySet = new HashSet(); private Set granuleContactSet = new HashSet(); private Dataset dataset; + + private IsoType isoType; private static Log log = LogFactory.getLog(Granule.class); @@ -847,7 +850,14 @@ public int compareFields(Object orig, Object inc){ } } } - + + public IsoType getIsoType() { + return isoType; + } + + public void setIsoType(IsoType isoType) { + this.isoType = isoType; + } }