use of com.rebuild.core.service.general.RepeatedRecordsException in project rebuild by getrebuild.
the class RobotTriggerObserver method execAction.
/**
* 执行触发内容
*
* @param context
* @param when
*/
protected void execAction(OperatingContext context, TriggerWhen when) {
final ID primaryId = context.getAnyRecord().getPrimary();
final String sourceName = primaryId + ":" + when.name().charAt(0);
TriggerAction[] beExecuted = when == TriggerWhen.DELETE ? DELETE_ACTION_HOLDS.get(primaryId) : RobotTriggerManager.instance.getActions(getEffectedId(context), when);
if (beExecuted == null || beExecuted.length == 0) {
return;
}
final boolean originTriggerSource = getTriggerSource() == null;
// 设置原始触发源
if (originTriggerSource) {
TRIGGER_SOURCE.set(context);
} else {
// 自己触发自己,避免无限执行
boolean x = primaryId.equals(getTriggerSource().getAnyRecord().getPrimary());
boolean xor = x || sourceName.equals(TRIGGER_SOURCE_LAST.get());
if (x || xor) {
if (Application.devMode())
log.warn("Self trigger, ignore : {}", sourceName);
return;
}
}
TRIGGER_SOURCE_LAST.set(sourceName);
try {
for (TriggerAction action : beExecuted) {
log.info("Trigger [ {} ] executing on record ({}) : {}", action.getType(), when.name(), primaryId);
try {
action.execute(context);
CommonsLog.createLog(TYPE_TRIGGER, context.getOperator(), action.getActionContext().getConfigId());
} catch (Throwable ex) {
// DataValidate 直接抛出
if (ex instanceof DataValidateException)
throw ex;
log.error("Trigger execution failed : {} << {}", action, context, ex);
CommonsLog.createLog(TYPE_TRIGGER, context.getOperator(), action.getActionContext().getConfigId(), ex);
// FIXME 触发器执行失败是否抛出
if (ex instanceof MissingMetaExcetion || ex instanceof ExpressionRuntimeException || ex instanceof RepeatedRecordsException) {
throw new TriggerException(Language.L("触发器执行失败 : %s", ex.getLocalizedMessage()));
} else if (ex instanceof TriggerException) {
throw (TriggerException) ex;
} else {
throw new RebuildException(ex);
}
} finally {
if (originTriggerSource) {
action.clean();
}
}
}
} finally {
if (originTriggerSource) {
TRIGGER_SOURCE.remove();
TRIGGER_SOURCE_LAST.remove();
}
}
}
use of com.rebuild.core.service.general.RepeatedRecordsException in project rebuild by getrebuild.
the class ModelExtrasController method transform.
// 记录转换
@RequestMapping("transform")
public RespBody transform(HttpServletRequest request) {
ID transid = getIdParameterNotNull(request, "transid");
ID sourceRecord = getIdParameterNotNull(request, "source");
ID mainid = getIdParameter(request, "mainid");
ConfigBean config = TransformManager.instance.getTransformConfig(transid, null);
Entity targetEntity = MetadataHelper.getEntity(config.getString("target"));
RecordTransfomer transfomer = new RecordTransfomer(targetEntity, (JSONObject) config.getJSON("config"));
if (!transfomer.checkFilter(sourceRecord)) {
return RespBody.error(Language.L("当前记录不符合转换条件"), 400);
}
try {
ID newId = transfomer.transform(sourceRecord, mainid);
return RespBody.ok(newId);
} catch (Exception ex) {
log.warn(">>>>> {}", ex.getLocalizedMessage());
String detail = ex.getLocalizedMessage();
if (ex instanceof RepeatedRecordsException) {
detail = Language.L("存在重复记录");
}
return RespBody.errorl("记录转换失败 (%s)", detail);
}
}
Aggregations