Index: dspace-api/src/main/java/org/dspace/content/InstallItem.java =================================================================== --- dspace-api/src/main/java/org/dspace/content/InstallItem.java (revision 4205) +++ dspace-api/src/main/java/org/dspace/content/InstallItem.java (working copy) @@ -45,6 +45,7 @@ import org.dspace.authorize.AuthorizeException; import org.dspace.core.ConfigurationManager; import org.dspace.core.Context; +import org.dspace.embargo.EmbargoManager; import org.dspace.handle.HandleManager; /** @@ -90,9 +91,17 @@ Item item = is.getItem(); String handle; + // this is really just to flush out fatal embargo metadata + // problems before we set inArchive. + DCDate liftDate = EmbargoManager.getEmbargoDate(c, item); + // create accession date DCDate now = DCDate.getCurrent(); item.addDC("date", "accessioned", null, now.toString()); + + // add date available if not under embargo, otherwise it will + // be set when the embargo is lifted. + if (liftDate == null) item.addDC("date", "available", null, now.toString()); // create issue date if not present @@ -100,7 +109,9 @@ if (currentDateIssued.length == 0) { - item.addDC("date", "issued", null, now.toString()); + DCDate issued = new DCDate(); + issued.setDateLocal(now.getYear(),now.getMonth(),now.getDay(),-1,-1,-1); + item.addDC("date", "issued", null, issued.toString()); } // if no previous handle supplied, create one @@ -157,6 +168,11 @@ // the defaults from the collection item.inheritCollectionDefaultPolicies(is.getCollection()); + // set embargo lift date and take away read access if indicated. + if (liftDate != null) + EmbargoManager.setEmbargo(c, item, liftDate); + + return item; } Index: dspace-api/src/main/java/org/dspace/content/Item.java =================================================================== --- dspace-api/src/main/java/org/dspace/content/Item.java (revision 4205) +++ dspace-api/src/main/java/org/dspace/content/Item.java (working copy) @@ -2261,4 +2261,33 @@ DCValue t[] = getMetadata("dc", "title", null, Item.ANY); return (t.length >= 1) ? t[0].value : null; } + + /** + * Find all the items in the archive with ANY entries in the + * indicated metadata field. + * + * @param context DSpace context object + * @param schema metdata field schema + * @param element metdata field element + * @param qualifier metdata field qualifier + * @return an iterator over the items matching that authority value + * @throws SQLException, AuthorizeException, IOException + */ + public static ItemIterator findByMetadataField(Context context, + String schema, String element, String qualifier) + throws SQLException, AuthorizeException, IOException + { + MetadataSchema mds = MetadataSchema.find(context, schema); + if (mds == null) + throw new IllegalArgumentException("No such metadata schema: "+schema); + MetadataField mdf = MetadataField.findByElement(context, mds.getSchemaID(), element, qualifier); + if (mdf == null) + throw new IllegalArgumentException("No such metadata field: schema="+schema+", element="+element+", qualifier="+qualifier); + + TableRowIterator rows = DatabaseManager.queryTable(context, "item", + "SELECT item.* FROM metadatavalue,item WHERE item.in_archive='1' "+ + "AND item.item_id = metadatavalue.item_id AND metadata_field_id = ?", + mdf.getFieldID()); + return new ItemIterator(context, rows); } +}