Skip to content

Commit

Permalink
Merge pull request #152 from yg3630536/feature/qr-code-down-model
Browse files Browse the repository at this point in the history
support resources id mode for QrCodeTrransportation
  • Loading branch information
junqizhang-dev committed Mar 31, 2020
2 parents 0d38bbd + 5b9d414 commit 90a9601
Show file tree
Hide file tree
Showing 38 changed files with 1,949 additions and 991 deletions.
1,160 changes: 894 additions & 266 deletions docs/zh_CN/docs/weidentity-java-sdk-doc.rst

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@ public final class DataDriverConstant {
* jdbc url properties.
*/
public static final String JDBC_URL = "jdbc.url";

/**
* jdbc driver properties.
*/
public static final String JDBC_DRIVER = "jdbc.driver";

/**
* jdbc username properties.
Expand Down Expand Up @@ -159,6 +164,7 @@ public final class DataDriverConstant {
/**
* the default value for pool.
*/
public static final String POOL_DRIVER_NAME_DEFAULT_VALUE = "com.mysql.jdbc.Driver";
public static final String POOL_MAX_ACTIVE_DEFAULT_VALUE = "50";
public static final String POOL_MIN_IDLE_DEFAULT_VALUE = "5";
public static final String POOL_MAX_IDLE_DEFAULT_VALUE = "5";
Expand Down
7 changes: 6 additions & 1 deletion src/main/java/com/webank/weid/constant/ErrorCode.java
Original file line number Diff line number Diff line change
Expand Up @@ -479,7 +479,7 @@ public enum ErrorCode {
*/
TRANSPORTATION_PROTOCOL_FIELD_INVALID(
100806,
"the protocol field values cannot be included '|'."
"the protocol field value invalid."
),

/**
Expand Down Expand Up @@ -512,6 +512,11 @@ public enum ErrorCode {
*/
TRANSPORTATION_NO_SPECIFYER_TO_SET(100812, "no spcifyer to set."),

/**
* the trans mode is invalid.
*/
TRANSPORTATION_TRANSMODE_TYPE_INVALID(100813, "the trans mode is invalid."),

/**
* Authority issuer main error code.
*/
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/com/webank/weid/constant/ServiceType.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,6 @@
package com.webank.weid.constant;

public enum ServiceType {
SYS_GET_BARCODE_DATA
//获取Transportation数据
SYS_GET_TRANS_DATA
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import lombok.Setter;
import lombok.ToString;

import com.webank.weid.constant.ServiceType;
import com.webank.weid.protocol.amop.base.AmopBaseMsgArgs;

/**
Expand All @@ -36,13 +37,18 @@
@Getter
@Setter
@ToString
public class GetBarCodeDataArgs extends AmopBaseMsgArgs {
public class GetTransDataArgs extends AmopBaseMsgArgs {

/**
* the resource Id.
*/
private String resourceId;

/**
* 数据类型.
*/
private String className;

/**
* weId信息.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
import com.webank.weid.protocol.response.ResponseData;
import com.webank.weid.rpc.callback.AmopCallback;
import com.webank.weid.service.impl.base.AmopCommonArgs;
import com.webank.weid.service.impl.inner.DownBarCodeDataService;
import com.webank.weid.service.impl.inner.DownTransDataService;
import com.webank.weid.suite.auth.impl.WeIdAuthImpl;
import com.webank.weid.suite.auth.inf.WeIdAuth;
import com.webank.weid.suite.auth.protocol.WeIdAuthObj;
Expand Down Expand Up @@ -64,7 +64,7 @@ private WeIdAuth getweIdAuthService() {
}

private static void initDefaultService() {
register(ServiceType.SYS_GET_BARCODE_DATA.name(), new DownBarCodeDataService());
register(ServiceType.SYS_GET_TRANS_DATA.name(), new DownTransDataService());
}

private static void register(String serviceType, TransmissionService<?> service) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
import com.webank.weid.constant.ErrorCode;
import com.webank.weid.constant.ParamKeyConstant;
import com.webank.weid.exception.DataTypeCastException;
import com.webank.weid.protocol.amop.GetBarCodeDataArgs;
import com.webank.weid.protocol.amop.GetTransDataArgs;
import com.webank.weid.protocol.base.WeIdDocument;
import com.webank.weid.protocol.response.GetEncryptKeyResponse;
import com.webank.weid.protocol.response.ResponseData;
Expand All @@ -43,19 +43,19 @@
import com.webank.weid.suite.api.transportation.params.EncodeType;
import com.webank.weid.suite.crypto.CryptServiceFactory;
import com.webank.weid.suite.entity.CryptType;
import com.webank.weid.suite.entity.TransCodeBaseData;
import com.webank.weid.suite.persistence.sql.driver.MysqlDriver;
import com.webank.weid.suite.transmission.TransmissionService;
import com.webank.weid.suite.transportation.bar.protocol.BarCodeData;
import com.webank.weid.util.DataToolUtils;

/**
* 根据资源获取barCodeData回调处理.
* @author yanggang
*
*/
public class DownBarCodeDataService implements TransmissionService<String> {
public class DownTransDataService implements TransmissionService<String> {

private static final Logger logger = LoggerFactory.getLogger(DownBarCodeDataService.class);
private static final Logger logger = LoggerFactory.getLogger(DownTransDataService.class);

private Persistence dataDriver;

Expand All @@ -78,7 +78,7 @@ private Persistence getDataDriver() {
@Override
public ResponseData<String> service(String message) {
try {
GetBarCodeDataArgs arg = DataToolUtils.deserialize(message, GetBarCodeDataArgs.class);
GetTransDataArgs arg = DataToolUtils.deserialize(message, GetTransDataArgs.class);
return getBarCodeData(arg);
} catch (Exception e) {
logger.error("[onPush] get barCodeData has error.", e);
Expand All @@ -89,7 +89,9 @@ public ResponseData<String> service(String message) {
}
}

private ResponseData<String> getBarCodeData(GetBarCodeDataArgs arg) {
private ResponseData<String> getBarCodeData(
GetTransDataArgs arg
) throws ClassNotFoundException {
logger.info("[getBarCodeData] begin query data param:{}", arg);
ResponseData<String> barCodeRes = new ResponseData<String>();
barCodeRes.setResult(StringUtils.EMPTY);
Expand All @@ -112,11 +114,11 @@ private ResponseData<String> getBarCodeData(GetBarCodeDataArgs arg) {
return barCodeRes;
}
// 解析数据
BarCodeData barCodeData = DataToolUtils.deserialize(
responseData.getResult(), BarCodeData.class);
TransCodeBaseData codeData = (TransCodeBaseData)DataToolUtils.deserialize(
responseData.getResult(), Class.forName(arg.getClassName())
);
//得到数据编解码类型(原文&密文)
EncodeType encodeType =
EncodeType.getObject(String.valueOf(barCodeData.getEncodeType()));
EncodeType encodeType = EncodeType.getEncodeType(codeData.getEncodeType());
logger.info("[getBarCodeData] the encode is {}", encodeType.name());
if (encodeType == EncodeType.ORIGINAL) {
// 原文类型
Expand All @@ -134,12 +136,12 @@ private ResponseData<String> getBarCodeData(GetBarCodeDataArgs arg) {
return barCodeRes;
}
logger.info("[getBarCodeData] begin decrypt the data");
String data = String.valueOf(barCodeData.getData());
String data = String.valueOf(codeData.getData());
String value = CryptServiceFactory
.getCryptService(CryptType.AES)
.decrypt(data, encryptKey.getEncryptKey());
barCodeData.setData(value);
barCodeRes.setResult(DataToolUtils.serialize(barCodeData));
codeData.setData(value);
barCodeRes.setResult(DataToolUtils.serialize(codeData));
barCodeRes.setErrorCode(ErrorCode.SUCCESS);
logger.info("[getBarCodeData] query data successfully.");
return barCodeRes;
Expand All @@ -156,7 +158,7 @@ private ResponseData<String> getBarCodeData(GetBarCodeDataArgs arg) {
* @param arg 请求参数
* @return 返回密钥对象
*/
private GetEncryptKeyResponse getEncryptKey(GetBarCodeDataArgs arg) {
private GetEncryptKeyResponse getEncryptKey(GetTransDataArgs arg) {
logger.info("[getEncryptKey] begin query encrypt key param:{}", arg);
GetEncryptKeyResponse encryptResponse = new GetEncryptKeyResponse();
ResponseData<String> keyResponse = this.getDataDriver().get(
Expand Down Expand Up @@ -208,7 +210,7 @@ private GetEncryptKeyResponse getEncryptKey(GetBarCodeDataArgs arg) {
* @param keyMap 查询出来的key数据
* @return
*/
private boolean checkAuthority(GetBarCodeDataArgs arg, Map<String, Object> keyMap) {
private boolean checkAuthority(GetTransDataArgs arg, Map<String, Object> keyMap) {
if (keyMap == null) {
logger.error("[checkAuthority] illegal input.");
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
import com.webank.weid.suite.transportation.bar.impl.BarCodeTransportationImpl;
import com.webank.weid.suite.transportation.json.impl.JsonTransportationImpl;
import com.webank.weid.suite.transportation.pdf.impl.PdfTransportationImpl;
import com.webank.weid.suite.transportation.qr.impl.QrCodeJsonTransportationImpl;
import com.webank.weid.suite.transportation.qr.impl.QrCodeTransportationImpl;

/**
* Created by Junqi Zhang on 2019/5/13.
Expand All @@ -46,7 +46,7 @@ public static JsonTransportation newJsonTransportation() {
}

public static QrCodeTransportation newQrCodeTransportation() {
return new QrCodeJsonTransportationImpl();
return new QrCodeTransportationImpl();
}

public static PdfTransportation newPdfTransportation() {
Expand All @@ -66,7 +66,7 @@ public static Transportation build(TransportationType transportationType) {
case BAR_CODE:
return new BarCodeTransportationImpl();
case QR_CODE:
return new QrCodeJsonTransportationImpl();
return new QrCodeTransportationImpl();
default:
logger.error("the type = {} unsupported.", transportationType.name());
throw new WeIdBaseException(ErrorCode.THIS_IS_UNSUPPORTED);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@

package com.webank.weid.suite.api.transportation.params;

import com.webank.weid.constant.ErrorCode;
import com.webank.weid.exception.WeIdBaseException;

/**
* enumeration of supported coding types.
*
Expand Down Expand Up @@ -50,22 +53,18 @@ public enum EncodeType {
public int getCode() {
return code;
}

public String toString() {
return String.valueOf(this.code);
}

/**
* get EncodeType by code.
* @param value code value
* @return codeType
* @param code code value
* @return EncodeType
*/
public static EncodeType getObject(String value) {
public static EncodeType getEncodeType(int code) {
for (EncodeType codeType : EncodeType.values()) {
if (String.valueOf(codeType.getCode()).equals(value)) {
if (code == codeType.getCode()) {
return codeType;
}
}
return null;
throw new WeIdBaseException(ErrorCode.TRANSPORTATION_PROTOCOL_ENCODE_ERROR);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@ public class ProtocolProperty {
* 目前默认为ORG,表示协议第三段为机构名如: 00org/resourceId
*/
private UriType uriType = UriType.ORG;

/**
* 二维码的数据模式: 默认为纯数据模式.
*/
private TransMode transMode = TransMode.DATA_MODE;

public EncodeType getEncodeType() {
return encodeType;
Expand All @@ -50,12 +55,21 @@ public ProtocolProperty(EncodeType encodeType) {
this.encodeType = encodeType;
}

public ProtocolProperty(EncodeType encodeType, TransMode transMode) {
this(encodeType);
this.transMode = transMode;
}

public TransType getTransType() {
return transType;
}

public UriType getUriType() {
return uriType;
}

public TransMode getTransMode() {
return transMode;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
/*
* Copyright© (2018-2020) WeBank Co., Ltd.
*
* This file is part of weid-java-sdk.
*
* weid-java-sdk is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* weid-java-sdk is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with weid-java-sdk. If not, see <https://www.gnu.org/licenses/>.
*/

package com.webank.weid.suite.api.transportation.params;

import com.webank.weid.constant.ErrorCode;
import com.webank.weid.exception.WeIdBaseException;

/**
* Transportation的数据模式, 目前支持二维码的纯数据模式和下载模式
* 在使用transportation序列化二维码的时候可以通过这个指定二维码包含的是纯数据,还是下载模式.
* 纯数据模式(DATA_MODE):表示序列化出来的数据为实际数据,此模式下的内容会过大,可能无法编码到二维码中.
*下载模式(DOWNLOAD_MODE):将协议数据存储在数据库中,通过短编码进行映射.
*
* @author yanggang
*
*/
public enum TransMode {

/**
* 纯数据模式.
*/
DATA_MODE(0),

/**
* 下载模式.
*/
DOWNLOAD_MODE(1),
;

private Integer code;

TransMode(Integer code) {
this.code = code;
}

public Integer getCode() {
return code;
}

/**
* get TransMode By code.
*
* @param code the TransMode code
* @return TransMode
*/
public static TransMode getTransModeByCode(Integer code) {
for (TransMode type : TransMode.values()) {
if (type.getCode() == code) {
return type;
}
}
throw new WeIdBaseException(ErrorCode.TRANSPORTATION_TRANSMODE_TYPE_INVALID);
}

}
6 changes: 4 additions & 2 deletions src/main/java/com/webank/weid/suite/endpoint/RpcServer.java
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,10 @@ public void process(AioSession<String> session, String msg) {
return;
}
} catch (IOException e) {
logger.error("Failed to track remote address for session ID: "
+ session.getSessionID());
logger.error(
"Failed to track remote address for session ID: {}",
session.getSessionID()
);
}
String bizResult = StringUtils.EMPTY;
try {
Expand Down

0 comments on commit 90a9601

Please sign in to comment.