Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

merge 0.9 to master and fix ci error #774

Merged
merged 13 commits into from
Feb 29, 2024
Merged
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ public enum TypeEnums {

METRIC,
DIMENSION,
TAG,
DOMAIN,
ENTITY,
VIEW,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ public class TagResp extends SchemaItem {

private String type;

private Boolean isCollect;

private boolean hasAdminRes;

private Map<String, Object> ext = new HashMap<>();

private TagDefineType tagDefineType = TagDefineType.FIELD;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;

import java.io.File;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
Expand All @@ -17,9 +19,9 @@
@Slf4j
@Component
public class FileHandlerImpl implements FileHandler {
public static final String FILE_SPILT = File.separator;

private final LocalFileConfig localFileConfig;

public FileHandlerImpl(LocalFileConfig localFileConfig) {
this.localFileConfig = localFileConfig;
}
Expand All @@ -31,8 +33,8 @@ public void backupFile(String fileName) {
createDir(dictDirectoryBackup);
}

String source = localFileConfig.getDictDirectoryLatest() + "/" + fileName;
String target = dictDirectoryBackup + "/" + fileName;
String source = localFileConfig.getDictDirectoryLatest() + FILE_SPILT + fileName;
String target = dictDirectoryBackup + FILE_SPILT + fileName;
Path sourcePath = Paths.get(source);
Path targetPath = Paths.get(target);
try {
Expand Down Expand Up @@ -88,7 +90,7 @@ public void writeFile(List<String> lines, String fileName, Boolean append) {
if (!existPath(dictDirectoryLatest)) {
createDir(dictDirectoryLatest);
}
String filePath = dictDirectoryLatest + "/" + fileName;
String filePath = dictDirectoryLatest + FILE_SPILT + fileName;
if (existPath(filePath)) {
backupFile(fileName);
}
Expand Down Expand Up @@ -117,7 +119,7 @@ public String getDictRootPath() {
@Override
public Boolean deleteDictFile(String fileName) {
backupFile(fileName);
deleteFile(localFileConfig.getDictDirectoryLatest() + "/" + fileName);
deleteFile(localFileConfig.getDictDirectoryLatest() + FILE_SPILT + fileName);
return true;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
package com.tencent.supersonic.headless.core.file;

import com.tencent.supersonic.headless.core.knowledge.helper.HanlpHelper;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;

import java.io.FileNotFoundException;

@Data
@Configuration
@Slf4j
Expand All @@ -18,16 +21,21 @@ public class LocalFileConfig {
private String dictDirectoryBackup;

public String getDictDirectoryLatest() {
return getResourceDir() + dictDirectoryLatest;
return getDictDirectoryPrefixDir() + dictDirectoryLatest;
}

public String getDictDirectoryBackup() {
return getResourceDir() + dictDirectoryBackup;
return getDictDirectoryPrefixDir() + dictDirectoryBackup;
}

private String getResourceDir() {
//return hanlpPropertiesPath = HanlpHelper.getHanlpPropertiesPath();
return ClassLoader.getSystemClassLoader().getResource("").getPath();
private String getDictDirectoryPrefixDir() {
try {
return HanlpHelper.getHanlpPropertiesPath();
} catch (FileNotFoundException e) {
log.warn("getDictDirectoryPrefixDir error: " + e);
e.printStackTrace();
}
return "";
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
public class SysTimeDimensionBuilder {

public static void addSysTimeDimension(List<Dim> dims, DbAdaptor engineAdaptor) {
log.info("addSysTimeDimension before:{}, engineAdaptor:{}", dims, engineAdaptor);
log.debug("addSysTimeDimension before:{}, engineAdaptor:{}", dims, engineAdaptor);
Dim timeDim = getTimeDim(dims);
if (timeDim == null) {
timeDim = Dim.getDefault();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.tencent.supersonic.headless.server.pojo;


import com.tencent.supersonic.headless.api.pojo.request.PageSchemaItemReq;

import java.util.List;

public class TagFilterPage extends PageSchemaItemReq {
private String type;
private List<Integer> statusList;
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
package com.tencent.supersonic.headless.server.rest;

import com.github.pagehelper.PageInfo;
import com.tencent.supersonic.auth.api.authentication.pojo.User;
import com.tencent.supersonic.auth.api.authentication.utils.UserHolder;
import com.tencent.supersonic.headless.api.pojo.request.TagReq;
import com.tencent.supersonic.headless.api.pojo.response.TagResp;
import com.tencent.supersonic.headless.server.pojo.TagFilterPage;
import com.tencent.supersonic.headless.server.service.TagService;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
Expand Down Expand Up @@ -56,4 +58,12 @@ public TagResp getTag(@PathVariable("id") Long id,
return tagService.getTag(id);
}

@PostMapping("/queryTag")
public PageInfo<TagResp> queryPage(@RequestBody TagFilterPage tagFilterPage,
HttpServletRequest request,
HttpServletResponse response) throws Exception {
User user = UserHolder.findUser(request, response);
return tagService.queryPage(tagFilterPage, user);
}

}
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
package com.tencent.supersonic.headless.server.service;

import com.github.pagehelper.PageInfo;
import com.tencent.supersonic.auth.api.authentication.pojo.User;
import com.tencent.supersonic.headless.api.pojo.request.TagReq;
import com.tencent.supersonic.headless.api.pojo.response.TagResp;
import com.tencent.supersonic.headless.server.pojo.TagFilter;
import com.tencent.supersonic.headless.server.pojo.TagFilterPage;
import java.util.List;

public interface TagService {
Expand All @@ -17,4 +19,7 @@ public interface TagService {
TagResp getTag(Long id);

List<TagResp> query(TagFilter tagFilter);

PageInfo<TagResp> queryPage(TagFilterPage tagFilterPage, User user);

}
Original file line number Diff line number Diff line change
@@ -1,16 +1,27 @@
package com.tencent.supersonic.headless.server.service.impl;

import com.alibaba.fastjson.JSONObject;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.google.common.collect.Lists;
import com.tencent.supersonic.auth.api.authentication.pojo.User;
import com.tencent.supersonic.common.pojo.enums.AuthType;
import com.tencent.supersonic.common.pojo.enums.StatusEnum;
import com.tencent.supersonic.common.pojo.enums.TypeEnums;
import com.tencent.supersonic.common.pojo.exception.InvalidArgumentException;
import com.tencent.supersonic.headless.api.pojo.TagDefineParams;
import com.tencent.supersonic.headless.api.pojo.enums.TagDefineType;
import com.tencent.supersonic.headless.api.pojo.request.TagReq;

import com.tencent.supersonic.headless.api.pojo.response.ModelResp;
import com.tencent.supersonic.headless.api.pojo.response.TagResp;
import com.tencent.supersonic.headless.server.persistence.dataobject.CollectDO;
import com.tencent.supersonic.headless.server.persistence.dataobject.TagDO;
import com.tencent.supersonic.headless.server.persistence.repository.TagRepository;
import com.tencent.supersonic.headless.server.pojo.TagFilter;
import com.tencent.supersonic.headless.server.pojo.TagFilterPage;
import com.tencent.supersonic.headless.server.service.CollectService;
import com.tencent.supersonic.headless.server.service.ModelService;
import com.tencent.supersonic.headless.server.service.TagService;
import com.tencent.supersonic.headless.server.utils.NameCheckUtils;
import java.util.ArrayList;
Expand All @@ -19,6 +30,7 @@
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Set;
import java.util.stream.Collectors;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections.CollectionUtils;
Expand All @@ -31,9 +43,14 @@
public class TagServiceImpl implements TagService {

private final TagRepository tagRepository;
private final ModelService modelService;
private final CollectService collectService;

public TagServiceImpl(TagRepository tagRepository) {
public TagServiceImpl(TagRepository tagRepository, ModelService modelService,
CollectService collectService) {
this.tagRepository = tagRepository;
this.modelService = modelService;
this.collectService = collectService;
}

@Override
Expand Down Expand Up @@ -98,10 +115,74 @@ public List<TagResp> query(TagFilter tagFilter) {
return new ArrayList<>();
}

@Override
public PageInfo<TagResp> queryPage(TagFilterPage tagFilterPage, User user) {
TagFilter tagFilter = new TagFilter();
BeanUtils.copyProperties(tagFilterPage, tagFilter);
List<ModelResp> modelRespList = modelService.getAllModelByDomainIds(tagFilterPage.getDomainIds());
List<Long> modelIds = modelRespList.stream().map(ModelResp::getId).collect(Collectors.toList());
tagFilterPage.getModelIds().addAll(modelIds);
tagFilter.setModelIds(tagFilterPage.getModelIds());

List<CollectDO> collectList = collectService.getCollectList(user.getName())
.stream().filter(collectDO -> TypeEnums.TAG.name().equalsIgnoreCase(collectDO.getType()))
.collect(Collectors.toList());
List<Long> collectIds = collectList.stream().map(CollectDO::getCollectId).collect(Collectors.toList());
if (tagFilterPage.isHasCollect()) {
if (CollectionUtils.isEmpty(collectIds)) {
tagFilter.setIds(Lists.newArrayList(-1L));
} else {
tagFilter.setIds(collectIds);
}
}

PageInfo<TagDO> tagDOPageInfo = PageHelper.startPage(tagFilterPage.getCurrent(),
tagFilterPage.getPageSize())
.doSelectPageInfo(() -> query(tagFilter));
PageInfo<TagResp> pageInfo = new PageInfo<>();
BeanUtils.copyProperties(tagDOPageInfo, pageInfo);
List<TagResp> tagRespList = convertList(tagDOPageInfo.getList(), collectIds);
fillAdminRes(tagRespList, user);
pageInfo.setList(tagRespList);

return pageInfo;
}

private void fillAdminRes(List<TagResp> tagRespList, User user) {
List<ModelResp> modelRespList = modelService.getModelListWithAuth(user, null, AuthType.ADMIN);
if (CollectionUtils.isEmpty(modelRespList)) {
return;
}
Set<Long> modelIdSet = modelRespList.stream().map(ModelResp::getId).collect(Collectors.toSet());
for (TagResp tagResp : tagRespList) {
if (modelIdSet.contains(tagResp.getModelId())) {
tagResp.setHasAdminRes(true);
} else {
tagResp.setHasAdminRes(false);
}
}
}

private List<TagResp> convertList(List<TagDO> tagDOList, List<Long> collectIds) {
List<TagResp> tagRespList = new ArrayList<>();
if (CollectionUtils.isNotEmpty(tagDOList)) {
tagDOList.stream().forEach(tagDO -> {
TagResp tagResp = convert(tagDO);
if (CollectionUtils.isNotEmpty(collectIds) && collectIds.contains(tagDO.getId())) {
tagResp.setIsCollect(true);
} else {
tagResp.setIsCollect(false);
}
tagRespList.add(tagResp);
});
}
return tagRespList;
}

private void checkExit(TagReq tagReq) {
TagFilter tagFilter = new TagFilter();
tagFilter.setModelIds(Arrays.asList(tagReq.getModelId()));
//tagFilter.setStatusList(Arrays.asList(StatusEnum.ONLINE.getCode(),StatusEnum.OFFLINE.getCode()));

List<TagResp> tagResps = query(tagFilter);
if (!CollectionUtils.isEmpty(tagResps)) {
Long bizNameSameCount = tagResps.stream().filter(tagResp -> !tagResp.getId().equals(tagReq.getId()))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@
and ( id like CONCAT('%',#{key , jdbcType=VARCHAR},'%') or
name like CONCAT('%',#{key , jdbcType=VARCHAR},'%') or
biz_name like CONCAT('%',#{key , jdbcType=VARCHAR},'%') or
description like CONCAT('%',#{key , jdbcType=VARCHAR},'%')
description like CONCAT('%',#{key , jdbcType=VARCHAR},'%'))
</if>
<if test="id != null">
and id like CONCAT('%',#{id , jdbcType=VARCHAR},'%')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public void webPageRecognizeWithQueryFilter() throws Exception {
QueryFilter queryFilter = new QueryFilter();
queryFilter.setElementID(2L);
queryFilter.setValue("alice");
queryRequest.setModelId(1L);
// queryRequest.setModelId(1L);
queryFilters.getFilters().add(queryFilter);
queryRequest.setQueryFilters(queryFilters);

Expand Down
22 changes: 21 additions & 1 deletion launchers/standalone/src/test/resources/db/schema-h2.sql
Original file line number Diff line number Diff line change
Expand Up @@ -529,4 +529,24 @@ CREATE TABLE IF NOT EXISTS `s2_view` (
query_config VARCHAR(3000),
`admin` varchar(3000) DEFAULT NULL,
`admin_org` varchar(3000) DEFAULT NULL
);
);

CREATE TABLE IF NOT EXISTS `s2_tag` (
`id` INT NOT NULL AUTO_INCREMENT,
`model_id` INT NOT NULL ,
`name` varchar(255) NOT NULL ,
`biz_name` varchar(255) NOT NULL ,
`description` varchar(500) DEFAULT NULL ,
`status` INT NOT NULL ,
`sensitive_level` INT NOT NULL ,
`type` varchar(50) NOT NULL , -- ATOMIC, DERIVED
`define_type` varchar(50) NOT NULL, -- FIELD, DIMENSION
`type_params` LONGVARCHAR DEFAULT NULL ,
`created_at` TIMESTAMP NOT NULL ,
`created_by` varchar(100) NOT NULL ,
`updated_at` TIMESTAMP DEFAULT NULL ,
`updated_by` varchar(100) DEFAULT NULL ,
`ext` LONGVARCHAR DEFAULT NULL ,
PRIMARY KEY (`id`)
);
COMMENT ON TABLE s2_tag IS 'tag information';
Loading