提交 e06b01b0 编写于 作者: O o2null

Merge branch '修复内容管理发布文档指定身份不生效问题' into 'develop'

修复内容管理发布文档指定身份不生效问题 同时合并到master

See merge request o2oa/o2oa!577
package com.x.cms.assemble.control.jaxrs.document; package com.x.cms.assemble.control.jaxrs.document;
import java.io.ByteArrayInputStream;
import java.io.InputStream;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Date; import java.util.Date;
import java.util.List; import java.util.List;
import java.util.UUID;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import com.x.base.core.entity.annotation.CheckPersistType;
import com.x.base.core.project.config.StorageMapping;
import com.x.base.core.project.exception.ExceptionWhen;
import com.x.processplatform.core.entity.content.Attachment;
import org.apache.commons.io.FilenameUtils;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import com.google.gson.JsonElement; import com.google.gson.JsonElement;
...@@ -49,7 +57,7 @@ public class ActionPersistSaveDocument extends BaseAction { ...@@ -49,7 +57,7 @@ public class ActionPersistSaveDocument extends BaseAction {
try { try {
wi = this.convertToWrapIn( jsonElement, Wi.class ); wi = this.convertToWrapIn( jsonElement, Wi.class );
document = Wi.copier.copy(wi); document = Wi.copier.copy(wi);
document.setId( wi.getId() ); //继承传入的ID document.setId( wi.getId() );
identity = wi.getIdentity(); identity = wi.getIdentity();
} catch (Exception e ) { } catch (Exception e ) {
check = false; check = false;
...@@ -59,7 +67,7 @@ public class ActionPersistSaveDocument extends BaseAction { ...@@ -59,7 +67,7 @@ public class ActionPersistSaveDocument extends BaseAction {
} }
if (check) { if (check) {
if( !"xadmin".equals( effectivePerson.getDistinguishedName() )) { if( StringUtils.isBlank(identity)) {
try { try {
identity = userManagerService.getPersonIdentity( effectivePerson.getDistinguishedName(), identity ); identity = userManagerService.getPersonIdentity( effectivePerson.getDistinguishedName(), identity );
} catch (Exception e) { } catch (Exception e) {
...@@ -298,6 +306,48 @@ public class ActionPersistSaveDocument extends BaseAction { ...@@ -298,6 +306,48 @@ public class ActionPersistSaveDocument extends BaseAction {
} }
} }
//从流程管理中复制所有的附件到CMS
if (check) {
if ( wi.getWf_attachmentIds() != null && wi.getWf_attachmentIds().length > 0 ) {
FileInfo fileInfo = null;
Attachment attachment = null;
StorageMapping mapping_attachment = null;
StorageMapping mapping_fileInfo = null;
InputStream input = null;
byte[] attachment_content = null;
for (String attachmentId : wi.getWf_attachmentIds()) {
try (EntityManagerContainer emc = EntityManagerContainerFactory.instance().create()) {
document = emc.find(document.getId(), Document.class, ExceptionWhen.not_found);
attachment = emc.find(attachmentId, Attachment.class, ExceptionWhen.not_found);
if (attachment != null) {
emc.beginTransaction(FileInfo.class);
emc.beginTransaction(Document.class);
mapping_attachment = ThisApplication.context().storageMappings().get(Attachment.class, attachment.getStorage());
attachment_content = attachment.readContent(mapping_attachment);
mapping_fileInfo = ThisApplication.context().storageMappings().random(FileInfo.class);
fileInfo = concreteFileInfo(effectivePerson.getDistinguishedName(), document, mapping_fileInfo, attachment.getName(), attachment.getSite());
input = new ByteArrayInputStream(attachment_content);
fileInfo.saveContent(mapping_fileInfo, input, attachment.getName());
fileInfo.setName(attachment.getName());
emc.check(document, CheckPersistType.all);
emc.persist(fileInfo, CheckPersistType.all);
emc.commit();
}
} catch (Throwable th) {
th.printStackTrace();
result.error(th);
} finally {
if (input != null) {
input.close();
}
}
}
}
}
if (check) { if (check) {
// 检查是否有需要新添加的云图片信息 // 检查是否有需要新添加的云图片信息
if (wi.getCloudPictures() != null && !wi.getCloudPictures().isEmpty()) { if (wi.getCloudPictures() != null && !wi.getCloudPictures().isEmpty()) {
...@@ -341,6 +391,39 @@ public class ActionPersistSaveDocument extends BaseAction { ...@@ -341,6 +391,39 @@ public class ActionPersistSaveDocument extends BaseAction {
return result; return result;
} }
private FileInfo concreteFileInfo(String person, Document document, StorageMapping storage, String name, String site) throws Exception {
String fileName = UUID.randomUUID().toString();
String extension = FilenameUtils.getExtension(name);
FileInfo attachment = new FileInfo();
if (StringUtils.isEmpty(extension)) {
throw new Exception("file extension is empty.");
} else {
fileName = fileName + "." + extension;
}
if (name.indexOf("\\") > 0) {
name = StringUtils.substringAfterLast(name, "\\");
}
if (name.indexOf("/") > 0) {
name = StringUtils.substringAfterLast(name, "/");
}
attachment.setCreateTime(new Date());
attachment.setLastUpdateTime(new Date());
attachment.setExtension(extension);
attachment.setName(name);
attachment.setFileName(fileName);
attachment.setStorage(storage.getName());
attachment.setAppId(document.getAppId());
attachment.setCategoryId(document.getCategoryId());
attachment.setDocumentId(document.getId());
attachment.setCreatorUid(person);
attachment.setSite(site);
attachment.setFileHost("");
attachment.setFilePath("");
attachment.setFileType("ATTACHMENT");
return attachment;
}
public static class Wi{ public static class Wi{
@FieldDescribe("ID,非必填,更新时必填写,不然就是新增文档") @FieldDescribe("ID,非必填,更新时必填写,不然就是新增文档")
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册