use of org.orcid.pojo.ajaxForm.CustomEmailForm in project ORCID-Source by ORCID.
the class CustomEmailController method getEmptyCustomEmailForm.
@RequestMapping(value = "/get-empty.json", method = RequestMethod.GET)
@ResponseBody
public CustomEmailForm getEmptyCustomEmailForm(@RequestParam("clientId") String clientId) {
String groupId = getEffectiveUserOrcid();
if (PojoUtil.isEmpty(clientId) || !clientDetailsManager.exists(clientId)) {
throw new IllegalArgumentException(getMessage("manage.developer_tools.group.custom_emails.invalid_client_id"));
} else if (!clientDetailsManager.belongsTo(clientId, groupId)) {
throw new IllegalArgumentException(getMessage("manage.developer_tools.group.custom_emails.not_your_client"));
}
CustomEmailForm result = new CustomEmailForm();
result.setSubject(Text.valueOf(""));
result.setContent(Text.valueOf(""));
result.setSender(Text.valueOf(""));
result.setHtml(true);
result.setEmailType(Text.valueOf(EmailType.CLAIM.name()));
result.setClientId(clientId);
return result;
}
use of org.orcid.pojo.ajaxForm.CustomEmailForm in project ORCID-Source by ORCID.
the class CustomEmailController method getCustomEmails.
@RequestMapping(value = "/get.json", method = RequestMethod.GET)
@ResponseBody
public List<CustomEmailForm> getCustomEmails(@RequestParam("clientId") String clientId) throws IllegalArgumentException {
List<CustomEmailForm> result = new ArrayList<CustomEmailForm>();
boolean haveErrors = false;
String groupId = getEffectiveUserOrcid();
MemberType groupType = profileEntityManager.getGroupType(groupId);
if (!(MemberType.PREMIUM_INSTITUTION.equals(groupType) || MemberType.BASIC_INSTITUTION.equals(groupType))) {
haveErrors = true;
} else if (!clientDetailsManager.exists(clientId)) {
haveErrors = true;
} else if (!clientDetailsManager.belongsTo(clientId, groupId)) {
haveErrors = true;
}
if (!haveErrors) {
List<CustomEmailEntity> customEmails = customEmailManager.getCustomEmails(clientId);
for (CustomEmailEntity entity : customEmails) {
CustomEmailForm form = CustomEmailForm.valueOf(entity);
result.add(form);
}
}
return result;
}
use of org.orcid.pojo.ajaxForm.CustomEmailForm in project ORCID-Source by ORCID.
the class CustomEmailControllerTest method validateSubjectTest.
@Test
public void validateSubjectTest() {
CustomEmailForm customEmail = customEmailController.getEmptyCustomEmailForm("APP-5555555555555555");
customEmail.setSubject(Text.valueOf("This is a subject <a>"));
customEmail = customEmailController.validateSubject(customEmail);
assertEquals(1, customEmail.getSubject().getErrors().size());
assertEquals(customEmailController.getMessage("custom_email.subject.html"), customEmail.getSubject().getErrors().get(0));
customEmail.setSubject(Text.valueOf("This is a subject"));
customEmail = customEmailController.validateSubject(customEmail);
assertEquals(0, customEmail.getSubject().getErrors().size());
}
use of org.orcid.pojo.ajaxForm.CustomEmailForm in project ORCID-Source by ORCID.
the class CustomEmailControllerTest method validateContentTest.
@Test
public void validateContentTest() {
CustomEmailForm customEmail = customEmailController.getEmptyCustomEmailForm("APP-5555555555555555");
customEmail = customEmailController.validateContent(customEmail);
assertNotNull(customEmail);
assertEquals(1, customEmail.getContent().getErrors().size());
assertEquals(customEmailController.getMessage("custom_email.content.not_blank"), customEmail.getContent().getErrors().get(0));
customEmail.setContent(Text.valueOf("This is a test"));
customEmail = customEmailController.validateContent(customEmail);
assertNotNull(customEmail);
assertEquals(1, customEmail.getContent().getErrors().size());
assertEquals(customEmailController.getMessage("custom_email.content.verification_url_required"), customEmail.getContent().getErrors().get(0));
customEmail.setContent(Text.valueOf("${verification_url}"));
customEmail = customEmailController.validateContent(customEmail);
assertNotNull(customEmail);
assertEquals(0, customEmail.getContent().getErrors().size());
customEmail.setContent(Text.valueOf("This is a test ${verification_url} <a>"));
customEmail.setHtml(false);
customEmail = customEmailController.validateContent(customEmail);
assertNotNull(customEmail);
assertEquals(1, customEmail.getContent().getErrors().size());
assertEquals(customEmailController.getMessage("custom_email.content.html"), customEmail.getContent().getErrors().get(0));
customEmail.setHtml(true);
customEmail = customEmailController.validateContent(customEmail);
assertNotNull(customEmail);
assertEquals(0, customEmail.getContent().getErrors().size());
}
Aggregations