Association between assets with JAXR in Centrasite 9.5 issue

Hi,

I’m building a JAVA application to bulk load assets (custom asset type) from CSV file to Centrasite 9.5 via JAXR.

It works fine except that only the last asset retains the association (relationship), I think it is because it’s the last relationship created before disconnection from Centrasite.

The code I’m using is below, can someone give an hint on how to solve this without having to close the connection for each asset?


   public static void loadListOfServices() throws IOException {
      List<CustomService> services = readFromCSV();
      try
         {
            connectToCentrasite();            
            for(CustomService item : services){
               createCustomService(item.getBusinessName(), item.getDescription(), item.getVersion(), item.getRationale(), item.getPhysicalName(), item.getProject(), item.getProjectRelationType());
            }
         }
      catch(JAXRException e)
         {
            LOGGER.error(e);
         } finally {
            disconnectFromCentrasite();
         }
   }

   public static void createCustomService(String customServiceName, String customServiceDescription, String customVersionValue, String customRationaleValue, 
                                                          String customPhysicalName, String projectName, String relationType) throws JAXRException{
                                                          
                                                          
            RegistryEntry customService = centrasiteService.createUserObject(customServiceName, customServiceDescription, centrasiteService.getCustomServiceType());
            
            centrasiteService.addSlotToObject(customService, "Rationale", customRationaleValue , CentraSiteSlotType.XS_STRING);
            
            centrasiteService.addSlotToObject(customService, "Version", customVersionValue, CentraSiteSlotType.XS_STRING);
            
            centrasiteService.addSlotToObject(customService, "PhysicalServices", customPhysicalName, CentraSiteSlotType.XS_STRING);
            
            RegistryEntry customProjectToRelate = centrasiteService.findUserObject(projectName, centrasiteService.getCustomProjectType());
            RegistryEntry relatedObject = centrasiteService.createRelationshipAttribute(customProjectToRelate, customService, centrasiteService.getCustomProjectType(), relationType, true);
            
            centrasiteService.saveObject(relatedObject);
            centrasiteService.saveObject(customService);
            centrasiteService.saveObject(customProjectToRelate);
    }

I found the problem and I post the solution so it can help someone with the same problem.

The problem is in the JAXRHandler.java as referred in http://techcommunity.softwareag.com/documents/portlet_file_entry/10157/BasicTutorialonCentraSiteAPIforJAXR.pdf/d7267364-ca66-44d9-b52c-9d717e6d61c3?status=0

In this class the method that creates the relationship is not correct.
The method allows to define if the existing relations should be maintained, if “keepExisting” is true it gets the existing relations to a collection, but does not use this collection.

In the code shown in “Listing 2.4.2a: add association attribute”


public CentraSiteRegistryObject
createRelationshipAttribute(CentraSiteRegistryObject ro, String type, String
relationshipName,Collection<RegistryObject> targetROs,
                                                            Boolean keepExisting)
throws JAXRException{
    // m0
    RegistryService regService = con.getRegistryService();
    CentraSiteQueryManager cqm = (CentraSiteQueryManager)
regService.getBusinessQueryManager();
    // m1
    CentraSiteTypeDescription td = cqm.getTypeDescription(type);// type description
of desired type
    // m2
    CentraSiteRelationShipAttribute attribute = null;
    for (CentraSiteRelationShipAttribute ca : td.getRelationShipAttributes()) {//
search for the attribute with the right name
  if (ca.getName().equals(relationshipName)) {
      attribute = ca;// initialize the attribute
      break;
  }
    }
    // m3
    Collection<RegistryObject> tros = new ArrayList<RegistryObject>(); //
collection for all related services
    tros.addAll(targetROs);
    if (keepExisting) { // if service is already related to other services => keep
them
 tros.addAll(ro.getRelationShipValue(attribute));
    }
    // m4
    ro.setRelationShipValue(attribute,targetROs); // set the attribute and its
values
    // m5
    return ro;
}// end createRelationshipAttrib

Change - ro.setRelationShipValue(attribute,targetROs); for ro.setRelationShipValue(attribute,tros);