public RuntimeDtoImpl(org.eclipse.che.api.workspace.shared.dto.RuntimeDto origin) { java.util.Map<java.lang.String, org.eclipse.che.api.workspace.shared.dto.MachineDto> machinesIn = origin.getMachines(); if (machinesIn != null) { java.util.Map<java.lang.String, org.eclipse.che.api.workspace.shared.dto.MachineDto> machinesOut = new java.util.HashMap<java.lang.String, org.eclipse.che.api.workspace.shared.dto.MachineDto>(); java.util.List<org.eclipse.che.api.workspace.shared.dto.WarningDto> warningsIn = origin.getWarnings(); if (warningsIn != null) { java.util.List<org.eclipse.che.api.workspace.shared.dto.WarningDto> warningsOut = new java.util.ArrayList<org.eclipse.che.api.workspace.shared.dto.WarningDto>(); this.owner = origin.getOwner(); this.activeEnv = origin.getActiveEnv(); java.util.List<org.eclipse.che.api.workspace.shared.dto.CommandDto> commandsIn = origin.getCommands(); if (commandsIn != null) { java.util.List<org.eclipse.che.api.workspace.shared.dto.CommandDto> commandsOut = new java.util.ArrayList<org.eclipse.che.api.workspace.shared.dto.CommandDto>(); this.machineToken = origin.getMachineToken(); java.util.List<org.eclipse.che.api.core.rest.shared.dto.Link> linksIn = origin.getLinks(); if (linksIn != null) { java.util.List<org.eclipse.che.api.core.rest.shared.dto.Link> linksOut = new java.util.ArrayList<org.eclipse.che.api.core.rest.shared.dto.Link>();
/** Converts {@link Runtime} to {@link RuntimeDto}. */ public static RuntimeDto asDto(Runtime runtime) { if (runtime == null) { return null; } RuntimeDto runtimeDto = newDto(RuntimeDto.class).withActiveEnv(runtime.getActiveEnv()); if (runtime.getMachines() != null) { runtimeDto.setMachines( runtime .getMachines() .entrySet() .stream() .collect(toMap(Map.Entry::getKey, entry -> asDto(entry.getValue())))); } if (runtime.getWarnings() != null) { runtimeDto.setWarnings( runtime.getWarnings().stream().map(DtoConverter::asDto).collect(Collectors.toList())); } if (runtime.getCommands() != null) { runtimeDto.setCommands( runtime.getCommands().stream().map(DtoConverter::asDto).collect(toList())); } return runtimeDto; }
private WorkspaceDto filterServers(WorkspaceDto workspace, boolean includeInternal) { // no runtime - nothing to filter if (workspace.getRuntime() == null) { return workspace; } // if it is needed to include internal there is nothing to filter if (includeInternal) { return workspace; } for (MachineDto machine : workspace.getRuntime().getMachines().values()) { Map<String, ServerDto> filteredServers = new HashMap<>(); machine .getServers() .forEach( (name, server) -> { if (!"true" .equals(server.getAttributes().get(ServerConfig.INTERNAL_SERVER_ATTRIBUTE))) { filteredServers.put(name, server); } }); machine.withServers(filteredServers); } return workspace; } }
public WorkspaceImpl(WorkspaceDto workspace) { this( workspace.getId(), workspace.getNamespace(), workspace.getConfig(), workspace.getRuntime(), workspace.getAttributes(), workspace.isTemporary(), workspace.getStatus(), workspace.getLinks(), workspace.getRuntime() != null ? workspace.getRuntime().getMachineToken() : null); }
private WorkspaceDto asDtoWithLinksAndToken(Workspace workspace) throws ServerException { WorkspaceDto workspaceDto = asDto(workspace).withLinks(linksGenerator.genLinks(workspace, getServiceContext())); RuntimeDto runtimeDto = workspaceDto.getRuntime(); if (runtimeDto != null) { try { runtimeDto.setMachineToken(machineTokenProvider.getToken(workspace.getId())); } catch (MachineAccessForbidden e) { // set runtime to null since user doesn't have the required permissions workspaceDto.setRuntime(null); } catch (MachineTokenException e) { throw new ServerException(e.getMessage(), e); } } return workspaceDto; }