Search in sources :

Example 46 with ConfigBean

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

the class AdvFilterManager method getAdvFilterList.

/**
 * 获取高级查询列表
 *
 * @param entity
 * @param user
 * @return
 */
public JSONArray getAdvFilterList(String entity, ID user) {
    Object[][] canUses = getUsesConfig(user, entity, null);
    List<ConfigBean> ces = new ArrayList<>();
    for (Object[] c : canUses) {
        ConfigBean e = new ConfigBean().set("id", c[0]).set("editable", UserHelper.isSelf(user, (ID) c[2])).set("name", c[4]);
        ces.add(e);
    }
    ces.sort(Comparator.comparing(o -> o.getString("name")));
    return JSONUtils.toJSONArray(ces.toArray(new ConfigBean[0]));
}
Also used : JSONArray(com.alibaba.fastjson.JSONArray) List(java.util.List) JSON(com.alibaba.fastjson.JSON) ID(cn.devezhao.persist4j.engine.ID) RebuildException(com.rebuild.core.RebuildException) UserHelper(com.rebuild.core.privileges.UserHelper) Comparator(java.util.Comparator) ConfigBean(com.rebuild.core.configuration.ConfigBean) JSONUtils(com.rebuild.utils.JSONUtils) Application(com.rebuild.core.Application) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) ConfigBean(com.rebuild.core.configuration.ConfigBean)

Example 47 with ConfigBean

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

the class AutoFillinManager method getFillinValue.

/**
 * 获取回填值
 *
 * @param field
 * @param source
 * @return
 */
public JSONArray getFillinValue(Field field, ID source) {
    final EasyField easyField = EasyMetaFactory.valueOf(field);
    // 内置字段无配置 @see field-edit.html
    if (easyField.isBuiltin())
        return JSONUtils.EMPTY_ARRAY;
    final List<ConfigBean> config = new ArrayList<>();
    for (ConfigBean cb : getConfig(field)) config.add(cb.clone());
    // 父级级联
    // 利用表单回填做父级级联字段回填
    String cascadingField = easyField.getExtraAttr(EasyFieldConfigProps.REFERENCE_CASCADINGFIELD);
    if (StringUtils.isNotBlank(cascadingField)) {
        String[] fs = cascadingField.split(MetadataHelper.SPLITER_RE);
        ConfigBean fake = new ConfigBean().set("source", fs[1]).set("target", fs[0]).set("whenCreate", true).set("whenUpdate", true).set("fillinForce", true);
        // 移除冲突的表单回填配置
        for (Iterator<ConfigBean> iter = config.iterator(); iter.hasNext(); ) {
            ConfigBean cb = iter.next();
            if (cb.getString("source").equals(fake.getString("source")) && cb.getString("target").equals(fake.getString("target"))) {
                iter.remove();
                break;
            }
        }
        config.add(fake);
    }
    if (config.isEmpty())
        return JSONUtils.EMPTY_ARRAY;
    Entity sourceEntity = MetadataHelper.getEntity(source.getEntityCode());
    Entity targetEntity = field.getOwnEntity();
    Set<String> sourceFields = new HashSet<>();
    for (Iterator<ConfigBean> iter = config.iterator(); iter.hasNext(); ) {
        ConfigBean e = iter.next();
        String sourceField = e.getString("source");
        String targetField = e.getString("target");
        if (!MetadataHelper.checkAndWarnField(sourceEntity, sourceField) || !MetadataHelper.checkAndWarnField(targetEntity, targetField)) {
            iter.remove();
            continue;
        }
        sourceFields.add(sourceField);
    }
    if (sourceFields.isEmpty())
        return JSONUtils.EMPTY_ARRAY;
    String ql = String.format("select %s from %s where %s = ?", StringUtils.join(sourceFields, ","), sourceEntity.getName(), sourceEntity.getPrimaryField().getName());
    Record sourceRecord = Application.createQueryNoFilter(ql).setParameter(1, source).record();
    if (sourceRecord == null)
        return JSONUtils.EMPTY_ARRAY;
    JSONArray fillin = new JSONArray();
    for (ConfigBean e : config) {
        String sourceField = e.getString("source");
        String targetField = e.getString("target");
        Field sourceFieldMeta = sourceEntity.getField(sourceField);
        Field targetFieldMeta = targetEntity.getField(targetField);
        Object value = null;
        if (sourceRecord.hasValue(sourceField, false)) {
            if (EasyMetaFactory.getDisplayType(sourceFieldMeta) == DisplayType.N2NREFERENCE) {
                value = N2NReferenceSupport.items(sourceFieldMeta, source);
            } else {
                value = sourceRecord.getObjectValue(sourceField);
            }
            value = conversionCompatibleValue(sourceEntity.getField(sourceField), targetFieldMeta, value);
        }
        // NOTE 忽略空值
        if (NullValue.isNull(value) || StringUtils.isBlank(value.toString())) {
            continue;
        }
        // 日期格式处理
        if (value instanceof Date && (targetFieldMeta.getType() == FieldType.DATE || targetFieldMeta.getType() == FieldType.TIMESTAMP)) {
            value = EasyMetaFactory.valueOf(targetFieldMeta).wrapValue(value);
        }
        ConfigBean clone = e.clone().set("value", value);
        clone.set("source", null);
        fillin.add(clone.toJSON());
    }
    return fillin;
}
Also used : Entity(cn.devezhao.persist4j.Entity) JSONArray(com.alibaba.fastjson.JSONArray) ConfigBean(com.rebuild.core.configuration.ConfigBean) Field(cn.devezhao.persist4j.Field) Record(cn.devezhao.persist4j.Record) JSONObject(com.alibaba.fastjson.JSONObject)

Example 48 with ConfigBean

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

the class AutoFillinManager method getConfig.

/**
 * 获取配置
 *
 * @param field
 * @return
 */
@SuppressWarnings("unchecked")
private List<ConfigBean> getConfig(Field field) {
    final String cKey = "AutoFillinManager-" + field.getOwnEntity().getName() + "." + field.getName();
    Object cached = Application.getCommonsCache().getx(cKey);
    if (cached != null) {
        return (List<ConfigBean>) cached;
    }
    Object[][] array = Application.createQueryNoFilter("select sourceField,targetField,extConfig from AutoFillinConfig where belongEntity = ? and belongField = ?").setParameter(1, field.getOwnEntity().getName()).setParameter(2, field.getName()).array();
    ArrayList<ConfigBean> entries = new ArrayList<>();
    for (Object[] o : array) {
        ConfigBean entry = new ConfigBean().set("source", o[0]).set("target", o[1]);
        JSONObject ext = JSON.parseObject((String) o[2]);
        entry.set("whenCreate", ext.getBoolean("whenCreate")).set("whenUpdate", ext.getBoolean("whenUpdate")).set("fillinForce", ext.getBoolean("fillinForce"));
        entries.add(entry);
    }
    Application.getCommonsCache().putx(cKey, entries);
    return entries;
}
Also used : JSONObject(com.alibaba.fastjson.JSONObject) JSONObject(com.alibaba.fastjson.JSONObject) ConfigBean(com.rebuild.core.configuration.ConfigBean)

Example 49 with ConfigBean

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

the class PickListManager method getPickList.

/**
 * @param field
 * @return
 */
public JSONArray getPickList(Field field) {
    ConfigBean[] entries = getPickListRaw(field, false);
    for (ConfigBean e : entries) {
        e.set("hide", null);
        e.set("mask", null);
    }
    return JSONUtils.toJSONArray(entries);
}
Also used : ConfigBean(com.rebuild.core.configuration.ConfigBean)

Example 50 with ConfigBean

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

the class ApiGateway method verfiy.

/**
 * 验证请求并构建请求上下文
 *
 * @param request
 * @param useApi
 * @return
 */
protected ApiContext verfiy(HttpServletRequest request, @SuppressWarnings("unused") BaseApi useApi) {
    final Map<String, String> sortedMap = new TreeMap<>();
    for (Map.Entry<String, String[]> e : request.getParameterMap().entrySet()) {
        String[] vv = e.getValue();
        sortedMap.put(e.getKey(), vv == null || vv.length == 0 ? null : vv[0]);
    }
    final String appid = getParameterNotNull(sortedMap, "appid");
    final String sign = getParameterNotNull(sortedMap, "sign");
    final ConfigBean apiConfig = RebuildApiManager.instance.getApp(appid);
    if (apiConfig == null) {
        throw new ApiInvokeException(ApiInvokeException.ERR_BADAUTH, "Invalid [appid] " + appid);
    }
    // 验证签名
    final String timestamp = sortedMap.get("timestamp");
    final String signType = sortedMap.get("sign_type");
    sortedMap.remove("sign");
    // 明文签名
    if (timestamp == null && signType == null) {
        if (!apiConfig.getString("appSecret").equals(sign)) {
            throw new ApiInvokeException(ApiInvokeException.ERR_BADAUTH, "Invalid [sign] : " + sign);
        }
    } else // 密文签名
    {
        long systemTime = System.currentTimeMillis() / 1000;
        if (Math.abs(systemTime - ObjectUtils.toLong(timestamp)) > (Application.devMode() ? 100 : 15)) {
            throw new ApiInvokeException(ApiInvokeException.ERR_BADAUTH, "Invalid [timestamp] : " + appid);
        }
        StringBuilder sign2 = new StringBuilder();
        for (Map.Entry<String, String> e : sortedMap.entrySet()) {
            sign2.append(e.getKey()).append('=').append(e.getValue()).append('&');
        }
        sign2.append(appid).append('.').append(apiConfig.getString("appSecret"));
        String sign2sign;
        if ("MD5".equals(signType)) {
            sign2sign = EncryptUtils.toMD5Hex(sign2.toString());
        } else if ("SHA1".equals(signType)) {
            sign2sign = EncryptUtils.toSHA1Hex(sign2.toString());
        } else {
            throw new ApiInvokeException(ApiInvokeException.ERR_BADAUTH, "Invalid [sign_type] : " + signType);
        }
        if (!sign.equals(sign2sign)) {
            throw new ApiInvokeException(ApiInvokeException.ERR_BADAUTH, "Invalid [sign] : " + sign);
        }
    }
    // 组合请求数据
    String postData = ServletUtils.getRequestString(request);
    JSON postJson = postData != null ? (JSON) JSON.parse(postData) : null;
    ID bindUser = apiConfig.getID("bindUser");
    // 默认绑定系统用户
    if (bindUser == null)
        bindUser = UserService.SYSTEM_USER;
    return new ApiContext(sortedMap, postJson, appid, bindUser);
}
Also used : JSON(com.alibaba.fastjson.JSON) ConfigBean(com.rebuild.core.configuration.ConfigBean) ID(cn.devezhao.persist4j.engine.ID)

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