Search in sources :

Example 1 with BaseMeta

use of cn.devezhao.persist4j.metadata.BaseMeta 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 BaseMeta

use of cn.devezhao.persist4j.metadata.BaseMeta in project rebuild by getrebuild.

the class MetadataSorter method sortByLevel.

/**
 * 按字段分类排序
 *
 * @param fields
 */
static Field[] sortByLevel(List<BaseMeta> fields) {
    List<BaseMeta> othersFields = new ArrayList<>();
    List<BaseMeta> commonsFields = new ArrayList<>();
    List<BaseMeta> approvalFields = new ArrayList<>();
    for (BaseMeta field : fields) {
        if (MetadataHelper.isApprovalField(field.getName())) {
            approvalFields.add(field);
        } else if (MetadataHelper.isCommonsField((Field) field)) {
            commonsFields.add(field);
        } else {
            othersFields.add(field);
        }
    }
    sortByLabel(othersFields);
    List<BaseMeta> allFields = new ArrayList<>(othersFields);
    sortByLabel(commonsFields);
    allFields.addAll(commonsFields);
    sortByLabel(approvalFields);
    allFields.addAll(approvalFields);
    return allFields.toArray(new Field[0]);
}
Also used : Field(cn.devezhao.persist4j.Field) ArrayList(java.util.ArrayList) BaseMeta(cn.devezhao.persist4j.metadata.BaseMeta)

Aggregations

BaseMeta (cn.devezhao.persist4j.metadata.BaseMeta)2 ArrayList (java.util.ArrayList)2 Entity (cn.devezhao.persist4j.Entity)1 Field (cn.devezhao.persist4j.Field)1 EasyEntity (com.rebuild.core.metadata.easymeta.EasyEntity)1