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