From d70ba1103d3bf139511a599f579093676f88637d Mon Sep 17 00:00:00 2001 From: David Stuve Date: Mon, 5 Apr 2004 16:15:09 +0000 Subject: [PATCH] Item mapper added for adding items from one collection to another git-svn-id: http://scm.dspace.org/svn/repo/trunk@833 9c30dcfa-912a-0410-8fc2-9e0234be79fd --- dspace/etc/dspace-web.xml | 11 + dspace/jsp/collection-home.jsp | 10 +- dspace/jsp/tools/itemmap-browse.jsp | 135 ++++++ dspace/jsp/tools/itemmap-info.jsp | 76 ++++ dspace/jsp/tools/itemmap-main.jsp | 167 +++++++ .../webui/servlet/admin/ItemMapServlet.java | 430 ++++++++++++++++++ 6 files changed, 828 insertions(+), 1 deletion(-) create mode 100644 dspace/jsp/tools/itemmap-browse.jsp create mode 100644 dspace/jsp/tools/itemmap-info.jsp create mode 100644 dspace/jsp/tools/itemmap-main.jsp create mode 100644 dspace/src/org/dspace/app/webui/servlet/admin/ItemMapServlet.java diff --git a/dspace/etc/dspace-web.xml b/dspace/etc/dspace-web.xml index e006af000e..cda814a5bf 100644 --- a/dspace/etc/dspace-web.xml +++ b/dspace/etc/dspace-web.xml @@ -130,6 +130,11 @@ org.dspace.app.webui.servlet.AdvancedSearchServlet + + itemmap + org.dspace.app.webui.servlet.admin.ItemMapServlet + + bitstream org.dspace.app.webui.servlet.BitstreamServlet @@ -377,6 +382,12 @@ eperson-list /tools/eperson-list + + + itemmap + /tools/itemmap + + feedback diff --git a/dspace/jsp/collection-home.jsp b/dspace/jsp/collection-home.jsp index 800b6ce250..ce2a7dc0d7 100644 --- a/dspace/jsp/collection-home.jsp +++ b/dspace/jsp/collection-home.jsp @@ -213,13 +213,21 @@ -
+
+ + +
+ + +
+ + <% if(submitters != null) { %> diff --git a/dspace/jsp/tools/itemmap-browse.jsp b/dspace/jsp/tools/itemmap-browse.jsp new file mode 100644 index 0000000000..31d1a20c2e --- /dev/null +++ b/dspace/jsp/tools/itemmap-browse.jsp @@ -0,0 +1,135 @@ +<%-- + - itemmap-browse.jsp + - + - Version: $ $ + - + - Date: $ $ + - + - Copyright (c) 2002, Hewlett-Packard Company and Massachusetts + - Institute of Technology. All rights reserved. + - + - Redistribution and use in source and binary forms, with or without + - modification, are permitted provided that the following conditions are + - met: + - + - - Redistributions of source code must retain the above copyright + - notice, this list of conditions and the following disclaimer. + - + - - Redistributions in binary form must reproduce the above copyright + - notice, this list of conditions and the following disclaimer in the + - documentation and/or other materials provided with the distribution. + - + - - Neither the name of the Hewlett-Packard Company nor the name of the + - Massachusetts Institute of Technology nor the names of their + - contributors may be used to endorse or promote products derived from + - this software without specific prior written permission. + - + - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + - ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + - LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + - A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + - HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + - INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + - BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + - OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + - ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + - TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE + - USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH + - DAMAGE. + --%> + + +<%-- + - Display the results of an item browse + - + - Attributes to pass in: + - + - items - sorted Map of Items to display + - collection - Collection we're managing + - collections - Map of Collections, keyed by collection_id + - browsetext - text to display at the top + + + + + --%> + +<%@ page contentType="text/html;charset=UTF-8" %> + +<%@ taglib uri="http://www.dspace.org/dspace-tags.tld" prefix="dspace" %> + +<%@ page import="java.net.URLEncoder" %> +<%@ page import="java.util.Iterator" %> +<%@ page import="java.util.Map" %> +<%@ page import="org.dspace.content.Collection" %> +<%@ page import="org.dspace.content.Item" %> + +<% + Collection collection = (Collection)request.getAttribute("collection"); + Map items = (Map)request.getAttribute("items"); + Map collections = (Map)request.getAttribute("collections"); + String browsetext = (String)request.getAttribute("browsetext"); + Boolean showcollection = new Boolean(false); + String browsetype = (String)request.getAttribute("browsetype"); +%> + + + +

Browse <%=browsetext%>

+ +
+ + + + + + + + + <% if(showcollection.booleanValue()) { %> + + + <% } else { %> + +<% + String row = "even"; + Iterator i = items.keySet().iterator(); + + while( i.hasNext() ) + { + Item item = (Item)items.get(i.next()); +%> + + + + + +<% if( showcollection.booleanValue() ) { %> +<%-- not currently implemented --%> + + +<% } else { %> + + +<% } %> + +
DateFirst AuthorTitleAction Remove + <% } %> +
+ <%= item.getDC("date", "issued", Item.ANY)[0].value %> + + <%= item.getDC("contributor", Item.ANY, Item.ANY)[0].value %> + + <%= item.getDC("title", null, Item.ANY)[0].value %> <%= collection.getID() %> + <%= item.getDC("title", null, Item.ANY)[0].value %> + +<% } + + row = (row.equals("odd") ? "even" : "odd"); +%> +
+
+ +
diff --git a/dspace/jsp/tools/itemmap-info.jsp b/dspace/jsp/tools/itemmap-info.jsp new file mode 100644 index 0000000000..0e8d7089e9 --- /dev/null +++ b/dspace/jsp/tools/itemmap-info.jsp @@ -0,0 +1,76 @@ +<%-- + - itemmap-info.jsp + - + - Version: $ $ + - + - Date: $ $ + - + - Copyright (c) 2002, Hewlett-Packard Company and Massachusetts + - Institute of Technology. All rights reserved. + - + - Redistribution and use in source and binary forms, with or without + - modification, are permitted provided that the following conditions are + - met: + - + - - Redistributions of source code must retain the above copyright + - notice, this list of conditions and the following disclaimer. + - + - - Redistributions in binary form must reproduce the above copyright + - notice, this list of conditions and the following disclaimer in the + - documentation and/or other materials provided with the distribution. + - + - - Neither the name of the Hewlett-Packard Company nor the name of the + - Massachusetts Institute of Technology nor the names of their + - contributors may be used to endorse or promote products derived from + - this software without specific prior written permission. + - + - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + - ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + - LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + - A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + - HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + - INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + - BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + - OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + - ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + - TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE + - USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH + - DAMAGE. + --%> + +<%-- + - Display information with a 'continue' button. (Maybe a cancel?) + - + - Attributes to pass in: + - + - collection - Collection we're managing + - message - String to output + --%> + +<%@ page contentType="text/html;charset=UTF-8" %> + +<%@ taglib uri="http://www.dspace.org/dspace-tags.tld" prefix="dspace" %> + +<%@ page import="java.net.URLEncoder" %> +<%@ page import="java.util.Iterator" %> +<%@ page import="java.util.Map" %> +<%@ page import="org.dspace.content.Collection" %> +<%@ page import="org.dspace.content.Item" %> +<%@ page import="org.dspace.core.ConfigurationManager" %> + +<% + Collection collection = (Collection)request.getAttribute("collection"); + String message = (String)request.getAttribute("message"); +%> + + + +

Item Map Info

+ +

<%=message%>

+ +
+ + +
+
diff --git a/dspace/jsp/tools/itemmap-main.jsp b/dspace/jsp/tools/itemmap-main.jsp new file mode 100644 index 0000000000..550992b96f --- /dev/null +++ b/dspace/jsp/tools/itemmap-main.jsp @@ -0,0 +1,167 @@ +<%-- + - itemmap-main.jsp + - + - Version: $ $ + - + - Date: $ $ + - + - Copyright (c) 2002, Hewlett-Packard Company and Massachusetts + - Institute of Technology. All rights reserved. + - + - Redistribution and use in source and binary forms, with or without + - modification, are permitted provided that the following conditions are + - met: + - + - - Redistributions of source code must retain the above copyright + - notice, this list of conditions and the following disclaimer. + - + - - Redistributions in binary form must reproduce the above copyright + - notice, this list of conditions and the following disclaimer in the + - documentation and/or other materials provided with the distribution. + - + - - Neither the name of the Hewlett-Packard Company nor the name of the + - Massachusetts Institute of Technology nor the names of their + - contributors may be used to endorse or promote products derived from + - this software without specific prior written permission. + - + - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + - ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + - LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + - A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + - HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + - INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + - BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + - OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + - ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + - TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE + - USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH + - DAMAGE. + --%> + + +<%-- + - Display the main page for item mapping (status and controls) + - + - Attributes to pass in: + - + - collection - Collection we're managing + - collections - Map of Collections, keyed by collection_id + - collection_counts - Map of Collection IDs to counts + - count_native - how many items are in collection + - count_import - how many items are 'virtual' + --%> + +<%@ page contentType="text/html;charset=UTF-8" %> + +<%@ taglib uri="http://www.dspace.org/dspace-tags.tld" prefix="dspace" %> + +<%@ page import="java.net.URLEncoder" %> +<%@ page import="java.util.Iterator" %> +<%@ page import="java.util.Map" %> +<%@ page import="org.dspace.content.Collection" %> +<%@ page import="org.dspace.content.Item" %> +<%@ page import="org.dspace.core.ConfigurationManager" %> + +<% + Collection collection = (Collection)request.getAttribute("collection"); + int count_native = + ((Integer)request.getAttribute("count_native")).intValue(); + int count_import = + ((Integer)request.getAttribute("count_import")).intValue(); + Map items = (Map)request.getAttribute("items"); + Map collections = (Map)request.getAttribute("collections"); + Map collection_counts = (Map)request.getAttribute("collection_counts"); + Collection [] all_collections = (Collection[]) + request.getAttribute("all_collections"); +%> + + + +

Item Mapper - Map Items from Other Collections

+ +

This Collection: <%=collection.getMetadata("name")%>

+ +

There are <%=count_native%> items owned by this collection, and + <%=count_import%> items mapped from other collections.

+ +<%-- +

Quick Add Item:

+ +

Enter the Handle or internal item ID of the item you want to add:

+ +
+ + +
+ + + + + + + + + + +
Handle: + /" size=12> + +
Internal ID: + + +
+
+
+ +

Import an entire collection

+
+ + + + +
+--%> + +

Import By Author Match

+ Enter part of an author's name for a list of matching items
+ +
+ + + +
+
+ +

Browse Item Imported From Collections:

+ +<% + String row = "even"; + Iterator colKeys = collections.keySet().iterator(); + + while( colKeys.hasNext() ) + { + Collection myCollection = (Collection)collections.get(colKeys.next()); + String myTitle = myCollection.getMetadata("name"); + int cid = collection.getID(); + int myID = myCollection.getID(); + int myCount = ((Integer)collection_counts.get( + new Integer(myID))).intValue(); + + String myLink = request.getContextPath()+"/tools/itemmap?action=browse"; +%> +

<%=myTitle%> (<%=myCount%>)

+<% } %> +
+ diff --git a/dspace/src/org/dspace/app/webui/servlet/admin/ItemMapServlet.java b/dspace/src/org/dspace/app/webui/servlet/admin/ItemMapServlet.java new file mode 100644 index 0000000000..964c7f2967 --- /dev/null +++ b/dspace/src/org/dspace/app/webui/servlet/admin/ItemMapServlet.java @@ -0,0 +1,430 @@ +/* + * ItemMapServlet.java + * + * Version: $$ + * + * Date: $$ + * + * Copyright (c) 2002, Hewlett-Packard Company and Massachusetts + * Institute of Technology. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * - Neither the name of the Hewlett-Packard Company nor the name of the + * Massachusetts Institute of Technology nor the names of their + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE + * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH + * DAMAGE. + */ + +package org.dspace.app.webui.servlet.admin; + +import javax.servlet.ServletException; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import java.util.HashMap; +import java.util.Iterator; +import java.util.Map; +import java.sql.SQLException; + +import org.dspace.authorize.AuthorizeException; +import org.dspace.authorize.AuthorizeManager; +import org.dspace.app.webui.servlet.DSpaceServlet; +import org.dspace.app.webui.util.JSPManager; +import org.dspace.app.webui.util.UIUtil; +import org.dspace.content.Collection; +import org.dspace.content.DCValue; +import org.dspace.content.DSpaceObject; +import org.dspace.content.Item; +import org.dspace.content.ItemIterator; +import org.dspace.core.Constants; +import org.dspace.core.Context; +import org.dspace.storage.rdbms.DatabaseManager; +import org.dspace.handle.HandleManager; +import org.dspace.storage.rdbms.TableRowIterator; +import org.dspace.storage.rdbms.TableRow; + +/** + * Servlet for editing and deleting (expunging) items + * + * @version $Revision$ + */ +public class ItemMapServlet extends DSpaceServlet +{ + protected void doDSGet(Context context, HttpServletRequest request, + HttpServletResponse response) + throws java.sql.SQLException, javax.servlet.ServletException, + java.io.IOException, AuthorizeException + { + doDSPost( context, request, response ); + } + + protected void doDSPost(Context context, HttpServletRequest request, + HttpServletResponse response) + throws java.sql.SQLException, javax.servlet.ServletException, + java.io.IOException, AuthorizeException + { + String jspPage = null; + + // get with a collection ID means put up browse window + int myID = UIUtil.getIntParameter(request, "cid"); + + // get collection + Collection myCollection = Collection.find(context, myID); + + // authorize check + AuthorizeManager.authorizeAction(context, myCollection, Constants.COLLECTION_EDITOR); + + String action = request.getParameter("action"); + + if( action == null ) { action = ""; } + + if( action.equals("") ) + { + // get with no action parameter set means to put up the main page + // which is statistics and some command buttons to add/remove items + + int count_native = 0; // # of items owned by this collection + int count_import = 0; // # of virtual items + 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(); + + // 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); + + } + + // 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("add") ) + { + int itemID = UIUtil.getIntParameter(request, "item_id"); + String handle = (String)request.getParameter("handle"); + boolean error = true; + Item itemToAdd = null; + + if( itemID > 0 ) + { + itemToAdd = Item.find(context, itemID); + + if( itemToAdd != null ) error = false; + } + else if(handle != null && !handle.equals("")) + { + DSpaceObject dso=HandleManager.resolveToObject(context, handle); + + if(dso != null && dso.getType() == Constants.ITEM) + { + itemToAdd = (Item)dso; + error = false; + } + } + + //FIXME: error handling! + if( !error ) + { + String myTitle = + itemToAdd.getDC("title",null,Item.ANY)[0].value; + String ownerName = + itemToAdd.getOwningCollection().getMetadata("name"); + + // hook up item, but first, does it belong already? + TableRowIterator tri = DatabaseManager.query(context, + "collection2item", + "SELECT collection2item.* FROM collection2item WHERE " + + "collection_id=" + myCollection.getID() + + " AND item_id=" + itemToAdd.getID()); + + if(tri.hasNext()) + { + request.setAttribute("message", "Item is already part of that collection!"); + } + else + { + // Create mapping + myCollection.addItem( itemToAdd ); + + // set up a nice 'done' message + request.setAttribute("message", "Item added successfully:
" + + myTitle + "
From Collection:
" + ownerName); + + } + + request.setAttribute("collection", myCollection); + + // show this page when we're done + jspPage = "itemmap-info.jsp"; + + // show the page + JSPManager.showJSP(request, response, jspPage); + } + else + { + // Display an error + } + } + else if( action.equals("Add Entire Collection") ) + { + int targetID = UIUtil.getIntParameter(request, "collection2import"); + + Collection targetCollection = Collection.find(context, targetID); + + // get all items from that collection and add them if not + // already added + + // get all items to be added + ItemIterator i = targetCollection.getItems(); + Map toAdd = new HashMap(); + String message = ""; + + while( i.hasNext() ) + { + Item myItem = i.next(); + + toAdd.put(new Integer(myItem.getID()), myItem); + } + + // now see what we already have, removing dups from the 'toAdd' list + i = myCollection.getItems(); + + while( i.hasNext() ) + { + Item myItem = i.next(); + Integer myKey = new Integer(myItem.getID()); + + // remove works even if key isn't present + toAdd.remove(myKey); + } + + // what's left in toAdd should be added + Iterator addKeys = toAdd.keySet().iterator(); + + while( addKeys.hasNext() ) + { + Item myItem = (Item)toAdd.get(addKeys.next()); + myCollection.addItem(myItem); + message += "
Added item ID: " + myItem.getID(); + } + + request.setAttribute("message", message); + request.setAttribute("collection", myCollection); + + // show this page when we're done + jspPage = "itemmap-info.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 = ""; + + for( int j = 0; j < itemIDs.length; j++ ) + { + int i = Integer.parseInt(itemIDs[j]); + message += "
Remove item " + i; + + Item myItem = Item.find(context, i); + + // make sure item doesn't belong to this collection + if( !myItem.isOwningCollection(myCollection) ) + { + myCollection.removeItem(myItem); + } + } + + request.setAttribute("message", message); + request.setAttribute("collection", myCollection); + + // 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 = ""; + + 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); + message += "
Added item " + i; + } + } + } + + request.setAttribute("message", message); + request.setAttribute("collection", myCollection); + + // 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") ) + { + // find all items with a matching author string and not currently in this collection + // sorting by date would be ideal... + String myQuery = (String)request.getParameter("namepart"); + + TableRowIterator tri = DatabaseManager.query(context, + "SELECT * from ItemsByAuthor WHERE sort_author like '%" + + myQuery + "%' AND item_id NOT IN (SELECT item_id FROM collection2item WHERE collection_id=" + + myCollection.getID() + ")" ); + + Map items = new HashMap(); + + while( tri.hasNext() ) + { + TableRow tr = tri.next(); + + // now instantiate and pass items to 'Add' page + int itemID = tr.getIntColumn("item_id"); + + Item myItem = Item.find(context, itemID); + + // only put on list if you can read item + if( AuthorizeManager.authorizeActionBoolean(context, myItem, Constants.READ) ) + { + items.put(new Integer(itemID), myItem); + } + } + + request.setAttribute("collection", myCollection); + request.setAttribute("browsetext", "Items matching author '" + myQuery + "'"); + 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 + ItemIterator i = myCollection.getItems(); + Map items = new HashMap(); + + while(i.hasNext()) + { + Item myItem = i.next(); + + if( myItem.isOwningCollection(targetCollection) ) + { + Integer myKey = new Integer(myItem.getID()); + items.put(myKey, myItem); + } + } + + request.setAttribute("collection", myCollection); + request.setAttribute("browsetext", targetCollection.getMetadata("name")); + request.setAttribute("items", items); + request.setAttribute("browsetype", new String("Remove")); + + // show this page when we're done + jspPage = "itemmap-browse.jsp"; + + // show the page + JSPManager.showJSP(request, response, jspPage); + } + + context.complete(); + } +}