Package org.dspace.content

Examples of org.dspace.content.ItemIterator


            List<Integer> iids = new ArrayList<Integer>();
            for (BrowseItem bi : binfo.getBrowseItemResults())
            {
                iids.add(bi.getID());
            }
            ItemIterator ii = new ItemIterator(context, iids);
            MetadataExport exporter = new MetadataExport(context, ii, false);

            // Perform the export
            DSpaceCSV csv = exporter.export();
View Full Code Here


            {
                if (thing.getType() == Constants.ITEM)
                {
                    List<Integer> item = new ArrayList<Integer>();
                    item.add(thing.getID());
                    exporter = new MetadataExport(context, new ItemIterator(context, item), false);
                }
                else if (thing.getType() == Constants.COLLECTION)
                {
                    Collection collection = (Collection)thing;
                    ItemIterator toExport = collection.getAllItems();
                    exporter = new MetadataExport(context, toExport, false);
                }
                else if (thing.getType() == Constants.COMMUNITY)
                {
                    exporter = new MetadataExport(context, (Community)thing, false);
View Full Code Here

            throws ServletException, IOException, SQLException,
            AuthorizeException
    {
        // Turn the iterator into a list
        List<Item> subList = new LinkedList<Item>();
        ItemIterator subs = Item.findBySubmitter(context, context
                .getCurrentUser());

        try
        {
            while (subs.hasNext())
            {
                subList.add(subs.next());
            }
        }
        finally
        {
            if (subs != null)
            {
                subs.close();
            }
        }

        Item[] items = new Item[subList.size()];
View Full Code Here

    {
      EPerson person = sc.getOnBehalfOf() != null ? sc.getOnBehalfOf() : sc.getAuthenticated();
      List<Item> collectionItems = new ArrayList<Item>();

      // first get the ones out of the archive
      ItemIterator items = Item.findBySubmitter(sc.getContext(), person);
      while(items.hasNext())
      {
        Item item = items.next();
        Collection[] cols = item.getCollections();
        for (Collection col : cols)
        {
          if (col.getID() == collection.getID())
          {
View Full Code Here

            }
        }

        if (zip)
        {
            ItemIterator items;
            if (myItem != null)
            {
                List<Integer> myItems = new ArrayList<Integer>();
                myItems.add(myItem.getID());
                items = new ItemIterator(c, myItems);
            }
            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();
                    }
                }
            }
        }
View Full Code Here

                Collection[] collections = community.getAllCollections();
                for (Collection collection : collections)
                {
                    ArrayList<Integer> items = new ArrayList<Integer>();
                    // 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();
                        }
                        if (items.size() > 0)
                        {
                            itemsMap.put("collection_"+collection.getID(), items);
                        }
                    }
                }
            }
            else if (dso.getType() == Constants.COLLECTION)
            {
                Collection collection = (Collection) dso;
                ArrayList<Integer> items = new ArrayList<Integer>();

                // 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();
                    }
                    if (items.size() > 0)
                    {
                        itemsMap.put("collection_"+collection.getID(), items);
                    }
                }
            }
            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();
                    }
                }
                ArrayList<Integer> items = new ArrayList<Integer>();
                items.add(item.getID());
                itemsMap.put("item_"+item.getID(), items);
            }
            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 && 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 anonymous thread
        if (itemsMap.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.turnOffAuthorisationSystem();

                        String fileName = assembleFileName("item", eperson,
                                new Date());
                        String workParentDir = getExportWorkDirectory()
                                + System.getProperty("file.separator")
                                + fileName;
                        String downloadDir = getExportDownloadDirectory(eperson
                                .getID());
                        File dnDir = new File(downloadDir);
                        if (!dnDir.exists() && !dnDir.mkdirs())
                        {
                            log.error("Unable to create download directory");
                        }

                        Iterator<String> iter = itemsMap.keySet().iterator();
                        while(iter.hasNext())
                        {
                            String keyName = iter.next();
                            iitems = new ItemIterator(context, itemsMap.get(keyName));

                            String workDir = workParentDir
                                    + System.getProperty("file.separator")
                                    + keyName;

                            File wkDir = new File(workDir);
                            if (!wkDir.exists() && !wkDir.mkdirs())
                            {
                                log.error("Unable to create working directory");
                            }


                            // export the items using normal export method
                            exportItem(context, iitems, workDir, 1, migrate);
                            iitems.close();
                        }

                        // now zip up the export directory created above
                        zip(workParentDir, 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.restoreAuthSystemState();
                    }
                    catch (Exception e1)
                    {
                        try
                        {
                            emailErrorMessage(eperson, e1.getMessage());
                        }
                        catch (Exception e)
                        {
                            // wont throw here
                        }
                        throw new IllegalStateException(e1);
                    }
                    finally
                    {
                        if (iitems != null)
                        {
                            iitems.close();
                        }

                        // Make sure the database connection gets closed in all conditions.
                      try {
              context.complete();
View Full Code Here

            }
        }
        else
        {
            //otherwise, just find every item and process
            ItemIterator i = Item.findAll(c);
            try
            {
                while (i.hasNext() && processed < max2Process)
                {
                    applyFiltersItem(c, i.next());
                }
            }
            finally
            {
                if (i != null)
                {
                    i.close();
                }
            }
        }
    }
View Full Code Here

                                              throws Exception
    {
        //only apply filters if collection not in skip-list
        if(!inSkipList(collection.getHandle()))
        {
            ItemIterator i = collection.getItems();
            try
            {
                while (i.hasNext() && processed < max2Process)
                {
                    applyFiltersItem(c, i.next());
                }
            }
            finally
            {
                if (i != null)
                {
                    i.close();
                }
            }
        }
    }
View Full Code Here

            {
                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

  {
    int count_native = 0;
    int count_import = 0;
   
    // get all items from that collection
        ItemIterator iterator = collection.getItems();

        try
        {
            // iterate through the items in this collection, and count how many
            // are native, and how many are imports, and which collections they
            // came from
            while (iterator.hasNext())
            {
                Item item = iterator.next();

                if (item.isOwningCollection(collection))
                {
                    count_native++;
                }
                else
                {
                    count_import++;
                }
            }
        }
        finally
        {
            if (iterator != null)
            {
                iterator.close();
            }
        }
       
        int[] counts = new int[2];
        counts[0] = count_native;
View Full Code Here

TOP

Related Classes of org.dspace.content.ItemIterator

Copyright © 2018 www.massapicom. 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.