use of org.orcid.jaxb.model.record_rc4.Keyword in project ORCID-Source by ORCID.
the class ProfileKeywordManagerTest method testAddKeywordToUnclaimedRecordPreserveKeywordVisibility.
@Test
public void testAddKeywordToUnclaimedRecordPreserveKeywordVisibility() {
when(sourceManager.retrieveSourceEntity()).thenReturn(new SourceEntity(new ClientDetailsEntity(CLIENT_1_ID)));
Keyword keyword = getKeyword();
keyword = profileKeywordManager.createKeyword(unclaimedOrcid, keyword, true);
keyword = profileKeywordManager.getKeyword(unclaimedOrcid, keyword.getPutCode());
assertNotNull(keyword);
assertEquals(Visibility.PUBLIC, keyword.getVisibility());
}
use of org.orcid.jaxb.model.record_rc4.Keyword in project ORCID-Source by ORCID.
the class ProfileKeywordManagerTest method displayIndexIsSetTo_1_FromUI.
@Test
public void displayIndexIsSetTo_1_FromUI() {
when(sourceManager.retrieveSourceEntity()).thenReturn(new SourceEntity(new ClientDetailsEntity(CLIENT_1_ID)));
Keyword keyword = getKeyword();
keyword.setContent(keyword.getContent() + " fromUI1");
keyword = profileKeywordManager.createKeyword(claimedOrcid, keyword, false);
keyword = profileKeywordManager.getKeyword(claimedOrcid, keyword.getPutCode());
assertNotNull(keyword);
assertEquals(Long.valueOf(1), keyword.getDisplayIndex());
}
use of org.orcid.jaxb.model.record_rc4.Keyword in project ORCID-Source by ORCID.
the class ProfileKeywordManagerTest method getKeyword.
private Keyword getKeyword() {
Keyword keyword = new Keyword();
keyword.setContent("keyword-1");
keyword.setVisibility(Visibility.PUBLIC);
return keyword;
}
use of org.orcid.jaxb.model.record_rc4.Keyword in project ORCID-Source by ORCID.
the class MemberV2ApiServiceDelegatorImpl method viewKeywords.
@Override
public Response viewKeywords(String orcid) {
Keywords keywords = profileKeywordManagerReadOnly.getKeywords(orcid, getLastModifiedTime(orcid));
// Lets copy the list so we don't modify the cached collection
if (keywords.getKeywords() != null) {
List<Keyword> filteredList = new ArrayList<Keyword>(keywords.getKeywords());
keywords = new Keywords();
keywords.setKeywords(filteredList);
}
orcidSecurityManager.checkAndFilter(orcid, keywords.getKeywords(), ScopePathType.ORCID_BIO_READ_LIMITED);
ElementUtils.setPathToKeywords(keywords, orcid);
Api2_0_LastModifiedDatesHelper.calculateLastModified(keywords);
sourceUtils.setSourceName(keywords);
return Response.ok(keywords).build();
}
use of org.orcid.jaxb.model.record_rc4.Keyword in project ORCID-Source by ORCID.
the class ProfileKeywordManagerImpl method updateKeywords.
@Override
@Transactional
public Keywords updateKeywords(String orcid, Keywords keywords) {
List<ProfileKeywordEntity> existingKeywordsList = profileKeywordDao.getProfileKeywors(orcid, getLastModified(orcid));
// Delete the deleted ones
for (ProfileKeywordEntity existing : existingKeywordsList) {
boolean deleteMe = true;
if (keywords.getKeywords() != null) {
for (Keyword updatedOrNew : keywords.getKeywords()) {
if (existing.getId().equals(updatedOrNew.getPutCode())) {
deleteMe = false;
break;
}
}
}
if (deleteMe) {
try {
profileKeywordDao.deleteProfileKeyword(existing);
} catch (Exception e) {
throw new ApplicationException("Unable to delete keyword " + existing.getId(), e);
}
}
}
if (keywords != null && keywords.getKeywords() != null) {
for (Keyword updatedOrNew : keywords.getKeywords()) {
if (updatedOrNew.getPutCode() != null) {
// Update the existing ones
for (ProfileKeywordEntity existingKeyword : existingKeywordsList) {
if (existingKeyword.getId().equals(updatedOrNew.getPutCode())) {
existingKeyword.setLastModified(new Date());
existingKeyword.setVisibility(updatedOrNew.getVisibility());
existingKeyword.setKeywordName(updatedOrNew.getContent());
existingKeyword.setDisplayIndex(updatedOrNew.getDisplayIndex());
profileKeywordDao.merge(existingKeyword);
}
}
} else {
// Add the new ones
ProfileKeywordEntity newKeyword = adapter.toProfileKeywordEntity(updatedOrNew);
SourceEntity sourceEntity = sourceManager.retrieveSourceEntity();
ProfileEntity profile = new ProfileEntity(orcid);
newKeyword.setProfile(profile);
newKeyword.setDateCreated(new Date());
//Set the source
if (sourceEntity.getSourceProfile() != null) {
newKeyword.setSourceId(sourceEntity.getSourceProfile().getId());
}
if (sourceEntity.getSourceClient() != null) {
newKeyword.setClientSourceId(sourceEntity.getSourceClient().getId());
}
newKeyword.setVisibility(updatedOrNew.getVisibility());
newKeyword.setDisplayIndex(updatedOrNew.getDisplayIndex());
profileKeywordDao.persist(newKeyword);
}
}
}
return keywords;
}
Aggregations