Skip to Content.
Sympa Menu

grouper-users - Re: [grouper-users] RE: Change Log Consumer

Subject: Grouper Users - Open Discussion List

List archive

Re: [grouper-users] RE: Change Log Consumer


Chronological Thread 
  • From: Shilen Patel <>
  • To: "Klug, Lawrence" <>
  • Cc: Chris Hyzer <>, "" <>
  • Subject: Re: [grouper-users] RE: Change Log Consumer
  • Date: Mon, 8 Oct 2012 17:25:31 +0000
  • Accept-language: en-US

Hi,

Here's one way:

        if (changeLogEntry.equalsCategoryAndAction(ChangeLogTypeBuiltin.ATTRIBUTE_ASSIGN_VALUE_ADD)) {
          // first perhaps verify that the value is what you want..

          // then proceed
          String attributeDefNameName = changeLogEntry.retrieveValueForLabel(ChangeLogLabels.ATTRIBUTE_ASSIGN_VALUE_ADD.attributeDefNameName);    
          String attributeAssignId = changeLogEntry.retrieveValueForLabel(ChangeLogLabels.ATTRIBUTE_ASSIGN_VALUE_ADD.attributeAssignId);    

         // make sure this is the attribute that you care about if you want..
         if ("etc:testAttr".equals(attributeDefNameName)) {
           AttributeAssign assign = AttributeAssignFinder.findById(attributeAssignId, false);
           if (assign == null) {
             // must have been deleted...
           } else {
             // if the attribute can be assigned to more than just groups, avoid NPE here..
             System.out.println(assign.getOwnerGroup().getName()); 
           }
         }
       }

Thanks!

-- Shilen

From: "Klug, Lawrence" <>
Date: Mon, 8 Oct 2012 15:40:51 +0000
To: Shilen Patel <>
Cc: Chris Hyzer <>, "" <>
Subject: RE: [grouper-users] RE: Change Log Consumer

Hi Shilen,

 

Thanks for the PIT code sample.  Group delete notification is now working cool.

 

I do have one more use case that I want to ask about. 

 

The use case is “Group Add” and I want to be able to send a notification when a Plone group is created.

 

Since Plone groups are identified by an attribute and I need the value of the attribute for the notification,

 

Question: how can I get the associated group name from an “ATTRIBUTE_ASSIGN_VALUE_ADD” event? 

 

Thanks,

 

Lawrence

 

From: Shilen Patel []
Sent: Sunday, October 07, 2012 10:33 AM
To: Klug, Lawrence
Cc: Chris Hyzer;
Subject: Re: [grouper-users] RE: Change Log Consumer

 

Here's an example of getting the attribute values that were assigned to a group after the group is deleted based on the group delete change log entry.  Change "etc:testAttr" to your attribute name.

 

      for (ChangeLogEntry changeLogEntry : changeLogEntryList) {

        currentId = changeLogEntry.getSequenceNumber();

        Timestamp timestamp = changeLogEntry.getCreatedOn();

 

        if (changeLogEntry.equalsCategoryAndAction(ChangeLogTypeBuiltin.GROUP_DELETE)) {

          String groupId = changeLogEntry.retrieveValueForLabel(ChangeLogLabels.GROUP_DELETE.id);    

          PITGroup pitGroup = PITGroupFinder.findBySourceId(groupId, timestamp, timestamp, true).iterator().next();

          PITAttributeDefName pitAttributeDefName = PITAttributeDefNameFinder.findByName("etc:testAttr", timestamp, timestamp, true, false).iterator().next();

          Set<PITAttributeAssign> assignments = GrouperDAOFactory.getFactory().getPITAttributeAssign().findByOwnerPITGroupId(pitGroup.getId());

          for (PITAttributeAssign assignment : assignments) {

            if (assignment.getAttributeDefNameId().equals(pitAttributeDefName.getId())) {

              Set<PITAttributeAssignValue> values = PITAttributeAssignValueFinder.findByPITAttributeAssign(assignment, null, null);

              for (PITAttributeAssignValue value : values) {

                // If the value was deleted as part of the group delete (not before in another transaction, then the context ids should match.  Also, the end time for the value should be close to the change log entry time if it was all deleted together.

                System.out.println("Value: " + value.valueString() + ", Value ended: " + value.getEndTime() + ", Value context id: " + value.getContextId() + ", change log context id: " + changeLogEntry.getContextId());

              }

            }

          }

        }

      }

 

But the above uses some internal api calls.  For 2.1.3+ (not released but in the 2.1 branch in SVN), you can do the following instead:

 

      for (ChangeLogEntry changeLogEntry : changeLogEntryList) {

        currentId = changeLogEntry.getSequenceNumber();

        Timestamp timestamp = changeLogEntry.getCreatedOn();

 

        if (changeLogEntry.equalsCategoryAndAction(ChangeLogTypeBuiltin.GROUP_DELETE)) {

          String groupId = changeLogEntry.retrieveValueForLabel(ChangeLogLabels.GROUP_DELETE.id);    

          PITGroup pitGroup = PITGroupFinder.findBySourceId(groupId, timestamp, timestamp, true).iterator().next();

          PITAttributeDefName pitAttributeDefName = PITAttributeDefNameFinder.findByName("etc:testAttr", timestamp, timestamp, true, false).iterator().next();

          Set<PITAttributeAssign> assignments = PITAttributeAssignFinder.findByOwnerPITGroupAndPITAttributeDefName(pitGroup, pitAttributeDefName, null, null);

          for (PITAttributeAssign assignment : assignments) {

            Set<PITAttributeAssignValue> values = PITAttributeAssignValueFinder.findByPITAttributeAssign(assignment, null, null);

            for (PITAttributeAssignValue value : values) {

              // If the value was deleted as part of the group delete (not before in another transaction, then the context ids should match.  Also, the end time for the value should be close to the change log entry time if it was all deleted together.

              System.out.println("Value: " + value.valueString() + ", Value ended: " + value.getEndTime() + ", Value context id: " + value.getContextId() + ", change log context id: " + changeLogEntry.getContextId());

            }

          }

        }

      }

 

Let me know if you have questions.

 

Thanks!

 

-- Shilen

 

 

From: "Klug, Lawrence" <>
Date: Fri, 5 Oct 2012 18:42:52 +0000
To: Chris Hyzer <>, "" <>
Subject: [grouper-users] RE: Change Log Consumer

 

Nice, point me to an example!

 

From: Chris Hyzer []
Sent: Friday, October 05, 2012 11:08 AM
To: Klug, Lawrence;
Subject: RE: Change Log Consumer

 

I think you should be able to get the information in the point-in-time data.  i.e. subtract a minute or whatever, and get the attribute value from then.  There still could be a race condition, but in general, it should work J.  Shilen, can you give more info on it if this is the way to go?

 

Thanks,

Chris

 

From:On Behalf Of Klug, Lawrence
Sent: Friday, October 05, 2012 11:18 AM
To:
Subject: [grouper-users] Change Log Consumer

 

Hi,

 

I’d like to identify Group delete events where the Group in has a specific attribute so that I can notify an external application(Plone).  It looks like the system deletes attributeAssign objects just prior to the delete group event (see below), so is what I’m trying to do possible?  So can I access the Group that belongs to a attributeAssign event?  How?

 

**** PLONE CHANGE LOG CONSUMER ****

Processing changeLog #74383, privilege.deletePrivilege

**** PLONE CHANGE LOG CONSUMER ****

Processing changeLog #74384, privilege.deletePrivilege

**** PLONE CHANGE LOG CONSUMER ****

Processing changeLog #74385, privilege.deletePrivilege

**** PLONE CHANGE LOG CONSUMER ****

Processing changeLog #74386, attributeAssignValue.deleteAttributeAssignValue

**** PLONE CHANGE LOG CONSUMER ****

Processing changeLog #74387, attributeAssignValue.deleteAttributeAssignValue

**** PLONE CHANGE LOG CONSUMER ****

Processing changeLog #74388, attributeAssign.deleteAttributeAssign

**** PLONE CHANGE LOG CONSUMER ****

Processing changeLog #74389, group.deleteGroup

 

Thanks,

 

Lawrence

 




Archive powered by MHonArc 2.6.16.

Top of Page