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());
}
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;
}
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());
}
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);
}
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;
}
Aggregations