public boolean importRepository(String json) {
      ObjectMapper mapper = new ObjectMapper();
      ImportExportModel model = null;
      try {
         model = mapper.readValue(json, ImportExportModel.class);
      } catch (Exception e) {
         log.error("Exception while reading json import", e);
      }

      if (log.isInfoEnabled()) {
         log.info("Retrieve {} services to import into repository", model != null ? model.getServices().size() : 0);
         log.info("Retrieve {} resources to import into repository", model != null ? model.getResources().size() : 0);
         log.info("Retrieve {} responses to import into repository", model != null ? model.getResponses().size() : 0);
         log.info("Retrieve {} requests to import into repository", model != null ? model.getRequests().size() : 0);
         log.info("Retrieve {} event messages to import into repository",
               model != null && model.getEventMessages() != null ? model.getEventMessages().size() : 0);
      }
      if (model != null) {
         serviceRepository.saveAll(model.getServices());
         resourceRepository.saveAll(model.getResources());
         responseRepository.saveAll(model.getResponses());
         requestRepository.saveAll(model.getRequests());
         // Make it optional to allow importing an old snapshot.
         if (model.getEventMessages() != null) {
            eventMessageRepository.saveAll(model.getEventMessages());
         }

         // Once everything is saved, be sure to fire a change event to allow
         // propagation.
         for (Service service : model.getServices()) {
            publishServiceChangeEvent(service);
         }
         return true;
      }
      return false;
   }
@Test
   void testImportRepository() {
      // Setup and export result.
      String json = "{\"services\":[{\"name\":\"Imp1\",\"version\":\"1.2\",\"xmlNS\":null,\"type\":null,\"operations\":[],\"id\":25638445759706201468670970602},"
            + "{\"name\":\"Imp2\",\"version\":\"1.1\",\"xmlNS\":null,\"type\":null,\"operations\":[],\"id\":25638445759706201468670970603}], "
            + "\"resources\":[{\"name\":\"Resource 1\",\"content\":\"<wsdl></wsdl>\",\"type\":\"WSDL\",\"serviceId\":25638445759706201468670970602,\"id\":25638445759706201468670970605}], "
            + "\"requests\":[], \"responses\":[]}";

      boolean result = service.importRepository(json);

      // Get imported service and assert on content.
      Service service = repository.findByNameAndVersion("Imp1", "1.2");
      assertNotNull(service);
      assertEquals("Imp1", service.getName());
      assertEquals("1.2", service.getVersion());
      assertEquals("25638445759706201468670970602", service.getId().toString());

      // Get imported resources and assert on content.
      List<Resource> resources = resourceRepository.findByServiceId(service.getId());
      assertEquals(1, resources.size());
      assertEquals("Resource 1", resources.get(0).getName());
      assertEquals("<wsdl></wsdl>", resources.get(0).getContent());
      assertEquals(ResourceType.WSDL, resources.get(0).getType());
   }