Explorar o código

流程文档通过云端转换doc和pdf错误

(cherry picked from commit 4a44356a69c182c759b401cccc164a07edccda19)
o2sword %!s(int64=4) %!d(string=hai) anos
pai
achega
7ad9db29a2

+ 11 - 35
o2server/x_base_core_project/src/main/java/com/x/base/core/project/config/Collect.java

@@ -6,10 +6,13 @@ import java.io.OutputStream;
 import java.net.HttpURLConnection;
 import java.net.URL;
 import java.nio.charset.StandardCharsets;
+import java.util.HashMap;
+import java.util.Map;
 import java.util.Objects;
 
 import com.x.base.core.project.connection.ActionResponse;
 import com.x.base.core.project.http.ActionResult;
+import com.x.base.core.project.jaxrs.WrapBoolean;
 import com.x.base.core.project.tools.BaseTools;
 import org.apache.commons.io.FileUtils;
 import org.apache.commons.io.IOUtils;
@@ -164,49 +167,22 @@ public class Collect extends ConfigObject {
 		this.server = server;
 	}
 
-	public boolean validate()
-			throws ExceptionCollectConnectError, ExceptionCollectDisable, ExceptionCollectValidateFailure, Exception {
+	public boolean validate() throws Exception {
 
 		if (!Config.collect().getEnable()) {
 			throw new ExceptionCollectDisable();
 		}
 
 		try {
-			URL url = new URL(this.url("/o2_collect_assemble/jaxrs/collect/validate"));
-			HttpURLConnection connection = (HttpURLConnection) url.openConnection();
-			connection.setRequestProperty(ConnectionAction.ACCESS_CONTROL_ALLOW_CREDENTIALS,
-					ConnectionAction.ACCESS_CONTROL_ALLOW_CREDENTIALS_VALUE);
-			connection.setRequestProperty(ConnectionAction.ACCESS_CONTROL_ALLOW_HEADERS,
-					ConnectionAction.ACCESS_CONTROL_ALLOW_HEADERS_VALUE);
-			connection.setRequestProperty(ConnectionAction.ACCESS_CONTROL_ALLOW_METHODS,
-					ConnectionAction.ACCESS_CONTROL_ALLOW_METHODS_VALUE);
-			connection.setRequestProperty(ConnectionAction.CACHE_CONTROL, ConnectionAction.CACHE_CONTROL_VALUE);
-			connection.setRequestProperty(ConnectionAction.CONTENT_TYPE, ConnectionAction.CONTENT_TYPE_VALUE);
-			connection.setRequestMethod("POST");
-			connection.setUseCaches(false);
-			connection.setDoOutput(true);
-			connection.setDoInput(true);
-			connection.connect();
-			try (OutputStream output = connection.getOutputStream()) {
-				String req = "{\"name\":\"" + Config.collect().getName() + "\",\"password\":\""
-						+ Config.collect().getPassword() + "\"}";
-				IOUtils.write(req, output, StandardCharsets.UTF_8);
-			}
-			if (200 != connection.getResponseCode()) {
-				throw new ExceptionCollectValidateFailure();
-			}
-			try (InputStream input = connection.getInputStream()) {
-				byte[] buffer = IOUtils.toByteArray(input);
-				String value = new String(buffer, DefaultCharset.name);
-				if (!StringUtils.contains(value, "success")) {
-					throw new ExceptionCollectValidateFailure();
-				}
-			}
-			connection.disconnect();
+			String url = Config.collect().url(Collect.ADDRESS_COLLECT_VALIDATE);
+			Map<String, String> map = new HashMap<>();
+			map.put("name", this.getName());
+			map.put("password", this.getPassword());
+			ActionResponse resp = ConnectionAction.post(url, null, map);
+			return resp.getData(WrapBoolean.class).getValue();
 		} catch (Exception e) {
 			throw new ExceptionCollectConnectError();
 		}
-		return true;
 	}
 
 	public boolean connect() throws Exception {
@@ -257,4 +233,4 @@ public class Collect extends ConfigObject {
 		this.key = key;
 	}
 
-}
+}

+ 5 - 5
o2server/x_base_core_project/src/main/java/com/x/base/core/project/tools/DocumentTools.java

@@ -38,7 +38,7 @@ public class DocumentTools {
 
 		Config.collect().validate();
 
-		Tika tika = new Tika();
+		/*Tika tika = new Tika();
 		String type = tika.detect(bytes, fileName);
 
 		switch (Objects.toString(type, "")) {
@@ -48,7 +48,7 @@ public class DocumentTools {
 			break;
 		default:
 			throw new ExceptionUnsupportedMediaType(type);
-		}
+		}*/
 
 		URL serverUrl = new URL(Config.collect().url() + "/o2_collect_assemble/jaxrs/document/to/pdf");
 
@@ -110,7 +110,7 @@ public class DocumentTools {
 
 		Config.collect().validate();
 
-		Tika tika = new Tika();
+		/*Tika tika = new Tika();
 		String type = tika.detect(bytes, fileName);
 
 		switch (Objects.toString(type, "")) {
@@ -120,7 +120,7 @@ public class DocumentTools {
 			break;
 		default:
 			throw new ExceptionUnsupportedMediaType(type);
-		}
+		}*/
 
 		URL serverUrl = new URL(Config.collect().url() + "/o2_collect_assemble/jaxrs/document/to/image");
 
@@ -438,4 +438,4 @@ public class DocumentTools {
 	}
 
 
-}
+}

+ 4 - 2
o2server/x_processplatform_assemble_surface/src/main/java/com/x/processplatform/assemble/surface/jaxrs/attachment/ActionPreviewImage.java

@@ -40,8 +40,10 @@ class ActionPreviewImage extends BaseAction {
 			}
 		}
 		String key = "";
+		StorageMapping mapping = ThisApplication.context().storageMappings().get(Attachment.class,
+				attachment.getStorage());
+		byte[] bytes = DocumentTools.toPdf(attachment.getName(), attachment.readContent(mapping), "");
 		try (EntityManagerContainer emc = EntityManagerContainerFactory.instance().create()) {
-			byte[] bytes = DocumentTools.toImage(attachment.getName(), attachment.getBytes(), "", page);
 			String name = FilenameUtils.getBaseName(attachment.getName()) + ".png";
 			StorageMapping gfMapping = ThisApplication.context().storageMappings().random(GeneralFile.class);
 			GeneralFile generalFile = new GeneralFile(gfMapping.getName(), name, effectivePerson.getDistinguishedName());
@@ -63,4 +65,4 @@ class ActionPreviewImage extends BaseAction {
 
 	}
 
-}
+}

+ 1 - 6
o2server/x_processplatform_assemble_surface/src/main/java/com/x/processplatform/assemble/surface/jaxrs/attachment/ActionPreviewImageResult.java

@@ -32,11 +32,6 @@ class ActionPreviewImageResult extends BaseAction {
 				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 ExceptionPreviewImageResultObject(flag);
 			}
@@ -54,4 +49,4 @@ class ActionPreviewImageResult extends BaseAction {
 
 	}
 
-}
+}

+ 4 - 2
o2server/x_processplatform_assemble_surface/src/main/java/com/x/processplatform/assemble/surface/jaxrs/attachment/ActionPreviewPdf.java

@@ -43,8 +43,10 @@ class ActionPreviewPdf extends BaseAction {
 			}
 		}
 		String key = "";
+		StorageMapping mapping = ThisApplication.context().storageMappings().get(Attachment.class,
+				attachment.getStorage());
+		byte[] bytes = DocumentTools.toPdf(attachment.getName(), attachment.readContent(mapping), "");
 		try (EntityManagerContainer emc = EntityManagerContainerFactory.instance().create()) {
-			byte[] bytes = DocumentTools.toPdf(attachment.getName(), attachment.getBytes(), "");
 			String name = FilenameUtils.getBaseName(attachment.getName()) + ".pdf";
 			StorageMapping gfMapping = ThisApplication.context().storageMappings().random(GeneralFile.class);
 			GeneralFile generalFile = new GeneralFile(gfMapping.getName(), name, effectivePerson.getDistinguishedName());
@@ -65,4 +67,4 @@ class ActionPreviewPdf extends BaseAction {
 
 	}
 
-}
+}

+ 1 - 6
o2server/x_processplatform_assemble_surface/src/main/java/com/x/processplatform/assemble/surface/jaxrs/attachment/ActionPreviewPdfResult.java

@@ -34,11 +34,6 @@ class ActionPreviewPdfResult extends BaseAction {
 				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 ExceptionPreviewImageResultObject(flag);
 			}
@@ -56,4 +51,4 @@ class ActionPreviewPdfResult extends BaseAction {
 
 	}
 
-}
+}