@Test public void getAllXmiFormat() throws EncodingException, IOException { final AtomicReference<JsonNode> response = new AtomicReference<>(); final BrewingUnit brewingUnit = CoffeeFactory.eINSTANCE.createBrewingUnit(); Answer<Void> answer = invocation -> { response.set(invocation.getArgument(0)); return null; }; doAnswer(answer).when(context).json(any(JsonNode.class)); final LinkedHashMap<String, List<String>> queryParams = new LinkedHashMap<>(); queryParams.put("format", Collections.singletonList("xmi")); when(context.queryParamMap()).thenReturn(queryParams); final Map<URI, EObject> allModels = Collections.singletonMap(URI.createURI("test"), brewingUnit); when(modelRepository.getAllModels()).thenReturn(allModels); modelController.getAll(context); assertThat(response.get().get("data"), is(equalTo( Json.object( Json.prop("test", new XmiCodec().encode(brewingUnit)))))); }
public void getAll(final Context ctx) { try { final Map<URI, EObject> allModels = this.modelRepository.getAllModels(); Map<URI, JsonNode> encodedEntries = Maps.newLinkedHashMap(); for (Map.Entry<URI, EObject> entry : allModels.entrySet()) { final JsonNode encoded = codecs.encode(ctx, entry.getValue()); encodedEntries.put(entry.getKey(), encoded); } ctx.json(JsonResponse.success(JsonCodec.encode(encodedEntries))); } catch (EncodingException ex) { handleEncodingError(ctx, ex); } catch (IOException e) { handleError(ctx, 404, "Could not load all models"); } }
ModelController { public void getAll(final Context ctx) { try { final Map<URI, EObject> allModels = this.modelRepository.getAllModels(); Map<URI, JsonNode> encodedEntries = Maps.newLinkedHashMap(); for (Map.Entry<URI, EObject> entry : allModels.entrySet()) { final JsonNode encoded = codecs.encode(ctx, entry.getValue()); encodedEntries.put(entry.getKey(), encoded); } ctx.json(JsonResponse.success(JsonCodec.encode(encodedEntries))); } catch (EncodingException ex) { handleEncodingError(ctx, ex); } catch (IOException e) { handleError(ctx, 404, "Could not load all models"); } } }
ModelController { public void getAll(final Context ctx) { try { final Map<URI, EObject> allModels = this.modelRepository.getAllModels(); Map<URI, JsonNode> encodedEntries = Maps.newLinkedHashMap(); for (Map.Entry<URI, EObject> entry : allModels.entrySet()) { final JsonNode encoded = codecs.encode(ctx, entry.getValue()); encodedEntries.put(entry.getKey(), encoded); } ctx.json(JsonResponse.success(JsonCodec.encode(encodedEntries))); } catch (EncodingException ex) { handleEncodingError(ctx, ex); } catch (IOException e) { handleError(ctx, 404, "Could not load all models"); } } @Inject  ModelController(final ModelRepository modelRepository, final SessionController sessionController,
      final ServerConfiguration serverConfiguration); }
ModelController { public void getAll(final Context ctx) { try { final Map<URI, EObject> allModels = this.modelRepository.getAllModels(); Map<URI, JsonNode> encodedEntries = Maps.newLinkedHashMap(); for (Map.Entry<URI, EObject> entry : allModels.entrySet()) { final JsonNode encoded = codecs.encode(ctx, entry.getValue()); encodedEntries.put(entry.getKey(), encoded); } ctx.json(JsonResponse.success(JsonCodec.encode(encodedEntries))); } catch (EncodingException ex) { handleEncodingError(ctx, ex); } catch (IOException e) { handleError(ctx, 404, "Could not load all models"); } } @Inject  ModelController(final ModelRepository modelRepository, final SessionController sessionController,
      final ServerConfiguration serverConfiguration); void create(final Context ctx, final String modeluri); void delete(final Context ctx, final String modeluri); void getAll(final Context ctx); void getOne(final Context ctx, final String modeluri); void update(final Context ctx, final String modeluri); void save(final Context ctx, final String modeluri); Handler getModelUrisHandler(); void executeCommand(final Context ctx, final String modelURI); }
ModelController { public void getAll(final Context ctx) { try { final Map<URI, EObject> allModels = this.modelRepository.getAllModels(); Map<URI, JsonNode> encodedEntries = Maps.newLinkedHashMap(); for (Map.Entry<URI, EObject> entry : allModels.entrySet()) { final JsonNode encoded = codecs.encode(ctx, entry.getValue()); encodedEntries.put(entry.getKey(), encoded); } ctx.json(JsonResponse.success(JsonCodec.encode(encodedEntries))); } catch (EncodingException ex) { handleEncodingError(ctx, ex); } catch (IOException e) { handleError(ctx, 404, "Could not load all models"); } } @Inject  ModelController(final ModelRepository modelRepository, final SessionController sessionController,
      final ServerConfiguration serverConfiguration); void create(final Context ctx, final String modeluri); void delete(final Context ctx, final String modeluri); void getAll(final Context ctx); void getOne(final Context ctx, final String modeluri); void update(final Context ctx, final String modeluri); void save(final Context ctx, final String modeluri); Handler getModelUrisHandler(); void executeCommand(final Context ctx, final String modelURI);  }