Skip to content

Commit

Permalink
Minor fix of DataSourceModel
Browse files Browse the repository at this point in the history
  • Loading branch information
jefftlin committed Aug 21, 2024
1 parent 447ca8d commit b923795
Show file tree
Hide file tree
Showing 7 changed files with 77 additions and 28 deletions.
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
package com.webank.wedatasphere.exchangis.datasource.core.domain;


import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.webank.wedatasphere.exchangis.datasource.core.utils.Json;
import org.apache.commons.lang3.StringUtils;

import javax.validation.constraints.Size;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

/**
* DataSource model
*/
@JsonInclude(JsonInclude.Include.NON_EMPTY)
public class ExchangisDataSourceModel {

/**
Expand All @@ -26,6 +30,7 @@ public class ExchangisDataSourceModel {
/**
* Model name (always equal to cluster name)
*/
@Size(max = 100)
private String modelName;

/**
Expand All @@ -36,19 +41,24 @@ public class ExchangisDataSourceModel {
/**
* Model description
*/
@Size(max = 100)
private String modelDesc;

private String parameter;

private Map<String, Object> parameterMap;

private String createOwner;

private String createUser;

@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
private Date createTime;

private String modifyUser;

private Date updateTime;
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
private Date modifyTime;

/**
* resolve parameters
Expand Down Expand Up @@ -108,6 +118,14 @@ public void setModelDesc(String modelDesc) {
this.modelDesc = modelDesc;
}

public String getCreateOwner() {
return createOwner;
}

public void setCreateOwner(String createOwner) {
this.createOwner = createOwner;
}

public String getCreateUser() {
return createUser;
}
Expand Down Expand Up @@ -140,11 +158,11 @@ public void setModifyUser(String modifyUser) {
this.modifyUser = modifyUser;
}

public Date getUpdateTime() {
return updateTime;
public Date getModifyTime() {
return modifyTime;
}

public void setUpdateTime(Date updateTime) {
this.updateTime = updateTime;
public void setModifyTime(Date modifyTime) {
this.modifyTime = modifyTime;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,14 @@ public void setCreateUser(String createUser) {
this.createUser = createUser;
}

public Date getCreateTime() {
return createTime;
}

public void setCreateTime(Date createTime) {
this.createTime = createTime;
}

public String getModifyUser() {
return modifyUser;
}
Expand All @@ -149,6 +157,14 @@ public void setModifyUser(String modifyUser) {
this.modifyUser = modifyUser;
}

public Date getModifyTime() {
return modifyTime;
}

public void setModifyTime(Date modifyTime) {
this.modifyTime = modifyTime;
}

public RateLimit() {
this.limitRealm = DEFAULT_LIMIT_REALM;
this.flowRateLimitUnit = DEFAULT_FLOW_RATE_LIMIT_UNIT;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.webank.wedatasphere.exchangis.datasource.server.restful.api;

import com.webank.wedatasphere.exchangis.common.UserUtils;
import com.webank.wedatasphere.exchangis.common.config.GlobalConfiguration;
import com.webank.wedatasphere.exchangis.common.enums.AuthType;
import com.webank.wedatasphere.exchangis.common.pager.PageList;
import com.webank.wedatasphere.exchangis.datasource.core.domain.ExchangisDataSourceModel;
Expand Down Expand Up @@ -38,23 +39,29 @@ public ExchangisDataSourceModelController(DataSourceModelService dataSourceModel
this.dataSourceModelService = dataSourceModelService;
}

@RequestMapping( value = "", method = RequestMethod.POST)
public Message add(@Valid @RequestBody ExchangisDataSourceModel model, HttpServletRequest request){
if(StringUtils.isNotBlank(model.getCreateUser()) && isDuplicate(model.getModelName(), request)){
Message.error("The name of model already exists");
@RequestMapping(value = "", method = RequestMethod.POST)
public Message add(@Valid @RequestBody ExchangisDataSourceModel model, HttpServletRequest request) {
if (StringUtils.isNotBlank(model.getCreateUser()) && isDuplicate(model.getModelName(), request)) {
return Message.error("The name of model already exists");
}
String userName = UserUtils.getLoginUser(request);
if (GlobalConfiguration.isAdminUser(userName)) {
model.setCreateOwner("");
} else {
model.setCreateOwner(model.getCreateUser());
}
model.setModelName(StringEscapeUtils.escapeHtml3(model.getModelName()));
boolean ok = dataSourceModelService.add(model);
return ok ? Message.ok() :
Message.error("Failed ti add datasource model");
}

@RequestMapping( value = "/{id}", method = RequestMethod.DELETE)
@RequestMapping(value = "/{id}", method = RequestMethod.DELETE)
public Message delete(@PathVariable Long id, HttpServletRequest request) {
DataSourceModelQuery query = new DataSourceModelQuery();
query.setModelId(id.intValue());
List<ExchangisDataSourceModel> dsModels = dataSourceModelService.selectAllList(query);
if(Objects.nonNull(dsModels) && dsModels.size() > 0){
if (Objects.nonNull(dsModels) && dsModels.size() > 0) {
return Message.error("The model is in use, cannot delete it");
}
boolean result = dataSourceModelService.delete(String.valueOf(id));
Expand All @@ -65,15 +72,15 @@ public Message delete(@PathVariable Long id, HttpServletRequest request) {
Message.error("Failed to delete the dataSource model");
}

@RequestMapping( value = "/{id}", method = RequestMethod.PUT)
public Message update(@Valid @RequestBody ExchangisDataSourceModel model, HttpServletRequest request){
if(model.getId() <= 0){
@RequestMapping(value = "/{id}", method = RequestMethod.PUT)
public Message update(@Valid @RequestBody ExchangisDataSourceModel model, HttpServletRequest request) {
if (model.getId() <= 0) {
Message.error("Error dataSource model");
}
ExchangisDataSourceModel osMA = dataSourceModelService.get(model.getId());
if(!osMA.getModelName().equals(model.getModelName())
if (!osMA.getModelName().equals(model.getModelName())
&& StringUtils.isNotBlank(model.getCreateUser())
&& isDuplicate(model.getModelName(), model.getCreateUser())){
&& isDuplicate(model.getModelName(), model.getCreateUser())) {
return Message.error("The model is in duplicate");
}
model.setModelName(StringEscapeUtils.escapeHtml3(model.getModelName()));
Expand All @@ -86,8 +93,8 @@ && isDuplicate(model.getModelName(), model.getCreateUser())){
}

@RequestMapping(value = "/{modelType:\\w+}/list", method = RequestMethod.GET)
public Message listByType(@PathVariable("modelType")String modelType,
HttpServletRequest request){
public Message listByType(@PathVariable("modelType") String modelType,
HttpServletRequest request) {
DataSourceModelQuery query = new DataSourceModelQuery();
query.setSourceType(modelType);
List<ExchangisDataSourceModel> list = dataSourceModelService.selectAllList(query);
Expand All @@ -106,15 +113,15 @@ public Message listByType(@PathVariable("modelType")String modelType,
@RequestMapping(value = "pageList", method = RequestMethod.GET)
public Message pageList(DataSourceModelQuery pageQuery, HttpServletRequest request) {
PageList<ExchangisDataSourceModel> list = null;
int pageSize = pageQuery.getPageSize();
if (pageSize == 0){
int pageSize = pageQuery.getPageSize();
if (pageSize == 0) {
pageQuery.setPageSize(10);
}
list = dataSourceModelService.findPage(pageQuery);
String username = UserUtils.getLoginUser(request);
list.getData().forEach(element -> {
//Bind authority scopes
if(StringUtils.isNotBlank(element.getCreateUser()) && !element.getCreateUser().equals(username)){
if (StringUtils.isNotBlank(element.getCreateUser()) && !element.getCreateUser().equals(username)) {
//Remove sensitive data
Map<String, Object> params = element.resolveParams();
Map<String, Object> newParams = new HashMap<>();
Expand All @@ -131,7 +138,7 @@ public Message selectAll(DataSourceModelQuery pageQuery, HttpServletRequest requ
String username = UserUtils.getLoginUser(request);
data.forEach(element -> {
//Bind authority scopes
if(StringUtils.isNotBlank(element.getCreateUser()) && !element.getCreateUser().equals(username)){
if (StringUtils.isNotBlank(element.getCreateUser()) && !element.getCreateUser().equals(username)) {
//Remove sensitive data
Map<String, Object> params = element.resolveParams();
Map<String, Object> newParams = new HashMap<>();
Expand All @@ -142,13 +149,13 @@ public Message selectAll(DataSourceModelQuery pageQuery, HttpServletRequest requ
return Message.ok().data("data", data);
}

private boolean isDuplicate(String tsName, HttpServletRequest request){
private boolean isDuplicate(String tsName, HttpServletRequest request) {
DataSourceModelQuery query = new DataSourceModelQuery();
query.setModelExactName(tsName);
return !dataSourceModelService.selectAllList(query).isEmpty();
}

private boolean isDuplicate(String tsName, String createUser){
private boolean isDuplicate(String tsName, String createUser) {
DataSourceModelQuery query = new DataSourceModelQuery();
query.setModelExactName(tsName);
query.setCreateUser(createUser);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@

@RestController
@RequestMapping(value = "dss/exchangis/main/datasources/rate-limit", produces = {"application/json;charset=utf-8"})
public class RateLimitController {
public class ExchangisRateLimitController {

private static final Logger LOG = LoggerFactory.getLogger(RateLimitController.class);
private static final Logger LOG = LoggerFactory.getLogger(ExchangisRateLimitController.class);

@Resource
private DataSourceModelService dataSourceModelService;
Expand Down
8 changes: 8 additions & 0 deletions exchangis-datasource/exchangis-datasource-service/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -68,5 +68,13 @@
</configuration>
</plugin>
</plugins>
<resources>
<resource>
<directory>src/main/java</directory>
<includes>
<include>**/*.xml</include>
</includes>
</resource>
</resources>
</build>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.webank.wedatasphere.exchangis.datasource.mapper.DataSourceModelMapper">
<resultMap id="resultModel" type="DataSourceModel">
<resultMap id="resultModel" type="com.webank.wedatasphere.exchangis.datasource.core.domain.ExchangisDataSourceModel">
<result property="id" column="id"/>
<result property="clusterName" column="cluster_name"/>
<result property="modelName" column="model_name"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ public Message listDataSources(HttpServletRequest request, String engineType, St
*/
@Override
@Transactional(rollbackFor = Exception.class)
public Map<String, Object> create(String operator, DataSourceCreateVo vo) throws ExchangisDataSourceException {
public Map<String, Object> create(String operator, DataSourceCreateVo vo) throws ExchangisDataSourceException, JsonErrorException {
// TODO merge parameter from data source model
Map<String, Object> payLoads;
try {
Expand Down

0 comments on commit b923795

Please sign in to comment.