Example #1
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;
  }
Example #2
0
 @Override
 public DataSourceBuilder getDataSourceBuilder(String id) throws BaseException {
   return dataSourceBuilderListener.getInstance(id);
 }
  @Override
  public TemplateResult process(RequestAction action, String templateKey, Map<String, String> param)
      throws BaseException {

    TemplateResult result = null;
    DataTemplate template = null;
    try {
      template = dataTemplates.getInstance(templateKey);
      DataAccess access = dataAccess.getFirstInstance();

      switch ((DataAccessRequestAction) action) {
        case GetData:
          {
            result = getData(access, template, param);
            break;
          }
        case GetUser:
          {
            result = getUser(access, template, param);
            break;
          }
        case GetUsers:
          {
            result = getUsers(access, template, param);
            break;
          }
        case UpdateUser:
          {
            result = updateUser(access, template, param);
            break;
          }
        case CreateUser:
          {
            result = createUser(access, template, param);
            break;
          }
        case GetItems:
          {
            result = getItems(access, template, param);
            break;
          }
        case GetItem:
          {
            result = getItem(access, template, param);
            break;
          }
        case UpdateItem:
          {
            result = updateItem(access, template, param);
            break;
          }
        case CreateItem:
          {
            result = createItem(access, template, param);
            break;
          }
        case GetInteractions:
          {
            result = getInteractions(access, template, param);
            break;
          }
        case GetInteraction:
          {
            result = getInteraction(access, template, param);
            break;
          }
        case AddInteraction:
          {
            result = addInteraction(access, template, param);
            break;
          }
        case GetSources:
          {
            result = getSources(access, template, param);
            break;
          }
        case CreateSource:
          {
            result = createSource(access, template, param);
            break;
          }
        case UpdateSource:
          {
            result = updateSource(access, template, param);
            break;
          }
        case GetSource:
          {
            result = getSource(access, template, param);
            break;
          }
        case GetDataSourceBuilder:
          {
            result = getDataSourceBuilder(access, template, param);
            break;
          }
        case DeleteSource:
          {
            result = deleteSource(access, template, param);
            break;
          }
        case GetRelation:
          {
            result = getRelations(access, template, param);
            break;
          }
        case GetRelations:
          {
            result = getRelations(access, template, param);
            break;
          }
        case CreateRelation:
          {
            result = createRelation(access, template, param);
            break;
          }
        case UpdateRelation:
          {
            result = updateRelation(access, template, param);
            break;
          }
      }
    } catch (BaseException ex) {
      if (template != null) result = template.transform(ex);
      ex.printStackTrace();

    } catch (Exception ex) {
      if (template != null) result = template.transform(new BaseException(ex.getMessage()));
      ex.printStackTrace();
    }

    return result;
  }