ActionPreviewPdfResult.java 2.0 KB
Newer Older
R
roo00 已提交
1 2
package com.x.processplatform.assemble.surface.jaxrs.attachment;

3 4 5 6
import com.x.base.core.container.EntityManagerContainer;
import com.x.base.core.container.factory.EntityManagerContainerFactory;
import com.x.base.core.project.config.StorageMapping;
import com.x.processplatform.assemble.surface.ThisApplication;
R
roo00 已提交
7 8
import org.apache.commons.lang3.StringUtils;

R
roo00 已提交
9
import com.x.base.core.project.annotation.ActionLogger;
R
roo00 已提交
10 11 12 13 14 15
import com.x.base.core.project.exception.ExceptionAccessDenied;
import com.x.base.core.project.http.ActionResult;
import com.x.base.core.project.http.EffectivePerson;
import com.x.base.core.project.jaxrs.WoFile;
import com.x.base.core.project.logger.Logger;
import com.x.base.core.project.logger.LoggerFactory;
O
o2null 已提交
16
import com.x.general.core.entity.GeneralFile;
R
roo00 已提交
17 18 19

class ActionPreviewPdfResult extends BaseAction {

R
roo00 已提交
20
	@ActionLogger
R
roo00 已提交
21 22 23
	private static Logger logger = LoggerFactory.getLogger(ActionPreviewPdfResult.class);

	ActionResult<Wo> execute(EffectivePerson effectivePerson, String flag) throws Exception {
R
roo00 已提交
24 25
		ActionResult<Wo> result = new ActionResult<>();
		Wo wo = null;
26 27 28 29 30 31 32 33 34 35 36 37 38
		try (EntityManagerContainer emc = EntityManagerContainerFactory.instance().create()) {
			GeneralFile generalFile = emc.find(flag, GeneralFile.class);
			if(generalFile!=null){
				if (!StringUtils.equals(effectivePerson.getDistinguishedName(), generalFile.getPerson())) {
					throw new ExceptionAccessDenied(effectivePerson);
				}
				StorageMapping gfMapping = ThisApplication.context().storageMappings().get(GeneralFile.class,
						generalFile.getStorage());
				wo = new Wo(generalFile.readContent(gfMapping), this.contentType(true, generalFile.getName()),
						this.contentDisposition(true, generalFile.getName()));
				result.setData(wo);
			} else {
				throw new ExceptionPreviewImageResultObject(flag);
R
roo00 已提交
39
			}
40

R
roo00 已提交
41
		}
R
roo00 已提交
42 43
		result.setData(wo);
		return result;
R
roo00 已提交
44 45 46 47 48 49 50 51 52 53
	}

	public static class Wo extends WoFile {

		public Wo(byte[] bytes, String contentType, String contentDisposition) {
			super(bytes, contentType, contentDisposition);
		}

	}

54
}