1 40 package org.dspace.app.webui.servlet.admin; 41 42 import java.util.HashMap ; 43 import java.util.Map ; 44 import java.util.LinkedList ; 45 46 import javax.servlet.http.HttpServletRequest ; 47 import javax.servlet.http.HttpServletResponse ; 48 49 import org.dspace.app.webui.servlet.DSpaceServlet; 50 import org.dspace.app.webui.util.JSPManager; 51 import org.dspace.app.webui.util.UIUtil; 52 import org.dspace.authorize.AuthorizeException; 53 import org.dspace.authorize.AuthorizeManager; 54 import org.dspace.browse.Browse; 55 import org.dspace.content.Collection; 56 import org.dspace.content.Item; 57 import org.dspace.content.ItemIterator; 58 import org.dspace.core.Constants; 59 import org.dspace.core.Context; 60 import org.dspace.storage.rdbms.DatabaseManager; 61 import org.dspace.storage.rdbms.TableRow; 62 import org.dspace.storage.rdbms.TableRowIterator; 63 64 69 public class ItemMapServlet extends DSpaceServlet 70 { 71 protected void doDSGet(Context context, HttpServletRequest request, 72 HttpServletResponse response) throws java.sql.SQLException , 73 javax.servlet.ServletException , java.io.IOException , 74 AuthorizeException 75 { 76 doDSPost(context, request, response); 77 } 78 79 protected void doDSPost(Context context, HttpServletRequest request, 80 HttpServletResponse response) throws java.sql.SQLException , 81 javax.servlet.ServletException , java.io.IOException , 82 AuthorizeException 83 { 84 String jspPage = null; 85 86 int myID = UIUtil.getIntParameter(request, "cid"); 88 89 Collection myCollection = Collection.find(context, myID); 91 92 AuthorizeManager.authorizeAction(context, myCollection, 94 Constants.COLLECTION_ADMIN); 95 96 String action = request.getParameter("action"); 97 98 if (action == null) 99 { 100 action = ""; 101 } 102 103 String cancel = request.getParameter("cancel"); 105 106 if (cancel == null) 107 { 108 cancel = ""; 109 } 110 111 if (action.equals("") || !cancel.equals("")) 112 { 113 int count_native = 0; int count_import = 0; Map myItems = new HashMap (); Map myCollections = new HashMap (); Map myCounts = new HashMap (); 123 ItemIterator i = myCollection.getItems(); 125 126 while (i.hasNext()) 130 { 131 Item myItem = i.next(); 132 133 Integer myKey = new Integer (myItem.getID()); 135 136 if (myItem.isOwningCollection(myCollection)) 137 { 138 count_native++; 139 } 140 else 141 { 142 count_import++; 143 } 144 145 Collection owningCollection = myItem.getOwningCollection(); 147 Integer cKey = new Integer (owningCollection.getID()); 148 149 if (myCollections.containsKey(cKey)) 150 { 151 Integer x = (Integer ) myCounts.get(cKey); 152 int myCount = x.intValue() + 1; 153 154 myCounts.put(cKey, new Integer (myCount)); 156 } 157 else 158 { 159 myCollections.put(cKey, owningCollection); 161 myCounts.put(cKey, new Integer (1)); 162 } 163 164 myItems.put(myKey, myItem); 166 } 167 168 myCollections.remove(new Integer (myCollection.getID())); 171 172 request.setAttribute("collection", myCollection); 175 request.setAttribute("count_native", new Integer (count_native)); 176 request.setAttribute("count_import", new Integer (count_import)); 177 request.setAttribute("items", myItems); 178 request.setAttribute("collections", myCollections); 179 request.setAttribute("collection_counts", myCounts); 180 request 181 .setAttribute("all_collections", Collection 182 .findAll(context)); 183 184 jspPage = "itemmap-main.jsp"; 186 187 JSPManager.showJSP(request, response, jspPage); 189 } 190 256 else if (action.equals("Remove")) 257 { 258 String [] itemIDs = request.getParameterValues("item_ids"); 260 String message = "remove"; 261 LinkedList removedItems = new LinkedList (); 262 263 for (int j = 0; j < itemIDs.length; j++) 264 { 265 int i = Integer.parseInt(itemIDs[j]); 266 removedItems.add(itemIDs[j]); 267 268 Item myItem = Item.find(context, i); 269 270 if (!myItem.isOwningCollection(myCollection)) 272 { 273 myCollection.removeItem(myItem); 274 Browse.itemChanged(context,myItem); 275 } 276 } 277 278 request.setAttribute("message", message); 279 request.setAttribute("collection", myCollection); 280 request.setAttribute("processedItems", removedItems); 281 282 jspPage = "itemmap-info.jsp"; 284 285 JSPManager.showJSP(request, response, jspPage); 287 } 288 else if (action.equals("Add")) 289 { 290 String [] itemIDs = request.getParameterValues("item_ids"); 292 String message = "added"; 293 LinkedList addedItems = new LinkedList (); 294 295 296 if (itemIDs == null) 297 { 298 message = "none-selected"; 299 } 300 else 301 { 302 for (int j = 0; j < itemIDs.length; j++) 303 { 304 int i = Integer.parseInt(itemIDs[j]); 305 306 Item myItem = Item.find(context, i); 307 308 if (AuthorizeManager.authorizeActionBoolean(context, 309 myItem, Constants.READ)) 310 { 311 if (!myItem.isOwningCollection(myCollection)) 313 { 314 myCollection.addItem(myItem); 315 Browse.itemChanged(context,myItem); 316 addedItems.add(itemIDs[j]); 317 } 318 } 319 } 320 } 321 322 request.setAttribute("message", message); 323 request.setAttribute("collection", myCollection); 324 request.setAttribute("processedItems", addedItems); 325 326 jspPage = "itemmap-info.jsp"; 328 329 JSPManager.showJSP(request, response, jspPage); 331 } 332 else if (action.equals("Search Authors")) 333 { 334 String myQuery = (String ) request.getParameter("namepart"); 338 339 TableRowIterator tri = DatabaseManager.query(context, 340 "SELECT * from ItemsByAuthor WHERE sort_author like ? AND " + 341 "item_id NOT IN (SELECT item_id FROM collection2item " + 342 "WHERE collection_id= ? )", 343 '%'+myQuery.toLowerCase()+'%',myCollection.getID()); 344 345 Map items = new HashMap (); 346 347 while (tri.hasNext()) 348 { 349 TableRow tr = tri.next(); 350 351 int itemID = tr.getIntColumn("item_id"); 353 354 Item myItem = Item.find(context, itemID); 355 356 if (AuthorizeManager.authorizeActionBoolean(context, myItem, 358 Constants.READ)) 359 { 360 items.put(new Integer (itemID), myItem); 361 } 362 } 363 tri.close(); 364 365 request.setAttribute("collection", myCollection); 366 request.setAttribute("browsetext", myQuery); 367 request.setAttribute("items", items); 368 request.setAttribute("browsetype", new String ("Add")); 369 370 jspPage = "itemmap-browse.jsp"; 371 JSPManager.showJSP(request, response, jspPage); 372 } 373 else if (action.equals("browse")) 374 { 375 int t = UIUtil.getIntParameter(request, "t"); 377 378 Collection targetCollection = Collection.find(context, t); 379 380 ItemIterator i = myCollection.getItems(); 383 Map items = new HashMap (); 384 385 while (i.hasNext()) 386 { 387 Item myItem = i.next(); 388 389 if (myItem.isOwningCollection(targetCollection)) 390 { 391 Integer myKey = new Integer (myItem.getID()); 392 items.put(myKey, myItem); 393 } 394 } 395 396 request.setAttribute("collection", myCollection); 397 request.setAttribute("browsetext", targetCollection 398 .getMetadata("name")); 399 request.setAttribute("items", items); 400 request.setAttribute("browsetype", new String ("Remove")); 401 402 jspPage = "itemmap-browse.jsp"; 404 405 JSPManager.showJSP(request, response, jspPage); 407 } 408 409 context.complete(); 410 } 411 } 412 | Popular Tags |