use of org.orcid.persistence.jpa.entities.AddressEntity in project ORCID-Source by ORCID.
the class JpaJaxbAddressAdapterTest method fromOtherNameEntityToOtherNameTest.
@Test
public void fromOtherNameEntityToOtherNameTest() {
AddressEntity entity = getAddressEntity();
Address address = adapter.toAddress(entity);
assertNotNull(address);
assertEquals(Iso3166Country.US, address.getCountry().getValue());
assertNotNull(address.getCreatedDate());
assertNotNull(address.getLastModifiedDate());
assertEquals(Long.valueOf(1), address.getPutCode());
assertNotNull(address.getSource());
assertEquals("APP-000000001", address.getSource().retrieveSourcePath());
assertEquals(Visibility.PUBLIC, address.getVisibility());
}
use of org.orcid.persistence.jpa.entities.AddressEntity 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;
}
use of org.orcid.persistence.jpa.entities.AddressEntity in project ORCID-Source by ORCID.
the class AddressManagerImpl method updateAddresses.
@Override
public Addresses updateAddresses(String orcid, Addresses addresses) {
List<AddressEntity> existingAddressList = addressDao.getAddresses(orcid, getLastModified(orcid));
// Delete the deleted ones
for (AddressEntity existingAddress : existingAddressList) {
boolean deleteMe = true;
if (addresses.getAddress() != null) {
for (Address updatedOrNew : addresses.getAddress()) {
if (existingAddress.getId().equals(updatedOrNew.getPutCode())) {
deleteMe = false;
break;
}
}
}
if (deleteMe) {
try {
addressDao.deleteAddress(orcid, existingAddress.getId());
} catch (Exception e) {
throw new ApplicationException("Unable to delete address " + existingAddress.getId(), e);
}
}
}
if (addresses != null && addresses.getAddress() != null) {
for (Address updatedOrNew : addresses.getAddress()) {
if (updatedOrNew.getPutCode() != null) {
// Update the existing ones
for (AddressEntity existingAddress : existingAddressList) {
if (existingAddress.getId().equals(updatedOrNew.getPutCode())) {
existingAddress.setLastModified(new Date());
existingAddress.setVisibility(org.orcid.jaxb.model.common_v2.Visibility.fromValue(updatedOrNew.getVisibility().value()));
existingAddress.setIso2Country(org.orcid.jaxb.model.common_v2.Iso3166Country.fromValue(updatedOrNew.getCountry().getValue().value()));
existingAddress.setDisplayIndex(updatedOrNew.getDisplayIndex());
addressDao.merge(existingAddress);
}
}
} else {
// Add the new ones
AddressEntity newAddress = adapter.toAddressEntity(updatedOrNew);
SourceEntity sourceEntity = sourceManager.retrieveSourceEntity();
ProfileEntity profile = new ProfileEntity(orcid);
newAddress.setUser(profile);
newAddress.setDateCreated(new Date());
// Set the source id
if (sourceEntity.getSourceProfile() != null) {
newAddress.setSourceId(sourceEntity.getSourceProfile().getId());
}
if (sourceEntity.getSourceClient() != null) {
newAddress.setClientSourceId(sourceEntity.getSourceClient().getId());
}
newAddress.setVisibility(org.orcid.jaxb.model.common_v2.Visibility.fromValue(updatedOrNew.getVisibility().value()));
newAddress.setDisplayIndex(updatedOrNew.getDisplayIndex());
addressDao.persist(newAddress);
}
}
}
return addresses;
}
use of org.orcid.persistence.jpa.entities.AddressEntity in project ORCID-Source by ORCID.
the class AddressManagerImpl method updateAddress.
@Override
@Transactional
public Address updateAddress(String orcid, Long putCode, Address address, boolean isApiRequest) {
SourceEntity sourceEntity = sourceManager.retrieveSourceEntity();
AddressEntity updatedEntity = addressDao.getAddress(orcid, putCode);
Visibility originalVisibility = Visibility.fromValue(updatedEntity.getVisibility().value());
// Save the original source
String existingSourceId = updatedEntity.getSourceId();
String existingClientSourceId = updatedEntity.getClientSourceId();
// If it is an update from the API, check the source and preserve the original visibility
if (isApiRequest) {
orcidSecurityManager.checkSource(updatedEntity);
}
// Validate the address
PersonValidator.validateAddress(address, sourceEntity, false, isApiRequest, originalVisibility);
// Validate it is not duplicated
List<AddressEntity> existingAddresses = addressDao.getAddresses(orcid, getLastModified(orcid));
for (AddressEntity existing : existingAddresses) {
// If it is not the same element
if (!existing.getId().equals(address.getPutCode())) {
if (isDuplicated(existing, address, sourceEntity)) {
Map<String, String> params = new HashMap<String, String>();
params.put("type", "address");
params.put("value", address.getCountry().getValue().value());
throw new OrcidDuplicatedElementException(params);
}
}
}
adapter.toAddressEntity(address, updatedEntity);
updatedEntity.setLastModified(new Date());
// Be sure it doesn't overwrite the source
updatedEntity.setSourceId(existingSourceId);
updatedEntity.setClientSourceId(existingClientSourceId);
addressDao.merge(updatedEntity);
return adapter.toAddress(updatedEntity);
}
use of org.orcid.persistence.jpa.entities.AddressEntity in project ORCID-Source by ORCID.
the class AddressManagerReadOnlyImpl method getPrimaryAddress.
@Override
@Cacheable(value = "primary-address", key = "#orcid.concat('-').concat(#lastModified)")
public Address getPrimaryAddress(String orcid, long lastModified) {
List<AddressEntity> addresses = addressDao.getAddresses(orcid, getLastModified(orcid));
Address address = null;
if (addresses != null) {
// Look for the address with the largest display index
for (AddressEntity entity : addresses) {
if (address == null || address.getDisplayIndex() < entity.getDisplayIndex()) {
address = adapter.toAddress(entity);
}
}
}
return address;
}
Aggregations