Ejemplo n.º 1
0
  @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);
  }
Ejemplo n.º 2
0
  @Override
  public ResourcePolicy createResourcePolicy(
      Context context, DSpaceObject dso, Group group, EPerson eperson, int type, String rpType)
      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);
    resourcePolicyService.update(context, myPolicy);

    return myPolicy;
  }
Ejemplo n.º 3
0
  @Override
  public ResourcePolicy createOrModifyPolicy(
      ResourcePolicy policy,
      Context context,
      String name,
      Group group,
      EPerson ePerson,
      Date embargoDate,
      int action,
      String reason,
      DSpaceObject dso)
      throws AuthorizeException, SQLException {

    int policyID = -1;
    if (policy != null) policyID = policy.getID();

    // if an identical policy (same Action and same Group) is already in place modify it...
    ResourcePolicy policyTemp = findByTypeIdGroupAction(context, dso, group, action, policyID);
    if (policyTemp != null) {
      policy = policyTemp;
      policy.setRpType(ResourcePolicy.TYPE_CUSTOM);
    }

    if (policy == null) {
      policy =
          createResourcePolicy(context, dso, group, ePerson, action, ResourcePolicy.TYPE_CUSTOM);
    }
    policy.setGroup(group);
    policy.setEPerson(ePerson);

    if (embargoDate != null) {
      policy.setStartDate(embargoDate);
    } else {
      policy.setStartDate(null);
      policy.setEndDate(null);
    }
    policy.setRpName(name);
    policy.setRpDescription(reason);
    return policy;
  }