Skip to content

Commit

Permalink
Merge pull request #294 from yanggang-JV/feature/get-issuer-count
Browse files Browse the repository at this point in the history
* add function for get issuer count
  • Loading branch information
junqizhang-dev committed Apr 12, 2021
2 parents 8f106bc + f168f4b commit 50f964b
Show file tree
Hide file tree
Showing 11 changed files with 369 additions and 4 deletions.
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.8.0
1.8.1
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") {
compile("com.webank:weid-contract-java:1.2.30-rc.8-SNAPSHOT") {
exclude group: "org.slf4j", module: "slf4j-log4j12"
}
compile fileTree(dir: 'lib', include: '*.jar')
Expand Down
16 changes: 16 additions & 0 deletions src/main/java/com/webank/weid/constant/ErrorCode.java
Original file line number Diff line number Diff line change
Expand Up @@ -686,6 +686,22 @@ public enum ErrorCode {
"the specific issuer type or address does not exist."
),

/**
* The capacity has reached the upper limit.
*/
SPECIFIC_ISSUER_CONTRACT_ERROR_EXCEED_MAX(
500503,
"the capacity has reached the upper limit."
),

/**
* Has issuer in the specific issuer type.
*/
SPECIFIC_ISSUER_CONTRACT_ERROR_EXIST_ISSUER(
500504,
"has issuer in the specific issuer type."
),

/**
* The weid invalid.
*/
Expand Down
40 changes: 40 additions & 0 deletions src/main/java/com/webank/weid/protocol/base/IssuerType.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
* Copyright© (2018-2021) 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.protocol.base;

import lombok.Data;

@Data
public class IssuerType {
/**
* Required: The Issuer Type Name.
*/
private String typeName;

/**
* Required: The The Issuer Type Owner..
*/
private String owner;

/**
* Required: The create date of the Authority Issuer, in timestamp (Long) format.
*/
private Long created;
}
36 changes: 36 additions & 0 deletions src/main/java/com/webank/weid/rpc/AuthorityIssuerService.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import java.util.List;

import com.webank.weid.protocol.base.AuthorityIssuer;
import com.webank.weid.protocol.base.IssuerType;
import com.webank.weid.protocol.base.WeIdAuthentication;
import com.webank.weid.protocol.base.WeIdPrivateKey;
import com.webank.weid.protocol.request.RegisterAuthorityIssuerArgs;
Expand Down Expand Up @@ -175,4 +176,39 @@ ResponseData<List<String>> getAllSpecificTypeIssuerList(
* @return the all issuer
*/
ResponseData<Integer> getIssuerCount();

/**
* get the issuer count with Recognized.
* @return the all issuer with Recognized
*/
ResponseData<Integer> getRecognizedIssuerCount();

/**
* get the issuer size in issuerType.
* @param issuerType the issuerType
* @return the all issuer in issuerType
*/
ResponseData<Integer> getSpecificTypeIssuerSize(String issuerType);

/**
* get the issuer type count.
* @return the all issuer type
*/
ResponseData<Integer> getIssuerTypeCount();

/**
* remove the issuerType.
* @param callerAuth the caller
* @param issuerType the issuerType name
* @return true is success, false is fail
*/
ResponseData<Boolean> removeIssuerType(WeIdAuthentication callerAuth, String issuerType);

/**
* get the issuerType list.
* @param index the start index
* @param num the page size
* @return the issuerType list
*/
ResponseData<List<IssuerType>> getIssuerTypeList(Integer index, Integer num);
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import com.webank.weid.constant.ErrorCode;
import com.webank.weid.constant.WeIdConstant;
import com.webank.weid.protocol.base.AuthorityIssuer;
import com.webank.weid.protocol.base.IssuerType;
import com.webank.weid.protocol.base.WeIdAuthentication;
import com.webank.weid.protocol.base.WeIdPrivateKey;
import com.webank.weid.protocol.request.RegisterAuthorityIssuerArgs;
Expand Down Expand Up @@ -540,4 +541,41 @@ public ResponseData<String> getWeIdByOrgId(String orgId) {
public ResponseData<Integer> getIssuerCount() {
return authEngine.getIssuerCount();
}

@Override
public ResponseData<Integer> getRecognizedIssuerCount() {
return authEngine.getRecognizedIssuerCount();
}

@Override
public ResponseData<Integer> getSpecificTypeIssuerSize(String issuerType) {
return authEngine.getSpecificTypeIssuerSize(issuerType);
}

@Override
public ResponseData<Integer> getIssuerTypeCount() {
return authEngine.getIssuerTypeCount();
}

@Override
public ResponseData<Boolean> removeIssuerType(
WeIdAuthentication callerAuth,
String issuerType
) {
ErrorCode innerCode = isIssuerTypeValid(issuerType);
if (innerCode != ErrorCode.SUCCESS) {
return new ResponseData<>(false, innerCode);
}
innerCode = isCallerAuthValid(callerAuth);
if (innerCode != ErrorCode.SUCCESS) {
return new ResponseData<>(false, innerCode);
}
return authEngine.removeIssuerType(
issuerType, callerAuth.getWeIdPrivateKey().getPrivateKey());
}

@Override
public ResponseData<List<IssuerType>> getIssuerTypeList(Integer index, Integer num) {
return authEngine.getIssuerTypeList(index, num);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import java.util.List;

import com.webank.weid.protocol.base.AuthorityIssuer;
import com.webank.weid.protocol.base.IssuerType;
import com.webank.weid.protocol.request.RegisterAuthorityIssuerArgs;
import com.webank.weid.protocol.request.RemoveAuthorityIssuerArgs;
import com.webank.weid.protocol.response.ResponseData;
Expand Down Expand Up @@ -138,10 +139,45 @@ 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();

/**
* get the issuer count with Recognized.
* @return the all issuer with Recognized
*/
public ResponseData<Integer> getRecognizedIssuerCount();

/**
* get the issuer size in issuerType.
* @param issuerType the issuerType
* @return the all issuer in issuerType
*/
public ResponseData<Integer> getSpecificTypeIssuerSize(String issuerType);

/**
* get the issuer type count.
* @return the all issuer type
*/
public ResponseData<Integer> getIssuerTypeCount();

/**
* remove the issuerType.
* @param issuerType the issuerType name
* @param privateKey the privateKey
* @return true is success, false is fail
*/
public ResponseData<Boolean> removeIssuerType(String issuerType, String privateKey);

/**
* get the issuerType list.
* @param index the start index
* @param num the page size
* @return the issuerType list
*/
public ResponseData<List<IssuerType>> getIssuerTypeList(Integer index, Integer num);
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import org.fisco.bcos.web3j.abi.datatypes.Address;
import org.fisco.bcos.web3j.protocol.core.methods.response.TransactionReceipt;
import org.fisco.bcos.web3j.tuples.generated.Tuple2;
import org.fisco.bcos.web3j.tuples.generated.Tuple3;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand All @@ -37,6 +38,7 @@
import com.webank.weid.contract.v2.SpecificIssuerController;
import com.webank.weid.contract.v2.SpecificIssuerController.SpecificIssuerRetLogEventResponse;
import com.webank.weid.protocol.base.AuthorityIssuer;
import com.webank.weid.protocol.base.IssuerType;
import com.webank.weid.protocol.request.RegisterAuthorityIssuerArgs;
import com.webank.weid.protocol.request.RemoveAuthorityIssuerArgs;
import com.webank.weid.protocol.response.ResponseData;
Expand Down Expand Up @@ -562,9 +564,94 @@ public ResponseData<Integer> getIssuerCount() {
Integer count = authorityIssuerController.getTotalIssuer().send().intValue();
return new ResponseData<>(count, ErrorCode.SUCCESS);
} catch (Exception e) {
logger.error("[getCptCount] query CptCount failed. exception message: ", e);
logger.error("[getIssuerCount] query IssuerCount failed. exception message: ", e);
return new ResponseData<>(0, ErrorCode.TRANSACTION_EXECUTE_ERROR);
}
}

@Override
public ResponseData<Integer> getSpecificTypeIssuerSize(String issuerType) {
try {
Integer count = specificIssuerController.getSpecificTypeIssuerSize(
DataToolUtils.stringToByte32Array(issuerType)).send().intValue();
return new ResponseData<>(count, ErrorCode.SUCCESS);
} catch (Exception e) {
logger.error("[getIssuerCount] query IssuerCount failed. exception message: ", e);
return new ResponseData<>(0, ErrorCode.TRANSACTION_EXECUTE_ERROR);
}
}

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

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

@Override
public ResponseData<Boolean> removeIssuerType(String issuerType, String privateKey) {
try {
SpecificIssuerController specificIssuerController = reloadContract(
fiscoConfig.getSpecificIssuerAddress(),
privateKey,
SpecificIssuerController.class);
TransactionReceipt receipt = specificIssuerController
.removeIssuerType(DataToolUtils.stringToByte32Array(issuerType)).send();

// pass-in empty address
String emptyAddress = new Address(BigInteger.ZERO).toString();
ErrorCode errorCode = resolveSpecificIssuerEvents(receipt, false, emptyAddress);
TransactionInfo info = new TransactionInfo(receipt);
return new ResponseData<>(errorCode.getCode() == ErrorCode.SUCCESS.getCode(),
errorCode, info);
} catch (Exception e) {
logger.error("remove issuer type failed.", e);
return new ResponseData<>(false, ErrorCode.TRANSACTION_EXECUTE_ERROR);
}
}

@Override
public ResponseData<List<IssuerType>> getIssuerTypeList(Integer index, Integer num) {
List<IssuerType> list = new ArrayList<IssuerType>();
try {
Tuple3<List<byte[]>, List<String>, List<BigInteger>> tuple =
specificIssuerController.getIssuerTypeList(
new BigInteger(index.toString()),
new BigInteger(num.toString())
).send();
List<byte[]> typeNames = tuple.getValue1(); //typeNames
List<String> owners = tuple.getValue2(); //owners
List<BigInteger> createds = tuple.getValue3(); //createds
for (int i = 0; i < typeNames.size(); i++) {
IssuerType issuerType = new IssuerType();
issuerType.setTypeName(new String(typeNames.get(i)).trim());
issuerType.setOwner(WeIdUtils.convertAddressToWeId(owners.get(i)));
issuerType.setCreated(createds.get(i).longValue());
list.add(issuerType);
}
return new ResponseData<>(list, ErrorCode.SUCCESS);
} catch (Exception e) {
logger.error(
"[getIssuerTypeList] query IssuerTypeList failed. exception message: ", e);
return new ResponseData<>(list, ErrorCode.TRANSACTION_EXECUTE_ERROR);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -298,4 +298,28 @@ public void testAddIssuerIntoIssuerType_invalidIssuer() {
Assert.assertFalse(response.getResult());
}

/**
* case: Get RetIssuerType Count.
*/
@Test
public void testGetRetIssuerCountByIssuerType() {
ResponseData<Integer> responseBefore =
authorityIssuerService.getSpecificTypeIssuerSize(issuerType);
LogUtil.info(logger, "getSpecificTypeIssuerSize", responseBefore);
Assert.assertEquals(ErrorCode.SUCCESS.getCode(), responseBefore.getErrorCode().intValue());

WeIdAuthentication weIdAuthentication = TestBaseUtil.buildWeIdAuthentication(createWeId);
weIdAuthentication.setWeIdPrivateKey(new WeIdPrivateKey(privateKey));
ResponseData<Boolean> response1 = authorityIssuerService
.addIssuerIntoIssuerType(weIdAuthentication, issuerType, super.createWeId().getWeId());
LogUtil.info(logger, "addIssuerIntoIssuerType", response1);
Assert.assertEquals(ErrorCode.SUCCESS.getCode(), response1.getErrorCode().intValue());
Assert.assertTrue(response1.getResult());

ResponseData<Integer> responseAfter =
authorityIssuerService.getSpecificTypeIssuerSize(issuerType);
LogUtil.info(logger, "getSpecificTypeIssuerSize", responseAfter);
Assert.assertEquals(ErrorCode.SUCCESS.getCode(), responseAfter.getErrorCode().intValue());
Assert.assertTrue((responseAfter.getResult() - responseBefore.getResult()) == 1);
}
}

0 comments on commit 50f964b

Please sign in to comment.