Search in sources :

Example 6 with EntityRecordCreator

use of com.rebuild.core.metadata.EntityRecordCreator in project rebuild by getrebuild.

the class DataImporter method checkoutRecord.

/**
 * @param row
 * @return
 */
protected Record checkoutRecord(Cell[] row) {
    Record recordHub = EntityHelper.forNew(rule.getToEntity().getEntityCode(), this.owningUser);
    // 解析数据
    RecordCheckout recordCheckout = new RecordCheckout(rule.getFiledsMapping());
    Record checkout = recordCheckout.checkout(recordHub, row);
    if (recordCheckout.getTraceLogs().isEmpty()) {
        cellTraces = null;
    } else {
        cellTraces = StringUtils.join(recordCheckout.getTraceLogs(), ", ");
    }
    // 检查重复
    if (rule.getRepeatOpt() < ImportRule.REPEAT_OPT_IGNORE) {
        final ID repeat = findRepeatedRecordId(rule.getRepeatFields(), recordHub);
        if (repeat != null && rule.getRepeatOpt() == ImportRule.REPEAT_OPT_SKIP) {
            return null;
        }
        if (repeat != null && rule.getRepeatOpt() == ImportRule.REPEAT_OPT_UPDATE) {
            // 更新
            checkout = EntityHelper.forUpdate(repeat, this.owningUser);
            for (Iterator<String> iter = recordHub.getAvailableFieldIterator(); iter.hasNext(); ) {
                String field = iter.next();
                if (MetadataHelper.isCommonsField(field))
                    continue;
                checkout.setObjectValue(field, recordHub.getObjectValue(field));
            }
        }
    }
    // Throws DataSpecificationException
    if (checkout.getPrimary() == null) {
        new EntityRecordCreator(rule.getToEntity(), JSONUtils.EMPTY_OBJECT, null).verify(checkout);
    }
    return checkout;
}
Also used : Record(cn.devezhao.persist4j.Record) ID(cn.devezhao.persist4j.engine.ID) EntityRecordCreator(com.rebuild.core.metadata.EntityRecordCreator)

Aggregations

Record (cn.devezhao.persist4j.Record)6 EntityRecordCreator (com.rebuild.core.metadata.EntityRecordCreator)6 Entity (cn.devezhao.persist4j.Entity)5 ID (cn.devezhao.persist4j.engine.ID)1 RobotApprovalConfigService (com.rebuild.core.service.approval.RobotApprovalConfigService)1 ActionType (com.rebuild.core.service.trigger.ActionType)1 RobotTriggerConfigService (com.rebuild.core.service.trigger.RobotTriggerConfigService)1