use of com.rebuild.core.metadata.easymeta.EasyEntity in project rebuild by getrebuild.
the class Entity2Schema method dropEntity.
/**
* @param entity
* @param force
* @return
*/
public boolean dropEntity(Entity entity, boolean force) {
// Check admin
getUser();
EasyEntity easy = EasyMetaFactory.valueOf(entity);
ID metaRecordId = easy.getMetaId();
if (easy.isBuiltin() || metaRecordId == null) {
throw new MetadataModificationException(Language.L("系统内置,不允许删除"));
}
if (entity.getDetailEntity() != null) {
if (force) {
log.warn("Force drop detail-entity first : " + entity.getDetailEntity().getName());
boolean dropDetail = this.dropEntity(entity.getDetailEntity(), true);
if (dropDetail) {
entity = MetadataHelper.getEntity(entity.getEntityCode());
} else {
throw new MetadataModificationException(Language.L("不能直接删除主实体,请先删除明细实体"));
}
} else {
throw new MetadataModificationException(Language.L("不能直接删除主实体,请先删除明细实体"));
}
}
for (Field whoRef : entity.getReferenceToFields(false)) {
if (whoRef.getOwnEntity().equals(entity))
continue;
if (whoRef.getType() == FieldType.ANY_REFERENCE)
continue;
throw new MetadataModificationException(Language.L("实体已被其他实体引用 (引用实体 : %s)", Language.L(whoRef.getOwnEntity())));
}
// 有记录的强删
if (!force) {
long count;
if ((count = checkRecordCount(entity)) > 0) {
throw new MetadataModificationException(Language.L("不能删除有数据的实体 (记录数 : %d)", count));
}
}
// 先删配置
final ID sessionUser = UserContextHolder.getUser(true);
if (sessionUser == null)
UserContextHolder.setUser(getUser());
try {
Application.getBean(MetaEntityService.class).delete(metaRecordId);
} finally {
if (sessionUser == null)
UserContextHolder.clear();
}
// 最后删表
String ddl = String.format("drop table if exists `%s`", entity.getPhysicalName());
try {
Application.getSqlExecutor().execute(ddl, 10 * 60);
} catch (Throwable ex) {
log.error("DDL ERROR : \n" + ddl, ex);
return false;
}
MetadataHelper.getMetadataFactory().refresh();
return true;
}
use of com.rebuild.core.metadata.easymeta.EasyEntity in project rebuild by getrebuild.
the class MetaSchemaGenerator method performEntity.
private JSON performEntity(Entity entity, boolean detail) {
JSONObject schemaEntity = new JSONObject(true);
// 实体
EasyEntity easyEntity = EasyMetaFactory.valueOf(entity);
schemaEntity.put("entity", entity.getName());
schemaEntity.put("entityIcon", easyEntity.getIcon());
schemaEntity.put("entityLabel", easyEntity.getLabel());
if (easyEntity.getComments() != null) {
schemaEntity.put("comments", easyEntity.getComments());
}
schemaEntity.put("nameField", entity.getNameField().getName());
schemaEntity.put("quickFields", easyEntity.getExtraAttr("quickFields"));
// 字段
JSONArray metaFields = new JSONArray();
for (Field field : entity.getFields()) {
if (field.getType() == FieldType.PRIMARY || MetadataHelper.isCommonsField(field) || (detail && MetadataHelper.getDetailToMainField(entity).equals(field))) {
continue;
}
metaFields.add(performField(field));
}
schemaEntity.put("fields", metaFields);
// 表单回填
schemaEntity.put(CFG_FILLINS, performFillins(entity));
// 布局
schemaEntity.put(CFG_LAYOUTS, performLayouts(entity));
// 高级查询
schemaEntity.put(CFG_FILTERS, performFilters(entity));
// 触发器
schemaEntity.put(CFG_TRIGGERS, performTriggers(entity));
if (!detail) {
// 审批流程
schemaEntity.put(CFG_APPROVALS, performApprovals(entity));
// 字段转换
schemaEntity.put(CFG_TRANSFORMS, performTransforms(entity));
}
return schemaEntity;
}
use of com.rebuild.core.metadata.easymeta.EasyEntity in project rebuild by getrebuild.
the class MetaEntityController method setEntityBase.
/**
* 设置实体信息
*
* @param mv
* @param entity
* @return
*/
protected static EasyEntity setEntityBase(ModelAndView mv, String entity) {
EasyEntity entityMeta = EasyMetaFactory.valueOf(entity);
mv.getModel().put("entityMetaId", entityMeta.getMetaId());
mv.getModel().put("entityName", entityMeta.getName());
mv.getModel().put("entityLabel", entityMeta.getLabel());
mv.getModel().put("icon", entityMeta.getIcon());
mv.getModel().put("comments", entityMeta.getComments());
mv.getModel().put("entityCode", entityMeta.getRawMeta().getEntityCode());
return entityMeta;
}
use of com.rebuild.core.metadata.easymeta.EasyEntity in project rebuild by getrebuild.
the class MetaEntityController method listEntity.
@RequestMapping("entity/entity-list")
public RespBody listEntity(HttpServletRequest request) {
boolean usesBizz = getBoolParameter(request, "bizz", false);
boolean usesDetail = getBoolParameter(request, "detail", false);
List<Map<String, Object>> data = new ArrayList<>();
for (Entity entity : MetadataSorter.sortEntities(null, usesBizz, usesDetail)) {
EasyEntity easyMeta = EasyMetaFactory.valueOf(entity);
Map<String, Object> map = new HashMap<>();
map.put("entityName", easyMeta.getName());
map.put("entityLabel", easyMeta.getLabel());
map.put("comments", easyMeta.getComments());
map.put("icon", easyMeta.getIcon());
map.put("builtin", easyMeta.isBuiltin());
if (entity.getDetailEntity() != null) {
map.put("detailEntity", entity.getDetailEntity().getName());
}
if (entity.getMainEntity() != null) {
map.put("mainEntity", entity.getMainEntity().getName());
}
map.put("tags", easyMeta.getExtraAttr(EasyEntityConfigProps.TAGS));
data.add(map);
}
return RespBody.ok(data);
}
use of com.rebuild.core.metadata.easymeta.EasyEntity in project rebuild by getrebuild.
the class MetaEntityController method pageBase.
@GetMapping("entity/{entity}/base")
public ModelAndView pageBase(@PathVariable String entity, HttpServletResponse response) throws IOException {
Entity metaEntity = MetadataHelper.getEntity(entity);
// 不允许访问
if (!(MetadataHelper.isBusinessEntity(metaEntity) || MetadataHelper.isBizzEntity(metaEntity))) {
response.sendError(403);
return null;
}
ModelAndView mv = createModelAndView("/admin/metadata/entity-edit");
EasyEntity easyEntity = setEntityBase(mv, entity);
mv.getModel().put("nameField", metaEntity.getNameField().getName());
if (metaEntity.getMainEntity() != null) {
mv.getModel().put("mainEntity", metaEntity.getMainEntity().getName());
mv.getModel().put("detailEntity", metaEntity.getName());
} else if (metaEntity.getDetailEntity() != null) {
mv.getModel().put("mainEntity", metaEntity.getName());
mv.getModel().put("detailEntity", metaEntity.getDetailEntity().getName());
}
// 扩展配置
mv.getModel().put("entityExtConfig", easyEntity.getExtraAttrs(true));
return mv;
}
Aggregations