Skip to content

Commit

Permalink
Merge branch 'main' into patch-1
Browse files Browse the repository at this point in the history
  • Loading branch information
amontenegro authored Jan 16, 2024
2 parents 939e210 + 0c4fad4 commit 7b5e7b6
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 7 deletions.
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
## v2.49.3 - 2024-01-15

[Full Changelog](https://github.com/ORCID/ORCID-Source/compare/v2.49.2...v2.49.3)

- [#6972](https://github.com/ORCID/ORCID-Source/pull/6972): fix: Affiliation type validation

### Fix

- Affiliation type validation

## v2.49.2 - 2024-01-11

[Full Changelog](https://github.com/ORCID/ORCID-Source/compare/v2.49.1...v2.49.2)
Expand Down
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.search.Search;
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 @@ -331,7 +334,7 @@ public void validateRegistrationFields(HttpServletRequest request, Registration

if (Features.REGISTRATION_2_0.isActive() && reg.getAffiliationForm() != null) {
AffiliationForm affiliationForm = reg.getAffiliationForm();
if (!affiliationForm.getAffiliationType().getValue().equals("Employment")) {
if (!AffiliationType.EMPLOYMENT.equals(AffiliationType.fromValue(affiliationForm.getAffiliationType().getValue()))) {
setError(affiliationForm.getAffiliationType(), "Invalid affiliation type");
}
if (reg.getAffiliationForm().getDepartmentName() != null) {
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

0 comments on commit 7b5e7b6

Please sign in to comment.