Search in sources :

Example 1 with ModelQuery

use of org.activiti.engine.repository.ModelQuery in project carbon-business-process by wso2.

the class ModelService method getModels.

@GET
@Path("/")
@Produces(MediaType.APPLICATION_JSON)
public Response getModels() {
    RepositoryService repositoryService = BPMNOSGIService.getRepositoryService();
    // Apply filters
    Map<String, String> allRequestParams = new HashMap<>();
    for (String property : allPropertiesList) {
        String value = uriInfo.getQueryParameters().getFirst(property);
        if (value != null) {
            allRequestParams.put(property, value);
        }
    }
    ModelQuery modelQuery = repositoryService.createModelQuery();
    String id = uriInfo.getQueryParameters().getFirst("id");
    if (id != null) {
        modelQuery.modelId(id);
    }
    String category = uriInfo.getQueryParameters().getFirst("category");
    if (category != null) {
        modelQuery.modelCategory(category);
    }
    String categoryLike = uriInfo.getQueryParameters().getFirst("categoryLike");
    if (categoryLike != null) {
        modelQuery.modelCategoryLike(categoryLike);
    }
    String categoryNotEquals = uriInfo.getQueryParameters().getFirst("categoryNotEquals");
    if (categoryNotEquals != null) {
        modelQuery.modelCategoryNotEquals(categoryNotEquals);
    }
    String name = uriInfo.getQueryParameters().getFirst("name");
    if (name != null) {
        modelQuery.modelName(name);
    }
    String nameLike = uriInfo.getQueryParameters().getFirst("nameLike");
    if (nameLike != null) {
        modelQuery.modelNameLike(nameLike);
    }
    String key = uriInfo.getQueryParameters().getFirst("key");
    if (key != null) {
        modelQuery.modelKey(key);
    }
    String version = uriInfo.getQueryParameters().getFirst("version");
    if (version != null) {
        modelQuery.modelVersion(Integer.valueOf(version));
    }
    String latestVersion = uriInfo.getQueryParameters().getFirst("latestVersion");
    if (latestVersion != null) {
        boolean isLatestVersion = Boolean.valueOf(latestVersion);
        if (isLatestVersion) {
            modelQuery.latestVersion();
        }
    }
    String deploymentId = uriInfo.getQueryParameters().getFirst("deploymentId");
    if (deploymentId != null) {
        modelQuery.deploymentId(deploymentId);
    }
    String deployed = uriInfo.getQueryParameters().getFirst("deployed");
    if (deployed != null) {
        boolean isDeployed = Boolean.valueOf(deployed);
        if (isDeployed) {
            modelQuery.deployed();
        } else {
            modelQuery.notDeployed();
        }
    }
    String tenantId = uriInfo.getQueryParameters().getFirst("tenantId");
    if (tenantId != null) {
        modelQuery.modelTenantId(tenantId);
    }
    String tenantIdLike = uriInfo.getQueryParameters().getFirst("tenantIdLike");
    if (tenantIdLike != null) {
        modelQuery.modelTenantIdLike(tenantIdLike);
    }
    String sWithoutTenantId = uriInfo.getQueryParameters().getFirst("withoutTenantId");
    if (sWithoutTenantId != null) {
        boolean withoutTenantId = Boolean.valueOf(sWithoutTenantId);
        if (withoutTenantId) {
            modelQuery.modelWithoutTenantId();
        }
    }
    DataResponse response = new ModelsPaginateList(new RestResponseFactory(), uriInfo).paginateList(allRequestParams, modelQuery, "id", allowedSortProperties);
    List<ModelResponse> modelResponseList = (List<ModelResponse>) response.getData();
    if (log.isDebugEnabled()) {
        log.debug("modelResponseList: " + modelResponseList.size());
    }
    return Response.ok().entity(response).build();
}
Also used : ModelsPaginateList(org.wso2.carbon.bpmn.rest.model.repository.ModelsPaginateList) RestResponseFactory(org.wso2.carbon.bpmn.rest.common.RestResponseFactory) HashMap(java.util.HashMap) DataResponse(org.wso2.carbon.bpmn.rest.model.common.DataResponse) ModelResponse(org.wso2.carbon.bpmn.rest.model.repository.ModelResponse) ModelQuery(org.activiti.engine.repository.ModelQuery) ModelsPaginateList(org.wso2.carbon.bpmn.rest.model.repository.ModelsPaginateList) ArrayList(java.util.ArrayList) List(java.util.List) RepositoryService(org.activiti.engine.RepositoryService) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 2 with ModelQuery

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

the class ModelQueryEscapeClauseTest method testQueryByCategoryLike.

public void testQueryByCategoryLike() throws Exception {
    ModelQuery query = repositoryService.createModelQuery().modelCategoryLike("%\\%%");
    Model model = query.singleResult();
    assertThat(model).isNotNull();
    assertThat(model.getKey()).isEqualTo("someKey1");
    assertThat(new String(repositoryService.getModelEditorSource(model.getId()), "utf-8")).isEqualTo("bytes");
    assertThat(query.list()).hasSize(1);
    assertThat(query.count()).isEqualTo(1);
    query = repositoryService.createModelQuery().modelCategoryLike("%\\_%");
    model = query.singleResult();
    assertThat(model).isNotNull();
    assertThat(model.getKey()).isEqualTo("someKey2");
    assertThat(new String(repositoryService.getModelEditorSource(model.getId()), "utf-8")).isEqualTo("bytes");
    assertThat(query.list()).hasSize(1);
    assertThat(query.count()).isEqualTo(1);
}
Also used : Model(org.activiti.engine.repository.Model) ModelQuery(org.activiti.engine.repository.ModelQuery)

Example 3 with ModelQuery

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

the class ModelQueryEscapeClauseTest method testQueryByTenantIdLike.

public void testQueryByTenantIdLike() throws Exception {
    ModelQuery query = repositoryService.createModelQuery().modelTenantIdLike("%\\%%");
    Model model = query.singleResult();
    assertThat(model).isNotNull();
    assertThat(model.getKey()).isEqualTo("someKey1");
    assertThat(new String(repositoryService.getModelEditorSource(model.getId()), "utf-8")).isEqualTo("bytes");
    assertThat(query.list()).hasSize(1);
    assertThat(query.count()).isEqualTo(1);
    query = repositoryService.createModelQuery().modelTenantIdLike("%\\_%");
    model = query.singleResult();
    assertThat(model).isNotNull();
    assertThat(model.getKey()).isEqualTo("someKey2");
    assertThat(new String(repositoryService.getModelEditorSource(model.getId()), "utf-8")).isEqualTo("bytes");
    assertThat(query.list()).hasSize(1);
    assertThat(query.count()).isEqualTo(1);
}
Also used : Model(org.activiti.engine.repository.Model) ModelQuery(org.activiti.engine.repository.ModelQuery)

Example 4 with ModelQuery

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

the class ModelQueryTest method testQueryByName.

public void testQueryByName() throws Exception {
    ModelQuery query = repositoryService.createModelQuery().modelName("my model");
    Model model = query.singleResult();
    assertThat(model).isNotNull();
    assertThat(new String(repositoryService.getModelEditorSource(model.getId()), "utf-8")).isEqualTo("bytes");
    assertThat(query.list()).hasSize(1);
    assertThat(query.count()).isEqualTo(1);
}
Also used : Model(org.activiti.engine.repository.Model) ModelQuery(org.activiti.engine.repository.ModelQuery)

Example 5 with ModelQuery

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

the class ModelQueryTest method testQueryByInvalidNameLike.

public void testQueryByInvalidNameLike() {
    ModelQuery query = repositoryService.createModelQuery().modelNameLike("%invalid%");
    assertThat(query.singleResult()).isNull();
    assertThat(query.list()).hasSize(0);
    assertThat(query.count()).isEqualTo(0);
}
Also used : ModelQuery(org.activiti.engine.repository.ModelQuery)

Aggregations

ModelQuery (org.activiti.engine.repository.ModelQuery)23 Model (org.activiti.engine.repository.Model)9 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 List (java.util.List)1 GET (javax.ws.rs.GET)1 Path (javax.ws.rs.Path)1 Produces (javax.ws.rs.Produces)1 RepositoryService (org.activiti.engine.RepositoryService)1 RestResponseFactory (org.wso2.carbon.bpmn.rest.common.RestResponseFactory)1 DataResponse (org.wso2.carbon.bpmn.rest.model.common.DataResponse)1 ModelResponse (org.wso2.carbon.bpmn.rest.model.repository.ModelResponse)1 ModelsPaginateList (org.wso2.carbon.bpmn.rest.model.repository.ModelsPaginateList)1