Search in sources :

Example 36 with Keywords

use of org.orcid.jaxb.model.v3.dev1.record.Keywords in project ORCID-Source by ORCID.

the class ProfileKeywordManagerImpl method updateKeywords.

@Override
@Transactional
public Keywords updateKeywords(String orcid, Keywords keywords) {
    List<ProfileKeywordEntity> existingKeywordsList = profileKeywordDao.getProfileKeywords(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(org.orcid.jaxb.model.common_v2.Visibility.fromValue(updatedOrNew.getVisibility().value()));
                        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(org.orcid.jaxb.model.common_v2.Visibility.fromValue(updatedOrNew.getVisibility().value()));
                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.v3.dev1.record.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 37 with Keywords

use of org.orcid.jaxb.model.v3.dev1.record.Keywords in project ORCID-Source by ORCID.

the class ValidateV3_dev1SamplesTest method unmarshallFromPath.

private Object unmarshallFromPath(String path, Class<?> type, String schemaPath) throws SAXException, URISyntaxException {
    try (Reader reader = new InputStreamReader(getClass().getResourceAsStream(path))) {
        Object obj = unmarshall(reader, type, schemaPath);
        Object result = null;
        if (ResearcherUrls.class.equals(type)) {
            result = (ResearcherUrls) obj;
        } else if (ResearcherUrl.class.equals(type)) {
            result = (ResearcherUrl) obj;
        } else if (PersonalDetails.class.equals(type)) {
            result = (PersonalDetails) obj;
        } else if (PersonExternalIdentifier.class.equals(type)) {
            result = (PersonExternalIdentifier) obj;
        } else if (PersonExternalIdentifiers.class.equals(type)) {
            result = (PersonExternalIdentifiers) obj;
        } else if (Biography.class.equals(type)) {
            result = (Biography) obj;
        } else if (Name.class.equals(type)) {
            result = (Name) obj;
        } else if (CreditName.class.equals(type)) {
            result = (CreditName) obj;
        } else if (OtherName.class.equals(type)) {
            result = (OtherName) obj;
        } else if (OtherNames.class.equals(type)) {
            result = (OtherNames) obj;
        } else if (Keywords.class.equals(type)) {
            result = (Keywords) obj;
        } else if (Keyword.class.equals(type)) {
            result = (Keyword) obj;
        } else if (Addresses.class.equals(type)) {
            result = (Addresses) obj;
        } else if (Address.class.equals(type)) {
            result = (Address) obj;
        } else if (Emails.class.equals(type)) {
            result = (Emails) obj;
        } else if (Email.class.equals(type)) {
            result = (Email) obj;
        } else if (Person.class.equals(type)) {
            result = (Person) obj;
        } else if (Deprecated.class.equals(type)) {
            result = (Deprecated) obj;
        } else if (Preferences.class.equals(type)) {
            result = (Preferences) obj;
        } else if (History.class.equals(type)) {
            result = (History) obj;
        } else if (Record.class.equals(type)) {
            result = (Record) obj;
        } else if (ActivitiesSummary.class.equals(type)) {
            result = (ActivitiesSummary) obj;
        } else if (Works.class.equals(type)) {
            result = (Works) obj;
        } else if (Education.class.equals(type)) {
            result = (Education) obj;
        } else if (Educations.class.equals(type)) {
            result = (Educations) obj;
        } else if (Employment.class.equals(type)) {
            result = (Employment) obj;
        } else if (Employments.class.equals(type)) {
            result = (Employments) obj;
        } else if (Distinction.class.equals(type)) {
            result = (Distinction) obj;
        } else if (Distinctions.class.equals(type)) {
            result = (Distinctions) obj;
        } else if (InvitedPosition.class.equals(type)) {
            result = (InvitedPosition) obj;
        } else if (InvitedPositions.class.equals(type)) {
            result = (InvitedPositions) obj;
        } else if (Membership.class.equals(type)) {
            result = (Membership) obj;
        } else if (Memberships.class.equals(type)) {
            result = (Memberships) obj;
        } else if (Qualification.class.equals(type)) {
            result = (Qualification) obj;
        } else if (Qualifications.class.equals(type)) {
            result = (Qualifications) obj;
        } else if (Service.class.equals(type)) {
            result = (Service) obj;
        } else if (Services.class.equals(type)) {
            result = (Services) obj;
        }
        return result;
    } catch (IOException e) {
        throw new RuntimeException("Error reading notification from classpath", e);
    }
}
Also used : Email(org.orcid.jaxb.model.v3.dev1.record.Email) InputStreamReader(java.io.InputStreamReader) Keyword(org.orcid.jaxb.model.v3.dev1.record.Keyword) Address(org.orcid.jaxb.model.v3.dev1.record.Address) OtherNames(org.orcid.jaxb.model.v3.dev1.record.OtherNames) InvitedPosition(org.orcid.jaxb.model.v3.dev1.record.InvitedPosition) CreditName(org.orcid.jaxb.model.v3.dev1.record.CreditName) Reader(java.io.Reader) InputStreamReader(java.io.InputStreamReader) Service(org.orcid.jaxb.model.v3.dev1.record.Service) IOException(java.io.IOException) PersonExternalIdentifier(org.orcid.jaxb.model.v3.dev1.record.PersonExternalIdentifier) History(org.orcid.jaxb.model.v3.dev1.record.History) ActivitiesSummary(org.orcid.jaxb.model.v3.dev1.record.summary.ActivitiesSummary) Qualification(org.orcid.jaxb.model.v3.dev1.record.Qualification) Deprecated(org.orcid.jaxb.model.v3.dev1.record.Deprecated) Education(org.orcid.jaxb.model.v3.dev1.record.Education) Employment(org.orcid.jaxb.model.v3.dev1.record.Employment) Biography(org.orcid.jaxb.model.v3.dev1.record.Biography) Membership(org.orcid.jaxb.model.v3.dev1.record.Membership) ResearcherUrl(org.orcid.jaxb.model.v3.dev1.record.ResearcherUrl) Distinction(org.orcid.jaxb.model.v3.dev1.record.Distinction)

Example 38 with Keywords

use of org.orcid.jaxb.model.v3.dev1.record.Keywords in project ORCID-Source by ORCID.

the class MemberV3ApiServiceDelegator_KeywordsTest method testViewPublicKeyword.

@Test
public void testViewPublicKeyword() {
    SecurityContextTestUtils.setUpSecurityContext("4444-4444-4444-4443", ScopePathType.PERSON_READ_LIMITED);
    Response response = serviceDelegator.viewKeyword("4444-4444-4444-4443", 1L);
    assertNotNull(response);
    Keyword keyword = (Keyword) response.getEntity();
    assertNotNull(keyword);
    assertEquals("/4444-4444-4444-4443/keywords/1", keyword.getPath());
    Utils.verifyLastModified(keyword.getLastModifiedDate());
    assertEquals("tea making", keyword.getContent());
    assertEquals(Visibility.PUBLIC, keyword.getVisibility());
    assertEquals("APP-5555555555555555", keyword.getSource().retrieveSourcePath());
}
Also used : Response(javax.ws.rs.core.Response) Keyword(org.orcid.jaxb.model.v3.dev1.record.Keyword) DBUnitTest(org.orcid.test.DBUnitTest) Test(org.junit.Test)

Example 39 with Keywords

use of org.orcid.jaxb.model.v3.dev1.record.Keywords in project ORCID-Source by ORCID.

the class MemberV3ApiServiceDelegator_KeywordsTest method testViewKeywordsReadPublic.

@Test
public void testViewKeywordsReadPublic() {
    SecurityContextTestUtils.setUpSecurityContextForClientOnly("APP-5555555555555555", ScopePathType.READ_PUBLIC);
    Response r = serviceDelegator.viewKeywords(ORCID);
    Keywords element = (Keywords) r.getEntity();
    assertNotNull(element);
    assertEquals("/0000-0000-0000-0003/keywords", element.getPath());
    Utils.assertIsPublicOrSource(element, "APP-5555555555555555");
}
Also used : Response(javax.ws.rs.core.Response) Keywords(org.orcid.jaxb.model.v3.dev1.record.Keywords) DBUnitTest(org.orcid.test.DBUnitTest) Test(org.junit.Test)

Example 40 with Keywords

use of org.orcid.jaxb.model.v3.dev1.record.Keywords in project ORCID-Source by ORCID.

the class MemberV3ApiServiceDelegator_KeywordsTest method testDeleteKeyword.

@Test
public void testDeleteKeyword() {
    SecurityContextTestUtils.setUpSecurityContext("4444-4444-4444-4499", ScopePathType.PERSON_READ_LIMITED, ScopePathType.PERSON_UPDATE);
    Response response = serviceDelegator.viewKeywords("4444-4444-4444-4499");
    assertNotNull(response);
    Keywords keywords = (Keywords) response.getEntity();
    assertNotNull(keywords);
    assertNotNull(keywords.getKeywords());
    assertEquals(1, keywords.getKeywords().size());
    response = serviceDelegator.deleteKeyword("4444-4444-4444-4499", 8L);
    assertNotNull(response);
    assertEquals(Response.Status.NO_CONTENT.getStatusCode(), response.getStatus());
    response = serviceDelegator.viewKeywords("4444-4444-4444-4499");
    assertNotNull(response);
    keywords = (Keywords) response.getEntity();
    assertNotNull(keywords);
    assertNotNull(keywords.getKeywords());
    assertTrue(keywords.getKeywords().isEmpty());
}
Also used : Response(javax.ws.rs.core.Response) Keywords(org.orcid.jaxb.model.v3.dev1.record.Keywords) DBUnitTest(org.orcid.test.DBUnitTest) Test(org.junit.Test)

Aggregations

Keywords (org.orcid.jaxb.model.v3.dev1.record.Keywords)50 Keyword (org.orcid.jaxb.model.v3.dev1.record.Keyword)49 Test (org.junit.Test)44 OtherNames (org.orcid.jaxb.model.v3.dev1.record.OtherNames)34 Address (org.orcid.jaxb.model.v3.dev1.record.Address)33 Addresses (org.orcid.jaxb.model.v3.dev1.record.Addresses)33 Biography (org.orcid.jaxb.model.v3.dev1.record.Biography)33 PersonExternalIdentifiers (org.orcid.jaxb.model.v3.dev1.record.PersonExternalIdentifiers)33 ResearcherUrls (org.orcid.jaxb.model.v3.dev1.record.ResearcherUrls)33 Email (org.orcid.jaxb.model.v3.dev1.record.Email)32 OtherName (org.orcid.jaxb.model.v3.dev1.record.OtherName)32 PersonExternalIdentifier (org.orcid.jaxb.model.v3.dev1.record.PersonExternalIdentifier)32 ResearcherUrl (org.orcid.jaxb.model.v3.dev1.record.ResearcherUrl)32 Emails (org.orcid.jaxb.model.v3.dev1.record.Emails)31 Person (org.orcid.jaxb.model.v3.dev1.record.Person)28 Name (org.orcid.jaxb.model.v3.dev1.record.Name)27 Record (org.orcid.jaxb.model.v3.dev1.record.Record)15 ActivitiesSummary (org.orcid.jaxb.model.v3.dev1.record.summary.ActivitiesSummary)14 EducationSummary (org.orcid.jaxb.model.v3.dev1.record.summary.EducationSummary)14 EmploymentSummary (org.orcid.jaxb.model.v3.dev1.record.summary.EmploymentSummary)14