diff --git a/private-backend/.gitignore b/private-backend/.gitignore index bcd3dc2..fac0b50 100644 --- a/private-backend/.gitignore +++ b/private-backend/.gitignore @@ -95,4 +95,5 @@ fabric.properties # Customized ignore files target +private-backend.iml private-server.iml diff --git a/private-backend/README.md b/private-backend/README.md index 4f8ed41..461679d 100644 --- a/private-backend/README.md +++ b/private-backend/README.md @@ -1,19 +1,19 @@ -# IRext private server +# IRext Private Backend Private server is a runtime that any user can deploy and access it with IRext restful web service call or SDK. ### Runtime environment - Java runtime 1.7 or above -- Mysql server 5.6 or above -- Redis service +- Mysql server 8.0 or above +- Redis server 4.0 or above - A Linux OS is preferred ### Deploy - Fetch or compile libirdecode_jni.so out of source code of irext/core. -- Run following command when you fetched or compiled the private-server.jar out of the private server Spring-Boot project. +- Run following command when you fetched or compiled the private-backend-.jar out of the private server Spring-Boot project. ```shell script -java -jar private-server.jar +java -jar private-backend-.jar ``` diff --git a/private-backend/package/private-server-1.5.0.jar b/private-backend/package/private-backend-1.5.0.jar similarity index 99% rename from private-backend/package/private-server-1.5.0.jar rename to private-backend/package/private-backend-1.5.0.jar index 1f1f618..741cfa5 100644 Binary files a/private-backend/package/private-server-1.5.0.jar and b/private-backend/package/private-backend-1.5.0.jar differ diff --git a/private-backend/pom.xml b/private-backend/pom.xml index 1b96d85..5fe115d 100644 --- a/private-backend/pom.xml +++ b/private-backend/pom.xml @@ -4,7 +4,7 @@ 4.0.0 net.irext.server - private-server + private-backend 1.5.0 jar diff --git a/private-backend/src/main/java/net/irext/server/businesslogic/IndexingLogic.java b/private-backend/src/main/java/net/irext/server/businesslogic/IndexingLogic.java index cda993e..09538a9 100644 --- a/private-backend/src/main/java/net/irext/server/businesslogic/IndexingLogic.java +++ b/private-backend/src/main/java/net/irext/server/businesslogic/IndexingLogic.java @@ -6,9 +6,11 @@ import net.irext.server.request.CreateRemoteReferenceRequest; import net.irext.server.utils.Constants; import net.irext.server.mapper.*; import net.irext.server.model.*; +import org.jetbrains.annotations.NotNull; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; +import java.io.IOException; import java.util.ArrayList; import java.util.List; @@ -199,7 +201,7 @@ public class IndexingLogic { remoteRef.setBrandName(brandName); remoteRef.setCityCode(remoteIndex.getCityCode()); remoteRef.setOperatorId(remoteIndex.getOperatorId()); - remoteRef.setRemoteCode(remoteIndex.getId().toString()); + remoteRef.setRemoteCode(""); remoteRef.setRemote(remoteIndex.getRemote()); remoteRef.setProtocol(remoteIndex.getProtocol()); remoteRef.setRemoteMap(remoteIndex.getRemoteMap()); @@ -220,11 +222,29 @@ public class IndexingLogic { .url(url) .post(body) .build(); - Response response = client.newCall(request).execute(); - return response.body().string(); + + client.newCall(request).enqueue(new Callback() { + + @Override + public void onFailure(Request request, IOException e) { + System.err.println("remoteRef request failed: " + e.getMessage()); + } + + @Override + public void onResponse(Response response) throws IOException { + try { + if (!response.isSuccessful()) { + throw new IOException("unexpected code from remoteRef response: " + response); + } + + } catch (Exception e) { + System.err.println("error processing remoteRef response: " + e.getMessage()); + } + } + }); } catch (Exception e) { e.printStackTrace(); } - return null; + return null; } } diff --git a/private-backend/src/main/java/net/irext/server/utils/Constants.java b/private-backend/src/main/java/net/irext/server/utils/Constants.java index 9b28c07..136602d 100644 --- a/private-backend/src/main/java/net/irext/server/utils/Constants.java +++ b/private-backend/src/main/java/net/irext/server/utils/Constants.java @@ -32,7 +32,7 @@ public class Constants { public static final int STATUS_INVALID = 0; public static final int STATUS_PARA_DATA = 15; - public static final String REMOTE_REF_URL = "http://192.168.75.128:8083/irext-server/remote_ref/create_remote_ref"; + public static final String REMOTE_REF_URL = "http://srv.irext.net/irext-server/remote_ref/create_remote_ref"; public enum CategoryID { AIR_CONDITIONER(1), diff --git a/private-console/routes/code_manage_routes.js b/private-console/routes/code_manage_routes.js index be8e8af..2fa0532 100644 --- a/private-console/routes/code_manage_routes.js +++ b/private-console/routes/code_manage_routes.js @@ -13,7 +13,6 @@ app.post('/irext/int/list_categories', intService.listCategories); app.post('/irext/int/list_brands', intService.listBrands); app.post('/irext/int/list_indexes', intService.listIndexes); app.post('/irext/int/list_ir_protocols', intService.listIRProtocols); -app.post('/irext/int/download_bin', intService.downloadIndex); app.post('/irext/int/list_unpublished_brands', intService.listUnpublishedBrands); app.post('/irext/int/list_unpublished_remote_indexes', intService.listUnpublishedRemoteIndexes); diff --git a/private-console/services/code_manage_service.js b/private-console/services/code_manage_service.js index 7e663b6..e22f33e 100644 --- a/private-console/services/code_manage_service.js +++ b/private-console/services/code_manage_service.js @@ -233,26 +233,6 @@ exports.searchRemoteIndexes = function (req, res) { }); }; -/* - * function : Download remote binary by post request - * parameter : remote index ID - * return : Redirect to binary download - */ -exports.downloadIndex = function (req, res) { - let remoteIndexID = req.body.index_id; - - internalLogic.downloadRemoteBinCachedWorkUnit(remoteIndexID, function (serveBinErr, filePath) { - if (errorCode.SUCCESS.code === serveBinErr.code) { - logger.info("download file located at " + filePath); - res.download(filePath, ""); - } else { - logger.info("download file failed"); - res.write(''); - res.end(); - } - }); -}; - /* * function : Download remote binary * parameter : remote index ID @@ -260,8 +240,10 @@ exports.downloadIndex = function (req, res) { */ exports.downloadRemoteIndex = function (req, res) { let remoteIndexID = req.query.remote_index_id; + let adminId = req.query.admin_id; + let token = req.query.token; - internalLogic.downloadRemoteBinCachedWorkUnit(remoteIndexID, function (serveBinErr, filePath) { + internalLogic.downloadRemoteBinCachedWorkUnit(adminId, token, remoteIndexID, function (serveBinErr, filePath) { if (errorCode.SUCCESS.code === serveBinErr.code) { logger.info("download file located at " + filePath); res.download(filePath, ""); diff --git a/private-console/web/code/index.html b/private-console/web/code/index.html index 5a21ffe..2ba4212 100644 --- a/private-console/web/code/index.html +++ b/private-console/web/code/index.html @@ -63,25 +63,25 @@
- - - - - - -
diff --git a/private-console/work_unit/code_manage_logic.js b/private-console/work_unit/code_manage_logic.js index 2e8e173..266136b 100644 --- a/private-console/work_unit/code_manage_logic.js +++ b/private-console/work_unit/code_manage_logic.js @@ -40,9 +40,10 @@ let adminAuth = new AdminAuth(REDIS_HOST, REDIS_PORT, null, REDIS_PASSWORD); // relative XML file path let PROTOCOL_PATH = "protocol"; -let contributeProtocolService = "/irext-server/contribute/contribute_protocol"; +let contributeProtocolService = "/irext-server/contribution/contribute_protocol"; let contributeBrandsService = "/irext-server/contribution/contribute_brands"; let contributeRemoteIndexesService = "/irext-server/contribution/contribute_remote_indexes"; +let createRemoteRefService = "/irext-server/remote_ref/create_remote_ref"; exports.listCategoriesWorkUnit = function (lang, from, count, callback) { let conditions = { @@ -331,7 +332,7 @@ exports.searchRemoteIndexesWorkUnit = function (lang, remoteMap, from, count, ca }); }; -exports.downloadRemoteBinCachedWorkUnit = function (remoteIndexID, callback) { +exports.downloadRemoteBinCachedWorkUnit = function (adminId, token, remoteIndexID, callback) { RemoteIndex.getRemoteIndexByID(remoteIndexID, function (getRemoteIndexErr, remoteIndex) { if (errorCode.SUCCESS.code === getRemoteIndexErr.code && null != remoteIndex) { let fileName = "irda_" + remoteIndex.protocol + "_" + remoteIndex.remote + ".bin"; @@ -342,6 +343,93 @@ exports.downloadRemoteBinCachedWorkUnit = function (remoteIndexID, callback) { fs.exists(localBinFileName, function (exists) { if (exists) { logger.info("file " + localBinFileName + " already exists, serve directly"); + // create remote reference of this remote index + let categoryId = 0; + let categoryName = ''; + let brandId = 0; + let brandName = ''; + let name = ''; + let remoteRef = null; + RemoteIndex.getRemoteIndexByID(remoteIndexID, function (getRemoteIndexErr, remoteIndex) { + if (errorCode.SUCCESS.code === getRemoteIndexErr.code) { + categoryId = remoteIndex.category_id; + brandId = remoteIndex.brand_id; + Category.getCategoryByID(categoryId, function (getCategoryErr, category) { + if (errorCode.SUCCESS.code === getCategoryErr.code) { + categoryName = category.name; + if (enums.CATEGORY_STB !== categoryId) { + Brand.getBrandByID(brandId, function (getBrandErr, brand) { + if (errorCode.SUCCESS.code === getBrandErr.code) { + brandName = brand.name; + name = brandName + categoryName; + remoteRef = { + "name": name, + "categoryId": categoryId, + "categoryName": categoryName, + "brandId": brandId, + "brandName": brandName, + "cityCode": "", + "operatorId": 0, + "remoteCode": "", + "subCate": remoteIndex.sub_cate, + "protocol": remoteIndex.protocol, + "remote": remoteIndex.remote, + "remoteMap": remoteIndex.remote_map, + } + let queryParams = new Map(); + let requestSender = + new RequestSender(EXTERNAL_SERVER_ADDRESS, + EXTERNAL_SERVER_PORT, + createRemoteRefService, + queryParams); + let createRemoteRefRequest = { + "id": adminId, + "token": token, + "remoteRef": remoteRef, + }; + requestSender.sendPostRequest(createRemoteRefRequest, + function (createRemoteRefErr, createRemoteRefResponse) { + logger.info(createRemoteRefErr); + }); + } + }); + } else { + name = categoryName + "-" + remoteIndex.city_code + "-" + remoteIndex.operator_id; + remoteRef = { + "name": name, + "categoryId": categoryId, + "categoryName": categoryName, + "brandId": 0, + "brandName": "", + "cityCode": remoteIndex.city_code, + "operatorId": remoteIndex.operator_id, + "remoteCode": "", + "subCate": remoteIndex.sub_cate, + "protocol": remoteIndex.protocol, + "remote": remoteIndex.remote, + "remoteMap": remoteIndex.remote_map, + } + let queryParams = new Map(); + let requestSender = + new RequestSender(EXTERNAL_SERVER_ADDRESS, + EXTERNAL_SERVER_PORT, + createRemoteRefService, + queryParams); + let createRemoteRefRequest = { + "id": adminId, + "token": token, + "remoteRef": remoteRef, + }; + requestSender.sendPostRequest(createRemoteRefRequest, + function (createRemoteRefErr, createRemoteRefResponse) { + logger.info(createRemoteRefErr); + }); + } + } + }); + } + }); + callback(error, localBinFileName); } else { logger.info("file " + localBinFileName + " does not exist"); @@ -848,7 +936,7 @@ exports.publishBrandsWorkUnit = function (adminID, callback) { function (contributeBrandsRequestErr, contributeBrandsResponse) { logger.info(contributeBrandsRequestErr); callback(errorCode.SUCCESS); - }); + }); callback(errorCode.SUCCESS); }); } else {