-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Yen, David (398B-Affiliate)
committed
May 11, 2024
1 parent
c179ad4
commit 513c7bc
Showing
48 changed files
with
4,704 additions
and
178 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
src/main/java/gov/nasa/cumulus/metadata/aggregator/bo/TaskConfigBO.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package gov.nasa.cumulus.metadata.aggregator.bo; | ||
|
||
import gov.nasa.cumulus.metadata.state.MENDsIsoXMLSpatialTypeEnum; | ||
|
||
import java.util.ArrayList; | ||
import java.util.HashMap; | ||
import java.util.HashSet; | ||
|
||
public class TaskConfigBO { | ||
HashSet<MENDsIsoXMLSpatialTypeEnum> isoXMLSpatialTypeHashSet; | ||
ArrayList<HashMap<String, String>> subTypeHashArray = new ArrayList<>(); | ||
|
||
public TaskConfigBO() {} | ||
|
||
public HashSet<MENDsIsoXMLSpatialTypeEnum> getIsoXMLSpatialTypeHashSet() { | ||
return isoXMLSpatialTypeHashSet; | ||
} | ||
|
||
public void setIsoXMLSpatialTypeHashSet(HashSet<MENDsIsoXMLSpatialTypeEnum> isoXMLSpatialTypeHashSet) { | ||
this.isoXMLSpatialTypeHashSet = isoXMLSpatialTypeHashSet; | ||
} | ||
|
||
public ArrayList<HashMap<String, String>> getSubTypeHashArray() { | ||
return subTypeHashArray; | ||
} | ||
|
||
public void setSubTypeHashArray(ArrayList<HashMap<String, String>> subTypeHashArray) { | ||
this.subTypeHashArray = subTypeHashArray; | ||
} | ||
} |
71 changes: 71 additions & 0 deletions
71
src/main/java/gov/nasa/cumulus/metadata/aggregator/factory/TaskConfigFactory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
package gov.nasa.cumulus.metadata.aggregator.factory; | ||
|
||
import cumulus_message_adapter.message_parser.AdapterLogger; | ||
import gov.nasa.cumulus.metadata.aggregator.bo.TaskConfigBO; | ||
import gov.nasa.cumulus.metadata.state.MENDsIsoXMLSpatialTypeEnum; | ||
import org.apache.commons.lang3.StringUtils; | ||
import org.json.simple.JSONArray; | ||
import org.json.simple.JSONObject; | ||
|
||
import java.util.ArrayList; | ||
import java.util.HashMap; | ||
import java.util.HashSet; | ||
|
||
public class TaskConfigFactory { | ||
static String className = "gov.nasa.cumulus.metadata.aggregator.factory.TaskConfigFactory"; | ||
|
||
public static TaskConfigBO createTaskConfigBO(JSONObject config) { | ||
TaskConfigBO taskConfigBO = new TaskConfigBO(); | ||
//Construct isoXMLSpatialTypeHashset | ||
JSONArray isoXMLSpatialTypeJsonArray = (JSONArray) config.get("isoXMLSpatialType"); | ||
taskConfigBO.setIsoXMLSpatialTypeHashSet(createIsoXMLSpatialTypeSet(isoXMLSpatialTypeJsonArray)); | ||
//Construct subTypeHashArray | ||
JSONArray subTypeTypeJsonArray = (JSONArray) config.get("relatedUrlSubTypeMap"); | ||
taskConfigBO.setSubTypeHashArray(createSubTypeHashArray(subTypeTypeJsonArray)); | ||
return taskConfigBO; | ||
|
||
} | ||
|
||
public static HashSet<MENDsIsoXMLSpatialTypeEnum> createIsoXMLSpatialTypeSet(JSONArray isoXMLSpatialTypeConfigJSONArray) throws IllegalArgumentException{ | ||
HashSet<MENDsIsoXMLSpatialTypeEnum> isoSpatialTypes = new HashSet<>(); | ||
// if not containing isoXMLTypes, then return an empty HashSet | ||
if(isoXMLSpatialTypeConfigJSONArray == null || isoXMLSpatialTypeConfigJSONArray.size()==0) { | ||
return isoSpatialTypes; | ||
} | ||
isoXMLSpatialTypeConfigJSONArray.forEach(item -> { | ||
String t = (String) item; | ||
MENDsIsoXMLSpatialTypeEnum en = MENDsIsoXMLSpatialTypeEnum.getEnum(getIsoXMLSpatialTypeStr(t)); | ||
isoSpatialTypes.add(en); | ||
}); | ||
AdapterLogger.LogDebug(className + " isoSpatialTypes HashSet: " + isoSpatialTypes); | ||
return isoSpatialTypes; | ||
} | ||
|
||
public static String getIsoXMLSpatialTypeStr(String token) { | ||
final String trimmedToken = StringUtils.trim(token); | ||
String s; | ||
try { | ||
s = MENDsIsoXMLSpatialTypeEnum.getEnumValuList().stream() | ||
.filter(e -> StringUtils.equals(trimmedToken, e)).findFirst().get(); | ||
} catch (java.util.NoSuchElementException e) { | ||
s = ""; | ||
} | ||
return s; | ||
} | ||
|
||
public static ArrayList<HashMap<String, String>> createSubTypeHashArray(JSONArray jsonArray) { | ||
ArrayList<HashMap<String, String>> subTypeHashArray = new ArrayList<>(); | ||
if(jsonArray !=null && jsonArray.size()>0) { | ||
jsonArray.forEach(item -> { | ||
String regex = ((JSONObject) item).get("regex").toString(); | ||
String subType = ((JSONObject) item).get("subType").toString(); | ||
HashMap<String, String> mapper = new HashMap<>(); | ||
mapper.put("regex", regex); | ||
mapper.put("subType", subType); | ||
subTypeHashArray.add(mapper); | ||
}); | ||
} | ||
return subTypeHashArray; | ||
} | ||
|
||
} |
54 changes: 54 additions & 0 deletions
54
src/main/java/gov/nasa/cumulus/metadata/aggregator/processor/RelatedUrlsProcessor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package gov.nasa.cumulus.metadata.aggregator.processor; | ||
|
||
import gov.nasa.cumulus.metadata.aggregator.bo.TaskConfigBO; | ||
import org.json.simple.JSONArray; | ||
import org.json.simple.JSONObject; | ||
import org.json.simple.parser.JSONParser; | ||
|
||
import java.util.ArrayList; | ||
import java.util.HashMap; | ||
|
||
/** | ||
* this class is a post-processing of created umm-g | ||
* by appending relatedUrl items into RelatedUrls array based on | ||
* | ||
* if any item within payload.granules[0].files[] matched collection configurations meta.subTypeMap array's | ||
* regex | ||
*/ | ||
public class RelatedUrlsProcessor { | ||
public void RelatedUrlsProcessor() { | ||
} | ||
|
||
public JSONObject appendSubTypes(JSONObject granuleJson, TaskConfigBO taskConfigBO, JSONArray files) { | ||
ArrayList<HashMap<String, String>> subTypeHashArray=taskConfigBO.getSubTypeHashArray(); | ||
JSONArray relateUrlsArray = (JSONArray) granuleJson.get("RelatedUrls"); | ||
// 1: Loop through the existing RelatedUrls array to find any match for the subType regex. | ||
// for the finding match, set Subtype to | ||
for(int i=0; i<relateUrlsArray.size(); i++) { | ||
JSONObject relatedUrlJson = (JSONObject) relateUrlsArray.get(i); | ||
String URLStr=relatedUrlJson.get("URL").toString(); | ||
for(HashMap<String, String> subTypeHash : subTypeHashArray) { | ||
if(URLStr.matches(subTypeHash.get("regex"))) { | ||
relatedUrlJson.put("Subtype", subTypeHash.get("subType")); | ||
} | ||
} | ||
} | ||
// 2: Loop through the existing Input files:[] array to find any match for the subType regex. | ||
// for the finding match, append a new RelatedUrl item with Subtype set to subTypeHash.get("subType") | ||
for(Object file: files) { | ||
JSONObject fileJson = (JSONObject) file; | ||
String source = fileJson.get("source").toString(); | ||
for(HashMap<String, String> subTypeHash : subTypeHashArray) { | ||
if(source.matches(subTypeHash.get("regex"))) { | ||
JSONObject relatedUrl = new JSONObject(); | ||
relatedUrl.put("URL", source); | ||
relatedUrl.put("Type", "GET DATA"); | ||
relatedUrl.put("Subtype", subTypeHash.get("subType")); | ||
relateUrlsArray.add(relatedUrl); | ||
} | ||
} | ||
} | ||
return granuleJson; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.