Search in sources :

Example 1 with RebuildException

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);
}
Also used : UserService(com.rebuild.core.privileges.UserService) ServiceSpec(com.rebuild.core.service.ServiceSpec) RebuildException(com.rebuild.core.RebuildException) Test(org.junit.jupiter.api.Test)

Example 2 with RebuildException

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);
    }
}
Also used : Response(com.qiniu.http.Response) QiniuException(com.qiniu.common.QiniuException) BucketManager(com.qiniu.storage.BucketManager) RebuildException(com.rebuild.core.RebuildException)

Example 3 with RebuildException

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;
}
Also used : Field(cn.devezhao.persist4j.Field) RebuildException(com.rebuild.core.RebuildException) ID(cn.devezhao.persist4j.engine.ID) MetadataModificationException(com.rebuild.core.metadata.impl.MetadataModificationException)

Example 4 with RebuildException

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;
}
Also used : ArrayList(java.util.ArrayList) RebuildException(com.rebuild.core.RebuildException) AnalysisContext(com.alibaba.excel.context.AnalysisContext) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) AnalysisEventListener(com.alibaba.excel.event.AnalysisEventListener) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) List(java.util.List) ArrayList(java.util.ArrayList) Map(java.util.Map) Cell(cn.devezhao.commons.excel.Cell)

Example 5 with RebuildException

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();
        }
    }
}
Also used : ExpressionRuntimeException(com.googlecode.aviator.exception.ExpressionRuntimeException) RebuildException(com.rebuild.core.RebuildException) MissingMetaExcetion(cn.devezhao.persist4j.metadata.MissingMetaExcetion) ID(cn.devezhao.persist4j.engine.ID) RepeatedRecordsException(com.rebuild.core.service.general.RepeatedRecordsException)

Aggregations

RebuildException (com.rebuild.core.RebuildException)16 ID (cn.devezhao.persist4j.engine.ID)4 Entity (cn.devezhao.persist4j.Entity)2 JSONObject (com.alibaba.fastjson.JSONObject)2 File (java.io.File)2 ArrayList (java.util.ArrayList)2 Map (java.util.Map)2 Cipher (javax.crypto.Cipher)2 SecretKeySpec (javax.crypto.spec.SecretKeySpec)2 Cell (cn.devezhao.commons.excel.Cell)1 Field (cn.devezhao.persist4j.Field)1 Record (cn.devezhao.persist4j.Record)1 PersistManagerImpl (cn.devezhao.persist4j.engine.PersistManagerImpl)1 MetadataException (cn.devezhao.persist4j.metadata.MetadataException)1 MissingMetaExcetion (cn.devezhao.persist4j.metadata.MissingMetaExcetion)1 AnalysisContext (com.alibaba.excel.context.AnalysisContext)1 AnalysisEventListener (com.alibaba.excel.event.AnalysisEventListener)1 JSON (com.alibaba.fastjson.JSON)1 JSONArray (com.alibaba.fastjson.JSONArray)1 EncodeHintType (com.google.zxing.EncodeHintType)1