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