Skip to content

Commit

Permalink
import adapters config list to map
Browse files Browse the repository at this point in the history
  • Loading branch information
alx652 committed Mar 8, 2024
1 parent 2bceef8 commit b9cc1ef
Show file tree
Hide file tree
Showing 4 changed files with 85 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@
@Slf4j
public class GsrsFactoryConfiguration {

private Map<String, Map<String,Map<String, Object>>> validators;
private Map<String, Map<String, Map<String, Object>>> validators;

private Map<String, List<Map<String, Object>>> importAdapterFactories;
private Map<String, Map<String, Map<String, Object>>> importAdapterFactories;

private Map<String, List<Map<String, Object>>> matchableCalculators;

Expand Down Expand Up @@ -146,16 +146,40 @@ public List<? extends ImportAdapterFactoryConfig> getImportAdapterFactories(Stri
return Collections.emptyList();
}
try {
List<Map<String, Object>> list = importAdapterFactories.get(context);
log.trace("list (before):");
list.forEach(i -> i.keySet().forEach(k -> log.trace("key: {}; value: {}", k, i.get(k))));
Map<String, Map<String, Object>> map = importAdapterFactories.get(context);
log.trace("map (before):");

if (list == null || list.isEmpty()) {
// fix this later
// list.forEach(i -> i.keySet().forEach(k -> log.trace("key: {}; value: {}", k, i.get(k))));

if (map == null || map.isEmpty()) {
log.warn("no import adapter factory configuration info found!");
return Collections.emptyList();
}

// Copy the key into the Object for quality control and maybe as a way to access by key from the list
for (String k: map.keySet()) {
map.get(k).put("key", k);
}

// By the time we are here all conf files have been processed

List<Object> list = map.values().stream().collect(Collectors.toList());

List<? extends ImportAdapterFactoryConfig> configs = EntityUtils.convertClean(list, new TypeReference<List<? extends ImportAdapterFactoryConfig>>() {
});

System.out.println("Import adapter factory configurations found before filtering: " + configs.size());

configs = configs.stream().filter(a->!a.isDisabled()).sorted(Comparator.comparing(a->a.getOrder(),nullsFirst(naturalOrder()))).collect(Collectors.toList());

System.out.println("Import adapter factory configurations active after filtering: " + configs.size());

System.out.println(String.format("%s|%s|%s|%s", "ImportAdapterFactoryConfig", "class", "key", "order", "isDisabled"));
for (ImportAdapterFactoryConfig config : configs) {
System.out.println(String.format("%s|%s|%s|%s", "ImportAdapterFactoryConfig", config.getImportAdapterFactoryClass(), config.getKey(), config.getOrder(), config.isDisabled()));
}

//log.trace("list (after):");
//configs.forEach(c-> log.trace("name: {}; desc: {}; ext: {}", c.getAdapterName(), c.getDescription(), c.getSupportedFileExtensions()));
return configs;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@ public class DefaultImportAdapterFactoryConfig implements ImportAdapterFactoryCo
//private List<ActionConfig> actions;
private List<String> extensions;
private String adapterName;

private String key;
private Double order;
private boolean disabled = false;

private Map<String, Object> parameters;
private String stagingAreaServiceClass;
private List<Class> entityServices;
Expand Down Expand Up @@ -78,6 +83,37 @@ public void setImportAdapterFactoryClass(Class importAdapterFactoryClass) {
this.importAdapterFactoryClass = importAdapterFactoryClass;
}

@Override
public String getKey() {
return this.key;
}

@Override
public void setKey(String key) {
this.key = key;
}

@Override
public Double getOrder() {
return this.order;
}

@Override
public void setOrder(Double order) {
this.order = order;
}

@Override
public boolean isDisabled() {
return this.disabled;
}

@Override
public void setDisabled(boolean disabled) {
this.disabled = disabled;
}


@Override
public Map<String, Object> getParameters() {
return parameters;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,16 @@ public interface ImportAdapterFactoryConfig {

void setImportAdapterFactoryClass(Class importAdapterFactoryClass);

String getKey();
void setKey(String key);


Double getOrder();
void setOrder(Double order);

boolean isDisabled();
void setDisabled(boolean disabled);

Map<String, Object> getParameters();
void setParameters(Map<String, Object> params);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ public class TestDefaultImportAdapterFactoryConfig {
@Test
@Disabled
public void testSetup() throws ClassNotFoundException, IllegalAccessException, NoSuchFieldException {
// AW: this test does not work, I modified it a bit to not cause build error
// The test was "disabled" before I made these code changes.
// AW: to check with MM on why it was disabled.

String substanceContext="substances";
GsrsFactoryConfiguration config = new GsrsFactoryConfiguration();
Map<String, String> stagingAreaService = new HashMap<>();
Expand All @@ -24,15 +28,17 @@ public void testSetup() throws ClassNotFoundException, IllegalAccessException, N
entityService.put("substances", "gsrs.stagingarea.service.StagingAreaEntityService");
config.setDefaultStagingAreaEntityService(entityService);

Map<String, List<Map<String,Object>>> adapterConfig = new HashMap<>();
Map<String, Map<String,Map<String,Object>>> adapterConfig = new HashMap<>();
Map<String,Object> oneAdapter = new HashMap<>();

oneAdapter.put("key", "SDFImportAdaptorFactory");
oneAdapter.put("importAdapterFactoryClass", "gsrs.module.substance.importers.SDFImportAdaptorFactory");
oneAdapter.put("adapterName", "NSRS SDF Adapter");
oneAdapter.put("extensions", new String[] {"sdf", "sd"});
oneAdapter.put("parameters", buildConfigParameters());
oneAdapter.put("description", "general description");
List<Map<String,Object>> adapters = new ArrayList<>();
adapters.add(oneAdapter);
Map<String, Map<String,Object>> adapters = new HashMap<>();
adapters.put((String)oneAdapter.get("key"), oneAdapter);
adapterConfig.put(substanceContext, adapters);
config.setImportAdapterFactories(adapterConfig);

Expand Down

0 comments on commit b9cc1ef

Please sign in to comment.