"If you are performing an AIP restore, you can ignore this warning as the Community/Collection AIP will likely create this group once it is processed.");
continue;
}
log.debug("Translated group name: {}", name);
Group groupObj = null; // The group to restore
Group collider = Group.findByName(context, name); // Existing group?
if (null != collider)
{ // Group already exists, so empty it
if (params.replaceModeEnabled()) // -r -f
{
for (Group member : collider.getMemberGroups())
{
collider.removeMember(member);
}
for (EPerson member : collider.getMembers())
{
// Remove all group members *EXCEPT* we don't ever want
// to remove the current user from the list of Administrators
// (otherwise remainder of ingest will fail)
if(!(collider.equals(Group.find(context, 1)) &&
member.equals(context.getCurrentUser())))
{
collider.removeMember(member);
}
}
log.info("Existing Group {} was cleared. Its members will be replaced.", name);
groupObj = collider;
}
else if (params.keepExistingModeEnabled()) // -r -k
{
log.warn("Existing Group {} was not replaced from the package.",
name);
continue;
}
else
{
throw new PackageException("Group " + name + " already exists");
}
}
else
{ // No such group exists -- so, we'll need to create it!
log.debug("Creating group for a {}", parent.getTypeText());
// First Check if this is a "typed" group (i.e. Community or Collection associated Group)
// If so, we'll create it via the Community or Collection
String type = group.getAttribute(RoleDisseminator.TYPE);
log.debug("Group type is {}", type);
if(type!=null && !type.isEmpty() && parent!=null)
{
//What type of dspace object is this group associated with
if(parent.getType()==Constants.COLLECTION)
{
Collection collection = (Collection) parent;
// Create this Collection-associated group, based on its group type
if(type.equals(RoleDisseminator.GROUP_TYPE_ADMIN))
{
groupObj = collection.createAdministrators();
}
else if(type.equals(RoleDisseminator.GROUP_TYPE_SUBMIT))
{
groupObj = collection.createSubmitters();
}
else if(type.equals(RoleDisseminator.GROUP_TYPE_WORKFLOW_STEP_1))
{
groupObj = collection.createWorkflowGroup(1);
}
else if(type.equals(RoleDisseminator.GROUP_TYPE_WORKFLOW_STEP_2))
{
groupObj = collection.createWorkflowGroup(2);
}
else if(type.equals(RoleDisseminator.GROUP_TYPE_WORKFLOW_STEP_3))
{
groupObj = collection.createWorkflowGroup(3);
}
}
else if(parent.getType()==Constants.COMMUNITY)
{
Community community = (Community) parent;
// Create this Community-associated group, based on its group type
if(type.equals(RoleDisseminator.GROUP_TYPE_ADMIN))
{
groupObj = community.createAdministrators();
}
}
//Ignore all other dspace object types
}
//If group not yet created, create it with the given name
if(groupObj==null)
{
groupObj = Group.create(context);
}
// Always set the name: parent.createBlop() is guessing
groupObj.setName(name);
log.info("Created Group {}.", groupObj.getName());
}
// Add EPeople to newly created Group
NodeList members = group.getElementsByTagName(RoleDisseminator.MEMBER);
for (int memberx = 0; memberx < members.getLength(); memberx++)
{
Element member = (Element) members.item(memberx);
String memberName = member.getAttribute(RoleDisseminator.NAME);
EPerson memberEPerson = EPerson.findByEmail(context, memberName);
if (null != memberEPerson)
groupObj.addMember(memberEPerson);
else
throw new PackageValidationException("EPerson " + memberName
+ " not found, not added to " + name);
}
// Actually write Group info to DB
// NOTE: this update() doesn't call a commit(). So, Group info
// may still be rolled back if a subsequent error occurs
groupObj.update();
}
// Go back and add Group members, now that all groups exist
for (int groupx = 0; groupx < groups.getLength(); groupx++)
{
Element group = (Element) groups.item(groupx);
String name = group.getAttribute(RoleDisseminator.NAME);
log.debug("Processing group {}", name);
try
{
// Translate Group name back to internal ID format (e.g. COLLECTION_<ID>_ADMIN)
name = PackageUtils.translateGroupNameForImport(context, name);
log.debug("Translated group name: {}", name);
}
catch(PackageException pe)
{
// If an error is thrown, then this Group corresponds to a
// Community or Collection that doesn't currently exist in the
// system. So,skip it for now.
// (NOTE: We already logged a warning about this group earlier as
// this is the second time we are looping through all groups)
continue;
}
// Find previously created group
Group groupObj = Group.findByName(context, name);
log.debug("Looked up the group and found {}", groupObj);
NodeList members = group
.getElementsByTagName(RoleDisseminator.MEMBER_GROUP);
for (int memberx = 0; memberx < members.getLength(); memberx++)
{
Element member = (Element) members.item(memberx);
String memberName = member.getAttribute(RoleDisseminator.NAME);
//Translate Group name back to internal ID format (e.g. COLLECTION_<ID>_ADMIN)
memberName = PackageUtils.translateGroupNameForImport(context, memberName);
// Find previously created group
Group memberGroup = Group.findByName(context, memberName);
groupObj.addMember(memberGroup);
}
// Actually update Group info in DB
// NOTE: Group info may still be rolled back if a subsequent error occurs
groupObj.update();