Skip to content
This repository was archived by the owner on Mar 8, 2020. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
55 commits
Select commit Hold shift + click to select a range
781b6e9
409: Use ValueGenerator strategy for generating resource values
bestbeforetoday Mar 22, 2017
6ae5a56
Merge branch 'master' of github.com:fabric-composer/fabric-composer
bestbeforetoday Mar 23, 2017
39276a4
Merge branch 'master' of github.com:fabric-composer/fabric-composer
bestbeforetoday Mar 23, 2017
ef85b28
Use proper case for Data heading on Test page (#496)
bestbeforetoday Mar 23, 2017
4a9008a
Merge branch 'master' of github.com:fabric-composer/fabric-composer
bestbeforetoday Mar 24, 2017
259d3f9
Merge branch 'master' of github.com:fabric-composer/fabric-composer
bestbeforetoday Mar 28, 2017
9207f9a
Merge branch 'master' of github.com:fabric-composer/fabric-composer
bestbeforetoday Mar 31, 2017
eb9ce5d
Merge branch 'master' of github.com:fabric-composer/fabric-composer
bestbeforetoday Apr 4, 2017
ef9cbe5
Merge branch 'master' of github.com:fabric-composer/fabric-composer
bestbeforetoday Apr 7, 2017
e082798
Merge branch 'master' of github.com:fabric-composer/fabric-composer
bestbeforetoday Apr 18, 2017
b258cb2
Change generate option to a string on composer-common.Factory functions
bestbeforetoday Apr 18, 2017
10fcaa5
Merge branch 'master' of github.com:fabric-composer/fabric-composer
bestbeforetoday Apr 18, 2017
7a421f0
Merge branch 'master' of github.com:fabric-composer/fabric-composer
bestbeforetoday Apr 19, 2017
ed4661d
Merge branch 'master' of github.com:fabric-composer/fabric-composer
bestbeforetoday Apr 19, 2017
29899d4
Merge branch 'master' of github.com:hyperledger/composer
bestbeforetoday Apr 20, 2017
c294127
Change sed command for better compatibility (#1)
Apr 20, 2017
d056775
Merge branch 'master' into master
Apr 20, 2017
9b8aca5
Merge branch 'master' of github.com:hyperledger/composer
bestbeforetoday Apr 20, 2017
257a2ea
Merge branch 'master' of github.com:bestbeforetoday/hyperledger-composer
bestbeforetoday Apr 20, 2017
a6d35f6
Merge branch 'master' into master
dselman Apr 20, 2017
fdf1103
Merge branch 'master' of github.com:hyperledger/composer
bestbeforetoday Apr 21, 2017
44232ee
Merge branch 'master' into master
Apr 21, 2017
479b158
Merge branch 'master' of github.com:hyperledger/composer
bestbeforetoday Apr 25, 2017
5291c7e
Merge branch 'master' of github.com:hyperledger/composer
bestbeforetoday Apr 26, 2017
b85d897
Merge branch 'master' of github.com:bestbeforetoday/hyperledger-composer
bestbeforetoday Apr 26, 2017
88964e2
Merge branch 'master' of github.com:hyperledger/composer
bestbeforetoday May 2, 2017
b3dec7b
Merge branch 'master' of github.com:hyperledger/composer
bestbeforetoday May 2, 2017
bd60e8e
Merge branch 'master' of github.com:hyperledger/composer
bestbeforetoday May 3, 2017
8861a63
Merge branch 'master' of github.com:hyperledger/composer
bestbeforetoday May 5, 2017
8ce1639
Fix path name in weekly QA doc
bestbeforetoday May 5, 2017
f92c5d4
Merge branch 'master' of github.com:hyperledger/composer
bestbeforetoday May 9, 2017
43d1e37
Merge branch 'master' of github.com:hyperledger/composer
bestbeforetoday May 11, 2017
f5330f7
Merge branch 'master' of github.com:hyperledger/composer
bestbeforetoday May 19, 2017
3952e26
Merge branch 'master' of github.com:hyperledger/composer
bestbeforetoday May 20, 2017
59bab43
Merge branch 'master' of github.com:hyperledger/composer
bestbeforetoday May 22, 2017
47f8544
Merge branch 'master' of github.com:hyperledger/composer
bestbeforetoday May 25, 2017
6c8d535
Merge branch 'master' of github.com:hyperledger/composer
bestbeforetoday Jun 8, 2017
9c27886
Merge branch 'master' of github.com:hyperledger/composer
bestbeforetoday Jun 8, 2017
496cd4c
Merge branch 'master' of github.com:hyperledger/composer
bestbeforetoday Jun 8, 2017
6f6b981
Merge branch 'master' of github.com:hyperledger/composer
bestbeforetoday Jun 8, 2017
3aab55c
Merge branch 'master' of github.com:hyperledger/composer
bestbeforetoday Jun 9, 2017
ae6f3ed
Merge branch 'master' of github.com:hyperledger/composer into issue796
bestbeforetoday Jun 9, 2017
708585a
Merge branch 'master' of github.com:hyperledger/composer
bestbeforetoday Jun 9, 2017
5f2eab6
Merge branch 'master' into issue796
bestbeforetoday Jun 9, 2017
ded05f4
Merge branch 'master' of github.com:hyperledger/composer into issue796
bestbeforetoday Jun 13, 2017
ab61911
Refactor of Factory to remove duplicate code
bestbeforetoday Jun 14, 2017
7a9c059
Correct changelog.txt
bestbeforetoday Jun 14, 2017
7c77f50
Correct some logic errors getting class declarations
bestbeforetoday Jun 14, 2017
575aa31
Merge branch 'master' of github.com:hyperledger/composer into issue796
bestbeforetoday Jun 14, 2017
ca7d316
Increase unit test coverage
bestbeforetoday Jun 14, 2017
3ea8c68
Message and unit test improvements.
bestbeforetoday Jun 15, 2017
7921bee
Merge branch 'master' of github.com:hyperledger/composer into issue796
bestbeforetoday Jun 15, 2017
85010c7
Merge branch 'master' of github.com:hyperledger/composer into issue796
bestbeforetoday Jun 16, 2017
feec43b
Fix BusinessNetworkConnector tests for changes to error message text
bestbeforetoday Jun 16, 2017
9a456c3
Merge branch 'master' into issue796
dselman Jun 19, 2017
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
12 changes: 8 additions & 4 deletions packages/composer-common/api.txt
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ class BusinessNetworkMetadata {
class Factory {
+ void constructor(ModelManager)
+ Resource newInstance(string,string,string,Object,boolean,string) throws ModelException
+ Resource newResource(string,string,string,Object,boolean,string) throws ModelException
+ Resource newConcept(string,string,Object,boolean,string) throws ModelException
+ Relationship newRelationship(string,string,string) throws ModelException
+ Resource newResource(string,string,string,Object,boolean,string) throws TypeNotFoundException
+ Resource newConcept(string,string,Object,boolean,string) throws TypeNotFoundException
+ Relationship newRelationship(string,string,string) throws TypeNotFoundException
+ Resource newTransaction(string,string,string,Object,string)
+ Resource newEvent(string,string,string,Object,string)
+ Object toJSON()
Expand All @@ -45,7 +45,7 @@ class FileWallet extends Wallet {
+ Promise remove(string)
}
class IllegalModelException extends BaseException {
+ void constructor(string,string,string)
+ void constructor(String,ModelFile,Object,String,String,String,String)
+ string getModelFile()
+ string getFileLocation()
}
Expand Down Expand Up @@ -117,6 +117,10 @@ class Serializer {
class ValidationException extends BaseException {
+ void constructor(string)
}
class TypeNotFoundException extends BaseException {
+ void constructor(String,String)
+ string getTypeName()
}
class Wallet {
+ Wallet getWallet()
+ void setWallet(Wallet)
Expand Down
5 changes: 5 additions & 0 deletions packages/composer-common/changelog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@
# Note that the latest public API is documented using JSDocs and is available in api.txt.
#

Version 0.7.6 {1dbfded54f54b7861b8eadb64d95f82a} 2017-06-14
- Added TypeNotFoundException
- Corrected JSDoc for IllegalModelException.constructor
- Corrected JSDoc for Factory.newRelationship

Version 0.7.5 {b2c1c30d370b04c153426500a03c3061} 2017-06-07
- Added optional JSZip options parameter to toArchive

Expand Down
70 changes: 13 additions & 57 deletions packages/composer-common/lib/factory.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
const debug = require('debug')('ibm-concerto');
const Globalize = require('./globalize');

const ModelUtil = require('./modelutil');

const InstanceGenerator = require('./serializer/instancegenerator');
const ValueGeneratorFactory = require('./serializer/valuegenerator');
const ResourceValidator = require('./serializer/resourcevalidator');
Expand Down Expand Up @@ -86,7 +88,7 @@ class Factory {
* <dt>sample</dt><dd>return a resource instance with generated sample data.</dd>
* <dt>empty</dt><dd>return a resource instance with empty property values.</dd></dl>
* @return {Resource} the new instance
* @throws {ModelException} if the type is not registered with the ModelManager
* @throws {TypeNotFoundException} if the type is not registered with the ModelManager
*/
newResource(ns, type, id, options) {
if(!id || typeof(id) !== 'string') {
Expand All @@ -105,24 +107,9 @@ class Factory {
}));
}

let modelFile = this.modelManager.getModelFile(ns);
if(!modelFile) {
let formatter = Globalize.messageFormatter('factory-newinstance-notregisteredwithmm');
throw new Error(formatter({
namespace: ns
}));
}

if(!modelFile.isDefined(type)) {
let formatter = Globalize.messageFormatter('factory-newinstance-typenotdeclaredinns');

throw new Error(formatter({
namespace: ns,
type: type
}));
}
const qualifiedName = ModelUtil.getFullyQualifiedName(ns, type);
const classDecl = this.modelManager.getType(qualifiedName);

let classDecl = modelFile.getType(type);
if(classDecl.isAbstract()) {
let formatter = Globalize.messageFormatter('factory-newinstance-abstracttype');
throw new Error(formatter({
Expand Down Expand Up @@ -176,27 +163,11 @@ class Factory {
* <dt>sample</dt><dd>return a resource instance with generated sample data.</dd>
* <dt>empty</dt><dd>return a resource instance with empty property values.</dd></dl>
* @return {Resource} the new instance
* @throws {ModelException} if the type is not registered with the ModelManager
* @throws {TypeNotFoundException} if the type is not registered with the ModelManager
*/
newConcept(ns, type, options) {
let modelFile = this.modelManager.getModelFile(ns);
if(!modelFile) {
let formatter = Globalize.messageFormatter('factory-newinstance-notregisteredwithmm');
throw new Error(formatter({
namespace: ns
}));
}

if(!modelFile.isDefined(type)) {
let formatter = Globalize.messageFormatter('factory-newinstance-typenotdeclaredinns');

throw new Error(formatter({
namespace: ns,
type: type
}));
}

let classDecl = modelFile.getType(type);
const qualifiedName = ModelUtil.getFullyQualifiedName(ns, type);
const classDecl = this.modelManager.getType(qualifiedName);

if(classDecl.isAbstract()) {
let formatter = Globalize.messageFormatter('factory-newinstance-abstracttype');
Expand Down Expand Up @@ -247,29 +218,14 @@ class Factory {
* @param {string} type - the type of the Resource
* @param {string} id - the identifier
* @return {Relationship} - the new relationship instance
* @throws {ModelException} if the type is not registered with the ModelManager
* @throws {TypeNotFoundException} if the type is not registered with the ModelManager
*/
newRelationship(ns, type, id) {
let modelFile = this.modelManager.getModelFile(ns);
if(!modelFile) {
let formatter = Globalize.messageFormatter('factory-newrelationship-notregisteredwithmm');

throw new Error(formatter({
namespace: ns
}));
}

if(!modelFile.isDefined(type)) {
let formatter = Globalize.messageFormatter('factory-newinstance-typenotdeclaredinns');

throw new Error(formatter({
namespace: ns,
type: type
}));
}
// Load the type declaration to force an error if it doesn't exist
const fqn = ModelUtil.getFullyQualifiedName(ns, type);
this.modelManager.getType(fqn);

let relationship = new Relationship(this.modelManager,ns,type,id);
return relationship;
return new Relationship(this.modelManager, ns, type, id);
}

/**
Expand Down
10 changes: 2 additions & 8 deletions packages/composer-common/lib/globalize.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,8 @@ const messages = require('../messages/en.json');
function messageFormatter(message) {
return function (inserts) {
let result = messages.en[message];
if (Array.isArray(inserts)) {
for (let i = 0; i < inserts.length; i++) {
result = result.replace(new RegExp(`{${i}}`), inserts[i]);
}
} else {
for (let key in inserts) {
result = result.replace(new RegExp(`{${key}}`, 'g'), inserts[key]);
}
for (let key in inserts) {
result = result.replace(new RegExp(`\\{${key}\\}`, 'g'), inserts[key]);
}
return result;
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

const TransactionDeclaration = require('./transactiondeclaration');
const IllegalModelException = require('./illegalmodelexception');
const ModelUtil = require('../modelutil');
//const Globalize = require('../globalize');

/**
Expand Down Expand Up @@ -145,9 +146,9 @@ class FunctionDeclaration {
throw new IllegalModelException('Transaction processing function ' + this.name + ' must have 1 function argument of type transaction.' );
}
const transactionClassName = this.parameterTypes[0];
const classDecl = this.modelManager.getType(transactionClassName);

if(!(classDecl instanceof TransactionDeclaration)) {
if (ModelUtil.isPrimitiveType(transactionClassName) ||
!(this.modelManager.getType(transactionClassName) instanceof TransactionDeclaration)) {
throw new IllegalModelException('Function ' + this.getName() + ' processes ' + transactionClassName + ' which is not a transaction.');
}
}
Expand Down
12 changes: 8 additions & 4 deletions packages/composer-common/lib/introspect/illegalmodelexception.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,14 @@ const BaseException = require('../baseexception');
class IllegalModelException extends BaseException {

/**
* Create an IllegalModelException
* @param {string} message - the message for the exception
* @param {string} modelFile - the optional modelfile associated with the exception
* @param {string} fileLocation - the optional file location associated with the exception
* Create an IllegalModelException.
* @param {String} message - the message for the exception
* @param {ModelFile} [modelFile] - the optional modelfile associated with the exception
* @param {Object} [fileLocation] - location details of the error within the model file.
* @param {String} fileLocation.start.line - start line of the error location.
* @param {String} fileLocation.start.column - start column of the error location.
* @param {String} fileLocation.end.line - end line of the error location.
* @param {String} fileLocation.end.column - end column of the error location.
*/
constructor(message, modelFile, fileLocation) {

Expand Down
10 changes: 7 additions & 3 deletions packages/composer-common/lib/introspect/modelfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -164,9 +164,9 @@ class ModelFile {
const modelFile = this.getModelManager().getModelFile(importNamespace);
if (!modelFile) {
let formatter = Globalize.messageFormatter('modelmanager-gettype-noregisteredns');
throw new Error(formatter({
throw new IllegalModelException(formatter({
type: importName
}));
}), this);
}
if (ModelUtil.isWildcardName(importName)) {
// This is a wildcard import, org.acme.*
Expand All @@ -175,7 +175,11 @@ class ModelFile {
}
const importShortName = ModelUtil.getShortName(importName);
if (!modelFile.isLocalType(importShortName)) {
throw new Error('No type ' + importShortName + ' in namespace ' + importNamespace);
let formatter = Globalize.messageFormatter('modelmanager-gettype-notypeinns');
throw new IllegalModelException(formatter({
type: importShortName,
namespace: importNamespace
}), this);
}
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,12 @@ class RelationshipDeclaration extends Property {
classDeclaration = this.getParent().getModelFile().getType(this.getType());
}
else {
// otherwise we have to use the modelmanager to try to load
classDeclaration = this.getParent().getModelFile().getModelManager().getType(this.getFullyQualifiedTypeName());
// otherwise we have to use the modelmanager to try to load
try {
classDeclaration = this.getParent().getModelFile().getModelManager().getType(this.getFullyQualifiedTypeName());
} catch (err) {
// Let classDeclaration remain null and get handled below
}
}

if(classDeclaration === null) {
Expand Down
94 changes: 44 additions & 50 deletions packages/composer-common/lib/modelmanager.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ const Globalize = require('./globalize');
const IllegalModelException = require('./introspect/illegalmodelexception');
const ModelUtil = require('./modelutil');
const ModelFile = require('./introspect/modelfile');
const TypeNotFoundException = require('./typenotfoundexception');

/**
* <p>
Expand Down Expand Up @@ -229,41 +230,37 @@ class ModelManager {
/**
* Check that the type is valid and returns the FQN of the type.
* @param {string} context - error reporting context
* @param {string} type - a short type name
* @param {string} type - fully qualified type name
* @return {string} - the resolved type name (fully qualified)
* @throws {IllegalModelException} - if the type is not defined
* @private
*/
resolveType(context, type) {
// is the type a primitive?
if (!ModelUtil.isPrimitiveType(type)) {

let ns = ModelUtil.getNamespace(type);
let modelFile = this.getModelFile(ns);

if (!modelFile) {
let formatter = Globalize.messageFormatter('modelmanager-resolvetype-nonsfortype');
throw new IllegalModelException(formatter({
type: type,
context: context
}));
}
if (ModelUtil.isPrimitiveType(type)) {
return type;
}

if (!modelFile.isLocalType(type)) {
let formatter = Globalize.messageFormatter('modelmanager-resolvetype-notypeinnsforcontext');
throw new IllegalModelException(formatter({
context: context,
type: type,
namespace: modelFile.getNamespace()
}));
}
else {
return type;
}
let ns = ModelUtil.getNamespace(type);
let modelFile = this.getModelFile(ns);
if (!modelFile) {
let formatter = Globalize.messageFormatter('modelmanager-resolvetype-nonsfortype');
throw new IllegalModelException(formatter({
type: type,
context: context
}));
}
else {

if (modelFile.isLocalType(type)) {
return type;
}

let formatter = Globalize.messageFormatter('modelmanager-resolvetype-notypeinnsforcontext');
throw new IllegalModelException(formatter({
context: context,
type: type,
namespace: modelFile.getNamespace()
}));
}

/**
Expand Down Expand Up @@ -294,35 +291,32 @@ class ModelManager {
/**
* Look up a type in all registered namespaces.
*
* @param {string} type - the fully qualified name of a type
* @return {ClassDeclaration} - the class declaration or null for primitive types
* @throws {Error} - if the type cannot be found
* @param {string} qualifiedName - fully qualified type name.
* @return {ClassDeclaration} - the class declaration for the specified type.
* @throws {TypeNotFoundException} - if the type cannot be found or is a primitive type.
* @private
*/
getType(type) {
// is the type a primitive?
if (!ModelUtil.isPrimitiveType(type)) {
let ns = ModelUtil.getNamespace(type);
let modelFile = this.getModelFile(ns);

if (!modelFile) {
let formatter = Globalize.messageFormatter('modelmanager-gettype-noregisteredns');
throw new Error(formatter({
type: type
}));
}

let classDecl = modelFile.getType(type);

if (!classDecl) {
throw new Error('No type ' + type + ' in namespace ' + modelFile.getNamespace());
}

return classDecl;
getType(qualifiedName) {
const namespace = ModelUtil.getNamespace(qualifiedName);

const modelFile = this.getModelFile(namespace);
if (!modelFile) {
const formatter = Globalize.messageFormatter('modelmanager-gettype-noregisteredns');
throw new TypeNotFoundException(qualifiedName, formatter({
type: qualifiedName
}));
}
else {
return null;

const classDecl = modelFile.getType(qualifiedName);
if (!classDecl) {
const formatter = Globalize.messageFormatter('modelmanager-gettype-notypeinns');
throw new TypeNotFoundException(qualifiedName, formatter({
type: ModelUtil.getShortName(qualifiedName),
namespace: namespace
}));
}

return classDecl;
}

/**
Expand Down
Loading