ActionGet.java 2.2 KB
Newer Older
O
o2sword 已提交
1 2 3 4 5 6 7 8 9 10 11
package com.x.query.assemble.surface.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;
import com.x.base.core.project.exception.ExceptionAccessDenied;
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;
O
o2sword 已提交
14 15 16 17 18
import com.x.query.assemble.surface.Business;
import com.x.query.core.entity.Query;
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);

O
o2sword 已提交
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);

O
o2sword 已提交
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58
		try (EntityManagerContainer emc = EntityManagerContainerFactory.instance().create()) {
			ActionResult<Wo> result = new ActionResult<>();
			Business business = new Business(emc);
			Statement statement = emc.flag(flag, Statement.class);
			if (null == statement) {
				throw new ExceptionEntityNotExist(flag, Statement.class);
			}
			Query query = emc.flag(statement.getQuery(), Query.class);
			if (null == query) {
				throw new ExceptionEntityNotExist(flag, Query.class);
			}
			if (!business.readable(effectivePerson, query)) {
				throw new ExceptionAccessDenied(effectivePerson, query);
			}
			if (!business.readable(effectivePerson, statement)) {
				throw new ExceptionAccessDenied(effectivePerson, statement);
			}
			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);
	}
}