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;
}
Aggregations