1 /**
2 * Copyright 2014 Internet2
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16 /*
17 * Copyright (C) 2006-2007 blair christensen.
18 * All Rights Reserved.
19 *
20 * You may use and distribute under the same terms as Grouper itself.
21 */
22
23 package edu.internet2.middleware.grouper.app.gsh;
24 import bsh.CallStack;
25 import bsh.Interpreter;
26 import edu.internet2.middleware.grouper.Group;
27 import edu.internet2.middleware.grouper.GroupFinder;
28 import edu.internet2.middleware.grouper.GroupType;
29 import edu.internet2.middleware.grouper.GroupTypeFinder;
30 import edu.internet2.middleware.grouper.GrouperSession;
31 import edu.internet2.middleware.grouper.exception.GroupModifyException;
32 import edu.internet2.middleware.grouper.exception.GroupNotFoundException;
33 import edu.internet2.middleware.grouper.exception.InsufficientPrivilegeException;
34 import edu.internet2.middleware.grouper.exception.SchemaException;
35
36 /**
37 * Add a {@link GroupType} to a {@link Group}.
38 * <p/>
39 * @author blair christensen.
40 * @version $Id: groupAddType.java,v 1.3 2009-03-15 06:37:23 mchyzer Exp $
41 * @since 0.1.0
42 */
43 public class groupAddType {
44
45 // PUBLIC CLASS METHODS //
46
47 /**
48 * Add a {@link GroupType} to a {@link Group}.
49 * <p/>
50 * @param i BeanShell interpreter.
51 * @param stack BeanShell call stack.
52 * @param name Name of {@link Group}.
53 * @param type Name of {@link GroupType}.
54 * @return True if {@link GroupType} added to {@link Group}.
55 * @throws GrouperShellException
56 * @since 0.1.0
57 */
58 public static boolean invoke(
59 Interpreter i, CallStack stack, String name, String type
60 )
61 throws GrouperShellException
62 {
63 GrouperShell.setOurCommand(i, true);
64 try {
65 return invoke(GrouperShell.getSession(i), name, type);
66 }
67 catch (GroupModifyException eGM) {
68 GrouperShell.error(i, eGM);
69 }
70 catch (GroupNotFoundException eGNF) {
71 GrouperShell.error(i, eGNF);
72 }
73 catch (InsufficientPrivilegeException eIP) {
74 GrouperShell.error(i, eIP);
75 }
76 catch (SchemaException eS) {
77 GrouperShell.error(i, eS);
78 }
79 return false;
80 }
81
82 /**
83 * Add a {@link GroupType} to a {@link Group}.
84 * <p/>
85 * @param grouperSession
86 * @param name Name of {@link Group}.
87 * @param type Name of {@link GroupType}.
88 * @return True if {@link GroupType} added to {@link Group}.
89 */
90 @SuppressWarnings("deprecation")
91 public static boolean invoke(GrouperSession grouperSession, String name, String type) {
92 Group g = GroupFinder.findByName(grouperSession, name, true);
93 GroupType t = GroupTypeFinder.find(type, true);
94 g.addType(t);
95 return true;
96 }
97
98 } // public class groupAddType
99