/** * figures out if the date is valid for the policy * * @param resourcePolicy resource policy * @return true if policy has begun and hasn't expired yet (or no dates are * set) */ @Override public boolean isDateValid(ResourcePolicy resourcePolicy) { Date sd = resourcePolicy.getStartDate(); Date ed = resourcePolicy.getEndDate(); // if no dates set, return true (most common case) if ((sd == null) && (ed == null)) { return true; } // one is set, now need to do some date math Date now = new Date(); // check start date first if (sd != null && now.before(sd)) { // start date is set, return false if we're before it return false; } // now expiration date if (ed != null && now.after(ed)) { // end date is set, return false if we're after it return false; } // if we made it this far, start < now < end return true; // date must be okay }
private boolean willChangeStatus(Item item) throws SQLException { List<ResourcePolicy> policies = authorizeService.getPoliciesActionFilter(context, item, Constants.READ); for (ResourcePolicy policy : policies) { if ((policy.getGroup() != null) && (policy.getGroup().getName().equals("Anonymous"))) { if (policy.getStartDate() != null && policy.getStartDate().after(new Date())) { return true; } if (policy.getEndDate() != null && policy.getEndDate().after(new Date())) { return true; } } } return false; }
dates.add(policy.getStartDate()); if (policy.getEndDate() != null) { dates.add(policy.getEndDate());
/** * Return a hash code for this object. * * @return int hash of object */ @Override public int hashCode() { int hash = 7; hash = 19 * hash + this.getAction(); if (this.getGroup() != null) { hash = 19 * hash + this.getGroup().hashCode(); } else { hash = 19 * hash + -1; } if (this.getEPerson() != null) { hash = 19 * hash + this.getEPerson().hashCode(); } else { hash = 19 * hash + -1; } hash = 19 * hash + (this.getStartDate() != null ? this.getStartDate().hashCode() : 0); hash = 19 * hash + (this.getEndDate() != null ? this.getEndDate().hashCode() : 0); return hash; }
if (policy.getEndDate() != null) { rightsContext.setAttribute("end-date", iso8601.format(policy.getEndDate())); if (policy.getEndDate().before(now)) { rightsContext.setAttribute("in-effect", "false");
return false; if (!ObjectUtils.equals(getEndDate(), other.getEndDate())) { return false;
this.rpType = dspacePolicy.getRpType(); this.startDate = dspacePolicy.getStartDate(); this.endDate = dspacePolicy.getEndDate(); switch (dspacePolicy.getdSpaceObject().getType()) { case org.dspace.core.Constants.BITSTREAM:
@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; }