* @throws ConfigException if an error is encountered. More specific information can be found in
* the exception's statusCode.
*/
@Override
protected Optional<Map<String, String>> _call() {
final ConfigDatabase config = configDatabase();
switch (action) {
case CONFIG_GET: {
if (name == null || name.isEmpty())
throw new ConfigException(StatusCode.SECTION_OR_NAME_NOT_PROVIDED);
if (value == null || value.isEmpty()) {
Optional<String> val = Optional.absent();
if (scope == ConfigScope.GLOBAL) {
val = config.getGlobal(name);
} else {
try {
val = config.get(name);
} catch (ConfigException e) {
if (scope == ConfigScope.LOCAL) {
throw new ConfigException(e.statusCode);
}
}
// Fallback on global config file if name wasn't found locally
if (!val.isPresent()) {
val = config.getGlobal(name);
}
}
if (val.isPresent()) {
Map<String, String> resultMap = new HashMap<String, String>();
resultMap.put(name, val.get());
return Optional.of(resultMap);
}
} else {
throw new ConfigException(StatusCode.TOO_MANY_ARGS);
}
break;
}
case CONFIG_SET: {
if (name == null || name.isEmpty())
throw new ConfigException(StatusCode.SECTION_OR_NAME_NOT_PROVIDED);
if (scope == ConfigScope.GLOBAL) {
config.putGlobal(name, value);
} else {
config.put(name, value);
}
break;
}
case CONFIG_UNSET: {
if (name == null || name.isEmpty())
throw new ConfigException(StatusCode.SECTION_OR_NAME_NOT_PROVIDED);
if (scope == ConfigScope.GLOBAL) {
config.removeGlobal(name);
} else {
config.remove(name);
}
break;
}
case CONFIG_REMOVE_SECTION: {
if (name == null || name.isEmpty())
throw new ConfigException(StatusCode.SECTION_OR_NAME_NOT_PROVIDED);
if (scope == ConfigScope.GLOBAL) {
config.removeSectionGlobal(name);
} else {
config.removeSection(name);
}
break;
}
case CONFIG_LIST: {
Map<String, String> results = null;
if (scope == ConfigScope.LOCAL) {
results = config.getAll();
} else {
results = config.getAllGlobal();
if (scope == ConfigScope.DEFAULT) {
try {
Map<String, String> localresults = config.getAll();
results.putAll(localresults);
} catch (ConfigException e) {