Skip to content

Commit

Permalink
Merge pull request #105 from hx23840/1.0
Browse files Browse the repository at this point in the history
fix add datasource bug,if you add optional item,it doesn't work
  • Loading branch information
EchoXiaoLang authored Sep 1, 2022
2 parents 96d54d9 + 5825afb commit 5f9a210
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import com.youngdatafan.portal.model.management.datasource.vo.ConnectionDetailVO;
import com.youngdatafan.portal.model.management.datasource.vo.DatasourceConnectorVO;
import com.youngdatafan.portal.model.management.datasource.vo.JCDataSourceVO;
import com.youngdatafan.portal.model.management.datasource.vo.ParameterVo;
import com.youngdatafan.portal.model.management.util.jdbc.DatasourceExplainDTO;
import com.youngdatafan.portal.model.management.util.jdbc.JdbcUtils;
import java.sql.Connection;
Expand Down Expand Up @@ -313,6 +314,23 @@ public List<DatasourceDTO> getDatasourceNoPage(String userId, String sourcePlatf
public String getUrl(JCDataSourceVO jcDataSourceVO) throws Exception {
ConnectionDetailVO connectionDetailVO = new ConnectionDetailVO();
ConnectionDetailVO.ConnectionBean connectionBean = new ConnectionDetailVO.ConnectionBean();

ConnectionDetailVO.ConnectionBean.AttributesBean attributesBean = new ConnectionDetailVO.ConnectionBean.AttributesBean();

List<ParameterVo> optionsParameterVo = jcDataSourceVO.getDsConnectorSetting().getOptionsParameterVo();
List<ConnectionDetailVO.ConnectionBean.AttributesBean.AttributeBean> attributeBeanLis = new ArrayList<>();

for (ParameterVo parameterVo: optionsParameterVo) {
ConnectionDetailVO.ConnectionBean.AttributesBean.AttributeBean attributeBean = new ConnectionDetailVO.ConnectionBean.AttributesBean.AttributeBean();
attributeBean.setCode(parameterVo.getCode());
attributeBean.setAttribute(parameterVo.getAttribute());

attributeBeanLis.add(attributeBean);
}

attributesBean.setAttribute(attributeBeanLis);

connectionBean.setAttributes(attributesBean);
connectionBean.setUsername(jcDataSourceVO.getDsUsername());
connectionBean.setAccess(jcDataSourceVO.getAccess());
connectionBean.setType(jcDataSourceVO.getDsType());
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,22 @@
package com.youngdatafan.portal.model.management.util.jdbc;

import com.youngdatafan.dataintegration.core.util.JsonUtils;
import com.youngdatafan.dataintegration.core.util.json.JSONLinkedObject;
import com.youngdatafan.portal.model.management.basicmodel.dto.AllColumnDTO;
import com.youngdatafan.portal.model.management.common.entity.ModelFilterVO;
import com.youngdatafan.portal.model.management.datasource.dto.DatasourceDTO;
import com.youngdatafan.portal.model.management.datasource.vo.ConnectionDetailVO;
import com.youngdatafan.portal.model.management.util.enums.DimensionMetricEnum;
import com.youngdatafan.portal.model.management.util.enums.TrueFalse;
import org.apache.commons.lang.StringEscapeUtils;
import org.json.JSONArray;
import org.json.JSONObject;
import org.json.XML;
import org.pentaho.di.core.database.Database;
import org.pentaho.di.core.database.DatabaseMeta;
import org.pentaho.di.core.encryption.KettleTwoWayPasswordEncoder;
import org.pentaho.di.core.exception.KettleDatabaseException;
import org.pentaho.di.core.exception.KettleXMLException;
import org.pentaho.di.core.row.RowMetaInterface;
import org.pentaho.di.core.row.ValueMetaInterface;
import org.springframework.util.StringUtils;
Expand Down Expand Up @@ -188,9 +196,45 @@ private static Database getDatabaseConnect(DatasourceDTO datasourceDTO) {
}
String password = PASSWORD_ENCODER.decode(datasourceDTO.getDsPassword());

DatabaseMeta databaseMeta = new DatabaseMeta(datasourceDTO.getDatasourceId()
, datasourceDTO.getDsType(), "JDBC", datasourceExplainDTO.getHost()
, datasourceExplainDTO.getDb(), datasourceExplainDTO.getPort(), datasourceDTO.getDsUsername(), password);
ConnectionDetailVO connectionDetailVO = new ConnectionDetailVO();
ConnectionDetailVO.ConnectionBean connectionBean = new ConnectionDetailVO.ConnectionBean();

ConnectionDetailVO.ConnectionBean.AttributesBean attributesBean = new ConnectionDetailVO.ConnectionBean.AttributesBean();

JSONArray jsonArray = new JSONObject(datasourceDTO.getDsConectorSetting()).getJSONArray("optionsParameterVo");
List<ConnectionDetailVO.ConnectionBean.AttributesBean.AttributeBean> attributeBeanLis = new ArrayList<>();

for (Object parameterVo: jsonArray) {
ConnectionDetailVO.ConnectionBean.AttributesBean.AttributeBean attributeBean = new ConnectionDetailVO.ConnectionBean.AttributesBean.AttributeBean();

JSONObject jsonObject = (JSONObject)parameterVo;
attributeBean.setCode(jsonObject.getString("code"));
attributeBean.setAttribute(jsonObject.getString("attribute"));

attributeBeanLis.add(attributeBean);
}

attributesBean.setAttribute(attributeBeanLis);

connectionBean.setAttributes(attributesBean);
connectionBean.setUsername(datasourceDTO.getDsUsername());
connectionBean.setAccess("JDBC");
connectionBean.setType(datasourceDTO.getDsType());
connectionBean.setServer(datasourceExplainDTO.getHost());
connectionBean.setDatabase(datasourceExplainDTO.getDb());
connectionBean.setPassword(password);
connectionBean.setPort(datasourceExplainDTO.getPort());
connectionDetailVO.setConnection(connectionBean);
String projectFile = StringEscapeUtils.unescapeXml(JsonUtils.toString(connectionDetailVO));
projectFile = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
+ XML.toString(new JSONLinkedObject(projectFile));
DatabaseMeta databaseMeta = null;
try {
databaseMeta = new DatabaseMeta(projectFile);
} catch (KettleXMLException e) {
throw new RuntimeException(e);
}

final Database database = new Database(databaseMeta);
try {
database.connect();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ public static FileSystemOptions getFileSystemOptions(String fileServerType, Stri
S3FileSystemConfigBuilder.getInstance().setCredentialsProvider(opts, new AWSStaticCredentialsProvider(new BasicAWSCredentials(username, password)));
break;
default:
S3FileSystemConfigBuilder.getInstance().setUseHttps(opts, false);
S3FileSystemConfigBuilder.getInstance().setCredentialsProvider(opts, new AWSStaticCredentialsProvider(new BasicAWSCredentials(username, password)));
break;
}
return opts;
Expand Down

0 comments on commit 5f9a210

Please sign in to comment.