001package org.kuali.ole.service; 002 003import org.kuali.ole.OLEConstants; 004import org.kuali.ole.deliver.bo.PatronBillPayment; 005import org.kuali.ole.deliver.bo.*; 006import org.kuali.rice.kim.api.KimConstants; 007import org.kuali.rice.kim.api.identity.entity.Entity; 008import org.kuali.rice.kim.api.identity.entity.EntityDefault; 009import org.kuali.rice.kim.impl.KIMPropertyConstants; 010import org.kuali.rice.kim.impl.identity.address.EntityAddressBo; 011import org.kuali.rice.kim.impl.identity.affiliation.EntityAffiliationBo; 012import org.kuali.rice.kim.impl.identity.email.EntityEmailBo; 013import org.kuali.rice.kim.impl.identity.employment.EntityEmploymentBo; 014import org.kuali.rice.kim.impl.identity.entity.EntityBo; 015import org.kuali.rice.kim.impl.identity.phone.EntityPhoneBo; 016import org.kuali.rice.kim.impl.identity.type.EntityTypeContactInfoBo; 017import org.kuali.rice.kim.service.KIMServiceLocatorInternal; 018import org.kuali.rice.kim.service.UiDocumentService; 019import org.kuali.rice.krad.lookup.LookupableImpl; 020import org.kuali.rice.krad.service.BusinessObjectService; 021import org.kuali.rice.krad.service.KRADServiceLocator; 022import org.kuali.rice.krad.util.GlobalVariables; 023import org.kuali.rice.krad.util.KRADConstants; 024 025import java.text.SimpleDateFormat; 026import java.util.*; 027 028/** 029 * OlePatronHelperServiceImpl converts PatronProperties to EntityProperties and generate new search criteria. 030 */ 031public class OlePatronHelperServiceImpl implements OlePatronHelperService { 032 private static final org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(OlePatronHelperServiceImpl.class); 033 034 protected static final String ENTITY_EMAIL_PROPERTY_PREFIX = "entity.entityTypeContactInfos.emailAddresses."; 035 protected static final String ENTITY_NAME_PROPERTY_PREFIX = "entity.names."; 036 protected static final String BILL_ENTITY_NAME_PROPERTY_PREFIX = "olePatron.entity.names."; 037 private BusinessObjectService businessObjectService; 038 protected Map<String, String> criteriaConversion = new HashMap<String, String>(); 039 040 { 041 criteriaConversion.put(KIMPropertyConstants.Person.FIRST_NAME, "entity.names.firstName"); 042 criteriaConversion.put(KIMPropertyConstants.Person.MIDDLE_NAME, "entity.names.middleName"); 043 criteriaConversion.put(KIMPropertyConstants.Person.LAST_NAME, "entity.names.lastName"); 044 criteriaConversion.put(KIMPropertyConstants.Person.EMAIL_ADDRESS, "entity.entityTypeContactInfos.emailAddresses.emailAddress"); 045 } 046 047 protected Map<String, String> billCriteriaConversion = new HashMap<String, String>(); 048 049 { 050 billCriteriaConversion.put(KIMPropertyConstants.Person.FIRST_NAME, "olePatron.entity.names.firstName"); 051 billCriteriaConversion.put(KIMPropertyConstants.Person.LAST_NAME, "olePatron.entity.names.lastName"); 052 billCriteriaConversion.put(KIMPropertyConstants.Person.EMAIL_ADDRESS, "olePatron.entity.entityTypeContactInfos.emailAddresses.emailAddress"); 053 } 054 055 056 057 public EntityBo editAndSaveEntityBo(OlePatronDocument patronDocument) { 058 LOG.debug("Inside the editAndSaveEntityBo method"); 059 EntityBo kimEntity; 060 List<EntityTypeContactInfoBo> entityTypes; 061 EntityTypeContactInfoBo entityType; 062 kimEntity = patronDocument.getEntity(); 063 if (kimEntity.getId() == null) { 064 String kimEntityId=KRADServiceLocator.getSequenceAccessorService().getNextAvailableSequenceNumber("krim_entity_id_s").toString(); 065 kimEntity.setId(kimEntityId); 066 entityTypes = new ArrayList<EntityTypeContactInfoBo>(); 067 entityType = new EntityTypeContactInfoBo(); 068 kimEntity.setActive(true); 069 entityType.setEntityTypeCode(KimConstants.EntityTypes.PERSON); 070 entityType.setActive(true); 071 entityType.setEntityId(kimEntity.getId()); 072 } else { 073 kimEntity.setActive(true); 074 entityTypes = kimEntity.getEntityTypeContactInfos(); 075 if (!entityTypes.isEmpty()) { 076 entityType = entityTypes.get(0); 077 entityType.setActive(true); 078 } else { 079 entityType = new EntityTypeContactInfoBo(); 080 entityType.setEntityTypeCode(KimConstants.EntityTypes.PERSON); 081 } 082 } 083 084 List<EntityAffiliationBo> affiliationBoList = new ArrayList<EntityAffiliationBo>(); 085 List<EntityEmploymentBo> employeeList = new ArrayList<EntityEmploymentBo>(); 086 String affiliationSeq = null; 087 if (patronDocument.getPatronAffiliations().size() > 0) { 088 for (OlePatronAffiliation patronAffiliation : patronDocument.getPatronAffiliations()) { 089 patronAffiliation.setEntityId(kimEntity.getId()); 090 EntityAffiliationBo entityAffiliationBo = patronAffiliation.getEntityAffliationBo(); 091 if (entityAffiliationBo.getId() == null) { 092 affiliationSeq = KRADServiceLocator.getSequenceAccessorService().getNextAvailableSequenceNumber("krim_entity_afltn_id_s").toString(); 093 entityAffiliationBo.setId(affiliationSeq); 094 } 095 for (EntityEmploymentBo employmentBo : patronAffiliation.getEmployments()) { 096 employmentBo.setEntityAffiliation(entityAffiliationBo); 097 employmentBo.setEntityAffiliationId(entityAffiliationBo.getId()); 098 employeeList.add(employmentBo); 099 } 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 oleAddressBo.setDeliverAddress(patronDocument.getOleEntityAddressBo().get(i).getOleAddressBo().isDeliverAddress()); 273 oleAddressBos.add(oleAddressBo); 274 275 } 276 return oleAddressBos; 277 } 278 279 280 /** 281 * Check whether name entity is present in search criteria 282 * 283 * @param propertyName 284 * @return boolean 285 */ 286 protected boolean isNameEntityCriteria(String propertyName) { 287 LOG.debug("Inside the isNameEntityCriteria method"); 288 return propertyName.startsWith(ENTITY_NAME_PROPERTY_PREFIX); 289 } 290 291 /** 292 * Check whether email entity is present in search criteria 293 * 294 * @param propertyName 295 * @return boolean 296 */ 297 protected boolean isEmailEntityCriteria(String propertyName) { 298 LOG.debug("Inside the isEmailEntityCriteria method"); 299 return propertyName.startsWith(ENTITY_EMAIL_PROPERTY_PREFIX); 300 } 301 302 303 public boolean deletePatron(OlePatronDocument olePatronDocument) { 304 LOG.debug("Inside the deletePatron method"); 305 boolean deleteFlag = false; 306 SimpleDateFormat fmt = new SimpleDateFormat(OLEConstants.OlePatron.PATRON_MAINTENANCE_DATE_FORMAT); 307 Map billMap = new HashMap(); 308 billMap.put(OLEConstants.OlePatron.PAY_BILL_PATRON_ID, olePatronDocument.getOlePatronId()); 309 List<PatronBillPayment> patronBillPayments = (List<PatronBillPayment>) KRADServiceLocator.getBusinessObjectService().findMatching(PatronBillPayment.class, billMap); 310 311 if (olePatronDocument != null && olePatronDocument.getOlePatronId() != null) { 312 if (olePatronDocument.getOleLoanDocuments() == null || olePatronDocument.getOleLoanDocuments().size() == 0) { 313 if ((olePatronDocument.getOleTemporaryCirculationHistoryRecords() == null || olePatronDocument.getOleTemporaryCirculationHistoryRecords().size() == 0)) { 314 if ((olePatronDocument.getOleDeliverRequestBos() == null || olePatronDocument.getOleDeliverRequestBos().size() == 0)) { 315 if ((patronBillPayments == null || patronBillPayments.size() == 0)) { 316 olePatronDocument.setActiveIndicator(false); 317 List<OleAddressBo> addressBos = olePatronDocument.getOleAddresses(); 318 if (addressBos.size() > 0) { 319 for (OleAddressBo addressBo : addressBos) { 320 if (addressBo.getAddressSource().isEmpty() || "".equals(addressBo.getAddressSource())) { 321 addressBo.setAddressSource(null); 322 } 323 } 324 } 325 KRADServiceLocator.getBusinessObjectService().save(olePatronDocument); 326 deleteFlag = true; 327 } 328 } 329 } 330 } 331 } 332 return deleteFlag; 333 } 334 335 /** 336 * This method is for checking the added address source or not 337 * 338 * @param oleAddresses 339 * @return true , if the address source has value in a single patron record, else false 340 */ 341 public boolean checkAddressSource(List<OleAddressBo> oleAddresses) { 342 343 boolean valid = true; 344 for (OleAddressBo oleAddress : oleAddresses) { 345 if ((oleAddress.getAddressSource() != null) && (oleAddress.getAddressSource().equals(""))) { 346 valid = false; 347 } 348 } 349 return valid; 350 } 351 352 /** 353 * This method is for checking the entity phone has multiple defaults 354 * 355 * @param phoneBoList 356 * @return true , if the entity phone has only one default in a single patron record, else false 357 */ 358 public boolean checkPhoneMultipleDefault(List<EntityPhoneBo> phoneBoList) { 359 boolean valid = true; 360 boolean isDefaultSet = false; 361 int i = 0; 362 for (EntityPhoneBo phone : phoneBoList) { 363 if (phone.isDefaultValue()) { 364 if (isDefaultSet) { 365 valid = false; 366 } else { 367 isDefaultSet = true; 368 } 369 } 370 i++; 371 } 372 if (!phoneBoList.isEmpty() && !isDefaultSet) { 373 valid = false; 374 } 375 return valid; 376 } 377 378 /** 379 * This method is for checking the entity address has multiple defaults 380 * 381 * @param addrBoList 382 * @return true , if the entity address has only one default in a single patron record, else false 383 */ 384 public boolean checkAddressMultipleDefault(List<OleEntityAddressBo> addrBoList) { 385 boolean valid = true; 386 boolean isDefaultSet = false; 387 int i = 0; 388 for (OleEntityAddressBo addr : addrBoList) { 389 EntityAddressBo entityAddressBo = addr.getEntityAddressBo(); 390 if (entityAddressBo.isDefaultValue()) { 391 if (isDefaultSet) { 392 valid = false; 393 } else { 394 isDefaultSet = true; 395 } 396 } 397 i++; 398 } 399 if (!addrBoList.isEmpty() && !isDefaultSet) { 400 valid = false; 401 } 402 return valid; 403 } 404 405 /** 406 * This method is for checking the entity email address has multiple defaults 407 * 408 * @param emailBoList 409 * @return true , if the entity email address has only one default in a single patron record, else false 410 */ 411 public boolean checkEmailMultipleDefault(List<EntityEmailBo> emailBoList) { 412 boolean valid = true; 413 boolean isDefaultSet = false; 414 int i = 0; 415 for (EntityEmailBo email : emailBoList) { 416 if (email.isDefaultValue()) { 417 if (isDefaultSet) { 418 valid = false; 419 } else { 420 isDefaultSet = true; 421 } 422 } 423 i++; 424 } 425 if (!emailBoList.isEmpty() && !isDefaultSet) { 426 valid = false; 427 } 428 return valid; 429 } 430 431 public boolean isBorrowerTypeActive(OlePatronDocument olePatronDocument) { 432 boolean isPatronTypeActive = false; 433 HashMap<String, String> map = new HashMap<String, String>(); 434 map.put(OLEConstants.BORROWER_TYPE_ID, olePatronDocument.getBorrowerType()); 435 List<OleBorrowerType> borrowerTypes = (List<OleBorrowerType>) getBusinessObjectService().findMatching(OleBorrowerType.class, map); 436 if (borrowerTypes.size() > 0) { 437 if (borrowerTypes.get(0).isActive()) { 438 isPatronTypeActive = true; 439 } 440 } 441 return isPatronTypeActive; 442 } 443 444 public boolean validatePatron(OlePatronDocument patronDocument) { 445 boolean isValid = true; 446 isValid &= validateEntityInformation(patronDocument); 447 isValid &= validateAddress(patronDocument, "oleEntityAddressBo"); 448 isValid &= validateRequiredField(patronDocument); 449 isValid &=checkDuplicateBarcode(patronDocument); 450 return isValid; 451 } 452 453 private boolean validateEntityInformation( OlePatronDocument patronDoc) { 454 boolean valid = true; 455 List<OleEntityAddressBo> addressBoList = patronDoc.getOleEntityAddressBo(); 456 List<EntityEmailBo> emailBoList = patronDoc.getEmails(); 457 List<EntityPhoneBo> phoneBoList = patronDoc.getPhones(); 458 if (addressBoList.size() == 1) { 459 OleEntityAddressBo oleEntityAddressBo = addressBoList.get(0); 460 oleEntityAddressBo.getEntityAddressBo().setDefaultValue(true); 461 } 462 if (emailBoList.size() == 1) { 463 EntityEmailBo entityEmailBo = emailBoList.get(0); 464 entityEmailBo.setDefaultValue(true); 465 } 466 if (phoneBoList.size() == 1) { 467 EntityPhoneBo entityPhoneBo = phoneBoList.get(0); 468 entityPhoneBo.setDefaultValue(true); 469 } 470 if (!checkPhoneMultipleDefault(patronDoc.getPhones())) { 471 GlobalVariables.getMessageMap().putErrorForSectionId(OLEConstants.OlePatron.PHONE_SECTION_ID, OLEConstants.OlePatron.ERROR_SELECTION_PREFERRED_PHONE); 472 valid &= false; 473 } 474 if (!checkAddressMultipleDefault(patronDoc.getOleEntityAddressBo())) { 475 GlobalVariables.getMessageMap().putErrorForSectionId(OLEConstants.OlePatron.ADDRESS_SECTION_ID, OLEConstants.OlePatron.ERROR_SELECTION_PREFERRED_ADDRESS); 476 valid &= false; 477 } 478 if (!checkEmailMultipleDefault(patronDoc.getEmails())) { 479 GlobalVariables.getMessageMap().putErrorForSectionId(OLEConstants.OlePatron.EMAIL_SECTION_ID, OLEConstants.OlePatron.ERROR_SELECTION_PREFERRED_EMAIL); 480 valid &= false; 481 } 482 if (!checkAddressMultipleDeliverAddress(patronDoc.getOleEntityAddressBo(), "oleEntityAddressBo")) { 483 // GlobalVariables.getMessageMap().putErrorForSectionId(OLEConstants.OlePatron.ADDRESS_SECTION_ID, OLEConstants.OlePatron.ERROR_SELECTION_PREFERRED_DELIVER_ADDRESS); 484 valid &= false; 485 } 486 return valid; 487 } 488 489 protected boolean checkAddressMultipleDeliverAddress(List<OleEntityAddressBo> addrBoList, String listName) { 490 boolean valid = true; 491 boolean isDefaultSet = false; 492 boolean isAtleastOneChecked=false; 493 int i = 0; 494 for (OleEntityAddressBo addr : addrBoList) { 495 OleAddressBo oleAddressBo = addr.getOleAddressBo(); 496 if (oleAddressBo.isDeliverAddress()) { 497 isAtleastOneChecked=true; 498 if (isDefaultSet) { 499 //this.putFieldError("dataObject." + listName + "[" + i + "].defaultValue", OLEConstants.OlePatron.ERROR_PATRON_MULIT_DELIVER_ADDRESS); 500 GlobalVariables.getMessageMap().putError(KRADConstants.GLOBAL_ERRORS, OLEConstants.OlePatron.ERROR_PATRON_MULIT_DELIVER_ADDRESS); 501 valid = false; 502 } else { 503 isDefaultSet = true; 504 } 505 } 506 i++; 507 } 508 if(!isAtleastOneChecked){ 509 valid=true; 510 } else { 511 if (!addrBoList.isEmpty() && !isDefaultSet) { 512 //this.putFieldError("dataObject."+listName+"[0].defaultValue",RiceKeyConstants.ERROR_NO_DEFAULT_SELETION); 513 valid = false; 514 } 515 } 516 return valid; 517 } 518 519 public boolean validateRequiredField(OlePatronDocument olePatronDocument) { 520 boolean valid = true; 521 List<OleEntityAddressBo> addressBoList = olePatronDocument.getOleEntityAddressBo(); 522 List<EntityEmailBo> emailBoList = olePatronDocument.getEmails(); 523 if (!(addressBoList.size() > 0 || emailBoList.size() > 0)) { 524 GlobalVariables.getMessageMap().putError(KRADConstants.GLOBAL_ERRORS, OLEConstants.OlePatron.ERROR_PATRON_REQUIRED_ADDRESS); 525 valid = false; 526 } 527 return valid; 528 } 529 530 public boolean validateAddress(OlePatronDocument olePatronDocument, String addressBos) { 531 List<OleEntityAddressBo> addressBoList = olePatronDocument.getOleEntityAddressBo(); 532 OleEntityAddressBo oleEntityAddressBo; 533 boolean valid = true; 534 boolean flag=true; 535 boolean dateExist = true; 536 Map<Date,Date> map=new HashMap<>(); 537 for (int i = 0; i < addressBoList.size(); i++) { 538 oleEntityAddressBo = addressBoList.get(i); 539 if (oleEntityAddressBo.getEntityAddressBo().isDefaultValue()) { 540 if (oleEntityAddressBo.getOleAddressBo().getAddressValidFrom() != null || oleEntityAddressBo.getOleAddressBo().getAddressValidTo() != null) { 541 GlobalVariables.getMessageMap().putError("dataObject." + addressBos + "[0].defaultValue", OLEConstants.OlePatron.ERROR_PATRON_ADDRESS_DEFAULT_DATE); 542 flag= false; 543 } 544 } 545 if(oleEntityAddressBo.getOleAddressBo().getAddressValidFrom()!=null && oleEntityAddressBo.getOleAddressBo().getAddressValidTo()!=null && oleEntityAddressBo.getOleAddressBo().getAddressValidFrom().compareTo(oleEntityAddressBo.getOleAddressBo().getAddressValidTo())>0){ 546 GlobalVariables.getMessageMap().putError("dataObject." + addressBos + "[0].defaultValue", OLEConstants.OlePatron.ERROR_PATRON_VALID_ADDRESS_TO_DATE); 547 flag= false; 548 } 549 550 if(!oleEntityAddressBo.getEntityAddressBo().isDefaultValue()){ 551 if(oleEntityAddressBo.getOleAddressBo().getAddressValidFrom()==null && oleEntityAddressBo.getOleAddressBo().getAddressValidTo()!=null){ 552 GlobalVariables.getMessageMap().putError("dataObject." + addressBos + "[0].defaultValue", OLEConstants.OlePatron.ERROR_PATRON_REQUIRED_ADDRESS_FROM_DATE, "ValidFrom"); 553 flag= false; 554 } 555 if(oleEntityAddressBo.getOleAddressBo().getAddressValidTo()==null && oleEntityAddressBo.getOleAddressBo().getAddressValidFrom()!=null){ 556 GlobalVariables.getMessageMap().putError("dataObject." + addressBos + "[0].defaultValue", OLEConstants.OlePatron.ERROR_PATRON_REQUIRED_ADDRESS_FROM_DATE, "ValidTo"); 557 flag= false; 558 } 559 for(Map.Entry<Date,Date> entry:map.entrySet()){ 560 if(entry.getKey()!=null&&entry.getValue()!=null&&oleEntityAddressBo.getOleAddressBo().getAddressValidFrom()!=null&&oleEntityAddressBo.getOleAddressBo().getAddressValidTo()!=null){ 561 if(oleEntityAddressBo.getOleAddressBo().getAddressValidFrom().compareTo(entry.getKey())>=0 && oleEntityAddressBo.getOleAddressBo().getAddressValidFrom().compareTo(entry.getValue())<=0 562 || oleEntityAddressBo.getOleAddressBo().getAddressValidTo().compareTo(entry.getKey())>=0 && oleEntityAddressBo.getOleAddressBo().getAddressValidTo().compareTo(entry.getValue())<=0){ 563 GlobalVariables.getMessageMap().putError("dataObject." + addressBos + "[0].defaultValue",OLEConstants.OlePatron.ERROR_PATRON_ADDRESS_FROM_TO_DATE_OVERLAP); 564 flag= false; 565 } 566 if(entry.getKey().compareTo(oleEntityAddressBo.getOleAddressBo().getAddressValidFrom())>=0 && entry.getKey().compareTo(oleEntityAddressBo.getOleAddressBo().getAddressValidTo())<=0 567 || entry.getValue().compareTo(oleEntityAddressBo.getOleAddressBo().getAddressValidFrom())>=0 && entry.getValue().compareTo(oleEntityAddressBo.getOleAddressBo().getAddressValidTo())<=0){ 568 GlobalVariables.getMessageMap().putError("dataObject." + addressBos + "[0].defaultValue", OLEConstants.OlePatron.ERROR_PATRON_ADDRESS_FROM_TO_DATE_OVERLAP); 569 flag= false; 570 } 571 } 572 } 573 }else if (oleEntityAddressBo.getOleAddressBo().getAddressValidFrom() != null || oleEntityAddressBo.getOleAddressBo().getAddressValidTo() != null) { 574 575 if (dateExist) { 576 dateExist = false; 577 } else { 578 GlobalVariables.getMessageMap().putError("dataObject." + addressBos + "[0].defaultValue", OLEConstants.OlePatron.ERROR_PATRON_ADDRESS_SINGLE_DATE); 579 flag= false; 580 } 581 } 582 map.put(oleEntityAddressBo.getOleAddressBo().getAddressValidFrom(),oleEntityAddressBo.getOleAddressBo().getAddressValidTo()); 583 } 584 if(!flag){ 585 return false; 586 } 587 return valid; 588 } 589 590 private UiDocumentService uiDocumentService; 591 /** 592 * Gets the value of uiDocumentService property 593 * 594 * @return uiDocumentService(UiDocumentService) 595 */ 596 public UiDocumentService getUIDocumentService() { 597 if (uiDocumentService == null) { 598 uiDocumentService = KIMServiceLocatorInternal.getUiDocumentService(); 599 } 600 return uiDocumentService; 601 } 602 603 protected boolean checkDuplicateBarcode(OlePatronDocument patronDoc) { 604 boolean valid = true; 605 Map barcodeMap = new HashMap(); 606 barcodeMap.put(OLEConstants.OlePatron.BARCODE, patronDoc.getBarcode()); 607 List<OlePatronDocument> olePatronDocuments = (List<OlePatronDocument>) KRADServiceLocator.getBusinessObjectService().findMatching(OlePatronDocument.class, barcodeMap); 608 if (olePatronDocuments.size() > 0) { 609 for (OlePatronDocument olePatronDocument : olePatronDocuments) { 610 if (patronDoc.getOlePatronId() == null || !(patronDoc.getOlePatronId().equals(olePatronDocument.getOlePatronId()))) { 611 GlobalVariables.getMessageMap().putErrorWithoutFullErrorPath(KRADConstants.GLOBAL_ERRORS, OLEConstants.OlePatron.PATRON_DUPLICATE_BARCODE); 612 valid = false; 613 } 614 } 615 } 616 return valid; 617 } 618 619 /** 620 * Gets the instance of BusinessObjectService 621 * 622 * @return businessObjectService(BusinessObjectService) 623 */ 624 public BusinessObjectService getBusinessObjectService() { 625 if (businessObjectService == null) { 626 businessObjectService = KRADServiceLocator.getBusinessObjectService(); 627 } 628 return businessObjectService; 629 } 630 631 public String getPatronPreferredAddress(EntityTypeContactInfoBo entityTypeContactInfoBo) throws Exception { 632 LOG.debug("Inside the getPatronPreferredAddress method"); 633 String address = ""; 634 if (entityTypeContactInfoBo.getAddresses() != null) { 635 for (int i = 0; i < entityTypeContactInfoBo.getAddresses().size(); i++) { 636 if (entityTypeContactInfoBo.getAddresses().get(i).isDefaultValue()) { 637 if (entityTypeContactInfoBo.getAddresses().get(i).getLine1() != null) 638 if (!entityTypeContactInfoBo.getAddresses().get(i).getLine1().isEmpty()) 639 address += entityTypeContactInfoBo.getAddresses().get(i).getLine1() + ","; 640 641 if (entityTypeContactInfoBo.getAddresses().get(i).getLine2() != null) 642 if (!entityTypeContactInfoBo.getAddresses().get(i).getLine2().isEmpty()) 643 address += entityTypeContactInfoBo.getAddresses().get(i).getLine2() + ","; 644 645 if (entityTypeContactInfoBo.getAddresses().get(i).getLine3() != null) 646 if (!entityTypeContactInfoBo.getAddresses().get(i).getLine3().isEmpty()) 647 address += entityTypeContactInfoBo.getAddresses().get(i).getLine3() + ","; 648 649 if (entityTypeContactInfoBo.getAddresses().get(i).getCity() != null) 650 if (!entityTypeContactInfoBo.getAddresses().get(i).getCity().isEmpty()) 651 address += entityTypeContactInfoBo.getAddresses().get(i).getCity() + ","; 652 653 if (entityTypeContactInfoBo.getAddresses().get(i).getStateProvinceCode() != null) 654 if (!entityTypeContactInfoBo.getAddresses().get(i).getStateProvinceCode().isEmpty()) 655 address += entityTypeContactInfoBo.getAddresses().get(i).getStateProvinceCode() + ","; 656 657 if (entityTypeContactInfoBo.getAddresses().get(i).getCountryCode() != null) 658 if (!entityTypeContactInfoBo.getAddresses().get(i).getCountryCode().isEmpty()) 659 address += entityTypeContactInfoBo.getAddresses().get(i).getCountryCode() + ","; 660 661 if (entityTypeContactInfoBo.getAddresses().get(i).getPostalCode() != null) 662 if (!entityTypeContactInfoBo.getAddresses().get(i).getPostalCode().isEmpty()) 663 address += entityTypeContactInfoBo.getAddresses().get(i).getPostalCode(); 664 } 665 } 666 } 667 668 return address; 669 } 670 671 public String getPatronHomePhoneNumber(EntityTypeContactInfoBo entityTypeContactInfoBo) throws Exception { 672 LOG.debug("Inside the getPatronHomePhoneNumber method"); 673 String phoneNumber = ""; 674 if (entityTypeContactInfoBo.getPhoneNumbers() != null) { 675 for (int j = 0; j < entityTypeContactInfoBo.getPhoneNumbers().size(); j++) { 676 if (entityTypeContactInfoBo.getPhoneNumbers().get(j).getPhoneTypeCode().equalsIgnoreCase("HM")) { 677 phoneNumber = (entityTypeContactInfoBo.getPhoneNumbers().get(j).getPhoneNumber()); 678 } 679 } 680 } 681 return phoneNumber; 682 } 683 684 public String getPatronHomeEmailId(EntityTypeContactInfoBo entityTypeContactInfoBo) throws Exception { 685 LOG.debug("Inside the getPatronHomeEmailId method"); 686 String emailId = ""; 687 if (entityTypeContactInfoBo.getEmailAddresses() != null) { 688 for (int j = 0; j < entityTypeContactInfoBo.getEmailAddresses().size(); j++) { 689 if (entityTypeContactInfoBo.getEmailAddresses().get(j).getDefaultValue()) { 690 emailId = (entityTypeContactInfoBo.getEmailAddresses().get(j).getEmailAddress()); 691 break; 692 } 693 } 694 } 695 return emailId; 696 } 697 698 699}