Skip to content

Commit

Permalink
Enhancement: Merged two services into one for building writeSet and f…
Browse files Browse the repository at this point in the history
…ew other refractor

Signed-off-by: n0s09by <[email protected]>
  • Loading branch information
nidhi-singh02 committed Jan 5, 2024
1 parent f0f3000 commit ee49783
Show file tree
Hide file tree
Showing 12 changed files with 125 additions and 202 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package hlf.java.rest.client.controller;

import hlf.java.rest.client.model.AnchorPeerParamsDTO;
import hlf.java.rest.client.model.ChannelUpdateParamsDTO;
import hlf.java.rest.client.model.ClientResponseModel;
import hlf.java.rest.client.model.CommitChannelParamsDTO;
import hlf.java.rest.client.model.NewOrgParamsDTO;
Expand Down Expand Up @@ -140,7 +140,7 @@ public ResponseEntity<ClientResponseModel> getDeserializedJson(
@PostMapping(value = "/channel/{channelName}/add_anchor_peer")
public ResponseEntity<ClientResponseModel> addAnchorPeersToChannel(
@PathVariable @Validated String channelName,
@RequestBody @Validated AnchorPeerParamsDTO anchorPeerParamsDTO) {
@RequestBody @Validated ChannelUpdateParamsDTO anchorPeerParamsDTO) {
return networkStatus.addAnchorPeersToChannel(channelName, anchorPeerParamsDTO);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package hlf.java.rest.client.model;

import java.util.List;
import lombok.Data;

@Data
public class ChannelUpdateParamsDTO {
private String organizationMspId;
private List<AnchorPeerDTO> anchorPeerDTOs;
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
package hlf.java.rest.client.model;

import java.util.List;
import lombok.Data;

@Data
public class NewOrgParamsDTO {

public class NewOrgParamsDTO extends ChannelUpdateParamsDTO {
private String organizationName;
private String organizationMspId;
private MSPDTO mspDTO;
private List<AnchorPeerDTO> anchorPeerDTOs;
}

This file was deleted.

4 changes: 2 additions & 2 deletions src/main/java/hlf/java/rest/client/service/NetworkStatus.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package hlf.java.rest.client.service;

import hlf.java.rest.client.model.AnchorPeerParamsDTO;
import hlf.java.rest.client.model.ChannelUpdateParamsDTO;
import hlf.java.rest.client.model.ClientResponseModel;
import hlf.java.rest.client.model.CommitChannelParamsDTO;
import hlf.java.rest.client.model.NewOrgParamsDTO;
Expand All @@ -23,5 +23,5 @@ ResponseEntity<ClientResponseModel> addOrgToChannel(
String channelName, NewOrgParamsDTO organizationDetails);

ResponseEntity<ClientResponseModel> addAnchorPeersToChannel(
String channelName, AnchorPeerParamsDTO anchorPeerParamsDTO);
String channelName, ChannelUpdateParamsDTO anchorPeerParamsDTO);
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package hlf.java.rest.client.service;

import hlf.java.rest.client.exception.ServiceException;
import hlf.java.rest.client.model.NewOrgParamsDTO;
import hlf.java.rest.client.model.ChannelUpdateParamsDTO;
import org.hyperledger.fabric.protos.common.Configtx.ConfigGroup;

public interface AddOrgToChannelWriteSetBuilder {
public interface UpdateChannel {

ConfigGroup buildWriteset(ConfigGroup readset, NewOrgParamsDTO organizationDetails)
ConfigGroup buildWriteset(ConfigGroup readset, ChannelUpdateParamsDTO organizationDetails)
throws ServiceException;
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,13 @@
import hlf.java.rest.client.exception.ErrorConstants;
import hlf.java.rest.client.exception.FabricTransactionException;
import hlf.java.rest.client.exception.ServiceException;
import hlf.java.rest.client.model.AnchorPeerParamsDTO;
import hlf.java.rest.client.model.ChannelUpdateParamsDTO;
import hlf.java.rest.client.model.ClientResponseModel;
import hlf.java.rest.client.model.CommitChannelParamsDTO;
import hlf.java.rest.client.model.NewOrgParamsDTO;
import hlf.java.rest.client.service.AddAnchorPeerToChannelWriteSetBuilder;
import hlf.java.rest.client.service.AddOrgToChannelWriteSetBuilder;
import hlf.java.rest.client.service.ChannelConfigDeserialization;
import hlf.java.rest.client.service.NetworkStatus;
import hlf.java.rest.client.service.UpdateChannel;
import java.io.IOException;
import java.util.Base64;
import lombok.extern.slf4j.Slf4j;
Expand All @@ -40,10 +39,8 @@ public class NetworkStatusImpl implements NetworkStatus {

@Autowired private Gateway gateway;
@Autowired private User user;
@Autowired private AddOrgToChannelWriteSetBuilder addOrgToChannelWriteSetBuilder;

@Autowired private AddAnchorPeerToChannelWriteSetBuilder addAnchorPeerToChannelWriteSetBuilder;
@Autowired private ChannelConfigDeserialization channelConfigDeserialization;
@Autowired private UpdateChannel updateChannel;

private String getDeserializedConfig(MessageOrBuilder message) {
String channelConfigString;
Expand Down Expand Up @@ -101,21 +98,23 @@ public ResponseEntity<ClientResponseModel> getChannelFromNetwork(String channelN
HttpStatus.OK);
}

private ConfigUpdate getChannelConfig(
String channelName, ChannelUpdateParamsDTO organizationDetails) {
ConfigUpdate.Builder configUpdateBuilder = createConfigUpdate(channelName);
return configUpdateBuilder
.setWriteSet(
updateChannel.buildWriteset(configUpdateBuilder.getReadSet(), organizationDetails))
.build();
}

@Override
public ResponseEntity<ClientResponseModel> generateConfigUpdate(
String channelName, NewOrgParamsDTO organizationDetails) {
Network network = gateway.getNetwork(channelName);

if (network != null) {
ConfigUpdate.Builder configUpdateBuilder = createConfigUpdate(channelName);
ConfigUpdate configUpdate =
configUpdateBuilder
.setWriteSet(
addOrgToChannelWriteSetBuilder.buildWriteset(
configUpdateBuilder.getReadSet(), organizationDetails))
.build();
MessageOrBuilder message = configUpdate;
String base64EncodedByteArrayDeserialized = getDeserializedConfig(configUpdate);
String base64EncodedByteArrayDeserialized =
getDeserializedConfig(getChannelConfig(channelName, organizationDetails));
return new ResponseEntity<>(
new ClientResponseModel(ErrorConstants.NO_ERROR, base64EncodedByteArrayDeserialized),
HttpStatus.OK);
Expand Down Expand Up @@ -327,15 +326,8 @@ public ResponseEntity<ClientResponseModel> addOrgToChannel(
if (network != null && user != null) {
try {
Channel selectedChannel = network.getChannel();
ConfigUpdate.Builder configUpdateBuilder = createConfigUpdate(channelName);
ConfigUpdate configUpdate =
configUpdateBuilder
.setWriteSet(
addOrgToChannelWriteSetBuilder.buildWriteset(
configUpdateBuilder.getReadSet(), organizationDetails))
.build();
MessageOrBuilder message = configUpdate;
String channelConfigString = JsonFormat.printer().print(message);
ConfigUpdate configUpdate = getChannelConfig(channelName, organizationDetails);
String channelConfigString = JsonFormat.printer().print(configUpdate);
log.info(channelConfigDeserialization.deserializeValueFields(channelConfigString));
UpdateChannelConfiguration updateChannelConfiguration = new UpdateChannelConfiguration();
updateChannelConfiguration.setUpdateChannelConfiguration(
Expand Down Expand Up @@ -379,20 +371,13 @@ public ResponseEntity<ClientResponseModel> addOrgToChannel(

@Override
public ResponseEntity<ClientResponseModel> addAnchorPeersToChannel(
String channelName, AnchorPeerParamsDTO anchorPeerParamsDTO) {
String channelName, ChannelUpdateParamsDTO anchorPeerParamsDTO) {
Network network = gateway.getNetwork(channelName);
if (network != null && user != null) {
try {
Channel selectedChannel = network.getChannel();
ConfigUpdate.Builder configUpdateBuilder = createConfigUpdate(channelName);
ConfigUpdate configUpdate =
configUpdateBuilder
.setWriteSet(
addAnchorPeerToChannelWriteSetBuilder.buildWriteSetForAnchorPeers(
configUpdateBuilder.getReadSet(), anchorPeerParamsDTO))
.build();
MessageOrBuilder message = configUpdate;
String channelConfigString = JsonFormat.printer().print(message);
ConfigUpdate configUpdate = getChannelConfig(channelName, anchorPeerParamsDTO);
String channelConfigString = JsonFormat.printer().print(configUpdate);
log.info(channelConfigDeserialization.deserializeValueFields(channelConfigString));
UpdateChannelConfiguration updateChannelConfiguration = new UpdateChannelConfiguration();
updateChannelConfiguration.setUpdateChannelConfiguration(
Expand Down
Loading

0 comments on commit ee49783

Please sign in to comment.