Skip to content

Commit

Permalink
Merge pull request #281 from yanggang-JV/feature/query-cpt-count
Browse files Browse the repository at this point in the history
* query cpt List and Count
  • Loading branch information
junqizhang-dev committed Jan 11, 2021
2 parents 935c0c9 + de3667a commit 0db4ea9
Show file tree
Hide file tree
Showing 14 changed files with 131 additions and 11 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
### V1.7.0
Features:
1. FISCO BCOS 1.3.x support is fully removed - please use the FISCO BCOS 2.x node version respectively.
2. Evidence and WeIdDocument query performance improved due to support batch type blockchain node data lookup.
3. Authority Issuer can be registered by any WeID while only administrator can recognize.
4. Greatly enhanced WeID-Build-Tools functionalities.
5. Persistence now supports Redis as storage layer.

### V1.6.3-hotfix-1 (2020-08-26)
- Bugfixes:
1. Use batch block transaction receipts getter to improve evidence performance.
Expand Down
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.28") {
compile("com.webank:weid-contract-java:1.2.29-rc.2-SNAPSHOT") {
exclude group: "org.slf4j", module: "slf4j-log4j12"
}
compile fileTree(dir: 'lib', include: '*.jar')
Expand Down
6 changes: 6 additions & 0 deletions src/main/java/com/webank/weid/rpc/AuthorityIssuerService.java
Original file line number Diff line number Diff line change
Expand Up @@ -169,4 +169,10 @@ ResponseData<List<String>> getAllSpecificTypeIssuerList(
* @return WeID
*/
ResponseData<String> getWeIdByOrgId(String orgId);

/**
* get the issuer count.
* @return the all issuer
*/
ResponseData<Integer> getIssuerCount();
}
18 changes: 18 additions & 0 deletions src/main/java/com/webank/weid/rpc/CptService.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@

package com.webank.weid.rpc;

import java.util.List;

import com.webank.wedpr.selectivedisclosure.CredentialTemplateEntity;

import com.webank.weid.protocol.base.Cpt;
Expand Down Expand Up @@ -101,4 +103,20 @@ public interface CptService {
* @return The updated CPT info
*/
ResponseData<CredentialTemplateEntity> queryCredentialTemplate(Integer cptId);

/**
* Get CPTIDS from chain.
*
* @param startPos start position
* @param num batch number
* @return CPTID list
*/
ResponseData<List<Integer>> getCptIdList(Integer startPos, Integer num);

/**
* Get CPT count.
*
* @return the cpt count
*/
ResponseData<Integer> getCptCount();
}
7 changes: 7 additions & 0 deletions src/main/java/com/webank/weid/rpc/PolicyService.java
Original file line number Diff line number Diff line change
Expand Up @@ -86,4 +86,11 @@ ResponseData<Integer> registerPresentationPolicy(List<Integer> claimPolicyIdList
* @return claim policy list
*/
ResponseData<List<Integer>> getAllClaimPolicies(Integer startPos, Integer num);

/**
* Get Policy count.
*
* @return the Policy count
*/
ResponseData<Integer> getPolicyCount();
}
Original file line number Diff line number Diff line change
Expand Up @@ -535,4 +535,9 @@ public ResponseData<String> getWeIdByOrgId(String orgId) {
return new ResponseData<>(StringUtils.EMPTY, ErrorCode.AUTHORITY_ISSUER_ERROR);
}
}

@Override
public ResponseData<Integer> getIssuerCount() {
return authEngine.getIssuerCount();
}
}
18 changes: 15 additions & 3 deletions src/main/java/com/webank/weid/service/impl/CptServiceImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

import java.math.BigInteger;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.webank.wedpr.selectivedisclosure.CredentialTemplateEntity;
Expand All @@ -29,9 +30,7 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.webank.weid.constant.CredentialConstant;
import com.webank.weid.constant.ErrorCode;
import com.webank.weid.constant.JsonSchemaConstant;
import com.webank.weid.constant.WeIdConstant;
import com.webank.weid.protocol.base.Cpt;
import com.webank.weid.protocol.base.CptBaseInfo;
Expand Down Expand Up @@ -371,7 +370,20 @@ private ErrorCode validateCptJsonSchemaMap(
*/
@Override
public ResponseData<CredentialTemplateEntity> queryCredentialTemplate(Integer cptId) {

return cptServiceEngine.queryCredentialTemplate(cptId);
}


@Override
public ResponseData<List<Integer>> getCptIdList(Integer startPos, Integer num) {
if (startPos < 0 || num < 1) {
return new ResponseData<>(null, ErrorCode.ILLEGAL_INPUT);
}
return cptServiceEngine.getCptIdList(startPos, num, WeIdConstant.CPT_DATA_INDEX);
}

@Override
public ResponseData<Integer> getCptCount() {
return cptServiceEngine.getCptCount(WeIdConstant.CPT_DATA_INDEX);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,11 @@ public ResponseData<List<Integer>> getAllClaimPolicies(Integer startPos, Integer
if (startPos < 0 || num < 1) {
return new ResponseData<>(null, ErrorCode.ILLEGAL_INPUT);
}
return cptServiceEngine.getCptLists(startPos, num, WeIdConstant.POLICY_DATA_INDEX);
return cptServiceEngine.getCptIdList(startPos, num, WeIdConstant.POLICY_DATA_INDEX);
}

@Override
public ResponseData<Integer> getPolicyCount() {
return cptServiceEngine.getCptCount(WeIdConstant.POLICY_DATA_INDEX);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -138,4 +138,10 @@ public ResponseData<Boolean> addIssuer(
public ResponseData<String> getWeIdFromOrgId(String orgId);

public ResponseData<Boolean> recognizeWeId(Boolean isRecognize, String addr, String privateKey);

/**
* get the issuer count.
* @return the all issuer
*/
public ResponseData<Integer> getIssuerCount();
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ public interface CptServiceEngine extends ReloadStaticContract {
* @param cptJsonSchemaNew cpt content
* @param rsvSignature signature
* @param privateKey private key
* @param dataStorageIndex 0 is cpt, 1 is policy
* @return result
*/
ResponseData<CptBaseInfo> updateCpt(
Expand All @@ -64,6 +65,7 @@ ResponseData<CptBaseInfo> updateCpt(
* @param cptJsonSchemaNew cpt content
* @param rsvSignature signature
* @param privateKey private key
* @param dataStorageIndex 0 is cpt, 1 is policy
* @return result
*/
ResponseData<CptBaseInfo> registerCpt(
Expand All @@ -82,6 +84,7 @@ ResponseData<CptBaseInfo> registerCpt(
* @param cptJsonSchemaNew cpt content
* @param rsvSignature signature
* @param privateKey private key
* @param dataStorageIndex 0 is cpt, 1 is policy
* @return result
*/
ResponseData<CptBaseInfo> registerCpt(
Expand All @@ -96,6 +99,7 @@ ResponseData<CptBaseInfo> registerCpt(
* call cpt contract method to query cpt info from blockchain.
*
* @param cptId the id of the cpt
* @param dataStorageIndex 0 is cpt, 1 is policy
* @return cpt info
*/
ResponseData<Cpt> queryCpt(int cptId, int dataStorageIndex);
Expand All @@ -118,5 +122,19 @@ ResponseData<Integer> putPolicyIntoCpt(Integer cptId, List<Integer> policyIdList

ResponseData<List<Integer>> getPolicyFromCpt(Integer cptId);

ResponseData<List<Integer>> getCptLists(int startPos, int num, int dataStorageIndex);
/**
* 分页查询cptId列表.
* @param startPos 起始位置
* @param num 查询数量
* @param dataStorageIndex 存储类型,0表示CPT,1表示policy
* @return 返回id列表
*/
ResponseData<List<Integer>> getCptIdList(int startPos, int num, int dataStorageIndex);

/**
* 查询cpt或者policy总数.
* @param dataStorageIndex 存储类型,0表示CPT,1表示policy
* @return 返回总数
*/
ResponseData<Integer> getCptCount(int dataStorageIndex);
}
Empty file.
Original file line number Diff line number Diff line change
Expand Up @@ -556,4 +556,15 @@ public ResponseData<Boolean> addIssuer(String issuerType, String issuerAddress,
}
}

@Override
public ResponseData<Integer> getIssuerCount() {
try {
Integer count = authorityIssuerController.getTotalIssuer().send().intValue();
return new ResponseData<>(count, ErrorCode.SUCCESS);
} catch (Exception e) {
logger.error("[getCptCount] query CptCount failed. exception message: ", e);
return new ResponseData<>(0, ErrorCode.TRANSACTION_EXECUTE_ERROR);
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -706,19 +706,42 @@ public ResponseData<List<Integer>> getPolicyFromCpt(Integer cptId) {
}

@Override
public ResponseData<List<Integer>> getCptLists(int startPos, int num, int dataStorageIndex) {
public ResponseData<List<Integer>> getCptIdList(int startPos, int num, int dataStorageIndex) {
try {
List list = cptController.getCptIdList(
new BigInteger(String.valueOf(startPos), 10),
new BigInteger(String.valueOf(num), 10)).send();
List<?> list = null;
if (dataStorageIndex == WeIdConstant.CPT_DATA_INDEX) {
list = cptController.getCptIdList(
new BigInteger(String.valueOf(startPos), 10),
new BigInteger(String.valueOf(num), 10)).send();
} else {
list = cptController.getPolicyIdList(
new BigInteger(String.valueOf(startPos), 10),
new BigInteger(String.valueOf(num), 10)).send();
}
List<Integer> cpts = new ArrayList<>();
for (Object obj : list) {
cpts.add(((BigInteger) obj).intValue());
}
return new ResponseData<>(cpts, ErrorCode.SUCCESS);
} catch (Exception e) {
logger.error("[queryCpt] query Cpt failed. exception message: ", e);
logger.error("[getCptIdList] query CptLists failed. exception message: ", e);
return new ResponseData<>(null, ErrorCode.TRANSACTION_EXECUTE_ERROR);
}
}

@Override
public ResponseData<Integer> getCptCount(int dataStorageIndex) {
try {
Integer count = null;
if (dataStorageIndex == WeIdConstant.CPT_DATA_INDEX) {
count = cptController.getTotalCptId().send().intValue();
} else {
count = cptController.getTotalPolicyId().send().intValue();
}
return new ResponseData<>(count, ErrorCode.SUCCESS);
} catch (Exception e) {
logger.error("[getCptCount] query CptCount failed. exception message: ", e);
return new ResponseData<>(0, ErrorCode.TRANSACTION_EXECUTE_ERROR);
}
}
}
1 change: 1 addition & 0 deletions src/main/java/com/webank/weid/util/DataToolUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -1568,6 +1568,7 @@ public static synchronized String byte32ListToString(List<byte[]> bytesList, int
public static List<BigInteger> getParamCreatedList(int length) {
long created = DateUtils.getNoMillisecondTimeStamp();
List<BigInteger> createdList = new ArrayList<>();
createdList.add(BigInteger.ZERO);
createdList.add(BigInteger.valueOf(created));
return createdList;
}
Expand Down

0 comments on commit 0db4ea9

Please sign in to comment.