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

3 4 5 6 7
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.general.core.entity.file.GeneralFile;
import com.x.processplatform.assemble.surface.ThisApplication;
R
roo00 已提交
8 9
import org.apache.commons.lang3.StringUtils;

R
roo00 已提交
10
import com.x.base.core.project.annotation.ActionLogger;
R
roo00 已提交
11 12 13 14 15 16 17 18 19
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;

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 39 40 41 42 43
		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);

				generalFile.deleteContent(gfMapping);
				emc.beginTransaction(GeneralFile.class);
				emc.delete(GeneralFile.class, generalFile.getId());
				emc.commit();
			} else {
				throw new ExceptionPreviewImageResultObject(flag);
R
roo00 已提交
44
			}
45

R
roo00 已提交
46
		}
R
roo00 已提交
47 48
		result.setData(wo);
		return result;
R
roo00 已提交
49 50 51 52 53 54 55 56 57 58 59
	}

	public static class Wo extends WoFile {

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

	}

}