@Override public ResourcePolicy createResourcePolicy(Context context, DSpaceObject dso, Group group, EPerson eperson, int type, String rpType, String rpName, String rpDescription, Date startDate, Date endDate) throws SQLException, AuthorizeException { if (group == null && eperson == null) { throw new IllegalArgumentException( "We need at least an eperson or a group in order to create a resource policy."); } ResourcePolicy myPolicy = resourcePolicyService.create(context); myPolicy.setdSpaceObject(dso); myPolicy.setAction(type); myPolicy.setGroup(group); myPolicy.setEPerson(eperson); myPolicy.setRpType(rpType); myPolicy.setRpName(rpName); myPolicy.setRpDescription(rpDescription); myPolicy.setEndDate(endDate); myPolicy.setStartDate(startDate); resourcePolicyService.update(context, myPolicy); return myPolicy; }
policy.setRpType(ResourcePolicy.TYPE_CUSTOM);
/** * Add the default policies, which have not been already added to the given DSpace object * * @param context The relevant DSpace Context. * @param dso The DSpace Object to add policies to * @param defaultCollectionPolicies list of policies * @throws SQLException An exception that provides information on a database access error or other errors. * @throws AuthorizeException Exception indicating the current user of the context does not have permission * to perform a particular action. */ protected void addDefaultPoliciesNotInPlace(Context context, DSpaceObject dso, List<ResourcePolicy> defaultCollectionPolicies) throws SQLException, AuthorizeException { for (ResourcePolicy defaultPolicy : defaultCollectionPolicies) { if (!authorizeService .isAnIdenticalPolicyAlreadyInPlace(context, dso, defaultPolicy.getGroup(), Constants.READ, defaultPolicy.getID())) { ResourcePolicy newPolicy = resourcePolicyService.clone(context, defaultPolicy); newPolicy.setdSpaceObject(dso); newPolicy.setAction(Constants.READ); newPolicy.setRpType(ResourcePolicy.TYPE_INHERITED); resourcePolicyService.update(context, newPolicy); } } }
@Override public void addPolicies(Context c, List<ResourcePolicy> policies, DSpaceObject dest) throws SQLException, AuthorizeException { // now add them to the destination object List<ResourcePolicy> newPolicies = new LinkedList<>(); for (ResourcePolicy srp : policies) { ResourcePolicy rp = resourcePolicyService.create(c); // copy over values rp.setdSpaceObject(dest); rp.setAction(srp.getAction()); rp.setEPerson(srp.getEPerson()); rp.setGroup(srp.getGroup()); rp.setStartDate(srp.getStartDate()); rp.setEndDate(srp.getEndDate()); rp.setRpName(srp.getRpName()); rp.setRpDescription(srp.getRpDescription()); rp.setRpType(srp.getRpType()); // and add policy to list of new policies newPolicies.add(rp); } resourcePolicyService.update(c, newPolicies); }
@Override public ResourcePolicy clone(Context context, ResourcePolicy resourcePolicy) throws SQLException, AuthorizeException { ResourcePolicy clone = create(context); clone.setGroup(resourcePolicy.getGroup()); clone.setEPerson(resourcePolicy.getEPerson()); clone.setStartDate((Date) ObjectUtils.clone(resourcePolicy.getStartDate())); clone.setEndDate((Date) ObjectUtils.clone(resourcePolicy.getEndDate())); clone.setRpType((String) ObjectUtils.clone(resourcePolicy.getRpType())); clone.setRpDescription((String) ObjectUtils.clone(resourcePolicy.getRpDescription())); update(context, clone); return clone; }