1 56 package org.opencrx.kernel.layer.application; 57 58 import java.io.BufferedReader ; 59 import java.io.ByteArrayInputStream ; 60 import java.io.ByteArrayOutputStream ; 61 import java.io.IOException ; 62 import java.io.InputStream ; 63 import java.io.InputStreamReader ; 64 import java.io.PrintWriter ; 65 import java.util.ArrayList ; 66 import java.util.Date ; 67 import java.util.HashMap ; 68 import java.util.Iterator ; 69 import java.util.List ; 70 import java.util.Map ; 71 import java.util.SortedMap ; 72 import java.util.StringTokenizer ; 73 import java.util.Map.Entry; 74 75 import org.openmdx.application.log.AppLog; 76 import org.openmdx.base.exception.ServiceException; 77 import org.openmdx.base.text.format.DateFormat; 78 import org.openmdx.compatibility.base.dataprovider.cci.AttributeSelectors; 79 import org.openmdx.compatibility.base.dataprovider.cci.DataproviderObject; 80 import org.openmdx.compatibility.base.dataprovider.cci.DataproviderObject_1_0; 81 import org.openmdx.compatibility.base.dataprovider.cci.Directions; 82 import org.openmdx.compatibility.base.dataprovider.cci.RequestCollection; 83 import org.openmdx.compatibility.base.dataprovider.cci.SystemAttributes; 84 import org.openmdx.compatibility.base.naming.Path; 85 import org.openmdx.compatibility.base.query.FilterOperators; 86 import org.openmdx.compatibility.base.query.FilterProperty; 87 import org.openmdx.compatibility.base.query.Quantors; 88 import org.openmdx.kernel.id.UUIDs; 89 90 public class VCard { 91 92 public VCard( 94 OpenCrxKernel_1 plugin, 95 RequestCollection delegation, 96 Codes codes 97 ) { 98 this.plugin = plugin; 99 this.delegation = delegation; 100 this.codes = codes; 101 } 102 103 private Short numberAsShort( 105 Object number 106 ) { 107 return new Short (((Number )number).shortValue()); 108 } 109 110 public byte[] exportItem( 112 DataproviderObject_1_0 contact, 113 short locale 114 ) throws ServiceException { 115 AppLog.trace("inspecting contact", contact); 116 117 String lastName = contact.values("lastName").size() == 0 ? "" : (String )contact.values("lastName").get(0); 118 String firstName = contact.values("firstName").size() == 0 ? "" : (String )contact.values("firstName").get(0); 119 String middleName = contact.values("middleName").size() == 0 ? "" : (String )contact.values("middleName").get(0); 120 String salutation = contact.values("salutation").size() == 0 ? "" : (String )contact.values("salutation").get(0); 121 String suffix = contact.values("suffix").size() == 0 ? "" : (String )contact.values("suffix").get(0); 122 String jobTitle = contact.values("jobTitle").size() == 0 ? "" : (String )contact.values("jobTitle").get(0); 123 String organization = contact.values("organization").size() == 0 ? "" : (String )contact.values("organization").get(0); 124 List addresses = this.delegation.addFindRequest( 125 contact.path().getChild("address"), 126 null, 127 AttributeSelectors.ALL_ATTRIBUTES, 128 0, 129 Integer.MAX_VALUE, 130 Directions.ASCENDING 131 ); 132 String telWorkVoice = ""; 133 String telHomeVoice = ""; 134 String telCellVoice = ""; 135 String telWorkFax = ""; 136 String telHomeFax = ""; 137 String telPrimary = ""; 138 String adrWork = ""; 139 String adrHome = ""; 140 String urlHome = ""; 141 String urlWork = ""; 142 String emailPrefInternet = ""; 143 144 for(Iterator i = addresses.iterator(); i.hasNext(); ) { 145 146 DataproviderObject_1_0 address = (DataproviderObject_1_0)i.next(); 147 AppLog.trace("inspecting address", address); 148 String addressClass = (String )address.values(SystemAttributes.OBJECT_CLASS).get(0); 149 List usage = new ArrayList (); 150 for(Iterator j = address.values("usage").iterator(); j.hasNext(); ) { 151 usage.add( 152 this.numberAsShort(j.next()) 153 ); 154 } 155 if("org:opencrx:kernel:account1:PostalAddress".equals(addressClass)) { 156 String adr = ""; 157 List addressLines = address.values("postalAddressLine"); 159 for(int j = 0; j < addressLines.size(); j++) { 160 adr += adr.length() == 0 ? "" : "=0D=0A"; 161 adr += addressLines.get(j); 162 } 163 List postalStreet = address.values("postalStreet"); 165 for(int j = 0; j < postalStreet.size(); j++) { 166 adr += adr.length() == 0 ? "" : "=0D=0A"; 167 adr += postalStreet.get(j); 168 } 169 adr += address.values("postalCity").size() == 0 171 ? ";" 172 : ";" + (String )address.values("postalCity").get(0); 173 adr += ";"; 175 adr += address.values("postalCode").size() == 0 176 ? ";" 177 : ";" + (String )address.values("postalCode").get(0); 178 Map postalCountries = this.codes.getLongText("org:opencrx:kernel:address1:PostalAddressable:postalCountry", locale, true); 180 adr += address.values("postalCountry").size() == 0 181 ? ";" 182 : ";" + (String )postalCountries.get(this.numberAsShort(address.values("postalCountry").get(0))); 183 184 if(usage.contains(USAGE_POSTAL_HOME)) { 186 adrHome = adr; 187 } 188 else if(usage.contains(USAGE_POSTAL_WORK)) { 190 adrWork = adr; 191 } 192 } 193 else if("org:opencrx:kernel:account1:EMailAddress".equals(addressClass)) { 194 if(usage.contains(USAGE_EMAIL_PRIMARY)) { 196 emailPrefInternet = address.values("emailAddress").size() == 0 197 ? "" 198 : (String )address.values("emailAddress").get(0); 199 } 200 } 201 else if("org:opencrx:kernel:account1:PhoneNumber".equals(addressClass)) { 202 String phoneNumberFull = 203 address.values("phoneNumberFull").size() == 0 204 ? "" 205 : (String )address.values("phoneNumberFull").get(0); 206 if(usage.contains(USAGE_PHONE_HOME)) { 208 telHomeVoice = phoneNumberFull; 209 } 210 else if(usage.contains(USAGE_PHONE_WORK)) { 212 telWorkVoice = phoneNumberFull; 213 } 214 else if(usage.contains(USAGE_FAX_HOME)) { 216 telHomeFax = phoneNumberFull; 217 } 218 else if(usage.contains(USAGE_FAX_WORK)) { 220 telWorkFax = phoneNumberFull; 221 } 222 else if(usage.contains(USAGE_MOBILE)) { 224 telCellVoice = phoneNumberFull; 225 } 226 else if(usage.contains(USAGE_PHONE_PRIMARY)) { 228 telPrimary = phoneNumberFull; 229 } 230 } 231 else if("org:opencrx:kernel:account1:WebAddress".equals(addressClass)) { 232 String webUrl = 233 address.values("webUrl").size() == 0 234 ? "" 235 : (String )address.values("webUrl").get(0); 236 if(usage.contains(USAGE_WEB_HOME)) { 238 urlHome = webUrl; 239 } 240 else if(usage.contains(USAGE_WEB_WORK)) { 242 urlWork = webUrl; 243 } 244 } 245 } 246 247 ByteArrayOutputStream os = new ByteArrayOutputStream (); 248 PrintWriter pw = new PrintWriter (os); 249 pw.println("BEGIN:VCARD"); 250 pw.println("VERSION:2.1"); 251 pw.println("N:" + lastName + ";" + firstName + ";"+ middleName + ";" + salutation + ";" + suffix); 252 pw.println("FN:" + firstName + (middleName.length() == 0 ? "" : " " + middleName) + (lastName.length() == 0 ? "" : " " + lastName) + (suffix.length() == 0 ? "" : " " + suffix)); 253 pw.println("ORG:" + organization); 254 pw.println("TITLE:" + jobTitle); 255 pw.println("TEL;WORK;VOICE:" + telWorkVoice); 256 pw.println("TEL;HOME;VOICE:" + telHomeVoice); 257 pw.println("TEL;CELL;VOICE:" + telCellVoice); 258 pw.println("TEL;WORK;FAX:" + telWorkFax); 259 pw.println("TEL;HOME;FAX:" + telHomeFax); 260 pw.println("TEL;PREF:" + telPrimary); 261 pw.println("ADR;WORK;ENCODING=QUOTED-PRINTABLE:;;" + adrWork); 262 pw.println("ADR;HOME;ENCODING=QUOTED-PRINTABLE:;;" + adrHome); 263 pw.println("URL;HOME:" + urlHome); 264 pw.println("URL;WORK:" + urlWork); 265 pw.println("EMAIL;PREF;INTERNET:" + emailPrefInternet); 266 pw.println("REV:" + DateFormat.getInstance().format(new Date ())); 267 pw.println("END:VCARD"); 268 try { 269 pw.flush(); 270 os.close(); 271 } catch(Exception e) {} 272 return os.toByteArray(); 273 } 274 275 private boolean updatePostalAddress( 277 DataproviderObject address, 278 String newValue, 279 short locale 280 ) throws ServiceException { 281 if((newValue != null) && (newValue.length() > 0)) { 282 String [] tokens = new String []{"", "", "", "", "", "", ""}; 283 StringTokenizer tokenizer = new StringTokenizer (newValue, ";", true); 284 int ii = 0; 285 boolean hasTokens = false; 286 while(tokenizer.hasMoreTokens() && (ii < tokens.length)) { 287 String t = tokenizer.nextToken(); 288 if(";".equals(t)) { 289 ii++; 290 } 291 else { 292 tokens[ii] = t; 293 hasTokens = true; 294 } 295 } 296 if(!hasTokens) { 297 return false; 298 } 299 List street = new ArrayList (); 301 String temp = tokens[2]; 302 int pos = 0; 303 while((pos = temp.indexOf("=0D=0A")) >= 0) { 304 street.add(temp.substring(0, pos)); 305 temp = temp.substring(pos + 6); 306 } 307 street.add(temp); 308 address.clearValues("postalAddressLine"); 309 for(int i = 0; i < street.size()-1; i++) { 310 address.values("postalAddressLine").add(street.get(i)); 311 } 312 address.clearValues("postalStreet").add(street.get(street.size()-1)); 313 address.clearValues("postalCity").add(tokens[3]); 314 address.clearValues("postalState").add(tokens[4]); 315 address.clearValues("postalCode").add(tokens[5]); 316 address.clearValues("postalCountry").add(new Short ((short)0)); 317 318 AppLog.trace("lookup country", tokens[6]); 320 SortedMap countries = this.codes.getLongText("org:opencrx:kernel:address1:PostalAddressable:postalCountry", locale, true); 321 if(countries != null) { 322 for(Iterator i = countries.entrySet().iterator(); i.hasNext(); ) { 323 Entry entry = (Entry)i.next(); 324 if(((String )entry.getValue()).indexOf(tokens[6]) >= 0) { 325 address.clearValues("postalCountry").add( 326 entry.getKey() 327 ); 328 break; 329 } 330 } 331 } 332 AppLog.trace("updated address", address); 333 return true; 334 } 335 return false; 336 } 337 338 private boolean updatePhoneNumber( 340 DataproviderObject address, 341 String newValue 342 ) throws ServiceException { 343 if((newValue != null) && (newValue.length() > 0)) { 344 address.clearValues("phoneNumberFull").add(newValue); 345 address.clearValues("automaticParsing").add(Boolean.TRUE); 346 this.plugin.parsePhoneNumber(address, null); 347 AppLog.trace("updated address", address); 348 return true; 349 } 350 return false; 351 } 352 353 private boolean updateWebAddress( 355 DataproviderObject address, 356 String newValue 357 ) { 358 if((newValue != null) && (newValue.length() > 0)) { 359 address.clearValues("webUrl").add(newValue); 360 AppLog.trace("updated address", address); 361 return true; 362 } 363 return false; 364 } 365 366 private boolean updateEMailAddress( 368 DataproviderObject address, 369 String newValue 370 ) { 371 if((newValue != null) && (newValue.length() > 0)) { 372 address.clearValues("emailAddress").add(newValue); 373 AppLog.trace("updated address", address); 374 return true; 375 } 376 return false; 377 } 378 379 public DataproviderObject importItem( 381 byte[] item, 382 Path segmentPath, 383 short locale, 384 List report 385 ) throws ServiceException { 386 try { 387 InputStream is = new ByteArrayInputStream (item); 389 BufferedReader reader = new BufferedReader (new InputStreamReader (is)); 390 Map data = new HashMap (); 391 String line = null; 392 boolean lineCont = false; 393 String currentName = null; 394 while((line = reader.readLine()) != null) { 395 if(lineCont) { 396 data.put( 397 currentName, 398 data.get(currentName) + line 399 ); 400 lineCont = false; 401 } 402 else if(line.indexOf(":") >= 0) { 403 int pos = line.indexOf(":"); 404 currentName = line.substring(0, pos).toUpperCase(); 405 lineCont = (currentName.indexOf("ENCODING=QUOTED-PRINTABLE") >= 0) && line.endsWith("="); 406 data.put( 407 currentName, 408 line.substring(pos + 1, lineCont ? line.length() - 1 : line.length()) 409 ); 410 } 411 } 412 AppLog.trace("parsed vcard", data); 413 return this.importItem( 414 data, 415 segmentPath, 416 locale, 417 false, 418 report 419 ); 420 } 421 catch(IOException e) { 422 AppLog.warning("can not read item", e.getMessage()); 423 } 424 return null; 425 } 426 427 435 public DataproviderObject importItem( 436 Map vcard, 437 Path segmentPath, 438 short locale, 439 boolean createOnly, 440 List report 441 ) throws ServiceException { 442 String emailPrefInternet = (String )vcard.get("EMAIL;PREF;INTERNET"); 443 DataproviderObject contact = null; 444 if((emailPrefInternet != null) && (emailPrefInternet.length() > 0)) { 445 AppLog.trace("looking up", emailPrefInternet); 446 List addresses = this.delegation.addFindRequest( 447 segmentPath.getChild("extent"), 448 new FilterProperty[]{ 449 new FilterProperty( 450 Quantors.THERE_EXISTS, 451 "identity", 452 FilterOperators.IS_LIKE, 453 new String []{ 454 segmentPath.getDescendant(new String []{"account", ":*", "address", ":*"}).toXri() 455 } 456 ), 457 new FilterProperty( 458 Quantors.THERE_EXISTS, 459 SystemAttributes.OBJECT_CLASS, 460 FilterOperators.IS_IN, 461 new String []{ 462 "org:opencrx:kernel:account1:EMailAddress" 463 } 464 ), 465 new FilterProperty( 466 Quantors.THERE_EXISTS, 467 "emailAddress", 468 FilterOperators.IS_IN, 469 new String []{ 470 emailPrefInternet 471 } 472 ) 473 } 474 ); 475 if(addresses.iterator().hasNext()) { 476 AppLog.trace("address found"); 477 DataproviderObject_1_0 address = (DataproviderObject_1_0)addresses.iterator().next(); 478 contact = this.plugin.retrieveObjectForModification( 479 address.path().getParent().getParent() 480 ); 481 } 482 } 483 AppLog.trace("account", contact); 484 485 boolean isNew = contact == null; 486 if(isNew) { 487 contact = new DataproviderObject( 488 segmentPath.getDescendant(new String []{"account", UUIDs.getGenerator().next().toString()}) 489 ); 490 contact.values(SystemAttributes.OBJECT_CLASS).add( 491 "org:opencrx:kernel:account1:Contact" 492 ); 493 } 494 if("org:opencrx:kernel:account1:Contact".equals(contact.values(SystemAttributes.OBJECT_CLASS).get(0))) { 495 496 499 String name = (String )vcard.get("N"); 501 if((name != null) && (name.indexOf(";") >= 0)) { 502 String [] tokens = new String []{"", "", "", "", ""}; 503 StringTokenizer tokenizer = new StringTokenizer (name, ";", true); 504 int ii = 0; 505 while(tokenizer.hasMoreTokens() && (ii < tokens.length)) { 506 String t = tokenizer.nextToken(); 507 if(";".equals(t)) { 508 ii++; 509 } 510 else { 511 tokens[ii] = t; 512 } 513 } 514 if(tokens[0].length() > 0) { 516 contact.clearValues("lastName").add(tokens[0]); 517 } 518 else if(contact.values("lastName").size() == 0) { 519 contact.values("lastName").add("N/A"); 520 } 521 if(tokens[1].length() > 0) { 523 contact.clearValues("firstName").add(tokens[1]); 524 } 525 if(tokens[2].length() > 0) { 527 contact.clearValues("middleName").add(tokens[2]); 528 } 529 if(tokens[3].length() > 0) { 531 contact.clearValues("salutation").add(tokens[3]); 532 } 533 if(tokens[4].length() > 0) { 535 contact.clearValues("suffix").add(tokens[4]); 536 } 537 } 538 String jobTitle = (String )vcard.get("TITLE"); 540 if((jobTitle != null) && (jobTitle.length() > 0)) { 541 contact.clearValues("jobTitle").add(jobTitle); 542 } 543 String organization = (String )vcard.get("ORG"); 545 if((organization != null) && (organization.length() > 0)) { 546 contact.clearValues("organization").add(organization); 547 } 548 this.plugin.accounts.setAccountFullName(contact, null); 549 if(isNew) { 550 AppLog.trace("adding", contact); 551 this.delegation.addCreateRequest( 552 contact 553 ); 554 report.add("Create contact"); 555 } 556 else if(!createOnly) { 557 AppLog.trace("updating", contact); 558 report.add("Update contact"); 559 } 560 } 561 String s = vcard.get("NOTE") != null ? (String )vcard.get("NOTE") : (String )vcard.get("NOTE;ENCODING=QUOTED-PRINTABLE"); 563 if(s != null) { 564 DataproviderObject note = null; 565 isNew = false; 566 try { 567 note = this.plugin.retrieveObjectForModification( 568 contact.path().getDescendant(new String []{"note", "VCARD"}) 569 ); 570 } 571 catch(Exception e) {} 572 if(note == null) { 573 note = new DataproviderObject(contact.path().getDescendant(new String []{"note", "VCARD"})); 574 note.values(SystemAttributes.OBJECT_CLASS).add("org:opencrx:kernel:generic:Note"); 575 isNew = true; 576 } 577 note.clearValues("title").add("vCard note"); 578 String text = ""; 579 int pos = 0; 580 while((pos = s.indexOf("=0D=0A")) >= 0) { 581 text += s.substring(0, pos) + "\n"; 582 s = s.substring(pos + 6); 583 } 584 note.clearValues("text").add(text); 585 if(isNew) { 586 this.delegation.addCreateRequest( 587 note 588 ); 589 report.add("Create note"); 590 } 591 else if(!createOnly) { 592 report.add("Update note"); 593 } 594 } 595 596 List addresses = this.delegation.addFindRequest( 598 contact.path().getChild("address"), 599 null, 600 AttributeSelectors.ALL_ATTRIBUTES, 601 0, 602 Integer.MAX_VALUE, 603 Directions.ASCENDING 604 ); 605 606 DataproviderObject adrHome = null; 607 DataproviderObject adrWork = null; 608 DataproviderObject telPrimary = null; 609 DataproviderObject telHomeVoice = null; 610 DataproviderObject telWorkVoice = null; 611 DataproviderObject telHomeFax = null; 612 DataproviderObject telWorkFax = null; 613 DataproviderObject urlHome = null; 614 DataproviderObject urlWork = null; 615 DataproviderObject telCellVoice = null; 616 DataproviderObject emailPrimary = null; 617 618 for(Iterator i = addresses.iterator(); i.hasNext(); ) { 620 DataproviderObject address = new DataproviderObject((DataproviderObject_1_0)i.next()); 621 String addressClass = (String )address.values(SystemAttributes.OBJECT_CLASS).get(0); 622 List usage = new ArrayList (); 623 for(Iterator j = address.values("usage").iterator(); j.hasNext(); ) { 624 usage.add( 625 this.numberAsShort(j.next()) 626 ); 627 } 628 if("org:opencrx:kernel:account1:PostalAddress".equals(addressClass)) { 629 if(usage.contains(USAGE_POSTAL_HOME)) { 630 adrHome = this.plugin.retrieveObjectForModification(address.path()); 631 } 632 else if(usage.contains(USAGE_POSTAL_WORK)) { 633 adrWork = this.plugin.retrieveObjectForModification(address.path()); 634 } 635 } 636 else if("org:opencrx:kernel:account1:EMailAddress".equals(addressClass)) { 637 if(usage.contains(USAGE_EMAIL_PRIMARY)) { 638 emailPrimary = this.plugin.retrieveObjectForModification(address.path()); 639 } 640 } 641 else if("org:opencrx:kernel:account1:PhoneNumber".equals(addressClass)) { 642 if(usage.contains(USAGE_PHONE_HOME)) { 643 telHomeVoice = this.plugin.retrieveObjectForModification(address.path()); 644 } 645 else if(usage.contains(USAGE_PHONE_WORK)) { 647 telWorkVoice = this.plugin.retrieveObjectForModification(address.path()); 648 } 649 else if(usage.contains(USAGE_FAX_HOME)) { 651 telHomeFax = this.plugin.retrieveObjectForModification(address.path()); 652 } 653 else if(usage.contains(USAGE_FAX_WORK)) { 655 telWorkFax = this.plugin.retrieveObjectForModification(address.path()); 656 } 657 else if(usage.contains(USAGE_MOBILE)) { 659 telCellVoice = this.plugin.retrieveObjectForModification(address.path()); 660 } 661 else if(usage.contains(USAGE_PHONE_PRIMARY)) { 663 telPrimary = this.plugin.retrieveObjectForModification(address.path()); 664 } 665 } 666 else if("org:opencrx:kernel:account1:WebAddress".equals(addressClass)) { 667 if(usage.contains(USAGE_WEB_HOME)) { 668 urlHome = this.plugin.retrieveObjectForModification(address.path()); 669 } 670 else if(usage.contains(USAGE_WEB_WORK)) { 672 urlWork = this.plugin.retrieveObjectForModification(address.path()); 673 } 674 } 675 } 676 isNew = false; 678 if(adrHome == null) { 679 adrHome = new DataproviderObject(contact.path().getDescendant(new String []{"address", UUIDs.getGenerator().next().toString()})); 680 adrHome.values(SystemAttributes.OBJECT_CLASS).add("org:opencrx:kernel:account1:PostalAddress"); 681 adrHome.values("usage").add(USAGE_POSTAL_HOME); 682 isNew = true; 683 } 684 s = vcard.get("ADR;HOME") != null ? (String )vcard.get("ADR;HOME") : (String )vcard.get("ADR;HOME;ENCODING=QUOTED-PRINTABLE"); 685 if(this.updatePostalAddress(adrHome, s, locale)) { 686 if(isNew) { 687 this.delegation.addCreateRequest(adrHome); 688 report.add("Create postal address"); 689 } 690 else if(!createOnly) { 691 report.add("Update postal address"); 692 } 693 } 694 isNew = false; 696 if(adrWork == null) { 697 adrWork = new DataproviderObject(contact.path().getDescendant(new String []{"address", UUIDs.getGenerator().next().toString()})); 698 adrWork.values(SystemAttributes.OBJECT_CLASS).add("org:opencrx:kernel:account1:PostalAddress"); 699 adrWork.values("usage").add(USAGE_POSTAL_WORK); 700 isNew = true; 701 } 702 s = vcard.get("ADR;WORK") != null ? (String )vcard.get("ADR;WORK") : (String )vcard.get("ADR;WORK;ENCODING=QUOTED-PRINTABLE"); 703 if(this.updatePostalAddress(adrWork, s, locale)) { 704 if(isNew) { 705 this.delegation.addCreateRequest(adrWork); 706 report.add("Create postal address"); 707 } 708 else if(!createOnly) { 709 report.add("Update postal address"); 710 } 711 } 712 isNew = false; 714 if(telPrimary == null) { 715 telPrimary = new DataproviderObject(contact.path().getDescendant(new String []{"address", UUIDs.getGenerator().next().toString()})); 716 telPrimary.values(SystemAttributes.OBJECT_CLASS).add("org:opencrx:kernel:account1:PhoneNumber"); 717 telPrimary.values("usage").add(USAGE_PHONE_PRIMARY); 718 isNew = true; 719 } 720 if(this.updatePhoneNumber(telPrimary, (String )vcard.get("TEL;PREF"))) { 721 if(isNew) { 722 this.delegation.addCreateRequest(telPrimary); 723 report.add("Create phone number"); 724 } 725 else if(!createOnly ) { 726 report.add("Update phone number"); 727 } 728 } 729 isNew = false; 731 if(telHomeVoice == null) { 732 telHomeVoice = new DataproviderObject(contact.path().getDescendant(new String []{"address", UUIDs.getGenerator().next().toString()})); 733 telHomeVoice.values(SystemAttributes.OBJECT_CLASS).add("org:opencrx:kernel:account1:PhoneNumber"); 734 telHomeVoice.values("usage").add(USAGE_PHONE_HOME); 735 isNew = true; 736 } 737 if(this.updatePhoneNumber(telHomeVoice, (String )vcard.get("TEL;HOME;VOICE"))) { 738 if(isNew) { 739 this.delegation.addCreateRequest(telHomeVoice); 740 report.add("Create phone number"); 741 } 742 else if(!createOnly) { 743 report.add("Update phone number"); 744 } 745 } 746 isNew = false; 748 if(telWorkVoice == null) { 749 telWorkVoice = new DataproviderObject(contact.path().getDescendant(new String []{"address", UUIDs.getGenerator().next().toString()})); 750 telWorkVoice.values(SystemAttributes.OBJECT_CLASS).add("org:opencrx:kernel:account1:PhoneNumber"); 751 telWorkVoice.values("usage").add(USAGE_PHONE_WORK); 752 isNew = true; 753 } 754 if(this.updatePhoneNumber(telWorkVoice, (String )vcard.get("TEL;WORK;VOICE"))) { 755 if(isNew) { 756 this.delegation.addCreateRequest(telWorkVoice); 757 report.add("Create phone number"); 758 } 759 else if(!createOnly) { 760 report.add("Update phone number"); 761 } 762 } 763 isNew = false; 765 if(telHomeFax == null) { 766 telHomeFax = new DataproviderObject(contact.path().getDescendant(new String []{"address", UUIDs.getGenerator().next().toString()})); 767 telHomeFax.values(SystemAttributes.OBJECT_CLASS).add("org:opencrx:kernel:account1:PhoneNumber"); 768 telHomeFax.values("usage").add(USAGE_FAX_HOME); 769 isNew = true; 770 } 771 if(this.updatePhoneNumber(telHomeFax, (String )vcard.get("TEL;HOME;FAX"))) { 772 if(isNew) { 773 this.delegation.addCreateRequest(telHomeFax); 774 report.add("Create phone number"); 775 } 776 else if(!createOnly) { 777 report.add("Update phone number"); 778 } 779 } 780 isNew = false; 782 if(telWorkFax == null) { 783 telWorkFax = new DataproviderObject(contact.path().getDescendant(new String []{"address", UUIDs.getGenerator().next().toString()})); 784 telWorkFax.values(SystemAttributes.OBJECT_CLASS).add("org:opencrx:kernel:account1:PhoneNumber"); 785 telWorkFax.values("usage").add(USAGE_FAX_WORK); 786 isNew = true; 787 } 788 if(this.updatePhoneNumber(telWorkFax, (String )vcard.get("TEL;WORK;FAX"))) { 789 if(isNew) { 790 this.delegation.addCreateRequest(telWorkFax); 791 report.add("Create phone number"); 792 } 793 else if(!createOnly) { 794 report.add("Update phone number"); 795 } 796 } 797 isNew = false; 799 if(telCellVoice == null) { 800 telCellVoice = new DataproviderObject(contact.path().getDescendant(new String []{"address", UUIDs.getGenerator().next().toString()})); 801 telCellVoice.values(SystemAttributes.OBJECT_CLASS).add("org:opencrx:kernel:account1:PhoneNumber"); 802 telCellVoice.values("usage").add(USAGE_MOBILE); 803 isNew = true; 804 } 805 if(this.updatePhoneNumber(telCellVoice, (String )vcard.get("TEL;CELL;VOICE"))) { 806 if(isNew) { 807 this.delegation.addCreateRequest(telCellVoice); 808 report.add("Create phone number"); 809 } 810 else if(!createOnly) { 811 report.add("Update phone number"); 812 } 813 } 814 isNew = false; 816 if(urlHome == null) { 817 urlHome = new DataproviderObject(contact.path().getDescendant(new String []{"address", UUIDs.getGenerator().next().toString()})); 818 urlHome.values(SystemAttributes.OBJECT_CLASS).add("org:opencrx:kernel:account1:WebAddress"); 819 urlHome.values("usage").add(USAGE_WEB_HOME); 820 isNew = true; 821 } 822 if(this.updateWebAddress(urlHome, (String )vcard.get("URL;HOME"))) { 823 if(isNew) { 824 this.delegation.addCreateRequest(urlHome); 825 report.add("Create web address"); 826 } 827 else if(!createOnly) { 828 report.add("Update web address"); 829 } 830 } 831 isNew = false; 833 if(urlWork == null) { 834 urlWork = new DataproviderObject(contact.path().getDescendant(new String []{"address", UUIDs.getGenerator().next().toString()})); 835 urlWork.values(SystemAttributes.OBJECT_CLASS).add("org:opencrx:kernel:account1:WebAddress"); 836 urlWork.values("usage").add(USAGE_WEB_WORK); 837 isNew = true; 838 } 839 if(this.updateWebAddress(urlWork, (String )vcard.get("URL;WORK"))) { 840 if(isNew) { 841 this.delegation.addCreateRequest(urlWork); 842 report.add("Create web address"); 843 } 844 else if(!createOnly) { 845 report.add("Update web address"); 846 } 847 } 848 isNew = false; 850 if(emailPrimary == null) { 851 emailPrimary = new DataproviderObject(contact.path().getDescendant(new String []{"address", UUIDs.getGenerator().next().toString()})); 852 emailPrimary.values(SystemAttributes.OBJECT_CLASS).add("org:opencrx:kernel:account1:EMailAddress"); 853 emailPrimary.values("usage").add(USAGE_EMAIL_PRIMARY); 854 isNew = true; 855 } 856 s = vcard.get("EMAIL;PREF;INTERNET") != null ? (String )vcard.get("EMAIL;PREF;INTERNET") : (String )vcard.get("EMAIL;INTERNET"); 857 if(this.updateEMailAddress(emailPrimary, s)) { 858 if(isNew) { 859 this.delegation.addCreateRequest(emailPrimary); 860 report.add("Create email address"); 861 } 862 else if(!createOnly) { 863 report.add("Update email address"); 864 } 865 } 866 return contact; 867 } 868 869 public static final String MIME_TYPE = "text/x-vcard"; 873 public static final int MIME_TYPE_CODE = 3; 874 875 static private final Short USAGE_EMAIL_PRIMARY = new Short ((short)300); 876 static private final Short USAGE_POSTAL_HOME = new Short ((short)400); 877 static private final Short USAGE_POSTAL_WORK = new Short ((short)500); 878 static private final Short USAGE_PHONE_PRIMARY = new Short ((short)300); 879 static private final Short USAGE_PHONE_HOME =new Short ((short)400); 880 static private final Short USAGE_PHONE_WORK = new Short ((short)500); 881 static private final Short USAGE_FAX_HOME = new Short ((short)430); 882 static private final Short USAGE_FAX_WORK = new Short ((short)530); 883 static private final Short USAGE_MOBILE = new Short ((short)200); 884 static private final Short USAGE_WEB_HOME = new Short ((short)400); 885 static private final Short USAGE_WEB_WORK = new Short ((short)500); 886 887 private final OpenCrxKernel_1 plugin; 888 private final RequestCollection delegation; 889 private final Codes codes; 890 891 } 892 893 | Popular Tags |