/** Converts {@link Machine} to {@link MachineDto}. */ public static MachineDto asDto(Machine machine) { MachineDto machineDto = newDto(MachineDto.class) .withAttributes(machine.getAttributes()) .withStatus(machine.getStatus()); if (machine.getServers() != null) { machineDto.withServers( machine .getServers() .entrySet() .stream() .collect(toMap(Map.Entry::getKey, entry -> asDto(entry.getValue())))); } return machineDto; }
/** 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; }
/** Converts {@link WorkspaceConfig} to {@link WorkspaceConfigDto}. */ public static WorkspaceConfigDto asDto(WorkspaceConfig workspace) { List<CommandDto> commands = workspace.getCommands().stream().map(DtoConverter::asDto).collect(toList()); List<ProjectConfigDto> projects = workspace.getProjects().stream().map(DtoConverter::asDto).collect(toList()); Map<String, EnvironmentDto> environments = workspace .getEnvironments() .entrySet() .stream() .collect(toMap(Map.Entry::getKey, entry -> asDto(entry.getValue()))); return newDto(WorkspaceConfigDto.class) .withName(workspace.getName()) .withDefaultEnv(workspace.getDefaultEnv()) .withCommands(commands) .withProjects(projects) .withEnvironments(environments) .withAttributes(workspace.getAttributes()) .withDescription(workspace.getDescription()); }
links.add(getIconLink); return asDto(stack).withLinks(links);
/** Converts {@link MachineConfig} to {@link MachineConfigDto}. */ public static MachineConfigDto asDto(MachineConfig machine) { MachineConfigDto machineDto = newDto(MachineConfigDto.class).withInstallers(machine.getInstallers()); if (machine.getServers() != null) { machineDto.setServers( machine .getServers() .entrySet() .stream() .collect(toMap(Map.Entry::getKey, entry -> asDto(entry.getValue())))); } if (machine.getAttributes() != null) { machineDto.setAttributes(machine.getAttributes()); } if (machine.getVolumes() != null) { machineDto.setVolumes( machine .getVolumes() .entrySet() .stream() .collect(toMap(Map.Entry::getKey, entry -> asDto(entry.getValue())))); } if (machine.getEnv() != null) { machineDto.setEnv(machine.getEnv()); } return machineDto; }
/** Converts {@link Environment} to {@link EnvironmentDto}. */ public static EnvironmentDto asDto(Environment env) { final EnvironmentDto envDto = newDto(EnvironmentDto.class); if (env.getMachines() != null) { envDto.withMachines( env.getMachines() .entrySet() .stream() .collect(toMap(Map.Entry::getKey, entry -> asDto(entry.getValue())))); } if (env.getRecipe() != null) { envDto.withRecipe( newDto(RecipeDto.class) .withType(env.getRecipe().getType()) .withContentType(env.getRecipe().getContentType()) .withLocation(env.getRecipe().getLocation()) .withContent(env.getRecipe().getContent())); } return envDto; }
/** Converts {@link Workspace} to {@link WorkspaceDto}. */ public static WorkspaceDto asDto(Workspace workspace) { WorkspaceDto workspaceDto = newDto(WorkspaceDto.class) .withId(workspace.getId()) .withStatus(workspace.getStatus()) .withNamespace(workspace.getNamespace()) .withTemporary(workspace.isTemporary()) .withAttributes(workspace.getAttributes()) .withConfig(asDto(workspace.getConfig())); if (workspace.getRuntime() != null) { RuntimeDto runtime = asDto(workspace.getRuntime()); workspaceDto.setRuntime(runtime); } return workspaceDto; }
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; }
/** Convert {@link StackImpl} to {@link StackDto}. */ public static StackDto asDto(Stack stack) { WorkspaceConfigDto workspaceConfigDto = null; if (stack.getWorkspaceConfig() != null) { workspaceConfigDto = asDto(stack.getWorkspaceConfig()); } List<StackComponentDto> componentsDto = null; if (stack.getComponents() != null) { componentsDto = stack .getComponents() .stream() .map( component -> newDto(StackComponentDto.class) .withName(component.getName()) .withVersion(component.getVersion())) .collect(toList()); } return newDto(StackDto.class) .withId(stack.getId()) .withName(stack.getName()) .withDescription(stack.getDescription()) .withCreator(stack.getCreator()) .withScope(stack.getScope()) .withTags(stack.getTags()) .withComponents(componentsDto) .withWorkspaceConfig(workspaceConfigDto); }