mirror of
https://github.com/DSpace/DSpace.git
synced 2025-10-12 12:33:18 +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:
@@ -476,24 +476,18 @@ public class METSRightsCrosswalk
|
|||||||
//get what class of context this is
|
//get what class of context this is
|
||||||
String contextClass = element.getAttributeValue("CONTEXTCLASS");
|
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);
|
ResourcePolicy rp = resourcePolicyService.create(context);
|
||||||
if (element.getAttributeValue("CONTEXTCLASS").equalsIgnoreCase("GENERAL PUBLIC")) {
|
SimpleDateFormat sdf = new SimpleDateFormat( "yyyy-MM-dd" );
|
||||||
Group anonGroup = groupService.findByName(context, Group.ANONYMOUS);
|
|
||||||
rp.setGroup(anonGroup);
|
// get reference to the <Permissions> element
|
||||||
}
|
// Note: we are assuming here that there will only ever be ONE <Permissions>
|
||||||
else
|
// element. Currently there are no known use cases for multiple.
|
||||||
{
|
Element permsElement = element.getChild("Permissions", METSRights_NS);
|
||||||
if (element.getAttributeValue("CONTEXTCLASS").equalsIgnoreCase("REPOSITORY MGR")) {
|
if(permsElement == null) {
|
||||||
Group adminGroup = groupService.findByName(context, Group.ADMIN);
|
log.error("No <Permissions> element was found. Skipping this <Context> element.");
|
||||||
rp.setGroup(adminGroup);
|
continue;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (element.getAttributeValue("rpName") != null)
|
if (element.getAttributeValue("rpName") != null)
|
||||||
{
|
{
|
||||||
rp.setRpName(element.getAttributeValue("rpName"));
|
rp.setRpName(element.getAttributeValue("rpName"));
|
||||||
@@ -508,52 +502,9 @@ public class METSRightsCrosswalk
|
|||||||
rp.setEndDate(sdf.parse(element.getAttributeValue("end-date")));
|
rp.setEndDate(sdf.parse(element.getAttributeValue("end-date")));
|
||||||
}
|
}
|
||||||
}catch (ParseException ex) {
|
}catch (ParseException ex) {
|
||||||
java.util.logging.Logger.getLogger(METSRightsCrosswalk.class.getName()).log(Level.SEVERE, null, ex);
|
log.error("Failed to parse embargo date. The date needs to be in the format 'yyyy-MM-dd'.", 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);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
//also get reference to the <Permissions> element
|
|
||||||
Element permsElement = element.getChild("Permissions", METSRights_NS);
|
|
||||||
|
|
||||||
//Check if this permission pertains to Anonymous users
|
//Check if this permission pertains to Anonymous users
|
||||||
if(ANONYMOUS_CONTEXTCLASS.equals(contextClass))
|
if(ANONYMOUS_CONTEXTCLASS.equals(contextClass))
|
||||||
{
|
{
|
||||||
@@ -564,7 +515,7 @@ public class METSRightsCrosswalk
|
|||||||
throw new CrosswalkInternalException("The DSpace database has not been properly initialized. The Anonymous Group is missing from the database.");
|
throw new CrosswalkInternalException("The DSpace database has not been properly initialized. The Anonymous Group is missing from the database.");
|
||||||
}
|
}
|
||||||
|
|
||||||
assignPermissions(context, dso, anonGroup, permsElement);
|
rp.setGroup(anonGroup);
|
||||||
} // else if this permission declaration pertains to Administrators
|
} // else if this permission declaration pertains to Administrators
|
||||||
else if(ADMIN_CONTEXTCLASS.equals(contextClass))
|
else if(ADMIN_CONTEXTCLASS.equals(contextClass))
|
||||||
{
|
{
|
||||||
@@ -575,7 +526,7 @@ public class METSRightsCrosswalk
|
|||||||
throw new CrosswalkInternalException("The DSpace database has not been properly initialized. The Administrator Group is missing from the database.");
|
throw new CrosswalkInternalException("The DSpace database has not been properly initialized. The Administrator Group is missing from the database.");
|
||||||
}
|
}
|
||||||
|
|
||||||
assignPermissions(context, dso, adminGroup, permsElement);
|
rp.setGroup(adminGroup);
|
||||||
} // else if this permission pertains to another DSpace group
|
} // else if this permission pertains to another DSpace group
|
||||||
else if(GROUP_CONTEXTCLASS.equals(contextClass))
|
else if(GROUP_CONTEXTCLASS.equals(contextClass))
|
||||||
{
|
{
|
||||||
@@ -604,8 +555,8 @@ public class METSRightsCrosswalk
|
|||||||
+ "Please restore this group using the SITE AIP, or recreate it.");
|
+ "Please restore this group using the SITE AIP, or recreate it.");
|
||||||
}
|
}
|
||||||
|
|
||||||
//assign permissions to group on this object
|
//assign group to policy
|
||||||
assignPermissions(context, dso, group, permsElement);
|
rp.setGroup(group);
|
||||||
}
|
}
|
||||||
catch(PackageException pe)
|
catch(PackageException pe)
|
||||||
{
|
{
|
||||||
@@ -613,7 +564,7 @@ public class METSRightsCrosswalk
|
|||||||
//We'll just wrap it as a CrosswalkException and throw it upwards
|
//We'll just wrap it as a CrosswalkException and throw it upwards
|
||||||
throw new CrosswalkException(pe);
|
throw new CrosswalkException(pe);
|
||||||
}
|
}
|
||||||
}//end if Group
|
}// else if this permission pertains to a DSpace person
|
||||||
else if(PERSON_CONTEXTCLASS.equals(contextClass))
|
else if(PERSON_CONTEXTCLASS.equals(contextClass))
|
||||||
{
|
{
|
||||||
//we need to find the person it pertains to
|
//we need to find the person it pertains to
|
||||||
@@ -642,12 +593,18 @@ public class METSRightsCrosswalk
|
|||||||
+ "Please restore this Person object using the SITE AIP, or recreate it.");
|
+ "Please restore this Person object using the SITE AIP, or recreate it.");
|
||||||
}
|
}
|
||||||
|
|
||||||
//assign permissions to person on this object
|
//assign person to the policy
|
||||||
assignPermissions(context, dso, person, permsElement);
|
rp.setEPerson(person);
|
||||||
}//end if Person
|
}//end if Person
|
||||||
else
|
else {
|
||||||
log.error("Unrecognized CONTEXTCLASS: " + contextClass);
|
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 if "Context" element
|
||||||
}//end while loop
|
}//end while loop
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user