use of com.rebuild.core.configuration.ConfigurationException in project rebuild by getrebuild.
the class ProjectController method pageProject.
@GetMapping("{projectId}/tasks")
public ModelAndView pageProject(@PathVariable String projectId, HttpServletRequest request, HttpServletResponse response) throws IOException {
final ID projectId2 = ID.isId(projectId) ? ID.valueOf(projectId) : null;
if (projectId2 == null) {
response.sendError(404);
return null;
}
final ID user = getRequestUser(request);
ConfigBean p;
try {
p = ProjectManager.instance.getProject(projectId2, getRequestUser(request));
} catch (ConfigurationException ex) {
response.sendError(403, ex.getLocalizedMessage());
return null;
}
ModelAndView mv = createModelAndView("/project/project-tasks");
mv.getModel().put("projectId", p.getID("id"));
mv.getModel().put("iconName", p.getString("iconName"));
mv.getModel().put("projectCode", p.getString("projectCode"));
mv.getModel().put("projectName", p.getString("projectName"));
mv.getModel().put("isMember", p.get("members", Set.class).contains(user));
mv.getModel().put("scope", p.getInteger("scope"));
mv.getModel().put("status", p.getInteger("status"));
// 分组显示
JSONArray plansList = new JSONArray();
String group = getParameter(request, "group");
if (GROUP_PRIORITY.equalsIgnoreCase(group)) {
plansList.add(newCustomPlan(GROUP_PRIORITY + "-3", Language.L("非常紧急")));
plansList.add(newCustomPlan(GROUP_PRIORITY + "-2", Language.L("紧急")));
plansList.add(newCustomPlan(GROUP_PRIORITY + "-1", Language.L("普通")));
plansList.add(newCustomPlan(GROUP_PRIORITY + "-0", Language.L("较低")));
} else if (GROUP_DEADLINE.equalsIgnoreCase(group)) {
plansList.add(newCustomPlan(GROUP_DEADLINE + "-1", Language.L("已逾期")));
plansList.add(newCustomPlan(GROUP_DEADLINE + "-2", Language.L("今天")));
plansList.add(newCustomPlan(GROUP_DEADLINE + "-3", Language.L("7 天内")));
plansList.add(newCustomPlan(GROUP_DEADLINE + "-4", Language.L("以后或未安排")));
} else if (GROUP_MODIFIED.equalsIgnoreCase(group)) {
plansList.add(newCustomPlan(GROUP_MODIFIED + "-1", Language.L("今天")));
plansList.add(newCustomPlan(GROUP_MODIFIED + "-2", Language.L("7 天内")));
plansList.add(newCustomPlan(GROUP_MODIFIED + "-3", Language.L("14 天内")));
plansList.add(newCustomPlan(GROUP_MODIFIED + "-4", Language.L("更早")));
} else {
final ConfigBean[] plans = ProjectManager.instance.getPlansOfProject(projectId2);
for (ConfigBean e : plans) {
plansList.add(e.toJSON());
}
}
mv.getModel().put("projectPlans", plansList.toJSONString());
return mv;
}
use of com.rebuild.core.configuration.ConfigurationException in project rebuild by getrebuild.
the class RecordTransfomer method transform.
/**
* @param sourceRecordId
* @return
* @see #checkFilter(ID)
*/
public ID transform(ID sourceRecordId, ID mainId) {
// 手动事务,因为可能要转换多条记录
TransactionStatus tx = TransactionManual.newTransaction();
try {
// 主记录
Map<String, Object> map = null;
if (mainId != null) {
Field targetDtf = MetadataHelper.getDetailToMainField(targetEntity);
map = Collections.singletonMap(targetDtf.getName(), mainId);
}
JSONObject fieldsMapping = transConfig.getJSONObject("fieldsMapping");
if (fieldsMapping == null || fieldsMapping.isEmpty()) {
throw new ConfigurationException("Invalid config of transform : " + transConfig);
}
final Entity sourceEntity = MetadataHelper.getEntity(sourceRecordId.getEntityCode());
final ID newId = transformRecord(sourceEntity, targetEntity, fieldsMapping, sourceRecordId, map);
if (newId == null) {
throw new ConfigurationException("Cannot transform record of main : " + transConfig);
}
// 明细记录(如有)
JSONObject fieldsMappingDetail = transConfig.getJSONObject("fieldsMappingDetail");
if (fieldsMappingDetail != null && !fieldsMappingDetail.isEmpty()) {
Entity sourceDetailEntity = sourceEntity.getDetailEntity();
Field sourceDtf = MetadataHelper.getDetailToMainField(sourceDetailEntity);
String sql = String.format("select %s from %s where %s = '%s'", sourceDetailEntity.getPrimaryField().getName(), sourceDetailEntity.getName(), sourceDtf.getName(), sourceRecordId);
Object[][] details = Application.createQueryNoFilter(sql).array();
Entity targetDetailEntity = targetEntity.getDetailEntity();
if (details.length > 0) {
Field targetDtf = MetadataHelper.getDetailToMainField(targetDetailEntity);
map = Collections.singletonMap(targetDtf.getName(), newId);
}
for (Object[] o : details) {
transformRecord(sourceDetailEntity, targetDetailEntity, fieldsMappingDetail, (ID) o[0], map);
}
}
// 回填
String fillbackField = transConfig.getString("fillbackField");
if (StringUtils.isNotBlank(fillbackField) && MetadataHelper.checkAndWarnField(sourceEntity, fillbackField)) {
Record updateSource = EntityHelper.forUpdate(sourceRecordId, getUser(), false);
updateSource.setID(fillbackField, newId);
// TODO 此配置未开放
int fillbackMode = transConfig.getIntValue("fillbackMode");
// 仅更新,无业务规则
if (fillbackMode == 3) {
Application.getCommonsService().update(updateSource, false);
} else // 忽略审批状态(进行中)强制更新
if (fillbackMode == 2) {
GeneralEntityServiceContextHolder.setAllowForceUpdate(updateSource.getPrimary());
try {
Application.getEntityService(sourceEntity.getEntityCode()).update(updateSource);
} finally {
GeneralEntityServiceContextHolder.isAllowForceUpdateOnce();
}
} else // 默认
{
Application.getEntityService(sourceEntity.getEntityCode()).update(updateSource);
}
}
TransactionManual.commit(tx);
return newId;
} catch (Exception ex) {
TransactionManual.rollback(tx);
throw ex;
}
}
use of com.rebuild.core.configuration.ConfigurationException in project rebuild by getrebuild.
the class ReportTemplateController method preview.
@GetMapping("/report-templates/preview")
public void preview(@IdParam ID reportId, HttpServletResponse response) throws IOException {
Object[] report = Application.createQueryNoFilter("select belongEntity,templateType from DataReportConfig where configId = ?").setParameter(1, reportId).unique();
Entity entity = MetadataHelper.getEntity((String) report[0]);
String sql = String.format("select %s from %s order by modifiedOn desc", entity.getPrimaryField().getName(), entity.getName());
Object[] random = Application.createQueryNoFilter(sql).unique();
if (random == null) {
response.sendError(400, Language.L("未找到可供预览的记录"));
return;
}
File file;
try {
// 列表报表
if (ObjectUtils.toInt(report[1]) == DataReportManager.TYPE_LIST) {
JSONObject queryData = JSONUtils.toJSONObject(new String[] { "pageSize", "entity" }, new Object[] { 2, report[0] });
file = new EasyExcelListGenerator(reportId, queryData).generate();
} else {
file = new EasyExcelGenerator(reportId, (ID) random[0]).generate();
}
} catch (ConfigurationException ex) {
response.sendError(500, ex.getLocalizedMessage());
return;
}
FileDownloader.downloadTempFile(response, file, null);
}
use of com.rebuild.core.configuration.ConfigurationException in project rebuild by getrebuild.
the class ProjectTaskController method relatedTaskList.
@RequestMapping("tasks/related-list")
public JSON relatedTaskList(@IdParam(name = "related", required = false) ID relatedId, @IdParam(name = "task", required = false) ID taskId, HttpServletRequest request) {
Assert.isTrue(relatedId != null || taskId != null, Language.L("无效请求参数"));
final ID user = getRequestUser(request);
String queryWhere = String.format("relatedRecord = '%s'", relatedId);
// 关键词搜索
String search = getParameter(request, "search");
if (StringUtils.isNotBlank(search)) {
queryWhere += " and taskName like '%" + StringEscapeUtils.escapeSql(search) + "%'";
}
int pageNo = getIntParameter(request, "pageNo", 1);
int pageSize = getIntParameter(request, "pageSize", 40);
queryWhere += " order by " + buildQuerySort(request);
// 获取指定任务的(其他条件忽略)
if (taskId != null) {
queryWhere = String.format("taskId = '%s'", taskId);
}
Object[][] tasks = Application.createQueryNoFilter(String.format("select %s from ProjectTask where %s", FMT_FIELDS11, queryWhere)).setLimit(pageSize, pageNo * pageSize - pageSize).array();
JSONArray array = new JSONArray();
for (Object[] o : tasks) {
try {
array.add(formatTask(o, user, false));
} catch (ConfigurationException ex) {
// FIXME 无项目权限会报错(考虑任务在相关项中是否无权限也显示)
log.warn(ex.getLocalizedMessage());
}
}
return array;
}
use of com.rebuild.core.configuration.ConfigurationException in project rebuild by getrebuild.
the class ProjectManager method getProjectByX.
/**
* @param taskOrPlan
* @param checkUser
* @return
*/
public ConfigBean getProjectByX(ID taskOrPlan, ID checkUser) {
final String ckey = CKEY_TP2P + taskOrPlan;
ID projectId = (ID) Application.getCommonsCache().getx(ckey);
if (projectId == null) {
Object[] x = Application.getQueryFactory().uniqueNoFilter(taskOrPlan, "projectId");
projectId = x == null ? null : (ID) x[0];
if (projectId != null) {
Application.getCommonsCache().putx(ckey, projectId);
}
}
if (projectId == null) {
throw new ConfigurationException(Language.L("任务/面板不存在或已被删除"));
}
try {
return getProject(projectId, checkUser);
} catch (ConfigurationException ex) {
throw new AccessDeniedException(Language.L("无权访问该项目"), ex);
}
}
Aggregations