Examples of ItemIterator


Examples of org.dspace.content.ItemIterator

                                RelationPreference.UNLINKED);
            }
        }

        EPerson eperson = EPerson.find(context, rp.getEpersonID());
        ItemIterator items = Item.findBySubmitter(context, eperson);
        List<MetadataField> mfs = metadataFieldWithAuthorityRP(context);
        int count = 0;
        while (items.hasNext())
        {
            Item item = items.next();
            if (rejected == null || !rejected.contains(item.getID()))
            {
                boolean found = false;
                for (MetadataField mf : mfs)
                {
View Full Code Here

Examples of org.dspace.content.ItemIterator

    public static Set<Integer> getPotentialMatch(Context context,
            ResearcherPage researcher) throws SQLException, AuthorizeException,
            IOException
    {
        Set<Integer> invalidIds = new HashSet<Integer>();
        ItemIterator iter = null;
        try
        {
            iter = getPendingMatch(context, researcher);
            while (iter.hasNext())
            {
                invalidIds.add(iter.nextID());
            }
        }
        finally
        {
            if (iter != null)
                iter.close();
        }

        DSpace dspace = new DSpace();
        ApplicationService applicationService = dspace.getServiceManager()
                .getServiceByName("applicationService",
View Full Code Here

Examples of org.dspace.content.ItemIterator

        if (containerType == Constants.COLLECTION)
        {
            Collection collection = Collection.find(c, containerID);
            Group group = Group.find(c, groupID);

            ItemIterator i = collection.getItems();
            try
            {
                if (contentType == Constants.ITEM)
                {
                    // build list of all items in a collection
                    while (i.hasNext())
                    {
                        Item myitem = i.next();

                        // is this a replace? delete policies first
                        if (isReplace || clearOnly)
                        {
                            AuthorizeManager.removeAllPolicies(c, myitem);
                        }

                        if (!clearOnly)
                        {
                            // now add the policy
                            ResourcePolicy rp = ResourcePolicy.create(c);

                            rp.setResource(myitem);
                            rp.setAction(actionID);
                            rp.setGroup(group);

                            rp.update();
                        }
                    }
                }
                else if (contentType == Constants.BUNDLE)
                {
                    // build list of all items in a collection
                    // build list of all bundles in those items
                    while (i.hasNext())
                    {
                        Item myitem = i.next();

                        Bundle[] bundles = myitem.getBundles();

                        for (int j = 0; j < bundles.length; j++)
                        {
                            Bundle t = bundles[j]; // t for target

                            // is this a replace? delete policies first
                            if (isReplace || clearOnly)
                            {
                                AuthorizeManager.removeAllPolicies(c, t);
                            }

                            if (!clearOnly)
                            {
                                // now add the policy
                                ResourcePolicy rp = ResourcePolicy.create(c);

                                rp.setResource(t);
                                rp.setAction(actionID);
                                rp.setGroup(group);

                                rp.update();
                            }
                        }
                    }
                }
                else if (contentType == Constants.BITSTREAM)
                {
                    // build list of all bitstreams in a collection
                    // iterate over items, bundles, get bitstreams
                    while (i.hasNext())
                    {
                        Item myitem = i.next();
                        System.out.println("Item " + myitem.getID());

                        Bundle[] bundles = myitem.getBundles();

                        for (int j = 0; j < bundles.length; j++)
                        {
                            System.out.println("Bundle " + bundles[j].getID());

                            Bitstream[] bitstreams = bundles[j].getBitstreams();

                            for (int k = 0; k < bitstreams.length; k++)
                            {
                                Bitstream t = bitstreams[k]; // t for target

                                if ( filter == null ||
                                     t.getName().indexOf( filter ) != -1 )
                                {
                                    // is this a replace? delete policies first
                                    if (isReplace || clearOnly)
                                    {
                                            AuthorizeManager.removeAllPolicies(c, t);
                                    }

                                    if (!clearOnly)
                                    {
                                            // now add the policy
                                            ResourcePolicy rp = ResourcePolicy.create(c);

                                            rp.setResource(t);
                                            rp.setAction(actionID);
                                            rp.setGroup(group);

                                            rp.update();
                                    }
                                }
                            }
                        }
                    }
                }
            }
            finally
            {
                if (i != null)
                    i.close();
            }
        }
    }
View Full Code Here

Examples of org.dspace.content.ItemIterator

                        + " is not a valid item Handle");
                System.exit(1);
            }
        }

        ItemIterator items = null;
        try
        {
            if (line.hasOption('c'))
            {
                String handle = getHandleArg(line.getOptionValue('c'));

                // Exporting a collection's worth of items
                DSpaceObject o = HandleManager.resolveToObject(context, handle);

                if ((o != null) && o instanceof Collection)
                {
                    items = ((Collection) o).getItems();
                }
                else
                {
                    System.err.println(line.getOptionValue('c')
                            + " is not a valid collection Handle");
                    System.exit(1);
                }
            }

            if (line.hasOption('a'))
            {
                items = Item.findAll(context);
            }

            if (items == null)
            {
                System.err.println("Nothing to export specified!");
                System.exit(1);
            }

            while (items.hasNext())
            {
                writeAIP(context, items.next(), dest);
            }
        }
        finally
        {
            if (items != null)
                items.close();
        }
       
        context.abort();
        System.exit(0);
    }
View Full Code Here

Examples of org.dspace.content.ItemIterator

     * @param force
     */
    public static void updateIndex(Context context, boolean force) {
        try
        {
                ItemIterator items = null;
                try
                {
                    for(items = Item.findAll(context);items.hasNext();)
                    {
                        Item item = (Item) items.next();
                        indexContent(context,item,force);
                        item.decache();
                    }
                }
                finally
                {
                    if (items != null)
                        items.close();
                }

                Collection[] collections = Collection.findAll(context);
              for (int i = 0; i < collections.length; i++)
              {
View Full Code Here

Examples of org.dspace.content.ItemIterator

                html.addURL(url, null);
            if (makeSitemapOrg)
                sitemapsOrg.addURL(url, null);
        }

        ItemIterator allItems = Item.findAll(c);
        try
        {
            int itemCount = 0;

            while (allItems.hasNext())
            {
                Item i = allItems.next();
                String url = handleURLStem + i.getHandle();
                Date lastMod = i.getLastModified();

                if (makeHTMLMap)
                    html.addURL(url, lastMod);
                if (makeSitemapOrg)
                    sitemapsOrg.addURL(url, lastMod);
                i.decache();

                itemCount++;
            }

            if (makeHTMLMap)
            {
                int files = html.finish();
                log.info(LogManager.getHeader(c, "write_sitemap",
                        "type=html,num_files=" + files + ",communities="
                                + comms.length + ",collections=" + colls.length
                                + ",items=" + itemCount));
            }

            if (makeSitemapOrg)
            {
                int files = sitemapsOrg.finish();
                log.info(LogManager.getHeader(c, "write_sitemap",
                        "type=html,num_files=" + files + ",communities="
                                + comms.length + ",collections=" + colls.length
                                + ",items=" + itemCount));
            }
        }
        finally
        {
            if (allItems != null)
                allItems.close();
        }
       
        c.abort();
    }
View Full Code Here

Examples of org.dspace.content.ItemIterator

            AuthorizeException, IOException
    {

        Context ctx = new Context();
        ctx.setIgnoreAuthorization(true);
        ItemIterator iter = Item.findAll(ctx);

        Properties props = new Properties();

        File processed = new File("license.processed");

        if (processed.exists())
            props.load(new FileInputStream(processed));

        int i = 0;

        try
        {
            while (iter.hasNext())
            {
                if (i == 100)
                {
                    props.store(new FileOutputStream(processed),
                                    "processed license files, remove to restart processing from scratch");
                    i = 0;
                }

                Item item = (Item) iter.next();
                log.info("checking: " + item.getID());
                if (!props.containsKey("I" + item.getID()))
                {
                    handleItem(item);
                    log.info("processed: " + item.getID());
View Full Code Here

Examples of org.dspace.content.ItemIterator

        Context c = new Context();

        // ve are superuser!
        c.setIgnoreAuthorization(true);

        ItemIterator ii = null;

        // first set owning Collections
        Collection[] collections = Collection.findAll(c);

        System.out.println("Setting item owningCollection fields in database");

        for (int q = 0; q < collections.length; q++)
        {
            ii = collections[q].getItems();

            while (ii.hasNext())
            {
                Item myItem = ii.next();

                // set it if it's not already set
                if (myItem.getOwningCollection() == null)
                {
                    myItem.setOwningCollection(collections[q]);
                    myItem.update();
                    System.out.println("Set owner of item " + myItem.getID()
                            + " to collection " + collections[q].getID());
                }
            }
        }

        // commit pending transactions before continuing
        c.commit();

        // now combine some bundles
        ii = Item.findAll(c);

        while (ii.hasNext())
        {
            boolean skipItem = false;
            Item myItem = ii.next();

            int licenseBundleIndex = -1; // array index of license bundle (we'll
                                         // skip this one often)
            int primaryBundleIndex = -1; // array index of our primary bundle
                                         // (all bitstreams assemble here)
View Full Code Here

Examples of org.dspace.content.ItemIterator

            }
        }

        if (zip)
        {
            ItemIterator items;
            if (myItem != null)
            {
                items = new ItemIterator(c, new ArrayList(myItem.getID()));
            }
            else
            {
                System.out.println("Exporting from collection: " + myIDString);
                items = mycollection.getItems();
            }
            exportAsZip(c, items, destDirName, zipFileName, seqStart, migrate);
        }
        else
        {
            if (myItem != null)
            {
                // it's only a single item
                exportItem(c, myItem, destDirName, seqStart, migrate);
            }
            else
            {
                System.out.println("Exporting from collection: " + myIDString);

                // it's a collection, so do a bunch of items
                ItemIterator i = mycollection.getItems();
                try
                {
                    exportItem(c, i, destDirName, seqStart, migrate);
                }
                finally
                {
                    if (i != null)
                        i.close();
                }
            }
        }

        c.complete();
View Full Code Here

Examples of org.dspace.content.ItemIterator

                // get all the collections in the community
                Collection[] collections = community.getCollections();
                for (Collection collection : collections)
                {
                    // get all the items in each collection
                    ItemIterator iitems = collection.getItems();
                    try
                    {
                        while (iitems.hasNext())
                        {
                            Item item = iitems.next();
                            // get all the bundles in the item
                            Bundle[] bundles = item.getBundles();
                            for (Bundle bundle : bundles)
                            {
                                // get all the bitstreams in each bundle
                                Bitstream[] bitstreams = bundle.getBitstreams();
                                for (Bitstream bit : bitstreams)
                                {
                                    // add up the size
                                    size += bit.getSize();
                                }
                            }
                            items.add(item.getID());
                        }
                    }
                    finally
                    {
                        if (iitems != null)
                            iitems.close();
                    }
                }
            }
            else if (dso.getType() == Constants.COLLECTION)
            {
                Collection collection = (Collection) dso;
                // get all the items in the collection
                ItemIterator iitems = collection.getItems();
                try
                {
                    while (iitems.hasNext())
                    {
                        Item item = iitems.next();
                        // get all thebundles in the item
                        Bundle[] bundles = item.getBundles();
                        for (Bundle bundle : bundles)
                        {
                            // get all the bitstreams in the bundle
                            Bitstream[] bitstreams = bundle.getBitstreams();
                            for (Bitstream bit : bitstreams)
                            {
                                // add up the size
                                size += bit.getSize();
                            }
                        }
                        items.add(item.getID());
                    }
                }
                finally
                {
                    if (iitems != null)
                        iitems.close();
                }
            }
            else if (dso.getType() == Constants.ITEM)
            {
                Item item = (Item) dso;
                // get all the bundles in the item
                Bundle[] bundles = item.getBundles();
                for (Bundle bundle : bundles)
                {
                    // get all the bitstreams in the bundle
                    Bitstream[] bitstreams = bundle.getBitstreams();
                    for (Bitstream bit : bitstreams)
                    {
                        // add up the size
                        size += bit.getSize();
                    }
                }
                items.add(item.getID());
            }
            else
            {
                // nothing to do just ignore this type of DSPaceObject
            }
        }

        // check the size of all the bitstreams against the configuration file
        // entry if it exists
        String megaBytes = ConfigurationManager
                .getProperty("org.dspace.app.itemexport.max.size");
        if (megaBytes != null)
        {
            float maxSize = 0;
            try
            {
                maxSize = Float.parseFloat(megaBytes);
            }
            catch (Exception e)
            {
                // ignore...configuration entry may not be present
            }

            if (maxSize > 0)
            {
                if (maxSize < (size / 1048576.00))
                { // a megabyte
                    throw new ItemExportException(ItemExportException.EXPORT_TOO_LARGE,
                                                  "The overall size of this export is too large.  Please contact your administrator for more information.");
                }
            }
        }

        // if we have any items to process then kick off annonymous thread
        if (items.size() > 0)
        {
            Thread go = new Thread()
            {
                public void run()
                {
                    Context context = null;
                    ItemIterator iitems = null;
                    try
                    {
                        // create a new dspace context
                        context = new Context();
                        // ignore auths
                        context.setIgnoreAuthorization(true);
                        iitems = new ItemIterator(context, items);

                        String fileName = assembleFileName("item", eperson,
                                new Date());
                        String workDir = getExportWorkDirectory()
                                + System.getProperty("file.separator")
                                + fileName;
                        String downloadDir = getExportDownloadDirectory(eperson
                                .getID());

                        File wkDir = new File(workDir);
                        if (!wkDir.exists())
                        {
                            wkDir.mkdirs();
                        }

                        File dnDir = new File(downloadDir);
                        if (!dnDir.exists())
                        {
                            dnDir.mkdirs();
                        }

                        // export the items using normal export method
                        exportItem(context, iitems, workDir, 1, migrate);
                        // now zip up the export directory created above
                        zip(workDir, downloadDir
                                + System.getProperty("file.separator")
                                + fileName + ".zip");
                        // email message letting user know the file is ready for
                        // download
                        emailSuccessMessage(context, eperson, fileName + ".zip");
                        // return to enforcing auths
                        context.setIgnoreAuthorization(false);
                    }
                    catch (Exception e1)
                    {
                        try
                        {
                            emailErrorMessage(eperson, e1.getMessage());
                        }
                        catch (Exception e)
                        {
                            // wont throw here
                        }
                        throw new RuntimeException(e1);
                    }
                    finally
                    {
                        if (iitems != null)
                            iitems.close();
                       
                        // Make sure the database connection gets closed in all conditions.
                      try {
              context.complete();
            } catch (SQLException sqle) {
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.