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();
}
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());
}
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());
}
}
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());
}
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);
}
}
}
}
Aggregations