Search in sources :

Example 1 with EasyEntity

use of com.rebuild.core.metadata.easymeta.EasyEntity in project rebuild by getrebuild.

the class MetadataSorter method sortEntities.

/**
 * 用户权限内*可读*实体
 *
 * @param user
 * @param usesBizz 是否包括内置 BIZZ 实体
 * @param usesDetail 是否包括明细实体
 * @return
 */
public static Entity[] sortEntities(ID user, boolean usesBizz, boolean usesDetail) {
    List<BaseMeta> entities = new ArrayList<>();
    for (Entity e : MetadataHelper.getEntities()) {
        if (!e.isQueryable())
            continue;
        if (!usesDetail && e.getMainEntity() != null)
            continue;
        EasyEntity easyEntity = EasyMetaFactory.valueOf(e);
        if (easyEntity.isBuiltin() && !easyEntity.isPlainEntity())
            continue;
        Entity checkEntity = e;
        if (usesDetail && e.getMainEntity() != null)
            checkEntity = e.getMainEntity();
        if (user == null || !MetadataHelper.hasPrivilegesField(checkEntity)) {
            entities.add(e);
        } else if (Application.getPrivilegesManager().allowRead(user, checkEntity.getEntityCode())) {
            entities.add(e);
        }
    }
    sortByLabel(entities);
    if (usesBizz) {
        entities.add(MetadataHelper.getEntity(EntityHelper.User));
        entities.add(MetadataHelper.getEntity(EntityHelper.Department));
        entities.add(MetadataHelper.getEntity(EntityHelper.Role));
        entities.add(MetadataHelper.getEntity(EntityHelper.Team));
    }
    return entities.toArray(new Entity[0]);
}
Also used : EasyEntity(com.rebuild.core.metadata.easymeta.EasyEntity) EasyEntity(com.rebuild.core.metadata.easymeta.EasyEntity) Entity(cn.devezhao.persist4j.Entity) ArrayList(java.util.ArrayList) BaseMeta(cn.devezhao.persist4j.metadata.BaseMeta)

Example 2 with EasyEntity

use of com.rebuild.core.metadata.easymeta.EasyEntity in project rebuild by getrebuild.

the class NavBuilder method addInitNavOnInstall.

/**
 * 首次安装添加菜单
 *
 * @param initEntity
 */
public void addInitNavOnInstall(String[] initEntity) {
    JSONArray initNav = replaceLang(NAVS_DEFAULT);
    for (String e : initEntity) {
        EasyEntity entity = EasyMetaFactory.valueOf(e);
        JSONObject navItem = JSONUtils.toJSONObject(NAV_ITEM_PROPS, new String[] { entity.getIcon(), entity.getLabel(), "ENTITY", entity.getName() });
        initNav.add(navItem);
    }
    Record record = RecordBuilder.builder(EntityHelper.LayoutConfig).add("belongEntity", "N").add("shareTo", SHARE_ALL).add("applyType", TYPE_NAV).add("config", initNav.toJSONString()).build(UserService.SYSTEM_USER);
    UserContextHolder.setUser(UserService.SYSTEM_USER);
    try {
        Application.getService(EntityHelper.LayoutConfig).create(record);
    } finally {
        UserContextHolder.clear();
    }
}
Also used : EasyEntity(com.rebuild.core.metadata.easymeta.EasyEntity) JSONObject(com.alibaba.fastjson.JSONObject) JSONArray(com.alibaba.fastjson.JSONArray) Record(cn.devezhao.persist4j.Record)

Example 3 with EasyEntity

use of com.rebuild.core.metadata.easymeta.EasyEntity in project rebuild by getrebuild.

the class EntityController method putEntityMeta.

/**
 * @param into
 * @param entity
 */
protected void putEntityMeta(ModelAndView into, Entity entity) {
    EasyEntity easyMeta = EasyMetaFactory.valueOf(entity);
    into.getModel().put("entityName", easyMeta.getName());
    into.getModel().put("entityLabel", easyMeta.getLabel());
    into.getModel().put("entityIcon", easyMeta.getIcon());
    EasyEntity main = null;
    EasyEntity detail = null;
    if (entity.getMainEntity() != null) {
        main = EasyMetaFactory.valueOf(entity.getMainEntity());
        detail = EasyMetaFactory.valueOf(entity);
    } else if (entity.getDetailEntity() != null) {
        main = EasyMetaFactory.valueOf(entity);
        detail = EasyMetaFactory.valueOf(entity.getDetailEntity());
    } else {
        into.getModel().put("mainEntity", easyMeta.getName());
    }
    if (main != null) {
        into.getModel().put("mainEntity", main.getName());
        into.getModel().put("mainEntityLabel", main.getLabel());
        into.getModel().put("mainEntityIcon", main.getIcon());
        into.getModel().put("detailEntity", detail.getName());
        into.getModel().put("detailEntityLabel", detail.getLabel());
        into.getModel().put("detailEntityIcon", detail.getIcon());
    }
}
Also used : EasyEntity(com.rebuild.core.metadata.easymeta.EasyEntity)

Example 4 with EasyEntity

use of com.rebuild.core.metadata.easymeta.EasyEntity in project rebuild by getrebuild.

the class GeneralListController method pageList.

@GetMapping("list")
public ModelAndView pageList(@PathVariable String entity, HttpServletRequest request, HttpServletResponse response) throws IOException {
    final ID user = getRequestUser(request);
    final Entity listEntity = checkPageOfEntity(user, entity, response);
    if (listEntity == null)
        return null;
    final EasyEntity easyEntity = EasyMetaFactory.valueOf(listEntity);
    // 使用主实体列表配置
    final EasyEntity mainEntity = listEntity.getMainEntity() == null ? easyEntity : EasyMetaFactory.valueOf(listEntity.getMainEntity());
    String listPage = listEntity.getMainEntity() != null ? "/general/detail-list" : "/general/record-list";
    Integer listMode = getIntParameter(request, "forceListMode");
    if (listMode == null) {
        listMode = ObjectUtils.toInt(mainEntity.getExtraAttr(EasyEntityConfigProps.ADV_LIST_MODE), 1);
    }
    if (listMode == 2) {
        // Mode2
        listPage = "/general/record-list2";
    }
    ModelAndView mv = createModelAndView(listPage, entity, user);
    // 列表相关权限
    mv.getModel().put(ZeroEntry.AllowCustomDataList.name(), Application.getPrivilegesManager().allow(user, ZeroEntry.AllowCustomDataList));
    mv.getModel().put(ZeroEntry.AllowDataExport.name(), Application.getPrivilegesManager().allow(user, ZeroEntry.AllowDataExport));
    mv.getModel().put(ZeroEntry.AllowBatchUpdate.name(), Application.getPrivilegesManager().allow(user, ZeroEntry.AllowBatchUpdate));
    JSON listConfig = null;
    if (listMode == 1) {
        listConfig = DataListManager.instance.getFieldsLayout(entity, user);
        // 扩展配置
        String advListHideFilters = mainEntity.getExtraAttr(EasyEntityConfigProps.ADV_LIST_HIDE_FILTERS);
        String advListHideCharts = mainEntity.getExtraAttr(EasyEntityConfigProps.ADV_LIST_HIDE_CHARTS);
        mv.getModel().put(EasyEntityConfigProps.ADV_LIST_HIDE_FILTERS, advListHideFilters);
        mv.getModel().put(EasyEntityConfigProps.ADV_LIST_HIDE_CHARTS, advListHideCharts);
        mv.getModel().put("hideAside", BooleanUtils.toBoolean(advListHideFilters) && BooleanUtils.toBoolean(advListHideCharts));
    } else if (listMode == 2) {
        listConfig = DataListManager.instance.getFieldsLayoutMode2(listEntity);
        // 明细列表
        if (listEntity.getMainEntity() != null)
            mv.getModel().put("DataListType", "DetailList");
    }
    mv.getModel().put("DataListConfig", JSON.toJSONString(listConfig));
    // 快速查询
    mv.getModel().put("quickFieldsLabel", getQuickFieldsLabel(listEntity));
    return mv;
}
Also used : EasyEntity(com.rebuild.core.metadata.easymeta.EasyEntity) EasyEntity(com.rebuild.core.metadata.easymeta.EasyEntity) Entity(cn.devezhao.persist4j.Entity) ModelAndView(org.springframework.web.servlet.ModelAndView) JSON(com.alibaba.fastjson.JSON) ID(cn.devezhao.persist4j.engine.ID)

Example 5 with EasyEntity

use of com.rebuild.core.metadata.easymeta.EasyEntity in project rebuild by getrebuild.

the class ModelExtrasController method checkCreates.

@GetMapping("check-creates")
public JSON checkCreates(HttpServletRequest request) {
    final ID user = getRequestUser(request);
    String entity = getParameter(request, "entity", "");
    JSONArray allowed = new JSONArray();
    for (String e : entity.split(",")) {
        if (!MetadataHelper.containsEntity(e))
            continue;
        EasyEntity easyEntity = EasyMetaFactory.valueOf(e);
        if (!MetadataHelper.hasPrivilegesField(easyEntity.getRawMeta()))
            continue;
        if (Application.getPrivilegesManager().allow(user, easyEntity.getRawMeta().getEntityCode(), BizzPermission.CREATE)) {
            allowed.add(easyEntity.toJSON());
        }
    }
    return allowed;
}
Also used : EasyEntity(com.rebuild.core.metadata.easymeta.EasyEntity) JSONArray(com.alibaba.fastjson.JSONArray) ID(cn.devezhao.persist4j.engine.ID) GetMapping(org.springframework.web.bind.annotation.GetMapping)

Aggregations

EasyEntity (com.rebuild.core.metadata.easymeta.EasyEntity)16 Entity (cn.devezhao.persist4j.Entity)6 ModelAndView (org.springframework.web.servlet.ModelAndView)6 Field (cn.devezhao.persist4j.Field)5 ID (cn.devezhao.persist4j.engine.ID)5 JSONObject (com.alibaba.fastjson.JSONObject)5 JSONArray (com.alibaba.fastjson.JSONArray)3 ArrayList (java.util.ArrayList)3 EasyField (com.rebuild.core.metadata.easymeta.EasyField)2 CopyEntity (com.rebuild.core.metadata.impl.CopyEntity)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2 GetMapping (org.springframework.web.bind.annotation.GetMapping)2 Permission (cn.devezhao.bizz.privileges.Permission)1 Team (cn.devezhao.bizz.security.member.Team)1 Record (cn.devezhao.persist4j.Record)1 FieldType (cn.devezhao.persist4j.dialect.FieldType)1 Type (cn.devezhao.persist4j.dialect.Type)1 BaseMeta (cn.devezhao.persist4j.metadata.BaseMeta)1 JSON (com.alibaba.fastjson.JSON)1