Search in sources :

Example 1 with ProfileKeywordEntity

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

the class MapperFacadeFactory method getKeywordMapperFacade.

public MapperFacade getKeywordMapperFacade() {
    MapperFactory mapperFactory = new DefaultMapperFactory.Builder().build();
    ClassMapBuilder<Keyword, ProfileKeywordEntity> keywordClassMap = mapperFactory.classMap(Keyword.class, ProfileKeywordEntity.class);
    addV2DateFields(keywordClassMap);
    registerSourceConverters(mapperFactory, keywordClassMap);
    keywordClassMap.field("putCode", "id");
    keywordClassMap.field("content", "keywordName");
    keywordClassMap.fieldBToA("displayIndex", "displayIndex");
    keywordClassMap.byDefault();
    keywordClassMap.register();
    return mapperFactory.getMapperFacade();
}
Also used : ProfileKeywordEntity(org.orcid.persistence.jpa.entities.ProfileKeywordEntity) Keyword(org.orcid.jaxb.model.record_v2.Keyword) DefaultMapperFactory(ma.glasnost.orika.impl.DefaultMapperFactory) DefaultMapperFactory(ma.glasnost.orika.impl.DefaultMapperFactory) MapperFactory(ma.glasnost.orika.MapperFactory)

Example 2 with ProfileKeywordEntity

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

the class JpaJaxbKeywordAdapterTest method fromKeywordToProfileKeywordEntityTest.

@Test
public void fromKeywordToProfileKeywordEntityTest() throws JAXBException {
    Keyword keyword = getKeyword();
    ProfileKeywordEntity entity = adapter.toProfileKeywordEntity(keyword);
    assertNotNull(entity);
    assertNotNull(entity.getDateCreated());
    assertNotNull(entity.getLastModified());
    assertEquals(Long.valueOf(1), entity.getId());
    assertEquals("keyword1", entity.getKeywordName());
    assertEquals(Visibility.PUBLIC, entity.getVisibility());
    // Source
    assertNull(entity.getSourceId());
    assertNull(entity.getClientSourceId());
    assertNull(entity.getElementSourceId());
}
Also used : ProfileKeywordEntity(org.orcid.persistence.jpa.entities.ProfileKeywordEntity) Keyword(org.orcid.jaxb.model.record_v2.Keyword) Test(org.junit.Test)

Example 3 with ProfileKeywordEntity

use of org.orcid.persistence.jpa.entities.ProfileKeywordEntity 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 4 with ProfileKeywordEntity

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

the class ProfileKeywordDaoTest method testAddProfileKeyword.

@Test
public void testAddProfileKeyword() {
    assertEquals(4, profileKeywordDao.getProfileKeywors("4444-4444-4444-4443", 0L).size());
    boolean result = profileKeywordDao.addProfileKeyword("4444-4444-4444-4443", "new_keyword", "4444-4444-4444-4443", null, org.orcid.jaxb.model.common_v2.Visibility.PUBLIC);
    assertTrue(result);
    assertEquals(5, profileKeywordDao.getProfileKeywors("4444-4444-4444-4443", 0L).size());
    ProfileKeywordEntity entity = new ProfileKeywordEntity();
    entity.setKeywordName("this is my keyword");
    entity.setProfile(new ProfileEntity("4444-4444-4444-4443"));
    entity.setSourceId("4444-4444-4444-4443");
    entity.setVisibility(org.orcid.jaxb.model.common_v2.Visibility.PUBLIC);
    profileKeywordDao.persist(entity);
    assertEquals(6, profileKeywordDao.getProfileKeywors("4444-4444-4444-4443", 0L).size());
}
Also used : ProfileKeywordEntity(org.orcid.persistence.jpa.entities.ProfileKeywordEntity) ProfileEntity(org.orcid.persistence.jpa.entities.ProfileEntity) Test(org.junit.Test) DBUnitTest(org.orcid.test.DBUnitTest)

Example 5 with ProfileKeywordEntity

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

the class Jaxb2JpaAdapterImpl method setKeywords.

private void setKeywords(ProfileEntity profileEntity, Keywords keywords) {
    String sourceId = getSourceId();
    SortedSet<ProfileKeywordEntity> existingProfileKeywordEntities = profileEntity.getKeywords();
    Iterator<ProfileKeywordEntity> existingIt = null;
    if (existingProfileKeywordEntities != null) {
        existingIt = existingProfileKeywordEntities.iterator();
    }
    //Iterate over the list of existing elements, to see which ones still exists but preserving all the ones where the calling client is not the source of
    if (existingIt != null) {
        while (existingIt.hasNext()) {
            ProfileKeywordEntity existing = existingIt.next();
            String existingElementSource = existing.getElementSourceId();
            if (sourceId != null && !sourceId.equals(existingElementSource)) {
            //If am not the source of this element, do nothing
            } else {
                //If am the source, check if the element exists in the list of incoming elements
                String value = existing.getKeywordName();
                boolean found = false;
                if (keywords != null && keywords.getKeyword() != null) {
                    for (Keyword newKeyword : keywords.getKeyword()) {
                        if (Objects.equals(value, newKeyword.getContent())) {
                            found = true;
                            break;
                        }
                    }
                }
                //If it doesn't exists, remove it from the existing elements
                if (!found) {
                    existingIt.remove();
                }
            }
        }
    }
    //Iterate over the list of all new ones and add the ones that doesn't exists yet
    if (keywords != null && keywords.getKeyword() != null) {
        for (Keyword newKeyword : keywords.getKeyword()) {
            boolean exists = false;
            if (existingProfileKeywordEntities != null) {
                for (ProfileKeywordEntity existingEntity : existingProfileKeywordEntities) {
                    if (Objects.equals(newKeyword.getContent(), existingEntity.getKeywordName())) {
                        exists = true;
                        //If the profile is not claimed, you can update the visibility
                        if (profileEntity.getClaimed() == null || !profileEntity.getClaimed()) {
                            //Update the visibility of existing elements if the profile is not claimed
                            String existingVisibilityValue = existingEntity.getVisibility() == null ? null : existingEntity.getVisibility().value();
                            String listVisibilityValue = keywords.getVisibility() == null ? null : keywords.getVisibility().value();
                            if (listVisibilityValue != null && !Objects.equals(existingVisibilityValue, listVisibilityValue)) {
                                existingEntity.setVisibility(org.orcid.jaxb.model.common_v2.Visibility.fromValue(listVisibilityValue));
                            }
                        }
                        break;
                    }
                }
            }
            if (!exists) {
                if (existingProfileKeywordEntities == null) {
                    existingProfileKeywordEntities = new TreeSet<ProfileKeywordEntity>();
                    profileEntity.setKeywords(existingProfileKeywordEntities);
                }
                ProfileKeywordEntity newEntity = new ProfileKeywordEntity();
                newEntity.setProfile(profileEntity);
                //Set source
                SourceEntity source = sourceManager.retrieveSourceEntity();
                setSource(source, newEntity);
                newEntity.setKeywordName(newKeyword.getContent());
                newEntity.setVisibility(getDefaultVisibility(profileEntity, keywords.getVisibility(), OrcidVisibilityDefaults.KEYWORD_DEFAULT));
                newEntity.setDisplayIndex(0L);
                for (ProfileKeywordEntity tempEntity : existingProfileKeywordEntities) tempEntity.setDisplayIndex(tempEntity.getDisplayIndex() + 1);
                existingProfileKeywordEntities.add(newEntity);
            }
        }
    }
}
Also used : ProfileKeywordEntity(org.orcid.persistence.jpa.entities.ProfileKeywordEntity) Keyword(org.orcid.jaxb.model.message.Keyword) SourceEntity(org.orcid.persistence.jpa.entities.SourceEntity)

Aggregations

ProfileKeywordEntity (org.orcid.persistence.jpa.entities.ProfileKeywordEntity)17 ProfileEntity (org.orcid.persistence.jpa.entities.ProfileEntity)9 Test (org.junit.Test)6 Date (java.util.Date)5 ExternalIdentifierEntity (org.orcid.persistence.jpa.entities.ExternalIdentifierEntity)5 OtherNameEntity (org.orcid.persistence.jpa.entities.OtherNameEntity)5 ResearcherUrlEntity (org.orcid.persistence.jpa.entities.ResearcherUrlEntity)5 Keyword (org.orcid.jaxb.model.record_v2.Keyword)4 AddressEntity (org.orcid.persistence.jpa.entities.AddressEntity)4 SourceEntity (org.orcid.persistence.jpa.entities.SourceEntity)4 DBUnitTest (org.orcid.test.DBUnitTest)4 Transactional (org.springframework.transaction.annotation.Transactional)4 OrcidDuplicatedElementException (org.orcid.core.exception.OrcidDuplicatedElementException)3 OrgAffiliationRelationEntity (org.orcid.persistence.jpa.entities.OrgAffiliationRelationEntity)3 ProfileFundingEntity (org.orcid.persistence.jpa.entities.ProfileFundingEntity)3 HashMap (java.util.HashMap)2 HashSet (java.util.HashSet)2 TreeSet (java.util.TreeSet)2 Transactional (javax.transaction.Transactional)2 ApplicationException (org.orcid.core.exception.ApplicationException)2