コード例 #1
0
  /** Test that an email template returns successful with a subject and message */
  @Test
  public void testRetrieveTemplateJSON() {
    context.turnOffAuthorization();

    EmailTemplate template =
        settingRepo.createEmailTemplate(
            "newTemplate", "New Template Subject", "New Template Message");
    template.save();
    Long id = template.getId();

    JPA.em().getTransaction().commit();
    JPA.em().clear();
    JPA.em().getTransaction().begin();

    LOGIN();

    String UPDATE_URL = Router.reverse("ViewTab.retrieveTemplateJSON").url;

    Map<String, String> params = new HashMap<String, String>();
    params.put("id", id.toString());

    Response response = POST(UPDATE_URL, params);
    assertIsOk(response);
    assertContentMatch("\"success\": true,", response);

    template = settingRepo.findEmailTemplate(id);
    template.delete();

    context.restoreAuthorization();
  }
コード例 #2
0
  @Override
  public EmailTemplate generateSystemEmailTemplate(String name) {
    try {
      String templatePath = BASE_PATH + encodeTemplateName(name);
      File templateFile = new File(templatePath);

      String data = FileUtils.readFileToString(templateFile);

      // Remove any comment lines
      data = data.replaceAll("\\s*#.*[\\n\\r]{1}", "");

      // Extract the subject
      Matcher subjectMatcher = SUBJECT_PATTERN.matcher(data);
      if (!subjectMatcher.find())
        throw new IllegalStateException("Unable to identify the template's subject.");
      String subject = subjectMatcher.group(1).trim();

      // Trim the subject leaving just the body.
      int index = data.indexOf("\n");
      if (index < 0) index = data.indexOf("\r");
      String message = data.substring(index);

      if (subject == null || subject.length() == 0)
        throw new IllegalStateException("Unable to identify the template's subject.");

      if (message == null || message.length() == 0)
        throw new IllegalStateException("Unable to identify the template's message.");

      try {
        context.turnOffAuthorization();

        // Check if the template allready exists
        EmailTemplate template = settingRepo.findEmailTemplateByName(name);
        if (template == null) {
          // The template dosn't exist, so create a new one.
          template = settingRepo.createEmailTemplate(name, subject, message);
        } else {
          // The template allready exists. Update it's contents.
          template.setSubject(subject);
          template.setMessage(message);
        }
        template.setSystemRequired(true);

        template.save();
        return template;
      } finally {
        context.restoreAuthorization();
      }

    } catch (Exception e) {
      throw new IllegalStateException("Unable to generate system email template: " + name, e);
    }
  }
コード例 #3
0
  /** Test that an admin can change the custom action values. */
  @Test
  public void testUpdateCustomActionsJSON() {
    context.turnOffAuthorization();

    Person person = personRepo.findPersonByEmail("*****@*****.**");
    Submission submission = subRepo.createSubmission(person);
    submission.setAssignee(person);
    submission.save();

    Long id = submission.getId();

    assertEquals(submission.getAssignee().getCurrentEmailAddress(), "*****@*****.**");

    CustomActionDefinition actionDef =
        settingRepo.createCustomActionDefinition("Passed Classes", false).save();

    Long actionId = actionDef.getId();

    JPA.em().getTransaction().commit();
    JPA.em().clear();
    JPA.em().getTransaction().begin();

    LOGIN();

    String UPDATE_URL = Router.reverse("ViewTab.updateCustomActionsJSON").url;

    Map<String, String> params = new HashMap<String, String>();
    params.put("id", id.toString());
    params.put("action", actionId.toString());
    params.put("value", "true");

    Response response = POST(UPDATE_URL, params);
    assertIsOk(response);

    submission = subRepo.findSubmission(id);
    actionDef = settingRepo.findCustomActionDefinition(actionId);

    assertTrue(submission.getCustomAction(actionDef).getValue());

    submission.delete();
    actionDef.delete();

    context.restoreAuthorization();
  }
コード例 #4
0
  /** Test that the left column gets refreshed properly. */
  @Test
  public void testRefreshLeftColumn() {
    context.turnOffAuthorization();

    Person person = personRepo.findPersonByEmail("*****@*****.**");
    Submission submission = subRepo.createSubmission(person);
    submission.setDocumentTitle("My Document Title");
    State state = stateManager.getState("InReview");
    submission.setState(state);
    EmbargoType embargo = settingRepo.findAllEmbargoTypes().get(0);
    submission.addEmbargoType(embargo);
    submission.save();
    Long id = submission.getId();

    assertEquals("My Document Title", submission.getDocumentTitle());

    JPA.em().getTransaction().commit();
    JPA.em().clear();
    JPA.em().getTransaction().begin();

    LOGIN();

    String UPDATE_URL = Router.reverse("ViewTab.updateJSON").url;

    Map<String, String> params = new HashMap<String, String>();
    params.put("subId", id.toString());
    params.put("field", "title");
    params.put("value", "This is a new title");

    Response response = POST(UPDATE_URL, params);
    assertIsOk(response);
    assertContentMatch("\"success\": true,", response);

    submission = subRepo.findSubmission(id);

    UPDATE_URL = Router.reverse("ViewTab.refreshLeftColumn").url;

    params.clear();
    params.put("id", id.toString());

    response = POST(UPDATE_URL, params);
    assertIsOk(response);
    assertContentMatch("Document title changed to", response);

    submission.delete();

    context.restoreAuthorization();
  }
コード例 #5
0
  @Override
  public List<EmailTemplate> generateAllSystemEmailTemplates() {

    List<EmailTemplate> created = new ArrayList<EmailTemplate>();
    for (String name : getAllSystemEmailTemplateNames()) {

      EmailTemplate template = settingRepo.findEmailTemplateByName(name);

      if (template == null) {
        template = generateSystemEmailTemplate(name);
        created.add(template);
      }
    }

    return created;
  }