use of com.rebuild.core.RebuildException 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.RebuildException in project rebuild by getrebuild.
the class QiniuCloud method delete.
/**
* 删除文件
*
* @param key
* @return
*/
protected boolean delete(String key) {
BucketManager bucketManager = new BucketManager(getAuth(), CONFIGURATION);
Response resp;
try {
resp = bucketManager.delete(this.bucketName, key);
if (resp.isOK()) {
return true;
} else {
throw new RebuildException("Failed to delete file : " + this.bucketName + " < " + key + " : " + resp.bodyString());
}
} catch (QiniuException e) {
throw new RebuildException("Failed to delete file : " + this.bucketName + " < " + key, e);
}
}
use of com.rebuild.core.RebuildException in project rebuild by getrebuild.
the class ApprovalFields2Schema method createFields.
/**
* @param approvalEntity
* @return Returns true if successful
* @throws MetadataModificationException
*/
public boolean createFields(Entity approvalEntity) throws MetadataModificationException {
if (MetadataHelper.hasApprovalField(approvalEntity)) {
if (!approvalEntity.containsField(EntityHelper.ApprovalLastUser)) {
return createApporvalLastUser(approvalEntity);
}
return false;
}
if (!(MetadataHelper.hasPrivilegesField(approvalEntity) || EasyMetaFactory.valueOf(approvalEntity).isPlainEntity())) {
throw new RebuildException("UNSUPPORTED ENTITY : " + approvalEntity.getName());
}
Field apporvalId = createUnsafeField(approvalEntity, EntityHelper.ApprovalId, Language.L("审批流程"), DisplayType.REFERENCE, true, false, false, true, true, null, "RobotApprovalConfig", CascadeModel.Ignore, null, null);
Field apporvalState = createUnsafeField(approvalEntity, EntityHelper.ApprovalState, Language.L("审批状态"), DisplayType.STATE, true, false, false, true, true, null, null, null, null, ApprovalState.DRAFT.getState());
Field apporvalStepId = createUnsafeField(approvalEntity, EntityHelper.ApprovalStepNode, Language.L("审批步骤"), DisplayType.TEXT, true, false, false, true, false, null, null, null, null, null);
Field apporvalLastUser = buildApporvalLastUser(approvalEntity);
boolean schemaReady = schema2Database(approvalEntity, new Field[] { apporvalId, apporvalState, apporvalStepId, apporvalLastUser });
if (!schemaReady) {
Application.getCommonsService().delete(recordedMetaId.toArray(new ID[0]));
throw new MetadataModificationException(Language.L("无法同步元数据到数据库"));
}
MetadataHelper.getMetadataFactory().refresh();
return true;
}
use of com.rebuild.core.RebuildException in project rebuild by getrebuild.
the class ExcelUtils method readExcel.
/**
* @param excel
* @param maxRows
* @param hasHead
* @return
*/
public static List<Cell[]> readExcel(File excel, int maxRows, boolean hasHead) {
final List<Cell[]> rows = new ArrayList<>();
final AtomicInteger rowNo = new AtomicInteger(0);
try (InputStream is = new FileInputStream(excel)) {
try (BufferedInputStream bis = new BufferedInputStream(is)) {
// noinspection rawtypes
EasyExcel.read(bis, null, new AnalysisEventListener() {
@Override
public void invokeHeadMap(Map headMap, AnalysisContext context) {
if (hasHead) {
this.invoke(headMap, context);
} else {
rowNo.incrementAndGet();
}
}
@Override
public void invoke(Object data, AnalysisContext analysisContext) {
if (maxRows > 0 && rows.size() >= maxRows) {
return;
}
@SuppressWarnings("unchecked") Map<Integer, String> dataMap = (Map<Integer, String>) data;
List<Cell> row = new ArrayList<>();
for (int i = 0; i < dataMap.size(); i++) {
row.add(new Cell(dataMap.get(i), rowNo.get(), i));
}
rows.add(row.toArray(new Cell[0]));
rowNo.incrementAndGet();
}
@Override
public void doAfterAllAnalysed(AnalysisContext analysisContext) {
}
}).sheet().doRead();
}
} catch (IOException e) {
throw new RebuildException(e);
}
return rows;
}
use of com.rebuild.core.RebuildException 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();
}
}
}
Aggregations