Search in sources :

Example 66 with Keyword

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

Example 67 with Keyword

use of org.orcid.jaxb.model.record_rc3.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.record_v2.Keyword)

Example 68 with Keyword

use of org.orcid.jaxb.model.record_rc3.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();
}
Also used : Keywords(org.orcid.jaxb.model.record_v2.Keywords) Keyword(org.orcid.jaxb.model.record_v2.Keyword) ArrayList(java.util.ArrayList)

Example 69 with Keyword

use of org.orcid.jaxb.model.record_rc3.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;
}
Also used : ProfileKeywordEntity(org.orcid.persistence.jpa.entities.ProfileKeywordEntity) ApplicationException(org.orcid.core.exception.ApplicationException) Keyword(org.orcid.jaxb.model.record_v2.Keyword) SourceEntity(org.orcid.persistence.jpa.entities.SourceEntity) ApplicationException(org.orcid.core.exception.ApplicationException) OrcidDuplicatedElementException(org.orcid.core.exception.OrcidDuplicatedElementException) Date(java.util.Date) ProfileEntity(org.orcid.persistence.jpa.entities.ProfileEntity) Transactional(javax.transaction.Transactional)

Example 70 with Keyword

use of org.orcid.jaxb.model.record_rc3.Keyword in project ORCID-Source by ORCID.

the class KeywordsForm method toKeywords.

public Keywords toKeywords() {
    Keywords keywords = new Keywords();
    List<Keyword> kList = new ArrayList<Keyword>();
    for (KeywordForm form : this.keywords) {
        kList.add(form.toKeyword());
    }
    keywords.setKeywords(kList);
    return keywords;
}
Also used : Keywords(org.orcid.jaxb.model.record_v2.Keywords) Keyword(org.orcid.jaxb.model.record_v2.Keyword) ArrayList(java.util.ArrayList)

Aggregations

Test (org.junit.Test)88 Keyword (org.orcid.jaxb.model.record_v2.Keyword)82 Address (org.orcid.jaxb.model.record_v2.Address)44 PersonExternalIdentifier (org.orcid.jaxb.model.record_v2.PersonExternalIdentifier)44 ResearcherUrl (org.orcid.jaxb.model.record_v2.ResearcherUrl)44 OtherName (org.orcid.jaxb.model.record_v2.OtherName)42 Email (org.orcid.jaxb.model.record_v2.Email)41 Keywords (org.orcid.jaxb.model.record_v2.Keywords)41 Biography (org.orcid.jaxb.model.record_v2.Biography)33 OtherNames (org.orcid.jaxb.model.record_v2.OtherNames)33 Addresses (org.orcid.jaxb.model.record_v2.Addresses)31 Emails (org.orcid.jaxb.model.record_v2.Emails)31 PersonExternalIdentifiers (org.orcid.jaxb.model.record_v2.PersonExternalIdentifiers)31 ResearcherUrls (org.orcid.jaxb.model.record_v2.ResearcherUrls)31 Person (org.orcid.jaxb.model.record_v2.Person)30 Name (org.orcid.jaxb.model.record_v2.Name)29 ClientResponse (com.sun.jersey.api.client.ClientResponse)22 DBUnitTest (org.orcid.test.DBUnitTest)20 Keyword (org.orcid.jaxb.model.record_rc3.Keyword)19 Response (javax.ws.rs.core.Response)18