Reputation: 3317
When I try to call a transaction on an asset that is inherited from a abstract base class asset, the call fails with Error: Invalid or missing identifier for Type <type> in namespace <name.spa.ce>
user.cto
namespace com.aczire.alm.base.user
import com.aczire.alm.base.*
abstract participant User {
o String uid
o String title optional
o String firstName optional
o String lastName optional
o UserTransactionLogEntry[] logEntries
}
concept UserTransactionLogEntry {
//--> User modified_by
o String comment optional
o DateTime timestamp
}
abstract transaction UserTransaction {
o String comment
}
abstract event UserTransactionEvent {
o String comment
}
admin.cto
namespace com.aczire.alm.base.user.admin
import com.aczire.alm.base.*
import com.aczire.alm.base.user.*
participant Admin identified by uname extends User {
o String uname
}
abstract transaction AdminUserTransaction extends UserTransaction {
o Admin user
--> Admin modified_by
}
abstract event AdminUserTransactionEvent extends UserTransactionEvent {
--> Admin user
--> Admin modified_by
}
transaction CreateUser extends AdminUserTransaction {
}
admin.js
/**
* Create a User
* @param {com.aczire.alm.base.user.admin.CreateUser} createUser - the CreateUser transaction
* @transaction
*/
function createUser(newuser) {
console.log('createUser');
var factory = getFactory();
var NS_AU = 'com.aczire.alm.base.user.admin';
var user = factory.newResource(NS_AU, 'Admin', newuser.uname);
user.uid = newuser.uid;
// save the order
return getAssetRegistry(NS_AU)
.then(function (registry) {
return registry.add(user);
})
.then(function(){
var userCreatedEvent = factory.newEvent(NS_AU, 'UserCreatedEvent');
userCreatedEvent.user = user;
userCreatedEvent.comment = 'Created new admin user - ' + newuser.uname + '!';
emit(userCreatedEvent);
});
}
I tried making the parameters to the TP as User, Admin; moving the transaction arguments to base class as User type; moving the transaction to the base class etc.. But nothing seems to work.
Does the inheritance works differently here?
Error shown in composer playground.
Upvotes: 0
Views: 1616
Reputation: 147
Your admin.js has some issues. The error is because Admin is a participant so you have to getParticipantRegistry() not Assetregistry and then add the user. Also in your model file admin.cto there is no event named UserCreatedEvent. So you first need to add it to the model and then emit the event. To add the user try changing to this.
/**
* Create a User
* @param {com.aczire.alm.base.user.admin.CreateUser} createUser - the CreateUser transaction
* @transaction
*/
function createUser(newuser) {
console.log('createUser');
var NS_AU = 'com.aczire.alm.base.user.admin';
var factory = getFactory();
var testuser = factory.newResource(NS_AU, 'Admin', newuser.user.uname);
testuser.uid=newuser.user.uid
testuser.logEntries=newuser.user.logEntries
// save the order
return getParticipantRegistry('com.aczire.alm.base.user.admin.Admin')
.then(function (registry) {
return registry.add(testuser);
});
}
Upvotes: 1