KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > dspace > app > webui > servlet > admin > AuthorizeAdminServlet


1 /*
2  * AuthorizeAdminServlet.java
3  *
4  * Version: $Revision: 1.15 $
5  *
6  * Date: $Date: 2005/04/20 14:22:29 $
7  *
8  * Copyright (c) 2002-2005, Hewlett-Packard Company and Massachusetts
9  * Institute of Technology. All rights reserved.
10  *
11  * Redistribution and use in source and binary forms, with or without
12  * modification, are permitted provided that the following conditions are
13  * met:
14  *
15  * - Redistributions of source code must retain the above copyright
16  * notice, this list of conditions and the following disclaimer.
17  *
18  * - Redistributions in binary form must reproduce the above copyright
19  * notice, this list of conditions and the following disclaimer in the
20  * documentation and/or other materials provided with the distribution.
21  *
22  * - Neither the name of the Hewlett-Packard Company nor the name of the
23  * Massachusetts Institute of Technology nor the names of their
24  * contributors may be used to endorse or promote products derived from
25  * this software without specific prior written permission.
26  *
27  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
28  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
29  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
30  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
31  * HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
32  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
33  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
34  * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
35  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
36  * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
37  * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
38  * DAMAGE.
39  */

40 package org.dspace.app.webui.servlet.admin;
41
42 import java.io.IOException JavaDoc;
43 import java.sql.SQLException JavaDoc;
44 import java.util.HashMap JavaDoc;
45 import java.util.List JavaDoc;
46 import java.util.Map JavaDoc;
47
48 import javax.servlet.ServletException JavaDoc;
49 import javax.servlet.http.HttpServletRequest JavaDoc;
50 import javax.servlet.http.HttpServletResponse JavaDoc;
51
52 import org.dspace.app.webui.servlet.DSpaceServlet;
53 import org.dspace.app.webui.util.JSPManager;
54 import org.dspace.app.webui.util.UIUtil;
55 import org.dspace.authorize.AuthorizeException;
56 import org.dspace.authorize.AuthorizeManager;
57 import org.dspace.authorize.PolicySet;
58 import org.dspace.authorize.ResourcePolicy;
59 import org.dspace.content.Bitstream;
60 import org.dspace.content.Bundle;
61 import org.dspace.content.Collection;
62 import org.dspace.content.Community;
63 import org.dspace.content.DSpaceObject;
64 import org.dspace.content.Item;
65 import org.dspace.core.Constants;
66 import org.dspace.core.Context;
67 import org.dspace.eperson.EPerson;
68 import org.dspace.eperson.Group;
69 import org.dspace.handle.HandleManager;
70
71 /**
72  * Servlet for editing permissions
73  *
74  * @author dstuve
75  * @version $Revision: 1.15 $
76  */

77 public class AuthorizeAdminServlet extends DSpaceServlet
78 {
79     protected void doDSGet(Context c, HttpServletRequest JavaDoc request,
80             HttpServletResponse JavaDoc response) throws ServletException JavaDoc, IOException JavaDoc,
81             SQLException JavaDoc, AuthorizeException
82     {
83         // handle gets and posts with the post method
84
doDSPost(c, request, response);
85
86         // show the main page (select communities, collections, items, etc)
87
// showMainPage(c, request, response);
88
}
89
90     protected void doDSPost(Context c, HttpServletRequest JavaDoc request,
91             HttpServletResponse JavaDoc response) throws ServletException JavaDoc, IOException JavaDoc,
92             SQLException JavaDoc, AuthorizeException
93     {
94         String JavaDoc button = UIUtil.getSubmitButton(request, "submit");
95
96         if (button.equals("submit_collection"))
97         {
98             // select a collection to work on
99
Collection[] collections = Collection.findAll(c);
100
101             request.setAttribute("collections", collections);
102             JSPManager.showJSP(request, response,
103                     "/dspace-admin/collection-select.jsp");
104         }
105         else if (button.equals("submit_community"))
106         {
107             // select a community to work on
108
Community[] communities = Community.findAll(c);
109
110             request.setAttribute("communities", communities);
111             JSPManager.showJSP(request, response,
112                     "/dspace-admin/community-select.jsp");
113         }
114         else if (button.equals("submit_advanced"))
115         {
116             // select a collections to work on
117
Collection[] collections = Collection.findAll(c);
118             Group[] groups = Group.findAll(c, Group.NAME);
119
120             request.setAttribute("collections", collections);
121             request.setAttribute("groups", groups);
122
123             JSPManager.showJSP(request, response,
124                     "/dspace-admin/authorize-advanced.jsp");
125         }
126         else if (button.equals("submit_item"))
127         {
128             // select an item to work on
129
JSPManager.showJSP(request, response,
130                     "/dspace-admin/item-select.jsp");
131         }
132         // ITEMS ////////////////////////////////////////////////////
133
else if (button.equals("submit_item_select"))
134         {
135             Item item = null;
136
137             int item_id = UIUtil.getIntParameter(request, "item_id");
138             String JavaDoc handle = request.getParameter("handle");
139
140             // if id is set, use it
141
if (item_id > 0)
142             {
143                 item = Item.find(c, item_id);
144             }
145             else if ((handle != null) && !handle.equals(""))
146             {
147                 // otherwise, attempt to resolve handle
148
DSpaceObject dso = HandleManager.resolveToObject(c, handle);
149
150                 // make sure it's an item
151
if ((dso != null) && (dso.getType() == Constants.ITEM))
152                 {
153                     item = (Item) dso;
154                 }
155             }
156
157             // no item set yet, failed ID & handle, ask user to try again
158
if (item == null)
159             {
160                 request.setAttribute("invalid.id", new Boolean JavaDoc(true));
161                 JSPManager.showJSP(request, response,
162                         "/dspace-admin/item-select.jsp");
163             }
164             else
165             {
166                 // show edit form!
167
prepItemEditForm(c, request, item);
168
169                 JSPManager.showJSP(request, response,
170                         "/dspace-admin/authorize-item-edit.jsp");
171             }
172         }
173         else if (button.equals("submit_item_add_policy"))
174         {
175             // want to add a policy, create an empty one and invoke editor
176
Item item = Item
177                     .find(c, UIUtil.getIntParameter(request, "item_id"));
178
179             ResourcePolicy policy = ResourcePolicy.create(c);
180             policy.setResource(item);
181             policy.update();
182
183             Group[] groups = Group.findAll(c, Group.NAME);
184             EPerson[] epeople = EPerson.findAll(c, EPerson.EMAIL);
185
186             // return to item permission page
187
request.setAttribute("edit_title", "Item " + item.getID());
188             request.setAttribute("policy", policy);
189             request.setAttribute("groups", groups);
190             request.setAttribute("epeople", epeople);
191             request.setAttribute("id_name", "item_id");
192             request.setAttribute("id", "" + item.getID());
193             request.setAttribute("newpolicy", "true");
194
195             JSPManager.showJSP(request, response,
196                     "/dspace-admin/authorize-policy-edit.jsp");
197         }
198         else if (button.equals("submit_item_edit_policy"))
199         {
200             // edit an item's policy - set up and call policy editor
201
Item item = Item
202                     .find(c, UIUtil.getIntParameter(request, "item_id"));
203
204             int policy_id = UIUtil.getIntParameter(request, "policy_id");
205             ResourcePolicy policy = null;
206
207             policy = ResourcePolicy.find(c, policy_id);
208
209             Group[] groups = Group.findAll(c, Group.NAME);
210             EPerson[] epeople = EPerson.findAll(c, EPerson.EMAIL);
211
212             // return to collection permission page
213
request.setAttribute("edit_title", "Item " + item.getID());
214             request.setAttribute("policy", policy);
215             request.setAttribute("groups", groups);
216             request.setAttribute("epeople", epeople);
217             request.setAttribute("id_name", "item_id");
218             request.setAttribute("id", "" + item.getID());
219             JSPManager.showJSP(request, response,
220                     "/dspace-admin/authorize-policy-edit.jsp");
221         }
222         else if (button.equals("submit_bundle_add_policy"))
223         {
224             // want to add a policy, create an empty one and invoke editor
225
Item item = Item
226                     .find(c, UIUtil.getIntParameter(request, "item_id"));
227             Bundle bundle = Bundle.find(c, UIUtil.getIntParameter(request,
228                     "bundle_id"));
229
230             ResourcePolicy policy = ResourcePolicy.create(c);
231             policy.setResource(bundle);
232             policy.update();
233
234             Group[] groups = Group.findAll(c, Group.NAME);
235             EPerson[] epeople = EPerson.findAll(c, EPerson.EMAIL);
236
237             // return to item permission page
238
request.setAttribute("edit_title", "(Item, Bundle) = ("
239                     + item.getID() + "," + bundle.getID() + ")");
240             request.setAttribute("policy", policy);
241             request.setAttribute("groups", groups);
242             request.setAttribute("epeople", epeople);
243             request.setAttribute("id_name", "item_id");
244             request.setAttribute("id", "" + item.getID());
245             request.setAttribute("newpolicy", "true");
246
247             JSPManager.showJSP(request, response,
248                     "/dspace-admin/authorize-policy-edit.jsp");
249         }
250         else if (button.equals("submit_bitstream_add_policy"))
251         {
252             // want to add a policy, create an empty one and invoke editor
253
Item item = Item
254                     .find(c, UIUtil.getIntParameter(request, "item_id"));
255             Bitstream bitstream = Bitstream.find(c, UIUtil.getIntParameter(
256                     request, "bitstream_id"));
257
258             ResourcePolicy policy = ResourcePolicy.create(c);
259             policy.setResource(bitstream);
260             policy.update();
261
262             Group[] groups = Group.findAll(c, Group.NAME);
263             EPerson[] epeople = EPerson.findAll(c, EPerson.EMAIL);
264
265             // return to item permission page
266
request.setAttribute("edit_title", "(Item,Bitstream) = ("
267                     + item.getID() + "," + bitstream.getID() + ")");
268             request.setAttribute("policy", policy);
269             request.setAttribute("groups", groups);
270             request.setAttribute("epeople", epeople);
271             request.setAttribute("id_name", "item_id");
272             request.setAttribute("id", "" + item.getID());
273             request.setAttribute("newpolicy", "true");
274
275             JSPManager.showJSP(request, response,
276                     "/dspace-admin/authorize-policy-edit.jsp");
277         }
278         else if (button.equals("submit_item_delete_policy"))
279         {
280             // delete a permission from an item
281
Item item = Item
282                     .find(c, UIUtil.getIntParameter(request, "item_id"));
283             ResourcePolicy policy = ResourcePolicy.find(c, UIUtil
284                     .getIntParameter(request, "policy_id"));
285
286             // do the remove
287
policy.delete();
288
289             // show edit form!
290
prepItemEditForm(c, request, item);
291
292             JSPManager.showJSP(request, response,
293                     "/dspace-admin/authorize-item-edit.jsp");
294         }
295         // COLLECTIONS ////////////////////////////////////////////////////////
296
else if (button.equals("submit_collection_add_policy"))
297         {
298             // want to add a policy, create an empty one and invoke editor
299
Collection collection = Collection.find(c, UIUtil.getIntParameter(
300                     request, "collection_id"));
301
302             ResourcePolicy policy = ResourcePolicy.create(c);
303             policy.setResource(collection);
304             policy.update();
305
306             Group[] groups = Group.findAll(c, Group.NAME);
307             EPerson[] epeople = EPerson.findAll(c, EPerson.EMAIL);
308
309             // return to collection permission page
310
request.setAttribute("edit_title", "Collection "
311                     + collection.getID());
312             request.setAttribute("policy", policy);
313             request.setAttribute("groups", groups);
314             request.setAttribute("epeople", epeople);
315             request.setAttribute("id_name", "collection_id");
316             request.setAttribute("id", "" + collection.getID());
317             request.setAttribute("newpolicy", "true");
318
319             JSPManager.showJSP(request, response,
320                     "/dspace-admin/authorize-policy-edit.jsp");
321         }
322         else if (button.equals("submit_community_select"))
323         {
324             // edit the collection's permissions
325
Community target = Community.find(c, UIUtil.getIntParameter(
326                     request, "community_id"));
327             List JavaDoc policies = AuthorizeManager.getPolicies(c, target);
328
329             request.setAttribute("community", target);
330             request.setAttribute("policies", policies);
331             JSPManager.showJSP(request, response,
332                     "/dspace-admin/authorize-community-edit.jsp");
333         }
334         else if (button.equals("submit_collection_delete_policy"))
335         {
336             // delete a permission from a collection
337
Collection collection = Collection.find(c, UIUtil.getIntParameter(
338                     request, "collection_id"));
339             ResourcePolicy policy = ResourcePolicy.find(c, UIUtil
340                     .getIntParameter(request, "policy_id"));
341
342             // do the remove
343
policy.delete();
344
345             // return to collection permission page
346
request.setAttribute("collection", collection);
347
348             List JavaDoc policies = AuthorizeManager.getPolicies(c, collection);
349             request.setAttribute("policies", policies);
350
351             JSPManager.showJSP(request, response,
352                     "/dspace-admin/authorize-collection-edit.jsp");
353         }
354         else if (button.equals("submit_community_delete_policy"))
355         {
356             // delete a permission from a community
357
Community community = Community.find(c, UIUtil.getIntParameter(
358                     request, "community_id"));
359             ResourcePolicy policy = ResourcePolicy.find(c, UIUtil
360                     .getIntParameter(request, "policy_id"));
361
362             // do the remove
363
policy.delete();
364
365             // return to collection permission page
366
request.setAttribute("community", community);
367
368             List JavaDoc policies = AuthorizeManager.getPolicies(c, community);
369             request.setAttribute("policies", policies);
370
371             JSPManager.showJSP(request, response,
372                     "/dspace-admin/authorize-community-edit.jsp");
373         }
374         else if (button.equals("submit_collection_edit_policy"))
375         {
376             // edit a collection's policy - set up and call policy editor
377
Collection collection = Collection.find(c, UIUtil.getIntParameter(
378                     request, "collection_id"));
379
380             int policy_id = UIUtil.getIntParameter(request, "policy_id");
381             ResourcePolicy policy = null;
382
383             if (policy_id == -1)
384             {
385                 // create new policy
386
policy = ResourcePolicy.create(c);
387                 policy.setResource(collection);
388                 policy.update();
389             }
390             else
391             {
392                 policy = ResourcePolicy.find(c, policy_id);
393             }
394
395             Group[] groups = Group.findAll(c, Group.NAME);
396             EPerson[] epeople = EPerson.findAll(c, EPerson.EMAIL);
397
398             // return to collection permission page
399
request.setAttribute("edit_title", "Collection "
400                     + collection.getID());
401             request.setAttribute("policy", policy);
402             request.setAttribute("groups", groups);
403             request.setAttribute("epeople", epeople);
404             request.setAttribute("id_name", "collection_id");
405             request.setAttribute("id", "" + collection.getID());
406             JSPManager.showJSP(request, response,
407                     "/dspace-admin/authorize-policy-edit.jsp");
408         }
409         else if (button.equals("submit_community_edit_policy"))
410         {
411             // edit a community's policy - set up and call policy editor
412
Community community = Community.find(c, UIUtil.getIntParameter(
413                     request, "community_id"));
414
415             int policy_id = UIUtil.getIntParameter(request, "policy_id");
416             ResourcePolicy policy = null;
417
418             if (policy_id == -1)
419             {
420                 // create new policy
421
policy = ResourcePolicy.create(c);
422                 policy.setResource(community);
423                 policy.update();
424             }
425             else
426             {
427                 policy = ResourcePolicy.find(c, policy_id);
428             }
429
430             Group[] groups = Group.findAll(c, Group.NAME);
431             EPerson[] epeople = EPerson.findAll(c, EPerson.EMAIL);
432
433             // return to collection permission page
434
request
435                     .setAttribute("edit_title", "Community "
436                             + community.getID());
437             request.setAttribute("policy", policy);
438             request.setAttribute("groups", groups);
439             request.setAttribute("epeople", epeople);
440             request.setAttribute("id_name", "community_id");
441             request.setAttribute("id", "" + community.getID());
442             JSPManager.showJSP(request, response,
443                     "/dspace-admin/authorize-policy-edit.jsp");
444         }
445         else if (button.equals("submit_collection_add_policy"))
446         {
447             // want to add a policy, create an empty one and invoke editor
448
Collection collection = Collection.find(c, UIUtil.getIntParameter(
449                     request, "collection_id"));
450
451             ResourcePolicy policy = ResourcePolicy.create(c);
452             policy.setResource(collection);
453             policy.update();
454
455             Group[] groups = Group.findAll(c, Group.NAME);
456             EPerson[] epeople = EPerson.findAll(c, EPerson.EMAIL);
457
458             // return to collection permission page
459
request.setAttribute("edit_title", "Collection "
460                     + collection.getID());
461             request.setAttribute("policy", policy);
462             request.setAttribute("groups", groups);
463             request.setAttribute("epeople", epeople);
464             request.setAttribute("id_name", "collection_id");
465             request.setAttribute("id", "" + collection.getID());
466             request.setAttribute("newpolicy", "true");
467
468             JSPManager.showJSP(request, response,
469                     "/dspace-admin/authorize-policy-edit.jsp");
470         }
471         else if (button.equals("submit_community_add_policy"))
472         {
473             // want to add a policy, create an empty one and invoke editor
474
Community community = Community.find(c, UIUtil.getIntParameter(
475                     request, "community_id"));
476
477             ResourcePolicy policy = ResourcePolicy.create(c);
478             policy.setResource(community);
479             policy.update();
480
481             Group[] groups = Group.findAll(c, Group.NAME);
482             EPerson[] epeople = EPerson.findAll(c, EPerson.EMAIL);
483
484             // return to collection permission page
485
request
486                     .setAttribute("edit_title", "Community "
487                             + community.getID());
488             request.setAttribute("policy", policy);
489             request.setAttribute("groups", groups);
490             request.setAttribute("epeople", epeople);
491             request.setAttribute("id_name", "community_id");
492             request.setAttribute("id", "" + community.getID());
493             request.setAttribute("newpolicy", "true");
494
495             JSPManager.showJSP(request, response,
496                     "/dspace-admin/authorize-policy-edit.jsp");
497         }
498         else if (button.equals("submit_save_policy"))
499         {
500             int policy_id = UIUtil.getIntParameter(request, "policy_id");
501             int action_id = UIUtil.getIntParameter(request, "action_id");
502             int group_id = UIUtil.getIntParameter(request, "group_id");
503             int collection_id = UIUtil
504                     .getIntParameter(request, "collection_id");
505             int community_id = UIUtil.getIntParameter(request, "community_id");
506             int item_id = UIUtil.getIntParameter(request, "item_id");
507
508             Item item = null;
509             Collection collection = null;
510             Community community = null;
511             String JavaDoc display_page = null;
512
513             ResourcePolicy policy = ResourcePolicy.find(c, policy_id);
514             Group group = Group.find(c, group_id);
515
516             if (collection_id != -1)
517             {
518                 collection = Collection.find(c, collection_id);
519
520                 // modify the policy
521
policy.setAction(action_id);
522                 policy.setGroup(group);
523                 policy.update();
524
525                 // if it is a read, policy, modify the logo policy to match
526
if (action_id == Constants.READ)
527                 {
528                     // first get a list of READ policies from collection
529
List JavaDoc rps = AuthorizeManager.getPoliciesActionFilter(c,
530                             collection, Constants.READ);
531
532                     // remove all bitstream policies, then add READs
533
Bitstream bs = collection.getLogo();
534
535                     if (bs != null)
536                     {
537                         AuthorizeManager.removeAllPolicies(c, bs);
538                         AuthorizeManager.addPolicies(c, rps, bs);
539                     }
540                 }
541
542                 // set up page attributes
543
request.setAttribute("collection", collection);
544                 request.setAttribute("policies", AuthorizeManager.getPolicies(
545                         c, collection));
546                 display_page = "/dspace-admin/authorize-collection-edit.jsp";
547             }
548             else if (community_id != -1)
549             {
550                 community = Community.find(c, community_id);
551
552                 // modify the policy
553
policy.setAction(action_id);
554                 policy.setGroup(group);
555                 policy.update();
556
557                 // if it is a read, policy, modify the logo policy to match
558
if (action_id == Constants.READ)
559                 {
560                     // first get a list of READ policies from collection
561
List JavaDoc rps = AuthorizeManager.getPoliciesActionFilter(c,
562                             community, Constants.READ);
563
564                     // remove all bitstream policies, then add READs
565
Bitstream bs = community.getLogo();
566
567                     if (bs != null)
568                     {
569                         AuthorizeManager.removeAllPolicies(c, bs);
570                         AuthorizeManager.addPolicies(c, rps, bs);
571                     }
572                 }
573
574                 // set up page attributes
575
request.setAttribute("community", community);
576                 request.setAttribute("policies", AuthorizeManager.getPolicies(
577                         c, community));
578                 display_page = "/dspace-admin/authorize-community-edit.jsp";
579             }
580             else if (item_id != -1)
581             {
582                 item = Item.find(c, item_id);
583
584                 // modify the policy
585
policy.setAction(action_id);
586                 policy.setGroup(group);
587                 policy.update();
588
589                 // show edit form!
590
prepItemEditForm(c, request, item);
591
592                 display_page = "/dspace-admin/authorize-item-edit.jsp";
593             }
594
595             // now return to previous state
596
JSPManager.showJSP(request, response, display_page);
597         }
598         else if (button.equals("submit_cancel_policy"))
599         {
600             // delete the policy that we created if it's a new one
601
if ((request.getParameter("newpolicy") != null))
602             {
603                 int policy_id = UIUtil.getIntParameter(request, "policy_id");
604                 ResourcePolicy rp = ResourcePolicy.find(c, policy_id);
605                 rp.delete();
606             }
607
608             // return to the previous page
609
int collection_id = UIUtil
610                     .getIntParameter(request, "collection_id");
611             int community_id = UIUtil.getIntParameter(request, "community_id");
612             int item_id = UIUtil.getIntParameter(request, "item_id");
613             String JavaDoc display_page = null;
614
615             if (collection_id != -1)
616             {
617                 // set up for return to collection edit page
618
Collection t = Collection.find(c, collection_id);
619
620                 request.setAttribute("collection", t);
621                 request.setAttribute("policies", AuthorizeManager.getPolicies(
622                         c, t));
623                 display_page = "/dspace-admin/authorize-collection-edit.jsp";
624             }
625             else if (community_id != -1)
626             {
627                 // set up for return to community edit page
628
Community t = Community.find(c, community_id);
629
630                 request.setAttribute("community", t);
631                 request.setAttribute("policies", AuthorizeManager.getPolicies(
632                         c, t));
633                 display_page = "/dspace-admin/authorize-community-edit.jsp";
634             }
635             else if (item_id != -1)
636             {
637                 // set up for return to item edit page
638
Item t = Item.find(c, item_id);
639
640                 // show edit form!
641
prepItemEditForm(c, request, t);
642
643                 display_page = "/dspace-admin/authorize-item-edit.jsp";
644             }
645
646             JSPManager.showJSP(request, response, display_page);
647         }
648         else if (button.equals("submit_advanced_clear"))
649         {
650             // remove all policies for a set of objects
651
int collection_id = UIUtil
652                     .getIntParameter(request, "collection_id");
653             int resource_type = UIUtil
654                     .getIntParameter(request, "resource_type");
655
656             // if it's to bitstreams, do it to bundles too
657
PolicySet.setPolicies(c, Constants.COLLECTION, collection_id,
658                     resource_type, 0, 0, false, true);
659
660             if (resource_type == Constants.BITSTREAM)
661             {
662                 PolicySet.setPolicies(c, Constants.COLLECTION, collection_id,
663                         Constants.BUNDLE, 0, 0, false, true);
664             }
665
666             // return to the main page
667
showMainPage(c, request, response);
668         }
669         else if (button.equals("submit_advanced_add"))
670         {
671             // add a policy to a set of objects
672
int collection_id = UIUtil
673                     .getIntParameter(request, "collection_id");
674             int resource_type = UIUtil
675                     .getIntParameter(request, "resource_type");
676             int action_id = UIUtil.getIntParameter(request, "action_id");
677             int group_id = UIUtil.getIntParameter(request, "group_id");
678
679             PolicySet.setPolicies(c, Constants.COLLECTION, collection_id,
680                     resource_type, action_id, group_id, false, false);
681
682             // if it's a bitstream, do it to the bundle too
683
if (resource_type == Constants.BITSTREAM)
684             {
685                 PolicySet.setPolicies(c, Constants.COLLECTION, collection_id,
686                         Constants.BUNDLE, action_id, group_id, false, false);
687             }
688
689             // return to the main page
690
showMainPage(c, request, response);
691         }
692         else if (button.equals("submit_collection_select"))
693         {
694             // edit the collection's permissions
695
Collection collection = Collection.find(c, UIUtil.getIntParameter(
696                     request, "collection_id"));
697             List JavaDoc policies = AuthorizeManager.getPolicies(c, collection);
698
699             request.setAttribute("collection", collection);
700             request.setAttribute("policies", policies);
701             JSPManager.showJSP(request, response,
702                     "/dspace-admin/authorize-collection-edit.jsp");
703         }
704         else
705         {
706             // return to the main page
707
showMainPage(c, request, response);
708         }
709
710         c.complete();
711     }
712
713     void showMainPage(Context c, HttpServletRequest JavaDoc request,
714             HttpServletResponse JavaDoc response) throws ServletException JavaDoc, IOException JavaDoc,
715             SQLException JavaDoc, AuthorizeException
716     {
717         JSPManager.showJSP(request, response,
718                 "/dspace-admin/authorize-main.jsp");
719     }
720
721     void prepItemEditForm(Context c, HttpServletRequest JavaDoc request, Item item)
722             throws SQLException JavaDoc
723     {
724         List JavaDoc item_policies = AuthorizeManager.getPolicies(c, item);
725
726         // Put bundle and bitstream policies in their own hashes
727
Map JavaDoc bundle_policies = new HashMap JavaDoc();
728         Map JavaDoc bitstream_policies = new HashMap JavaDoc();
729
730         Bundle[] bundles = item.getBundles();
731
732         for (int i = 0; i < bundles.length; i++)
733         {
734             Bundle myBundle = bundles[i];
735             List JavaDoc myPolicies = AuthorizeManager.getPolicies(c, myBundle);
736
737             // add bundle's policies to bundle_policies map
738
bundle_policies.put(new Integer JavaDoc(myBundle.getID()), myPolicies);
739
740             // go through all bundle's bitstreams, add to bitstream map
741
Bitstream[] bitstreams = myBundle.getBitstreams();
742
743             for (int j = 0; j < bitstreams.length; j++)
744             {
745                 Bitstream myBitstream = bitstreams[j];
746                 myPolicies = AuthorizeManager.getPolicies(c, myBitstream);
747                 bitstream_policies.put(new Integer JavaDoc(myBitstream.getID()),
748                         myPolicies);
749             }
750         }
751
752         request.setAttribute("item", item);
753         request.setAttribute("item_policies", item_policies);
754         request.setAttribute("bundles", bundles);
755         request.setAttribute("bundle_policies", bundle_policies);
756         request.setAttribute("bitstream_policies", bitstream_policies);
757     }
758 }
759
Popular Tags