CLOUDSTACK-84: fixed NPE that used to happen on API layer when list resource of the project was called when project was going through removal process.

This commit is contained in:
Alena Prokharchyk 2012-10-05 14:20:22 -07:00
parent f6ab8b4344
commit be2017849a
6 changed files with 25 additions and 4 deletions

View File

@ -93,4 +93,6 @@ public interface ProjectService {
Project enableProject(long projectId);
boolean deleteProjectInvitation(long invitationId);
Project findByProjectAccountIdIncludingRemoved(long projectAccountId);
}

View File

@ -733,6 +733,10 @@ public class ApiDBUtils {
return _projectMgr.findByProjectAccountId(projectAccountId);
}
public static Project findProjectByProjectAccountIdIncludingRemoved(long projectAccountId) {
return _projectMgr.findByProjectAccountIdIncludingRemoved(projectAccountId);
}
public static Project findProjectById(long projectId) {
return _projectMgr.getProject(projectId);
}

View File

@ -2746,7 +2746,7 @@ public class ApiResponseHelper implements ResponseGenerator {
regularAccounts.add(accountName);
} else {
// convert account to projectIds
Project project = ApiDBUtils.findProjectByProjectAccountId(account.getId());
Project project = ApiDBUtils.findProjectByProjectAccountIdIncludingRemoved(account.getId());
if (project.getUuid() != null && !project.getUuid().isEmpty())
projectIds.add(project.getUuid());
@ -3343,7 +3343,7 @@ public class ApiResponseHelper implements ResponseGenerator {
if (account.getType() == Account.ACCOUNT_TYPE_PROJECT) {
// find the project
Project project = ApiDBUtils.findProjectByProjectAccountId(account.getId());
Project project = ApiDBUtils.findProjectByProjectAccountIdIncludingRemoved(account.getId());
response.setProjectId(project.getId());
response.setProjectName(project.getName());
} else {
@ -3359,7 +3359,7 @@ public class ApiResponseHelper implements ResponseGenerator {
Account account = ApiDBUtils.findAccountByIdIncludingRemoved(accountId);
if (account.getType() == Account.ACCOUNT_TYPE_PROJECT) {
// find the project
Project project = ApiDBUtils.findProjectByProjectAccountId(account.getId());
Project project = ApiDBUtils.findProjectByProjectAccountIdIncludingRemoved(account.getId());
response.setProjectId(project.getId());
response.setProjectName(project.getName());
} else {
@ -3670,7 +3670,7 @@ public class ApiResponseHelper implements ResponseGenerator {
if (account.getType() == Account.ACCOUNT_TYPE_PROJECT) {
// find the project
Project project = ApiDBUtils.findProjectByProjectAccountId(account.getId());
Project project = ApiDBUtils.findProjectByProjectAccountIdIncludingRemoved(account.getId());
response.setProjectId(project.getId());
response.setProjectName(project.getName());
} else {

View File

@ -515,6 +515,11 @@ public class ProjectManagerImpl implements ProjectManager, Manager{
return _projectDao.findByProjectAccountId(projectAccountId);
}
@Override
public ProjectVO findByProjectAccountIdIncludingRemoved(long projectAccountId) {
return _projectDao.findByProjectAccountIdIncludingRemoved(projectAccountId);
}
@Override
public Project findByNameAndDomainId(String name, long domainId) {
return _projectDao.findByNameAndDomain(name, domainId);

View File

@ -31,5 +31,7 @@ public interface ProjectDao extends GenericDao<ProjectVO, Long> {
ProjectVO findByProjectAccountId(long projectAccountId);
List<ProjectVO> listByState(Project.State state);
ProjectVO findByProjectAccountIdIncludingRemoved(long projectAccountId);
}

View File

@ -108,4 +108,12 @@ public class ProjectDaoImpl extends GenericDaoBase<ProjectVO, Long> implements P
sc.setParameters("state", state);
return listBy(sc);
}
@Override
public ProjectVO findByProjectAccountIdIncludingRemoved(long projectAccountId) {
SearchCriteria<ProjectVO> sc = AllFieldsSearch.create();
sc.setParameters("projectAccountId", projectAccountId);
return findOneIncludingRemovedBy(sc);
}
}