@Override public boolean enableAccount(long accountId) { boolean success = false; AccountVO acctForUpdate = _accountDao.createForUpdate(); acctForUpdate.setState(State.enabled); acctForUpdate.setNeedsCleanup(false); success = _accountDao.update(Long.valueOf(accountId), acctForUpdate); return success; }
protected boolean lockAccount(long accountId) { boolean success = false; Account account = _accountDao.findById(accountId); if (account != null) { if (account.getState().equals(State.locked)) { return true; // already locked, no-op } else if (account.getState().equals(State.enabled)) { AccountVO acctForUpdate = _accountDao.createForUpdate(); acctForUpdate.setState(State.locked); success = _accountDao.update(Long.valueOf(accountId), acctForUpdate); } else { if (s_logger.isInfoEnabled()) { s_logger.info("Attempting to lock a non-enabled account, current state is " + account.getState() + " (accountId: " + accountId + "), locking failed."); } } } else { s_logger.warn("Failed to lock account " + accountId + ", account not found."); } return success; }
protected boolean lockAccount(long accountId) { final short opendb = TransactionLegacy.currentTxn().getDatabaseId(); boolean success = false; try (TransactionLegacy txn = TransactionLegacy.open(TransactionLegacy.CLOUD_DB)) { Account account = _accountDao.findById(accountId); if (account != null) { if (account.getState() == State.locked) { return true; // already locked, no-op } else if (account.getState() == State.enabled) { AccountVO acctForUpdate = _accountDao.createForUpdate(); acctForUpdate.setState(State.locked); success = _accountDao.update(Long.valueOf(accountId), acctForUpdate); } else { if (s_logger.isInfoEnabled()) { s_logger.info("Attempting to lock a non-enabled account, current state is " + account.getState() + " (accountId: " + accountId + "), locking failed."); } } } else { s_logger.warn("Failed to lock account " + accountId + ", account not found."); } } catch (Exception e) { s_logger.error("Exception occured while locking account by Quota Alert Manager", e); throw e; } finally { TransactionLegacy.open(opendb).close(); } return success; }
@Override @ActionEvent(eventType = EventTypes.EVENT_ACCOUNT_MARK_DEFAULT_ZONE, eventDescription = "Marking account with the " + "default zone", async = true) public AccountVO markDefaultZone(final String accountName, final long domainId, final long defaultZoneId) { // Check if the account exists final Account account = _accountDao.findEnabledAccount(accountName, domainId); if (account == null) { s_logger.error("Unable to find account by name: " + accountName + " in domain " + domainId); throw new InvalidParameterValueException("Account by name: " + accountName + " doesn't exist in domain " + domainId); } // Don't allow modification of system account if (account.getId() == Account.ACCOUNT_ID_SYSTEM) { throw new InvalidParameterValueException("Can not modify system account"); } final AccountVO acctForUpdate = _accountDao.findById(account.getId()); acctForUpdate.setDefaultZoneId(defaultZoneId); if (_accountDao.update(account.getId(), acctForUpdate)) { CallContext.current().setEventDetails("Default zone id= " + defaultZoneId); return _accountDao.findById(account.getId()); } else { return null; } }
} else { account.setNeedsCleanup(false); _accountDao.update(accountId, account);
boolean success1 = _accountDao.update(accountFinal.getId(), acctForUpdate);