提交 f148008d 编写于 作者: O o2null

Merge branch 'fix/general' into 'wrdp'

删除general下file移动到generalfile后未删除的文件

See merge request o2oa/o2oa!2249
package com.x.general.assemble.control.jaxrs.general;
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.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;
import com.x.general.assemble.control.ThisApplication;
import com.x.general.core.entity.general.File;
public class ActionGet extends BaseAction {
private static Logger logger = LoggerFactory.getLogger(ActionGet.class);
protected ActionResult<Wo> execute(EffectivePerson effectivePerson, String flag) throws Exception {
logger.debug(effectivePerson, "flag:{}.", flag);
ActionResult<Wo> result = new ActionResult<>();
Wo wo = null;
try (EntityManagerContainer emc = EntityManagerContainerFactory.instance().create()) {
File generalFile = emc.find(flag, File.class);
if(generalFile!=null){
StorageMapping gfMapping = ThisApplication.context().storageMappings().get(File.class,
generalFile.getStorage());
wo = new Wo(generalFile.readContent(gfMapping), this.contentType(false, generalFile.getName()),
this.contentDisposition(false, generalFile.getName()));
result.setData(wo);
generalFile.deleteContent(gfMapping);
emc.beginTransaction(File.class);
emc.delete(File.class, generalFile.getId());
emc.commit();
} else {
throw new ExceptionInputFileObject(flag);
}
}
result.setData(wo);
return result;
}
public static class Wo extends WoFile {
public Wo(byte[] bytes, String contentType, String contentDisposition) {
super(bytes, contentType, contentDisposition);
}
}
}
package com.x.general.assemble.control.jaxrs.general;
import com.x.base.core.project.jaxrs.StandardJaxrsAction;
abstract class BaseAction extends StandardJaxrsAction {
}
package com.x.general.assemble.control.jaxrs.general;
import com.x.base.core.project.exception.PromptException;
public class ExceptionInputFileObject extends PromptException {
private static final long serialVersionUID = 9085364457175859374L;
ExceptionInputFileObject(String flag) {
super("对象不存在:{}.", flag);
}
}
\ No newline at end of file
package com.x.general.assemble.control.jaxrs.general;
import com.x.base.core.project.annotation.JaxrsDescribe;
import com.x.base.core.project.annotation.JaxrsMethodDescribe;
import com.x.base.core.project.annotation.JaxrsParameterDescribe;
import com.x.base.core.project.http.ActionResult;
import com.x.base.core.project.http.EffectivePerson;
import com.x.base.core.project.jaxrs.ResponseFactory;
import com.x.base.core.project.jaxrs.StandardJaxrsAction;
import com.x.base.core.project.logger.Logger;
import com.x.base.core.project.logger.LoggerFactory;
import javax.servlet.http.HttpServletRequest;
import javax.ws.rs.*;
import javax.ws.rs.container.AsyncResponse;
import javax.ws.rs.container.Suspended;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.MediaType;
@Path("generalfile")
@JaxrsDescribe("获取附件")
public class FileAction extends StandardJaxrsAction {
private static Logger logger = LoggerFactory.getLogger(FileAction.class);
@JaxrsMethodDescribe(value = "获取附件.", action = ActionGet.class)
@GET
@Path("flag/{flag}")
@Consumes(MediaType.APPLICATION_JSON)
public void getResult(@Suspended final AsyncResponse asyncResponse, @Context HttpServletRequest request,
@JaxrsParameterDescribe("附件标记") @PathParam("flag") String flag) {
ActionResult<ActionGet.Wo> result = new ActionResult<>();
EffectivePerson effectivePerson = this.effectivePerson(request);
try {
result = new ActionGet().execute(effectivePerson, flag);
} catch (Exception e) {
logger.error(e, effectivePerson, request, null);
result.error(e);
}
asyncResponse.resume(ResponseFactory.getEntityTagActionResultResponse(request, result));
}
}
\ No newline at end of file
package com.x.general.assemble.control.jaxrs.generalfile;
import javax.servlet.http.HttpServletRequest;
import javax.ws.rs.Consumes;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.container.AsyncResponse;
import javax.ws.rs.container.Suspended;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.MediaType;
import com.x.base.core.project.annotation.JaxrsDescribe;
import com.x.base.core.project.annotation.JaxrsMethodDescribe;
import com.x.base.core.project.annotation.JaxrsParameterDescribe;
......@@ -10,13 +20,6 @@ import com.x.base.core.project.jaxrs.StandardJaxrsAction;
import com.x.base.core.project.logger.Logger;
import com.x.base.core.project.logger.LoggerFactory;
import javax.servlet.http.HttpServletRequest;
import javax.ws.rs.*;
import javax.ws.rs.container.AsyncResponse;
import javax.ws.rs.container.Suspended;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.MediaType;
@Path("generalfile")
@JaxrsDescribe("获取附件")
public class GeneralFileAction extends StandardJaxrsAction {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册