protected DCDate recoverEmbargoDate(Item item) { DCDate liftDate = null; List<MetadataValue> lift = itemService.getMetadata(item, lift_schema, lift_element, lift_qualifier, Item.ANY); if (lift.size() > 0) { liftDate = new DCDate(lift.get(0).getValue()); // sanity check: do not allow an embargo lift date in the past. if (liftDate.toDate().before(new Date())) { liftDate = null; } } return liftDate; }
@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()); } /* * NOTE: We do not check here for past dates as it can result in errors during AIP restoration. * Therefore, UIs should perform any such date validation on input. See DS-3348 */ return result; }
} else { log.debug("Testing embargo on item=" + item.getHandle() + ", date=" + liftDate.toString()); if (liftDate.toDate().before(now)) { if (line.hasOption('v')) { System.err.println(
@Override public Version createNewVersion(Context c, Item item, String summary) { try { VersionHistory vh = versionHistoryService.findByItem(c, item); if (vh == null) { // first time: create 2 versions: old and new one vh = versionHistoryService.create(c); // get dc:date.accessioned to be set as first version date... List<MetadataValue> values = itemService.getMetadata(item, "dc", "date", "accessioned", Item.ANY); Date versionDate = new Date(); if (values != null && values.size() > 0) { String date = values.get(0).getValue(); versionDate = new DCDate(date).toDate(); } createVersion(c, vh, item, "", versionDate); } // Create new Item Item itemNew = provider.createNewItemAndAddItInWorkspace(c, item); // create new version Version version = createVersion(c, vh, itemNew, summary, new Date()); // Complete any update of the Item and new Identifier generation that needs to happen provider.updateItemState(c, itemNew, item); return version; } catch (Exception e) { throw new RuntimeException(e.getMessage(), e); } }
/** * Enforce embargo by turning off all read access to bitstreams in * this Item. * * @param context the DSpace context * @param item the item to embargo */ @Override public void setEmbargo(Context context, Item item) throws SQLException, AuthorizeException { DCDate liftDate = EmbargoServiceFactory.getInstance().getEmbargoService().getEmbargoTermsAsDate(context, item); for (Bundle bn : item.getBundles()) { // Skip the LICENSE and METADATA bundles, they stay world-readable String bnn = bn.getName(); if (!(bnn.equals(Constants.LICENSE_BUNDLE_NAME) || bnn.equals(Constants.METADATA_BUNDLE_NAME) || bnn .equals(CreativeCommonsServiceImpl.CC_BUNDLE_NAME))) { //AuthorizeManager.removePoliciesActionFilter(context, bn, Constants.READ); generatePolicies(context, liftDate.toDate(), null, bn, item.getOwningCollection()); for (Bitstream bs : bn.getBitstreams()) { //AuthorizeManager.removePoliciesActionFilter(context, bs, Constants.READ); generatePolicies(context, liftDate.toDate(), null, bs, item.getOwningCollection()); } } } }
Calendar endDate = Calendar.getInstance(); endDate.setTime(dcStart.toDate()); endDate.add(Calendar.YEAR, 1); DCDate dcEndDate = new DCDate(endDate.getTime());
return new DCDate(workflowStartDate).toDate();