|
|
@@ -1,5 +1,9 @@
|
|
|
package com.x.organization.assemble.control.jaxrs.inputperson;
|
|
|
|
|
|
+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.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;
|
|
|
@@ -7,6 +11,9 @@ import com.x.base.core.project.logger.Logger;
|
|
|
import com.x.base.core.project.logger.LoggerFactory;
|
|
|
import com.x.base.core.project.cache.Cache.CacheKey;
|
|
|
import com.x.base.core.project.cache.CacheManager;
|
|
|
+import com.x.general.core.entity.file.GeneralFile;
|
|
|
+import com.x.organization.assemble.control.ThisApplication;
|
|
|
+import org.apache.commons.lang3.StringUtils;
|
|
|
|
|
|
import java.util.Optional;
|
|
|
|
|
|
@@ -17,13 +24,28 @@ public class ActionGetResult extends BaseAction {
|
|
|
protected ActionResult<Wo> execute(EffectivePerson effectivePerson, String flag) throws Exception {
|
|
|
logger.debug(effectivePerson, "flag:{}.", flag);
|
|
|
ActionResult<Wo> result = new ActionResult<>();
|
|
|
- CacheKey cacheKey = new CacheKey(flag);
|
|
|
- Optional<?> optional = CacheManager.get(this.cache, cacheKey);
|
|
|
- if (!optional.isPresent()) {
|
|
|
- throw new ExceptionResultNotFound(flag);
|
|
|
+ Wo wo = null;
|
|
|
+ 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 ExceptionInputResultObject(flag);
|
|
|
+ }
|
|
|
+
|
|
|
}
|
|
|
- CacheInputResult o = (CacheInputResult) optional.get();
|
|
|
- Wo wo = new Wo(o.getBytes(), this.contentType(true, o.getName()), this.contentDisposition(true, o.getName()));
|
|
|
result.setData(wo);
|
|
|
return result;
|
|
|
}
|