Association between assets with JAXR in Centrasite 9.5 issue


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();
            for(CustomService item : services){
               createCustomService(item.getBusinessName(), item.getDescription(), item.getVersion(), item.getRationale(), item.getPhysicalName(), item.getProject(), item.getProjectRelationType());
      catch(JAXRException e)
         } finally {

   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);

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

The problem is in the as referred in

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)
    // 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
    // m3
    Collection<RegistryObject> tros = new ArrayList<RegistryObject>(); //
collection for all related services
    if (keepExisting) { // if service is already related to other services => keep
    // m4
    ro.setRelationShipValue(attribute,targetROs); // set the attribute and its
    // m5
    return ro;
}// end createRelationshipAttrib

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