Search in sources :

Example 61 with Email

use of org.gluu.oxtrust.model.scim2.Email in project oxTrust by GluuFederation.

the class PatchUtil method addPatch.

public GluuCustomPerson addPatch(User source, GluuCustomPerson destination) throws Exception {
    if (source == null) {
        return null;
    }
    if (destination == null) {
        log.trace(" creating a new GluuCustomPerson instant ");
        destination = new GluuCustomPerson();
    }
    log.trace(" setting schemas ");
    destination.setSchemas(source.getSchemas());
    personService.addCustomObjectClass(destination);
    // getting emails
    log.trace(" setting emails ");
    if (source.getEmails() != null && source.getEmails().size() > 0) {
        List<Email> emails = copyUtils2.getAttributeListValue(destination, Email.class, "oxTrustEmail");
        if (emails == null) {
            emails = new ArrayList<Email>();
        }
        emails.addAll(source.getEmails());
        copyUtils2.setAttributeListValue(destination, emails, "oxTrustEmail");
    }
    // getting addresses
    log.trace(" setting addresses ");
    if (source.getAddresses() != null && source.getAddresses().size() > 0) {
        List<Address> addresses = copyUtils2.getAttributeListValue(destination, Address.class, "oxTrustAddresses");
        if (addresses == null) {
            addresses = new ArrayList<Address>();
        }
        addresses.addAll(source.getAddresses());
        copyUtils2.setAttributeListValue(destination, addresses, "oxTrustAddresses");
    }
    // getting phone numbers;
    log.trace(" setting phoneNumbers ");
    if (source.getPhoneNumbers() != null && source.getPhoneNumbers().size() > 0) {
        List<PhoneNumber> phoneNumbers = copyUtils2.getAttributeListValue(destination, PhoneNumber.class, "oxTrustPhoneValue");
        if (phoneNumbers == null) {
            phoneNumbers = new ArrayList<PhoneNumber>();
        }
        phoneNumbers.addAll(source.getPhoneNumbers());
        copyUtils2.setAttributeListValue(destination, phoneNumbers, "oxTrustPhoneValue");
    }
    // getting ims
    log.trace(" setting ims ");
    if (source.getIms() != null && source.getIms().size() > 0) {
        List<Im> ims = copyUtils2.getAttributeListValue(destination, Im.class, "oxTrustImsValue");
        if (ims == null) {
            ims = new ArrayList<Im>();
        }
        ims.addAll(source.getIms());
        copyUtils2.setAttributeListValue(destination, ims, "oxTrustImsValue");
    }
    // getting Photos
    log.trace(" setting photos ");
    if (source.getPhotos() != null && source.getPhotos().size() > 0) {
        List<Photo> photos = copyUtils2.getAttributeListValue(destination, Photo.class, "oxTrustPhotos");
        if (photos == null) {
            photos = new ArrayList<Photo>();
        }
        photos.addAll(source.getPhotos());
        copyUtils2.setAttributeListValue(destination, photos, "oxTrustPhotos");
    }
    // getting user groups
    log.trace(" setting groups ");
    if (source.getGroups() != null && source.getGroups().size() > 0) {
        List<String> groupsList = destination.getMemberOf();
        List<GroupRef> listGroups = source.getGroups();
        for (GroupRef group : listGroups) {
            String groupToAdd = groupService.getDnForGroup(group.getValue());
            if (groupToAdd != null || !groupToAdd.trim().equalsIgnoreCase("")) {
                groupsList.add(groupToAdd);
            }
        }
        destination.setMemberOf(groupsList);
    }
    // getting roles
    log.trace(" setting roles ");
    if (source.getRoles() != null && source.getRoles().size() > 0) {
        List<Role> roles = copyUtils2.getAttributeListValue(destination, Role.class, "oxTrustRole");
        if (roles == null) {
            roles = new ArrayList<Role>();
        }
        roles.addAll(source.getRoles());
        copyUtils2.setAttributeListValue(destination, roles, "oxTrustRole");
    }
    // getting entitlements
    log.trace(" setting entitlements ");
    if (source.getEntitlements() != null && source.getEntitlements().size() > 0) {
        List<Entitlement> entitlements = copyUtils2.getAttributeListValue(destination, Entitlement.class, "oxTrustEntitlements");
        if (entitlements == null) {
            entitlements = new ArrayList<Entitlement>();
        }
        entitlements.addAll(source.getEntitlements());
        copyUtils2.setAttributeListValue(destination, entitlements, "oxTrustEntitlements");
    }
    // getting x509Certificates
    log.trace(" setting certs ");
    if (source.getX509Certificates() != null && source.getX509Certificates().size() > 0) {
        List<X509Certificate> X509Certificates = copyUtils2.getAttributeListValue(destination, X509Certificate.class, "oxTrustx509Certificate");
        if (X509Certificates == null) {
            X509Certificates = new ArrayList<X509Certificate>();
        }
        X509Certificates.addAll(source.getX509Certificates());
        copyUtils2.setAttributeListValue(destination, X509Certificates, "oxTrustx509Certificate");
    }
    log.trace(" setting extensions ");
    if (source.getExtensions() != null && (source.getExtensions().size() > 0)) {
        Map<String, Extension> destMap = destination.fetchExtensions();
        if (destMap == null) {
            destMap = new HashMap<String, Extension>();
        }
        destMap.putAll(source.getExtensions());
        destination.setExtensions(destMap);
    }
    if (source.isActive() != null) {
        copyUtils2.setGluuStatus(source, destination);
    }
    return destination;
}
Also used : Email(org.gluu.oxtrust.model.scim2.Email) Address(org.gluu.oxtrust.model.scim2.Address) Im(org.gluu.oxtrust.model.scim2.Im) Photo(org.gluu.oxtrust.model.scim2.Photo) GluuCustomPerson(org.gluu.oxtrust.model.GluuCustomPerson) X509Certificate(org.gluu.oxtrust.model.scim2.X509Certificate) Role(org.gluu.oxtrust.model.scim2.Role) Extension(org.gluu.oxtrust.model.scim2.Extension) PhoneNumber(org.gluu.oxtrust.model.scim2.PhoneNumber) GroupRef(org.gluu.oxtrust.model.scim2.GroupRef) Entitlement(org.gluu.oxtrust.model.scim2.Entitlement)

Example 62 with Email

use of org.gluu.oxtrust.model.scim2.Email in project oxTrust by GluuFederation.

the class PatchUtil method removePatch.

public GluuCustomPerson removePatch(User source, GluuCustomPerson destination) throws Exception {
    if (source == null) {
        return null;
    }
    if (destination == null) {
        log.trace(" creating a new GluuCustomPerson instant ");
        destination = new GluuCustomPerson();
    }
    log.trace(" setting schemas ");
    destination.setSchemas(source.getSchemas());
    personService.addCustomObjectClass(destination);
    log.trace(" setting userName ");
    if (source.getUserName() != null && source.getUserName().length() > 0) {
        destination.setUid(source.getUserName());
    }
    if (source.getName() != null) {
        log.trace(" setting givenname ");
        if (source.getName().getGivenName() != null) {
            destination.setGivenName("");
        }
        log.trace(" setting famillyname ");
        if (source.getName().getFamilyName() != null) {
            destination.setSurname("");
        }
        log.trace(" setting middlename ");
        if (source.getName().getMiddleName() != null) {
            // destination.setAttribute("oxTrustMiddleName",
            // source.getName().getMiddleName());
            destination.setAttribute("middleName", "");
        }
        log.trace(" setting honor");
        if (source.getName().getHonorificPrefix() != null) {
            destination.setAttribute("oxTrusthonorificPrefix", "");
        }
        if (source.getName().getHonorificSuffix() != null) {
            destination.setAttribute("oxTrusthonorificSuffix", "");
        }
    }
    log.trace(" setting displayname ");
    if (source.getDisplayName() != null) {
        destination.setDisplayName(source.getDisplayName());
    }
    log.trace(" setting externalID ");
    if (source.getExternalId() != null) {
        destination.setAttribute("oxTrustExternalId", source.getExternalId());
    }
    log.trace(" setting nickname ");
    if (source.getNickName() != null) {
        // destination.setAttribute("oxTrustNickName",
        // source.getNickName());
        destination.setAttribute("nickname", "");
    }
    log.trace(" setting profileURL ");
    if (source.getProfileUrl() != null) {
        destination.setAttribute("oxTrustProfileURL", "");
    }
    // getting emails
    log.trace(" setting emails ");
    if (source.getEmails() != null && source.getEmails().size() > 0) {
        List<Email> emails = copyUtils2.getAttributeListValue(destination, Email.class, "oxTrustEmail");
        if (emails != null && emails.size() > 0) {
            List<Email> newemails = source.getEmails();
            Iterator<Email> emailsIt = emails.iterator();
            Iterator<Email> newemailsIt = newemails.iterator();
            while (emailsIt.hasNext()) {
                Email email = emailsIt.next();
                if (email != null && email.getType() != null) {
                    while (newemailsIt.hasNext()) {
                        Email newEmail = newemailsIt.next();
                        if (newEmail.getType() != null && newEmail.getType().getValue().equals(email.getType().getValue())) {
                            emailsIt.remove();
                        }
                    }
                }
            }
            copyUtils2.setAttributeListValue(destination, emails, "oxTrustEmail");
        }
    }
    // getting addresses
    log.trace(" setting addresses ");
    if (source.getAddresses() != null && source.getAddresses().size() > 0) {
        List<Address> addresses = copyUtils2.getAttributeListValue(destination, Address.class, "oxTrustAddresses");
        if (addresses != null && addresses.size() > 0) {
            List<Address> newaddresses = source.getAddresses();
            Iterator<Address> addressesIt = addresses.iterator();
            Iterator<Address> newaddressesIt = newaddresses.iterator();
            while (addressesIt.hasNext()) {
                Address address = addressesIt.next();
                if (address != null && address.getType() != null) {
                    while (newaddressesIt.hasNext()) {
                        Address newaddress = newaddressesIt.next();
                        if (newaddress.getType().getValue() != null && newaddress.getType().getValue().equals(address.getType().getValue())) {
                            addressesIt.remove();
                        }
                    }
                }
            }
            copyUtils2.setAttributeListValue(destination, addresses, "oxTrustAddresses");
        }
    }
    // getting phone numbers;
    log.trace(" setting phoneNumbers ");
    if (source.getPhoneNumbers() != null && source.getPhoneNumbers().size() > 0) {
        List<PhoneNumber> phoneNumbers = copyUtils2.getAttributeListValue(destination, PhoneNumber.class, "oxTrustPhoneValue");
        if (phoneNumbers != null && phoneNumbers.size() > 0) {
            List<PhoneNumber> newPhoneNumbers = source.getPhoneNumbers();
            Iterator<PhoneNumber> phoneNumbersIt = phoneNumbers.iterator();
            Iterator<PhoneNumber> newPhoneNumbersIt = newPhoneNumbers.iterator();
            while (phoneNumbersIt.hasNext()) {
                PhoneNumber phoneNumber = phoneNumbersIt.next();
                while (newPhoneNumbersIt.hasNext()) {
                    PhoneNumber newPhoneNumber = newPhoneNumbersIt.next();
                    if (newPhoneNumber.getType() != null && newPhoneNumber.getType().getValue().equals(phoneNumber.getType().getValue())) {
                        phoneNumbersIt.remove();
                    }
                }
            }
            copyUtils2.setAttributeListValue(destination, phoneNumbers, "oxTrustPhoneValue");
        }
    }
    // getting ims
    log.trace(" setting ims ");
    if (source.getIms() != null && source.getIms().size() > 0) {
        List<Im> ims = copyUtils2.getAttributeListValue(destination, Im.class, "oxTrustImsValue");
        if (ims != null && ims.size() > 0) {
            List<Im> newims = source.getIms();
            Iterator<Im> imsIt = ims.iterator();
            Iterator<Im> newimssIt = newims.iterator();
            while (imsIt.hasNext()) {
                Im im = imsIt.next();
                if (im != null && im.getType() != null) {
                    while (newimssIt.hasNext()) {
                        Im newIm = newimssIt.next();
                        if (newIm.getType() != null && newIm.getType().getValue().equals(im.getType().getValue())) {
                            imsIt.remove();
                        }
                    }
                }
            }
            copyUtils2.setAttributeListValue(destination, ims, "oxTrustImsValue");
        }
    }
    // getting Photos
    log.trace(" setting photos ");
    if (source.getPhotos() != null && source.getPhotos().size() > 0) {
        List<Photo> photos = copyUtils2.getAttributeListValue(destination, Photo.class, "oxTrustPhotos");
        if (photos != null && photos.size() > 0) {
            List<Photo> newPhotos = source.getPhotos();
            Iterator<Photo> photosIt = photos.iterator();
            Iterator<Photo> newphotosIt = newPhotos.iterator();
            while (photosIt.hasNext()) {
                Photo old = photosIt.next();
                if (old != null && old.getType() != null) {
                    while (newphotosIt.hasNext()) {
                        Photo newelement = newphotosIt.next();
                        if (newelement.getType() != null && newelement.getType().getValue().equals(old.getType().getValue())) {
                            photosIt.remove();
                        }
                    }
                }
            }
            copyUtils2.setAttributeListValue(destination, photos, "oxTrustPhotos");
        }
    }
    if (source.getUserType() != null) {
        destination.setAttribute("oxTrustUserType", "");
    }
    if (source.getTitle() != null) {
        destination.setAttribute("oxTrustTitle", "");
    }
    if (source.getPreferredLanguage() != null) {
        destination.setPreferredLanguage("");
    }
    if (source.getLocale() != null) {
        // destination.setAttribute("oxTrustLocale", source.getLocale());
        destination.setAttribute("locale", "");
    }
    if (source.getTimezone() != null) {
        destination.setTimezone("");
    }
    if (source.isActive() != null) {
        destination.setAttribute("oxTrustActive", source.isActive().toString());
    }
    if (source.getPassword() != null && source.getPassword().length() > 0) {
        destination.setUserPassword(source.getPassword());
    }
    // getting user groups
    log.trace(" setting groups ");
    if (source.getGroups() != null && source.getGroups().size() > 0) {
        List<String> members = destination.getMemberOf();
        if (members != null || members.size() > 0) {
            members.removeAll(source.getGroups());
        }
        destination.setMemberOf(members);
    }
    // getting roles
    log.trace(" setting roles ");
    if (source.getRoles() != null && source.getRoles().size() > 0) {
        List<Role> roles = copyUtils2.getAttributeListValue(destination, Role.class, "oxTrustRole");
        if (roles != null && roles.size() > 0) {
            List<Role> newRoles = source.getRoles();
            Iterator<Role> oldsIt = roles.iterator();
            Iterator<Role> newsIt = newRoles.iterator();
            while (oldsIt.hasNext()) {
                Role old = oldsIt.next();
                if (old != null && old.getType() != null) {
                    while (newsIt.hasNext()) {
                        Role newelement = newsIt.next();
                        if (newelement.getType() != null && newelement.getType().getValue().equals(old.getType().getValue())) {
                            oldsIt.remove();
                        }
                    }
                }
            }
            copyUtils2.setAttributeListValue(destination, roles, "oxTrustRole");
        }
    }
    // getting entitlements
    log.trace(" setting entitlements ");
    if (source.getEntitlements() != null && source.getEntitlements().size() > 0) {
        List<Entitlement> entitlements = copyUtils2.getAttributeListValue(destination, Entitlement.class, "oxTrustEntitlements");
        if (entitlements != null && entitlements.size() > 0) {
            List<Entitlement> newEentitlements = source.getEntitlements();
            Iterator<Entitlement> oldsIt = entitlements.iterator();
            Iterator<Entitlement> newsIt = newEentitlements.iterator();
            while (oldsIt.hasNext()) {
                Entitlement old = oldsIt.next();
                if (old != null && old.getType() != null) {
                    while (newsIt.hasNext()) {
                        Entitlement newelement = newsIt.next();
                        if (newelement.getType() != null && newelement.getType().getValue().equals(old.getType().getValue())) {
                            oldsIt.remove();
                        }
                    }
                }
            }
            copyUtils2.setAttributeListValue(destination, entitlements, "oxTrustEntitlements");
        }
    }
    // getting x509Certificates
    log.trace(" setting certs ");
    if (source.getX509Certificates() != null && source.getX509Certificates().size() > 0) {
        List<X509Certificate> X509Certificates = copyUtils2.getAttributeListValue(destination, X509Certificate.class, "oxTrustx509Certificate");
        if (X509Certificates != null && X509Certificates.size() > 0) {
            List<X509Certificate> newX509Certificates = source.getX509Certificates();
            Iterator<X509Certificate> oldsIt = X509Certificates.iterator();
            Iterator<X509Certificate> newsIt = newX509Certificates.iterator();
            while (oldsIt.hasNext()) {
                X509Certificate old = oldsIt.next();
                if (old != null && old.getType() != null) {
                    while (newsIt.hasNext()) {
                        X509Certificate newelement = newsIt.next();
                        if (newelement.getType() != null && newelement.getType().getValue().equals(old.getType().getValue())) {
                            oldsIt.remove();
                        }
                    }
                }
            }
            copyUtils2.setAttributeListValue(destination, X509Certificates, "oxTrustx509Certificate");
        }
    }
    log.trace(" setting extensions ");
    if (source.getExtensions() != null && (source.getExtensions().size() > 0)) {
        destination.setExtensions(source.getExtensions());
    }
    if (source.isActive() != null) {
        copyUtils2.setGluuStatus(source, destination);
    }
    return destination;
}
Also used : Email(org.gluu.oxtrust.model.scim2.Email) Address(org.gluu.oxtrust.model.scim2.Address) Im(org.gluu.oxtrust.model.scim2.Im) Photo(org.gluu.oxtrust.model.scim2.Photo) GluuCustomPerson(org.gluu.oxtrust.model.GluuCustomPerson) X509Certificate(org.gluu.oxtrust.model.scim2.X509Certificate) Role(org.gluu.oxtrust.model.scim2.Role) PhoneNumber(org.gluu.oxtrust.model.scim2.PhoneNumber) Entitlement(org.gluu.oxtrust.model.scim2.Entitlement)

Example 63 with Email

use of org.gluu.oxtrust.model.scim2.Email in project oxTrust by GluuFederation.

the class UserExtensionsTest method createUserObject.

private User createUserObject() throws Exception {
    User user = new User();
    user.setUserName("userjson.add.username");
    String testUserName = user.getUserName() + " (" + System.currentTimeMillis() + ")";
    user.setUserName(testUserName);
    user.setPassword("test");
    user.setDisplayName("Scim2DisplayName");
    Email email = new Email();
    email.setValue("scim@gluu.org");
    email.setType(org.gluu.oxtrust.model.scim2.Email.Type.WORK);
    email.setPrimary(true);
    user.getEmails().add(email);
    PhoneNumber phone = new PhoneNumber();
    phone.setType(org.gluu.oxtrust.model.scim2.PhoneNumber.Type.WORK);
    phone.setValue("654-6509-263");
    user.getPhoneNumbers().add(phone);
    org.gluu.oxtrust.model.scim2.Address address = new org.gluu.oxtrust.model.scim2.Address();
    address.setCountry("US");
    address.setStreetAddress("random street");
    address.setLocality("Austin");
    address.setPostalCode("65672");
    address.setRegion("TX");
    address.setPrimary(true);
    address.setType(org.gluu.oxtrust.model.scim2.Address.Type.WORK);
    address.setFormatted(address.getStreetAddress() + " " + address.getLocality() + " " + address.getPostalCode() + " " + address.getRegion() + " " + address.getCountry());
    user.getAddresses().add(address);
    user.setPreferredLanguage("US_en");
    org.gluu.oxtrust.model.scim2.Name name = new org.gluu.oxtrust.model.scim2.Name();
    name.setFamilyName("SCIM");
    name.setGivenName("SCIM");
    user.setName(name);
    // User Extensions
    Extension.Builder extensionBuilder = new Extension.Builder(Constants.USER_EXT_SCHEMA_ID);
    extensionBuilder.setField("scimCustomFirst", "customFirstValue");
    // extensionBuilder.setFieldAsList("scimCustomSecond", Arrays.asList(new
    // String[]{"2016-02-23T03:35:22Z", "2016-02-24T01:52:05Z"}));
    extensionBuilder.setFieldAsList("scimCustomSecond", Arrays.asList(new Date[] { (new DateTime("1969-01-02")).toDate(), (new DateTime("2016-02-27")).toDate() }));
    extensionBuilder.setField("scimCustomThird", new BigDecimal(3000));
    user.addExtension(extensionBuilder.build());
    return user;
}
Also used : User(org.gluu.oxtrust.model.scim2.User) Email(org.gluu.oxtrust.model.scim2.Email) Date(java.util.Date) DateTime(org.joda.time.DateTime) BigDecimal(java.math.BigDecimal) Extension(org.gluu.oxtrust.model.scim2.Extension) PhoneNumber(org.gluu.oxtrust.model.scim2.PhoneNumber)

Example 64 with Email

use of org.gluu.oxtrust.model.scim2.Email in project oxTrust by GluuFederation.

the class Scim2UserService method updateUser.

public User updateUser(String id, User user) throws Exception {
    GluuCustomPerson gluuPerson = personService.getPersonByInum(id);
    if (gluuPerson == null) {
        throw new EntryPersistenceException("Scim2UserService.updateUser(): " + "Resource " + id + " not found");
    } else {
        // Validate if attempting to update userName of a different id
        if (user.getUserName() != null) {
            GluuCustomPerson personToFind = new GluuCustomPerson();
            personToFind.setUid(user.getUserName());
            List<GluuCustomPerson> foundPersons = personService.findPersons(personToFind, 2);
            if (foundPersons != null && foundPersons.size() > 0) {
                for (GluuCustomPerson foundPerson : foundPersons) {
                    if (foundPerson != null && !foundPerson.getInum().equalsIgnoreCase(gluuPerson.getInum())) {
                        throw new DuplicateEntryException("Cannot update userName of a different id: " + user.getUserName());
                    }
                }
            }
        }
    }
    GluuCustomPerson updatedGluuPerson = copyUtils2.copy(user, gluuPerson, true);
    if (user.getGroups().size() > 0) {
        serviceUtil.groupMembersAdder(updatedGluuPerson, personService.getDnForPerson(id));
    }
    log.info(" Setting meta: update user ");
    // Date should be in UTC format
    DateTimeFormatter dateTimeFormatter = ISODateTimeFormat.dateTime().withZoneUTC();
    Date dateLastModified = DateTime.now().toDate();
    updatedGluuPerson.setAttribute("oxTrustMetaLastModified", dateTimeFormatter.print(dateLastModified.getTime()));
    if (updatedGluuPerson.getAttribute("oxTrustMetaLocation") == null || (updatedGluuPerson.getAttribute("oxTrustMetaLocation") != null && updatedGluuPerson.getAttribute("oxTrustMetaLocation").isEmpty())) {
        String relativeLocation = "/scim/v2/Users/" + id;
        updatedGluuPerson.setAttribute("oxTrustMetaLocation", relativeLocation);
    }
    // Sync email, forward ("oxTrustEmail" -> "mail")
    updatedGluuPerson = serviceUtil.syncEmailForward(updatedGluuPerson, true);
    // For custom script: update user
    if (externalScimService.isEnabled()) {
        externalScimService.executeScimUpdateUserMethods(updatedGluuPerson);
    }
    personService.updatePerson(updatedGluuPerson);
    log.debug(" person updated ");
    User updatedUser = copyUtils2.copy(updatedGluuPerson, null);
    return updatedUser;
}
Also used : GluuCustomPerson(org.gluu.oxtrust.model.GluuCustomPerson) User(org.gluu.oxtrust.model.scim2.User) ScimPatchUser(org.gluu.oxtrust.model.scim2.ScimPatchUser) EntryPersistenceException(org.gluu.site.ldap.persistence.exception.EntryPersistenceException) DuplicateEntryException(org.gluu.site.ldap.exception.DuplicateEntryException) DateTimeFormatter(org.joda.time.format.DateTimeFormatter) Date(java.util.Date)

Example 65 with Email

use of org.gluu.oxtrust.model.scim2.Email in project oxTrust by GluuFederation.

the class ServiceUtil method syncEmailReverse.

/**
 * One-way sync from "mail" to "oxTrustEmail". This method takes current values of "oxTrustEmail" attribute, deletes
 * those that do not match any of those in "mail", and adds new ones that are missing.
 * @param gluuCustomPerson
 * @param isScim2
 * @return
 * @throws Exception
 */
public static GluuCustomPerson syncEmailReverse(GluuCustomPerson gluuCustomPerson, boolean isScim2) throws Exception {
    /*
        Implementation of this method could not be simplified to creating a new empty list for oxTrustEmail and then do
        the respective additions based on current mail values since information such as display, primary, etc. would be lost.
        Instead, it uses set operations to know which existing entries must be removed or retained, and then apply additions
        of new data.
         */
    logger.info(" IN Utils.syncEmailReverse()...");
    GluuCustomAttribute mail = gluuCustomPerson.getGluuCustomAttribute("mail");
    GluuCustomAttribute oxTrustEmail = gluuCustomPerson.getGluuCustomAttribute("oxTrustEmail");
    if (mail == null) {
        gluuCustomPerson.setAttribute("oxTrustEmail", new String[0]);
    } else {
        ObjectMapper mapper = getObjectMapper();
        Set<String> mailSet = new HashSet<String>();
        if (mail.getValues() != null)
            mailSet.addAll(Arrays.asList(mail.getValues()));
        Set<String> mailSetCopy = new HashSet<String>(mailSet);
        Set<String> oxTrustEmailSet = new HashSet<String>();
        List<Email> oxTrustEmails = new ArrayList<Email>();
        if (oxTrustEmail != null && oxTrustEmail.getValues() != null) {
            for (String oxTrustEmailJson : oxTrustEmail.getValues()) oxTrustEmails.add(mapper.readValue(oxTrustEmailJson, Email.class));
            for (Email email : oxTrustEmails) oxTrustEmailSet.add(email.getValue());
        }
        // Keep those in "mail" and not in oxTrustEmail
        mailSetCopy.removeAll(oxTrustEmailSet);
        // Keep those in oxTrustEmail and not in "mail"
        oxTrustEmailSet.removeAll(mailSet);
        List<Integer> delIndexes = new ArrayList<Integer>();
        // Build a list of indexes that should be removed in oxTrustEmails
        for (int i = 0; i < oxTrustEmails.size(); i++) {
            if (oxTrustEmailSet.contains(oxTrustEmails.get(i).getValue()))
                delIndexes.add(0, i);
        }
        // Delete unmatched oxTrustEmail entries from highest index to lowest
        for (Integer idx : delIndexes) // must not pass an Integer directly
        oxTrustEmails.remove(idx.intValue());
        List<String> newValues = new ArrayList<String>();
        for (Email email : oxTrustEmails) newValues.add(mapper.writeValueAsString(email));
        for (String mailStr : mailSetCopy) {
            Email email = new Email();
            email.setValue(mailStr);
            email.setPrimary(false);
            newValues.add(mapper.writeValueAsString(email));
        }
        gluuCustomPerson.setAttribute("oxTrustEmail", newValues.toArray(new String[0]));
    }
    logger.info(" LEAVING Utils.syncEmailReverse()...");
    return gluuCustomPerson;
}
Also used : GluuCustomAttribute(org.gluu.oxtrust.model.GluuCustomAttribute) Email(org.gluu.oxtrust.model.scim2.user.Email) ObjectMapper(org.codehaus.jackson.map.ObjectMapper)

Aggregations

Email (org.orcid.jaxb.model.record_v2.Email)82 Test (org.junit.Test)78 Emails (org.orcid.jaxb.model.record_v2.Emails)49 Address (org.orcid.jaxb.model.record_v2.Address)41 Keyword (org.orcid.jaxb.model.record_v2.Keyword)41 PersonExternalIdentifier (org.orcid.jaxb.model.record_v2.PersonExternalIdentifier)41 ResearcherUrl (org.orcid.jaxb.model.record_v2.ResearcherUrl)41 OtherName (org.orcid.jaxb.model.record_v2.OtherName)39 Person (org.orcid.jaxb.model.record_v2.Person)35 Biography (org.orcid.jaxb.model.record_v2.Biography)34 OtherNames (org.orcid.jaxb.model.record_v2.OtherNames)33 Addresses (org.orcid.jaxb.model.record_v2.Addresses)31 Keywords (org.orcid.jaxb.model.record_v2.Keywords)31 PersonExternalIdentifiers (org.orcid.jaxb.model.record_v2.PersonExternalIdentifiers)31 ResearcherUrls (org.orcid.jaxb.model.record_v2.ResearcherUrls)31 Name (org.orcid.jaxb.model.record_v2.Name)30 Record (org.orcid.jaxb.model.record_v2.Record)19 ArrayList (java.util.ArrayList)18 EducationSummary (org.orcid.jaxb.model.record.summary_v2.EducationSummary)18 EmploymentSummary (org.orcid.jaxb.model.record.summary_v2.EmploymentSummary)18