@Override public void setEmbargo(Context context, Item item) throws SQLException, AuthorizeException { // if lift is null, we might be restoring an item from an AIP DCDate myLift = getEmbargoTermsAsDate(context, item); if (myLift == null) { if ((myLift = recoverEmbargoDate(item)) == null) { return; } } String slift = myLift.toString(); boolean ignoreAuth = context.ignoreAuthorization(); try { context.setIgnoreAuthorization(true); itemService.clearMetadata(context, item, lift_schema, lift_element, lift_qualifier, Item.ANY); itemService.addMetadata( context, item, lift_schema, lift_element, lift_qualifier, null, slift); log.info("Set embargo on Item " + item.getHandle() + ", expires on: " + slift); setter.setEmbargo(context, item); itemService.update(context, item); } finally { context.setIgnoreAuthorization(ignoreAuth); } }
@Override public DCDate getEmbargoTermsAsDate(Context context, Item item) throws SQLException, AuthorizeException { List<MetadataValue> terms = itemService.getMetadata(item, terms_schema, terms_element, terms_qualifier, Item.ANY); DCDate result = null; // Its poor form to blindly use an object that could be null... if (terms == null) return null; result = setter.parseTerms(context, item, terms.size() > 0 ? terms.get(0).getValue() : null); if (result == null) return null; // new DCDate(non-date String) means toDate() will return null Date liftDate = result.toDate(); if (liftDate == null) { throw new IllegalArgumentException( "Embargo lift date is uninterpretable: " + result.toString()); } // sanity check: do not allow an embargo lift date in the past. if (liftDate.before(new Date())) { throw new IllegalArgumentException( "Embargo lift date must be in the future, but this is in the past: " + result.toString()); } return result; }
@Override public void checkEmbargo(Context context, Item item) throws SQLException, IOException, AuthorizeException { setter.checkEmbargo(context, item); }