Skip to content

Commit

Permalink
Merge pull request #930 from NASA-PDS/issue_923
Browse files Browse the repository at this point in the history
923: throw error for unknowns
  • Loading branch information
jordanpadams committed Jun 12, 2024
2 parents d127665 + 6600b84 commit cada831
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 4 deletions.
22 changes: 18 additions & 4 deletions src/main/java/gov/nasa/pds/validate/ValidateLauncher.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
Expand All @@ -65,6 +66,7 @@
import org.apache.commons.cli.HelpFormatter;
import org.apache.commons.cli.Option;
import org.apache.commons.cli.ParseException;
import org.apache.commons.cli.UnrecognizedOptionException;
import org.apache.commons.configuration.AbstractConfiguration;
import org.apache.commons.configuration.Configuration;
import org.apache.commons.configuration.ConfigurationException;
Expand All @@ -73,7 +75,7 @@
import org.apache.solr.client.solrj.SolrClient;
import org.apache.solr.client.solrj.SolrQuery;
import org.apache.solr.client.solrj.SolrServerException;
import org.apache.solr.client.solrj.impl.HttpSolrClient;
import org.apache.solr.client.solrj.impl.Http2SolrClient;
import org.apache.solr.client.solrj.response.QueryResponse;
import org.apache.solr.common.SolrDocument;
import org.apache.solr.common.SolrDocumentList;
Expand Down Expand Up @@ -513,7 +515,7 @@ private void getLatestJsonContext() {
String endpoint = ToolInfo.getEndpoint();
String query = ToolInfo.getQuery();

SolrClient client = new HttpSolrClient.Builder(url).build();
SolrClient client = new Http2SolrClient.Builder(url).build();
SolrQuery solrQuery = new SolrQuery(query);
solrQuery.setRequestHandler("/" + endpoint);
solrQuery.setStart(0);
Expand Down Expand Up @@ -676,9 +678,21 @@ private void copyFile(File source, File dest) throws IOException {
*/
public void query(File configuration) throws ConfigurationException {
try {
Configuration config = null;
AbstractConfiguration.setDefaultListDelimiter(',');
config = new PropertiesConfiguration(configuration);
Configuration config = new PropertiesConfiguration(configuration);
Iterator<String> keys = config.getKeys();
String unknowns = "";

while (keys.hasNext()) {
String key = keys.next();
if (!ConfigKey.ALL_KEYWORDS.contains(key)) {
if (unknowns.isBlank()) unknowns = key;
else unknowns += ", " + key;
}
}
if (!unknowns.isBlank()) {
throw new UnrecognizedOptionException("Unrecognized keyword(s) in given configuration file: " + unknowns);
}

List<String> targetList = new ArrayList<>();
if (config.isEmpty()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@

package gov.nasa.pds.validate.commandline.options;

import java.lang.reflect.Field;
import java.lang.reflect.Modifier;
import java.util.HashSet;
import java.util.Set;

/**
* An interface that contains the valid property keys for the Validate Tool configuration file.
*
Expand Down Expand Up @@ -159,4 +164,26 @@ public class ConfigKey {
public static final String TARGET_MANIFEST = "validate.targetManifest";

public static final String SKIP_PRODUCT_VALIDATION = "validate.ignoreProductValidation";

/* dumb way to fix this, but this class should have been enum to start with and now it is too late
*
* Declare a Set then put all the values in it. This way we can check that values in the
* config file are allowable. As currently written it is simple to expand this list but
* not include an update later checks if it is valid or not. Really, this is just a smelly
* code hack for bad design choice back when it was a quick and dirty tool.
*/
public static final Set<String> ALL_KEYWORDS;
static {
ALL_KEYWORDS = new HashSet<String>();
for (Field field : ConfigKey.class.getDeclaredFields()) {
if (Modifier.isStatic(field.getModifiers()) && field.getType().equals(String.class)) {
try {
ALL_KEYWORDS.add(field.get(null).toString());
} catch (IllegalArgumentException | IllegalAccessException e) {
// can we ever get here??
throw new IllegalStateException("Got to place we should not be able to reach.", e);
}
}
}
}
}

0 comments on commit cada831

Please sign in to comment.