Search in sources :

Example 21 with Text

use of org.orcid.pojo.ajaxForm.Text in project ORCID-Source by ORCID.

the class OrcidInfo method getWorkJson.

@RequestMapping(value = "/{orcid:(?:\\d{4}-){3,}\\d{3}[\\dX]}/works.json")
@ResponseBody
public List<WorkForm> getWorkJson(HttpServletRequest request, @PathVariable("orcid") String orcid, @RequestParam(value = "workIds") String workIdsStr) {
    Map<String, String> countries = retrieveIsoCountries();
    Map<String, String> languages = lm.buildLanguageMap(localeManager.getLocale(), false);
    HashMap<Long, WorkForm> minimizedWorksMap = activityCacheManager.pubMinWorksMap(orcid, getLastModifiedTime(orcid));
    List<WorkForm> works = new ArrayList<WorkForm>();
    String[] workIds = workIdsStr.split(",");
    for (String workId : workIds) {
        if (minimizedWorksMap.containsKey(Long.valueOf(workId))) {
            WorkForm work = minimizedWorksMap.get(Long.valueOf(workId));
            validateVisibility(work.getVisibility());
            if (!PojoUtil.isEmpty(work.getCountryCode())) {
                Text countryName = Text.valueOf(countries.get(work.getCountryCode().getValue()));
                work.setCountryName(countryName);
            }
            // Set language name
            if (!PojoUtil.isEmpty(work.getLanguageCode())) {
                Text languageName = Text.valueOf(languages.get(work.getLanguageCode().getValue()));
                work.setLanguageName(languageName);
            }
            // Set translated title language name
            if (work.getTranslatedTitle() != null && !StringUtils.isEmpty(work.getTranslatedTitle().getLanguageCode())) {
                String languageName = languages.get(work.getTranslatedTitle().getLanguageCode());
                work.getTranslatedTitle().setLanguageName(languageName);
            }
            works.add(work);
        }
    }
    return works;
}
Also used : WorkForm(org.orcid.pojo.ajaxForm.WorkForm) ArrayList(java.util.ArrayList) Text(org.orcid.pojo.ajaxForm.Text) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 22 with Text

use of org.orcid.pojo.ajaxForm.Text in project ORCID-Source by ORCID.

the class OauthRegistrationControllerTest method testStripHtmlFromNames.

@SuppressWarnings("unchecked")
@Test
public void testStripHtmlFromNames() throws UnsupportedEncodingException {
    HttpSession session = mock(HttpSession.class);
    RequestInfoForm rf = new RequestInfoForm();
    RedirectView mv = new RedirectView();
    when(servletRequest.getSession()).thenReturn(session);
    when(servletRequest.getSession().getAttribute("requestInfoForm")).thenReturn(rf);
    when(authorizationEndpoint.approveOrDeny(Matchers.anyMap(), Matchers.anyMap(), Matchers.any(SessionStatus.class), Matchers.any(Principal.class))).thenReturn(mv);
    when(authenticationManager.authenticate(Matchers.any(Authentication.class))).thenAnswer(new Answer<Authentication>() {

        @Override
        public Authentication answer(InvocationOnMock invocation) throws Throwable {
            OrcidOAuth2Authentication mockedAuthentication = mock(OrcidOAuth2Authentication.class);
            return mockedAuthentication;
        }
    });
    Text email = Text.valueOf(System.currentTimeMillis() + "@test.orcid.org");
    OauthRegistrationForm reg = new OauthRegistrationForm();
    org.orcid.pojo.ajaxForm.Visibility fv = new org.orcid.pojo.ajaxForm.Visibility();
    fv.setVisibility(org.orcid.jaxb.model.common_v2.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);
    reg.setApproved(true);
    Checkbox c = new Checkbox();
    c.setValue(true);
    reg.setTermsOfUse(c);
    reg.setCreationType(Text.valueOf(CreationMethod.DIRECT.value()));
    reg.setPersistentTokenEnabled(true);
    oauthRegistrationController.registerAndAuthorize(servletRequest, servletResponse, reg);
    ArgumentCaptor<HttpServletRequest> argument1 = ArgumentCaptor.forClass(HttpServletRequest.class);
    ArgumentCaptor<Registration> argument2 = ArgumentCaptor.forClass(Registration.class);
    ArgumentCaptor<Boolean> argument3 = ArgumentCaptor.forClass(Boolean.class);
    ArgumentCaptor<Locale> argument4 = ArgumentCaptor.forClass(Locale.class);
    ArgumentCaptor<String> argument5 = ArgumentCaptor.forClass(String.class);
    verify(registrationController).createMinimalRegistration(argument1.capture(), argument2.capture(), argument3.capture(), argument4.capture(), argument5.capture());
    assertNotNull(argument2.getValue());
    Registration registration = argument2.getValue();
    assertEquals(email.getValue(), registration.getEmail().getValue());
    assertEquals("Given Names", registration.getGivenNames().getValue());
    assertEquals("Family Name", registration.getFamilyNames().getValue());
}
Also used : Locale(java.util.Locale) HttpServletRequest(javax.servlet.http.HttpServletRequest) OauthRegistrationForm(org.orcid.pojo.ajaxForm.OauthRegistrationForm) Checkbox(org.orcid.pojo.ajaxForm.Checkbox) Registration(org.orcid.pojo.ajaxForm.Registration) SessionStatus(org.springframework.web.bind.support.SessionStatus) RequestInfoForm(org.orcid.pojo.ajaxForm.RequestInfoForm) HttpSession(javax.servlet.http.HttpSession) Text(org.orcid.pojo.ajaxForm.Text) OrcidOAuth2Authentication(org.orcid.core.oauth.OrcidOAuth2Authentication) OrcidOAuth2Authentication(org.orcid.core.oauth.OrcidOAuth2Authentication) Authentication(org.springframework.security.core.Authentication) InvocationOnMock(org.mockito.invocation.InvocationOnMock) RedirectView(org.springframework.web.servlet.view.RedirectView) Principal(java.security.Principal) DBUnitTest(org.orcid.test.DBUnitTest) Test(org.junit.Test)

Example 23 with Text

use of org.orcid.pojo.ajaxForm.Text in project ORCID-Source by ORCID.

the class WorksController method getWorkJson.

/**
     * List works associated with a profile
     */
@SuppressWarnings("unchecked")
@RequestMapping(value = "/works.json", method = RequestMethod.GET)
@ResponseBody
public List<WorkForm> getWorkJson(HttpServletRequest request, @RequestParam(value = "workIds") String workIdsStr) {
    Map<String, String> countries = retrieveIsoCountries();
    Map<String, String> languages = lm.buildLanguageMap(localeManager.getLocale(), false);
    List<WorkForm> workList = new ArrayList<>();
    WorkForm work = null;
    String[] workIds = workIdsStr.split(",");
    if (workIds != null) {
        HashMap<String, WorkForm> worksMap = (HashMap<String, WorkForm>) request.getSession().getAttribute(WORKS_MAP);
        // this should never happen, but just in case.
        if (worksMap == null) {
            createWorksIdList(request);
            worksMap = (HashMap<String, WorkForm>) request.getSession().getAttribute(WORKS_MAP);
        }
        for (String workId : workIds) {
            work = worksMap.get(Long.valueOf(workId));
            // Set country name
            if (!PojoUtil.isEmpty(work.getCountryCode())) {
                Text countryName = Text.valueOf(countries.get(work.getCountryCode().getValue()));
                work.setCountryName(countryName);
            }
            // Set language name
            if (!PojoUtil.isEmpty(work.getLanguageCode())) {
                Text languageName = Text.valueOf(languages.get(work.getLanguageCode().getValue()));
                work.setLanguageName(languageName);
            }
            // Set translated title language name
            if (!(work.getTranslatedTitle() == null) && !StringUtils.isEmpty(work.getTranslatedTitle().getLanguageCode())) {
                String languageName = languages.get(work.getTranslatedTitle().getLanguageCode());
                work.getTranslatedTitle().setLanguageName(languageName);
            }
            workList.add(work);
        }
    }
    return workList;
}
Also used : WorkForm(org.orcid.pojo.ajaxForm.WorkForm) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Text(org.orcid.pojo.ajaxForm.Text) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 24 with Text

use of org.orcid.pojo.ajaxForm.Text in project ORCID-Source by ORCID.

the class DeveloperToolsControllerTest method testResetClientSecret.

@Test
public void testResetClientSecret() throws Exception {
    SSOCredentials ssoCredentials = new SSOCredentials();
    ssoCredentials.setClientName(Text.valueOf("Client Name"));
    ssoCredentials.setClientDescription(Text.valueOf("This is a test"));
    ssoCredentials.setClientWebsite(Text.valueOf("http://client.com"));
    Set<RedirectUri> redirectUris = new HashSet<RedirectUri>();
    RedirectUri rUri = new RedirectUri();
    rUri.setType(Text.valueOf("default"));
    rUri.setValue(Text.valueOf("http://test.com"));
    redirectUris.add(rUri);
    ssoCredentials.setRedirectUris(redirectUris);
    SSOCredentials result = developerToolsController.generateSSOCredentialsJson(ssoCredentials);
    assertNotNull(result);
    assertNotNull(result.getErrors());
    assertEquals(result.getErrors().size(), 0);
    Text clientSecret = result.getClientSecret();
    assertTrue(developerToolsController.resetClientSecret(result.getClientOrcid().getValue()));
    ClientDetailsEntity clientDetails = clientDetailsDao.findByClientId(result.getClientOrcid().getValue(), System.currentTimeMillis());
    assertEquals(result.getClientName().getValue(), clientDetails.getClientName());
    assertEquals(result.getClientDescription().getValue(), clientDetails.getClientDescription());
    assertEquals(result.getClientOrcid().getValue(), clientDetails.getClientId());
    assertEquals(result.getClientWebsite().getValue(), clientDetails.getClientWebsite());
    Set<ClientSecretEntity> clientSecrets = clientDetails.getClientSecrets();
    assertNotNull(clientSecrets);
    assertEquals(2, clientSecrets.size());
    for (ClientSecretEntity clientSecretEntity : clientSecrets) {
        String secret = encryptionManager.decryptForInternalUse(clientSecretEntity.getClientSecret());
        if (!clientSecretEntity.isPrimary())
            assertEquals(clientSecret.getValue(), secret);
        else
            assertFalse(clientSecret.getValue().equals(secret));
    }
}
Also used : ClientDetailsEntity(org.orcid.persistence.jpa.entities.ClientDetailsEntity) SSOCredentials(org.orcid.pojo.ajaxForm.SSOCredentials) ClientSecretEntity(org.orcid.persistence.jpa.entities.ClientSecretEntity) RedirectUri(org.orcid.pojo.ajaxForm.RedirectUri) Text(org.orcid.pojo.ajaxForm.Text) HashSet(java.util.HashSet) Test(org.junit.Test) BaseControllerTest(org.orcid.frontend.web.util.BaseControllerTest)

Aggregations

Text (org.orcid.pojo.ajaxForm.Text)24 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)15 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)15 ArrayList (java.util.ArrayList)8 RedirectUri (org.orcid.pojo.ajaxForm.RedirectUri)8 Test (org.junit.Test)6 ProfileEntity (org.orcid.persistence.jpa.entities.ProfileEntity)5 Contributor (org.orcid.pojo.ajaxForm.Contributor)4 WorkForm (org.orcid.pojo.ajaxForm.WorkForm)4 HashSet (java.util.HashSet)3 BaseControllerTest (org.orcid.frontend.web.util.BaseControllerTest)3 SSOCredentials (org.orcid.pojo.ajaxForm.SSOCredentials)3 Locale (java.util.Locale)2 HttpSession (javax.servlet.http.HttpSession)2 InvocationOnMock (org.mockito.invocation.InvocationOnMock)2 Visibility (org.orcid.jaxb.model.common_v2.Visibility)2 Work (org.orcid.jaxb.model.record_v2.Work)2 Checkbox (org.orcid.pojo.ajaxForm.Checkbox)2 Client (org.orcid.pojo.ajaxForm.Client)2 Date (org.orcid.pojo.ajaxForm.Date)2