private TemplateResult getDataSourceBuilder(
      DataAccess access, DataTemplate template, Map<String, String> param) throws BaseException {
    String id = param.get(Helper.Keys.SourceId);
    DataSourceBuilder builder = access.getDataSourceBuilder(id);

    if (builder.getConfiguration(Helper.Keys.DataBuilderId) == null) {
      builder.setConfiguration(
          new ConfigurationItem(
              Helper.Keys.DataBuilderId,
              ConfigurationItem.ConfigurationItemType.String,
              builder.getKey(),
              ConfigurationItem.ConfigurationItemRequirementType.Hidden));
    }

    return template.transform(builder);
  }
Example #2
0
  private DataSource connectDataSource(Map<String, String> content) throws BaseException {
    String typeKey = content.get(Helper.Keys.DataBuilderId);
    String dataSourceId = content.get(Helper.Keys.SourceId);

    if (typeKey == null)
      throw new MissingArgumentException(
          String.format("Argument %s is missing.", Helper.Keys.DataBuilderId));
    if (dataSourceId == null)
      throw new MissingArgumentException(
          String.format("Argument %s is missing.", Helper.Keys.SourceId));

    DataSourceBuilder connection = dataSourceBuilderListener.getInstance(typeKey);

    DataSource source = connection.createInstance(dataSourceId, content);
    source.setState(DataInformation.DataState.CONNECTING);

    Thread thread =
        new Thread() {
          public void run() {
            try {
              source.connect();
              source.setState(DataInformation.DataState.READY);
              threads.remove(source.getId());
            } catch (BaseException e) {
              e.printStackTrace();
              threads.remove(source.getId());
              dataSources.remove(source.getId());
            }
          }
        };

    threads.put(dataSourceId, thread);

    thread.start();

    return source;
  }