Note: This bug is displayed in read-only format because the product is no longer active in Red Hat Bugzilla.

Bug 947956

Summary: UserProfileDAOImpl not distinguishing creating and updating user profile when firing preSave/postSave events
Product: [JBoss] JBoss Enterprise Portal Platform 6 Reporter: Adam Kovari <akovari>
Component: PortalAssignee: Default User <jbpapp-maint>
Status: CLOSED CURRENTRELEASE QA Contact:
Severity: unspecified Docs Contact:
Priority: unspecified    
Version: 6.1.0CC: bdawidow, epp-bugs, laszlo.van.den.hoek, nobody, tkyjovsk, trangvh
Target Milestone: ER01   
Target Release: 6.1.0   
Hardware: Unspecified   
OS: Unspecified   
Whiteboard:
Fixed In Version: Doc Type: Bug Fix
Doc Text:
A problem with the way UserDAOImpl.saveUserProfile(UserProfile profile, boolean broadcast) flagged updates to existing user profiles caused UserProfileListener to not correctly detect whether the request was for a new user creation request or an existing user profile update. The fix ensures that for new user creation requests, UserProfileDAOImpl.saveUserProfile sends the flag isNew=true. Subsequent calls send isNew=false in preSave/postSave events for existing users. Listeners can now correctly determine whether the call is a UserProfile user creation or user update.
Story Points: ---
Clone Of: Environment:
Last Closed: 2013-11-07 14:24:08 UTC Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:

Description Adam Kovari 2013-04-03 15:47:25 UTC
Description of problem:
org.exoplatform.services.organization.idm.UserProfileDAOImpl; the following is a code excerpt of the file included in the community version of the Maven artefact  org.exoplatform.portal:exo.portal.component.identity:3.3.0-GA

   //   void createUserProfileEntry(UserProfile up, IdentitySession session) throws Exception
   //   {
   //      UserProfileData upd = new UserProfileData();
   //      upd.setUserProfile(up);
   //      session.save(upd);
   //      session.flush();
   //      cache_.remove(up.getUserName());
   //   }

   public void saveUserProfile(UserProfile profile, boolean broadcast) throws Exception
   {

      if (broadcast)
      {
         preSave(profile, true);
      }

      setProfile(profile.getUserName(), profile);

      if (broadcast)
      {
         postSave(profile, true);
      }

   }

As you can see, the preSave() method is always called with "true". However, saveUserProfile() is the only available method for persisting UserProfile objects. From the commented-out createUserProfileEntry() method, I draw the conclusion that at some point, there was a distinction between methods to call for new and existing UserProfiles (just as there is for Users in the UserDAOImpl in the same package - there are a createUser() and a saveUser()).

Where all this breaks down is in the listeners; upon saving the UserProfile, I want to send either a save or an update message over JMS to a SOA-P application that transforms the message and forwards it to a mainframe application that needs to know about user creation and modification. I need to pick the correct message format, but as it turns out, I can't use the isNew parameter to reliably determine which one to choose.

I have tried to work around the problem by creating the UserProfile first and the User second, and sync from the User Listener, since the User preSave() does receive a correct value for isNew; however, Hibernate won't let me: new UserProfiles can not be saved if the User they are associated with does not yet exist in the database; they are a dependent entity.

Can you provide a version of the Identity Component that can distinguish between updating and saving UserProfile objects, or a suitable workaround to that end?

Version-Release number of selected component (if applicable):
EPP 5
JPP 6

How reproducible:
always

Steps to Reproduce:
please see attached customer case
  
Actual results:
true as the parameter even with update

Expected results:
true/false depending on create or update

Additional info:

Comment 2 Tomas Kyjovsky 2013-08-15 13:10:14 UTC
Verified with 6.1.0.ER01.1 and ER04 using a custom UserEventListener.

Creating new user "test":
15:07:08,804 INFO  [stdout] (http-/127.0.0.1:8080-1) preSave(user:test, isNew:true)
15:07:08,804 INFO  [stdout] (http-/127.0.0.1:8080-1) preSave(user:test, isNew:true)
15:07:08,830 INFO  [stdout] (http-/127.0.0.1:8080-1) postSave(user:test, isNew:true)
15:07:08,894 INFO  [stdout] (http-/127.0.0.1:8080-1) postSave(user:test, isNew:true)

Updating created user "test":
15:07:18,435 INFO  [stdout] (http-/127.0.0.1:8080-1) preSave(user:test, isNew:false)
15:07:18,435 INFO  [stdout] (http-/127.0.0.1:8080-1) preSave(user:test, isNew:false)
15:07:18,443 INFO  [stdout] (http-/127.0.0.1:8080-1) postSave(user:test, isNew:false)
15:07:18,447 INFO  [stdout] (http-/127.0.0.1:8080-1) postSave(user:test, isNew:false)