use of org.activiti.engine.repository.Model in project Activiti by Activiti.
the class ModelCollectionResourceTest method testGetModels.
@Deployment(resources = { "org/activiti/rest/service/api/repository/oneTaskProcess.bpmn20.xml" })
public void testGetModels() throws Exception {
// Create 2 models
Model model1 = null;
Model model2 = null;
try {
model1 = repositoryService.newModel();
model1.setCategory("Model category");
model1.setKey("Model key");
model1.setMetaInfo("Model metainfo");
model1.setName("Model name");
model1.setVersion(2);
model1.setDeploymentId(deploymentId);
repositoryService.saveModel(model1);
model2 = repositoryService.newModel();
model2.setCategory("Another category");
model2.setKey("Another key");
model2.setMetaInfo("Another metainfo");
model2.setName("Another name");
model2.setVersion(3);
repositoryService.saveModel(model2);
// Try filter-less, should return all models
String url = RestUrls.createRelativeResourceUrl(RestUrls.URL_MODEL_COLLECTION);
assertResultsPresentInDataResponse(url, model1.getId(), model2.getId());
// Filter based on id
url = RestUrls.createRelativeResourceUrl(RestUrls.URL_MODEL_COLLECTION) + "?id=" + model1.getId();
assertResultsPresentInDataResponse(url, model1.getId());
// Filter based on category
url = RestUrls.createRelativeResourceUrl(RestUrls.URL_MODEL_COLLECTION) + "?category=" + encode("Another category");
assertResultsPresentInDataResponse(url, model2.getId());
// Filter based on category like
url = RestUrls.createRelativeResourceUrl(RestUrls.URL_MODEL_COLLECTION) + "?categoryLike=" + encode("Mode%");
assertResultsPresentInDataResponse(url, model1.getId());
// Filter based on category not equals
url = RestUrls.createRelativeResourceUrl(RestUrls.URL_MODEL_COLLECTION) + "?categoryNotEquals=" + encode("Another category");
assertResultsPresentInDataResponse(url, model1.getId());
// Filter based on name
url = RestUrls.createRelativeResourceUrl(RestUrls.URL_MODEL_COLLECTION) + "?name=" + encode("Another name");
assertResultsPresentInDataResponse(url, model2.getId());
// Filter based on name like
url = RestUrls.createRelativeResourceUrl(RestUrls.URL_MODEL_COLLECTION) + "?nameLike=" + encode("%del name");
assertResultsPresentInDataResponse(url, model1.getId());
// Filter based on key
url = RestUrls.createRelativeResourceUrl(RestUrls.URL_MODEL_COLLECTION) + "?key=" + encode("Model key");
assertResultsPresentInDataResponse(url, model1.getId());
// Filter based on version
url = RestUrls.createRelativeResourceUrl(RestUrls.URL_MODEL_COLLECTION) + "?version=3";
assertResultsPresentInDataResponse(url, model2.getId());
// Filter based on deploymentId
url = RestUrls.createRelativeResourceUrl(RestUrls.URL_MODEL_COLLECTION) + "?deploymentId=" + deploymentId;
assertResultsPresentInDataResponse(url, model1.getId());
// Filter based on deployed=true
url = RestUrls.createRelativeResourceUrl(RestUrls.URL_MODEL_COLLECTION) + "?deployed=true";
assertResultsPresentInDataResponse(url, model1.getId());
// Filter based on deployed=false
url = RestUrls.createRelativeResourceUrl(RestUrls.URL_MODEL_COLLECTION) + "?deployed=false";
assertResultsPresentInDataResponse(url, model2.getId());
// Filter based on latestVersion
url = RestUrls.createRelativeResourceUrl(RestUrls.URL_MODEL_COLLECTION) + "?key=" + encode("Model key") + "&latestVersion=true";
// Make sure both models have same key
model2 = repositoryService.createModelQuery().modelId(model2.getId()).singleResult();
model2.setKey("Model key");
repositoryService.saveModel(model2);
assertResultsPresentInDataResponse(url, model2.getId());
// Filter without tenant ID, before tenant update
url = RestUrls.createRelativeResourceUrl(RestUrls.URL_MODEL_COLLECTION) + "?withoutTenantId=true";
assertResultsPresentInDataResponse(url, model1.getId(), model2.getId());
// Set tenant ID
model1 = repositoryService.getModel(model1.getId());
model1.setTenantId("myTenant");
repositoryService.saveModel(model1);
// Filter without tenant ID, after tenant update
url = RestUrls.createRelativeResourceUrl(RestUrls.URL_MODEL_COLLECTION) + "?withoutTenantId=true";
assertResultsPresentInDataResponse(url, model2.getId());
// Filter based on tenantId
url = RestUrls.createRelativeResourceUrl(RestUrls.URL_MODEL_COLLECTION) + "?tenantId=myTenant";
assertResultsPresentInDataResponse(url, model1.getId());
url = RestUrls.createRelativeResourceUrl(RestUrls.URL_MODEL_COLLECTION) + "?tenantId=anotherTenant";
assertResultsPresentInDataResponse(url);
// Filter based on tenantId like
url = RestUrls.createRelativeResourceUrl(RestUrls.URL_MODEL_COLLECTION) + "?tenantIdLike=" + encode("%enant");
assertResultsPresentInDataResponse(url, model1.getId());
url = RestUrls.createRelativeResourceUrl(RestUrls.URL_MODEL_COLLECTION) + "?tenantIdLike=anotherTenant";
assertResultsPresentInDataResponse(url);
} finally {
if (model1 != null) {
try {
repositoryService.deleteModel(model1.getId());
} catch (Throwable ignore) {
}
}
if (model2 != null) {
try {
repositoryService.deleteModel(model2.getId());
} catch (Throwable ignore) {
}
}
}
}
use of org.activiti.engine.repository.Model in project Activiti by Activiti.
the class ModelResourceSourceTest method testGetModelEditorSource.
public void testGetModelEditorSource() throws Exception {
Model model = null;
try {
model = repositoryService.newModel();
model.setName("Model name");
repositoryService.saveModel(model);
repositoryService.addModelEditorSource(model.getId(), "This is the editor source".getBytes());
HttpGet httpGet = new HttpGet(SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_MODEL_SOURCE, model.getId()));
CloseableHttpResponse response = executeRequest(httpGet, HttpStatus.SC_OK);
// Check "OK" status
assertEquals("application/octet-stream", response.getEntity().getContentType().getValue());
assertEquals("This is the 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 testGetModelEditorSourceExtraNoSource.
public void testGetModelEditorSourceExtraNoSource() 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_EXTRA, 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 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/explorer/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);
}
}
}
use of org.activiti.engine.repository.Model in project Activiti by Activiti.
the class ModelQueryTest method testQueryByKey.
public void testQueryByKey() {
ModelQuery query = repositoryService.createModelQuery().modelName("my model").modelKey("someKey");
Model model = query.singleResult();
assertNotNull(model);
assertEquals(1, query.list().size());
assertEquals(1, query.count());
}
Aggregations