1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.ole.select.businessobject;
17
18 import org.kuali.ole.select.service.impl.BatchLoadServiceImpl;
19 import org.kuali.ole.sys.OLEConstants;
20 import org.kuali.ole.sys.context.SpringContext;
21 import org.kuali.rice.kim.api.services.IdentityManagementService;
22 import org.kuali.rice.krad.bo.PersistableBusinessObjectBase;
23 import org.kuali.rice.krad.exception.DocumentAuthorizationException;
24 import org.kuali.rice.krad.util.GlobalVariables;
25 import org.kuali.rice.krad.util.KRADConstants;
26 import org.kuali.rice.krad.util.UrlFactory;
27
28 import java.io.*;
29 import java.math.BigDecimal;
30 import java.sql.Timestamp;
31 import java.util.LinkedHashMap;
32 import java.util.List;
33 import java.util.Properties;
34
35 public class OleLoadSumRecords extends PersistableBusinessObjectBase {
36 private static org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(OleLoadSumRecords.class);
37
38 private Integer acqLoadSumId;
39 private String principalId;
40 private Integer acqLoadSuccCount;
41 private Integer acqLoadFailCount;
42
43 private Integer acqLoadTotCount;
44 private Integer acqLoadPoTotCount;
45 private String acqLoadDescription;
46 private String fileName;
47 private BigDecimal profileId;
48 private OleLoadProfile profileFile;
49 private List<OleLoadFailureRecords> oleLoadFailureRecords;
50 private String attachmentLink;
51 private byte[] fileContents;
52 private static boolean countFlag;
53 private Integer acqLoadTotPoCount;
54 private String documentNumber;
55 private Timestamp loadCreatedDate;
56 private Integer acqLoadTotBibCount;
57 private String listOfAllBibs;
58
59 public String getListOfAllBibs() {
60 List bibIDList = SpringContext.getBean(BatchLoadServiceImpl.class).getBibIDList(this.acqLoadSumId.toString());
61 String ids = "";
62 int i = 0;
63 if (bibIDList.size() > 0) {
64 for (; i < bibIDList.size() - 1; i++) {
65 ids += bibIDList.get(i) + " OR id:";
66 }
67 ids += bibIDList.get(i);
68 }
69
70 return ids;
71 }
72
73
74 public OleLoadSumRecords() {
75 countFlag = true;
76 }
77
78 public Integer getAcqLoadTotBibCount() {
79 return acqLoadTotBibCount;
80 }
81
82 public void setAcqLoadTotBibCount(Integer acqLoadTotBibCount) {
83 this.acqLoadTotBibCount = acqLoadTotBibCount;
84 }
85
86
87 public List<OleLoadFailureRecords> getOleLoadFailureRecords() {
88 return oleLoadFailureRecords;
89 }
90
91 public void setOleLoadFailureRecords(List<OleLoadFailureRecords> oleLoadFailureRecords) {
92 this.oleLoadFailureRecords = oleLoadFailureRecords;
93 }
94
95 public OleLoadProfile getProfileFile() {
96 return profileFile;
97 }
98
99 public void setProfileFile(OleLoadProfile profileFile) {
100 this.profileFile = profileFile;
101 }
102
103 public String getPrincipalId() {
104 return principalId;
105 }
106
107 public void setPrincipalId(String principalId) {
108 this.principalId = principalId;
109 }
110
111 public String getFileName() {
112 return fileName;
113 }
114
115 public Integer getAcqLoadSumId() {
116 return acqLoadSumId;
117 }
118
119 public void setAcqLoadSumId(Integer acqLoadSumId) {
120 this.acqLoadSumId = acqLoadSumId;
121 }
122
123 public Integer getAcqLoadSuccCount() {
124 return acqLoadSuccCount;
125 }
126
127 public void setAcqLoadSuccCount(Integer acqLoadSuccCount) {
128 this.acqLoadSuccCount = acqLoadSuccCount;
129 }
130
131 public Integer getAcqLoadFailCount() {
132 return acqLoadFailCount;
133 }
134
135 public void setAcqLoadFailCount(Integer acqLoadFailCount) {
136 this.acqLoadFailCount = acqLoadFailCount;
137 }
138
139 public Integer getAcqLoadTotCount() {
140 return acqLoadTotCount;
141 }
142
143 public void setAcqLoadTotCount(Integer acqLoadTotCount) {
144 this.acqLoadTotCount = acqLoadTotCount;
145 }
146
147 public Integer getAcqLoadPoTotCount() {
148 return acqLoadPoTotCount;
149 }
150
151 public void setAcqLoadPoTotCount(Integer acqLoadPoTotCount) {
152 this.acqLoadPoTotCount = acqLoadPoTotCount;
153 }
154
155 public String getAcqLoadDescription() {
156 return acqLoadDescription;
157 }
158
159 public void setAcqLoadDescription(String acqLoadDescription) {
160 this.acqLoadDescription = acqLoadDescription;
161 }
162
163 public void setFileName(String fileName) {
164 this.fileName = fileName;
165 }
166
167 public BigDecimal getProfileId() {
168 return profileId;
169 }
170
171 public void setProfileId(BigDecimal profileId) {
172 this.profileId = profileId;
173 }
174
175 public Integer getAcqLoadTotPoCount() {
176 if (this.acqLoadPoTotCount != 0)
177 return getPoToalCount(this.acqLoadPoTotCount);
178 else
179 return this.acqLoadPoTotCount;
180 }
181
182 public void setAcqLoadTotPoCount(Integer acqLoadTotPoCount) {
183 this.acqLoadTotPoCount = acqLoadTotPoCount;
184 }
185
186 public String getDocumentNumber() {
187 return documentNumber;
188 }
189
190 public void setDocumentNumber(String documentNumber) {
191 this.documentNumber = documentNumber;
192 }
193
194 public Timestamp getLoadCreatedDate() {
195 return loadCreatedDate;
196 }
197
198 public void setLoadCreatedDate(Timestamp loadCreatedDate) {
199 this.loadCreatedDate = loadCreatedDate;
200 }
201
202
203 protected LinkedHashMap toStringMapper_RICE20_REFACTORME() {
204
205 return null;
206 }
207
208 public byte[] getFileContents() {
209 String directoryPath = null;
210 try {
211 directoryPath = getDirectoryPath() + this.acqLoadSumId + OLEConstants.BATCH_FAILURE_FILE_MRK;
212 File file = new File(directoryPath);
213 if (file.exists()) {
214 InputStream fis = new FileInputStream(file);
215 byte[] filecontents = new byte[(int) file.length()];
216 fis.read(filecontents);
217 return filecontents;
218 }
219 } catch (Exception ex) {
220 }
221
222 return null;
223 }
224
225 public String getAttachmentLink() {
226 boolean hasPermission = false;
227 String documentTypeName = OLEConstants.OleLoadSummary.LOAD_SUMMARY;
228 String nameSpaceCode = OLEConstants.OleLoadSummary.LOAD_SUMMARY_NAMESPACE;
229 if (LOG.isDebugEnabled()) {
230 LOG.debug("Inside getInquiryUrl documentTypeName >>>>>>>>>>>>>>>>>" + documentTypeName);
231 LOG.debug("Inside getInquiryUrl nameSpaceCode >>>>>>>>>>>>>>>>>" + nameSpaceCode);
232 }
233 hasPermission = SpringContext.getBean(IdentityManagementService.class).hasPermission(GlobalVariables.getUserSession().getPerson().getPrincipalId(), nameSpaceCode, OLEConstants.OleLoadSummary.CAN_VIEW_LOAD_SUMMARY);
234
235 if (!hasPermission) {
236 if (LOG.isDebugEnabled())
237 LOG.debug("Inside getInquiryUrl hasPermission if>>>>>>>>>>>>>>>>>" + hasPermission);
238 throw new DocumentAuthorizationException(GlobalVariables.getUserSession().getPerson().getPrincipalName(), " to edit reuisition document ", "dfsf");
239 } else {
240 if (this.oleLoadFailureRecords.size() > 0) {
241 Properties params = new Properties();
242 params.put(KRADConstants.DISPATCH_REQUEST_PARAMETER, OLEConstants.DOWNLOAD_CUSTM_BO_ATTACHMENT_METHOD);
243 params.put(OLEConstants.BUSINESS_OBJECT_CLASS_ATTRIBUTE, OleLoadSumRecords.class.getName());
244 params.put("acqLoadSumId", this.acqLoadSumId.toString());
245 params.put("fileName", this.acqLoadSumId + OLEConstants.BATCH_FAILURE_FILE_MRK);
246 params.put("fileContentType", ".mrk");
247 params.put("fileContentBOField", "fileContents");
248 return UrlFactory.parameterizeUrl(KRADConstants.INQUIRY_ACTION, params);
249 } else
250 return null;
251 }
252 }
253
254 public void setAttachmentLink(String attachmentLink) {
255 this.attachmentLink = attachmentLink;
256 }
257
258 private String getDirectoryPath() {
259
260
261 String directoryPath = SpringContext.getBean(BatchLoadServiceImpl.class).getDestinationPath();
262 return directoryPath;
263 }
264
265 public Integer getPoToalCount(Integer acqLoadPoTotCount) {
266 this.acqLoadTotBibCount = this.acqLoadSuccCount;
267 int count = 0;
268 String reqIds = null;
269 try {
270 String directoryPath = getDirectoryPath() + this.acqLoadSumId + OLEConstants.BATCH_REQ_ID_FILE;
271 File file = new File(directoryPath);
272 if (file.exists()) {
273 if (countFlag) {
274 InputStream fis = new FileInputStream(file);
275 BufferedInputStream bis = new BufferedInputStream(fis);
276 DataInputStream dis = new DataInputStream(bis);
277 reqIds = dis.readLine();
278 countFlag = false;
279 count = SpringContext.getBean(BatchLoadServiceImpl.class).getPoCount(reqIds);
280 if (count == -1) {
281 return count;
282 }
283 this.setAcqLoadFailCount(this.acqLoadTotCount - count);
284 this.setAcqLoadSuccCount(this.acqLoadTotCount - this.acqLoadFailCount);
285 this.acqLoadPoTotCount = count;
286 return count;
287 }
288 }
289 } catch (Exception ex) {
290 }
291 return acqLoadPoTotCount;
292 }
293
294
295 }