| 1 | |
|
| 2 | |
|
| 3 | |
|
| 4 | |
|
| 5 | |
|
| 6 | |
|
| 7 | |
|
| 8 | |
|
| 9 | |
|
| 10 | |
|
| 11 | |
|
| 12 | |
|
| 13 | |
|
| 14 | |
|
| 15 | |
|
| 16 | |
package org.kuali.rice.ken.service.impl; |
| 17 | |
|
| 18 | |
import org.apache.commons.lang.StringUtils; |
| 19 | |
import org.kuali.rice.ken.bo.NotificationMessageDelivery; |
| 20 | |
import org.kuali.rice.ken.document.kew.NotificationWorkflowDocument; |
| 21 | |
import org.kuali.rice.ken.service.NotificationMessageContentService; |
| 22 | |
import org.kuali.rice.ken.service.NotificationWorkflowDocumentService; |
| 23 | |
import org.kuali.rice.ken.util.NotificationConstants; |
| 24 | |
import org.kuali.rice.kew.dto.ActionRequestDTO; |
| 25 | |
import org.kuali.rice.kew.dto.WorkflowIdDTO; |
| 26 | |
import org.kuali.rice.kew.exception.WorkflowException; |
| 27 | |
import org.kuali.rice.kew.service.WorkflowDocument; |
| 28 | |
import org.kuali.rice.kew.util.KEWConstants; |
| 29 | |
import org.kuali.rice.kim.bo.entity.KimPrincipal; |
| 30 | |
import org.kuali.rice.kim.service.KIMServiceLocator; |
| 31 | |
|
| 32 | |
|
| 33 | |
|
| 34 | |
|
| 35 | |
|
| 36 | |
|
| 37 | |
public class NotificationWorkflowDocumentServiceImpl implements NotificationWorkflowDocumentService { |
| 38 | 0 | private static org.apache.log4j.Logger LOG = org.apache.log4j.Logger |
| 39 | |
.getLogger(NotificationWorkflowDocumentServiceImpl.class); |
| 40 | |
|
| 41 | |
private NotificationMessageContentService messageContentService; |
| 42 | |
|
| 43 | |
|
| 44 | |
|
| 45 | |
|
| 46 | |
|
| 47 | 0 | public NotificationWorkflowDocumentServiceImpl(NotificationMessageContentService messageContentService) { |
| 48 | 0 | this.messageContentService = messageContentService; |
| 49 | 0 | } |
| 50 | |
|
| 51 | |
|
| 52 | |
|
| 53 | |
|
| 54 | |
|
| 55 | |
|
| 56 | |
public Long createAndAdHocRouteNotificationWorkflowDocument(NotificationMessageDelivery messageDelivery, String initiatorUserId, |
| 57 | |
String recipientUserId, String annotation) throws WorkflowException { |
| 58 | |
|
| 59 | 0 | WorkflowIdDTO initiator = new WorkflowIdDTO(initiatorUserId); |
| 60 | |
|
| 61 | |
|
| 62 | 0 | NotificationWorkflowDocument document = new NotificationWorkflowDocument(initiator); |
| 63 | |
|
| 64 | |
|
| 65 | 0 | document.getRouteHeader().setAppDocId(messageDelivery.getId().toString()); |
| 66 | |
|
| 67 | |
|
| 68 | |
|
| 69 | 0 | document.setApplicationContent(messageContentService.generateNotificationMessage(messageDelivery.getNotification(), messageDelivery.getUserRecipientId())); |
| 70 | |
|
| 71 | 0 | if (!StringUtils.isBlank(messageDelivery.getNotification().getTitle())) { |
| 72 | 0 | document.setTitle(messageDelivery.getNotification().getTitle()); |
| 73 | |
} else { |
| 74 | 0 | LOG.error("Encountered notification with no title set: Message Delivery #" + messageDelivery.getId() + ", Notification #" + messageDelivery.getNotification().getId()); |
| 75 | |
} |
| 76 | |
|
| 77 | |
|
| 78 | |
String actionRequested; |
| 79 | 0 | if(NotificationConstants.DELIVERY_TYPES.ACK.equals(messageDelivery.getNotification().getDeliveryType())) { |
| 80 | 0 | actionRequested = NotificationConstants.KEW_CONSTANTS.ACK_AD_HOC_ROUTE; |
| 81 | |
} else { |
| 82 | 0 | actionRequested = NotificationConstants.KEW_CONSTANTS.FYI_AD_HOC_ROUTE; |
| 83 | |
} |
| 84 | |
|
| 85 | |
|
| 86 | |
|
| 87 | |
|
| 88 | |
|
| 89 | |
|
| 90 | |
|
| 91 | |
|
| 92 | |
|
| 93 | 0 | KimPrincipal principal = KIMServiceLocator.getIdentityManagementService().getPrincipalByPrincipalName(recipientUserId); |
| 94 | 0 | document.adHocRouteDocumentToPrincipal(actionRequested, annotation, principal.getPrincipalId(), |
| 95 | |
messageDelivery.getNotification().getProducer().getName(), true); |
| 96 | |
|
| 97 | |
|
| 98 | 0 | document.routeDocument(annotation); |
| 99 | |
|
| 100 | 0 | return document.getRouteHeaderId(); |
| 101 | |
} |
| 102 | |
|
| 103 | |
|
| 104 | |
|
| 105 | |
|
| 106 | |
|
| 107 | |
|
| 108 | |
public NotificationWorkflowDocument getNotificationWorkflowDocumentByDocumentId(String initiatorUserId, Long workflowDocumentId) throws WorkflowException { |
| 109 | |
|
| 110 | 0 | WorkflowIdDTO initiator = new WorkflowIdDTO(initiatorUserId); |
| 111 | |
|
| 112 | |
|
| 113 | |
|
| 114 | 0 | return new NotificationWorkflowDocument(initiator, workflowDocumentId); |
| 115 | |
} |
| 116 | |
|
| 117 | |
|
| 118 | |
|
| 119 | |
|
| 120 | |
public void clearAllFyisAndAcknowledgeNotificationWorkflowDocument(String initiatorUserId, NotificationWorkflowDocument workflowDocument, String annotation) throws WorkflowException { |
| 121 | 0 | ActionRequestDTO[] reqs = workflowDocument.getActionRequests(); |
| 122 | 0 | for(int i = 0; i < reqs.length; i++) { |
| 123 | 0 | LOG.info("Action Request[" + i + "] = " + reqs[i].getActionRequested()); |
| 124 | 0 | if(reqs[i].getActionRequested().equals(KEWConstants.ACTION_REQUEST_ACKNOWLEDGE_REQ)) { |
| 125 | 0 | workflowDocument.acknowledge(annotation); |
| 126 | 0 | } else if(reqs[i].getActionRequested().equals(KEWConstants.ACTION_REQUEST_FYI_REQ)) { |
| 127 | 0 | workflowDocument.logDocumentAction(annotation); |
| 128 | 0 | workflowDocument.clearFYI(); |
| 129 | |
} else { |
| 130 | 0 | throw new WorkflowException("Invalid notification action request in workflow document (" + workflowDocument.getRouteHeaderId().toString() + ") was encountered. Should be either an acknowledge or fyi and was not."); |
| 131 | |
} |
| 132 | |
} |
| 133 | 0 | } |
| 134 | |
|
| 135 | |
|
| 136 | |
|
| 137 | |
|
| 138 | |
public void terminateWorkflowDocument(WorkflowDocument document) throws WorkflowException { |
| 139 | 0 | document.superUserCancel("terminating document: routeHeaderId=" + document.getRouteHeaderId() + ", appDocId=" + document.getAppDocId()); |
| 140 | 0 | } |
| 141 | |
} |