
package org.dspace.embfix;

import org.dspace.authorize.AuthorizeManager;
import org.dspace.content.Bitstream;
import org.dspace.content.Bundle;
import org.dspace.content.DCDate;
import org.dspace.content.Item;
import org.dspace.content.ItemIterator;
import org.dspace.core.Context;
import org.dspace.core.Constants;
import org.dspace.authorize.ResourcePolicy;
import org.dspace.embargo.EmbargoManager;

/**
 * TEST CODE - not fit for general consumption
 * @author richardrodgers
 */
public class EmbargoResetter {
    
    public static void main(String[] args) throws Exception {
        Context c = new Context();
        c.setIgnoreAuthorization(true);
        ItemIterator itIter = Item.findAll(c);
        long count = 0L;
        while (itIter.hasNext()) {
            Item item = itIter.next();
            DCDate date = EmbargoManager.getEmbargoDate(c, item);
            if (date != null) {
                EmbargoManager.setEmbargo(c, item, date);
                c.commit();
                System.out.println("Set Embargo on: " + item.getHandle()  + " lifting: " + date);
            }
            if ((++count % 100) == 0) {
                System.out.print(".");
                c.clearCache();
            }
        }
        c.complete();
        System.out.println("Examined " + count + " items");
    }
}
