(improvement)(headless)(chat) Add views and adapt chat and headless (#700)

* (improvement)(headless)(chat) Add views and adapt chat and headless

---------

Co-authored-by: jolunoluo
This commit is contained in:
LXW
2024-01-30 20:43:53 +08:00
committed by GitHub
parent 31f8c1df35
commit 24b442baef
237 changed files with 3205 additions and 4479 deletions

View File

@@ -1,60 +0,0 @@
package com.tencent.supersonic.common.pojo;
import lombok.Data;
import org.apache.commons.lang3.StringUtils;
import org.springframework.util.CollectionUtils;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.LinkedHashSet;
import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;
@Data
public class ModelCluster {
private static final String split = "_";
private Set<Long> modelIds = new LinkedHashSet<>();
private Set<String> modelNames = new LinkedHashSet<>();
private String key;
private String name;
public static ModelCluster build(Set<Long> modelIds) {
ModelCluster modelCluster = new ModelCluster();
modelCluster.setModelIds(modelIds);
modelCluster.setKey(StringUtils.join(modelIds, split));
return modelCluster;
}
public static ModelCluster build(String key) {
ModelCluster modelCluster = new ModelCluster();
modelCluster.setModelIds(getModelIdFromKey(key));
modelCluster.setKey(key);
return modelCluster;
}
public void buildName(Map<Long, String> modelNameMap) {
modelNames = modelNameMap.entrySet().stream().filter(entry ->
modelIds.contains(entry.getKey())).map(Map.Entry::getValue)
.collect(Collectors.toSet());
name = String.join(split, modelNames);
}
public static Set<Long> getModelIdFromKey(String key) {
return Arrays.stream(key.split(split))
.map(Long::parseLong).collect(Collectors.toSet());
}
public Long getFirstModel() {
if (CollectionUtils.isEmpty(modelIds)) {
return -1L;
}
return new ArrayList<>(modelIds).get(0);
}
}

View File

@@ -14,7 +14,7 @@ public enum DictWordType {
VALUE("value"),
MODEL("model"),
VIEW("view"),
ENTITY("entity"),
@@ -48,7 +48,7 @@ public enum DictWordType {
//domain
String[] natures = nature.split(DictWordType.NATURE_SPILT);
if (natures.length == 2 && StringUtils.isNumeric(natures[1])) {
return MODEL;
return VIEW;
}
//dimension value
if (natures.length == 3 && StringUtils.isNumeric(natures[1]) && StringUtils.isNumeric(natures[2])) {

View File

@@ -0,0 +1,11 @@
package com.tencent.supersonic.common.pojo.enums;
public enum TimeMode {
/**
* date mode
* LAST - a certain time
* RECENT - a period time
*/
LAST, RECENT
}

View File

@@ -1,32 +1,13 @@
package com.tencent.supersonic.common.pojo.enums;
public enum TypeEnums {
DATASOURCE("datasource"),
METRIC("metric"),
DIMENSION("dimension"),
DOMAIN("domain"),
ENTITY("entity"),
UNKNOWN("unknown");
METRIC,
DIMENSION,
DOMAIN,
ENTITY,
VIEW,
MODEL,
UNKNOWN;
private String name;
TypeEnums(String name) {
this.name = name;
}
public String getName() {
return name;
}
public static TypeEnums of(String type) {
for (TypeEnums typeEnum : TypeEnums.values()) {
if (typeEnum.name.equalsIgnoreCase(type)) {
return typeEnum;
}
}
return TypeEnums.UNKNOWN;
}
}

View File

@@ -1,33 +1,15 @@
package com.tencent.supersonic.common.util;
import com.tencent.supersonic.common.pojo.Pair;
import org.apache.commons.codec.binary.Hex;
import javax.crypto.Mac;
import javax.crypto.spec.SecretKeySpec;
import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException;
import static java.lang.Thread.sleep;
import org.apache.commons.codec.digest.DigestUtils;
public class SignatureUtils {
private static final String ALGORITHM_HMAC_SHA256 = "HmacSHA256";
private static final long TIME_OUT = 60 * 1000 * 30;
public static String generateSignature(String appKey, String appSecret, long timestamp) {
try {
Mac sha256HMAC = Mac.getInstance(ALGORITHM_HMAC_SHA256);
SecretKeySpec secretKey = new SecretKeySpec(appSecret.getBytes(), ALGORITHM_HMAC_SHA256);
sha256HMAC.init(secretKey);
String data = appKey + timestamp;
byte[] hash = sha256HMAC.doFinal(data.getBytes());
return Hex.encodeHexString(hash);
} catch (NoSuchAlgorithmException | InvalidKeyException e) {
throw new RuntimeException("Error generating signature", e);
}
public static String generateSignature(String appSecret, long timestamp) {
String psw = timestamp + appSecret + timestamp;
return DigestUtils.sha1Hex(psw);
}
public static Pair<Boolean, String> isValidSignature(String appKey, String appSecret,
@@ -42,7 +24,7 @@ public class SignatureUtils {
return new Pair<>(false, "Timestamp is too old");
}
String generatedSignature = generateSignature(appKey, appSecret, timestamp);
String generatedSignature = generateSignature(appSecret, timestamp);
if (generatedSignature.equals(signatureToCheck)) {
return new Pair<>(true, "Signature is valid");
@@ -52,19 +34,15 @@ public class SignatureUtils {
}
public static void main(String[] args) throws InterruptedException {
// appkey为申请的接口id
String appKey = "1";
//生成的密钥
String appSecret = "8fb44f17-f37d-4510-bb29-59b0e0b266d0";
long timestamp = System.currentTimeMillis();
String appSecret = "38f2857c-d9ee-4c3a-bcc2-2cdb62fda5aa";
long timestamp = 1706504908126L;
System.out.println("timeStamp:" + timestamp);
//生成的签名
String serverSignature = generateSignature(appKey, appSecret, timestamp);
String serverSignature = generateSignature(appSecret, timestamp);
System.out.println("Server Signature: " + serverSignature);
sleep(4000);
//用户需要的入参
Pair<Boolean, String> isValid = isValidSignature(appKey, appSecret, timestamp, serverSignature);
Pair<Boolean, String> isValid = isValidSignature("1", appSecret, timestamp, serverSignature);
System.out.println("Is Signature Valid? " + isValid.first);
}