Search in sources :

Example 26 with Keyword

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());
}
Also used : ClientDetailsEntity(org.orcid.persistence.jpa.entities.ClientDetailsEntity) Keyword(org.orcid.jaxb.model.v3.dev1.record.Keyword) SourceEntity(org.orcid.persistence.jpa.entities.SourceEntity) Test(org.junit.Test) BaseTest(org.orcid.core.BaseTest)

Example 27 with Keyword

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);
}
Also used : Keywords(org.orcid.jaxb.model.v3.dev1.record.Keywords) Keyword(org.orcid.jaxb.model.v3.dev1.record.Keyword) Test(org.junit.Test) BaseTest(org.orcid.core.BaseTest)

Example 28 with Keyword

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;
}
Also used : Keyword(org.orcid.jaxb.model.v3.dev1.record.Keyword)

Example 29 with 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;
}
Also used : Keyword(org.orcid.jaxb.model.v3.dev1.record.Keyword)

Example 30 with Keyword

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);
}
Also used : ProfileKeywordEntity(org.orcid.persistence.jpa.entities.ProfileKeywordEntity) HashMap(java.util.HashMap) SourceEntity(org.orcid.persistence.jpa.entities.SourceEntity) OrcidDuplicatedElementException(org.orcid.core.exception.OrcidDuplicatedElementException) Visibility(org.orcid.jaxb.model.v3.dev1.common.Visibility) Date(java.util.Date) Transactional(javax.transaction.Transactional)

Aggregations

Keyword (org.orcid.jaxb.model.v3.dev1.record.Keyword)75 Test (org.junit.Test)59 Keywords (org.orcid.jaxb.model.v3.dev1.record.Keywords)40 Address (org.orcid.jaxb.model.v3.dev1.record.Address)39 OtherName (org.orcid.jaxb.model.v3.dev1.record.OtherName)39 PersonExternalIdentifier (org.orcid.jaxb.model.v3.dev1.record.PersonExternalIdentifier)39 ResearcherUrl (org.orcid.jaxb.model.v3.dev1.record.ResearcherUrl)39 Email (org.orcid.jaxb.model.v3.dev1.record.Email)36 Biography (org.orcid.jaxb.model.v3.dev1.record.Biography)31 OtherNames (org.orcid.jaxb.model.v3.dev1.record.OtherNames)31 Addresses (org.orcid.jaxb.model.v3.dev1.record.Addresses)30 Emails (org.orcid.jaxb.model.v3.dev1.record.Emails)30 PersonExternalIdentifiers (org.orcid.jaxb.model.v3.dev1.record.PersonExternalIdentifiers)30 ResearcherUrls (org.orcid.jaxb.model.v3.dev1.record.ResearcherUrls)30 Person (org.orcid.jaxb.model.v3.dev1.record.Person)28 Name (org.orcid.jaxb.model.v3.dev1.record.Name)27 DBUnitTest (org.orcid.test.DBUnitTest)20 Response (javax.ws.rs.core.Response)18 Record (org.orcid.jaxb.model.v3.dev1.record.Record)15 EducationSummary (org.orcid.jaxb.model.v3.dev1.record.summary.EducationSummary)15