/** Sets command's goal ID. */ public void setGoal(String goalId) { getAttributes().put(COMMAND_GOAL_ATTRIBUTE_NAME, goalId); }
/** Sets command's preview URL. */ public void setPreviewURL(String previewURL) { getAttributes().put(COMMAND_PREVIEW_URL_ATTRIBUTE_NAME, previewURL); }
@Override protected String getCommandPropertyValue() { final String previewUrl = editedCommand.getAttributes().get(COMMAND_PREVIEW_URL_ATTRIBUTE_NAME); return previewUrl != null ? previewUrl : ""; }
@Override protected void updateCommandPropertyValue(String content) { editedCommand.getAttributes().put(COMMAND_PREVIEW_URL_ATTRIBUTE_NAME, content); } }
/** Returns command's preview URL or {@code null} if none. */ @Nullable public String getPreviewURL() { return getAttributes().get(COMMAND_PREVIEW_URL_ATTRIBUTE_NAME); }
/** Returns ID of the command's goal or {@code null} if none. */ @Nullable public String getGoal() { return getAttributes().get(COMMAND_GOAL_ATTRIBUTE_NAME); }
@Override public int hashCode() { return Objects.hash(name, typeId, commandLine, getAttributes(), getApplicableContext()); }
/** * Compares this {@link CommandImpl} to another {@link CommandImpl}, ignoring applicable context * considerations. * * @param anotherCommand the {@link CommandImpl} to compare this {@link CommandImpl} against * @return {@code true} if the argument represents an equivalent {@link CommandImpl} ignoring * applicable context; {@code false} otherwise */ public boolean equalsIgnoreContext(CommandImpl anotherCommand) { if (this == anotherCommand) { return true; } return Objects.equals(getName(), anotherCommand.getName()) && Objects.equals(typeId, anotherCommand.typeId) && Objects.equals(commandLine, anotherCommand.commandLine) && Objects.equals(getAttributes(), anotherCommand.getAttributes()); }
/** * {@inheritDoc} * * @see #equalsIgnoreContext(CommandImpl) */ @Override public boolean equals(Object o) { if (this == o) { return true; } if (!(o instanceof CommandImpl)) { return false; } CommandImpl other = (CommandImpl) o; return Objects.equals(getName(), other.getName()) && Objects.equals(typeId, other.typeId) && Objects.equals(commandLine, other.commandLine) && Objects.equals(getAttributes(), other.getAttributes()) && Objects.equals(getApplicableContext(), other.getApplicableContext()); }
/** Creates copy of the given {@code command}. */ public CommandImpl(CommandImpl command) { this( command.getName(), command.getCommandLine(), command.getType(), new HashMap<>(command.getAttributes()), new ApplicableContext(command.getApplicableContext())); }
/** 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); }
final String previewUrl = command.getAttributes().get(COMMAND_PREVIEW_URL_ATTRIBUTE_NAME); if (!isNullOrEmpty(previewUrl)) { macroProcessor
/** * 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); }