use of org.orcid.persistence.jpa.entities.OtherNameEntity in project ORCID-Source by ORCID.
the class JpaJaxbOtherNameAdapterTest method fromOtherNameEntityToOtherNameTest.
@Test
public void fromOtherNameEntityToOtherNameTest() {
OtherNameEntity entity = getOtherNameEntity();
OtherName otherName = adapter.toOtherName(entity);
assertNotNull(otherName);
assertEquals("display-name", otherName.getContent());
assertNotNull(otherName.getCreatedDate());
assertNotNull(otherName.getLastModifiedDate());
assertEquals(Long.valueOf(1), otherName.getPutCode());
assertNotNull(otherName.getSource());
assertEquals("APP-000000001", otherName.getSource().retrieveSourcePath());
assertEquals(Visibility.PUBLIC, otherName.getVisibility());
}
use of org.orcid.persistence.jpa.entities.OtherNameEntity in project ORCID-Source by ORCID.
the class JpaJaxbOtherNameAdapterTest method getOtherNameEntity.
private OtherNameEntity getOtherNameEntity() {
OtherNameEntity result = new OtherNameEntity();
result.setId(Long.valueOf(1));
result.setDateCreated(new Date());
result.setLastModified(new Date());
result.setDisplayName("display-name");
result.setProfile(new ProfileEntity("0000-0000-0000-0000"));
result.setVisibility(org.orcid.jaxb.model.common_v2.Visibility.PUBLIC);
result.setClientSourceId("APP-000000001");
return result;
}
use of org.orcid.persistence.jpa.entities.OtherNameEntity in project ORCID-Source by ORCID.
the class OtherNameManagerImpl method createOtherName.
@Override
@Transactional
public OtherName createOtherName(String orcid, OtherName otherName, boolean isApiRequest) {
SourceEntity sourceEntity = sourceManager.retrieveSourceEntity();
// Validate the otherName
PersonValidator.validateOtherName(otherName, sourceEntity, true, isApiRequest, null);
// Validate it is not duplicated
List<OtherNameEntity> existingOtherNames = otherNameDao.getOtherNames(orcid, getLastModified(orcid));
for (OtherNameEntity existing : existingOtherNames) {
if (isDuplicated(existing, otherName, sourceEntity)) {
Map<String, String> params = new HashMap<String, String>();
params.put("type", "other-name");
params.put("value", otherName.getContent());
throw new OrcidDuplicatedElementException(params);
}
}
OtherNameEntity newEntity = jpaJaxbOtherNameAdapter.toOtherNameEntity(otherName);
ProfileEntity profile = profileEntityCacheManager.retrieve(orcid);
newEntity.setProfile(profile);
newEntity.setDateCreated(new Date());
// Set the source
if (sourceEntity.getSourceProfile() != null) {
newEntity.setSourceId(sourceEntity.getSourceProfile().getId());
}
if (sourceEntity.getSourceClient() != null) {
newEntity.setClientSourceId(sourceEntity.getSourceClient().getId());
}
setIncomingPrivacy(newEntity, profile);
DisplayIndexCalculatorHelper.setDisplayIndexOnNewEntity(newEntity, isApiRequest);
otherNameDao.persist(newEntity);
return jpaJaxbOtherNameAdapter.toOtherName(newEntity);
}
use of org.orcid.persistence.jpa.entities.OtherNameEntity 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(org.orcid.jaxb.model.common_v2.Visibility.fromValue(updatedOrNew.getVisibility().value()));
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(org.orcid.jaxb.model.common_v2.Visibility.fromValue(updatedOrNew.getVisibility().value()));
newOtherName.setDisplayIndex(updatedOrNew.getDisplayIndex());
otherNameDao.persist(newOtherName);
}
}
}
return otherNames;
}
use of org.orcid.persistence.jpa.entities.OtherNameEntity in project ORCID-Source by ORCID.
the class ProfileEntityManagerImpl method claimProfileAndUpdatePreferences.
@Override
@Transactional
public boolean claimProfileAndUpdatePreferences(String orcid, String email, Locale locale, Claim claim) {
// Verify the email
boolean emailVerified = emailManager.verifySetCurrentAndPrimary(orcid, email);
if (!emailVerified) {
throw new InvalidParameterException("Unable to claim and verify email: " + email + " for user: " + orcid);
}
// Update the profile entity fields
ProfileEntity profile = profileDao.find(orcid);
profile.setLastModified(new Date());
profile.setIndexingStatus(IndexingStatus.REINDEX);
profile.setClaimed(true);
profile.setCompletedDate(new Date());
profile.setEncryptedPassword(encryptionManager.hashForInternalUse(claim.getPassword().getValue()));
if (locale != null) {
profile.setLocale(org.orcid.jaxb.model.common_v2.Locale.fromValue(locale.value()));
}
if (claim != null) {
profile.setSendChangeNotifications(claim.getSendChangeNotifications().getValue());
profile.setSendOrcidNews(claim.getSendOrcidNews().getValue());
profile.setActivitiesVisibilityDefault(org.orcid.jaxb.model.common_v2.Visibility.valueOf(claim.getActivitiesVisibilityDefault().getVisibility().name()));
}
// Update the visibility for every bio element to the visibility
// selected by the user
// Update the bio
org.orcid.jaxb.model.common_v2.Visibility defaultVisibility = org.orcid.jaxb.model.common_v2.Visibility.fromValue(claim.getActivitiesVisibilityDefault().getVisibility().value());
if (profile.getBiographyEntity() != null) {
profile.getBiographyEntity().setVisibility(defaultVisibility);
}
// Update address
if (profile.getAddresses() != null) {
for (AddressEntity a : profile.getAddresses()) {
a.setVisibility(defaultVisibility);
}
}
// Update the keywords
if (profile.getKeywords() != null) {
for (ProfileKeywordEntity k : profile.getKeywords()) {
k.setVisibility(defaultVisibility);
}
}
// Update the other names
if (profile.getOtherNames() != null) {
for (OtherNameEntity o : profile.getOtherNames()) {
o.setVisibility(defaultVisibility);
}
}
// Update the researcher urls
if (profile.getResearcherUrls() != null) {
for (ResearcherUrlEntity r : profile.getResearcherUrls()) {
r.setVisibility(defaultVisibility);
}
}
// Update the external identifiers
if (profile.getExternalIdentifiers() != null) {
for (ExternalIdentifierEntity e : profile.getExternalIdentifiers()) {
e.setVisibility(defaultVisibility);
}
}
profileDao.merge(profile);
profileDao.flush();
return true;
}
Aggregations