class DGroup

This class wraps an org.dspace.eperson.Group object

Constants

ADMIN_ID

id of administrator group

ANONYMOUS_ID

id of anonymous user group

Public Class Methods

all() click to toggle source

return array of all org.dspace.eperson.Group objects

# File lib/dspace/dgroup.rb, line 17
def self.all
  java_import org.dspace.eperson.Group;
  Group.findAll(DSpace.context, 1);
end
find(name_or_id) click to toggle source

returns nil or the org.dspace.eperson.Group object with the given name or id name_or_id: must be a string or integer

# File lib/dspace/dgroup.rb, line 25
def self.find(name_or_id)
  java_import org.dspace.eperson.Group;
  if (name_or_id.class == String)
    return Group.findByName(DSpace.context, name_or_id);
  else
    return Group.find(DSpace.context, name_or_id)
  end
end
find_or_create(name) click to toggle source

find and return the existing group with the given name or create and return a new group with the given name

name must be a string

# File lib/dspace/dgroup.rb, line 38
def self.find_or_create(name)
  raise "must give a name " unless name
  group = self.find(name);
  if (group.nil?) then
    group = Group.create(DSpace.context);
    group.setName(name)
    group.update();
    puts "Created #{group.toString()}"
  else
    puts "Exists #{group.toString()}"
  end
  return group;
end

Public Instance Methods

addMember(group_or_eperson) click to toggle source

add a memeber to the group

group_or_eperson must be a org.dspace.eperson.EPerson or Group object

# File lib/dspace/dgroup.rb, line 62
def addMember(group_or_eperson)
  raise "must give non nil group_or_eperson" if group_or_eperson.nil?
  @obj.addMember(group_or_eperson);
  @obj.update
  return @obj;
end
inspect() click to toggle source

convert to string

# File lib/dspace/dgroup.rb, line 71
def inspect
  return "nil" if @obj.nil?
  return "#<#{self.class.name}:#{@obj.getName}>"  end
members() click to toggle source

return EPerson and Groups that are (direct) members of this Group

# File lib/dspace/dgroup.rb, line 54
def members
  return  @obj.getMemberGroups.collect { |p| p }  + @obj.getMembers.collect { |p| p }
end