@Slf4j
public
class
ObjectDataController
implements
IObjectDataController {
@Resource
ObjectDescribeServiceImpl objectDescribeService;
@Resource
ObjectDataProxy objectDataProxy;
@Resource
LayoutServiceImpl layoutService;
@Override
public
FcpServiceResult findById(FindObjectDataArg arg) {
if
(validateArg(arg)) {
return
FCPUtils.buildFcpServiceResult(
null
, Status.CODE_ERROR, Status.MESSAGE_PARAMETER_IS_NULL,
null
);
}
try
{
IObjectDescribe describe;
describe = getObjectDescribeInstance(arg, arg.getObject_describe_id(), arg.getObject_describe_apiname(), Id.parse(arg.getObject_describe_id()));
if
(
null
== describe) {
return
FCPUtils.buildFcpServiceResult(
null
, Status.CODE_NOT_FOUND, Status.MESSAGE_NOT_FOUND,
null
);
}
IObjectData objectData = objectDataProxy.findById(Id.parse(arg.getObject_data_id()), describe.getTenantId(), describe.getApiName());
return
getFcpServiceResult(arg, describe, objectData);
}
catch
(Exception e) {
log.error(
"find object data err. tenant_id:{},object_describe_id:{}, object_data_id:{}"
, arg.getEnterpriseId(), arg.getObject_describe_id(), arg.getObject_data_id(), e);
return
FCPUtils.buildFcpServiceResult(
null
, Status.CODE_ERROR, Status.MESSAGE_ERROR, e);
}
}
private
FcpServiceResult getFcpServiceResult(FindObjectDataArg arg, IObjectDescribe describe, IObjectData objectData) {
if
(
null
== objectData) {
return
FCPUtils.buildFcpServiceResult(
null
, Status.CODE_NOT_FOUND, Status.MESSAGE_NOT_FOUND,
null
);
}
else
{
ILayout layout =
null
;
if
(arg.isInclude_layout()) {
layout = layoutService.findDefault(describe.getApiName(), arg.getEnterpriseId());
if
(
null
== layout) {
return
FCPUtils.buildFcpServiceResult(
null
, Status.CODE_NOT_FOUND, Status.MESSAGE_NOT_FOUND,
null
);
}
}
return
FCPUtils.buildFcpServiceResult(FCPResult.builder().objectDescribe(((ObjectDescribe) describe).getContainerDocument()).objectData(objectData).layout(layout !=
null
? ((Layout) layout).getContainerDocument() :
null
).build(), Status.CODE_OK, Status.MESSAGE_OK,
null
);
}
}
private
IObjectDescribe getObjectDescribeInstance(FindObjectDataArg arg, String object_describe_id, String object_describe_apiname, Id parse) {
IObjectDescribe describe;
if
(Strings.isNullOrEmpty(object_describe_id)) {
describe =
objectDescribeService.findByTenantIdAndObjectDescribeApiName(arg.getEnterpriseId(), object_describe_apiname);
}
else
{
describe = objectDescribeService.findById(arg.getEnterpriseId(), parse);
}
return
describe;
}
}