Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Add disambiguated organization data to affiliation created while… #6973

Merged
merged 3 commits into from
Jan 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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) {
Expand All @@ -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);
Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<EmploymentSummary> 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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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()) {
Expand Down