@@ -277,40 +277,39 @@ public Project createProject(final String name, final String displayText, String
277277 }
278278
279279 try (CheckedReservation projectReservation = new CheckedReservation (owner , ResourceType .project , null , null , 1L , reservationDao , _resourceLimitMgr )) {
280+ final Account ownerFinal = owner ;
281+ User finalUser = user ;
282+ Project project = Transaction .execute (new TransactionCallback <Project >() {
283+ @ Override
284+ public Project doInTransaction (TransactionStatus status ) {
280285
281- final Account ownerFinal = owner ;
282- User finalUser = user ;
283- Project project = Transaction .execute (new TransactionCallback <Project >() {
284- @ Override
285- public Project doInTransaction (TransactionStatus status ) {
286-
287- //Create an account associated with the project
288- StringBuilder acctNm = new StringBuilder ("PrjAcct-" );
289- acctNm .append (name ).append ("-" ).append (ownerFinal .getDomainId ());
286+ //Create an account associated with the project
287+ StringBuilder acctNm = new StringBuilder ("PrjAcct-" );
288+ acctNm .append (name ).append ("-" ).append (ownerFinal .getDomainId ());
290289
291- Account projectAccount = _accountMgr .createAccount (acctNm .toString (), Account .Type .PROJECT , null , domainId , null , null , UUID .randomUUID ().toString ());
290+ Account projectAccount = _accountMgr .createAccount (acctNm .toString (), Account .Type .PROJECT , null , domainId , null , null , UUID .randomUUID ().toString ());
292291
293- Project project = _projectDao .persist (new ProjectVO (name , displayText , ownerFinal .getDomainId (), projectAccount .getId ()));
292+ Project project = _projectDao .persist (new ProjectVO (name , displayText , ownerFinal .getDomainId (), projectAccount .getId ()));
294293
295- //assign owner to the project
296- assignAccountToProject (project , ownerFinal .getId (), ProjectAccount .Role .Admin ,
297- Optional .ofNullable (finalUser ).map (User ::getId ).orElse (null ), null );
294+ //assign owner to the project
295+ assignAccountToProject (project , ownerFinal .getId (), ProjectAccount .Role .Admin ,
296+ Optional .ofNullable (finalUser ).map (User ::getId ).orElse (null ), null );
298297
299- if (project != null ) {
300- CallContext .current ().setEventDetails ("Project id=" + project .getId ());
301- CallContext .current ().putContextParameter (Project .class , project .getUuid ());
302- }
298+ if (project != null ) {
299+ CallContext .current ().setEventDetails ("Project id=" + project .getId ());
300+ CallContext .current ().putContextParameter (Project .class , project .getUuid ());
301+ }
303302
304- //Increment resource count
305- _resourceLimitMgr .incrementResourceCount (ownerFinal .getId (), ResourceType .project );
303+ //Increment resource count
304+ _resourceLimitMgr .incrementResourceCount (ownerFinal .getId (), ResourceType .project );
306305
307- return project ;
308- }
309- });
306+ return project ;
307+ }
308+ });
310309
311- messageBus .publish (_name , ProjectManager .MESSAGE_CREATE_TUNGSTEN_PROJECT_EVENT , PublishScope .LOCAL , project );
310+ messageBus .publish (_name , ProjectManager .MESSAGE_CREATE_TUNGSTEN_PROJECT_EVENT , PublishScope .LOCAL , project );
312311
313- return project ;
312+ return project ;
314313 }
315314 }
316315
@@ -671,13 +670,13 @@ private void updateProjectAccount(ProjectAccountVO futureOwner, Role newAccRole,
671670 boolean shouldIncrementResourceCount = Role .Admin == newAccRole ;
672671
673672 try (CheckedReservation checkedReservation = new CheckedReservation (account , ResourceType .project , shouldIncrementResourceCount ? 1L : 0L , reservationDao , _resourceLimitMgr )) {
674- futureOwner .setAccountRole (newAccRole );
675- _projectAccountDao .update (futureOwner .getId (), futureOwner );
676- if (shouldIncrementResourceCount ) {
677- _resourceLimitMgr .incrementResourceCount (accountId , ResourceType .project );
678- } else {
679- _resourceLimitMgr .decrementResourceCount (accountId , ResourceType .project );
680- }
673+ futureOwner .setAccountRole (newAccRole );
674+ _projectAccountDao .update (futureOwner .getId (), futureOwner );
675+ if (shouldIncrementResourceCount ) {
676+ _resourceLimitMgr .incrementResourceCount (accountId , ResourceType .project );
677+ } else {
678+ _resourceLimitMgr .decrementResourceCount (accountId , ResourceType .project );
679+ }
681680 }
682681 }
683682
@@ -877,16 +876,16 @@ public boolean addAccountToProject(long projectId, String accountName, String em
877876
878877 boolean shouldIncrementResourceCount = projectRoleType != null && Role .Admin == projectRoleType ;
879878 try (CheckedReservation cr = new CheckedReservation (account , ResourceType .project , shouldIncrementResourceCount ? 1L : 0L , reservationDao , _resourceLimitMgr )) {
880- if (assignAccountToProject (project , account .getId (), projectRoleType , null ,
881- Optional .ofNullable (projectRole ).map (ProjectRole ::getId ).orElse (null )) != null ) {
882- if (shouldIncrementResourceCount ) {
883- _resourceLimitMgr .incrementResourceCount (account .getId (), ResourceType .project );
879+ if (assignAccountToProject (project , account .getId (), projectRoleType , null ,
880+ Optional .ofNullable (projectRole ).map (ProjectRole ::getId ).orElse (null )) != null ) {
881+ if (shouldIncrementResourceCount ) {
882+ _resourceLimitMgr .incrementResourceCount (account .getId (), ResourceType .project );
883+ }
884+ return true ;
885+ } else {
886+ logger .warn ("Failed to add account {} to project {}" , accountName , project );
887+ return false ;
884888 }
885- return true ;
886- } else {
887- logger .warn ("Failed to add account {} to project {}" , accountName , project );
888- return false ;
889- }
890889 }
891890 }
892891 }
0 commit comments