public String exportRepository(List<String> ids, String format) {
      StringBuilder result = new StringBuilder("{");
      ObjectMapper mapper = new ObjectMapper();

      // First, retrieve service list.
      List<Service> services = serviceRepository.findByIdIn(ids);
      try {
         String jsonArray = mapper.writeValueAsString(services);
         result.append("\"services\":").append(jsonArray).append(", ");
      } catch (Exception e) {
         log.error("Exception while serializing services for export", e);
      }

      // Then, get resources associated to services.
      List<Resource> resources = resourceRepository.findByServiceIdIn(ids);
      try {
         String jsonArray = mapper.writeValueAsString(resources);
         result.append("\"resources\":").append(jsonArray).append(", ");
      } catch (Exception e) {
         log.error("Exception while serializing resources for export", e);
      }

      // Finally, get requests and responses associated to the services.
      List<String> operationIds = new ArrayList<>();
      for (Service service : services) {
         for (Operation operation : service.getOperations()) {
            operationIds.add(IdBuilder.buildOperationId(service, operation));
         }
      }

      List<Request> requests = requestRepository.findByOperationIdIn(operationIds);
      List<Response> responses = responseRepository.findByOperationIdIn(operationIds);
      List<EventMessage> eventMessages = eventMessageRepository.findByOperationIdIn(operationIds);
      try {
         String jsonArray = mapper.writeValueAsString(requests);
         result.append("\"requests\":").append(jsonArray).append(", ");
         jsonArray = mapper.writeValueAsString(responses);
         result.append("\"responses\":").append(jsonArray).append(", ");
         jsonArray = mapper.writeValueAsString(eventMessages);
         result.append("\"eventMessages\":").append(jsonArray);
      } catch (Exception e) {
         log.error("Exception while serializing messages for export", e);
      }

      return result.append("}").toString();
   }
@Test
   void testExportRepository() {
      String result = service.exportRepository(ids, "json");

      ObjectMapper mapper = new ObjectMapper();

      // Check that result is a valid JSON object.
      JsonNode jsonObj = null;
      try {
         jsonObj = mapper.readTree(result);
      } catch (IOException e) {
         fail("No exception should be thrown when parsing Json");
      }

      try {
         // Retrieve and assert on services part.
         ArrayNode services = (ArrayNode) jsonObj.get("services");
         assertEquals(3, services.size());
         for (int i = 0; i < services.size(); i++) {
            JsonNode service = services.get(i);
            String name = service.get("name").asText();
            assertTrue("HelloWorld".equals(name) || "MyService-hello".equals(name));
         }
      } catch (Exception e) {
         fail("Exception while getting services array");
      }

      try {
         // Retrieve and assert on resources part.
         ArrayNode resources = (ArrayNode) jsonObj.get("resources");
         assertEquals(1, resources.size());
         JsonNode resource = resources.get(0);
         assertEquals("Resource 1", resource.get("name").asText());
         assertEquals("<wsdl></wsdl>", resource.get("content").asText());
      } catch (Exception e) {
         fail("Exception while getting resources array");
      }
   }