Search in sources :

Example 1 with MetaschemaImporter

use of com.rebuild.core.rbstore.MetaschemaImporter in project rebuild by getrebuild.

the class CopyEntity method copy.

/**
 * @param entityName
 * @param detailName
 * @return
 */
public String copy(String entityName, String detailName) {
    final ID user = getUser();
    RbAssert.isAllow(UserHelper.isSuperAdmin(user), Language.L("仅超级管理员可操作"));
    // 导出
    JSONObject schemadata = (JSONObject) new MetaSchemaGenerator(sourceEntity).generate();
    String uniqueEntityName = clearConfig(schemadata, entityName);
    JSONObject detailSchema = schemadata.getJSONObject("detail");
    if (StringUtils.isBlank(detailName)) {
        schemadata.remove("detail");
    } else if (detailSchema != null) {
        clearConfig(detailSchema, detailName);
    }
    // 导入
    MetaschemaImporter importer = new MetaschemaImporter(schemadata);
    importer.setUser(user);
    TaskExecutors.run(importer);
    return uniqueEntityName;
}
Also used : JSONObject(com.alibaba.fastjson.JSONObject) MetaSchemaGenerator(com.rebuild.core.rbstore.MetaSchemaGenerator) ID(cn.devezhao.persist4j.engine.ID) MetaschemaImporter(com.rebuild.core.rbstore.MetaschemaImporter)

Example 2 with MetaschemaImporter

use of com.rebuild.core.rbstore.MetaschemaImporter in project rebuild by getrebuild.

the class TestSupport method addTestEntities.

/**
 * 添加测试用实体
 *
 * @param dropExists
 * @return
 * @throws Exception
 */
@SuppressWarnings("SameParameterValue")
protected static boolean addTestEntities(boolean dropExists) throws Exception {
    boolean changed = false;
    if (dropExists) {
        if (MetadataHelper.containsEntity(TestAllFields)) {
            LOG.warn("Dropping test entity : " + TestAllFields);
            new Entity2Schema(UserService.ADMIN_USER).dropEntity(MetadataHelper.getEntity(TestAllFields), true);
        }
        if (MetadataHelper.containsEntity(SalesOrder)) {
            LOG.warn("Dropping test entity : " + SalesOrder);
            new Entity2Schema(UserService.ADMIN_USER).dropEntity(MetadataHelper.getEntity(SalesOrder), true);
        }
        if (MetadataHelper.containsEntity(Account)) {
            LOG.warn("Dropping test entity : " + Account);
            new Entity2Schema(UserService.ADMIN_USER).dropEntity(MetadataHelper.getEntity(Account), true);
        }
    }
    if (!MetadataHelper.containsEntity(TestAllFields)) {
        Entity2Schema entity2Schema = new Entity2Schema(UserService.ADMIN_USER);
        String entityName = entity2Schema.createEntity(TestAllFields.toUpperCase(), null, null, true);
        Entity testEntity = MetadataHelper.getEntity(entityName);
        for (DisplayType dt : DisplayType.values()) {
            if (dt == DisplayType.ID || dt == DisplayType.ANYREFERENCE) {
                continue;
            }
            String fieldName = dt.name().toUpperCase();
            if (BlockList.isBlock(fieldName))
                fieldName += "1";
            if (dt == DisplayType.REFERENCE || dt == DisplayType.N2NREFERENCE) {
                new Field2Schema(UserService.ADMIN_USER).createField(testEntity, fieldName, dt, null, entityName, null);
            } else if (dt == DisplayType.CLASSIFICATION) {
                JSON extra = JSON.parseObject("{classification:'018-0000000000000001'}");
                new Field2Schema(UserService.ADMIN_USER).createField(testEntity, fieldName, dt, null, entityName, extra);
            } else if (dt == DisplayType.STATE) {
                JSON extra = JSON.parseObject("{stateClass:'com.rebuild.core.support.state.HowtoState'}");
                new Field2Schema(UserService.ADMIN_USER).createField(testEntity, fieldName, dt, null, entityName, extra);
            } else {
                new Field2Schema(UserService.ADMIN_USER).createField(testEntity, fieldName, dt, null, null, null);
            }
        }
        changed = true;
    }
    if (!MetadataHelper.containsEntity(Account)) {
        String metaschema = FileUtils.readFileToString(ResourceUtils.getFile("classpath:schema-Account999.json"));
        MetaschemaImporter importer = new MetaschemaImporter(JSON.parseObject(metaschema));
        TaskExecutors.run((HeavyTask<?>) importer.setUser(UserService.ADMIN_USER));
        changed = true;
    }
    if (!MetadataHelper.containsEntity(SalesOrder)) {
        String metaschema = FileUtils.readFileToString(ResourceUtils.getFile("classpath:schema-SalesOrder999.json"));
        MetaschemaImporter importer = new MetaschemaImporter(JSON.parseObject(metaschema));
        TaskExecutors.run((HeavyTask<?>) importer.setUser(UserService.ADMIN_USER));
        changed = true;
    }
    return changed;
}
Also used : Entity(cn.devezhao.persist4j.Entity) Entity2Schema(com.rebuild.core.metadata.impl.Entity2Schema) DisplayType(com.rebuild.core.metadata.easymeta.DisplayType) Field2Schema(com.rebuild.core.metadata.impl.Field2Schema) JSON(com.alibaba.fastjson.JSON) MetaschemaImporter(com.rebuild.core.rbstore.MetaschemaImporter)

Aggregations

MetaschemaImporter (com.rebuild.core.rbstore.MetaschemaImporter)2 Entity (cn.devezhao.persist4j.Entity)1 ID (cn.devezhao.persist4j.engine.ID)1 JSON (com.alibaba.fastjson.JSON)1 JSONObject (com.alibaba.fastjson.JSONObject)1 DisplayType (com.rebuild.core.metadata.easymeta.DisplayType)1 Entity2Schema (com.rebuild.core.metadata.impl.Entity2Schema)1 Field2Schema (com.rebuild.core.metadata.impl.Field2Schema)1 MetaSchemaGenerator (com.rebuild.core.rbstore.MetaSchemaGenerator)1