use of com.rebuild.core.service.general.transform.RecordTransfomer 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