1 package org.kuali.ole.service;
2
3 import org.kuali.ole.OLEConstants;
4 import org.kuali.ole.deliver.bo.PatronBillPayment;
5 import org.kuali.ole.deliver.bo.*;
6 import org.kuali.rice.kim.api.KimConstants;
7 import org.kuali.rice.kim.api.identity.entity.Entity;
8 import org.kuali.rice.kim.api.identity.entity.EntityDefault;
9 import org.kuali.rice.kim.impl.KIMPropertyConstants;
10 import org.kuali.rice.kim.impl.identity.address.EntityAddressBo;
11 import org.kuali.rice.kim.impl.identity.affiliation.EntityAffiliationBo;
12 import org.kuali.rice.kim.impl.identity.email.EntityEmailBo;
13 import org.kuali.rice.kim.impl.identity.employment.EntityEmploymentBo;
14 import org.kuali.rice.kim.impl.identity.entity.EntityBo;
15 import org.kuali.rice.kim.impl.identity.phone.EntityPhoneBo;
16 import org.kuali.rice.kim.impl.identity.type.EntityTypeContactInfoBo;
17 import org.kuali.rice.kim.service.KIMServiceLocatorInternal;
18 import org.kuali.rice.kim.service.UiDocumentService;
19 import org.kuali.rice.krad.lookup.LookupableImpl;
20 import org.kuali.rice.krad.service.BusinessObjectService;
21 import org.kuali.rice.krad.service.KRADServiceLocator;
22 import org.kuali.rice.krad.util.GlobalVariables;
23 import org.kuali.rice.krad.util.KRADConstants;
24
25 import java.text.SimpleDateFormat;
26 import java.util.*;
27
28
29
30
31 public class OlePatronHelperServiceImpl extends LookupableImpl implements OlePatronHelperService {
32 private static final org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(OlePatronHelperServiceImpl.class);
33
34 protected static final String ENTITY_EMAIL_PROPERTY_PREFIX = "entity.entityTypeContactInfos.emailAddresses.";
35 protected static final String ENTITY_NAME_PROPERTY_PREFIX = "entity.names.";
36 protected static final String BILL_ENTITY_NAME_PROPERTY_PREFIX = "olePatron.entity.names.";
37 private BusinessObjectService businessObjectService;
38 protected Map<String, String> criteriaConversion = new HashMap<String, String>();
39
40 {
41 criteriaConversion.put(KIMPropertyConstants.Person.FIRST_NAME, "entity.names.firstName");
42 criteriaConversion.put(KIMPropertyConstants.Person.MIDDLE_NAME, "entity.names.middleName");
43 criteriaConversion.put(KIMPropertyConstants.Person.LAST_NAME, "entity.names.lastName");
44 criteriaConversion.put(KIMPropertyConstants.Person.EMAIL_ADDRESS, "entity.entityTypeContactInfos.emailAddresses.emailAddress");
45 }
46
47 protected Map<String, String> billCriteriaConversion = new HashMap<String, String>();
48
49 {
50 billCriteriaConversion.put(KIMPropertyConstants.Person.FIRST_NAME, "olePatron.entity.names.firstName");
51 billCriteriaConversion.put(KIMPropertyConstants.Person.LAST_NAME, "olePatron.entity.names.lastName");
52 billCriteriaConversion.put(KIMPropertyConstants.Person.EMAIL_ADDRESS, "olePatron.entity.entityTypeContactInfos.emailAddresses.emailAddress");
53 }
54
55
56
57 public EntityBo editAndSaveEntityBo(OlePatronDocument patronDocument) {
58 LOG.debug("Inside the editAndSaveEntityBo method");
59 EntityBo kimEntity;
60 List<EntityTypeContactInfoBo> entityTypes;
61 EntityTypeContactInfoBo entityType;
62 kimEntity = patronDocument.getEntity();
63 if (kimEntity.getId() == null) {
64 String kimEntityId=KRADServiceLocator.getSequenceAccessorService().getNextAvailableSequenceNumber("krim_entity_id_s").toString();
65 kimEntity.setId(kimEntityId);
66 entityTypes = new ArrayList<EntityTypeContactInfoBo>();
67 entityType = new EntityTypeContactInfoBo();
68 kimEntity.setActive(true);
69 entityType.setEntityTypeCode(KimConstants.EntityTypes.PERSON);
70 entityType.setActive(true);
71 entityType.setEntityId(kimEntity.getId());
72 } else {
73 kimEntity.setActive(true);
74 entityTypes = kimEntity.getEntityTypeContactInfos();
75 if (!entityTypes.isEmpty()) {
76 entityType = entityTypes.get(0);
77 entityType.setActive(true);
78 } else {
79 entityType = new EntityTypeContactInfoBo();
80 entityType.setEntityTypeCode(KimConstants.EntityTypes.PERSON);
81 }
82 }
83
84 List<EntityAffiliationBo> affiliationBoList = new ArrayList<EntityAffiliationBo>();
85 List<EntityEmploymentBo> employeeList = new ArrayList<EntityEmploymentBo>();
86 String affiliationSeq = null;
87 if (patronDocument.getPatronAffiliations().size() > 0) {
88 for (OlePatronAffiliation patronAffiliation : patronDocument.getPatronAffiliations()) {
89 patronAffiliation.setEntityId(kimEntity.getId());
90 EntityAffiliationBo entityAffiliationBo = patronAffiliation.getEntityAffliationBo();
91 if (entityAffiliationBo.getId() == null) {
92 affiliationSeq = KRADServiceLocator.getSequenceAccessorService().getNextAvailableSequenceNumber("krim_entity_afltn_id_s").toString();
93 entityAffiliationBo.setId(affiliationSeq);
94 }
95 for (EntityEmploymentBo employmentBo : patronAffiliation.getEmployments()) {
96 employmentBo.setEntityAffiliation(entityAffiliationBo);
97 employmentBo.setEntityAffiliationId(entityAffiliationBo.getId());
98 employeeList.add(employmentBo);
99 }
100 affiliationBoList.add(entityAffiliationBo);
101 }
102 }
103 kimEntity.setAffiliations(affiliationBoList);
104 kimEntity.setEmploymentInformation(employeeList);
105 kimEntity.setNames(Arrays.asList(patronDocument.getName()));
106 List<EntityAddressBo> addressList = new ArrayList<EntityAddressBo>();
107 if (patronDocument.getOleEntityAddressBo().size() > 0) {
108 for (OleEntityAddressBo oleEntityAddress : patronDocument.getOleEntityAddressBo()) {
109 if(oleEntityAddress.getEntityAddressBo()!=null && oleEntityAddress.getEntityAddressBo().getAddressType()!=null){
110 oleEntityAddress.getEntityAddressBo().setAddressTypeCode(oleEntityAddress.getEntityAddressBo().getAddressType().getCode());
111 }
112 addressList.add(oleEntityAddress.getEntityAddressBo());
113 }
114 }
115 patronDocument.setEmployments(employeeList);
116 entityTypes.clear();
117 entityType.setAddresses(addressList);
118 entityType.setEmailAddresses(patronDocument.getEmails());
119 entityType.setPhoneNumbers(patronDocument.getPhones());
120 entityTypes.add(entityType);
121 kimEntity.setEntityTypeContactInfos(entityTypes);
122 try {
123 patronDocument.getIdentityService().updateEntity(EntityBo.to(kimEntity));
124 } catch (Exception e) {
125 LOG.error("Unable to save edited patron Record" + e);
126 }
127
128 return kimEntity;
129 }
130
131 public EntityBo copyAndSaveEntityBo(OlePatronDocument patronDocument) {
132 LOG.debug("Inside the copyAndSaveEntityBo method");
133
134 EntityBo kimEntity;
135 List<EntityTypeContactInfoBo> entityTypes;
136 EntityTypeContactInfoBo entityType;
137 kimEntity = patronDocument.getEntity();
138 kimEntity.setId(null);
139 kimEntity.setObjectId(null);
140 kimEntity.setVersionNumber(null);
141 boolean isUpdatePatron=false;
142 if (kimEntity.getId() == null) {
143 String kimEntityId=KRADServiceLocator.getSequenceAccessorService().getNextAvailableSequenceNumber("krim_entity_id_s").toString();
144 kimEntity.setId(kimEntityId);
145 entityTypes = new ArrayList<EntityTypeContactInfoBo>();
146 entityType = new EntityTypeContactInfoBo();
147 kimEntity.setActive(true);
148 entityType.setEntityTypeCode(KimConstants.EntityTypes.PERSON);
149 entityType.setActive(true);
150 entityType.setEntityId(kimEntity.getId());
151 } else {
152 isUpdatePatron=true;
153 kimEntity.setActive(true);
154 entityTypes = kimEntity.getEntityTypeContactInfos();
155 if (!entityTypes.isEmpty()) {
156 entityType = entityTypes.get(0);
157 entityType.setActive(true);
158 } else {
159 entityType = new EntityTypeContactInfoBo();
160 entityType.setEntityTypeCode(KimConstants.EntityTypes.PERSON);
161 }
162 entityType.setEntityId(kimEntity.getId());
163 }
164
165 List<EntityAffiliationBo> affiliationBoList = new ArrayList<EntityAffiliationBo>();
166 List<EntityEmploymentBo> employeeList = new ArrayList<EntityEmploymentBo>();
167 String affiliationSeq = null;
168 if (patronDocument.getPatronAffiliations().size() > 0) {
169 for (OlePatronAffiliation patronAffiliation : patronDocument.getPatronAffiliations()) {
170 EntityAffiliationBo entityAffiliationBo = patronAffiliation.getEntityAffliationBo();
171 entityAffiliationBo.setEntityId(kimEntity.getId());
172 entityAffiliationBo.setObjectId(null);
173 entityAffiliationBo.setVersionNumber(null);
174 if (entityAffiliationBo.getId() == null) {
175 affiliationSeq = KRADServiceLocator.getSequenceAccessorService().getNextAvailableSequenceNumber("krim_entity_afltn_id_s").toString();
176 entityAffiliationBo.setId(affiliationSeq);
177 }
178 for (EntityEmploymentBo employmentBo : patronAffiliation.getEmployments()) {
179 employmentBo.setEntityAffiliation(entityAffiliationBo);
180 employmentBo.setEntityAffiliationId(entityAffiliationBo.getId());
181 employeeList.add(employmentBo);
182 }
183 affiliationBoList.add(entityAffiliationBo);
184 }
185 }
186 kimEntity.setAffiliations(affiliationBoList);
187 kimEntity.setEmploymentInformation(employeeList);
188 if (patronDocument.getName() != null) {
189 patronDocument.getName().setId(null);
190 patronDocument.getName().setVersionNumber(null);
191 patronDocument.getName().setObjectId(null);
192 patronDocument.getName().setEntityId(null);
193 }
194 kimEntity.setNames(Arrays.asList(patronDocument.getName()));
195
196 List<EntityAddressBo> addressList = new ArrayList<EntityAddressBo>();
197 if (patronDocument.getOleEntityAddressBo() != null) {
198 for (OleEntityAddressBo oleEntityAddress : patronDocument.getOleEntityAddressBo()) {
199 oleEntityAddress.getEntityAddressBo().setId(null);
200 oleEntityAddress.getEntityAddressBo().setVersionNumber(null);
201 oleEntityAddress.getEntityAddressBo().setObjectId(null);
202 oleEntityAddress.getEntityAddressBo().setEntityId(kimEntity.getId());
203 if(oleEntityAddress.getEntityAddressBo()!=null && oleEntityAddress.getEntityAddressBo().getAddressType()!=null){
204 oleEntityAddress.getEntityAddressBo().setAddressTypeCode(oleEntityAddress.getEntityAddressBo().getAddressType().getCode());
205 }
206 addressList.add(oleEntityAddress.getEntityAddressBo());
207 }
208 }
209 List<EntityPhoneBo> entityPhoneBos = new ArrayList<EntityPhoneBo>();
210 if (patronDocument.getPhones() != null) {
211 for (EntityPhoneBo entityPhoneBo : patronDocument.getPhones()) {
212 entityPhoneBo.setObjectId(null);
213 entityPhoneBo.setVersionNumber(null);
214 entityPhoneBo.setId(null);
215 if(entityPhoneBo.getPhoneType()!=null){
216 entityPhoneBo.setPhoneTypeCode(entityPhoneBo.getPhoneType().getCode());
217 }
218 entityPhoneBo.setEntityId(kimEntity.getId());
219 entityPhoneBos.add(entityPhoneBo);
220 }
221 }
222 List<EntityEmailBo> entityEmailBos = new ArrayList<>();
223 if (patronDocument.getEmails() != null) {
224 for (EntityEmailBo emailBo : patronDocument.getEmails()) {
225 emailBo.setObjectId(null);
226 emailBo.setVersionNumber(null);
227 emailBo.setId(null);
228 if(emailBo.getEmailType()!=null){
229 emailBo.setEmailTypeCode(emailBo.getEmailType().getCode());
230 }
231 emailBo.setEntityId(kimEntity.getId());
232 entityEmailBos.add(emailBo);
233 }
234 }
235 entityType.setAddresses(addressList);
236 entityType.setEmailAddresses(entityEmailBos);
237 entityType.setPhoneNumbers(entityPhoneBos);
238 entityTypes.add(entityType);
239 kimEntity.setEntityTypeContactInfos(entityTypes);
240 try {
241 if (isUpdatePatron) {
242 Entity entity = patronDocument.getIdentityService().updateEntity(EntityBo.to(kimEntity));
243 } else {
244 Entity entity = patronDocument.getIdentityService().createEntity(EntityBo.to(kimEntity));
245 }
246
247 } catch (Exception e) {
248 LOG.error("Copied to save edited patron Record" + e);
249 }
250 return kimEntity;
251 }
252
253 public List<OleAddressBo> retrieveOleAddressBo(EntityBo entityBo, OlePatronDocument patronDocument) {
254 List<EntityAddressBo> addressBos = entityBo.getEntityTypeContactInfos().get(0).getAddresses();
255 List<OleAddressBo> oleAddressBos = new ArrayList<OleAddressBo>();
256 for (int i = 0; i < addressBos.size(); i++) {
257 EntityAddressBo entityAddressBo = addressBos.get(i);
258 Map<String, Object> criteria = new HashMap<String, Object>();
259 criteria.put(OLEConstants.OlePatron.ENTITY_BO_ID, entityAddressBo.getId());
260 OleAddressBo oleAddressBo = KRADServiceLocator.getBusinessObjectService().findByPrimaryKey(OleAddressBo.class, criteria);
261 if (oleAddressBo == null) {
262 oleAddressBo = new OleAddressBo();
263 }
264 oleAddressBo.setOlePatronId(entityBo.getId());
265 oleAddressBo.setOleAddressId(KRADServiceLocator.getSequenceAccessorService().getNextAvailableSequenceNumber("OLE_DLVR_ADD_S").toString());
266 oleAddressBo.setEntityAddress(entityAddressBo);
267 oleAddressBo.setAddressValidFrom(patronDocument.getOleEntityAddressBo().get(i).getOleAddressBo().getAddressValidFrom());
268 oleAddressBo.setAddressValidTo(patronDocument.getOleEntityAddressBo().get(i).getOleAddressBo().getAddressValidTo());
269 oleAddressBo.setAddressVerified(patronDocument.getOleEntityAddressBo().get(i).getOleAddressBo().isAddressVerified());
270 oleAddressBo.setAddressSource(patronDocument.getOleEntityAddressBo().get(i).getOleAddressBo().getAddressSource());
271 oleAddressBo.setId(patronDocument.getOleEntityAddressBo().get(i).getOleAddressBo().getId());
272 oleAddressBos.add(oleAddressBo);
273
274 }
275 return oleAddressBos;
276 }
277
278
279
280
281
282
283
284
285 protected boolean isNameEntityCriteria(String propertyName) {
286 LOG.debug("Inside the isNameEntityCriteria method");
287 return propertyName.startsWith(ENTITY_NAME_PROPERTY_PREFIX);
288 }
289
290
291
292
293
294
295
296 protected boolean isEmailEntityCriteria(String propertyName) {
297 LOG.debug("Inside the isEmailEntityCriteria method");
298 return propertyName.startsWith(ENTITY_EMAIL_PROPERTY_PREFIX);
299 }
300
301
302 public boolean deletePatron(OlePatronDocument olePatronDocument) {
303 LOG.debug("Inside the deletePatron method");
304 boolean deleteFlag = false;
305 SimpleDateFormat fmt = new SimpleDateFormat(OLEConstants.OlePatron.PATRON_MAINTENANCE_DATE_FORMAT);
306 Map billMap = new HashMap();
307 billMap.put(OLEConstants.OlePatron.PAY_BILL_PATRON_ID, olePatronDocument.getOlePatronId());
308 List<PatronBillPayment> patronBillPayments = (List<PatronBillPayment>) KRADServiceLocator.getBusinessObjectService().findMatching(PatronBillPayment.class, billMap);
309
310 if (olePatronDocument != null && olePatronDocument.getOlePatronId() != null) {
311 if (olePatronDocument.getOleLoanDocuments() == null || olePatronDocument.getOleLoanDocuments().size() == 0) {
312 if ((olePatronDocument.getOleTemporaryCirculationHistoryRecords() == null || olePatronDocument.getOleTemporaryCirculationHistoryRecords().size() == 0)) {
313 if ((olePatronDocument.getOleDeliverRequestBos() == null || olePatronDocument.getOleDeliverRequestBos().size() == 0)) {
314 if ((patronBillPayments == null || patronBillPayments.size() == 0)) {
315 olePatronDocument.setActiveIndicator(false);
316 List<OleAddressBo> addressBos = olePatronDocument.getOleAddresses();
317 if (addressBos.size() > 0) {
318 for (OleAddressBo addressBo : addressBos) {
319 if (addressBo.getAddressSource().isEmpty() || "".equals(addressBo.getAddressSource())) {
320 addressBo.setAddressSource(null);
321 }
322 }
323 }
324 KRADServiceLocator.getBusinessObjectService().save(olePatronDocument);
325 deleteFlag = true;
326 }
327 }
328 }
329 }
330 }
331 return deleteFlag;
332 }
333
334
335
336
337
338
339
340 public boolean checkAddressSource(List<OleAddressBo> oleAddresses) {
341
342 boolean valid = true;
343 for (OleAddressBo oleAddress : oleAddresses) {
344 if ((oleAddress.getAddressSource() != null) && (oleAddress.getAddressSource().equals(""))) {
345 valid = false;
346 }
347 }
348 return valid;
349 }
350
351
352
353
354
355
356
357 public boolean checkPhoneMultipleDefault(List<EntityPhoneBo> phoneBoList) {
358 boolean valid = true;
359 boolean isDefaultSet = false;
360 int i = 0;
361 for (EntityPhoneBo phone : phoneBoList) {
362 if (phone.isDefaultValue()) {
363 if (isDefaultSet) {
364 valid = false;
365 } else {
366 isDefaultSet = true;
367 }
368 }
369 i++;
370 }
371 if (!phoneBoList.isEmpty() && !isDefaultSet) {
372 valid = false;
373 }
374 return valid;
375 }
376
377
378
379
380
381
382
383 public boolean checkAddressMultipleDefault(List<OleEntityAddressBo> addrBoList) {
384 boolean valid = true;
385 boolean isDefaultSet = false;
386 int i = 0;
387 for (OleEntityAddressBo addr : addrBoList) {
388 EntityAddressBo entityAddressBo = addr.getEntityAddressBo();
389 if (entityAddressBo.isDefaultValue()) {
390 if (isDefaultSet) {
391 valid = false;
392 } else {
393 isDefaultSet = true;
394 }
395 }
396 i++;
397 }
398 if (!addrBoList.isEmpty() && !isDefaultSet) {
399 valid = false;
400 }
401 return valid;
402 }
403
404
405
406
407
408
409
410 public boolean checkEmailMultipleDefault(List<EntityEmailBo> emailBoList) {
411 boolean valid = true;
412 boolean isDefaultSet = false;
413 int i = 0;
414 for (EntityEmailBo email : emailBoList) {
415 if (email.isDefaultValue()) {
416 if (isDefaultSet) {
417 valid = false;
418 } else {
419 isDefaultSet = true;
420 }
421 }
422 i++;
423 }
424 if (!emailBoList.isEmpty() && !isDefaultSet) {
425 valid = false;
426 }
427 return valid;
428 }
429
430 public boolean isBorrowerTypeActive(OlePatronDocument olePatronDocument) {
431 boolean isPatronTypeActive = false;
432 HashMap<String, String> map = new HashMap<String, String>();
433 map.put(OLEConstants.BORROWER_TYPE_ID, olePatronDocument.getBorrowerType());
434 List<OleBorrowerType> borrowerTypes = (List<OleBorrowerType>) getBusinessObjectService().findMatching(OleBorrowerType.class, map);
435 if (borrowerTypes.size() > 0) {
436 if (borrowerTypes.get(0).isActive()) {
437 isPatronTypeActive = true;
438 }
439 }
440 return isPatronTypeActive;
441 }
442
443 public boolean validatePatron(OlePatronDocument patronDocument) {
444 boolean isValid = true;
445 isValid &= validateEntityInformation(patronDocument);
446 isValid &= validateAddress(patronDocument, "oleEntityAddressBo");
447 isValid &= validateRequiredField(patronDocument);
448 isValid &=checkDuplicateBarcode(patronDocument);
449 return isValid;
450 }
451
452 private boolean validateEntityInformation( OlePatronDocument patronDoc) {
453 boolean valid = true;
454 List<OleEntityAddressBo> addressBoList = patronDoc.getOleEntityAddressBo();
455 List<EntityEmailBo> emailBoList = patronDoc.getEmails();
456 List<EntityPhoneBo> phoneBoList = patronDoc.getPhones();
457 if (addressBoList.size() == 1) {
458 OleEntityAddressBo oleEntityAddressBo = addressBoList.get(0);
459 oleEntityAddressBo.getEntityAddressBo().setDefaultValue(true);
460 }
461 if (emailBoList.size() == 1) {
462 EntityEmailBo entityEmailBo = emailBoList.get(0);
463 entityEmailBo.setDefaultValue(true);
464 }
465 if (phoneBoList.size() == 1) {
466 EntityPhoneBo entityPhoneBo = phoneBoList.get(0);
467 entityPhoneBo.setDefaultValue(true);
468 }
469 if (!checkPhoneMultipleDefault(patronDoc.getPhones())) {
470 GlobalVariables.getMessageMap().putErrorForSectionId(OLEConstants.OlePatron.PHONE_SECTION_ID, OLEConstants.OlePatron.ERROR_SELECTION_PREFERRED_PHONE);
471 valid &= false;
472 }
473 if (!checkAddressMultipleDefault(patronDoc.getOleEntityAddressBo())) {
474 GlobalVariables.getMessageMap().putErrorForSectionId(OLEConstants.OlePatron.ADDRESS_SECTION_ID, OLEConstants.OlePatron.ERROR_SELECTION_PREFERRED_ADDRESS);
475 valid &= false;
476 }
477 if (!checkEmailMultipleDefault(patronDoc.getEmails())) {
478 GlobalVariables.getMessageMap().putErrorForSectionId(OLEConstants.OlePatron.EMAIL_SECTION_ID, OLEConstants.OlePatron.ERROR_SELECTION_PREFERRED_EMAIL);
479 valid &= false;
480 }
481 return valid;
482 }
483
484 public boolean validateRequiredField(OlePatronDocument olePatronDocument) {
485 boolean valid = true;
486 List<OleEntityAddressBo> addressBoList = olePatronDocument.getOleEntityAddressBo();
487 List<EntityEmailBo> emailBoList = olePatronDocument.getEmails();
488 if (!(addressBoList.size() > 0 || emailBoList.size() > 0)) {
489 GlobalVariables.getMessageMap().putError(KRADConstants.GLOBAL_ERRORS, OLEConstants.OlePatron.ERROR_PATRON_REQUIRED_ADDRESS);
490 valid = false;
491 }
492 return valid;
493 }
494
495 public boolean validateAddress(OlePatronDocument olePatronDocument, String addressBos) {
496 List<OleEntityAddressBo> addressBoList = olePatronDocument.getOleEntityAddressBo();
497 OleEntityAddressBo oleEntityAddressBo;
498 boolean valid = true;
499 boolean flag=true;
500 boolean dateExist = true;
501 Map<Date,Date> map=new HashMap<>();
502 for (int i = 0; i < addressBoList.size(); i++) {
503 oleEntityAddressBo = addressBoList.get(i);
504 if (oleEntityAddressBo.getEntityAddressBo().isDefaultValue()) {
505 if (oleEntityAddressBo.getOleAddressBo().getAddressValidFrom() != null || oleEntityAddressBo.getOleAddressBo().getAddressValidTo() != null) {
506 GlobalVariables.getMessageMap().putError("dataObject." + addressBos + "[0].defaultValue", OLEConstants.OlePatron.ERROR_PATRON_ADDRESS_DEFAULT_DATE);
507 flag= false;
508 }
509 }
510 if(oleEntityAddressBo.getOleAddressBo().getAddressValidFrom()!=null && oleEntityAddressBo.getOleAddressBo().getAddressValidTo()!=null && oleEntityAddressBo.getOleAddressBo().getAddressValidFrom().compareTo(oleEntityAddressBo.getOleAddressBo().getAddressValidTo())>0){
511 GlobalVariables.getMessageMap().putError("dataObject." + addressBos + "[0].defaultValue", OLEConstants.OlePatron.ERROR_PATRON_VALID_ADDRESS_TO_DATE);
512 flag= false;
513 }
514
515 if(!oleEntityAddressBo.getEntityAddressBo().isDefaultValue()){
516 if(oleEntityAddressBo.getOleAddressBo().getAddressValidFrom()==null && oleEntityAddressBo.getOleAddressBo().getAddressValidTo()!=null){
517 GlobalVariables.getMessageMap().putError("dataObject." + addressBos + "[0].defaultValue", OLEConstants.OlePatron.ERROR_PATRON_REQUIRED_ADDRESS_FROM_DATE, "ValidFrom");
518 flag= false;
519 }
520 if(oleEntityAddressBo.getOleAddressBo().getAddressValidTo()==null && oleEntityAddressBo.getOleAddressBo().getAddressValidFrom()!=null){
521 GlobalVariables.getMessageMap().putError("dataObject." + addressBos + "[0].defaultValue", OLEConstants.OlePatron.ERROR_PATRON_REQUIRED_ADDRESS_FROM_DATE, "ValidTo");
522 flag= false;
523 }
524 for(Map.Entry<Date,Date> entry:map.entrySet()){
525 if(entry.getKey()!=null&&entry.getValue()!=null&&oleEntityAddressBo.getOleAddressBo().getAddressValidFrom()!=null&&oleEntityAddressBo.getOleAddressBo().getAddressValidTo()!=null){
526 if(oleEntityAddressBo.getOleAddressBo().getAddressValidFrom().compareTo(entry.getKey())>=0 && oleEntityAddressBo.getOleAddressBo().getAddressValidFrom().compareTo(entry.getValue())<=0
527 || oleEntityAddressBo.getOleAddressBo().getAddressValidTo().compareTo(entry.getKey())>=0 && oleEntityAddressBo.getOleAddressBo().getAddressValidTo().compareTo(entry.getValue())<=0){
528 GlobalVariables.getMessageMap().putError("dataObject." + addressBos + "[0].defaultValue",OLEConstants.OlePatron.ERROR_PATRON_ADDRESS_FROM_TO_DATE_OVERLAP);
529 flag= false;
530 }
531 if(entry.getKey().compareTo(oleEntityAddressBo.getOleAddressBo().getAddressValidFrom())>=0 && entry.getKey().compareTo(oleEntityAddressBo.getOleAddressBo().getAddressValidTo())<=0
532 || entry.getValue().compareTo(oleEntityAddressBo.getOleAddressBo().getAddressValidFrom())>=0 && entry.getValue().compareTo(oleEntityAddressBo.getOleAddressBo().getAddressValidTo())<=0){
533 GlobalVariables.getMessageMap().putError("dataObject." + addressBos + "[0].defaultValue", OLEConstants.OlePatron.ERROR_PATRON_ADDRESS_FROM_TO_DATE_OVERLAP);
534 flag= false;
535 }
536 }
537 }
538 }else if (oleEntityAddressBo.getOleAddressBo().getAddressValidFrom() != null || oleEntityAddressBo.getOleAddressBo().getAddressValidTo() != null) {
539
540 if (dateExist) {
541 dateExist = false;
542 } else {
543 GlobalVariables.getMessageMap().putError("dataObject." + addressBos + "[0].defaultValue", OLEConstants.OlePatron.ERROR_PATRON_ADDRESS_SINGLE_DATE);
544 flag= false;
545 }
546 }
547 map.put(oleEntityAddressBo.getOleAddressBo().getAddressValidFrom(),oleEntityAddressBo.getOleAddressBo().getAddressValidTo());
548 }
549 if(!flag){
550 return false;
551 }
552 return valid;
553 }
554
555 private UiDocumentService uiDocumentService;
556
557
558
559
560
561 public UiDocumentService getUIDocumentService() {
562 if (uiDocumentService == null) {
563 uiDocumentService = KIMServiceLocatorInternal.getUiDocumentService();
564 }
565 return uiDocumentService;
566 }
567
568 protected boolean checkDuplicateBarcode(OlePatronDocument patronDoc) {
569 boolean valid = true;
570 Map barcodeMap = new HashMap();
571 barcodeMap.put(OLEConstants.OlePatron.BARCODE, patronDoc.getBarcode());
572 List<OlePatronDocument> olePatronDocuments = (List<OlePatronDocument>) KRADServiceLocator.getBusinessObjectService().findMatching(OlePatronDocument.class, barcodeMap);
573 if (olePatronDocuments.size() > 0) {
574 for (OlePatronDocument olePatronDocument : olePatronDocuments) {
575 if (patronDoc.getOlePatronId() == null || !(patronDoc.getOlePatronId().equals(olePatronDocument.getOlePatronId()))) {
576 GlobalVariables.getMessageMap().putErrorWithoutFullErrorPath(KRADConstants.GLOBAL_ERRORS, OLEConstants.OlePatron.PATRON_DUPLICATE_BARCODE);
577 valid = false;
578 }
579 }
580 }
581 return valid;
582 }
583
584
585
586
587
588
589 public BusinessObjectService getBusinessObjectService() {
590 if (businessObjectService == null) {
591 businessObjectService = KRADServiceLocator.getBusinessObjectService();
592 }
593 return businessObjectService;
594 }
595
596
597 }