Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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 @@ -13,10 +13,17 @@
*/
package org.trellisldp.app.config;

import static java.util.Collections.synchronizedMap;

import com.fasterxml.jackson.annotation.JsonAnyGetter;
import com.fasterxml.jackson.annotation.JsonAnySetter;
import com.fasterxml.jackson.annotation.JsonProperty;

import io.dropwizard.Configuration;

import java.util.HashMap;
import java.util.Map;

import javax.validation.constraints.NotNull;

/**
Expand Down Expand Up @@ -63,6 +70,8 @@ public class TrellisConfiguration extends Configuration {

private String resourceLocation = null;

private final Map<String, Object> extras = synchronizedMap(new HashMap<>());

/**
* Get the base URL for the partition.
* @return the partition baseURL
Expand Down Expand Up @@ -171,6 +180,27 @@ public String getResources() {
return resourceLocation;
}

/**
* Set an extra configuration value.
* @param name the name of this config value
* @param value the value to set
* @return this config for chaining
*/
@JsonAnySetter
public TrellisConfiguration setAdditionalConfig(final String name, final Object value) {
extras.put(name, value);
return this;
}

/**
* Get any extra metadata.
* @return a {@link Map} of any extra metadata
*/
@JsonAnyGetter
public Map<String, Object> any() {
return extras;
}

/**
* Set the cache max-age value.
* @param cacheMaxAge the cache max age header value
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
*/
package org.trellisldp.app.config;

import static com.google.common.collect.Lists.newArrayList;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNull;
Expand All @@ -23,6 +24,8 @@
import io.dropwizard.jersey.validation.Validators;

import java.io.File;
import java.util.List;
import java.util.Map;

import org.junit.jupiter.api.Test;
import org.junit.platform.runner.JUnitPlatform;
Expand All @@ -49,6 +52,14 @@ public void testConfigurationGeneral1() throws Exception {
assertNull(config.getResources());
assertEquals((Integer) 2, config.getBinaryHierarchyLevels());
assertEquals((Integer) 1, config.getBinaryHierarchyLength());
assertEquals("my.cluster.node", config.any().get("cassandraAddress"));
assertEquals((Integer)245993, config.any().get("cassandraPort"));
@SuppressWarnings("unchecked")
final Map<String, Object> extraConfig = (Map<String, Object>) config.any().get("extraConfigValues");
assertTrue((Boolean) extraConfig.get("one"));
@SuppressWarnings("unchecked")
final List<String> list = (List<String>) extraConfig.get("two");
assertEquals(newArrayList("value1", "value2"), list);
}


Expand Down
10 changes: 10 additions & 0 deletions trellis-app/src/test/resources/config1.yml
Original file line number Diff line number Diff line change
Expand Up @@ -77,3 +77,13 @@ cors:

binaryHierarchyLevels: 2
binaryHierarchyLength: 1

cassandraAddress: my.cluster.node
cassandraPort: 245993

extraConfigValues:
one: true
two:
- "value1"
- "value2"