提交 eef908ae 编写于 作者: O o2null

Merge branch 'cherry-pick-4a44356a' into 'hotfix/cloud_doc_pdf'

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

See merge request o2oa/o2oa!3133
......@@ -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;
}
}
\ No newline at end of file
}
......@@ -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 {
}
}
\ No newline at end of file
}
......@@ -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 {
}
}
\ No newline at end of file
}
......@@ -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 {
}
}
\ No newline at end of file
}
......@@ -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 {
}
}
\ No newline at end of file
}
......@@ -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 {
}
}
\ No newline at end of file
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册