use of org.springframework.context.NoSuchMessageException in project spring-framework by spring-projects.
the class ResourceBundleMessageSourceTests method testReloadableResourceBundleMessageSourceWithInappropriateEnglishCharset.
@Test
public void testReloadableResourceBundleMessageSourceWithInappropriateEnglishCharset() {
ReloadableResourceBundleMessageSource ms = new ReloadableResourceBundleMessageSource();
ms.setBasename("org/springframework/context/support/messages");
ms.setFallbackToSystemLocale(false);
Properties fileCharsets = new Properties();
fileCharsets.setProperty("org/springframework/context/support/messages", "unicode");
ms.setFileEncodings(fileCharsets);
try {
ms.getMessage("code1", null, Locale.ENGLISH);
fail("Should have thrown NoSuchMessageException");
} catch (NoSuchMessageException ex) {
// expected
}
}
use of org.springframework.context.NoSuchMessageException in project spring-framework by spring-projects.
the class ResourceBundleMessageSourceTests method testReloadableResourceBundleMessageSourceWithInappropriateDefaultCharset.
@Test
public void testReloadableResourceBundleMessageSourceWithInappropriateDefaultCharset() {
ReloadableResourceBundleMessageSource ms = new ReloadableResourceBundleMessageSource();
ms.setBasename("org/springframework/context/support/messages");
ms.setDefaultEncoding("unicode");
Properties fileCharsets = new Properties();
fileCharsets.setProperty("org/springframework/context/support/messages_de", "unicode");
ms.setFileEncodings(fileCharsets);
ms.setFallbackToSystemLocale(false);
try {
ms.getMessage("code1", null, Locale.ENGLISH);
fail("Should have thrown NoSuchMessageException");
} catch (NoSuchMessageException ex) {
// expected
}
}
use of org.springframework.context.NoSuchMessageException in project ORCID-Source by ORCID.
the class OauthControllerBase method generateRequestInfoForm.
private RequestInfoForm generateRequestInfoForm(String clientId, String scopesString, String redirectUri, String responseType, String stateParam, String email, String orcid, String givenNames, String familyNames, String nonce, String maxAge) throws UnsupportedEncodingException {
RequestInfoForm infoForm = new RequestInfoForm();
// If the user is logged in
String loggedUserOrcid = getEffectiveUserOrcid();
if (!PojoUtil.isEmpty(loggedUserOrcid)) {
infoForm.setUserOrcid(loggedUserOrcid);
ProfileEntity profile = profileEntityCacheManager.retrieve(loggedUserOrcid);
String creditName = "";
RecordNameEntity recordName = profile.getRecordNameEntity();
if (recordName != null) {
if (!PojoUtil.isEmpty(profile.getRecordNameEntity().getCreditName())) {
creditName = profile.getRecordNameEntity().getCreditName();
} else {
creditName = PojoUtil.isEmpty(profile.getRecordNameEntity().getGivenNames()) ? "" : profile.getRecordNameEntity().getGivenNames();
creditName += PojoUtil.isEmpty(profile.getRecordNameEntity().getFamilyName()) ? "" : " " + profile.getRecordNameEntity().getFamilyName();
creditName = creditName.trim();
}
}
if (!PojoUtil.isEmpty(creditName)) {
infoForm.setUserName(URLDecoder.decode(creditName, "UTF-8").trim());
}
}
Set<ScopePathType> scopes = new HashSet<ScopePathType>();
if (!PojoUtil.isEmpty(clientId) && !PojoUtil.isEmpty(scopesString)) {
scopesString = URLDecoder.decode(scopesString, "UTF-8").trim();
scopesString = scopesString.replaceAll(" +", " ");
scopes = ScopePathType.getScopesFromSpaceSeparatedString(scopesString);
} else {
throw new InvalidRequestException("Unable to find parameters");
}
for (ScopePathType theScope : scopes) {
ScopeInfoForm scopeInfoForm = new ScopeInfoForm();
scopeInfoForm.setValue(theScope.value());
scopeInfoForm.setName(theScope.name());
try {
scopeInfoForm.setDescription(getMessage(ScopePathType.class.getName() + '.' + theScope.name()));
scopeInfoForm.setLongDescription(getMessage(ScopePathType.class.getName() + '.' + theScope.name() + ".longDesc"));
} catch (NoSuchMessageException e) {
LOGGER.warn("Unable to find key message for scope: " + theScope.name() + " " + theScope.value());
}
infoForm.getScopes().add(scopeInfoForm);
}
// Check if the client has persistent tokens enabled
ClientDetailsEntity clientDetails = clientDetailsEntityCacheManager.retrieve(clientId);
if (clientDetails.isPersistentTokensEnabled()) {
infoForm.setClientHavePersistentTokens(true);
}
// If client details is ok, continue
String clientName = clientDetails.getClientName() == null ? "" : clientDetails.getClientName();
String clientEmailRequestReason = clientDetails.getEmailAccessReason() == null ? "" : clientDetails.getEmailAccessReason();
String clientDescription = clientDetails.getClientDescription() == null ? "" : clientDetails.getClientDescription();
String memberName = "";
// If client type is null it means it is a public client
if (ClientType.PUBLIC_CLIENT.equals(clientDetails.getClientType())) {
memberName = PUBLIC_MEMBER_NAME;
} else if (!PojoUtil.isEmpty(clientDetails.getGroupProfileId())) {
ProfileEntity groupProfile = profileEntityCacheManager.retrieve(clientDetails.getGroupProfileId());
if (groupProfile.getRecordNameEntity() != null) {
memberName = groupProfile.getRecordNameEntity().getCreditName();
}
}
// name, since it should be a SSO user
if (StringUtils.isBlank(memberName)) {
memberName = clientName;
}
if (!PojoUtil.isEmpty(email) || !PojoUtil.isEmpty(orcid)) {
// Check if orcid exists, if so, show login screen
if (!PojoUtil.isEmpty(orcid)) {
orcid = orcid.trim();
if (orcidProfileManager.exists(orcid)) {
infoForm.setUserId(orcid);
}
} else {
// Check if email exists, if so, show login screen
if (!PojoUtil.isEmpty(email)) {
email = email.trim();
if (emailManager.emailExists(email)) {
infoForm.setUserId(email);
}
}
}
}
infoForm.setUserEmail(email);
if (PojoUtil.isEmpty(loggedUserOrcid))
infoForm.setUserOrcid(orcid);
infoForm.setUserGivenNames(givenNames);
infoForm.setUserFamilyNames(familyNames);
infoForm.setClientId(clientId);
infoForm.setClientDescription(clientDescription);
infoForm.setClientName(clientName);
infoForm.setClientEmailRequestReason(clientEmailRequestReason);
infoForm.setMemberName(memberName);
infoForm.setRedirectUrl(redirectUri);
infoForm.setStateParam(stateParam);
infoForm.setResponseType(responseType);
infoForm.setNonce(nonce);
return infoForm;
}
use of org.springframework.context.NoSuchMessageException in project ORCID-Source by ORCID.
the class NotificationManagerImpl method sendWelcomeEmail.
@Override
public void sendWelcomeEmail(String userOrcid, String email) {
ProfileEntity profileEntity = profileEntityCacheManager.retrieve(userOrcid);
Locale userLocale = getUserLocaleFromProfileEntity(profileEntity);
Map<String, Object> templateParams = new HashMap<String, Object>();
boolean useV2Template = false;
String subject;
try {
subject = messageSourceNoFallback.getMessage("email.subject.register.welcome", null, userLocale);
useV2Template = true;
} catch (NoSuchMessageException e) {
subject = messages.getMessage("email.subject.register.thanks", null, userLocale);
}
String emailName = deriveEmailFriendlyName(profileEntity);
String verificationUrl = createVerificationUrl(email, orcidUrlManager.getBaseUrl());
String orcidId = userOrcid;
String baseUri = orcidUrlManager.getBaseUrl();
String baseUriHttp = orcidUrlManager.getBaseUriHttp();
templateParams.put("subject", subject);
templateParams.put("emailName", emailName);
templateParams.put("verificationUrl", verificationUrl);
templateParams.put("orcidId", orcidId);
templateParams.put("baseUri", baseUri);
templateParams.put("baseUriHttp", baseUriHttp);
SourceEntity source = sourceManager.retrieveSourceEntity();
if (source != null) {
String sourceId = source.getSourceId();
String sourceName = source.getSourceName();
// If the source is not the user itself
if (sourceId != null && !sourceId.equals(orcidId)) {
if (!PojoUtil.isEmpty(sourceName)) {
String paramValue = " " + messages.getMessage("common.through", null, userLocale) + " " + sourceName + ".";
templateParams.put("source_name_if_exists", paramValue);
} else {
templateParams.put("source_name_if_exists", ".");
}
} else {
templateParams.put("source_name_if_exists", ".");
}
} else {
templateParams.put("source_name_if_exists", ".");
}
addMessageParams(templateParams, userLocale);
// Generate body from template
String body = (useV2Template) ? templateManager.processTemplate("welcome_email_v2.ftl", templateParams) : templateManager.processTemplate("welcome_email.ftl", templateParams);
// Generate html from template
String html = (useV2Template) ? templateManager.processTemplate("welcome_email_html_v2.ftl", templateParams) : templateManager.processTemplate("welcome_email_html.ftl", templateParams);
mailGunManager.sendEmail(SUPPORT_VERIFY_ORCID_ORG, email, subject, body, html);
}
use of org.springframework.context.NoSuchMessageException in project ORCID-Source by ORCID.
the class NotificationManagerImpl method processVerificationEmail.
private void processVerificationEmail(String userOrcid, String email, boolean isVerificationReminder) {
ProfileEntity profile = profileEntityCacheManager.retrieve(userOrcid);
Locale locale = getUserLocaleFromProfileEntity(profile);
boolean useV2Template = false;
try {
messageSourceNoFallback.getMessage("email.verify.primary_reminder_v2", null, locale);
useV2Template = true;
} catch (NoSuchMessageException e) {
}
String primaryEmail = emailManager.findPrimaryEmail(userOrcid).getEmail();
String emailFriendlyName = deriveEmailFriendlyName(profile);
String subject = createSubjectForVerificationEmail(email, primaryEmail, locale);
Map<String, Object> templateParams = createParamsForVerificationEmail(subject, emailFriendlyName, userOrcid, email, primaryEmail, locale);
templateParams.put("isReminder", isVerificationReminder);
// Generate body from template
String body = (useV2Template) ? templateManager.processTemplate("verification_email_v2.ftl", templateParams) : templateManager.processTemplate("verification_email.ftl", templateParams);
String htmlBody = (useV2Template) ? templateManager.processTemplate("verification_email_html_v2.ftl", templateParams) : templateManager.processTemplate("verification_email_html.ftl", templateParams);
mailGunManager.sendEmail(SUPPORT_VERIFY_ORCID_ORG, email, subject, body, htmlBody);
}
Aggregations