@ApiOperation(value = "Create a model", tags = {
            "Models" }, notes = "All request values are optional. For example, you can only include the name attribute in the request body JSON-object, only setting the name of the model, leaving all other fields null.",
            code = 201)
    @ApiResponses(value = {
            @ApiResponse(code = 201, message = "Indicates the model was created.")
    })
    @PostMapping(value = "/repository/models", produces = "application/json")
    @ResponseStatus(HttpStatus.CREATED)
    public ModelResponse createModel(@RequestBody ModelRequest modelRequest) {
        Model model = repositoryService.newModel();
        model.setCategory(modelRequest.getCategory());
        model.setDeploymentId(modelRequest.getDeploymentId());
        model.setKey(modelRequest.getKey());
        model.setMetaInfo(modelRequest.getMetaInfo());
        model.setName(modelRequest.getName());
        model.setVersion(modelRequest.getVersion());
        model.setTenantId(modelRequest.getTenantId());
        
        if (restApiInterceptor != null) {
            restApiInterceptor.createModel(model, modelRequest);
        }

        repositoryService.saveModel(model);
        return restResponseFactory.createModelResponse(model);
    }
@Test
    @Deployment(resources = { "org/flowable/rest/service/api/repository/oneTaskProcess.bpmn20.xml" })
    public void testCreateModel() throws Exception {
        Model model = null;
        try {

            Calendar createTime = Calendar.getInstance();
            createTime.set(Calendar.MILLISECOND, 0);
            processEngineConfiguration.getClock().setCurrentTime(createTime.getTime());

            // Create create request
            ObjectNode requestNode = objectMapper.createObjectNode();
            requestNode.put("name", "Model name");
            requestNode.put("category", "Model category");
            requestNode.put("key", "Model key");
            requestNode.put("metaInfo", "Model metainfo");
            requestNode.put("deploymentId", deploymentId);
            requestNode.put("version", 2);
            requestNode.put("tenantId", "myTenant");

            HttpPost httpPost = new HttpPost(SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_MODEL_COLLECTION));
            httpPost.setEntity(new StringEntity(requestNode.toString()));
            CloseableHttpResponse response = executeRequest(httpPost, HttpStatus.SC_CREATED);
            JsonNode responseNode = objectMapper.readTree(response.getEntity().getContent());
            closeResponse(response);
            assertThat(responseNode).isNotNull();
            assertThatJson(responseNode)
                    .when(Option.IGNORING_EXTRA_FIELDS)
                    .isEqualTo("{"
                            + "name: 'Model name',"
                            + "key: 'Model key',"
                            + "category: 'Model category',"
                            + "version: 2,"
                            + "metaInfo: 'Model metainfo',"
                            + "deploymentId: '" + deploymentId + "',"
                            + "tenantId: 'myTenant',"
                            + "url: '" + SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_MODEL, responseNode.get("id").textValue()) + "',"
                            + "deploymentUrl: '" + SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_DEPLOYMENT, deploymentId) + "',"
                            + "createTime: " + new TextNode(getISODateStringWithTZ(createTime.getTime())) + ","
                            + "lastUpdateTime: " + new TextNode(getISODateStringWithTZ(createTime.getTime()))
                            + "}");

            model = repositoryService.createModelQuery().modelId(responseNode.get("id").textValue()).singleResult();
            assertThat(model).isNotNull();
            assertThat(model.getCategory()).isEqualTo("Model category");
            assertThat(model.getName()).isEqualTo("Model name");
            assertThat(model.getKey()).isEqualTo("Model key");
            assertThat(model.getDeploymentId()).isEqualTo(deploymentId);
            assertThat(model.getMetaInfo()).isEqualTo("Model metainfo");
            assertThat(model.getTenantId()).isEqualTo("myTenant");
            assertThat(model.getVersion().intValue()).isEqualTo(2);

        } finally {
            if (model != null) {
                try {
                    repositoryService.deleteModel(model.getId());
                } catch (Throwable ignore) {
                }
            }
        }
    }