提交 f095cd7d 编写于 作者: R roo00

删除旧版本queryView和queryStat

上级 3b2b0766
......@@ -14,8 +14,6 @@ import com.x.processplatform.assemble.surface.jaxrs.file.FileAction;
import com.x.processplatform.assemble.surface.jaxrs.form.FormAction;
import com.x.processplatform.assemble.surface.jaxrs.job.JobAction;
import com.x.processplatform.assemble.surface.jaxrs.process.ProcessAction;
import com.x.processplatform.assemble.surface.jaxrs.querystat.QueryStatAction;
import com.x.processplatform.assemble.surface.jaxrs.queryview.QueryViewAction;
import com.x.processplatform.assemble.surface.jaxrs.read.ReadAction;
import com.x.processplatform.assemble.surface.jaxrs.readcompleted.ReadCompletedAction;
import com.x.processplatform.assemble.surface.jaxrs.review.ReviewAction;
......@@ -51,8 +49,6 @@ public class ActionApplication extends AbstractActionApplication {
classes.add(WorkAction.class);
classes.add(WorkCompletedAction.class);
classes.add(JobAction.class);
classes.add(QueryViewAction.class);
classes.add(QueryStatAction.class);
classes.add(ToolAction.class);
classes.add(TestAction.class);
classes.add(FileAction.class);
......
package com.x.processplatform.assemble.surface.jaxrs.querystat;
import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.List;
import org.apache.commons.lang3.StringUtils;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.reflect.TypeToken;
import com.x.base.core.container.EntityManagerContainer;
import com.x.base.core.container.factory.EntityManagerContainerFactory;
import com.x.base.core.project.bean.NameIdPair;
import com.x.base.core.project.gson.GsonPropertyObject;
import com.x.base.core.project.gson.XGsonBuilder;
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.processplatform.assemble.surface.Business;
import com.x.processplatform.core.entity.element.Application;
import com.x.processplatform.core.entity.element.QueryStat;
import com.x.processplatform.core.entity.element.QueryView;
import com.x.processplatform.core.entity.query.Calculate;
import com.x.processplatform.core.entity.query.DateRangeEntry;
import com.x.processplatform.core.entity.query.FilterEntry;
import com.x.processplatform.core.entity.query.Query;
import com.x.processplatform.core.entity.query.SelectEntry;
import com.x.processplatform.core.entity.query.WhereEntry;
class ActionExecute extends BaseAction {
private static Logger logger = LoggerFactory.getLogger(ActionExecute.class);
private static Type filterEntryCollectionType = new TypeToken<List<FilterEntry>>() {
}.getType();
private static Type stringCollectionType = new TypeToken<List<String>>() {
}.getType();
ActionResult<Query> execute(EffectivePerson effectivePerson, String flag, String applicationFlag,
JsonElement jsonElement) throws Exception {
try (EntityManagerContainer emc = EntityManagerContainerFactory.instance().create()) {
ActionResult<Query> result = new ActionResult<>();
Wi wi = this.convertToWrapIn(jsonElement, Wi.class);
Business business = new Business(emc);
Application application = business.application().pick(applicationFlag);
if (null == application) {
throw new ApplicationNotExistedException(applicationFlag);
}
QueryStat queryStat = business.queryStat().pick(flag, application);
if (null == queryStat) {
throw new QueryStatNotExistedException(flag, applicationFlag);
}
QueryView queryView = business.queryView().pick(queryStat.getQueryView(), application);
if (null == queryView) {
throw new QueryViewNotExistedException(flag, applicationFlag);
}
if (!business.queryView().allowRead(effectivePerson, queryView, application)) {
throw new QueryViewAccessDeniedException(effectivePerson.getDistinguishedName(), queryView.getId(),
applicationFlag);
}
Query query = gson.fromJson(queryView.getData(), Query.class);
/* 从queryStat里面取得data,并从中间分离出calculate注入到query中 */
if (StringUtils.isNotBlank(queryStat.getData())) {
JsonElement element = gson.fromJson(queryStat.getData(), JsonElement.class);
if (null != element && element.isJsonObject()) {
JsonObject jsonObject = element.getAsJsonObject();
if (jsonObject.has("calculate")) {
query.setCalculate(gson.fromJson(jsonObject.get("calculate"), Calculate.class));
}
}
}
if (null != wi) {
if (null != wi.getDate()) {
query.setDateRangeEntry(this.readDateRangeEntry(wi.getDate()));
}
if ((null != wi.getFilter()) && (!wi.getFilter().isJsonNull())) {
query.setFilterEntryList(this.readFilterEntryList(wi.getFilter()));
}
if ((null != wi.getColumn()) && (!wi.getColumn().isJsonNull())) {
query.setColumnList(this.readColumnList(wi.getColumn(), query.getSelectEntryList()));
}
WhereEntry whereEntry = this.readWhereEntry(wi.getApplication(), wi.getProcess(), wi.getUnit(),
wi.getPerson(), wi.getIdentity());
if (whereEntry.available()) {
query.setWhereEntry(whereEntry);
}
}
query.query();
/* 整理一下输出值 */
if ((null != query.getGroupEntry()) && query.getGroupEntry().available()) {
query.setGrid(null);
}
if ((null != query.getCalculate()) && (query.getCalculate().available())) {
query.setGrid(null);
query.setGroupGrid(null);
}
result.setData(query);
return result;
}
}
public static class Wi extends GsonPropertyObject {
private DateRangeEntry date;
private JsonElement filter;
private JsonElement column;
private JsonElement application;
private JsonElement process;
private JsonElement unit;
private JsonElement person;
private JsonElement identity;
public DateRangeEntry getDate() {
return date;
}
public void setDate(DateRangeEntry date) {
this.date = date;
}
public JsonElement getFilter() {
return filter;
}
public void setFilter(JsonElement filter) {
this.filter = filter;
}
public JsonElement getColumn() {
return column;
}
public void setColumn(JsonElement column) {
this.column = column;
}
public JsonElement getApplication() {
return application;
}
public void setApplication(JsonElement application) {
this.application = application;
}
public JsonElement getProcess() {
return process;
}
public void setProcess(JsonElement process) {
this.process = process;
}
public JsonElement getPerson() {
return person;
}
public void setPerson(JsonElement person) {
this.person = person;
}
public JsonElement getIdentity() {
return identity;
}
public void setIdentity(JsonElement identity) {
this.identity = identity;
}
public JsonElement getUnit() {
return unit;
}
public void setUnit(JsonElement unit) {
this.unit = unit;
}
}
private WhereEntry readWhereEntry(JsonElement application, JsonElement process, JsonElement unit,
JsonElement person, JsonElement identity) throws Exception {
WhereEntry whereEntry = new WhereEntry();
if (null != application && (!application.isJsonNull())) {
whereEntry.setApplicationList(this.readApplication(application));
}
if (null != process && (!process.isJsonNull())) {
whereEntry.setProcessList(this.readProcess(process));
}
if (null != unit && (!unit.isJsonNull())) {
whereEntry.setUnitList(this.readUnit(unit));
}
if (null != person && (!person.isJsonNull())) {
whereEntry.setPersonList(this.readPerson(person));
}
if (null != identity && (!identity.isJsonNull())) {
whereEntry.setIdentityList(this.readIdentity(identity));
}
return whereEntry;
}
private List<NameIdPair> readApplication(JsonElement o) throws Exception {
List<NameIdPair> results = new ArrayList<>();
List<String> flags = new ArrayList<>();
if (o.isJsonArray()) {
flags = XGsonBuilder.instance().fromJson(o, stringCollectionType);
} else if (o.isJsonPrimitive() && o.getAsJsonPrimitive().isString()) {
flags.add(o.getAsJsonPrimitive().getAsString());
}
for (String str : flags) {
NameIdPair p = new NameIdPair(str, str);
results.add(p);
}
return results;
}
private List<NameIdPair> readProcess(JsonElement o) throws Exception {
List<NameIdPair> results = new ArrayList<>();
List<String> flags = new ArrayList<>();
if (o.isJsonArray()) {
flags = XGsonBuilder.instance().fromJson(o, stringCollectionType);
} else if (o.isJsonPrimitive() && o.getAsJsonPrimitive().isString()) {
flags.add(o.getAsJsonPrimitive().getAsString());
}
for (String str : flags) {
NameIdPair p = new NameIdPair(str, str);
results.add(p);
}
return results;
}
private List<NameIdPair> readUnit(JsonElement o) throws Exception {
List<NameIdPair> results = new ArrayList<>();
List<String> flags = new ArrayList<>();
if (o.isJsonArray()) {
flags = XGsonBuilder.instance().fromJson(o, stringCollectionType);
} else if (o.isJsonPrimitive() && o.getAsJsonPrimitive().isString()) {
flags.add(o.getAsJsonPrimitive().getAsString());
}
for (String str : flags) {
NameIdPair p = new NameIdPair(str, str);
results.add(p);
}
return results;
}
private List<NameIdPair> readIdentity(JsonElement o) throws Exception {
List<NameIdPair> results = new ArrayList<>();
List<String> flags = new ArrayList<>();
if (o.isJsonArray()) {
flags = XGsonBuilder.instance().fromJson(o, stringCollectionType);
} else if (o.isJsonPrimitive() && o.getAsJsonPrimitive().isString()) {
flags.add(o.getAsJsonPrimitive().getAsString());
}
for (String str : flags) {
NameIdPair p = new NameIdPair(str, str);
results.add(p);
}
return results;
}
private List<NameIdPair> readPerson(JsonElement o) throws Exception {
List<NameIdPair> results = new ArrayList<>();
List<String> flags = new ArrayList<>();
if (o.isJsonArray()) {
flags = XGsonBuilder.instance().fromJson(o, stringCollectionType);
} else if (o.isJsonPrimitive() && o.getAsJsonPrimitive().isString()) {
flags.add(o.getAsJsonPrimitive().getAsString());
}
for (String str : flags) {
NameIdPair p = new NameIdPair(str, str);
results.add(p);
}
return results;
}
private DateRangeEntry readDateRangeEntry(DateRangeEntry o) throws Exception {
if (!o.available()) {
throw new Exception("dateRangeEntry not available:" + o);
}
return o;
}
private List<FilterEntry> readFilterEntryList(JsonElement o) throws Exception {
List<FilterEntry> list = new ArrayList<>();
if (o.isJsonArray()) {
list = XGsonBuilder.instance().fromJson(o, filterEntryCollectionType);
} else if (o.isJsonObject()) {
list.add(XGsonBuilder.instance().fromJson(o, FilterEntry.class));
}
for (FilterEntry entry : list) {
if (!entry.available()) {
throw new Exception("filterEntry not available:" + entry);
}
}
return list;
}
private List<String> readColumnList(JsonElement o, List<SelectEntry> selectEntryList) throws Exception {
List<String> columns = new ArrayList<>();
if (o.isJsonArray()) {
/* 多值 */
for (JsonElement element : o.getAsJsonArray()) {
String column = this.getColumn(element, selectEntryList);
if (StringUtils.isNotEmpty(column)) {
columns.add(column);
}
}
} else if (o.isJsonPrimitive()) {
/* 单值 */
String column = this.getColumn(o, selectEntryList);
if (StringUtils.isNotEmpty(column)) {
columns.add(column);
}
}
return columns;
}
private String getColumn(JsonElement o, List<SelectEntry> list) throws Exception {
if (null == o || o.isJsonNull() || (!o.isJsonPrimitive()) || ListTools.isEmpty(list)) {
return null;
}
if (o.getAsJsonPrimitive().isNumber()) {
Integer idx = o.getAsJsonPrimitive().getAsInt();
if ((idx >= 1) && (idx <= (list.size() + 1))) {
return list.get(idx - 1).getColumn();
}
} else if (o.getAsJsonPrimitive().isString()) {
String str = o.getAsJsonPrimitive().getAsString();
for (SelectEntry entry : list) {
if (StringUtils.equals(entry.getColumn(), str)) {
return entry.getColumn();
}
}
}
return null;
}
}
\ No newline at end of file
package com.x.processplatform.assemble.surface.jaxrs.querystat;
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.project.bean.WrapCopier;
import com.x.base.core.project.bean.WrapCopierFactory;
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.processplatform.assemble.surface.Business;
import com.x.processplatform.core.entity.element.Application;
import com.x.processplatform.core.entity.element.QueryStat;
class ActionFlag extends BaseAction {
private static Logger logger = LoggerFactory.getLogger(ActionFlag.class);
ActionResult<Wo> execute(EffectivePerson effectivePerson, String flag, String applicationFlag) throws Exception {
try (EntityManagerContainer emc = EntityManagerContainerFactory.instance().create()) {
ActionResult<Wo> result = new ActionResult<>();
Business business = new Business(emc);
Application application = business.application().pick(applicationFlag);
if (null == application) {
throw new ApplicationNotExistedException(applicationFlag);
}
QueryStat o = business.queryStat().pick(flag, application);
if (null == o) {
throw new QueryStatNotExistedException(flag, applicationFlag);
}
if (!business.queryStat().allowRead(effectivePerson, o, application)) {
throw new QueryStatAccessDeniedException(effectivePerson.getDistinguishedName(), flag, applicationFlag);
}
Wo wo = Wo.copier.copy(o);
result.setData(wo);
return result;
}
}
public static class Wo extends QueryStat {
private static final long serialVersionUID = 2886873983211744188L;
static WrapCopier<QueryStat, Wo> copier = WrapCopierFactory.wo(QueryStat.class, Wo.class, null,
JpaObject.FieldsInvisible);
}
}
\ No newline at end of file
package com.x.processplatform.assemble.surface.jaxrs.querystat;
import java.util.ArrayList;
import java.util.List;
import javax.persistence.EntityManager;
import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.CriteriaQuery;
import javax.persistence.criteria.Predicate;
import javax.persistence.criteria.Root;
import com.x.base.core.container.EntityManagerContainer;
import com.x.base.core.container.factory.EntityManagerContainerFactory;
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.organization.OrganizationDefinition;
import com.x.base.core.project.tools.SortTools;
import com.x.processplatform.assemble.surface.Business;
import com.x.processplatform.assemble.surface.wrapout.element.WrapOutQueryStat;
import com.x.processplatform.core.entity.element.Application;
import com.x.processplatform.core.entity.element.QueryStat;
import com.x.processplatform.core.entity.element.QueryStat_;
class ActionList extends BaseAction {
private static Logger logger = LoggerFactory.getLogger(ActionList.class);
ActionResult<List<WrapOutQueryStat>> execute(EffectivePerson effectivePerson, String applicationFlag)
throws Exception {
try (EntityManagerContainer emc = EntityManagerContainerFactory.instance().create()) {
Business business = new Business(emc);
Application application = business.application().pick(applicationFlag);
if (null == application) {
throw new ApplicationNotExistedException(applicationFlag);
}
ActionResult<List<WrapOutQueryStat>> result = new ActionResult<>();
List<WrapOutQueryStat> wraps = new ArrayList<>();
List<String> ids = this.list(business, effectivePerson, application);
List<QueryStat> os = business.entityManagerContainer().list(QueryStat.class, ids);
wraps = outCopier.copy(os);
SortTools.asc(wraps, true, "name");
result.setData(wraps);
return result;
}
}
private List<String> list(Business business, EffectivePerson effectivePerson, Application application)
throws Exception {
EntityManager em = business.entityManagerContainer().get(QueryStat.class);
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<String> cq = cb.createQuery(String.class);
Root<QueryStat> root = cq.from(QueryStat.class);
Predicate p = cb.conjunction();
/* 不是管理员或者流程管理员 */
if (effectivePerson.isNotManager()
&& (!business.organization().person().hasRole(effectivePerson.getDistinguishedName(),
OrganizationDefinition.ProcessPlatformManager, OrganizationDefinition.Manager))
&& effectivePerson.isNotPerson(application.getControllerList())) {
p = cb.equal(root.get(QueryStat_.creatorPerson), effectivePerson.getDistinguishedName());
p = cb.or(p, root.get(QueryStat_.controllerList).in(effectivePerson.getDistinguishedName()));
p = cb.or(p,
cb.and(cb.isEmpty(root.get(QueryStat_.availablePersonList)),
cb.isEmpty(root.get(QueryStat_.availableUnitList)),
cb.isEmpty(root.get(QueryStat_.availableIdentityList))));
p = cb.or(p, cb.isMember(effectivePerson.getDistinguishedName(), root.get(QueryStat_.availablePersonList)));
p = cb.or(p, root.get(QueryStat_.availableUnitList)
.in(business.organization().unit().listWithPersonSupNested(effectivePerson)));
p = cb.or(p, root.get(QueryStat_.availableIdentityList)
.in(business.organization().identity().listWithPerson(effectivePerson)));
}
p = cb.and(p, cb.equal(root.get(QueryStat_.application), application.getId()));
cq.select(root.get(QueryStat_.id)).where(p).distinct(true);
List<String> list = em.createQuery(cq).getResultList();
return list;
}
}
\ No newline at end of file
package com.x.processplatform.assemble.surface.jaxrs.querystat;
import com.x.base.core.project.exception.PromptException;
class ApplicationNotExistedException extends PromptException {
private static final long serialVersionUID = 5092496738469805434L;
ApplicationNotExistedException(String flag) {
super("application:{} not existed.", flag);
}
}
package com.x.processplatform.assemble.surface.jaxrs.querystat;
import com.x.base.core.project.bean.WrapCopier;
import com.x.base.core.project.bean.WrapCopierFactory;
import com.x.base.core.project.jaxrs.StandardJaxrsAction;
import com.x.processplatform.assemble.surface.wrapout.element.WrapOutQueryStat;
import com.x.processplatform.core.entity.element.QueryStat;
abstract class BaseAction extends StandardJaxrsAction {
static WrapCopier<QueryStat, WrapOutQueryStat> outCopier = WrapCopierFactory.wo(QueryStat.class,
WrapOutQueryStat.class, null, WrapOutQueryStat.Excludes);
}
\ No newline at end of file
package com.x.processplatform.assemble.surface.jaxrs.querystat;
import com.x.base.core.project.exception.PromptException;
class QueryStatAccessDeniedException extends PromptException {
private static final long serialVersionUID = 5192798633373774203L;
QueryStatAccessDeniedException(String person, String queryStat, String application) {
super("person:{} access queryStat :{}, denied, in application: {}.", person, queryStat, application);
}
}
package com.x.processplatform.assemble.surface.jaxrs.querystat;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import javax.ws.rs.Consumes;
import javax.ws.rs.GET;
import javax.ws.rs.PUT;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
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 javax.ws.rs.core.Response;
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 com.x.processplatform.assemble.surface.wrapout.element.WrapOutQueryStat;
import com.x.processplatform.core.entity.query.Query;
@Path("querystat")
@JaxrsDescribe("统计操作")
public class QueryStatAction extends StandardJaxrsAction {
private static Logger logger = LoggerFactory.getLogger(QueryStatAction.class);
//@HttpMethodDescribe(value = "列示所有当前用户可见的QueryStat.", response = WrapOutQueryStat.class)
@GET
@Path("list/application/flag/{applicationFlag}")
@Produces(HttpMediaType.APPLICATION_JSON_UTF_8)
@Consumes(MediaType.APPLICATION_JSON)
public void list(@Suspended final AsyncResponse asyncResponse, @Context HttpServletRequest request, @PathParam("applicationFlag") String applicationFlag) {
ActionResult<List<WrapOutQueryStat>> result = new ActionResult<>();
EffectivePerson effectivePerson = this.effectivePerson(request);
try {
result = new ActionList().execute(effectivePerson, applicationFlag);
} catch (Exception e) {
logger.error(e, effectivePerson, request, null);
result.error(e);
}
asyncResponse.resume(ResponseFactory.getDefaultActionResultResponse(result));
}
@JaxrsMethodDescribe(value = "获取指定的QueryStat.", action = ActionFlag.class)
@GET
@Path("flag/{flag}/application/flag/{applicationFlag}")
@Produces(HttpMediaType.APPLICATION_JSON_UTF_8)
@Consumes(MediaType.APPLICATION_JSON)
public void flag(@Suspended final AsyncResponse asyncResponse, @Context HttpServletRequest request, @PathParam("flag") String flag,
@PathParam("applicationFlag") String applicationFlag) {
ActionResult<ActionFlag.Wo> result = new ActionResult<>();
EffectivePerson effectivePerson = this.effectivePerson(request);
try {
result = new ActionFlag().execute(effectivePerson, flag, applicationFlag);
} catch (Exception e) {
logger.error(e, effectivePerson, request, null);
result.error(e);
}
asyncResponse.resume(ResponseFactory.getDefaultActionResultResponse(result));
}
//@HttpMethodDescribe(value = "执行QueryView查询.", response = Query.class)
@PUT
@Path("flag/{flag}/application/flag/{applicationFlag}/execute")
@Produces(HttpMediaType.APPLICATION_JSON_UTF_8)
@Consumes(MediaType.APPLICATION_JSON)
public void execute(@Suspended final AsyncResponse asyncResponse, @Context HttpServletRequest request, @PathParam("flag") String flag,
@PathParam("applicationFlag") String applicationFlag, JsonElement jsonElement) {
ActionResult<Query> result = new ActionResult<>();
EffectivePerson effectivePerson = this.effectivePerson(request);
try {
result = new ActionExecute().execute(effectivePerson, flag, applicationFlag, jsonElement);
} catch (Exception e) {
logger.error(e, effectivePerson, request, jsonElement);
result.error(e);
}
asyncResponse.resume(ResponseFactory.getDefaultActionResultResponse(result));
}
}
\ No newline at end of file
package com.x.processplatform.assemble.surface.jaxrs.querystat;
import com.x.base.core.project.exception.PromptException;
class QueryStatNotExistedException extends PromptException {
private static final long serialVersionUID = -4720230175081531553L;
QueryStatNotExistedException(String flag, String applicationFlag) {
super("queryStat :{}, not existed in application: {}.", flag, applicationFlag);
}
}
package com.x.processplatform.assemble.surface.jaxrs.querystat;
import com.x.base.core.project.exception.PromptException;
class QueryViewAccessDeniedException extends PromptException {
private static final long serialVersionUID = -3643751916412139045L;
QueryViewAccessDeniedException(String person, String queryView, String application) {
super("person:{} access queryView :{}, denied, in application: {}.", person, queryView, application);
}
}
package com.x.processplatform.assemble.surface.jaxrs.querystat;
import com.x.base.core.project.exception.PromptException;
class QueryViewNotExistedException extends PromptException {
private static final long serialVersionUID = 1633835400422042028L;
QueryViewNotExistedException(String flag, String applicationFlag) {
super("queryView: {}, not existed in application: {}.", flag, applicationFlag);
}
}
package com.x.processplatform.assemble.surface.jaxrs.queryview;
import java.io.ByteArrayOutputStream;
import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.List;
import java.util.Map.Entry;
import java.util.Objects;
import org.apache.commons.lang3.StringUtils;
import org.apache.poi.xssf.usermodel.XSSFCell;
import org.apache.poi.xssf.usermodel.XSSFRow;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import com.google.gson.Gson;
import com.google.gson.JsonElement;
import com.google.gson.reflect.TypeToken;
import com.x.base.core.container.EntityManagerContainer;
import com.x.base.core.container.factory.EntityManagerContainerFactory;
import com.x.base.core.project.bean.NameIdPair;
import com.x.base.core.project.cache.ApplicationCache;
import com.x.base.core.project.exception.ExceptionWhen;
import com.x.base.core.project.gson.GsonPropertyObject;
import com.x.base.core.project.gson.XGsonBuilder;
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.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.StringTools;
import com.x.processplatform.assemble.surface.Business;
import com.x.processplatform.core.entity.element.Application;
import com.x.processplatform.core.entity.element.QueryView;
import com.x.processplatform.core.entity.query.DateRangeEntry;
import com.x.processplatform.core.entity.query.FilterEntry;
import com.x.processplatform.core.entity.query.Query;
import com.x.processplatform.core.entity.query.Row;
import com.x.processplatform.core.entity.query.SelectEntry;
import com.x.processplatform.core.entity.query.WhereEntry;
import net.sf.ehcache.Ehcache;
import net.sf.ehcache.Element;
class ActionExcel extends BaseAction {
private static Logger logger = LoggerFactory.getLogger(ActionExcel.class);
private static Type filterEntryCollectionType = new TypeToken<List<FilterEntry>>() {
}.getType();
private static Type stringCollectionType = new TypeToken<List<String>>() {
}.getType();
private Gson gson = XGsonBuilder.instance();
ActionResult<Wo> execute(EffectivePerson effectivePerson, String flag, String applicationFlag,
JsonElement jsonElement) throws Exception {
try (EntityManagerContainer emc = EntityManagerContainerFactory.instance().create();
XSSFWorkbook workbook = new XSSFWorkbook();
ByteArrayOutputStream os = new ByteArrayOutputStream()) {
Ehcache cache = ApplicationCache.instance().getCache(QueryView.class);
ActionResult<Wo> result = new ActionResult<>();
Wi wi = this.convertToWrapIn(jsonElement, Wi.class);
Business business = new Business(emc);
Application application = business.application().pick(applicationFlag);
QueryView queryView = business.queryView().pick(flag, application, ExceptionWhen.not_found);
if (!business.queryView().allowRead(effectivePerson, queryView, application)) {
throw new Exception("insufficient permissions.");
}
Query query = this.concrete(queryView, wi);
query.query();
/* 整理一下输出值 */
if ((null != query.getGroupEntry()) && query.getGroupEntry().available()) {
query.setGrid(null);
}
if ((null != query.getCalculate()) && (query.getCalculate().available())) {
query.setGrid(null);
query.setGroupGrid(null);
}
XSSFSheet sheet = workbook.createSheet("grid");
if (ListTools.isNotEmpty(query.getSelectEntryList())) {
XSSFRow r = sheet.createRow(0);
XSSFCell c = null;
int i = 0;
for (SelectEntry o : query.getSelectEntryList()) {
c = r.createCell(i);
c.setCellValue(o.getDisplayName());
i++;
}
}
if (null != query.getGrid() && (!query.getGrid().isEmpty())) {
Row row = null;
XSSFRow r = null;
XSSFCell c = null;
int i = 0;
for (int j = 0; j < query.getGrid().size(); j++) {
row = query.getGrid().get(j);
r = sheet.createRow(j + 1);
i = 0;
for (Entry<String, Object> entry : row.getData().entrySet()) {
c = r.createCell(i);
c.setCellValue(Objects.toString(entry.getValue(), ""));
i++;
}
}
}
String name = queryView.getName() + ".xlsx";
workbook.write(os);
ExcelResultObject obj = new ExcelResultObject();
obj.setBytes(os.toByteArray());
obj.setName(name);
obj.setPerson(effectivePerson.getDistinguishedName());
String id = StringTools.uniqueToken();
cache.put(new Element(id, obj));
Wo wo = new Wo();
wo.setId(id);
result.setData(wo);
return result;
}
}
public static class Wo extends WoId {
}
public static class Wi extends GsonPropertyObject {
private DateRangeEntry date;
private JsonElement filter;
private JsonElement column;
private JsonElement application;
private JsonElement process;
private JsonElement unit;
private JsonElement person;
private JsonElement identity;
public DateRangeEntry getDate() {
return date;
}
public void setDate(DateRangeEntry date) {
this.date = date;
}
public JsonElement getFilter() {
return filter;
}
public void setFilter(JsonElement filter) {
this.filter = filter;
}
public JsonElement getColumn() {
return column;
}
public void setColumn(JsonElement column) {
this.column = column;
}
public JsonElement getApplication() {
return application;
}
public void setApplication(JsonElement application) {
this.application = application;
}
public JsonElement getProcess() {
return process;
}
public void setProcess(JsonElement process) {
this.process = process;
}
public JsonElement getPerson() {
return person;
}
public void setPerson(JsonElement person) {
this.person = person;
}
public JsonElement getIdentity() {
return identity;
}
public void setIdentity(JsonElement identity) {
this.identity = identity;
}
public JsonElement getUnit() {
return unit;
}
public void setUnit(JsonElement unit) {
this.unit = unit;
}
}
private Query concrete(QueryView queryView, Wi wi) throws Exception {
Query query = gson.fromJson(queryView.getData(), Query.class);
if (null != wi) {
if (null != wi.getDate()) {
query.setDateRangeEntry(this.readDateRangeEntry(wi.getDate()));
}
if ((null != wi.getFilter()) && (!wi.getFilter().isJsonNull())) {
query.setFilterEntryList(this.readFilterEntryList(wi.getFilter()));
}
if ((null != wi.getColumn()) && (!wi.getColumn().isJsonNull())) {
query.setColumnList(this.readColumnList(wi.getColumn(), query.getSelectEntryList()));
}
WhereEntry whereEntry = this.readWhereEntry(wi.getApplication(), wi.getProcess(), wi.getUnit(),
wi.getPerson(), wi.getIdentity());
if (whereEntry.available()) {
query.setWhereEntry(whereEntry);
}
}
return query;
}
private WhereEntry readWhereEntry(JsonElement application, JsonElement process, JsonElement unit,
JsonElement person, JsonElement identity) throws Exception {
WhereEntry whereEntry = new WhereEntry();
if (null != application && (!application.isJsonNull())) {
whereEntry.setApplicationList(this.readApplication(application));
}
if (null != process && (!process.isJsonNull())) {
whereEntry.setProcessList(this.readProcess(process));
}
if (null != unit && (!unit.isJsonNull())) {
whereEntry.setUnitList(this.readUnit(unit));
}
if (null != person && (!person.isJsonNull())) {
whereEntry.setPersonList(this.readPerson(person));
}
if (null != identity && (!identity.isJsonNull())) {
whereEntry.setIdentityList(this.readIdentity(identity));
}
return whereEntry;
}
private List<NameIdPair> readApplication(JsonElement o) throws Exception {
List<NameIdPair> results = new ArrayList<>();
List<String> flags = new ArrayList<>();
if (o.isJsonArray()) {
flags = XGsonBuilder.instance().fromJson(o, stringCollectionType);
} else if (o.isJsonPrimitive() && o.getAsJsonPrimitive().isString()) {
flags.add(o.getAsJsonPrimitive().getAsString());
}
for (String str : flags) {
NameIdPair p = new NameIdPair(str, str);
results.add(p);
}
return results;
}
private List<NameIdPair> readProcess(JsonElement o) throws Exception {
List<NameIdPair> results = new ArrayList<>();
List<String> flags = new ArrayList<>();
if (o.isJsonArray()) {
flags = XGsonBuilder.instance().fromJson(o, stringCollectionType);
} else if (o.isJsonPrimitive() && o.getAsJsonPrimitive().isString()) {
flags.add(o.getAsJsonPrimitive().getAsString());
}
for (String str : flags) {
NameIdPair p = new NameIdPair(str, str);
results.add(p);
}
return results;
}
private List<NameIdPair> readUnit(JsonElement o) throws Exception {
List<NameIdPair> results = new ArrayList<>();
List<String> flags = new ArrayList<>();
if (o.isJsonArray()) {
flags = XGsonBuilder.instance().fromJson(o, stringCollectionType);
} else if (o.isJsonPrimitive() && o.getAsJsonPrimitive().isString()) {
flags.add(o.getAsJsonPrimitive().getAsString());
}
for (String str : flags) {
NameIdPair p = new NameIdPair(str, str);
results.add(p);
}
return results;
}
private List<NameIdPair> readIdentity(JsonElement o) throws Exception {
List<NameIdPair> results = new ArrayList<>();
List<String> flags = new ArrayList<>();
if (o.isJsonArray()) {
flags = XGsonBuilder.instance().fromJson(o, stringCollectionType);
} else if (o.isJsonPrimitive() && o.getAsJsonPrimitive().isString()) {
flags.add(o.getAsJsonPrimitive().getAsString());
}
for (String str : flags) {
NameIdPair p = new NameIdPair(str, str);
results.add(p);
}
return results;
}
private List<NameIdPair> readPerson(JsonElement o) throws Exception {
List<NameIdPair> results = new ArrayList<>();
List<String> flags = new ArrayList<>();
if (o.isJsonArray()) {
flags = XGsonBuilder.instance().fromJson(o, stringCollectionType);
} else if (o.isJsonPrimitive() && o.getAsJsonPrimitive().isString()) {
flags.add(o.getAsJsonPrimitive().getAsString());
}
for (String str : flags) {
NameIdPair p = new NameIdPair(str, str);
results.add(p);
}
return results;
}
private DateRangeEntry readDateRangeEntry(DateRangeEntry o) throws Exception {
if (!o.available()) {
throw new Exception("dateRangeEntry not available:" + o);
}
return o;
}
private List<FilterEntry> readFilterEntryList(JsonElement o) throws Exception {
List<FilterEntry> list = new ArrayList<>();
if (o.isJsonArray()) {
list = XGsonBuilder.instance().fromJson(o, filterEntryCollectionType);
} else if (o.isJsonObject()) {
list.add(XGsonBuilder.instance().fromJson(o, FilterEntry.class));
}
for (FilterEntry entry : list) {
if (!entry.available()) {
throw new Exception("filterEntry not available:" + entry);
}
}
return list;
}
private List<String> readColumnList(JsonElement o, List<SelectEntry> selectEntryList) throws Exception {
List<String> columns = new ArrayList<>();
if (o.isJsonArray()) {
/* 多值 */
for (JsonElement element : o.getAsJsonArray()) {
String column = this.getColumn(element, selectEntryList);
if (StringUtils.isNotEmpty(column)) {
columns.add(column);
}
}
} else if (o.isJsonPrimitive()) {
/* 单值 */
String column = this.getColumn(o, selectEntryList);
if (StringUtils.isNotEmpty(column)) {
columns.add(column);
}
}
return columns;
}
private String getColumn(JsonElement o, List<SelectEntry> list) throws Exception {
if (null == o || o.isJsonNull() || (!o.isJsonPrimitive()) || ListTools.isEmpty(list)) {
return null;
}
if (o.getAsJsonPrimitive().isNumber()) {
Integer idx = o.getAsJsonPrimitive().getAsInt();
if ((idx >= 1) && (idx <= (list.size() + 1))) {
return list.get(idx - 1).getColumn();
}
} else if (o.getAsJsonPrimitive().isString()) {
String str = o.getAsJsonPrimitive().getAsString();
for (SelectEntry entry : list) {
if (StringUtils.equals(entry.getColumn(), str)) {
return entry.getColumn();
}
}
}
return null;
}
}
\ No newline at end of file
package com.x.processplatform.assemble.surface.jaxrs.queryview;
import org.apache.commons.lang3.StringUtils;
import com.x.base.core.project.cache.ApplicationCache;
import com.x.base.core.project.http.ActionResult;
import com.x.base.core.project.http.EffectivePerson;
import com.x.base.core.project.jaxrs.WoFile;
import com.x.base.core.project.logger.Logger;
import com.x.base.core.project.logger.LoggerFactory;
import com.x.processplatform.core.entity.element.QueryView;
import net.sf.ehcache.Ehcache;
import net.sf.ehcache.Element;
class ActionExcelResult extends BaseAction {
private static Logger logger = LoggerFactory.getLogger(ActionExcelResult.class);
ActionResult<Wo> execute(EffectivePerson effectivePerson, String flag) throws Exception {
ActionResult<Wo> result = new ActionResult<>();
Ehcache cache = ApplicationCache.instance().getCache(QueryView.class);
String cacheKey = ApplicationCache.concreteCacheKey(flag);
Element element = cache.get(cacheKey);
if (null != element && null != element.getObjectValue()) {
ExcelResultObject obj = (ExcelResultObject) element.getObjectValue();
if (!StringUtils.equals(effectivePerson.getDistinguishedName(), obj.getPerson())) {
throw new ExceptionPersonNotMatch(effectivePerson.getDistinguishedName());
}
Wo wo = new Wo(obj.getBytes(), this.contentType(true, obj.getName()),
this.contentDisposition(true, obj.getName()));
result.setData(wo);
} else {
throw new ExceptionExcelResultObject(flag);
}
return result;
}
public static class Wo extends WoFile {
public Wo(byte[] bytes, String contentType, String contentDisposition) {
super(bytes, contentType, contentDisposition);
}
}
}
\ No newline at end of file
package com.x.processplatform.assemble.surface.jaxrs.queryview;
import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.List;
import org.apache.commons.lang3.StringUtils;
import com.google.gson.Gson;
import com.google.gson.JsonElement;
import com.google.gson.reflect.TypeToken;
import com.x.base.core.container.EntityManagerContainer;
import com.x.base.core.container.factory.EntityManagerContainerFactory;
import com.x.base.core.project.bean.NameIdPair;
import com.x.base.core.project.exception.ExceptionWhen;
import com.x.base.core.project.gson.GsonPropertyObject;
import com.x.base.core.project.gson.XGsonBuilder;
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.processplatform.assemble.surface.Business;
import com.x.processplatform.core.entity.element.Application;
import com.x.processplatform.core.entity.element.QueryView;
import com.x.processplatform.core.entity.query.DateRangeEntry;
import com.x.processplatform.core.entity.query.FilterEntry;
import com.x.processplatform.core.entity.query.Query;
import com.x.processplatform.core.entity.query.SelectEntry;
import com.x.processplatform.core.entity.query.WhereEntry;
class ActionExecute extends BaseAction {
private static Logger logger = LoggerFactory.getLogger(ActionExecute.class);
private static Type filterEntryCollectionType = new TypeToken<List<FilterEntry>>() {
}.getType();
private static Type stringCollectionType = new TypeToken<List<String>>() {
}.getType();
private Gson gson = XGsonBuilder.instance();
ActionResult<Query> execute(EffectivePerson effectivePerson, String flag, String applicationFlag,
JsonElement jsonElement) throws Exception {
try (EntityManagerContainer emc = EntityManagerContainerFactory.instance().create()) {
ActionResult<Query> result = new ActionResult<>();
Wi wi = this.convertToWrapIn(jsonElement, Wi.class);
Business business = new Business(emc);
Application application = business.application().pick(applicationFlag);
QueryView queryView = business.queryView().pick(flag, application);
if (null == queryView) {
throw new ExceptionQueryViewNotExist(flag);
}
if (!business.queryView().allowRead(effectivePerson, queryView, application)) {
throw new Exception("insufficient permissions.");
}
Query query = this.concrete(queryView, wi);
logger.debug(effectivePerson, "query:{}.", query);
query.query();
/* 整理一下输出值 */
if ((null != query.getGroupEntry()) && query.getGroupEntry().available()) {
query.setGrid(null);
}
if ((null != query.getCalculate()) && (query.getCalculate().available())) {
query.setGrid(null);
query.setGroupGrid(null);
}
result.setData(query);
return result;
}
}
public static class Wi extends GsonPropertyObject {
private DateRangeEntry date;
private JsonElement filter;
private JsonElement column;
private JsonElement application;
private JsonElement process;
private JsonElement unit;
private JsonElement person;
private JsonElement identity;
public DateRangeEntry getDate() {
return date;
}
public void setDate(DateRangeEntry date) {
this.date = date;
}
public JsonElement getFilter() {
return filter;
}
public void setFilter(JsonElement filter) {
this.filter = filter;
}
public JsonElement getColumn() {
return column;
}
public void setColumn(JsonElement column) {
this.column = column;
}
public JsonElement getApplication() {
return application;
}
public void setApplication(JsonElement application) {
this.application = application;
}
public JsonElement getProcess() {
return process;
}
public void setProcess(JsonElement process) {
this.process = process;
}
public JsonElement getPerson() {
return person;
}
public void setPerson(JsonElement person) {
this.person = person;
}
public JsonElement getIdentity() {
return identity;
}
public void setIdentity(JsonElement identity) {
this.identity = identity;
}
public JsonElement getUnit() {
return unit;
}
public void setUnit(JsonElement unit) {
this.unit = unit;
}
}
private Query concrete(QueryView queryView, Wi wi) throws Exception {
Query query = gson.fromJson(queryView.getData(), Query.class);
if (null != wi) {
if (null != wi.getDate()) {
query.setDateRangeEntry(this.readDateRangeEntry(wi.getDate()));
}
if ((null != wi.getFilter()) && (!wi.getFilter().isJsonNull())) {
query.setFilterEntryList(this.readFilterEntryList(wi.getFilter()));
}
if ((null != wi.getColumn()) && (!wi.getColumn().isJsonNull())) {
query.setColumnList(this.readColumnList(wi.getColumn(), query.getSelectEntryList()));
}
WhereEntry whereEntry = this.readWhereEntry(wi.getApplication(), wi.getProcess(), wi.getUnit(),
wi.getPerson(), wi.getIdentity());
if (whereEntry.available()) {
query.setWhereEntry(whereEntry);
}
}
return query;
}
private WhereEntry readWhereEntry(JsonElement application, JsonElement process, JsonElement unit,
JsonElement person, JsonElement identity) throws Exception {
WhereEntry whereEntry = new WhereEntry();
if (null != application && (!application.isJsonNull())) {
whereEntry.setApplicationList(this.readApplication(application));
}
if (null != process && (!process.isJsonNull())) {
whereEntry.setProcessList(this.readProcess(process));
}
if (null != unit && (!unit.isJsonNull())) {
whereEntry.setUnitList(this.readUnit(unit));
}
if (null != person && (!person.isJsonNull())) {
whereEntry.setPersonList(this.readPerson(person));
}
if (null != identity && (!identity.isJsonNull())) {
whereEntry.setIdentityList(this.readIdentity(identity));
}
return whereEntry;
}
private List<NameIdPair> readApplication(JsonElement o) throws Exception {
List<NameIdPair> results = new ArrayList<>();
List<String> flags = new ArrayList<>();
if (o.isJsonArray()) {
flags = XGsonBuilder.instance().fromJson(o, stringCollectionType);
} else if (o.isJsonPrimitive() && o.getAsJsonPrimitive().isString()) {
flags.add(o.getAsJsonPrimitive().getAsString());
}
for (String str : flags) {
NameIdPair p = new NameIdPair(str, str);
results.add(p);
}
return results;
}
private List<NameIdPair> readProcess(JsonElement o) throws Exception {
List<NameIdPair> results = new ArrayList<>();
List<String> flags = new ArrayList<>();
if (o.isJsonArray()) {
flags = XGsonBuilder.instance().fromJson(o, stringCollectionType);
} else if (o.isJsonPrimitive() && o.getAsJsonPrimitive().isString()) {
flags.add(o.getAsJsonPrimitive().getAsString());
}
for (String str : flags) {
NameIdPair p = new NameIdPair(str, str);
results.add(p);
}
return results;
}
private List<NameIdPair> readUnit(JsonElement o) throws Exception {
List<NameIdPair> results = new ArrayList<>();
List<String> flags = new ArrayList<>();
if (o.isJsonArray()) {
flags = XGsonBuilder.instance().fromJson(o, stringCollectionType);
} else if (o.isJsonPrimitive() && o.getAsJsonPrimitive().isString()) {
flags.add(o.getAsJsonPrimitive().getAsString());
}
for (String str : flags) {
NameIdPair p = new NameIdPair(str, str);
results.add(p);
}
return results;
}
private List<NameIdPair> readIdentity(JsonElement o) throws Exception {
List<NameIdPair> results = new ArrayList<>();
List<String> flags = new ArrayList<>();
if (o.isJsonArray()) {
flags = XGsonBuilder.instance().fromJson(o, stringCollectionType);
} else if (o.isJsonPrimitive() && o.getAsJsonPrimitive().isString()) {
flags.add(o.getAsJsonPrimitive().getAsString());
}
for (String str : flags) {
NameIdPair p = new NameIdPair(str, str);
results.add(p);
}
return results;
}
private List<NameIdPair> readPerson(JsonElement o) throws Exception {
List<NameIdPair> results = new ArrayList<>();
List<String> flags = new ArrayList<>();
if (o.isJsonArray()) {
flags = XGsonBuilder.instance().fromJson(o, stringCollectionType);
} else if (o.isJsonPrimitive() && o.getAsJsonPrimitive().isString()) {
flags.add(o.getAsJsonPrimitive().getAsString());
}
for (String str : flags) {
NameIdPair p = new NameIdPair(str, str);
results.add(p);
}
return results;
}
private DateRangeEntry readDateRangeEntry(DateRangeEntry o) throws Exception {
if (!o.available()) {
throw new Exception("dateRangeEntry not available:" + o);
}
return o;
}
private List<FilterEntry> readFilterEntryList(JsonElement o) throws Exception {
List<FilterEntry> list = new ArrayList<>();
if (o.isJsonArray()) {
list = XGsonBuilder.instance().fromJson(o, filterEntryCollectionType);
} else if (o.isJsonObject()) {
list.add(XGsonBuilder.instance().fromJson(o, FilterEntry.class));
}
for (FilterEntry entry : list) {
if (!entry.available()) {
throw new Exception("filterEntry not available:" + entry);
}
}
return list;
}
private List<String> readColumnList(JsonElement o, List<SelectEntry> selectEntryList) throws Exception {
List<String> columns = new ArrayList<>();
if (o.isJsonArray()) {
/* 多值 */
for (JsonElement element : o.getAsJsonArray()) {
String column = this.getColumn(element, selectEntryList);
if (StringUtils.isNotEmpty(column)) {
columns.add(column);
}
}
} else if (o.isJsonPrimitive()) {
/* 单值 */
String column = this.getColumn(o, selectEntryList);
if (StringUtils.isNotEmpty(column)) {
columns.add(column);
}
}
return columns;
}
private String getColumn(JsonElement o, List<SelectEntry> list) throws Exception {
if (null == o || o.isJsonNull() || (!o.isJsonPrimitive()) || ListTools.isEmpty(list)) {
return null;
}
if (o.getAsJsonPrimitive().isNumber()) {
Integer idx = o.getAsJsonPrimitive().getAsInt();
if ((idx >= 1) && (idx <= (list.size() + 1))) {
return list.get(idx - 1).getColumn();
}
} else if (o.getAsJsonPrimitive().isString()) {
String str = o.getAsJsonPrimitive().getAsString();
for (SelectEntry entry : list) {
if (StringUtils.equals(entry.getColumn(), str)) {
return entry.getColumn();
}
}
}
return null;
}
}
\ No newline at end of file
package com.x.processplatform.assemble.surface.jaxrs.queryview;
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.project.bean.WrapCopier;
import com.x.base.core.project.bean.WrapCopierFactory;
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.processplatform.assemble.surface.Business;
import com.x.processplatform.core.entity.element.Application;
import com.x.processplatform.core.entity.element.QueryView;
class ActionFlag extends BaseAction {
private static Logger logger = LoggerFactory.getLogger(ActionExecute.class);
ActionResult<Wo> execute(EffectivePerson effectivePerson, String flag, String applicationFlag) throws Exception {
try (EntityManagerContainer emc = EntityManagerContainerFactory.instance().create()) {
ActionResult<Wo> result = new ActionResult<>();
Business business = new Business(emc);
Application application = business.application().pick(applicationFlag);
if (null == application) {
throw new ExceptionApplicationNotExist(applicationFlag);
}
QueryView o = business.queryView().pick(flag, application);
if (null == o) {
throw new ExceptionQueryViewNotExist(flag);
}
if (!business.queryView().allowRead(effectivePerson, o, application)) {
throw new Exception("insufficient permissions");
}
Wo wo = Wo.copier.copy(o);
result.setData(wo);
return result;
}
}
public static class Wo extends QueryView {
private static final long serialVersionUID = 2886873983211744188L;
public static WrapCopier<QueryView, Wo> copier = WrapCopierFactory.wo(QueryView.class, Wo.class, null,
JpaObject.FieldsInvisible);
}
}
\ No newline at end of file
package com.x.processplatform.assemble.surface.jaxrs.queryview;
import java.util.ArrayList;
import java.util.List;
import javax.persistence.EntityManager;
import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.CriteriaQuery;
import javax.persistence.criteria.Predicate;
import javax.persistence.criteria.Root;
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.project.bean.WrapCopier;
import com.x.base.core.project.bean.WrapCopierFactory;
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.organization.OrganizationDefinition;
import com.x.base.core.project.tools.SortTools;
import com.x.processplatform.assemble.surface.Business;
import com.x.processplatform.core.entity.element.Application;
import com.x.processplatform.core.entity.element.QueryView;
import com.x.processplatform.core.entity.element.QueryView_;
class ActionList extends BaseAction {
private static Logger logger = LoggerFactory.getLogger(ActionExecute.class);
ActionResult<List<Wo>> execute(EffectivePerson effectivePerson, String applicationFlag) throws Exception {
try (EntityManagerContainer emc = EntityManagerContainerFactory.instance().create()) {
Business business = new Business(emc);
Application application = business.application().pick(applicationFlag);
if (null == application) {
throw new ExceptionApplicationNotExist(applicationFlag);
}
ActionResult<List<Wo>> result = new ActionResult<>();
List<Wo> wraps = new ArrayList<>();
List<String> ids = this.list(business, effectivePerson, application);
List<QueryView> os = business.entityManagerContainer().list(QueryView.class, ids);
wraps = Wo.copier.copy(os);
SortTools.asc(wraps, true, "name");
result.setData(wraps);
return result;
}
}
public static class Wo extends QueryView {
private static final long serialVersionUID = 2886873983211744188L;
public static List<String> Excludes = new ArrayList<>(JpaObject.FieldsInvisible);
static WrapCopier<QueryView, Wo> copier = WrapCopierFactory.wo(QueryView.class, Wo.class, null, Wo.Excludes);
}
private List<String> list(Business business, EffectivePerson effectivePerson, Application application)
throws Exception {
EntityManager em = business.entityManagerContainer().get(QueryView.class);
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<String> cq = cb.createQuery(String.class);
Root<QueryView> root = cq.from(QueryView.class);
Predicate p = cb.conjunction();
/* 不是管理员或者流程管理员 */
if (effectivePerson.isNotManager()
&& (!business.organization().person().hasRole(effectivePerson,
OrganizationDefinition.ProcessPlatformManager, OrganizationDefinition.Manager))
&& effectivePerson.isNotPerson(application.getControllerList())) {
p = cb.equal(root.get(QueryView_.creatorPerson), effectivePerson.getDistinguishedName());
p = cb.or(p, root.get(QueryView_.controllerList).in(effectivePerson.getDistinguishedName()));
p = cb.or(p,
cb.and(cb.isEmpty(root.get(QueryView_.availablePersonList)),
cb.isEmpty(root.get(QueryView_.availableUnitList)),
cb.isEmpty(root.get(QueryView_.availableIdentityList))));
p = cb.or(p, cb.isMember(effectivePerson.getDistinguishedName(), root.get(QueryView_.availablePersonList)));
p = cb.or(p, root.get(QueryView_.availableUnitList)
.in(business.organization().unit().listWithPersonSupNested(effectivePerson)));
p = cb.or(p, root.get(QueryView_.availableIdentityList)
.in(business.organization().identity().listWithPerson(effectivePerson.getDistinguishedName())));
}
p = cb.and(p, cb.equal(root.get(QueryView_.application), application.getId()));
p = cb.and(p, cb.notEqual(root.get(QueryView_.display), false));
cq.select(root.get(QueryView_.id)).where(p).distinct(true);
List<String> list = em.createQuery(cq).getResultList();
return list;
}
}
\ No newline at end of file
package com.x.processplatform.assemble.surface.jaxrs.queryview;
import com.x.base.core.project.jaxrs.StandardJaxrsAction;
abstract class BaseAction extends StandardJaxrsAction {
public static class ExcelResultObject {
private byte[] bytes;
private String person;
private String name;
public byte[] getBytes() {
return bytes;
}
public void setBytes(byte[] bytes) {
this.bytes = bytes;
}
public String getPerson() {
return person;
}
public void setPerson(String person) {
this.person = person;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
}
\ No newline at end of file
package com.x.processplatform.assemble.surface.jaxrs.queryview;
import com.x.base.core.project.exception.PromptException;
class ExceptionApplicationNotExist extends PromptException {
private static final long serialVersionUID = -4908883340253465376L;
ExceptionApplicationNotExist(String flag) {
super("指定的应用不存在:{}.", flag);
}
}
package com.x.processplatform.assemble.surface.jaxrs.queryview;
import com.x.base.core.project.exception.PromptException;
class ExceptionExcelResultObject extends PromptException {
private static final long serialVersionUID = -4908883340253465376L;
ExceptionExcelResultObject(String flag) {
super("指定的Excel结果不存在:{}.", flag);
}
}
package com.x.processplatform.assemble.surface.jaxrs.queryview;
import com.x.base.core.project.exception.PromptException;
class ExceptionPersonNotMatch extends PromptException {
private static final long serialVersionUID = -4908883340253465376L;
ExceptionPersonNotMatch(String flag) {
super("用户不匹配:{}.", flag);
}
}
package com.x.processplatform.assemble.surface.jaxrs.queryview;
import com.x.base.core.project.exception.PromptException;
class ExceptionQueryViewNotExist extends PromptException {
private static final long serialVersionUID = -4908883340253465376L;
ExceptionQueryViewNotExist(String flag) {
super("指定的应用不存在:{}.", flag);
}
}
package com.x.processplatform.assemble.surface.jaxrs.queryview;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import javax.ws.rs.Consumes;
import javax.ws.rs.GET;
import javax.ws.rs.PUT;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
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 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.annotation.JaxrsParameterDescribe;
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 com.x.processplatform.core.entity.query.Query;
@Path("queryview")
@JaxrsDescribe("视图操作")
public class QueryViewAction extends StandardJaxrsAction {
private static Logger logger = LoggerFactory.getLogger(QueryViewAction.class);
@JaxrsMethodDescribe(value = "列示所有当前用户可见的QueryView而且display=true的.", action = ActionList.class)
@GET
@Path("list/application/flag/{applicationFlag}")
@Produces(HttpMediaType.APPLICATION_JSON_UTF_8)
@Consumes(MediaType.APPLICATION_JSON)
public void list(@Suspended final AsyncResponse asyncResponse, @Context HttpServletRequest request,
@PathParam("applicationFlag") String applicationFlag) {
ActionResult<List<ActionList.Wo>> result = new ActionResult<>();
EffectivePerson effectivePerson = this.effectivePerson(request);
try {
result = new ActionList().execute(effectivePerson, applicationFlag);
} catch (Exception e) {
logger.error(e, effectivePerson, request, null);
result.error(e);
}
asyncResponse.resume(ResponseFactory.getDefaultActionResultResponse(result));
}
@JaxrsMethodDescribe(value = "获取指定的QueryView.", action = ActionFlag.class)
@GET
@Path("flag/{flag}/application/flag/{applicationFlag}")
@Produces(HttpMediaType.APPLICATION_JSON_UTF_8)
@Consumes(MediaType.APPLICATION_JSON)
public void flag(@Suspended final AsyncResponse asyncResponse, @Context HttpServletRequest request,
@JaxrsParameterDescribe("视图标识") @PathParam("flag") String flag,
@JaxrsParameterDescribe("应用标识") @PathParam("applicationFlag") String applicationFlag) {
ActionResult<ActionFlag.Wo> result = new ActionResult<>();
EffectivePerson effectivePerson = this.effectivePerson(request);
try {
result = new ActionFlag().execute(effectivePerson, flag, applicationFlag);
} catch (Exception e) {
logger.error(e, effectivePerson, request, null);
result.error(e);
}
asyncResponse.resume(ResponseFactory.getDefaultActionResultResponse(result));
}
@JaxrsMethodDescribe(value = "执行QueryView查询.", action = ActionExecute.class)
@PUT
@Path("flag/{flag}/application/flag/{applicationFlag}/execute")
@Produces(HttpMediaType.APPLICATION_JSON_UTF_8)
@Consumes(MediaType.APPLICATION_JSON)
public void execute(@Suspended final AsyncResponse asyncResponse, @Context HttpServletRequest request,
@JaxrsParameterDescribe("视图标识") @PathParam("flag") String flag,
@JaxrsParameterDescribe("应用标识") @PathParam("applicationFlag") String applicationFlag,
JsonElement jsonElement) {
ActionResult<Query> result = new ActionResult<>();
EffectivePerson effectivePerson = this.effectivePerson(request);
try {
result = new ActionExecute().execute(effectivePerson, flag, applicationFlag, jsonElement);
} catch (Exception e) {
logger.error(e, effectivePerson, request, jsonElement);
result.error(e);
}
asyncResponse.resume(ResponseFactory.getDefaultActionResultResponse(result));
}
@JaxrsMethodDescribe(value = "导出Excel的Query执行结果,PUT方法,可以添加附加Query参数", action = ActionExcel.class)
@PUT
@Path("flag/{flag}/application/flag/{applicationFlag}/excel")
@Produces(HttpMediaType.APPLICATION_JSON_UTF_8)
@Consumes(MediaType.APPLICATION_JSON)
public void excel(@Suspended final AsyncResponse asyncResponse, @Context HttpServletRequest request,
@JaxrsParameterDescribe("视图标识") @PathParam("flag") String flag,
@JaxrsParameterDescribe("应用标识") @PathParam("applicationFlag") String applicationFlag,
JsonElement jsonElement) {
ActionResult<ActionExcel.Wo> result = new ActionResult<>();
EffectivePerson effectivePerson = this.effectivePerson(request);
try {
result = new ActionExcel().execute(effectivePerson, flag, applicationFlag, jsonElement);
} catch (Exception e) {
logger.error(e, effectivePerson, request, jsonElement);
result.error(e);
}
asyncResponse.resume(ResponseFactory.getDefaultActionResultResponse(result));
}
@JaxrsMethodDescribe(value = "导出Excel的Query执行结果,Get方法,不添加附加Query参数.", action = ActionExcelResult.class)
@GET
@Path("excel/result/{flag}")
@Consumes(MediaType.APPLICATION_JSON)
public void excelResult(@Suspended final AsyncResponse asyncResponse, @Context HttpServletRequest request,
@JaxrsParameterDescribe("对象标识") @PathParam("flag") String flag) {
ActionResult<ActionExcelResult.Wo> result = new ActionResult<>();
EffectivePerson effectivePerson = this.effectivePerson(request);
try {
result = new ActionExcelResult().execute(effectivePerson, flag);
} catch (Exception e) {
logger.error(e, effectivePerson, request, null);
result.error(e);
}
asyncResponse.resume(ResponseFactory.getDefaultActionResultResponse(result));
}
}
\ No newline at end of file
package com.x.processplatform.assemble.surface.wrapin.element;
import com.google.gson.JsonElement;
import com.x.processplatform.core.entity.element.ApplicationDict;
public class WrapInApplicationDict extends ApplicationDict {
private static final long serialVersionUID = 6419951244780354684L;
private JsonElement data;
public JsonElement getData() {
return data;
}
public void setData(JsonElement data) {
this.data = data;
}
}
package com.x.processplatform.assemble.surface.wrapin.element;
import com.google.gson.JsonElement;
import com.x.base.core.project.gson.GsonPropertyObject;
import com.x.processplatform.core.entity.query.DateRangeEntry;
public class WrapInQueryExecute extends GsonPropertyObject {
private DateRangeEntry date;
private JsonElement filter;
private JsonElement column;
private JsonElement application;
private JsonElement process;
private JsonElement company;
private JsonElement department;
private JsonElement person;
private JsonElement identity;
public DateRangeEntry getDate() {
return date;
}
public void setDate(DateRangeEntry date) {
this.date = date;
}
public JsonElement getFilter() {
return filter;
}
public void setFilter(JsonElement filter) {
this.filter = filter;
}
public JsonElement getColumn() {
return column;
}
public void setColumn(JsonElement column) {
this.column = column;
}
public JsonElement getApplication() {
return application;
}
public void setApplication(JsonElement application) {
this.application = application;
}
public JsonElement getProcess() {
return process;
}
public void setProcess(JsonElement process) {
this.process = process;
}
public JsonElement getCompany() {
return company;
}
public void setCompany(JsonElement company) {
this.company = company;
}
public JsonElement getDepartment() {
return department;
}
public void setDepartment(JsonElement department) {
this.department = department;
}
public JsonElement getPerson() {
return person;
}
public void setPerson(JsonElement person) {
this.person = person;
}
public JsonElement getIdentity() {
return identity;
}
public void setIdentity(JsonElement identity) {
this.identity = identity;
}
}
package com.x.processplatform.assemble.surface.test;
import java.io.File;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.stream.Collectors;
import org.apache.commons.io.FileUtils;
import org.apache.commons.io.filefilter.FalseFileFilter;
import org.apache.commons.io.filefilter.TrueFileFilter;
import org.apache.commons.lang3.builder.CompareToBuilder;
import org.junit.Test;
import com.x.base.core.project.bean.NameIdPair;
import com.x.base.core.project.bean.NameValuePair;
import com.x.base.core.project.connection.HttpConnection;
import com.x.base.core.project.gson.XGsonBuilder;
import com.x.processplatform.core.entity.query.CalculateEntry;
import com.x.processplatform.core.entity.query.CalculateType;
import com.x.processplatform.core.entity.query.DateEffectType;
import com.x.processplatform.core.entity.query.DateRangeEntry;
import com.x.processplatform.core.entity.query.DateRangeType;
import com.x.processplatform.core.entity.query.FilterEntry;
import com.x.processplatform.core.entity.query.GroupEntry;
import com.x.processplatform.core.entity.query.OrderEntry;
import com.x.processplatform.core.entity.query.OrderType;
import com.x.processplatform.core.entity.query.Query;
import com.x.processplatform.core.entity.query.SelectEntry;
import com.x.processplatform.core.entity.query.SelectType;
public class TestClient {
@Test
public void test1() {
Query query = new Query();
query.getWhereEntry().getApplicationList().add(new NameIdPair("测试应用", "0c2c3d76-5301-4918-8869-f88de8d2fe57"));
query.getRestrictWhereEntry().getApplicationList()
.add(new NameIdPair("测试应用", "0c2c3d76-5301-4918-8869-f88de8d2fe57"));
DateRangeEntry dateRangeEntry1 = new DateRangeEntry();
dateRangeEntry1.setDateEffectType(DateEffectType.start);
dateRangeEntry1.setYear("2016");
dateRangeEntry1.setDateRangeType(DateRangeType.year);
query.setDateRangeEntry(dateRangeEntry1);
DateRangeEntry dateRangeEntry2 = new DateRangeEntry();
dateRangeEntry2.setDateEffectType(DateEffectType.start);
dateRangeEntry2.setYear("2016");
dateRangeEntry2.setDateRangeType(DateRangeType.year);
query.setRestrictDateRangeEntry(dateRangeEntry2);
SelectEntry selectEntry1 = new SelectEntry();
SelectEntry selectEntry2 = new SelectEntry();
SelectEntry selectEntry3 = new SelectEntry();
SelectEntry selectEntry4 = new SelectEntry();
SelectEntry selectEntry5 = new SelectEntry();
SelectEntry selectEntry6 = new SelectEntry();
selectEntry1.setSelectType(SelectType.attribute);
selectEntry1.setAttribute("title");
selectEntry1.setColumn("atitle");
selectEntry1.setDisplayName("标题");
selectEntry2.setSelectType(SelectType.attribute);
selectEntry2.setAttribute("creatorPerson");
selectEntry2.setColumn("acreatorPerson");
selectEntry2.setDisplayName("创建人");
selectEntry3.setSelectType(SelectType.path);
selectEntry3.setPath("subject");
selectEntry3.setColumn("psubject");
selectEntry3.setDisplayName("主题");
selectEntry4.setSelectType(SelectType.path);
selectEntry4.setPath("amonut");
selectEntry4.setColumn("pamonut");
selectEntry4.setDisplayName("金额");
selectEntry5.setSelectType(SelectType.path);
selectEntry5.setPath("phone");
selectEntry5.setColumn("pphone");
selectEntry5.setDisplayName("电话");
selectEntry6.setSelectType(SelectType.path);
selectEntry6.setPath("slDate");
selectEntry6.setColumn("pslDate");
selectEntry6.setDisplayName("日期");
query.getSelectEntryList().add(selectEntry1);
query.getSelectEntryList().add(selectEntry2);
query.getSelectEntryList().add(selectEntry3);
query.getSelectEntryList().add(selectEntry4);
query.getSelectEntryList().add(selectEntry5);
query.getSelectEntryList().add(selectEntry6);
FilterEntry filterEntry1 = new FilterEntry();
filterEntry1.setComparison("equals");
filterEntry1.setValue("aaaaa");
filterEntry1.setPath("city.name");
filterEntry1.setLogic("and");
query.getFilterEntryList().add(filterEntry1);
FilterEntry filterEntry2 = new FilterEntry();
filterEntry2.setComparison("notEquals");
filterEntry2.setValue("bbbbb");
filterEntry2.setPath("city.title");
filterEntry2.setLogic("and");
query.getRestrictFilterEntryList().add(filterEntry2);
CalculateEntry calculateEntry1 = new CalculateEntry();
CalculateEntry calculateEntry2 = new CalculateEntry();
CalculateEntry calculateEntry3 = new CalculateEntry();
CalculateEntry calculateEntry4 = new CalculateEntry();
CalculateEntry calculateEntry5 = new CalculateEntry();
CalculateEntry calculateEntry6 = new CalculateEntry();
calculateEntry1.setCalculateType(CalculateType.sum);
calculateEntry1.setColumn("pamount");
calculateEntry2.setCalculateType(CalculateType.average);
calculateEntry2.setColumn("pamount");
calculateEntry3.setCalculateType(CalculateType.count);
calculateEntry3.setColumn("pamount");
// calculateEntry4.setCalculateType(CalculateType.groupSum);
// calculateEntry4.setColumn("pamount");
// calculateEntry5.setCalculateType(CalculateType.groupAverage);
// calculateEntry5.setColumn("pamount");
// calculateEntry6.setCalculateType(CalculateType.groupCount);
calculateEntry6.setColumn("pamount");
// query.getCalculateEntryList().add(calculateEntry1);
// query.getCalculateEntryList().add(calculateEntry2);
// query.getCalculateEntryList().add(calculateEntry3);
// query.getCalculateEntryList().add(calculateEntry4);
// query.getCalculateEntryList().add(calculateEntry5);
// query.getCalculateEntryList().add(calculateEntry6);
GroupEntry groupEntry = new GroupEntry();
groupEntry.setColumn("pphone");
groupEntry.setOrderType(OrderType.desc);
query.setGroupEntry(groupEntry);
OrderEntry orderEntry1 = new OrderEntry();
orderEntry1.setColumn("pphone");
orderEntry1.setOrderType(OrderType.asc);
OrderEntry orderEntry2 = new OrderEntry();
orderEntry2.setColumn("pslDate");
orderEntry2.setOrderType(OrderType.desc);
query.getOrderEntryList().add(orderEntry1);
query.getOrderEntryList().add(orderEntry2);
System.out.println(query.toString());
}
@Test
public void test2() throws Exception {
Map<String, Object> map1 = new HashMap<>();
map1.put("title", "aaaa");
map1.put("order", 1);
Map<String, Object> map2 = new HashMap<>();
map2.put("title", "aaaa");
map2.put("order", 2);
Map<String, Object> map3 = new HashMap<>();
map3.put("title", "bbbb");
map3.put("order", 3);
Map<String, Object> map4 = new HashMap<>();
map4.put("title", "bbbb");
map4.put("order", 4);
List<Map<String, Object>> list = new ArrayList<>();
list.add(map1);
list.add(map2);
list.add(map3);
list.add(map4);
List<OrderEntry> attributes = new ArrayList<>();
OrderEntry order1 = new OrderEntry();
OrderEntry order2 = new OrderEntry();
order1.setColumn("title");
order1.setOrderType(OrderType.desc);
order2.setColumn("order");
order2.setOrderType(OrderType.asc);
attributes.add(order1);
attributes.add(order2);
list = list.stream().sorted((o1, o2) -> compareWith(o1, o2, attributes)).collect(Collectors.toList());
System.out.println(XGsonBuilder.toJson(list));
}
public static int compareWith(Map<String, Object> o1, Map<String, Object> o2, List<OrderEntry> orderEntries) {
CompareToBuilder compareToBuilder = new CompareToBuilder();
for (OrderEntry en : orderEntries) {
if (Objects.equals(OrderType.asc, en.getOrderType())) {
compareToBuilder.append(o1.get(en.getColumn()), o2.get(en.getColumn()));
} else {
compareToBuilder.append(o2.get(en.getColumn()), o1.get(en.getColumn()));
}
}
return compareToBuilder.toComparison();
}
@Test
public void test3() throws Exception {
String addr = "http://dev.ray.local:20020/x_processplatform_assemble_surface/jaxrs/work/process/3fb84f9b-0b04-49d2-9e6d-db44abca3528?v=0.4.2&jgj06idw";
NameValuePair p = new NameValuePair("x-token", "TGzu9RzlNSLTGmXpL-MtJWt3UM2XzDf1lLLI6RVFFlXvQ_2S-AT8jQ");
List<NameValuePair> heads = new ArrayList<>();
heads.add(p);
for (int i = 0; i < 100000; i++) {
System.out.println(i);
HttpConnection.postAsString(addr, heads, "{title: \"数据测试流程一-无标题\", identity: \"zr\"}");
}
}
@Test
public void test4() throws Exception {
File file = new File("D:/导出");
for (File o : FileUtils.listFiles(file, FalseFileFilter.FALSE, TrueFileFilter.TRUE)) {
System.out.println(o.getAbsolutePath());
}
}
}
\ No newline at end of file
package com.x.processplatform.assemble.surface.test;
import java.io.File;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.apache.commons.io.FileUtils;
import org.apache.commons.io.filefilter.DirectoryFileFilter;
import org.apache.commons.io.filefilter.FalseFileFilter;
import org.apache.commons.lang3.StringUtils;
import org.apache.http.HttpEntity;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.ContentType;
import org.apache.http.entity.mime.MultipartEntityBuilder;
import org.apache.http.entity.mime.content.FileBody;
import org.apache.http.entity.mime.content.StringBody;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.protocol.HTTP;
import org.junit.Test;
import com.google.gson.JsonElement;
import com.x.base.core.project.annotation.FieldDescribe;
import com.x.base.core.project.bean.NameValuePair;
import com.x.base.core.project.connection.ActionResponse;
import com.x.base.core.project.connection.ConnectionAction;
import com.x.base.core.project.gson.GsonPropertyObject;
import com.x.base.core.project.gson.XGsonBuilder;
import com.x.base.core.project.jaxrs.WoId;
import com.x.base.core.project.tools.DateTools;
import com.x.base.core.project.tools.DefaultCharset;
public class TestClientImportFile {
@Test
public void test4() throws Exception {
File file = new File("d:/公文中等结果集");
List<NameValuePair> heads = new ArrayList<>();
String xtoken = "jlMh2guoFia-EPxnDppJq1pXYeQZDa_GCp05aUeYqxzMvh87Dpd_A725Uy1VQNhSXe8IsPd8nkw";
heads.add(new NameValuePair("x-token", xtoken));
for (File dir : FileUtils.listFilesAndDirs(file, FalseFileFilter.FALSE, DirectoryFileFilter.DIRECTORY)) {
if (!StringUtils.equals(file.getAbsolutePath(), dir.getAbsolutePath())) {
File docFile = new File(dir, "文件内容&文件内容.doc");
File infoFile = new File(dir, "baseinfo.txt");
if ((!docFile.exists()) || (!infoFile.exists())) {
System.out.println(dir + "中的文件为空");
} else {
String infoText = StringUtils.trim(FileUtils.readFileToString(infoFile, "gbk"));
infoText = StringUtils.substring(infoText, 1, infoText.length() - 1);
Info info = XGsonBuilder.instance().fromJson(infoText, Info.class);
System.out.println(info);
Req req = new Req();
req.setTitle(info.getSubject());
req.setForm("00a9df18-4a5a-490a-a2a4-224faf7d7e2a");
req.setIdentity("周睿@93b9c84c-e5be-4fd9-bcef-96754bc34371@I");
Map<String, Object> map = new HashMap<>();
map.put("mainSend", StringUtils.split(info.getFGMainDepartmentWP(), "#"));
map.put("contactSend", StringUtils.split(info.getFGContactDepartmentRP(), "#"));
map.put("date", DateTools.parse(info.getFLBeginDateOS(), "yyyy/MM/dd HH:mm:ss"));
map.put("subject", info.getSubject());
req.setData(XGsonBuilder.instance().toJsonTree(map));
ActionResponse resp = ConnectionAction.post(
"http://dev.:20020/x_processplatform_assemble_surface/jaxrs/workcompleted/process/ 8a01b431-8aac-4ab1-b555-7686952e13a7",
heads, req.toString());
WoId id = resp.getData(WoId.class);
CloseableHttpClient httpclient = HttpClients.createDefault();
HttpPost httppost = new HttpPost(
"http://127.0.0.1:20020/x_processplatform_assemble_surface/jaxrs/attachment/upload/workcompleted/"
+ id.getId());
ContentType contentType = ContentType.create(HTTP.PLAIN_TEXT_TYPE, DefaultCharset.charset);
HttpEntity reqEntity = MultipartEntityBuilder.create().addPart("file", new FileBody(docFile))
.addPart("fileName", new StringBody("文件内容&文件内容.doc", contentType))
.addPart("site", new StringBody("attachment", contentType)).build();
httppost.setEntity(reqEntity);
httppost.addHeader("x-token", xtoken);
// httpclient.execute(httppost);
CloseableHttpResponse response = httpclient.execute(httppost);
}
}
}
}
@Test
public void test1() throws Exception {
File file = new File("E:/公文文档1");
List<NameValuePair> heads = new ArrayList<>();
String xtoken = "HeEoZIVgPjQ31rEg7ARdQeRVMf3woS408yvnPg3u8lM7ddsEJNHFDLJTxCww6MWxaEy5G28B49o";
heads.add(new NameValuePair("x-token", xtoken));
for (File dir : FileUtils.listFilesAndDirs(file, FalseFileFilter.FALSE, DirectoryFileFilter.DIRECTORY)) {
if (!StringUtils.equals(file.getAbsolutePath(), dir.getAbsolutePath())) {
File docFile = new File(dir, "文件内容&文件内容.doc");
File infoFile = new File(dir, "baseinfo.txt");
if ((!docFile.exists()) || (!infoFile.exists())) {
System.out.println(dir + "中的文件为空");
} else {
String infoText = StringUtils.trim(FileUtils.readFileToString(infoFile, "gbk"));
infoText = StringUtils.substring(infoText, 1, infoText.length() - 1);
infoText = "{" + infoText + "}";
Info info = XGsonBuilder.instance().fromJson(infoText, Info.class);
System.out.println(info);
Req req = new Req();
req.setTitle(info.getSubject());
req.setForm("990c1e21-5643-4c89-abe7-ce7527520b74");
req.setIdentity("周睿@ce37b1c0-61c5-4b94-bcf3-c489347cf062@I");
Map<String, Object> map = new HashMap<>();
map.put("mainSend", StringUtils.split(info.getFGMainDepartmentWP(), "#"));
map.put("contactSend", StringUtils.split(info.getFGContactDepartmentRP(), "#"));
map.put("date", DateTools.parse(info.getFLBeginDateOS(), "yyyy/MM/dd HH:mm:ss"));
map.put("subject", info.getSubject());
req.setData(XGsonBuilder.instance().toJsonTree(map));
ActionResponse resp = ConnectionAction.post(
"http://127.0.0.1:20020/x_processplatform_assemble_surface/jaxrs/workcompleted/process/c2da6212-7241-489f-9cfa-e2003fff89d4",
heads, req.toString());
WoId id = resp.getData(WoId.class);
CloseableHttpClient httpclient = HttpClients.createDefault();
HttpPost httppost = new HttpPost(
"http://127.0.0.1:20020/x_processplatform_assemble_surface/jaxrs/attachment/upload/workcompleted/"
+ id.getId());
ContentType contentType = ContentType.create(HTTP.PLAIN_TEXT_TYPE, DefaultCharset.charset);
HttpEntity reqEntity = MultipartEntityBuilder.create().addPart("file", new FileBody(docFile))
.addPart("fileName", new StringBody("文件内容&文件内容.doc", contentType))
.addPart("site", new StringBody("attachment", contentType)).build();
httppost.setEntity(reqEntity);
httppost.addHeader("x-token", xtoken);
// httpclient.execute(httppost);
CloseableHttpResponse response = httpclient.execute(httppost);
}
}
}
}
public static class Info extends GsonPropertyObject {
private String subject;
private String FGMainDepartmentWP;
private String FGContactDepartmentRP;
private String FLBeginDateOS;
public String getSubject() {
return subject;
}
public void setSubject(String subject) {
this.subject = subject;
}
public String getFGMainDepartmentWP() {
return FGMainDepartmentWP;
}
public void setFGMainDepartmentWP(String fGMainDepartmentWP) {
FGMainDepartmentWP = fGMainDepartmentWP;
}
public String getFGContactDepartmentRP() {
return FGContactDepartmentRP;
}
public void setFGContactDepartmentRP(String fGContactDepartmentRP) {
FGContactDepartmentRP = fGContactDepartmentRP;
}
public String getFLBeginDateOS() {
return FLBeginDateOS;
}
public void setFLBeginDateOS(String fLBeginDateOS) {
FLBeginDateOS = fLBeginDateOS;
}
}
public static class Req extends GsonPropertyObject {
@FieldDescribe("标题.")
private String title;
@FieldDescribe("序号.")
private String serial;
@FieldDescribe("指定表单.")
private String form;
@FieldDescribe("指定表单数据.")
private String formData;
@FieldDescribe("启动人员身份.")
private String identity;
@FieldDescribe("开始日期.")
private Date startTime;
@FieldDescribe("结束日期.")
private Date completedTime;
@FieldDescribe("工作数据.")
private JsonElement data;
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public String getIdentity() {
return identity;
}
public void setIdentity(String identity) {
this.identity = identity;
}
public JsonElement getData() {
return data;
}
public void setData(JsonElement data) {
this.data = data;
}
public Date getCompletedTime() {
return completedTime;
}
public void setCompletedTime(Date completedTime) {
this.completedTime = completedTime;
}
public String getForm() {
return form;
}
public void setForm(String form) {
this.form = form;
}
public String getFormData() {
return formData;
}
public void setFormData(String formData) {
this.formData = formData;
}
public String getSerial() {
return serial;
}
public void setSerial(String serial) {
this.serial = serial;
}
public Date getStartTime() {
return startTime;
}
public void setStartTime(Date startTime) {
this.startTime = startTime;
}
}
}
\ No newline at end of file
{
"scopeType": "workCompleted",
"exportGrid": true,
"exportGoupGrid": true,
"selectEntryList": [
{
"orderType": "original",
"selectType": "attribute",
"attribute": "title",
"column": "atitle",
"displayName": "标题",
"path": ""
},
{
"orderType": "original",
"selectType": "attribute",
"attribute": "creatorPerson",
"column": "acreatorPerson",
"displayName": "创建人",
"path": ""
},
{
"orderType": "original",
"selectType": "path",
"attribute": "",
"column": "psubject",
"displayName": "主题",
"path": "subject"
},
{
"orderType": "original",
"selectType": "path",
"attribute": "",
"column": "pamonut",
"displayName": "金额",
"path": "amonut"
},
{
"orderType": "original",
"selectType": "path",
"attribute": "",
"column": "pphone",
"displayName": "电话",
"path": "phone"
},
{
"orderType": "original",
"selectType": "path",
"attribute": "",
"column": "pslDate",
"displayName": "日期",
"path": "slDate"
}
],
"whereEntry": {
"applicationList": [
{
"name": "测试应用",
"id": "0c2c3d76-5301-4918-8869-f88de8d2fe57"
}
],
"processList": [],
"companyList": [],
"departmentList": [],
"personList": [],
"identityList": []
},
"restrictWhereEntry": {
"applicationList": [
{
"name": "测试应用",
"id": "0c2c3d76-5301-4918-8869-f88de8d2fe57"
}
],
"processList": [],
"companyList": [],
"departmentList": [],
"personList": [],
"identityList": []
},
"filterEntryList": [
{
"path": "city.name",
"value": "aaaaa",
"logic": "and",
"comparison": "equals"
}
],
"restrictFilterEntryList": [
{
"path": "city.title",
"value": "bbbbb",
"logic": "and",
"comparison": "notEquals"
}
],
"dateRangeEntry": {
"dateRangeType": "year",
"dateEffectType": "start",
"start": "2016-11-16 13:22:39",
"completed": "2016-11-16 13:22:39",
"year": "2016",
"month": "",
"date": "",
"season": 0,
"week": 0,
"adjust": 0
},
"restrictDateRangeEntry": {
"dateRangeType": "year",
"dateEffectType": "start",
"start": "2016-11-16 13:22:39",
"completed": "2016-11-16 13:22:39",
"year": "2016",
"month": "",
"date": "",
"season": 0,
"week": 0,
"adjust": 0
},
"orderEntryList": [
{
"column": "pphone",
"orderType": "asc"
},
{
"column": "pslDate",
"orderType": "desc"
}
],
"groupEntry": {
"column": "pphone",
"orderType": "desc"
},
"calculateEntryList": [
{
"column": "pamount",
"calculateType": "sum"
},
{
"column": "pamount",
"calculateType": "average"
},
{
"column": "pamount",
"calculateType": "count"
},
{
"column": "pamount",
"calculateType": "groupSum"
},
{
"column": "pamount",
"calculateType": "groupAverage"
},
{
"column": "pamount",
"calculateType": "groupCount"
}
]
}
.classpath
.project
/.settings/
/target/
此差异已折叠。
<?xml version="1.0"?>
<project
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>o2oa</groupId>
<artifactId>o2server</artifactId>
<version>4.0.5</version>
</parent>
<artifactId>x_processplatform_core_express</artifactId>
<packaging>jar</packaging>
<dependencies>
<dependency>
<groupId>o2oa</groupId>
<artifactId>x_base_core_project</artifactId>
</dependency>
<dependency>
<groupId>o2oa</groupId>
<artifactId>x_processplatform_core_entity</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<executions>
<execution>
<id>copy-jar</id>
<phase>verify</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<outputDirectory>../store/jars</outputDirectory>
<resources>
<resource>
<directory>target</directory>
<includes>
<include>${project.artifactId}.jar</include>
</includes>
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
\ No newline at end of file
package com.x.processplatform.core.entity.query;
package com.x.processplatform.core.express.query;
import java.util.ArrayList;
import java.util.List;
import com.x.base.core.project.gson.GsonPropertyObject;
import com.x.base.core.project.tools.ListTools;
import com.x.processplatform.core.entity.query.CalculateEntry;
import com.x.processplatform.core.entity.query.OrderEffectType;
import com.x.processplatform.core.entity.query.OrderType;
public class Calculate extends GsonPropertyObject {
......
package com.x.processplatform.core.entity.query;
package com.x.processplatform.core.express.query;
import com.x.base.core.project.gson.GsonPropertyObject;
import com.x.processplatform.core.entity.query.CalculateEntry;
public class CalculateCell extends GsonPropertyObject {
......
package com.x.processplatform.core.entity.query;
package com.x.processplatform.core.express.query;
import org.apache.commons.lang3.StringUtils;
import com.x.base.core.project.gson.GsonPropertyObject;
import com.x.processplatform.core.entity.query.CalculateType;
import com.x.processplatform.core.entity.query.OrderEffectType;
import com.x.processplatform.core.entity.query.OrderType;
public class CalculateEntry extends GsonPropertyObject {
......
package com.x.processplatform.core.entity.query;
package com.x.processplatform.core.express.query;
import java.util.ArrayList;
import java.util.LinkedHashMap;
......@@ -11,6 +11,15 @@ import java.util.stream.Collectors;
import org.apache.commons.lang3.BooleanUtils;
import org.apache.commons.lang3.builder.CompareToBuilder;
import com.x.processplatform.core.entity.query.Calculate;
import com.x.processplatform.core.entity.query.CalculateCell;
import com.x.processplatform.core.entity.query.CalculateEntry;
import com.x.processplatform.core.entity.query.GroupEntry;
import com.x.processplatform.core.entity.query.OrderEffectType;
import com.x.processplatform.core.entity.query.OrderType;
import com.x.processplatform.core.entity.query.Row;
import com.x.processplatform.core.entity.query.Table;
public class CalculateEntryTools {
public static List<CalculateCell> calculateAmount(Table table, List<CalculateEntry> calculateEntries)
......
package com.x.processplatform.core.entity.query;
package com.x.processplatform.core.express.query;
import org.apache.commons.lang3.StringUtils;
import com.x.base.core.project.gson.GsonPropertyObject;
import com.x.processplatform.core.entity.query.FormatType;
public class CustomFilterEntry extends GsonPropertyObject {
......
package com.x.processplatform.core.entity.query;
package com.x.processplatform.core.express.query;
import java.util.Date;
import java.util.Objects;
import com.x.base.core.project.gson.GsonPropertyObject;
import com.x.processplatform.core.entity.query.DateEffectType;
import com.x.processplatform.core.entity.query.DateRangeType;
public class DateRangeEntry extends GsonPropertyObject {
......
package com.x.processplatform.core.entity.query;
package com.x.processplatform.core.express.query;
import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.Predicate;
......@@ -6,6 +6,7 @@ import javax.persistence.criteria.Root;
import com.x.processplatform.core.entity.content.Work;
import com.x.processplatform.core.entity.content.WorkCompleted;
import com.x.processplatform.core.entity.query.DateRangeEntry;
import com.x.query.core.entity.Item;
public class DateRangeEntryTools {
......
package com.x.processplatform.core.entity.query;
package com.x.processplatform.core.express.query;
public enum DateRangeType {
year, season, month, week, date, range, none
......
package com.x.processplatform.core.entity.query;
package com.x.processplatform.core.express.query;
import org.apache.commons.lang3.BooleanUtils;
import org.apache.commons.lang3.StringUtils;
......@@ -6,6 +6,7 @@ import org.apache.commons.lang3.math.NumberUtils;
import com.x.base.core.project.gson.GsonPropertyObject;
import com.x.base.core.project.tools.DateTools;
import com.x.processplatform.core.entity.query.FormatType;
public class FilterEntry extends GsonPropertyObject {
......
package com.x.processplatform.core.entity.query;
package com.x.processplatform.core.express.query;
import java.util.Date;
import java.util.List;
......@@ -13,6 +13,9 @@ import org.apache.commons.lang3.math.NumberUtils;
import com.x.base.core.project.tools.DateTools;
import com.x.base.core.project.tools.ListTools;
import com.x.processplatform.core.entity.query.Comparison;
import com.x.processplatform.core.entity.query.FilterEntry;
import com.x.processplatform.core.entity.query.FormatType;
import com.x.query.core.entity.Item;
import com.x.query.core.entity.Item_;
......
package com.x.processplatform.core.entity.query;
package com.x.processplatform.core.express.query;
public enum FormatType {
textValue, numberValue, booleanValue, dateTimeValue
......
package com.x.processplatform.core.entity.query;
package com.x.processplatform.core.express.query;
import org.apache.commons.lang3.StringUtils;
import com.x.base.core.project.gson.GsonPropertyObject;
import com.x.processplatform.core.entity.query.OrderType;
public class GroupEntry extends GsonPropertyObject {
......
package com.x.processplatform.core.entity.query;
package com.x.processplatform.core.express.query;
import java.util.ArrayList;
import java.util.LinkedHashMap;
......@@ -10,6 +10,13 @@ import java.util.stream.Collectors;
import org.apache.commons.lang3.builder.CompareToBuilder;
import com.x.processplatform.core.entity.query.GroupEntry;
import com.x.processplatform.core.entity.query.OrderEntry;
import com.x.processplatform.core.entity.query.OrderEntryTools;
import com.x.processplatform.core.entity.query.OrderType;
import com.x.processplatform.core.entity.query.Row;
import com.x.processplatform.core.entity.query.Table;
public class GroupEntryTools {
public static List<LinkedHashMap<String, Object>> group(Table table, GroupEntry groupEntry,
List<OrderEntry> orderEntries) throws Exception {
......
package com.x.processplatform.core.entity.query;
package com.x.processplatform.core.express.query;
import java.util.Objects;
import org.apache.commons.lang3.StringUtils;
import com.x.base.core.project.gson.GsonPropertyObject;
import com.x.processplatform.core.entity.query.OrderType;
public class OrderEntry extends GsonPropertyObject {
......
package com.x.processplatform.core.entity.query;
package com.x.processplatform.core.express.query;
import java.util.ArrayList;
import java.util.List;
......@@ -8,6 +8,10 @@ import java.util.stream.Collectors;
import org.apache.commons.lang3.builder.CompareToBuilder;
import com.x.base.core.project.tools.ListTools;
import com.x.processplatform.core.entity.query.OrderEntry;
import com.x.processplatform.core.entity.query.OrderType;
import com.x.processplatform.core.entity.query.Row;
import com.x.processplatform.core.entity.query.Table;
public class OrderEntryTools {
......
package com.x.processplatform.core.entity.query;
package com.x.processplatform.core.express.query;
import java.util.ArrayList;
import java.util.Date;
......@@ -29,6 +29,28 @@ import com.x.processplatform.core.entity.content.Work;
import com.x.processplatform.core.entity.content.WorkCompleted;
import com.x.processplatform.core.entity.content.WorkCompleted_;
import com.x.processplatform.core.entity.content.Work_;
import com.x.processplatform.core.entity.query.Calculate;
import com.x.processplatform.core.entity.query.CalculateCell;
import com.x.processplatform.core.entity.query.CalculateEntryTools;
import com.x.processplatform.core.entity.query.Comparison;
import com.x.processplatform.core.entity.query.CustomFilterEntry;
import com.x.processplatform.core.entity.query.DateEffectType;
import com.x.processplatform.core.entity.query.DateRangeEntry;
import com.x.processplatform.core.entity.query.DateRangeEntryTools;
import com.x.processplatform.core.entity.query.DateRangeType;
import com.x.processplatform.core.entity.query.FilterEntry;
import com.x.processplatform.core.entity.query.FilterEntryTools;
import com.x.processplatform.core.entity.query.GroupEntry;
import com.x.processplatform.core.entity.query.GroupEntryTools;
import com.x.processplatform.core.entity.query.OrderEntry;
import com.x.processplatform.core.entity.query.OrderEntryTools;
import com.x.processplatform.core.entity.query.Row;
import com.x.processplatform.core.entity.query.ScopeType;
import com.x.processplatform.core.entity.query.SelectEntry;
import com.x.processplatform.core.entity.query.SelectEntryTools;
import com.x.processplatform.core.entity.query.Table;
import com.x.processplatform.core.entity.query.WhereEntry;
import com.x.processplatform.core.entity.query.WhereEntryTools;
import com.x.query.core.entity.Item;
import com.x.query.core.entity.Item_;
......
package com.x.processplatform.core.entity.query;
package com.x.processplatform.core.express.query;
import java.util.LinkedHashMap;
import java.util.Objects;
......
package com.x.processplatform.core.entity.query;
package com.x.processplatform.core.express.query;
import java.util.Objects;
import org.apache.commons.lang3.StringUtils;
import com.x.base.core.project.gson.GsonPropertyObject;
import com.x.processplatform.core.entity.query.OrderType;
import com.x.processplatform.core.entity.query.SelectType;
public class SelectEntry extends GsonPropertyObject {
......
package com.x.processplatform.core.entity.query;
package com.x.processplatform.core.express.query;
import java.util.List;
import java.util.stream.Collectors;
import com.x.processplatform.core.entity.query.OrderType;
import com.x.processplatform.core.entity.query.SelectEntry;
import com.x.processplatform.core.entity.query.SelectType;
public class SelectEntryTools {
public static List<SelectEntry> filterOrderSelectEntries(List<SelectEntry> selectEntries) {
......
package com.x.processplatform.core.entity.query;
package com.x.processplatform.core.express.query;
import java.util.ArrayList;
import org.apache.commons.lang3.StringUtils;
import com.x.processplatform.core.entity.query.Row;
public class Table extends ArrayList<Row> {
private static final long serialVersionUID = 7525624451700204922L;
......
package com.x.processplatform.core.entity.query;
package com.x.processplatform.core.express.query;
import java.util.List;
......@@ -13,6 +13,7 @@ import com.x.processplatform.core.entity.content.Work;
import com.x.processplatform.core.entity.content.WorkCompleted;
import com.x.processplatform.core.entity.content.WorkCompleted_;
import com.x.processplatform.core.entity.content.Work_;
import com.x.processplatform.core.entity.query.WhereEntry;
import com.x.query.core.entity.Item;
import com.x.query.core.entity.Item_;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册