Skip to Content.
Sympa Menu

grouper-users - RE: [grouper-users] RE: Grouper 1.4.0: Using hooks

Subject: Grouper Users - Open Discussion List

List archive

RE: [grouper-users] RE: Grouper 1.4.0: Using hooks


Chronological Thread 
  • From: "Dr. Loris Bennett" <>
  • To: Chris Hyzer <>
  • Cc: Grouper Users Mailing List <>
  • Subject: RE: [grouper-users] RE: Grouper 1.4.0: Using hooks
  • Date: Wed, 04 Feb 2009 12:08:05 +0100
  • Organization: Freie Universität Berlin

Hi Chris,

I tried the failsafe call, but got the same errors. In the UI:

Error: Could not create group. Error is 'cannot create child
group: Problem create child stem:

Stem[displayName=test,name=test,uuid=029bc9c2-50bd-4122-891c-ffdf252744b8,creator=fd703376-4f16-47df-b707-64d8c5953d04,modifier=fd703376-4f16-47df-b707-64d8c5953d04],
child: Group[name=test:xxx,uuid=d559eccd-9be2-4555-ac1a-40ee72bb106e],
memberDto: 'd559eccd-9be2-4555-ac1a-40ee72bb106e'/'group'/'g:gsa', Problem in
HibernateSession: HibernateSession: isNew: false, isReadonly: false,
grouperTransactionType: READ_WRITE_NEW, Exception in uniqueResult: (class
java.lang.Object), ByHqlStatic, query: 'select m.id from Member as m where
m.uuid = :uuid', cacheable: false, cacheRegion:
edu.internet2.middleware.grouper.internal.dao.hib3.Hib3MemberDAO.Exists, tx
type: nullBind var[0]: 'Param (class java.lang.String):
'uuid'->'90e883dd-326e-40f1-9416-805d2770a9d6', , Problem in
HibernateSession: HibernateSession: isNew: false, isReadonly: false,
grouperTransactionType: READ_WRITE_NEW'.

I have attached an extract from the grouper log and the code.

Thanks for all your help.

Loris


On Tue, 2009-02-03 at 23:32 -0500, Chris Hyzer wrote:
> Ive been thinking about your issue, and if your question is, why should you
> use the failsafe group type call since the type hasn’t been applied yet, it
> might be because when you add a type to a group, it might update the group
> lastUpdated col, and invoke the update hook again. Then, the second time,
> it does have that type, and you cant add it again. This is something we
> are exploring for 1.5 (not setting the Group lastUpdated for each
> peripheral operation like memberships, types, etc). However, for 1.4, the
> group object might be saved for any related change, which fires the hooks
> again... so if you use the failsafe method per one of my previous emails,
> then the second time the hook is called, it doesn’t fail.
>
> Hope this helps, if not, send your code and description again and I will
> take a look. :)
>
> Kind regards,
> Chris
>
> > -----Original Message-----
> > From: Dr. Loris Bennett
> > [mailto:]
> > Sent: Tuesday, February 03, 2009 9:37 AM
> > To: Chris Hyzer
> > Cc: Grouper Users Mailing List
> > Subject: RE: [grouper-users] RE: Grouper 1.4.0: Using hooks
> >
> > Hi Chris,
> >
> > I don't understand what is going on here. If I create a new group via
> > the UI without selecting any custom type, the code
> >
> > Group g = postInsertBean.getGroup();
> > Set<GroupType> types = g.getTypes();
> >
> > tells me that the new group has just one type, namely 'base'. I then
> > get
> > the error
> >
> > ERROR JDBCExceptionReporter.logExceptions(78) - ERROR:
> > duplicate
> > key violates unique constraint "grouptypetyple_grouptype_idx"
> >
> > But how can the group already have the type at this point? The
> > following
> > error appears in the UI:
> >
> > Error: Could not create group. Error is 'cannot create child
> > group: Problem create child stem:
> > Stem[displayName=test,name=test,uuid=029bc9c2-50bd-4122-891c-
> > ffdf252744b8,creator=fd703376-4f16-47df-b707-
> > 64d8c5953d04,modifier=fd703376-4f16-47df-b707-64d8c5953d04], child:
> > Group[name=test:xyz,uuid=dc2a2fa6-4fad-446e-bf5c-d08dba8d0b33],
> > memberDto: 'dc2a2fa6-4fad-446e-bf5c-d08dba8d0b33'/'group'/'g:gsa',
> > Problem in HibernateSession: HibernateSession: isNew: false,
> > isReadonly: false, grouperTransactionType: READ_WRITE_NEW, Exception in
> > uniqueResult: (class java.lang.Object), ByHqlStatic, query: 'select
> > m.id from Member as m where m.uuid = :uuid', cacheable: false,
> > cacheRegion:
> > edu.internet2.middleware.grouper.internal.dao.hib3.Hib3MemberDAO.Exists
> > , tx type: nullBind var[0]: 'Param (class java.lang.String): 'uuid'-
> > >'b412a97d-080a-4b68-a856-5a237a041e06', , Problem in HibernateSession:
> > HibernateSession: isNew: false, isReadonly: false,
> > grouperTransactionType: READ_WRITE_NEW'.
> >
> > Any ideas what I am doing wrong?
> >
> > Cheers
> >
> > Loris
> >
> > On Fri, 2009-01-30 at 15:36 -0500, Chris Hyzer wrote:
> > > That index "grouptypetyple_grouptype_idx" is a unique index on
> > > grouper_group_types cols: group_uuid and type_uuid.
> > >
> > > So that error means that the group already has the type.
> > >
> > >
> > >
> > > I have also found it unnatural that the default Grouper API behavior
> > > is to throw exceptions if the task is already done. E.g.
> > >
> > >
> > >
> > > group.addType(someType);
> > >
> > >
> > >
> > > Will throw an exception if the type is already there... I have been
> > > slowly overloading these types of methods with their safe
> > > equivalents... so if you change it to:
> > >
> > >
> > >
> > > //false means don’t throw exception if type is already assigned
> > >
> > > group.addType(someType, false);
> > >
> > >
> > >
> > > It should do the trick. Let me know if not.
> > >
> > >
> > >
> > > Thanks,
> > >
> > > Chris
> > >
> > >
> > >
> > > Ps. Btw, web services do not behave that way... e.g. if you add a
> > > member to a group that already has the member, it will be a no-op,
> > > return SUCCESS, and let you know exactly what happened (e.g. success,
> > > but it already had the assignment)
> > >
> > >
> > >
> > >
> > >
> > > > -----Original Message-----
> > >
> > > > From: Dr. Loris Bennett
> > > > [mailto:]
> > >
> > > > Sent: Friday, January 30, 2009 8:27 AM
> > >
> > > > To: Chris Hyzer
> > >
> > > > Cc: Grouper Users Mailing List
> > >
> > > > Subject: RE: [grouper-users] RE: Grouper 1.4.0: Using hooks
> > >
> > > >
> > >
> > > > However, when I try to add the type in groupPostInsert, I get
> > >
> > > >
> > >
> > > > ERROR JDBCExceptionReporter.logExceptions(78) - ERROR:
> > >
> > > > duplicate
> > >
> > > > key violates unique constraint
> > > "grouptypetyple_grouptype_idx"
> > >
> > > >
> > >
> > > > Any ideas?
> > >
> > > >
> > >
> > > > Loris
> > >
> > > >
> > >
> > > > On Fri, 2009-01-30 at 07:34 -0500, Chris Hyzer wrote:
> > >
> > > > > Good catch! Thanks!
> > >
> > > > >
> > >
> > > > > > -----Original Message-----
> > >
> > > > > > From: Dr. Loris Bennett
> > > > > > [mailto:]
> > >
> > > > > > Sent: Friday, January 30, 2009 7:31 AM
> > >
> > > > > > To: Chris Hyzer
> > >
> > > > > > Cc: Grouper Users Mailing List
> > >
> > > > > > Subject: RE: [grouper-users] RE: Grouper 1.4.0: Using hooks
> > >
> > > > > >
> > >
> > > > > > OK, I see what I am doing wrong. I have the addType in my
> > >
> > > > > > groupPreInsert, whereas the group must already exist before I
> > > can
> > >
> > > > add
> > >
> > > > > > anything to it.
> > >
> > > > > >
> > >
> > > > > > On Fri, 2009-01-30 at 11:39 +0100, Dr. Loris Bennett wrote:
> > >
> > > > > > > Hi Chris,
> > >
> > > > > > >
> > >
> > > > > > > Using
> > >
> > > > > > >
> > >
> > > > > > > fubGroup = GroupTypeFinder.find(groupTypeName);
> > >
> > > > > > >
> > >
> > > > > > > I can get my custom group type, but when I try to add this
> > > with
> > >
> > > > > > >
> > >
> > > > > > > g.addType(fubGroup);
> > >
> > > > > > >
> > >
> > > > > > > I get the error:
> > >
> > > > > > >
> > >
> > > > > > > ERROR JDBCExceptionReporter.logExceptions(78) -
> > ERROR:
> > >
> > > > insert
> > >
> > > > > > or
> > >
> > > > > > > update on table "grouper_groups_types" violates
> > > foreign
> > >
> > > > key
> > >
> > > > > > > constraint "fk_groups_types_group_uuid"
> > >
> > > > > > > Detail: Key
> > >
> > > > > > > (group_uuid)=(6ea9f650-cdc8-4e69-93df-5b35a87351fe)
> > is
> > >
> > > > not
> > >
> > > > > > > present in table "grouper_groups".
> > >
> > > > > > >
> > >
> > > > > > > Am I doing something wrong here?
> > >
> > > > > > >
> > >
> > > > > > > TIA
> > >
> > > > > > >
> > >
> > > > > > > Loris
> > >
> > > > > > >
> > >
> > > > > > >
> > >
> > > > > > > On Thu, 2009-01-29 at 03:21 -0500, Chris Hyzer wrote:
> > >
> > > > > > > > >
> > >
> > > > > > > > > So the pre-insert would also set the custom attribute,
> > > right?
> > >
> > > > > > > >
> > >
> > > > > > > > OK, didn’t know we were talking about a custom attribute.
> > > It’s
> > >
> > > > a
> > >
> > > > > > little tricky since the set of attributes is known when the
> > > group
> > >
> > > > SQL
> > >
> > > > > > is written, but you are making changes (I guess to that
> > > attribute
> > >
> > > > set).
> > >
> > > > > > I would think a post insert is the best bet, and you don’t need
> > > the
> > >
> > > > > > pre, but play around and try different things, and if you cant
> > > get
> > >
> > > > > > anything to work let me know.
> > >
> > > > > > > >
> > >
> > > > > > > > Chris
> > >
> > > > > > > >
> > >
> > > > > > > >
> > >
> > > > > > --
> > >
> > > > > > Dr. Loris Bennett (Mr.)
> > >
> > > > > > Freie Universität Berlin
> > >
> > > > > > ZEDAT - Zentraleinrichtung für Datenverarbeitung / Computer
> > > Center
> > >
> > > > > > Compute & Media Service
> > >
> > > > > > Fabeckstr. 32, Room 221
> > >
> > > > > > D-14195 Berlin
> > >
> > > > > > Tel ++49 30 838 51024
> > >
> > > > > > Fax ++49 30 838 56721
> > >
> > > > > > Email
> > > > > >
> > >
> > > > > > Web www.zedat.fu-berlin.de
> > >
> > > > >
> > >
> > > > --
> > >
> > > > Dr. Loris Bennett (Mr.)
> > >
> > > > Freie Universität Berlin
> > >
> > > > ZEDAT - Zentraleinrichtung für Datenverarbeitung / Computer Center
> > >
> > > > Compute & Media Service
> > >
> > > > Fabeckstr. 32, Room 221
> > >
> > > > D-14195 Berlin
> > >
> > > > Tel ++49 30 838 51024
> > >
> > > > Fax ++49 30 838 56721
> > >
> > > > Email
> > > >
> > >
> > > > Web www.zedat.fu-berlin.de
> > >
> > >
> > >
> > >
> > --
> > Dr. Loris Bennett (Mr.)
> > Freie Universität Berlin
> > ZEDAT - Zentraleinrichtung für Datenverarbeitung / Computer Center
> > Compute & Media Service
> > Fabeckstr. 32, Room 221
> > D-14195 Berlin
> > Tel ++49 30 838 51024
> > Fax ++49 30 838 56721
> > Email
> >
> > Web www.zedat.fu-berlin.de
>
--
Dr. Loris Bennett (Mr.)
Freie Universität Berlin
ZEDAT - Zentraleinrichtung für Datenverarbeitung / Computer Center
Compute & Media Service
Fabeckstr. 32, Room 221
D-14195 Berlin
Tel ++49 30 838 51024
Fax ++49 30 838 56721
Email

Web www.zedat.fu-berlin.de
2009-02-04 11:44:04,939: [http-xxx.xxx.xxx.xxx-xxx] ERROR GroupHooks.groupPreInsert(33) - HOOKTEST: Group[name=test:xxx,uuid=d559eccd-9be2-4555-ac1a-40ee72bb106e]
2009-02-04 11:44:05,042: [http-xxx.xxx.xxx.xxx-xxx] ERROR GroupHooks.groupPostInsert(62) - HOOKTEST: key = extension, val = xxx
2009-02-04 11:44:05,042: [http-xxx.xxx.xxx.xxx-xxx] ERROR GroupHooks.groupPostInsert(62) - HOOKTEST: key = displayExtension, val = xxx
2009-02-04 11:44:05,043: [http-xxx.xxx.xxx.xxx-xxx] ERROR GroupHooks.groupPostInsert(62) - HOOKTEST: key = name, val = test:xxx
2009-02-04 11:44:05,043: [http-xxx.xxx.xxx.xxx-xxx] ERROR GroupHooks.groupPostInsert(62) - HOOKTEST: key = displayName, val = test:xxx
2009-02-04 11:44:05,044: [http-xxx.xxx.xxx.xxx-xxx] ERROR GroupHooks.groupPostInsert(66) - HOOKTEST: no. types = 1
2009-02-04 11:44:05,044: [http-xxx.xxx.xxx.xxx-xxx] ERROR GroupHooks.groupPostInsert(70) - HOOKTEST: no. fields = 12
2009-02-04 11:44:05,045: [http-xxx.xxx.xxx.xxx-xxx] ERROR GroupHooks.groupPostInsert(72) - HOOKTEST: type = base, field = admins
2009-02-04 11:44:05,045: [http-xxx.xxx.xxx.xxx-xxx] ERROR GroupHooks.groupPostInsert(72) - HOOKTEST: type = base, field = description
2009-02-04 11:44:05,046: [http-xxx.xxx.xxx.xxx-xxx] ERROR GroupHooks.groupPostInsert(72) - HOOKTEST: type = base, field = displayExtension
2009-02-04 11:44:05,046: [http-xxx.xxx.xxx.xxx-xxx] ERROR GroupHooks.groupPostInsert(72) - HOOKTEST: type = base, field = displayName
2009-02-04 11:44:05,047: [http-xxx.xxx.xxx.xxx-xxx] ERROR GroupHooks.groupPostInsert(72) - HOOKTEST: type = base, field = extension
2009-02-04 11:44:05,047: [http-xxx.xxx.xxx.xxx-xxx] ERROR GroupHooks.groupPostInsert(72) - HOOKTEST: type = base, field = members
2009-02-04 11:44:05,048: [http-xxx.xxx.xxx.xxx-xxx] ERROR GroupHooks.groupPostInsert(72) - HOOKTEST: type = base, field = name
2009-02-04 11:44:05,048: [http-xxx.xxx.xxx.xxx-xxx] ERROR GroupHooks.groupPostInsert(72) - HOOKTEST: type = base, field = optins
2009-02-04 11:44:05,049: [http-xxx.xxx.xxx.xxx-xxx] ERROR GroupHooks.groupPostInsert(72) - HOOKTEST: type = base, field = optouts
2009-02-04 11:44:05,049: [http-xxx.xxx.xxx.xxx-xxx] ERROR GroupHooks.groupPostInsert(72) - HOOKTEST: type = base, field = readers
2009-02-04 11:44:05,050: [http-xxx.xxx.xxx.xxx-xxx] ERROR GroupHooks.groupPostInsert(72) - HOOKTEST: type = base, field = updaters
2009-02-04 11:44:05,050: [http-xxx.xxx.xxx.xxx-xxx] ERROR GroupHooks.groupPostInsert(72) - HOOKTEST: type = base, field = viewers
2009-02-04 11:44:05,051: [http-xxx.xxx.xxx.xxx-xxx] ERROR GroupHooks.groupPostInsert(76) - HOOKTEST: no. removable types = 0
2009-02-04 11:44:05,051: [http-xxx.xxx.xxx.xxx-xxx] ERROR GroupHooks.groupPostInsert(88) - HOOKTEST: Determining available groups ...
2009-02-04 11:44:05,087: [http-xxx.xxx.xxx.xxx-xxx] ERROR GroupHooks.groupPostInsert(92) - HOOKTEST: GroupType: addIncludeExclude
2009-02-04 11:44:05,088: [http-xxx.xxx.xxx.xxx-xxx] ERROR GroupHooks.groupPostInsert(92) - HOOKTEST: GroupType: base
2009-02-04 11:44:05,088: [http-xxx.xxx.xxx.xxx-xxx] ERROR GroupHooks.groupPostInsert(92) - HOOKTEST: GroupType: fubGroup
2009-02-04 11:44:05,089: [http-xxx.xxx.xxx.xxx-xxx] ERROR GroupHooks.groupPostInsert(92) - HOOKTEST: GroupType: fuGroupId
2009-02-04 11:44:05,089: [http-xxx.xxx.xxx.xxx-xxx] ERROR GroupHooks.groupPostInsert(92) - HOOKTEST: GroupType: grouperLoader
2009-02-04 11:44:05,090: [http-xxx.xxx.xxx.xxx-xxx] ERROR GroupHooks.groupPostInsert(92) - HOOKTEST: GroupType: groupId
2009-02-04 11:44:05,090: [http-xxx.xxx.xxx.xxx-xxx] ERROR GroupHooks.groupPostInsert(92) - HOOKTEST: GroupType: requireInGroups
2009-02-04 11:44:05,091: [http-xxx.xxx.xxx.xxx-xxx] ERROR GroupHooks.groupPostInsert(92) - HOOKTEST: GroupType: testRequireInGroupAttribute
2009-02-04 11:44:05,091: [http-xxx.xxx.xxx.xxx-xxx] ERROR GroupHooks.groupPostInsert(102) - HOOKTEST: Trying failsafe addType
2009-02-04 11:44:05,181: [http-xxx.xxx.xxx.xxx-xxx] ERROR JDBCExceptionReporter.logExceptions(78) - Batch-Eintrag 0 update grouper_groups_types set hibernate_version_number=
2, group_uuid=d559eccd-9be2-4555-ac1a-40ee72bb106e, type_uuid=4181edd5-f612-42c9-9fad-fa8c20e0b086 where id=020586481f40e22c011f40e3319d0007 wurde abgebrochen.  Rufen Sie 'getNextExcep
tion' auf, um die Ursache zu erfahren.
2009-02-04 11:44:05,182: [http-xxx.xxx.xxx.xxx-xxx] ERROR JDBCExceptionReporter.logExceptions(78) - ERROR: duplicate key violates unique constraint "grouptypetyple_grouptype
_idx"
2009-02-04 11:44:05,185: [http-xxx.xxx.xxx.xxx-xxx] ERROR AbstractFlushingEventListener.performExecutions(301) - Could not synchronize database state with session
package de.zedat.cms.fudis;

import java.util.Map;
import java.util.Set;

import org.apache.log4j.Logger;

import edu.internet2.middleware.grouper.Field;
import edu.internet2.middleware.grouper.Group;
import edu.internet2.middleware.grouper.GroupType;
import edu.internet2.middleware.grouper.GroupTypeFinder;
//import edu.internet2.middleware.grouper.GrouperSession;
import edu.internet2.middleware.grouper.exception.GroupModifyException;
import edu.internet2.middleware.grouper.exception.InsufficientPrivilegeException;
import edu.internet2.middleware.grouper.exception.SchemaException;
import edu.internet2.middleware.grouper.hooks.beans.HooksContext;
import edu.internet2.middleware.grouper.hooks.beans.HooksGroupBean;
//import edu.internet2.middleware.grouper.hooks.logic.GrouperHooksUtils;

public class GroupHooks extends edu.internet2.middleware.grouper.hooks.GroupHooks {

	/**
	 * Log4j logger
	 */
	static Logger log4j = Logger.getLogger("de.zedat.cms.fudis");

	@Override
	public void groupPreInsert(HooksContext hooksContext, HooksGroupBean preInsertBean) {
		// TODO Auto-generated method stub
		super.groupPreInsert(hooksContext, preInsertBean);
		Group g = preInsertBean.getGroup();

		log4j.error("HOOKTEST: " + g);
		Set<GroupType> types = g.getTypes();
		log4j.debug("HOOKTEST: no. types = " + types.size());
		String typeName = "";
		for (GroupType type: types) {
			typeName = type.getName();
			Set<Field> fields = type.getFields();
			log4j.debug("HOOKTEST: no. fields = " + fields.size());
			for (Field field : fields) {
				log4j.debug("HOOKTEST: type = " + typeName + ", field = " + field.getName());
			}
		}
	}

	@SuppressWarnings("unchecked")
	@Override
	public void groupPostInsert(HooksContext hooksContext, HooksGroupBean postInsertBean) {
		// TODO Auto-generated method stub
		super.groupPostInsert(hooksContext, postInsertBean);

//		GrouperSession sess = hooksContext.grouperSession();
//		Set<String> keys = hooksContext.attributeKeySet();
		Group g = postInsertBean.getGroup();

//		GroupType fuGroup = new GroupType();

		Map<String,String> attMap = g.getAttributes();
		for (String key : attMap.keySet()) {
			String val = attMap.get(key);
			log4j.error("HOOKTEST: key = " + key + ", val = " + val);
		}
		String typeName = "";
		Set<GroupType> types = g.getTypes();
		log4j.error("HOOKTEST: no. types = " + types.size());
		for (GroupType type: types) {
			typeName = type.getName();
			Set<Field> fields = type.getFields();
			log4j.error("HOOKTEST: no. fields = " + fields.size());
			for (Field field : fields) {
				log4j.error("HOOKTEST: type = " + typeName + ", field = " + field.getName());
			}
		}
		Set rTypes = g.getRemovableTypes();
		log4j.error("HOOKTEST: no. removable types = " + rTypes.size());
		for (Object type: rTypes) {
			GroupType gtype = (GroupType) type;
			typeName = gtype.getName();
			Set<Field> fields = gtype.getFields();
			log4j.error("HOOKTEST: no. fields = " + fields.size());
			for (Field field : fields) {
				log4j.error("HOOKTEST: type = " + typeName + ", field = " + field.getName());
			}
		}	
		GroupType fubGroup = null;
		String groupTypeName = "fubGroup";
		log4j.error("HOOKTEST: Determining available groups ...");
		try {
			Set<GroupType> groupTypes = GroupTypeFinder.findAll();
			for (GroupType groupType : groupTypes) {
				log4j.error("HOOKTEST: GroupType: " + groupType.getName());
			}
			fubGroup = GroupTypeFinder.find(groupTypeName);
		} catch (SchemaException e) {
			log4j.error("HOOKTEST: Unable to find group type " + groupTypeName);
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		try {
			log4j.error("HOOKTEST: Trying failsafe addType");
			g.addType(fubGroup,false);
//			log4j.error("HOOKTEST: Trying addType");
//			g.addType(fubGroup);
		} catch (GroupModifyException e) {
			log4j.error("HOOKTEST: Unable to add group type " + groupTypeName + " due to GroupModifyException");
			e.printStackTrace();
		} catch (InsufficientPrivilegeException e) {
			log4j.error("HOOKTEST: Unable to add group type " + groupTypeName + " due to InsufficientPrivilegeException");
			e.printStackTrace();
		} catch (SchemaException e) {
			log4j.error("HOOKTEST: Unable to add group type " + groupTypeName + " due to GroupModifyException");
			e.printStackTrace();
		} catch (Exception e) {
			log4j.error("HOOKTEST: Unable to add group type " + groupTypeName + " due to " + e.getMessage());
			e.printStackTrace();

		}	
		
		
	}	

}



Archive powered by MHonArc 2.6.16.

Top of Page