Search in sources :

Example 1 with RecordTransfomer

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);
    }
}
Also used : EasyEntity(com.rebuild.core.metadata.easymeta.EasyEntity) Entity(cn.devezhao.persist4j.Entity) ID(cn.devezhao.persist4j.engine.ID) ConfigBean(com.rebuild.core.configuration.ConfigBean) RecordTransfomer(com.rebuild.core.service.general.transform.RecordTransfomer) RepeatedRecordsException(com.rebuild.core.service.general.RepeatedRecordsException) RepeatedRecordsException(com.rebuild.core.service.general.RepeatedRecordsException) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

Entity (cn.devezhao.persist4j.Entity)1 ID (cn.devezhao.persist4j.engine.ID)1 ConfigBean (com.rebuild.core.configuration.ConfigBean)1 EasyEntity (com.rebuild.core.metadata.easymeta.EasyEntity)1 RepeatedRecordsException (com.rebuild.core.service.general.RepeatedRecordsException)1 RecordTransfomer (com.rebuild.core.service.general.transform.RecordTransfomer)1 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)1