Search in sources :

Example 6 with AddressEntity

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);
        }
    }
}
Also used : SourceEntity(org.orcid.persistence.jpa.entities.SourceEntity) Country(org.orcid.jaxb.model.message.Country) Iso3166Country(org.orcid.jaxb.model.message.Iso3166Country) Iso3166Country(org.orcid.jaxb.model.message.Iso3166Country) AddressEntity(org.orcid.persistence.jpa.entities.AddressEntity) CompletionDate(org.orcid.jaxb.model.message.CompletionDate) SubmissionDate(org.orcid.jaxb.model.message.SubmissionDate) Date(java.util.Date) FuzzyDate(org.orcid.jaxb.model.message.FuzzyDate) PublicationDate(org.orcid.jaxb.model.message.PublicationDate) DeactivationDate(org.orcid.jaxb.model.message.DeactivationDate)

Example 7 with AddressEntity

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);
    }
}
Also used : AddressEntity(org.orcid.persistence.jpa.entities.AddressEntity)

Example 8 with AddressEntity

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();
}
Also used : Address(org.orcid.jaxb.model.record_v2.Address) DefaultMapperFactory(ma.glasnost.orika.impl.DefaultMapperFactory) DefaultMapperFactory(ma.glasnost.orika.impl.DefaultMapperFactory) MapperFactory(ma.glasnost.orika.MapperFactory) AddressEntity(org.orcid.persistence.jpa.entities.AddressEntity)

Example 9 with AddressEntity

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;
}
Also used : ProfileKeywordEntity(org.orcid.persistence.jpa.entities.ProfileKeywordEntity) ResearcherUrlEntity(org.orcid.persistence.jpa.entities.ResearcherUrlEntity) ExternalIdentifierEntity(org.orcid.persistence.jpa.entities.ExternalIdentifierEntity) ProfileEntity(org.orcid.persistence.jpa.entities.ProfileEntity) Date(java.util.Date) InvalidParameterException(java.security.InvalidParameterException) Visibility(org.orcid.jaxb.model.common_v2.Visibility) OtherNameEntity(org.orcid.persistence.jpa.entities.OtherNameEntity) AddressEntity(org.orcid.persistence.jpa.entities.AddressEntity) Transactional(org.springframework.transaction.annotation.Transactional)

Example 10 with AddressEntity

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;
}
Also used : AddressEntity(org.orcid.persistence.jpa.entities.AddressEntity) Date(java.util.Date) ProfileEntity(org.orcid.persistence.jpa.entities.ProfileEntity)

Aggregations

AddressEntity (org.orcid.persistence.jpa.entities.AddressEntity)19 Date (java.util.Date)8 ProfileEntity (org.orcid.persistence.jpa.entities.ProfileEntity)8 Test (org.junit.Test)6 Address (org.orcid.jaxb.model.record_v2.Address)5 OrcidDuplicatedElementException (org.orcid.core.exception.OrcidDuplicatedElementException)4 ExternalIdentifierEntity (org.orcid.persistence.jpa.entities.ExternalIdentifierEntity)4 OtherNameEntity (org.orcid.persistence.jpa.entities.OtherNameEntity)4 ProfileKeywordEntity (org.orcid.persistence.jpa.entities.ProfileKeywordEntity)4 ResearcherUrlEntity (org.orcid.persistence.jpa.entities.ResearcherUrlEntity)4 SourceEntity (org.orcid.persistence.jpa.entities.SourceEntity)4 ApplicationException (org.orcid.core.exception.ApplicationException)3 Visibility (org.orcid.jaxb.model.common_v2.Visibility)3 HashMap (java.util.HashMap)2 Transactional (javax.transaction.Transactional)2 Country (org.orcid.jaxb.model.message.Country)2 Iso3166Country (org.orcid.jaxb.model.message.Iso3166Country)2 OrcidProfile (org.orcid.jaxb.model.message.OrcidProfile)2 SubmissionDate (org.orcid.jaxb.model.message.SubmissionDate)2 OrgAffiliationRelationEntity (org.orcid.persistence.jpa.entities.OrgAffiliationRelationEntity)2