| 1 |
|
|
| 2 |
|
|
| 3 |
|
|
| 4 |
|
|
| 5 |
|
|
| 6 |
|
|
| 7 |
|
|
| 8 |
|
package com.atlassian.core.user; |
| 9 |
|
|
| 10 |
|
import com.opensymphony.user.*; |
| 11 |
|
import org.apache.log4j.Category; |
| 12 |
|
|
| 13 |
|
import java.util.*; |
| 14 |
|
|
| 15 |
|
|
| 16 |
|
|
| 17 |
|
|
| 18 |
|
|
| 19 |
|
@see |
| 20 |
|
|
|
|
|
| 74% |
Uncovered Elements: 19 (73) |
Complexity: 23 |
Complexity Density: 0.5 |
|
| 21 |
|
public class GroupUtils |
| 22 |
|
{ |
| 23 |
|
private static final Category log = Category.getInstance(GroupUtils.class); |
| 24 |
|
|
| 25 |
|
final static Comparator alphaGroupComparator = new Comparator() |
| 26 |
|
{ |
|
|
|
| 38.5% |
Uncovered Elements: 8 (13) |
Complexity: 4 |
Complexity Density: 0.57 |
|
| 27 |
17
|
public int compare(Object a, Object b)... |
| 28 |
|
{ |
| 29 |
17
|
if (a == null) |
| 30 |
|
{ |
| 31 |
0
|
if (b == null) |
| 32 |
|
{ |
| 33 |
0
|
return 0; |
| 34 |
|
} |
| 35 |
|
else |
| 36 |
|
{ |
| 37 |
0
|
return -1; |
| 38 |
|
} |
| 39 |
|
} |
| 40 |
|
else |
| 41 |
|
{ |
| 42 |
17
|
if (b == null) |
| 43 |
|
{ |
| 44 |
0
|
return 1; |
| 45 |
|
} |
| 46 |
|
else |
| 47 |
|
{ |
| 48 |
17
|
return alphaStringComparator.compare(((Group) a).getName(), ((Group) b).getName()); |
| 49 |
|
} |
| 50 |
|
} |
| 51 |
|
} |
| 52 |
|
}; |
| 53 |
|
|
| 54 |
|
final static Comparator alphaStringComparator = new Comparator() |
| 55 |
|
{ |
|
|
|
| 46.7% |
Uncovered Elements: 8 (15) |
Complexity: 4 |
Complexity Density: 0.44 |
|
| 56 |
25
|
public int compare(Object o1, Object o2)... |
| 57 |
|
{ |
| 58 |
25
|
String a = (String) o1; |
| 59 |
25
|
String b = (String) o2; |
| 60 |
|
|
| 61 |
25
|
if (a == null) |
| 62 |
|
{ |
| 63 |
0
|
if (b == null) |
| 64 |
|
{ |
| 65 |
0
|
return 0; |
| 66 |
|
} |
| 67 |
|
else |
| 68 |
|
{ |
| 69 |
0
|
return -1; |
| 70 |
|
} |
| 71 |
|
} |
| 72 |
|
else |
| 73 |
|
{ |
| 74 |
25
|
if (b == null) |
| 75 |
|
{ |
| 76 |
0
|
return 1; |
| 77 |
|
} |
| 78 |
|
else |
| 79 |
|
{ |
| 80 |
25
|
return a.compareToIgnoreCase(b); |
| 81 |
|
} |
| 82 |
|
} |
| 83 |
|
} |
| 84 |
|
}; |
| 85 |
|
|
| 86 |
|
|
| 87 |
|
|
| 88 |
|
|
| 89 |
|
|
|
|
|
| 85.7% |
Uncovered Elements: 1 (7) |
Complexity: 3 |
Complexity Density: 0.43 |
|
| 90 |
1
|
public static Group getGroupSafely(String name) throws ImmutableException... |
| 91 |
|
{ |
| 92 |
1
|
Group group = null; |
| 93 |
|
|
| 94 |
1
|
try |
| 95 |
|
{ |
| 96 |
1
|
group = UserManager.getInstance().getGroup(name); |
| 97 |
|
} |
| 98 |
|
catch (EntityNotFoundException e) |
| 99 |
|
{ |
| 100 |
1
|
try |
| 101 |
|
{ |
| 102 |
1
|
group = UserManager.getInstance().createGroup(name); |
| 103 |
|
} |
| 104 |
|
catch (DuplicateEntityException e1) |
| 105 |
|
{ |
| 106 |
0
|
e.printStackTrace(System.err); |
| 107 |
|
} |
| 108 |
|
} |
| 109 |
|
|
| 110 |
1
|
return group; |
| 111 |
|
} |
| 112 |
|
|
| 113 |
|
|
| 114 |
|
|
| 115 |
|
@return |
| 116 |
|
|
|
|
|
| 83.3% |
Uncovered Elements: 2 (12) |
Complexity: 4 |
Complexity Density: 0.5 |
|
| 117 |
6
|
public static Group getGroup(String name)... |
| 118 |
|
{ |
| 119 |
6
|
if (name == null) |
| 120 |
|
{ |
| 121 |
1
|
return null; |
| 122 |
|
} |
| 123 |
|
else |
| 124 |
|
{ |
| 125 |
5
|
if (GroupUtils.existsGroup(name)) |
| 126 |
|
{ |
| 127 |
4
|
try |
| 128 |
|
{ |
| 129 |
4
|
return UserManager.getInstance().getGroup(name); |
| 130 |
|
} |
| 131 |
|
catch (EntityNotFoundException e) |
| 132 |
|
{ |
| 133 |
0
|
log.error("Error getting group: " + name, e); |
| 134 |
0
|
return null; |
| 135 |
|
} |
| 136 |
|
} |
| 137 |
|
else |
| 138 |
|
{ |
| 139 |
1
|
return null; |
| 140 |
|
} |
| 141 |
|
} |
| 142 |
|
} |
| 143 |
|
|
| 144 |
|
|
| 145 |
|
|
| 146 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (4) |
Complexity: 2 |
Complexity Density: 0.5 |
|
| 147 |
9
|
public static boolean existsGroup(String name)... |
| 148 |
|
{ |
| 149 |
9
|
try |
| 150 |
|
{ |
| 151 |
9
|
UserManager.getInstance().getGroup(name); |
| 152 |
|
} |
| 153 |
|
catch (EntityNotFoundException e) |
| 154 |
|
{ |
| 155 |
3
|
return false; |
| 156 |
|
} |
| 157 |
|
|
| 158 |
6
|
return true; |
| 159 |
|
} |
| 160 |
|
|
| 161 |
|
|
| 162 |
|
@return |
| 163 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
|
| 164 |
4
|
public static Collection getGroups()... |
| 165 |
|
{ |
| 166 |
4
|
List groups = UserManager.getInstance().getGroups(); |
| 167 |
4
|
sortGroups(groups); |
| 168 |
4
|
return groups; |
| 169 |
|
} |
| 170 |
|
|
| 171 |
|
|
| 172 |
|
|
| 173 |
|
|
| 174 |
|
@param |
| 175 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 176 |
5
|
public static void sortGroups(List groups)... |
| 177 |
|
{ |
| 178 |
5
|
Collections.sort(groups, alphaGroupComparator); |
| 179 |
|
} |
| 180 |
|
|
| 181 |
|
|
| 182 |
|
|
| 183 |
|
|
| 184 |
|
@param |
| 185 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 186 |
1
|
public static void sortGroupNames(List groups)... |
| 187 |
|
{ |
| 188 |
1
|
Collections.sort(groups, alphaStringComparator); |
| 189 |
|
} |
| 190 |
|
|
| 191 |
|
|
| 192 |
|
|
| 193 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (8) |
Complexity: 3 |
Complexity Density: 0.5 |
|
| 194 |
1
|
public static void removeGroup(Group group) throws Exception... |
| 195 |
|
{ |
| 196 |
1
|
Collection users = new HashSet(group.getUsers()); |
| 197 |
|
|
| 198 |
2
|
for (Iterator iterator = users.iterator(); iterator.hasNext();) |
| 199 |
|
{ |
| 200 |
1
|
try |
| 201 |
|
{ |
| 202 |
1
|
User u = UserUtils.getUser((String) iterator.next()); |
| 203 |
1
|
u.removeFromGroup(group); |
| 204 |
|
} |
| 205 |
|
catch (EntityNotFoundException e) |
| 206 |
|
{ |
| 207 |
|
|
| 208 |
|
} |
| 209 |
|
} |
| 210 |
|
|
| 211 |
1
|
group.remove(); |
| 212 |
|
} |
| 213 |
|
|
| 214 |
|
} |