Because Motorprise users can have roles such as approvers or admins, they may be referenced in the profiles of their parent organizations. For example, Ernesto Hernandez is listed as an approver in the profile of USMW - Wholesale.

When users are deleted, all such references to them must also be deleted. Failing to remove these references when deleting the users would result in referential integrity constraint violations.

To avoid this, we created a new class, atg.projects.b2bstore.userprofiling.B2BDeleteFormHandler, that extends MultiProfileUpdateFormHandler to override the behavior when user profiles are deleted. We remove any references to the user item in B2BDeleteFormHandler before handing it over to the base class for removing the user item. Using the B2BDeleteFormHandler is no different than using MultiProfileUpdateFormHandler. In Motorprise, users can be deleted from the Company Administration page using the Delete Users link (users_delete.jsp). We display a list of all the users with checkboxes and a Delete button to delete the selected users.

The following describes the code snippets from users_delete.jsp:

First, the repository ID of the organization is passed to the atg/userdirectory/droplet/UserList component to get the list of users for the current organizations. The ID of the admin who is accessing the page is passed into excludeId so that the admin is excluded from the returned list of users. This ensures that the admin may not delete his or her own account while logged into it:

<dsp:droplet name="UserList">
   <dsp:param bean="Profile.currentOrganization.repositoryid"
      name="organizationId"/>
<dsp:param bean="Profile.id" name="excludeId"/>
   <dsp:oparam name="output">

Next, we set the name of the user repository item in the form handler to delete:

<dsp:form action="users_delete_confirm.jsp" method="post">
   <dsp:input bean="DeleteProfileFormHandler.itemDescriptorName"
      type="hidden" value="user"/>

We used the Range droplet to get 10 items each time and display each user:

<dsp:droplet name="Range">
   <dsp:param name="array" param="users"/>
   <dsp:param name="start" param="startIndex"/>
   <dsp:param name="howMany" value="10"/>
   <dsp:param name="sortProperties" value="+name"/>

Next, we display a checkbox. When the admin selects this box on the page, the repository id of the corresponding user is added to DeleteProfileFormHandler.repositoryIds so that this user item is deleted from the repository:

<dsp:oparam name="output">
<dsp:input bean="DeleteProfileFormHandler.repositoryIds"
   paramvalue="element.repositoryItem.id" type="checkbox"/>
   <dsp:valueof param="element.repositoryItem.firstName"/>&nbsp;<dsp:valueof
      param="element.repositoryItem.lastName"/><BR>
</dsp:oparam>

<dsp:oparam name="outputEnd">
   <dsp:droplet name="IsEmpty">
     <dsp:param name="value" param="nextHowMany"/>
     <dsp:oparam name="false"><BR>
       <dsp:a href="users_delete.jsp">  Next 10 <dsp:param name="startIndex"
         param="nextStart"/></dsp:a>
     </dsp:oparam>
   </dsp:droplet>
</dsp:oparam>

When the admin selects users displayed by the code above and hits the Delete button, he or she is redirected to the delete confirmation screen (users_delete_confirm.jsp), which shows the users and a Delete button to confirm.

We get the repository ids of all the users that were selected to delete in the previous screen and fetch their profiles using the ProfileLookUp component to display user info:

<dsp:form action="company_admin.jsp" method="post">

   <dsp:droplet name="ForEach">
      <dsp:param bean="DeleteProfileFormHandler.repositoryIds" name="array"/>
      <dsp:param name="elementName" value="userId"/>
      <dsp:oparam name="output">
         <dsp:droplet name="ProfileLookUp">
            <dsp:param name="id" param="userId"/>
            <dsp:param name="elementName" value="user"/>
            <dsp:oparam name="output">
            <dsp:valueof param="user.firstName"/>
            &nbsp;
            <dsp:valueof param="user.lastName"/><br>
            </dsp:oparam>
         </dsp:droplet>
      </dsp:oparam>
   </dsp:droplet>

<br>
   <dsp:input bean="DeleteProfileFormHandler.delete" type="submit"
      value="Delete"/> &nbsp;
   <dsp:input bean="DeleteProfileFormHandler.cancel" type="submit"
      value="Cancel"/>
</dsp:form>
 
loading table of contents...