use of com.rebuild.core.service.dashboard.charts.builtin.BuiltinChart in project rebuild by getrebuild.
the class ChartsFactory method create.
/**
* @param config
* @param user
* @return
* @throws ChartsException
*/
public static ChartData create(JSONObject config, ID user) throws ChartsException {
String entityName = config.getString("entity");
if (!MetadataHelper.containsEntity(entityName)) {
throw new ChartsException(Language.L("源实体 [%s] 已不存在", entityName.toUpperCase()));
}
Entity entity = MetadataHelper.getEntity(entityName);
if (user == null || !Application.getPrivilegesManager().allowRead(user, entity.getEntityCode())) {
throw new DefinedException(Language.L("没有读取 %s 的权限", EasyMetaFactory.getLabel(entity)));
}
String type = config.getString("type");
if ("INDEX".equalsIgnoreCase(type)) {
return (ChartData) new IndexChart(config).setUser(user);
} else if ("TABLE".equalsIgnoreCase(type)) {
return (ChartData) new TableChart(config).setUser(user);
} else if ("LINE".equalsIgnoreCase(type)) {
return (ChartData) new LineChart(config).setUser(user);
} else if ("BAR".equalsIgnoreCase(type)) {
return (ChartData) new BarChart(config).setUser(user);
} else if ("PIE".equalsIgnoreCase(type)) {
return (ChartData) new PieChart(config).setUser(user);
} else if ("FUNNEL".equalsIgnoreCase(type)) {
return (ChartData) new FunnelChart(config).setUser(user);
} else if ("TREEMAP".equalsIgnoreCase(type)) {
return (ChartData) new TreemapChart(config).setUser(user);
} else if ("RADAR".equalsIgnoreCase(type)) {
return (ChartData) new RadarChart(config).setUser(user);
} else if ("SCATTER".equalsIgnoreCase(type)) {
return (ChartData) new ScatterChart(config).setUser(user);
} else {
for (BuiltinChart ch : getBuiltinCharts()) {
if (ch.getChartType().equalsIgnoreCase(type)) {
return (ChartData) ((ChartData) ch).setUser(user);
}
}
}
throw new ChartsException("Unknown chart type : " + type);
}
use of com.rebuild.core.service.dashboard.charts.builtin.BuiltinChart in project rebuild by getrebuild.
the class ChartManager method getChart.
/**
* @param chartid
* @return
*/
public ConfigBean getChart(ID chartid) {
final String ckey = "Chart-" + chartid;
ConfigBean cb = (ConfigBean) Application.getCommonsCache().getx(ckey);
if (cb != null) {
return cb.clone();
}
Object[] o = Application.createQueryNoFilter("select title,chartType,config,createdBy from ChartConfig where chartId = ?").setParameter(1, chartid).unique();
if (o == null) {
for (BuiltinChart ch : ChartsFactory.getBuiltinCharts()) {
if (chartid.equals(ch.getChartId())) {
o = new Object[] { ch.getChartTitle(), ch.getChartType(), ch.getChartConfig(), UserService.SYSTEM_USER };
}
}
if (o == null) {
return null;
}
}
cb = new ConfigBean().set("title", o[0]).set("type", o[1]).set("config", o[2] instanceof JSON ? o[2] : JSON.parse((String) o[2])).set("createdBy", o[3]);
Application.getCommonsCache().putx(ckey, cb);
return cb.clone();
}
use of com.rebuild.core.service.dashboard.charts.builtin.BuiltinChart in project rebuild by getrebuild.
the class DashboardController method chartList.
@GetMapping("/chart-list")
public JSONArray chartList(HttpServletRequest request) {
final ID user = getRequestUser(request);
String type = request.getParameter("type");
JSONArray charts;
if ("BUILTIN".equalsIgnoreCase(type)) {
charts = (JSONArray) JSONUtils.EMPTY_ARRAY.clone();
} else {
// 指定实体
String[] specEntity = null;
if ("ENTITY".equalsIgnoreCase(type)) {
String entity = getParameterNotNull(request, "entity");
Entity entityMeta = MetadataHelper.getEntity(entity);
if (entityMeta.getMainEntity() != null) {
specEntity = new String[] { entity, entityMeta.getMainEntity().getName() };
} else if (entityMeta.getDetailEntity() != null) {
specEntity = new String[] { entity, entityMeta.getDetailEntity().getName() };
} else {
specEntity = new String[] { entity };
}
}
charts = ChartManager.instance.getChartList(user, specEntity, "MYSELF".equalsIgnoreCase(type));
}
// 附加内置图表
if (!("ENTITY".equalsIgnoreCase(type) || "MYSELF".equalsIgnoreCase(type))) {
for (BuiltinChart b : ChartsFactory.getBuiltinCharts()) {
charts.add(JSONUtils.toJSONObject(new String[] { "id", "title", "type", "entityLabel" }, new Object[] { b.getChartId(), b.getChartTitle(), b.getChartType(), Language.L("内置") }));
}
}
return charts;
}
Aggregations