Esempio n. 1
0
  @Test
  public void shouldPrepareViewForParameters() throws Exception {
    // // given
    Map<String, String> arguments = ImmutableMap.of("context", "{\"form.id\":\"13\"}");
    ModelAndView expectedMav = mock(ModelAndView.class);
    CrudService crudController = mock(CrudService.class);
    given(
            crudController.prepareView(
                BasicConstants.PLUGIN_IDENTIFIER,
                BasicConstants.VIEW_PARAMETERS,
                arguments,
                Locale.ENGLISH))
        .willReturn(expectedMav);

    ParameterService parameterService = mock(ParameterService.class);
    given(parameterService.getParameterId()).willReturn(13L);

    BasicController basicController = new BasicController();
    setField(basicController, "crudController", crudController);
    setField(basicController, "parameterService", parameterService);

    // // when
    ModelAndView mav = basicController.getParameterPageView(Locale.ENGLISH);

    // // then
    assertEquals(expectedMav, mav);
  }
Esempio n. 2
0
  private static void getRapidMinerParameters(StringBuffer string) {
    string.append("RapidMiner Parameters:" + Tools.getLineSeparator());

    for (String key : ParameterService.getParameterKeys()) {
      string.append(
          "  " + key + "\t= " + ParameterService.getParameterValue(key) + Tools.getLineSeparator());
    }
  }
  /**
   * @param reference
   * @param type
   * @return
   */
  public boolean isA18Nec(String reference, String type) {
    boolean returnBool = false;
    String seaPortParam = "";
    try {
      seaPortParam = ParameterService.getInstance().getParameterValue(Constants.PARAM_A18_PORTS);
    } catch (Exception e1) {
      return false;
    }
    List l;
    try {
      l = getSeaportsForFacility(reference, type);
      for (int i = 0, n = l.size(); i < n; i++) {
        try {
          FacilityValue facVal = (FacilityValue) findByPrimaryKey(new FacilityPK((Long) l.get(i)));
          if (seaPortParam.indexOf(facVal.getReference()) != -1) {
            returnBool = true;
            break;
          }
        } catch (Exception e) {

        }
      }
    } catch (Exception e1) {

    }

    return returnBool;
  }
Esempio n. 4
0
  // init I18N
  static {
    ParameterService.init();

    String localeLanguage =
        ParameterService.getParameterValue(RapidMiner.PROPERTY_RAPIDMINER_GENERAL_LOCALE_LANGUAGE);
    Locale locale = Locale.getDefault();
    if (localeLanguage != null) {
      locale = new Locale(localeLanguage);
      Locale.setDefault(locale);
      LogService.getRoot().log(Level.INFO, "com.rapidminer.tools.I18N.set_locale_to", locale);
    } else {
      LogService.getRoot()
          .log(Level.INFO, "com.rapidminer.tools.I18N.using_default_locale", locale);
    }
    JComponent.setDefaultLocale(locale);

    USER_ERROR_BUNDLE =
        new ExtensibleResourceBundle(
            ResourceBundle.getBundle(
                "com.rapidminer.resources.i18n.UserErrorMessages",
                locale,
                I18N.class.getClassLoader()));
    ERROR_BUNDLE =
        new ExtensibleResourceBundle(
            ResourceBundle.getBundle(
                "com.rapidminer.resources.i18n.Errors", locale, I18N.class.getClassLoader()));
    GUI_BUNDLE =
        new ExtensibleResourceBundle(
            ResourceBundle.getBundle(
                "com.rapidminer.resources.i18n.GUI", locale, I18N.class.getClassLoader()));
    SETTINGS_BUNDLE =
        new ExtensibleResourceBundle(
            ResourceBundle.getBundle(
                "com.rapidminer.resources.i18n.Settings", locale, I18N.class.getClassLoader()));

    ResourceBundle plotterBundle =
        ResourceBundle.getBundle(
            "com.rapidminer.resources.i18n.PlotterMessages", locale, I18N.class.getClassLoader());

    GUI_BUNDLE.addResourceBundle(plotterBundle);
  }
  public static void sendEmailWithException(
      String address, String subject, String content, Map<String, String> headers)
      throws MailNotSentException {
    try {
      String method =
          ParameterService.getParameterValue(RapidMiner.PROPERTY_RAPIDMINER_TOOLS_MAIL_METHOD);
      int methodIndex = -1;
      if (method != null) {
        try {
          methodIndex = Integer.parseInt(method);
        } catch (NumberFormatException e) {
          methodIndex = -1;
          for (int i = 0; i < RapidMiner.PROPERTY_RAPIDMINER_TOOLS_MAIL_METHOD_VALUES.length; i++) {
            if (RapidMiner.PROPERTY_RAPIDMINER_TOOLS_MAIL_METHOD_VALUES[i].equals(method)) {
              methodIndex = i;
              break;
            }
          }
        }
      }
      if (methodIndex == -1) {
        methodIndex = RapidMiner.PROPERTY_RAPIDMINER_TOOLS_MAIL_METHOD_SMTP;
      }

      MailSender mailSender = null;
      switch (methodIndex) {
        case RapidMiner.PROPERTY_RAPIDMINER_TOOLS_MAIL_METHOD_SMTP:
          mailSender = new MailSenderSMTP();
          break;
        case RapidMiner.PROPERTY_RAPIDMINER_TOOLS_MAIL_METHOD_SENDMAIL:
          mailSender = new MailSenderSendmail();
          break;
        default:
          // LogService.getGlobal().log("Illegal send mail method: " + method + ".",
          // LogService.ERROR);
          LogService.getRoot()
              .log(
                  Level.SEVERE,
                  "com.rapidminer.tools.MailUtilities.illegal_send_mail_method",
                  method);
          throw new MailNotSentException(
              "Illegal send mail method", "illegal_send_mail_method", method);
      }

      if (mailSender != null) {
        mailSender.sendEmail(address, subject, content, headers);
        // LogService.getRoot().info("Sent mail to "+address+" with subject "+subject);
        LogService.getRoot()
            .log(
                Level.INFO,
                "com.rapidminer.tools.MailUtilities.sent_mail_to_adress_with_subject",
                new Object[] {address, subject});
      }
    } catch (Exception e) {
      // LogService.getGlobal().log("Cannot send mail to " + address + ": " + e,
      // LogService.ERROR);
      LogService.getRoot()
          .log(
              Level.SEVERE,
              "com.rapidminer.tools.MailUtilities.sending_mail_to_address_error",
              new Object[] {address, e});
      throw new MailNotSentException(
          "Cannot send mail", "sending_mail_to_address_error", e, new Object[] {address, e});
    }
  }