Skip to content

Commit

Permalink
Merge pull request #291 from WeBankFinTech/release/1.8.0
Browse files Browse the repository at this point in the history
Release/1.8.0
  • Loading branch information
yanggang-JV committed Jan 26, 2021
2 parents 5fef93f + e76f1d0 commit ef216f7
Show file tree
Hide file tree
Showing 8 changed files with 89 additions and 4 deletions.
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.7.1
1.8.0
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ dependencies {
localDeps 'org.projectlombok:lombok:1.18.10'
if (!gradle.startParameter.isOffline()) {
compile logger, lombok, apache_commons, json, mysql_driver, redisson, zxing, rpc, pdfbox, protobuf, caffeine, oval
compile("com.webank:weid-contract-java:1.2.29-rc.2-SNAPSHOT") {
compile("com.webank:weid-contract-java:1.2.29") {
exclude group: "org.slf4j", module: "slf4j-log4j12"
}
compile fileTree(dir: 'lib', include: '*.jar')
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/com/webank/weid/protocol/cpt/Cpt109.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@

package com.webank.weid.protocol.cpt;

import com.github.reinert.jjschema.Attributes;

import lombok.Data;

/**
Expand All @@ -28,6 +30,8 @@
*/

@Data
@Attributes(title = "Trusted Timestamp",
description = "Trusted Timestamp from authorized 3rd-party, or chain consensus")
public class Cpt109 {

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.webank.weid.protocol.response;

import java.util.List;

import lombok.Data;

/**
* get WeId and errorCode by pubkeyList response.
*
*/
@Data
public class WeIdListResult {

private List<String> weIdList;

private List<Integer> errorCodeList;
}
8 changes: 8 additions & 0 deletions src/main/java/com/webank/weid/rpc/WeIdService.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import com.webank.weid.protocol.request.ServiceArgs;
import com.webank.weid.protocol.response.CreateWeIdDataResult;
import com.webank.weid.protocol.response.ResponseData;
import com.webank.weid.protocol.response.WeIdListResult;


/**
Expand Down Expand Up @@ -219,4 +220,11 @@ ResponseData<List<WeIdPojo>> getWeIdList(
* @return total weid
*/
ResponseData<Integer> getWeIdCount();

/**
* get WeID list by pubKey list.
* @param pubKeyList the pubKey list
* @return return the WeIDListResult
*/
ResponseData<WeIdListResult> getWeIdListByPubKeyList(List<WeIdPublicKey> pubKeyList);
}
32 changes: 32 additions & 0 deletions src/main/java/com/webank/weid/service/impl/WeIdServiceImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,12 @@
package com.webank.weid.service.impl;

import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

import com.fasterxml.jackson.databind.ObjectMapper;

import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.math.NumberUtils;
import org.fisco.bcos.web3j.crypto.ECKeyPair;
Expand All @@ -47,6 +49,7 @@
import com.webank.weid.protocol.request.ServiceArgs;
import com.webank.weid.protocol.response.CreateWeIdDataResult;
import com.webank.weid.protocol.response.ResponseData;
import com.webank.weid.protocol.response.WeIdListResult;
import com.webank.weid.rpc.WeIdService;
import com.webank.weid.util.DataToolUtils;
import com.webank.weid.util.WeIdUtils;
Expand Down Expand Up @@ -960,4 +963,33 @@ public ResponseData<List<WeIdPojo>> getWeIdList(
public ResponseData<Integer> getWeIdCount() {
return weIdServiceEngine.getWeIdCount();
}

@Override
public ResponseData<WeIdListResult> getWeIdListByPubKeyList(List<WeIdPublicKey> pubKeyList) {
if (pubKeyList == null || pubKeyList.size() == 0) {
return new ResponseData<>(null, ErrorCode.ILLEGAL_INPUT);
}
WeIdListResult weIdListResult = new WeIdListResult();
weIdListResult.setWeIdList(new ArrayList<>());
weIdListResult.setErrorCodeList(new ArrayList<>());
ResponseData<WeIdListResult> responseData = new ResponseData<WeIdListResult>();
pubKeyList.forEach(weIdPublicKey -> {
String weId = WeIdUtils.convertPublicKeyToWeId(weIdPublicKey.getPublicKey());
if (StringUtils.isBlank(weId)) {
weIdListResult.getWeIdList().add(null);
weIdListResult.getErrorCodeList().add(ErrorCode.WEID_PUBLICKEY_INVALID.getCode());
} else {
if (this.isWeIdExist(weId).getResult()) {
weIdListResult.getWeIdList().add(weId);
weIdListResult.getErrorCodeList().add(ErrorCode.SUCCESS.getCode());
} else {
weIdListResult.getWeIdList().add(null);
weIdListResult.getErrorCodeList().add(
ErrorCode.WEID_PUBLIC_KEY_NOT_EXIST.getCode());
}
}
});
responseData.setResult(weIdListResult);
return responseData;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import com.webank.weid.protocol.request.RemoveAuthorityIssuerArgs;
import com.webank.weid.protocol.response.CreateWeIdDataResult;
import com.webank.weid.protocol.response.ResponseData;
import com.webank.weid.util.DataToolUtils;


public class TestGetAllAuthorityIssuerList extends TestBaseService {
Expand Down Expand Up @@ -148,10 +149,10 @@ public void testGetAllAuthorityIssuerList_removeListThenQuery() {

Assert.assertEquals(ErrorCode.SUCCESS.getCode(), response.getErrorCode().intValue());
List<AuthorityIssuer> authorityIssuers = response.getResult();

String sdkWeId = DataToolUtils.convertPrivateKeyToDefaultWeId(privateKey);
for (int i = 0; i < authorityIssuers.size(); i++) {
String weId = authorityIssuers.get(i).getWeId();
if (!weId.equals(createWeId.getWeId())) {
if (!weId.equals(createWeId.getWeId()) && !sdkWeId.equals(weId)) {
RemoveAuthorityIssuerArgs removeAuthorityIssuerArgs =
new RemoveAuthorityIssuerArgs();
removeAuthorityIssuerArgs.setWeId(weId);
Expand Down
23 changes: 23 additions & 0 deletions src/test/java/com/webank/weid/full/weid/TestGetWeIdDocument.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@

package com.webank.weid.full.weid;

import java.util.ArrayList;
import java.util.List;

import com.fasterxml.jackson.databind.ObjectMapper;
import org.junit.Assert;
import org.junit.Test;
Expand All @@ -33,11 +36,13 @@
import com.webank.weid.full.TestBaseUtil;
import com.webank.weid.protocol.base.WeIdDocument;
import com.webank.weid.protocol.base.WeIdPrivateKey;
import com.webank.weid.protocol.base.WeIdPublicKey;
import com.webank.weid.protocol.request.AuthenticationArgs;
import com.webank.weid.protocol.request.PublicKeyArgs;
import com.webank.weid.protocol.request.ServiceArgs;
import com.webank.weid.protocol.response.CreateWeIdDataResult;
import com.webank.weid.protocol.response.ResponseData;
import com.webank.weid.protocol.response.WeIdListResult;

/**
* getWeIdDocument method for testing WeIdService.
Expand Down Expand Up @@ -334,4 +339,22 @@ public void testGetWeIdDocument_weIdIsNull() {
Assert.assertEquals(ErrorCode.WEID_INVALID.getCode(), weIdDoc.getErrorCode().intValue());
Assert.assertNull(weIdDoc.getResult());
}

/**
* case: getWeIdList By publicKeyList.
*/
@Test
public void testGetWeIdListByPubkeyList() {
List<WeIdPublicKey> pubKeyList = new ArrayList<>();
int num = 5;
for (int i = 0; i < num; i++) {
WeIdPublicKey publicKey = new WeIdPublicKey();
publicKey.setPublicKey(TestBaseUtil.createEcKeyPair().getPublicKey());
pubKeyList.add(publicKey);
}
ResponseData<WeIdListResult> weIdListRes = weIdService.getWeIdListByPubKeyList(pubKeyList);
LogUtil.info(logger, "getWeIdListByPubKeyList", weIdListRes);
Assert.assertEquals(ErrorCode.SUCCESS.getCode(), weIdListRes.getErrorCode().intValue());
Assert.assertEquals(num, weIdListRes.getResult().getWeIdList().size());
}
}

0 comments on commit ef216f7

Please sign in to comment.