diff --git a/backend/.gitignore b/backend/.gitignore index 2643730..cb46321 100644 --- a/backend/.gitignore +++ b/backend/.gitignore @@ -1,5 +1,7 @@ /.DS_Store/ /build/ +/ContractDB/ +debugconf.json /cplibs/ cplibs # Compiled class file @@ -25,3 +27,4 @@ cplibs # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml hs_err_pid* +deployconfig.json \ No newline at end of file diff --git a/backend/build.gradle b/backend/build.gradle index 291af35..aaec739 100755 --- a/backend/build.gradle +++ b/backend/build.gradle @@ -1,11 +1,13 @@ buildscript { - repositories{ + repositories { mavenCentral() mavenLocal() } dependencies { classpath "org.bdware.bdcontract:simple-ypk-packer:0.3.0" classpath "org.bdware.bdcontract:ypk-deploy-tool:0.4.0" + classpath 'org.apache.logging.log4j:log4j-core:2.17.2' + classpath 'org.apache.logging.log4j:log4j-api:2.17.2' } } @@ -39,10 +41,8 @@ sourceSets { } dependencies { -// 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/libs/', include: '*.jar') testImplementation 'junit:junit:4.13.2' // api project(":datanet-search-engine-backend") implementation 'org.postgresql:postgresql:42.3.1' @@ -52,12 +52,15 @@ dependencies { // from configurations.runtimeClasspath // into "./build/output/libs/" //} - -task copyLibs(type: Copy ) { - from configurations.runtimeClasspath - exclude { - details-> details.file.getAbsolutePath().contains("cplibs") +def reltivePath = "./backend" +task grepCP(dependsOn: ["copyLibs"]) { + doLast { + org.bdware.datanet.YPKPacker.grepCPLibWithFilter("${reltivePath}/cplibs/libs", "${reltivePath}/build/output/libs", "${reltivePath}/grepcp.list") } +} + +task copyLibs(type: Copy) { + from configurations.runtimeClasspath into "./build/output/libs/" } @@ -74,37 +77,31 @@ task copyAssets(type: Copy) { from "../front" into "./build/output/assets/" } -task mergeJar(dependsOn: ["sourcesJar", "jar"]) { - doLast { - org.bdware.datanet.YPKPacker.mergeJar("./backend/build/libs/$project.name-${project.version}.jar", - "./backend/build/libs/$project.name-${project.version}-sources.jar", - "./backend/build/libs/$project.name-${project.version}-all.jar") - } -} -task copyJar(type: Copy, dependsOn: ["mergeJar", ":backend:copyLibs"]) { - from "./build/libs/$project.name-${project.version}-all.jar" - into "./build/output" - rename { String fileName -> "sc-example.jar" } +def currVersion = "0.0.4" +task copyJar(type: Copy, dependsOn: [":backend:copyLibs",":backend:jar"]) { + from "./build/libs/$project.name-${project.version}.jar" + into "./build/output/libs" + rename { String fileName -> "registry-${currVersion}.jar" } doFirst { println "copyJar start" } } -task buildZip(type: Zip, dependsOn: ["copyAssets", "copyJar", "copyYJS"]) { +task buildZip(type: Zip, dependsOn: ["copyAssets", "copyJar", "copyYJS", "grepCP"]) { from './build/output/' duplicatesStrategy = DuplicatesStrategy.INCLUDE archiveFileName = 'registry.zip' destinationDirectory = file('build/') } -def currVersion = "0.0.1" + task buildYPK(dependsOn: ["buildZip"]) { doLast { - org.bdware.datanet.YPKPacker.staticPack("./backend/build/registry.zip", "./backend/build/registry${currVersion}.ypk") + org.bdware.datanet.YPKPacker.staticPack("./backend/build/registry.zip", "./backend/build/registry-${currVersion}.ypk") } } -task deploy(dependsOn: ["buildYPK"]){ +task deploy(dependsOn: ["buildYPK"]) { doLast { org.bdware.ypkdeploy.HTTPTool.batchRun("./backend/deployconfig.json", true) } diff --git a/backend/debugconf.json b/backend/debugconf.json new file mode 100755 index 0000000..30417e7 --- /dev/null +++ b/backend/debugconf.json @@ -0,0 +1,16 @@ +{ + "agentHttpAddr": "127.0.0.1:18000", + "privKey": "589d94ee5688358a1c5c18430dd9c75097ddddebf769f139da36a807911d20f8", + "pubKey": "04d1924329f72ced148f6f333fb985ccbaa31b1e3aacf10be5f43d4a4ff5ad88899a005e79e37fc06993e1d66ada8cf8b711cb36f59538bb7d3e39e70fa9360ddd", + "script": "./build/registry-0.0.1.ypk", + "killContract": "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" + } + } \ No newline at end of file diff --git a/backend/grepcp.list b/backend/grepcp.list new file mode 100755 index 0000000..a481ccb --- /dev/null +++ b/backend/grepcp.list @@ -0,0 +1 @@ +yjs.jar \ 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 100755 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 old mode 100644 new mode 100755 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 --- 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 100755 index 0000000..f81dc55 --- /dev/null +++ b/backend/src/main/java/org/bdware/sc/registry/RegistryDB.java @@ -0,0 +1,32 @@ +package org.bdware.sc.registry; + +import com.google.gson.JsonObject; +import org.bdware.sc.engine.JSONTool; +import wrp.jdk.nashorn.api.scripting.ScriptObjectMirror; + +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.init(); + DBConnector.connect(); + + Map item = new HashMap<>(); + item.put("pubkey", requester); + item.put("type", "admin"); + item.put("username", jsonData.get("adminName").getAsString()); + 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/java/StartRegistry.java b/backend/src/test/java/StartRegistry.java new file mode 100644 index 0000000..4e373e9 --- /dev/null +++ b/backend/src/test/java/StartRegistry.java @@ -0,0 +1,7 @@ +import org.bdware.sc.debugger.DebugMain; + +public class StartRegistry { + public static void main(String[] args){ + DebugMain.main(args); + } +} 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 100755 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 100755 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 100755 index 0000000..28cb777 Binary files /dev/null and b/backend/yjs/assets/logo.png differ diff --git a/backend/yjs/main.yjs b/backend/yjs/main.yjs old mode 100644 new mode 100755 index d798434..baa2b27 --- 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 old mode 100644 new mode 100755 index b42373a..e2283ca --- 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 100755 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","姓名":"*明"}}} + } +}