Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Accept optional collection-config file while fetching approved status #102

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,9 @@ public ResponseEntity<Set<String>> 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)
Expand All @@ -104,7 +106,10 @@ public ResponseEntity<Set<String>> getApprovedOrganisationListForSmartContract(

Set<String> approvedOrganizations =
chaincodeOperationsService.getApprovedOrganizations(
networkName, chaincodeOperations, Optional.empty(), Optional.empty());
networkName,
chaincodeOperations,
Optional.empty(),
Optional.ofNullable(collectionConfigFile));

return new ResponseEntity<>(approvedOrganizations, HttpStatus.OK);
}
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/hlf/java/rest/client/exception/ErrorCode.java
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -48,5 +47,5 @@ Set<String> getApprovedOrganizations(
String networkName,
ChaincodeOperations chaincodeOperationsModel,
Optional<LifecycleChaincodeEndorsementPolicy> chaincodeEndorsementPolicyOptional,
Optional<ChaincodeCollectionConfiguration> chaincodeCollectionConfigurationOptional);
Optional<MultipartFile> collectionConfigFileOptional);
}
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ public Set<String> getApprovedOrganizations(
String networkName,
ChaincodeOperations chaincodeOperationsModel,
Optional<LifecycleChaincodeEndorsementPolicy> chaincodeEndorsementPolicyOptional,
Optional<ChaincodeCollectionConfiguration> chaincodeCollectionConfigurationOptional) {
Optional<MultipartFile> collectionConfigFileOptional) {
Set<String> organizationSet = new HashSet<>();
try {

Expand All @@ -215,9 +215,21 @@ public Set<String> 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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
}

Expand Down
Loading