Search in sources :

Example 51 with Name

use of org.orcid.jaxb.model.v3.dev1.record.Name in project ORCID-Source by ORCID.

the class PeerReviewForm method valueOf.

public static PeerReviewForm valueOf(PeerReview peerReview) {
    PeerReviewForm form = new PeerReviewForm();
    // Put code
    if (peerReview.getPutCode() != null) {
        form.setPutCode(Text.valueOf(peerReview.getPutCode()));
    }
    // Visibility
    if (peerReview.getVisibility() != null) {
        form.setVisibility(Visibility.valueOf(peerReview.getVisibility()));
    }
    // Completion date
    if (!PojoUtil.isEmpty(peerReview.getCompletionDate())) {
        form.setCompletionDate(Date.valueOf(peerReview.getCompletionDate()));
    }
    // Role
    if (peerReview.getRole() != null) {
        form.setRole(Text.valueOf(peerReview.getRole().value()));
    }
    // Type
    if (peerReview.getType() != null) {
        form.setType(Text.valueOf(peerReview.getType().value()));
    }
    // Url
    if (!PojoUtil.isEmpty(peerReview.getUrl())) {
        form.setUrl(Text.valueOf(peerReview.getUrl().getValue()));
    }
    // Org info
    if (peerReview.getOrganization() != null) {
        if (!PojoUtil.isEmpty(peerReview.getOrganization().getName())) {
            form.setOrgName(Text.valueOf(peerReview.getOrganization().getName()));
        }
        if (peerReview.getOrganization().getAddress() != null) {
            if (!PojoUtil.isEmpty(peerReview.getOrganization().getAddress().getCity())) {
                form.setCity(Text.valueOf(peerReview.getOrganization().getAddress().getCity()));
            }
            if (peerReview.getOrganization().getAddress().getCountry() != null) {
                form.setCountry(Text.valueOf(peerReview.getOrganization().getAddress().getCountry().value()));
            }
            if (!PojoUtil.isEmpty(peerReview.getOrganization().getAddress().getRegion())) {
                form.setRegion(Text.valueOf(peerReview.getOrganization().getAddress().getRegion()));
            }
        }
        if (peerReview.getOrganization().getDisambiguatedOrganization() != null) {
            if (!PojoUtil.isEmpty(peerReview.getOrganization().getDisambiguatedOrganization().getDisambiguatedOrganizationIdentifier())) {
                form.setDisambiguatedOrganizationSourceId(Text.valueOf(peerReview.getOrganization().getDisambiguatedOrganization().getDisambiguatedOrganizationIdentifier()));
            }
            if (!PojoUtil.isEmpty(peerReview.getOrganization().getDisambiguatedOrganization().getDisambiguationSource())) {
                form.setDisambiguationSource(Text.valueOf(peerReview.getOrganization().getDisambiguatedOrganization().getDisambiguationSource()));
            }
        }
    }
    // External ids
    if (peerReview.getExternalIdentifiers() != null) {
        List<ExternalID> externalIdentifiers = peerReview.getExternalIdentifiers().getExternalIdentifier();
        form.setExternalIdentifiers(new ArrayList<WorkExternalIdentifier>());
        for (ExternalID extId : externalIdentifiers) {
            form.getExternalIdentifiers().add(WorkExternalIdentifier.valueOf(extId));
        }
    }
    // Group Id
    if (!PojoUtil.isEmpty(peerReview.getGroupId())) {
        form.setGroupId(Text.valueOf(peerReview.getGroupId()));
    }
    // Subject ext Id
    if (peerReview.getSubjectExternalIdentifier() != null) {
        WorkExternalIdentifier wExtId = new WorkExternalIdentifier();
        if (peerReview.getSubjectExternalIdentifier().getRelationship() != null) {
            wExtId.setRelationship(Text.valueOf(peerReview.getSubjectExternalIdentifier().getRelationship().value()));
        }
        if (peerReview.getSubjectExternalIdentifier().getUrl() != null) {
            wExtId.setUrl(Text.valueOf(peerReview.getSubjectExternalIdentifier().getUrl().getValue()));
        }
        if (peerReview.getSubjectExternalIdentifier().getValue() != null) {
            wExtId.setWorkExternalIdentifierId(Text.valueOf(peerReview.getSubjectExternalIdentifier().getValue()));
        }
        if (peerReview.getSubjectExternalIdentifier().getType() != null) {
            wExtId.setWorkExternalIdentifierType(Text.valueOf(peerReview.getSubjectExternalIdentifier().getType()));
        }
        form.setSubjectExternalIdentifier(wExtId);
    }
    // Subject Container name
    if (peerReview.getSubjectContainerName() != null) {
        form.setSubjectContainerName(Text.valueOf(peerReview.getSubjectContainerName().getContent()));
    }
    // Subject type
    if (peerReview.getSubjectType() != null) {
        form.setSubjectType(Text.valueOf(peerReview.getSubjectType().value()));
    }
    // Subject name
    if (peerReview.getSubjectName() != null) {
        if (peerReview.getSubjectName().getTitle() != null) {
            form.setSubjectName(Text.valueOf(peerReview.getSubjectName().getTitle().getContent()));
        }
        TranslatedTitleForm tTitle = new TranslatedTitleForm();
        if (peerReview.getSubjectName().getTranslatedTitle() != null) {
            tTitle.setContent(peerReview.getSubjectName().getTranslatedTitle().getContent());
            tTitle.setLanguageCode(peerReview.getSubjectName().getTranslatedTitle().getLanguageCode());
        }
        form.setTranslatedSubjectName(tTitle);
    }
    // Subject url
    if (peerReview.getSubjectUrl() != null) {
        form.setSubjectUrl(Text.valueOf(peerReview.getSubjectUrl().getValue()));
    }
    // Source
    if (peerReview.getSource() != null) {
        form.setSource(peerReview.getSource().retrieveSourcePath());
        if (peerReview.getSource().getSourceName() != null)
            form.setSourceName(peerReview.getSource().getSourceName().getContent());
    }
    // Created Date
    if (peerReview.getCreatedDate() != null) {
        form.setCreatedDate(Date.valueOf(peerReview.getCreatedDate()));
    }
    // Last modified
    if (peerReview.getLastModifiedDate() != null) {
        form.setLastModified(Date.valueOf(peerReview.getLastModifiedDate()));
    }
    return form;
}
Also used : ExternalID(org.orcid.jaxb.model.v3.dev1.record.ExternalID)

Example 52 with Name

use of org.orcid.jaxb.model.v3.dev1.record.Name in project ORCID-Source by ORCID.

the class PeerReviewForm method toPeerReview.

public PeerReview toPeerReview() {
    PeerReview peerReview = new PeerReview();
    // Put Code
    if (!PojoUtil.isEmpty(putCode)) {
        peerReview.setPutCode(Long.valueOf(putCode.getValue()));
    }
    // Visibility
    if (visibility != null && visibility.getVisibility() != null) {
        peerReview.setVisibility(org.orcid.jaxb.model.v3.dev1.common.Visibility.fromValue(visibility.getVisibility().value()));
    }
    // Completion date
    if (completionDate != null) {
        peerReview.setCompletionDate(new FuzzyDate(completionDate.toFuzzyDate()));
    }
    // External identifiers
    if (externalIdentifiers != null && !externalIdentifiers.isEmpty()) {
        peerReview.setExternalIdentifiers(new ExternalIDs());
        for (WorkExternalIdentifier extId : externalIdentifiers) {
            peerReview.getExternalIdentifiers().getExternalIdentifier().add(extId.toRecordWorkExternalIdentifier());
        }
    }
    // Set Organization
    Organization organization = new Organization();
    OrganizationAddress organizationAddress = new OrganizationAddress();
    organization.setAddress(organizationAddress);
    if (!PojoUtil.isEmpty(orgName)) {
        organization.setName(orgName.getValue());
    }
    if (!PojoUtil.isEmpty(city)) {
        organizationAddress.setCity(city.getValue());
    }
    if (!PojoUtil.isEmpty(region)) {
        organizationAddress.setRegion(region.getValue());
    }
    if (!PojoUtil.isEmpty(country)) {
        organizationAddress.setCountry(Iso3166Country.fromValue(country.getValue()));
    }
    if (!PojoUtil.isEmpty(disambiguatedOrganizationSourceId)) {
        organization.setDisambiguatedOrganization(new DisambiguatedOrganization());
        organization.getDisambiguatedOrganization().setDisambiguatedOrganizationIdentifier(disambiguatedOrganizationSourceId.getValue());
        organization.getDisambiguatedOrganization().setDisambiguationSource(disambiguationSource.getValue());
    }
    peerReview.setOrganization(organization);
    // Role
    if (!PojoUtil.isEmpty(role)) {
        peerReview.setRole(Role.fromValue(role.getValue()));
    }
    // Type
    if (!PojoUtil.isEmpty(type)) {
        peerReview.setType(PeerReviewType.fromValue(type.getValue()));
    }
    // Url
    if (!PojoUtil.isEmpty(url)) {
        peerReview.setUrl(new Url(url.getValue()));
    }
    // Group id
    if (!PojoUtil.isEmpty(groupId)) {
        peerReview.setGroupId(groupId.getValue());
    }
    // Subject external id
    if (!PojoUtil.isEmpty(subjectExternalIdentifier)) {
        ExternalID subjectExtId = new ExternalID();
        if (!PojoUtil.isEmpty(subjectExternalIdentifier.getRelationship())) {
            subjectExtId.setRelationship(Relationship.fromValue(subjectExternalIdentifier.getRelationship().getValue()));
        }
        if (!PojoUtil.isEmpty(subjectExternalIdentifier.getUrl())) {
            subjectExtId.setUrl(new Url(subjectExternalIdentifier.getUrl().getValue()));
        }
        if (!PojoUtil.isEmpty(subjectExternalIdentifier.getWorkExternalIdentifierId())) {
            subjectExtId.setValue(subjectExternalIdentifier.getWorkExternalIdentifierId().getValue());
        }
        if (!PojoUtil.isEmpty(subjectExternalIdentifier.getWorkExternalIdentifierType())) {
            subjectExtId.setType(subjectExternalIdentifier.getWorkExternalIdentifierType().getValue());
        }
        peerReview.setSubjectExternalIdentifier(subjectExtId);
    }
    // Subject container name
    if (!PojoUtil.isEmpty(subjectContainerName)) {
        Title containerName = new Title(subjectContainerName.getValue());
        peerReview.setSubjectContainerName(containerName);
    }
    // Subject type
    if (!PojoUtil.isEmpty(subjectType)) {
        peerReview.setSubjectType(WorkType.fromValue(subjectType.getValue()));
    }
    // Subject name and subject translated name
    if (!PojoUtil.isEmpty(subjectName) || !PojoUtil.isEmpty(translatedSubjectName)) {
        WorkTitle workTitle = new WorkTitle();
        if (!PojoUtil.isEmpty(subjectName)) {
            workTitle.setTitle(new Title(subjectName.getValue()));
        }
        if (translatedSubjectName != null) {
            org.orcid.jaxb.model.v3.dev1.common.TranslatedTitle tTitle = new org.orcid.jaxb.model.v3.dev1.common.TranslatedTitle();
            if (!PojoUtil.isEmpty(translatedSubjectName.getContent())) {
                tTitle.setContent(translatedSubjectName.getContent());
            }
            if (!PojoUtil.isEmpty(translatedSubjectName.getLanguageCode())) {
                tTitle.setLanguageCode(translatedSubjectName.getLanguageCode());
            }
            workTitle.setTranslatedTitle(tTitle);
        }
        peerReview.setSubjectName(workTitle);
    }
    // Subject url
    if (!PojoUtil.isEmpty(subjectUrl)) {
        peerReview.setSubjectUrl(new Url(subjectUrl.getValue()));
    }
    return peerReview;
}
Also used : ExternalIDs(org.orcid.jaxb.model.v3.dev1.record.ExternalIDs) Organization(org.orcid.jaxb.model.v3.dev1.common.Organization) DisambiguatedOrganization(org.orcid.jaxb.model.v3.dev1.common.DisambiguatedOrganization) OrganizationAddress(org.orcid.jaxb.model.v3.dev1.common.OrganizationAddress) ExternalID(org.orcid.jaxb.model.v3.dev1.record.ExternalID) FuzzyDate(org.orcid.jaxb.model.v3.dev1.common.FuzzyDate) Title(org.orcid.jaxb.model.v3.dev1.common.Title) WorkTitle(org.orcid.jaxb.model.v3.dev1.record.WorkTitle) Url(org.orcid.jaxb.model.v3.dev1.common.Url) DisambiguatedOrganization(org.orcid.jaxb.model.v3.dev1.common.DisambiguatedOrganization) WorkTitle(org.orcid.jaxb.model.v3.dev1.record.WorkTitle) PeerReview(org.orcid.jaxb.model.v3.dev1.record.PeerReview)

Example 53 with Name

use of org.orcid.jaxb.model.v3.dev1.record.Name in project ORCID-Source by ORCID.

the class ManageProfileControllerTest method initMocks.

@Before
public void initMocks() throws Exception {
    controller = new ManageProfileController();
    MockitoAnnotations.initMocks(this);
    SecurityContextHolder.getContext().setAuthentication(getAuthentication(USER_ORCID));
    TargetProxyHelper.injectIntoProxy(controller, "profileEntityCacheManager", mockProfileEntityCacheManager);
    TargetProxyHelper.injectIntoProxy(controller, "encryptionManager", mockEncryptionManager);
    TargetProxyHelper.injectIntoProxy(controller, "emailManager", mockEmailManager);
    TargetProxyHelper.injectIntoProxy(controller, "localeManager", mockLocaleManager);
    TargetProxyHelper.injectIntoProxy(controller, "profileEntityManager", mockProfileEntityManager);
    TargetProxyHelper.injectIntoProxy(controller, "givenPermissionToManager", mockGivenPermissionToManager);
    TargetProxyHelper.injectIntoProxy(controller, "givenPermissionToManagerReadOnly", mockGivenPermissionToManagerReadOnly);
    TargetProxyHelper.injectIntoProxy(controller, "orcidSecurityManager", mockOrcidSecurityManager);
    TargetProxyHelper.injectIntoProxy(controller, "orcidIdentifierUtils", mockOrcidIdentifierUtils);
    TargetProxyHelper.injectIntoProxy(controller, "profileLastModifiedAspect", profileLastModifiedAspect);
    when(mockOrcidSecurityManager.isPasswordConfirmationRequired()).thenReturn(true);
    when(mockEncryptionManager.hashMatches(Mockito.anyString(), Mockito.anyString())).thenReturn(true);
    when(mockEncryptionManager.hashMatches(Mockito.eq("invalid password"), Mockito.anyString())).thenReturn(false);
    when(mockProfileEntityManager.deprecateProfile(Mockito.eq(DEPRECATED_USER_ORCID), Mockito.eq(USER_ORCID), Mockito.eq(ProfileEntity.USER_DRIVEN_DEPRECATION), Mockito.isNull())).thenReturn(true);
    when(mockProfileEntityManager.deprecateProfile(Mockito.eq(DEPRECATED_USER_ORCID), Mockito.eq(USER_ORCID), Mockito.anyString(), Mockito.anyString())).thenReturn(true);
    when(mockProfileEntityManager.deprecateProfile(Mockito.anyString(), Mockito.anyString(), Mockito.anyString(), Mockito.anyString())).thenReturn(false);
    when(profileLastModifiedAspect.retrieveLastModifiedDate(anyString())).thenReturn(new Date());
    when(mockOrcidIdentifierUtils.buildOrcidIdentifier(Mockito.anyString())).thenAnswer(new Answer<OrcidIdentifier>() {

        @Override
        public OrcidIdentifier answer(InvocationOnMock invocation) throws Throwable {
            OrcidIdentifier result = new OrcidIdentifier();
            result.setPath(invocation.getArgument(0));
            return result;
        }
    });
    when(mockLocaleManager.resolveMessage(Mockito.anyString(), Mockito.any())).thenAnswer(new Answer<String>() {

        @Override
        public String answer(InvocationOnMock invocation) throws Throwable {
            return invocation.getArgument(0);
        }
    });
    when(mockProfileEntityCacheManager.retrieve(Mockito.anyString())).then(new Answer<ProfileEntity>() {

        @Override
        public ProfileEntity answer(InvocationOnMock invocation) throws Throwable {
            ProfileEntity entity = new ProfileEntity();
            entity.setId(invocation.getArgument(0));
            Set<GivenPermissionToEntity> givenPermissionTo = new HashSet<GivenPermissionToEntity>();
            IntStream.range(0, 2).forEachOrdered(i -> {
                GivenPermissionToEntity e1 = new GivenPermissionToEntity();
                e1.setId(Long.valueOf(i));
                Date now = new Date();
                e1.setApprovalDate(now);
                e1.setDateCreated(now);
                e1.setGiver(invocation.getArgument(0));
                ProfileSummaryEntity ps = new ProfileSummaryEntity();
                RecordNameEntity recordName = new RecordNameEntity();
                recordName.setVisibility(org.orcid.jaxb.model.common_v2.Visibility.PUBLIC);
                if (i == 0) {
                    ps.setId("0000-0000-0000-0004");
                    recordName.setCreditName("Credit Name");
                } else {
                    ps.setId("0000-0000-0000-0005");
                    recordName.setFamilyName("Family Name");
                    recordName.setGivenNames("Given Names");
                }
                ps.setRecordNameEntity(recordName);
                e1.setReceiver(ps);
                givenPermissionTo.add(e1);
            });
            entity.setGivenPermissionTo(givenPermissionTo);
            EmailEntity email1 = new EmailEntity();
            email1.setId(invocation.getArgument(0) + "_1@test.orcid.org");
            email1.setVerified(true);
            email1.setCurrent(true);
            email1.setDateCreated(new Date());
            email1.setLastModified(new Date());
            email1.setPrimary(true);
            email1.setVisibility(org.orcid.jaxb.model.common_v2.Visibility.PUBLIC);
            EmailEntity email2 = new EmailEntity();
            email2.setId(invocation.getArgument(0) + "_2@test.orcid.org");
            email2.setVerified(true);
            email2.setCurrent(false);
            email2.setDateCreated(new Date());
            email2.setLastModified(new Date());
            email2.setPrimary(false);
            email2.setVisibility(org.orcid.jaxb.model.common_v2.Visibility.PUBLIC);
            Set<EmailEntity> emails = new HashSet<EmailEntity>();
            emails.add(email1);
            emails.add(email2);
            entity.setEmails(emails);
            entity.setRecordNameEntity(getRecordName(invocation.getArgument(0)));
            entity.setEncryptedPassword("password");
            return entity;
        }
    });
    when(mockEmailManager.getEmails(Mockito.anyString())).thenAnswer(new Answer<Emails>() {

        @Override
        public Emails answer(InvocationOnMock invocation) throws Throwable {
            Emails emails = new Emails();
            Email email1 = new Email();
            email1.setEmail(invocation.getArgument(0) + "_1@test.orcid.org");
            email1.setVisibility(Visibility.PUBLIC);
            emails.getEmails().add(email1);
            Email email2 = new Email();
            email2.setEmail(invocation.getArgument(0) + "_2@test.orcid.org");
            email2.setVisibility(Visibility.PUBLIC);
            emails.getEmails().add(email2);
            return emails;
        }
    });
    when(mockEmailManager.findCaseInsensitive(Mockito.anyString())).thenAnswer(new Answer<EmailEntity>() {

        @Override
        public EmailEntity answer(InvocationOnMock invocation) throws Throwable {
            String emailString = invocation.getArgument(0);
            String orcidString = emailString.substring(0, (emailString.indexOf("_")));
            EmailEntity email = new EmailEntity();
            email.setId(emailString);
            email.setVisibility(org.orcid.jaxb.model.common_v2.Visibility.PUBLIC);
            ProfileEntity entity = new ProfileEntity(orcidString);
            entity.setEncryptedPassword("password");
            entity.setRecordNameEntity(getRecordName(orcidString));
            email.setProfile(entity);
            return email;
        }
    });
    when(mockGivenPermissionToManagerReadOnly.findByGiver(anyString(), anyLong())).thenAnswer(new Answer<List<DelegateForm>>() {

        @Override
        public List<DelegateForm> answer(InvocationOnMock invocation) throws Throwable {
            XMLGregorianCalendar now = DateUtils.convertToXMLGregorianCalendar(new Date());
            List<DelegateForm> list = new ArrayList<DelegateForm>();
            DelegateForm one = new DelegateForm();
            one.setGiverOrcid(new OrcidIdentifier(USER_ORCID));
            one.setReceiverOrcid(new OrcidIdentifier("0000-0000-0000-0004"));
            one.setReceiverName(Text.valueOf("Credit Name"));
            one.setApprovalDate(now);
            list.add(one);
            DelegateForm two = new DelegateForm();
            two.setGiverOrcid(new OrcidIdentifier(USER_ORCID));
            two.setReceiverOrcid(new OrcidIdentifier("0000-0000-0000-0005"));
            two.setReceiverName(Text.valueOf("Given Names Family Name"));
            two.setApprovalDate(now);
            list.add(two);
            return list;
        }
    });
}
Also used : Arrays(java.util.Arrays) TargetProxyHelper(org.orcid.test.TargetProxyHelper) ProfileSummaryEntity(org.orcid.persistence.jpa.entities.ProfileSummaryEntity) Date(java.util.Date) Emails(org.orcid.jaxb.model.v3.dev1.record.Emails) DelegateForm(org.orcid.pojo.DelegateForm) EmailManager(org.orcid.core.manager.v3.EmailManager) RecordNameEntity(org.orcid.persistence.jpa.entities.RecordNameEntity) StringUtils(org.apache.commons.lang3.StringUtils) NamesForm(org.orcid.pojo.ajaxForm.NamesForm) MockitoAnnotations(org.mockito.MockitoAnnotations) ProfileLastModifiedAspect(org.orcid.persistence.aop.ProfileLastModifiedAspect) ManageDelegate(org.orcid.pojo.ManageDelegate) BiographyManager(org.orcid.core.manager.v3.BiographyManager) ProfileEntityCacheManager(org.orcid.core.manager.ProfileEntityCacheManager) SecurityContextHolder(org.springframework.security.core.context.SecurityContextHolder) BiographyForm(org.orcid.pojo.ajaxForm.BiographyForm) OrcidIdentifier(org.orcid.jaxb.model.v3.dev1.common.OrcidIdentifier) EncryptionManager(org.orcid.core.manager.EncryptionManager) Set(java.util.Set) CreditName(org.orcid.jaxb.model.v3.dev1.common.CreditName) FamilyName(org.orcid.jaxb.model.v3.dev1.record.FamilyName) ProfileEntity(org.orcid.persistence.jpa.entities.ProfileEntity) LocaleManager(org.orcid.core.locale.LocaleManager) Text(org.orcid.pojo.ajaxForm.Text) List(java.util.List) GivenPermissionToManagerReadOnly(org.orcid.core.manager.v3.read_only.GivenPermissionToManagerReadOnly) OrcidWebRole(org.orcid.core.security.OrcidWebRole) Email(org.orcid.jaxb.model.v3.dev1.record.Email) EmailEntity(org.orcid.persistence.jpa.entities.EmailEntity) VerificationModeFactory.times(org.mockito.internal.verification.VerificationModeFactory.times) Assert.assertFalse(org.junit.Assert.assertFalse) UsernamePasswordAuthenticationToken(org.springframework.security.authentication.UsernamePasswordAuthenticationToken) Authentication(org.springframework.security.core.Authentication) IntStream(java.util.stream.IntStream) ArgumentMatchers.anyLong(org.mockito.ArgumentMatchers.anyLong) Biography(org.orcid.jaxb.model.v3.dev1.record.Biography) NoSuchRequestHandlingMethodException(org.springframework.web.servlet.mvc.multiaction.NoSuchRequestHandlingMethodException) Mock(org.mockito.Mock) ProfileEntityManager(org.orcid.core.manager.v3.ProfileEntityManager) OrcidIdentifierUtils(org.orcid.core.utils.v3.OrcidIdentifierUtils) DateUtils(org.orcid.utils.DateUtils) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) GivenPermissionToEntity(org.orcid.persistence.jpa.entities.GivenPermissionToEntity) Answer(org.mockito.stubbing.Answer) RecordNameManager(org.orcid.core.manager.v3.RecordNameManager) InvocationOnMock(org.mockito.invocation.InvocationOnMock) SecurityQuestion(org.orcid.pojo.SecurityQuestion) OrcidSecurityManager(org.orcid.core.manager.v3.OrcidSecurityManager) Before(org.junit.Before) OrcidProfileUserDetails(org.orcid.core.oauth.OrcidProfileUserDetails) GivenNames(org.orcid.jaxb.model.v3.dev1.record.GivenNames) DeprecateProfile(org.orcid.pojo.DeprecateProfile) GivenPermissionToManager(org.orcid.core.manager.v3.GivenPermissionToManager) Assert.assertNotNull(org.junit.Assert.assertNotNull) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) Mockito.when(org.mockito.Mockito.when) Visibility(org.orcid.jaxb.model.v3.dev1.common.Visibility) XMLGregorianCalendar(javax.xml.datatype.XMLGregorianCalendar) Mockito.verify(org.mockito.Mockito.verify) Mockito(org.mockito.Mockito) Assert.assertNull(org.junit.Assert.assertNull) Name(org.orcid.jaxb.model.v3.dev1.record.Name) Assert.assertEquals(org.junit.Assert.assertEquals) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) ProfileSummaryEntity(org.orcid.persistence.jpa.entities.ProfileSummaryEntity) Set(java.util.Set) HashSet(java.util.HashSet) Email(org.orcid.jaxb.model.v3.dev1.record.Email) RecordNameEntity(org.orcid.persistence.jpa.entities.RecordNameEntity) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) OrcidIdentifier(org.orcid.jaxb.model.v3.dev1.common.OrcidIdentifier) DelegateForm(org.orcid.pojo.DelegateForm) List(java.util.List) ArrayList(java.util.ArrayList) Emails(org.orcid.jaxb.model.v3.dev1.record.Emails) GivenPermissionToEntity(org.orcid.persistence.jpa.entities.GivenPermissionToEntity) EmailEntity(org.orcid.persistence.jpa.entities.EmailEntity) Date(java.util.Date) ProfileEntity(org.orcid.persistence.jpa.entities.ProfileEntity) XMLGregorianCalendar(javax.xml.datatype.XMLGregorianCalendar) InvocationOnMock(org.mockito.invocation.InvocationOnMock) Before(org.junit.Before)

Example 54 with Name

use of org.orcid.jaxb.model.v3.dev1.record.Name in project ORCID-Source by ORCID.

the class ManageProfileControllerTest method testStripHtmlFromNames.

@Test
public void testStripHtmlFromNames() throws NoSuchRequestHandlingMethodException {
    RecordNameManager mockRecordNameManager = Mockito.mock(RecordNameManager.class);
    SecurityContextHolder.getContext().setAuthentication(getAuthentication(USER_ORCID));
    TargetProxyHelper.injectIntoProxy(controller, "recordNameManager", mockRecordNameManager);
    when(mockRecordNameManager.exists(Mockito.anyString())).thenReturn(true);
    NamesForm nf = new NamesForm();
    nf.setCreditName(Text.valueOf("<button onclick=\"alert('hello')\">Credit Name</button>"));
    nf.setGivenNames(Text.valueOf("<button onclick=\"alert('hello')\">Given Names</button>"));
    nf.setFamilyName(Text.valueOf("<button onclick=\"alert('hello')\">Family Name</button>"));
    nf.setVisibility(org.orcid.pojo.ajaxForm.Visibility.valueOf(Visibility.PUBLIC));
    nf = controller.setNameFormJson(nf);
    assertEquals("Credit Name", nf.getCreditName().getValue());
    assertEquals("Given Names", nf.getGivenNames().getValue());
    assertEquals("Family Name", nf.getFamilyName().getValue());
    Name name = new Name();
    name.setCreditName(new CreditName("Credit Name"));
    name.setFamilyName(new FamilyName("Family Name"));
    name.setGivenNames(new GivenNames("Given Names"));
    name.setVisibility(Visibility.PUBLIC);
    verify(mockRecordNameManager, times(1)).updateRecordName(Mockito.eq(USER_ORCID), Mockito.eq(name));
}
Also used : RecordNameManager(org.orcid.core.manager.v3.RecordNameManager) FamilyName(org.orcid.jaxb.model.v3.dev1.record.FamilyName) GivenNames(org.orcid.jaxb.model.v3.dev1.record.GivenNames) CreditName(org.orcid.jaxb.model.v3.dev1.common.CreditName) NamesForm(org.orcid.pojo.ajaxForm.NamesForm) CreditName(org.orcid.jaxb.model.v3.dev1.common.CreditName) FamilyName(org.orcid.jaxb.model.v3.dev1.record.FamilyName) Name(org.orcid.jaxb.model.v3.dev1.record.Name) Test(org.junit.Test)

Example 55 with Name

use of org.orcid.jaxb.model.v3.dev1.record.Name in project ORCID-Source by ORCID.

the class RegistrationControllerTest method testStripHtmlFromNames.

@Test
public void testStripHtmlFromNames() throws UnsupportedEncodingException {
    HttpSession session = mock(HttpSession.class);
    when(servletRequest.getSession()).thenReturn(session);
    Text email = Text.valueOf(System.currentTimeMillis() + "@test.orcid.org");
    when(registrationManager.createMinimalRegistration(Matchers.any(Registration.class), eq(false), Matchers.any(java.util.Locale.class), Matchers.anyString())).thenAnswer(new Answer<String>() {

        @Override
        public String answer(InvocationOnMock invocation) throws Throwable {
            return "0000-0000-0000-0000";
        }
    });
    Registration reg = new Registration();
    org.orcid.pojo.ajaxForm.Visibility fv = new org.orcid.pojo.ajaxForm.Visibility();
    fv.setVisibility(Visibility.PUBLIC);
    reg.setActivitiesVisibilityDefault(fv);
    reg.setEmail(email);
    reg.setEmailConfirm(email);
    reg.setFamilyNames(Text.valueOf("<button onclick=\"alert('hello')\">Family Name</button>"));
    reg.setGivenNames(Text.valueOf("<button onclick=\"alert('hello')\">Given Names</button>"));
    reg.setPassword(Text.valueOf("1234abcd"));
    reg.setPasswordConfirm(Text.valueOf("1234abcd"));
    reg.setValNumClient(2L);
    reg.setValNumServer(4L);
    Checkbox c = new Checkbox();
    c.setValue(true);
    reg.setTermsOfUse(c);
    reg.setCreationType(Text.valueOf(CreationMethod.API.value()));
    registrationController.setRegisterConfirm(servletRequest, servletResponse, reg);
    ArgumentCaptor<Registration> argument1 = ArgumentCaptor.forClass(Registration.class);
    ArgumentCaptor<Boolean> argument2 = ArgumentCaptor.forClass(Boolean.class);
    ArgumentCaptor<Locale> argument3 = ArgumentCaptor.forClass(Locale.class);
    ArgumentCaptor<String> argument4 = ArgumentCaptor.forClass(String.class);
    verify(registrationManager).createMinimalRegistration(argument1.capture(), argument2.capture(), argument3.capture(), argument4.capture());
    assertNotNull(argument1.getValue());
    Registration form = argument1.getValue();
    assertEquals("Given Names", form.getGivenNames().getValue());
    assertEquals("Family Name", form.getFamilyNames().getValue());
}
Also used : Locale(java.util.Locale) HttpSession(javax.servlet.http.HttpSession) Text(org.orcid.pojo.ajaxForm.Text) Registration(org.orcid.pojo.ajaxForm.Registration) InvocationOnMock(org.mockito.invocation.InvocationOnMock) Checkbox(org.orcid.pojo.ajaxForm.Checkbox) Visibility(org.orcid.jaxb.model.v3.dev1.common.Visibility) DBUnitTest(org.orcid.test.DBUnitTest) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)175 OtherName (org.orcid.jaxb.model.v3.dev1.record.OtherName)84 Name (org.orcid.jaxb.model.v3.dev1.record.Name)70 DBUnitTest (org.orcid.test.DBUnitTest)53 Biography (org.orcid.jaxb.model.v3.dev1.record.Biography)51 OtherNames (org.orcid.jaxb.model.v3.dev1.record.OtherNames)48 Response (javax.ws.rs.core.Response)43 PersonExternalIdentifier (org.orcid.jaxb.model.v3.dev1.record.PersonExternalIdentifier)43 ResearcherUrl (org.orcid.jaxb.model.v3.dev1.record.ResearcherUrl)40 Email (org.orcid.jaxb.model.v3.dev1.record.Email)39 Address (org.orcid.jaxb.model.v3.dev1.record.Address)37 Keyword (org.orcid.jaxb.model.v3.dev1.record.Keyword)36 Person (org.orcid.jaxb.model.v3.dev1.record.Person)35 Addresses (org.orcid.jaxb.model.v3.dev1.record.Addresses)33 PersonExternalIdentifiers (org.orcid.jaxb.model.v3.dev1.record.PersonExternalIdentifiers)33 ResearcherUrls (org.orcid.jaxb.model.v3.dev1.record.ResearcherUrls)33 Keywords (org.orcid.jaxb.model.v3.dev1.record.Keywords)31 Emails (org.orcid.jaxb.model.v3.dev1.record.Emails)30 ClientResponse (com.sun.jersey.api.client.ClientResponse)25 ActivitiesSummary (org.orcid.jaxb.model.v3.dev1.record.summary.ActivitiesSummary)25