use of org.orcid.jaxb.model.record_rc3.OtherName in project ORCID-Source by ORCID.
the class OtherNameManagerImpl method updateOtherNames.
@Override
@Transactional
public OtherNames updateOtherNames(String orcid, OtherNames otherNames) {
List<OtherNameEntity> existingOtherNamesEntityList = otherNameDao.getOtherNames(orcid, getLastModified(orcid));
//Delete the deleted ones
for (OtherNameEntity existingOtherName : existingOtherNamesEntityList) {
boolean deleteMe = true;
if (otherNames.getOtherNames() != null) {
for (OtherName updatedOrNew : otherNames.getOtherNames()) {
if (existingOtherName.getId().equals(updatedOrNew.getPutCode())) {
deleteMe = false;
break;
}
}
}
if (deleteMe) {
try {
otherNameDao.deleteOtherName(existingOtherName);
} catch (Exception e) {
throw new ApplicationException("Unable to delete other name " + existingOtherName.getId(), e);
}
}
}
if (otherNames != null && otherNames.getOtherNames() != null) {
for (OtherName updatedOrNew : otherNames.getOtherNames()) {
if (updatedOrNew.getPutCode() != null) {
//Update the existing ones
for (OtherNameEntity existingOtherName : existingOtherNamesEntityList) {
if (existingOtherName.getId().equals(updatedOrNew.getPutCode())) {
existingOtherName.setLastModified(new Date());
existingOtherName.setVisibility(updatedOrNew.getVisibility());
existingOtherName.setDisplayName(updatedOrNew.getContent());
existingOtherName.setDisplayIndex(updatedOrNew.getDisplayIndex());
otherNameDao.merge(existingOtherName);
}
}
} else {
//Add the new ones
OtherNameEntity newOtherName = jpaJaxbOtherNameAdapter.toOtherNameEntity(updatedOrNew);
SourceEntity sourceEntity = sourceManager.retrieveSourceEntity();
ProfileEntity profile = new ProfileEntity(orcid);
newOtherName.setProfile(profile);
newOtherName.setDateCreated(new Date());
//Set the source
if (sourceEntity.getSourceProfile() != null) {
newOtherName.setSourceId(sourceEntity.getSourceProfile().getId());
}
if (sourceEntity.getSourceClient() != null) {
newOtherName.setClientSourceId(sourceEntity.getSourceClient().getId());
}
newOtherName.setVisibility(updatedOrNew.getVisibility());
newOtherName.setDisplayIndex(updatedOrNew.getDisplayIndex());
otherNameDao.persist(newOtherName);
}
}
}
return otherNames;
}
use of org.orcid.jaxb.model.record_rc3.OtherName in project ORCID-Source by ORCID.
the class OtherNameForm method toOtherName.
public OtherName toOtherName() {
OtherName otherName = new OtherName();
if (!PojoUtil.isEmpty(this.getContent())) {
otherName.setContent(this.getContent());
}
if (this.visibility != null && this.visibility.getVisibility() != null) {
otherName.setVisibility(org.orcid.jaxb.model.common_v2.Visibility.fromValue(this.getVisibility().getVisibility().value()));
}
if (!PojoUtil.isEmpty(this.getPutCode())) {
otherName.setPutCode(Long.valueOf(this.getPutCode()));
}
if (displayIndex != null) {
otherName.setDisplayIndex(displayIndex);
} else {
otherName.setDisplayIndex(0L);
}
otherName.setSource(new Source(source));
return otherName;
}
use of org.orcid.jaxb.model.record_rc3.OtherName in project ORCID-Source by ORCID.
the class OtherNameManagerTest method testAddOtherNameToUnclaimedRecordPreserveOtherNameVisibility.
@Test
public void testAddOtherNameToUnclaimedRecordPreserveOtherNameVisibility() {
when(sourceManager.retrieveSourceEntity()).thenReturn(new SourceEntity(new ClientDetailsEntity(CLIENT_1_ID)));
OtherName otherName = getOtherName();
otherName = otherNameManager.createOtherName(unclaimedOrcid, otherName, true);
otherName = otherNameManager.getOtherName(unclaimedOrcid, otherName.getPutCode());
assertNotNull(otherName);
assertEquals(Visibility.PUBLIC, otherName.getVisibility());
}
use of org.orcid.jaxb.model.record_rc3.OtherName in project ORCID-Source by ORCID.
the class OtherNameManagerTest method displayIndexIsSetTo_1_FromUI.
@Test
public void displayIndexIsSetTo_1_FromUI() {
when(sourceManager.retrieveSourceEntity()).thenReturn(new SourceEntity(new ClientDetailsEntity(CLIENT_1_ID)));
OtherName otherName = getOtherName();
otherName.setContent(otherName.getContent() + " fromUI");
otherName = otherNameManager.createOtherName(claimedOrcid, otherName, false);
otherName = otherNameManager.getOtherName(claimedOrcid, otherName.getPutCode());
assertNotNull(otherName);
assertEquals(Long.valueOf(1), otherName.getDisplayIndex());
}
use of org.orcid.jaxb.model.record_rc3.OtherName in project ORCID-Source by ORCID.
the class OtherNameManagerTest method getOtherName.
private OtherName getOtherName() {
OtherName otherName = new OtherName();
otherName.setContent("other-name");
otherName.setVisibility(Visibility.PUBLIC);
return otherName;
}
Aggregations