| 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 java.util.Date; |
| 19 |
|
import java.util.HashMap; |
| 20 |
|
import java.util.List; |
| 21 |
|
import java.util.Map; |
| 22 |
|
|
| 23 |
|
import javax.servlet.ServletException; |
| 24 |
|
import javax.servlet.http.HttpServletRequest; |
| 25 |
|
import javax.servlet.http.HttpServletResponse; |
| 26 |
|
|
| 27 |
|
import org.apache.commons.lang.StringUtils; |
| 28 |
|
import org.apache.log4j.Logger; |
| 29 |
|
import org.kuali.rice.ken.bo.Notification; |
| 30 |
|
import org.kuali.rice.ken.bo.NotificationChannelReviewer; |
| 31 |
|
import org.kuali.rice.ken.document.kew.NotificationWorkflowDocument; |
| 32 |
|
import org.kuali.rice.ken.service.NotificationMessageContentService; |
| 33 |
|
import org.kuali.rice.ken.service.NotificationRecipientService; |
| 34 |
|
import org.kuali.rice.ken.service.NotificationWorkflowDocumentService; |
| 35 |
|
import org.kuali.rice.ken.util.NotificationConstants; |
| 36 |
|
import org.kuali.rice.ken.util.Util; |
| 37 |
|
import org.kuali.rice.kew.dto.NetworkIdDTO; |
| 38 |
|
import org.kuali.rice.kew.dto.WorkflowIdDTO; |
| 39 |
|
import org.kuali.rice.kew.service.WorkflowDocument; |
| 40 |
|
import org.kuali.rice.kim.bo.Person; |
| 41 |
|
import org.kuali.rice.kim.service.KIMServiceLocator; |
| 42 |
|
import org.kuali.rice.kim.util.KimConstants.KimGroupMemberTypes; |
| 43 |
|
import org.springframework.validation.BindException; |
| 44 |
|
import org.springframework.validation.ValidationUtils; |
| 45 |
|
import org.springframework.web.bind.ServletRequestBindingException; |
| 46 |
|
import org.springframework.web.servlet.ModelAndView; |
| 47 |
|
import org.springframework.web.servlet.mvc.multiaction.MultiActionController; |
| 48 |
|
|
| 49 |
|
|
| 50 |
|
|
| 51 |
|
|
| 52 |
|
|
| 53 |
|
@author |
| 54 |
|
|
|
|
|
| 0% |
Uncovered Elements: 129 (129) |
Complexity: 29 |
Complexity Density: 0.33 |
|
| 55 |
|
public class AdministerNotificationRequestController extends MultiActionController { |
| 56 |
|
private static final Logger LOG = Logger.getLogger(AdministerNotificationRequestController.class); |
| 57 |
|
|
| 58 |
|
|
| 59 |
|
|
| 60 |
|
|
|
|
|
| 0% |
Uncovered Elements: 24 (24) |
Complexity: 12 |
Complexity Density: 1 |
|
| 61 |
|
public static class AdministerNotificationRequestCommand { |
| 62 |
|
|
| 63 |
|
private Long docId; |
| 64 |
|
|
| 65 |
|
|
| 66 |
|
private NotificationWorkflowDocument document; |
| 67 |
|
private Notification notification; |
| 68 |
|
private String renderedContent; |
| 69 |
|
private boolean valid = true; |
| 70 |
|
private String message; |
| 71 |
|
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 72 |
0
|
public Long getDocId() {... |
| 73 |
0
|
return docId; |
| 74 |
|
} |
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 75 |
0
|
public void setDocId(Long docId) {... |
| 76 |
0
|
this.docId = docId; |
| 77 |
|
} |
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 78 |
0
|
public NotificationWorkflowDocument getDocument() {... |
| 79 |
0
|
return document; |
| 80 |
|
} |
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 81 |
0
|
public void setDocument(NotificationWorkflowDocument document) {... |
| 82 |
0
|
this.document = document; |
| 83 |
|
} |
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 84 |
0
|
public Notification getNotification() {... |
| 85 |
0
|
return notification; |
| 86 |
|
} |
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 87 |
0
|
public void setNotification(Notification notification) {... |
| 88 |
0
|
this.notification = notification; |
| 89 |
|
} |
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 90 |
0
|
public String getRenderedContent() {... |
| 91 |
0
|
return renderedContent; |
| 92 |
|
} |
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 93 |
0
|
public void setRenderedContent(String renderedContent) {... |
| 94 |
0
|
this.renderedContent = renderedContent; |
| 95 |
|
} |
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 96 |
0
|
public boolean isValid() {... |
| 97 |
0
|
return valid; |
| 98 |
|
} |
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 99 |
0
|
public void setValid(boolean valid) {... |
| 100 |
0
|
this.valid = valid; |
| 101 |
|
} |
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 102 |
0
|
public String getMessage() {... |
| 103 |
0
|
return message; |
| 104 |
|
} |
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 105 |
0
|
public void setMessage(String message) {... |
| 106 |
0
|
this.message = message; |
| 107 |
|
} |
| 108 |
|
} |
| 109 |
|
|
| 110 |
|
protected NotificationMessageContentService messageContentService; |
| 111 |
|
protected NotificationWorkflowDocumentService workflowDocumentService; |
| 112 |
|
protected NotificationRecipientService recipientService; |
| 113 |
|
|
| 114 |
|
|
| 115 |
|
|
| 116 |
|
@param |
| 117 |
|
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 118 |
0
|
public void setMessageContentService(... |
| 119 |
|
NotificationMessageContentService notificationMessageContentService) { |
| 120 |
0
|
this.messageContentService = notificationMessageContentService; |
| 121 |
|
} |
| 122 |
|
|
| 123 |
|
|
| 124 |
|
|
| 125 |
|
@param |
| 126 |
|
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 127 |
0
|
public void setWorkflowDocumentService(... |
| 128 |
|
NotificationWorkflowDocumentService notificationWorkflowDocumentService) { |
| 129 |
0
|
this.workflowDocumentService = notificationWorkflowDocumentService; |
| 130 |
|
} |
| 131 |
|
|
| 132 |
|
|
| 133 |
|
|
| 134 |
|
@param |
| 135 |
|
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 136 |
0
|
public void setRecipientService(... |
| 137 |
|
NotificationRecipientService notificationRecipientService) { |
| 138 |
0
|
this.recipientService = notificationRecipientService; |
| 139 |
|
} |
| 140 |
|
|
| 141 |
|
|
| 142 |
|
|
| 143 |
|
|
| 144 |
|
@param |
| 145 |
|
@return |
| 146 |
|
@throws |
| 147 |
|
|
|
|
|
| 0% |
Uncovered Elements: 3 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
|
| 148 |
0
|
private Notification retrieveNotificationForWorkflowDocument(WorkflowDocument document) throws Exception {... |
| 149 |
0
|
String notificationAsXml = document.getApplicationContent(); |
| 150 |
|
|
| 151 |
|
|
| 152 |
0
|
Notification notification = messageContentService.parseSerializedNotificationXml(notificationAsXml.getBytes()); |
| 153 |
|
|
| 154 |
0
|
return notification; |
| 155 |
|
} |
| 156 |
|
|
| 157 |
|
|
| 158 |
|
|
| 159 |
|
@param |
| 160 |
|
@param |
| 161 |
|
@param |
| 162 |
|
@return |
| 163 |
|
|
|
|
|
| 0% |
Uncovered Elements: 71 (71) |
Complexity: 16 |
Complexity Density: 0.34 |
|
| 164 |
0
|
public ModelAndView view(HttpServletRequest request, HttpServletResponse response, AdministerNotificationRequestCommand command) {... |
| 165 |
|
|
| 166 |
0
|
WorkflowIdDTO initiator = new WorkflowIdDTO(request.getRemoteUser()); |
| 167 |
|
|
| 168 |
|
|
| 169 |
0
|
if (command.getDocId() == null) { |
| 170 |
0
|
throw new RuntimeException("An invalid document ID was recieved from KEW's action list."); |
| 171 |
|
} |
| 172 |
|
|
| 173 |
|
|
| 174 |
0
|
String view = request.getParameter(NotificationConstants.NOTIFICATION_CONTROLLER_CONSTANTS.COMMAND); |
| 175 |
0
|
String standaloneWindow = "true"; |
| 176 |
0
|
if(view != null && view.equals(NotificationConstants.NOTIFICATION_DETAIL_VIEWS.INLINE)) { |
| 177 |
0
|
standaloneWindow = "false"; |
| 178 |
|
} |
| 179 |
|
|
| 180 |
0
|
NotificationWorkflowDocument document; |
| 181 |
0
|
Map<String, Object> model = new HashMap<String, Object>(); |
| 182 |
|
|
| 183 |
0
|
model.put(NotificationConstants.NOTIFICATION_CONTROLLER_CONSTANTS.STANDALONE_WINDOW, standaloneWindow); |
| 184 |
0
|
try { |
| 185 |
0
|
document = new NotificationWorkflowDocument(initiator, new Long(command.getDocId())); |
| 186 |
|
|
| 187 |
0
|
Notification notification = retrieveNotificationForWorkflowDocument(document); |
| 188 |
|
|
| 189 |
|
|
| 190 |
0
|
command.setDocument(document); |
| 191 |
0
|
command.setNotification(notification); |
| 192 |
|
|
| 193 |
0
|
command.setRenderedContent(Util.transformContent(notification)); |
| 194 |
|
|
| 195 |
0
|
LOG.info("notification auto remove date time: " + notification.getAutoRemoveDateTime()); |
| 196 |
0
|
if (document.stateIsApproved()) { |
| 197 |
0
|
command.setValid(false); |
| 198 |
0
|
command.setMessage("This notification request has been approved."); |
| 199 |
0
|
} else if (document.stateIsDisapproved()) { |
| 200 |
0
|
command.setMessage("This notification request has been disapproved."); |
| 201 |
0
|
} else if (notification.getAutoRemoveDateTime() != null && notification.getAutoRemoveDateTime().before(new Date(System.currentTimeMillis()))) { |
| 202 |
|
|
| 203 |
|
|
| 204 |
|
|
| 205 |
|
|
| 206 |
0
|
boolean disapproved = document.stateIsDisapproved(); |
| 207 |
0
|
if (!document.stateIsDisapproved()) { |
| 208 |
0
|
List<NotificationChannelReviewer> reviewers = notification.getChannel().getReviewers(); |
| 209 |
0
|
String user = null; |
| 210 |
0
|
for (NotificationChannelReviewer reviewer: reviewers) { |
| 211 |
0
|
if (KimGroupMemberTypes.PRINCIPAL_MEMBER_TYPE.equals(reviewer.getReviewerType())) { |
| 212 |
0
|
if (reviewer.getReviewerId().equals(request.getRemoteUser())) { |
| 213 |
0
|
user = request.getRemoteUser(); |
| 214 |
|
} |
| 215 |
0
|
} else if (KimGroupMemberTypes.GROUP_MEMBER_TYPE.equals(reviewer.getReviewerType())) { |
| 216 |
|
|
| 217 |
0
|
String[] members = recipientService.getGroupMembers(reviewer.getReviewerId()); |
| 218 |
0
|
for (String member: members) { |
| 219 |
0
|
if (StringUtils.equals(member, request.getRemoteUser())) { |
| 220 |
0
|
user = request.getRemoteUser(); |
| 221 |
0
|
break; |
| 222 |
|
} |
| 223 |
|
} |
| 224 |
|
} |
| 225 |
|
} |
| 226 |
|
|
| 227 |
0
|
if (user != null) { |
| 228 |
0
|
new WorkflowDocument(new NetworkIdDTO(user), new Long(command.getDocId())).disapprove("Disapproving notification request. Auto-remove datetime has already passed."); |
| 229 |
0
|
disapproved = true; |
| 230 |
|
} |
| 231 |
|
} |
| 232 |
0
|
command.setValid(false); |
| 233 |
0
|
if (disapproved) { |
| 234 |
0
|
command.setMessage("This notification request is no longer valid because the Auto-Remove date has already passed. It has been disapproved. Please refresh your action list."); |
| 235 |
|
} else { |
| 236 |
0
|
command.setMessage("This notification request is no longer valid because the Auto-Remove date has already passed."); |
| 237 |
|
} |
| 238 |
|
} |
| 239 |
|
|
| 240 |
0
|
model.put(getCommandName(command), command); |
| 241 |
|
} catch (Exception e) { |
| 242 |
0
|
throw new RuntimeException(e); |
| 243 |
|
} |
| 244 |
|
|
| 245 |
0
|
return new ModelAndView("ViewNotificationRequestDetails", model); |
| 246 |
|
} |
| 247 |
|
|
| 248 |
|
|
| 249 |
|
|
| 250 |
|
@param |
| 251 |
|
@param |
| 252 |
|
@param |
| 253 |
|
@return |
| 254 |
|
@throws |
| 255 |
|
|
|
|
|
| 0% |
Uncovered Elements: 5 (5) |
Complexity: 1 |
Complexity Density: 0.2 |
|
| 256 |
0
|
public ModelAndView approve(HttpServletRequest request, HttpServletResponse response, AdministerNotificationRequestCommand command) throws ServletException {... |
| 257 |
0
|
administerEventNotificationMessage(request, response, command, "approve"); |
| 258 |
0
|
Map<String, Object> model = new HashMap<String, Object>(); |
| 259 |
0
|
model.put("workflowActionTaken", "Approved"); |
| 260 |
0
|
model.put(NotificationConstants.NOTIFICATION_CONTROLLER_CONSTANTS.STANDALONE_WINDOW, request.getParameter(NotificationConstants.NOTIFICATION_CONTROLLER_CONSTANTS.STANDALONE_WINDOW)); |
| 261 |
0
|
return new ModelAndView("SendNotificationRequestActionTakenWindow", model); |
| 262 |
|
} |
| 263 |
|
|
| 264 |
|
|
| 265 |
|
|
| 266 |
|
@param |
| 267 |
|
@param |
| 268 |
|
@param |
| 269 |
|
@return |
| 270 |
|
@throws |
| 271 |
|
|
|
|
|
| 0% |
Uncovered Elements: 5 (5) |
Complexity: 1 |
Complexity Density: 0.2 |
|
| 272 |
0
|
public ModelAndView disapprove(HttpServletRequest request, HttpServletResponse response, AdministerNotificationRequestCommand command) throws ServletException {... |
| 273 |
0
|
administerEventNotificationMessage(request, response, command, "disapprove"); |
| 274 |
0
|
Map<String, Object> model = new HashMap<String, Object>(); |
| 275 |
0
|
model.put("workflowActionTaken", "Disapproved"); |
| 276 |
0
|
model.put(NotificationConstants.NOTIFICATION_CONTROLLER_CONSTANTS.STANDALONE_WINDOW, request.getParameter(NotificationConstants.NOTIFICATION_CONTROLLER_CONSTANTS.STANDALONE_WINDOW)); |
| 277 |
0
|
return new ModelAndView("SendNotificationRequestActionTakenWindow", model); |
| 278 |
|
} |
| 279 |
|
|
| 280 |
|
|
| 281 |
|
|
| 282 |
|
@param |
| 283 |
|
@param |
| 284 |
|
@param |
| 285 |
|
@return |
| 286 |
|
@throws |
| 287 |
|
|
|
|
|
| 0% |
Uncovered Elements: 5 (5) |
Complexity: 1 |
Complexity Density: 0.2 |
|
| 288 |
0
|
public ModelAndView acknowledge(HttpServletRequest request, HttpServletResponse response, AdministerNotificationRequestCommand command) throws ServletException {... |
| 289 |
0
|
administerEventNotificationMessage(request, response, command, "acknowledge"); |
| 290 |
0
|
Map<String, Object> model = new HashMap<String, Object>(); |
| 291 |
0
|
model.put(NotificationConstants.NOTIFICATION_CONTROLLER_CONSTANTS.STANDALONE_WINDOW, request.getParameter(NotificationConstants.NOTIFICATION_CONTROLLER_CONSTANTS.STANDALONE_WINDOW)); |
| 292 |
0
|
model.put("workflowActionTaken", "Acknowledged"); |
| 293 |
0
|
return new ModelAndView("SendNotificationRequestActionTakenWindow", model); |
| 294 |
|
} |
| 295 |
|
|
| 296 |
|
|
| 297 |
|
|
| 298 |
|
@param |
| 299 |
|
@param |
| 300 |
|
@param |
| 301 |
|
@throws |
| 302 |
|
|
|
|
|
| 0% |
Uncovered Elements: 28 (28) |
Complexity: 6 |
Complexity Density: 0.3 |
|
| 303 |
0
|
private void administerEventNotificationMessage(HttpServletRequest request, HttpServletResponse response, AdministerNotificationRequestCommand command, String action) throws ServletException {... |
| 304 |
0
|
LOG.debug("remoteUser: " + request.getRemoteUser()); |
| 305 |
|
|
| 306 |
0
|
BindException bindException = new BindException(command, "command"); |
| 307 |
0
|
ValidationUtils.rejectIfEmpty(bindException, "docId", "Document id must be specified"); |
| 308 |
0
|
if (bindException.hasErrors()) { |
| 309 |
0
|
throw new ServletRequestBindingException("Document id must be specified", bindException); |
| 310 |
|
} |
| 311 |
|
|
| 312 |
|
|
| 313 |
0
|
WorkflowIdDTO user = new WorkflowIdDTO(request.getRemoteUser()); |
| 314 |
|
|
| 315 |
0
|
try { |
| 316 |
|
|
| 317 |
0
|
NotificationWorkflowDocument document = new NotificationWorkflowDocument(user, command.getDocId()); |
| 318 |
|
|
| 319 |
0
|
Notification notification = retrieveNotificationForWorkflowDocument(document); |
| 320 |
|
|
| 321 |
0
|
String initiatorPrincipalId = document.getRouteHeader().getInitiatorPrincipalId(); |
| 322 |
0
|
Person initiator = KIMServiceLocator.getPersonService().getPerson(initiatorPrincipalId); |
| 323 |
0
|
String notificationBlurb = notification.getContentType().getName() + " notification submitted by " + initiator.getName() + " for channel " + notification.getChannel().getName(); |
| 324 |
0
|
if ("disapprove".equals(action)) { |
| 325 |
0
|
document.disapprove("User " + user.getWorkflowId() + " disapproving " + notificationBlurb); |
| 326 |
0
|
} else if ("approve".equals(action)) { |
| 327 |
0
|
document.approve("User " + user.getWorkflowId() + " approving " + notificationBlurb); |
| 328 |
0
|
} else if ("acknowledge".equals(action)) { |
| 329 |
0
|
document.acknowledge("User " + user.getWorkflowId() + " acknowledging " + notificationBlurb); |
| 330 |
|
} |
| 331 |
|
} catch (Exception e) { |
| 332 |
0
|
LOG.error("Exception occurred taking action on notification request", e); |
| 333 |
0
|
throw new ServletException("Exception occurred taking action on notification request", e); |
| 334 |
|
} |
| 335 |
|
} |
| 336 |
|
} |