Skip to content

Commit

Permalink
Merge pull request #144 from yg3630536/bugfix/optimization-code
Browse files Browse the repository at this point in the history
* optimization code for comment
  • Loading branch information
chenhaozx committed Mar 19, 2020
2 parents 3d43087 + 5f85fe6 commit 39f1ff9
Show file tree
Hide file tree
Showing 8 changed files with 37 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -58,4 +58,15 @@ public WeIdAuthentication(String weId, String privateKey) {
this.weIdPrivateKey = new WeIdPrivateKey();
this.weIdPrivateKey.setPrivateKey(privateKey);
}

/**
* Constructor with weId, privateKey and weIdPublicKeyId.
* @param weId the weId
* @param privateKey the privateKey
* @param weIdPublicKeyId the weIdPublicKeyId
*/
public WeIdAuthentication(String weId, String privateKey, String weIdPublicKeyId) {
this(weId, privateKey);
this.weIdPublicKeyId = weIdPublicKeyId;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -295,10 +295,6 @@ private ErrorCode checkIssueCredentialArgs(RequestIssueCredentialArgs args) {
if (!WeIdUtils.isWeIdValid(auth.getWeId())) {
return ErrorCode.WEID_INVALID;
}
if (!WeIdUtils
.isKeypairMatch(auth.getWeIdPrivateKey().getPrivateKey(), auth.getWeIdPublicKeyId())) {
return ErrorCode.WEID_PRIVATEKEY_DOES_NOT_MATCH;
}

return ErrorCode.SUCCESS;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public static PdfTransportation newPdfTransportation() {
* @param transportationType 封装类型枚举
* @return 返回具体处理类型
*/
public static Transportation newTransportation(TransportationType transportationType) {
public static Transportation build(TransportationType transportationType) {
switch (transportationType) {
case JSON:
return new JsonTransportationImpl();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -165,21 +165,21 @@ protected List<String> getVerifiers() {

protected void setVerifier(List<String> verifierWeIdList) {
if (this.verifierWeIdList != null) {
String errorMessage = ErrorCode.THIS_IS_REPEATED_CALL.getCode() + "-"
String errorMessage = ErrorCode.THIS_IS_REPEATED_CALL.getCode() + " - "
+ ErrorCode.THIS_IS_REPEATED_CALL.getCodeDesc();
logger.error("[specify] {}.", errorMessage);
throw new WeIdBaseException(errorMessage);
}
if (CollectionUtils.isEmpty(verifierWeIdList)) {
String errorMessage = ErrorCode.ILLEGAL_INPUT.getCode() + "-"
String errorMessage = ErrorCode.ILLEGAL_INPUT.getCode() + " - "
+ ErrorCode.ILLEGAL_INPUT.getCodeDesc();
logger.error("[specify] {}, the verifiers is null.", errorMessage);
throw new WeIdBaseException(errorMessage);
}
for (String weid : verifierWeIdList) {
ResponseData<Boolean> isExists = weidService.isWeIdExist(weid);
if (!isExists.getResult()) {
String errorMessage = ErrorCode.WEID_DOES_NOT_EXIST.getCode() + "-"
String errorMessage = ErrorCode.WEID_DOES_NOT_EXIST.getCode() + " - "
+ ErrorCode.WEID_DOES_NOT_EXIST.getCodeDesc();
logger.error("[specify] {} , weid = {} .", errorMessage, weid);
throw new WeIdBaseException(errorMessage);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.webank.weid.suite.api.transportation;
package com.webank.weid.util;

import java.awt.BasicStroke;
import java.awt.Color;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public synchronized void testInit() {
super.testInit();
presentation = this.getPresentationE();
transportation =
TransportationFactory.newTransportation(TransportationType.BAR_CODE)
TransportationFactory.build(TransportationType.BAR_CODE)
.specify(verifier);
original_transString = transportation.serialize(
presentation,
Expand Down Expand Up @@ -125,7 +125,7 @@ public void testDeserialize_credentialPojo() {
List<String> verifier = new ArrayList<String>();
verifier.add(createWeIdNew.getWeId());
ResponseData<String> response =
TransportationFactory.newTransportation(TransportationType.BAR_CODE)
TransportationFactory.build(TransportationType.BAR_CODE)
.specify(verifier)
.serialize(
credentialPojo,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public synchronized void testInit() {
presentation = getPresentationE();
if (transportation == null) {
transportation =
TransportationFactory.newTransportation(TransportationType.BAR_CODE)
TransportationFactory.build(TransportationType.BAR_CODE)
.specify(verifier);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import org.junit.Assert;
import org.junit.Test;

import com.webank.weid.exception.WeIdBaseException;
import com.webank.weid.full.TestBaseService;
import com.webank.weid.suite.api.transportation.TransportationFactory;
import com.webank.weid.suite.api.transportation.inf.Transportation;
Expand All @@ -25,4 +26,21 @@ public void testJsonSpecify() {
Assert.assertNotNull(transportation);

}

/**
* case: specify again.
*/
@Test
public void testJsonSpecify_again() {
Transportation transportation = TransportationFactory.newJsonTransportation();
List<String> weIdList = new ArrayList<>();
weIdList.add(createWeIdResult.getWeId());
weIdList.add(createWeIdNew.getWeId());
try {
transportation = transportation.specify(weIdList).specify(weIdList);
Assert.assertTrue(false);
} catch (WeIdBaseException e) {
Assert.assertTrue(true);
}
}
}

0 comments on commit 39f1ff9

Please sign in to comment.