use of com.rebuild.core.configuration.ConfigBean in project rebuild by getrebuild.
the class ProjectTaskController method getProjectAndPlans.
// -- for General Entity
@GetMapping("alist")
public RespBody getProjectAndPlans(HttpServletRequest request) {
final ID user = getRequestUser(request);
ConfigBean[] ps = ProjectManager.instance.getAvailable(user);
JSONArray alist = new JSONArray();
for (ConfigBean p : ps) {
// 已归档
if (p.getInteger("status") == ProjectManager.STATUS_ARCHIVED)
continue;
// 非成员
if (!p.get("members", Set.class).contains(user))
continue;
JSONObject item = (JSONObject) p.toJSON("id", "projectName");
// 面板
ConfigBean[] plans = ProjectManager.instance.getPlansOfProject(p.getID("id"));
JSONArray plansList = new JSONArray();
for (ConfigBean plan : plans) {
plansList.add(plan.toJSON("id", "planName", "flowStatus"));
}
item.put("plans", plansList);
alist.add(item);
}
return RespBody.ok(alist);
}
use of com.rebuild.core.configuration.ConfigBean in project rebuild by getrebuild.
the class ProjectHelper method isManageable.
/**
* 对 任务/评论/标签 是否有管理权
*
* @param taskOrCommentOrTag
* @param user
* @return
*/
public static boolean isManageable(ID taskOrCommentOrTag, ID user) {
// 管理员
if (UserHelper.isAdmin(user))
return true;
// 项目配置信息
ConfigBean pcfg;
if (taskOrCommentOrTag.getEntityCode() == EntityHelper.ProjectTaskTag) {
Object[] projectId = Application.getQueryFactory().uniqueNoFilter(taskOrCommentOrTag, "projectId");
pcfg = ProjectManager.instance.getProject((ID) projectId[0], null);
} else {
pcfg = ProjectManager.instance.getProjectByX(convert2Task(taskOrCommentOrTag), null);
}
// 负责人
if (user.equals(pcfg.getID("principal")))
return true;
// 非成员
if (!pcfg.get("members", Set.class).contains(user))
return false;
// 创建人
Object[] createdBy = Application.getQueryFactory().uniqueNoFilter(taskOrCommentOrTag, "createdBy");
return createdBy != null && createdBy[0].equals(user);
}
use of com.rebuild.core.configuration.ConfigBean in project rebuild by getrebuild.
the class ProjectManager method getProjects.
/**
* 获取全部项目
*
* @return
*/
private ConfigBean[] getProjects() {
ConfigBean[] cached = (ConfigBean[]) Application.getCommonsCache().getx(CKEY_PROJECTS);
if (cached == null) {
Object[][] array = Application.createQueryNoFilter("select configId,projectCode,projectName,iconName,scope,members,principal,extraDefinition,status from ProjectConfig").array();
List<ConfigBean> alist = new ArrayList<>();
for (Object[] o : array) {
String members = (String) o[5];
if (o[6] != null) {
members = StringUtils.isBlank(members) ? o[6].toString() : members + "," + o[6];
}
ConfigBean e = new ConfigBean().set("id", o[0]).set("projectCode", o[1]).set("projectName", o[2]).set("iconName", StringUtils.defaultIfBlank((String) o[3], "texture")).set("scope", o[4]).set("_members", members).set("principal", o[6]).set("status", ObjectUtils.toInt(o[8], 1));
// 扩展配置
String extraDefinition = (String) o[7];
if (JSONUtils.wellFormat(extraDefinition)) {
JSONObject extraDefinitionJson = JSON.parseObject(extraDefinition);
for (String name : extraDefinitionJson.keySet()) {
e.set(name, extraDefinitionJson.get(name));
}
}
alist.add(e);
}
cached = alist.toArray(new ConfigBean[0]);
Application.getCommonsCache().putx(CKEY_PROJECTS, cached);
}
for (ConfigBean p : cached) {
Set<ID> members = Collections.emptySet();
String userDefs = p.getString("_members");
if (StringUtils.isNotBlank(userDefs) && userDefs.length() >= 20) {
members = UserHelper.parseUsers(Arrays.asList(userDefs.split(",")), null);
}
p.set("members", members);
}
return cached;
}
use of com.rebuild.core.configuration.ConfigBean in project rebuild by getrebuild.
the class ProjectManager method getAvailable.
/**
* 获取指定用户可用项目
*
* @param user
* @return
*/
public ConfigBean[] getAvailable(ID user) {
ConfigBean[] projects = getProjects();
// 管理员可见全部
boolean isAdmin = UserHelper.isAdmin(user);
List<ConfigBean> alist = new ArrayList<>();
for (ConfigBean e : projects) {
boolean isMember = e.get("members", Set.class).contains(user);
boolean isPublic = e.getInteger("scope") == ProjectConfigService.SCOPE_ALL;
if (isAdmin || isMember || isPublic) {
boolean isArchived = e.getInteger("status") == STATUS_ARCHIVED;
if (isArchived) {
// 仅负责人
boolean isPrincipal = user.equals(e.getID("principal"));
if (isAdmin || isPrincipal)
alist.add(e.clone());
} else {
alist.add(e.clone());
}
}
}
return alist.toArray(new ConfigBean[0]);
}
use of com.rebuild.core.configuration.ConfigBean in project rebuild by getrebuild.
the class ProjectManager method getPlanOfProject.
/**
* @param planId
* @param projectId
* @return
*/
public ConfigBean getPlanOfProject(ID planId, ID projectId) {
if (projectId == null) {
Object[] o = Application.getQueryFactory().uniqueNoFilter(planId, "projectId");
projectId = o != null ? (ID) o[0] : null;
}
for (ConfigBean e : getPlansOfProject(projectId)) {
if (e.getID("id").equals(planId))
return e;
}
throw new ConfigurationException(Language.L("无效任务面板 (%s)", planId));
}
Aggregations