From 2ad0061b385c794520b4f13c0a37eb924b8a981b Mon Sep 17 00:00:00 2001 From: o2sword <171715986@qq.com> Date: Mon, 2 Nov 2020 17:32:13 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E8=8E=B7=E5=8F=96=E5=AE=9E?= =?UTF-8?q?=E4=BD=93=E5=AF=B9=E8=B1=A1=E7=9A=84=E5=B1=9E=E6=80=A7=E4=BF=A1?= =?UTF-8?q?=E6=81=AF=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../query/ActionGetEntityProperties.java | 126 ++++++++++++++++++ .../designer/jaxrs/query/QueryAction.java | 19 +++ 2 files changed, 145 insertions(+) create mode 100644 o2server/x_query_assemble_designer/src/main/java/com/x/query/assemble/designer/jaxrs/query/ActionGetEntityProperties.java diff --git a/o2server/x_query_assemble_designer/src/main/java/com/x/query/assemble/designer/jaxrs/query/ActionGetEntityProperties.java b/o2server/x_query_assemble_designer/src/main/java/com/x/query/assemble/designer/jaxrs/query/ActionGetEntityProperties.java new file mode 100644 index 0000000000..2c133b2394 --- /dev/null +++ b/o2server/x_query_assemble_designer/src/main/java/com/x/query/assemble/designer/jaxrs/query/ActionGetEntityProperties.java @@ -0,0 +1,126 @@ +package com.x.query.assemble.designer.jaxrs.query; + +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.dynamic.DynamicEntity; +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.query.assemble.designer.Business; +import com.x.query.core.entity.schema.Statement; +import com.x.query.core.entity.schema.Table; +import org.apache.commons.lang3.BooleanUtils; +import org.apache.commons.lang3.StringUtils; +import org.apache.commons.lang3.reflect.FieldUtils; +import org.apache.openjpa.persistence.jdbc.Strategy; + +import javax.persistence.Column; +import javax.persistence.Lob; +import java.lang.reflect.Field; +import java.util.ArrayList; +import java.util.List; + +class ActionGetEntityProperties extends BaseAction { + ActionResult> execute(EffectivePerson effectivePerson, String entity, String entityCategory) throws Exception { + try (EntityManagerContainer emc = EntityManagerContainerFactory.instance().create()) { + ActionResult> result = new ActionResult<>(); + Business business = new Business(emc); + if (!business.controllable(effectivePerson)) { + throw new ExceptionAccessDenied(effectivePerson); + } + Class cls = this.clazz(business, entity, entityCategory); + result.setData(this.getEntityDes(cls,true,false)); + return result; + } + } + + private List getEntityDes(Class clz, Boolean excludeInvisible, Boolean excludeLob){ + List wos = new ArrayList<>(); + Wo wo = null; + for (Field field : FieldUtils.getFieldsListWithAnnotation(clz, Column.class)) { + if (BooleanUtils.isTrue(excludeInvisible) && JpaObject.FieldsInvisible.contains(field.getName())) { + continue; + } + if (BooleanUtils.isTrue(excludeLob)) { + if (null != field.getAnnotation(Lob.class)) { + continue; + } else { + Strategy strategy = field.getAnnotation(Strategy.class); + if ((null != strategy) && StringUtils.equals(JpaObject.JsonPropertiesValueHandler, strategy.value())) { + continue; + } + } + } + wo = new Wo(); + wo.setName(field.getName()); + wo.setType(field.getType().getSimpleName()); + FieldDescribe fd = field.getAnnotation(FieldDescribe.class); + if(fd!=null){ + wo.setDescription(fd.value()); + } + wos.add(wo); + } + return wos; + } + + private Class clazz(Business business, String entity, String entityCategory) throws Exception { + Class cls = null; + if (StringUtils.equals(Statement.ENTITYCATEGORY_OFFICIAL, entityCategory) + || StringUtils.equals(Statement.ENTITYCATEGORY_CUSTOM, entityCategory)) { + try { + cls = (Class) Class.forName(entity); + } catch (Exception e) { + throw new ExceptionEntityNotExist(entity, entityCategory); + } + } else { + Table table = business.entityManagerContainer().flag(entity, Table.class); + if (null == table) { + throw new ExceptionEntityNotExist(entity, Table.class); + } + DynamicEntity dynamicEntity = new DynamicEntity(table.getName()); + try { + cls = (Class) Class.forName(dynamicEntity.className()); + } catch (Exception e) { + throw new ExceptionEntityNotExist(entity, entityCategory); + } + } + return cls; + } + + public static class Wo extends GsonPropertyObject { + @FieldDescribe("属性名称.") + private String name; + @FieldDescribe("属性类型.") + private String type; + @FieldDescribe("属性描述.") + private String description; + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getType() { + return type; + } + + public void setType(String type) { + this.type = type; + } + + public String getDescription() { + return description; + } + + public void setDescription(String description) { + this.description = description; + } + } +} diff --git a/o2server/x_query_assemble_designer/src/main/java/com/x/query/assemble/designer/jaxrs/query/QueryAction.java b/o2server/x_query_assemble_designer/src/main/java/com/x/query/assemble/designer/jaxrs/query/QueryAction.java index 99b6310194..57302d1d27 100644 --- a/o2server/x_query_assemble_designer/src/main/java/com/x/query/assemble/designer/jaxrs/query/QueryAction.java +++ b/o2server/x_query_assemble_designer/src/main/java/com/x/query/assemble/designer/jaxrs/query/QueryAction.java @@ -215,4 +215,23 @@ public class QueryAction extends BaseAction { asyncResponse.resume(ResponseFactory.getEntityTagActionResultResponse(request, result)); } + @JaxrsMethodDescribe(value = "根据标识获取语句操作对象的属性信息.", action = ActionGetEntityProperties.class) + @GET + @Path("entity/{entity}/category/{entityCategory}/properties") + @Produces(HttpMediaType.APPLICATION_JSON_UTF_8) + @Consumes(MediaType.APPLICATION_JSON) + public void getEntityProperties(@Suspended final AsyncResponse asyncResponse, @Context HttpServletRequest request, + @JaxrsParameterDescribe("实体类名称(系统表要全称如com.x.query.core.entity.Query,自建表只要名称)") @PathParam("entity") String entity, + @JaxrsParameterDescribe("实体类类型(自建表:dynamic|系统表:official)") @PathParam("entityCategory") String entityCategory) { + ActionResult> result = new ActionResult<>(); + EffectivePerson effectivePerson = this.effectivePerson(request); + try { + result = new ActionGetEntityProperties().execute(effectivePerson, entity, entityCategory); + } catch (Exception e) { + logger.error(e, effectivePerson, request, null); + result.error(e); + } + asyncResponse.resume(ResponseFactory.getEntityTagActionResultResponse(request, result)); + } + } \ No newline at end of file -- GitLab