| 1 |
|
|
| 2 |
|
|
| 3 |
|
|
| 4 |
|
|
| 5 |
|
|
| 6 |
|
|
| 7 |
|
|
| 8 |
|
|
| 9 |
|
|
| 10 |
|
|
| 11 |
|
|
| 12 |
|
|
| 13 |
|
|
| 14 |
|
|
| 15 |
|
|
| 16 |
|
package org.kuali.rice.ken.web.spring; |
| 17 |
|
|
| 18 |
|
import org.apache.commons.lang.StringUtils; |
| 19 |
|
import org.apache.log4j.Logger; |
| 20 |
|
import org.kuali.rice.core.api.namespace.Namespace; |
| 21 |
|
import org.kuali.rice.core.api.namespace.NamespaceService; |
| 22 |
|
import org.kuali.rice.ken.exception.ErrorList; |
| 23 |
|
import org.kuali.rice.kim.bo.Group; |
| 24 |
|
import org.kuali.rice.kim.bo.entity.KimPrincipal; |
| 25 |
|
import org.kuali.rice.kim.service.IdentityManagementService; |
| 26 |
|
import org.kuali.rice.kim.service.KIMServiceLocator; |
| 27 |
|
import org.kuali.rice.kns.service.KNSServiceLocatorInternal; |
| 28 |
|
import org.springframework.web.servlet.mvc.multiaction.MultiActionController; |
| 29 |
|
|
| 30 |
|
import javax.servlet.http.HttpServletRequest; |
| 31 |
|
import java.util.ArrayList; |
| 32 |
|
import java.util.List; |
| 33 |
|
|
| 34 |
|
|
| 35 |
|
|
| 36 |
|
|
| 37 |
|
@author |
| 38 |
|
|
| 39 |
|
|
|
|
|
| 0% |
Uncovered Elements: 55 (55) |
Complexity: 15 |
Complexity Density: 0.45 |
|
| 40 |
|
public class BaseSendNotificationController extends MultiActionController { |
| 41 |
|
private static final Logger LOG = Logger.getLogger(BaseSendNotificationController.class); |
| 42 |
|
|
| 43 |
|
private static final String USER_RECIPS_PARAM = "userRecipients"; |
| 44 |
|
private static final String WORKGROUP_RECIPS_PARAM = "workgroupRecipients"; |
| 45 |
|
private static final String WORKGROUP_NAMESPACE_CODES_PARAM = "workgroupNamespaceCodes"; |
| 46 |
|
private static final String SPLIT_REGEX = "(%2C|,)"; |
| 47 |
|
|
| 48 |
|
private static IdentityManagementService identityManagementService; |
| 49 |
|
private static NamespaceService namespaceService; |
| 50 |
|
|
|
|
|
| 0% |
Uncovered Elements: 5 (5) |
Complexity: 2 |
Complexity Density: 0.67 |
|
| 51 |
0
|
protected static IdentityManagementService getIdentityManagementService() {... |
| 52 |
0
|
if ( identityManagementService == null ) { |
| 53 |
0
|
identityManagementService = KIMServiceLocator.getIdentityManagementService(); |
| 54 |
|
} |
| 55 |
0
|
return identityManagementService; |
| 56 |
|
} |
| 57 |
|
|
|
|
|
| 0% |
Uncovered Elements: 5 (5) |
Complexity: 2 |
Complexity Density: 0.67 |
|
| 58 |
0
|
protected static NamespaceService getNamespaceService() {... |
| 59 |
0
|
if ( namespaceService == null ) { |
| 60 |
0
|
namespaceService = KNSServiceLocatorInternal.getNamespaceService(); |
| 61 |
|
} |
| 62 |
0
|
return namespaceService; |
| 63 |
|
} |
| 64 |
|
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 65 |
0
|
protected String[] parseUserRecipients(HttpServletRequest request) {... |
| 66 |
0
|
return parseCommaSeparatedValues(request, USER_RECIPS_PARAM); |
| 67 |
|
} |
| 68 |
|
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 69 |
0
|
protected String[] parseWorkgroupRecipients(HttpServletRequest request) {... |
| 70 |
0
|
return parseCommaSeparatedValues(request, WORKGROUP_RECIPS_PARAM); |
| 71 |
|
} |
| 72 |
|
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 73 |
0
|
protected String[] parseWorkgroupNamespaceCodes(HttpServletRequest request) {... |
| 74 |
0
|
return parseCommaSeparatedValues(request, WORKGROUP_NAMESPACE_CODES_PARAM); |
| 75 |
|
} |
| 76 |
|
|
|
|
|
| 0% |
Uncovered Elements: 13 (13) |
Complexity: 3 |
Complexity Density: 0.33 |
|
| 77 |
0
|
protected String[] parseCommaSeparatedValues(HttpServletRequest request, String param) {... |
| 78 |
0
|
String vals = request.getParameter(param); |
| 79 |
0
|
if (vals != null) { |
| 80 |
0
|
String[] split = vals.split(SPLIT_REGEX); |
| 81 |
0
|
List<String> strs = new ArrayList<String>(); |
| 82 |
0
|
for (String component: split) { |
| 83 |
0
|
if (StringUtils.isNotBlank(component)) { |
| 84 |
0
|
strs.add(component.trim()); |
| 85 |
|
} |
| 86 |
|
} |
| 87 |
0
|
return strs.toArray(new String[strs.size()]); |
| 88 |
|
} else { |
| 89 |
0
|
return new String[0]; |
| 90 |
|
} |
| 91 |
|
} |
| 92 |
|
|
|
|
|
| 0% |
Uncovered Elements: 8 (8) |
Complexity: 2 |
Complexity Density: 0.33 |
|
| 93 |
0
|
protected boolean isUserRecipientValid(String user, ErrorList errors) {... |
| 94 |
0
|
boolean valid = true; |
| 95 |
0
|
KimPrincipal principal = getIdentityManagementService().getPrincipalByPrincipalName(user); |
| 96 |
0
|
if (principal == null) { |
| 97 |
0
|
valid = false; |
| 98 |
0
|
errors.addError("'" + user + "' is not a valid principal name"); |
| 99 |
|
} |
| 100 |
|
|
| 101 |
0
|
return valid; |
| 102 |
|
} |
| 103 |
|
|
|
|
|
| 0% |
Uncovered Elements: 13 (13) |
Complexity: 3 |
Complexity Density: 0.33 |
|
| 104 |
0
|
protected boolean isWorkgroupRecipientValid(String groupName, String namespaceCode, ErrorList errors) {... |
| 105 |
0
|
Namespace nSpace = getNamespaceService().getNamespace(namespaceCode); |
| 106 |
0
|
if (nSpace == null) { |
| 107 |
0
|
errors.addError((new StringBuilder()).append('\'').append(namespaceCode).append("' is not a valid namespace code").toString()); |
| 108 |
0
|
return false; |
| 109 |
|
} else { |
| 110 |
0
|
Group i = getIdentityManagementService().getGroupByName(namespaceCode, groupName); |
| 111 |
0
|
if (i == null) { |
| 112 |
0
|
errors.addError((new StringBuilder()).append('\'').append(groupName).append( |
| 113 |
|
"' is not a valid group name for namespace code '").append(namespaceCode).append('\'').toString()); |
| 114 |
0
|
return false; |
| 115 |
|
} else { |
| 116 |
0
|
return true; |
| 117 |
|
} |
| 118 |
|
} |
| 119 |
|
} |
| 120 |
|
} |