Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue 361: ignore data conversion errors #368

Merged
merged 4 commits into from
Aug 14, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
import java.util.TreeSet;
import org.opensearch.search.SearchHit;
import org.opensearch.search.SearchHits;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.fasterxml.jackson.databind.ObjectMapper;
import gov.nasa.pds.api.registry.search.HitIterator;
import gov.nasa.pds.model.Pds4Product;
Expand All @@ -16,6 +18,7 @@


public class Pds4ProductBusinessObject extends ProductBusinessLogicImpl {
private static final Logger log = LoggerFactory.getLogger(Pds4ProductBusinessObject.class);
@SuppressWarnings("unused")
private ObjectMapper objectMapper;
private Pds4Product product = null;
Expand Down Expand Up @@ -87,8 +90,16 @@ public int setResponse(HitIterator hits, Summary summary, List<String> fields) {
uniqueProperties
.addAll(ProductBusinessObject.getFilteredProperties(kvp, fields, null).keySet());

Pds4Product prod = Pds4ProductFactory.createProduct(hits.getCurrentId(), kvp, this.isJSON);
list.add(prod);
try {
Pds4Product prod = Pds4ProductFactory.createProduct(hits.getCurrentId(), kvp, this.isJSON);
list.add(prod);
} catch (Throwable t) {
String lidvid = "unknown";
if (kvp.containsKey("lidvid")) {
lidvid = kvp.get("lidvid").toString();
al-niessner marked this conversation as resolved.
Show resolved Hide resolved
}
log.error ("CRITICAL: could not convert opensearch document to Pds4Product for lidvid: " + lidvid, t);
}
}

products.setData(list);
Expand All @@ -112,8 +123,12 @@ public int setResponse(SearchHits hits, Summary summary, List<String> fields) {
uniqueProperties
.addAll(ProductBusinessObject.getFilteredProperties(fieldMap, fields, null).keySet());

Pds4Product prod = Pds4ProductFactory.createProduct(id, fieldMap, this.isJSON);
list.add(prod);
try {
Pds4Product prod = Pds4ProductFactory.createProduct(id, fieldMap, this.isJSON);
list.add(prod);
} catch (Throwable t) {
log.error ("CRITICAL: could not convert opensearch document to Pds4Product for lidvid: " + hit.getId(), t);
al-niessner marked this conversation as resolved.
Show resolved Hide resolved
}
}
products.setData(list);
products.setSummary(summary);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
import java.util.TreeSet;
import org.opensearch.search.SearchHit;
import org.opensearch.search.SearchHits;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.fasterxml.jackson.databind.ObjectMapper;
import gov.nasa.pds.api.registry.search.HitIterator;
import gov.nasa.pds.model.PdsProduct;
Expand All @@ -15,6 +17,7 @@


public class PdsProductBusinessObject extends ProductBusinessLogicImpl {
private static final Logger log = LoggerFactory.getLogger(ProductBusinessObject.class);
private ObjectMapper objectMapper;
private PdsProduct product = null;
private PdsProducts products = null;
Expand Down Expand Up @@ -62,14 +65,22 @@ public int setResponse(HitIterator hits, Summary summary, List<String> fields) {
Set<String> uniqueProperties = new TreeSet<String>();

for (Map<String, Object> kvp : hits) {
uniqueProperties
.addAll(ProductBusinessObject.getFilteredProperties(kvp, fields, null).keySet());

products.addDataItem(SearchUtil.entityProductToAPIProduct(
objectMapper.convertValue(kvp, EntityProduct.class), this.baseURL));
products.getData().get(products.getData().size() - 1)
.setProperties((Map<String, List<String>>) (Map<String, ?>) ProductBusinessObject
.getFilteredProperties(kvp, null, null));
try {
uniqueProperties
.addAll(ProductBusinessObject.getFilteredProperties(kvp, fields, null).keySet());

products.addDataItem(SearchUtil.entityProductToAPIProduct(
objectMapper.convertValue(kvp, EntityProduct.class), this.baseURL));
products.getData().get(products.getData().size() - 1)
.setProperties((Map<String, List<String>>) (Map<String, ?>) ProductBusinessObject
.getFilteredProperties(kvp, null, null));
} catch (Throwable t) {
String lidvid = "unknown";
if (kvp.containsKey("lidvid")) {
lidvid = kvp.get("lidvid").toString();
}
log.error ("CRITICAL: could not convert opensearch document to EntityProduct for lidvid: " + lidvid, t);
al-niessner marked this conversation as resolved.
Show resolved Hide resolved
}
}
count = products.getData().size();

Expand All @@ -87,15 +98,19 @@ public int setResponse(SearchHits hits, Summary summary, List<String> fields) {
Set<String> uniqueProperties = new TreeSet<String>();

for (SearchHit hit : hits) {
kvp = hit.getSourceAsMap();
uniqueProperties
.addAll(ProductBusinessObject.getFilteredProperties(kvp, fields, null).keySet());

products.addDataItem(SearchUtil.entityProductToAPIProduct(
objectMapper.convertValue(kvp, EntityProduct.class), this.baseURL));
products.getData().get(products.getData().size() - 1)
.setProperties((Map<String, List<String>>) (Map<String, ?>) ProductBusinessObject
.getFilteredProperties(kvp, null, null));
try {
kvp = hit.getSourceAsMap();
uniqueProperties
.addAll(ProductBusinessObject.getFilteredProperties(kvp, fields, null).keySet());

products.addDataItem(SearchUtil.entityProductToAPIProduct(
objectMapper.convertValue(kvp, EntityProduct.class), this.baseURL));
products.getData().get(products.getData().size() - 1)
.setProperties((Map<String, List<String>>) (Map<String, ?>) ProductBusinessObject
.getFilteredProperties(kvp, null, null));
} catch (Throwable t) {
log.error("CRITICAL: could not convert opensearch document to EntityProduct for lidvid: " + hit.getId(), t);
}
}

summary.setProperties(new ArrayList<String>(uniqueProperties));
Expand Down
2 changes: 1 addition & 1 deletion service/src/main/resources/application.properties
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ openSearch.username=admin
openSearch.password=admin
openSearch.ssl=true
# use only for development purpose, left it to true otherwise
al-niessner marked this conversation as resolved.
Show resolved Hide resolved
openSearch.sslCertificateCNVerification=true
openSearch.sslCertificateCNVerification=false

# Only show products with following archive statuses
filter.archiveStatus=archived,certified
Expand Down