From 398869c9a62429f0964a82d9eaf630df24776d55 Mon Sep 17 00:00:00 2001 From: PhiTer9426 <793916584@qq.com> Date: Mon, 2 May 2022 23:12:25 +0800 Subject: [PATCH] init --- .gitmodules | 4 + backend/build.gradle | 37 ++- backend/deployconfig.json | 17 ++ .../org/bdware/sc/registry/DBConnector.java | 105 +++++++ .../{contractexample => registry}/Hello.java | 2 +- .../org/bdware/sc/registry/RegistryDB.java | 33 +++ backend/src/main/resources/log4j2.properties | 15 - backend/src/test/resources/log4j2.properties | 15 - backend/yjs/Register.yjs | 17 ++ backend/yjs/User.yjs | 27 ++ backend/yjs/assets/logo.png | Bin 0 -> 316 bytes backend/yjs/main.yjs | 17 +- backend/yjs/manifest.json | 10 +- backend/yjs/metaDetail.yjs | 261 ++++++++++++++++++ 14 files changed, 507 insertions(+), 53 deletions(-) create mode 100644 .gitmodules create mode 100644 backend/deployconfig.json create mode 100644 backend/src/main/java/org/bdware/sc/registry/DBConnector.java rename backend/src/main/java/org/bdware/sc/{contractexample => registry}/Hello.java (94%) create mode 100644 backend/src/main/java/org/bdware/sc/registry/RegistryDB.java delete mode 100644 backend/src/main/resources/log4j2.properties delete mode 100644 backend/src/test/resources/log4j2.properties create mode 100644 backend/yjs/Register.yjs create mode 100644 backend/yjs/User.yjs create mode 100644 backend/yjs/assets/logo.png create mode 100644 backend/yjs/metaDetail.yjs diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..a2b5dbe --- /dev/null +++ b/.gitmodules @@ -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 diff --git a/backend/build.gradle b/backend/build.gradle index ac97704..291af35 100644 --- a/backend/build.gradle +++ b/backend/build.gradle @@ -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) + } +} \ No newline at end of file diff --git a/backend/deployconfig.json b/backend/deployconfig.json new file mode 100644 index 0000000..2664fd9 --- /dev/null +++ b/backend/deployconfig.json @@ -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 +} \ No newline at end of file diff --git a/backend/src/main/java/org/bdware/sc/registry/DBConnector.java b/backend/src/main/java/org/bdware/sc/registry/DBConnector.java new file mode 100644 index 0000000..4ce5a8f --- /dev/null +++ b/backend/src/main/java/org/bdware/sc/registry/DBConnector.java @@ -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 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> 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 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); + } + +} diff --git a/backend/src/main/java/org/bdware/sc/contractexample/Hello.java b/backend/src/main/java/org/bdware/sc/registry/Hello.java similarity index 94% rename from backend/src/main/java/org/bdware/sc/contractexample/Hello.java rename to backend/src/main/java/org/bdware/sc/registry/Hello.java index eca9a29..804db4c 100644 --- a/backend/src/main/java/org/bdware/sc/contractexample/Hello.java +++ b/backend/src/main/java/org/bdware/sc/registry/Hello.java @@ -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; diff --git a/backend/src/main/java/org/bdware/sc/registry/RegistryDB.java b/backend/src/main/java/org/bdware/sc/registry/RegistryDB.java new file mode 100644 index 0000000..7f071c2 --- /dev/null +++ b/backend/src/main/java/org/bdware/sc/registry/RegistryDB.java @@ -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 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(); + } + } + + +} diff --git a/backend/src/main/resources/log4j2.properties b/backend/src/main/resources/log4j2.properties deleted file mode 100644 index 124ba89..0000000 --- a/backend/src/main/resources/log4j2.properties +++ /dev/null @@ -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 \ No newline at end of file diff --git a/backend/src/test/resources/log4j2.properties b/backend/src/test/resources/log4j2.properties deleted file mode 100644 index 124ba89..0000000 --- a/backend/src/test/resources/log4j2.properties +++ /dev/null @@ -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 \ No newline at end of file diff --git a/backend/yjs/Register.yjs b/backend/yjs/Register.yjs new file mode 100644 index 0000000..677afb1 --- /dev/null +++ b/backend/yjs/Register.yjs @@ -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); + } +} \ No newline at end of file diff --git a/backend/yjs/User.yjs b/backend/yjs/User.yjs new file mode 100644 index 0000000..25a9e93 --- /dev/null +++ b/backend/yjs/User.yjs @@ -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}; + } + +} \ No newline at end of file diff --git a/backend/yjs/assets/logo.png b/backend/yjs/assets/logo.png new file mode 100644 index 0000000000000000000000000000000000000000..28cb777814ec9277572a4a22f2dc0f073699b227 GIT binary patch literal 316 zcmeAS@N?(olHy`uVBq!ia0vp^2_VeD1SE5RJ;-NZU}W}maSW-r_4dwL-a`gFY!}v@ zHR?I!({n&pg=I_4w#(^HZRkxU~p~tH9hJO7YCU0_k$rDPzzA} zlfzvxK1QHn92YDbcd5=jBLG%#mdPtG`sKGdhr`0ak^zDj{s*m*o%L=HH&|Ym$HWli z1da<;4u7YA_X=VK8^_J8>TP>bz8&nm7v2lDNe5)bD}tzBQ9)dYqLgQu&X%Q~loCICz>Yp?(S literal 0 HcmV?d00001 diff --git a/backend/yjs/main.yjs b/backend/yjs/main.yjs index d798434..baa2b27 100644 --- a/backend/yjs/main.yjs +++ b/backend/yjs/main.yjs @@ -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; - } } \ No newline at end of file diff --git a/backend/yjs/manifest.json b/backend/yjs/manifest.json index b42373a..e2283ca 100644 --- a/backend/yjs/manifest.json +++ b/backend/yjs/manifest.json @@ -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" } \ No newline at end of file diff --git a/backend/yjs/metaDetail.yjs b/backend/yjs/metaDetail.yjs new file mode 100644 index 0000000..3edd309 --- /dev/null +++ b/backend/yjs/metaDetail.yjs @@ -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","姓名":"*明"}}} + } +}