提交 685d6bb7 编写于 作者: NoSubject's avatar NoSubject

Merge branch 'feature/ctl' into 'develop'

Feature/ctl 修改draft为save方式,添加components的默认

See merge request o2oa/o2oa!272
package com.x.base.core.project.config;
import java.io.File;
import java.util.ArrayList;
import java.util.List;
import com.x.base.core.project.annotation.FieldDescribe;
import com.x.base.core.project.gson.XGsonBuilder;
import com.x.base.core.project.tools.DefaultCharset;
import com.x.base.core.project.tools.ListTools;
import org.apache.commons.io.FileUtils;
public class Components extends ConfigObject {
public static final String NAME_SETTING = "Setting";
public static final String NAME_ORG = "Org";
public static final String NAME_CMSMANAGER = "cmsManager";
public static final String NAME_APPLICATIONEXPLORER = "ApplicationExplorer";
public static final String NAME_PORTALEXPLORER = "PortalExplorer";
public static final String NAME_DATAEXPLORER = "DataExplorer";
public static final String NAME_SERVICEMANAGER = "service.ServiceManager";
public static final String NAME_APPMARKET = "AppMarket";
public static final String NAME_APPCENTER = "AppCenter";
public static final String NAME_LOGVIEWER = "LogViewer";
public static final String NAME_PROFILE = "Profile";
public static final String NAME_BAM = "BAM";
public static final String NAME_CMS = "cms";
public static final String NAME_TASKCENTER = "TaskCenter";
public static final String NAME_HOMEPAGE = "Homepage";
public static final String NAME_HOTARTICLE = "HotArticle";
public static final String NAME_FILE = "File";
public static final String NAME_NOTE = "Note";
public static final String NAME_MEETING = "Meeting";
public static final String NAME_ONLINEMEETING = "OnlineMeeting";
public static final String NAME_ATTENDANCE = "Attendance";
public static final String NAME_FORUM = "Forum";
public static final String NAME_MINDER = "Minder";
public static final String NAME_CALENDAR = "Calendar";
public static final String NAME_ANN = "ANN";
public static final String NAME_SEARCH = "Search";
public static List<String> SYSTEM_NAME_NAMES = ListTools.toList(NAME_SETTING, NAME_ORG, NAME_CMSMANAGER,
NAME_APPLICATIONEXPLORER, NAME_PORTALEXPLORER, NAME_DATAEXPLORER, NAME_SERVICEMANAGER, NAME_APPMARKET,
NAME_APPCENTER, NAME_LOGVIEWER, NAME_PROFILE, NAME_BAM, NAME_CMS, NAME_TASKCENTER, NAME_HOMEPAGE,
NAME_HOTARTICLE, NAME_FILE, NAME_NOTE, NAME_MEETING, NAME_ONLINEMEETING, NAME_ATTENDANCE, NAME_FORUM,
NAME_MINDER, NAME_CALENDAR, NAME_ANN, NAME_SEARCH);
public static final String APPICON_PNG = "appicon.png";
public static Component systemComponent(String name) {
switch (name) {
case NAME_SETTING:
return new Component(NAME_SETTING, NAME_SETTING, "系统设置", APPICON_PNG, 1, Component.TYPE_SYSTEM);
case NAME_ORG:
return new Component(NAME_ORG, NAME_ORG, "组织管理", APPICON_PNG, 2, Component.TYPE_SYSTEM);
case NAME_CMSMANAGER:
return new Component(NAME_CMSMANAGER, "cms.column", "内容管理平台", APPICON_PNG, 3, Component.TYPE_SYSTEM);
case NAME_APPLICATIONEXPLORER:
return new Component(NAME_APPLICATIONEXPLORER, "process.ApplicationExplorer", "流程管理平台", APPICON_PNG, 4,
Component.TYPE_SYSTEM);
case NAME_PORTALEXPLORER:
return new Component(NAME_PORTALEXPLORER, "portal.PortalExplorer", "门户管理平台", APPICON_PNG, 5,
Component.TYPE_SYSTEM);
case NAME_DATAEXPLORER:
return new Component(NAME_DATAEXPLORER, "query.QueryExplorer", "数据中心平台", APPICON_PNG, 6,
Component.TYPE_SYSTEM);
case NAME_SERVICEMANAGER:
return new Component(NAME_SERVICEMANAGER, NAME_SERVICEMANAGER, "服务管理平台", APPICON_PNG, 7,
Component.TYPE_SYSTEM);
case NAME_APPMARKET:
return new Component(NAME_APPMARKET, NAME_APPMARKET, "应用市场", APPICON_PNG, 8, Component.TYPE_SYSTEM);
case NAME_APPCENTER:
return new Component(NAME_APPCENTER, NAME_APPCENTER, "应用管理", APPICON_PNG, 9, Component.TYPE_SYSTEM);
case NAME_LOGVIEWER:
return new Component(NAME_LOGVIEWER, NAME_LOGVIEWER, "日志", APPICON_PNG, 10, Component.TYPE_SYSTEM);
case NAME_PROFILE:
return new Component(NAME_PROFILE, NAME_PROFILE, "个人设置", APPICON_PNG, 11, Component.TYPE_SYSTEM);
case NAME_BAM:
return new Component(NAME_BAM, NAME_BAM, "流程监控", APPICON_PNG, 12, Component.TYPE_SYSTEM);
case NAME_CMS:
return new Component(NAME_CMS, "cms.Index", "信息平台", APPICON_PNG, 12, Component.TYPE_SYSTEM);
case NAME_TASKCENTER:
return new Component(NAME_TASKCENTER, "process.TaskCenter", "办公中心", APPICON_PNG, 13,
Component.TYPE_SYSTEM);
case NAME_HOMEPAGE:
return new Component(NAME_HOMEPAGE, NAME_HOMEPAGE, "首页", APPICON_PNG, 14, Component.TYPE_SYSTEM);
case NAME_HOTARTICLE:
return new Component(NAME_HOTARTICLE, NAME_HOTARTICLE, "热点", APPICON_PNG, 15, Component.TYPE_SYSTEM);
case NAME_FILE:
return new Component(NAME_FILE, NAME_FILE, "云文件", APPICON_PNG, 16, Component.TYPE_SYSTEM);
case NAME_NOTE:
return new Component(NAME_NOTE, NAME_NOTE, "便签", APPICON_PNG, 17, Component.TYPE_SYSTEM);
case NAME_MEETING:
return new Component(NAME_MEETING, NAME_MEETING, "会议管理", APPICON_PNG, 18, Component.TYPE_SYSTEM);
case NAME_ONLINEMEETING:
return new Component(NAME_ONLINEMEETING, NAME_ONLINEMEETING, "网络会议", APPICON_PNG, 19,
Component.TYPE_SYSTEM);
case NAME_ATTENDANCE:
return new Component(NAME_ATTENDANCE, NAME_ATTENDANCE, "考勤管理", APPICON_PNG, 20, Component.TYPE_SYSTEM);
case NAME_FORUM:
return new Component(NAME_FORUM, NAME_FORUM, "论坛", APPICON_PNG, 21, Component.TYPE_SYSTEM);
case NAME_MINDER:
return new Component(NAME_MINDER, NAME_MINDER, "脑图编辑器", APPICON_PNG, 22, Component.TYPE_SYSTEM);
case NAME_CALENDAR:
return new Component(NAME_CALENDAR, NAME_CALENDAR, "日程安排", APPICON_PNG, 23, Component.TYPE_SYSTEM);
case NAME_ANN:
return new Component(NAME_ANN, NAME_ANN, "神经网络", APPICON_PNG, 24, Component.TYPE_SYSTEM);
case NAME_SEARCH:
return new Component(NAME_SEARCH, NAME_SEARCH, "搜索", APPICON_PNG, 25, Component.TYPE_SYSTEM);
default:
return null;
}
}
public static Components defaultInstance() {
Components o = new Components();
o.systems.add(systemComponent(NAME_SETTING));
o.systems.add(systemComponent(NAME_ORG));
o.systems.add(systemComponent(NAME_CMSMANAGER));
o.systems.add(systemComponent(NAME_CMS));
o.systems.add(systemComponent(NAME_APPLICATIONEXPLORER));
o.systems.add(systemComponent(NAME_PORTALEXPLORER));
o.systems.add(systemComponent(NAME_DATAEXPLORER));
o.systems.add(systemComponent(NAME_SERVICEMANAGER));
o.systems.add(systemComponent(NAME_APPMARKET));
o.systems.add(systemComponent(NAME_APPCENTER));
o.systems.add(systemComponent(NAME_LOGVIEWER));
o.systems.add(systemComponent(NAME_PROFILE));
o.systems.add(systemComponent(NAME_BAM));
o.systems.add(systemComponent(NAME_TASKCENTER));
o.systems.add(systemComponent(NAME_HOMEPAGE));
o.systems.add(systemComponent(NAME_HOTARTICLE));
o.systems.add(systemComponent(NAME_FILE));
o.systems.add(systemComponent(NAME_NOTE));
o.systems.add(systemComponent(NAME_MEETING));
o.systems.add(systemComponent(NAME_ONLINEMEETING));
o.systems.add(systemComponent(NAME_ATTENDANCE));
o.systems.add(systemComponent(NAME_FORUM));
o.systems.add(systemComponent(NAME_MINDER));
o.systems.add(systemComponent(NAME_CALENDAR));
o.systems.add(systemComponent(NAME_ANN));
o.systems.add(systemComponent(NAME_SEARCH));
return o;
}
@FieldDescribe("默认模块")
private List<Component> systems = new ArrayList<>();
public Components() {
// nothing
}
public void save() throws Exception {
File file = new File(Config.base(), Config.PATH_CONFIG_PORTAL);
FileUtils.write(file, XGsonBuilder.toJson(this), DefaultCharset.charset);
}
public static class Component {
public static final String TYPE_SYSTEM = "system";
public static final String TYPE_CUSTOM = "custom";
public Component() {
}
public Component(String name, String path, String title, String iconPath, Integer orderNumber, String type) {
this.name = name;
this.path = path;
this.title = title;
this.iconPath = iconPath;
this.orderNumber = orderNumber;
this.type = type;
}
@FieldDescribe("名称")
private String name;
@FieldDescribe("路径")
private String path;
@FieldDescribe("标题")
private String title;
@FieldDescribe("iconPath")
private String iconPath;
@FieldDescribe("排序号")
private Integer orderNumber;
@FieldDescribe("类型")
private String type;
@FieldDescribe("允许列表,可以混用person,role")
private List<String> allowList = new ArrayList<>();
@FieldDescribe("禁止列表,可以混用person,role")
private List<String> dentyList = new ArrayList<>();
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getPath() {
return path;
}
public void setPath(String path) {
this.path = path;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public String getIconPath() {
return iconPath;
}
public void setIconPath(String iconPath) {
this.iconPath = iconPath;
}
public List<String> getAllowList() {
return allowList;
}
public void setAllowList(List<String> allowList) {
this.allowList = allowList;
}
public List<String> getDentyList() {
return dentyList;
}
public void setDentyList(List<String> dentyList) {
this.dentyList = dentyList;
}
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
public Integer getOrderNumber() {
return orderNumber;
}
public void setOrderNumber(Integer orderNumber) {
this.orderNumber = orderNumber;
}
}
public List<Component> getSystems() {
return systems;
}
public void setSystems(List<Component> systems) {
this.systems = systems;
}
}
\ No newline at end of file
......@@ -74,6 +74,7 @@ public class Config {
public static final String PATH_CONFIG_COMMUNICATE = "config/communicate.json";
public static final String PATH_CONFIG_EXMAIL = "config/exmail.json";
public static final String PATH_CONFIG_PORTAL = "config/portal.json";
public static final String PATH_CONFIG_COMPONENTS = "config/components.json";
public static final String DIR_COMMONS = "commons";
public static final String DIR_COMMONS_TESS4J_TESSDATA = "commons/tess4j/tessdata";
......@@ -124,8 +125,6 @@ public class Config {
public static final String SCRIPTING_ENGINE_NAME = "JavaScript";
// public static final String RESOUCE_CONFIG = "config";
public static final String RESOURCE_NODE_PREFIX = "node/";
public static final String RESOURCE_NODE_EVENTQUEUE = RESOURCE_NODE_PREFIX + "eventQueue";
public static final String RESOURCE_NODE_EVENTQUEUEEXECUTOR = RESOURCE_NODE_PREFIX + "eventQueueExecutor";
......@@ -1227,6 +1226,23 @@ public class Config {
return instance().portal;
}
private Components components = null;
public static Components components() throws Exception {
if (null == instance().components) {
synchronized (Config.class) {
if (null == instance().components) {
Components obj = BaseTools.readConfigObject(PATH_CONFIG_COMPONENTS, Components.class);
if (null == obj) {
obj = Components.defaultInstance();
}
instance().components = obj;
}
}
}
return instance().components;
}
public static Object resource(String name) throws Exception {
return initialContext().lookup(name);
}
......
package com.x.component.assemble.control;
import com.x.base.core.project.Context;
import com.x.base.core.project.config.Config;
import com.x.base.core.project.logger.Logger;
import com.x.base.core.project.logger.LoggerFactory;
import com.x.component.assemble.control.schedule.InitComponents;
public class ThisApplication {
private ThisApplication() {
// nothing
}
protected static Context context;
private static Logger logger = LoggerFactory.getLogger(ThisApplication.class);
public static Context context() {
return context;
}
public static void init() {
try {
LoggerFactory.setLevel(Config.logLevel().x_component_assemble_control());
context.scheduleLocal(InitComponents.class, 1);
} catch (Exception e) {
e.printStackTrace();
logger.error(e);
}
}
public static void destroy() {
try {
//nothing
} catch (Exception e) {
e.printStackTrace();
logger.error(e);
}
}
......
package com.x.component.assemble.control.jaxrs.component;
import java.util.List;
import com.x.base.core.project.cache.ApplicationCache;
import com.x.base.core.project.jaxrs.StandardJaxrsAction;
import com.x.base.core.project.tools.ListTools;
import com.x.component.core.entity.Component;
import net.sf.ehcache.Ehcache;
......@@ -13,118 +10,4 @@ class ActionBase extends StandardJaxrsAction {
Ehcache cache = ApplicationCache.instance().getCache(Component.class);
static final String COMPONENT_FILE = "File";
static final String COMPONENT_NOTE = "Note";
static final String COMPONENT_MEETING = "Meeting";
static final String COMPONENT_EXECUTION = "Execution";
static final String COMPONENT_ATTENDANCE = "Attendance";
static final String COMPONENT_FORUM = "Forum";
static final String COMPONENT_HOTARTICLE = "HotArticle";
static final String COMPONENT_EXEMANAGER = "ExeManager";
static final String COMPONENT_ONLINEMEETING = "OnlineMeeting";
static final String COMPONENT_ANN = "ANN";
// static final String COMPONENT_STRATEGY = "Strategy";
// static final String COMPONENT_REPORT = "Report";
static final String COMPONENT_MINDER = "Minder";
static final String COMPONENT_CALENDAR = "Calendar";
static final String COMPONENT_SEARCH = "Search";
static final String COMPONENT_HOMEPAGE = "Homepage";
List<String> DEFAULT_COMPONENT_LIST = ListTools.toList(COMPONENT_FILE, COMPONENT_NOTE, COMPONENT_MEETING,
COMPONENT_EXECUTION, COMPONENT_ATTENDANCE, COMPONENT_FORUM, COMPONENT_HOTARTICLE, COMPONENT_EXEMANAGER,
COMPONENT_ONLINEMEETING, COMPONENT_ANN, COMPONENT_MINDER, COMPONENT_CALENDAR, COMPONENT_HOMEPAGE);
// {
// "name": "File",
// "path": "File",
// "title": "云文件",
// "iconPath": "appicon.png",
// "visible":true
// },
//
// {
// "name": "Note",
// "path": "Note",
// "title": "便签",
// "iconPath": "appicon.png",
// "visible": true
// },
// {
// "name": "Meeting",
// "path": "Meeting",
// "title": "会议管理",
// "iconPath": "appicon.png",
// "visible": true
// },
// {
// "name": "Execution",
// "path": "Execution",
// "title": "执行力管理",
// "iconPath": "appicon.png",
// "visible": true
// },
// {
// "name": "Attendance",
// "path": "Attendance",
// "title": "考勤管理",
// "iconPath": "appicon.png",
// "visible": true
// },
// {
// "name": "Forum",
// "path": "Forum",
// "title": "论坛",
// "iconPath": "appicon.png",
// "visible": true
// },
// {
// "name": "HotArticle",
// "path": "HotArticle",
// "title": "热点",
// "iconPath": "appicon.png",
// "visible": true
// },
// {
// "name": "ExeManager",
// "path": "ExeManager",
// "title": "执行力管理",
// "iconPath": "appicon.png",
// "visible": true
// },
// {
// "name": "OnlineMeeting",
// "path": "OnlineMeeting",
// "title": "网络会议",
// "iconPath": "appicon.png",
// "visible": true
// },
// {
// "name": "Strategy",
// "path": "Strategy",
// "title": "战略管理",
// "iconPath": "appicon.png",
// "visible": true
// },
// {
// "name": "Report",
// "path": "Report",
// "title": "工作报告",
// "iconPath": "appicon.png",
// "visible": true
// },
// {
// "name": "Minder",
// "path": "Minder",
// "title": "脑图编辑器",
// "iconPath": "appicon.png",
// "visible": true
// },
// {
// "name": "Calendar",
// "path": "Calendar",
// "title": "日程安排",
// "iconPath": "appicon.png",
// "visible": true
// }
}
......@@ -12,6 +12,7 @@ import com.x.base.core.project.exception.ExceptionAccessDenied;
import com.x.base.core.project.http.ActionResult;
import com.x.base.core.project.http.EffectivePerson;
import com.x.base.core.project.jaxrs.WrapBoolean;
import com.x.base.core.project.tools.ListTools;
import com.x.component.assemble.control.Business;
import com.x.component.core.entity.Component;
......@@ -25,6 +26,7 @@ class ActionCreate extends ActionBase {
}
Wi wi = this.convertToWrapIn(jsonElement, Wi.class);
Component component = Wi.copier.copy(wi);
component.setType(Component.TYPE_CUSTOM);
emc.beginTransaction(Component.class);
emc.persist(component, CheckPersistType.all);
emc.commit();
......@@ -40,7 +42,7 @@ class ActionCreate extends ActionBase {
private static final long serialVersionUID = 8867806242224800105L;
static WrapCopier<Wi, Component> copier = WrapCopierFactory.wi(Wi.class, Component.class, null,
JpaObject.FieldsUnmodify);
ListTools.toList(JpaObject.FieldsUnmodify, Component.type_FIELDNAME));
}
......
......@@ -12,6 +12,8 @@ import com.x.base.core.project.jaxrs.WrapBoolean;
import com.x.component.assemble.control.Business;
import com.x.component.core.entity.Component;
import org.apache.commons.codec.binary.StringUtils;
class ActionDelete extends ActionBase {
ActionResult<Wo> execute(EffectivePerson effectivePerson, String flag) throws Exception {
try (EntityManagerContainer emc = EntityManagerContainerFactory.instance().create()) {
......@@ -24,6 +26,10 @@ class ActionDelete extends ActionBase {
if (null == component) {
throw new ExceptionEntityNotExist(flag, Component.class);
}
if (StringUtils.equals(component.getType(),Component.TYPE_SYSTEM)) {
throw new ExceptionDeleteSystemComponent();
}
emc.beginTransaction(Component.class);
emc.remove(component, CheckRemoveType.all);
emc.commit();
......
......@@ -13,6 +13,7 @@ import com.x.base.core.project.exception.ExceptionEntityNotExist;
import com.x.base.core.project.http.ActionResult;
import com.x.base.core.project.http.EffectivePerson;
import com.x.base.core.project.jaxrs.WrapBoolean;
import com.x.base.core.project.tools.ListTools;
import com.x.component.assemble.control.Business;
import com.x.component.core.entity.Component;
......@@ -46,7 +47,7 @@ class ActionEdit extends ActionBase {
private static final long serialVersionUID = 8867806242224800105L;
static WrapCopier<Wi, Component> copier = WrapCopierFactory.wi(Wi.class, Component.class, null,
JpaObject.FieldsUnmodify);
ListTools.toList(JpaObject.FieldsUnmodify, Component.type_FIELDNAME));
}
......
......@@ -2,20 +2,20 @@ package com.x.component.assemble.control.jaxrs.component;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.Date;
import java.util.List;
import java.util.stream.Collectors;
import org.apache.commons.collections4.ListUtils;
import com.x.base.core.container.EntityManagerContainer;
import com.x.base.core.container.factory.EntityManagerContainerFactory;
import com.x.base.core.entity.JpaObject;
import com.x.base.core.entity.annotation.CheckPersistType;
import com.x.base.core.project.bean.WrapCopier;
import com.x.base.core.project.bean.WrapCopierFactory;
import com.x.base.core.project.cache.ApplicationCache;
import com.x.base.core.project.config.Components;
import com.x.base.core.project.http.ActionResult;
import com.x.base.core.project.http.EffectivePerson;
import com.x.base.core.project.logger.Logger;
import com.x.base.core.project.logger.LoggerFactory;
import com.x.base.core.project.tools.ListTools;
import com.x.component.core.entity.Component;
......@@ -23,38 +23,41 @@ import net.sf.ehcache.Element;
class ActionListAll extends ActionBase {
private static Logger logger = LoggerFactory.getLogger(ActionListAll.class);
ActionResult<List<Wo>> execute(EffectivePerson effectivePerson) throws Exception {
try (EntityManagerContainer emc = EntityManagerContainerFactory.instance().create()) {
ActionResult<List<Wo>> result = new ActionResult<>();
List<Wo> wos = new ArrayList<>();
String cacheKey = ApplicationCache.concreteCacheKey(this.getClass());
Element element = cache.get(cacheKey);
if (null != element && (null != element.getObjectValue())) {
wos = (List<Wo>) element.getObjectValue();
result.setData((List<Wo>) element.getObjectValue());
} else {
final List<Wo> wos = new ArrayList<>();
List<Component> os = emc.listAll(Component.class);
if (os.isEmpty()) {
/* 一个模块都没有新建默认 */
synchronized (ActionListAll.class) {
if (emc.listAll(Component.class).isEmpty()) {
emc.beginTransaction(Component.class);
for (String name : DEFAULT_COMPONENT_LIST) {
Component o = this.createComponent(name);
emc.persist(o, CheckPersistType.all);
os.add(o);
os.stream().filter(o -> ListTools.contains(Components.SYSTEM_NAME_NAMES, o.getName()))
.sorted(Comparator.comparing(Component::getOrderNumber, Comparator.nullsLast(Integer::compareTo))
.thenComparing(Component::getCreateTime, Comparator.nullsLast(Date::compareTo)))
.forEach(o -> {
try {
wos.add(Wo.copier.copy(o));
} catch (Exception e) {
logger.error(e);
}
});
os.stream().filter(o -> !ListTools.contains(Components.SYSTEM_NAME_NAMES, o.getName()))
.sorted(Comparator.comparing(Component::getOrderNumber, Comparator.nullsLast(Integer::compareTo))
.thenComparing(Component::getCreateTime, Comparator.nullsLast(Date::compareTo)))
.forEach(o -> {
try {
wos.add(Wo.copier.copy(o));
} catch (Exception e) {
logger.error(e);
}
emc.commit();
ApplicationCache.notify(Component.class);
}
}
}
wos = Wo.copier.copy(os);
wos = wos.stream().sorted(
Comparator.comparing(Component::getOrderNumber, Comparator.nullsLast(Integer::compareTo)))
.collect(Collectors.toList());
});
cache.put(new Element(cacheKey, wos));
result.setData(wos);
}
result.setData(wos);
return result;
}
}
......@@ -68,125 +71,4 @@ class ActionListAll extends ActionBase {
}
private Component createComponent(String name) {
Component o = new Component();
switch (name) {
case COMPONENT_FILE:
o.setName(COMPONENT_FILE);
o.setPath(COMPONENT_FILE);
o.setTitle("云文件");
o.setIconPath("appicon.png");
o.setVisible(true);
break;
case COMPONENT_NOTE:
o.setName(COMPONENT_NOTE);
o.setPath(COMPONENT_NOTE);
o.setTitle("便签");
o.setIconPath("appicon.png");
o.setVisible(true);
break;
case COMPONENT_MEETING:
o.setName(COMPONENT_MEETING);
o.setPath(COMPONENT_MEETING);
o.setTitle("会议管理");
o.setIconPath("appicon.png");
o.setVisible(true);
break;
case COMPONENT_EXECUTION:
o.setName(COMPONENT_EXECUTION);
o.setPath(COMPONENT_EXECUTION);
o.setTitle("执行力管理");
o.setIconPath("appicon.png");
o.setVisible(true);
break;
case COMPONENT_ATTENDANCE:
o.setName(COMPONENT_ATTENDANCE);
o.setPath(COMPONENT_ATTENDANCE);
o.setTitle("考勤管理");
o.setIconPath("appicon.png");
o.setVisible(true);
break;
case COMPONENT_FORUM:
o.setName(COMPONENT_FORUM);
o.setPath(COMPONENT_FORUM);
o.setTitle("论坛");
o.setIconPath("appicon.png");
o.setVisible(true);
break;
case COMPONENT_HOTARTICLE:
o.setName(COMPONENT_HOTARTICLE);
o.setPath(COMPONENT_HOTARTICLE);
o.setTitle("热点");
o.setIconPath("appicon.png");
o.setVisible(true);
break;
case COMPONENT_EXEMANAGER:
o.setName(COMPONENT_EXEMANAGER);
o.setPath(COMPONENT_EXEMANAGER);
o.setTitle("执行力配置");
o.setIconPath("appicon.png");
o.setVisible(true);
break;
case COMPONENT_ONLINEMEETING:
o.setName(COMPONENT_ONLINEMEETING);
o.setPath(COMPONENT_ONLINEMEETING);
o.setTitle("网络会议");
o.setIconPath("appicon.png");
o.setVisible(true);
break;
// case COMPONENT_STRATEGY:
// o.setName(COMPONENT_STRATEGY);
// o.setPath(COMPONENT_STRATEGY);
// o.setTitle("战略管理");
// o.setIconPath("appicon.png");
// o.setVisible(true);
// break;
// case COMPONENT_REPORT:
// o.setName(COMPONENT_REPORT);
// o.setPath(COMPONENT_REPORT);
// o.setTitle("工作报告");
// o.setIconPath("appicon.png");
// o.setVisible(true);
// break;
case COMPONENT_MINDER:
o.setName(COMPONENT_MINDER);
o.setPath(COMPONENT_MINDER);
o.setTitle("脑图编辑器");
o.setIconPath("appicon.png");
o.setVisible(true);
break;
case COMPONENT_CALENDAR:
o.setName(COMPONENT_CALENDAR);
o.setPath(COMPONENT_CALENDAR);
o.setTitle("日程安排");
o.setIconPath("appicon.png");
o.setVisible(true);
break;
case COMPONENT_ANN:
o.setName(COMPONENT_ANN);
o.setPath(COMPONENT_ANN);
o.setTitle("神经网络");
o.setIconPath("appicon.png");
o.setVisible(true);
break;
case COMPONENT_SEARCH:
o.setName(COMPONENT_SEARCH);
o.setPath(COMPONENT_SEARCH);
o.setTitle("搜索");
o.setIconPath("appicon.png");
o.setVisible(true);
break;
case COMPONENT_HOMEPAGE:
o.setName(COMPONENT_HOMEPAGE);
o.setPath(COMPONENT_HOMEPAGE);
o.setTitle("首页");
o.setIconPath("appicon.png");
o.setVisible(true);
break;
default:
break;
}
return o;
}
}
package com.x.component.assemble.control.jaxrs.component;
import com.x.base.core.project.exception.PromptException;
class ExceptionDeleteSystemComponent extends PromptException {
private static final long serialVersionUID = 4132300948670472899L;
ExceptionDeleteSystemComponent() {
super("不能删除系统组件.");
}
}
package com.x.component.assemble.control.schedule;
import java.util.ArrayList;
import java.util.List;
import com.x.base.core.container.EntityManagerContainer;
import com.x.base.core.container.factory.EntityManagerContainerFactory;
import com.x.base.core.entity.annotation.CheckPersistType;
import com.x.base.core.entity.annotation.CheckRemoveType;
import com.x.base.core.project.config.Config;
import com.x.base.core.project.logger.Logger;
import com.x.base.core.project.logger.LoggerFactory;
import com.x.base.core.project.schedule.AbstractJob;
import com.x.base.core.project.tools.ListTools;
import com.x.component.core.entity.Component;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
public class InitComponents extends AbstractJob {
private static Logger logger = LoggerFactory.getLogger(InitComponents.class);
@Override
public void schedule(JobExecutionContext jobExecutionContext) throws Exception {
try {
this.init();
} catch (Exception e) {
logger.error(e);
throw new JobExecutionException(e);
}
}
private void init() throws Exception {
try (EntityManagerContainer emc = EntityManagerContainerFactory.instance().create()) {
List<String> names = ListTools.extractProperty(Config.components().getSystems(), "name", String.class, true,
true);
List<Component> os = emc.listEqual(Component.class, Component.type_FIELDNAME, Component.TYPE_SYSTEM);
List<Component> removes = new ArrayList<>();
for (Component o : os) {
if (!names.contains(o.getName())) {
removes.add(o);
}
}
if (!removes.isEmpty()) {
emc.beginTransaction(Component.class);
for (Component o : removes) {
emc.remove(o, CheckRemoveType.all);
}
emc.commit();
}
for (Component o : os) {
names.remove(o.getName());
}
List<Component> adds = new ArrayList<>();
for (com.x.base.core.project.config.Components.Component o : Config.components().getSystems()) {
if (!names.contains(o.getName())) {
Component component = new Component();
component.setName(o.getName());
component.setPath(o.getPath());
component.setTitle(o.getTitle());
component.setIconPath(o.getIconPath());
component.setOrderNumber(o.getOrderNumber());
component.setVisible(true);
component.setType(Component.TYPE_SYSTEM);
adds.add(component);
}
}
if (!adds.isEmpty()) {
emc.beginTransaction(Component.class);
for (Component o : adds) {
emc.persist(o, CheckPersistType.all);
}
emc.commit();
}
}
}
}
......@@ -373,6 +373,12 @@
"isCollection": true,
"description": "拒绝访问人员."
},
{
"name": "type",
"type": "String",
"isCollection": false,
"description": "类型:system|custom"
},
{
"name": "createTime",
"type": "Date",
......@@ -456,6 +462,12 @@
"isCollection": true,
"description": "拒绝访问人员."
},
{
"name": "type",
"type": "String",
"isCollection": false,
"description": "类型:system|custom"
},
{
"name": "createTime",
"type": "Date",
......
package com.x.component.assemble.control;
import com.x.base.core.project.Context;
import com.x.base.core.project.config.Config;
import com.x.base.core.project.logger.Logger;
import com.x.base.core.project.logger.LoggerFactory;
import com.x.component.assemble.control.schedule.InitComponents;
public class ThisApplication {
private ThisApplication() {
// nothing
}
protected static Context context;
private static Logger logger = LoggerFactory.getLogger(ThisApplication.class);
public static Context context() {
return context;
}
public static void init() {
try {
LoggerFactory.setLevel(Config.logLevel().x_component_assemble_control());
context.scheduleLocal(InitComponents.class, 1);
} catch (Exception e) {
e.printStackTrace();
logger.error(e);
}
}
public static void destroy() {
try {
//nothing
} catch (Exception e) {
e.printStackTrace();
logger.error(e);
}
}
......
package com.x.component.assemble.control.jaxrs.component;
import java.util.List;
import com.x.base.core.project.cache.ApplicationCache;
import com.x.base.core.project.jaxrs.StandardJaxrsAction;
import com.x.base.core.project.tools.ListTools;
import com.x.component.core.entity.Component;
import net.sf.ehcache.Ehcache;
......@@ -13,118 +10,4 @@ class ActionBase extends StandardJaxrsAction {
Ehcache cache = ApplicationCache.instance().getCache(Component.class);
static final String COMPONENT_FILE = "File";
static final String COMPONENT_NOTE = "Note";
static final String COMPONENT_MEETING = "Meeting";
static final String COMPONENT_EXECUTION = "Execution";
static final String COMPONENT_ATTENDANCE = "Attendance";
static final String COMPONENT_FORUM = "Forum";
static final String COMPONENT_HOTARTICLE = "HotArticle";
static final String COMPONENT_EXEMANAGER = "ExeManager";
static final String COMPONENT_ONLINEMEETING = "OnlineMeeting";
static final String COMPONENT_ANN = "ANN";
// static final String COMPONENT_STRATEGY = "Strategy";
// static final String COMPONENT_REPORT = "Report";
static final String COMPONENT_MINDER = "Minder";
static final String COMPONENT_CALENDAR = "Calendar";
static final String COMPONENT_SEARCH = "Search";
static final String COMPONENT_HOMEPAGE = "Homepage";
List<String> DEFAULT_COMPONENT_LIST = ListTools.toList(COMPONENT_FILE, COMPONENT_NOTE, COMPONENT_MEETING,
COMPONENT_EXECUTION, COMPONENT_ATTENDANCE, COMPONENT_FORUM, COMPONENT_HOTARTICLE, COMPONENT_EXEMANAGER,
COMPONENT_ONLINEMEETING, COMPONENT_ANN, COMPONENT_MINDER, COMPONENT_CALENDAR, COMPONENT_HOMEPAGE);
// {
// "name": "File",
// "path": "File",
// "title": "云文件",
// "iconPath": "appicon.png",
// "visible":true
// },
//
// {
// "name": "Note",
// "path": "Note",
// "title": "便签",
// "iconPath": "appicon.png",
// "visible": true
// },
// {
// "name": "Meeting",
// "path": "Meeting",
// "title": "会议管理",
// "iconPath": "appicon.png",
// "visible": true
// },
// {
// "name": "Execution",
// "path": "Execution",
// "title": "执行力管理",
// "iconPath": "appicon.png",
// "visible": true
// },
// {
// "name": "Attendance",
// "path": "Attendance",
// "title": "考勤管理",
// "iconPath": "appicon.png",
// "visible": true
// },
// {
// "name": "Forum",
// "path": "Forum",
// "title": "论坛",
// "iconPath": "appicon.png",
// "visible": true
// },
// {
// "name": "HotArticle",
// "path": "HotArticle",
// "title": "热点",
// "iconPath": "appicon.png",
// "visible": true
// },
// {
// "name": "ExeManager",
// "path": "ExeManager",
// "title": "执行力管理",
// "iconPath": "appicon.png",
// "visible": true
// },
// {
// "name": "OnlineMeeting",
// "path": "OnlineMeeting",
// "title": "网络会议",
// "iconPath": "appicon.png",
// "visible": true
// },
// {
// "name": "Strategy",
// "path": "Strategy",
// "title": "战略管理",
// "iconPath": "appicon.png",
// "visible": true
// },
// {
// "name": "Report",
// "path": "Report",
// "title": "工作报告",
// "iconPath": "appicon.png",
// "visible": true
// },
// {
// "name": "Minder",
// "path": "Minder",
// "title": "脑图编辑器",
// "iconPath": "appicon.png",
// "visible": true
// },
// {
// "name": "Calendar",
// "path": "Calendar",
// "title": "日程安排",
// "iconPath": "appicon.png",
// "visible": true
// }
}
......@@ -12,6 +12,7 @@ import com.x.base.core.project.exception.ExceptionAccessDenied;
import com.x.base.core.project.http.ActionResult;
import com.x.base.core.project.http.EffectivePerson;
import com.x.base.core.project.jaxrs.WrapBoolean;
import com.x.base.core.project.tools.ListTools;
import com.x.component.assemble.control.Business;
import com.x.component.core.entity.Component;
......@@ -25,6 +26,7 @@ class ActionCreate extends ActionBase {
}
Wi wi = this.convertToWrapIn(jsonElement, Wi.class);
Component component = Wi.copier.copy(wi);
component.setType(Component.TYPE_CUSTOM);
emc.beginTransaction(Component.class);
emc.persist(component, CheckPersistType.all);
emc.commit();
......@@ -40,7 +42,7 @@ class ActionCreate extends ActionBase {
private static final long serialVersionUID = 8867806242224800105L;
static WrapCopier<Wi, Component> copier = WrapCopierFactory.wi(Wi.class, Component.class, null,
JpaObject.FieldsUnmodify);
ListTools.toList(JpaObject.FieldsUnmodify, Component.type_FIELDNAME));
}
......
......@@ -12,6 +12,8 @@ import com.x.base.core.project.jaxrs.WrapBoolean;
import com.x.component.assemble.control.Business;
import com.x.component.core.entity.Component;
import org.apache.commons.codec.binary.StringUtils;
class ActionDelete extends ActionBase {
ActionResult<Wo> execute(EffectivePerson effectivePerson, String flag) throws Exception {
try (EntityManagerContainer emc = EntityManagerContainerFactory.instance().create()) {
......@@ -24,6 +26,10 @@ class ActionDelete extends ActionBase {
if (null == component) {
throw new ExceptionEntityNotExist(flag, Component.class);
}
if (StringUtils.equals(component.getType(),Component.TYPE_SYSTEM)) {
throw new ExceptionDeleteSystemComponent();
}
emc.beginTransaction(Component.class);
emc.remove(component, CheckRemoveType.all);
emc.commit();
......
......@@ -13,6 +13,7 @@ import com.x.base.core.project.exception.ExceptionEntityNotExist;
import com.x.base.core.project.http.ActionResult;
import com.x.base.core.project.http.EffectivePerson;
import com.x.base.core.project.jaxrs.WrapBoolean;
import com.x.base.core.project.tools.ListTools;
import com.x.component.assemble.control.Business;
import com.x.component.core.entity.Component;
......@@ -46,7 +47,7 @@ class ActionEdit extends ActionBase {
private static final long serialVersionUID = 8867806242224800105L;
static WrapCopier<Wi, Component> copier = WrapCopierFactory.wi(Wi.class, Component.class, null,
JpaObject.FieldsUnmodify);
ListTools.toList(JpaObject.FieldsUnmodify, Component.type_FIELDNAME));
}
......
......@@ -2,20 +2,20 @@ package com.x.component.assemble.control.jaxrs.component;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.Date;
import java.util.List;
import java.util.stream.Collectors;
import org.apache.commons.collections4.ListUtils;
import com.x.base.core.container.EntityManagerContainer;
import com.x.base.core.container.factory.EntityManagerContainerFactory;
import com.x.base.core.entity.JpaObject;
import com.x.base.core.entity.annotation.CheckPersistType;
import com.x.base.core.project.bean.WrapCopier;
import com.x.base.core.project.bean.WrapCopierFactory;
import com.x.base.core.project.cache.ApplicationCache;
import com.x.base.core.project.config.Components;
import com.x.base.core.project.http.ActionResult;
import com.x.base.core.project.http.EffectivePerson;
import com.x.base.core.project.logger.Logger;
import com.x.base.core.project.logger.LoggerFactory;
import com.x.base.core.project.tools.ListTools;
import com.x.component.core.entity.Component;
......@@ -23,38 +23,41 @@ import net.sf.ehcache.Element;
class ActionListAll extends ActionBase {
private static Logger logger = LoggerFactory.getLogger(ActionListAll.class);
ActionResult<List<Wo>> execute(EffectivePerson effectivePerson) throws Exception {
try (EntityManagerContainer emc = EntityManagerContainerFactory.instance().create()) {
ActionResult<List<Wo>> result = new ActionResult<>();
List<Wo> wos = new ArrayList<>();
String cacheKey = ApplicationCache.concreteCacheKey(this.getClass());
Element element = cache.get(cacheKey);
if (null != element && (null != element.getObjectValue())) {
wos = (List<Wo>) element.getObjectValue();
result.setData((List<Wo>) element.getObjectValue());
} else {
final List<Wo> wos = new ArrayList<>();
List<Component> os = emc.listAll(Component.class);
if (os.isEmpty()) {
/* 一个模块都没有新建默认 */
synchronized (ActionListAll.class) {
if (emc.listAll(Component.class).isEmpty()) {
emc.beginTransaction(Component.class);
for (String name : DEFAULT_COMPONENT_LIST) {
Component o = this.createComponent(name);
emc.persist(o, CheckPersistType.all);
os.add(o);
os.stream().filter(o -> ListTools.contains(Components.SYSTEM_NAME_NAMES, o.getName()))
.sorted(Comparator.comparing(Component::getOrderNumber, Comparator.nullsLast(Integer::compareTo))
.thenComparing(Component::getCreateTime, Comparator.nullsLast(Date::compareTo)))
.forEach(o -> {
try {
wos.add(Wo.copier.copy(o));
} catch (Exception e) {
logger.error(e);
}
});
os.stream().filter(o -> !ListTools.contains(Components.SYSTEM_NAME_NAMES, o.getName()))
.sorted(Comparator.comparing(Component::getOrderNumber, Comparator.nullsLast(Integer::compareTo))
.thenComparing(Component::getCreateTime, Comparator.nullsLast(Date::compareTo)))
.forEach(o -> {
try {
wos.add(Wo.copier.copy(o));
} catch (Exception e) {
logger.error(e);
}
emc.commit();
ApplicationCache.notify(Component.class);
}
}
}
wos = Wo.copier.copy(os);
wos = wos.stream().sorted(
Comparator.comparing(Component::getOrderNumber, Comparator.nullsLast(Integer::compareTo)))
.collect(Collectors.toList());
});
cache.put(new Element(cacheKey, wos));
result.setData(wos);
}
result.setData(wos);
return result;
}
}
......@@ -68,125 +71,4 @@ class ActionListAll extends ActionBase {
}
private Component createComponent(String name) {
Component o = new Component();
switch (name) {
case COMPONENT_FILE:
o.setName(COMPONENT_FILE);
o.setPath(COMPONENT_FILE);
o.setTitle("云文件");
o.setIconPath("appicon.png");
o.setVisible(true);
break;
case COMPONENT_NOTE:
o.setName(COMPONENT_NOTE);
o.setPath(COMPONENT_NOTE);
o.setTitle("便签");
o.setIconPath("appicon.png");
o.setVisible(true);
break;
case COMPONENT_MEETING:
o.setName(COMPONENT_MEETING);
o.setPath(COMPONENT_MEETING);
o.setTitle("会议管理");
o.setIconPath("appicon.png");
o.setVisible(true);
break;
case COMPONENT_EXECUTION:
o.setName(COMPONENT_EXECUTION);
o.setPath(COMPONENT_EXECUTION);
o.setTitle("执行力管理");
o.setIconPath("appicon.png");
o.setVisible(true);
break;
case COMPONENT_ATTENDANCE:
o.setName(COMPONENT_ATTENDANCE);
o.setPath(COMPONENT_ATTENDANCE);
o.setTitle("考勤管理");
o.setIconPath("appicon.png");
o.setVisible(true);
break;
case COMPONENT_FORUM:
o.setName(COMPONENT_FORUM);
o.setPath(COMPONENT_FORUM);
o.setTitle("论坛");
o.setIconPath("appicon.png");
o.setVisible(true);
break;
case COMPONENT_HOTARTICLE:
o.setName(COMPONENT_HOTARTICLE);
o.setPath(COMPONENT_HOTARTICLE);
o.setTitle("热点");
o.setIconPath("appicon.png");
o.setVisible(true);
break;
case COMPONENT_EXEMANAGER:
o.setName(COMPONENT_EXEMANAGER);
o.setPath(COMPONENT_EXEMANAGER);
o.setTitle("执行力配置");
o.setIconPath("appicon.png");
o.setVisible(true);
break;
case COMPONENT_ONLINEMEETING:
o.setName(COMPONENT_ONLINEMEETING);
o.setPath(COMPONENT_ONLINEMEETING);
o.setTitle("网络会议");
o.setIconPath("appicon.png");
o.setVisible(true);
break;
// case COMPONENT_STRATEGY:
// o.setName(COMPONENT_STRATEGY);
// o.setPath(COMPONENT_STRATEGY);
// o.setTitle("战略管理");
// o.setIconPath("appicon.png");
// o.setVisible(true);
// break;
// case COMPONENT_REPORT:
// o.setName(COMPONENT_REPORT);
// o.setPath(COMPONENT_REPORT);
// o.setTitle("工作报告");
// o.setIconPath("appicon.png");
// o.setVisible(true);
// break;
case COMPONENT_MINDER:
o.setName(COMPONENT_MINDER);
o.setPath(COMPONENT_MINDER);
o.setTitle("脑图编辑器");
o.setIconPath("appicon.png");
o.setVisible(true);
break;
case COMPONENT_CALENDAR:
o.setName(COMPONENT_CALENDAR);
o.setPath(COMPONENT_CALENDAR);
o.setTitle("日程安排");
o.setIconPath("appicon.png");
o.setVisible(true);
break;
case COMPONENT_ANN:
o.setName(COMPONENT_ANN);
o.setPath(COMPONENT_ANN);
o.setTitle("神经网络");
o.setIconPath("appicon.png");
o.setVisible(true);
break;
case COMPONENT_SEARCH:
o.setName(COMPONENT_SEARCH);
o.setPath(COMPONENT_SEARCH);
o.setTitle("搜索");
o.setIconPath("appicon.png");
o.setVisible(true);
break;
case COMPONENT_HOMEPAGE:
o.setName(COMPONENT_HOMEPAGE);
o.setPath(COMPONENT_HOMEPAGE);
o.setTitle("首页");
o.setIconPath("appicon.png");
o.setVisible(true);
break;
default:
break;
}
return o;
}
}
package com.x.component.core.entity;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import javax.persistence.Column;
......@@ -14,12 +13,6 @@ import javax.persistence.OrderColumn;
import javax.persistence.Table;
import javax.persistence.UniqueConstraint;
import org.apache.openjpa.persistence.PersistentCollection;
import org.apache.openjpa.persistence.jdbc.ContainerTable;
import org.apache.openjpa.persistence.jdbc.ElementColumn;
import org.apache.openjpa.persistence.jdbc.ElementIndex;
import org.apache.openjpa.persistence.jdbc.Index;
import com.x.base.core.entity.JpaObject;
import com.x.base.core.entity.SliceJpaObject;
import com.x.base.core.entity.annotation.CheckPersist;
......@@ -28,6 +21,12 @@ import com.x.base.core.entity.annotation.ContainerEntity;
import com.x.base.core.entity.annotation.Flag;
import com.x.base.core.project.annotation.FieldDescribe;
import org.apache.openjpa.persistence.PersistentCollection;
import org.apache.openjpa.persistence.jdbc.ContainerTable;
import org.apache.openjpa.persistence.jdbc.ElementColumn;
import org.apache.openjpa.persistence.jdbc.ElementIndex;
import org.apache.openjpa.persistence.jdbc.Index;
@ContainerEntity
@Entity
@Table(name = PersistenceProperties.Component.table, uniqueConstraints = {
......@@ -41,6 +40,10 @@ public class Component extends SliceJpaObject {
private static final String TABLE = PersistenceProperties.Component.table;
public static final String TYPE_SYSTEM = "system";
public static final String TYPE_CUSTOM = "custom";
public String getId() {
return id;
}
......@@ -57,6 +60,7 @@ public class Component extends SliceJpaObject {
/* 以上为 JpaObject 默认字段 */
public void onPersist() throws Exception {
// nothing
}
/* 更新运行方法 */
......@@ -123,22 +127,11 @@ public class Component extends SliceJpaObject {
@CheckPersist(allowEmpty = true)
private List<String> denyList = new ArrayList<String>();
/** flag标志位 */
// public static String[] FLA GS = new String[] { JpaObject.id_FIELDNAME,
// name_FIELDNAME };
// @FieldDescribe("管理人员.")
// public static final String title_FIELDNAME = "title";
// @PersistentCollection(fetch = FetchType.EAGER)
// @OrderColumn(name = ORDERCOLUMNCOLUMN)
// @ContainerTable(name = TABLE + "_controllerList", joinIndex = @Index(name =
// TABLE + "_controllerList_join"))
// @ElementColumn(length =
// AbstractPersistenceProperties.organization_name_length, name =
// "xcontrollerList")
// @ElementIndex(name = TABLE + "_controllerList_element")
// @CheckPersist(allowEmpty = true)
// private List<String> controllerList = new ArrayList<String>();
public static final String type_FIELDNAME = "type";
@FieldDescribe("类型:system|custom")
@Column(length = JpaObject.length_16B, name = ColumnNamePrefix + type_FIELDNAME)
@CheckPersist(allowEmpty = false)
private String type;
public String getName() {
return name;
......@@ -196,6 +189,14 @@ public class Component extends SliceJpaObject {
this.iconPath = iconPath;
}
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
public Integer getOrderNumber() {
return orderNumber;
}
......
package com.x.message.assemble.communicate.jaxrs.message;
import org.apache.commons.lang3.StringUtils;
import com.google.gson.JsonElement;
import com.x.base.core.container.EntityManagerContainer;
import com.x.base.core.container.factory.EntityManagerContainerFactory;
......@@ -14,13 +12,13 @@ import com.x.base.core.project.config.Config;
import com.x.base.core.project.gson.GsonPropertyObject;
import com.x.base.core.project.http.ActionResult;
import com.x.base.core.project.http.EffectivePerson;
import com.x.base.core.project.jaxrs.WoId;
import com.x.base.core.project.jaxrs.WrapBoolean;
import com.x.base.core.project.logger.Logger;
import com.x.base.core.project.logger.LoggerFactory;
import com.x.base.core.project.message.MessageConnector;
import com.x.message.assemble.communicate.ThisApplication;
import com.x.message.core.entity.Message;
import org.apache.commons.lang3.StringUtils;
class ActionCustomCreate extends BaseAction {
......
......@@ -46,6 +46,8 @@ class ActionDraw extends BaseAction {
throw new ExceptionAccessDenied(effectivePerson, application);
}
Work work = this.mockWork(application, process, person, identity, unit, wi.getTitle());
//设置id值与workid相同.save可以判断
work.setId("");
String form = this.findForm(business, process);
if (StringUtils.isEmpty(form)) {
throw new ExceptionNoneForm();
......
package com.x.processplatform.assemble.surface.jaxrs.draft;
import com.google.gson.JsonElement;
import com.x.base.core.container.EntityManagerContainer;
import com.x.base.core.container.factory.EntityManagerContainerFactory;
import com.x.base.core.entity.annotation.CheckPersistType;
import com.x.base.core.project.annotation.FieldDescribe;
import com.x.base.core.project.exception.ExceptionAccessDenied;
import com.x.base.core.project.exception.ExceptionEntityNotExist;
import com.x.base.core.project.gson.GsonPropertyObject;
import com.x.base.core.project.http.ActionResult;
import com.x.base.core.project.http.EffectivePerson;
import com.x.base.core.project.jaxrs.WoId;
import com.x.processplatform.core.entity.content.Data;
import com.x.processplatform.core.entity.content.Draft;
import com.x.processplatform.core.entity.content.Work;
class ActionEdit extends BaseAction {
ActionResult<Wo> execute(EffectivePerson effectivePerson, String id, JsonElement jsonElement) throws Exception {
ActionResult<Wo> result = new ActionResult<>();
try (EntityManagerContainer emc = EntityManagerContainerFactory.instance().create()) {
Wi wi = this.convertToWrapIn(jsonElement, Wi.class);
Draft draft = emc.find(id, Draft.class);
if (null == draft) {
throw new ExceptionEntityNotExist(id, Draft.class);
}
if (effectivePerson.isNotPerson(draft.getPerson())) {
throw new ExceptionAccessDenied(effectivePerson, draft);
}
emc.beginTransaction(Draft.class);
draft.setTitle(wi.getWork().getTitle());
draft.getProperties().setData(wi.getData());
emc.check(draft, CheckPersistType.all);
emc.commit();
Wo wo = new Wo();
wo.setId(draft.getId());
result.setData(wo);
return result;
}
}
public static class Wi extends GsonPropertyObject {
@FieldDescribe("数据")
private Data data;
@FieldDescribe("工作")
private Work work;
public Data getData() {
return data;
}
public void setData(Data data) {
this.data = data;
}
public Work getWork() {
return work;
}
public void setWork(Work work) {
this.work = work;
}
}
public static class Wo extends WoId {
}
}
......@@ -48,6 +48,8 @@ class ActionGet extends BaseAction {
wo.setData(draft.getProperties().getData());
Work work = this.mockWork(application, process, draft.getPerson(), draft.getIdentity(), draft.getUnit(),
draft.getTitle());
//设置id值与workid相同.save可以判断
work.setId(draft.getId());
String form = this.findForm(business, process);
if (StringUtils.isEmpty(form)) {
throw new ExceptionNoneForm();
......
......@@ -20,7 +20,9 @@ import com.x.processplatform.core.entity.content.Work;
import com.x.processplatform.core.entity.element.Application;
import com.x.processplatform.core.entity.element.Process;
class ActionCreate extends BaseAction {
import org.apache.commons.lang3.StringUtils;
class ActionSave extends BaseAction {
ActionResult<Wo> execute(EffectivePerson effectivePerson, JsonElement jsonElement) throws Exception {
ActionResult<Wo> result = new ActionResult<>();
......@@ -47,20 +49,20 @@ class ActionCreate extends BaseAction {
if (!business.process().startable(effectivePerson, identities, units, process)) {
throw new ExceptionAccessDenied(effectivePerson, process);
}
Draft draft = new Draft();
emc.beginTransaction(Draft.class);
draft.setApplication(application.getId());
draft.setApplicationAlias(application.getAlias());
draft.setApplicationName(application.getName());
draft.setProcess(process.getId());
draft.setProcessAlias(process.getAlias());
draft.setProcessName(process.getName());
draft.setPerson(person);
draft.setIdentity(identity);
draft.setUnit(unit);
draft.setTitle(wi.getWork().getTitle());
draft.getProperties().setData(wi.getData());
emc.persist(draft,CheckPersistType.all);
Draft draft = null;
if (StringUtils.isEmpty(wi.getWork().getId())) {
draft = new Draft();
this.update(draft, wi, application, process, person, identity, unit);
emc.check(draft, CheckPersistType.all);
} else {
draft = emc.find(wi.getWork().getId(), Draft.class);
if (null == draft) {
throw new ExceptionEntityNotExist(wi.getWork().getId(), Draft.class);
}
this.update(draft, wi, application, process, person, identity, unit);
emc.persist(draft, CheckPersistType.all);
}
emc.commit();
Wo wo = new Wo();
wo.setId(draft.getId());
......@@ -69,6 +71,21 @@ class ActionCreate extends BaseAction {
}
}
private void update(Draft draft, Wi wi, Application application, Process process, String person, String identity,
String unit) {
draft.setApplication(application.getId());
draft.setApplicationAlias(application.getAlias());
draft.setApplicationName(application.getName());
draft.setProcess(process.getId());
draft.setProcessAlias(process.getAlias());
draft.setProcessName(process.getName());
draft.setPerson(person);
draft.setIdentity(identity);
draft.setUnit(unit);
draft.setTitle(wi.getWork().getTitle());
draft.getProperties().setData(wi.getData());
}
public static class Wi extends GsonPropertyObject {
@FieldDescribe("数据")
......@@ -103,7 +120,6 @@ class ActionCreate extends BaseAction {
public void setIdentity(String identity) {
this.identity = identity;
}
}
public static class Wo extends WoId {
......
......@@ -88,34 +88,16 @@ public class DraftAction extends StandardJaxrsAction {
asyncResponse.resume(ResponseFactory.getEntityTagActionResultResponse(request, result));
}
@POST
@Produces(HttpMediaType.APPLICATION_JSON_UTF_8)
@Consumes(MediaType.APPLICATION_JSON)
@JaxrsMethodDescribe(value = "创建草稿.", action = ActionCreate.class)
public void create(@Suspended final AsyncResponse asyncResponse, @Context HttpServletRequest request,
JsonElement jsonElement) {
ActionResult<ActionCreate.Wo> result = new ActionResult<>();
EffectivePerson effectivePerson = this.effectivePerson(request);
try {
result = new ActionCreate().execute(effectivePerson, jsonElement);
} catch (Exception e) {
logger.error(e, effectivePerson, request, jsonElement);
result.error(e);
}
asyncResponse.resume(ResponseFactory.getEntityTagActionResultResponse(request, result));
}
@PUT
@Produces(HttpMediaType.APPLICATION_JSON_UTF_8)
@Consumes(MediaType.APPLICATION_JSON)
@Path("{id}")
@JaxrsMethodDescribe(value = "编辑草稿.", action = ActionEdit.class)
@JaxrsMethodDescribe(value = "保存草稿.", action = ActionSave.class)
public void edit(@Suspended final AsyncResponse asyncResponse, @Context HttpServletRequest request,
@JaxrsParameterDescribe("工作标识") @PathParam("id") String id, JsonElement jsonElement) {
ActionResult<ActionEdit.Wo> result = new ActionResult<>();
JsonElement jsonElement) {
ActionResult<ActionSave.Wo> result = new ActionResult<>();
EffectivePerson effectivePerson = this.effectivePerson(request);
try {
result = new ActionEdit().execute(effectivePerson, id, jsonElement);
result = new ActionSave().execute(effectivePerson, jsonElement);
} catch (Exception e) {
logger.error(e, effectivePerson, request, jsonElement);
result.error(e);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册