This commit is contained in:
PhiTer9426 2022-05-02 23:12:25 +08:00
parent a536e8e11f
commit 398869c9a6
14 changed files with 507 additions and 53 deletions

4
.gitmodules vendored Normal file
View File

@ -0,0 +1,4 @@
[submodule "datanet-search-engine-backend"]
path = datanet-search-engine-backend
url = https://gitee.com/BDWare/datanet-search-engine-backend.git
branch = master

View File

@ -1,6 +1,11 @@
buildscript {
repositories{
mavenCentral()
mavenLocal()
}
dependencies {
classpath files("buildlibs/simpleypkpacker.jar")
classpath "org.bdware.bdcontract:simple-ypk-packer:0.3.0"
classpath "org.bdware.bdcontract:ypk-deploy-tool:0.4.0"
}
}
@ -34,15 +39,25 @@ sourceSets {
}
dependencies {
api 'org.apache.logging.log4j:log4j-core:2.14.1'
api 'org.apache.logging.log4j:log4j-api:2.14.1'
// api 'org.apache.logging.log4j:log4j-core:2.14.1'
// api 'org.apache.logging.log4j:log4j-api:2.14.1'
implementation fileTree(dir: 'cplibs', include: '*.jar')
implementation fileTree(dir: 'cplibs/lib/', include: '*.jar')
// implementation fileTree(dir: 'cplibs/lib/', include: '*.jar')
testImplementation 'junit:junit:4.13.2'
// api project(":datanet-search-engine-backend")
implementation 'org.postgresql:postgresql:42.3.1'
}
task copyLibs(type: Copy) {
//task copyLibs(type: Copy) {
// from configurations.runtimeClasspath
// into "./build/output/libs/"
//}
task copyLibs(type: Copy ) {
from configurations.runtimeClasspath
exclude {
details-> details.file.getAbsolutePath().contains("cplibs")
}
into "./build/output/libs/"
}
@ -79,12 +94,18 @@ task copyJar(type: Copy, dependsOn: ["mergeJar", ":backend:copyLibs"]) {
task buildZip(type: Zip, dependsOn: ["copyAssets", "copyJar", "copyYJS"]) {
from './build/output/'
duplicatesStrategy = DuplicatesStrategy.INCLUDE
archiveFileName = 'contractexample.zip'
archiveFileName = 'registry.zip'
destinationDirectory = file('build/')
}
def currVersion = "0.0.1"
task buildYPK(dependsOn: ["buildZip"]) {
doLast {
org.bdware.datanet.YPKPacker.staticPack("./backend/build/contractexample.zip", "./backend/build/contractexample.ypk")
org.bdware.datanet.YPKPacker.staticPack("./backend/build/registry.zip", "./backend/build/registry${currVersion}.ypk")
}
}
task deploy(dependsOn: ["buildYPK"]){
doLast {
org.bdware.ypkdeploy.HTTPTool.batchRun("./backend/deployconfig.json", true)
}
}

17
backend/deployconfig.json Normal file
View File

@ -0,0 +1,17 @@
{
"host": "023.node.internetapi.cn",
"privateKey": "e85ce2f4d8882ff343d32ce42adde91d09e29c321452dd4ef9f07ebe76d1c6a5",
"publicKey": "04da01345770b7e09d4774bf6c0395399b18814aa0b7b158f64b634b8f3d628d9964af6523835225af11e467271f4969d67bf90b32eaa09f517c79b2d1f9b8a926",
"ypkPath": "./backend/build/registry0.0.1.ypk",
"killBeforeStart": "Registry",
"createParam": {
"privateKey": "4616ff0e2a4f982364914f9be30b51c6bc6ccb6602114a9ee8792f2ccf67465b",
"publicKey": "04f9b9b8f324908464f78a6235e2dd93e4dfdaf045e9b1b5cfd57374516cc61a79a86fc2b42d3321a5b49a0f25381a7bed61901b40b729f72354e716673d551e98",
"registerID": "DBTest.test.test/registry",
"auditURI": "tcp://127.0.0.1:2051",
"DBUrl": "jdbc:postgresql://iodlog.demo.internetapi.cn:5432/iodlog?useServerPrepStmts=true",
"username": "iodlog",
"password": "iodlog1107"
},
"agentPort": 21130
}

View File

@ -0,0 +1,105 @@
package org.bdware.sc.registry;
import com.google.gson.JsonObject;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.bdware.sc.util.ExceptionUtil;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
public class DBConnector {
private static final Logger LOGGER = LogManager.getLogger(DBConnector.class);
public static Connection jdbcConnection;
public static String url;
public static String userName;
public static String password;
public static void init() throws SQLException {
try {
JsonObject ret = new JsonObject();
ret.addProperty("success", "yes");
System.out.println(ret.get("success"));
Class.forName("org.postgresql.Driver");
connClose(jdbcConnection);
} catch (Exception e) {
LOGGER.error(e.getMessage());
LOGGER.debug(ExceptionUtil.exceptionToString(e));
}
jdbcConnection = DriverManager.getConnection(url, userName, password);
}
public static void connect() throws SQLException {
if (url == null) init();
if (jdbcConnection == null || jdbcConnection.isClosed())
jdbcConnection = DriverManager.getConnection(url, userName, password);
}
private static void connClose(Connection conn) {
if (conn == null) return;
try {
if (conn != null && !conn.isClosed()) conn.close();
} catch (Exception e) {
LOGGER.error(e.getMessage());
LOGGER.debug(ExceptionUtil.exceptionToString(e));
}
}
private static void pstmtClose(PreparedStatement pstmt) {
if (pstmt == null) return;
try {
if (pstmt != null && !pstmt.isClosed()) pstmt.close();
} catch (Exception e) {
LOGGER.error(e.getMessage());
LOGGER.debug(ExceptionUtil.exceptionToString(e));
}
}
public static void insert(String schema, String table, Map<String, Object> items) {
// if (!items.containsKey("time") || items.get("time").equals("0")) return; // If time is null, do nothing.
// prepare columns and values needed in sql
StringBuilder columns = new StringBuilder();
StringBuilder values = new StringBuilder();
List<Map.Entry<String, Object>> list = new ArrayList<>(items.entrySet());
list.forEach(item -> {
columns.append("\"").append(item.getKey()).append("\",");
values.append("?,");
});
columns.deleteCharAt(columns.lastIndexOf(","));
values.deleteCharAt(values.lastIndexOf(","));
// generate sql
// example:
// INSERT INTO "public"."doip_request" ("op","server_doid","status_code","client_doid","do_prefix",
// "response_hash","server_pubkey","do_data_id","do_repo","request_hash","client_pubkey","server_ip",
// "client_ip","time","record_hash") VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)
String sql = "INSERT INTO \"" + schema + "\".\"" + table + "\" (" + columns + ") VALUES (" + values + ")";
// execute sql
PreparedStatement pstmt = null;
try {
connect();
pstmt = jdbcConnection.prepareStatement(sql);
int i = 1;
for (Map.Entry<String, Object> item : list) {
pstmt.setObject(i, item.getValue());
i++;
}
System.out.println(pstmt);
pstmt.executeUpdate();
} catch (SQLException e) {
LOGGER.error(e.getMessage());
LOGGER.debug(ExceptionUtil.exceptionToString(e));
}
pstmtClose(pstmt);
connClose(jdbcConnection);
}
}

View File

@ -1,4 +1,4 @@
package org.bdware.sc.contractexample;
package org.bdware.sc.registry;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

View File

@ -0,0 +1,33 @@
package org.bdware.sc.registry;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import org.bdware.sc.engine.JSONTool;
import wrp.jdk.nashorn.api.scripting.ScriptObjectMirror;
import java.sql.SQLException;
import java.util.HashMap;
import java.util.Map;
public class RegistryDB {
public static void init(ScriptObjectMirror arg, String requester) {
try {
JsonObject jsonData = JSONTool.convertMirrorToJson(arg).getAsJsonObject();
DBConnector.url = jsonData.get("DBUrl").getAsString();
DBConnector.password = jsonData.get("password").getAsString();
DBConnector.userName = jsonData.get("username").getAsString();
DBConnector.connect();
Map<String, Object> item = new HashMap<>();
item.put("pubkey", requester);
item.put("type", "admin");
item.put("username", "admin");
DBConnector.insert("registry", "user", item);
} catch (Exception e) {
e.printStackTrace();
}
}
}

View File

@ -1,15 +0,0 @@
filter.threshold.type=ThresholdFilter
filter.threshold.level=debug
appender.console.type=Console
appender.console.name=STDOUT
appender.console.layout.type=PatternLayout
appender.console.layout.pattern=%highlight{[%-5p] %d{HH:mm:ss.SSS} %m (%F:%L)[%M]%n}{FATAL=Bright Red,ERROR=Red,WARN=Yellow,INFO=Green,DEBUG=Blue,TRACE=White}
appender.rolling.type=File
appender.rolling.name=log
appender.rolling.append=true
appender.rolling.fileName=./log/gateway.log
appender.rolling.layout.type=PatternLayout
appender.rolling.layout.pattern=%d-%m%n
rootLogger.level=info
rootLogger.appenderRef.stdout.ref=STDOUT
rootLogger.appenderRef.log.ref=log

View File

@ -1,15 +0,0 @@
filter.threshold.type=ThresholdFilter
filter.threshold.level=debug
appender.console.type=Console
appender.console.name=STDOUT
appender.console.layout.type=PatternLayout
appender.console.layout.pattern=%highlight{[%-5p] %d{HH:mm:ss.SSS} %m (%F:%L)[%M]%n}{FATAL=Bright Red,ERROR=Red,WARN=Yellow,INFO=Green,DEBUG=Blue,TRACE=White}
appender.rolling.type=File
appender.rolling.name=log
appender.rolling.append=true
appender.rolling.fileName=./log/gateway.log
appender.rolling.layout.type=PatternLayout
appender.rolling.layout.pattern=%d-%m%n
rootLogger.level=info
rootLogger.appenderRef.stdout.ref=STDOUT
rootLogger.appenderRef.log.ref=log

17
backend/yjs/Register.yjs Normal file
View File

@ -0,0 +1,17 @@
import "User.yjs";
import "metaDetail.yjs";
oracle Register{
@ArgSchema({"!doId":"string","offset":"number","count":"number"})
export function retrieve(){
//executeContract去拿到Repo的原始结果
//根据request进行判断找到对应的rule
//将原始结果与rule做一个映射得到转换后的结果
//返回转换后的结果。
return Transform.trans(abc);
}
function onCreate(arg){
Global.registerID = arg.registerID;
org.bdware.sc.registry.RegistryDB.init(arg, requester);
}
}

27
backend/yjs/User.yjs Normal file
View File

@ -0,0 +1,27 @@
module User{
export function getRole(){
//{"role":"anymo...","code":0}
return {"role":"admin","code": 0};
}
export function getUserInfo(arg){
return {"pubkey":"xxx","name":"xx","phone":"xxx","descripstion":"","permission":"admin,user,"};
}
//{"pubkey":"xxx","name":"xx","phone":"xxx","description":"","permission":"admin,user,"}
export function updateUserInfo(arg){
return {"code":1};
}
export function addUserInfo(arg){
return {"code":1};
}
//...
export function getUserList(arg){
var ret = [];
ret.push(
{"pubkey":"xxx","name":"xx","phone":"xxx","description":"xxxxxxx","permission":"admin,user"},
{"pubkey":"xxx","name":"xx","phone":"xxx","description":"xxxxxxx","permission":"admin"},
{"pubkey":"xxx","name":"xx","phone":"xxx","description":"xxxxxxx","permission":"user"}
);
return {"total":10,"data":ret,"code":0};
}
}

BIN
backend/yjs/assets/logo.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 316 B

View File

@ -1,12 +1,11 @@
oracle ContractExample {
function onCreate(){
Global.owner = requester;
function onCreate() {
Global.owner = requester;
}
export function callHello(arg) {
return Hello.call()+requester;
}
export function getOwner() {
return Global.owner;
}
export function callHello(arg){
return Hello.call()+requester;
}
export function getOwner(){
return Global.owner;
}
}

View File

@ -1,9 +1,9 @@
{
"main": "main.yjs",
"memory": "kill,init",
"doi": "Contract_1172400934",
"main": "Register.yjs",
"doi": "Contract_-1259280471",
"insnLimit": 0,
"buildTime": 1635385270646,
"buildTime": 1651497662646,
"builder": "ContractEngine",
"startAtUnpack": true
"startAtUnpack": false,
"sourcePath": "public/Register"
}

261
backend/yjs/metaDetail.yjs Normal file
View File

@ -0,0 +1,261 @@
module metaStandardDetail{
export function getRegistryInfo(arg){
return {"code":0,"registryID":"macjw.ab","description":"这是xx市的注册表添加更多Registry描述"};
}
export function verifyRule(arg){
return {"code":0,"msg":"success"}
}
export function getFieldTypeList(arg){
return {"code":0, "data":[
{
"typeName":"string",
"lable":"字符串",
"formDesc":{
"固定值":{
"type":"input"
},
"默认值":{
"type":"input"
},
"最小长度":{
"type":"input"
},
"最大长度":{
"type":"input"
},
"必备项":{
"type":"select",
"options":["是","否"]
},
}
},
{
"typeName":"boolean",
"lable":"真假",
"formDesc":{
"固定值":{
"type":"input"
},
"默认值":{
"type":"input"
},
"必备项":{
"type":"select",
"options":["是","否"]
},
}
},
]};
}
export function listRemoteRegistry(){
var ret = [
{"registryID":"macjw","name":"jw市市级注册"},
{"registryID":"macjw.de.cd","name":"jw市de县cd镇注册表"}
];
return {
"total":10,"data":ret,"code":0};
}
//{如果是offset+count就按顺序
// controlType=过滤
// createStartDate createEndDate
// updateStartDate updateEndDate
// 如果是keyword:... 就模糊搜索}
// registryID
//{"createStartDate":16111,"createEndDate":12222,"offset":0,"count":5}
export function listMetaStandard(arg){
var ret =[];
ret.push({
"name":"CO传感数据",
"createDate":167227222,
"updateDate":1111111,
"creator":"xxx",
"updater":"aabbcc",
"registryID":"macjw.ab",
"controlType":"private",
"typeList":["public","private"],
"status":"off",
"version":"2.1",
"doId":"ab.ccd/aaaaa-aaa",
"desc":"元数据标准说明",
"fields":[
{
"name":"owner",
"type":"string",
"description":"简要的说明",
"constraint":{
"固定值":"xxxxx",
"最大长度":50,
"必备项":"是",
}
},
{
"name":"pubkey",
"type":"string",
"description":"pubkey简要的说明2",
"constraint":{
"固定值":"jjjjjjj",
"最大长度":50
}
}
]
},
{
"name":"BF传感数据",
"createDate":167226222,
"updateDate":1111311,
"creator":"xxx",
"updater":"aabbcc",
"registryID":"macjw",
"controlType":"public",
"typeList":["public","private"],
"status":"on",
"version":"2.1",
"doId":"ab.ccd/aabbbaa-aaa",
"desc":"元数据标准说明",
"fields":[
{
"name":"repository",
"type":"string",
"description":"简要的说明",
"constraint":{
"固定值":"xxx",
"最大长度":50,
"必备项":"是",
}
},
{
"name":"format",
"type":"boolean",
"description":"简要的说明2",
"constraint":{
"必备项":"否"
}
},
{
"name":"registertime",
"type":"string",
"description":"registertime简要的说明333333333",
"constraint":{
"固定值":"ooooo",
"默认值":"hhhhhhhh",
"最小长度":10,
"必备项":"否",
}
},
]
},
{
"name":"AA传感数据",
"createDate":167227222,
"updateDate":1111111,
"creator":"xxx",
"updater":"aabbcc",
"registryID":"macjw.ab",
"controlType":"private",
"typeList":["public","private"],
"status":"off",
"version":"2.1",
"doId":"ab.ccd/adddda-aaa",
"desc":"元数据标准说明",
"fields":[
{
"name":"owner",
"type":"string",
"description":"简要的说明",
"constraint":{
"固定值":"xxxxx",
"最大长度":50,
"必备项":"是",
}
},
{
"name":"pubkey",
"type":"string",
"description":"pubkey简要的说明2",
"constraint":{
"固定值":"jjjjjjj",
"最大长度":50
}
}
]
},
{
"name":"HHH传感数据",
"createDate":167227222,
"updateDate":1111111,
"creator":"xxx",
"updater":"aabbcc",
"registryID":"macjw.ac",
"controlType":"private",
"typeList":["public","private"],
"status":"on",
"version":"2.1",
"doId":"ab.ccd/aggga-aaa",
"desc":"元数据标准说明",
"fields":[
{
"name":"owner",
"type":"string",
"description":"简要的说明",
"constraint":{
"固定值":"xxxxx",
"最大长度":50,
"必备项":"是",
}
},
{
"name":"pubkey",
"type":"string",
"description":"pubkey简要的说明2",
"constraint":{
"固定值":"jjjjjjj",
"最大长度":50
}
}
]
}
);
return {
"total":10,"data":ret,"code":0};
}
export function updateMetaStandardDetail(arg){
var ret =[];
//通知对应的远程注册表,需要更新这个关系。
return {
"total":10,"data":ret,"code":0};
}
//{"offset":..,"count":,"localMetaStandardDoid":}
export function listMetaStandardRelaction(arg){
var ret = [];
ret.push({
"name":"煤矿传感数据映射",
"localMetaStandardDoid":"xx.xx/adfa",
"remoteMetaStandardDoid":"ab.ccd/aaaaa-aaa",
"createDate":167227222,
"updateDate":1111111,
"creator":"aabbcc",
"updater":"aabbcc",
"mapRule":{
"owner":"${val.大小}",
"pubkey":"function(val){}",
}
});
return {
"total":10,"data":ret,"code":0};
}
//{"localMetaID":"xxx","mapRule":{},"remoteMetaID":"xxx"}
export function getPreviewMapResult(arg){
return {"code":0, data:{"localData":{"大小":"500KB","姓名":"小东"},"remoteData":{"size":"500000Byte","name":"*东"}}};
//TODO 返回映射格式有误
// return {"code":1,"....."}
}
//{"localDataSample":{},"mapRule":{},"remoteMetaID":"xxx"}
export function getMapResult(){
return {"code":0, data: {"remoteData":{"size":"500000Byte","姓名":"*明"}}}
}
}