@Override public int hashCode() { int hash = 7; hash = 31 * hash + Objects.hashCode(id); hash = 31 * hash + Objects.hashCode(name); hash = 31 * hash + Objects.hashCode(commandLine); hash = 31 * hash + Objects.hashCode(type); hash = 31 * hash + getAttributes().hashCode(); return hash; }
WorkspaceImpl workspace = workspaceManager.getWorkspace(id); List<CommandImpl> commands = workspace.getConfig().getCommands(); if (!commands.removeIf(cmd -> cmd.getName().equals(cmdName))) { throw new NotFoundException( format("Workspace '%s' doesn't contain command '%s'", id, cmdName)); commands.add(new CommandImpl(update)); return asDtoWithLinksAndToken(doUpdate(id, workspace));
@DELETE @Path("/{id}/command/{name}") @ApiOperation( value = "Remove the command from the workspace", notes = "This operation can be performed only by the workspace owner") @ApiResponses({ @ApiResponse(code = 204, message = "The command successfully removed"), @ApiResponse(code = 403, message = "The user does not have access delete the command"), @ApiResponse(code = 404, message = "The workspace not found"), @ApiResponse(code = 500, message = "Internal server error occurred") }) public void deleteCommand( @ApiParam("The id of the workspace") @PathParam("id") String id, @ApiParam("The name of the command to remove") @PathParam("name") String commandName) throws ServerException, BadRequestException, NotFoundException, ConflictException, ForbiddenException { WorkspaceImpl workspace = workspaceManager.getWorkspace(id); if (workspace .getConfig() .getCommands() .removeIf(command -> command.getName().equals(commandName))) { doUpdate(id, workspace); } }
@POST @Path("/{id}/command") @Consumes(APPLICATION_JSON) @Produces(APPLICATION_JSON) @ApiOperation( value = "Update the workspace by adding a new command to it", notes = "This operation can be performed only by the workspace owner") @ApiResponses({ @ApiResponse(code = 200, message = "The workspace successfully updated"), @ApiResponse(code = 400, message = "Missed required parameters, parameters are not valid"), @ApiResponse(code = 403, message = "The user does not have access to update the workspace"), @ApiResponse(code = 404, message = "The workspace not found"), @ApiResponse(code = 409, message = "The command with such name already exists"), @ApiResponse(code = 500, message = "Internal server error occurred") }) public WorkspaceDto addCommand( @ApiParam("The workspace id") @PathParam("id") String id, @ApiParam(value = "The new workspace command", required = true) CommandDto newCommand) throws ServerException, BadRequestException, NotFoundException, ConflictException, ForbiddenException { requiredNotNull(newCommand, "Command"); WorkspaceImpl workspace = workspaceManager.getWorkspace(id); workspace.getConfig().getCommands().add(new CommandImpl(newCommand)); return asDtoWithLinksAndToken(doUpdate(id, workspace)); }
@Override public boolean equals(Object obj) { if (this == obj) { return true; } if (!(obj instanceof CommandImpl)) { return false; } final CommandImpl that = (CommandImpl) obj; return Objects.equals(id, that.id) && Objects.equals(name, that.name) && Objects.equals(commandLine, that.commandLine) && Objects.equals(type, that.type) && getAttributes().equals(that.getAttributes()); }