Search in sources :

Example 21 with ProfileEntity

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

the class WorkDaoTest method testAddWork.

@Test
@Rollback(true)
@Transactional(propagation = Propagation.REQUIRES_NEW)
public void testAddWork() {
    String title = "New Work";
    String subtitle = "Subtitle";
    String citation = "Test citation";
    String description = "Description for new work";
    String url = "http://work.com";
    WorkEntity work = new WorkEntity();
    work.setCitation(citation);
    work.setCitationType(CitationType.FORMATTED_UNSPECIFIED);
    work.setDescription(description);
    work.setTitle(title);
    work.setSubtitle(subtitle);
    work.setWorkType(WorkType.BOOK);
    work.setWorkUrl(url);
    ProfileEntity profile = new ProfileEntity(USER_ORCID);
    work.setProfile(profile);
    work.setSourceId(USER_ORCID);
    work.setAddedToProfileDate(new Date());
    assertNull(work.getId());
    try {
        work = workDao.addWork(work);
    } catch (Exception e) {
        fail();
    }
    assertNotNull(work.getId());
}
Also used : WorkEntity(org.orcid.persistence.jpa.entities.WorkEntity) ProfileEntity(org.orcid.persistence.jpa.entities.ProfileEntity) Date(java.util.Date) Test(org.junit.Test) DBUnitTest(org.orcid.test.DBUnitTest) Rollback(org.springframework.test.annotation.Rollback) Transactional(org.springframework.transaction.annotation.Transactional)

Example 22 with ProfileEntity

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

the class Jaxb2JpaAdapterImpl method toProfileEntity.

@Override
public ProfileEntity toProfileEntity(OrcidProfile profile, ProfileEntity existingProfileEntity, UpdateOptions updateOptions) {
    Assert.notNull(profile, "Cannot convert a null OrcidProfile");
    ProfileEntity profileEntity = existingProfileEntity == null ? new ProfileEntity() : existingProfileEntity;
    // if orcid-id exist us it
    String orcidString = profile.getOrcidIdentifier().getPath();
    if (profile.retrieveOrcidUriAsString() != null && !profile.retrieveOrcidUriAsString().isEmpty()) {
        orcidString = OrcidStringUtils.getOrcidNumber(profile.retrieveOrcidUriAsString());
    }
    profileEntity.setId(orcidString);
    profileEntity.setOrcidType(org.orcid.jaxb.model.common_v2.OrcidType.fromValue(profile.getType().value()));
    profileEntity.setGroupType(profile.getGroupType());
    setBioDetails(profileEntity, profile.getOrcidBio());
    setHistoryDetails(profileEntity, profile.getOrcidHistory());
    setActivityDetails(profileEntity, profile.getOrcidActivities(), updateOptions);
    setInternalDetails(profileEntity, profile.getOrcidInternal());
    setPreferencesDetails(profileEntity, profile.getOrcidPreferences());
    profileEntity.setUserLastIp(profile.getUserLastIp());
    profileEntity.setReviewed(profile.isReviewed());
    if (profileEntity.getUsedRecaptchaOnRegistration() == null) {
        profileEntity.setUsedRecaptchaOnRegistration(false);
    }
    return profileEntity;
}
Also used : ProfileEntity(org.orcid.persistence.jpa.entities.ProfileEntity)

Example 23 with ProfileEntity

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

the class MigratePasswords method migrate.

private void migrate() {
    init();
    Date start = new Date();
    @SuppressWarnings("unchecked") List<ProfileEntity> profiles = Collections.EMPTY_LIST;
    do {
        profiles = profileDao.findLastModifiedBefore(start, CHUNK_SIZE);
        for (ProfileEntity profileEntity : profiles) {
            LOG.info("Migrating password for profile: {}", profileEntity.getId());
            String encryptedPassword = profileEntity.getEncryptedPassword();
            if (encryptedPassword != null) {
                String decryptedPassword = encryptionManager.legacyDecryptForInternalUse(encryptedPassword);
                String hashedPassword = encryptionManager.hashForInternalUse(decryptedPassword);
                profileEntity.setEncryptedPassword(hashedPassword);
            }
            profileEntity.setLastModified(new Date());
            profileDao.merge(profileEntity);
        }
    } while (!profiles.isEmpty());
}
Also used : Date(java.util.Date) ProfileEntity(org.orcid.persistence.jpa.entities.ProfileEntity)

Example 24 with ProfileEntity

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

the class OrcidProfileManagerImpl method persistAddedAffiliations.

private void persistAddedAffiliations(String orcid, List<Affiliation> updatedAffiliationsList) {
    ProfileEntity profileEntity = profileDao.find(orcid);
    for (Affiliation updatedAffiliation : updatedAffiliationsList) {
        OrgAffiliationRelationEntity orgAffiliationRelationEntity = jaxb2JpaAdapter.getNewOrgAffiliationRelationEntity(updatedAffiliation, profileEntity);
        orgAffiliationRelationDao.persist(orgAffiliationRelationEntity);
    }
    orcidProfileCacheManager.remove(orcid);
}
Also used : OrgAffiliationRelationEntity(org.orcid.persistence.jpa.entities.OrgAffiliationRelationEntity) ProfileEntity(org.orcid.persistence.jpa.entities.ProfileEntity) Affiliation(org.orcid.jaxb.model.message.Affiliation)

Example 25 with ProfileEntity

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

the class OrcidProfileManagerImpl method deleteProfile.

@Override
@Transactional
public OrcidProfile deleteProfile(String orcid) {
    ProfileEntity profileEntity = profileDao.find(orcid);
    if (profileEntity == null) {
        LOG.debug("Asked to delete profile {}, but not found in DB", orcid);
        return null;
    }
    profileDao.remove(profileEntity);
    profileDao.flush();
    orcidIndexManager.deleteOrcidProfile(orcid);
    orcidProfileCacheManager.remove(orcid);
    // OrcidProfile orcidProfile = adapter.toOrcidProfile(profileEntity);
    return null;
}
Also used : ProfileEntity(org.orcid.persistence.jpa.entities.ProfileEntity) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

ProfileEntity (org.orcid.persistence.jpa.entities.ProfileEntity)374 Date (java.util.Date)107 Test (org.junit.Test)107 HashMap (java.util.HashMap)74 Transactional (org.springframework.transaction.annotation.Transactional)74 SourceEntity (org.orcid.persistence.jpa.entities.SourceEntity)71 DBUnitTest (org.orcid.test.DBUnitTest)65 ClientDetailsEntity (org.orcid.persistence.jpa.entities.ClientDetailsEntity)48 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)44 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)37 HashSet (java.util.HashSet)35 RecordNameEntity (org.orcid.persistence.jpa.entities.RecordNameEntity)35 Locale (java.util.Locale)34 Rollback (org.springframework.test.annotation.Rollback)27 OrgEntity (org.orcid.persistence.jpa.entities.OrgEntity)26 ArrayList (java.util.ArrayList)25 EmailEntity (org.orcid.persistence.jpa.entities.EmailEntity)21 Set (java.util.Set)17 Authentication (org.springframework.security.core.Authentication)17 OAuth2Authentication (org.springframework.security.oauth2.provider.OAuth2Authentication)16