api_refactor: move admin level account apis to admin pkg

Signed-off-by: Rohit Yadav <[email protected]>


Project: http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/repo
Commit: 
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/commit/1b1d91dc
Tree: http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/tree/1b1d91dc
Diff: http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/diff/1b1d91dc

Branch: refs/heads/api_refactoring
Commit: 1b1d91dc4fa6fd0f4fca5b0b74ab9bfce7127a49
Parents: 2a7fa67
Author: Rohit Yadav <[email protected]>
Authored: Thu Dec 6 10:25:20 2012 -0800
Committer: Rohit Yadav <[email protected]>
Committed: Thu Dec 6 10:25:20 2012 -0800

----------------------------------------------------------------------
 .../com/cloud/api/commands/CreateAccountCmd.java   |  159 ---------------
 .../com/cloud/api/commands/DeleteAccountCmd.java   |  109 ----------
 .../com/cloud/api/commands/UpdateAccountCmd.java   |  130 ------------
 api/src/com/cloud/user/AccountService.java         |    2 +-
 .../admin/account/command/CreateAccountCmd.java    |  159 +++++++++++++++
 .../admin/account/command/DeleteAccountCmd.java    |  109 ++++++++++
 .../admin/account/command/UpdateAccountCmd.java    |  130 ++++++++++++
 client/tomcatconf/commands.properties.in           |    6 +-
 server/src/com/cloud/user/AccountManagerImpl.java  |    2 +-
 .../com/cloud/user/MockAccountManagerImpl.java     |    2 +-
 10 files changed, 404 insertions(+), 404 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/1b1d91dc/api/src/com/cloud/api/commands/CreateAccountCmd.java
----------------------------------------------------------------------
diff --git a/api/src/com/cloud/api/commands/CreateAccountCmd.java 
b/api/src/com/cloud/api/commands/CreateAccountCmd.java
deleted file mode 100755
index d1d3996..0000000
--- a/api/src/com/cloud/api/commands/CreateAccountCmd.java
+++ /dev/null
@@ -1,159 +0,0 @@
-// Licensed to the Apache Software Foundation (ASF) under one
-// or more contributor license agreements.  See the NOTICE file
-// distributed with this work for additional information
-// regarding copyright ownership.  The ASF licenses this file
-// to you 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 com.cloud.api.commands;
-
-import java.util.Collection;
-import java.util.Map;
-
-import org.apache.log4j.Logger;
-
-import org.apache.cloudstack.api.ApiConstants;
-import org.apache.cloudstack.api.BaseCmd;
-import org.apache.cloudstack.api.IdentityMapper;
-import org.apache.cloudstack.api.Implementation;
-import org.apache.cloudstack.api.Parameter;
-import org.apache.cloudstack.api.ServerApiException;
-import com.cloud.api.response.AccountResponse;
-import com.cloud.api.response.UserResponse;
-import com.cloud.user.Account;
-import com.cloud.user.UserAccount;
-import com.cloud.user.UserContext;
-
-@Implementation(description="Creates an account", 
responseObject=UserResponse.class)
-public class CreateAccountCmd extends BaseCmd {
-    public static final Logger s_logger = 
Logger.getLogger(CreateAccountCmd.class.getName());
-
-    private static final String s_name = "createaccountresponse";
-
-    /////////////////////////////////////////////////////
-    //////////////// API parameters /////////////////////
-    /////////////////////////////////////////////////////
-
-    @Parameter(name=ApiConstants.ACCOUNT, type=CommandType.STRING, 
description="Creates the user under the specified account. If no account is 
specified, the username will be used as the account name.")
-    private String accountName;
-
-    @Parameter(name=ApiConstants.ACCOUNT_TYPE, type=CommandType.SHORT, 
required=true, description="Type of the account.  Specify 0 for user, 1 for 
root admin, and 2 for domain admin")
-    private Short accountType;
-
-    @IdentityMapper(entityTableName="domain")
-    @Parameter(name=ApiConstants.DOMAIN_ID, type=CommandType.LONG, 
description="Creates the user under the specified domain.")
-    private Long domainId;
-
-    @Parameter(name=ApiConstants.EMAIL, type=CommandType.STRING, 
required=true, description="email")
-    private String email;
-
-    @Parameter(name=ApiConstants.FIRSTNAME, type=CommandType.STRING, 
required=true, description="firstname")
-    private String firstName;
-
-    @Parameter(name=ApiConstants.LASTNAME, type=CommandType.STRING, 
required=true, description="lastname")
-    private String lastName;
-
-    @Parameter(name=ApiConstants.PASSWORD, type=CommandType.STRING, 
required=true, description="Hashed password (Default is MD5). If you wish to 
use any other hashing algorithm, you would need to write a custom 
authentication adapter See Docs section.")
-    private String password;
-
-    @Parameter(name=ApiConstants.TIMEZONE, type=CommandType.STRING, 
description="Specifies a timezone for this command. For more information on the 
timezone parameter, see Time Zone Format.")
-    private String timeZone;
-
-    @Parameter(name=ApiConstants.USERNAME, type=CommandType.STRING, 
required=true, description="Unique username.")
-    private String userName;
-
-    @Parameter(name=ApiConstants.NETWORK_DOMAIN, type=CommandType.STRING, 
description="Network domain for the account's networks")
-    private String networkDomain;
-
-    @Parameter(name = ApiConstants.ACCOUNT_DETAILS, type = CommandType.MAP, 
description = "details for account used to store specific parameters")
-    private Map<String, String> details;
-    /////////////////////////////////////////////////////
-    /////////////////// Accessors ///////////////////////
-    /////////////////////////////////////////////////////
-
-    public String getAccountName() {
-        return accountName;
-    }
-
-    public Short getAccountType() {
-        return accountType;
-    }
-
-    public Long getDomainId() {
-        return domainId;
-    }
-
-    public String getEmail() {
-        return email;
-    }
-
-    public String getFirstName() {
-        return firstName;
-    }
-
-    public String getLastName() {
-        return lastName;
-    }
-
-    public String getPassword() {
-        return password;
-    }
-
-    public String getTimeZone() {
-        return timeZone;
-    }
-
-    public String getUsername() {
-        return userName;
-    }
-
-    public String getNetworkDomain() {
-        return networkDomain;
-    }
-
-    public Map<String, String> getDetails() {
-        if (details == null || details.isEmpty()) {
-            return null;
-        }
-
-        Collection<String> paramsCollection = details.values();
-        Map<String, String> params = (Map<String, String>) 
(paramsCollection.toArray())[0];
-        return params;
-    }
-
-    /////////////////////////////////////////////////////
-    /////////////// API Implementation///////////////////
-    /////////////////////////////////////////////////////
-
-    @Override
-    public String getCommandName() {
-        return s_name;
-    }
-
-    @Override
-    public long getEntityOwnerId() {
-        return Account.ACCOUNT_ID_SYSTEM;
-    }
-
-    @Override
-    public void execute(){
-        UserContext.current().setEventDetails("Account Name: 
"+getAccountName()+", Domain Id:"+getDomainId());
-        UserAccount userAccount = 
_accountService.createUserAccount(getUsername(), getPassword(), getFirstName(), 
getLastName(), getEmail(), getTimeZone(), getAccountName(), getAccountType(), 
getDomainId(), getNetworkDomain(), getDetails());
-        if (userAccount != null) {
-            AccountResponse response = 
_responseGenerator.createUserAccountResponse(userAccount);
-            response.setResponseName(getCommandName());
-            this.setResponseObject(response);
-        } else {
-            throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to 
create a user account");
-        }
-    }
-}

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/1b1d91dc/api/src/com/cloud/api/commands/DeleteAccountCmd.java
----------------------------------------------------------------------
diff --git a/api/src/com/cloud/api/commands/DeleteAccountCmd.java 
b/api/src/com/cloud/api/commands/DeleteAccountCmd.java
deleted file mode 100755
index 47c3475..0000000
--- a/api/src/com/cloud/api/commands/DeleteAccountCmd.java
+++ /dev/null
@@ -1,109 +0,0 @@
-// Licensed to the Apache Software Foundation (ASF) under one
-// or more contributor license agreements.  See the NOTICE file
-// distributed with this work for additional information
-// regarding copyright ownership.  The ASF licenses this file
-// to you 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 com.cloud.api.commands;
-
-import org.apache.log4j.Logger;
-
-import org.apache.cloudstack.api.ApiConstants;
-import org.apache.cloudstack.api.BaseAsyncCmd;
-import org.apache.cloudstack.api.BaseCmd;
-import org.apache.cloudstack.api.IdentityMapper;
-import org.apache.cloudstack.api.Implementation;
-import org.apache.cloudstack.api.Parameter;
-import org.apache.cloudstack.api.ServerApiException;
-import com.cloud.api.response.SuccessResponse;
-import com.cloud.async.AsyncJob;
-import com.cloud.event.EventTypes;
-import com.cloud.user.Account;
-import com.cloud.user.User;
-import com.cloud.user.UserContext;
-
-@Implementation(description="Deletes a account, and all users associated with 
this account", responseObject=SuccessResponse.class)
-public class DeleteAccountCmd extends BaseAsyncCmd {
-    public static final Logger s_logger = 
Logger.getLogger(DeleteAccountCmd.class.getName());
-    private static final String s_name = "deleteaccountresponse";
-
-    /////////////////////////////////////////////////////
-    //////////////// API parameters /////////////////////
-    /////////////////////////////////////////////////////
-
-
-    @IdentityMapper(entityTableName="account")
-    @Parameter(name=ApiConstants.ID, type=CommandType.LONG, required=true, 
description="Account id")
-    private Long id;
-
-
-    /////////////////////////////////////////////////////
-    /////////////////// Accessors ///////////////////////
-    /////////////////////////////////////////////////////
-
-    public Long getId() {
-        return id;
-    }
-
-
-    /////////////////////////////////////////////////////
-    /////////////// API Implementation///////////////////
-    /////////////////////////////////////////////////////
-
-    public static String getStaticName() {
-        return s_name;
-    }
-
-    @Override
-    public String getCommandName() {
-        return s_name;
-    }
-
-    @Override
-    public long getEntityOwnerId() {
-        Account account = UserContext.current().getCaller();// Let's give the 
caller here for event logging.
-        if (account != null) {
-            return account.getAccountId();
-        }
-
-        return Account.ACCOUNT_ID_SYSTEM; // no account info given, parent 
this command to SYSTEM so ERROR events are tracked
-    }
-
-    @Override
-    public String getEventType() {
-        return EventTypes.EVENT_ACCOUNT_DELETE;
-    }
-
-    @Override
-    public String getEventDescription() {
-        User user = _responseGenerator.findUserById(getId());
-        return (user != null ? ("deleting User " + user.getUsername() + " (id: 
" + user.getId() + ") and accountId = " + user.getAccountId()) : "user delete, 
but this user does not exist in the system");
-    }
-
-    @Override
-    public void execute(){
-        UserContext.current().setEventDetails("Account Id: "+getId());
-        boolean result = _accountService.deleteUserAccount(getId());
-        if (result) {
-            SuccessResponse response = new SuccessResponse(getCommandName());
-            this.setResponseObject(response);
-        } else {
-            throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to 
delete user account and all corresponding users");
-        }
-    }
-
-    @Override
-    public AsyncJob.Type getInstanceType() {
-        return AsyncJob.Type.Account;
-    }
-}

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/1b1d91dc/api/src/com/cloud/api/commands/UpdateAccountCmd.java
----------------------------------------------------------------------
diff --git a/api/src/com/cloud/api/commands/UpdateAccountCmd.java 
b/api/src/com/cloud/api/commands/UpdateAccountCmd.java
deleted file mode 100755
index ad4cbd5..0000000
--- a/api/src/com/cloud/api/commands/UpdateAccountCmd.java
+++ /dev/null
@@ -1,130 +0,0 @@
-// Licensed to the Apache Software Foundation (ASF) under one
-// or more contributor license agreements.  See the NOTICE file
-// distributed with this work for additional information
-// regarding copyright ownership.  The ASF licenses this file
-// to you 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 com.cloud.api.commands;
-
-import java.util.Collection;
-import java.util.Map;
-
-import org.apache.log4j.Logger;
-
-import org.apache.cloudstack.api.ApiConstants;
-import org.apache.cloudstack.api.BaseCmd;
-import org.apache.cloudstack.api.IdentityMapper;
-import org.apache.cloudstack.api.Implementation;
-import org.apache.cloudstack.api.Parameter;
-import org.apache.cloudstack.api.ServerApiException;
-import com.cloud.api.response.AccountResponse;
-import com.cloud.user.Account;
-
-@Implementation(description="Updates account information for the authenticated 
user", responseObject=AccountResponse.class)
-public class UpdateAccountCmd extends BaseCmd{
-    public static final Logger s_logger = 
Logger.getLogger(UpdateAccountCmd.class.getName());
-    private static final String s_name = "updateaccountresponse";
-
-    /////////////////////////////////////////////////////
-    //////////////// API parameters /////////////////////
-    /////////////////////////////////////////////////////
-
-    @IdentityMapper(entityTableName="account")
-    @Parameter(name=ApiConstants.ID, type=CommandType.LONG, 
description="Account id")
-    private Long id;
-
-    @Parameter(name=ApiConstants.ACCOUNT, type=CommandType.STRING, 
description="the current account name")
-    private String accountName;
-
-    @IdentityMapper(entityTableName="domain")
-    @Parameter(name=ApiConstants.DOMAIN_ID, type=CommandType.LONG, 
description="the ID of the domain where the account exists")
-    private Long domainId;
-
-    @Parameter(name=ApiConstants.NEW_NAME, type=CommandType.STRING, 
required=true, description="new name for the account")
-    private String newName;
-
-    @Parameter(name=ApiConstants.NETWORK_DOMAIN, type=CommandType.STRING, 
description="Network domain for the account's networks; empty string will 
update domainName with NULL value")
-    private String networkDomain;
-
-    @Parameter(name = ApiConstants.ACCOUNT_DETAILS, type = CommandType.MAP, 
description = "details for account used to store specific parameters")
-    private Map details;
-
-    /////////////////////////////////////////////////////
-    /////////////////// Accessors ///////////////////////
-    /////////////////////////////////////////////////////
-
-    public Long getId() {
-        return id;
-    }
-
-    public String getAccountName() {
-        return accountName;
-    }
-
-    public Long getDomainId() {
-        return domainId;
-    }
-
-    public String getNewName() {
-        return newName;
-    }
-
-    public String getNetworkDomain() {
-        return networkDomain;
-    }
-
-    public Map getDetails() {
-        if (details == null || details.isEmpty()) {
-            return null;
-        }
-
-        Collection paramsCollection = details.values();
-        Map params = (Map) (paramsCollection.toArray())[0];
-        return params;
-    }
-
-    /////////////////////////////////////////////////////
-    /////////////// API Implementation///////////////////
-    /////////////////////////////////////////////////////
-
-    @Override
-    public String getCommandName() {
-        return s_name;
-    }
-
-    @Override
-    public long getEntityOwnerId() {
-        Account account = _entityMgr.findById(Account.class, getId());
-        if (account != null) {
-            return account.getAccountId();
-        }
-        account = _accountService.getActiveAccountByName(getAccountName(), 
getDomainId());
-        if (account != null) {
-            return account.getAccountId();
-        }
-
-        return Account.ACCOUNT_ID_SYSTEM; // no account info given, parent 
this command to SYSTEM so ERROR events are tracked
-    }
-
-    @Override
-    public void execute(){
-        Account result = _accountService.updateAccount(this);
-        if (result != null){
-            AccountResponse response = 
_responseGenerator.createAccountResponse(result);
-            response.setResponseName(getCommandName());
-            this.setResponseObject(response);
-        } else {
-            throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to 
update account");
-        }
-    }
-}

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/1b1d91dc/api/src/com/cloud/user/AccountService.java
----------------------------------------------------------------------
diff --git a/api/src/com/cloud/user/AccountService.java 
b/api/src/com/cloud/user/AccountService.java
index 8be8e9e..fe68c3e 100755
--- a/api/src/com/cloud/user/AccountService.java
+++ b/api/src/com/cloud/user/AccountService.java
@@ -26,7 +26,7 @@ import 
org.apache.cloudstack.api.admin.user.command.UpdateUserCmd;
 import org.apache.cloudstack.api.user.account.command.ListAccountsCmd;
 import org.apache.cloudstack.api.admin.user.command.ListUsersCmd;
 import com.cloud.api.commands.RegisterCmd;
-import com.cloud.api.commands.UpdateAccountCmd;
+import org.apache.cloudstack.api.admin.account.command.UpdateAccountCmd;
 import com.cloud.domain.Domain;
 import com.cloud.exception.ConcurrentOperationException;
 import com.cloud.exception.PermissionDeniedException;

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/1b1d91dc/api/src/org/apache/cloudstack/api/admin/account/command/CreateAccountCmd.java
----------------------------------------------------------------------
diff --git 
a/api/src/org/apache/cloudstack/api/admin/account/command/CreateAccountCmd.java 
b/api/src/org/apache/cloudstack/api/admin/account/command/CreateAccountCmd.java
new file mode 100755
index 0000000..99ff4c2
--- /dev/null
+++ 
b/api/src/org/apache/cloudstack/api/admin/account/command/CreateAccountCmd.java
@@ -0,0 +1,159 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you 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.apache.cloudstack.api.admin.account.command;
+
+import java.util.Collection;
+import java.util.Map;
+
+import org.apache.log4j.Logger;
+
+import org.apache.cloudstack.api.ApiConstants;
+import org.apache.cloudstack.api.BaseCmd;
+import org.apache.cloudstack.api.IdentityMapper;
+import org.apache.cloudstack.api.Implementation;
+import org.apache.cloudstack.api.Parameter;
+import org.apache.cloudstack.api.ServerApiException;
+import com.cloud.api.response.AccountResponse;
+import com.cloud.api.response.UserResponse;
+import com.cloud.user.Account;
+import com.cloud.user.UserAccount;
+import com.cloud.user.UserContext;
+
+@Implementation(description="Creates an account", 
responseObject=UserResponse.class)
+public class CreateAccountCmd extends BaseCmd {
+    public static final Logger s_logger = 
Logger.getLogger(CreateAccountCmd.class.getName());
+
+    private static final String s_name = "createaccountresponse";
+
+    /////////////////////////////////////////////////////
+    //////////////// API parameters /////////////////////
+    /////////////////////////////////////////////////////
+
+    @Parameter(name=ApiConstants.ACCOUNT, type=CommandType.STRING, 
description="Creates the user under the specified account. If no account is 
specified, the username will be used as the account name.")
+    private String accountName;
+
+    @Parameter(name=ApiConstants.ACCOUNT_TYPE, type=CommandType.SHORT, 
required=true, description="Type of the account.  Specify 0 for user, 1 for 
root admin, and 2 for domain admin")
+    private Short accountType;
+
+    @IdentityMapper(entityTableName="domain")
+    @Parameter(name=ApiConstants.DOMAIN_ID, type=CommandType.LONG, 
description="Creates the user under the specified domain.")
+    private Long domainId;
+
+    @Parameter(name=ApiConstants.EMAIL, type=CommandType.STRING, 
required=true, description="email")
+    private String email;
+
+    @Parameter(name=ApiConstants.FIRSTNAME, type=CommandType.STRING, 
required=true, description="firstname")
+    private String firstName;
+
+    @Parameter(name=ApiConstants.LASTNAME, type=CommandType.STRING, 
required=true, description="lastname")
+    private String lastName;
+
+    @Parameter(name=ApiConstants.PASSWORD, type=CommandType.STRING, 
required=true, description="Hashed password (Default is MD5). If you wish to 
use any other hashing algorithm, you would need to write a custom 
authentication adapter See Docs section.")
+    private String password;
+
+    @Parameter(name=ApiConstants.TIMEZONE, type=CommandType.STRING, 
description="Specifies a timezone for this command. For more information on the 
timezone parameter, see Time Zone Format.")
+    private String timeZone;
+
+    @Parameter(name=ApiConstants.USERNAME, type=CommandType.STRING, 
required=true, description="Unique username.")
+    private String userName;
+
+    @Parameter(name=ApiConstants.NETWORK_DOMAIN, type=CommandType.STRING, 
description="Network domain for the account's networks")
+    private String networkDomain;
+
+    @Parameter(name = ApiConstants.ACCOUNT_DETAILS, type = CommandType.MAP, 
description = "details for account used to store specific parameters")
+    private Map<String, String> details;
+    /////////////////////////////////////////////////////
+    /////////////////// Accessors ///////////////////////
+    /////////////////////////////////////////////////////
+
+    public String getAccountName() {
+        return accountName;
+    }
+
+    public Short getAccountType() {
+        return accountType;
+    }
+
+    public Long getDomainId() {
+        return domainId;
+    }
+
+    public String getEmail() {
+        return email;
+    }
+
+    public String getFirstName() {
+        return firstName;
+    }
+
+    public String getLastName() {
+        return lastName;
+    }
+
+    public String getPassword() {
+        return password;
+    }
+
+    public String getTimeZone() {
+        return timeZone;
+    }
+
+    public String getUsername() {
+        return userName;
+    }
+
+    public String getNetworkDomain() {
+        return networkDomain;
+    }
+
+    public Map<String, String> getDetails() {
+        if (details == null || details.isEmpty()) {
+            return null;
+        }
+
+        Collection<String> paramsCollection = details.values();
+        Map<String, String> params = (Map<String, String>) 
(paramsCollection.toArray())[0];
+        return params;
+    }
+
+    /////////////////////////////////////////////////////
+    /////////////// API Implementation///////////////////
+    /////////////////////////////////////////////////////
+
+    @Override
+    public String getCommandName() {
+        return s_name;
+    }
+
+    @Override
+    public long getEntityOwnerId() {
+        return Account.ACCOUNT_ID_SYSTEM;
+    }
+
+    @Override
+    public void execute(){
+        UserContext.current().setEventDetails("Account Name: 
"+getAccountName()+", Domain Id:"+getDomainId());
+        UserAccount userAccount = 
_accountService.createUserAccount(getUsername(), getPassword(), getFirstName(), 
getLastName(), getEmail(), getTimeZone(), getAccountName(), getAccountType(), 
getDomainId(), getNetworkDomain(), getDetails());
+        if (userAccount != null) {
+            AccountResponse response = 
_responseGenerator.createUserAccountResponse(userAccount);
+            response.setResponseName(getCommandName());
+            this.setResponseObject(response);
+        } else {
+            throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to 
create a user account");
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/1b1d91dc/api/src/org/apache/cloudstack/api/admin/account/command/DeleteAccountCmd.java
----------------------------------------------------------------------
diff --git 
a/api/src/org/apache/cloudstack/api/admin/account/command/DeleteAccountCmd.java 
b/api/src/org/apache/cloudstack/api/admin/account/command/DeleteAccountCmd.java
new file mode 100755
index 0000000..d00d7c8
--- /dev/null
+++ 
b/api/src/org/apache/cloudstack/api/admin/account/command/DeleteAccountCmd.java
@@ -0,0 +1,109 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you 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.apache.cloudstack.api.admin.account.command;
+
+import org.apache.log4j.Logger;
+
+import org.apache.cloudstack.api.ApiConstants;
+import org.apache.cloudstack.api.BaseAsyncCmd;
+import org.apache.cloudstack.api.BaseCmd;
+import org.apache.cloudstack.api.IdentityMapper;
+import org.apache.cloudstack.api.Implementation;
+import org.apache.cloudstack.api.Parameter;
+import org.apache.cloudstack.api.ServerApiException;
+import com.cloud.api.response.SuccessResponse;
+import com.cloud.async.AsyncJob;
+import com.cloud.event.EventTypes;
+import com.cloud.user.Account;
+import com.cloud.user.User;
+import com.cloud.user.UserContext;
+
+@Implementation(description="Deletes a account, and all users associated with 
this account", responseObject=SuccessResponse.class)
+public class DeleteAccountCmd extends BaseAsyncCmd {
+    public static final Logger s_logger = 
Logger.getLogger(DeleteAccountCmd.class.getName());
+    private static final String s_name = "deleteaccountresponse";
+
+    /////////////////////////////////////////////////////
+    //////////////// API parameters /////////////////////
+    /////////////////////////////////////////////////////
+
+
+    @IdentityMapper(entityTableName="account")
+    @Parameter(name=ApiConstants.ID, type=CommandType.LONG, required=true, 
description="Account id")
+    private Long id;
+
+
+    /////////////////////////////////////////////////////
+    /////////////////// Accessors ///////////////////////
+    /////////////////////////////////////////////////////
+
+    public Long getId() {
+        return id;
+    }
+
+
+    /////////////////////////////////////////////////////
+    /////////////// API Implementation///////////////////
+    /////////////////////////////////////////////////////
+
+    public static String getStaticName() {
+        return s_name;
+    }
+
+    @Override
+    public String getCommandName() {
+        return s_name;
+    }
+
+    @Override
+    public long getEntityOwnerId() {
+        Account account = UserContext.current().getCaller();// Let's give the 
caller here for event logging.
+        if (account != null) {
+            return account.getAccountId();
+        }
+
+        return Account.ACCOUNT_ID_SYSTEM; // no account info given, parent 
this command to SYSTEM so ERROR events are tracked
+    }
+
+    @Override
+    public String getEventType() {
+        return EventTypes.EVENT_ACCOUNT_DELETE;
+    }
+
+    @Override
+    public String getEventDescription() {
+        User user = _responseGenerator.findUserById(getId());
+        return (user != null ? ("deleting User " + user.getUsername() + " (id: 
" + user.getId() + ") and accountId = " + user.getAccountId()) : "user delete, 
but this user does not exist in the system");
+    }
+
+    @Override
+    public void execute(){
+        UserContext.current().setEventDetails("Account Id: "+getId());
+        boolean result = _accountService.deleteUserAccount(getId());
+        if (result) {
+            SuccessResponse response = new SuccessResponse(getCommandName());
+            this.setResponseObject(response);
+        } else {
+            throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to 
delete user account and all corresponding users");
+        }
+    }
+
+    @Override
+    public AsyncJob.Type getInstanceType() {
+        return AsyncJob.Type.Account;
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/1b1d91dc/api/src/org/apache/cloudstack/api/admin/account/command/UpdateAccountCmd.java
----------------------------------------------------------------------
diff --git 
a/api/src/org/apache/cloudstack/api/admin/account/command/UpdateAccountCmd.java 
b/api/src/org/apache/cloudstack/api/admin/account/command/UpdateAccountCmd.java
new file mode 100755
index 0000000..9bb095e
--- /dev/null
+++ 
b/api/src/org/apache/cloudstack/api/admin/account/command/UpdateAccountCmd.java
@@ -0,0 +1,130 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you 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.apache.cloudstack.api.admin.account.command;
+
+import java.util.Collection;
+import java.util.Map;
+
+import org.apache.log4j.Logger;
+
+import org.apache.cloudstack.api.ApiConstants;
+import org.apache.cloudstack.api.BaseCmd;
+import org.apache.cloudstack.api.IdentityMapper;
+import org.apache.cloudstack.api.Implementation;
+import org.apache.cloudstack.api.Parameter;
+import org.apache.cloudstack.api.ServerApiException;
+import com.cloud.api.response.AccountResponse;
+import com.cloud.user.Account;
+
+@Implementation(description="Updates account information for the authenticated 
user", responseObject=AccountResponse.class)
+public class UpdateAccountCmd extends BaseCmd{
+    public static final Logger s_logger = 
Logger.getLogger(UpdateAccountCmd.class.getName());
+    private static final String s_name = "updateaccountresponse";
+
+    /////////////////////////////////////////////////////
+    //////////////// API parameters /////////////////////
+    /////////////////////////////////////////////////////
+
+    @IdentityMapper(entityTableName="account")
+    @Parameter(name=ApiConstants.ID, type=CommandType.LONG, 
description="Account id")
+    private Long id;
+
+    @Parameter(name=ApiConstants.ACCOUNT, type=CommandType.STRING, 
description="the current account name")
+    private String accountName;
+
+    @IdentityMapper(entityTableName="domain")
+    @Parameter(name=ApiConstants.DOMAIN_ID, type=CommandType.LONG, 
description="the ID of the domain where the account exists")
+    private Long domainId;
+
+    @Parameter(name=ApiConstants.NEW_NAME, type=CommandType.STRING, 
required=true, description="new name for the account")
+    private String newName;
+
+    @Parameter(name=ApiConstants.NETWORK_DOMAIN, type=CommandType.STRING, 
description="Network domain for the account's networks; empty string will 
update domainName with NULL value")
+    private String networkDomain;
+
+    @Parameter(name = ApiConstants.ACCOUNT_DETAILS, type = CommandType.MAP, 
description = "details for account used to store specific parameters")
+    private Map details;
+
+    /////////////////////////////////////////////////////
+    /////////////////// Accessors ///////////////////////
+    /////////////////////////////////////////////////////
+
+    public Long getId() {
+        return id;
+    }
+
+    public String getAccountName() {
+        return accountName;
+    }
+
+    public Long getDomainId() {
+        return domainId;
+    }
+
+    public String getNewName() {
+        return newName;
+    }
+
+    public String getNetworkDomain() {
+        return networkDomain;
+    }
+
+    public Map getDetails() {
+        if (details == null || details.isEmpty()) {
+            return null;
+        }
+
+        Collection paramsCollection = details.values();
+        Map params = (Map) (paramsCollection.toArray())[0];
+        return params;
+    }
+
+    /////////////////////////////////////////////////////
+    /////////////// API Implementation///////////////////
+    /////////////////////////////////////////////////////
+
+    @Override
+    public String getCommandName() {
+        return s_name;
+    }
+
+    @Override
+    public long getEntityOwnerId() {
+        Account account = _entityMgr.findById(Account.class, getId());
+        if (account != null) {
+            return account.getAccountId();
+        }
+        account = _accountService.getActiveAccountByName(getAccountName(), 
getDomainId());
+        if (account != null) {
+            return account.getAccountId();
+        }
+
+        return Account.ACCOUNT_ID_SYSTEM; // no account info given, parent 
this command to SYSTEM so ERROR events are tracked
+    }
+
+    @Override
+    public void execute(){
+        Account result = _accountService.updateAccount(this);
+        if (result != null){
+            AccountResponse response = 
_responseGenerator.createAccountResponse(result);
+            response.setResponseName(getCommandName());
+            this.setResponseObject(response);
+        } else {
+            throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to 
update account");
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/1b1d91dc/client/tomcatconf/commands.properties.in
----------------------------------------------------------------------
diff --git a/client/tomcatconf/commands.properties.in 
b/client/tomcatconf/commands.properties.in
index a0ac700..decd475 100755
--- a/client/tomcatconf/commands.properties.in
+++ b/client/tomcatconf/commands.properties.in
@@ -19,9 +19,9 @@
 ### Please standardize naming conventions to camel-case (even for acronyms).
 
 ### Account commands
-createAccount=com.cloud.api.commands.CreateAccountCmd;3
-deleteAccount=com.cloud.api.commands.DeleteAccountCmd;3
-updateAccount=com.cloud.api.commands.UpdateAccountCmd;3
+createAccount=org.apache.cloudstack.api.admin.account.command.CreateAccountCmd;3
+deleteAccount=org.apache.cloudstack.api.admin.account.command.DeleteAccountCmd;3
+updateAccount=org.apache.cloudstack.api.admin.account.command.UpdateAccountCmd;3
 
disableAccount=org.apache.cloudstack.api.admin.account.command.DisableAccountCmd;7
 
enableAccount=org.apache.cloudstack.api.admin.account.command.EnableAccountCmd;7
 ###lockAccount=com.cloud.api.commands.LockAccountCmd;7

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/1b1d91dc/server/src/com/cloud/user/AccountManagerImpl.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/user/AccountManagerImpl.java 
b/server/src/com/cloud/user/AccountManagerImpl.java
index 59b7584..ae5be66 100755
--- a/server/src/com/cloud/user/AccountManagerImpl.java
+++ b/server/src/com/cloud/user/AccountManagerImpl.java
@@ -48,7 +48,7 @@ import com.cloud.api.ApiDBUtils;
 import org.apache.cloudstack.api.admin.user.command.DeleteUserCmd;
 import org.apache.cloudstack.api.user.account.command.ListAccountsCmd;
 import com.cloud.api.commands.RegisterCmd;
-import com.cloud.api.commands.UpdateAccountCmd;
+import org.apache.cloudstack.api.admin.account.command.UpdateAccountCmd;
 import org.apache.cloudstack.api.admin.user.command.UpdateUserCmd;
 import com.cloud.configuration.Config;
 import com.cloud.configuration.ConfigurationManager;

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/1b1d91dc/server/test/com/cloud/user/MockAccountManagerImpl.java
----------------------------------------------------------------------
diff --git a/server/test/com/cloud/user/MockAccountManagerImpl.java 
b/server/test/com/cloud/user/MockAccountManagerImpl.java
index 3b1adc6..484a2cc 100644
--- a/server/test/com/cloud/user/MockAccountManagerImpl.java
+++ b/server/test/com/cloud/user/MockAccountManagerImpl.java
@@ -28,7 +28,7 @@ import 
org.apache.cloudstack.api.admin.user.command.DeleteUserCmd;
 import org.apache.cloudstack.api.admin.user.command.ListUsersCmd;
 import org.apache.cloudstack.api.user.account.command.ListAccountsCmd;
 import com.cloud.api.commands.RegisterCmd;
-import com.cloud.api.commands.UpdateAccountCmd;
+import org.apache.cloudstack.api.admin.account.command.UpdateAccountCmd;
 import org.apache.cloudstack.api.admin.user.command.UpdateUserCmd;
 import com.cloud.api.view.vo.ControlledViewEntity;
 import com.cloud.domain.Domain;

Reply via email to