How to create an object/entity XOM-BOM using lists - ibm-odm

I need create object with an attribute that is based on a list of other objects. By default when creating a XOM using XSD, Rule Designer assigns lists as vector of java object. I need some orientation how to verbalize and instantiate the list and add the object members.

You need to create a separate Class of Objects you want to store in the list. After that you have to create a list type variable in your Request Class. "listOfMyObjects" as an example. Then, after updating your BOM instance, you will see a new member in it. You can verbolize it as you need. "{list of my objects} from {this}", where the "my object" itself have to be verbolized as well, as an example.
After that you can work with the list in your rules like that:
definition: make this object equals to any of My Object from list of my objects
if: your condition
then: add new object to list of my objects

Related

Programmatically assign python3 class instance attributes

I may have a few dozen different classes instances with varying attributes that I just need to put patterns/random values into and don't want to have to manually code it all out. Is there a way to loop thru the attributes in a class instance?
For example:
class test_class:
attr1=0
attr2=0
attr3=0
i=test_class()
#How do I do the below in a loop without knowing the attribute names?
i.attr1=1
i.attr2=1
i.attr3=1
I know how I can get a list/dict of the attributes, but how do I do it so I can assign values to those attributes? How do I programmatically loop thru the class instance attributes and assign new values?
if you know the attribute names you can just use setattr
If you just want to get a list of all object's attributes you can use dir

how to create an object (call the constructor) from a BOM member in a BAL rule? IBM ODM

I have requirement in BAL rule to create objects and add them to a list
For instance, Customer is a class with below members
1. Name
2. Location
Based on the 'if' condition of the BAL rule, need to create objects of Type Customer and add them to Customerlist.
I tried to create objects by creating method in the Customer class in BOM editor by following steps provided under this link
how to create an object (call the constructor) from a BOM member on a decision table action column?
But I'm getting below error:
'Incompatible value in the 'return' instruction'
Can anyone please provide detailed steps to create objects and add them to a list in BAL?
Constructors are not directly verbalized in the BOM. You can create a method in XOM which creates the object via constructor and you can map this method onto BOM and verbalize it to be used in rule artifacts.
My suggestion to your scenario would be:
Create a verbalization in the XOM to receive the elements that will be added to the main list (Composite pattern).
Verbalize it
Add it in your Action Column (i.e. within a Decision Table)
I used this approach with great success in several scenarios, with no lack of performance.
Hope this helps.
Create an object and adding it to a list should be two separate methods.
Create: Assuming you followed the recipe for the link you provided, you should have a BOM method called createCustomer() on the Customer BOM class. Since there is no XOM to back that BOM method, you must supply B2X code for that method. Most people refer to such as a method as a virtual BOM method. It would be helpful to see the B2X code for that method. Are your BOM and XOM classes the same type? If not, you would have specified an execution name for the Customer BOM class. In that case, you may need to cast the return value of the createCustomer() BOM method to the Customer BOM class.
// Verbalize as: new customer
Customer Customer.createCustomer()
return (Customer) new OtherCustomerClassFromXOM();
Add: Define another virtual BOM method on some class, and name the method addCustomer(Customer customer). Usually it would be on the class that contained the list variable as a member. But if the list variable is a global variable (i.e., a ruleset variable), then the method could be a static member on any class, even your Customer class.
// Verbalize as: add {0} to {1}
void Customer.addCustomer(Customer customer, java.util.Collection customerList)
if (customerList == null) {
customerList = new java.util.ArrayList();
}
customerList.add(customer);

Sharepoint Extenal List and Custom Field Types

I have an odd issue.
I have client that wants a sharepoint list what is populated from a WCFService. That part is working quite well.
I have a bdcmodel that is mapping the WCF data and I can create an external list from the bdcmodel as well so that is working fine.
The issue I have is that one of the properties in the model is actually a collection of entities called Attributes. The objects in this collection simply have 2 properties Name and Value so really they are just a key value pair.
The client wants to see the list of attributes of the parent entity in the external list. So there would be an Attributes column and within that column would be the list of attributes for each parent object.
Is there even a way to do this? I am looking into Custom Field Types, but it seems like these are really intended to be singular values.
How would I create a list within and external list?
Any help anyone can give would be great even if its just to tell me that there really isn't a stable way to do this so I can go back to the client and tell them we will need to build a custom list to support this because the OOB external list and custom fields and custom field types won't support this kind of nested listing.
I decided to set up the custom field as a string and when I get my collection in from the BdcModel I am serializing it to JSON and then passing it to the field. When the field is viewed in display, edit or new I have overridden the FieldRenderingControl and I am tiling the collection out that way.

System.ComponentModel.BindingList: Add(object) vs. AddNew()

What is the difference between the System.ComponentModel.BindingList methods Add(object) and AddNew()? The MSDN documentation says this:
Add: Adds an object to the end of the Collection<T>.
AddNew: Adds a new item to the collection.
It seems like both methods add an item to the collection, but Add(object) does it in one shot whereas AddNew() is slightly more complicated. My tests with Add(object) seem to be working, but I want to know if I am using the correct method.
So what is the difference between these methods?
AddNew() creates the object for you (that's why it doesn't have a parameter).
It's designed to be used by grids, which don't know how to create a new object to pass to Add().
AddNew() is very handy (it’s the well-known Factory design pattern) when you implement a class derived of BindingList().
It allows your code to initialize new items with values that depend on the list itself - e.g. a foreign key to the parent object if the binding list contains a list of children.

Sharepoint : Prevent a feature from activating on a condition

I made a feature that creates a list with some default data (with a list definition and all required XML)
I observed that when the list already exists, the data will be inserted again in the list... So I tried to make a "FeatureReceiver" to prevent the feature from creating the list if it already exists, but the base class of FeatureReceiver is an abstract class, so even if the list doesn't exists, I can't "call" the base function to continue the normal process...
Is there an easy way to do this or will I have to create the list through the FeatureReceiver by calling the XML file?
I would suggest that you create the lists and all the other stuff you have to do (add/remove fields, contenttypes etc) all through code. I usually never create any lists through xml. This might give you some guidance:
http://johanleino.wordpress.com/2009/08/12/howto-add-splist-based-on-a-custom-template/

Resources