Examples of ItemIterator


Examples of org.dspace.content.ItemIterator

            throws ServletException, IOException, SQLException,
            AuthorizeException
    {
        // Turn the iterator into a list
        List subList = new LinkedList();
        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()];

        for (int i = 0; i < subList.size(); i++)
View Full Code Here

Examples of org.dspace.content.ItemIterator

        Map myItems = new HashMap(); // # for the browser
        Map myCollections = new HashMap(); // collections for list
        Map myCounts = new HashMap(); // counts for each collection
       
        // get all items from that collection, add them to a hash
        ItemIterator i = myCollection.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 (i.hasNext())
                {
                    Item myItem = i.next();

                    // get key for hash
                    Integer myKey = new Integer(myItem.getID());

                    if (myItem.isOwningCollection(myCollection))
                    {
                        count_native++;
                    }
                    else
                    {
                        count_import++;
                    }

                    // is the collection in the hash?
                    Collection owningCollection = myItem.getOwningCollection();
                    Integer cKey = new Integer(owningCollection.getID());

                    if (myCollections.containsKey(cKey))
                    {
                        Integer x = (Integer) myCounts.get(cKey);
                        int myCount = x.intValue() + 1;

                        // increment count for that collection
                        myCounts.put(cKey, new Integer(myCount));
                    }
                    else
                    {
                        // store and initialize count
                        myCollections.put(cKey, owningCollection);
                        myCounts.put(cKey, new Integer(1));
                    }

                    // store the item
                    myItems.put(myKey, myItem);
                }
            }
            finally
            {
                if (i != null)
                    i.close();
            }
           
            // remove this collection's entry because we already have a native
        // count
        myCollections.remove(new Integer(myCollection.getID()));
       
        // sort items - later
        // show page
        request.setAttribute("collection", myCollection);
        request.setAttribute("count_native", new Integer(count_native));
        request.setAttribute("count_import", new Integer(count_import));
        request.setAttribute("items", myItems);
        request.setAttribute("collections", myCollections);
        request.setAttribute("collection_counts", myCounts);
        request
        .setAttribute("all_collections", Collection
            .findAll(context));
       
        // show this page when we're done
        jspPage = "itemmap-main.jsp";
       
        // show the page
        JSPManager.showJSP(request, response, jspPage);
      }
      else if (action.equals("Remove"))
      {
        // get item IDs to remove
        String[] itemIDs = request.getParameterValues("item_ids");
        String message = "remove";
        LinkedList removedItems = new LinkedList();
       
                if (itemIDs == null)
                {
                        message = "none-removed";
                }
                else
                {
           for (int j = 0; j < itemIDs.length; j++)
          {
            int i = Integer.parseInt(itemIDs[j]);
            removedItems.add(itemIDs[j]);
         
            Item myItem = Item.find(context, i);
         
            // make sure item doesn't belong to this collection
            if (!myItem.isOwningCollection(myCollection))
            {
              myCollection.removeItem(myItem);
              try
              {
                IndexBrowse ib = new IndexBrowse(context);
                ib.itemChanged(myItem);
              }
              catch (BrowseException e)
              {
                log.error("caught exception: ", e);
                throw new ServletException(e);
              }
            }
          }
    }
       
        request.setAttribute("message", message);
        request.setAttribute("collection", myCollection);
        request.setAttribute("processedItems", removedItems);
       
        // show this page when we're done
        jspPage = "itemmap-info.jsp";
       
        // show the page
        JSPManager.showJSP(request, response, jspPage);
      }
      else if (action.equals("Add"))
      {
        // get item IDs to add
        String[] itemIDs = request.getParameterValues("item_ids");
        String message = "added";
        LinkedList addedItems = new LinkedList();
       
       
        if (itemIDs == null)
        {
          message = "none-selected";
        }
        else
        {
          for (int j = 0; j < itemIDs.length; j++)
          {
            int i = Integer.parseInt(itemIDs[j]);
           
            Item myItem = Item.find(context, i);
           
            if (AuthorizeManager.authorizeActionBoolean(context,
                myItem, Constants.READ))
            {
              // make sure item doesn't belong to this collection
              if (!myItem.isOwningCollection(myCollection))
              {
                myCollection.addItem(myItem);
                try
                  {
                    IndexBrowse ib = new IndexBrowse(context);
                    ib.itemChanged(myItem);
                  }
                  catch (BrowseException e)
                  {
                    log.error("caught exception: ", e);
                    throw new ServletException(e);
                  }
                addedItems.add(itemIDs[j]);
              }
            }
          }
        }
       
        request.setAttribute("message", message);
        request.setAttribute("collection", myCollection);
        request.setAttribute("processedItems", addedItems);
       
        // show this page when we're done
        jspPage = "itemmap-info.jsp";
       
        // show the page
        JSPManager.showJSP(request, response, jspPage);
      }
      else if (action.equals("Search Authors"))
      {
        String name = (String) request.getParameter("namepart");
        String bidx = ConfigurationManager.getProperty("itemmap.author.index");
        if (bidx == null)
        {
          throw new ServletException("There is no configuration for itemmap.author.index");
        }
        Map items = new HashMap();
        try
        {
          BrowserScope bs = new BrowserScope(context);
          BrowseIndex bi = BrowseIndex.getBrowseIndex(bidx);
         
          // set up the browse scope
          bs.setBrowseIndex(bi);
          bs.setOrder(SortOption.ASCENDING);
          bs.setFilterValue(name);
                bs.setFilterValuePartial(true);
          bs.setJumpToValue(null);
          bs.setResultsPerPage(10000)// an arbitrary number (large) for the time being
          bs.setBrowseLevel(1);
         
          BrowseEngine be = new BrowseEngine(context);
          BrowseInfo results = be.browse(bs);
          Item[] browseItems = results.getItemResults(context);
         
          // FIXME: oh god this is so annoying - what an API /Richard
          // we need to deduplicate against existing items in this collection
          ItemIterator itr = myCollection.getItems();
                try
                {
                    ArrayList idslist = new ArrayList();
                    while (itr.hasNext())
                    {
                        idslist.add(new Integer(itr.nextID()));
                    }

                    for (int i = 0; i < browseItems.length; i++)
                    {
                        // only if it isn't already in this collection
                        if (!idslist.contains(new Integer(browseItems[i].getID())))
                        {
                            // only put on list if you can read item
                            if (AuthorizeManager.authorizeActionBoolean(context, browseItems[i], Constants.READ))
                            {
                                items.put(new Integer(browseItems[i].getID()), browseItems[i]);
                            }
                        }
                    }
                }
                finally
                {
                    if (itr != null)
                        itr.close();
                }
            }
        catch (BrowseException e)
        {
          log.error("caught exception: ", e);
          throw new ServletException(e);
        }
       
        request.setAttribute("collection", myCollection);
        request.setAttribute("browsetext", name);
        request.setAttribute("items", items);
        request.setAttribute("browsetype", new String("Add"));
       
        jspPage = "itemmap-browse.jsp";
        JSPManager.showJSP(request, response, jspPage);
      }
      else if (action.equals("browse"))
      {
        // target collection to browse
        int t = UIUtil.getIntParameter(request, "t");
       
        Collection targetCollection = Collection.find(context, t);
       
        // now find all imported items from that collection
        // seemingly inefficient, but database should have this query cached
            Map items = new HashMap();
        ItemIterator i = myCollection.getItems();
            try
            {
                while (i.hasNext())
                {
                    Item myItem = i.next();

                    if (myItem.isOwningCollection(targetCollection))
                    {
                        Integer myKey = new Integer(myItem.getID());
                        items.put(myKey, myItem);
                    }
                }
            }
            finally
            {
                if (i != null)
                    i.close();
            }
       
            request.setAttribute("collection", myCollection);
        request.setAttribute("browsetext", targetCollection
            .getMetadata("name"));
View Full Code Here

Examples of org.dspace.content.ItemIterator

            {
                if (thing.getType() == Constants.ITEM)
                {
                    ArrayList item = new ArrayList();
                    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

Examples of org.dspace.content.ItemIterator

     
      ItemUpdate.prv("Metadata field to match for item: " + dtom.toString());

      this.addUndoMetadataField(dtom)//seed the undo list with the identifier field
     
      ItemIterator itr = Item.findByMetadataField(context, dtom.schema, dtom.element, dtom.qualifier, dtom.value);
    int count = 0;
    while (itr.hasNext())
    {
      item = itr.next();
      count++;
    }
   
    itr.close();
   
    ItemUpdate.prv("items matching = " + count );
   
    if (count != 1)
    {
View Full Code Here

Examples of org.dspace.content.ItemIterator

  {
    FlowResult result = new FlowResult();
    Collection collection = Collection.find(context, collectionID);
    HarvestedCollection hc = HarvestedCollection.find(context, collectionID);
   
    ItemIterator it = collection.getAllItems();
    //IndexBrowse ib = new IndexBrowse(context);
    while (it.hasNext()) {
      Item item = it.next();
      //System.out.println("Deleting: " + item.getHandle());
      //ib.itemRemoved(item);
      collection.removeItem(item);
    }
    hc.setHarvestResult(null,"");
View Full Code Here

Examples of org.dspace.content.ItemIterator

            ArrayList iids = new ArrayList();
            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

Examples of org.dspace.content.ItemIterator

        ArrayList iids = new ArrayList();
        for (Item item : items)
        {
            iids.add(item.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

Examples of org.dspace.content.ItemIterator

            this.addExpand("parentCommunity");
        }

        //TODO: Item paging. limit, offset/page
        if(expandFields.contains("items") || expandFields.contains("all")) {
            ItemIterator childItems;
            if(limit != null && limit >= 0 && offset != null && offset >= 0) {
                childItems = collection.getItems(limit, offset);
            } else {
                childItems = collection.getItems();
            }

            items = new ArrayList<Item>();
            while(childItems.hasNext()) {
                org.dspace.content.Item item = childItems.next();

                if(ItemService.isItemListedForUser(context, item)) {
                    items.add(new Item(item, null, context));
                }
            }
View Full Code Here

Examples of org.dspace.content.ItemIterator

        try
        {
            context = createContext(getUser(headers));

            ItemIterator dspaceItems = org.dspace.content.Item.findAllUnfiltered(context);
            items = new ArrayList<Item>();

            if (!((limit != null) && (limit >= 0) && (offset != null) && (offset >= 0)))
            {
                log.warn("Pagging was badly set, using default values.");
                limit = 100;
                offset = 0;
            }

            for (int i = 0; (dspaceItems.hasNext()) && (i < (limit + offset)); i++)
            {
                org.dspace.content.Item dspaceItem = dspaceItems.next();
                if (i >= offset)
                {
                    if (ItemService.isItemListedForUser(context, dspaceItem))
                    {
                        items.add(new Item(dspaceItem, expand, context));
View Full Code Here

Examples of org.dspace.content.ItemIterator

            }
        }
       
        if (dso instanceof Collection)
        {
            ItemIterator items = ((Collection) dso).getAllItems();
            while (items.hasNext())
            {
                Item item = items.next();
                this.dspaceDFS(item, callback, check, false);
                item.decache();
            }
        }
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.