Skip to content

Commit

Permalink
working on membership... not quite done
Browse files Browse the repository at this point in the history
  • Loading branch information
johne committed Feb 16, 2012
1 parent d755232 commit eec98d4
Show file tree
Hide file tree
Showing 7 changed files with 233 additions and 21 deletions.
10 changes: 9 additions & 1 deletion scripts/import/import-base.rb
Expand Up @@ -135,13 +135,21 @@ def processFile(csvFile)
end end
skip = false skip = false
end end


if (@exceptional == 0)
postProcess()
end

report = "processed file #{csvFile} with config #{@infoFile}\n\n" report = "processed file #{csvFile} with config #{@infoFile}\n\n"
report << "created #{created}\n#{updatedLabel} #{updated}\nfailed #{exceptional}\ntotal #{total}\n\n" report << "created #{created}\n#{updatedLabel} #{updated}\nfailed #{exceptional}\ntotal #{total}\n\n"
report << exceptions report << exceptions


sendReport(report) sendReport(report)
end end

def postProcess()
# do nothing... override if needed
end


def trimRow(row) def trimRow(row)
row.each do |col| row.each do |col|
Expand Down
159 changes: 159 additions & 0 deletions scripts/import/import-members.rb
@@ -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)
14 changes: 5 additions & 9 deletions scripts/import/import-worlds.rb
Expand Up @@ -61,16 +61,12 @@ def processRow(row)
end end


groupProps = { groupProps = {
"term" => row[0], "sakai:term" => row[0],
"contactName" => row[9], "sakai:contactName" => row[9],
"contactEmail" => row[10], "sakai:contactEmail" => row[10],
"grouping" => grouping "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) if (!@customProperties.nil? && @customProperties.count > 1)
@customProperties.each_with_index { @customProperties.each_with_index {
Expand Down
25 changes: 20 additions & 5 deletions scripts/import/sampleServer.json
Expand Up @@ -7,11 +7,8 @@
"serverUrl" : "http://localhost:8080/", "serverUrl" : "http://localhost:8080/",
"users.csv" : { "users.csv" : {
"allowUpdate" : false, "allowUpdate" : false,
"customProperties" : [ "skipHeaderRow" : true,
"testProp1", "customProperties": []
"testProp2"
],
"skipHeaderRow" : true
}, },
"worlds.csv" : { "worlds.csv" : {
"customProperties" : [ "customProperties" : [
Expand All @@ -24,5 +21,23 @@
"portfolio" : "/var/templates/worlds/group/simple-group", "portfolio" : "/var/templates/worlds/group/simple-group",
"project" : "/var/templates/worlds/research/research-project" "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"
}
}
} }
} }
12 changes: 6 additions & 6 deletions scripts/import/samples/courses.csv
@@ -1,6 +1,6 @@
W11,10_sis_testing_001b,,Testing Course 101,SIS Testing,SIS Testing,0,,course,,,grouped W11,10-sis-testing-001,,Testing Course 101,SIS Testing,SIS Testing,0,,course,,,not-grouped
Sp11,10-sis-testing-002b,,Testing Course 201,SIS Testing,SIS Testing,0,,course,,,grouped Sp11,10-sis-testing-002,,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-022,,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-220,,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 Sp11,10-sis-testing-222,,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 Su11,10-sis-testing-003,,Testing Course 301,SIS Testing,SIS Testing,0,,course,,,not-grouped
33 changes: 33 additions & 0 deletions scripts/import/samples/members-small.csv
@@ -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 change: 1 addition & 0 deletions scripts/import/samples/users.csv
@@ -1,3 +1,4 @@
header row
admin,Administrator,Alexa,noone@nowhere.com,password,maintain,admin admin,Administrator,Alexa,noone@nowhere.com,password,maintain,admin
aphillips,Phillips,Anna,noone@nowhere.com,password,maintain,aphillips aphillips,Phillips,Anna,noone@nowhere.com,password,maintain,aphillips
bkoppelman,Koppelman,Brian,noone@nowhere.com,password,maintain,bkoppelman bkoppelman,Koppelman,Brian,noone@nowhere.com,password,maintain,bkoppelman
Expand Down

0 comments on commit eec98d4

Please sign in to comment.