Commit f969816fdfe077e0ec339ae560e4087fca144613
1 parent
be367201
Exists in
master
Correções e melhorias no workflow
Showing
14 changed files
with
153 additions
and
10 deletions
Show diff stats
cit-esi-api/src/main/java/br/com/centralit/esi/api/document/dao/DocumentDao.java
cit-esi-api/src/main/java/br/com/centralit/esi/api/document/dao/impl/DocumentDaoHibernate.java
... | ... | @@ -57,4 +57,17 @@ public class DocumentDaoHibernate extends CitGenericDAOImpl implements DocumentD |
57 | 57 | |
58 | 58 | return query.getResultList(); |
59 | 59 | } |
60 | + | |
61 | + @SuppressWarnings("unchecked") | |
62 | + @Override | |
63 | + public List<Document> findByWorkItem(Long workItemId) { | |
64 | + String queryString = "select document from Document as document" | |
65 | + + " where document.workItem.id = :workItemId" | |
66 | + + " and document.dataInativo is null "; | |
67 | + | |
68 | + Query query = em().createQuery(queryString); | |
69 | + query.setParameter("workItemId", workItemId); | |
70 | + | |
71 | + return query.getResultList(); | |
72 | + } | |
60 | 73 | } | ... | ... |
cit-esi-api/src/main/java/br/com/centralit/esi/api/document/service/DocumentService.java
... | ... | @@ -28,4 +28,6 @@ public interface DocumentService extends GenericService<Document, Long> { |
28 | 28 | void buildDocument(String name, MultipartFile file, Long documentId, Long documentType, String documentDescription, Long processInstanceId, Long workItemId); |
29 | 29 | |
30 | 30 | List<Document> findByProcessInstance(Long processInstanceId); |
31 | + | |
32 | + List<Document> findByWorkItem(Long workItemId); | |
31 | 33 | } | ... | ... |
cit-esi-api/src/main/java/br/com/centralit/esi/api/document/service/impl/DocumentServiceImpl.java
... | ... | @@ -126,4 +126,9 @@ public class DocumentServiceImpl extends GenericServiceImpl<Document, Long> impl |
126 | 126 | return documentDao.findByProcessInstance(processInstanceId); |
127 | 127 | } |
128 | 128 | |
129 | + @Override | |
130 | + public List<Document> findByWorkItem(Long workItemId) { | |
131 | + return documentDao.findByWorkItem(workItemId); | |
132 | + } | |
133 | + | |
129 | 134 | } | ... | ... |
cit-esi-api/src/main/java/br/com/centralit/esi/api/execution/service/ProcessInstanceServiceBase.java
... | ... | @@ -52,5 +52,7 @@ public interface ProcessInstanceServiceBase extends GenericService<ProcessInstan |
52 | 52 | public void addMessage(RuntimeEnvironment runtimeEnvironment, ProcessInstance processInstance, NotificationTemplate notificationTemplate, User[] users, Group[] groups, List<File> files); |
53 | 53 | |
54 | 54 | public void sendMessages(RuntimeEnvironment runtimeEnvironment, ProcessInstance processInstance); |
55 | + | |
56 | + void sendNotificationForAssignments(RuntimeEnvironment runtimeEnvironment, Long userTaskItemId, String notificationTemplateName, boolean sendAttachedFiles); | |
55 | 57 | |
56 | 58 | } | ... | ... |
cit-esi-api/src/main/java/br/com/centralit/esi/api/execution/service/impl/ProcessInstanceServiceBaseImpl.java
1 | 1 | package br.com.centralit.esi.api.execution.service.impl; |
2 | 2 | |
3 | 3 | import java.io.File; |
4 | +import java.io.FileOutputStream; | |
5 | +import java.io.IOException; | |
4 | 6 | import java.util.ArrayList; |
5 | 7 | import java.util.Arrays; |
6 | 8 | import java.util.Calendar; |
... | ... | @@ -21,6 +23,8 @@ import br.com.centralit.esi.api.design.model.FlowVersion; |
21 | 23 | import br.com.centralit.esi.api.design.model.event.Event; |
22 | 24 | import br.com.centralit.esi.api.design.service.FlowActionService; |
23 | 25 | import br.com.centralit.esi.api.design.service.FlowConnectionService; |
26 | +import br.com.centralit.esi.api.document.model.Document; | |
27 | +import br.com.centralit.esi.api.document.service.DocumentService; | |
24 | 28 | import br.com.centralit.esi.api.enumerated.ActorTypeEnum; |
25 | 29 | import br.com.centralit.esi.api.enumerated.EstimateTimeTypeEnum; |
26 | 30 | import br.com.centralit.esi.api.enumerated.ProcessInstanceStatusEnum; |
... | ... | @@ -32,6 +36,7 @@ import br.com.centralit.esi.api.execution.model.ProcessInstance; |
32 | 36 | import br.com.centralit.esi.api.execution.model.ProcessInstanceVariable; |
33 | 37 | import br.com.centralit.esi.api.execution.model.UserTaskItem; |
34 | 38 | import br.com.centralit.esi.api.execution.model.WorkItem; |
39 | +import br.com.centralit.esi.api.execution.model.WorkItemAssignment; | |
35 | 40 | import br.com.centralit.esi.api.execution.service.ProcessInstanceServiceBase; |
36 | 41 | import br.com.centralit.esi.api.execution.service.ProcessInstanceVariableService; |
37 | 42 | import br.com.centralit.esi.api.execution.service.ProcessInstanceVariableValueService; |
... | ... | @@ -43,6 +48,7 @@ import br.com.centralit.esi.api.notification.model.Message; |
43 | 48 | import br.com.centralit.esi.api.notification.model.Notification; |
44 | 49 | import br.com.centralit.esi.api.notification.model.NotificationTemplate; |
45 | 50 | import br.com.centralit.esi.api.notification.service.NotificationService; |
51 | +import br.com.centralit.esi.api.notification.service.NotificationTemplateService; | |
46 | 52 | import br.com.centralit.esi.api.parameter.model.Parameter; |
47 | 53 | import br.com.centralit.esi.api.parameter.service.ParameterService; |
48 | 54 | import br.com.centralit.esi.api.runtime.RuntimeContext; |
... | ... | @@ -53,6 +59,7 @@ import br.com.centralit.esi.api.security.model.User; |
53 | 59 | import br.com.centralit.esi.api.security.service.SecurityService; |
54 | 60 | import br.com.centralit.esi.api.subscriber.model.Subscriber; |
55 | 61 | import br.com.centralit.esi.api.util.EsiAppUtils; |
62 | +import br.com.centralit.esi.exception.EsiBusinessException; | |
56 | 63 | import br.com.centralit.framework.exception.BusinessException; |
57 | 64 | import br.com.centralit.framework.mail.HTMLMail; |
58 | 65 | import br.com.centralit.framework.service.arquitetura.GenericServiceImpl; |
... | ... | @@ -103,7 +110,13 @@ public abstract class ProcessInstanceServiceBaseImpl extends GenericServiceImpl< |
103 | 110 | private NotificationService notificationService; |
104 | 111 | |
105 | 112 | @Autowired |
113 | + private NotificationTemplateService notificationTemplateService; | |
114 | + | |
115 | + @Autowired | |
106 | 116 | protected SecurityService securityService; |
117 | + | |
118 | + @Autowired | |
119 | + protected DocumentService documentService; | |
107 | 120 | |
108 | 121 | protected ProcessInstanceDao processInstanceDao; |
109 | 122 | |
... | ... | @@ -177,6 +190,7 @@ public abstract class ProcessInstanceServiceBaseImpl extends GenericServiceImpl< |
177 | 190 | runtimeEnvironment.addOrUpdateObject("processInstanceService", this); |
178 | 191 | runtimeEnvironment.addOrUpdateObject("processInstance", processInstance); |
179 | 192 | runtimeEnvironment.addOrUpdateObject("userTaskService", workItemUserTaskService); |
193 | + runtimeEnvironment.addOrUpdateObject("notificationTemplateService", notificationTemplateService); | |
180 | 194 | } |
181 | 195 | |
182 | 196 | |
... | ... | @@ -373,11 +387,12 @@ public abstract class ProcessInstanceServiceBaseImpl extends GenericServiceImpl< |
373 | 387 | String HTMLText = runtimeEnvironment.parseString(message.getHTMLText()); |
374 | 388 | String from = runtimeEnvironment.parseString(message.getFrom()); |
375 | 389 | String subject = runtimeEnvironment.parseString(message.getSubject()); |
390 | + subject = UtilString.isNullOrEmpty(subject) ? " " : subject; | |
376 | 391 | |
377 | - if (EsiAppUtils.BPE_SEND_EMAIL) { | |
392 | + if (EsiAppUtils.BPE_SEND_EMAIL && !UtilString.isNullOrEmpty(HTMLText)) { | |
378 | 393 | htmlMail.sendMail(message.getEmails(runtimeEnvironment), from, subject, HTMLText, message.getFiles()); |
379 | 394 | } |
380 | - if (EsiAppUtils.BPE_SEND_NOTIFICATION) { | |
395 | + if (EsiAppUtils.BPE_SEND_NOTIFICATION && !UtilString.isNullOrEmpty(text)) { | |
381 | 396 | Notification notification = new Notification(subject, text, message.getUsers() != null ? Arrays.asList(message.getUsers()) : null, message.getGroups() != null ? Arrays.asList(message.getGroups()) : null); |
382 | 397 | notificationService.sendNotification(runtimeEnvironment, notification); |
383 | 398 | } |
... | ... | @@ -689,7 +704,7 @@ public abstract class ProcessInstanceServiceBaseImpl extends GenericServiceImpl< |
689 | 704 | |
690 | 705 | @Override |
691 | 706 | public void addMessage(RuntimeEnvironment runtimeEnvironment, ProcessInstance processInstance, NotificationTemplate notificationTemplate, User[] users, Group[] groups, List<File> files) { |
692 | - if (!UtilString.isNullOrEmpty(notificationTemplate.getText())) { | |
707 | + if (!UtilString.isNullOrEmpty(notificationTemplate.getText()) || !UtilString.isNullOrEmpty(notificationTemplate.getHTMLText())) { | |
693 | 708 | String text = runtimeEnvironment.parseString(notificationTemplate.getText()); |
694 | 709 | String HTMLText = runtimeEnvironment.parseString(notificationTemplate.getHTMLText()); |
695 | 710 | String from = runtimeEnvironment.parseString(EsiAppUtils.BPE_EMAIL_FROM); |
... | ... | @@ -740,4 +755,83 @@ public abstract class ProcessInstanceServiceBaseImpl extends GenericServiceImpl< |
740 | 755 | |
741 | 756 | return processInstance; |
742 | 757 | } |
758 | + | |
759 | + public User[] getAssignedUsers(UserTaskItem userTask) { | |
760 | + List<User> list = new ArrayList<User>(); | |
761 | + if (userTask.getAssignments() != null) { | |
762 | + for (WorkItemAssignment assignment : userTask.getAssignments()) { | |
763 | + if (assignment.getUser() != null) { | |
764 | + User user = securityService.getUser(assignment.getUser().getId()); | |
765 | + if (user != null) { | |
766 | + list.add(user); | |
767 | + } | |
768 | + } | |
769 | + } | |
770 | + | |
771 | + User[] result = new User[list.size()]; | |
772 | + list.toArray(result); | |
773 | + | |
774 | + return result; | |
775 | + }else{ | |
776 | + return new User[0]; | |
777 | + } | |
778 | + } | |
779 | + | |
780 | + public Group[] getAssignedGroups(UserTaskItem userTask) { | |
781 | + List<Group> list = new ArrayList<Group>(); | |
782 | + if (userTask.getAssignments() != null) { | |
783 | + for (WorkItemAssignment assignment : userTask.getAssignments()) { | |
784 | + if (assignment.getGroup() != null) { | |
785 | + Group group = securityService.getGroup(assignment.getGroup().getId()); | |
786 | + if (group != null) { | |
787 | + list.add(group); | |
788 | + } | |
789 | + } | |
790 | + } | |
791 | + | |
792 | + Group[] result = new Group[list.size()]; | |
793 | + list.toArray(result); | |
794 | + | |
795 | + return result; | |
796 | + }else{ | |
797 | + return new Group[0]; | |
798 | + } | |
799 | + } | |
800 | + | |
801 | + @SuppressWarnings("resource") | |
802 | + @Override | |
803 | + public void sendNotificationForAssignments(RuntimeEnvironment runtimeEnvironment, Long userTaskItemId, String notificationTemplateName, boolean sendAttachedFiles) { | |
804 | + NotificationTemplate notificationTemplate = notificationTemplateService.findByName(notificationTemplateName); | |
805 | + if (notificationTemplate != null) { | |
806 | + UserTaskItem userTaskItem = workItemUserTaskService.getReference(userTaskItemId); | |
807 | + if (userTaskItem != null) { | |
808 | + ProcessInstance processInstance = userTaskItem.getProcessInstance(); | |
809 | + | |
810 | + List<File> files = null; | |
811 | + if (sendAttachedFiles) { | |
812 | + List<Document> documents = documentService.findByProcessInstance(processInstance.getId()); | |
813 | + if (documents != null) { | |
814 | + files = new ArrayList<File>(); | |
815 | + for (Document document : documents) { | |
816 | + try { | |
817 | + if (document.getAttachedFile() != null && document.getAttachedFile().getFile() != null) { | |
818 | + File tempFile = File.createTempFile("temp", ""); | |
819 | + FileOutputStream fos = new FileOutputStream(tempFile); | |
820 | + fos.write(document.getAttachedFile().getFile()); | |
821 | + | |
822 | + files.add(tempFile); | |
823 | + } | |
824 | + } catch (IOException e) { | |
825 | + e.printStackTrace(); | |
826 | + throw new EsiBusinessException(e); | |
827 | + } | |
828 | + } | |
829 | + } | |
830 | + } | |
831 | + | |
832 | + this.addMessage(runtimeEnvironment, processInstance, notificationTemplate, this.getAssignedUsers(userTaskItem), this.getAssignedGroups(userTaskItem), files); | |
833 | + this.sendMessages(runtimeEnvironment, processInstance); | |
834 | + } | |
835 | + } | |
836 | + } | |
743 | 837 | } |
744 | 838 | \ No newline at end of file | ... | ... |
cit-esi-api/src/main/java/br/com/centralit/esi/api/pack/service/impl/PackServiceImpl.java
... | ... | @@ -175,7 +175,7 @@ public class PackServiceImpl extends GenericServiceImpl<Pack, Long> implements P |
175 | 175 | if (pack.getNotifications() != null) { |
176 | 176 | for (NotificationTemplate notification : pack.getNotifications()) { |
177 | 177 | notification = notificationTemplateService.save(notification, pack.getReplaceElement()); |
178 | - pack.getElements().add(new PackElement(pack, PackElementTypeEnum.NOTIFICATION, notification.getId(), notification.getName(), notification.getSubject())); | |
178 | + pack.getElements().add(new PackElement(pack, PackElementTypeEnum.NOTIFICATION, notification.getId(), notification.getName(), notification.getDescription())); | |
179 | 179 | } |
180 | 180 | } |
181 | 181 | if (pack.isNew()) { | ... | ... |
cit-esi-api/src/main/java/br/com/centralit/esi/api/util/ConvertUtilsESI.java
... | ... | @@ -159,6 +159,18 @@ public class ConvertUtilsESI { |
159 | 159 | return str.length() == 24 && str.charAt(4) == '-' && str.charAt(7) == '-' && str.charAt(10) == 'T' && str.charAt(13) == ':'; |
160 | 160 | } |
161 | 161 | |
162 | + public static boolean isTimestamp(final String str) { | |
163 | + try { | |
164 | + if (str.length() >= 19 && str.charAt(4) == '-' && str.charAt(7) == '-' && str.charAt(10) == ' ' && str.charAt(13) == ':') { | |
165 | + Timestamp ts = Timestamp.valueOf(str); | |
166 | + return ts != null; | |
167 | + } | |
168 | + | |
169 | + } catch (Exception e) { | |
170 | + } | |
171 | + return false; | |
172 | + } | |
173 | + | |
162 | 174 | /** |
163 | 175 | * @param value |
164 | 176 | * @return |
... | ... | @@ -173,6 +185,9 @@ public class ConvertUtilsESI { |
173 | 185 | }else if (value instanceof Calendar) { |
174 | 186 | SimpleDateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy"); |
175 | 187 | return dateFormat.format(((Calendar) value).getTime()); |
188 | + }else if (value instanceof Timestamp) { | |
189 | + SimpleDateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy hh:mm:ss"); | |
190 | + return dateFormat.format(((Timestamp) value).getTime()); | |
176 | 191 | }else if (value instanceof Date) { |
177 | 192 | SimpleDateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy"); |
178 | 193 | return dateFormat.format(((Date) value).getTime()); |
... | ... | @@ -645,5 +660,5 @@ public class ConvertUtilsESI { |
645 | 660 | |
646 | 661 | return result; |
647 | 662 | } |
648 | - | |
663 | + | |
649 | 664 | } | ... | ... |
cit-esi-api/src/main/java/br/com/centralit/esi/api/util/ParseUtilsESI.java
1 | 1 | package br.com.centralit.esi.api.util; |
2 | 2 | |
3 | 3 | import java.lang.reflect.Method; |
4 | +import java.sql.Timestamp; | |
4 | 5 | import java.util.HashMap; |
5 | 6 | |
6 | 7 | import org.apache.commons.lang.text.StrSubstitutor; |
... | ... | @@ -69,6 +70,8 @@ public class ParseUtilsESI { |
69 | 70 | result = json.get(property); |
70 | 71 | if (result instanceof String && ConvertUtilsESI.isJsonDate((String) result)) { |
71 | 72 | result = UtilDate.jsonToDate((String) result); |
73 | + }else if (result instanceof String && ConvertUtilsESI.isTimestamp((String) result)) { | |
74 | + return Timestamp.valueOf((String) result); | |
72 | 75 | } |
73 | 76 | } catch (Exception e) { |
74 | 77 | } | ... | ... |
cit-esi-web/src/main/java/br/com/centralit/listener/StartupListenerEsi.java
... | ... | @@ -848,7 +848,8 @@ public class StartupListenerEsi extends UtilStartup implements ApplicationListen |
848 | 848 | str.append("var parameterService = runtimeEnvironment.getObject(\"parameterService\");\n\n"); |
849 | 849 | str.append("var EnvironmentVariable = importNames.EnvironmentVariable;\n\n"); |
850 | 850 | str.append("var VariableTypeEnum = importNames.VariableTypeEnum;\n"); |
851 | - str.append("var HashMap = importNames.HashMap;\n\n"); | |
851 | + str.append("var HashMap = importNames.HashMap;\n"); | |
852 | + str.append("var StringBuilder = importNames.StringBuilder;\n\n"); | |
852 | 853 | |
853 | 854 | str.append("addOrUpdateObject = function(name, value) {\n"); |
854 | 855 | str.append(" runtimeEnvironment.addOrUpdateObject(name, value);\n"); |
... | ... | @@ -930,6 +931,10 @@ public class StartupListenerEsi extends UtilStartup implements ApplicationListen |
930 | 931 | str.append(" userTaskService.assign(runtimeEnvironment, userTask, "+uuid+".ActorTypeEnum.GROUP, type, group);\n"); |
931 | 932 | str.append("};\n\n"); |
932 | 933 | |
934 | + str.append("sendNotificationForAssignments = function(userTaskId, templateName, sendAttachedFiles) {\n"); | |
935 | + str.append(" processInstanceService.sendNotificationForAssignments(runtimeEnvironment, userTaskId, templateName, sendAttachedFiles);\n"); | |
936 | + str.append("};\n\n"); | |
937 | + | |
933 | 938 | return str.toString(); |
934 | 939 | } |
935 | 940 | ... | ... |
cit-esi-web/src/main/webapp/assets/js/angular/custom/controller/NotificationTemplateListController.js
... | ... | @@ -9,6 +9,7 @@ citApp.controller('NotificationTemplateListController', ["$scope", "Notification |
9 | 9 | }; |
10 | 10 | |
11 | 11 | $scope.headers = [ {title : $translate.instant('LABEL.NOME'), value : 'name', tamanho: 30 } , |
12 | + {title : $translate.instant('LABEL.DESCRICAO'), value : 'description' }, | |
12 | 13 | {title : $translate.instant('LABEL.ASSUNTO'), value : 'subject' }]; |
13 | 14 | |
14 | 15 | $scope.filterCriteria = { |
... | ... | @@ -16,8 +17,9 @@ citApp.controller('NotificationTemplateListController', ["$scope", "Notification |
16 | 17 | dir : 'asc', |
17 | 18 | sort : 'name', |
18 | 19 | limit : 10, |
19 | - fields: ['id', 'name', 'subject'], | |
20 | + fields: ['id', 'name', 'description', 'subject'], | |
20 | 21 | filters : [ {type : 'string', field : 'name' } , |
22 | + {type : 'string', field : 'description' }, | |
21 | 23 | {type : 'string', field : 'subject' }] |
22 | 24 | }; |
23 | 25 | ... | ... |
cit-esi-web/src/main/webapp/assets/js/angular/custom/controller/PackController.js
... | ... | @@ -305,7 +305,7 @@ citApp.controller('PackController', ["$scope", "PackRepository", "DataObjectRepo |
305 | 305 | |
306 | 306 | $scope.setNotificationTemplate = function (item) { |
307 | 307 | if (item && item.id) { |
308 | - $scope.addElement('NOTIFICATION', item, 'subject'); | |
308 | + $scope.addElement('NOTIFICATION', item, 'description'); | |
309 | 309 | } |
310 | 310 | $scope.clearNotificationTemplate(); |
311 | 311 | }; | ... | ... |
cit-esi-web/src/main/webapp/html/businessProcess/businessProcessData.html
... | ... | @@ -166,7 +166,7 @@ |
166 | 166 | </div> |
167 | 167 | </div> |
168 | 168 | <div class="col-md-2" ng-if="processoNegocio.target == 'FLOW' && !processoNegocio.displayable"> |
169 | - <label-input ng-type="text" ng-id="processoNegocio.cronExpression" ng-label="LABEL.EXPRESSAO_CRON" ng-obrigatorio="false" | |
169 | + <label-input ng-type="text" ng-id="processoNegocio.cronExpression" ng-label="ESI.EXPRESSAO_CRON" ng-obrigatorio="false" | |
170 | 170 | ng-disabled="!edit" ng-model="processoNegocio.cronExpression" ng-custom-maxlength="255" form="processoNegocioForm"/> |
171 | 171 | </div> |
172 | 172 | </div> | ... | ... |
cit-esi-web/src/main/webapp/html/pack/packEdit.html
... | ... | @@ -307,7 +307,7 @@ |
307 | 307 | <auto-complete |
308 | 308 | ng-find="findNotificationTemplate(value)" |
309 | 309 | ng-acao-borracha="clearNotificationTemplate()" |
310 | - ng-item="item.subject" | |
310 | + ng-item="item.description" | |
311 | 311 | ng-label="" |
312 | 312 | ng-model="notificationTemplate" |
313 | 313 | ng-set-result="setNotificationTemplate(item)" | ... | ... |