Search in sources :

Example 1 with BiographyEntity

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

the class BiographyManagerReadOnlyImpl method getBiography.

@Override
@Cacheable(value = "biography", key = "#orcid.concat('-').concat(#lastModified)")
public Biography getBiography(String orcid, long lastModified) {
    BiographyEntity biographyEntity = null;
    try {
        biographyEntity = biographyDao.getBiography(orcid);
    } catch (Exception e) {
        LOGGER.warn("Couldn't find biography for " + orcid);
    }
    if (biographyEntity != null) {
        Biography bio = new Biography();
        bio.setContent(biographyEntity.getBiography());
        bio.setVisibility(biographyEntity.getVisibility());
        bio.setLastModifiedDate(new LastModifiedDate(DateUtils.convertToXMLGregorianCalendar(biographyEntity.getLastModified())));
        bio.setCreatedDate(new CreatedDate(DateUtils.convertToXMLGregorianCalendar(biographyEntity.getDateCreated())));
        return bio;
    }
    return null;
}
Also used : LastModifiedDate(org.orcid.jaxb.model.common_v2.LastModifiedDate) Biography(org.orcid.jaxb.model.record_v2.Biography) CreatedDate(org.orcid.jaxb.model.common_v2.CreatedDate) BiographyEntity(org.orcid.persistence.jpa.entities.BiographyEntity) Cacheable(org.springframework.cache.annotation.Cacheable)

Example 2 with BiographyEntity

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

the class BiographyDaoTest method testfindByOrcid.

@Test
public void testfindByOrcid() {
    BiographyEntity bio = biographyDao.getBiography("4444-4444-4444-4447");
    assertNotNull(bio);
    assertEquals("Biography for 4444-4444-4444-4447", bio.getBiography());
    assertEquals(Visibility.LIMITED, bio.getVisibility());
}
Also used : BiographyEntity(org.orcid.persistence.jpa.entities.BiographyEntity) Test(org.junit.Test) DBUnitTest(org.orcid.test.DBUnitTest)

Example 3 with BiographyEntity

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

the class ProfileEntityManagerImpl method deactivateRecord.

@Override
@Transactional
public boolean deactivateRecord(String orcid) {
    //Clear the record
    ProfileEntity toClear = profileDao.find(orcid);
    toClear.setLastModified(new Date());
    toClear.setDeactivationDate(new Date());
    toClear.setActivitiesVisibilityDefault(Visibility.PRIVATE);
    toClear.setIndexingStatus(IndexingStatus.REINDEX);
    // Remove works
    workManager.removeAllWorks(orcid);
    // Remove funding
    if (toClear.getProfileFunding() != null) {
        toClear.getProfileFunding().clear();
    }
    // Remove affiliations
    if (toClear.getOrgAffiliationRelations() != null) {
        toClear.getOrgAffiliationRelations().clear();
    }
    // Remove external identifiers
    if (toClear.getExternalIdentifiers() != null) {
        toClear.getExternalIdentifiers().clear();
    }
    // Remove researcher urls
    if (toClear.getResearcherUrls() != null) {
        toClear.getResearcherUrls().clear();
    }
    // Remove other names
    if (toClear.getOtherNames() != null) {
        toClear.getOtherNames().clear();
    }
    // Remove keywords
    if (toClear.getKeywords() != null) {
        toClear.getKeywords().clear();
    }
    // Remove address
    if (toClear.getAddresses() != null) {
        toClear.getAddresses().clear();
    }
    BiographyEntity bioEntity = toClear.getBiographyEntity();
    if (bioEntity != null) {
        bioEntity.setBiography("");
        bioEntity.setVisibility(Visibility.PRIVATE);
    }
    //Set the deactivated names
    RecordNameEntity recordName = toClear.getRecordNameEntity();
    if (recordName != null) {
        recordName.setCreditName(null);
        recordName.setGivenNames("Given Names Deactivated");
        recordName.setFamilyName("Family Name Deactivated");
        recordName.setVisibility(org.orcid.jaxb.model.common_v2.Visibility.PUBLIC);
    }
    Set<EmailEntity> emails = toClear.getEmails();
    if (emails != null) {
        // For each email in the deprecated profile                            
        for (EmailEntity email : emails) {
            email.setVisibility(org.orcid.jaxb.model.common_v2.Visibility.PRIVATE);
        }
    }
    profileDao.merge(toClear);
    profileDao.flush();
    //Delete all connections
    userConnectionDao.deleteByOrcid(orcid);
    notificationManager.sendAmendEmail(orcid, AmendedSection.UNKNOWN, null);
    return true;
}
Also used : RecordNameEntity(org.orcid.persistence.jpa.entities.RecordNameEntity) EmailEntity(org.orcid.persistence.jpa.entities.EmailEntity) BiographyEntity(org.orcid.persistence.jpa.entities.BiographyEntity) ProfileEntity(org.orcid.persistence.jpa.entities.ProfileEntity) Date(java.util.Date) Transactional(org.springframework.transaction.annotation.Transactional)

Example 4 with BiographyEntity

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

the class BiographyDaoTest method testUpdate.

@Test
public void testUpdate() {
    BiographyEntity bio = biographyDao.getBiography("4444-4444-4444-4442");
    assertNotNull(bio);
    assertEquals("Biography for 4444-4444-4444-4442", bio.getBiography());
    assertEquals(Visibility.PUBLIC, bio.getVisibility());
    bio.setBiography("Updated biography");
    bio.setVisibility(Visibility.LIMITED);
    assertTrue(biographyDao.updateBiography("4444-4444-4444-4442", bio.getBiography(), bio.getVisibility()));
    BiographyEntity updatedBio = biographyDao.getBiography("4444-4444-4444-4442");
    assertNotNull(updatedBio);
    assertEquals("Updated biography", bio.getBiography());
    assertEquals(Visibility.LIMITED, bio.getVisibility());
}
Also used : BiographyEntity(org.orcid.persistence.jpa.entities.BiographyEntity) Test(org.junit.Test) DBUnitTest(org.orcid.test.DBUnitTest)

Example 5 with BiographyEntity

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

the class BiographyDaoImpl method persistBiography.

@Override
@Transactional
public void persistBiography(String orcid, String biography, Visibility visibility) {
    BiographyEntity bio = new BiographyEntity();
    bio.setVisibility(visibility);
    bio.setBiography(biography);
    bio.setProfile(new ProfileEntity(orcid));
    bio.setDateCreated(new Date());
    bio.setLastModified(new Date());
    entityManager.persist(bio);
}
Also used : BiographyEntity(org.orcid.persistence.jpa.entities.BiographyEntity) ProfileEntity(org.orcid.persistence.jpa.entities.ProfileEntity) Date(java.util.Date) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

BiographyEntity (org.orcid.persistence.jpa.entities.BiographyEntity)8 Test (org.junit.Test)3 ProfileEntity (org.orcid.persistence.jpa.entities.ProfileEntity)3 DBUnitTest (org.orcid.test.DBUnitTest)3 Date (java.util.Date)2 RecordNameEntity (org.orcid.persistence.jpa.entities.RecordNameEntity)2 Transactional (org.springframework.transaction.annotation.Transactional)2 HashSet (java.util.HashSet)1 TreeSet (java.util.TreeSet)1 Query (javax.persistence.Query)1 CreatedDate (org.orcid.jaxb.model.common_v2.CreatedDate)1 LastModifiedDate (org.orcid.jaxb.model.common_v2.LastModifiedDate)1 OrcidProfile (org.orcid.jaxb.model.message.OrcidProfile)1 Visibility (org.orcid.jaxb.model.message.Visibility)1 Biography (org.orcid.jaxb.model.record_v2.Biography)1 AddressEntity (org.orcid.persistence.jpa.entities.AddressEntity)1 EmailEntity (org.orcid.persistence.jpa.entities.EmailEntity)1 ExternalIdentifierEntity (org.orcid.persistence.jpa.entities.ExternalIdentifierEntity)1 OrgAffiliationRelationEntity (org.orcid.persistence.jpa.entities.OrgAffiliationRelationEntity)1 OrgEntity (org.orcid.persistence.jpa.entities.OrgEntity)1