|
| 1 | +--- |
| 2 | +title: "Internal Model" |
| 3 | +linkTitle: "Internal Model" |
| 4 | +description: "Description of domain model of milkman" |
| 5 | + |
| 6 | +--- |
| 7 | + |
| 8 | +Plugins in milkman can extend various functionality. For this, an explanation of how a request is structured is necessary first. |
| 9 | + |
| 10 | +# Getting Started |
| 11 | +A [sample plugin](https://github.com/warmuuh/milkman/tree/master/milkman-note) was created that shows how to add an Aspect Tab to a Request. |
| 12 | + |
| 13 | +if you want to setup a new project, an exemplary pom can be found [here](/docs/development/setup). |
| 14 | + |
| 15 | +# Data Model |
| 16 | + |
| 17 | + |
| 18 | + |
| 19 | +The core of milkman is very abstract and is only intended to organize workspaces, which contain environments and collections of requests. |
| 20 | +A request is of a specific type and might contain some basic data. In the case of an HttpRequest, this might be the URL and the Method. |
| 21 | + |
| 22 | +A request can also contain several `RequestAspects` which describe the request object further. In our example, this might be headers or the body of a request, but can also contain totally unrelated and auxiliary attributes. |
| 23 | + |
| 24 | +All Aspects and the container gets serialized using Jackson and stored in a local Database. |
| 25 | + |
| 26 | +# Extension Points |
| 27 | + |
| 28 | +Milkman uses [SPI](https://docs.oracle.com/javase/tutorial/ext/basics/spi.html) for extension. You just have to provide an implementation to one of the Extension Points below and move your packaged jar into the `/plugin` folder to have milkman pick up your plugin. |
| 29 | + |
| 30 | +## RequestAspectsPlugin |
| 31 | + |
| 32 | +A request aspect can add aspects to either a request- or response container as well as according editors (providing the Tab to edit this specific aspect). |
| 33 | + |
| 34 | +## ContentTypePlugin |
| 35 | + |
| 36 | +A content type plugin is used to format and highlight content based on a mime-type. |
| 37 | + |
| 38 | +## RequestTypePlugin |
| 39 | + |
| 40 | +A plugin providing a request type such as HttpRequest, or SQL request or whatever you can think of. |
| 41 | +This plugin has to provide a small editor for basic attributes of the request as well. |
| 42 | + |
| 43 | +## ImporterPlugin |
| 44 | + |
| 45 | +a plugin that imports things into the current workspace, such as collections, requests, environments. |
| 46 | + |
| 47 | +## OptionPageProvider |
| 48 | + |
| 49 | +a plugin to provide a UI for editing options of a "logical" plugin. The OptionPageBuilder can be used to create common ui. On startup, changed options will be loaded from database. |
| 50 | + |
| 51 | +## UI Theme Plugin |
| 52 | + |
| 53 | +provides an application-theme css and a syntax-theme css for styling. |
| 54 | + |
| 55 | +## Workspace Synchronizer Plugin |
| 56 | + |
| 57 | +provides a mechanism to synchronize the workspace with some external mechanism |
| 58 | + |
| 59 | +## Request Export Plugin |
| 60 | + |
| 61 | +extension point for adding export methods to a request-type. |
| 62 | + |
| 63 | +## Collection Export Plugin |
| 64 | + |
| 65 | +extension point for adding export methods to a collection. |
| 66 | + |
| 67 | +# Persistence |
| 68 | +All requests and RequestAspects (not response-aspects) will be stored in database and serialized using jackson. So you have to make sure that your classes properly serialize/deserialize. |
| 69 | + |
| 70 | +# Common Components |
| 71 | +Some common components are provided by milkman to make development of plugins easier: |
| 72 | + |
| 73 | + * TableEditor: a table that might or might not be editable. used for editing headers or environments or such. |
| 74 | + * ContentEditor: a content editor that supports highlighting and formatting |
| 75 | + * Dialogs: some common dialogs, such as credentialsInput or StringInput. |
| 76 | + |
| 77 | +# Testing |
| 78 | +milkman uses TestFX for testing. A [sample test](https://github.com/warmuuh/milkman/blob/master/milkman-note/src/test/java/milkman/plugin/note/NotesAspectEditorTest.java) can be seen in the notes plugin. |
| 79 | + |
| 80 | +# Gotchas |
| 81 | +JavaFX uses a lot of weak references. That means, if you don't keep references to e.g. bindings or controllers even (if they are not referred to by e.g. FXML-onActions), they get garbage-collected and the bindings simply don't work. |
| 82 | +You can use `setUserData` in some cases to have a strong reference of the UI element to e.g. the controller, so they both get garbage-collected at the same time. |
0 commit comments