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;
}
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());
}
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;
}
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));
}
}
Aggregations