You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
62 lines
2.9 KiB
62 lines
2.9 KiB
package com.fr.plugin.pack; |
|
|
|
import com.finebi.common.api.vo.table.parameter.Parameters; |
|
import com.finebi.common.exception.FineEngineException; |
|
import com.finebi.common.exception.execute.FineWidgetNoDataException; |
|
import com.finebi.dashboard.api.bean.widget.WidgetBean; |
|
import com.finebi.dashboard.api.cell.DashboardCellCreator; |
|
import com.finebi.dashboard.api.fun.AbstractWidgetExecuteProvider; |
|
import com.finebi.dashboard.api.structure.result.preview.BIPreViewResult; |
|
import com.finebi.dashboard.impl.widget.EngineResultToPreViewResultVisitor; |
|
import com.finebi.dashboard.impl.widget.FineWidget; |
|
import com.finebi.dashboard.impl.widget.visitor.DefaultBeanToWidget; |
|
import com.finebi.dashboard.impl.widget.visitor.TableAbsentChecker; |
|
import com.finebi.dashboard.impl.widget.visitor.UrlParameterProcessor; |
|
import com.finebi.dashboard.impl.widget.visitor.WidgetBeanToFineWidgetVisitor; |
|
import com.finebi.foundation.api.structure.result.BIResult; |
|
import com.fr.decision.authority.data.User; |
|
import com.fr.plugin.pack.exception.WidgetExceedException; |
|
import com.fr.plugin.pack.traffic.PackTraffic; |
|
import com.fr.plugin.pack.traffic.PackTrafficFactory; |
|
|
|
import java.util.Optional; |
|
|
|
/** |
|
* @author Jonas |
|
* @version 5.1.3 |
|
* Created by Jonas on 2020-10-19 |
|
*/ |
|
public class PackWidgetExecuteProvider extends AbstractWidgetExecuteProvider { |
|
private PackTraffic widgetTraffic = PackTrafficFactory.getWidgetTraffic(); |
|
|
|
@Override |
|
public BIPreViewResult getPreViewResult(WidgetBean widgetBean, User user, Parameters parameters) throws FineEngineException { |
|
String widgetId = null; |
|
try { |
|
widgetId = widgetBean.getWid(); |
|
if (!widgetTraffic.offer(widgetId)) { |
|
throw new WidgetExceedException(); |
|
} |
|
return getResult(widgetBean, user, parameters); |
|
} finally { |
|
widgetTraffic.release(widgetId); |
|
} |
|
} |
|
|
|
private BIPreViewResult getResult(WidgetBean widgetBean, User user, Parameters parameters) throws FineEngineException { |
|
// bean转widget |
|
TableAbsentChecker.check(widgetBean); |
|
FineWidget widget = new DefaultBeanToWidget<>(new WidgetBeanToFineWidgetVisitor(user)) |
|
.addProcess(new UrlParameterProcessor(parameters)) |
|
.translate(widgetBean); |
|
// 从引擎拿计算数据 |
|
BIResult engineResult = getEngineExecutorResult(widget); |
|
EngineResultToPreViewResultVisitor resultTranVisitor = new EngineResultToPreViewResultVisitor(engineResult, parameters); |
|
return widget.accept(resultTranVisitor); |
|
} |
|
|
|
private BIResult getEngineExecutorResult(FineWidget fineWidget) throws FineEngineException { |
|
Optional<BIResult> execute = DashboardCellCreator.widgetExecutor().execute(fineWidget); |
|
return execute.orElseThrow(() -> new FineWidgetNoDataException("widget result is null !widget name is : " + fineWidget.getWidgetName())); |
|
} |
|
}
|
|
|