Search in sources :

Example 6 with ScimPersonAddresses

use of org.gluu.oxtrust.model.scim.ScimPersonAddresses in project oxTrust by GluuFederation.

the class CopyUtilsTestUpdate method testCopyScim1FilledMultipleAttributesUpdate.

@Test
public void testCopyScim1FilledMultipleAttributesUpdate() throws Exception {
    GluuCustomPerson destination = new GluuCustomPerson();
    ScimPerson source = new ScimPerson();
    source.setActive("true");
    ScimPersonAddresses address = new ScimPersonAddresses();
    address.setCountry("country");
    address.setFormatted("formatted");
    address.setLocality("locality");
    address.setPostalCode("postalCode");
    address.setPrimary("address_primary");
    address.setRegion("region");
    address.setStreetAddress("streetAddress");
    address.setType("address_type");
    List<ScimPersonAddresses> addresses = new ArrayList<ScimPersonAddresses>();
    addresses.add(address);
    source.setAddresses(addresses);
    List<ScimCustomAttributes> customAttributes = new ArrayList<ScimCustomAttributes>();
    ScimCustomAttributes customattribute = new ScimCustomAttributes();
    customattribute.setName("custom_name");
    List<String> values = new ArrayList<String>();
    values.add("value1");
    values.add("value3");
    values.add("value2");
    values.add("value4");
    customattribute.setValues(values);
    customAttributes.add(customattribute);
    source.setCustomAttributes(customAttributes);
    source.setDisplayName("displayName");
    ScimPersonEmails email = new ScimPersonEmails();
    email.setPrimary("email_primary");
    email.setType("email_type");
    email.setValue("email_value");
    List<ScimPersonEmails> emails = new ArrayList<ScimPersonEmails>();
    emails.add(email);
    source.setEmails(emails);
    ScimEntitlements entitlement = new ScimEntitlements();
    entitlement.setValue("entitlement_value");
    List<ScimEntitlements> entitlements = new ArrayList<ScimEntitlements>();
    entitlements.add(entitlement);
    source.setEntitlements(entitlements);
    source.setExternalId("externalId");
    ScimPersonGroups group1 = new ScimPersonGroups();
    group1.setDisplay("group_display");
    group1.setValue("group_value");
    ScimPersonGroups group2 = new ScimPersonGroups();
    group2.setDisplay("group_display1");
    group2.setValue("group_value1");
    List<ScimPersonGroups> groups = new ArrayList<ScimPersonGroups>();
    groups.add(group1);
    groups.add(group2);
    source.setGroups(groups);
    source.setId("id");
    ScimPersonIms personims = new ScimPersonIms();
    personims.setType("ims_type");
    personims.setValue("ims_value");
    List<ScimPersonIms> ims = new ArrayList<ScimPersonIms>();
    ims.add(personims);
    source.setIms(ims);
    source.setLocale("locale");
    PersonMeta meta = new PersonMeta();
    meta.setCreated("created");
    meta.setLastModified("lastModified");
    meta.setLocation("location");
    meta.setVersion("version");
    source.setMeta(meta);
    ScimName name = new ScimName();
    name.setFamilyName("familyName");
    name.setGivenName("givenName");
    name.setHonorificPrefix("honorificPrefix");
    name.setHonorificSuffix("honorificSuffix");
    name.setMiddleName("middleName");
    source.setName(name);
    source.setNickName("nickName");
    source.setPassword("password");
    ScimPersonPhones phonenumber = new ScimPersonPhones();
    phonenumber.setType("phone_type");
    phonenumber.setValue("phone_value");
    List<ScimPersonPhones> phoneNumbers = new ArrayList<ScimPersonPhones>();
    phoneNumbers.add(phonenumber);
    source.setPhoneNumbers(phoneNumbers);
    ScimPersonPhotos photo = new ScimPersonPhotos();
    photo.setType("photo_type");
    photo.setValue("photo_value");
    List<ScimPersonPhotos> photos = new ArrayList<ScimPersonPhotos>();
    photos.add(photo);
    source.setPhotos(photos);
    source.setPreferredLanguage("preferredLanguage");
    source.setProfileUrl("profileUrl");
    ScimRoles role = new ScimRoles();
    role.setValue("role_value");
    List<ScimRoles> roles = new ArrayList<ScimRoles>();
    roles.add(role);
    source.setRoles(roles);
    List<String> schemas = new ArrayList<String>();
    schemas.add("shema");
    source.setSchemas(schemas);
    source.setTimezone("timezone");
    source.setTitle("title");
    source.setUserName("userName");
    source.setUserType("userType");
    Scimx509Certificates cert = new Scimx509Certificates();
    cert.setValue("cert_value");
    List<Scimx509Certificates> x509Certificates = new ArrayList<Scimx509Certificates>();
    x509Certificates.add(cert);
    source.setX509Certificates(x509Certificates);
    GluuCustomPerson copy = copyUtils.copy(source, destination, true);
    assertNotNull(copy);
    assertEquals(copy.getUid(), "userName");
    assertEquals(copy.getGivenName(), "givenName");
    assertEquals(copy.getSurname(), "familyName");
    assertEquals(copy.getDisplayName(), "displayName");
    assertEquals(copy.getPreferredLanguage(), "preferredLanguage");
    assertEquals(copy.getTimezone(), "timezone");
    assertEquals(copy.getUserPassword(), "password");
    assertNotNull(copy.getMemberOf());
    assertEquals(copy.getMemberOf().size(), 2);
    assertEquals(copy.getMemberOf().get(0), "Mocked DN");
    assertEquals(copy.getMemberOf().get(1), "Mocked DN1");
    assertEquals(copy.getAttribute(GLUU_STATUS), "true");
    assertNull(copy.getAttribute(OX_TRUST_PHOTOS_TYPE));
    assertNull(copy.getAttribute(OX_TRUST_PHONE_TYPE));
    assertNull(copy.getAttribute(OX_TRUST_ADDRESS_PRIMARY));
    assertNull(copy.getAttribute(OX_TRUST_ADDRESS_TYPE));
    assertNull(copy.getAttribute(OX_TRUST_COUNTRY));
    assertNull(copy.getAttribute(OX_TRUST_POSTAL_CODE));
    assertNull(copy.getAttribute(OX_TRUST_REGION));
    assertNull(copy.getAttribute(OX_TRUST_LOCALITY));
    assertNull(copy.getAttribute(OX_TRUST_ADDRESS_FORMATTED));
    assertNull(copy.getAttribute(OX_TRUST_STREET));
    assertNull(copy.getAttribute(OX_TRUST_EMAIL_PRIMARY));
    assertNull(copy.getAttribute(OX_TRUST_EMAIL_TYPE));
    assertEquals(copy.getAttribute(OX_TRUST_META_LOCATION), "location");
    assertEquals(copy.getAttribute(OX_TRUST_META_VERSION), "version");
    assertEquals(copy.getAttribute(OX_TRUST_META_LAST_MODIFIED), "lastModified");
    assertEquals(copy.getAttribute(OX_TRUST_META_CREATED), "created");
    assertEquals(copy.getAttribute(OX_TRUSTX509_CERTIFICATE), "[{\"value\":\"cert_value\"}]");
    assertEquals(copy.getAttribute(OX_TRUST_ENTITLEMENTS), "[{\"value\":\"entitlement_value\"}]");
    assertEquals(copy.getAttribute(OX_TRUST_ROLE), "[{\"value\":\"role_value\"}]");
    assertEquals(copy.getAttribute(OX_TRUST_ACTIVE), "true");
    assertEquals(copy.getAttribute(OX_TRUST_LOCALE), "locale");
    assertEquals(copy.getAttribute(OX_TRUST_TITLE), "title");
    assertEquals(copy.getAttribute(OX_TRUST_USER_TYPE), "userType");
    assertEquals(copy.getAttribute(OX_TRUST_PHOTOS), "[{\"value\":\"photo_value\",\"type\":\"photo_type\"}]");
    assertEquals(copy.getAttribute(OX_TRUST_IMS_VALUE), "[{\"value\":\"ims_value\",\"type\":\"ims_type\"}]");
    assertEquals(copy.getAttribute(OX_TRUST_PHONE_VALUE), "[{\"value\":\"phone_value\",\"type\":\"phone_type\"}]");
    assertEquals(copy.getAttribute(OX_TRUST_ADDRESSES), "[{\"type\":\"address_type\",\"streetAddress\":\"streetAddress\",\"locality\":\"locality\",\"region\":\"region\",\"postalCode\":\"postalCode\",\"country\":\"country\",\"formatted\":\"formatted\",\"primary\":\"address_primary\"}]");
    assertEquals(copy.getAttribute(OX_TRUST_EMAIL), "[{\"value\":\"email_value\",\"type\":\"email_type\",\"primary\":\"email_primary\"}]");
    assertEquals(copy.getAttribute(OX_TRUST_PROFILE_URL), "profileUrl");
    assertEquals(copy.getAttribute(OX_TRUST_NICK_NAME), "nickName");
    assertEquals(copy.getAttribute(OX_TRUST_EXTERNAL_ID), "externalId");
    assertEquals(copy.getAttribute(OX_TRUSTHONORIFIC_SUFFIX), "honorificSuffix");
    assertEquals(copy.getAttribute(OX_TRUSTHONORIFIC_PREFIX), "honorificPrefix");
    assertEquals(copy.getAttribute(OX_TRUST_MIDDLE_NAME), "middleName");
}
Also used : ScimEntitlements(org.gluu.oxtrust.model.scim.ScimEntitlements) ArrayList(java.util.ArrayList) ScimPersonIms(org.gluu.oxtrust.model.scim.ScimPersonIms) GluuCustomPerson(org.gluu.oxtrust.model.GluuCustomPerson) ScimPersonEmails(org.gluu.oxtrust.model.scim.ScimPersonEmails) PersonMeta(org.gluu.oxtrust.model.scim.PersonMeta) Scimx509Certificates(org.gluu.oxtrust.model.scim.Scimx509Certificates) ScimName(org.gluu.oxtrust.model.scim.ScimName) ScimRoles(org.gluu.oxtrust.model.scim.ScimRoles) ScimPersonAddresses(org.gluu.oxtrust.model.scim.ScimPersonAddresses) ScimPersonPhotos(org.gluu.oxtrust.model.scim.ScimPersonPhotos) ScimPersonGroups(org.gluu.oxtrust.model.scim.ScimPersonGroups) ScimPersonPhones(org.gluu.oxtrust.model.scim.ScimPersonPhones) ScimPerson(org.gluu.oxtrust.model.scim.ScimPerson) ScimCustomAttributes(org.gluu.oxtrust.model.scim.ScimCustomAttributes) Test(org.testng.annotations.Test) ConfigurableTest(org.gluu.oxtrust.action.test.ConfigurableTest)

Example 7 with ScimPersonAddresses

use of org.gluu.oxtrust.model.scim.ScimPersonAddresses in project oxTrust by GluuFederation.

the class CopyUtilsTestUpdate method testCopyScim1FilledNullCustomAttributesUpdate.

@Test
public void testCopyScim1FilledNullCustomAttributesUpdate() throws Exception {
    GluuCustomPerson destination = new GluuCustomPerson();
    ScimPerson source = new ScimPerson();
    source.setActive("active");
    ScimPersonAddresses address = new ScimPersonAddresses();
    address.setCountry("country");
    address.setFormatted("formatted");
    address.setLocality("locality");
    address.setPostalCode("postalCode");
    address.setPrimary("address_primary");
    address.setRegion("region");
    address.setStreetAddress("streetAddress");
    address.setType("address_type");
    List<ScimPersonAddresses> addresses = new ArrayList<ScimPersonAddresses>();
    addresses.add(address);
    source.setAddresses(addresses);
    source.setCustomAttributes(null);
    source.setDisplayName("displayName");
    ScimPersonEmails email = new ScimPersonEmails();
    email.setPrimary("email_primary");
    email.setType("email_type");
    email.setValue("email_value");
    List<ScimPersonEmails> emails = new ArrayList<ScimPersonEmails>();
    emails.add(email);
    source.setEmails(emails);
    ScimEntitlements entitlement = new ScimEntitlements();
    entitlement.setValue("entitlement_value");
    List<ScimEntitlements> entitlements = new ArrayList<ScimEntitlements>();
    entitlements.add(entitlement);
    source.setEntitlements(entitlements);
    source.setExternalId("externalId");
    ScimPersonGroups group1 = new ScimPersonGroups();
    group1.setDisplay("group_display");
    group1.setValue("group_value");
    ScimPersonGroups group2 = new ScimPersonGroups();
    group2.setDisplay("group_display1");
    group2.setValue("group_value1");
    List<ScimPersonGroups> groups = new ArrayList<ScimPersonGroups>();
    groups.add(group1);
    groups.add(group2);
    source.setGroups(groups);
    source.setId("id");
    ScimPersonIms personims = new ScimPersonIms();
    personims.setType("ims_type");
    personims.setValue("ims_value");
    List<ScimPersonIms> ims = new ArrayList<ScimPersonIms>();
    ims.add(personims);
    source.setIms(ims);
    source.setLocale("locale");
    PersonMeta meta = new PersonMeta();
    meta.setCreated("created");
    meta.setLastModified("lastModified");
    meta.setLocation("location");
    meta.setVersion("version");
    source.setMeta(meta);
    ScimName name = new ScimName();
    name.setFamilyName("familyName");
    name.setGivenName("givenName");
    name.setHonorificPrefix("honorificPrefix");
    name.setHonorificSuffix("honorificSuffix");
    name.setMiddleName("middleName");
    source.setName(name);
    source.setNickName("nickName");
    source.setPassword("password");
    ScimPersonPhones phonenumber = new ScimPersonPhones();
    phonenumber.setType("phone_type");
    phonenumber.setValue("phone_value");
    List<ScimPersonPhones> phoneNumbers = new ArrayList<ScimPersonPhones>();
    phoneNumbers.add(phonenumber);
    source.setPhoneNumbers(phoneNumbers);
    ScimPersonPhotos photo = new ScimPersonPhotos();
    photo.setType("photo_type");
    photo.setValue("photo_value");
    List<ScimPersonPhotos> photos = new ArrayList<ScimPersonPhotos>();
    photos.add(photo);
    source.setPhotos(photos);
    source.setPreferredLanguage("preferredLanguage");
    source.setProfileUrl("profileUrl");
    ScimRoles role = new ScimRoles();
    role.setValue("role_value");
    List<ScimRoles> roles = new ArrayList<ScimRoles>();
    roles.add(role);
    source.setRoles(roles);
    List<String> schemas = new ArrayList<String>();
    schemas.add("shema");
    source.setSchemas(schemas);
    source.setTimezone("timezone");
    source.setTitle("title");
    source.setUserName("userName");
    source.setUserType("userType");
    Scimx509Certificates cert = new Scimx509Certificates();
    cert.setValue("cert_value");
    List<Scimx509Certificates> x509Certificates = new ArrayList<Scimx509Certificates>();
    x509Certificates.add(cert);
    source.setX509Certificates(x509Certificates);
    GluuCustomPerson copy = copyUtils.copy(source, destination, true);
    assertNotNull(copy);
    assertEquals(copy.getUid(), "userName");
    assertEquals(copy.getGivenName(), "givenName");
    assertEquals(copy.getSurname(), "familyName");
    assertEquals(copy.getDisplayName(), "displayName");
    assertEquals(copy.getPreferredLanguage(), "preferredLanguage");
    assertEquals(copy.getTimezone(), "timezone");
    assertEquals(copy.getUserPassword(), "password");
    assertNotNull(copy.getMemberOf());
    assertEquals(copy.getMemberOf().size(), 2);
    assertEquals(copy.getMemberOf().get(0), "Mocked DN");
    assertEquals(copy.getMemberOf().get(1), "Mocked DN1");
    assertNull(copy.getAttribute(GLUU_STATUS));
    assertNull(copy.getAttribute(OX_TRUST_PHOTOS_TYPE));
    assertNull(copy.getAttribute(OX_TRUST_PHONE_TYPE));
    assertNull(copy.getAttribute(OX_TRUST_ADDRESS_PRIMARY));
    assertNull(copy.getAttribute(OX_TRUST_ADDRESS_TYPE));
    assertNull(copy.getAttribute(OX_TRUST_COUNTRY));
    assertNull(copy.getAttribute(OX_TRUST_POSTAL_CODE));
    assertNull(copy.getAttribute(OX_TRUST_REGION));
    assertNull(copy.getAttribute(OX_TRUST_LOCALITY));
    assertNull(copy.getAttribute(OX_TRUST_ADDRESS_FORMATTED));
    assertNull(copy.getAttribute(OX_TRUST_STREET));
    assertNull(copy.getAttribute(OX_TRUST_EMAIL_PRIMARY));
    assertNull(copy.getAttribute(OX_TRUST_EMAIL_TYPE));
    assertEquals(copy.getAttribute(OX_TRUST_META_LOCATION), "location");
    assertEquals(copy.getAttribute(OX_TRUST_META_VERSION), "version");
    assertEquals(copy.getAttribute(OX_TRUST_META_LAST_MODIFIED), "lastModified");
    assertEquals(copy.getAttribute(OX_TRUST_META_CREATED), "created");
    assertEquals(copy.getAttribute(OX_TRUSTX509_CERTIFICATE), "[{\"value\":\"cert_value\"}]");
    assertEquals(copy.getAttribute(OX_TRUST_ENTITLEMENTS), "[{\"value\":\"entitlement_value\"}]");
    assertEquals(copy.getAttribute(OX_TRUST_ROLE), "[{\"value\":\"role_value\"}]");
    assertEquals(copy.getAttribute(OX_TRUST_ACTIVE), "active");
    assertEquals(copy.getAttribute(OX_TRUST_LOCALE), "locale");
    assertEquals(copy.getAttribute(OX_TRUST_TITLE), "title");
    assertEquals(copy.getAttribute(OX_TRUST_USER_TYPE), "userType");
    assertEquals(copy.getAttribute(OX_TRUST_PHOTOS), "[{\"value\":\"photo_value\",\"type\":\"photo_type\"}]");
    assertEquals(copy.getAttribute(OX_TRUST_IMS_VALUE), "[{\"value\":\"ims_value\",\"type\":\"ims_type\"}]");
    assertEquals(copy.getAttribute(OX_TRUST_PHONE_VALUE), "[{\"value\":\"phone_value\",\"type\":\"phone_type\"}]");
    assertEquals(copy.getAttribute(OX_TRUST_ADDRESSES), "[{\"type\":\"address_type\",\"streetAddress\":\"streetAddress\",\"locality\":\"locality\",\"region\":\"region\",\"postalCode\":\"postalCode\",\"country\":\"country\",\"formatted\":\"formatted\",\"primary\":\"address_primary\"}]");
    assertEquals(copy.getAttribute(OX_TRUST_EMAIL), "[{\"value\":\"email_value\",\"type\":\"email_type\",\"primary\":\"email_primary\"}]");
    assertEquals(copy.getAttribute(OX_TRUST_PROFILE_URL), "profileUrl");
    assertEquals(copy.getAttribute(OX_TRUST_NICK_NAME), "nickName");
    assertEquals(copy.getAttribute(OX_TRUST_EXTERNAL_ID), "externalId");
    assertEquals(copy.getAttribute(OX_TRUSTHONORIFIC_SUFFIX), "honorificSuffix");
    assertEquals(copy.getAttribute(OX_TRUSTHONORIFIC_PREFIX), "honorificPrefix");
    assertEquals(copy.getAttribute(OX_TRUST_MIDDLE_NAME), "middleName");
}
Also used : ScimEntitlements(org.gluu.oxtrust.model.scim.ScimEntitlements) ArrayList(java.util.ArrayList) ScimPersonIms(org.gluu.oxtrust.model.scim.ScimPersonIms) GluuCustomPerson(org.gluu.oxtrust.model.GluuCustomPerson) ScimPersonEmails(org.gluu.oxtrust.model.scim.ScimPersonEmails) PersonMeta(org.gluu.oxtrust.model.scim.PersonMeta) Scimx509Certificates(org.gluu.oxtrust.model.scim.Scimx509Certificates) ScimName(org.gluu.oxtrust.model.scim.ScimName) ScimRoles(org.gluu.oxtrust.model.scim.ScimRoles) ScimPersonAddresses(org.gluu.oxtrust.model.scim.ScimPersonAddresses) ScimPersonPhotos(org.gluu.oxtrust.model.scim.ScimPersonPhotos) ScimPersonGroups(org.gluu.oxtrust.model.scim.ScimPersonGroups) ScimPersonPhones(org.gluu.oxtrust.model.scim.ScimPersonPhones) ScimPerson(org.gluu.oxtrust.model.scim.ScimPerson) Test(org.testng.annotations.Test) ConfigurableTest(org.gluu.oxtrust.action.test.ConfigurableTest)

Example 8 with ScimPersonAddresses

use of org.gluu.oxtrust.model.scim.ScimPersonAddresses in project oxTrust by GluuFederation.

the class CopyUtils method copy.

/**
	 * Copy data from GluuCustomPerson object to ScimPerson object "Reda"
	 * 
	 * @param source
	 * @param destination
	 * @return
	 * @throws Exception
	 */
public ScimPerson copy(GluuCustomPerson source, ScimPerson destination) throws Exception {
    if (source == null) {
        return null;
    }
    if (destination == null) {
        log.trace(" creating a new GluuCustomPerson instant ");
        destination = new ScimPerson();
    }
    destination.getSchemas().add(Constants.SCIM1_CORE_SCHEMA_ID);
    log.trace(" setting ID ");
    if (source.getInum() != null) {
        destination.setId(source.getInum());
    }
    log.trace(" setting userName ");
    if (source.getUid() != null) {
        destination.setUserName(source.getUid());
    }
    log.trace(" setting ExternalID ");
    if (source.getAttribute(OX_TRUST_EXTERNAL_ID) != null) {
        destination.setExternalId(source.getAttribute(OX_TRUST_EXTERNAL_ID));
    }
    log.trace(" setting givenname ");
    if (source.getGivenName() != null) {
        destination.getName().setGivenName(source.getGivenName());
    }
    log.trace(" getting family name ");
    if (source.getSurname() != null) {
        destination.getName().setFamilyName(source.getSurname());
    }
    log.trace(" getting middlename ");
    if (source.getAttribute(OX_TRUST_MIDDLE_NAME) != null) {
        destination.getName().setMiddleName(source.getAttribute(OX_TRUST_MIDDLE_NAME));
    }
    ;
    log.trace(" getting honorificPrefix ");
    if (source.getAttribute(OX_TRUSTHONORIFIC_PREFIX) != null) {
        destination.getName().setHonorificPrefix(source.getAttribute(OX_TRUSTHONORIFIC_PREFIX));
    }
    ;
    log.trace(" getting honorificSuffix ");
    if (source.getAttribute(OX_TRUSTHONORIFIC_SUFFIX) != null) {
        destination.getName().setHonorificSuffix(source.getAttribute(OX_TRUSTHONORIFIC_SUFFIX));
    }
    ;
    log.trace(" getting displayname ");
    if (source.getDisplayName() != null) {
        destination.setDisplayName(source.getDisplayName());
    }
    log.trace(" getting nickname ");
    if (source.getAttribute(OX_TRUST_NICK_NAME) != null) {
        destination.setNickName(source.getAttribute(OX_TRUST_NICK_NAME));
    }
    log.trace(" getting profileURL ");
    if (source.getAttribute(OX_TRUST_PROFILE_URL) != null) {
        destination.setProfileUrl(source.getAttribute(OX_TRUST_PROFILE_URL));
    }
    log.trace(" getting emails ");
    // if (source.getAttribute(OX_TRUST_EMAIL) != null) {
    if (source.getAttributeArray(OX_TRUST_EMAIL) != null) {
        // List<ScimPersonEmails> listOfEmails = mapper.readValue(source.getAttribute(OX_TRUST_EMAIL), new TypeReference<List<ScimPersonEmails>>(){});
        /*
			 * List<ScimPersonEmails> emails = new
			 * ArrayList<ScimPersonEmails>(); String[] listEmails =
			 * source.getAttributes("oxTrustEmail"); String[] listEmailTyps =
			 * source.getAttributes("oxTrustEmailType"); String[]
			 * listEmailPrimary = source.getAttributes("oxTrustEmailPrimary");
			 * for(int i = 0 ; i<listEmails.length ; i++ ){ ScimPersonEmails
			 * oneEmail = new ScimPersonEmails();
			 * oneEmail.setValue(listEmails[i]);
			 * oneEmail.setType(listEmailTyps[i]);
			 * oneEmail.setPrimary(listEmailPrimary[i]); emails.add(oneEmail); }
			 */
        // destination.setEmails(listOfEmails);
        /*
			String[] emailArray = source.getAttributeArray(OX_TRUST_EMAIL);
			List<ScimPersonEmails> emails = new ArrayList<ScimPersonEmails>();

			for (String emailStr : emailArray) {
				ScimPersonEmails email = mapper.readValue(emailStr, ScimPersonEmails.class);
				emails.add(email);
			}
			*/
        List<ScimPersonEmails> emails = getAttributeListValue(source, ScimPersonEmails.class, OX_TRUST_EMAIL);
        destination.setEmails(emails);
    }
    log.trace(" getting addresses ");
    // getting addresses
    if (source.getAttribute(OX_TRUST_ADDRESSES) != null) {
        // List<ScimPersonAddresses> listOfAddresses = mapper.readValue(source.getAttribute(OX_TRUST_ADDRESSES), new TypeReference<List<ScimPersonAddresses>>(){});
        /*
			 * List<ScimPersonAddresses> addresses = new
			 * ArrayList<ScimPersonAddresses>(); String[] listStreets =
			 * source.getAttributes("oxTrustStreet"); String[] listAddressTypes
			 * = source.getAttributes("oxTrustAddressType"); String[]
			 * listLocalities = source.getAttributes("oxTrustLocality");
			 * String[] listRegions = source.getAttributes("oxTrustRegion");
			 * String[] listPostalCodes =
			 * source.getAttributes("oxTrustPostalCode"); String[] listCountries
			 * = source.getAttributes("oxTrustCountry"); String[]
			 * listAddressFormatted =
			 * source.getAttributes("oxTrustAddressFormatted"); String[]
			 * listAddressPrimary =
			 * source.getAttributes("oxTrustAddressPrimary");
			 * if(listStreets.length > 0){ for(int i = 0 ; i <
			 * listStreets.length ; i++ ){ ScimPersonAddresses address = new
			 * ScimPersonAddresses();
			 * 
			 * if(!listAddressFormatted[i].equalsIgnoreCase("empty")){address.
			 * setFormatted
			 * (listAddressFormatted[i]);}else{address.setFormatted("");}
			 * if(!listStreets
			 * [i].equalsIgnoreCase("empty")){address.setStreetAddress
			 * (listStreets[i]);}else{address.setStreetAddress("");}
			 * if(!listAddressTypes
			 * [i].equalsIgnoreCase("empty")){address.setType
			 * (listAddressTypes[i]);}else{address.setType("");}
			 * if(!listLocalities
			 * [i].equalsIgnoreCase("empty")){address.setLocality
			 * (listLocalities[i]);}else{address.setLocality("");}
			 * if(!listRegions
			 * [i].equalsIgnoreCase("empty")){address.setRegion(listRegions
			 * [i]);}else{address.setRegion("");}
			 * if(!listPostalCodes[i].equalsIgnoreCase
			 * ("empty")){address.setPostalCode
			 * (listPostalCodes[i]);}else{address.setPostalCode("");}
			 * if(!listCountries
			 * [i].equalsIgnoreCase("empty")){address.setCountry
			 * (listCountries[i]);}else{address.setCountry("");}
			 * if(!listAddressPrimary
			 * [i].equalsIgnoreCase("empty")){address.setPrimary
			 * (listAddressPrimary[i]);}else{address.setPrimary("");}
			 * addresses.add(address);
			 * 
			 * } }
			 */
        // destination.setAddresses(listOfAddresses);
        List<ScimPersonAddresses> addresses = getAttributeListValue(source, ScimPersonAddresses.class, OX_TRUST_ADDRESSES);
        destination.setAddresses(addresses);
    }
    log.trace(" setting phoneNumber ");
    // getting user's PhoneNumber
    if (source.getAttribute(OX_TRUST_PHONE_VALUE) != null) {
        // List<ScimPersonPhones> listOfPhones = mapper.readValue(source.getAttribute(OX_TRUST_PHONE_VALUE), new TypeReference<List<ScimPersonPhones>>(){});
        /*
			 * List<ScimPersonPhones> phones = new
			 * ArrayList<ScimPersonPhones>(); String[] listNumbers =
			 * source.getAttributes("oxTrustPhoneValue"); String[]
			 * listPhoneTypes = source.getAttributes("oxTrustPhoneType");
			 * if(listNumbers.length > 0){ for(int i = 0 ; i <
			 * listNumbers.length ; i++){ ScimPersonPhones phone = new
			 * ScimPersonPhones();
			 * if(!listNumbers[i].equalsIgnoreCase("empty")){
			 * phone.setValue(listNumbers[i]);}else{phone.setValue("");}
			 * if(!listPhoneTypes
			 * [i].equalsIgnoreCase("empty")){phone.setType(listPhoneTypes
			 * [i]);}else{phone.setType("");} phones.add(phone);
			 * 
			 * } }
			 */
        // destination.setPhoneNumbers(listOfPhones);
        List<ScimPersonPhones> phoneNumbers = getAttributeListValue(source, ScimPersonPhones.class, OX_TRUST_PHONE_VALUE);
        destination.setPhoneNumbers(phoneNumbers);
    }
    log.trace(" getting ims ");
    // getting ims
    if (source.getAttribute(OX_TRUST_IMS_VALUE) != null) {
        // List<ScimPersonIms> listOfIms = mapper.readValue(source.getAttribute(OX_TRUST_IMS_VALUE), new TypeReference<List<ScimPersonIms>>(){});
        /*
			 * List<ScimPersonIms> ims = new ArrayList<ScimPersonIms>();
			 * String[] imValues = source.getAttributes("oxTrustImsValue");
			 * String[] imTypes = source.getAttributes("oxTrustImsType");
			 * if(imValues.length > 0){ for(int i = 0 ; i < imValues.length ;
			 * i++){ ScimPersonIms im = new ScimPersonIms(); if(imValues[i] !=
			 * null){im.setValue(imValues[i]);im.setType(imTypes[i]);}
			 * ims.add(im); } }
			 */
        // destination.setIms(listOfIms);
        List<ScimPersonIms> ims = getAttributeListValue(source, ScimPersonIms.class, OX_TRUST_IMS_VALUE);
        destination.setIms(ims);
    }
    log.trace(" setting photos ");
    // getting photos
    if (source.getAttribute(OX_TRUST_PHOTOS) != null) {
        // List<ScimPersonPhotos> listOfPhotos = mapper.readValue(source.getAttribute(OX_TRUST_PHOTOS), new TypeReference<List<ScimPersonPhotos>>(){});
        /*
			 * List<ScimPersonPhotos> photos = new
			 * ArrayList<ScimPersonPhotos>(); String[] photoList =
			 * source.getAttributes("oxTrustPhotos"); String[] photoTypes =
			 * source.getAttributes("oxTrustPhotosType");
			 * 
			 * if(photoList.length > 0){ for(int i = 0 ; i < photoList.length ;
			 * i++){
			 * 
			 * ScimPersonPhotos photo = new ScimPersonPhotos(); if(photoList[i]
			 * !=
			 * null){photo.setValue(photoList[i]);photo.setType(photoTypes[i]);}
			 * photos.add(photo); } }
			 */
        // destination.setPhotos(listOfPhotos);
        List<ScimPersonPhotos> photos = getAttributeListValue(source, ScimPersonPhotos.class, OX_TRUST_PHOTOS);
        destination.setPhotos(photos);
    }
    log.trace(" setting userType ");
    if (source.getAttribute(OX_TRUST_USER_TYPE) != null) {
        destination.setUserType(source.getAttribute(OX_TRUST_USER_TYPE));
    }
    log.trace(" setting title ");
    if (source.getAttribute(OX_TRUST_TITLE) != null) {
        destination.setTitle(source.getAttribute(OX_TRUST_TITLE));
    }
    log.trace(" setting Locale ");
    if (source.getAttribute(OX_TRUST_LOCALE) != null) {
        destination.setLocale(source.getAttribute(OX_TRUST_LOCALE));
    }
    log.trace(" setting preferredLanguage ");
    if (source.getPreferredLanguage() != null) {
        destination.setPreferredLanguage(source.getPreferredLanguage());
    }
    log.trace(" setting timeZone ");
    if (source.getTimezone() != null) {
        destination.setTimezone(source.getTimezone());
    }
    log.trace(" setting active ");
    if (source.getAttribute(OX_TRUST_ACTIVE) != null) {
        destination.setActive(source.getAttribute(OX_TRUST_ACTIVE));
    }
    log.trace(" setting password ");
    destination.setPassword("Hidden for Privacy Reasons");
    // getting user groups
    log.trace(" setting  groups ");
    if (source.getMemberOf() != null) {
        List<String> listOfGroups = source.getMemberOf();
        List<ScimPersonGroups> groupsList = new ArrayList<ScimPersonGroups>();
        for (String groupDN : listOfGroups) {
            ScimPersonGroups group = new ScimPersonGroups();
            GluuGroup gluuGroup = groupService.getGroupByDn(groupDN);
            group.setValue(gluuGroup.getInum());
            group.setDisplay(gluuGroup.getDisplayName());
            groupsList.add(group);
        }
        destination.setGroups(groupsList);
    }
    // getting roles
    if (source.getAttribute(OX_TRUST_ROLE) != null) {
        // List<ScimRoles> listOfRoles = mapper.readValue(source.getAttribute(OX_TRUST_ROLE), new TypeReference<List<ScimRoles>>(){});
        /*
			 * List<ScimRoles> roles = new ArrayList<ScimRoles>(); String[]
			 * listRoles = source.getAttributes("oxTrustRole");
			 * if(listRoles.length > 0){ for(int i = 0 ; i < listRoles.length
			 * ;i++){ ScimRoles role = new ScimRoles(); if(listRoles[i] !=
			 * null){role.setValue(listRoles[i]);} roles.add(role); } }
			 */
        // destination.setRoles(listOfRoles);
        List<ScimRoles> roles = getAttributeListValue(source, ScimRoles.class, OX_TRUST_ROLE);
        destination.setRoles(roles);
    }
    log.trace(" getting entitlements ");
    // getting entitlements
    if (source.getAttribute(OX_TRUST_ENTITLEMENTS) != null) {
        // List<ScimEntitlements> listOfEnts = mapper.readValue(source.getAttribute(OX_TRUST_ENTITLEMENTS), new TypeReference<List<ScimEntitlements>>(){});
        /*
			 * List<ScimEntitlements> entitlements = new
			 * ArrayList<ScimEntitlements>(); String[] listEntitlements =
			 * source.getAttributes("oxTrustEntitlements");
			 * if(listEntitlements.length > 0){ for(int i = 0 ; i <
			 * listEntitlements.length ; i++ ){ ScimEntitlements ent = new
			 * ScimEntitlements(); if(listEntitlements[i] !=
			 * null){ent.setValue(listEntitlements[i]);} entitlements.add(ent);
			 * } }
			 */
        // destination.setEntitlements(listOfEnts);
        List<ScimEntitlements> entitlements = getAttributeListValue(source, ScimEntitlements.class, OX_TRUST_ENTITLEMENTS);
        destination.setEntitlements(entitlements);
    }
    // getting x509Certificates
    log.trace(" setting certs ");
    if (source.getAttribute(OX_TRUSTX509_CERTIFICATE) != null) {
        // List<Scimx509Certificates> listOfCerts = mapper.readValue(source.getAttribute(OX_TRUSTX509_CERTIFICATE), new TypeReference<List<Scimx509Certificates>>(){});
        /*
			 * List<Scimx509Certificates> certificates = new
			 * ArrayList<Scimx509Certificates>(); String[] listCertif =
			 * source.getAttributes("oxTrustx509Certificate");
			 * if(listCertif.length > 0){ for(int i = 0 ; i < listCertif.length
			 * ; i++){ Scimx509Certificates cert = new Scimx509Certificates();
			 * if(listCertif[i] != null){cert.setValue(listCertif[i]);}
			 * certificates.add(cert);
			 * 
			 * } }
			 */
        // destination.setX509Certificates(listOfCerts);
        List<Scimx509Certificates> x509Certificates = getAttributeListValue(source, Scimx509Certificates.class, OX_TRUSTX509_CERTIFICATE);
        destination.setX509Certificates(x509Certificates);
    }
    log.trace(" setting meta ");
    // getting meta data
    if (source.getAttribute(OX_TRUST_META_CREATED) != null) {
        destination.getMeta().setCreated(source.getAttribute(OX_TRUST_META_CREATED));
    }
    if (source.getAttribute(OX_TRUST_META_LAST_MODIFIED) != null) {
        destination.getMeta().setLastModified(source.getAttribute(OX_TRUST_META_LAST_MODIFIED));
    }
    if (source.getAttribute(OX_TRUST_META_VERSION) != null) {
        destination.getMeta().setVersion(source.getAttribute(OX_TRUST_META_VERSION));
    }
    // if (source.getAttribute(OX_TRUST_META_LOCATION) != null) {
    // destination.getMeta().setLocation(source.getAttribute(OX_TRUST_META_LOCATION));
    String location = source.getAttribute(OX_TRUST_META_LOCATION);
    if (location != null && !location.isEmpty()) {
        if (!location.startsWith("https://") && !location.startsWith("http://")) {
            location = appConfiguration.getBaseEndpoint() + location;
        }
    } else {
        location = appConfiguration.getBaseEndpoint() + "/scim/v1/Users/" + source.getInum();
    }
    destination.getMeta().setLocation(location);
    // }
    log.trace(" getting custom Attributes ");
    // getting custom Attributes
    List<GluuAttribute> listOfAttr = attributeService.getSCIMRelatedAttributes();
    if (listOfAttr != null && listOfAttr.size() > 0) {
        List<ScimCustomAttributes> listOfCustomAttr = new ArrayList<ScimCustomAttributes>();
        for (GluuAttribute attr : listOfAttr) {
            boolean isEmpty = attr.getOxMultivaluedAttribute() == null;
            if (!isEmpty && attr.getOxMultivaluedAttribute().getValue().equalsIgnoreCase("true")) {
                boolean isAttrEmpty = source.getAttributes(attr.getName()) == null;
                if (!isAttrEmpty) {
                    String[] arrayValues = source.getAttributes(attr.getName());
                    List<String> values = new ArrayList<String>(Arrays.asList(arrayValues));
                    ScimCustomAttributes scimAttr = new ScimCustomAttributes();
                    scimAttr.setName(attr.getName());
                    scimAttr.setValues(values);
                    listOfCustomAttr.add(scimAttr);
                }
            } else {
                boolean isAttrEmpty = source.getAttributes(attr.getName()) == null;
                if (!isAttrEmpty) {
                    List<String> values = new ArrayList<String>();
                    values.add(source.getAttribute(attr.getName()));
                    ScimCustomAttributes scimAttr = new ScimCustomAttributes();
                    scimAttr.setName(attr.getName());
                    scimAttr.setValues(values);
                    listOfCustomAttr.add(scimAttr);
                }
            }
        }
        if (listOfCustomAttr.size() > 0) {
            destination.setCustomAttributes(listOfCustomAttr);
        }
    }
    log.trace(" returning destination ");
    return destination;
}
Also used : ScimEntitlements(org.gluu.oxtrust.model.scim.ScimEntitlements) ArrayList(java.util.ArrayList) ScimPersonIms(org.gluu.oxtrust.model.scim.ScimPersonIms) ScimPersonEmails(org.gluu.oxtrust.model.scim.ScimPersonEmails) Scimx509Certificates(org.gluu.oxtrust.model.scim.Scimx509Certificates) ScimRoles(org.gluu.oxtrust.model.scim.ScimRoles) ScimPersonAddresses(org.gluu.oxtrust.model.scim.ScimPersonAddresses) GluuGroup(org.gluu.oxtrust.model.GluuGroup) GluuAttribute(org.xdi.model.GluuAttribute) ScimPersonPhotos(org.gluu.oxtrust.model.scim.ScimPersonPhotos) ScimPersonGroups(org.gluu.oxtrust.model.scim.ScimPersonGroups) ScimPersonPhones(org.gluu.oxtrust.model.scim.ScimPersonPhones) ScimPerson(org.gluu.oxtrust.model.scim.ScimPerson) ScimCustomAttributes(org.gluu.oxtrust.model.scim.ScimCustomAttributes)

Example 9 with ScimPersonAddresses

use of org.gluu.oxtrust.model.scim.ScimPersonAddresses in project oxTrust by GluuFederation.

the class CopyUtilsTestCreate method testCopyScim1MixedCreate.

@Test
public void testCopyScim1MixedCreate() throws Exception {
    GluuCustomPerson destination = new GluuCustomPerson();
    ScimPerson source = new ScimPerson();
    source.setActive("false");
    ScimPersonAddresses address = new ScimPersonAddresses();
    address.setCountry("country");
    address.setFormatted("");
    address.setPostalCode("postalCode");
    address.setPrimary("address_primary");
    address.setRegion("region");
    address.setLocality(null);
    address.setStreetAddress("streetAddress");
    address.setType("address_type");
    List<ScimPersonAddresses> addresses = new ArrayList<ScimPersonAddresses>();
    addresses.add(address);
    source.setAddresses(addresses);
    List<ScimCustomAttributes> customAttributes = new ArrayList<ScimCustomAttributes>();
    source.setCustomAttributes(customAttributes);
    source.setDisplayName("displayName");
    ScimPersonEmails email = new ScimPersonEmails();
    email.setPrimary("email_primary");
    email.setType("email_type");
    email.setValue("email_value");
    List<ScimPersonEmails> emails = new ArrayList<ScimPersonEmails>();
    emails.add(email);
    source.setEmails(emails);
    ScimEntitlements entitlement = new ScimEntitlements();
    entitlement.setValue("entitlement_value");
    List<ScimEntitlements> entitlements = new ArrayList<ScimEntitlements>();
    entitlements.add(entitlement);
    source.setEntitlements(entitlements);
    source.setExternalId("externalId");
    List<ScimPersonGroups> groups = new ArrayList<ScimPersonGroups>();
    source.setGroups(groups);
    source.setId("id");
    ScimPersonIms personims = new ScimPersonIms();
    personims.setType("ims_type");
    personims.setValue("ims_value");
    List<ScimPersonIms> ims = new ArrayList<ScimPersonIms>();
    ims.add(personims);
    source.setIms(ims);
    source.setLocale("locale");
    PersonMeta meta = new PersonMeta();
    meta.setCreated("");
    meta.setLastModified("");
    meta.setLocation("");
    meta.setVersion("");
    source.setMeta(meta);
    ScimName name = new ScimName();
    name.setFamilyName("familyName");
    name.setGivenName("givenName");
    name.setHonorificPrefix("honorificPrefix");
    name.setHonorificSuffix("honorificSuffix");
    name.setMiddleName("middleName");
    source.setName(name);
    source.setNickName("nickName");
    source.setPassword("password");
    ScimPersonPhones phonenumber = new ScimPersonPhones();
    phonenumber.setType("phone_type");
    phonenumber.setValue("phone_value");
    List<ScimPersonPhones> phoneNumbers = new ArrayList<ScimPersonPhones>();
    phoneNumbers.add(phonenumber);
    source.setPhoneNumbers(phoneNumbers);
    ScimPersonPhotos photo = new ScimPersonPhotos();
    photo.setType("photo_type");
    photo.setValue("photo_value");
    List<ScimPersonPhotos> photos = new ArrayList<ScimPersonPhotos>();
    photos.add(photo);
    source.setPhotos(photos);
    source.setPreferredLanguage("");
    source.setProfileUrl("profileUrl");
    ScimRoles role = new ScimRoles();
    role.setValue("role_value");
    List<ScimRoles> roles = new ArrayList<ScimRoles>();
    roles.add(role);
    source.setRoles(roles);
    List<String> schemas = new ArrayList<String>();
    schemas.add("shema");
    source.setSchemas(schemas);
    source.setTimezone("");
    source.setTitle("title");
    source.setUserName("userName");
    source.setUserType("userType");
    source.setX509Certificates(null);
    GluuCustomPerson copy = copyUtils.copy(source, destination, false);
    assertNotNull(copy);
    assertEquals(copy.getUid(), "userName");
    assertEquals(copy.getGivenName(), "givenName");
    assertEquals(copy.getSurname(), "familyName");
    assertEquals(copy.getDisplayName(), "displayName");
    assertNull(copy.getPreferredLanguage());
    assertNull(copy.getTimezone());
    assertEquals(copy.getUserPassword(), "password");
    assertNotNull(copy.getMemberOf());
    assertEquals(copy.getMemberOf().size(), 0);
    assertEquals(copy.getAttribute(GLUU_STATUS), "false");
    assertNull(copy.getAttribute(OX_TRUST_PHOTOS_TYPE));
    assertNull(copy.getAttribute(OX_TRUST_PHONE_TYPE));
    assertNull(copy.getAttribute(OX_TRUST_ADDRESS_PRIMARY));
    assertNull(copy.getAttribute(OX_TRUST_ADDRESS_TYPE));
    assertNull(copy.getAttribute(OX_TRUST_COUNTRY));
    assertNull(copy.getAttribute(OX_TRUST_POSTAL_CODE));
    assertNull(copy.getAttribute(OX_TRUST_REGION));
    assertNull(copy.getAttribute(OX_TRUST_LOCALITY));
    assertNull(copy.getAttribute(OX_TRUST_ADDRESS_FORMATTED));
    assertNull(copy.getAttribute(OX_TRUST_STREET));
    assertNull(copy.getAttribute(OX_TRUST_EMAIL_PRIMARY));
    assertNull(copy.getAttribute(OX_TRUST_EMAIL_TYPE));
    assertNull(copy.getAttribute(OX_TRUST_META_LOCATION));
    assertNull(copy.getAttribute(OX_TRUST_META_VERSION));
    assertNull(copy.getAttribute(OX_TRUST_META_LAST_MODIFIED));
    assertNull(copy.getAttribute(OX_TRUST_META_CREATED));
    assertNull(copy.getAttribute(OX_TRUSTX509_CERTIFICATE));
    assertEquals(copy.getAttribute(OX_TRUST_ENTITLEMENTS), "[{\"value\":\"entitlement_value\"}]");
    assertEquals(copy.getAttribute(OX_TRUST_ROLE), "[{\"value\":\"role_value\"}]");
    assertEquals(copy.getAttribute(OX_TRUST_ACTIVE), "false");
    assertEquals(copy.getAttribute(OX_TRUST_LOCALE), "locale");
    assertEquals(copy.getAttribute(OX_TRUST_TITLE), "title");
    assertEquals(copy.getAttribute(OX_TRUST_USER_TYPE), "userType");
    assertEquals(copy.getAttribute(OX_TRUST_PHOTOS), "[{\"value\":\"photo_value\",\"type\":\"photo_type\"}]");
    assertEquals(copy.getAttribute(OX_TRUST_IMS_VALUE), "[{\"value\":\"ims_value\",\"type\":\"ims_type\"}]");
    assertEquals(copy.getAttribute(OX_TRUST_PHONE_VALUE), "[{\"value\":\"phone_value\",\"type\":\"phone_type\"}]");
    assertEquals(copy.getAttribute(OX_TRUST_ADDRESSES), "[{\"type\":\"address_type\",\"streetAddress\":\"streetAddress\",\"locality\":null,\"region\":\"region\",\"postalCode\":\"postalCode\",\"country\":\"country\",\"formatted\":\"\",\"primary\":\"address_primary\"}]");
    assertEquals(copy.getAttribute(OX_TRUST_EMAIL), "[{\"value\":\"email_value\",\"type\":\"email_type\",\"primary\":\"email_primary\"}]");
    assertEquals(copy.getAttribute(OX_TRUST_PROFILE_URL), "profileUrl");
    assertEquals(copy.getAttribute(OX_TRUST_NICK_NAME), "nickName");
    assertEquals(copy.getAttribute(OX_TRUST_EXTERNAL_ID), "externalId");
    assertEquals(copy.getAttribute(OX_TRUSTHONORIFIC_SUFFIX), "honorificSuffix");
    assertEquals(copy.getAttribute(OX_TRUSTHONORIFIC_PREFIX), "honorificPrefix");
    assertEquals(copy.getAttribute(OX_TRUST_MIDDLE_NAME), "middleName");
}
Also used : ScimEntitlements(org.gluu.oxtrust.model.scim.ScimEntitlements) ArrayList(java.util.ArrayList) ScimPersonIms(org.gluu.oxtrust.model.scim.ScimPersonIms) GluuCustomPerson(org.gluu.oxtrust.model.GluuCustomPerson) ScimPersonEmails(org.gluu.oxtrust.model.scim.ScimPersonEmails) PersonMeta(org.gluu.oxtrust.model.scim.PersonMeta) ScimName(org.gluu.oxtrust.model.scim.ScimName) ScimRoles(org.gluu.oxtrust.model.scim.ScimRoles) ScimPersonAddresses(org.gluu.oxtrust.model.scim.ScimPersonAddresses) ScimPersonPhotos(org.gluu.oxtrust.model.scim.ScimPersonPhotos) ScimPersonGroups(org.gluu.oxtrust.model.scim.ScimPersonGroups) ScimPersonPhones(org.gluu.oxtrust.model.scim.ScimPersonPhones) ScimPerson(org.gluu.oxtrust.model.scim.ScimPerson) ScimCustomAttributes(org.gluu.oxtrust.model.scim.ScimCustomAttributes) Test(org.testng.annotations.Test) ConfigurableTest(org.gluu.oxtrust.action.test.ConfigurableTest)

Example 10 with ScimPersonAddresses

use of org.gluu.oxtrust.model.scim.ScimPersonAddresses in project oxTrust by GluuFederation.

the class CopyUtilsTestCreate method testCopyScim1FilledMultipleAttributesCreate.

@Test
public void testCopyScim1FilledMultipleAttributesCreate() throws Exception {
    GluuCustomPerson destination = new GluuCustomPerson();
    ScimPerson source = new ScimPerson();
    source.setActive("true");
    ScimPersonAddresses address = new ScimPersonAddresses();
    address.setCountry("country");
    address.setFormatted("formatted");
    address.setLocality("locality");
    address.setPostalCode("postalCode");
    address.setPrimary("address_primary");
    address.setRegion("region");
    address.setStreetAddress("streetAddress");
    address.setType("address_type");
    List<ScimPersonAddresses> addresses = new ArrayList<ScimPersonAddresses>();
    addresses.add(address);
    source.setAddresses(addresses);
    List<ScimCustomAttributes> customAttributes = new ArrayList<ScimCustomAttributes>();
    ScimCustomAttributes customattribute = new ScimCustomAttributes();
    customattribute.setName("custom_name");
    List<String> values = new ArrayList<String>();
    values.add("value1");
    values.add("value3");
    values.add("value2");
    values.add("value4");
    customattribute.setValues(values);
    customAttributes.add(customattribute);
    source.setCustomAttributes(customAttributes);
    source.setDisplayName("displayName");
    ScimPersonEmails email = new ScimPersonEmails();
    email.setPrimary("email_primary");
    email.setType("email_type");
    email.setValue("email_value");
    List<ScimPersonEmails> emails = new ArrayList<ScimPersonEmails>();
    emails.add(email);
    source.setEmails(emails);
    ScimEntitlements entitlement = new ScimEntitlements();
    entitlement.setValue("entitlement_value");
    List<ScimEntitlements> entitlements = new ArrayList<ScimEntitlements>();
    entitlements.add(entitlement);
    source.setEntitlements(entitlements);
    source.setExternalId("externalId");
    ScimPersonGroups group1 = new ScimPersonGroups();
    group1.setDisplay("group_display");
    group1.setValue("group_value");
    ScimPersonGroups group2 = new ScimPersonGroups();
    group2.setDisplay("group_display1");
    group2.setValue("group_value1");
    List<ScimPersonGroups> groups = new ArrayList<ScimPersonGroups>();
    groups.add(group1);
    groups.add(group2);
    source.setGroups(groups);
    source.setId("id");
    ScimPersonIms personims = new ScimPersonIms();
    personims.setType("ims_type");
    personims.setValue("ims_value");
    List<ScimPersonIms> ims = new ArrayList<ScimPersonIms>();
    ims.add(personims);
    source.setIms(ims);
    source.setLocale("locale");
    PersonMeta meta = new PersonMeta();
    meta.setCreated("created");
    meta.setLastModified("lastModified");
    meta.setLocation("location");
    meta.setVersion("version");
    source.setMeta(meta);
    ScimName name = new ScimName();
    name.setFamilyName("familyName");
    name.setGivenName("givenName");
    name.setHonorificPrefix("honorificPrefix");
    name.setHonorificSuffix("honorificSuffix");
    name.setMiddleName("middleName");
    source.setName(name);
    source.setNickName("nickName");
    source.setPassword("password");
    ScimPersonPhones phonenumber = new ScimPersonPhones();
    phonenumber.setType("phone_type");
    phonenumber.setValue("phone_value");
    List<ScimPersonPhones> phoneNumbers = new ArrayList<ScimPersonPhones>();
    phoneNumbers.add(phonenumber);
    source.setPhoneNumbers(phoneNumbers);
    ScimPersonPhotos photo = new ScimPersonPhotos();
    photo.setType("photo_type");
    photo.setValue("photo_value");
    List<ScimPersonPhotos> photos = new ArrayList<ScimPersonPhotos>();
    photos.add(photo);
    source.setPhotos(photos);
    source.setPreferredLanguage("preferredLanguage");
    source.setProfileUrl("profileUrl");
    ScimRoles role = new ScimRoles();
    role.setValue("role_value");
    List<ScimRoles> roles = new ArrayList<ScimRoles>();
    roles.add(role);
    source.setRoles(roles);
    List<String> schemas = new ArrayList<String>();
    schemas.add("shema");
    source.setSchemas(schemas);
    source.setTimezone("timezone");
    source.setTitle("title");
    source.setUserName("userName");
    source.setUserType("userType");
    Scimx509Certificates cert = new Scimx509Certificates();
    cert.setValue("cert_value");
    List<Scimx509Certificates> x509Certificates = new ArrayList<Scimx509Certificates>();
    x509Certificates.add(cert);
    source.setX509Certificates(x509Certificates);
    GluuCustomPerson copy = copyUtils.copy(source, destination, false);
    assertNotNull(copy);
    assertEquals(copy.getUid(), "userName");
    assertEquals(copy.getGivenName(), "givenName");
    assertEquals(copy.getSurname(), "familyName");
    assertEquals(copy.getDisplayName(), "displayName");
    assertEquals(copy.getPreferredLanguage(), "preferredLanguage");
    assertEquals(copy.getTimezone(), "timezone");
    assertEquals(copy.getUserPassword(), "password");
    assertNotNull(copy.getMemberOf());
    assertEquals(copy.getMemberOf().size(), 2);
    assertEquals(copy.getMemberOf().get(0), "Mocked DN");
    assertEquals(copy.getMemberOf().get(1), "Mocked DN1");
    assertEquals(copy.getAttribute(GLUU_STATUS), "true");
    assertNull(copy.getAttribute(OX_TRUST_PHOTOS_TYPE));
    assertNull(copy.getAttribute(OX_TRUST_PHONE_TYPE));
    assertNull(copy.getAttribute(OX_TRUST_ADDRESS_PRIMARY));
    assertNull(copy.getAttribute(OX_TRUST_ADDRESS_TYPE));
    assertNull(copy.getAttribute(OX_TRUST_COUNTRY));
    assertNull(copy.getAttribute(OX_TRUST_POSTAL_CODE));
    assertNull(copy.getAttribute(OX_TRUST_REGION));
    assertNull(copy.getAttribute(OX_TRUST_LOCALITY));
    assertNull(copy.getAttribute(OX_TRUST_ADDRESS_FORMATTED));
    assertNull(copy.getAttribute(OX_TRUST_STREET));
    assertNull(copy.getAttribute(OX_TRUST_EMAIL_PRIMARY));
    assertNull(copy.getAttribute(OX_TRUST_EMAIL_TYPE));
    assertEquals(copy.getAttribute(OX_TRUST_META_LOCATION), "location");
    assertEquals(copy.getAttribute(OX_TRUST_META_VERSION), "version");
    assertEquals(copy.getAttribute(OX_TRUST_META_LAST_MODIFIED), "lastModified");
    assertEquals(copy.getAttribute(OX_TRUST_META_CREATED), "created");
    assertEquals(copy.getAttribute(OX_TRUSTX509_CERTIFICATE), "[{\"value\":\"cert_value\"}]");
    assertEquals(copy.getAttribute(OX_TRUST_ENTITLEMENTS), "[{\"value\":\"entitlement_value\"}]");
    assertEquals(copy.getAttribute(OX_TRUST_ROLE), "[{\"value\":\"role_value\"}]");
    assertEquals(copy.getAttribute(OX_TRUST_ACTIVE), "true");
    assertEquals(copy.getAttribute(OX_TRUST_LOCALE), "locale");
    assertEquals(copy.getAttribute(OX_TRUST_TITLE), "title");
    assertEquals(copy.getAttribute(OX_TRUST_USER_TYPE), "userType");
    assertEquals(copy.getAttribute(OX_TRUST_PHOTOS), "[{\"value\":\"photo_value\",\"type\":\"photo_type\"}]");
    assertEquals(copy.getAttribute(OX_TRUST_IMS_VALUE), "[{\"value\":\"ims_value\",\"type\":\"ims_type\"}]");
    assertEquals(copy.getAttribute(OX_TRUST_PHONE_VALUE), "[{\"value\":\"phone_value\",\"type\":\"phone_type\"}]");
    assertEquals(copy.getAttribute(OX_TRUST_ADDRESSES), "[{\"type\":\"address_type\",\"streetAddress\":\"streetAddress\",\"locality\":\"locality\",\"region\":\"region\",\"postalCode\":\"postalCode\",\"country\":\"country\",\"formatted\":\"formatted\",\"primary\":\"address_primary\"}]");
    assertEquals(copy.getAttribute(OX_TRUST_EMAIL), "[{\"value\":\"email_value\",\"type\":\"email_type\",\"primary\":\"email_primary\"}]");
    assertEquals(copy.getAttribute(OX_TRUST_PROFILE_URL), "profileUrl");
    assertEquals(copy.getAttribute(OX_TRUST_NICK_NAME), "nickName");
    assertEquals(copy.getAttribute(OX_TRUST_EXTERNAL_ID), "externalId");
    assertEquals(copy.getAttribute(OX_TRUSTHONORIFIC_SUFFIX), "honorificSuffix");
    assertEquals(copy.getAttribute(OX_TRUSTHONORIFIC_PREFIX), "honorificPrefix");
    assertEquals(copy.getAttribute(OX_TRUST_MIDDLE_NAME), "middleName");
}
Also used : ScimEntitlements(org.gluu.oxtrust.model.scim.ScimEntitlements) ArrayList(java.util.ArrayList) ScimPersonIms(org.gluu.oxtrust.model.scim.ScimPersonIms) GluuCustomPerson(org.gluu.oxtrust.model.GluuCustomPerson) ScimPersonEmails(org.gluu.oxtrust.model.scim.ScimPersonEmails) PersonMeta(org.gluu.oxtrust.model.scim.PersonMeta) Scimx509Certificates(org.gluu.oxtrust.model.scim.Scimx509Certificates) ScimName(org.gluu.oxtrust.model.scim.ScimName) ScimRoles(org.gluu.oxtrust.model.scim.ScimRoles) ScimPersonAddresses(org.gluu.oxtrust.model.scim.ScimPersonAddresses) ScimPersonPhotos(org.gluu.oxtrust.model.scim.ScimPersonPhotos) ScimPersonGroups(org.gluu.oxtrust.model.scim.ScimPersonGroups) ScimPersonPhones(org.gluu.oxtrust.model.scim.ScimPersonPhones) ScimPerson(org.gluu.oxtrust.model.scim.ScimPerson) ScimCustomAttributes(org.gluu.oxtrust.model.scim.ScimCustomAttributes) Test(org.testng.annotations.Test) ConfigurableTest(org.gluu.oxtrust.action.test.ConfigurableTest)

Aggregations

ArrayList (java.util.ArrayList)14 ScimPerson (org.gluu.oxtrust.model.scim.ScimPerson)14 ScimPersonAddresses (org.gluu.oxtrust.model.scim.ScimPersonAddresses)14 ScimPersonEmails (org.gluu.oxtrust.model.scim.ScimPersonEmails)14 ScimPersonGroups (org.gluu.oxtrust.model.scim.ScimPersonGroups)14 ScimPersonIms (org.gluu.oxtrust.model.scim.ScimPersonIms)14 ScimPersonPhones (org.gluu.oxtrust.model.scim.ScimPersonPhones)14 ScimPersonPhotos (org.gluu.oxtrust.model.scim.ScimPersonPhotos)14 ScimRoles (org.gluu.oxtrust.model.scim.ScimRoles)14 ConfigurableTest (org.gluu.oxtrust.action.test.ConfigurableTest)13 GluuCustomPerson (org.gluu.oxtrust.model.GluuCustomPerson)13 PersonMeta (org.gluu.oxtrust.model.scim.PersonMeta)13 ScimEntitlements (org.gluu.oxtrust.model.scim.ScimEntitlements)13 ScimName (org.gluu.oxtrust.model.scim.ScimName)13 Test (org.testng.annotations.Test)13 ScimCustomAttributes (org.gluu.oxtrust.model.scim.ScimCustomAttributes)12 Scimx509Certificates (org.gluu.oxtrust.model.scim.Scimx509Certificates)12 GluuCustomAttribute (org.gluu.oxtrust.model.GluuCustomAttribute)4 GluuGroup (org.gluu.oxtrust.model.GluuGroup)1 GluuAttribute (org.xdi.model.GluuAttribute)1