@@ -246,40 +246,49 @@ public Project enableProject(long projectId){
246246
247247
248248 @ Override
249- @ ActionEvent (eventType = EventTypes .EVENT_PROJECT_DELETE , eventDescription = "deleting project" , async = true )
250- @ DB
251- public boolean deleteProject (long projectId ) {
249+ @ ActionEvent (eventType = EventTypes .EVENT_PROJECT_DELETE , eventDescription = "deleting project" , async = true )
250+ public boolean deleteProject (long projectId ) {
252251 UserContext ctx = UserContext .current ();
253- Account caller = ctx .getCaller ();
254252
255253 ProjectVO project = getProject (projectId );
256254 //verify input parameters
257255 if (project == null ) {
258256 throw new InvalidParameterValueException ("Unable to find project by id " + projectId );
259257 }
260258
261- _accountMgr .checkAccess (caller ,AccessType .ModifyProject , true , _accountMgr .getAccount (project .getProjectAccountId ()));
259+ _accountMgr .checkAccess (ctx . getCaller () ,AccessType .ModifyProject , true , _accountMgr .getAccount (project .getProjectAccountId ()));
262260
261+ return deleteProject (ctx .getCaller (), ctx .getCallerUserId (), project );
262+ }
263+
264+ @ DB
265+ @ Override
266+ public boolean deleteProject (Account caller , long callerUserId , ProjectVO project ) {
263267 //mark project as inactive first, so you can't add resources to it
264268 Transaction txn = Transaction .currentTxn ();
265269 txn .start ();
266- s_logger .debug ("Marking project id=" + projectId + " with state " + State .Disabled + " as a part of project delete..." );
270+ s_logger .debug ("Marking project id=" + project . getId () + " with state " + State .Disabled + " as a part of project delete..." );
267271 project .setState (State .Disabled );
268- boolean updateResult = _projectDao .update (projectId , project );
269- _resourceLimitMgr .decrementResourceCount (getProjectOwner (projectId ).getId (), ResourceType .project );
272+ boolean updateResult = _projectDao .update (project .getId (), project );
273+ //owner can be already removed at this point, so adding the conditional check
274+ Account projectOwner = getProjectOwner (project .getId ());
275+ if (projectOwner != null ) {
276+ _resourceLimitMgr .decrementResourceCount (projectOwner .getId (), ResourceType .project );
277+ }
278+
270279 txn .commit ();
271280
272281 if (updateResult ) {
273- if (!cleanupProject (project , _accountDao .findById (caller .getId ()), ctx . getCallerUserId () )) {
274- s_logger .warn ("Failed to cleanup project's id=" + projectId + " resources, not removing the project yet" );
282+ if (!cleanupProject (project , _accountDao .findById (caller .getId ()), callerUserId )) {
283+ s_logger .warn ("Failed to cleanup project's id=" + project . getId () + " resources, not removing the project yet" );
275284 return false ;
276285 } else {
277- return _projectDao .remove (projectId );
286+ return _projectDao .remove (project . getId () );
278287 }
279288 } else {
280- s_logger .warn ("Failed to mark the project id=" + projectId + " with state " + State .Disabled );
289+ s_logger .warn ("Failed to mark the project id=" + project . getId () + " with state " + State .Disabled );
281290 return false ;
282- }
291+ }
283292 }
284293
285294 @ DB
@@ -376,16 +385,14 @@ public List<? extends Project> listProjects(Long id, String name, String display
376385 accountId = caller .getId ();
377386 }
378387
379- if (!listAll ) {
380- if (domainId == null && accountId == null ) {
381- accountId = caller .getId ();
382- } else {
383- if (caller .getType () == Account .ACCOUNT_TYPE_DOMAIN_ADMIN || !isRecursive ) {
384- DomainVO domain = _domainDao .findById (caller .getDomainId ());
385- path = domain .getPath ();
386- }
387- }
388+
389+ if (domainId == null && accountId == null ) {
390+ accountId = caller .getId ();
391+ } else if (caller .getType () == Account .ACCOUNT_TYPE_DOMAIN_ADMIN || (!isRecursive && !listAll )) {
392+ DomainVO domain = _domainDao .findById (caller .getDomainId ());
393+ path = domain .getPath ();
388394 }
395+
389396
390397 if (path != null ) {
391398 SearchBuilder <DomainVO > domainSearch = _domainDao .createSearchBuilder ();
@@ -469,8 +476,12 @@ public boolean deleteAccountFromProject(long projectId, long accountId) {
469476
470477 @ Override
471478 public Account getProjectOwner (long projectId ) {
472- long accountId = _projectAccountDao .getProjectOwner (projectId ).getAccountId ();
473- return _accountMgr .getAccount (accountId );
479+ ProjectAccount prAcct = _projectAccountDao .getProjectOwner (projectId );
480+ if (prAcct != null ) {
481+ return _accountMgr .getAccount (prAcct .getAccountId ());
482+ }
483+
484+ return null ;
474485 }
475486
476487 @ Override
0 commit comments