Search in sources :

Example 11 with ResearcherUrlEntity

use of org.orcid.persistence.jpa.entities.ResearcherUrlEntity in project ORCID-Source by ORCID.

the class ProfileEntityManagerImpl method claimProfileAndUpdatePreferences.

@Override
@Transactional
public boolean claimProfileAndUpdatePreferences(String orcid, String email, Locale locale, Claim claim) {
    // Verify the email
    boolean emailVerified = emailManager.verifySetCurrentAndPrimary(orcid, email);
    if (!emailVerified) {
        throw new InvalidParameterException("Unable to claim and verify email: " + email + " for user: " + orcid);
    }
    // Update the profile entity fields
    ProfileEntity profile = profileDao.find(orcid);
    profile.setLastModified(new Date());
    profile.setIndexingStatus(IndexingStatus.REINDEX);
    profile.setClaimed(true);
    profile.setCompletedDate(new Date());
    if (locale != null) {
        profile.setLocale(org.orcid.jaxb.model.common_v2.Locale.fromValue(locale.value()));
    }
    if (claim != null) {
        profile.setSendChangeNotifications(claim.getSendChangeNotifications().getValue());
        profile.setSendOrcidNews(claim.getSendOrcidNews().getValue());
        profile.setActivitiesVisibilityDefault(Visibility.valueOf(claim.getActivitiesVisibilityDefault().getVisibility().name()));
    }
    // Update the visibility for every bio element to the visibility
    // selected by the user
    // Update the bio
    org.orcid.jaxb.model.common_v2.Visibility defaultVisibility = org.orcid.jaxb.model.common_v2.Visibility.fromValue(claim.getActivitiesVisibilityDefault().getVisibility().value());
    if (profile.getBiographyEntity() != null) {
        profile.getBiographyEntity().setVisibility(defaultVisibility);
    }
    // Update address
    if (profile.getAddresses() != null) {
        for (AddressEntity a : profile.getAddresses()) {
            a.setVisibility(defaultVisibility);
        }
    }
    // Update the keywords
    if (profile.getKeywords() != null) {
        for (ProfileKeywordEntity k : profile.getKeywords()) {
            k.setVisibility(defaultVisibility);
        }
    }
    // Update the other names
    if (profile.getOtherNames() != null) {
        for (OtherNameEntity o : profile.getOtherNames()) {
            o.setVisibility(defaultVisibility);
        }
    }
    // Update the researcher urls
    if (profile.getResearcherUrls() != null) {
        for (ResearcherUrlEntity r : profile.getResearcherUrls()) {
            r.setVisibility(defaultVisibility);
        }
    }
    // Update the external identifiers
    if (profile.getExternalIdentifiers() != null) {
        for (ExternalIdentifierEntity e : profile.getExternalIdentifiers()) {
            e.setVisibility(defaultVisibility);
        }
    }
    profileDao.merge(profile);
    profileDao.flush();
    return true;
}
Also used : ProfileKeywordEntity(org.orcid.persistence.jpa.entities.ProfileKeywordEntity) ResearcherUrlEntity(org.orcid.persistence.jpa.entities.ResearcherUrlEntity) ExternalIdentifierEntity(org.orcid.persistence.jpa.entities.ExternalIdentifierEntity) ProfileEntity(org.orcid.persistence.jpa.entities.ProfileEntity) Date(java.util.Date) InvalidParameterException(java.security.InvalidParameterException) Visibility(org.orcid.jaxb.model.common_v2.Visibility) OtherNameEntity(org.orcid.persistence.jpa.entities.OtherNameEntity) AddressEntity(org.orcid.persistence.jpa.entities.AddressEntity) Transactional(org.springframework.transaction.annotation.Transactional)

Example 12 with ResearcherUrlEntity

use of org.orcid.persistence.jpa.entities.ResearcherUrlEntity in project ORCID-Source by ORCID.

the class ResearcherUrlDaoTest method testCannotAddDuplicatedResearcherUrl.

@Test
@Rollback(true)
@Transactional(propagation = Propagation.REQUIRES_NEW)
public void testCannotAddDuplicatedResearcherUrl() {
    try {
        ResearcherUrlEntity newRUrl = new ResearcherUrlEntity();
        newRUrl.setDateCreated(new Date());
        newRUrl.setLastModified(new Date());
        newRUrl.setClientSourceId("4444-4444-4444-4443");
        newRUrl.setUrl("http://www.researcherurl2.com?id=1");
        newRUrl.setUrlName("test");
        newRUrl.setUser(new ProfileEntity("4444-4444-4444-4443"));
        newRUrl.setVisibility(Visibility.PUBLIC);
        newRUrl = dao.merge(newRUrl);
        assertNotNull(newRUrl);
        fail();
    } catch (PersistenceException e) {
    }
}
Also used : ResearcherUrlEntity(org.orcid.persistence.jpa.entities.ResearcherUrlEntity) PersistenceException(javax.persistence.PersistenceException) Date(java.util.Date) ProfileEntity(org.orcid.persistence.jpa.entities.ProfileEntity) Test(org.junit.Test) DBUnitTest(org.orcid.test.DBUnitTest) Rollback(org.springframework.test.annotation.Rollback) Transactional(org.springframework.transaction.annotation.Transactional)

Example 13 with ResearcherUrlEntity

use of org.orcid.persistence.jpa.entities.ResearcherUrlEntity in project ORCID-Source by ORCID.

the class JpaJaxbResearcherUrlAdapterTest method fromResearcherUrlEntityToResearcherUrl.

@Test
public void fromResearcherUrlEntityToResearcherUrl() {
    ResearcherUrlEntity entity = getResearcherUrlEntity();
    ResearcherUrl r = jpaJaxbResearcherUrlAdapter.toResearcherUrl(entity);
    // General info
    assertNotNull(r);
    assertEquals(Long.valueOf(13579), r.getPutCode());
    assertEquals("http://orcid.org", r.getUrl().getValue());
    assertEquals("Orcid URL", r.getUrlName());
    assertEquals(Visibility.LIMITED, r.getVisibility());
    // Source
    assertEquals("APP-0001", r.getSource().retrieveSourcePath());
}
Also used : ResearcherUrlEntity(org.orcid.persistence.jpa.entities.ResearcherUrlEntity) ResearcherUrl(org.orcid.jaxb.model.record_v2.ResearcherUrl) Test(org.junit.Test)

Example 14 with ResearcherUrlEntity

use of org.orcid.persistence.jpa.entities.ResearcherUrlEntity in project ORCID-Source by ORCID.

the class JpaJaxbResearcherUrlAdapterTest method testToResearcherUrlEntity.

@Test
public void testToResearcherUrlEntity() throws JAXBException {
    ResearcherUrls rUrls = getResearcherUrls();
    assertNotNull(rUrls);
    assertNotNull(rUrls.getResearcherUrls());
    assertEquals(1, rUrls.getResearcherUrls().size());
    ResearcherUrlEntity entity = jpaJaxbResearcherUrlAdapter.toResearcherUrlEntity(rUrls.getResearcherUrls().get(0));
    assertNotNull(entity);
    // General info
    assertEquals(Long.valueOf(1248), entity.getId());
    assertEquals(Visibility.PUBLIC.value(), entity.getVisibility().value());
    assertEquals("http://site1.com/", entity.getUrl());
    assertEquals("Site # 1", entity.getUrlName());
    // Source
    assertNull(entity.getSourceId());
    assertNull(entity.getClientSourceId());
    assertNull(entity.getElementSourceId());
}
Also used : ResearcherUrlEntity(org.orcid.persistence.jpa.entities.ResearcherUrlEntity) ResearcherUrls(org.orcid.jaxb.model.record_v2.ResearcherUrls) Test(org.junit.Test)

Example 15 with ResearcherUrlEntity

use of org.orcid.persistence.jpa.entities.ResearcherUrlEntity in project ORCID-Source by ORCID.

the class ResearcherUrlManagerImpl method deleteResearcherUrl.

@Override
public boolean deleteResearcherUrl(String orcid, Long id, boolean checkSource) {
    boolean result = true;
    ResearcherUrlEntity toDelete = researcherUrlDao.getResearcherUrl(orcid, id);
    if (checkSource) {
        orcidSecurityManager.checkSource(toDelete);
    }
    try {
        researcherUrlDao.deleteResearcherUrl(orcid, id);
    } catch (Exception e) {
        LOGGER.error("Unable to delete researcherUrl with ID: " + id);
        result = false;
    }
    return result;
}
Also used : ResearcherUrlEntity(org.orcid.persistence.jpa.entities.ResearcherUrlEntity) ApplicationException(org.orcid.core.exception.ApplicationException) OrcidDuplicatedElementException(org.orcid.core.exception.OrcidDuplicatedElementException)

Aggregations

ResearcherUrlEntity (org.orcid.persistence.jpa.entities.ResearcherUrlEntity)28 ProfileEntity (org.orcid.persistence.jpa.entities.ProfileEntity)12 Transactional (org.springframework.transaction.annotation.Transactional)12 Date (java.util.Date)10 Test (org.junit.Test)10 OrcidDuplicatedElementException (org.orcid.core.exception.OrcidDuplicatedElementException)8 ExternalIdentifierEntity (org.orcid.persistence.jpa.entities.ExternalIdentifierEntity)7 OtherNameEntity (org.orcid.persistence.jpa.entities.OtherNameEntity)7 ProfileKeywordEntity (org.orcid.persistence.jpa.entities.ProfileKeywordEntity)7 SourceEntity (org.orcid.persistence.jpa.entities.SourceEntity)7 AddressEntity (org.orcid.persistence.jpa.entities.AddressEntity)6 DBUnitTest (org.orcid.test.DBUnitTest)6 ApplicationException (org.orcid.core.exception.ApplicationException)5 HashMap (java.util.HashMap)4 ResearcherUrl (org.orcid.jaxb.model.record_v2.ResearcherUrl)3 ResearcherUrl (org.orcid.jaxb.model.v3.dev1.record.ResearcherUrl)3 OrgAffiliationRelationEntity (org.orcid.persistence.jpa.entities.OrgAffiliationRelationEntity)3 ProfileFundingEntity (org.orcid.persistence.jpa.entities.ProfileFundingEntity)3 Rollback (org.springframework.test.annotation.Rollback)3 InvalidParameterException (java.security.InvalidParameterException)2