in src/main/java/com/googlesource/gerrit/plugins/lfs/PutLfsGlobalConfig.java [67:125]
public Response<LfsGlobalConfigInfo> apply(ProjectResource resource, LfsGlobalConfigInput input)
throws RestApiException {
adminView.validate(resource);
Project.NameKey projectName = resource.getNameKey();
if (input == null) {
input = new LfsGlobalConfigInput();
}
LfsProjectsConfig config = lfsConfigFactory.getProjectsConfig();
try (MetaDataUpdate md = metaDataUpdateFactory.get().create(projectName)) {
try {
config.load(md);
} catch (ConfigInvalidException | IOException e) {
throw new ResourceConflictException("Cannot read LFS config in " + projectName);
}
Config cfg = new Config();
if (input.namespaces != null) {
Set<String> backends = lfsConfigFactory.getGlobalConfig().getBackends().keySet();
Set<Entry<String, LfsProjectConfigInfo>> namespaces = input.namespaces.entrySet();
for (Map.Entry<String, LfsProjectConfigInfo> namespace : namespaces) {
LfsProjectConfigInfo info = namespace.getValue();
if (info.enabled != null) {
cfg.setBoolean(pluginName, namespace.getKey(), KEY_ENABLED, info.enabled);
}
if (info.maxObjectSize != null) {
cfg.setLong(pluginName, namespace.getKey(), KEY_MAX_OBJECT_SIZE, info.maxObjectSize);
}
if (info.readOnly != null) {
cfg.setBoolean(pluginName, namespace.getKey(), KEY_READ_ONLY, info.readOnly);
}
if (!Strings.isNullOrEmpty(info.backend)) {
if (!backends.contains(info.backend)) {
throw new ResourceConflictException(
String.format(
"Namespace %s: backend %s does not exist", namespace, info.backend));
}
cfg.setString(pluginName, namespace.getKey(), KEY_BACKEND, info.backend);
}
}
}
config.setProjectConfig(cfg);
try {
config.commit(md);
} catch (IOException e) {
if (e.getCause() instanceof ConfigInvalidException) {
throw new ResourceConflictException(
"Cannot update LFS config in " + projectName + ": " + e.getCause().getMessage());
}
throw new ResourceConflictException("Cannot update LFS config in " + projectName);
}
} catch (RepositoryNotFoundException e) {
throw new ResourceNotFoundException(projectName.get());
} catch (IOException e) {
throw new ResourceNotFoundException(projectName.get(), e);
}
return get.apply(resource);
}