/** * Lists all programs. * * @return list of {@link ProgramRecord}s * @throws IOException if a network error occurred * @throws UnauthenticatedException if the request is not authorized successfully in the gateway server */ public Map<ProgramType, List<ProgramRecord>> listAllPrograms(NamespaceId namespace) throws IOException, UnauthenticatedException, UnauthorizedException { ImmutableMap.Builder<ProgramType, List<ProgramRecord>> allPrograms = ImmutableMap.builder(); for (ProgramType programType : ProgramType.values()) { if (programType.isListable()) { List<ProgramRecord> programRecords = Lists.newArrayList(); programRecords.addAll(listAllPrograms(namespace, programType)); allPrograms.put(programType, programRecords); } } return allPrograms.build(); }
/** * Lists programs of a type belonging to an application. * * @param app the application * @param programType type of the programs to list * @return list of {@link ProgramRecord}s * @throws ApplicationNotFoundException if the application with the given ID was not found * @throws IOException if a network error occurred * @throws UnauthenticatedException if the request is not authorized successfully in the gateway server */ public List<ProgramRecord> listPrograms(ApplicationId app, ProgramType programType) throws ApplicationNotFoundException, IOException, UnauthenticatedException, UnauthorizedException { Preconditions.checkArgument(programType.isListable()); List<ProgramRecord> programs = Lists.newArrayList(); for (ProgramRecord program : listPrograms(app)) { if (programType.equals(program.getType())) { programs.add(program); } } return programs; }
private static List<Command> generateCommands(ApplicationClient applicationClient, CLIConfig cliConfig) { List<Command> commands = Lists.newArrayList(); for (ElementType elementType : ElementType.values()) { if (elementType.getProgramType() != null && elementType.getProgramType().isListable()) { commands.add(new ListProgramsCommand(elementType.getProgramType(), applicationClient, cliConfig)); } } return commands; } }
private static List<Command> generateCommands(ApplicationClient applicationClient, CLIConfig cliConfig) { List<Command> commands = Lists.newArrayList(); for (ElementType elementType : ElementType.values()) { if (elementType.getProgramType() != null && elementType.getProgramType().isListable()) { commands.add(new ListProgramsCommand(elementType.getProgramType(), applicationClient, cliConfig)); } } return commands; } }
/** * Lists all programs of a type. * * @param programType type of the programs to list * @return list of {@link ProgramRecord}s * @throws IOException if a network error occurred * @throws UnauthenticatedException if the request is not authorized successfully in the gateway server */ public List<ProgramRecord> listAllPrograms(NamespaceId namespace, ProgramType programType) throws IOException, UnauthenticatedException, UnauthorizedException { Preconditions.checkArgument(programType.isListable()); String path = programType.getCategoryName(); URL url = config.resolveNamespacedURLV3(namespace, path); HttpRequest request = HttpRequest.get(url).build(); ObjectResponse<List<ProgramRecord>> response = ObjectResponse.fromJsonBody( restClient.execute(request, config.getAccessToken()), new TypeToken<List<ProgramRecord>>() { }); return response.getResponseObject(); }