Search in sources :

Example 1 with Model

use of org.activiti.engine.repository.Model in project Activiti by Activiti.

the class ModelResourceTest method testDeleteModel.

public void testDeleteModel() throws Exception {
    Model model = null;
    try {
        Calendar now = Calendar.getInstance();
        now.set(Calendar.MILLISECOND, 0);
        processEngineConfiguration.getClock().setCurrentTime(now.getTime());
        model = repositoryService.newModel();
        model.setCategory("Model category");
        model.setKey("Model key");
        model.setMetaInfo("Model metainfo");
        model.setName("Model name");
        model.setVersion(2);
        repositoryService.saveModel(model);
        HttpDelete httpDelete = new HttpDelete(SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_MODEL, model.getId()));
        closeResponse(executeRequest(httpDelete, HttpStatus.SC_NO_CONTENT));
        // Check if the model is really gone
        assertNull(repositoryService.createModelQuery().modelId(model.getId()).singleResult());
        model = null;
    } finally {
        if (model != null) {
            try {
                repositoryService.deleteModel(model.getId());
            } catch (Throwable ignore) {
            // Ignore, model might not be created
            }
        }
    }
}
Also used : HttpDelete(org.apache.http.client.methods.HttpDelete) Calendar(java.util.Calendar) Model(org.activiti.engine.repository.Model)

Example 2 with Model

use of org.activiti.engine.repository.Model in project Activiti by Activiti.

the class ModelResourceSourceTest method testGetModelEditorSourceNoSource.

public void testGetModelEditorSourceNoSource() throws Exception {
    Model model = null;
    try {
        model = repositoryService.newModel();
        model.setName("Model name");
        repositoryService.saveModel(model);
        HttpGet httpGet = new HttpGet(SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_MODEL_SOURCE, model.getId()));
        closeResponse(executeRequest(httpGet, HttpStatus.SC_NOT_FOUND));
    } finally {
        try {
            repositoryService.deleteModel(model.getId());
        } catch (Throwable ignore) {
        // Ignore, model might not be created
        }
    }
}
Also used : HttpGet(org.apache.http.client.methods.HttpGet) Model(org.activiti.engine.repository.Model)

Example 3 with Model

use of org.activiti.engine.repository.Model in project Activiti by Activiti.

the class ModelResourceSourceTest method testGetModelEditorSourceExtra.

public void testGetModelEditorSourceExtra() throws Exception {
    Model model = null;
    try {
        model = repositoryService.newModel();
        model.setName("Model name");
        repositoryService.saveModel(model);
        repositoryService.addModelEditorSourceExtra(model.getId(), "This is the extra editor source".getBytes());
        HttpGet httpGet = new HttpGet(SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_MODEL_SOURCE_EXTRA, model.getId()));
        CloseableHttpResponse response = executeRequest(httpGet, HttpStatus.SC_OK);
        // Check "OK" status
        assertEquals("application/octet-stream", response.getEntity().getContentType().getValue());
        assertEquals("This is the extra editor source", IOUtils.toString(response.getEntity().getContent()));
        closeResponse(response);
    } finally {
        try {
            repositoryService.deleteModel(model.getId());
        } catch (Throwable ignore) {
        // Ignore, model might not be created
        }
    }
}
Also used : HttpGet(org.apache.http.client.methods.HttpGet) Model(org.activiti.engine.repository.Model) CloseableHttpResponse(org.apache.http.client.methods.CloseableHttpResponse)

Example 4 with Model

use of org.activiti.engine.repository.Model in project Activiti by Activiti.

the class ModelResourceSourceTest method testSetModelEditorSource.

public void testSetModelEditorSource() throws Exception {
    Model model = null;
    try {
        model = repositoryService.newModel();
        model.setName("Model name");
        repositoryService.saveModel(model);
        HttpPut httpPut = new HttpPut(SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_MODEL_SOURCE, model.getId()));
        httpPut.setEntity(HttpMultipartHelper.getMultiPartEntity("sourcefile", "application/octet-stream", new ByteArrayInputStream("This is the new editor source".getBytes()), null));
        closeResponse(executeBinaryRequest(httpPut, HttpStatus.SC_NO_CONTENT));
        assertEquals("This is the new editor source", new String(repositoryService.getModelEditorSource(model.getId())));
    } finally {
        try {
            repositoryService.deleteModel(model.getId());
        } catch (Throwable ignore) {
        // Ignore, model might not be created
        }
    }
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) Model(org.activiti.engine.repository.Model) HttpPut(org.apache.http.client.methods.HttpPut)

Example 5 with Model

use of org.activiti.engine.repository.Model in project Activiti by Activiti.

the class DemoDataConfiguration method createModelData.

protected void createModelData(String name, String description, String jsonFile) {
    List<Model> modelList = repositoryService.createModelQuery().modelName("Demo model").list();
    if (modelList == null || modelList.isEmpty()) {
        Model model = repositoryService.newModel();
        model.setName(name);
        ObjectNode modelObjectNode = new ObjectMapper().createObjectNode();
        modelObjectNode.put("name", name);
        modelObjectNode.put("description", description);
        model.setMetaInfo(modelObjectNode.toString());
        repositoryService.saveModel(model);
        try {
            InputStream svgStream = this.getClass().getClassLoader().getResourceAsStream("org/activiti/rest/demo/model/test.svg");
            repositoryService.addModelEditorSourceExtra(model.getId(), IOUtils.toByteArray(svgStream));
        } catch (Exception e) {
            LOGGER.warn("Failed to read SVG", e);
        }
        try {
            InputStream editorJsonStream = this.getClass().getClassLoader().getResourceAsStream(jsonFile);
            repositoryService.addModelEditorSource(model.getId(), IOUtils.toByteArray(editorJsonStream));
        } catch (Exception e) {
            LOGGER.warn("Failed to read editor JSON", e);
        }
    }
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) InputStream(java.io.InputStream) Model(org.activiti.engine.repository.Model) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Aggregations

Model (org.activiti.engine.repository.Model)55 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)16 ModelQuery (org.activiti.engine.repository.ModelQuery)9 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)8 BpmnModel (org.activiti.bpmn.model.BpmnModel)8 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)8 CloseableHttpResponse (org.apache.http.client.methods.CloseableHttpResponse)7 JsonNode (com.fasterxml.jackson.databind.JsonNode)6 InputStream (java.io.InputStream)6 Calendar (java.util.Calendar)6 ActivitiException (org.activiti.engine.ActivitiException)6 Deployment (org.activiti.engine.test.Deployment)6 ByteArrayInputStream (java.io.ByteArrayInputStream)5 HttpGet (org.apache.http.client.methods.HttpGet)5 HttpPut (org.apache.http.client.methods.HttpPut)5 StringEntity (org.apache.http.entity.StringEntity)4 Button (com.vaadin.ui.Button)3 ClickEvent (com.vaadin.ui.Button.ClickEvent)3 ClickListener (com.vaadin.ui.Button.ClickListener)3 HorizontalLayout (com.vaadin.ui.HorizontalLayout)3