diff --git a/orcid-core/src/main/java/org/orcid/core/manager/RegistrationManager.java b/orcid-core/src/main/java/org/orcid/core/manager/RegistrationManager.java index a49e5bac857..777033f11db 100644 --- a/orcid-core/src/main/java/org/orcid/core/manager/RegistrationManager.java +++ b/orcid-core/src/main/java/org/orcid/core/manager/RegistrationManager.java @@ -17,4 +17,6 @@ public interface RegistrationManager { String createMinimalRegistration(Registration registration, boolean usedCaptcha, Locale locale, String ip); Long getCount(); + + void createAffiliation(Registration registration, String newUserOrcid); } diff --git a/orcid-core/src/main/java/org/orcid/core/manager/impl/RegistrationManagerImpl.java b/orcid-core/src/main/java/org/orcid/core/manager/impl/RegistrationManagerImpl.java index 5de0ae5d3ab..60601f387c2 100644 --- a/orcid-core/src/main/java/org/orcid/core/manager/impl/RegistrationManagerImpl.java +++ b/orcid-core/src/main/java/org/orcid/core/manager/impl/RegistrationManagerImpl.java @@ -13,6 +13,7 @@ import org.orcid.core.manager.AdminManager; import org.orcid.core.manager.EncryptionManager; import org.orcid.core.manager.OrcidGenerationManager; +import org.orcid.core.manager.OrgDisambiguatedManager; import org.orcid.core.manager.ProfileEntityCacheManager; import org.orcid.core.manager.ProfileEntityManager; import org.orcid.core.manager.RegistrationManager; @@ -38,7 +39,9 @@ import org.orcid.persistence.jpa.entities.EmailEntity; import org.orcid.persistence.jpa.entities.OrcidGrantedAuthority; import org.orcid.persistence.jpa.entities.ProfileEntity; +import org.orcid.pojo.OrgDisambiguated; import org.orcid.pojo.ProfileDeprecationRequest; +import org.orcid.pojo.ajaxForm.AffiliationForm; import org.orcid.pojo.ajaxForm.PojoUtil; import org.orcid.pojo.ajaxForm.Registration; import org.orcid.pojo.ajaxForm.Text; @@ -97,6 +100,9 @@ public class RegistrationManagerImpl implements RegistrationManager { @Resource(name = "affiliationsManagerV3") private AffiliationsManager affiliationsManager; + + @Resource + private OrgDisambiguatedManager orgDisambiguatedManager; @Required public void setEncryptionManager(EncryptionManager encryptionManager) { @@ -108,6 +114,18 @@ public Long getCount() { return profileDao.getConfirmedProfileCount(); } + @Override + public void createAffiliation(Registration registration, String orcid) { + AffiliationForm affiliationForm = registration.getAffiliationForm(); + OrgDisambiguated orgDisambiguated = orgDisambiguatedManager.findInDB(Long.valueOf(affiliationForm.getOrgDisambiguatedId().getValue())); + affiliationForm.setDisambiguatedAffiliationSourceId(Text.valueOf(orgDisambiguated.getSourceId())); + affiliationForm.setDisambiguationSource(Text.valueOf(orgDisambiguated.getSourceType())); + affiliationForm.setCity(Text.valueOf(orgDisambiguated.getCity())); + affiliationForm.setCountry(Text.valueOf(orgDisambiguated.getCountry())); + Affiliation affiliation = registration.getAffiliationForm().toAffiliation(); + affiliationsManager.createEmploymentAffiliation(orcid, (Employment) affiliation, false); + } + @Override public VerifyRegistrationToken parseEncyrptedParamsForVerification(String encryptedParams) { String decryptedParams = encryptionManager.decryptForExternalUse(encryptedParams); @@ -298,11 +316,6 @@ private String createMinimalProfile(Registration registration, boolean usedCaptc } recordNameManager.createRecordName(orcid, name); - if (Features.REGISTRATION_2_0.isActive() && registration.getAffiliationForm() != null) { - Affiliation affiliation = registration.getAffiliationForm().toAffiliation(); - affiliationsManager.createEmploymentAffiliation(orcid, (Employment) affiliation, false); - } - // Create email frequency entity boolean sendQuarterlyTips = (registration.getSendOrcidNews() == null) ? false : registration.getSendOrcidNews().getValue(); emailFrequencyManager.createOnRegister(orcid, SendEmailFrequency.WEEKLY, SendEmailFrequency.WEEKLY, SendEmailFrequency.WEEKLY, sendQuarterlyTips); diff --git a/orcid-core/src/test/java/org/orcid/core/manager/impl/RegistrationManagerImplTest.java b/orcid-core/src/test/java/org/orcid/core/manager/impl/RegistrationManagerImplTest.java index e0a6b83b2b1..bda40388b09 100644 --- a/orcid-core/src/test/java/org/orcid/core/manager/impl/RegistrationManagerImplTest.java +++ b/orcid-core/src/test/java/org/orcid/core/manager/impl/RegistrationManagerImplTest.java @@ -470,11 +470,14 @@ public void testRegisterWithAffiliationTest() { registrationForm.setAffiliationForm(getAffiliationForm()); String userOrcid = registrationManager.createMinimalRegistration(registrationForm, true, java.util.Locale.ENGLISH, "0.0.0.0"); + registrationManager.createAffiliation(registrationForm, userOrcid); assertNotNull(userOrcid); assertTrue(OrcidStringUtils.isValidOrcid(userOrcid)); List employmentSummaryList = affiliationsManager.getEmploymentSummaryList(userOrcid); assertNotNull(employmentSummaryList); assertEquals(1, employmentSummaryList.size()); + // Cleanup + affiliationsManager.removeAffiliation(userOrcid, employmentSummaryList.get(0).getPutCode()); } private Registration createRegistrationForm(String email, boolean claimed) { diff --git a/orcid-web/src/main/java/org/orcid/frontend/web/controllers/RegistrationController.java b/orcid-web/src/main/java/org/orcid/frontend/web/controllers/RegistrationController.java index b06c4b7574a..f142de18577 100644 --- a/orcid-web/src/main/java/org/orcid/frontend/web/controllers/RegistrationController.java +++ b/orcid-web/src/main/java/org/orcid/frontend/web/controllers/RegistrationController.java @@ -48,8 +48,11 @@ import org.orcid.jaxb.model.common.AvailableLocales; import org.orcid.jaxb.model.message.CreationMethod; import org.orcid.jaxb.model.v3.release.common.Visibility; +import org.orcid.jaxb.model.v3.release.record.Affiliation; import org.orcid.jaxb.model.v3.release.record.AffiliationType; +import org.orcid.jaxb.model.v3.release.record.Employment; import org.orcid.persistence.constants.SendEmailFrequency; +import org.orcid.pojo.OrgDisambiguated; import org.orcid.pojo.Redirect; import org.orcid.pojo.ajaxForm.AffiliationForm; import org.orcid.pojo.ajaxForm.Date; @@ -553,6 +556,9 @@ private void createMinimalRegistrationAndLogUserIn(HttpServletRequest request, H String unencryptedPassword = registration.getPassword().getValue(); String orcidId = createMinimalRegistration(request, registration, usedCaptchaVerification, locale, ip); logUserIn(request, response, orcidId, unencryptedPassword); + if (Features.REGISTRATION_2_0.isActive() && registration.getAffiliationForm() != null) { + createAffiliation(registration, orcidId); + } } public void logUserIn(HttpServletRequest request, HttpServletResponse response, String orcidId, String password) { @@ -584,6 +590,10 @@ public String createMinimalRegistration(HttpServletRequest request, Registration return newUserOrcid; } + private void createAffiliation(Registration registration, String newUserOrcid) { + registrationManager.createAffiliation(registration, newUserOrcid); + } + private void processProfileHistoryEvents(Registration registration, String newUserOrcid) { // t&cs must be accepted but check just in case! if (registration.getTermsOfUse().getValue()) {