use of org.orcid.persistence.jpa.entities.AddressEntity in project ORCID-Source by ORCID.
the class Jaxb2JpaAdapterImpl method setCountry.
private void setCountry(ProfileEntity profileEntity, ContactDetails contactDetails) {
Country contactCountry = contactDetails.getAddress() != null && contactDetails.getAddress().getCountry() != null ? contactDetails.getAddress().getCountry() : null;
Iso3166Country country = contactCountry != null ? contactCountry.getValue() : null;
if (country != null) {
Set<AddressEntity> addresses = profileEntity.getAddresses();
if (addresses == null) {
addresses = new HashSet<AddressEntity>();
profileEntity.setAddresses(addresses);
}
boolean addIt = true;
//If the address exists, don't add it
for (AddressEntity address : addresses) {
if (Objects.equals(country.value(), address.getIso2Country().value())) {
addIt = false;
}
}
if (addIt) {
AddressEntity newAddress = new AddressEntity();
newAddress.setDateCreated(new Date());
//The default country is the smallest one, so, lets add this one as the biggest display index possible for the record
newAddress.setIso2Country(org.orcid.jaxb.model.common_v2.Iso3166Country.fromValue(country.value()));
newAddress.setLastModified(new Date());
newAddress.setUser(profileEntity);
newAddress.setVisibility(getDefaultVisibility(profileEntity, contactCountry.getVisibility(), OrcidVisibilityDefaults.COUNTRY_DEFAULT));
//Set source
SourceEntity source = sourceManager.retrieveSourceEntity();
setSource(source, newAddress);
newAddress.setDisplayIndex(0L);
for (AddressEntity address : addresses) address.setDisplayIndex(address.getDisplayIndex() + 1L);
addresses.add(newAddress);
}
}
}
use of org.orcid.persistence.jpa.entities.AddressEntity in project ORCID-Source by ORCID.
the class Jpa2JaxbAdapterImpl method setCountry.
private void setCountry(ProfileEntity profileEntity, ContactDetails contactDetails) {
if (profileEntity.getAddresses() != null && !profileEntity.getAddresses().isEmpty()) {
//The primary will be the one with the biggest display index
AddressEntity primary = null;
for (AddressEntity address : profileEntity.getAddresses()) {
if (primary == null || primary.getDisplayIndex() < address.getDisplayIndex()) {
primary = address;
}
}
Source source = getSource(primary);
Address address = new Address();
Country country = new Country(Iso3166Country.fromValue(primary.getIso2Country().value()));
country.setSource(source);
country.setVisibility(Visibility.fromValue(primary.getVisibility().value()));
address.setCountry(country);
contactDetails.setAddress(address);
}
}
use of org.orcid.persistence.jpa.entities.AddressEntity in project ORCID-Source by ORCID.
the class MapperFacadeFactory method getAddressMapperFacade.
public MapperFacade getAddressMapperFacade() {
MapperFactory mapperFactory = new DefaultMapperFactory.Builder().build();
ClassMapBuilder<Address, AddressEntity> addressClassMap = mapperFactory.classMap(Address.class, AddressEntity.class);
addV2DateFields(addressClassMap);
registerSourceConverters(mapperFactory, addressClassMap);
addressClassMap.field("putCode", "id");
addressClassMap.field("country.value", "iso2Country");
addressClassMap.field("visibility", "visibility");
addressClassMap.fieldBToA("displayIndex", "displayIndex");
addressClassMap.byDefault();
addressClassMap.register();
return mapperFactory.getMapperFacade();
}
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());
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(claim.getActivitiesVisibilityDefault().getVisibility());
}
//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 JpaJaxbAddressAdapterTest method getAddressEntity.
private AddressEntity getAddressEntity() {
AddressEntity result = new AddressEntity();
result.setId(Long.valueOf(1));
result.setDateCreated(new Date());
result.setLastModified(new Date());
result.setIso2Country(Iso3166Country.US);
result.setUser(new ProfileEntity("0000-0000-0000-0000"));
result.setVisibility(Visibility.PUBLIC);
result.setClientSourceId("APP-000000001");
return result;
}
Aggregations