use of com.thoughtworks.go.api.base.OutputListWriter in project gocd by gocd.
the class EnvironmentsRepresenter method toJSON.
public static void toJSON(OutputListWriter writer, Collection<EnvironmentConfig> environments, AgentInstance agentInstance) {
EnvironmentsConfig envConfigs = new EnvironmentsConfig();
envConfigs.addAll(environments);
Set<String> agentEnvAssociationFromDB = new HashSet<>(agentInstance.getAgent().getEnvironmentsAsList());
Set<String> agentEnvAssociationFromConfigRepo = envConfigs.stream().filter(environmentConfig -> !environmentConfig.isLocal()).map(environmentConfig -> environmentConfig.name().toString()).collect(Collectors.toSet());
Set<String> allAgentEnvAssociations = Sets.union(agentEnvAssociationFromDB, agentEnvAssociationFromConfigRepo);
List<String> sortedEnvNames = allAgentEnvAssociations.stream().sorted().collect(toList());
for (String envName : sortedEnvNames) {
EnvironmentConfig envConfig = envConfigs.find(new CaseInsensitiveString(envName));
if (envConfig != null) {
writer.addChild((childWriter) -> {
childWriter.add("name", envName);
childWriter.addChild("origin", (originWriter) -> origin(originWriter, envConfig, agentInstance.getUuid()));
});
} else {
writer.addChild((childWriter) -> {
childWriter.add("name", envName);
childWriter.addChild("origin", (originWriter) -> originWriter.add("type", "unknown"));
});
}
}
}
Aggregations