Skip to content
This repository has been archived by the owner on Aug 7, 2019. It is now read-only.

change affiliation field from mandatory to optional #3

Merged
merged 6 commits into from
Nov 15, 2017
Merged
Show file tree
Hide file tree
Changes from 1 commit
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 @@ -64,11 +64,11 @@

public class BMXHyperledgerFabricJSDKIntegrationSample {

public static final String NETWORK_CONFIG_PEERORG_CA = "fabric-ca-peerorg1-23033a"; //Only test with this CA
public static final String NETWORK_CONFIG_PEERORG_CA = "fabric-ca-peerorg1-20621a"; //Only test with this CA

public static final String NETWORK_CONFIG_PEERORG = "PeerOrg1"; //Only test with this peer org

public static final String TEST_CHANNEL = "ricks-test-channel";
public static final String TEST_CHANNEL = "java-test-channel";

static final SampleStore SAMPLE_STORE = new SampleStore(new File("bmxBlockChainSampleStore.properties"));

Expand Down Expand Up @@ -108,7 +108,8 @@ private void run(String[] args) throws Exception {
NetworkConfig.NetworkConfigUser networkConfigRegistrar = certificateAuthority.getRegistrar(PEER_ADMIN_NAME);
admin = SAMPLE_STORE.getMember(PEER_ADMIN_NAME, NETWORK_CONFIG_PEERORG);
admin.setEnrollmentSecret(networkConfigRegistrar.getEnrollSecret());
admin.setAffiliation(networkConfigRegistrar.getAffiliation());
if(networkConfigRegistrar.getAffiliation() != null)
admin.setAffiliation(networkConfigRegistrar.getAffiliation());
admin.setMspId(networkConfigRegistrar.getMspId());

}
Expand Down
36 changes: 27 additions & 9 deletions src/main/java/org/cr22rc/NetworkConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,9 @@ String getName() {
}

String getMspid() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would be careful here and in other places as I don't think these are optional. If they're not present probably should throw some type of exeception.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the field is required, should I remove the checking?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's one option. I would think better throwing an exception with an error that the field was missing from the NetworkConfig document.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Have you done some testing with this change ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I only do the testing with "affiliation" change from the Jason file. I will leave those fields untouched then

return value.getString("mspid");
if(value.containsKey("mspid"))
return value.getString("mspid");
return null;
}

public OrganizationConfig.CertificateAuthorityConfig getCertificateAuthority(String name) {
Expand Down Expand Up @@ -210,7 +212,9 @@ private CertificateAuthorityConfig(String name, JsonObject value, String mspid)
}

public String getCAName() {
return value.getString("caName");
if(value.containsKey("caName"))
return value.getString("caName");
return null;
}

NetworkConfigUser getRegistrar(String name) {
Expand All @@ -232,7 +236,8 @@ public Map<String, NetworkConfigUser> getRegistrars() {

NetworkConfigUser networkConfigUser = new NetworkConfigUser(registrar.getEnrollId(),
OrganizationConfig.this.getMspid(), registrar.getEnrollSecret());
networkConfigUser.affiliation = registrar.getAffiliation();
if(registrar.getAffiliation() != null)
networkConfigUser.affiliation = registrar.getAffiliation();

ret.put(registrar.getEnrollId(), networkConfigUser);

Expand Down Expand Up @@ -276,7 +281,9 @@ class PeerConfig extends EndPoint {
}

public String getEventURL() {
return value.getString("eventUrl");
if(value.containsKey("eventUrl"))
return value.getString("eventUrl");
return null;
}

}
Expand All @@ -292,15 +299,21 @@ class Registrar {
}

public String getEnrollId() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Again I think there would always be an id here

return value.getString("enrollId");
if(value.containsKey("enrollId"))
return value.getString("enrollId");
return null;
}

public String getAffiliation() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here this seems appropriate

return value.getString("affiliation");
if(value.containsKey("affiliation"))
return value.getString("affiliation");
return null;
}

public String getEnrollSecret() {
return value.getString("enrollSecret");
if(value.containsKey("enrollSecret"))
return value.getString("enrollSecret");
return null;
}

}
Expand All @@ -316,15 +329,20 @@ class EndPoint {
}

public String getURL() {
return value.getString("url");
if(value.containsKey("url"))
return value.getString("url");
return null;

}

public String getName() {
return name;
}

public String getTLSCerts() {
return value.getJsonObject("tlsCACerts").getString("pem");
if(value.containsKey("tlsCACerts"))
return value.getJsonObject("tlsCACerts").getString("pem");
return null;

}

Expand Down