ActionGet.java 2.2 KB
Newer Older
R
roo00 已提交
1 2 3 4 5 6 7
package com.x.query.assemble.designer.jaxrs.statement;

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;
R
roo00 已提交
8
import com.x.base.core.project.exception.ExceptionAccessDenied;
R
roo00 已提交
9 10 11
import com.x.base.core.project.exception.ExceptionEntityNotExist;
import com.x.base.core.project.http.ActionResult;
import com.x.base.core.project.http.EffectivePerson;
R
Ray 已提交
12 13
import com.x.base.core.project.logger.Logger;
import com.x.base.core.project.logger.LoggerFactory;
R
roo00 已提交
14
import com.x.query.assemble.designer.Business;
R
roo00 已提交
15
import com.x.query.core.entity.Query;
R
roo00 已提交
16 17 18
import com.x.query.core.entity.schema.Statement;

class ActionGet extends BaseAction {
R
Ray 已提交
19 20 21

	private static final Logger LOGGER = LoggerFactory.getLogger(ActionGet.class);

R
roo00 已提交
22
	ActionResult<Wo> execute(EffectivePerson effectivePerson, String flag) throws Exception {
R
Ray 已提交
23 24 25 26 27

		LOGGER.debug("execute:{}, flag:{}.", effectivePerson::getDistinguishedName, () -> flag);
		ClassLoader classLoader = Business.getDynamicEntityClassLoader();
		Thread.currentThread().setContextClassLoader(classLoader);

R
roo00 已提交
28 29
		try (EntityManagerContainer emc = EntityManagerContainerFactory.instance().create()) {
			ActionResult<Wo> result = new ActionResult<>();
R
roo00 已提交
30
			Business business = new Business(emc);
R
roo00 已提交
31 32 33 34
			Statement statement = emc.flag(flag, Statement.class);
			if (null == statement) {
				throw new ExceptionEntityNotExist(flag, Statement.class);
			}
R
roo00 已提交
35 36 37 38 39 40 41
			com.x.query.core.entity.Query query = emc.flag(statement.getQuery(), com.x.query.core.entity.Query.class);
			if (null == query) {
				throw new ExceptionEntityNotExist(flag, Query.class);
			}
			if (!business.editable(effectivePerson, query)) {
				throw new ExceptionAccessDenied(effectivePerson, query);
			}
R
roo00 已提交
42 43 44 45 46 47 48 49 50 51 52 53 54 55
			Wo wo = Wo.copier.copy(statement);
			result.setData(wo);
			return result;
		}
	}

	public static class Wo extends Statement {

		private static final long serialVersionUID = -5755898083219447939L;

		static WrapCopier<Statement, Wo> copier = WrapCopierFactory.wo(Statement.class, Wo.class, null,
				JpaObject.FieldsInvisible);
	}
}