use of com.rebuild.core.service.ServiceSpec in project rebuild by getrebuild.
the class MetaEntityService method delete.
@Override
public int delete(ID recordId) {
Object[] entityRecord = getPersistManagerFactory().createQuery("select entityName from MetaEntity where entityId = ?").setParameter(1, recordId).unique();
final Entity delEntity = MetadataHelper.getEntity((String) entityRecord[0]);
// 删除实体的相关配置
// Field: belongEntity
String[] confEntities = new String[] { "MetaField", "PickList", "LayoutConfig", "FilterConfig", "ShareAccess", "ChartConfig", "Attachment", "AutoFillinConfig", "RobotTriggerConfig", "RobotApprovalConfig", "DataReportConfig", "TransformConfig", "ExtformConfig", "NreferenceItem" };
int del = 0;
for (String conf : confEntities) {
Entity confEntity = MetadataHelper.getEntity(conf);
String ql = String.format("select %s from %s where belongEntity = ", confEntity.getPrimaryField().getName(), confEntity.getName());
if (confEntity.getEntityCode() == EntityHelper.Attachment) {
ql += delEntity.getEntityCode();
} else {
ql += String.format("'%s'", delEntity.getName());
if (confEntity.getEntityCode() == EntityHelper.TransformConfig) {
ql += String.format(" or targetEntity = '%s'", delEntity.getName());
}
}
Object[][] usedArray = getPersistManagerFactory().createQuery(ql).array();
ServiceSpec ss = Application.getService(confEntity.getEntityCode());
for (Object[] used : usedArray) {
ss.delete((ID) used[0]);
}
if (usedArray.length > 0) {
log.warn("Deleted configuration of entity [ {} ] in [ {} ] : {}", delEntity.getName(), conf, usedArray.length);
}
}
del += super.delete(recordId);
return del;
}
use of com.rebuild.core.service.ServiceSpec in project rebuild by getrebuild.
the class Application method init.
/**
* 系统初始化
*
* @throws Exception
*/
public static boolean init() throws Exception {
if (_READY)
throw new IllegalStateException("REBUILD ALREADY STARTED");
log.info("Initializing Rebuild context [ {} ] ...", _CONTEXT.getClass().getSimpleName());
if (!(_READY = ServerStatus.checkAll())) {
log.error(RebuildBanner.formatBanner("REBUILD STARTUP FILAED DURING THE STATUS CHECK.", "PLEASE VIEW LOGS FOR MORE DETAILS."));
return false;
}
// 升级数据库
new UpgradeDatabase().upgradeQuietly();
// 版本升级会清除缓存
int lastBuild = ObjectUtils.toInt(RebuildConfiguration.get(ConfigurationItem.AppBuild, true), 0);
if (lastBuild < BUILD) {
log.warn("Clean up the cache once when upgrading : {}", BUILD);
Installer.clearAllCache();
RebuildConfiguration.set(ConfigurationItem.AppBuild, BUILD);
}
// 刷新配置缓存
for (ConfigurationItem item : ConfigurationItem.values()) {
RebuildConfiguration.get(item, true);
}
// 加载自定义实体
log.info("Loading customized/business entities ...");
((DynamicMetadataFactory) _CONTEXT.getBean(PersistManagerFactory.class).getMetadataFactory()).refresh();
// 实体对应的服务类
_ESS = new HashMap<>();
for (Map.Entry<String, ServiceSpec> e : _CONTEXT.getBeansOfType(ServiceSpec.class).entrySet()) {
ServiceSpec s = e.getValue();
if (s.getEntityCode() > 0) {
_ESS.put(s.getEntityCode(), s);
if (devMode()) {
log.info("Service specification : {} for [ {} ]", s.getClass().getName(), s.getEntityCode());
}
}
}
// 初始化业务组件
List<Initialization> ordered = new ArrayList<>(_CONTEXT.getBeansOfType(Initialization.class).values());
OrderComparator.sort(ordered);
for (Initialization bean : ordered) {
bean.init();
}
License.isRbvAttached();
DataMigrator.dataMigrateIfNeed();
return true;
}
use of com.rebuild.core.service.ServiceSpec in project rebuild by getrebuild.
the class GeneralEntityServiceTest method getServiceSpec.
@Test
public void getServiceSpec() {
ServiceSpec ss = Application.getService(EntityHelper.User);
Assertions.assertTrue(ss instanceof UserService);
EntityService es = Application.getEntityService(MetadataHelper.getEntity(TestAllFields).getEntityCode());
Assertions.assertTrue(es instanceof GeneralEntityService);
boolean exThrows = false;
try {
Application.getEntityService(EntityHelper.User);
} catch (RebuildException ok) {
exThrows = true;
}
Assertions.assertTrue(exThrows);
}
use of com.rebuild.core.service.ServiceSpec in project rebuild by getrebuild.
the class FieldAggregation method execute.
@Override
public void execute(OperatingContext operatingContext) throws TriggerException {
final String chainName = actionContext.getConfigId() + ":" + operatingContext.getAction().getName();
final List<String> tschain = checkTriggerChain(chainName);
if (tschain == null)
return;
this.prepare(operatingContext);
if (targetRecordId == null) {
log.warn("No target record found");
return;
}
// 聚合数据过滤
JSONObject dataFilter = ((JSONObject) actionContext.getActionContent()).getJSONObject("dataFilter");
String dataFilterSql = null;
if (dataFilter != null && !dataFilter.isEmpty()) {
dataFilterSql = new AdvFilterParser(dataFilter).toSqlWhere();
}
// 构建目标记录数据
Record targetRecord = EntityHelper.forUpdate(targetRecordId, UserService.SYSTEM_USER, false);
JSONArray items = ((JSONObject) actionContext.getActionContent()).getJSONArray("items");
for (Object o : items) {
JSONObject item = (JSONObject) o;
String targetField = item.getString("targetField");
if (!MetadataHelper.checkAndWarnField(targetEntity, targetField)) {
continue;
}
String filterSql = followSourceWhere;
if (dataFilterSql != null) {
filterSql = String.format("( %s ) and ( %s )", followSourceWhere, dataFilterSql);
}
Object evalValue = new AggregationEvaluator(item, sourceEntity, filterSql).eval();
if (evalValue == null)
continue;
DisplayType dt = EasyMetaFactory.getDisplayType(targetEntity.getField(targetField));
if (dt == DisplayType.NUMBER) {
targetRecord.setLong(targetField, CommonsUtils.toLongHalfUp(evalValue));
} else if (dt == DisplayType.DECIMAL) {
targetRecord.setDouble(targetField, ObjectUtils.toDouble(evalValue));
} else if (dt == DisplayType.DATE || dt == DisplayType.DATETIME) {
if (evalValue instanceof Date)
targetRecord.setDate(targetField, (Date) evalValue);
else
targetRecord.setNull(targetField);
} else {
log.warn("Unsupported file-type {} with {}", dt, targetRecordId);
}
}
// 有需要才执行
if (!targetRecord.isEmpty()) {
final boolean forceUpdate = ((JSONObject) actionContext.getActionContent()).getBooleanValue("forceUpdate");
// 跳过权限
PrivilegesGuardContextHolder.setSkipGuard(targetRecordId);
// 强制更新 (v2.9)
if (forceUpdate) {
GeneralEntityServiceContextHolder.setAllowForceUpdate(targetRecordId);
}
// 会关联触发下一触发器(如有)
tschain.add(chainName);
TRIGGERS_CHAIN.set(tschain);
ServiceSpec useService = MetadataHelper.isBusinessEntity(targetEntity) ? Application.getEntityService(targetEntity.getEntityCode()) : Application.getService(targetEntity.getEntityCode());
targetRecord.setDate(EntityHelper.ModifiedOn, CalendarUtils.now());
try {
useService.update(targetRecord);
} finally {
PrivilegesGuardContextHolder.getSkipGuardOnce();
GeneralEntityServiceContextHolder.isAllowForceUpdateOnce();
}
}
}
use of com.rebuild.core.service.ServiceSpec in project rebuild by getrebuild.
the class FieldWriteback method execute.
@Override
public void execute(OperatingContext operatingContext) throws TriggerException {
final String chainName = actionContext.getConfigId() + ":" + operatingContext.getAction().getName();
final List<String> tschain = checkTriggerChain(chainName);
if (tschain == null)
return;
this.prepare(operatingContext);
if (targetRecordIds.isEmpty())
return;
if (targetRecordData.isEmpty()) {
log.info("No data of target record available : {}", targetRecordId);
return;
}
final ServiceSpec useService = MetadataHelper.isBusinessEntity(targetEntity) ? Application.getEntityService(targetEntity.getEntityCode()) : Application.getService(targetEntity.getEntityCode());
final boolean forceUpdate = ((JSONObject) actionContext.getActionContent()).getBooleanValue("forceUpdate");
boolean tschainAdded = false;
for (ID targetRecordId : targetRecordIds) {
if (operatingContext.getAction() == BizzPermission.DELETE && targetRecordId.equals(operatingContext.getAnyRecord().getPrimary())) {
// 删除时无需更新自己
continue;
}
// 跳过权限
PrivilegesGuardContextHolder.setSkipGuard(targetRecordId);
// 强制更新 (v2.9)
if (forceUpdate) {
GeneralEntityServiceContextHolder.setAllowForceUpdate(targetRecordId);
}
// 会关联触发下一触发器
if (!tschainAdded) {
tschainAdded = true;
tschain.add(chainName);
TRIGGERS_CHAIN.set(tschain);
}
Record targetRecord = targetRecordData.clone();
targetRecord.setID(targetEntity.getPrimaryField().getName(), targetRecordId);
targetRecord.setDate(EntityHelper.ModifiedOn, CalendarUtils.now());
GeneralEntityServiceContextHolder.setRepeatedCheckMode(GeneralEntityServiceContextHolder.RCM_CHECK_MAIN);
try {
useService.createOrUpdate(targetRecord);
} finally {
PrivilegesGuardContextHolder.getSkipGuardOnce();
GeneralEntityServiceContextHolder.isAllowForceUpdateOnce();
GeneralEntityServiceContextHolder.getRepeatedCheckModeOnce();
}
}
}
Aggregations