提交 5effb049 编写于 作者: O o2null

Merge branch 'fix/企业网盘优化' into 'wrdp'

[企业网盘]增加返回文件路径、允许文件重名

See merge request o2oa/o2oa!4341
......@@ -14,6 +14,8 @@ import javax.persistence.criteria.CriteriaQuery;
import javax.persistence.criteria.Predicate;
import javax.persistence.criteria.Root;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
public class Folder2Factory extends AbstractFactory {
......@@ -121,4 +123,30 @@ public class Folder2Factory extends AbstractFactory {
long count = em.createQuery(cq).getSingleResult();
return count > 0;
}
}
\ No newline at end of file
public void listSuPNested(String id, List<Folder2> list) throws Exception {
if(!Business.TOP_FOLD.equals(id)) {
Folder2 folder = this.entityManagerContainer().find(id, Folder2.class);
if (folder != null) {
list.add(folder);
if (!Business.TOP_FOLD.equals(folder.getSuperior())) {
listSuPNested(folder.getSuperior(), list);
}
}
}
}
public String getSupPath(String id) throws Exception {
String path = "";
List<Folder2> list = new ArrayList<>();
listSuPNested(id, list);
Collections.reverse(list);
if(!list.isEmpty()) {
for (Folder2 folder : list){
path = path + "/" + folder.getName();
}
}else
path = "/";
return path;
}
}
......@@ -38,6 +38,12 @@ class ActionListFileTypePaging extends BaseAction {
Integer adjustPageSize = this.adjustSize(size);
List<Attachment2> os = this.list(effectivePerson, business, adjustPage, adjustPageSize, wi);
List<Wo> wos = Wo.copier.copy(os);
wos.stream().forEach(wo -> {
try {
wo.setPath(business.folder2().getSupPath(wo.getFolder()));
} catch (Exception e) {
}
});
result.setData(wos);
result.setCount(this.count(effectivePerson, business, wi));
return result;
......@@ -95,6 +101,16 @@ class ActionListFileTypePaging extends BaseAction {
static WrapCopier<Attachment2, Wo> copier = WrapCopierFactory.wo(Attachment2.class, Wo.class,
JpaObject.singularAttributeField(Attachment2.class, true, true), null);
@FieldDescribe("文件路径")
private String path;
public String getPath() {
return path;
}
public void setPath(String path) {
this.path = path;
}
}
}
package com.x.file.assemble.control.jaxrs.attachment2;
import com.x.base.core.container.EntityManagerContainer;
import com.x.base.core.container.factory.EntityManagerContainerFactory;
import com.x.base.core.entity.annotation.CheckPersistType;
import com.x.base.core.project.cache.ApplicationCache;
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.WoId;
import com.x.base.core.project.tools.DefaultCharset;
import com.x.base.core.project.tools.ListTools;
import com.x.file.assemble.control.ThisApplication;
import com.x.file.core.entity.personal.Attachment;
import org.apache.commons.collections4.ListUtils;
import org.apache.commons.io.FilenameUtils;
import org.apache.commons.lang3.StringUtils;
import org.glassfish.jersey.media.multipart.FormDataContentDisposition;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
class ActionUpdateContent extends BaseAction {
ActionResult<Wo> execute(EffectivePerson effectivePerson, String id, byte[] bytes,
FormDataContentDisposition disposition) throws Exception {
try (EntityManagerContainer emc = EntityManagerContainerFactory.instance().create()) {
ActionResult<Wo> result = new ActionResult<>();
Attachment attachment = emc.find(id, Attachment.class);
if (null == attachment) {
throw new ExceptionAttachmentNotExist(id);
}
if ((!StringUtils.equals(effectivePerson.getDistinguishedName(), attachment.getPerson()))
&& (!attachment.getEditorList().contains(effectivePerson.getDistinguishedName()))) {
throw new ExceptionAttachmentAccessDenied(effectivePerson, attachment);
}
StorageMapping mapping = ThisApplication.context().storageMappings().get(Attachment.class,
attachment.getStorage());
if (null == mapping) {
throw new ExceptionStorageNotExist(attachment.getStorage());
}
attachment.setLastUpdatePerson(effectivePerson.getDistinguishedName());
/** 禁止不带扩展名的文件上传 */
/** 文件名编码转换 */
String fileName = new String(disposition.getFileName().getBytes(DefaultCharset.charset_iso_8859_1),
DefaultCharset.charset);
fileName = FilenameUtils.getName(fileName);
if (StringUtils.isEmpty(FilenameUtils.getExtension(fileName))) {
throw new ExceptionEmptyExtension(fileName);
}
/** 不允许不同的扩展名上传 */
if (!Objects.equals(StringUtils.lowerCase(FilenameUtils.getExtension(fileName)),
attachment.getExtension())) {
throw new ExceptionExtensionNotMatch(fileName, attachment.getExtension());
}
emc.beginTransaction(Attachment.class);
attachment.updateContent(mapping, bytes);
emc.check(attachment, CheckPersistType.all);
emc.commit();
/** 通知所有的共享和共享编辑人员 */
List<String> people = new ArrayList<>();
people = ListUtils.union(attachment.getShareList(), attachment.getEditorList());
people.add(attachment.getPerson());
for (String o : ListTools.trim(people, true, true)) {
if (!StringUtils.equals(o, effectivePerson.getDistinguishedName())) {
this.message_send_attachment_editorModify(attachment, effectivePerson.getDistinguishedName(), o);
}
}
ApplicationCache.notify(Attachment.class, attachment.getId());
Wo wo = new Wo();
wo.setId(attachment.getId());
result.setData(wo);
return result;
}
}
public static class Wo extends WoId {
}
}
\ No newline at end of file
package com.x.file.assemble.control.jaxrs.attachment2;
import com.x.base.core.container.EntityManagerContainer;
import com.x.base.core.container.factory.EntityManagerContainerFactory;
import com.x.base.core.entity.annotation.CheckPersistType;
import com.x.base.core.project.cache.ApplicationCache;
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.WoCallback;
import com.x.base.core.project.jaxrs.WoId;
import com.x.base.core.project.logger.Logger;
import com.x.base.core.project.logger.LoggerFactory;
import com.x.base.core.project.tools.DefaultCharset;
import com.x.base.core.project.tools.ListTools;
import com.x.file.assemble.control.ThisApplication;
import com.x.file.core.entity.personal.Attachment;
import org.apache.commons.collections4.ListUtils;
import org.apache.commons.io.FilenameUtils;
import org.apache.commons.lang3.StringUtils;
import org.glassfish.jersey.media.multipart.FormDataContentDisposition;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
class ActionUpdateContentCallback extends BaseAction {
private static Logger logger = LoggerFactory.getLogger(ActionUpdateContentCallback.class);
ActionResult<Wo<WoObject>> execute(EffectivePerson effectivePerson, String id, String callback, byte[] bytes,
FormDataContentDisposition disposition) throws Exception {
try (EntityManagerContainer emc = EntityManagerContainerFactory.instance().create()) {
ActionResult<Wo<WoObject>> result = new ActionResult<>();
Attachment attachment = emc.find(id, Attachment.class);
if (null == attachment) {
throw new ExceptionAttachmentNotExistCallback(callback, id);
}
if ((!StringUtils.equals(effectivePerson.getDistinguishedName(), attachment.getPerson()))
&& (!attachment.getEditorList().contains(effectivePerson.getDistinguishedName()))) {
throw new ExceptionAttachmentAccessDeniedCallback(effectivePerson, callback, attachment);
}
StorageMapping mapping = ThisApplication.context().storageMappings().get(Attachment.class,
attachment.getStorage());
if (null == mapping) {
throw new ExceptionStorageNotExistCallback(callback, attachment.getStorage());
}
attachment.setLastUpdatePerson(effectivePerson.getDistinguishedName());
/** 禁止不带扩展名的文件上传 */
/** 文件名编码转换 */
String fileName = new String(disposition.getFileName().getBytes(DefaultCharset.charset_iso_8859_1),
DefaultCharset.charset);
fileName = FilenameUtils.getName(fileName);
if (StringUtils.isEmpty(FilenameUtils.getExtension(fileName))) {
throw new ExceptionEmptyExtensionCallback(callback, fileName);
}
/** 不允许不同的扩展名上传 */
if (!Objects.equals(StringUtils.lowerCase(FilenameUtils.getExtension(fileName)),
attachment.getExtension())) {
throw new ExceptionExtensionNotMatchCallback(callback, fileName, attachment.getExtension());
}
emc.beginTransaction(Attachment.class);
attachment.updateContent(mapping, bytes);
emc.check(attachment, CheckPersistType.all);
emc.commit();
/** 通知所有的共享和共享编辑人员 */
List<String> people = new ArrayList<>();
people = ListUtils.union(attachment.getShareList(), attachment.getEditorList());
people.add(attachment.getPerson());
for (String o : ListTools.trim(people, true, true)) {
if (!StringUtils.equals(o, effectivePerson.getDistinguishedName())) {
this.message_send_attachment_editorModify(attachment, effectivePerson.getDistinguishedName(), o);
}
}
ApplicationCache.notify(Attachment.class, attachment.getId());
WoObject woObject = new WoObject();
woObject.setId(attachment.getId());
Wo<WoObject> wo = new Wo<>(callback, woObject);
result.setData(wo);
return result;
}
}
public static class Wo<T> extends WoCallback<T> {
public Wo(String callbackName, T t) {
super(callbackName, t);
}
}
public static class WoObject extends WoId {
}
}
\ No newline at end of file
......@@ -73,7 +73,8 @@ class ActionUpload extends BaseAction {
/** 同一目录下文件名唯一 */
if (this.exist(business, fileName, folderId, effectivePerson.getDistinguishedName())) {
throw new ExceptionSameNameFileExist(fileName);
fileName = this.adjustFileName(business, folderId, fileName);
//throw new ExceptionSameNameFileExist(fileName);
}
if(StringUtils.isEmpty(fileMd5)){
if(bytes==null) {
......@@ -118,4 +119,4 @@ class ActionUpload extends BaseAction {
public static class Wo extends WoId {
}
}
\ No newline at end of file
}
......@@ -13,7 +13,6 @@ 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 com.x.file.assemble.control.jaxrs.attachment2.ActionUpdateContentCallback.Wo;
import com.x.file.assemble.control.jaxrs.attachment2.ActionUploadCallback.WoObject;
import org.glassfish.jersey.media.multipart.FormDataContentDisposition;
import org.glassfish.jersey.media.multipart.FormDataParam;
......@@ -440,4 +439,4 @@ public class Attachment2Action extends StandardJaxrsAction {
}
asyncResponse.resume(ResponseFactory.getEntityTagActionResultResponse(request, result));
}
}
\ No newline at end of file
}
......@@ -2,63 +2,29 @@ package com.x.file.assemble.control.jaxrs.attachment2;
import com.x.base.core.project.cache.Cache;
import com.x.base.core.project.cache.CacheManager;
import com.x.base.core.project.gson.XGsonBuilder;
import com.x.base.core.project.jaxrs.StandardJaxrsAction;
import com.x.base.core.project.message.MessageConnector;
import com.x.base.core.project.organization.OrganizationDefinition;
import com.x.base.core.project.tools.ListTools;
import com.x.base.core.project.tools.StringTools;
import com.x.file.assemble.control.Business;
import com.x.file.core.entity.open.FileConfig;
import com.x.file.core.entity.open.FileConfigProperties;
import com.x.file.core.entity.personal.Attachment;
import com.x.file.core.entity.personal.Attachment2;
import com.x.file.core.entity.personal.Attachment2_;
import org.apache.commons.collections4.ListUtils;
import org.apache.commons.io.FilenameUtils;
import org.apache.commons.lang3.StringUtils;
import javax.persistence.EntityManager;
import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.CriteriaQuery;
import javax.persistence.criteria.Predicate;
import javax.persistence.criteria.Root;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
abstract class BaseAction extends StandardJaxrsAction {
protected void message_send_attachment_share(Attachment attachment, String person) throws Exception {
String title = "收到来自(" + OrganizationDefinition.name(attachment.getPerson()) + ")的共享文件:" + attachment.getName()
+ ".";
MessageConnector.send(MessageConnector.TYPE_ATTACHMENT_SHARE, title, person,
XGsonBuilder.convert(attachment, Attachment.class));
}
protected void message_send_attachment_shareCancel(Attachment attachment, String person) throws Exception {
String title = "(" + OrganizationDefinition.name(attachment.getPerson()) + ")取消了对:" + attachment.getName()
+ ",文件的共享.";
MessageConnector.send(MessageConnector.TYPE_ATTACHMENT_SHARECANCEL, title, person,
XGsonBuilder.convert(attachment, Attachment.class));
}
protected void message_send_attachment_editor(Attachment attachment, String person) throws Exception {
String title = "收到来自(" + OrganizationDefinition.name(attachment.getPerson()) + ")的可编辑共享文件:"
+ attachment.getName() + ".";
MessageConnector.send(MessageConnector.TYPE_ATTACHMENT_EDITOR, title, person,
XGsonBuilder.convert(attachment, Attachment.class));
}
protected void message_send_attachment_editorCancel(Attachment attachment, String person) throws Exception {
String title = "(" + OrganizationDefinition.name(attachment.getPerson()) + ")取消了对:" + attachment.getName()
+ ",文件的共享编辑.";
MessageConnector.send(MessageConnector.TYPE_ATTACHMENT_EDITORCANCEL, title, person,
XGsonBuilder.convert(attachment, Attachment.class));
}
protected void message_send_attachment_editorModify(Attachment attachment, String editor, String person)
throws Exception {
String title = "(" + OrganizationDefinition.name(editor) + ")对文件:" + attachment.getName() + ",进行了修改.";
MessageConnector.send(MessageConnector.TYPE_ATTACHMENT_EDITORMODIFY, title, person,
XGsonBuilder.convert(attachment, Attachment.class));
}
protected Boolean exist(Business business, String fileName, String folderId, String person) throws Exception {
EntityManager em = business.entityManagerContainer().get(Attachment2.class);
CriteriaBuilder cb = em.getCriteriaBuilder();
......@@ -106,4 +72,25 @@ abstract class BaseAction extends StandardJaxrsAction {
}
}
}
public String adjustFileName(Business business, String folderId, String fileName) throws Exception {
List<String> list = new ArrayList<>();
list.add(fileName);
String base = FilenameUtils.getBaseName(fileName);
String extension = FilenameUtils.getExtension(fileName);
for (int i = 1; i < 20; i++) {
list.add(base + i + (StringUtils.isEmpty(extension) ? "" : "." + extension));
}
list.add(StringTools.uniqueToken());
EntityManager em = business.entityManagerContainer().get(Attachment2.class);
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<String> cq = cb.createQuery(String.class);
Root<Attachment2> root = cq.from(Attachment2.class);
Predicate p = root.get(Attachment2_.name).in(list);
p = cb.and(p, cb.equal(root.get(Attachment2_.folder), folderId));
cq.select(root.get(Attachment2_.name)).where(p);
List<String> os = em.createQuery(cq).getResultList();
list = ListUtils.subtract(list, os);
return list.get(0);
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册