Search in sources :

Example 16 with EasyEntity

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

the class MetadataGetting method references.

// 哪些实体引用了指定实体
@GetMapping("references")
public List<String[]> references(HttpServletRequest request) {
    final ID user = getRequestUser(request);
    Entity entity = MetadataHelper.getEntity(getParameterNotNull(request, "entity"));
    String permission = getParameter(request, "permission");
    Permission checkPermission = null;
    if (permission != null) {
        checkPermission = PrivilegesManager.parse(permission);
    }
    Set<Entity> references = new HashSet<>();
    for (Field field : entity.getReferenceToFields()) {
        Entity own = field.getOwnEntity();
        if (!(own.getMainEntity() != null || field.getType() == FieldType.ANY_REFERENCE)) {
            references.add(own);
        }
    }
    List<String[]> data = new ArrayList<>();
    for (Entity e : references) {
        if (checkPermission == null || Application.getPrivilegesManager().allow(user, e.getEntityCode(), checkPermission)) {
            EasyEntity easy = EasyMetaFactory.valueOf(e);
            data.add(new String[] { easy.getName(), easy.getLabel() });
        }
    }
    return data;
}
Also used : EasyEntity(com.rebuild.core.metadata.easymeta.EasyEntity) EasyEntity(com.rebuild.core.metadata.easymeta.EasyEntity) Entity(cn.devezhao.persist4j.Entity) Field(cn.devezhao.persist4j.Field) Permission(cn.devezhao.bizz.privileges.Permission) ArrayList(java.util.ArrayList) ID(cn.devezhao.persist4j.engine.ID) HashSet(java.util.HashSet) 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