Adding parent/child relationships using SDK

Follow

Originally posted by ricardo.marques on 2012-03-13 13:28:57

The following request was received via support email:

Could you please give an example of setting (existing) parent for a managed object in java client development?

I tried the following but it seemed to have no effect on managed objects.

ManagedObjectRepresentation parentMO = … // get mo from inventory
ManagedObjectRepresentation childMO = … // creating manages object + set some properties
ManagedObjectReferenceRepresentation moRefRepr = new ManagedObjectReferenceRepresentation();
moRefRepr.setManagedObject( parentMO );
childMO.getParents().getReferences().add( moRefRepr );

User is running SDK 0.11.

We answered the support request with the following example of code (inventoryResource is an instance of InventoryApi):


ManagedObjectRepresentation moBridge = ….
ManagedObjectRepresentation mo11374857 = …
 
ManagedObjectReferenceRepresentation child2Ref = new ManagedObjectReferenceRepresentation();
child2Ref.setManagedObject(mo11374857);
 
       try {
           inventoryResource.getManagedObject(moBridge.getId()). addChildDevice(child2Ref);
       } catch (SDKException e1) {
           e1.printStackTrace();
       }

This method has been tested and should be thread-safe to add children objects to parent objects.
Have more questions? Submit a request

Comments