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