1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.rice.krad.test.document;
17
18 import org.kuali.rice.kim.api.identity.Person;
19 import org.kuali.rice.krad.document.SessionDocument;
20 import org.kuali.rice.krad.document.TransactionalDocumentBase;
21 import org.kuali.rice.krad.exception.PessimisticLockingException;
22 import org.kuali.rice.krad.test.document.bo.Account;
23 import org.kuali.rice.krad.util.GlobalVariables;
24
25 import java.util.ArrayList;
26 import java.util.List;
27
28
29
30
31
32
33 public class AccountRequestDocument2 extends TransactionalDocumentBase implements SessionDocument {
34
35 private static final long serialVersionUID = 7616690365412064056L;
36
37
38
39
40
41 public static final String ACCT_REQ_DOC_2_EDITABLE_FIELDS = "acctReqDoc2EditableFields";
42
43
44
45
46 public static final String EDIT_ALL_BUT_REASONS = "editAllButReasons";
47
48
49
50
51 public static final String EDIT_REASONS_ONLY = "editReasonsOnly";
52
53 private String requester;
54 private String reason1;
55 private String reason2;
56 private String requestType;
57 private String accountTypeCode;
58
59 private List<Account> accounts;
60
61 public AccountRequestDocument2() {
62 accounts = new ArrayList<Account>();
63 }
64
65 public String getReason2() {
66 return reason2;
67 }
68
69 public void setReason2(String reason2) {
70 this.reason2 = reason2;
71 }
72
73 public String getReason1() {
74 return reason1;
75 }
76
77 public void setReason1(String reason1) {
78 this.reason1 = reason1;
79 }
80
81 public String getRequester() {
82 return requester;
83 }
84
85 public void setRequester(String requester) {
86 this.requester = requester;
87 }
88
89 public List<Account> getAccounts() {
90 return accounts;
91 }
92
93 public void setAccounts(List<Account> accounts) {
94 this.accounts = accounts;
95 }
96
97 public Account getAccount(int index) {
98 while(accounts.size() - 1 < index) {
99 accounts.add(new Account());
100 }
101 return accounts.get(index);
102 }
103
104 public String getRequestType() {
105 return requestType;
106 }
107
108 public void setRequestType(String requestType) {
109 this.requestType = requestType;
110 }
111
112 public void setAccountTypeCode(String accountType) {
113 this.accountTypeCode = accountType;
114 }
115
116 public String getAccountTypeCode() {
117 return accountTypeCode;
118 }
119
120
121
122
123
124
125 @Override
126 public boolean useCustomLockDescriptors() {
127 return true;
128 }
129
130
131
132
133
134
135
136 @Override
137 public String getCustomLockDescriptor(Person user) {
138 String editableFields = (String) GlobalVariables.getUserSession().retrieveObject(ACCT_REQ_DOC_2_EDITABLE_FIELDS);
139 if (editableFields == null) {
140 throw new PessimisticLockingException("The user session's '" + ACCT_REQ_DOC_2_EDITABLE_FIELDS + "' property cannot be null");
141 }
142 else if (!EDIT_ALL_BUT_REASONS.equals(editableFields) && !EDIT_REASONS_ONLY.equals(editableFields)) {
143 throw new PessimisticLockingException("The value of the user session's '" + ACCT_REQ_DOC_2_EDITABLE_FIELDS + "' property is invalid");
144 }
145 return getDocumentNumber() + "-" + editableFields;
146 }
147 }