You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 2 Next »

The design here is to not load all groups from a loader, but be able to selectively load groups as needed, and located anywhere in the registry.

An example of this use case is someone can mark an arbitrary group as "load people from a course", while also selecting if that means students, instructors, or both. 

selectiveLoadingOfCourses

Sample data

Add the groups, some memberships, and the attributes.

import edu.internet2.middleware.grouper.*;
import edu.internet2.middleware.grouper.attr.*;
import edu.internet2.middleware.grouper.attr.assign.*;
import edu.internet2.middleware.grouper.attr.finder.*;

GrouperSession grouperSession = GrouperSession.startRootSession();

AttributeDef attributeDef = new AttributeDefSave(grouperSession).assignName("attr:courseDef").assignCreateParentStemsIfNotExist(true).assignCreateParentStemsIfNotExist(true).assignToGroup(true).assignAttributeDefType(AttributeDefType.attr).assignMultiAssignable(false).assignMultiValued(false).assignValueType(AttributeDefValueType.marker).save();
AttributeDef attributeValueDef = new AttributeDefSave(grouperSession).assignName("attr:courseValueDef").assignCreateParentStemsIfNotExist(true).assignToGroupAssn(true).assignAttributeDefType(AttributeDefType.attr).assignMultiAssignable(false).assignMultiValued(false).assignValueType(AttributeDefValueType.string).save();

AttributeDef attributeValueMarkerDef = new AttributeDefSave(grouperSession).assignName("attr:courseValueMarkerDef").assignCreateParentStemsIfNotExist(true).assignToGroupAssn(true).assignAttributeDefType(AttributeDefType.attr).assignMultiAssignable(false).assignMultiValued(false).assignValueType(AttributeDefValueType.marker).save();

attributeDef.getAttributeDefActionDelegate().configureActionList("assign");
attributeValueDef.getAttributeDefActionDelegate().configureActionList("assign");
attributeValueMarkerDef.getAttributeDefActionDelegate().configureActionList("assign");

course = new AttributeDefNameSave(grouperSession, attributeDef).assignName("attr:course").assignCreateParentStemsIfNotExist(true).save();

attributeValueDef.getAttributeDefScopeDelegate().assignOwnerNameEquals("attr:course");
attributeValueMarkerDef.getAttributeDefScopeDelegate().assignOwnerNameEquals("attr:course");

courseId = new AttributeDefNameSave(grouperSession, attributeValueDef).assignName("attr:courseId").assignCreateParentStemsIfNotExist(true).save();
includeStudents = new AttributeDefNameSave(grouperSession, attributeValueMarkerDef).assignName("attr:includeStudents").assignCreateParentStemsIfNotExist(true).save();
includeInstructors = new AttributeDefNameSave(grouperSession, attributeValueMarkerDef).assignName("attr:includeInstructors").assignCreateParentStemsIfNotExist(true).save();

Group math101 = new GroupSave(grouperSession).assignName("org:artsAndSciences:courses:math101").assignCreateParentStemsIfNotExist(true).save();

attributeAssignSave = new AttributeAssignSave(grouperSession).assignAttributeAssignType(AttributeAssignType.group).assignAttributeDefName(course).assignOwnerGroup(math101);

attributeAssignOnAssignSave = new AttributeAssignSave(grouperSession).assignAttributeAssignType(AttributeAssignType.group_asgn).assignAttributeDefName(courseId).addValue("math101");

attributeAssignSave.addAttributeAssignOnThisAssignment(attributeAssignOnAssignSave);

attributeAssignOnAssignSave = new AttributeAssignSave(grouperSession).assignAttributeAssignType(AttributeAssignType.group_asgn).assignAttributeDefName(includeStudents);

attributeAssignSave.addAttributeAssignOnThisAssignment(attributeAssignOnAssignSave);

attributeAssignSave.save();

Group clinical101 = new GroupSave(grouperSession).assignName("org:nursing:classes:clinical101").assignCreateParentStemsIfNotExist(true).save();

attributeAssignSave = new AttributeAssignSave(grouperSession).assignAttributeAssignType(AttributeAssignType.group).assignAttributeDefName(course).assignOwnerGroup(clinical101);

attributeAssignOnAssignSave = new AttributeAssignSave(grouperSession).assignAttributeAssignType(AttributeAssignType.group_asgn).assignAttributeDefName(courseId).addValue("clinical101");

attributeAssignSave.addAttributeAssignOnThisAssignment(attributeAssignOnAssignSave);

attributeAssignOnAssignSave = new AttributeAssignSave(grouperSession).assignAttributeAssignType(AttributeAssignType.group_asgn).assignAttributeDefName(includeStudents);

attributeAssignSave.addAttributeAssignOnThisAssignment(attributeAssignOnAssignSave);

attributeAssignOnAssignSave = new AttributeAssignSave(grouperSession).assignAttributeAssignType(AttributeAssignType.group_asgn).assignAttributeDefName(includeInstructors);

attributeAssignSave.addAttributeAssignOnThisAssignment(attributeAssignOnAssignSave);

attributeAssignSave.save();


Attribute assignments on groups

Note, if you delegate who has access to the employee intersect attribute def names, then others can control their own groups

Two groups with attributes:


Control views

The attribute assignment queries are complicated and have performance implications.  So to simplify things, we will make two views, and sync those into tables, so when we do the loader query, it is simpler and performs better.

View for which groups are employeeIntersects

Note, these are for mysql but will either work or will work with minor edits in other databases

create view employee_intersect_owners_v as
select distinct gaagv.group_id, gaagv.group_name,
case when exists 
(select 1 from grouper_aval_asn_asn_group_v gaaagv where gaaagv.attribute_def_name_name2 = 'attr:jobClass' and gaaagv.group_name = gaagv.group_name and gaaagv.enabled2 = 'T')
then 'T'
else 'F'
end as has_job_class,
case when exists 
(select 1 from grouper_aval_asn_asn_group_v gaaagv where gaaagv.attribute_def_name_name2 = 'attr:jobCode' and gaaagv.group_name = gaagv.group_name and gaaagv.enabled2 = 'T')
then 'T'
else 'F'
end as has_job_code,
case when exists 
(select 1 from grouper_aval_asn_asn_group_v gaaagv where gaaagv.attribute_def_name_name2 = 'attr:orgUnitCode' and gaaagv.group_name = gaagv.group_name and gaaagv.enabled2 = 'T')
then 'T'
else 'F'
end as has_org_unit_code
from  grouper_attr_asn_group_v gaagv
where gaagv.attribute_def_name_name = 'attr:employeeIntersect'
and gaagv.enabled = 'T';


View for which groups are unioned before intersected.

create view employee_intersect_unions_v as
select distinct gaaagv_union.group_id as group_id_owner,
gaaagv_union.group_name as group_name_owner,
case
  when gaaagv_union.attribute_def_name_name2 = 'attr:jobClass' then 'jobClass'
  when gaaagv_union.attribute_def_name_name2 = 'attr:jobCode' then 'jobCode'
  when gaaagv_union.attribute_def_name_name2 = 'attr:orgUnitCode' then 'orgUnitCode'
end as union_attribute,
case
  when gaaagv_union.attribute_def_name_name2 = 'attr:jobClass' then concat('basis:employee:jobClasses:jobClass_', upper(trim(gaaagv_union.value_string)))
  when gaaagv_union.attribute_def_name_name2 = 'attr:jobCode' then concat('basis:employee:jobCodes:jobCode_', upper(trim(gaaagv_union.value_string)))
  when gaaagv_union.attribute_def_name_name2 = 'attr:orgUnitCode' then concat('basis:employee:orgUnitCodes:orgUnitCode_', upper(trim(gaaagv_union.value_string)))
end as group_name_union
from  grouper_aval_asn_asn_group_v gaaagv_union
where gaaagv_union.attribute_def_name_name1 = 'attr:employeeIntersect'
  and gaaagv_union.attribute_def_name_name2 in ('attr:jobClass', 'attr:jobCode', 'attr:orgUnitCode')
  and gaaagv_union.enabled2 = 'T'
order by 2, 3, 4
;



Control tables

To simplify things and improve performance, we will sync those two views to two tables

Convert to tables:

create table employee_intersect_owners as select * from employee_intersect_owners_v;
ALTER TABLE employee_intersect_owners ADD PRIMARY KEY(group_id);
CREATE INDEX employee_int_owners_name_idx ON employee_intersect_owners (group_name);

create table employee_intersect_unions as select * from employee_intersect_unions_v;
ALTER TABLE employee_intersect_unions MODIFY group_name_union varchar(1024);
ALTER TABLE employee_intersect_unions ADD PRIMARY KEY(group_id_owner, group_name_union(300));
CREATE INDEX employee_int_unions_name_idx ON employee_intersect_unions (group_name_owner);

Sync the views to tables. 

grouper.client.properties

grouperClient.syncTable.employeeIntersectOwners.databaseFrom = grouper
grouperClient.syncTable.employeeIntersectOwners.tableFrom = employee_intersect_owners_v
grouperClient.syncTable.employeeIntersectOwners.databaseTo = grouper
grouperClient.syncTable.employeeIntersectOwners.tableTo = employee_intersect_owners
grouperClient.syncTable.employeeIntersectOwners.columns = *
grouperClient.syncTable.employeeIntersectOwners.primaryKeyColumns = group_id

grouperClient.syncTable.employeeIntersectUnions.databaseFrom = grouper
grouperClient.syncTable.employeeIntersectUnions.tableFrom = employee_intersect_unions_v
grouperClient.syncTable.employeeIntersectUnions.databaseTo = grouper
grouperClient.syncTable.employeeIntersectUnions.tableTo = employee_intersect_unions
grouperClient.syncTable.employeeIntersectUnions.columns = *
grouperClient.syncTable.employeeIntersectUnions.primaryKeyColumns = group_id_owner, group_name_union


Lets schedule this hourly at 50 minutes passed the hour

grouper-loader.properties

otherJob.employeeIntersectOwnersFull.class = edu.internet2.middleware.grouper.app.tableSync.TableSyncOtherJob
otherJob.employeeIntersectOwnersFull.quartzCron = 0 50 * * * ?
otherJob.employeeIntersectOwnersFull.grouperClientTableSyncConfigKey = employeeIntersectOwners
otherJob.employeeIntersectOwnersFull.syncType = fullSyncFull

otherJob.employeeIntersectUnionsFull.class = edu.internet2.middleware.grouper.app.tableSync.TableSyncOtherJob
otherJob.employeeIntersectUnionsFull.quartzCron = 0 51 * * * ?
otherJob.employeeIntersectUnionsFull.grouperClientTableSyncConfigKey = employeeIntersectUnions
otherJob.employeeIntersectUnionsFull.syncType = fullSyncFull

Run the jobs and make sure they are ok



Membership view

This view has the loader results to load the groups with attributes.  Note, since all the groups used are loaded basis groups (not in this example, but yes in practice) with immediate memberships, we can join to the grouper_memberships table.  This is done for performance reasons.  If there were effective members, then the grouper_memberships_lw_v would need to be used, and the grouper_groups table wouldnt be needed since that is in the view.

Note also the field_id of the "members" field from grouper_fields is hard-coded here.  If you use grouper_memberships_lw_v you dont need to do that.

create view employee_intersect_mships_v as
select eio.group_name as group_name,
       gm.subject_id as subject_id,
       gm.subject_source as subject_source_id
from employee_intersect_owners eio,
     grouper_members gm
     where
       (eio.has_job_class = 'T' or eio.has_job_code = 'T' or eio.has_org_unit_code = 'T')
       and  (eio.has_job_class = 'F' 
            or exists (select 1 from grouper_memberships gms, employee_intersect_unions eiu, grouper_groups gg
                       where eiu.group_id_owner = eio.group_id 
                         and gm.id = gms.member_id and gms.field_id = '58796e2b91fc4756a894af4d0d8d46b5' and gms.enabled = 'T'
                         and eiu.union_attribute = 'jobClass' and gg.name = eiu.group_name_union and gms.owner_id = gg.id ))
        and (eio.has_job_code = 'F' 
            or exists (select 1 from grouper_memberships gms, employee_intersect_unions eiu, grouper_groups gg
                       where eiu.group_id_owner = eio.group_id 
                         and gm.id = gms.member_id and gms.field_id = '58796e2b91fc4756a894af4d0d8d46b5' and gms.enabled = 'T'
                         and eiu.union_attribute = 'jobCode' and gg.name = eiu.group_name_union and gms.owner_id = gg.id ))
       and (eio.has_org_unit_code = 'F' 
            or exists (select 1 from grouper_memberships gms, employee_intersect_unions eiu, grouper_groups gg
                       where eiu.group_id_owner = eio.group_id 
                         and gm.id = gms.member_id and gms.field_id = '58796e2b91fc4756a894af4d0d8d46b5' and gms.enabled = 'T'
                         and eiu.union_attribute = 'orgUnitCode' and gg.name = eiu.group_name_union and gms.owner_id = gg.id ))



Loader job



See memberships on any groups with employee intersect attributes

Real time updates

This is not implemented yet but you could easily have a change log consumer that looks for membership changes to any of the union groups, and looks for attribute changes for the applicable attributes, and runs a full or incremental loader job based on events.  Ask the Grouper team for an example if this is a requirement.  Otherwise the above will run periodically (this example is hourly)




  • No labels