1 package org.kuali.ole.batch.rule;
2
3 import org.apache.commons.lang.StringUtils;
4 import org.apache.log4j.Logger;
5 import org.kuali.ole.OLEConstants;
6 import org.kuali.ole.batch.bo.OLEBatchProcessProfileBo;
7 import org.kuali.ole.batch.bo.OLEBatchProcessProfileMatchPoint;
8 import org.kuali.ole.batch.bo.OLEBatchProcessScheduleBo;
9 import org.kuali.ole.batch.document.OLEBatchProcessDefinitionDocument;
10 import org.kuali.ole.batch.form.OLEBatchProcessDefinitionForm;
11 import org.kuali.ole.batch.helper.OLESchedulerHelper;
12 import org.kuali.ole.batch.util.BatchBibImportUtil;
13 import org.kuali.rice.core.api.util.ConcreteKeyValue;
14 import org.kuali.rice.core.api.util.KeyValue;
15 import org.kuali.rice.coreservice.impl.parameter.ParameterBo;
16 import org.kuali.rice.kim.api.permission.PermissionService;
17 import org.kuali.rice.kim.api.services.KimApiServiceLocator;
18 import org.kuali.rice.kns.datadictionary.validation.fieldlevel.EmailAddressValidationPattern;
19 import org.kuali.rice.krad.service.BusinessObjectService;
20 import org.kuali.rice.krad.service.KRADServiceLocator;
21 import org.kuali.rice.krad.util.GlobalVariables;
22 import org.kuali.rice.krad.util.KRADConstants;
23 import org.quartz.CronExpression;
24
25 import java.text.ParseException;
26 import java.util.*;
27 import java.util.regex.Matcher;
28 import java.util.regex.Pattern;
29
30
31
32
33
34
35
36
37 public class OLEBatchProcessRule {
38
39 Logger LOG = Logger.getLogger(OLEBatchProcessRule.class);
40
41
42
43 public boolean batchValidations(OLEBatchProcessDefinitionForm oleBatchProcessDefinitionForm) {
44 OLEBatchProcessDefinitionDocument oleBatchProcessDefinitionDocument = (OLEBatchProcessDefinitionDocument) oleBatchProcessDefinitionForm.getDocument();
45 if (validateUser(GlobalVariables.getUserSession().getPrincipalId(), oleBatchProcessDefinitionDocument)) {
46 if (StringUtils.isBlank(oleBatchProcessDefinitionDocument.getBatchProcessProfileName())) {
47 GlobalVariables.getMessageMap().putError(KRADConstants.GLOBAL_ERRORS, OLEConstants.OLEBatchProcess.OLE_BATCH_SCHEDULE, "Profile Name");
48 }
49 else {
50 if (oleBatchProcessDefinitionDocument.getBatchProcessType().equalsIgnoreCase(OLEConstants.OLEBatchProcess.ORDER_RECORD_IMPORT)) {
51 validateOrderRecordImport(oleBatchProcessDefinitionDocument);
52 }
53 else if (!oleBatchProcessDefinitionDocument.getBatchProcessType().equalsIgnoreCase(OLEConstants.OLEBatchProcess.SERIAL_RECORD_IMPORT) && !oleBatchProcessDefinitionDocument.getBatchProcessType().equalsIgnoreCase(OLEConstants.OLEBatchProcess.BATCH_EXPORT) && !oleBatchProcessDefinitionDocument.getBatchProcessType().equalsIgnoreCase(OLEConstants.OLEBatchProcess.CLAIM_REPORT) && (oleBatchProcessDefinitionDocument.getIngestedFile() == null || oleBatchProcessDefinitionDocument.getIngestedFile().isEmpty())) {
54 GlobalVariables.getMessageMap().putError(KRADConstants.GLOBAL_ERRORS, OLEConstants.OLEBatchProcess.UPLOAD_FILE);
55 }
56 else if (oleBatchProcessDefinitionDocument.getBatchProcessType().equalsIgnoreCase(OLEConstants.OLEBatchProcess.BATCH_BIB_IMPORT)) {
57 if (oleBatchProcessDefinitionDocument.getIngestedFile() != null && !oleBatchProcessDefinitionDocument.getIngestedFile().getOriginalFilename().contains(".mrc")) {
58 GlobalVariables.getMessageMap().putError(KRADConstants.GLOBAL_ERRORS, OLEConstants.OLEBatchProcess.BATCH_BIB_IMPORT_INGEST_FILE_FORMAT);
59 }
60 } else if (oleBatchProcessDefinitionDocument.getBatchProcessType().equalsIgnoreCase(OLEConstants.OLEBatchProcess.BATCH_EXPORT) && oleBatchProcessDefinitionDocument.getLoadIdFromFile().equalsIgnoreCase("true")) {
61 if (oleBatchProcessDefinitionDocument.getIngestedFile() == null) {
62 GlobalVariables.getMessageMap().putError(KRADConstants.GLOBAL_ERRORS, OLEConstants.OLEBatchProcess.BATCH_EXPORT_INGEST_FILE_FORMAT);
63 } else if (oleBatchProcessDefinitionDocument.getIngestedFile() != null && !oleBatchProcessDefinitionDocument.getIngestedFile().getOriginalFilename().contains(".txt")) {
64 GlobalVariables.getMessageMap().putError(KRADConstants.GLOBAL_ERRORS, OLEConstants.OLEBatchProcess.BATCH_EXPORT_INGEST_FILE_FORMAT);
65 }
66 } else if (oleBatchProcessDefinitionDocument.getBatchProcessType().equalsIgnoreCase(OLEConstants.OLEBatchProcess.BATCH_DELETE)) {
67 if (oleBatchProcessDefinitionDocument.getIngestedFile() != null && !(oleBatchProcessDefinitionDocument.getIngestedFile().getOriginalFilename().contains(".txt")
68 || oleBatchProcessDefinitionDocument.getIngestedFile().getOriginalFilename().contains(".mrc"))) {
69 GlobalVariables.getMessageMap().putError(KRADConstants.GLOBAL_ERRORS, OLEConstants.OLEBatchProcess.BATCH_DELETE_INGEST_FILE_FORMAT);
70 }
71 Map<String,String> map = new HashMap<String,String>();
72 map.put("batchProcessProfileId", oleBatchProcessDefinitionDocument.getBatchProcessProfileId());
73 List<OLEBatchProcessProfileBo> oleBatchProcessProfileBos = (List<OLEBatchProcessProfileBo>) KRADServiceLocator.getBusinessObjectService().findMatching(OLEBatchProcessProfileBo.class, map);
74 if (oleBatchProcessProfileBos != null && oleBatchProcessProfileBos.size() > 0) {
75 OLEBatchProcessProfileBo oleBatchProcessProfileBo = oleBatchProcessProfileBos.get(0);
76 List<OLEBatchProcessProfileMatchPoint> bibMatchPointList = BatchBibImportUtil.buildMatchPointListByDataType(oleBatchProcessProfileBo.getOleBatchProcessProfileMatchPointList(), org.kuali.ole.docstore.common.document.content.enums.DocType.BIB.getCode());
77 if (bibMatchPointList == null) {
78 GlobalVariables.getMessageMap().putError(KRADConstants.GLOBAL_ERRORS, OLEConstants.OLEBatchProcess.BATCH_DELETE_MATCH_POINT);
79 } else if (bibMatchPointList.size() == 0) {
80 GlobalVariables.getMessageMap().putError(KRADConstants.GLOBAL_ERRORS, OLEConstants.OLEBatchProcess.BATCH_DELETE_MATCH_POINT);
81 } else if (StringUtils.isEmpty(bibMatchPointList.get(0).getMatchPoint())) {
82 GlobalVariables.getMessageMap().putError(KRADConstants.GLOBAL_ERRORS, OLEConstants.OLEBatchProcess.BATCH_DELETE_MATCH_POINT);
83 }
84
85 }
86 } else if (oleBatchProcessDefinitionDocument.getBatchProcessType().equalsIgnoreCase(OLEConstants.OLEBatchProcess.LOCATION_IMPORT)) {
87 if (oleBatchProcessDefinitionDocument.getIngestedFile() != null && !oleBatchProcessDefinitionDocument.getIngestedFile().getOriginalFilename().contains(".xml")){
88 GlobalVariables.getMessageMap().putError(KRADConstants.GLOBAL_ERRORS, OLEConstants.OLEBatchProcess.LOCATION_IMPORT_INGEST_FILE_FORMAT);
89 }
90 } else if (oleBatchProcessDefinitionDocument.getBatchProcessType().equalsIgnoreCase(OLEConstants.OLEBatchProcess.PATRON_IMPORT)) {
91 if (oleBatchProcessDefinitionDocument.getIngestedFile() != null && !oleBatchProcessDefinitionDocument.getIngestedFile().getOriginalFilename().contains(".xml")){
92 GlobalVariables.getMessageMap().putError(KRADConstants.GLOBAL_ERRORS, OLEConstants.OLEBatchProcess.PATRON_IMPORT_INGEST_FILE_FORMAT);
93 }
94 } else if (oleBatchProcessDefinitionDocument.getBatchProcessType().equalsIgnoreCase(OLEConstants.OLEBatchProcess.CLAIM_REPORT)){
95
96 } else if (oleBatchProcessDefinitionDocument.getBatchProcessType().equalsIgnoreCase(OLEConstants.OLEBatchProcess.SERIAL_RECORD_IMPORT)){
97 if(oleBatchProcessDefinitionDocument.getInputFormat().equalsIgnoreCase("XMl")){
98 if (oleBatchProcessDefinitionDocument.getIngestedFile() != null){
99 if(oleBatchProcessDefinitionDocument.getSerialRecordDocumentFile() == null && oleBatchProcessDefinitionDocument.getSerialRecordHistoryFile() == null && oleBatchProcessDefinitionDocument.getSerialRecordTypeFile() == null){
100 if(!oleBatchProcessDefinitionDocument.getIngestedFile().getOriginalFilename().contains(".xml")){
101 clearFile(oleBatchProcessDefinitionDocument);
102 GlobalVariables.getMessageMap().putError(KRADConstants.GLOBAL_ERRORS, OLEConstants.OLEBatchProcess.SERIAL_RECEIVING_IMPORT_INGEST_FILE_FORMAT);
103 }
104 } else{
105 clearFile(oleBatchProcessDefinitionDocument);
106 GlobalVariables.getMessageMap().putError(KRADConstants.GLOBAL_ERRORS, OLEConstants.OLEBatchProcess.SERIAL_XML_CSV_FORMAT);
107 }
108 } else {
109 clearFile(oleBatchProcessDefinitionDocument);
110 GlobalVariables.getMessageMap().putError(KRADConstants.GLOBAL_ERRORS, OLEConstants.OLEBatchProcess.UPLOAD_FILE);
111 }
112
113 } else if(oleBatchProcessDefinitionDocument.getInputFormat().equalsIgnoreCase("CSV")){
114 if(oleBatchProcessDefinitionDocument.getIngestedFile() != null){
115 clearFile(oleBatchProcessDefinitionDocument);
116 GlobalVariables.getMessageMap().putError(KRADConstants.GLOBAL_ERRORS, OLEConstants.OLEBatchProcess.SERIAL_XML_CSV_FORMAT);
117 } else{
118 if (oleBatchProcessDefinitionDocument.getSerialRecordDocumentFile() == null) {
119 clearFile(oleBatchProcessDefinitionDocument);
120 GlobalVariables.getMessageMap().putError(KRADConstants.GLOBAL_ERRORS, OLEConstants.OLEBatchProcess.RECORD_UPLOAD_CSV);
121 }
122 if(oleBatchProcessDefinitionDocument.getSerialRecordDocumentFile()!=null){
123 if(!oleBatchProcessDefinitionDocument.getSerialRecordDocumentFile().getOriginalFilename().contains(".csv")){
124 clearFile(oleBatchProcessDefinitionDocument);
125 GlobalVariables.getMessageMap().putError(KRADConstants.GLOBAL_ERRORS, OLEConstants.OLEBatchProcess.SERIAL_REC_CSV);
126 }else if(!oleBatchProcessDefinitionDocument.getSerialRecordDocumentFile().getOriginalFilename().endsWith(getParameter(OLEConstants.OLEBatchProcess.SERIAL_RECORD_NAME)+".csv")){
127 clearFile(oleBatchProcessDefinitionDocument);
128 GlobalVariables.getMessageMap().putError(KRADConstants.GLOBAL_ERRORS, OLEConstants.OLEBatchProcess.RECORD_NAME_MISMATCH);
129 }
130 }
131 if(oleBatchProcessDefinitionDocument.getSerialRecordTypeFile()!=null){
132 if(!oleBatchProcessDefinitionDocument.getSerialRecordTypeFile().getOriginalFilename().contains(".csv")){
133 clearFile(oleBatchProcessDefinitionDocument);
134 GlobalVariables.getMessageMap().putError(KRADConstants.GLOBAL_ERRORS,OLEConstants.OLEBatchProcess.SERIAL_TYP_CSV);
135 }
136 else if(!oleBatchProcessDefinitionDocument.getSerialRecordTypeFile().getOriginalFilename().endsWith(getParameter(OLEConstants.OLEBatchProcess.SERIAL_TYPE_NAME)+".csv")){
137 clearFile(oleBatchProcessDefinitionDocument);
138 GlobalVariables.getMessageMap().putError(KRADConstants.GLOBAL_ERRORS, OLEConstants.OLEBatchProcess.RECORD_TYPE_NAME_MISMATCH);
139 }
140 }
141 if(oleBatchProcessDefinitionDocument.getSerialRecordHistoryFile()!=null){
142 if(!oleBatchProcessDefinitionDocument.getSerialRecordHistoryFile().getOriginalFilename().contains(".csv")){
143 clearFile(oleBatchProcessDefinitionDocument);
144 GlobalVariables.getMessageMap().putError(KRADConstants.GLOBAL_ERRORS, OLEConstants.OLEBatchProcess.SERIAL_HIS_CSV);
145 }
146 else if(!oleBatchProcessDefinitionDocument.getSerialRecordHistoryFile().getOriginalFilename().endsWith(getParameter(OLEConstants.OLEBatchProcess.SERIAL_HISTORY_NAME)+".csv")){
147 clearFile(oleBatchProcessDefinitionDocument);
148 GlobalVariables.getMessageMap().putError(KRADConstants.GLOBAL_ERRORS,OLEConstants.OLEBatchProcess.RECORD_HISTORY_NAME_MISMATCH);
149 }
150 }
151
152 }
153 }
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181 }
182 }
183 if(StringUtils.isNotBlank(oleBatchProcessDefinitionDocument.getEmailIds()) && !validateEmailIds(oleBatchProcessDefinitionDocument.getEmailIds())){
184 GlobalVariables.getMessageMap().putError(KRADConstants.GLOBAL_ERRORS, OLEConstants.OLEBatchProcess.ERROR_EMAIL_ID);
185 }
186 if (oleBatchProcessDefinitionDocument.isScheduleFlag()) {
187 String cronOrSchedule = oleBatchProcessDefinitionDocument.getCronOrSchedule();
188 if (StringUtils.isNotBlank(cronOrSchedule)) {
189 if (oleBatchProcessDefinitionDocument.getCronOrSchedule().equals(OLEConstants.OLEBatchProcess.PROVIDED_CRON)) {
190 String cronExpression = oleBatchProcessDefinitionDocument.getEnteredCronExp();
191 if (StringUtils.isBlank(cronExpression)) {
192 GlobalVariables.getMessageMap().putError(OLEConstants.OLEBatchProcess.BATCH_PROCESS_SCHEDULE_SECTION_ID, OLEConstants.OLEBatchProcess.OLE_BATCH_SCHEDULE, "Cron Expression");
193 }
194 boolean validCronExpression = org.quartz.CronExpression.isValidExpression(cronExpression);
195 if (StringUtils.isNotBlank(cronExpression) && !validCronExpression) {
196 GlobalVariables.getMessageMap().putError(OLEConstants.OLEBatchProcess.BATCH_PROCESS_SCHEDULE_SECTION_ID, OLEConstants.OLEBatchProcess.ERROR_CRON_EXPRESSION);
197 }
198 } else {
199 OLEBatchProcessScheduleBo oleBatchProcessScheduleBo = oleBatchProcessDefinitionDocument.getOleBatchProcessScheduleBo();
200 String oneTimeOrRecur = oleBatchProcessDefinitionDocument.getOneTimeOrRecurring();
201 if (StringUtils.isNotBlank(oneTimeOrRecur)) {
202 oleBatchProcessScheduleBo.setOneTimeOrRecurring(oneTimeOrRecur);
203 if (oneTimeOrRecur.equalsIgnoreCase(OLEConstants.OLEBatchProcess.SCHEDULE_ONETIME)) {
204 Date oneDate = oleBatchProcessScheduleBo.getOneTimeDate();
205 String oneTime = oleBatchProcessScheduleBo.getOneTimeStartTime();
206 if (oneDate == null) {
207 GlobalVariables.getMessageMap().putError(OLEConstants.OLEBatchProcess.BATCH_PROCESS_SCHEDULE_SECTION_ID, OLEConstants.OLEBatchProcess.OLE_BATCH_SCHEDULE, "Date");
208 }
209 if (StringUtils.isBlank(oneTime)) {
210 GlobalVariables.getMessageMap().putError(OLEConstants.OLEBatchProcess.BATCH_PROCESS_SCHEDULE_SECTION_ID, OLEConstants.OLEBatchProcess.OLE_BATCH_SCHEDULE, "Time");
211 }
212 if (StringUtils.isNotBlank(oneTime) && !validateTime(oneTime)) {
213 GlobalVariables.getMessageMap().putError(OLEConstants.OLEBatchProcess.BATCH_PROCESS_SCHEDULE_SECTION_ID, OLEConstants.OLEBatchProcess.OLE_BATCH_SCHEDULE_TIME);
214 }
215 if(oneDate!=null && StringUtils.isNotEmpty(oneTime) && validateTime(oneTime) && isScheduleInValid(oleBatchProcessScheduleBo)){
216 GlobalVariables.getMessageMap().putError(OLEConstants.OLEBatchProcess.BATCH_PROCESS_SCHEDULE_SECTION_ID, OLEConstants.OLEBatchProcess.OLE_BATCH_SCHEDULE_ERR);
217 }
218 }
219
220 if (oneTimeOrRecur.equalsIgnoreCase(OLEConstants.OLEBatchProcess.SCHEDULE_RECURRING)) {
221 String schduleType = oleBatchProcessDefinitionDocument.getScheduleType();
222 if (StringUtils.isNotBlank(schduleType)) {
223 if (schduleType.equalsIgnoreCase(OLEConstants.OLEBatchProcess.SCHEDULE_TYPE_DAILY)) {
224 String startTimeDaily = oleBatchProcessScheduleBo.getStartTime();
225 if (StringUtils.isBlank(startTimeDaily)) {
226 GlobalVariables.getMessageMap().putError(OLEConstants.OLEBatchProcess.BATCH_PROCESS_SCHEDULE_SECTION_ID, OLEConstants.OLEBatchProcess.OLE_BATCH_SCHEDULE, "Start Time");
227 }
228 if (StringUtils.isNotBlank(startTimeDaily) && !validateTime(startTimeDaily)) {
229 GlobalVariables.getMessageMap().putError(OLEConstants.OLEBatchProcess.BATCH_PROCESS_SCHEDULE_SECTION_ID, OLEConstants.OLEBatchProcess.OLE_BATCH_SCHEDULE_TIME);
230 }
231 }
232 if (schduleType.equalsIgnoreCase(OLEConstants.OLEBatchProcess.SCHEDULE_TYPE_WEEKLY)) {
233 String startTimeWeekly = oleBatchProcessScheduleBo.getStartTime();
234 String weekDays = oleBatchProcessScheduleBo.getWeekDays();
235 if (StringUtils.isBlank(startTimeWeekly)) {
236 GlobalVariables.getMessageMap().putError(OLEConstants.OLEBatchProcess.BATCH_PROCESS_SCHEDULE_SECTION_ID, OLEConstants.OLEBatchProcess.OLE_BATCH_SCHEDULE, "Start Time");
237 }
238 if (StringUtils.isNotBlank(startTimeWeekly) && !validateTime(startTimeWeekly)) {
239 GlobalVariables.getMessageMap().putError(OLEConstants.OLEBatchProcess.BATCH_PROCESS_SCHEDULE_SECTION_ID, OLEConstants.OLEBatchProcess.OLE_BATCH_SCHEDULE_TIME);
240 }
241 if (StringUtils.isBlank(weekDays)) {
242 GlobalVariables.getMessageMap().putError(OLEConstants.OLEBatchProcess.BATCH_PROCESS_SCHEDULE_SECTION_ID, OLEConstants.OLEBatchProcess.OLE_BATCH_SCHEDULE, "Week Day");
243 }
244 }
245 if (schduleType.equalsIgnoreCase(OLEConstants.OLEBatchProcess.SCHEDULE_TYPE_MONTHLY)) {
246 String startTimeMonthly = oleBatchProcessScheduleBo.getStartTime();
247 String dayNumberMonthly = oleBatchProcessScheduleBo.getDayNumber();
248 String monthNumberMonthly = oleBatchProcessScheduleBo.getMonthNumber();
249 if (StringUtils.isBlank(startTimeMonthly)) {
250 GlobalVariables.getMessageMap().putError(OLEConstants.OLEBatchProcess.BATCH_PROCESS_SCHEDULE_SECTION_ID, OLEConstants.OLEBatchProcess.OLE_BATCH_SCHEDULE, "Start Time");
251 }
252 if (StringUtils.isNotBlank(startTimeMonthly) && !validateTime(startTimeMonthly)) {
253 GlobalVariables.getMessageMap().putError(OLEConstants.OLEBatchProcess.BATCH_PROCESS_SCHEDULE_SECTION_ID, OLEConstants.OLEBatchProcess.OLE_BATCH_SCHEDULE_TIME);
254 }
255 if (StringUtils.isBlank(dayNumberMonthly)) {
256 GlobalVariables.getMessageMap().putError(OLEConstants.OLEBatchProcess.BATCH_PROCESS_SCHEDULE_SECTION_ID, OLEConstants.OLEBatchProcess.OLE_BATCH_SCHEDULE, "Day of Month");
257 }
258 if (StringUtils.isBlank(monthNumberMonthly)) {
259 GlobalVariables.getMessageMap().putError(OLEConstants.OLEBatchProcess.BATCH_PROCESS_SCHEDULE_SECTION_ID, OLEConstants.OLEBatchProcess.OLE_BATCH_SCHEDULE, "Month Number");
260 }
261 }
262 } else {
263 GlobalVariables.getMessageMap().putError(OLEConstants.OLEBatchProcess.BATCH_PROCESS_SCHEDULE_SECTION_ID, OLEConstants.OLEBatchProcess.DAILY_WEEKLY_MONTHLY);
264 }
265 }
266 } else {
267 GlobalVariables.getMessageMap().putError(OLEConstants.OLEBatchProcess.BATCH_PROCESS_SCHEDULE_SECTION_ID, OLEConstants.OLEBatchProcess.ONE_TIME_OR_RECUR_ERROR);
268 }
269 }
270 } else {
271 GlobalVariables.getMessageMap().putError(OLEConstants.OLEBatchProcess.BATCH_PROCESS_SCHEDULE_SECTION_ID, OLEConstants.OLEBatchProcess.CRON_OR_SCHEDULE);
272 }
273 }
274 } else {
275 GlobalVariables.getMessageMap().putError(KRADConstants.GLOBAL_ERRORS, OLEConstants.OLEBatchProcess.ERROR_AUTHORIZATION);
276 }
277 int errorCount = GlobalVariables.getMessageMap().getErrorCount();
278 if (errorCount > 0) {
279 return false;
280 } else {
281 return true;
282 }
283 }
284
285
286
287 private boolean validateTime(String time) {
288 String TIME_24HR_PATTERN = "([01]?[0-9]|2[0-3]):[0-5][0-9]";
289 Matcher match = Pattern.compile(TIME_24HR_PATTERN).matcher(time);
290 return match.matches();
291 }
292
293 public boolean validateUser(String principalId, OLEBatchProcessDefinitionDocument oleBatchProcessDefinitionDocument) {
294 boolean hasPermission = true;
295 if (StringUtils.isNotEmpty(oleBatchProcessDefinitionDocument.getBatchProcessType())) {
296 if (oleBatchProcessDefinitionDocument.getBatchProcessType().equalsIgnoreCase(OLEConstants.OLEBatchProcess.BATCH_BIB_IMPORT)) {
297 hasPermission = canPerformBatchImport(principalId);
298 } else if(oleBatchProcessDefinitionDocument.getBatchProcessType().equalsIgnoreCase(OLEConstants.OLEBatchProcess.BATCH_EXPORT)) {
299 hasPermission = canPerformBatchExport(principalId);
300 } else if (oleBatchProcessDefinitionDocument.getBatchProcessType().equalsIgnoreCase(OLEConstants.OLEBatchProcess.BATCH_DELETE)) {
301 hasPermission = canPerformBatchDelete(principalId);
302 }
303 }
304 return hasPermission;
305 }
306
307 private boolean validateEmailIds(String emailsIds){
308 boolean validEmail=true;
309 String[] emailsIdsArray = emailsIds.split(",");
310 for(String emailId:emailsIdsArray){
311 validEmail = validateEmailAddress(emailId.trim());
312 if(!validEmail){
313 return false;
314 }
315 }
316 return validEmail;
317 }
318
319
320
321
322
323
324
325 private boolean validateEmailAddress(String emailAddress) {
326 boolean valid = true;
327
328
329 if (StringUtils.isNotBlank(emailAddress)) {
330 EmailAddressValidationPattern emailAddressPattern = new EmailAddressValidationPattern();
331 if (!emailAddressPattern.matches(emailAddress)) {
332 return false;
333 }
334 }
335 return valid;
336 }
337
338
339 public boolean canPerformBatchImport(String principalId){
340 PermissionService service= KimApiServiceLocator.getPermissionService();
341 return service.hasPermission(principalId,OLEConstants.CAT_NAMESPACE,OLEConstants.BATCH_PROCESS_IMPORT);
342 }
343
344 public boolean canPerformBatchExport(String principalId){
345 PermissionService service= KimApiServiceLocator.getPermissionService();
346 return service.hasPermission(principalId,OLEConstants.CAT_NAMESPACE,OLEConstants.BATCH_PROCESS_EXPORT);
347 }
348
349 public boolean canPerformBatchDelete(String principalId){
350 PermissionService service= KimApiServiceLocator.getPermissionService();
351 return service.hasPermission(principalId,OLEConstants.CAT_NAMESPACE,OLEConstants.BATCH_PROCESS_DELETE);
352 }
353
354 private boolean isScheduleInValid(OLEBatchProcessScheduleBo scheduleBo) {
355 String cronExp = OLESchedulerHelper.getInstance().getCronExpression(scheduleBo);
356 CronExpression exp;
357 try {
358 exp = new CronExpression(cronExp);
359 } catch (ParseException e) {
360 LOG.error("Error while parsing the cron expression:: "+cronExp,e);
361 return false;
362 }
363 Date date = exp.getNextValidTimeAfter(new Date());
364 return date == null;
365 }
366
367
368
369 private void validateOrderRecordImport(OLEBatchProcessDefinitionDocument oleBatchProcessDefinitionDocument){
370 if(oleBatchProcessDefinitionDocument.getMarcOnly()){
371 if(oleBatchProcessDefinitionDocument.getMarcFile()== null){
372 GlobalVariables.getMessageMap().putError(KRADConstants.GLOBAL_ERRORS, OLEConstants.OLEBatchProcess.UPLOAD_MARC_FILE);
373 }
374 }
375 else {
376 if(oleBatchProcessDefinitionDocument.getMarcFile() == null && oleBatchProcessDefinitionDocument.getEdiFile() == null){
377 GlobalVariables.getMessageMap().putError(KRADConstants.GLOBAL_ERRORS, OLEConstants.OLEBatchProcess.UPLOAD_FILE);
378 }
379 else if(oleBatchProcessDefinitionDocument.getMarcFile() == null){
380 GlobalVariables.getMessageMap().putError(KRADConstants.GLOBAL_ERRORS, OLEConstants.OLEBatchProcess.UPLOAD_MARC_FILE);
381 }
382 else if(oleBatchProcessDefinitionDocument.getEdiFile() == null){
383 GlobalVariables.getMessageMap().putError(KRADConstants.GLOBAL_ERRORS, OLEConstants.OLEBatchProcess.UPLOAD_EDI_FILE);
384 }
385 }
386 if(oleBatchProcessDefinitionDocument.getEdiFile() != null){
387 if (oleBatchProcessDefinitionDocument.getMarcFile()!=null && !(oleBatchProcessDefinitionDocument.getMarcFile().getOriginalFilename().contains(".mrc") ||
388 oleBatchProcessDefinitionDocument.getMarcFile().getOriginalFilename().contains(".xml"))) {
389 GlobalVariables.getMessageMap().putError(KRADConstants.GLOBAL_ERRORS, OLEConstants.OLEBatchProcess.UPLOAD_MARC_FILE);
390 }
391 if (oleBatchProcessDefinitionDocument.getEdiFile()!=null && !(oleBatchProcessDefinitionDocument.getEdiFile().getOriginalFilename().contains(".edi") ||
392 oleBatchProcessDefinitionDocument.getEdiFile().getOriginalFilename().contains(".xml"))) {
393 GlobalVariables.getMessageMap().putError(KRADConstants.GLOBAL_ERRORS, OLEConstants.OLEBatchProcess.UPLOAD_EDI_FILE);
394 }
395 }
396 else {
397 if (oleBatchProcessDefinitionDocument.getIngestedFile()!=null && !(oleBatchProcessDefinitionDocument.getIngestedFile().getOriginalFilename().contains(".mrc") ||
398 oleBatchProcessDefinitionDocument.getIngestedFile().getOriginalFilename().contains(".xml"))) {
399 GlobalVariables.getMessageMap().putError(KRADConstants.GLOBAL_ERRORS, OLEConstants.OLEBatchProcess.UPLOAD_MARC_FILE);
400 }
401 }
402 }
403
404 private String getParameter(String name) {
405 String parameter = "";
406 try {
407 Map<String, String> criteriaMap = new HashMap<String, String>();
408 criteriaMap.put("namespaceCode", OLEConstants.SYS_NMSPC);
409 criteriaMap.put("componentCode", OLEConstants.BATCH_CMPNT);
410 criteriaMap.put("name", name);
411 List<ParameterBo> parametersList = (List<ParameterBo>)KRADServiceLocator.getBusinessObjectService().findMatching(ParameterBo.class, criteriaMap);
412 for (ParameterBo parameterBo : parametersList) {
413 parameter = parameterBo.getValue();
414 }
415 } catch (Exception e) {
416 LOG.error(e, e);
417 }
418 return parameter;
419 }
420
421 private void clearFile(OLEBatchProcessDefinitionDocument oleBatchProcessDefinitionDocument ){
422 oleBatchProcessDefinitionDocument.setIngestedFile(null);
423 oleBatchProcessDefinitionDocument.setSerialRecordTypeFile(null);
424 oleBatchProcessDefinitionDocument.setSerialRecordDocumentFile(null);
425 oleBatchProcessDefinitionDocument.setSerialRecordHistoryFile(null);
426
427 }
428 }
429