Wednesday 14 December 2016

SOA Service Client : Create / Delete Relation In Teamcenter

How to create Relation between objects ?

Eg:
modObjprimary
|
|_modObjSecondary

private static void createRelations(ModelObject modObjprimary, ModelObject modObjSecondary, String sRelationName)
    {
        com.teamcenter.services.strong.core.DataManagementService dmService = com.teamcenter.services.strong.core.DataManagementService.getService(connection);
    

        Relationship[] relationShips = new Relationship[1];
        relationShips[0] = new Relationship();
        relationShips[0].clientId = "One" + System.currentTimeMillis();
        relationShips[0].primaryObject = modObjprimary;
        relationShips[0].secondaryObject = modObjSecondary;
        relationShips[0].relationType = sRelationName;

        CreateRelationsResponse response = dmService.createRelations(relationShips);
        if (response.serviceData.sizeOfPartialErrors() > 0)
        {
            processServiceDataForPartialErrors(response.serviceData);
        }

   }
How to Delete Relation in Teamcenter
public static boolean deleteRelation(Object leftObj, Object rightObj, String relName, DataManagementService dms)
           throws Exception
   {
      if (leftObj == null || rightObj == null)
        {
            return false;
        }
        Relationship relationship[] = new Relationship[1];
        relationship[0] = new Relationship();
        relationship[0].clientId = "anyid"; 
        relationship[0].primaryObject = (ModelObject) leftObj;
        relationship[0].relationType = relName;
        relationship[0].secondaryObject = (ModelObject) rightObj;
        relationship[0].userData = null;
        ServiceData serviceData = dms.deleteRelations(relationship);
        if (serviceData.sizeOfPartialErrors() == 0)
            return true;
        else
        {
            return false;
        }

    }

No comments:

Post a Comment