Permalink
Browse files

working on membership... not quite done

  • Loading branch information...
1 parent d755232 commit eec98d4dcd2b4bddccd7614e79e49f72cf9a9a14 @johne committed Feb 16, 2012
@@ -135,13 +135,21 @@ def processFile(csvFile)
end
skip = false
end
-
+
+ if (@exceptional == 0)
+ postProcess()
+ end
+
report = "processed file #{csvFile} with config #{@infoFile}\n\n"
report << "created #{created}\n#{updatedLabel} #{updated}\nfailed #{exceptional}\ntotal #{total}\n\n"
report << exceptions
sendReport(report)
end
+
+ def postProcess()
+ # do nothing... override if needed
+ end
def trimRow(row)
row.each do |col|
@@ -0,0 +1,159 @@
+#!/usr/bin/env ruby
+
+require 'rubygems'
+require 'csv'
+require 'json'
+require 'nakamura'
+require 'nakamura/users'
+require './import-base'
+include SlingInterface
+include SlingUsers
+include OaeImport
+
+
+if ARGV.size < 1
+ puts "Usage: import-members.rb PATH_TO_CSV_FILE [PATH_TO_SERVER_CONFIG_FILE.json]"
+ exit 1
+end
+
+
+class SisWorldUploader < OaeImportBase
+
+ attr_accessor :roleMaps
+ attr_accessor :groupCache
+
+ def createManager(server)
+ @userManager = UserManager.new(server)
+ @groupCache = {}
+ end
+
+
+ def processRow(row)
+ # 0 user
+ # 1 world id (groupname)
+ # 2 role
+
+ groupId = row[1].to_s
+
+ groupCacheEntry = @groupCache[groupId];
+
+ if (groupCacheEntry.nil?)
+ group = Group.new(groupId);
+
+ groupDetails = group.details(@server);
+
+ groupCacheEntry = {
+ "group"=> group,
+ "groupDetails"=> groupDetails,
+ "roles"=> {}
+ }
+ end
+
+ worldType = groupCacheEntry["groupDetails"]["properties"]["sakai:world-type"]
+
+ groupRoleMap = @roleMaps[worldType]
+
+ role = groupRoleMap[row[2].to_s]
+
+ roleArray = groupCacheEntry["roles"][role]
+
+ if (roleArray.nil?)
+ roleArray = []
+ end
+
+ user = row[0];
+
+ roleArray << row[0].to_s
+
+ # cache all the stuff away for now
+ groupCacheEntry["roles"][role] = roleArray
+
+ @groupCache[groupId] = groupCacheEntry
+ end
+
+ def postProcess()
+ @groupCache.each_pair do |k,v|
+ begin
+ processGroup(k, v)
+ rescue Exception => e
+ @exceptional += 1
+ @log.warn(e.message)
+ @log.warn(e.backtrace.join("\n"))
+ exceptions << "Processing group had error: #{e.message}"
+ exceptions << "\n"
+ end
+ end
+ end
+
+ def processGroup(groupId, groupCacheEntry)
+ group = Group.new(groupId)
+ rolesJson = groupCacheEntry["groupDetails"]["properties"]["sakai:roles"];
+
+ roles = JSON.parse(rolesJson)
+
+ roles.each do |role|
+ processRole(role["id"], group, groupCacheEntry)
+ end
+ end
+
+ def processRole(roleId, group, groupCacheEntry)
+ newRoleUsers = groupCacheEntry["roles"][roleId]
+
+ roleGroupId = group.name + "-" + roleId
+
+ roleGroup = Group.new(roleGroupId)
+
+ currentMembers = roleGroup.members(@server)
+
+ if (currentMembers.count > 0)
+ leftOver = currentMembers - newRoleUsers
+
+ leftOver.each do |removeUser|
+ roleGroup.remove_member(@server, removeUser)
+ end
+
+ @updated += leftOver.count
+ end
+
+ if (currentMembers.count > 0)
+ newRoleUsers = newRoleUsers - currentMembers
+ end
+
+ puts newRoleUsers
+
+ roleGroup.add_members(@server, newRoleUsers)
+
+ @created += newRoleUsers.count
+ end
+
+ def processServerProps(serverInfoFile)
+ ret = super(serverInfoFile)
+
+ @roleMaps = @serverProps["members.csv"]["roleMaps"] # maps cle roles to oae roles
+
+ ret
+ end
+
+ def subject
+ "members.csv file processed: " + currentDate
+ end
+
+ def updatedLabel
+ return "removed"
+ end
+
+ def skipFirstRow
+ skipFirstRowConfig("members.csv")
+ end
+
+ def expectedColumns
+ 3
+ end
+
+end
+
+csvFile = ARGV[0]
+serverInfo = ARGV[1] || nil
+@sisWorld = SisWorldUploader.new(serverInfo)
+
+@sisWorld.processFile(csvFile)
@@ -61,16 +61,12 @@ def processRow(row)
end
groupProps = {
- "term" => row[0],
- "contactName" => row[9],
- "contactEmail" => row[10],
- "grouping" => grouping
+ "sakai:term" => row[0],
+ "sakai:contactName" => row[9],
+ "sakai:contactEmail" => row[10],
+ "sakai:grouping" => grouping,
+ "sakai:world-type" => row[8]
}
-
- groupDetails["properties"]["term"] = row[0]
- groupDetails["properties"]["contactName"] = row[9]
- groupDetails["properties"]["contactEmail"] = row[10]
- groupDetails["properties"]["grouping"] = grouping
if (!@customProperties.nil? && @customProperties.count > 1)
@customProperties.each_with_index {
@@ -7,11 +7,8 @@
"serverUrl" : "http://localhost:8080/",
"users.csv" : {
"allowUpdate" : false,
- "customProperties" : [
- "testProp1",
- "testProp2"
- ],
- "skipHeaderRow" : true
+ "skipHeaderRow" : true,
+ "customProperties": []
},
"worlds.csv" : {
"customProperties" : [
@@ -24,5 +21,23 @@
"portfolio" : "/var/templates/worlds/group/simple-group",
"project" : "/var/templates/worlds/research/research-project"
}
+ },
+ "members.csv" : {
+ "skipHeaderRow" : false,
+ "roleMaps" : {
+ "course": {
+ "Instructor" : "lecturer",
+ "Student" : "student",
+ "Teaching Assistant" : "ta"
+ },
+ "portfolio": {
+ "Organizer": "manager",
+ "Participant": "member"
+ },
+ "project": {
+ "Organizer": "leadresearcher",
+ "Participant": "contributor"
+ }
+ }
}
}
@@ -1,6 +1,6 @@
-W11,10_sis_testing_001b,,Testing Course 101,SIS Testing,SIS Testing,0,,course,,,grouped
-Sp11,10-sis-testing-002b,,Testing Course 201,SIS Testing,SIS Testing,0,,course,,,grouped
-Sp11,10-sis-testing-022b,,Testing Course 202,SIS Testing,SIS Testing,0,,course,,,grouped
-Sp11,10-sis-testing-220b,,Testing Portfolio 203,SIS Testing,SIS Testing,0,,portfolio,,,grouped
-Sp11,10-sis-testing-222b,,Testing Project 204,SIS Testing,SIS Testing,0,,project,,,grouped
-Su11,10-sis-testing-003b,,Testing Course 301,SIS Testing,SIS Testing,0,,course,,,not-grouped
+W11,10-sis-testing-001,,Testing Course 101,SIS Testing,SIS Testing,0,,course,,,not-grouped
+Sp11,10-sis-testing-002,,Testing Course 201,SIS Testing,SIS Testing,0,,course,,,grouped
+Sp11,10-sis-testing-022,,Testing Course 202,SIS Testing,SIS Testing,0,,course,,,grouped
+Sp11,10-sis-testing-220,,Testing Portfolio 203,SIS Testing,SIS Testing,0,,portfolio,,,grouped
+Sp11,10-sis-testing-222,,Testing Project 204,SIS Testing,SIS Testing,0,,project,,,grouped
+Su11,10-sis-testing-003,,Testing Course 301,SIS Testing,SIS Testing,0,,course,,,not-grouped
@@ -0,0 +1,33 @@
+mbrissette,10-sis-testing-001,Instructor
+mpaquette,10-sis-testing-001,Instructor
+aphillips,10-sis-testing-002,Instructor
+bkoppelman,10-sis-testing-002,Instructor
+nwilson,10-sis-testing-002,Instructor
+cbuckley,10-sis-testing-022,Instructor
+gjohnson,10-sis-testing-022,Instructor
+klabelle,10-sis-testing-022,Instructor
+coliveira,10-sis-testing-220,Organizer
+mbrissette,10-sis-testing-220,Organizer
+mpaquette,10-sis-testing-222,Organizer
+dlarue,10-sis-testing-222,Organizer
+nwilson,10-sis-testing-003,Student
+aallen,10-sis-testing-001,Teaching Assistant
+aaustin,10-sis-testing-001,Teaching Assistant
+abass,10-sis-testing-001,Teaching Assistant
+abelanger,10-sis-testing-001,Student
+abishop,10-sis-testing-001,Student
+aboyer,10-sis-testing-001,Student
+abradley,10-sis-testing-001,Student
+abrouillette,10-sis-testing-001,Student
+aburns,10-sis-testing-001,Student
+acaldwell,10-sis-testing-001,Student
+aallen,10-sis-testing-002,Teaching Assistant
+aaustin,10-sis-testing-002,Teaching Assistant
+abass,10-sis-testing-002,Teaching Assistant
+abelanger,10-sis-testing-002,Student
+abishop,10-sis-testing-002,Student
+aboyer,10-sis-testing-002,Student
+abradley,10-sis-testing-002,Student
+abrouillette,10-sis-testing-002,Student
+aburns,10-sis-testing-002,Student
+acaldwell,10-sis-testing-002,Student
@@ -1,3 +1,4 @@
+header row
admin,Administrator,Alexa,noone@nowhere.com,password,maintain,admin
aphillips,Phillips,Anna,noone@nowhere.com,password,maintain,aphillips
bkoppelman,Koppelman,Brian,noone@nowhere.com,password,maintain,bkoppelman

0 comments on commit eec98d4

Please sign in to comment.