private void copyOtherNamesPreservingVisibility(PersonalDetails existingPersonalDetails, PersonalDetails updatedPersonalDetails) { OtherNames existingOtherNames = existingPersonalDetails.getOtherNames(); OtherNames updatedOtherNames = updatedPersonalDetails.getOtherNames(); // if no update, nothing to do if (updatedOtherNames == null) { return; } // otherwise take into account the visibility of updated and existing Visibility existingVisibility = existingOtherNames.getVisibility() != null ? existingOtherNames.getVisibility() : OrcidVisibilityDefaults.OTHER_NAMES_DEFAULT .getVisibility(); updatedOtherNames.setVisibility(updatedOtherNames.getVisibility() != null ? updatedOtherNames.getVisibility() : existingVisibility); // now visibility has been preserved, overwrite the content existingPersonalDetails.setOtherNames(updatedOtherNames); }
private OtherNames getOtherNames(ProfileEntity profile) { OtherNames otherNames = new OtherNames(); Visibility mostRestrictive = Visibility.PUBLIC; Set<OtherNameEntity> otherNamesEntitiy = profile.getOtherNames(); if (otherNamesEntitiy != null && otherNamesEntitiy.size() > 0) { for (OtherNameEntity otherNameEntity : otherNamesEntitiy) { //will only be null if there's an issue with the data or you're using this layer directly Visibility vis = (otherNameEntity.getVisibility() != null)?Visibility.valueOf(otherNameEntity.getVisibility()):Visibility.PRIVATE; if (vis.isMoreRestrictiveThan(mostRestrictive)) mostRestrictive = vis; OtherName otherName = new OtherName(otherNameEntity.getDisplayName(), vis); if(!PojoUtil.isEmpty(otherNameEntity.getElementSourceId())) { Source source = getSource(otherNameEntity); otherName.setSource(source); } otherNames.getOtherName().add(otherName); } } otherNames.setVisibility(mostRestrictive); return otherNames; }
OtherNames n = orcidMessage.getOrcidProfile().getOrcidBio().getPersonalDetails().getOtherNames(); if(n != null) { n.setVisibility(getMostFromCollection(n.getOtherName()));