package com.kaviju.accesscontrol.component;

import com.kaviju.accesscontrol.model.KARoleGroup;
import com.kaviju.accesscontrol.model.KAUserProfile;
import com.webobjects.appserver.WOContext;
import com.webobjects.appserver.WOResponse;
import com.webobjects.foundation.NSArray;

import er.extensions.components.*;

import com.kaviju.accesscontrol.model.KARole;

@SuppressWarnings("serial")
public class UserPermProfileEditor extends ERXNonSynchronizingComponent {
	private KAUserProfile userProfile;
	private NSArray<KARoleGroup> groups;
	private KARoleGroup group;
	private KARole role;

	public UserPermProfileEditor(WOContext context) {
        super(context);
    }
	
	@Override
	protected void preAppendToResponse(WOResponse response, WOContext context) {
		super.preAppendToResponse(response, context);
		userProfile = (KAUserProfile) valueForBinding("userProfile");
		if (userProfile.profile() == null) {
			groups = new NSArray<KARoleGroup>();
		}
		else {
			groups = userProfile.profile().displayedGroups();
		}
	}

	public KAUserProfile userProfile() {
		return userProfile;
	}

	public NSArray<KARoleGroup> groups() {
		return groups;
	}

	public KARoleGroup group() {
		return group;
	}

	public void setGroup(KARoleGroup group) {
		this.group = group;
	}

	public NSArray<KARole> rolesInGroup() {
		return userProfile().profile().displayedRolesForGroup(group());
	}

	public KARole role() {
		return role;
	}

	public void setRole(KARole role) {
		this.role = role;
	}
}
@@ -80,72 +80,9 @@
 del.
-KARoleGroup;%0Aimport com.kaviju.accesscontrol.model.KAUserProfile
+*
 ;%0Aim
@@ -249,55 +249,8 @@
 *;%0A%0A
-import com.kaviju.accesscontrol.model.KARole;%0A%0A
 @Sup
@@ -383,16 +383,44 @@
 rofile;%0A
+%09private KAProfile profile;%0A
 %09private
@@ -790,12 +790,18 @@
 ;%0A%09%09
-if (
+profile = 
 user
@@ -817,16 +817,31 @@
 rofile()
+;%0A%09%09if (profile
  == null
@@ -909,37 +909,23 @@
 roups = 
-userProfile.
 profile
-()
 .display
@@ -1242,31 +1242,15 @@
 urn 
-userProfile().
 profile
-()
 .dis

Fix a NPE when changing the user profile for another with more displayed groups of roles.