mirror of
https://github.com/DSpace/DSpace.git
synced 2025-10-07 01:54:22 +00:00
Merge pull request #1396 from Georgetown-University-Libraries/DS-3140
DS-3140 METSRightsCrosswalk NPE During AIP Restore - No Anonymous Read
This commit is contained in:
@@ -475,179 +475,136 @@ public class METSRightsCrosswalk
|
||||
{
|
||||
//get what class of context this is
|
||||
String contextClass = element.getAttributeValue("CONTEXTCLASS");
|
||||
|
||||
if ((element.getAttributeValue("start-date") != null)
|
||||
|| (element.getAttributeValue("end-date") != null)
|
||||
|| (element.getAttributeValue("rpName") != null))
|
||||
{
|
||||
SimpleDateFormat sdf = new SimpleDateFormat( "yyyy-MM-dd" );
|
||||
try {
|
||||
ResourcePolicy rp = resourcePolicyService.create(context);
|
||||
if (element.getAttributeValue("CONTEXTCLASS").equalsIgnoreCase("GENERAL PUBLIC")) {
|
||||
Group anonGroup = groupService.findByName(context, Group.ANONYMOUS);
|
||||
rp.setGroup(anonGroup);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (element.getAttributeValue("CONTEXTCLASS").equalsIgnoreCase("REPOSITORY MGR")) {
|
||||
Group adminGroup = groupService.findByName(context, Group.ADMIN);
|
||||
rp.setGroup(adminGroup);
|
||||
}
|
||||
}
|
||||
if (element.getAttributeValue("rpName") != null)
|
||||
{
|
||||
rp.setRpName(element.getAttributeValue("rpName"));
|
||||
}
|
||||
try {
|
||||
if (element.getAttributeValue("start-date") != null)
|
||||
{
|
||||
rp.setStartDate(sdf.parse(element.getAttributeValue("start-date")));
|
||||
}
|
||||
if (element.getAttributeValue("end-date") != null)
|
||||
{
|
||||
rp.setEndDate(sdf.parse(element.getAttributeValue("end-date")));
|
||||
}
|
||||
}catch (ParseException ex) {
|
||||
java.util.logging.Logger.getLogger(METSRightsCrosswalk.class.getName()).log(Level.SEVERE, null, ex);
|
||||
}
|
||||
|
||||
List<Element> le = new ArrayList<Element>(element.getChildren());
|
||||
for (Element el : le)
|
||||
{
|
||||
if ((el.getAttributeValue("DISCOVER").equalsIgnoreCase("true"))
|
||||
&& (el.getAttributeValue("DISPLAY").equalsIgnoreCase("true")))
|
||||
{
|
||||
if (el.getAttributeValue("DELETE").equalsIgnoreCase("false"))
|
||||
{
|
||||
if (el.getAttributeValue("MODIFY").equalsIgnoreCase("false"))
|
||||
{
|
||||
rp.setAction(Constants.READ);
|
||||
}
|
||||
else
|
||||
{
|
||||
rp.setAction(Constants.WRITE);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (el.getAttributeValue("MODIFY").equalsIgnoreCase("true"))
|
||||
{
|
||||
rp.setAction(Constants.DELETE);
|
||||
if ((el.getAttributeValue("COPY").equalsIgnoreCase("true"))
|
||||
&&(el.getAttributeValue("DUPLICATE").equalsIgnoreCase("true"))
|
||||
&&(el.getAttributeValue("PRINT").equalsIgnoreCase("true")))
|
||||
{
|
||||
rp.setAction(Constants.ADMIN);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
policies.add(rp);
|
||||
} catch (NullPointerException ex) {
|
||||
java.util.logging.Logger.getLogger(METSRightsCrosswalk.class.getName()).log(Level.SEVERE, null, ex);
|
||||
}
|
||||
assignPermissions(context, dso, policies);
|
||||
|
||||
ResourcePolicy rp = resourcePolicyService.create(context);
|
||||
SimpleDateFormat sdf = new SimpleDateFormat( "yyyy-MM-dd" );
|
||||
|
||||
// get reference to the <Permissions> element
|
||||
// Note: we are assuming here that there will only ever be ONE <Permissions>
|
||||
// element. Currently there are no known use cases for multiple.
|
||||
Element permsElement = element.getChild("Permissions", METSRights_NS);
|
||||
if(permsElement == null) {
|
||||
log.error("No <Permissions> element was found. Skipping this <Context> element.");
|
||||
continue;
|
||||
}
|
||||
else
|
||||
|
||||
if (element.getAttributeValue("rpName") != null)
|
||||
{
|
||||
//also get reference to the <Permissions> element
|
||||
Element permsElement = element.getChild("Permissions", METSRights_NS);
|
||||
|
||||
//Check if this permission pertains to Anonymous users
|
||||
if(ANONYMOUS_CONTEXTCLASS.equals(contextClass))
|
||||
rp.setRpName(element.getAttributeValue("rpName"));
|
||||
}
|
||||
try {
|
||||
if (element.getAttributeValue("start-date") != null)
|
||||
{
|
||||
//get DSpace Anonymous group, ID=0
|
||||
Group anonGroup = groupService.findByName(context, Group.ANONYMOUS);
|
||||
if(anonGroup==null)
|
||||
{
|
||||
throw new CrosswalkInternalException("The DSpace database has not been properly initialized. The Anonymous Group is missing from the database.");
|
||||
}
|
||||
|
||||
assignPermissions(context, dso, anonGroup, permsElement);
|
||||
} // else if this permission declaration pertains to Administrators
|
||||
else if(ADMIN_CONTEXTCLASS.equals(contextClass))
|
||||
rp.setStartDate(sdf.parse(element.getAttributeValue("start-date")));
|
||||
}
|
||||
if (element.getAttributeValue("end-date") != null)
|
||||
{
|
||||
//get DSpace Administrator group, ID=1
|
||||
Group adminGroup = groupService.findByName(context, Group.ADMIN);
|
||||
if(adminGroup==null)
|
||||
{
|
||||
throw new CrosswalkInternalException("The DSpace database has not been properly initialized. The Administrator Group is missing from the database.");
|
||||
}
|
||||
|
||||
assignPermissions(context, dso, adminGroup, permsElement);
|
||||
} // else if this permission pertains to another DSpace group
|
||||
else if(GROUP_CONTEXTCLASS.equals(contextClass))
|
||||
rp.setEndDate(sdf.parse(element.getAttributeValue("end-date")));
|
||||
}
|
||||
}catch (ParseException ex) {
|
||||
log.error("Failed to parse embargo date. The date needs to be in the format 'yyyy-MM-dd'.", ex);
|
||||
}
|
||||
|
||||
//Check if this permission pertains to Anonymous users
|
||||
if(ANONYMOUS_CONTEXTCLASS.equals(contextClass))
|
||||
{
|
||||
//get DSpace Anonymous group, ID=0
|
||||
Group anonGroup = groupService.findByName(context, Group.ANONYMOUS);
|
||||
if(anonGroup==null)
|
||||
{
|
||||
try
|
||||
{
|
||||
//we need to find the name of DSpace group it pertains to
|
||||
//Get the text within the <UserName> child element,
|
||||
// this is the group's name
|
||||
String groupName = element.getChildTextTrim("UserName", METSRights_NS);
|
||||
throw new CrosswalkInternalException("The DSpace database has not been properly initialized. The Anonymous Group is missing from the database.");
|
||||
}
|
||||
|
||||
//Translate Group name back to internal ID format (e.g. COLLECTION_<ID>_ADMIN)
|
||||
// from its external format (e.g. COLLECTION_<handle>_ADMIN)
|
||||
groupName = PackageUtils.translateGroupNameForImport(context, groupName);
|
||||
|
||||
//Check if this group exists in DSpace already
|
||||
Group group = groupService.findByName(context, groupName);
|
||||
|
||||
//if not found, throw an error -- user should restore group from the SITE AIP
|
||||
if(group==null)
|
||||
{
|
||||
throw new CrosswalkInternalException("Cannot restore Group permissions on object ("
|
||||
+ "type=" + Constants.typeText[dso.getType()] + ", "
|
||||
+ "handle=" + dso.getHandle() + ", "
|
||||
+ "ID=" + dso.getID()
|
||||
+ "). The Group named '" + groupName + "' is missing from DSpace. "
|
||||
+ "Please restore this group using the SITE AIP, or recreate it.");
|
||||
}
|
||||
|
||||
//assign permissions to group on this object
|
||||
assignPermissions(context, dso, group, permsElement);
|
||||
}
|
||||
catch(PackageException pe)
|
||||
{
|
||||
//A PackageException will only be thrown if translateDefaultGroupName() fails
|
||||
//We'll just wrap it as a CrosswalkException and throw it upwards
|
||||
throw new CrosswalkException(pe);
|
||||
}
|
||||
}//end if Group
|
||||
else if(PERSON_CONTEXTCLASS.equals(contextClass))
|
||||
rp.setGroup(anonGroup);
|
||||
} // else if this permission declaration pertains to Administrators
|
||||
else if(ADMIN_CONTEXTCLASS.equals(contextClass))
|
||||
{
|
||||
//get DSpace Administrator group, ID=1
|
||||
Group adminGroup = groupService.findByName(context, Group.ADMIN);
|
||||
if(adminGroup==null)
|
||||
{
|
||||
//we need to find the person it pertains to
|
||||
// Get the text within the <UserName> child element,
|
||||
// this is the person's email address
|
||||
String personEmail = element.getChildTextTrim("UserName", METSRights_NS);
|
||||
throw new CrosswalkInternalException("The DSpace database has not been properly initialized. The Administrator Group is missing from the database.");
|
||||
}
|
||||
|
||||
//Check if this person exists in DSpace already
|
||||
EPerson person = ePersonService.findByEmail(context, personEmail);
|
||||
rp.setGroup(adminGroup);
|
||||
} // else if this permission pertains to another DSpace group
|
||||
else if(GROUP_CONTEXTCLASS.equals(contextClass))
|
||||
{
|
||||
try
|
||||
{
|
||||
//we need to find the name of DSpace group it pertains to
|
||||
//Get the text within the <UserName> child element,
|
||||
// this is the group's name
|
||||
String groupName = element.getChildTextTrim("UserName", METSRights_NS);
|
||||
|
||||
//If cannot find by email, try by netID
|
||||
//(though METSRights should contain email if it was exported by DSpace)
|
||||
if(person==null)
|
||||
//Translate Group name back to internal ID format (e.g. COLLECTION_<ID>_ADMIN)
|
||||
// from its external format (e.g. COLLECTION_<handle>_ADMIN)
|
||||
groupName = PackageUtils.translateGroupNameForImport(context, groupName);
|
||||
|
||||
//Check if this group exists in DSpace already
|
||||
Group group = groupService.findByName(context, groupName);
|
||||
|
||||
//if not found, throw an error -- user should restore group from the SITE AIP
|
||||
if(group==null)
|
||||
{
|
||||
person = ePersonService.findByNetid(context, personEmail);
|
||||
}
|
||||
|
||||
//if not found, throw an error -- user should restore person from the SITE AIP
|
||||
if(person==null)
|
||||
{
|
||||
throw new CrosswalkInternalException("Cannot restore Person permissions on object ("
|
||||
throw new CrosswalkInternalException("Cannot restore Group permissions on object ("
|
||||
+ "type=" + Constants.typeText[dso.getType()] + ", "
|
||||
+ "handle=" + dso.getHandle() + ", "
|
||||
+ "ID=" + dso.getID()
|
||||
+ "). The Person with email/netid '" + personEmail + "' is missing from DSpace. "
|
||||
+ "Please restore this Person object using the SITE AIP, or recreate it.");
|
||||
+ "). The Group named '" + groupName + "' is missing from DSpace. "
|
||||
+ "Please restore this group using the SITE AIP, or recreate it.");
|
||||
}
|
||||
|
||||
//assign permissions to person on this object
|
||||
assignPermissions(context, dso, person, permsElement);
|
||||
}//end if Person
|
||||
else
|
||||
log.error("Unrecognized CONTEXTCLASS: " + contextClass);
|
||||
//assign group to policy
|
||||
rp.setGroup(group);
|
||||
}
|
||||
catch(PackageException pe)
|
||||
{
|
||||
//A PackageException will only be thrown if translateDefaultGroupName() fails
|
||||
//We'll just wrap it as a CrosswalkException and throw it upwards
|
||||
throw new CrosswalkException(pe);
|
||||
}
|
||||
}// else if this permission pertains to a DSpace person
|
||||
else if(PERSON_CONTEXTCLASS.equals(contextClass))
|
||||
{
|
||||
//we need to find the person it pertains to
|
||||
// Get the text within the <UserName> child element,
|
||||
// this is the person's email address
|
||||
String personEmail = element.getChildTextTrim("UserName", METSRights_NS);
|
||||
|
||||
//Check if this person exists in DSpace already
|
||||
EPerson person = ePersonService.findByEmail(context, personEmail);
|
||||
|
||||
//If cannot find by email, try by netID
|
||||
//(though METSRights should contain email if it was exported by DSpace)
|
||||
if(person==null)
|
||||
{
|
||||
person = ePersonService.findByNetid(context, personEmail);
|
||||
}
|
||||
|
||||
//if not found, throw an error -- user should restore person from the SITE AIP
|
||||
if(person==null)
|
||||
{
|
||||
throw new CrosswalkInternalException("Cannot restore Person permissions on object ("
|
||||
+ "type=" + Constants.typeText[dso.getType()] + ", "
|
||||
+ "handle=" + dso.getHandle() + ", "
|
||||
+ "ID=" + dso.getID()
|
||||
+ "). The Person with email/netid '" + personEmail + "' is missing from DSpace. "
|
||||
+ "Please restore this Person object using the SITE AIP, or recreate it.");
|
||||
}
|
||||
|
||||
//assign person to the policy
|
||||
rp.setEPerson(person);
|
||||
}//end if Person
|
||||
else {
|
||||
log.error("Unrecognized CONTEXTCLASS: " + contextClass);
|
||||
}
|
||||
|
||||
//set permissions on policy and add to object
|
||||
rp.setAction(parsePermissions(permsElement));
|
||||
policies.add(rp);
|
||||
assignPermissions(context, dso, policies);
|
||||
|
||||
} //end if "Context" element
|
||||
}//end while loop
|
||||
}
|
||||
|
Reference in New Issue
Block a user