Search in sources :

Example 51 with ConfigBean

use of com.rebuild.core.configuration.ConfigBean in project rebuild by getrebuild.

the class QueryParser method buildCountSql.

/**
 * @param pkName
 * @return
 */
private String buildCountSql(String pkName) {
    List<String> counts = new ArrayList<>();
    counts.add(String.format("count(%s)", pkName));
    countFields = new ArrayList<>();
    countFields.add(Collections.emptyMap());
    if (queryExpr.getBooleanValue("statsField")) {
        ConfigBean cb = DataListManager.instance.getListStatsField(UserService.SYSTEM_USER, entity.getName());
        if (cb != null && cb.getJSON("config") != null) {
            JSONArray items = ((JSONObject) cb.getJSON("config")).getJSONArray("items");
            for (Object o : items) {
                JSONObject item = (JSONObject) o;
                String field = item.getString("field");
                if (MetadataHelper.checkAndWarnField(entity, field)) {
                    counts.add(String.format("%s(%s)", item.getString("calc"), field));
                    countFields.add(item);
                }
            }
        }
    }
    return String.format("select %s from %s where ", StringUtils.join(counts, ","), entity.getName());
}
Also used : JSONObject(com.alibaba.fastjson.JSONObject) JSONArray(com.alibaba.fastjson.JSONArray) JSONObject(com.alibaba.fastjson.JSONObject) ConfigBean(com.rebuild.core.configuration.ConfigBean)

Example 52 with ConfigBean

use of com.rebuild.core.configuration.ConfigBean in project rebuild by getrebuild.

the class ProjectManagerTest method testCreateTask.

@Test
public void testCreateTask() {
    ConfigBean[] plans = ProjectManager.instance.getPlansOfProject(_LastSavedProject);
    Record task = EntityHelper.forNew(EntityHelper.ProjectTask, SIMPLE_USER);
    task.setID("projectId", _LastSavedProject);
    task.setID("projectPlanId", plans[0].getID("id"));
    task.setString("taskName", "任务" + System.currentTimeMillis());
    task = Application.getBean(ProjectTaskService.class).create(task);
    System.out.println("New task created : " + task.getPrimary());
    Assertions.assertTrue(ProjectHelper.checkReadable(task.getPrimary(), SIMPLE_USER));
    Assertions.assertTrue(ProjectHelper.isManageable(task.getPrimary(), SIMPLE_USER));
    // DELETE
    Application.getBean(ProjectTaskService.class).delete(task.getPrimary());
}
Also used : Record(cn.devezhao.persist4j.Record) ConfigBean(com.rebuild.core.configuration.ConfigBean) Test(org.junit.jupiter.api.Test)

Aggregations

ConfigBean (com.rebuild.core.configuration.ConfigBean)52 ID (cn.devezhao.persist4j.engine.ID)26 JSONObject (com.alibaba.fastjson.JSONObject)23 JSONArray (com.alibaba.fastjson.JSONArray)16 JSON (com.alibaba.fastjson.JSON)9 GetMapping (org.springframework.web.bind.annotation.GetMapping)9 Entity (cn.devezhao.persist4j.Entity)8 ArrayList (java.util.ArrayList)7 Field (cn.devezhao.persist4j.Field)6 Record (cn.devezhao.persist4j.Record)5 ConfigurationException (com.rebuild.core.configuration.ConfigurationException)5 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)4 ModelAndView (org.springframework.web.servlet.ModelAndView)4 DataSpecificationException (com.rebuild.core.service.DataSpecificationException)2 AdvFilterParser (com.rebuild.core.service.query.AdvFilterParser)2 List (java.util.List)2 Set (java.util.Set)2 Test (org.junit.jupiter.api.Test)2 Permission (cn.devezhao.bizz.privileges.Permission)1 BizzPermission (cn.devezhao.bizz.privileges.impl.BizzPermission)1