Skip to content

Commit

Permalink
#472 Crosslinks - use values from queried doc
Browse files Browse the repository at this point in the history
  • Loading branch information
tariqksoliman committed Jul 17, 2024
1 parent 1568eaa commit fa8cf50
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -226,8 +226,7 @@ public ResponseEntity<Object> productCrossLinks(String identifier)
// Get product metadata that we're cross-linking between services

HashMap<String, Object> product = new HashMap<>();

/*

List<String> fields = new ArrayList<>();

try {
Expand All @@ -241,8 +240,6 @@ public ResponseEntity<Object> productCrossLinks(String identifier)
} catch (IOException | OpenSearchException e) {
throw new UnhandledException(e);
}
*/


return new ResponseEntity<Object>(this.crossLinks.getLinks(product), new HttpHeaders(), HttpStatus.OK);
}
Expand Down Expand Up @@ -310,12 +307,12 @@ private HashMap<String, Object> getLidVid(PdsProductIdentifier identifier, List<

SearchRequest searchRequest =
registrySearchRequestBuilder.addLidvidMatch(identifier).fields(fields).build();

// useless to detail here that the HashMap is parameterized <String, Object>
// because of compilation features, see
// https://stackoverflow.com/questions/2390662/java-how-do-i-get-a-class-literal-from-a-generic-type
SearchResponse<HashMap> searchResponse =
this.openSearchClient.search(searchRequest, HashMap.class);

if (searchResponse.hits().total().value() == 0) {
throw new NotFoundException("No product found with identifier " + identifier.toString());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,20 +112,20 @@ public List<String> getRef_lid_target() {
return ref_lid_target;
}

private static String getFirstElmentOrNull(List<String> l) {
private static String getFirstElementOrNull(List<String> l) {
return l != null ? l.get(0) : null;
}

public String getPDS4FileRef() {
return EntityProduct.getFirstElmentOrNull(this.pds4FileReference);
return EntityProduct.getFirstElementOrNull(this.pds4FileReference);
}

public String getStartDateTime() {
return EntityProduct.getFirstElmentOrNull(this.start_date_time);
return EntityProduct.getFirstElementOrNull(this.start_date_time);
}

public String getStopDateTime() {
return EntityProduct.getFirstElmentOrNull(this.stop_date_time);
return EntityProduct.getFirstElementOrNull(this.stop_date_time);
}

public List<String> getModificationDate() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,55 +19,48 @@ public List<Tool> getTools() {
return tools;
}

public String get(HashMap<String, Object> product, String str) {
Object obj = product.get(str);
String value = obj != null ? obj.toString() : null;
if( value != null ) {
String array[] = value.replace("[", "").replace("]", "").split(",");
return array[0];
}
return "";
}

public Object getLinks(HashMap<String, Object> product) {
// first pull out all the supported metadata from the product
//String lid = product.get("lid");

Map<String, Object> values = new HashMap<>();
String lidvid = "urn:nasa:pds:mars2020_mastcamz_ops_calibrated:data:zlf_1019_0757408892_144ras_n0490000zcam07114_1100lmj::2.0";
String filename = "NLF_1019_0757408223_941RAD_N0490000NCAM02019_0A0195J01.IMG";
String lidvid = this.get(product, "lidvid");
String filename = this.get(product, "pds:File/pds:file_name");
int filenameLastIndexOf = filename.lastIndexOf('.');
String filenameWithoutFileExtension = filename.substring(0, filenameLastIndexOf);
String fileExtension = filename.substring(filenameLastIndexOf + 1);

values.put("vid", "2.0");
values.put("lid", "urn:nasa:pds:mars2020_mastcamz_ops_calibrated:data:zlf_1019_0757408892_144ras_n0490000zcam07114_1100lmj");
values.put("vid", this.get(product, "vid"));
values.put("lid", this.get(product, "lid"));
values.put("lidvid", lidvid);
values.put("mission", "Mars2020");
values.put("spacecraft", "");
values.put("mission", this.get(product, "pds:Investigation_Area/pds:name"));
values.put("spacecraft", this.get(product, "pds:Observing_System/pds:name"));
values.put("bundle", lidvid.split(":")[3]);
values.put("collection", lidvid.split(":")[4]);
values.put("target", "Mars");
values.put("target", this.get(product, "pds:Target_Identification/pds:name"));
values.put("filename", filename);
values.put("filenameWithoutFileExtension", filenameWithoutFileExtension);
values.put("fileExtension", fileExtension);
values.put("fileRef", "/mars2020_mastcamz_ops_calibrated/data/sol/01019/ids/rdr/zcam/ZLF_1019_0757408892_144RAS_N0490000ZCAM07114_1100LMJ02.xml");
values.put("productClass", "Product_Observational");
values.put("productType", "RAS");
values.put("nodeName", "PDS_IMG");
values.put("fileRef", this.get(product, "ops:Data_File_Info/ops:file_ref"));
values.put("productClass", this.get(product, "product_class"));
values.put("productType", this.get(product, "msn:Mission_Information/msn:product_type_name"));
values.put("nodeName", this.get(product, "ops:Harvest_Info/ops:node_name"));

List<Map<String, Object>> response = new ArrayList<>();

for (Tool t : getTools()) {
response.add(formToolLink(t, values, product));
}
return response;

//return product;//"lid";
/*
vid: properties.vid
lidvid: properties.lidvid
mission: properties.pds:Investigation_Area.pds:name
spacecraft:
bundleId:
target: properties.pds:Target_Identification.pds:name
filename: properties.ops:Data_File_Info.ops:file_name
filenameWithoutFileExtension
fileExtension
fileRef: properties.ops:Data_File_Info.ops:file_ref
productClass: properties.productClass
productType: properties.mgn:Magellan_Parameters.mgn:product_type
nodeName: properties.ops:Harvest_Info.ops:node_name
*/
}

private Map<String, Object> formToolLink(Tool t, Map<String, Object> values, HashMap<String, Object> product) {
Expand Down

0 comments on commit fa8cf50

Please sign in to comment.