/* * Copyright 2015-2016 OpenCB * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.opencb.opencga.app.cli.main.options; import com.beust.jcommander.JCommander; import com.beust.jcommander.Parameter; import com.beust.jcommander.Parameters; import com.beust.jcommander.ParametersDelegate; import org.opencb.opencga.app.cli.GeneralCliOptions.NumericOptions; import static org.opencb.opencga.app.cli.GeneralCliOptions.CommonCommandOptions; import static org.opencb.opencga.app.cli.GeneralCliOptions.DataModelOptions; /** * Created by pfurio on 13/06/16. */ @Parameters(commandNames = {"users"}, commandDescription = "User commands") public class UserCommandOptions { public CreateCommandOptions createCommandOptions; public InfoCommandOptions infoCommandOptions; public UpdateCommandOptions updateCommandOptions; public ChangePasswordCommandOptions changePasswordCommandOptions; public DeleteCommandOptions deleteCommandOptions; public ProjectsCommandOptions projectsCommandOptions; public LoginCommandOptions loginCommandOptions; public LogoutCommandOptions logoutCommandOptions; public ResetPasswordCommandOptions resetPasswordCommandOptions; public JCommander jCommander; public CommonCommandOptions commonCommandOptions; public DataModelOptions commonDataModelOptions; public NumericOptions commonNumericOptions; public UserCommandOptions(CommonCommandOptions commonCommandOptions, DataModelOptions dataModelOptions, NumericOptions numericOptions, JCommander jCommander) { this.commonCommandOptions = commonCommandOptions; this.commonDataModelOptions = dataModelOptions; this.commonNumericOptions = numericOptions; this.jCommander = jCommander; this.createCommandOptions = new CreateCommandOptions(); this.infoCommandOptions = new InfoCommandOptions(); this.updateCommandOptions = new UpdateCommandOptions(); this.changePasswordCommandOptions = new ChangePasswordCommandOptions(); this.deleteCommandOptions = new DeleteCommandOptions(); this.projectsCommandOptions = new ProjectsCommandOptions(); this.loginCommandOptions = new LoginCommandOptions(); this.logoutCommandOptions = new LogoutCommandOptions(); this.resetPasswordCommandOptions = new ResetPasswordCommandOptions(); } public JCommander getjCommander() { return jCommander; } public class BaseUserCommand { @ParametersDelegate public CommonCommandOptions commonOptions = commonCommandOptions; @Parameter(names = {"-u", "--user"}, description = "User id, this must be unique in OpenCGA", required = true, arity = 1) public String user; } public class NotRequiredUserParam { @Parameter(names = {"-u", "--user"}, description = "User id, this must be unique in OpenCGA", required = false, arity = 1) public String user; } @Parameters(commandNames = {"create"}, commandDescription = "Create a new user") public class CreateCommandOptions extends BaseUserCommand { @Parameter(names = {"-n", "--name"}, description = "User name", required = true, arity = 1) public String name; @Parameter(names = {"-p", "--password"}, description = "User password", required = true, password = true, arity = 1) public String password; @Parameter(names = {"-e", "--email"}, description = "User email", required = true, arity = 1) public String email; @Parameter(names = {"-o", "--organization"}, description = "User organization", required = false, arity = 1) public String organization; } @Parameters(commandNames = {"info"}, commandDescription = "Get complete information of the user together with owned and shared projects" + " and studies") public class InfoCommandOptions { @ParametersDelegate public CommonCommandOptions commonOptions = commonCommandOptions; @ParametersDelegate public DataModelOptions dataModelOptions = commonDataModelOptions; @ParametersDelegate public NotRequiredUserParam userParam = new NotRequiredUserParam(); @Deprecated @Parameter(names = {"--last-modified"}, description = "[DEPRECATED] If matches with the user's last activity, return " + "an empty QueryResult", arity = 1, required = false) public String lastModified; } @Parameters(commandNames = {"update"}, commandDescription = "Update some user attributes") public class UpdateCommandOptions extends BaseUserCommand { @Parameter(names = {"-n", "--name"}, description = "User name", arity = 1) public String name; @Parameter(names = {"-e", "--email"}, description = "User's email", arity = 1) public String email; @Parameter(names = {"-o", "--organization"}, description = "User's organization", arity = 1) public String organization; @Parameter(names = {"--attributes"}, description = "JSON string containing additional information to be stored", arity = 1) public String attributes; } @Parameters(commandNames = {"change-password"}, commandDescription = "Change the user's password") public class ChangePasswordCommandOptions { @Parameter(names = {"--password"}, description = "Old password", arity = 1, required = true) public String password; @Parameter(names = {"--npassword"}, description = "New password", arity = 1, required = true) public String npassword; } @Parameters(commandNames = {"delete"}, commandDescription = "[PENDING] Delete a user") public class DeleteCommandOptions extends BaseUserCommand { } @Parameters(commandNames = {"projects"}, commandDescription = "List all projects and studies belonging or shared with the user") public class ProjectsCommandOptions { @ParametersDelegate public CommonCommandOptions commonOptions = commonCommandOptions; @ParametersDelegate public DataModelOptions dataModelOptions = commonDataModelOptions; @ParametersDelegate public NumericOptions numericOptions = commonNumericOptions; @ParametersDelegate public NotRequiredUserParam userParam = new NotRequiredUserParam(); @Parameter(names = {"--shared"}, description = "When not set, it will only return the projects and studies belonging to the user. " + "However, if this parameter is set, it will also show the projects and studies shared with the user.", arity = 0) public boolean shared; } @Parameters(commandNames = {"login"}, commandDescription = "Get identified and gain access to the system") public class LoginCommandOptions extends BaseUserCommand { @Parameter(names = {"-p", "--password"}, description = "User password", arity = 1, required = true, password = true) public String password; } @Parameters(commandNames = {"logout"}, commandDescription = "End user session") public class LogoutCommandOptions { @Parameter(names = {"-S", "--session-id"}, description = "SessionId", required = false, arity = 1, hidden = true) public String sessionId; } @Parameters(commandNames = {"reset-password"}, commandDescription = "Reset password") public class ResetPasswordCommandOptions extends BaseUserCommand { } }