Search in sources :

Example 1 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)

Example 2 with AddressEntity

use of org.orcid.persistence.jpa.entities.AddressEntity in project ORCID-Source by ORCID.

the class AddressManagerImpl method deleteAddress.

@Override
@Transactional
public boolean deleteAddress(String orcid, Long putCode) {
    AddressEntity entity = addressDao.getAddress(orcid, putCode);
    orcidSecurityManager.checkSource(entity);
    try {
        addressDao.remove(entity);
    } catch (Exception e) {
        return false;
    }
    return true;
}
Also used : AddressEntity(org.orcid.persistence.jpa.entities.AddressEntity) ApplicationException(org.orcid.core.exception.ApplicationException) OrcidDuplicatedElementException(org.orcid.core.exception.OrcidDuplicatedElementException) Transactional(javax.transaction.Transactional)

Example 3 with AddressEntity

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;
}
Also used : Address(org.orcid.jaxb.model.record_v2.Address) AddressEntity(org.orcid.persistence.jpa.entities.AddressEntity) Cacheable(org.springframework.cache.annotation.Cacheable)

Example 4 with AddressEntity

use of org.orcid.persistence.jpa.entities.AddressEntity in project ORCID-Source by ORCID.

the class ProfileEntityManagerImplTest method testClaimChangingVisibility.

@Test
@Transactional
public void testClaimChangingVisibility() {
    Claim claim = new Claim();
    claim.setActivitiesVisibilityDefault(org.orcid.pojo.ajaxForm.Visibility.valueOf(Visibility.PRIVATE));
    claim.setPassword(Text.valueOf("passwordTest1"));
    claim.setPasswordConfirm(Text.valueOf("passwordTest1"));
    Checkbox checked = new Checkbox();
    checked.setValue(true);
    claim.setSendChangeNotifications(checked);
    claim.setSendOrcidNews(checked);
    claim.setTermsOfUse(checked);
    assertTrue(profileEntityManager.claimProfileAndUpdatePreferences("0000-0000-0000-0001", "public_0000-0000-0000-0001@test.orcid.org", Locale.EN, claim));
    ProfileEntity profile = profileEntityManager.findByOrcid("0000-0000-0000-0001");
    assertNotNull(profile);
    assertNotNull(profile.getBiographyEntity());
    assertEquals(org.orcid.jaxb.model.common_v2.Visibility.PRIVATE, profile.getBiographyEntity().getVisibility());
    assertNotNull(profile.getAddresses());
    assertEquals(3, profile.getAddresses().size());
    for (AddressEntity a : profile.getAddresses()) {
        assertEquals(org.orcid.jaxb.model.common_v2.Visibility.PRIVATE, a.getVisibility());
    }
    assertNotNull(profile.getExternalIdentifiers());
    assertEquals(3, profile.getExternalIdentifiers().size());
    for (ExternalIdentifierEntity e : profile.getExternalIdentifiers()) {
        assertEquals(org.orcid.jaxb.model.common_v2.Visibility.PRIVATE, e.getVisibility());
    }
    assertNotNull(profile.getKeywords());
    assertEquals(3, profile.getKeywords().size());
    for (ProfileKeywordEntity k : profile.getKeywords()) {
        assertEquals(org.orcid.jaxb.model.common_v2.Visibility.PRIVATE, k.getVisibility());
    }
    assertNotNull(profile.getOtherNames());
    assertEquals(3, profile.getOtherNames().size());
    for (OtherNameEntity o : profile.getOtherNames()) {
        assertEquals(org.orcid.jaxb.model.common_v2.Visibility.PRIVATE, o.getVisibility());
    }
    assertNotNull(profile.getResearcherUrls());
    assertEquals(3, profile.getResearcherUrls().size());
    for (ResearcherUrlEntity r : profile.getResearcherUrls()) {
        assertEquals(org.orcid.jaxb.model.common_v2.Visibility.PRIVATE, r.getVisibility());
    }
}
Also used : ProfileKeywordEntity(org.orcid.persistence.jpa.entities.ProfileKeywordEntity) Checkbox(org.orcid.pojo.ajaxForm.Checkbox) ResearcherUrlEntity(org.orcid.persistence.jpa.entities.ResearcherUrlEntity) ExternalIdentifierEntity(org.orcid.persistence.jpa.entities.ExternalIdentifierEntity) OtherNameEntity(org.orcid.persistence.jpa.entities.OtherNameEntity) Claim(org.orcid.pojo.ajaxForm.Claim) ProfileEntity(org.orcid.persistence.jpa.entities.ProfileEntity) AddressEntity(org.orcid.persistence.jpa.entities.AddressEntity) DBUnitTest(org.orcid.test.DBUnitTest) Test(org.junit.Test) Transactional(org.springframework.transaction.annotation.Transactional)

Example 5 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 = getNewMapperFactory();
    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) MapperFactory(ma.glasnost.orika.MapperFactory) AddressEntity(org.orcid.persistence.jpa.entities.AddressEntity)

Aggregations

AddressEntity (org.orcid.persistence.jpa.entities.AddressEntity)31 Date (java.util.Date)13 ProfileEntity (org.orcid.persistence.jpa.entities.ProfileEntity)13 Test (org.junit.Test)9 OrcidDuplicatedElementException (org.orcid.core.exception.OrcidDuplicatedElementException)8 SourceEntity (org.orcid.persistence.jpa.entities.SourceEntity)7 Address (org.orcid.jaxb.model.record_v2.Address)6 ExternalIdentifierEntity (org.orcid.persistence.jpa.entities.ExternalIdentifierEntity)6 OtherNameEntity (org.orcid.persistence.jpa.entities.OtherNameEntity)6 ProfileKeywordEntity (org.orcid.persistence.jpa.entities.ProfileKeywordEntity)6 ResearcherUrlEntity (org.orcid.persistence.jpa.entities.ResearcherUrlEntity)6 ApplicationException (org.orcid.core.exception.ApplicationException)5 Address (org.orcid.jaxb.model.v3.dev1.record.Address)5 Transactional (org.springframework.transaction.annotation.Transactional)5 HashMap (java.util.HashMap)4 Transactional (javax.transaction.Transactional)4 Visibility (org.orcid.jaxb.model.common_v2.Visibility)3 DBUnitTest (org.orcid.test.DBUnitTest)3 InvalidParameterException (java.security.InvalidParameterException)2 MapperFactory (ma.glasnost.orika.MapperFactory)2