Beispiel #1
0
 public DataSourceVO<?> mapRow(ResultSet rs, int rowNum) throws SQLException {
   DataSourceVO<?> ds =
       (DataSourceVO<?>)
           SerializationHelper.readObjectInContext(rs.getBlob(5).getBinaryStream());
   ds.setId(rs.getInt(1));
   ds.setXid(rs.getString(2));
   ds.setName(rs.getString(3));
   ds.setDefinition(ModuleRegistry.getDataSourceDefinition(rs.getString(4)));
   return ds;
 }
  @Override
  protected void importImpl() {
    String xid = json.getString("xid");

    if (StringUtils.isBlank(xid)) xid = ctx.getDataSourceDao().generateUniqueXid();

    DataSourceVO<?> vo = ctx.getDataSourceDao().getDataSource(xid);
    if (vo == null) {
      String typeStr = json.getString("type");
      if (StringUtils.isBlank(typeStr))
        addFailureMessage(
            "emport.dataSource.missingType", xid, ModuleRegistry.getDataSourceDefinitionTypes());
      else {
        DataSourceDefinition def = ModuleRegistry.getDataSourceDefinition(typeStr);
        if (def == null)
          addFailureMessage(
              "emport.dataSource.invalidType",
              xid,
              typeStr,
              ModuleRegistry.getDataSourceDefinitionTypes());
        else {
          vo = def.baseCreateDataSourceVO();
          vo.setXid(xid);
        }
      }
    }

    if (vo != null) {
      try {
        // The VO was found or successfully created. Finish reading it in.
        ctx.getReader().readInto(vo, json);

        // Now validate it. Use a new response object so we can distinguish errors in this vo from
        // other errors.
        ProcessResult voResponse = new ProcessResult();
        vo.validate(voResponse);
        if (voResponse.getHasMessages())
          setValidationMessages(voResponse, "emport.dataSource.prefix", xid);
        else {
          // Sweet. Save it.
          boolean isnew = vo.isNew();
          Common.runtimeManager.saveDataSource(vo);
          addSuccessMessage(isnew, "emport.dataSource.prefix", xid);
        }
      } catch (TranslatableJsonException e) {
        addFailureMessage("emport.dataSource.prefix", xid, e.getMsg());
      } catch (JsonException e) {
        addFailureMessage("emport.dataSource.prefix", xid, getJsonExceptionMessage(e));
      }
    }
  }