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);
}
}
}
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);
}
}
}
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());
}
}
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
}
}
}
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
}
}
}
Aggregations