Skip to content

Commit

Permalink
Merge branch 'develop' into feature/PODAAC-5708
Browse files Browse the repository at this point in the history
  • Loading branch information
Yen, David (398B-Affiliate) committed Aug 10, 2023
2 parents 1e7ad9c + 6404ff8 commit d643cc4
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 14 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [8.4.0]
### Added
- Update metadata aggregator to add description to image variables from image processor and test tig forge processor
### Deprecated
### Removed
### Fixed
Expand Down Expand Up @@ -526,4 +527,4 @@ Note: This is the first release where we are consolidating DMAS changes with Cum

### Fixed

### Security
### Security
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>gov.nasa.podaac</groupId>
<artifactId>cumulus-metadata-aggregator</artifactId>
<version>8.4.0-alpha.1-SNAPSHOT</version>
<version>8.4.0-alpha.2-SNAPSHOT</version>
<packaging>jar</packaging>

<name>Metadata-Aggregator</name>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
import java.math.BigInteger;
import java.net.URISyntaxException;
import java.nio.file.Paths;
import java.util.Iterator;


public class ImageProcessor extends ProcessorBase{
private final String className = this.getClass().getName();
Expand Down Expand Up @@ -79,18 +81,26 @@ public String appendImageUrl(String input, String cmrString)
JsonObject fileObj = f.getAsJsonObject();
String filename = StringUtils.trim(f.getAsJsonObject().get("fileName").getAsString());
if(isImageFile(filename)) {

String downloadUrl = getImageDownloadUrl(distribution_endpoint, fileObj.get("bucket").getAsString(),
fileObj.get("key").getAsString());
if(!isDownloadUrlAlreadyExist(relatedUrls, downloadUrl)) {
RelatedUrlType relatedUrlType = new RelatedUrlType();
relatedUrlType.setUrl(downloadUrl);
relatedUrlType.setType(RelatedUrlType.RelatedUrlTypeEnum.GET_RELATED_VISUALIZATION);
relatedUrlType.setSubtype(RelatedUrlType.RelatedUrlSubTypeEnum.DIRECT_DOWNLOAD);
relatedUrlType.setMimeType(getImageMimeType(filename));

String relatedUrlTypeStr = gsonBuilder.toJson(relatedUrlType);
relatedUrls.add(JsonParser.parseString(relatedUrlTypeStr));

// remove the related url if it already exists in related urls
removeExistingUrls(relatedUrls, downloadUrl);

// add related url for the new images in case something has changed
RelatedUrlType relatedUrlType = new RelatedUrlType();
relatedUrlType.setUrl(downloadUrl);
relatedUrlType.setType(RelatedUrlType.RelatedUrlTypeEnum.GET_RELATED_VISUALIZATION);
relatedUrlType.setSubtype(RelatedUrlType.RelatedUrlSubTypeEnum.DIRECT_DOWNLOAD);
relatedUrlType.setMimeType(getImageMimeType(filename));

if(fileObj.has("description")){
relatedUrlType.setDescription(fileObj.get("description").getAsString());
}

String relatedUrlTypeStr = gsonBuilder.toJson(relatedUrlType);
relatedUrls.add(JsonParser.parseString(relatedUrlTypeStr));
}
}
String newCMRStr = gsonBuilder.toJson(cmrJsonObj);
Expand All @@ -106,11 +116,23 @@ public boolean isDownloadUrlAlreadyExist(JsonArray relatedUrls, String downloadU
downloadUrl = StringUtils.trim(downloadUrl);
for (JsonElement relatdUrl : relatedUrls) {
String umg_downloadUrl = StringUtils.trim(relatdUrl.getAsJsonObject().get("URL").getAsString());
if(StringUtils.compare(umg_downloadUrl, downloadUrl) ==0) return true;
if(StringUtils.compare(umg_downloadUrl, downloadUrl) == 0) return true;
}
return false;
}

public void removeExistingUrls(JsonArray relatedUrls, String downloadUrl) {
downloadUrl = StringUtils.trim(downloadUrl);
Iterator<JsonElement> iterator = relatedUrls.iterator();
while (iterator.hasNext()) {
JsonElement relatedUrlElement = iterator.next();
String umg_downloadUrl = StringUtils.trim(relatedUrlElement.getAsJsonObject().get("URL").getAsString());
if (StringUtils.compareIgnoreCase(umg_downloadUrl, downloadUrl) == 0) {
iterator.remove();
}
}
}

public boolean isImageFile(String filename) {
return StringUtils.endsWith(filename, ".jpg") ||
StringUtils.endsWith(filename, ".png") ||
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@
AggregatorRelease_4_3_0_Test.class,
gov.nasa.cumulus.metadata.test.MetadataFilesToEchoTest.class,
gov.nasa.cumulus.metadata.test.UMMTest.class,

gov.nasa.cumulus.metadata.test.ImageProcessorTest.class,
gov.nasa.cumulus.metadata.test.FootprintProcessorTest.class,

})
public class AggregatorTestSuite {
// the class remains completely empty,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ public void testGetImageDownloadUrl_URISyntaxException() {

@Test
public void testAppendImageUrl() {

try {
/**
* From the input message , the distribution_endpoint is set to be:
Expand All @@ -127,12 +128,22 @@ public void testAppendImageUrl() {
"https://distribution_endpoint.jpl.nasa.gov/s3distribute/dyen-cumulus-public/dataset-image/MODIS_A-JPL-L2P-v2019.0/standard-deviation.jpg");
assertEquals(count, 1);

// test description
for (JsonElement relatedUrl : relatedUrls) {
JsonObject fileObj = relatedUrl.getAsJsonObject();
String ummg_downloadUrl = StringUtils.trim(fileObj.get("URL").getAsString());
if(ummg_downloadUrl.equals("https://distribution_endpoint.jpl.nasa.gov/s3distribute/dyen-cumulus-public/dataset-image/MODIS_A-JPL-L2P-v2019.0/sst.png")){
assertEquals(fileObj.get("Description").getAsString(), "sst");
}
}

} catch (URISyntaxException | IOException pe) {
System.out.println("testAppendImageUrl Error:" + pe);
pe.printStackTrace();
}
}


int findTimesOfAppearance(JsonArray relatedUrls, String downloadUrl) {
int count = 0;
downloadUrl = StringUtils.trim(downloadUrl);
Expand Down
3 changes: 2 additions & 1 deletion src/test/resources/cumulus_message_input_example.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@
"key": "dataset-image/MODIS_A-JPL-L2P-v2019.0/sst.png",
"size": 7152,
"fileName": "sst.png",
"type": "metadata"
"type": "metadata",
"description": "sst"
},
{
"bucket": "dyen-cumulus-public",
Expand Down

0 comments on commit d643cc4

Please sign in to comment.