All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.datarouter.clustersetting.web.dto.SettingJspDto Maven / Gradle / Ivy

/**
 * Copyright © 2009 HotPads ([email protected])
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package io.datarouter.clustersetting.web.dto;

import java.util.ArrayList;
import java.util.List;

import io.datarouter.storage.setting.DefaultSettingValue;
import io.datarouter.storage.setting.cached.CachedSetting;

public class SettingJspDto{

	private final String name;
	private final Boolean hasRedundantCustomValue;
	private final Boolean hasCustomValue;
	private final T value;
	private final T defaultValue;
	private final List codeOverrides;

	public SettingJspDto(CachedSetting setting){
		this.name = setting.getName();
		this.hasRedundantCustomValue = setting.getHasRedundantCustomValue();
		this.hasCustomValue = setting.getHasCustomValue();
		this.value = setting.get();
		this.defaultValue = setting.getDefaultValue();
		this.codeOverrides = toDefaults(setting.getDefaultSettingValue());
	}

	private List toDefaults(DefaultSettingValue defaults){
		List dtos = new ArrayList<>();
		// profile overrides
		defaults.getValueByEnvironmentType().forEach((profile, value) -> {
			String profileString = profile.getPersistentString();
			dtos.add(new ClusterSettingDefaultJspDto(false, profileString, null, null, null, value));
		});
		// serverType overrides
		defaults.getValueByServerTypeByEnvironmentType().forEach((profile, defaultByServerType) -> {
			String profileString = profile.getPersistentString();
			defaultByServerType.forEach((serverType, value) -> dtos.add(new ClusterSettingDefaultJspDto(false,
					profileString, null, serverType, null, value)));
		});
		// serverName overrides
		defaults.getValueByServerNameByEnvironmentType().forEach((profile, defaultByServerName) -> {
			String profileString = profile.getPersistentString();
			defaultByServerName.forEach((serverName, value) -> dtos.add(new ClusterSettingDefaultJspDto(false,
					profileString, null, null, serverName, value)));
		});
		// environment overrides
		defaults.getValueByEnvironmentNameByEnvironmentType().forEach((profile, defaultByEnvironment) -> {
			String profileString = profile.getPersistentString();
			defaultByEnvironment.forEach((environment, value) -> dtos.add(new ClusterSettingDefaultJspDto(false,
					profileString, environment, null, null, value)));
		});
		return dtos;
	}

	public String getName(){
		return name;
	}

	public Boolean getHasRedundantCustomValue(){
		return hasRedundantCustomValue;
	}

	public Boolean getHasCustomValue(){
		return hasCustomValue;
	}

	public T getValue(){
		return value;
	}

	public T getDefaultValue(){
		return defaultValue;
	}

	public List getCodeOverrides(){
		return codeOverrides;
	}

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy