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.
387 logger.info(
" IN Utils.syncEmailReverse()...");
389 GluuCustomAttribute mail = gluuCustomPerson.getGluuCustomAttribute(
"mail");
390 GluuCustomAttribute oxTrustEmail = gluuCustomPerson.getGluuCustomAttribute(
"oxTrustEmail");
393 gluuCustomPerson.setAttribute(
"oxTrustEmail",
new String[0]);
398 Set<String> mailSet=
new HashSet<String>();
399 if (mail.getValues()!=null)
400 mailSet.addAll(Arrays.asList(mail.getValues()));
402 Set<String> mailSetCopy=
new HashSet<String>(mailSet);
403 Set<String> oxTrustEmailSet =
new HashSet<String>();
404 List<Email> oxTrustEmails=
new ArrayList<Email>();
406 if (oxTrustEmail!=null && oxTrustEmail.getValues()!=null){
407 for (String oxTrustEmailJson : oxTrustEmail.getValues())
408 oxTrustEmails.add(mapper.readValue(oxTrustEmailJson, Email.class));
410 for (Email email : oxTrustEmails)
411 oxTrustEmailSet.add(email.getValue());
413 mailSetCopy.removeAll(oxTrustEmailSet);
414 oxTrustEmailSet.removeAll(mailSet);
416 List<Integer> delIndexes=
new ArrayList<Integer>();
418 for (
int i=0;i<oxTrustEmails.size();i++) {
419 if (oxTrustEmailSet.contains(oxTrustEmails.get(i).getValue()))
420 delIndexes.add(0, i);
423 for (Integer idx : delIndexes)
424 oxTrustEmails.remove(idx.intValue());
426 List<String> newValues=
new ArrayList<String>();
427 for (Email email : oxTrustEmails)
428 newValues.add(mapper.writeValueAsString(email));
430 for (String mailStr : mailSetCopy){
431 Email email =
new Email();
432 email.setValue(mailStr);
433 email.setPrimary(
false);
434 newValues.add(mapper.writeValueAsString(email));
437 gluuCustomPerson.setAttribute(
"oxTrustEmail", newValues.toArray(
new String[0]));
441 logger.info(
" LEAVING Utils.syncEmailReverse()...");
443 return gluuCustomPerson;
static Logger logger
Definition: ServiceUtil.java:47
static ObjectMapper getObjectMapper()
Definition: ServiceUtil.java:447
static final ObjectMapper mapper
Definition: ServiceUtil.java:62