bug 8491: remove corresponding record from resource_limits table when limit is updated with -1 value

status 8491: resolved fixed
This commit is contained in:
alena 2011-02-08 19:01:06 -08:00
parent 68b50d04b0
commit ebdd7a68fa
2 changed files with 13 additions and 4 deletions

View File

@ -87,7 +87,7 @@ public class UpdateResourceLimitCmd extends BaseCmd {
@Override
public void execute(){
ResourceLimit result = _accountService.updateResourceLimit(this);
if (result != null){
if (result != null || (result == null && max != null && max.longValue() == -1L)){
ResourceLimitResponse response = _responseGenerator.createResourceLimitResponse(result);
response.setResponseName(getCommandName());
this.setResponseObject(response);

View File

@ -645,10 +645,19 @@ public class AccountManagerImpl implements AccountManager, AccountService, Manag
List<ResourceLimitVO> limits = _resourceLimitDao.search(sc, searchFilter);
if (limits.size() == 1) {
// Update the existing limit
ResourceLimitVO limit = limits.get(0);
_resourceLimitDao.update(limit.getId(), max);
return _resourceLimitDao.findById(limit.getId());
//if limit is set to -1, remove the record
if (max != null && max.longValue() == -1L) {
//this parameter is needed by API as it expects the object to be returned and updates the UI with the object's new "max" parameter
ResourceLimitVO limitToReturn = limit;
limitToReturn.setMax(-1L);
_resourceLimitDao.remove(limit.getId());
return limitToReturn;
} else {
// Update the existing limit
_resourceLimitDao.update(limit.getId(), max);
return _resourceLimitDao.findById(limit.getId());
}
} else {
// Persist the new Limit
return _resourceLimitDao.persist(new ResourceLimitVO(domainId, accountId, resourceType, max));