提交 6f14ddd6 编写于 作者: O o2null

Merge branch 'feature/平台脚本、表单、页面等设计搜索' into 'wrdp'

[平台]脚本、表单、页面设计搜索

See merge request o2oa/o2oa!2593
package com.x.base.core.entity.enums;
import com.x.base.core.entity.JpaObject;
/**
* 平台设计搜索业务类型枚举类
* script(脚本:流程平台脚本、内容管理脚本、门户脚本、服务管理的代理、服务管理的接口)
* form(流程平台的表单、内容管理的表单)
* page(门户的页面)
* widget(门户的widget)
* process(流程平台的流程模板)
*/
public enum DesignerType {
script, form, page, widget, process;
public static final int length = JpaObject.length_64B;
}
package com.x.base.core.project.jaxrs;
import com.x.base.core.project.annotation.FieldDescribe;
import com.x.base.core.project.gson.GsonPropertyObject;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class WiDesigner extends GsonPropertyObject {
@FieldDescribe("搜索关键字.")
private String keyword;
@FieldDescribe("是否区分大小写.")
private Boolean caseSensitive;
@FieldDescribe("是否全字匹配.")
private Boolean matchWholeWord;
@FieldDescribe("是否正则表达式匹配.")
private Boolean matchRegExp;
@FieldDescribe("设计类型:script|form|page|widget|process")
private List<String> designerTypes = new ArrayList<>();
@FieldDescribe("应用ID列表.")
private List<String> appIdList = new ArrayList<>();
public String getKeyword() {
return keyword;
}
public void setKeyword(String keyword) {
this.keyword = keyword;
}
public Boolean getCaseSensitive() {
return caseSensitive;
}
public void setCaseSensitive(Boolean caseSensitive) {
this.caseSensitive = caseSensitive;
}
public Boolean getMatchWholeWord() {
return matchWholeWord;
}
public void setMatchWholeWord(Boolean matchWholeWord) {
this.matchWholeWord = matchWholeWord;
}
public Boolean getMatchRegExp() {
return matchRegExp;
}
public void setMatchRegExp(Boolean matchRegExp) {
this.matchRegExp = matchRegExp;
}
public List<String> getDesignerTypes() {
return designerTypes == null ? new ArrayList<>() : designerTypes;
}
public void setDesignerTypes(List<String> designerTypes) {
this.designerTypes = designerTypes;
}
public List<String> getAppIdList() {
return appIdList == null ? new ArrayList<>() : appIdList;
}
public void setAppIdList(List<String> appIdList) {
this.appIdList = appIdList;
}
}
package com.x.base.core.project.jaxrs;
import com.x.base.core.entity.enums.DesignerType;
import com.x.base.core.project.annotation.FieldDescribe;
import com.x.base.core.project.gson.GsonPropertyObject;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;
public class WrapDesigner extends GsonPropertyObject {
@FieldDescribe("应用Id.")
private String appId;
@FieldDescribe("应用名称.")
private String appName;
@FieldDescribe("设计Id.")
private String designerId;
@FieldDescribe("设计名称.")
private String designerName;
@FieldDescribe("设计类型.")
private String designerType;
private Date updateTime;
@FieldDescribe("匹配信息.")
private List<DesignerPattern> patternList = new ArrayList<>();
public String getAppId() {
return appId;
}
public void setAppId(String appId) {
this.appId = appId;
}
public String getAppName() {
return appName;
}
public void setAppName(String appName) {
this.appName = appName;
}
public String getDesignerId() {
return designerId;
}
public void setDesignerId(String designerId) {
this.designerId = designerId;
}
public String getDesignerName() {
return designerName;
}
public void setDesignerName(String designerName) {
this.designerName = designerName;
}
public String getDesignerType() {
return designerType;
}
public void setDesignerType(String designerType) {
this.designerType = designerType;
}
public Date getUpdateTime() {
return updateTime;
}
public void setUpdateTime(Date updateTime) {
this.updateTime = updateTime;
}
public List<DesignerPattern> getPatternList() {
return patternList;
}
public void setPatternList(List<DesignerPattern> patternList) {
this.patternList = patternList;
}
public void setPatternList(Map<String, String> map) {
if(map!=null && !map.isEmpty()){
List<DesignerPattern> patternList = new ArrayList<>();
for (String key : map.keySet()){
DesignerPattern pattern = new DesignerPattern();
pattern.setProperty(key);
pattern.setPropertyValue(map.get(key));
patternList.add(pattern);
}
this.patternList = patternList;
}
}
public DesignerPattern getPatternInstant(){
DesignerPattern pattern = new DesignerPattern();
return pattern;
}
public void clearPatternValue(){
for (DesignerPattern pattern : this.patternList){
pattern.setPropertyValue(null);
}
}
public DesignerPattern getScriptDesigner(){
DesignerPattern designerPattern = null;
if(DesignerType.script.toString().equals(this.getDesignerType())){
for (DesignerPattern pattern : this.patternList){
if ("text".equals(pattern.getProperty())){
designerPattern = pattern;
}else{
pattern.setPropertyValue(null);
}
}
}else{
this.clearPatternValue();
}
return designerPattern;
}
public class DesignerPattern extends GsonPropertyObject {
@FieldDescribe("元素类型(activity | process).")
private String elementType;
@FieldDescribe("元素ID.")
private String elementId;
@FieldDescribe("元素名称.")
private String elementName;
@FieldDescribe("设计属性.")
private String property;
@FieldDescribe("设计属性.")
private String propertyValue;
@FieldDescribe("匹配行")
private List<Integer> lines;
public String getElementType() {
return elementType;
}
public void setElementType(String elementType) {
this.elementType = elementType;
}
public String getElementId() {
return elementId;
}
public void setElementId(String elementId) {
this.elementId = elementId;
}
public String getElementName() {
return elementName;
}
public void setElementName(String elementName) {
this.elementName = elementName;
}
public String getProperty() {
return property;
}
public void setProperty(String property) {
this.property = property;
}
public List<Integer> getLines() {
return lines;
}
public void setLines(List<Integer> lines) {
this.lines = lines;
}
public String getPropertyValue() {
return propertyValue;
}
public void setPropertyValue(String propertyValue) {
this.propertyValue = propertyValue;
}
}
}
package com.x.base.core.project.tools;
import java.lang.reflect.Field;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.apache.commons.beanutils.PropertyUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.reflect.FieldUtils;
public class PropertyTools {
......@@ -32,4 +36,20 @@ public class PropertyTools {
return defaultObject;
}
}
\ No newline at end of file
public static <T> Map<String, String> fieldMatchKeyword(final List<String> properties, T t, String keyword, Boolean caseSensitive, Boolean matchWholeWord, Boolean matchRegExp) throws Exception {
Map<String, String> map = new HashMap<>();
if(ListTools.isNotEmpty(properties) && StringUtils.isNotBlank(keyword)) {
for (String name : properties) {
Object o = PropertyUtils.getProperty(t, name);
if (o!=null) {
String content = String.valueOf(o);
if (StringTools.matchKeyword(keyword, content, caseSensitive, matchWholeWord, matchRegExp)) {
map.put(name, content);
}
}
}
}
return map;
}
}
......@@ -19,7 +19,7 @@ import java.util.List;
/**
* 分类表单模板信息管理表基础功能服务类
*
*
* @author O2LEE
*/
public class FormFactory extends AbstractFactory {
......@@ -37,7 +37,7 @@ public class FormFactory extends AbstractFactory {
public Form get( String id ) throws Exception {
return this.entityManagerContainer().find( id, Form.class, ExceptionWhen.none );
}
/**
* @return List:String
* @throws Exception
......@@ -51,9 +51,9 @@ public class FormFactory extends AbstractFactory {
cq.select(root.get(Form_.id));
return em.createQuery(cq).getResultList();
}
/**
*
*
* @param ids 需要查询的ID列表
* @return List:Form
* @throws Exception
......@@ -70,15 +70,15 @@ public class FormFactory extends AbstractFactory {
// Predicate p = root.get(Form_.id).in(ids);
// return em.createQuery(cq.where(p)).getResultList();
// }
/**
* 列示指定应用的所有表单模板信息ID列表
* @param doucmentId 指定的文档ID
* @param appId 指定的文档ID
* @return
* @throws Exception
* @throws Exception
*/
//@MethodDescribe("列示指定分类的所有表单模板信息ID列表")
public List<String> listByAppId( String appId ) throws Exception {
public List<String> listByAppId( String appId ) throws Exception {
if( StringUtils.isEmpty(appId) ){
throw new Exception("内容管理listByAppId方法不接受appId为空的查询操作!");
}
......@@ -90,8 +90,21 @@ public class FormFactory extends AbstractFactory {
Predicate p = cb.equal(root.get( Form_.appId ), appId);
return em.createQuery(cq.where(p)).getResultList();
}
public List<Form> listFormByAppId( String appId ) throws Exception {
public List<String> listByAppIds(List<String> appIds) throws Exception {
EntityManager em = this.entityManagerContainer().get(Form.class);
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<String> cq = cb.createQuery(String.class);
Root<Form> root = cq.from(Form.class);
Predicate p = cb.conjunction();
if(ListTools.isNotEmpty(appIds)) {
p = cb.isMember(root.get(Form_.appId), cb.literal(appIds));
}
cq.select(root.get(Form_.id)).where(p);
return em.createQuery(cq).getResultList();
}
public List<Form> listFormByAppId( String appId ) throws Exception {
if( StringUtils.isEmpty(appId) ){
throw new Exception("内容管理listByAppId方法不接受appId为空的查询操作!");
}
......@@ -123,9 +136,9 @@ public class FormFactory extends AbstractFactory {
Root<Form> root = cq.from( Form.class );
Predicate appPre = cb.equal( root.get( Form_.appId ), appId );
Predicate p = CriteriaBuilderTools.predicate_or( cb, cb.equal( root.get( Form_.id ), formFlag ), cb.equal( root.get( Form_.name ), formFlag ) );
// p = CriteriaBuilderTools.predicate_or( cb, cb.equal( root.get( Form_.alias ), formFlag ), p );
// p = CriteriaBuilderTools.predicate_or( cb, cb.equal( root.get( Form_.alias ), formFlag ), p );
p = CriteriaBuilderTools.predicate_and( cb, appPre, p );
List<Form> list = em.createQuery(cq.where(p)).getResultList();
List<Form> list = em.createQuery(cq.where(p)).getResultList();
return ListTools.isEmpty( list ) ? null : list.get( 0 );
}
}
\ No newline at end of file
}
......@@ -12,6 +12,7 @@ import com.x.cms.assemble.control.jaxrs.categoryinfo.CategoryInfoAnonymousAction
import com.x.cms.assemble.control.jaxrs.commend.DocumentCommendAction;
import com.x.cms.assemble.control.jaxrs.comment.DocumentCommentInfoAction;
import com.x.cms.assemble.control.jaxrs.data.DataAction;
import com.x.cms.assemble.control.jaxrs.designer.DesignerAction;
import com.x.cms.assemble.control.jaxrs.document.DocumentAction;
import com.x.cms.assemble.control.jaxrs.document.DocumentAnonymousAction;
import com.x.cms.assemble.control.jaxrs.document.DocumentCipherAction;
......@@ -46,7 +47,7 @@ import java.util.Set;
public class ActionApplication extends AbstractActionApplication {
public Set<Class<?>> getClasses() {
this.classes.add(TemplateFormAction.class);
this.classes.add(AppInfoAction.class);
this.classes.add(AppInfoConfigAction.class);
......@@ -77,7 +78,7 @@ public class ActionApplication extends AbstractActionApplication {
this.classes.add(SearchFilterAction.class);
this.classes.add(InputAction.class);
this.classes.add(OutputAction.class);
this.classes.add(AppInfoAnonymousAction.class);
this.classes.add(AppDictAnonymousAction.class);
this.classes.add(CategoryInfoAnonymousAction.class);
......@@ -87,8 +88,8 @@ public class ActionApplication extends AbstractActionApplication {
this.classes.add(ScriptAnonymousAction.class);
this.classes.add(DocumentCommentInfoAction.class);
this.classes.add(DocumentCommendAction.class);
this.classes.add(DesignerAction.class);
return this.classes;
}
}
\ No newline at end of file
}
......@@ -7,13 +7,14 @@ import javax.servlet.annotation.WebFilter;
;
/**
* web服务过滤器,将指定的URL定义为需要用户认证的服务,如果用户未登录,则无法访问该服务
*
*
* @author O2LEE *
*/
@WebFilter(urlPatterns = {
@WebFilter(urlPatterns = {
"/jaxrs/document/cipher/*",
"/jaxrs/permission/management/*"
"/jaxrs/permission/management/*",
"/jaxrs/designer/*"
}, asyncSupported = true )
public class CmsJaxrsCipherFilter extends CipherManagerJaxrsFilter {
}
\ No newline at end of file
}
package com.x.cms.assemble.control.jaxrs.designer;
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.JpaObject;
import com.x.base.core.entity.enums.DesignerType;
import com.x.base.core.project.bean.WrapCopier;
import com.x.base.core.project.bean.WrapCopierFactory;
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.WiDesigner;
import com.x.base.core.project.jaxrs.WrapDesigner;
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.base.core.project.tools.PropertyTools;
import com.x.cms.assemble.control.Business;
import com.x.cms.core.entity.AppInfo;
import com.x.cms.core.entity.element.Form;
import com.x.cms.core.entity.element.Script;
import org.apache.commons.lang3.StringUtils;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.TimeUnit;
class ActionSearch extends BaseAction {
private static Logger logger = LoggerFactory.getLogger(ActionSearch.class);
ActionResult<List<Wo>> execute(EffectivePerson effectivePerson, JsonElement jsonElement) throws Exception {
if(!effectivePerson.isManager()){
throw new ExceptionAccessDenied(effectivePerson);
}
Wi wi = this.convertToWrapIn(jsonElement, Wi.class);
logger.info("{}开始内容管理设计搜索,关键字:{}", effectivePerson.getDistinguishedName(), wi.getKeyword());
if(StringUtils.isBlank(wi.getKeyword())){
throw new ExceptionFieldEmpty("keyword");
}
ActionResult<List<Wo>> result = new ActionResult<>();
List<Wo> resWos = new ArrayList<>();
List<CompletableFuture<List<Wo>>> list = new ArrayList<>();
if (wi.getDesignerTypes().isEmpty() || wi.getDesignerTypes().contains(DesignerType.form.toString())){
list.add(searchForm(wi, wi.getAppIdList()));
}
if (wi.getDesignerTypes().isEmpty() || wi.getDesignerTypes().contains(DesignerType.script.toString())){
list.add(searchScript(wi, wi.getAppIdList()));
}
for (CompletableFuture<List<Wo>> cf : list){
if(resWos.size()<50) {
resWos.addAll(cf.get(60, TimeUnit.SECONDS));
}
}
if (resWos.size()>50){
resWos = resWos.subList(0, 50);
}
result.setData(resWos);
result.setCount((long)resWos.size());
return result;
}
private CompletableFuture<List<Wo>> searchScript(final Wi wi, final List<String> appIdList) {
CompletableFuture<List<Wo>> cf = CompletableFuture.supplyAsync(() -> {
List<Wo> resWos = new ArrayList<>();
try (EntityManagerContainer emc = EntityManagerContainerFactory.instance().create()) {
List<WoScript> woScripts;
if (ListTools.isEmpty(appIdList)) {
woScripts = emc.fetchAll(Script.class, WoScript.copier);
} else {
woScripts = emc.fetchIn(Script.class, WoScript.copier, Script.appId_FIELDNAME, appIdList);
}
for (WoScript woScript : woScripts) {
Map<String, String> map = PropertyTools.fieldMatchKeyword(WoScript.copier.getCopyFields(), woScript, wi.getKeyword(),
wi.getCaseSensitive(), wi.getMatchWholeWord(), wi.getMatchRegExp());
if (!map.isEmpty()) {
Wo wo = new Wo();
AppInfo appInfo = emc.find( wo.getAppId(), AppInfo.class );
if(appInfo != null){
wo.setAppId(appInfo.getId());
wo.setAppName(appInfo.getAppName());
}
wo.setDesignerId(woScript.getId());
wo.setDesignerName(woScript.getName());
wo.setDesignerType(DesignerType.script.toString());
wo.setUpdateTime(woScript.getUpdateTime());
wo.setPatternList(map);
resWos.add(wo);
}
}
woScripts.clear();
}catch (Exception e){
logger.error(e);
}
return resWos;
});
return cf;
}
private CompletableFuture<List<Wo>> searchForm(final Wi wi, final List<String> appIdList) {
CompletableFuture<List<Wo>> cf = CompletableFuture.supplyAsync(() -> {
List<Wo> resWos = new ArrayList<>();
try (EntityManagerContainer emc = EntityManagerContainerFactory.instance().create()) {
Business business = new Business(emc);
List<String> formIds = business.getFormFactory().listByAppIds(appIdList);
for (List<String> partFormIds : ListTools.batch(formIds, 100)) {
List<WoForm> woForms = emc.fetchIn(Form.class, WoForm.copier, Form.id_FIELDNAME, partFormIds);
for (WoForm woForm : woForms) {
Map<String, String> map = PropertyTools.fieldMatchKeyword(WoForm.copier.getCopyFields(), woForm, wi.getKeyword(),
wi.getCaseSensitive(), wi.getMatchWholeWord(), wi.getMatchRegExp());
if (!map.isEmpty()) {
Wo wo = new Wo();
AppInfo appInfo = emc.find( wo.getAppId(), AppInfo.class );
if(appInfo != null){
wo.setAppId(appInfo.getId());
wo.setAppName(appInfo.getAppName());
}
wo.setDesignerId(woForm.getId());
wo.setDesignerName(woForm.getName());
wo.setDesignerType(DesignerType.form.toString());
wo.setUpdateTime(woForm.getUpdateTime());
wo.setPatternList(map);
resWos.add(wo);
}
}
woForms.clear();
}
}catch (Exception e){
logger.error(e);
}
return resWos;
});
return cf;
}
public static class Wi extends WiDesigner {
}
public static class Wo extends WrapDesigner{
}
public static class WoScript extends Script {
static WrapCopier<Script, WoScript> copier = WrapCopierFactory.wo(Script.class, WoScript.class,
JpaObject.singularAttributeField(Script.class, true, false),null);
}
public static class WoForm extends Form {
static WrapCopier<Form, WoForm> copier = WrapCopierFactory.wo(Form.class, WoForm.class,
JpaObject.singularAttributeField(Form.class, true, false),null);
}
}
package com.x.cms.assemble.control.jaxrs.designer;
import com.x.base.core.project.jaxrs.StandardJaxrsAction;
abstract class BaseAction extends StandardJaxrsAction {
}
package com.x.cms.assemble.control.jaxrs.designer;
import com.google.gson.JsonElement;
import com.x.base.core.project.annotation.JaxrsDescribe;
import com.x.base.core.project.annotation.JaxrsMethodDescribe;
import com.x.base.core.project.http.ActionResult;
import com.x.base.core.project.http.EffectivePerson;
import com.x.base.core.project.http.HttpMediaType;
import com.x.base.core.project.jaxrs.ResponseFactory;
import com.x.base.core.project.jaxrs.StandardJaxrsAction;
import com.x.base.core.project.logger.Logger;
import com.x.base.core.project.logger.LoggerFactory;
import javax.servlet.http.HttpServletRequest;
import javax.ws.rs.Consumes;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.container.AsyncResponse;
import javax.ws.rs.container.Suspended;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.MediaType;
import java.util.List;
@Path("designer")
@JaxrsDescribe("设计")
public class DesignerAction extends StandardJaxrsAction {
private static Logger logger = LoggerFactory.getLogger(DesignerAction.class);
@JaxrsMethodDescribe(value = "根据关键字搜索设计对象.", action = ActionSearch.class)
@POST
@Path("search")
@Produces(HttpMediaType.APPLICATION_JSON_UTF_8)
@Consumes(MediaType.APPLICATION_JSON)
public void search(@Suspended final AsyncResponse asyncResponse, @Context HttpServletRequest request,
JsonElement jsonElement) {
ActionResult<List<ActionSearch.Wo>> result = new ActionResult<>();
EffectivePerson effectivePerson = this.effectivePerson(request);
try {
result = new ActionSearch().execute(effectivePerson, jsonElement);
} catch (Exception e) {
logger.error(e, effectivePerson, request, null);
result.error(e);
}
asyncResponse.resume(ResponseFactory.getEntityTagActionResultResponse(request, result));
}
}
package com.x.cms.assemble.control.jaxrs.designer;
import com.x.base.core.project.exception.PromptException;
public class ExceptionFieldEmpty extends PromptException {
public ExceptionFieldEmpty(String field) {
super("参数: {} 值无效.", field);
}
}
......@@ -10,6 +10,7 @@ import javax.persistence.criteria.CriteriaQuery;
import javax.persistence.criteria.Predicate;
import javax.persistence.criteria.Root;
import com.x.base.core.project.tools.ListTools;
import com.x.portal.assemble.designer.AbstractFactory;
import com.x.portal.assemble.designer.Business;
import com.x.portal.core.entity.Page;
......@@ -74,6 +75,19 @@ public class PageFactory extends AbstractFactory {
return list;
}
public List<String> listWithPortals(List<String> portalIds) throws Exception {
EntityManager em = this.entityManagerContainer().get(Page.class);
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<String> cq = cb.createQuery(String.class);
Root<Page> root = cq.from(Page.class);
Predicate p = cb.conjunction();
if(ListTools.isNotEmpty(portalIds)) {
p = cb.isMember(root.get(Page_.portal), cb.literal(portalIds));
}
cq.select(root.get(Page_.id)).where(p);
return em.createQuery(cq).getResultList();
}
public boolean isFirstPage(Page page) {
return FIRSTPAGE_NAMES.contains(page.getName());
}
......@@ -88,4 +102,4 @@ public class PageFactory extends AbstractFactory {
return null;
}
}
\ No newline at end of file
}
......@@ -8,6 +8,7 @@ import javax.persistence.criteria.CriteriaQuery;
import javax.persistence.criteria.Predicate;
import javax.persistence.criteria.Root;
import com.x.base.core.project.tools.ListTools;
import com.x.portal.assemble.designer.AbstractFactory;
import com.x.portal.assemble.designer.Business;
import com.x.portal.core.entity.Widget;
......@@ -69,4 +70,17 @@ public class WidgetFactory extends AbstractFactory {
return list;
}
}
\ No newline at end of file
public List<String> listWithPortals(List<String> portalIds) throws Exception {
EntityManager em = this.entityManagerContainer().get(Widget.class);
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<String> cq = cb.createQuery(String.class);
Root<Widget> root = cq.from(Widget.class);
Predicate p = cb.conjunction();
if(ListTools.isNotEmpty(portalIds)) {
p = cb.isMember(root.get(Widget_.portal), cb.literal(portalIds));
}
cq.select(root.get(Widget_.id)).where(p);
return em.createQuery(cq).getResultList();
}
}
......@@ -5,6 +5,7 @@ import java.util.Set;
import javax.ws.rs.ApplicationPath;
import com.x.base.core.project.jaxrs.AbstractActionApplication;
import com.x.portal.assemble.designer.jaxrs.designer.DesignerAction;
import com.x.portal.assemble.designer.jaxrs.file.FileAction;
import com.x.portal.assemble.designer.jaxrs.id.IdAction;
import com.x.portal.assemble.designer.jaxrs.input.InputAction;
......@@ -30,7 +31,8 @@ public class ActionApplication extends AbstractActionApplication {
classes.add(IdAction.class);
classes.add(OutputAction.class);
classes.add(InputAction.class);
classes.add(DesignerAction.class);
return classes;
}
}
\ No newline at end of file
}
package com.x.portal.assemble.designer.jaxrs;
import com.x.base.core.project.jaxrs.CipherManagerJaxrsFilter;
import javax.servlet.annotation.WebFilter;
@WebFilter(urlPatterns = "/jaxrs/designer/*", asyncSupported = true)
public class DesignerJaxrsFilter extends CipherManagerJaxrsFilter {
}
package com.x.portal.assemble.designer.jaxrs.designer;
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.JpaObject;
import com.x.base.core.entity.enums.DesignerType;
import com.x.base.core.project.bean.WrapCopier;
import com.x.base.core.project.bean.WrapCopierFactory;
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.WiDesigner;
import com.x.base.core.project.jaxrs.WrapDesigner;
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.base.core.project.tools.PropertyTools;
import com.x.portal.assemble.designer.Business;
import com.x.portal.core.entity.Page;
import com.x.portal.core.entity.Portal;
import com.x.portal.core.entity.Script;
import com.x.portal.core.entity.Widget;
import org.apache.commons.lang3.StringUtils;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.TimeUnit;
class ActionSearch extends BaseAction {
private static Logger logger = LoggerFactory.getLogger(ActionSearch.class);
ActionResult<List<Wo>> execute(EffectivePerson effectivePerson, JsonElement jsonElement) throws Exception {
if(!effectivePerson.isManager()){
throw new ExceptionAccessDenied(effectivePerson);
}
Wi wi = this.convertToWrapIn(jsonElement, Wi.class);
logger.info("{}开始门户设计搜索,关键字:{}", effectivePerson.getDistinguishedName(), wi.getKeyword());
if(StringUtils.isBlank(wi.getKeyword())){
throw new ExceptionFieldEmpty("keyword");
}
ActionResult<List<Wo>> result = new ActionResult<>();
List<Wo> resWos = new ArrayList<>();
List<CompletableFuture<List<Wo>>> list = new ArrayList<>();
if (wi.getDesignerTypes().isEmpty() || wi.getDesignerTypes().contains(DesignerType.form.toString())){
list.add(searchPage(wi, wi.getAppIdList()));
}
if (wi.getDesignerTypes().isEmpty() || wi.getDesignerTypes().contains(DesignerType.script.toString())){
list.add(searchScript(wi, wi.getAppIdList()));
}
if (wi.getDesignerTypes().isEmpty() || wi.getDesignerTypes().contains(DesignerType.widget.toString())){
list.add(searchWidget(wi, wi.getAppIdList()));
}
for (CompletableFuture<List<Wo>> cf : list){
if(resWos.size()<50) {
resWos.addAll(cf.get(60, TimeUnit.SECONDS));
}
}
if (resWos.size()>50){
resWos = resWos.subList(0, 50);
}
result.setData(resWos);
result.setCount((long)resWos.size());
return result;
}
private CompletableFuture<List<Wo>> searchScript(final Wi wi, final List<String> appIdList) {
CompletableFuture<List<Wo>> cf = CompletableFuture.supplyAsync(() -> {
List<Wo> resWos = new ArrayList<>();
try (EntityManagerContainer emc = EntityManagerContainerFactory.instance().create()) {
List<WoScript> woScripts;
if (ListTools.isEmpty(appIdList)) {
woScripts = emc.fetchAll(Script.class, WoScript.copier);
} else {
woScripts = emc.fetchIn(Script.class, WoScript.copier, Script.portal_FIELDNAME, appIdList);
}
for (WoScript woScript : woScripts) {
Map<String, String> map = PropertyTools.fieldMatchKeyword(WoScript.copier.getCopyFields(), woScript, wi.getKeyword(),
wi.getCaseSensitive(), wi.getMatchWholeWord(), wi.getMatchRegExp());
if (!map.isEmpty()) {
Wo wo = new Wo();
Portal portal = emc.find(woScript.getPortal(), Portal.class);
if(portal != null){
wo.setAppId(portal.getId());
wo.setAppName(portal.getName());
}
wo.setDesignerId(woScript.getId());
wo.setDesignerName(woScript.getName());
wo.setDesignerType(DesignerType.script.toString());
wo.setUpdateTime(woScript.getUpdateTime());
wo.setPatternList(map);
resWos.add(wo);
}
}
woScripts.clear();
}catch (Exception e){
logger.error(e);
}
return resWos;
});
return cf;
}
private CompletableFuture<List<Wo>> searchPage(final Wi wi, final List<String> appIdList) {
CompletableFuture<List<Wo>> cf = CompletableFuture.supplyAsync(() -> {
List<Wo> resWos = new ArrayList<>();
try (EntityManagerContainer emc = EntityManagerContainerFactory.instance().create()) {
Business business = new Business(emc);
List<String> ids = business.page().listWithPortals(appIdList);
for (List<String> partIds : ListTools.batch(ids, 100)) {
List<WoPage> wos = emc.fetchIn(Page.class, WoPage.copier, Page.id_FIELDNAME, partIds);
for (WoPage wopage : wos) {
Map<String, String> map = PropertyTools.fieldMatchKeyword(WoPage.copier.getCopyFields(), wopage, wi.getKeyword(),
wi.getCaseSensitive(), wi.getMatchWholeWord(), wi.getMatchRegExp());
if (!map.isEmpty()) {
Wo wo = new Wo();
Portal portal = emc.find(wopage.getPortal(), Portal.class);
if(portal != null){
wo.setAppId(portal.getId());
wo.setAppName(portal.getName());
}
wo.setDesignerId(wopage.getId());
wo.setDesignerName(wopage.getName());
wo.setDesignerType(DesignerType.page.toString());
wo.setUpdateTime(wopage.getUpdateTime());
wo.setPatternList(map);
resWos.add(wo);
}
}
wos.clear();
}
}catch (Exception e){
logger.error(e);
}
return resWos;
});
return cf;
}
private CompletableFuture<List<Wo>> searchWidget(final Wi wi, final List<String> appIdList) {
CompletableFuture<List<Wo>> cf = CompletableFuture.supplyAsync(() -> {
List<Wo> resWos = new ArrayList<>();
try (EntityManagerContainer emc = EntityManagerContainerFactory.instance().create()) {
Business business = new Business(emc);
List<String> ids = business.widget().listWithPortals(appIdList);
for (List<String> partIds : ListTools.batch(ids, 100)) {
List<WoWidget> wos = emc.fetchIn(Widget.class, WoWidget.copier, WoWidget.id_FIELDNAME, partIds);
for (WoWidget woWidget : wos) {
Map<String, String> map = PropertyTools.fieldMatchKeyword(WoWidget.copier.getCopyFields(), woWidget, wi.getKeyword(),
wi.getCaseSensitive(), wi.getMatchWholeWord(), wi.getMatchRegExp());
if (!map.isEmpty()) {
Wo wo = new Wo();
Portal portal = emc.find(woWidget.getPortal(), Portal.class);
if(portal != null){
wo.setAppId(portal.getId());
wo.setAppName(portal.getName());
}
wo.setDesignerId(woWidget.getId());
wo.setDesignerName(woWidget.getName());
wo.setDesignerType(DesignerType.widget.toString());
wo.setUpdateTime(woWidget.getUpdateTime());
wo.setPatternList(map);
resWos.add(wo);
}
}
wos.clear();
}
}catch (Exception e){
logger.error(e);
}
return resWos;
});
return cf;
}
public static class Wi extends WiDesigner {
}
public static class Wo extends WrapDesigner{
}
public static class WoScript extends Script {
static WrapCopier<Script, WoScript> copier = WrapCopierFactory.wo(Script.class, WoScript.class,
JpaObject.singularAttributeField(Script.class, true, false),null);
}
public static class WoPage extends Page {
static WrapCopier<Page, WoPage> copier = WrapCopierFactory.wo(Page.class, WoPage.class,
JpaObject.singularAttributeField(WoPage.class, true, false),null);
}
public static class WoWidget extends Widget {
static WrapCopier<Widget, WoWidget> copier = WrapCopierFactory.wo(Widget.class, WoWidget.class,
JpaObject.singularAttributeField(WoWidget.class, true, false),null);
}
}
package com.x.portal.assemble.designer.jaxrs.designer;
import com.x.base.core.project.jaxrs.StandardJaxrsAction;
abstract class BaseAction extends StandardJaxrsAction {
}
package com.x.portal.assemble.designer.jaxrs.designer;
import com.google.gson.JsonElement;
import com.x.base.core.project.annotation.JaxrsDescribe;
import com.x.base.core.project.annotation.JaxrsMethodDescribe;
import com.x.base.core.project.http.ActionResult;
import com.x.base.core.project.http.EffectivePerson;
import com.x.base.core.project.http.HttpMediaType;
import com.x.base.core.project.jaxrs.ResponseFactory;
import com.x.base.core.project.jaxrs.StandardJaxrsAction;
import com.x.base.core.project.logger.Logger;
import com.x.base.core.project.logger.LoggerFactory;
import javax.servlet.http.HttpServletRequest;
import javax.ws.rs.Consumes;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.container.AsyncResponse;
import javax.ws.rs.container.Suspended;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.MediaType;
import java.util.List;
@Path("designer")
@JaxrsDescribe("设计")
public class DesignerAction extends StandardJaxrsAction {
private static Logger logger = LoggerFactory.getLogger(DesignerAction.class);
@JaxrsMethodDescribe(value = "根据关键字搜索设计对象.", action = ActionSearch.class)
@POST
@Path("search")
@Produces(HttpMediaType.APPLICATION_JSON_UTF_8)
@Consumes(MediaType.APPLICATION_JSON)
public void search(@Suspended final AsyncResponse asyncResponse, @Context HttpServletRequest request,
JsonElement jsonElement) {
ActionResult<List<ActionSearch.Wo>> result = new ActionResult<>();
EffectivePerson effectivePerson = this.effectivePerson(request);
try {
result = new ActionSearch().execute(effectivePerson, jsonElement);
} catch (Exception e) {
logger.error(e, effectivePerson, request, null);
result.error(e);
}
asyncResponse.resume(ResponseFactory.getEntityTagActionResultResponse(request, result));
}
}
package com.x.portal.assemble.designer.jaxrs.designer;
import com.x.base.core.project.exception.PromptException;
public class ExceptionFieldEmpty extends PromptException {
public ExceptionFieldEmpty(String field) {
super("参数: {} 值无效.", field);
}
}
......@@ -2,6 +2,7 @@ package com.x.processplatform.assemble.designer.element.factory;
import java.util.Comparator;
import java.util.List;
import java.util.concurrent.locks.Condition;
import java.util.stream.Collectors;
import javax.persistence.EntityManager;
......@@ -10,6 +11,7 @@ import javax.persistence.criteria.CriteriaQuery;
import javax.persistence.criteria.Predicate;
import javax.persistence.criteria.Root;
import com.x.base.core.project.tools.ListTools;
import com.x.processplatform.assemble.designer.AbstractFactory;
import com.x.processplatform.assemble.designer.Business;
import com.x.processplatform.core.entity.element.Form;
......@@ -31,6 +33,19 @@ public class FormFactory extends AbstractFactory {
return em.createQuery(cq).getResultList();
}
public List<String> listWithApplications(List<String> applications) throws Exception {
EntityManager em = this.entityManagerContainer().get(Form.class);
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<String> cq = cb.createQuery(String.class);
Root<Form> root = cq.from(Form.class);
Predicate p = cb.conjunction();
if(ListTools.isNotEmpty(applications)) {
p = cb.isMember(root.get(Form_.application), cb.literal(applications));
}
cq.select(root.get(Form_.id)).where(p);
return em.createQuery(cq).getResultList();
}
public List<Form> listWithApplicationObject(String application) throws Exception {
EntityManager em = this.entityManagerContainer().get(Form.class);
CriteriaBuilder cb = em.getCriteriaBuilder();
......@@ -47,4 +62,4 @@ public class FormFactory extends AbstractFactory {
return list;
}
}
\ No newline at end of file
}
......@@ -8,6 +8,7 @@ import com.x.base.core.project.jaxrs.AbstractActionApplication;
import com.x.processplatform.assemble.designer.jaxrs.application.ApplicationAction;
import com.x.processplatform.assemble.designer.jaxrs.applicationcategory.ApplicationCategoryAction;
import com.x.processplatform.assemble.designer.jaxrs.applicationdict.ApplicationDictAction;
import com.x.processplatform.assemble.designer.jaxrs.designer.DesignerAction;
import com.x.processplatform.assemble.designer.jaxrs.elementtool.ElementToolAction;
import com.x.processplatform.assemble.designer.jaxrs.file.FileAction;
import com.x.processplatform.assemble.designer.jaxrs.form.FormAction;
......@@ -45,7 +46,8 @@ public class ActionApplication extends AbstractActionApplication {
classes.add(MappingAction.class);
classes.add(ElementToolAction.class);
classes.add(WorkCompletedAction.class);
classes.add(DesignerAction.class);
return classes;
}
}
\ No newline at end of file
}
package com.x.processplatform.assemble.designer.jaxrs;
import com.x.base.core.project.jaxrs.CipherManagerJaxrsFilter;
import javax.servlet.annotation.WebFilter;
@WebFilter(urlPatterns = "/jaxrs/designer/*", asyncSupported = true)
public class DesignerJaxrsFilter extends CipherManagerJaxrsFilter {
}
package com.x.processplatform.assemble.designer.jaxrs.designer;
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.JpaObject;
import com.x.base.core.entity.enums.DesignerType;
import com.x.base.core.project.bean.WrapCopier;
import com.x.base.core.project.bean.WrapCopierFactory;
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.WiDesigner;
import com.x.base.core.project.jaxrs.WrapDesigner;
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.base.core.project.tools.PropertyTools;
import com.x.processplatform.assemble.designer.Business;
import com.x.processplatform.core.entity.element.Application;
import com.x.processplatform.core.entity.element.Form;
import com.x.processplatform.core.entity.element.Script;
import com.x.processplatform.core.entity.element.wrap.WrapProcess;
import org.apache.commons.lang3.StringUtils;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.TimeUnit;
class ActionSearch extends BaseAction {
private static Logger logger = LoggerFactory.getLogger(ActionSearch.class);
ActionResult<List<Wo>> execute(EffectivePerson effectivePerson, JsonElement jsonElement) throws Exception {
if(!effectivePerson.isManager()){
throw new ExceptionAccessDenied(effectivePerson);
}
Wi wi = this.convertToWrapIn(jsonElement, Wi.class);
logger.info("{}开始流程平台设计搜索,关键字:{}", effectivePerson.getDistinguishedName(), wi.getKeyword());
if(StringUtils.isBlank(wi.getKeyword())){
throw new ExceptionFieldEmpty("keyword");
}
ActionResult<List<Wo>> result = new ActionResult<>();
List<Wo> resWos = new ArrayList<>();
List<CompletableFuture<List<Wo>>> list = new ArrayList<>();
if (wi.getDesignerTypes().isEmpty() || wi.getDesignerTypes().contains(DesignerType.form.toString())){
list.add(searchForm(wi, wi.getAppIdList()));
}
if (wi.getDesignerTypes().isEmpty() || wi.getDesignerTypes().contains(DesignerType.script.toString())){
list.add(searchScript(wi, wi.getAppIdList()));
}
for (CompletableFuture<List<Wo>> cf : list){
if(resWos.size()<50) {
resWos.addAll(cf.get(60, TimeUnit.SECONDS));
}
}
if (resWos.size()>50){
resWos = resWos.subList(0, 50);
}
result.setData(resWos);
result.setCount((long)resWos.size());
return result;
}
private CompletableFuture<List<Wo>> searchScript(final Wi wi, final List<String> appIdList) {
CompletableFuture<List<Wo>> cf = CompletableFuture.supplyAsync(() -> {
List<Wo> resWos = new ArrayList<>();
try (EntityManagerContainer emc = EntityManagerContainerFactory.instance().create()) {
List<WoScript> woScripts;
if (ListTools.isEmpty(appIdList)) {
woScripts = emc.fetchAll(Script.class, WoScript.copier);
} else {
woScripts = emc.fetchIn(Script.class, WoScript.copier, Script.application_FIELDNAME, appIdList);
}
for (WoScript woScript : woScripts) {
Map<String, String> map = PropertyTools.fieldMatchKeyword(WoScript.copier.getCopyFields(), woScript, wi.getKeyword(),
wi.getCaseSensitive(), wi.getMatchWholeWord(), wi.getMatchRegExp());
if (!map.isEmpty()) {
Wo wo = new Wo();
Application app = emc.find(woScript.getApplication(), Application.class);
if (app != null) {
wo.setAppId(app.getId());
wo.setAppName(app.getName());
}
wo.setDesignerId(woScript.getId());
wo.setDesignerName(woScript.getName());
wo.setDesignerType(DesignerType.script.toString());
wo.setUpdateTime(woScript.getUpdateTime());
wo.setPatternList(map);
resWos.add(wo);
}
}
woScripts.clear();
}catch (Exception e){
logger.error(e);
}
return resWos;
});
return cf;
}
private CompletableFuture<List<Wo>> searchForm(final Wi wi, final List<String> appIdList) {
CompletableFuture<List<Wo>> cf = CompletableFuture.supplyAsync(() -> {
List<Wo> resWos = new ArrayList<>();
try (EntityManagerContainer emc = EntityManagerContainerFactory.instance().create()) {
Business business = new Business(emc);
List<String> formIds = business.form().listWithApplications(appIdList);
for (List<String> partFormIds : ListTools.batch(formIds, 100)) {
List<WoForm> woForms = emc.fetchIn(Form.class, WoForm.copier, Form.id_FIELDNAME, partFormIds);
for (WoForm woForm : woForms) {
Map<String, String> map = PropertyTools.fieldMatchKeyword(WoForm.copier.getCopyFields(), woForm, wi.getKeyword(),
wi.getCaseSensitive(), wi.getMatchWholeWord(), wi.getMatchRegExp());
if (!map.isEmpty()) {
Wo wo = new Wo();
Application app = emc.find(woForm.getApplication(), Application.class);
if (app != null) {
wo.setAppId(app.getId());
wo.setAppName(app.getName());
}
wo.setDesignerId(woForm.getId());
wo.setDesignerName(woForm.getName());
wo.setDesignerType(DesignerType.form.toString());
wo.setUpdateTime(woForm.getUpdateTime());
wo.setPatternList(map);
resWos.add(wo);
}
}
woForms.clear();
}
}catch (Exception e){
logger.error(e);
}
return resWos;
});
return cf;
}
public static class Wi extends WiDesigner {
}
public static class Wo extends WrapDesigner{
}
public static class WoScript extends Script {
static WrapCopier<Script, WoScript> copier = WrapCopierFactory.wo(Script.class, WoScript.class,
JpaObject.singularAttributeField(Script.class, true, false),null);
}
public static class WoForm extends Form {
static WrapCopier<Form, WoForm> copier = WrapCopierFactory.wo(Form.class, WoForm.class,
JpaObject.singularAttributeField(Form.class, true, false),null);
}
public static class WoProcess extends WrapProcess {
private static final long serialVersionUID = -8507786999314667403L;
}
}
package com.x.processplatform.assemble.designer.jaxrs.designer;
import com.x.base.core.project.jaxrs.StandardJaxrsAction;
abstract class BaseAction extends StandardJaxrsAction {
}
package com.x.processplatform.assemble.designer.jaxrs.designer;
import com.google.gson.JsonElement;
import com.x.base.core.project.annotation.JaxrsDescribe;
import com.x.base.core.project.annotation.JaxrsMethodDescribe;
import com.x.base.core.project.http.ActionResult;
import com.x.base.core.project.http.EffectivePerson;
import com.x.base.core.project.http.HttpMediaType;
import com.x.base.core.project.jaxrs.ResponseFactory;
import com.x.base.core.project.jaxrs.StandardJaxrsAction;
import com.x.base.core.project.logger.Logger;
import com.x.base.core.project.logger.LoggerFactory;
import javax.servlet.http.HttpServletRequest;
import javax.ws.rs.*;
import javax.ws.rs.container.AsyncResponse;
import javax.ws.rs.container.Suspended;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.MediaType;
import java.util.List;
@Path("designer")
@JaxrsDescribe("设计")
public class DesignerAction extends StandardJaxrsAction {
private static Logger logger = LoggerFactory.getLogger(DesignerAction.class);
@JaxrsMethodDescribe(value = "根据关键字搜索设计对象.", action = ActionSearch.class)
@POST
@Path("search")
@Produces(HttpMediaType.APPLICATION_JSON_UTF_8)
@Consumes(MediaType.APPLICATION_JSON)
public void search(@Suspended final AsyncResponse asyncResponse, @Context HttpServletRequest request,
JsonElement jsonElement) {
ActionResult<List<ActionSearch.Wo>> result = new ActionResult<>();
EffectivePerson effectivePerson = this.effectivePerson(request);
try {
result = new ActionSearch().execute(effectivePerson, jsonElement);
} catch (Exception e) {
logger.error(e, effectivePerson, request, null);
result.error(e);
}
asyncResponse.resume(ResponseFactory.getEntityTagActionResultResponse(request, result));
}
}
package com.x.processplatform.assemble.designer.jaxrs.designer;
import com.x.base.core.project.exception.PromptException;
public class ExceptionFieldEmpty extends PromptException {
public ExceptionFieldEmpty(String field) {
super("参数: {} 值无效.", field);
}
}
......@@ -7,19 +7,21 @@ import com.x.base.core.project.annotation.FieldTypeDescribe;
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.WiDesigner;
import com.x.base.core.project.jaxrs.WrapDesigner;
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.base.core.project.tools.SortTools;
import com.x.base.core.project.tools.StringTools;
import com.x.base.core.project.x_cms_assemble_control;
import com.x.base.core.project.x_portal_assemble_designer;
import com.x.base.core.project.x_processplatform_assemble_designer;
import com.x.query.service.processing.ThisApplication;
import org.apache.commons.beanutils.BeanUtils;
import org.apache.commons.lang3.StringUtils;
import java.util.*;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.*;
class ActionSearch extends BaseAction {
......@@ -29,27 +31,15 @@ class ActionSearch extends BaseAction {
throws Exception {
ActionResult<Wo> result = new ActionResult<>();
Wi wi = this.convertToWrapIn(jsonElement, Wi.class);
Wo wo = new Wo();
wo.setType(wi.getType());
if(StringUtils.isBlank(wi.getKeyword())){
throw new ExceptionFieldEmpty("keyword");
}
if(StringUtils.isBlank(wi.getType())){
throw new ExceptionFieldEmpty("type");
}
logger.print("{}搜索全局设计:{},关键字:{}", effectivePerson.getDistinguishedName(), wi.getType(), wi.getKeyword());
switch (wi.getType()) {
case "script":
wo.setScriptWrapList(searchScript(wi));
break;
default:
throw new ExceptionFieldEmpty("type");
}
result.setData(wo);
logger.print("{}搜索全局设计:{}", effectivePerson.getDistinguishedName(), wi);
result.setData(search(wi));
return result;
}
private List<ScriptWo> searchScript(final Wi wi) throws Exception{
private Wo search(final Wi wi) {
final Map<String, List<String>> moduleMap = new HashMap<>();
if(!ListTools.isEmpty(wi.getModuleList())){
for (Module module: wi.getModuleList()){
......@@ -69,65 +59,66 @@ class ActionSearch extends BaseAction {
moduleMap.put(ModuleType.portal.toString(), list);
moduleMap.put(ModuleType.processPlatform.toString(), list);
}
CompletableFuture<List<ScriptWo>> processPlatformCf = scriptSearchAsync(wi, moduleMap, ModuleType.processPlatform.toString(), x_processplatform_assemble_designer.class);
CompletableFuture<List<ScriptWo>> portalCf = scriptSearchAsync(wi, moduleMap, ModuleType.portal.toString(), x_portal_assemble_designer.class);
CompletableFuture<List<ScriptWo>> cmsCf = scriptSearchAsync(wi, moduleMap, ModuleType.cms.toString(), x_cms_assemble_control.class);
List<ScriptWo> scriptWoList = new ArrayList<>();
scriptWoList.addAll(processPlatformCf.get());
scriptWoList.addAll(portalCf.get());
scriptWoList.addAll(cmsCf.get());
return scriptWoList;
Executor executor = Executors.newFixedThreadPool(5);
CompletableFuture<List<WrapDesigner>> processPlatformCf = searchAsync(wi, moduleMap, ModuleType.processPlatform.toString(), x_processplatform_assemble_designer.class, executor);
CompletableFuture<List<WrapDesigner>> portalCf = searchAsync(wi, moduleMap, ModuleType.portal.toString(), x_portal_assemble_designer.class, executor);
CompletableFuture<List<WrapDesigner>> cmsCf = searchAsync(wi, moduleMap, ModuleType.cms.toString(), x_cms_assemble_control.class, executor);
Wo wo = new Wo();
try {
wo.setProcessPlatformList(processPlatformCf.get(200, TimeUnit.SECONDS));
} catch (Exception e) {
logger.warn("搜索流程平台设计异常:{}",e.getMessage());
}
try {
wo.setPortalList(portalCf.get(200, TimeUnit.SECONDS));
} catch (Exception e) {
logger.warn("搜索门户平台设计异常:{}",e.getMessage());
}
try {
wo.setCmsList(cmsCf.get(200, TimeUnit.SECONDS));
} catch (Exception e) {
logger.warn("搜索内容管理平台设计异常:{}",e.getMessage());
}
return wo;
}
private CompletableFuture<List<ScriptWo>> scriptSearchAsync(final Wi wi, final Map<String, List<String>> moduleMap, final String moduleType, final Class<?> applicationClass){
CompletableFuture<List<ScriptWo>> cf = CompletableFuture.supplyAsync(() -> {
List<ScriptWo> swList = new ArrayList<>();
private CompletableFuture<List<WrapDesigner>> searchAsync(final Wi wi, final Map<String, List<String>> moduleMap, final String moduleType, final Class<?> applicationClass, Executor executor){
CompletableFuture<List<WrapDesigner>> cf = CompletableFuture.supplyAsync(() -> {
List<WrapDesigner> swList = new ArrayList<>();
if(moduleMap.containsKey(moduleType)) {
try {
Map<String, Object> map = new HashMap<>();
map.put("appIdList", moduleMap.get(moduleType));
map.put("keyword", wi.getKeyword());
map.put("caseSensitive", wi.getCaseSensitive());
map.put("matchWholeWord", wi.getMatchWholeWord());
map.put("matchRegExp", wi.getMatchRegExp());
List<WrapScript> scriptList = ThisApplication.context().applications().postQuery(applicationClass,
Applications.joinQueryUri("script", "list", "manager"), map).getDataAsList(WrapScript.class);
logger.print("设计搜索关联{}的匹配脚本个数:{}", moduleType, scriptList.size());
getScriptSearchRes(wi, moduleType, swList, scriptList);
WiDesigner wiDesigner = new WiDesigner();
BeanUtils.copyProperties(wiDesigner, wi);
wiDesigner.setAppIdList(moduleMap.get(moduleType));
List<WrapDesigner> designerList = ThisApplication.context().applications().postQuery(applicationClass,
Applications.joinQueryUri("designer", "search"), wiDesigner).getDataAsList(WrapDesigner.class);
logger.info("设计搜索关联{}的匹配设计个数:{}", moduleType, designerList.size());
getSearchRes(wi, designerList);
swList = designerList;
} catch (Exception e) {
logger.error(e);
}
if (swList.size() > 2) {
try {
SortTools.desc(swList, "appId");
SortTools.desc(swList, "designerType","appId");
} catch (Exception e) {
}
}
}
return swList;
});
}, executor);
return cf;
}
private void getScriptSearchRes(final Wi wi, String moduleType, List<ScriptWo> swList, List<WrapScript> scriptList){
if (!ListTools.isEmpty(scriptList)){
for (WrapScript script:scriptList) {
if (StringTools.matchKeyword(wi.getKeyword(), script.getText(), wi.getCaseSensitive(), wi.getMatchWholeWord(), wi.getMatchRegExp())){
List<Integer> list = patternLines(script.getId()+"-"+script.getUpdateTime().getTime(),
wi.getKeyword(), script.getText(), wi.getCaseSensitive(), wi.getMatchWholeWord(), wi.getMatchRegExp());
if (!ListTools.isEmpty(list)){
ScriptWo scriptWo = new ScriptWo();
scriptWo.setModuleType(moduleType);
scriptWo.setAppId(script.getAppId());
scriptWo.setAppName(script.getAppName());
scriptWo.setScriptId(script.getId());
scriptWo.setScriptName(script.getName());
scriptWo.setPatternLines(list);
swList.add(scriptWo);
}
private void getSearchRes(final Wi wi, List<WrapDesigner> designerList){
if (!ListTools.isEmpty(designerList)){
for (WrapDesigner designer : designerList) {
WrapDesigner.DesignerPattern pattern = designer.getScriptDesigner();
if(pattern!=null) {
List<Integer> lines = patternLines(designer.getDesignerId() + "-" + designer.getUpdateTime().getTime(),
wi.getKeyword(), pattern.getPropertyValue(), wi.getCaseSensitive(), wi.getMatchWholeWord(), wi.getMatchRegExp());
pattern.setLines(lines);
pattern.setPropertyValue(null);
}
}
}
......@@ -138,15 +129,15 @@ class ActionSearch extends BaseAction {
@FieldDescribe("搜索关键字.")
private String keyword;
@FieldDescribe("搜索类型:script|form|process")
private String type;
@FieldDescribe("搜索设计类型:script|form|page|widget|process")
private List<String> designerTypes;
@FieldDescribe("是否区分大小写.")
private Boolean caseSensitive;
@FieldDescribe("是否全字匹配.")
private Boolean matchWholeWord;
@FieldDescribe("是否正则表达式匹配.")
private Boolean matchRegExp;
@FieldDescribe("限制查询的模块列表.")
@FieldDescribe("限制查询的模块列表(模块类型:processPlatform|cms|portal|query|service).")
@FieldTypeDescribe(fieldType = "class", fieldTypeName = "Module", fieldValue = "{\"moduleType\": \"cms\", \"flagList\": []}")
private List<Module> moduleList;
......@@ -158,12 +149,12 @@ class ActionSearch extends BaseAction {
this.keyword = keyword;
}
public String getType() {
return type;
public List<String> getDesignerTypes() {
return designerTypes;
}
public void setType(String type) {
this.type = type;
public void setDesignerTypes(List<String> designerTypes) {
this.designerTypes = designerTypes;
}
public Boolean getCaseSensitive() {
......@@ -202,7 +193,7 @@ class ActionSearch extends BaseAction {
public static class Module extends GsonPropertyObject {
@FieldDescribe("模块的应用id列表.")
private List<String> flagList;
@FieldDescribe("模块类型:processPlatform|cms|portal|query|service")
@FieldDescribe("模块类型.")
private String moduleType;
public List<String> getFlagList() {
......@@ -223,88 +214,37 @@ class ActionSearch extends BaseAction {
}
public static class Wo extends GsonPropertyObject {
@FieldDescribe("搜索类型:script|form|process")
private String type;
@FieldDescribe("脚本搜索结果集")
private List<ScriptWo> scriptWrapList = new ArrayList<>();
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
public List<ScriptWo> getScriptWrapList() {
return scriptWrapList;
}
private static final long serialVersionUID = 8169092162410529422L;
public void setScriptWrapList(List<ScriptWo> scriptWrapList) {
this.scriptWrapList = scriptWrapList;
}
}
private List<WrapDesigner> processPlatformList;
public static class ScriptWo extends GsonPropertyObject {
@FieldDescribe("模块类型:processPlatform|cms|portal|query|service")
private String moduleType;
@FieldDescribe("应用ID")
private String appId;
@FieldDescribe("应用名称")
private String appName;
@FieldDescribe("脚本Id")
private String scriptId;
@FieldDescribe("脚本名称")
private String scriptName;
@FieldDescribe("匹配行")
private List<Integer> patternLines;
private List<WrapDesigner> cmsList;
public String getModuleType() {
return moduleType;
}
public void setModuleType(String moduleType) {
this.moduleType = moduleType;
}
public String getAppId() {
return appId;
}
public void setAppId(String appId) {
this.appId = appId;
}
public String getAppName() {
return appName;
}
public void setAppName(String appName) {
this.appName = appName;
}
private List<WrapDesigner> portalList;
public String getScriptId() {
return scriptId;
public List<WrapDesigner> getProcessPlatformList() {
return processPlatformList;
}
public void setScriptId(String scriptId) {
this.scriptId = scriptId;
public void setProcessPlatformList(List<WrapDesigner> processPlatformList) {
this.processPlatformList = processPlatformList;
}
public String getScriptName() {
return scriptName;
public List<WrapDesigner> getCmsList() {
return cmsList;
}
public void setScriptName(String scriptName) {
this.scriptName = scriptName;
public void setCmsList(List<WrapDesigner> cmsList) {
this.cmsList = cmsList;
}
public List<Integer> getPatternLines() {
return patternLines;
public List<WrapDesigner> getPortalList() {
return portalList;
}
public void setPatternLines(List<Integer> patternLines) {
this.patternLines = patternLines;
public void setPortalList(List<WrapDesigner> portalList) {
this.portalList = portalList;
}
}
......
......@@ -3,10 +3,14 @@ package com.x.query.service.processing.jaxrs.design;
import com.x.base.core.entity.JpaObject;
/**
*
* processPlatform(流程管理平台)
* portal(门户管理平台)
* cms(内容管理平台)
* query (数据中心平台)
* service(服务管理平台)
*/
public enum ModuleType {
processPlatform, portal, cms;
processPlatform, portal, cms, query, service;
public static final int length = JpaObject.length_64B;
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册