| 1 |
|
|
| 2 |
|
|
| 3 |
|
|
| 4 |
|
|
| 5 |
|
|
| 6 |
|
|
| 7 |
|
|
| 8 |
|
|
| 9 |
|
|
| 10 |
|
package com.atlassian.core.user.preferences; |
| 11 |
|
|
| 12 |
|
import com.atlassian.core.AtlassianCoreException; |
| 13 |
|
import com.atlassian.core.util.PropertyUtils; |
| 14 |
|
import com.opensymphony.module.propertyset.PropertySet; |
| 15 |
|
import com.opensymphony.module.propertyset.PropertySetManager; |
| 16 |
|
import com.opensymphony.user.User; |
| 17 |
|
|
| 18 |
|
import java.io.Serializable; |
| 19 |
|
import java.util.HashMap; |
| 20 |
|
import java.util.Map; |
| 21 |
|
import java.util.Set; |
| 22 |
|
import java.util.HashSet; |
| 23 |
|
|
|
|
|
| 39.8% |
Uncovered Elements: 68 (113) |
Complexity: 33 |
Complexity Density: 0.52 |
|
| 24 |
|
public class UserPreferences implements Preferences, Serializable |
| 25 |
|
{ |
| 26 |
|
private PropertySet backingPS = null; |
| 27 |
|
|
| 28 |
|
|
| 29 |
|
private Set defaultKeys = null; |
| 30 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 31 |
1
|
public UserPreferences()... |
| 32 |
|
{ |
| 33 |
1
|
this((PropertySet) null, true); |
| 34 |
|
} |
| 35 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 36 |
7
|
public UserPreferences(User pUser)... |
| 37 |
|
{ |
| 38 |
7
|
this(pUser, true); |
| 39 |
|
} |
| 40 |
|
|
|
|
|
| 0% |
Uncovered Elements: 2 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
| 41 |
0
|
public UserPreferences(PropertySet propertySet)... |
| 42 |
|
{ |
| 43 |
0
|
backingPS = propertySet; |
| 44 |
0
|
defaultKeys = new HashSet(); |
| 45 |
|
} |
| 46 |
|
|
|
|
|
| 33.3% |
Uncovered Elements: 6 (9) |
Complexity: 2 |
Complexity Density: 0.29 |
|
| 47 |
1
|
public UserPreferences(PropertySet propertySet, boolean bulkload)... |
| 48 |
|
{ |
| 49 |
|
|
| 50 |
|
|
| 51 |
|
|
| 52 |
1
|
defaultKeys = new HashSet(); |
| 53 |
|
|
| 54 |
1
|
if (propertySet != null) |
| 55 |
|
{ |
| 56 |
0
|
PropertySet userPs = propertySet; |
| 57 |
|
|
| 58 |
0
|
Map params = new HashMap(2); |
| 59 |
0
|
params.put("PropertySet", userPs); |
| 60 |
0
|
params.put("bulkload", new Boolean(bulkload)); |
| 61 |
|
|
| 62 |
0
|
backingPS = PropertySetManager.getInstance("cached", params); |
| 63 |
|
} |
| 64 |
|
} |
| 65 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (9) |
Complexity: 2 |
Complexity Density: 0.29 |
|
| 66 |
7
|
public UserPreferences(User pUser, boolean bulkload)... |
| 67 |
|
{ |
| 68 |
|
|
| 69 |
|
|
| 70 |
|
|
| 71 |
7
|
defaultKeys = new HashSet(); |
| 72 |
|
|
| 73 |
7
|
if (pUser != null) |
| 74 |
|
{ |
| 75 |
5
|
PropertySet userPs = pUser.getPropertySet(); |
| 76 |
|
|
| 77 |
5
|
Map params = new HashMap(2); |
| 78 |
5
|
params.put("PropertySet", userPs); |
| 79 |
5
|
params.put("bulkload", new Boolean(bulkload)); |
| 80 |
|
|
| 81 |
5
|
backingPS = PropertySetManager.getInstance("cached", params); |
| 82 |
|
} |
| 83 |
|
} |
| 84 |
|
|
|
|
|
| 80% |
Uncovered Elements: 2 (10) |
Complexity: 4 |
Complexity Density: 0.67 |
|
| 85 |
4
|
public long getLong(String key)... |
| 86 |
|
{ |
| 87 |
|
|
| 88 |
4
|
if (defaultKeys.contains(key)) |
| 89 |
|
{ |
| 90 |
|
|
| 91 |
0
|
return DefaultPreferences.getPreferences().getLong(key); |
| 92 |
|
} |
| 93 |
|
else |
| 94 |
|
{ |
| 95 |
4
|
if (backingPS != null && backingPS.exists(key)) |
| 96 |
|
{ |
| 97 |
2
|
return backingPS.getLong(key); |
| 98 |
|
} |
| 99 |
|
else |
| 100 |
|
{ |
| 101 |
|
|
| 102 |
|
|
| 103 |
2
|
defaultKeys.add(key); |
| 104 |
|
|
| 105 |
2
|
return DefaultPreferences.getPreferences().getLong(key); |
| 106 |
|
} |
| 107 |
|
} |
| 108 |
|
} |
| 109 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (6) |
Complexity: 2 |
Complexity Density: 0.5 |
|
| 110 |
2
|
public void setLong(String key, long i) throws AtlassianCoreException... |
| 111 |
|
{ |
| 112 |
2
|
if (backingPS == null) |
| 113 |
|
{ |
| 114 |
1
|
throw new AtlassianCoreException("Trying to set a property on a null user this is not allowed"); |
| 115 |
|
} |
| 116 |
|
else |
| 117 |
|
{ |
| 118 |
|
|
| 119 |
1
|
defaultKeys.remove(key); |
| 120 |
1
|
backingPS.setLong(key, i); |
| 121 |
|
} |
| 122 |
|
} |
| 123 |
|
|
|
|
|
| 0% |
Uncovered Elements: 10 (10) |
Complexity: 4 |
Complexity Density: 0.67 |
|
| 124 |
0
|
public String getString(String key)... |
| 125 |
|
{ |
| 126 |
|
|
| 127 |
0
|
if (defaultKeys.contains(key)) |
| 128 |
|
{ |
| 129 |
|
|
| 130 |
0
|
return DefaultPreferences.getPreferences().getString(key); |
| 131 |
|
} |
| 132 |
|
else |
| 133 |
|
{ |
| 134 |
0
|
if (backingPS != null && backingPS.exists(key)) |
| 135 |
|
{ |
| 136 |
0
|
return backingPS.getString(key); |
| 137 |
|
} |
| 138 |
|
else |
| 139 |
|
{ |
| 140 |
|
|
| 141 |
0
|
defaultKeys.add(key); |
| 142 |
0
|
return DefaultPreferences.getPreferences().getString(key); |
| 143 |
|
} |
| 144 |
|
} |
| 145 |
|
} |
| 146 |
|
|
|
|
|
| 0% |
Uncovered Elements: 6 (6) |
Complexity: 2 |
Complexity Density: 0.5 |
|
| 147 |
0
|
public void setString(String key, String value) throws AtlassianCoreException... |
| 148 |
|
{ |
| 149 |
0
|
if (backingPS == null) |
| 150 |
|
{ |
| 151 |
0
|
throw new AtlassianCoreException("Trying to set a property on a null user this is not allowed"); |
| 152 |
|
} |
| 153 |
|
else |
| 154 |
|
{ |
| 155 |
|
|
| 156 |
0
|
defaultKeys.remove(key); |
| 157 |
0
|
backingPS.setString(key, value); |
| 158 |
|
} |
| 159 |
|
} |
| 160 |
|
|
|
|
|
| 0% |
Uncovered Elements: 10 (10) |
Complexity: 4 |
Complexity Density: 0.67 |
|
| 161 |
0
|
public boolean getBoolean(String key)... |
| 162 |
|
{ |
| 163 |
|
|
| 164 |
0
|
if (defaultKeys.contains(key)) |
| 165 |
|
{ |
| 166 |
|
|
| 167 |
0
|
return DefaultPreferences.getPreferences().getBoolean(key); |
| 168 |
|
} |
| 169 |
|
else |
| 170 |
|
{ |
| 171 |
0
|
if (backingPS != null && backingPS.exists(key)) |
| 172 |
|
{ |
| 173 |
0
|
return backingPS.getBoolean(key); |
| 174 |
|
} |
| 175 |
|
else |
| 176 |
|
{ |
| 177 |
|
|
| 178 |
0
|
defaultKeys.add(key); |
| 179 |
0
|
return DefaultPreferences.getPreferences().getBoolean(key); |
| 180 |
|
} |
| 181 |
|
} |
| 182 |
|
} |
| 183 |
|
|
|
|
|
| 0% |
Uncovered Elements: 6 (6) |
Complexity: 2 |
Complexity Density: 0.5 |
|
| 184 |
0
|
public void setBoolean(String key, boolean b) throws AtlassianCoreException... |
| 185 |
|
{ |
| 186 |
0
|
if (backingPS == null) |
| 187 |
|
{ |
| 188 |
0
|
throw new AtlassianCoreException("Trying to set a property on a null user this is not allowed"); |
| 189 |
|
} |
| 190 |
|
else |
| 191 |
|
{ |
| 192 |
|
|
| 193 |
0
|
defaultKeys.remove(key); |
| 194 |
0
|
backingPS.setBoolean(key, b); |
| 195 |
|
} |
| 196 |
|
} |
| 197 |
|
|
|
|
|
| 0% |
Uncovered Elements: 10 (10) |
Complexity: 3 |
Complexity Density: 0.5 |
|
| 198 |
0
|
public void remove(String key) throws AtlassianCoreException... |
| 199 |
|
{ |
| 200 |
0
|
if (backingPS == null) |
| 201 |
|
{ |
| 202 |
0
|
throw new AtlassianCoreException("Trying to remove a property on a null user this is not allowed"); |
| 203 |
|
} |
| 204 |
|
else |
| 205 |
|
{ |
| 206 |
0
|
if (backingPS.exists(key)) |
| 207 |
|
{ |
| 208 |
|
|
| 209 |
0
|
defaultKeys.remove(key); |
| 210 |
0
|
backingPS.remove(key); |
| 211 |
|
} |
| 212 |
|
else |
| 213 |
|
{ |
| 214 |
0
|
throw new AtlassianCoreException("The property with key '" + key + "' does not exist."); |
| 215 |
|
} |
| 216 |
|
} |
| 217 |
|
} |
| 218 |
|
|
|
|
|
| 43.8% |
Uncovered Elements: 9 (16) |
Complexity: 4 |
Complexity Density: 0.5 |
|
| 219 |
3
|
public boolean equals(Object o)... |
| 220 |
|
{ |
| 221 |
|
|
| 222 |
3
|
if (this == o) return true; |
| 223 |
1
|
if (!(o instanceof UserPreferences)) return false; |
| 224 |
|
|
| 225 |
0
|
final UserPreferences userPreferences = (UserPreferences) o; |
| 226 |
|
|
| 227 |
0
|
if (backingPS != null ? !PropertyUtils.identical(backingPS, userPreferences.backingPS) : userPreferences.backingPS != null) return false; |
| 228 |
|
|
| 229 |
0
|
return true; |
| 230 |
|
} |
| 231 |
|
|
|
|
|
| 66.7% |
Uncovered Elements: 1 (3) |
Complexity: 1 |
Complexity Density: 1 |
|
| 232 |
2
|
public int hashCode()... |
| 233 |
|
{ |
| 234 |
|
|
| 235 |
2
|
return (backingPS != null ? backingPS.hashCode() : 0); |
| 236 |
|
} |
| 237 |
|
} |