Pārlūkot izejas kodu

Merge branch 'fix/cms.publishbyworkflow_cipher' into 'develop'

Merge of fix/cms.publishbyworkflow_cipher to develop

See merge request o2oa/o2oa!121
o2null 5 gadi atpakaļ
vecāks
revīzija
81540c71da

+ 24 - 12
o2server/x_cms_assemble_control/src/main/java/com/x/cms/assemble/control/jaxrs/document/ActionPersistPublishByWorkFlow.java

@@ -167,18 +167,31 @@ public class ActionPersistPublishByWorkFlow extends BaseAction {
 		}
 
 		if (check) {
-			try (EntityManagerContainer emc = EntityManagerContainerFactory.instance().create()) {
-				if ( StringUtils.isNotEmpty( wi.getCreatorIdentity() )) {
-					wi.setCreatorPerson( userManagerService.getPersonNameWithIdentity( wi.getCreatorIdentity() ) );
-					wi.setCreatorUnitName( userManagerService.getUnitNameByIdentity( wi.getCreatorIdentity() ) );
-					wi.setCreatorTopUnitName( userManagerService.getTopUnitNameByIdentity( wi.getCreatorIdentity() ) );
-				} else {
-					if ("xadmin".equalsIgnoreCase( effectivePerson.getDistinguishedName()) ) {
+			try {
+				if (StringUtils.isEmpty( wi.getCreatorIdentity() )) {
+					if( "cipher".equalsIgnoreCase( effectivePerson.getDistinguishedName() )) {
+						wi.setCreatorIdentity("cipher");
+						wi.setCreatorPerson("cipher");
+						wi.setCreatorUnitName("cipher");
+						wi.setCreatorTopUnitName("cipher");
+					}else if ("xadmin".equalsIgnoreCase(effectivePerson.getDistinguishedName())) {
 						wi.setCreatorIdentity("xadmin");
 						wi.setCreatorPerson("xadmin");
 						wi.setCreatorUnitName("xadmin");
 						wi.setCreatorTopUnitName("xadmin");
-					} else {
+					}else {
+						//尝试一下根据当前用户获取用户的第一个身份
+						wi.setCreatorIdentity(userManagerService.getMajorIdentityWithPerson( effectivePerson.getDistinguishedName()) );
+					}
+				}
+
+				if ( !StringUtils.equals(  "cipher", wi.getCreatorIdentity() ) && !StringUtils.equals(  "xadmin", wi.getCreatorIdentity() )) {
+					//说明是指定的发布者,并不使用cipher和xadmin代替
+					if (StringUtils.isNotEmpty( wi.getCreatorIdentity() )) {
+						wi.setCreatorPerson( userManagerService.getPersonNameWithIdentity( wi.getCreatorIdentity() ) );
+						wi.setCreatorUnitName( userManagerService.getUnitNameByIdentity( wi.getCreatorIdentity() ) );
+						wi.setCreatorTopUnitName( userManagerService.getTopUnitNameByIdentity( wi.getCreatorIdentity() ) );
+					}else {
 						Exception exception = new ExceptionPersonHasNoIdentity(wi.getCreatorIdentity());
 						result.error(exception);
 					}
@@ -191,9 +204,6 @@ public class ActionPersistPublishByWorkFlow extends BaseAction {
 
 		if (check) {
 			if ( StringUtils.isEmpty(wi.getTitle())) {
-//				check = false;
-//				Exception exception = new ExceptionDocumentTitleEmpty();
-//				result.error(exception);
 				wi.setTitle( appInfo.getAppName() + " - " + categoryInfo.getCategoryName() + " - 无标题文档" );
 			}
 		}
@@ -212,6 +222,7 @@ public class ActionPersistPublishByWorkFlow extends BaseAction {
 			}
 		}
 
+		//从流程管理中复制所有的附件到CMS
 		if (check) {
 			if ( wi.getWf_attachmentIds() != null && wi.getWf_attachmentIds().length > 0 ) {
 				FileInfo fileInfo = null;
@@ -267,11 +278,12 @@ public class ActionPersistPublishByWorkFlow extends BaseAction {
 				throw exception;
 			}
 		}
+
 		if (check) {
 			try (EntityManagerContainer emc = EntityManagerContainerFactory.instance().create()) {
 				logService.log(emc, wi.getCreatorIdentity(),
 						document.getCategoryAlias() + ":" + document.getTitle(), document.getAppId(),
-						document.getCategoryId(), document.getId(), "", "DOCUMENT", "发布");
+						document.getCategoryId(), document.getId(), "", "DOCUMENT", "发布" );
 			} catch (Throwable th) {
 				th.printStackTrace();
 				result.error(th);

+ 86 - 5
o2server/x_cms_assemble_control/src/main/java/com/x/cms/assemble/control/jaxrs/document/ActionPersistPublishContent.java

@@ -1,12 +1,16 @@
 package com.x.cms.assemble.control.jaxrs.document;
 
-import java.util.ArrayList;
-import java.util.Date;
-import java.util.List;
-import java.util.Map;
+import java.io.ByteArrayInputStream;
+import java.io.InputStream;
+import java.util.*;
 
 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 com.google.gson.JsonElement;
@@ -228,6 +232,48 @@ public class ActionPersistPublishContent 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) {
 			try {				
 				Wo wo = new Wo();
@@ -240,6 +286,7 @@ public class ActionPersistPublishContent extends BaseAction {
 				throw exception;
 			}
 		}
+
 		if (check) {
 			try (EntityManagerContainer emc = EntityManagerContainerFactory.instance().create()) {
 				logService.log(emc, wi.getCreatorIdentity(),
@@ -358,11 +405,45 @@ public class ActionPersistPublishContent extends BaseAction {
 				logger.error( e, effectivePerson, request, null);
 			}
 		}
-				
+
+		ApplicationCache.notify(FileInfo.class);
 		ApplicationCache.notify(Document.class);
 		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 WrapCopier<Wi, Document> copier = WrapCopierFactory.wi( Wi.class, Document.class, null, null);

+ 8 - 1
o2server/x_cms_assemble_control/src/main/java/com/x/cms/assemble/control/jaxrs/document/BaseAction.java

@@ -3,11 +3,13 @@ package com.x.cms.assemble.control.jaxrs.document;
 import java.util.ArrayList;
 import java.util.Date;
 import java.util.List;
+import java.util.UUID;
 
 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.jaxrs.StandardJaxrsAction;
 import com.x.base.core.project.tools.ListTools;
 import com.x.cms.assemble.control.Business;
@@ -29,7 +31,10 @@ import com.x.cms.core.entity.AppInfo;
 import com.x.cms.core.entity.CategoryInfo;
 import com.x.cms.core.entity.Document;
 
+import com.x.cms.core.entity.FileInfo;
 import net.sf.ehcache.Ehcache;
+import org.apache.commons.io.FilenameUtils;
+import org.apache.commons.lang3.StringUtils;
 
 public class BaseAction extends StandardJaxrsAction {
 	protected Ehcache cache = ApplicationCache.instance().getCache( Document.class);
@@ -215,7 +220,9 @@ public class BaseAction extends StandardJaxrsAction {
 		}		
 		return false;
 	}
-	
+
+
+
 //	/**
 //	 * 将权限组,组织为一个整体集合
 //	 * @param personName

+ 3 - 1
o2server/x_cms_assemble_control/src/main/java/com/x/cms/assemble/control/jaxrs/document/DocumentCipherAction.java

@@ -11,6 +11,7 @@ import javax.ws.rs.core.Context;
 import javax.ws.rs.core.MediaType;
 
 import com.google.gson.JsonElement;
+import com.x.base.core.project.annotation.JaxrsDescribe;
 import com.x.base.core.project.annotation.JaxrsMethodDescribe;
 import com.x.base.core.project.http.ActionResult;
 import com.x.base.core.project.http.EffectivePerson;
@@ -21,6 +22,7 @@ import com.x.base.core.project.logger.Logger;
 import com.x.base.core.project.logger.LoggerFactory;
 
 @Path("document/cipher")
+@JaxrsDescribe("信息发布信息文档管理(Cipher)")
 public class DocumentCipherAction extends StandardJaxrsAction{
 	
 	private static  Logger logger = LoggerFactory.getLogger( DocumentCipherAction.class );
@@ -30,7 +32,7 @@ public class DocumentCipherAction extends StandardJaxrsAction{
 	@Path("publish/content")
 	@Produces(HttpMediaType.APPLICATION_JSON_UTF_8)
 	@Consumes(MediaType.APPLICATION_JSON)
-	public void publishContent( @Suspended final AsyncResponse asyncResponse, @Context HttpServletRequest request, JsonElement jsonElement ) {		
+	public void publishContentByWorkFlow( @Suspended final AsyncResponse asyncResponse, @Context HttpServletRequest request, JsonElement jsonElement ) {
 		EffectivePerson effectivePerson = this.effectivePerson( request );
 		ActionResult<ActionPersistPublishByWorkFlow.Wo> result = new ActionResult<>();
 		Boolean check = true;