Search in sources :

Example 26 with EasyField

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

the class DataListWrapper method wrapFieldValue.

/**
 * @param value
 * @param field
 * @return
 */
protected Object wrapFieldValue(Object value, Field field) {
    EasyField easyField = EasyMetaFactory.valueOf(field);
    if (easyField.getDisplayType() == DisplayType.ID) {
        return FieldValueHelper.wrapMixValue((ID) value, null);
    }
    boolean unpack = easyField.getDisplayType() == DisplayType.CLASSIFICATION || easyField.getDisplayType() == DisplayType.PICKLIST || easyField.getDisplayType() == DisplayType.STATE || easyField.getDisplayType() == DisplayType.BOOL;
    value = FieldValueHelper.wrapFieldValue(value, easyField, unpack);
    if (value != null && isUseDesensitized(easyField)) {
        value = FieldValueHelper.desensitized(easyField, value);
    }
    return value;
}
Also used : EasyField(com.rebuild.core.metadata.easymeta.EasyField)

Example 27 with EasyField

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

the class FieldValueHelperTest method testWrapFieldValue.

@Test
public void testWrapFieldValue() {
    Entity useEntity = MetadataHelper.getEntity(TestAllFields);
    for (Field field : useEntity.getFields()) {
        Object value = RandomStringUtils.randomNumeric(10);
        if (field.getType() == FieldType.REFERENCE) {
            value = ID.newId(field.getReferenceEntity().getEntityCode());
        } else if (field.getType() == FieldType.DATE || field.getType() == FieldType.TIMESTAMP) {
            value = CalendarUtils.now();
        } else if (field.getType() == FieldType.LONG || field.getType() == FieldType.DECIMAL) {
            value = null;
        }
        EasyField easyField = EasyMetaFactory.valueOf(field);
        if (easyField.getDisplayType() == DisplayType.IMAGE || easyField.getDisplayType() == DisplayType.FILE || easyField.getDisplayType() == DisplayType.N2NREFERENCE || easyField.getDisplayType() == DisplayType.BOOL || easyField.getDisplayType() == DisplayType.STATE || easyField.getDisplayType() == DisplayType.MULTISELECT) {
            value = easyField.exprDefaultValue();
        } else if (easyField.getDisplayType() == DisplayType.BARCODE || easyField.getDisplayType() == DisplayType.ID) {
            value = ID.newId(0);
        }
        Object wrappedValue = FieldValueHelper.wrapFieldValue(value, easyField, false);
        System.out.println(field.getName() + " > " + wrappedValue + " > " + easyField.isBuiltin());
        if (wrappedValue != null) {
            System.out.println("    TYPE > " + wrappedValue.getClass().getSimpleName());
            System.out.println("  UNPACK > " + FieldValueHelper.wrapFieldValue(value, easyField, true));
        }
    }
}
Also used : Entity(cn.devezhao.persist4j.Entity) Field(cn.devezhao.persist4j.Field) EasyField(com.rebuild.core.metadata.easymeta.EasyField) EasyField(com.rebuild.core.metadata.easymeta.EasyField) Test(org.junit.jupiter.api.Test)

Aggregations

EasyField (com.rebuild.core.metadata.easymeta.EasyField)27 Field (cn.devezhao.persist4j.Field)16 JSONObject (com.alibaba.fastjson.JSONObject)15 DisplayType (com.rebuild.core.metadata.easymeta.DisplayType)11 Entity (cn.devezhao.persist4j.Entity)10 ArrayList (java.util.ArrayList)7 JSONArray (com.alibaba.fastjson.JSONArray)6 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)6 Record (cn.devezhao.persist4j.Record)4 ID (cn.devezhao.persist4j.engine.ID)4 HashMap (java.util.HashMap)4 Map (java.util.Map)4 MissingMetaExcetion (cn.devezhao.persist4j.metadata.MissingMetaExcetion)2 FieldAggregationController.buildField (com.rebuild.web.robot.trigger.FieldAggregationController.buildField)2 FieldAggregationController.isAllowSourceField (com.rebuild.web.robot.trigger.FieldAggregationController.isAllowSourceField)2 FieldType (cn.devezhao.persist4j.dialect.FieldType)1 Type (cn.devezhao.persist4j.dialect.Type)1 StandardRecord (cn.devezhao.persist4j.engine.StandardRecord)1 JSON (com.alibaba.fastjson.JSON)1 LayoutConfigService (com.rebuild.core.configuration.general.LayoutConfigService)1