Search in sources :

Example 11 with Model

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

the class ModelSourceExtraResource method setModelSource.

@RequestMapping(value = "/repository/models/{modelId}/source-extra", method = RequestMethod.PUT)
protected void setModelSource(@PathVariable String modelId, HttpServletRequest request, HttpServletResponse response) {
    Model model = getModelFromRequest(modelId);
    if (model != null) {
        try {
            if (request instanceof MultipartHttpServletRequest == false) {
                throw new ActivitiIllegalArgumentException("Multipart request is required");
            }
            MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
            if (multipartRequest.getFileMap().size() == 0) {
                throw new ActivitiIllegalArgumentException("Multipart request with file content is required");
            }
            MultipartFile file = multipartRequest.getFileMap().values().iterator().next();
            repositoryService.addModelEditorSourceExtra(model.getId(), file.getBytes());
            response.setStatus(HttpStatus.NO_CONTENT.value());
        } catch (Exception e) {
            throw new ActivitiException("Error adding model editor source extra", e);
        }
    }
}
Also used : MultipartFile(org.springframework.web.multipart.MultipartFile) ActivitiException(org.activiti.engine.ActivitiException) ActivitiIllegalArgumentException(org.activiti.engine.ActivitiIllegalArgumentException) Model(org.activiti.engine.repository.Model) ActivitiException(org.activiti.engine.ActivitiException) ActivitiObjectNotFoundException(org.activiti.engine.ActivitiObjectNotFoundException) ActivitiIllegalArgumentException(org.activiti.engine.ActivitiIllegalArgumentException) MultipartHttpServletRequest(org.springframework.web.multipart.MultipartHttpServletRequest) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 12 with Model

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

the class ModelSourceResource method setModelSource.

@RequestMapping(value = "/repository/models/{modelId}/source", method = RequestMethod.PUT)
protected void setModelSource(@PathVariable String modelId, HttpServletRequest request, HttpServletResponse response) {
    Model model = getModelFromRequest(modelId);
    if (model != null) {
        if (request instanceof MultipartHttpServletRequest == false) {
            throw new ActivitiIllegalArgumentException("Multipart request is required");
        }
        MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
        if (multipartRequest.getFileMap().size() == 0) {
            throw new ActivitiIllegalArgumentException("Multipart request with file content is required");
        }
        MultipartFile file = multipartRequest.getFileMap().values().iterator().next();
        try {
            repositoryService.addModelEditorSource(modelId, file.getBytes());
            response.setStatus(HttpStatus.NO_CONTENT.value());
        } catch (Exception e) {
            throw new ActivitiException("Error adding model editor source extra", e);
        }
    }
}
Also used : MultipartFile(org.springframework.web.multipart.MultipartFile) ActivitiException(org.activiti.engine.ActivitiException) ActivitiIllegalArgumentException(org.activiti.engine.ActivitiIllegalArgumentException) Model(org.activiti.engine.repository.Model) ActivitiException(org.activiti.engine.ActivitiException) ActivitiObjectNotFoundException(org.activiti.engine.ActivitiObjectNotFoundException) ActivitiIllegalArgumentException(org.activiti.engine.ActivitiIllegalArgumentException) MultipartHttpServletRequest(org.springframework.web.multipart.MultipartHttpServletRequest) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 13 with Model

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

the class TenancyTest method testModelTenancy.

public void testModelTenancy() {
    // Create a few models with tenant
    int nrOfModelsWithTenant = 3;
    for (int i = 0; i < nrOfModelsWithTenant; i++) {
        Model model = repositoryService.newModel();
        model.setName(i + "");
        model.setTenantId(TEST_TENANT_ID);
        repositoryService.saveModel(model);
    }
    // Create a few models without tenant
    int nrOfModelsWithoutTenant = 5;
    for (int i = 0; i < nrOfModelsWithoutTenant; i++) {
        Model model = repositoryService.newModel();
        model.setName(i + "");
        repositoryService.saveModel(model);
    }
    // Check query
    assertEquals(nrOfModelsWithoutTenant + nrOfModelsWithTenant, repositoryService.createModelQuery().list().size());
    assertEquals(nrOfModelsWithoutTenant, repositoryService.createModelQuery().modelWithoutTenantId().list().size());
    assertEquals(nrOfModelsWithTenant, repositoryService.createModelQuery().modelTenantId(TEST_TENANT_ID).list().size());
    assertEquals(nrOfModelsWithTenant, repositoryService.createModelQuery().modelTenantIdLike("my%").list().size());
    assertEquals(0, repositoryService.createModelQuery().modelTenantId("a%").list().size());
    // Clean up
    for (Model model : repositoryService.createModelQuery().list()) {
        repositoryService.deleteModel(model.getId());
    }
}
Also used : Model(org.activiti.engine.repository.Model)

Example 14 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 15 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)

Aggregations

Model (org.activiti.engine.repository.Model)49 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)12 ModelQuery (org.activiti.engine.repository.ModelQuery)9 CloseableHttpResponse (org.apache.http.client.methods.CloseableHttpResponse)7 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)7 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)6 Calendar (java.util.Calendar)6 Deployment (org.activiti.engine.test.Deployment)6 JsonNode (com.fasterxml.jackson.databind.JsonNode)5 InputStream (java.io.InputStream)5 HttpGet (org.apache.http.client.methods.HttpGet)5 HttpPut (org.apache.http.client.methods.HttpPut)5 BpmnModel (org.activiti.bpmn.model.BpmnModel)4 ActivitiException (org.activiti.engine.ActivitiException)4 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 ByteArrayInputStream (java.io.ByteArrayInputStream)3