private ViewConfigurationModel fetchAssocDefViewConfig(Association assocDef) {
   try {
     // Note: othersTopicTypeUri=null, the view config's topic type is unknown (it is
     // client-specific)
     ResultSet<RelatedTopic> configTopics =
         assocDef.getRelatedTopics(
             "dm4.core.aggregation",
             "dm4.core.assoc_def",
             "dm4.core.view_config",
             null,
             true,
             false,
             0,
             null);
     return new ViewConfigurationModel(DeepaMehtaUtils.toTopicModels(configTopics.getItems()));
   } catch (Exception e) {
     throw new RuntimeException(
         "Fetching view configuration for association definition " + assocDef.getId() + " failed",
         e);
   }
 }
 @Override
 public Topic fetchPartType(Association assoc) {
   Topic partTypeTopic = assoc.getTopic("dm4.core.part_type");
   // error check
   if (partTypeTopic == null) {
     throw new RuntimeException(
         "Invalid association definition: topic role dm4.core.part_type "
             + "is missing in "
             + assoc);
   }
   //
   return partTypeTopic;
 }
 private AssociationDefinitionModel fetchAssociationDefinition(
     Association assoc, String wholeTypeUri, String partTypeUri) {
   try {
     long assocId = assoc.getId();
     return new AssociationDefinitionModel(
         assocId,
         assoc.getTypeUri(),
         wholeTypeUri,
         partTypeUri,
         fetchWholeCardinality(assocId).getUri(),
         fetchPartCardinality(assocId).getUri(),
         fetchAssocDefViewConfig(assoc));
   } catch (Exception e) {
     throw new RuntimeException(
         "Fetching association definition failed (wholeTypeUri=\""
             + wholeTypeUri
             + "\", partTypeUri="
             + partTypeUri
             + ", "
             + assoc
             + ")",
         e);
   }
 }
 @Override
 public void writeTo(
     Association assoc,
     Class<?> type,
     Type genericType,
     Annotation[] annotations,
     MediaType mediaType,
     MultivaluedMap<String, Object> httpHeaders,
     OutputStream entityStream)
     throws IOException, WebApplicationException {
   try {
     BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(entityStream));
     assoc.toJSON().write(writer);
     writer.flush();
   } catch (Exception e) {
     throw new IOException("Writing message body failed (" + assoc + ")", e);
   }
 }