@@ -966,12 +966,18 @@ public boolean deleteUserAccount(long accountId) {
966966 }
967967
968968 @ Override
969- public AccountVO enableAccount (String accountName , long domainId ) {
969+ public AccountVO enableAccount (String accountName , Long domainId , Long accountId ) {
970970
971971 // Check if account exists
972- Account account = _accountDao .findActiveAccount (accountName , domainId );
972+ Account account = null ;
973+ if (accountId != null ){
974+ account = _accountDao .findById (accountId );
975+ }else {
976+ account = _accountDao .findActiveAccount (accountName , domainId );
977+ }
978+
973979 if (account == null || account .getType () == Account .ACCOUNT_TYPE_PROJECT ) {
974- throw new InvalidParameterValueException ("Unable to find account " + accountName + " in domain " + domainId );
980+ throw new InvalidParameterValueException ("Unable to find account by accountId: " + accountId + " OR by name: " + accountName + " in domain " + domainId );
975981 }
976982
977983 // Don't allow to modify system account
@@ -987,18 +993,24 @@ public AccountVO enableAccount(String accountName, long domainId) {
987993 if (success ) {
988994 return _accountDao .findById (account .getId ());
989995 } else {
990- throw new CloudRuntimeException ("Unable to enable account " + accountName + " in domain " + domainId );
996+ throw new CloudRuntimeException ("Unable to enable account by accountId: " + accountId + " OR by name: " + accountName + " in domain " + domainId );
991997 }
992998 }
993999
9941000 @ Override
9951001 @ ActionEvent (eventType = EventTypes .EVENT_ACCOUNT_DISABLE , eventDescription = "locking account" , async = true )
996- public AccountVO lockAccount (String accountName , Long domainId ) {
1002+ public AccountVO lockAccount (String accountName , Long domainId , Long accountId ) {
9971003 Account caller = UserContext .current ().getCaller ();
9981004
999- Account account = _accountDao .findActiveAccount (accountName , domainId );
1005+ Account account = null ;
1006+ if (accountId != null ){
1007+ account = _accountDao .findById (accountId );
1008+ }else {
1009+ account = _accountDao .findActiveAccount (accountName , domainId );
1010+ }
1011+
10001012 if (account == null || account .getType () == Account .ACCOUNT_TYPE_PROJECT ) {
1001- throw new InvalidParameterValueException ("Unable to find active account with name " + accountName + " in domain " + domainId );
1013+ throw new InvalidParameterValueException ("Unable to find active account by accountId: " + accountId + " OR by name: " + accountName + " in domain " + domainId );
10021014 }
10031015
10041016 checkAccess (caller , null , account );
@@ -1011,44 +1023,56 @@ public AccountVO lockAccount(String accountName, Long domainId) {
10111023 if (lockAccount (account .getId ())) {
10121024 return _accountDao .findById (account .getId ());
10131025 } else {
1014- throw new CloudRuntimeException ("Unable to lock account " + accountName + " in domain " + domainId );
1026+ throw new CloudRuntimeException ("Unable to lock account by accountId: " + accountId + " OR by name: " + accountName + " in domain " + domainId );
10151027 }
10161028 }
10171029
10181030 @ Override
10191031 @ ActionEvent (eventType = EventTypes .EVENT_ACCOUNT_DISABLE , eventDescription = "disabling account" , async = true )
1020- public AccountVO disableAccount (String accountName , Long domainId ) throws ConcurrentOperationException , ResourceUnavailableException {
1032+ public AccountVO disableAccount (String accountName , Long domainId , Long accountId ) throws ConcurrentOperationException , ResourceUnavailableException {
10211033 Account caller = UserContext .current ().getCaller ();
10221034
1023- Account account = _accountDao .findActiveAccount (accountName , domainId );
1035+ Account account = null ;
1036+ if (accountId != null ){
1037+ account = _accountDao .findById (accountId );
1038+ }else {
1039+ account = _accountDao .findActiveAccount (accountName , domainId );
1040+ }
1041+
10241042 if (account == null || account .getType () == Account .ACCOUNT_TYPE_PROJECT ) {
1025- throw new InvalidParameterValueException ("Unable to find account " + accountName + " in domain " + domainId );
1043+ throw new InvalidParameterValueException ("Unable to find account by accountId: " + accountId + " OR by name: " + accountName + " in domain " + domainId );
10261044 }
10271045
10281046 checkAccess (caller , null , account );
10291047
10301048 if (disableAccount (account .getId ())) {
10311049 return _accountDao .findById (account .getId ());
10321050 } else {
1033- throw new CloudRuntimeException ("Unable to update account " + accountName + " in domain " + domainId );
1051+ throw new CloudRuntimeException ("Unable to update account by accountId: " + accountId + " OR by name: " + accountName + " in domain " + domainId );
10341052 }
10351053 }
10361054
10371055 @ Override
10381056 public AccountVO updateAccount (UpdateAccountCmd cmd ) {
1057+ Long accountId = cmd .getId ();
10391058 Long domainId = cmd .getDomainId ();
10401059 String accountName = cmd .getAccountName ();
10411060 String newAccountName = cmd .getNewName ();
10421061 String networkDomain = cmd .getNetworkDomain ();
10431062 Map <String , String >details = cmd .getDetails ();
10441063
10451064 boolean success = false ;
1046- Account account = _accountDao .findAccount (accountName , domainId );
1065+ Account account = null ;
1066+ if (accountId != null ){
1067+ account = _accountDao .findById (accountId );
1068+ }else {
1069+ account = _accountDao .findAccount (accountName , domainId );
1070+ }
10471071
10481072 // Check if account exists
10491073 if (account == null || account .getType () == Account .ACCOUNT_TYPE_PROJECT ) {
1050- s_logger .error ("Unable to find account " + accountName + " in domain " + domainId );
1051- throw new InvalidParameterValueException ("Unable to find account " + accountName + " in domain " + domainId );
1074+ s_logger .error ("Unable to find account by accountId: " + accountId + " OR by name: " + accountName + " in domain " + domainId );
1075+ throw new InvalidParameterValueException ("Unable to find account by accountId: " + accountId + " OR by name: " + accountName + " in domain " + domainId );
10521076 }
10531077
10541078 // Don't allow to modify system account
@@ -1095,7 +1119,7 @@ public AccountVO updateAccount(UpdateAccountCmd cmd) {
10951119 if (success ) {
10961120 return _accountDao .findById (account .getId ());
10971121 } else {
1098- throw new CloudRuntimeException ("Unable to update account " + accountName + " in domain " + domainId );
1122+ throw new CloudRuntimeException ("Unable to update account by accountId: " + accountId + " OR by name: " + accountName + " in domain " + domainId );
10991123 }
11001124 }
11011125
0 commit comments