Skip to content

Commit

Permalink
feat: Add 'includeMethodParameter' driver config
Browse files Browse the repository at this point in the history
  • Loading branch information
peacekeeper committed Aug 4, 2024
1 parent fe2a6fb commit f553ff6
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 2 deletions.
11 changes: 11 additions & 0 deletions driver-http/src/main/java/uniregistrar/driver/http/HttpDriver.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,14 @@ public class HttpDriver implements Driver {
public static final URI DEFAULT_UPDATE_URI = null;
public static final URI DEFAULT_DEACTIVATE_URI = null;
public static final URI DEFAULT_PROPERTIES_URI = null;
public static final Boolean DEFAULT_INCLUDE_METHOD_PARAMETER = false;

private HttpClient httpClient = DEFAULT_HTTP_CLIENT;
private URI createUri = DEFAULT_CREATE_URI;
private URI updateUri = DEFAULT_UPDATE_URI;
private URI deactivateUri = DEFAULT_DEACTIVATE_URI;
private URI propertiesUri = DEFAULT_PROPERTIES_URI;
private Boolean includeMethodParameter = DEFAULT_INCLUDE_METHOD_PARAMETER;

private Consumer<Map<String, Object>> beforeWriteCreateConsumer;
private Consumer<Map<String, Object>> beforeReadCreateConsumer;
Expand Down Expand Up @@ -332,6 +334,7 @@ private Map<String, Object> getHttpProperties() {
if (this.getUpdateUri() != null) httpProperties.put("updateUri", this.getUpdateUri().toString());
if (this.getDeactivateUri() != null) httpProperties.put("deactivateUri", this.getDeactivateUri().toString());
if (this.getPropertiesUri() != null) httpProperties.put("propertiesUri", this.getPropertiesUri().toString());
if (this.getIncludeMethodParameter() != null) httpProperties.put("propertiesUri", Boolean.toString(this.getIncludeMethodParameter()));
return httpProperties;
}

Expand Down Expand Up @@ -455,6 +458,14 @@ public void setPropertiesUri(String propertiesUri) {
this.propertiesUri = URI.create(propertiesUri);
}

public Boolean getIncludeMethodParameter() {
return includeMethodParameter;
}

public void setIncludeMethodParameter(Boolean includeMethodParameter) {
this.includeMethodParameter = includeMethodParameter;
}

public Consumer<Map<String, Object>> getBeforeWriteCreateConsumer() {
return beforeWriteCreateConsumer;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ public static void configureLocalUniRegistrar(String filePath, LocalUniRegistrar
String method = jsonObjectDriver.has("method") ? jsonObjectDriver.get("method").getAsString() : null;
String url = jsonObjectDriver.has("url") ? jsonObjectDriver.get("url").getAsString() : null;
String propertiesEndpoint = jsonObjectDriver.has("propertiesEndpoint") ? jsonObjectDriver.get("propertiesEndpoint").getAsString() : null;
String includeMethodParameter = jsonObjectDriver.has("includeMethodParameter") ? jsonObjectDriver.get("includeMethodParameter").getAsString() : null;

if (method == null) throw new IllegalArgumentException("Missing 'method' entry in driver configuration.");
if (url == null) throw new IllegalArgumentException("Missing 'url' entry in driver configuration.");
Expand All @@ -52,11 +53,12 @@ public static void configureLocalUniRegistrar(String filePath, LocalUniRegistrar
driver.setUpdateUri(url + "1.0/update");
driver.setDeactivateUri(url + "1.0/deactivate");
if ("true".equals(propertiesEndpoint)) driver.setPropertiesUri(url + "1.0/properties");
if ("true".equals(includeMethodParameter)) driver.setIncludeMethodParameter(Boolean.valueOf(includeMethodParameter));

// done

drivers.put(method, driver);
if (log.isInfoEnabled()) log.info("Added driver for method '" + method + "' at " + driver.getCreateUri() + " and " + driver.getUpdateUri() + " and " + driver.getDeactivateUri() + " (" + driver.getPropertiesUri() + ")");
if (log.isInfoEnabled()) log.info("Added driver for method '" + method + "' at " + driver.getCreateUri() + " and " + driver.getUpdateUri() + " and " + driver.getDeactivateUri() + " (" + driver.getPropertiesUri() + ")" + " (" + driver.getIncludeMethodParameter() + ")");
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ public static class DriverConfig {
private String method;
private String url;
private String propertiesEndpoint;
private String includeMethodParameter;

public String getMethod() {
return method;
Expand All @@ -50,12 +51,21 @@ public void setPropertiesEndpoint(String value) {
this.propertiesEndpoint = value;
}

public String getIncludeMethodParameter() {
return includeMethodParameter;
}

public void setIncludeMethodParameter(String includeMethodParameter) {
this.includeMethodParameter = includeMethodParameter;
}

@Override
public String toString() {
return new StringJoiner(", ", DriverConfig.class.getSimpleName() + "[", "]")
.add("method='" + method + "'")
.add("url='" + url + "'")
.add("propertiesEndpoint='" + propertiesEndpoint + "'")
.add("includeMethodParameter='" + includeMethodParameter + "'")
.toString();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ public void configureLocalUniRegistrar(DriverConfigs driverConfigs, LocalUniRegi
String method = dc.getMethod();
String url = dc.getUrl();
String propertiesEndpoint = dc.getPropertiesEndpoint();
String includeMethodParameter = dc.getIncludeMethodParameter();

if (method == null) throw new IllegalArgumentException("Missing 'method' entry in driver configuration.");
if (url == null) throw new IllegalArgumentException("Missing 'url' entry in driver configuration.");
Expand All @@ -117,11 +118,12 @@ public void configureLocalUniRegistrar(DriverConfigs driverConfigs, LocalUniRegi
driver.setUpdateUri(normalizeUri((url + servletMappings.getUpdate()), false));
driver.setDeactivateUri(normalizeUri((url + servletMappings.getDeactivate()), false));
if ("true".equals(propertiesEndpoint)) driver.setPropertiesUri(normalizeUri((url + servletMappings.getProperties()), false));
if ("true".equals(includeMethodParameter)) driver.setIncludeMethodParameter(Boolean.valueOf(includeMethodParameter));

// done

drivers.put(method, driver);
if (log.isInfoEnabled()) log.info("Added driver for method '" + method + "' at " + driver.getCreateUri() + " and " + driver.getUpdateUri() + " and " + driver.getDeactivateUri() + " (" + driver.getPropertiesUri() + ")");
if (log.isInfoEnabled()) log.info("Added driver for method '" + method + "' at " + driver.getCreateUri() + " and " + driver.getUpdateUri() + " and " + driver.getDeactivateUri() + " (" + driver.getPropertiesUri() + ")" + " (" + driver.getIncludeMethodParameter() + " )");
}

uniRegistrar.setDrivers(drivers);
Expand Down

0 comments on commit f553ff6

Please sign in to comment.