mirror of
https://github.com/DSpace/DSpace.git
synced 2025-10-07 18:14:26 +00:00
METSRightsCrosswalk ingest(...) Policy Logic Refactoring
Consolidation/refactoring of the ingest() method logic to address NPEs and incorrect behavior when importing certain objects (e.g. a collection with an rpName and association to a non-Admin/non-Anonymous group).
This commit is contained in:
@@ -471,107 +471,53 @@ 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)
|
try {
|
||||||
|| (element.getAttributeValue("end-date") != null)
|
ResourcePolicy rp = resourcePolicyService.create(context);
|
||||||
|| (element.getAttributeValue("rpName") != null))
|
SimpleDateFormat sdf = new SimpleDateFormat( "yyyy-MM-dd" );
|
||||||
{
|
|
||||||
SimpleDateFormat sdf = new SimpleDateFormat( "yyyy-MM-dd" );
|
//also get reference to the <Permissions> element
|
||||||
|
Element permsElement = element.getChild("Permissions", METSRights_NS);
|
||||||
|
|
||||||
|
if (element.getAttributeValue("rpName") != null)
|
||||||
|
{
|
||||||
|
rp.setRpName(element.getAttributeValue("rpName"));
|
||||||
|
}
|
||||||
try {
|
try {
|
||||||
ResourcePolicy rp = resourcePolicyService.create(context);
|
if (element.getAttributeValue("start-date") != null)
|
||||||
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")) {
|
rp.setStartDate(sdf.parse(element.getAttributeValue("start-date")));
|
||||||
Group adminGroup = groupService.findByName(context, Group.ADMIN);
|
|
||||||
rp.setGroup(adminGroup);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if (element.getAttributeValue("rpName") != null)
|
if (element.getAttributeValue("end-date") != null)
|
||||||
{
|
{
|
||||||
rp.setRpName(element.getAttributeValue("rpName"));
|
rp.setEndDate(sdf.parse(element.getAttributeValue("end-date")));
|
||||||
}
|
}
|
||||||
try {
|
}catch (ParseException ex) {
|
||||||
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);
|
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))
|
||||||
{
|
{
|
||||||
//get DSpace Anonymous group, ID=0
|
//get DSpace Anonymous group, ID=0
|
||||||
Group anonGroup = groupService.findByName(context, Group.ANONYMOUS);
|
Group anonGroup = groupService.findByName(context, Group.ANONYMOUS);;
|
||||||
if(anonGroup==null)
|
if(anonGroup==null)
|
||||||
{
|
{
|
||||||
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))
|
||||||
{
|
{
|
||||||
//get DSpace Administrator group, ID=1
|
//get DSpace Administrator group, ID=1
|
||||||
Group adminGroup = groupService.findByName(context, Group.ADMIN);
|
Group adminGroup = groupService.findByName(context, Group.ADMIN);;
|
||||||
if(adminGroup==null)
|
if(adminGroup==null)
|
||||||
{
|
{
|
||||||
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))
|
||||||
{
|
{
|
||||||
@@ -600,8 +546,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)
|
||||||
{
|
{
|
||||||
@@ -609,7 +555,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
|
||||||
@@ -638,11 +584,19 @@ 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);
|
||||||
|
} catch (NullPointerException ex) {
|
||||||
|
java.util.logging.Logger.getLogger(METSRightsCrosswalk.class.getName()).log(Level.SEVERE, null, ex);
|
||||||
}
|
}
|
||||||
} //end if "Context" element
|
} //end if "Context" element
|
||||||
}//end while loop
|
}//end while loop
|
||||||
|
Reference in New Issue
Block a user