forked from hyperledger-archives/composer
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' of https://github.com/fabric-composer/fabric-co…
- Loading branch information
Showing
17 changed files
with
206 additions
and
113 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
<!--- Provide a general summary of the pull request in the Title above --> | ||
|
||
## Checklist | ||
[ ] A link to the issue/user story that the pull request relates to | ||
[ ] How to recreate the problem without the fix | ||
[ ] Design of the fix | ||
[ ] How to prove that the fix works | ||
[ ] Automated tests that prove the fix keeps on working | ||
[ ] Documentation - any JSDoc, website, or Stackoverflow answers? | ||
|
||
|
||
## Issue/User story | ||
<!--- What issue / user story is this for --> | ||
|
||
## Steps to Reproduce | ||
<!--- Provide a link to a live example, or an unambiguous set of steps to --> | ||
<!--- reproduce this bug include code to reproduce, if relevant --> | ||
1. | ||
2. | ||
3. | ||
4. | ||
|
||
|
||
## Existing issues | ||
<!-- Have you searched for any existing issues or are their any similar issues that you've found? --> | ||
- [ ] [StackOverflow issues](http://stackoverflow.com/tags/fabric-composer) | ||
- [ ] [GitHub Issues](https://github.com/fabric-composer/fabric-composer/issues) | ||
- [ ] [Rocket Chat history](https://chat.hyperledger.org/channel/fabric-composer) | ||
|
||
<!-- please include any links to issues here --> | ||
|
||
## Design of the fix | ||
<!-- Focus on why you designed this fix this way, and what was discounted. Do not describe just the code - we can read that! --> | ||
|
||
## Validation of the fix | ||
<!-- Over and above the tests, what has been done to prove this works? --> | ||
|
||
## Automated Tests | ||
<!-- Please describe the automated tests that are put in place to stop this recurring --> | ||
|
||
## What documentation has been provided for this pull request | ||
<!-- JSDocs, WebSite and answers to StackOverflow questions are possible documentation sources --> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
machine: | ||
node: | ||
version: 6.9.5 | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -51,36 +51,49 @@ class BusinessNetworkDefinition { | |
* </p> | ||
* @param {String} identifier - the identifier of the business network. The | ||
* identifier is formed from a business network name + '@' + version. The | ||
* version is a semver valid version string. | ||
* @param {String} description - the description of the business network | ||
* @param {String} readme - the optional readme in markdown for the business network | ||
* version is a semver valid version string. If package.json is passed this is ignored. | ||
* @param {String} description - the description of the business network. If package.json is passed then this is ignored. | ||
* @param {object} packageJson - the JS object for package.json (optional) | ||
* @param {String} readme - the readme in markdown for the business network (optional) | ||
*/ | ||
constructor(identifier, description, readme) { | ||
constructor(identifier, description, packageJson, readme) { | ||
const method = 'constructor'; | ||
LOG.entry(method, identifier, description); | ||
this.identifier = identifier; | ||
|
||
const atIndex = this.identifier.lastIndexOf('@'); | ||
// if package.json is not present we generate one based on the metadata passed | ||
if(!packageJson) { | ||
const atIndex = identifier.lastIndexOf('@'); | ||
let name = null; | ||
|
||
if (atIndex >= 0) { | ||
this.name = this.identifier.substring(0, atIndex); | ||
} else { | ||
throw new Error('Malformed business network identifier. It must be "[email protected]"'); | ||
} | ||
if (atIndex >= 0) { | ||
name = identifier.substring(0, atIndex); | ||
} else { | ||
throw new Error('Malformed business network identifier. It must be "[email protected]"'); | ||
} | ||
|
||
const version = identifier.substring(atIndex + 1); | ||
if (!semver.valid(version)) { | ||
throw new Error('Version number is invalid. Should be valid according to semver but found: ' + version); | ||
} | ||
|
||
this.version = this.identifier.substring(atIndex + 1); | ||
if (!semver.valid(this.version)) { | ||
throw new Error('Version number is invalid. Should be valid according to semver but found: ' + this.version); | ||
packageJson = {}; | ||
packageJson.name = name; | ||
packageJson.version = version; | ||
packageJson.description = description; | ||
LOG.debug(method, 'Created package.json' + JSON.stringify(packageJson)); | ||
} | ||
else { | ||
LOG.debug(method, 'Using package.json' + JSON.stringify(packageJson)); | ||
} | ||
|
||
this.description = description; | ||
this.modelManager = new ModelManager(); | ||
this.aclManager = new AclManager(this.modelManager); | ||
this.scriptManager = new ScriptManager(this.modelManager); | ||
this.introspector = new Introspector(this.modelManager); | ||
this.factory = new Factory(this.modelManager); | ||
this.serializer = new Serializer(this.factory, this.modelManager); | ||
this.metadata = new BusinessNetworkMetadata(readme); | ||
|
||
this.metadata = new BusinessNetworkMetadata(packageJson,readme); | ||
LOG.exit(method); | ||
} | ||
|
||
|
@@ -89,7 +102,7 @@ class BusinessNetworkDefinition { | |
* @return {String} the identifier of this business network | ||
*/ | ||
getIdentifier() { | ||
return this.identifier; | ||
return this.getMetadata().getIdentifier(); | ||
} | ||
|
||
/** | ||
|
@@ -105,7 +118,7 @@ class BusinessNetworkDefinition { | |
* @return {String} the name of this business network | ||
*/ | ||
getName() { | ||
return this.name; | ||
return this.getMetadata().getName(); | ||
} | ||
|
||
/** | ||
|
@@ -114,7 +127,7 @@ class BusinessNetworkDefinition { | |
* to parse. | ||
*/ | ||
getVersion() { | ||
return this.version; | ||
return this.getMetadata().getVersion(); | ||
} | ||
|
||
|
||
|
@@ -123,7 +136,7 @@ class BusinessNetworkDefinition { | |
* @return {String} the description of this business network | ||
*/ | ||
getDescription() { | ||
return this.description; | ||
return this.getMetadata().getDescription(); | ||
} | ||
|
||
/** | ||
|
@@ -211,10 +224,7 @@ class BusinessNetworkDefinition { | |
return Promise.all(allPromises) | ||
.then(() => { | ||
LOG.debug(method, 'Loaded package.json'); | ||
let packageName = packageJsonContents.name; | ||
let packageVersion = packageJsonContents.version; | ||
let packageDescription = packageJsonContents.description; | ||
businessNetworkDefinition = new BusinessNetworkDefinition(packageName + '@' + packageVersion, packageDescription, readmeContents); | ||
businessNetworkDefinition = new BusinessNetworkDefinition(null, null, packageJsonContents, readmeContents); | ||
|
||
LOG.debug(method, 'Loaded all model, JavaScript, and ACL files'); | ||
LOG.debug(method, 'Adding model files to model manager'); | ||
|
@@ -247,12 +257,7 @@ class BusinessNetworkDefinition { | |
|
||
let zip = new JSZip(); | ||
|
||
let packageFileContents = JSON.stringify({ | ||
name: this.name, | ||
version: this.version, | ||
description: this.description | ||
}); | ||
|
||
let packageFileContents = JSON.stringify(this.getMetadata().getPackageJson()); | ||
zip.file('package.json', packageFileContents); | ||
|
||
// save the README.md if present | ||
|
@@ -370,11 +375,9 @@ class BusinessNetworkDefinition { | |
// parse the package.json | ||
let jsonObject = JSON.parse(packageJsonContents); | ||
let packageName = jsonObject.name; | ||
let packageVersion = jsonObject.version; | ||
let packageDescription = jsonObject.description; | ||
|
||
// create the business network definition | ||
const businessNetwork = new BusinessNetworkDefinition(packageName + '@' + packageVersion, packageDescription, readmeContents); | ||
const businessNetwork = new BusinessNetworkDefinition(null, null, jsonObject, readmeContents); | ||
const modelFiles = []; | ||
const modelFileNames = []; | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -41,7 +41,7 @@ describe('BusinessNetworkDefinition', () => { | |
}); | ||
|
||
it('should accept README', () => { | ||
const bnd = new BusinessNetworkDefinition('[email protected]', 'description', 'readme'); | ||
const bnd = new BusinessNetworkDefinition('[email protected]', 'description', null, 'readme'); | ||
bnd.getMetadata().getREADME().should.equal('readme'); | ||
}); | ||
}); | ||
|
@@ -97,6 +97,7 @@ describe('BusinessNetworkDefinition', () => { | |
businessNetwork.getVersion().should.equal('0.0.1'); | ||
businessNetwork.getDescription().should.equal('A test business network.'); | ||
businessNetwork.getMetadata().getREADME().should.equal('This is a test'); | ||
businessNetwork.getMetadata().getPackageJson().customKey.should.equal('custom value'); | ||
Object.keys(businessNetwork.modelManager.modelFiles).should.have.length(3); | ||
Object.keys(businessNetwork.scriptManager.scripts).should.have.length(2); | ||
businessNetwork.aclManager.getAclRules().should.have.length(5); | ||
|
@@ -141,8 +142,8 @@ describe('BusinessNetworkDefinition', () => { | |
let readFile = fs.readFileSync(__dirname + '/data/zip/test-archive.zip'); | ||
return BusinessNetworkDefinition.fromArchive(readFile).then((businessNetwork) => { | ||
businessNetwork.should.be.BusinessNetworkDefinition; | ||
businessNetwork.identifier.should.equal('[email protected]'); | ||
businessNetwork.description.should.equal('A test business network.'); | ||
businessNetwork.getIdentifier().should.equal('[email protected]'); | ||
businessNetwork.getDescription().should.equal('A test business network.'); | ||
businessNetwork.getMetadata().getREADME().should.equal('This is a test'); | ||
Object.keys(businessNetwork.modelManager.modelFiles).should.have.length(3); | ||
Object.keys(businessNetwork.scriptManager.scripts).should.have.length(2); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 2 additions & 1 deletion
3
packages/composer-common/test/data/zip/test-archive/package.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
{ | ||
"name": "test-archive", | ||
"version": "0.0.1", | ||
"description": "A test business network." | ||
"description": "A test business network.", | ||
"customKey": "custom value" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.