Search in sources :

Example 1 with PostalAddressType

use of oasis.names.tc.ebxml_regrep.xsd.rim._3.PostalAddressType in project ddf by codice.

the class PersonWebConverter method convert.

/**
     * This method creates a Map<String, Object> representation of the PersonType provided.
     * The following keys will be added to the map (Taken from EbrimConstants):
     * <p>
     * PERSON_NAME_KEY = "PersonName"
     * ADDRESS_KEY = "Address";
     * EMAIL_ADDRESS_KEY = "EmailAddress";
     * TELEPHONE_KEY = "TelephoneNumber";
     * <p>
     * This will also try to parse RegistryObjectType values to the map.
     * <p>
     * Uses:
     * PostalAddressWebConverter
     * EmailAddressWebConverter
     * TelephoneNumberWebConverter
     * PersonNameWebConverter
     *
     * @param person the PersonType to be converted into a map, null returns empty Map
     * @return Map<String, Object> representation of the PersonType provided
     */
public Map<String, Object> convert(PersonType person) {
    Map<String, Object> personMap = new HashMap<>();
    if (person == null) {
        return personMap;
    }
    webMapHelper.putAllIfNotEmpty(personMap, super.convertRegistryObject(person));
    if (person.isSetAddress()) {
        List<Map<String, Object>> addresses = new ArrayList<>();
        PostalAddressWebConverter addressConverter = new PostalAddressWebConverter();
        for (PostalAddressType address : person.getAddress()) {
            Map<String, Object> addressMap = addressConverter.convert(address);
            if (MapUtils.isNotEmpty(addressMap)) {
                addresses.add(addressMap);
            }
        }
        webMapHelper.putIfNotEmpty(personMap, ADDRESS_KEY, addresses);
    }
    if (person.isSetEmailAddress()) {
        List<Map<String, Object>> emailAddresses = new ArrayList<>();
        EmailAddressWebConverter emailConverter = new EmailAddressWebConverter();
        for (EmailAddressType email : person.getEmailAddress()) {
            Map<String, Object> emailMap = emailConverter.convert(email);
            if (MapUtils.isNotEmpty(emailMap)) {
                emailAddresses.add(emailMap);
            }
        }
        webMapHelper.putIfNotEmpty(personMap, EMAIL_ADDRESS_KEY, emailAddresses);
    }
    if (person.isSetPersonName()) {
        PersonNameWebConverter personNameConverter = new PersonNameWebConverter();
        Map<String, Object> personNameMap = personNameConverter.convert(person.getPersonName());
        webMapHelper.putIfNotEmpty(personMap, PERSON_NAME_KEY, personNameMap);
    }
    if (person.isSetTelephoneNumber()) {
        List<Map<String, Object>> telephoneNumbers = new ArrayList<>();
        TelephoneNumberWebConverter telephoneConverter = new TelephoneNumberWebConverter();
        for (TelephoneNumberType telephone : person.getTelephoneNumber()) {
            Map<String, Object> telephoneMap = telephoneConverter.convert(telephone);
            if (MapUtils.isNotEmpty(telephoneMap)) {
                telephoneNumbers.add(telephoneMap);
            }
        }
        webMapHelper.putIfNotEmpty(personMap, TELEPHONE_KEY, telephoneNumbers);
    }
    return personMap;
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) PostalAddressType(oasis.names.tc.ebxml_regrep.xsd.rim._3.PostalAddressType) TelephoneNumberType(oasis.names.tc.ebxml_regrep.xsd.rim._3.TelephoneNumberType) EmailAddressType(oasis.names.tc.ebxml_regrep.xsd.rim._3.EmailAddressType) Map(java.util.Map) HashMap(java.util.HashMap)

Example 2 with PostalAddressType

use of oasis.names.tc.ebxml_regrep.xsd.rim._3.PostalAddressType in project ddf by codice.

the class OrganizationWebConverter method convert.

/**
     * This method creates a Map<String, Object> representation of the OrganizationType provided.
     * The following keys will be added to the map (Taken from EbrimConstants):
     * <p>
     * PARENT = "parent";
     * PRIMARY_CONTACT = "primaryContact";
     * ADDRESS_KEY = "Address";
     * EMAIL_ADDRESS_KEY = "EmailAddress";
     * TELEPHONE_KEY = "TelephoneNumber";
     * <p>
     * This will also try to parse RegistryObjectType values to the map.
     * <p>
     * Uses:
     * PostalAddressWebConverter
     * EmailAddressWebConverter
     * TelephoneNumberWebConverter
     *
     * @param organization the OrganizationType to be converted into a map, null returns empty Map
     * @return Map<String, Object> representation of the OrganizationType provided
     */
public Map<String, Object> convert(OrganizationType organization) {
    Map<String, Object> organizationMap = new HashMap<>();
    if (organization == null) {
        return organizationMap;
    }
    webMapHelper.putAllIfNotEmpty(organizationMap, super.convertRegistryObject(organization));
    if (organization.isSetAddress()) {
        List<Map<String, Object>> addresses = new ArrayList<>();
        PostalAddressWebConverter addressConverter = new PostalAddressWebConverter();
        for (PostalAddressType address : organization.getAddress()) {
            Map<String, Object> addressMap = addressConverter.convert(address);
            if (MapUtils.isNotEmpty(addressMap)) {
                addresses.add(addressMap);
            }
        }
        webMapHelper.putIfNotEmpty(organizationMap, ADDRESS_KEY, addresses);
    }
    if (organization.isSetEmailAddress()) {
        List<Map<String, Object>> emailAddresses = new ArrayList<>();
        EmailAddressWebConverter emailConverter = new EmailAddressWebConverter();
        for (EmailAddressType email : organization.getEmailAddress()) {
            Map<String, Object> emailMap = emailConverter.convert(email);
            if (MapUtils.isNotEmpty(emailMap)) {
                emailAddresses.add(emailMap);
            }
        }
        webMapHelper.putIfNotEmpty(organizationMap, EMAIL_ADDRESS_KEY, emailAddresses);
    }
    webMapHelper.putIfNotEmpty(organizationMap, PARENT, organization.getParent());
    webMapHelper.putIfNotEmpty(organizationMap, PRIMARY_CONTACT, organization.getPrimaryContact());
    if (organization.isSetTelephoneNumber()) {
        List<Map<String, Object>> telephoneNumbers = new ArrayList<>();
        TelephoneNumberWebConverter telephoneConverter = new TelephoneNumberWebConverter();
        for (TelephoneNumberType telephone : organization.getTelephoneNumber()) {
            Map<String, Object> telephoneMap = telephoneConverter.convert(telephone);
            if (MapUtils.isNotEmpty(telephoneMap)) {
                telephoneNumbers.add(telephoneMap);
            }
        }
        webMapHelper.putIfNotEmpty(organizationMap, TELEPHONE_KEY, telephoneNumbers);
    }
    return organizationMap;
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) PostalAddressType(oasis.names.tc.ebxml_regrep.xsd.rim._3.PostalAddressType) TelephoneNumberType(oasis.names.tc.ebxml_regrep.xsd.rim._3.TelephoneNumberType) EmailAddressType(oasis.names.tc.ebxml_regrep.xsd.rim._3.EmailAddressType) Map(java.util.Map) HashMap(java.util.HashMap)

Example 3 with PostalAddressType

use of oasis.names.tc.ebxml_regrep.xsd.rim._3.PostalAddressType in project ddf by codice.

the class RegistryPackageWebConverterTest method getAddress.

private PostalAddressType getAddress(String city, String country, String zip, String state, String street, String streetNumber) {
    PostalAddressType address = RIM_FACTORY.createPostalAddressType();
    address.setCity(city);
    address.setCountry(country);
    address.setPostalCode(zip);
    address.setStateOrProvince(state);
    address.setStreet(street);
    address.setStreetNumber(streetNumber);
    return address;
}
Also used : PostalAddressType(oasis.names.tc.ebxml_regrep.xsd.rim._3.PostalAddressType)

Example 4 with PostalAddressType

use of oasis.names.tc.ebxml_regrep.xsd.rim._3.PostalAddressType in project ddf by codice.

the class RegistryPackageConverter method setMetacardAddressAttribute.

private static void setMetacardAddressAttribute(List<PostalAddressType> addresses, String metacardAttribute, MetacardImpl metacard) {
    if (CollectionUtils.isNotEmpty(addresses)) {
        StringBuilder addressString = new StringBuilder();
        PostalAddressType address = addresses.get(0);
        addressString = buildNonNullString(addressString, address.getStreet(), " ");
        addressString = buildNonNullString(addressString, address.getCity(), ", ");
        addressString = buildNonNullString(addressString, address.getStateOrProvince(), ", ");
        addressString = buildNonNullString(addressString, address.getPostalCode(), " ");
        addressString = buildNonNullString(addressString, address.getCountry(), ", ");
        if (StringUtils.isNotBlank(addressString.toString())) {
            metacard.setAttribute(metacardAttribute, addressString.toString());
        }
    }
}
Also used : PostalAddressType(oasis.names.tc.ebxml_regrep.xsd.rim._3.PostalAddressType)

Example 5 with PostalAddressType

use of oasis.names.tc.ebxml_regrep.xsd.rim._3.PostalAddressType in project ddf by codice.

the class RegistryPackageTypeHelperTest method assertPersons.

private void assertPersons(List<PersonType> persons) {
    // Values from xml file
    int expectedPersonsSize = 3;
    int expectedSize = 1;
    String expectedFirstName = "john";
    String expectedMiddleName = "middleName";
    String expectedLastname = "doe";
    String expectedCity = "Phoenix";
    String expectedCountry = "USA";
    String expectedPostalCode = "85037";
    String expectedState = "AZ";
    String expectedStreet = "1234 Some Street";
    String expectedAreaCode = "111";
    String expectedNumber = "111-1111";
    String expectedExtension = "1234";
    String expectedCountryCode = "country";
    String expectedPhoneType = "cell phone";
    String expectedEmail = "emailaddress@something.com";
    assertThat(persons, hasSize(expectedPersonsSize));
    PersonType person = persons.get(0);
    assertThat(person.isSetPersonName(), is(true));
    assertPersonName(person.getPersonName(), expectedFirstName, expectedMiddleName, expectedLastname);
    assertThat(person.isSetAddress(), is(true));
    List<PostalAddressType> addresses = person.getAddress();
    assertThat(addresses, hasSize(expectedSize));
    assertAddress(addresses.get(0), expectedCity, expectedCountry, expectedPostalCode, expectedState, expectedStreet);
    assertThat(person.isSetTelephoneNumber(), is(true));
    List<TelephoneNumberType> phoneNumbers = person.getTelephoneNumber();
    assertThat(phoneNumbers, hasSize(expectedSize));
    assertPhoneNumbers(phoneNumbers.get(0), expectedAreaCode, expectedNumber, expectedExtension, expectedCountryCode, expectedPhoneType);
    assertThat(person.isSetEmailAddress(), is(true));
    assertThat(person.getEmailAddress(), hasSize(expectedSize));
    List<EmailAddressType> emailAddresses = person.getEmailAddress();
    assertThat(emailAddresses.get(0).getAddress(), is(equalTo(expectedEmail)));
}
Also used : TelephoneNumberType(oasis.names.tc.ebxml_regrep.xsd.rim._3.TelephoneNumberType) PersonType(oasis.names.tc.ebxml_regrep.xsd.rim._3.PersonType) EmailAddressType(oasis.names.tc.ebxml_regrep.xsd.rim._3.EmailAddressType) PostalAddressType(oasis.names.tc.ebxml_regrep.xsd.rim._3.PostalAddressType)

Aggregations

PostalAddressType (oasis.names.tc.ebxml_regrep.xsd.rim._3.PostalAddressType)6 EmailAddressType (oasis.names.tc.ebxml_regrep.xsd.rim._3.EmailAddressType)4 TelephoneNumberType (oasis.names.tc.ebxml_regrep.xsd.rim._3.TelephoneNumberType)4 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2 OrganizationType (oasis.names.tc.ebxml_regrep.xsd.rim._3.OrganizationType)1 PersonType (oasis.names.tc.ebxml_regrep.xsd.rim._3.PersonType)1