use of org.orcid.jaxb.model.v3.dev1.record.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.v3.dev1.record.Keyword in project ORCID-Source by ORCID.
the class ProfileKeywordManagerTest method getAllTest.
@Test
public void getAllTest() {
String orcid = "0000-0000-0000-0003";
Keywords elements = profileKeywordManager.getKeywords(orcid);
assertNotNull(elements);
assertNotNull(elements.getKeywords());
assertEquals(5, elements.getKeywords().size());
boolean found1 = false, found2 = false, found3 = false, found4 = false, found5 = false;
for (Keyword element : elements.getKeywords()) {
if (9 == element.getPutCode()) {
found1 = true;
} else if (10 == element.getPutCode()) {
found2 = true;
} else if (11 == element.getPutCode()) {
found3 = true;
} else if (12 == element.getPutCode()) {
found4 = true;
} else if (13 == element.getPutCode()) {
found5 = true;
} else {
fail("Invalid put code found: " + element.getPutCode());
}
}
assertTrue(found1);
assertTrue(found2);
assertTrue(found3);
assertTrue(found4);
assertTrue(found5);
}
use of org.orcid.jaxb.model.v3.dev1.record.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.v3.dev1.record.Keyword in project ORCID-Source by ORCID.
the class OrcidSecurityManagerTestBase method createKeyword.
protected Keyword createKeyword(Visibility v, String sourceId) {
Keyword k = new Keyword();
k.setContent("keyword-" + System.currentTimeMillis());
k.setVisibility(v);
setSource(k, sourceId);
return k;
}
use of org.orcid.jaxb.model.v3.dev1.record.Keyword in project ORCID-Source by ORCID.
the class ProfileKeywordManagerImpl method updateKeyword.
@Override
@Transactional
public Keyword updateKeyword(String orcid, Long putCode, Keyword keyword, boolean isApiRequest) {
SourceEntity sourceEntity = sourceManager.retrieveSourceEntity();
ProfileKeywordEntity updatedEntity = profileKeywordDao.getProfileKeyword(orcid, putCode);
Visibility originalVisibility = Visibility.fromValue(updatedEntity.getVisibility().value());
// Save the original source
String existingSourceId = updatedEntity.getSourceId();
String existingClientSourceId = updatedEntity.getClientSourceId();
// Validate the keyword
PersonValidator.validateKeyword(keyword, sourceEntity, false, isApiRequest, originalVisibility);
// Validate it is not duplicated
List<ProfileKeywordEntity> existingKeywords = profileKeywordDao.getProfileKeywords(orcid, getLastModified(orcid));
for (ProfileKeywordEntity existing : existingKeywords) {
if (isDuplicated(existing, keyword, sourceEntity)) {
Map<String, String> params = new HashMap<String, String>();
params.put("type", "keyword");
params.put("value", keyword.getContent());
throw new OrcidDuplicatedElementException(params);
}
}
orcidSecurityManager.checkSource(updatedEntity);
adapter.toProfileKeywordEntity(keyword, updatedEntity);
updatedEntity.setLastModified(new Date());
// Be sure it doesn't overwrite the source
updatedEntity.setSourceId(existingSourceId);
updatedEntity.setClientSourceId(existingClientSourceId);
profileKeywordDao.merge(updatedEntity);
return adapter.toKeyword(updatedEntity);
}
Aggregations