/** Updates the specified {@code project} with the given {@code commands}. */ private Promise<Void> updateProject(Project project, List<CommandImpl> commands) { MutableProjectConfig config = new MutableProjectConfig(project); Map<String, List<String>> attributes = config.getAttributes(); List<String> attrValue = new ArrayList<>(attributes.size()); for (CommandImpl command : commands) { CommandDto commandDto = dtoFactory .createDto(CommandDto.class) .withName(command.getName()) .withType(command.getType()) .withCommandLine(command.getCommandLine()) .withAttributes(command.getAttributes()); attrValue.add(dtoFactory.toJson(commandDto)); } attributes.put(COMMANDS_ATTRIBUTE_NAME, attrValue); return project.update().withBody(config).send().then((Function<Project, Void>) arg -> null); }
/** Converts {@link Command} to {@link CommandDto}. */ public static CommandDto asDto(Command command) { return newDto(CommandDto.class) .withName(command.getName()) .withCommandLine(command.getCommandLine()) .withType(command.getType()) .withAttributes(command.getAttributes()); }
/** * Updates command. * * @return a promise that resolves to the {@link WorkspaceImpl}, or rejects with an error */ public Promise<WorkspaceImpl> updateCommand( String wsId, String commandName, CommandImpl commandUpdate) { final String url = baseHttpUrl + '/' + wsId + "/command/" + URL.encodePathSegment(commandName); final CommandDto commandDto = dtoFactory .createDto(CommandDto.class) .withName(commandUpdate.getName()) .withCommandLine(commandUpdate.getCommandLine()) .withType(commandUpdate.getType()) .withAttributes(commandUpdate.getAttributes()); return asyncRequestFactory .createRequest(PUT, url, commandDto, false) .header(ACCEPT, APPLICATION_JSON) .header(CONTENT_TYPE, APPLICATION_JSON) .loader(loaderFactory.newLoader("Updating command...")) .send(dtoUnmarshallerFactory.newUnmarshaller(WorkspaceDto.class)) .then((Function<WorkspaceDto, WorkspaceImpl>) WorkspaceImpl::new); }
/** * Adds command to workspace * * @param wsId workspace ID * @param newCommand the new workspace command * @return a promise that resolves to the {@link WorkspaceImpl}, or rejects with an error */ public Promise<WorkspaceImpl> addCommand(String wsId, CommandImpl newCommand) { final String url = baseHttpUrl + '/' + wsId + "/command"; final CommandDto commandDto = dtoFactory .createDto(CommandDto.class) .withName(newCommand.getName()) .withCommandLine(newCommand.getCommandLine()) .withType(newCommand.getType()) .withAttributes(newCommand.getAttributes()); return asyncRequestFactory .createPostRequest(url, commandDto) .header(ACCEPT, APPLICATION_JSON) .header(CONTENT_TYPE, APPLICATION_JSON) .loader(loaderFactory.newLoader("Adding command...")) .send(dtoUnmarshallerFactory.newUnmarshaller(WorkspaceDto.class)) .then((Function<WorkspaceDto, WorkspaceImpl>) WorkspaceImpl::new); }