From 2f831d9b4e41b8b178767caba8236581093db63a Mon Sep 17 00:00:00 2001 From: PhiTer9426 <793916584@qq.com> Date: Thu, 5 May 2022 21:37:56 +0800 Subject: [PATCH] getPreviewMapResult --- backend/build.gradle | 5 +- backend/debugconf.json | 9 +- backend/deployconfig.json | 2 +- .../org/bdware/sc/registry/DBConnector.java | 35 +++++--- .../java/org/bdware/sc/registry/Hello.java | 4 +- .../org/bdware/sc/registry/RegistryDB.java | 16 +++- backend/yjs/metaDetail.yjs | 90 +++++++++++++------ 7 files changed, 114 insertions(+), 47 deletions(-) diff --git a/backend/build.gradle b/backend/build.gradle index 3e89505..3ab72f9 100644 --- a/backend/build.gradle +++ b/backend/build.gradle @@ -51,6 +51,9 @@ dependencies { tasks.withType(JavaCompile) { options.encoding = "UTF-8" } +tasks.withType(Javadoc) { + options.encoding = "UTF-8" +} //task copyLibs(type: Copy) { // from configurations.runtimeClasspath // into "./build/output/libs/" @@ -89,7 +92,7 @@ task copyAssets(type: Copy) { into "./build/output/assets/" } -def currVersion = "0.0.5" +def currVersion = "0.0.8" task copyJar(type: Copy, dependsOn: [":backend:copyLibs",":backend:jar"]) { from "./build/libs/$project.name-${project.version}.jar" into "./build/output/libs" diff --git a/backend/debugconf.json b/backend/debugconf.json index 6512dda..0e4dad5 100755 --- a/backend/debugconf.json +++ b/backend/debugconf.json @@ -1,8 +1,8 @@ { - "agentHttpAddr": "127.0.0.1:18000", - "privKey": "589d94ee5688358a1c5c18430dd9c75097ddddebf769f139da36a807911d20f8", - "pubKey": "04d1924329f72ced148f6f333fb985ccbaa31b1e3aacf10be5f43d4a4ff5ad88899a005e79e37fc06993e1d66ada8cf8b711cb36f59538bb7d3e39e70fa9360ddd", - "script": "./build/registry-0.0.5.ypk", + "agentHttpAddr": "127.0.0.1:18005", + "privKey":"3eadae5557a15593bba8e9af03cb085d4b3fcfec2b7ce26c226f0733145adfd0", + "pubKey":"045546b5f6f5caef3c975e5da97ce5413eabfa48d69c9c74e9a2b6eb5c80d5651decff98b81c2f8409bdce3b5271ab7042625f09e641d848edc70755f780417202", + "script": "./build/registry-0.0.8.ypk", "killContract": "Registry", "createParam": { "privateKey": "4616ff0e2a4f982364914f9be30b51c6bc6ccb6602114a9ee8792f2ccf67465b", @@ -10,6 +10,7 @@ "registerID": "DBTest.test.test/registry", "auditURI": "tcp://127.0.0.1:2051", "DBUrl": "jdbc:postgresql://iodlog.demo.internetapi.cn:5432/iodlog?useServerPrepStmts=true", + "adminName": "admin6", "username": "iodlog", "password": "iodlog1107" } diff --git a/backend/deployconfig.json b/backend/deployconfig.json index fbe965b..8a29b59 100644 --- a/backend/deployconfig.json +++ b/backend/deployconfig.json @@ -2,7 +2,7 @@ "host": "023.node.internetapi.cn", "privateKey": "e85ce2f4d8882ff343d32ce42adde91d09e29c321452dd4ef9f07ebe76d1c6a5", "publicKey": "04da01345770b7e09d4774bf6c0395399b18814aa0b7b158f64b634b8f3d628d9964af6523835225af11e467271f4969d67bf90b32eaa09f517c79b2d1f9b8a926", - "ypkPath": "./backend/build/registry-0.0.5.ypk", + "ypkPath": "./backend/build/registry-0.0.7.ypk", "killBeforeStart": "Registry", "createParam": { "privateKey": "4616ff0e2a4f982364914f9be30b51c6bc6ccb6602114a9ee8792f2ccf67465b", diff --git a/backend/src/main/java/org/bdware/sc/registry/DBConnector.java b/backend/src/main/java/org/bdware/sc/registry/DBConnector.java index 4ce5a8f..0479d21 100644 --- a/backend/src/main/java/org/bdware/sc/registry/DBConnector.java +++ b/backend/src/main/java/org/bdware/sc/registry/DBConnector.java @@ -5,10 +5,7 @@ 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.sql.*; import java.util.ArrayList; import java.util.List; import java.util.Map; @@ -62,7 +59,6 @@ public class DBConnector { } 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(); @@ -75,11 +71,6 @@ public class DBConnector { 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 @@ -102,4 +93,28 @@ public class DBConnector { connClose(jdbcConnection); } + public static String querySampleByMetaID(String doid) { + String ret = ""; + String sql = "SELECT sample FROM registry.meta_data WHERE doid = ?;"; + + // execute sql + PreparedStatement pstmt = null; + try { + connect(); + pstmt = jdbcConnection.prepareStatement(sql); + pstmt.setString(1, doid); + ResultSet rs = null; + rs = pstmt.executeQuery(); + if (rs.next()) { + ret = rs.getString("sample"); + } + pstmt.execute(); + } catch (SQLException e) { + LOGGER.error(e.getMessage()); + LOGGER.debug(ExceptionUtil.exceptionToString(e)); + } + pstmtClose(pstmt); + connClose(jdbcConnection); + return ret; + } } diff --git a/backend/src/main/java/org/bdware/sc/registry/Hello.java b/backend/src/main/java/org/bdware/sc/registry/Hello.java index 804db4c..01dc141 100755 --- a/backend/src/main/java/org/bdware/sc/registry/Hello.java +++ b/backend/src/main/java/org/bdware/sc/registry/Hello.java @@ -4,12 +4,14 @@ import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.bdware.sc.ContractProcess; import org.bdware.sc.boundry.JavaScriptEntry; +import org.bdware.sc.debugger.DebugMain; + public class Hello { private static final Logger LOGGER = LogManager.getLogger(Hello.class); public static void main(String[] args) { - LOGGER.info("abc"); + DebugMain.main(args); } public static String call() { diff --git a/backend/src/main/java/org/bdware/sc/registry/RegistryDB.java b/backend/src/main/java/org/bdware/sc/registry/RegistryDB.java index f0b644a..7ef350e 100644 --- a/backend/src/main/java/org/bdware/sc/registry/RegistryDB.java +++ b/backend/src/main/java/org/bdware/sc/registry/RegistryDB.java @@ -5,14 +5,17 @@ import com.google.gson.JsonObject; import org.bdware.sc.engine.JSONTool; import wrp.jdk.nashorn.api.scripting.ScriptObjectMirror; import java.sql.SQLException; +import org.bdware.sc.util.JsonUtil; import java.util.HashMap; import java.util.Map; +import static org.bdware.sc.engine.JSONTool.convertMirrorToJson; + public class RegistryDB { public static void init(ScriptObjectMirror arg, String requester) { try { - JsonObject jsonData = JSONTool.convertMirrorToJson(arg).getAsJsonObject(); + JsonObject jsonData = convertMirrorToJson(arg).getAsJsonObject(); DBConnector.url = jsonData.get("DBUrl").getAsString(); DBConnector.password = jsonData.get("password").getAsString(); DBConnector.userName = jsonData.get("username").getAsString(); @@ -29,5 +32,14 @@ public class RegistryDB { } } - + public static Object querySampleByMetaID(ScriptObjectMirror scriptMirrorObject) { + JsonObject jo = convertMirrorToJson(scriptMirrorObject).getAsJsonObject(); + JsonObject ret = new JsonObject(); + String sample = DBConnector.querySampleByMetaID(jo.get("localMetaID").getAsString()); + if(!sample.equals("")) { + ret = JsonUtil.parseStringAsJsonObject(sample); + } + System.out.println(sample); + return JSONTool.convertJsonElementToMirror(ret); + } } diff --git a/backend/yjs/metaDetail.yjs b/backend/yjs/metaDetail.yjs index 87e0589..ce143d4 100644 --- a/backend/yjs/metaDetail.yjs +++ b/backend/yjs/metaDetail.yjs @@ -53,27 +53,54 @@ module metaStandardDetail { "total":10, "data":ret, "code":0 }; } -//{如果是offset+count,就按顺序, +// 如果是offset+count,就按顺序, // controlType=过滤 // createStartDate createEndDate // updateStartDate updateEndDate -// 如果是keyword:... 就模糊搜索} +// 如果是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":[ + 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":"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":{ @@ -137,29 +164,36 @@ module metaStandardDetail { //{"localMetaID":"xxx","mapRule":{},"remoteMetaID":"xxx"} export function getPreviewMapResult(arg) { - return { - "code":0, data:{ - "localData":{ - "大小":"500KB", "姓名":"小东" - }, "remoteData":{ - "size":"500000Byte", "name":"*东" - } - } - }; + arg = convertArgToJson(arg); + arg.localDataSample = org.bdware.sc.registry.RegistryDB.querySampleByMetaID(arg); + return getMapResult(arg); + + // return { + // "code":0, + // "data":{ + // "localData": { + // "大小":"500KB", "姓名":"小东" + // }, + // "remoteData":{ + // "size":"500000Byte", "name":"*东" + // } + // } + // }; //TODO 返回映射格式有误 // return {"code":1,"....."} } - function convertArgToJson(arg) { - if (typeof(arg)=='string') return JSON.parse(arg); - return arg; - } + //{"localDataSample":{},"mapRule":{},"remoteMetaID":"xxx"} export function getMapResult(arg) { arg = convertArgToJson(arg); - var ret = { - }; + var ret = {}; ret.data = org.bdware.sc.registry.RuleExecutor.executeRule(arg); ret.code = org.bdware.sc.registry.RuleExecutor.getLastExecuteStatus(); return ret; } + + function convertArgToJson(arg) { + if (typeof(arg)=='string') return JSON.parse(arg); + return arg; + } }