Search in sources :

Example 1 with CustomEmailForm

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;
}
Also used : CustomEmailForm(org.orcid.pojo.ajaxForm.CustomEmailForm) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 2 with CustomEmailForm

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;
}
Also used : MemberType(org.orcid.jaxb.model.clientgroup.MemberType) CustomEmailEntity(org.orcid.persistence.jpa.entities.CustomEmailEntity) ArrayList(java.util.ArrayList) CustomEmailForm(org.orcid.pojo.ajaxForm.CustomEmailForm) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 3 with CustomEmailForm

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());
}
Also used : CustomEmailForm(org.orcid.pojo.ajaxForm.CustomEmailForm) Test(org.junit.Test) BaseControllerTest(org.orcid.frontend.web.util.BaseControllerTest)

Example 4 with CustomEmailForm

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());
}
Also used : CustomEmailForm(org.orcid.pojo.ajaxForm.CustomEmailForm) Test(org.junit.Test) BaseControllerTest(org.orcid.frontend.web.util.BaseControllerTest)

Aggregations

CustomEmailForm (org.orcid.pojo.ajaxForm.CustomEmailForm)4 Test (org.junit.Test)2 BaseControllerTest (org.orcid.frontend.web.util.BaseControllerTest)2 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)2 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)2 ArrayList (java.util.ArrayList)1 MemberType (org.orcid.jaxb.model.clientgroup.MemberType)1 CustomEmailEntity (org.orcid.persistence.jpa.entities.CustomEmailEntity)1