1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.rice.krad.uif.view;
17
18 import org.apache.commons.lang.StringUtils;
19 import org.kuali.rice.core.api.util.RiceConstants;
20 import org.kuali.rice.core.api.util.RiceKeyConstants;
21 import org.kuali.rice.kim.api.identity.Person;
22 import org.kuali.rice.krad.datadictionary.parse.BeanTag;
23 import org.kuali.rice.krad.document.Document;
24 import org.kuali.rice.krad.document.authorization.PessimisticLock;
25 import org.kuali.rice.krad.service.KRADServiceLocatorWeb;
26 import org.kuali.rice.krad.service.PessimisticLockService;
27 import org.kuali.rice.krad.uif.UifConstants;
28 import org.kuali.rice.krad.util.GlobalVariables;
29 import org.kuali.rice.krad.util.KRADConstants;
30 import org.kuali.rice.krad.web.form.TransactionalDocumentFormBase;
31 import org.kuali.rice.krad.uif.util.LifecycleElement;
32
33
34
35
36
37
38 @BeanTag(name = "transactionalDocumentView", parent = "Uif-TransactionalDocumentView")
39 public class TransactionalDocumentView extends DocumentView {
40
41 private static final long serialVersionUID = 4375336878804984171L;
42
43 private PessimisticLockService pessimisticLockService;
44
45 public TransactionalDocumentView() {
46 super();
47
48 setViewTypeName(UifConstants.ViewType.TRANSACTIONAL);
49 }
50
51
52
53
54
55
56
57
58 @Override
59 public void performFinalize(Object model, LifecycleElement parent) {
60 super.performFinalize(model, parent);
61
62 if (getDocumentEntryForView().getUsePessimisticLocking()) {
63 TransactionalDocumentFormBase form = (TransactionalDocumentFormBase) model;
64
65 generatePessimisticLockMessages(form);
66 setupPessimisticLockingTimeout(form);
67 }
68 }
69
70
71
72
73
74
75 protected void generatePessimisticLockMessages(TransactionalDocumentFormBase form) {
76 Document document = form.getDocument();
77 Person user = GlobalVariables.getUserSession().getPerson();
78
79 for (PessimisticLock lock : document.getPessimisticLocks()) {
80 if (!lock.isOwnedByUser(user)) {
81 String lockDescriptor = StringUtils.defaultIfBlank(lock.getLockDescriptor(), "full");
82 String lockOwner = lock.getOwnedByUser().getName();
83 String lockTime = RiceConstants.getDefaultTimeFormat().format(lock.getGeneratedTimestamp());
84 String lockDate = RiceConstants.getDefaultDateFormat().format(lock.getGeneratedTimestamp());
85
86 GlobalVariables.getMessageMap().putError(KRADConstants.GLOBAL_ERRORS,
87 RiceKeyConstants.ERROR_TRANSACTIONAL_LOCKED, lockDescriptor, lockOwner, lockTime, lockDate);
88 }
89 }
90 }
91
92
93
94
95
96
97 protected void setupPessimisticLockingTimeout(TransactionalDocumentFormBase form) {
98 Document document = form.getDocument();
99
100 if (!document.getPessimisticLocks().isEmpty()) {
101 form.getView().getSessionPolicy().setEnableTimeoutWarning(true);
102 }
103 }
104
105 protected PessimisticLockService getPessimisticLockService() {
106 if (pessimisticLockService == null) {
107 pessimisticLockService = KRADServiceLocatorWeb.getPessimisticLockService();
108 }
109
110 return pessimisticLockService;
111 }
112
113 protected void setPessimisticLockService(PessimisticLockService pessimisticLockService) {
114 this.pessimisticLockService = pessimisticLockService;
115 }
116
117 }