1 package org.kuali.ole.alert.service.impl;
2
3 import org.apache.log4j.Logger;
4 import org.kuali.ole.alert.bo.ActionListAlertBo;
5 import org.kuali.ole.alert.bo.AlertBo;
6 import org.kuali.ole.alert.document.OleTransactionalDocumentBase;
7 import org.kuali.ole.alert.service.AlertService;
8 import org.kuali.rice.kim.api.identity.principal.Principal;
9 import org.kuali.rice.kim.api.services.KimApiServiceLocator;
10 import org.kuali.rice.krad.service.KRADServiceLocator;
11 import org.kuali.rice.krad.service.LegacyDataAppAdapter;
12 import org.kuali.rice.krad.util.GlobalVariables;
13 import sun.management.resources.agent_es;
14
15 import java.sql.Date;
16 import java.util.ArrayList;
17 import java.util.HashMap;
18 import java.util.List;
19 import java.util.Map;
20
21
22
23
24 public class AlertServiceImpl implements AlertService{
25 private static final Logger LOG = Logger.getLogger(AlertHelperServiceImpl.class);
26 private LegacyDataAppAdapter legacyDataAppAdapter = KRADServiceLocator.getLegacyDataAdapter();
27
28 public LegacyDataAppAdapter getLegacyDataAppAdapter() {
29 return legacyDataAppAdapter;
30 }
31
32 public void setLegacyDataAppAdapter(LegacyDataAppAdapter legacyDataAppAdapter) {
33 this.legacyDataAppAdapter = legacyDataAppAdapter;
34 }
35
36
37
38
39
40
41 public void saveAlert(OleTransactionalDocumentBase oleTransactionalDocumentBase){
42 LOG.info("Inside saveAlert for updating the alert table for the document with document Number : " +oleTransactionalDocumentBase.getDocumentNumber());
43 if(oleTransactionalDocumentBase.getAlertBoList()!=null && oleTransactionalDocumentBase.getAlertBoList().size()>0){
44 for(AlertBo alertBo : oleTransactionalDocumentBase.getAlertBoList()){
45 alertBo.setDocumentId(oleTransactionalDocumentBase.getDocumentNumber());
46 updateActionList(alertBo, oleTransactionalDocumentBase);
47 }
48 }
49 }
50
51
52
53
54
55
56 public List<AlertBo> retrieveAlertList(String documentNumber){
57 LOG.info("Inside the retrieveAlertList for getting the alerts related to the document with the document number : "+documentNumber);
58 List<AlertBo> alertBos = new ArrayList<AlertBo>();
59 List<AlertBo> unModifiableList = new ArrayList<AlertBo>();
60 try{
61 Map<String,String> actionMap = new HashMap();
62 actionMap.put("documentId",documentNumber);
63 unModifiableList = (List<AlertBo>)legacyDataAppAdapter.findMatching(AlertBo.class,actionMap);
64 }catch(Exception e){
65 LOG.info("Exception occured while getting the alert information to the user : " + documentNumber);
66 LOG.error(e,e);
67 }
68 if(unModifiableList!=null && unModifiableList.size()>0){
69 for(AlertBo alertBo : unModifiableList){
70 String status = null;
71 if(alertBo.getAlertDate()!=null){
72 int dateCompare= alertBo.getAlertDate().compareTo(new Date(System.currentTimeMillis()));
73 if(dateCompare>0){
74 status = "Future";
75 }else if(dateCompare<0){
76 status="Complete";
77 }else if(dateCompare==0){
78 status = "Active";
79 }
80
81 alertBo.setStatus(status);
82 alertBo.setAlertInitiatorName(getName(alertBo.getAlertInitiatorId()));
83 if(alertBo.getAlertModifierId()!=null){
84 alertBo.setAlertModifierName(getName(alertBo.getAlertModifierId()));
85 }
86 if(alertBo.getReceivingUserId()!=null){
87 alertBo.setReceivingUserName(getName(alertBo.getReceivingUserId()));
88 }
89 }
90
91 alertBos.add(alertBo);
92 }
93 }
94 return alertBos;
95 }
96
97
98
99
100
101 public void deleteAlerts(String documentNumber){
102 LOG.info("Inside the deleteAlerts for deleting the alerts related to the document with the document number : "+documentNumber);
103 Map<String,String> actionMap = new HashMap<>();
104 actionMap.put("documentId",documentNumber);
105 legacyDataAppAdapter.deleteMatching(AlertBo.class, actionMap);
106 deleteActionListAlerts(documentNumber);
107 }
108
109
110
111
112
113 public void deleteActionListAlerts(String documentNumber){
114 LOG.info("Inside the deleteActionListAlerts for deleting the alerts in the action list related to the document with the document number : "+documentNumber);
115 Map<String,String> actionMap = new HashMap<>();
116 actionMap.put("documentId",documentNumber);
117 legacyDataAppAdapter.deleteMatching(ActionListAlertBo.class, actionMap);
118 }
119
120
121
122
123
124
125
126 public void updateActionList(AlertBo alertBo,OleTransactionalDocumentBase oleTransactionalDocumentBase){
127 LOG.info("Inside the updateActionList for updating the alerts in the action list related to the document with the document number : "+oleTransactionalDocumentBase.getDocumentNumber() + " for an alert with the alert id : " +alertBo.getAlertId());
128 ActionListAlertBo actionListAlertBo = new ActionListAlertBo();
129 AlertBo alertBo1 = new AlertBo();
130 alertBo1.setDocumentId(alertBo.getDocumentId());
131 alertBo1.setAlertDate(alertBo.getAlertDate());
132 alertBo1.setAlertCreateDate(alertBo.getAlertCreateDate());
133 alertBo1.setAlertInitiatorId(alertBo.getAlertInitiatorId());
134 alertBo1.setAlertModifiedDate(alertBo.getAlertModifiedDate());
135 alertBo1.setAlertInitiatorId(alertBo.getAlertInitiatorId());
136 alertBo1.setAlertModifierId(alertBo.getAlertModifierId());
137 alertBo1.setAlertNote(alertBo.getAlertNote());
138 alertBo1.setReceivingUserId(alertBo.getReceivingUserId());
139 alertBo1.setAlertStatus(alertBo.isAlertStatus());
140 alertBo1.setAlertApproverId(alertBo.getAlertApproverId());
141 alertBo1.setAlertApprovedDate(alertBo.getAlertApprovedDate());
142 actionListAlertBo.setDocumentId(alertBo.getDocumentId());
143 actionListAlertBo.setActive(alertBo.isAlertStatus());
144 actionListAlertBo.setAlertDate(alertBo.getAlertDate());
145 actionListAlertBo.setRecordType(oleTransactionalDocumentBase.getDocumentHeader().getWorkflowDocument().getDocumentTypeName());
146 actionListAlertBo.setTitle(oleTransactionalDocumentBase.getDocumentTitle());
147 actionListAlertBo.setNote(alertBo.getAlertNote());
148 actionListAlertBo.setAlertUserId(alertBo.getReceivingUserId());
149 actionListAlertBo.setAlertInitiatorId(alertBo.getAlertInitiatorId());
150 actionListAlertBo.setAlertApproverId(alertBo.getAlertApproverId());
151 actionListAlertBo.setAlertApprovedDate(alertBo.getAlertApprovedDate());
152 alertBo1 = legacyDataAppAdapter.save(alertBo1);
153 actionListAlertBo.setAlertId(alertBo1.getAlertId());
154 legacyDataAppAdapter.save(actionListAlertBo);
155 }
156
157
158
159
160
161
162
163 public String getName(String principalId){
164 Principal principal = KimApiServiceLocator.getIdentityService().getPrincipal(principalId);
165 return principal.getPrincipalName();
166 }
167
168 }