Cannot instantiate Abstract Type when creating participant or asset in composer-rest-server - hyperledger-fabric

My model is as follows
abstract concept Address {
o String street
o String zip
o String city
o String country
}
participant Actor identified by userId {
o String userId
o String firstName
o String name
o Address address
}
When I POST a new Actor in composer rest server, I get the following error
"Cannot instantiate Abstract Type Address in namespace
io.mydomain.myapp",
What am I missing out on here ?

Abstract types are not meant to be instantiated so no wonder that it can't be created.
Read: https://hyperledger.github.io/composer/latest/reference/cto_language
Specifically this quote is of interest:
An optional 'abstract' declaration, to indicate that this type cannot
be created. Abstract resources can be used as a basis for other
classes to extend. Extensions of abstract classes do not inherit the
abstract status. For example, the asset Vehicle defined above should
never be created, as there should be more specific asset classes
defined to extend it.
Consider the Concepts subheading of the docs.
TL;DR: Read the documentation.

Related

Query the hazelcast data having inner object arrays using predicate

I have a user Object, Which has inner Object of type Address. Below are the structures of both User and Address.
User{
String name;
String id;
String phoneNumber;
List<Address> address
}
Address{
String type;
String streetName;
String houseNumber;
String Country;
int pin
}
I am storing the User Objects to the Hazelcast Cache. I would like to query Users whose address type is "Primary" and Country is "US".
The problem I am seeing is that each user can have multiple addresses, How to loop through the address and find the one with type "Primary" and for that particular address type how to query the Country "US". Can we use predicate to achieve this? If so, Please help me with how the predicate can be constructed.
Please check Querying in Collections and Arrays in the Hazelcast documentation.
In your case, you would like to have two conditions on the dependent collection, like:
Predicates.equal("address[any].country", "US")
Predicates.equal("address[any].type", "Primary")
But any should apply to the same entity (because you'd like to have US as Primary country). I don't think you can achieve it with just Predicates.
What you can do, however, is to use Custom Attributes and define your own ValueExtractor which would cover the logic you need.

Xtext DSL editor referring to the Java classes defined in my model

I have set of java classes and I want to refer them in the DSL which I am trying to edit using Xtext grammar. e.g. There is a class Employee :
class Employee{
String name;
double salary;
String organisation;
String status;
}
Now in my DSL I wish to use them. Hence when user is trying the name he should get these tree attributes as help. e.g. DSL i will like to trite like this:
employee.salary > 100000 then employee.status='GOLD'
My question is when i am typing the name such as employee than all the three attributes should be available to user as context help.

UML class diagram dependency or association

I'm not really sure about how to distinguish whether I should define a relationship as dependency or association for certain cases.
For example,
class AttendanceSheet {
Map<String> students;
boolean[] attend;
public void addStudent(Student s)
{
students.add(s.getName(),s.getStudentNumber());
}
public void checkAttendance(String name) { //... }
}
class Student {
private String name;
private int staffNumber;
//more information such as address, age, etc..
Student(String n, int sn)
{
name = n;
studentNumber = sn;
}
public String getName()
{
return name.clone();
}
public String getStudentNumber()
{
return studentNumber;
}
}
For this case, would Student and Association have association or dependency?
This is because I'm not sure whether the association must have the actual reference of the object or it suffice to just have certain information that can reach the object (since student id and number is far more enough to know find out which student object it is directing to).
In your case the <<uses>> is sufficient, because you don't have actual properties of type Student in AttendanceSheet.
As a side note: not using object references and instead just having the studentNumber is - to say the least - an odd design. But I don't know the context.
On the business level those objects are related, but there is no single preferred method of diagramming this relationship.
Please see Section 9.5.4 of UML specification for more details on the topic, especially Figure 9.12
To be specific those two notations are semantically equivalent (I'm ignoring irrelevant details):
In the first one to keep a traceability you can use an explicit Dependency pretty much the way you did.
One can also consider students as a Shared Aggregation, however it might be also considered an overkill. Not necessary, just showing a possibility for an answer completeness.
You may also consider Qulified associations to indicate a reference to the Student is based on their specific properties. This is pretty much closest to your need. Sorry, I don't know how to achieve such notation in my tool, but you can find more details in Figure 11.37 in Section 11.5 of the aforementioned specification.

JAXB Marshaller | ValidationEventHandler how to get whole complex object in locator

I am using JAXB javax.xml.bind.Marshaller to marshal XML and also doing XSD validation as a part of it.
My object to be marshal is of complex type like below
I have complex class like below
class A{
private B b;
private C c;
}
where B and C are other classes.
In case of XSD validation failure, I am getting proper error message in configured javax.xml.bind.ValidationEventHandler.
but the problem is, I am getting locator.object only either B or C where XSD validation fails.
[severity=FATAL_ERROR,message=cvc-maxLength-valid: Value 'test' with length = '4' is not facet-valid with respect to maxLength '1' for type '#AnonType_xxxxx'.,locator=[url=null,line=-1,column=-1,node=null,object=com.....C#1f4304be,field=null]]
Here, Is there any way that along with above message I can get always a full class object i.e. object=com.....A#1f4304be so that I can cast it and use for my futher business processing.
The challenge is Class B is the only class which contains unique identifier of users and hence whenever there is a failure for class C only, I am not able to find for which user, this failed as Class C does not have any unique information about user.
Seeking for advice and solution!

C# Inheritance access confusion

public class ABC
{
}
public class DEF : ABC
{
}
public class Class1
{
ABC abc = new DEF(); //No error
DEF def = new ABC(); //Compile time error
}
Can anyone explain to me this scenario.
and under what circumstances we might use it.
Its because as per the OOD rule you can assign child to parent but you cannot assign parent to child.
//this possible as you re assigning child to parent
ABC abc = new DEF(); //No error
//this is illegal as you are trying to assign child to parent directly
DEF def = new ABC(); //Compile time error
Reconsider your design again or if you want to convert parent object to child than you need method for that conversion directly its not possible to do it as per OOD rules.
Consider real time example relation of Customer and RetailCustomer or Corporatecustomer of bank. Where you can easily say RetailCustomer or CorporateCustomer is Customer, but you cannot say Customer is RetailCustomer or CorporateCustomer because customer can be of any type.
Same goes for relation between Parent Shape Class and Child Rectangle,Circle etc. class.
This is called as Ploymorphism .
As explained in MSDN
At run time, objects of a derived class may be treated as objects of a
base class in places such as method parameters and collections or
arrays. When this occurs, the object's declared type is no longer
identical to its run-time type.
Base classes may define and implement virtual methods, and derived
classes can override them, which means they provide their own
definition and implementation. At run-time, when client code calls the
method, the CLR looks up the run-time type of the object, and invokes
that override of the virtual method. Thus in your source code you can
call a method on a base class, and cause a derived class's version of
the method to be executed.
The answer of for this question is best explained here MSDN Polymorphism
Let's say ABC is Person, while DEF is Student (which is a subclass of Person). You can always treat a Student as a Person, so the assignment to abc (of type Person) of a Student is correct, but you cannot treat a generic Person as Student, so the assignment to def is wrong (for instance, you cannot get the student number of a person which is not a student)

Resources