diff --git a/src/main/java/hlf/java/rest/client/controller/ChaincodeOperationsController.java b/src/main/java/hlf/java/rest/client/controller/ChaincodeOperationsController.java index b9fdc90e..a18eb0be 100644 --- a/src/main/java/hlf/java/rest/client/controller/ChaincodeOperationsController.java +++ b/src/main/java/hlf/java/rest/client/controller/ChaincodeOperationsController.java @@ -93,7 +93,9 @@ public ResponseEntity> getApprovedOrganisationListForSmartContract( @RequestParam("chaincode_name") String chaincodeName, @RequestParam("chaincode_version") String chaincodeVersion, @RequestParam("sequence") Long sequence, - @RequestParam(value = "init_required", defaultValue = "false") boolean initRequired) { + @RequestParam(value = "init_required", defaultValue = "false") boolean initRequired, + @RequestPart(value = "collection_config", required = false) + MultipartFile collectionConfigFile) { ChaincodeOperations chaincodeOperations = ChaincodeOperations.builder() .chaincodeName(chaincodeName) @@ -104,7 +106,10 @@ public ResponseEntity> getApprovedOrganisationListForSmartContract( Set approvedOrganizations = chaincodeOperationsService.getApprovedOrganizations( - networkName, chaincodeOperations, Optional.empty(), Optional.empty()); + networkName, + chaincodeOperations, + Optional.empty(), + Optional.ofNullable(collectionConfigFile)); return new ResponseEntity<>(approvedOrganizations, HttpStatus.OK); } diff --git a/src/main/java/hlf/java/rest/client/exception/ErrorCode.java b/src/main/java/hlf/java/rest/client/exception/ErrorCode.java index 697f755b..32bb9ea9 100644 --- a/src/main/java/hlf/java/rest/client/exception/ErrorCode.java +++ b/src/main/java/hlf/java/rest/client/exception/ErrorCode.java @@ -23,6 +23,8 @@ public enum ErrorCode { CHAINCODE_PACKAGE_ID_VALIDATION_FAILED( 1005, "The chaincode packageId is not same in all the peers or not present."), + CHANNEL_CREATION_FAILED(3000, "Failed to create Channel"), + CHANNEL_JOIN_FAILED(3006, "Failed to join channel"), CHANNEL_CREATION_MISSING_ORDERER(4000, "Orderer is missing"), diff --git a/src/main/java/hlf/java/rest/client/service/ChaincodeOperationsService.java b/src/main/java/hlf/java/rest/client/service/ChaincodeOperationsService.java index b0d28cd1..7aa94167 100644 --- a/src/main/java/hlf/java/rest/client/service/ChaincodeOperationsService.java +++ b/src/main/java/hlf/java/rest/client/service/ChaincodeOperationsService.java @@ -4,7 +4,6 @@ import hlf.java.rest.client.model.ChaincodeOperationsType; import java.util.Optional; import java.util.Set; -import org.hyperledger.fabric.sdk.ChaincodeCollectionConfiguration; import org.hyperledger.fabric.sdk.LifecycleChaincodeEndorsementPolicy; import org.springframework.web.multipart.MultipartFile; @@ -48,5 +47,5 @@ Set getApprovedOrganizations( String networkName, ChaincodeOperations chaincodeOperationsModel, Optional chaincodeEndorsementPolicyOptional, - Optional chaincodeCollectionConfigurationOptional); + Optional collectionConfigFileOptional); } diff --git a/src/main/java/hlf/java/rest/client/service/impl/ChaincodeOperationsServiceImpl.java b/src/main/java/hlf/java/rest/client/service/impl/ChaincodeOperationsServiceImpl.java index c5a23f56..9d6a9434 100644 --- a/src/main/java/hlf/java/rest/client/service/impl/ChaincodeOperationsServiceImpl.java +++ b/src/main/java/hlf/java/rest/client/service/impl/ChaincodeOperationsServiceImpl.java @@ -195,7 +195,7 @@ public Set getApprovedOrganizations( String networkName, ChaincodeOperations chaincodeOperationsModel, Optional chaincodeEndorsementPolicyOptional, - Optional chaincodeCollectionConfigurationOptional) { + Optional collectionConfigFileOptional) { Set organizationSet = new HashSet<>(); try { @@ -215,9 +215,21 @@ public Set getApprovedOrganizations( lifecycleCheckCommitReadinessRequest.setChaincodeEndorsementPolicy( chaincodeEndorsementPolicyOptional.get()); } - if (chaincodeCollectionConfigurationOptional.isPresent()) { - lifecycleCheckCommitReadinessRequest.setChaincodeCollectionConfiguration( - chaincodeCollectionConfigurationOptional.get()); + + if (collectionConfigFileOptional.isPresent()) { + + try (InputStream inputStream = collectionConfigFileOptional.get().getInputStream()) { + + ChaincodeCollectionConfiguration chaincodeCollectionConfiguration = + ChaincodeCollectionConfiguration.fromJsonStream(inputStream); + + lifecycleCheckCommitReadinessRequest.setChaincodeCollectionConfiguration( + chaincodeCollectionConfiguration); + } catch (ChaincodeCollectionConfigurationException | IOException e) { + throw new ServiceException( + ErrorCode.DESERIALIZATION_FAILURE, + "Error occurred while extracting details from the uploaded Collection-Config file"); + } } lifecycleCheckCommitReadinessRequest.setInitRequired( diff --git a/src/main/java/hlf/java/rest/client/service/impl/ChannelServiceImpl.java b/src/main/java/hlf/java/rest/client/service/impl/ChannelServiceImpl.java index 52dfa4c9..bc38f8e4 100644 --- a/src/main/java/hlf/java/rest/client/service/impl/ChannelServiceImpl.java +++ b/src/main/java/hlf/java/rest/client/service/impl/ChannelServiceImpl.java @@ -107,7 +107,7 @@ public ClientResponseModel createChannel(ChannelOperationRequest channelOperatio } catch (Exception e) { log.error("Error in creating new channel: ", e); throw new ChannelOperationException( - ErrorCode.CHANNEL_JOIN_FAILED, "channel creation failed", e.getCause()); + ErrorCode.CHANNEL_CREATION_FAILED, "channel creation failed", e.getCause()); } }