Browse Source

KERNEL-8675 新引擎插件代码修改同步到11.0的内置新引擎中

fix-lag
loy 3 years ago
parent
commit
808783b8b5
  1. 37
      designer-base/src/main/java/com/fr/nx/app/designer/cptx/io/DesignReadWritableProvider.java
  2. 3
      designer-base/src/main/java/com/fr/nx/app/designer/toolbar/TemplateTransformer.java
  3. 79
      designer-base/src/main/java/com/fr/nx/app/designer/utils/DesignerCptxFileUtils.java
  4. 6
      designer-realize/src/main/java/com/fr/nx/app/designer/CptxApp.java
  5. 4
      designer-realize/src/main/java/com/fr/nx/app/designer/JStreamBook.java
  6. 16
      designer-realize/src/test/java/com/fr/nx/app/designer/CptxAppTest.java

37
designer-base/src/main/java/com/fr/nx/app/designer/cptx/io/DesignReadWritableProvider.java

@ -2,14 +2,9 @@ package com.fr.nx.app.designer.cptx.io;
import com.fr.common.annotations.Negative;
import com.fr.file.FILE;
import com.fr.nx.app.designer.utils.DesignerCptxFileUtils;
import com.fr.nx.cptx.io.handle.impl.AbstractCptxIOProvider;
import com.fr.nx.cptx.pack.util.CompiledReportInputStream;
import com.fr.nx.cptx.io.handle.impl.CompileToPathCptxIOProvider;
import com.fr.nx.cptx.pack.util.CompiledReportOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import com.fr.nx.cptx.utils.CptxFileUtils;
/**
* 用于设计器保存编译后的结果并缓存可web预览模版
@ -20,41 +15,21 @@ import java.io.OutputStream;
* @Description: 用于cptx写操作的Provider
*/
@Negative(until = "2020-05-10")
public class DesignReadWritableProvider extends AbstractCptxIOProvider {
public class DesignReadWritableProvider extends CompileToPathCptxIOProvider {
/**
* 原文件
*/
private final FILE file;
/**
* 编译文件夹
*/
private final String compileDir;
private CompiledReportOutputStream outputStream;
public DesignReadWritableProvider(FILE file) {
super(CptxFileUtils.getFormatPath(file.getPath()));
this.file = file;
this.compileDir = DesignerCptxFileUtils.generateCompileDir(file);
}
@Override
public InputStream open() throws Exception {
if (outputStream == null) {
throw new IOException("can not read cptx template before compile");
}
return new CompiledReportInputStream(outputStream.toByteArray());
}
/**
* 对于写操作用到的只有这个方法以流形式来操作
*
* @return 保存的目标输出流
* @throws Exception e
*/
@Override
public OutputStream createTemp() throws Exception {
outputStream = new CompiledReportOutputStream(file.asOutputStream(), compileDir);
return outputStream;
public CompiledReportOutputStream outputOpen() throws Exception {
return new CompiledReportOutputStream(file.asOutputStream(), getCompilePath());
}
}

3
designer-base/src/main/java/com/fr/nx/app/designer/toolbar/TemplateTransformer.java

@ -206,9 +206,8 @@ public enum TemplateTransformer {
// 读取可 web 预览模版并缓存
try {
// todo 是否考虑异步
String timestampedPath = CptxFileUtils.getTimestampedPath(file.getPath());
CptxTemplate previewCptxTemplate = CptxIOManager.open(cptx).getTemplate();
CptxTemplatePool.getInstance().addCptxTemplate(timestampedPath, previewCptxTemplate);
CptxTemplatePool.getInstance().addCptxTemplate(CptxFileUtils.getFormatPath(file.getPath()), previewCptxTemplate);
} catch (Exception e) {
FineLoggerFactory.getLogger().error(e.getMessage(), e);
}

79
designer-base/src/main/java/com/fr/nx/app/designer/utils/DesignerCptxFileUtils.java

@ -1,79 +0,0 @@
package com.fr.nx.app.designer.utils;
import com.fr.file.FILE;
import com.fr.general.CommonIOUtils;
import com.fr.log.FineLoggerFactory;
import com.fr.main.impl.WorkBook;
import com.fr.nx.marshal.impl.xml.DefaultXMLObjectUnmarshaler;
import com.fr.nx.marshal.util.MarshalUtil;
import com.fr.nx.cptx.entry.metadata.CptxMetadata;
import com.fr.nx.cptx.io.handle.impl.OriginCptProvider;
import com.fr.nx.cptx.marshal.util.CptxMarshalUtil;
import com.fr.nx.cptx.utils.CptxFileUtils;
import com.fr.stable.EncodeConstants;
import com.fr.stable.StableUtils;
import com.fr.stable.xml.XMLableReader;
import com.fr.workspace.WorkContext;
import java.io.ByteArrayOutputStream;
import java.io.InputStream;
import java.io.InputStreamReader;
/**
* Created by loy on 2021/1/18.
*
* <p>用于设计器的cptx的一些工具类
* <p>
*/
public class DesignerCptxFileUtils {
/**
* 根据file来获取cptx中的cpt
* @param file
* @return
*/
public static WorkBook getWorkBook(final FILE file){
try (InputStream input = file.asInputStream();
ByteArrayOutputStream outputStream = new ByteArrayOutputStream()) {
CommonIOUtils.copyBinaryTo(input, outputStream);
OriginCptProvider provider = new OriginCptProvider(outputStream.toByteArray());
return CptxFileUtils.getWorkBook(provider);
} catch (Exception e) {
FineLoggerFactory.getLogger().error(e.getMessage(), e);
}
return null;
}
/**
* 获取模板的元数据
* @param file
* @return
*/
public static CptxMetadata getMetadata(FILE file){
try {
String metadataPath = StableUtils.pathJoin(generateCompileDir(file), CptxMarshalUtil.NAME_METADATA);
if(!WorkContext.getWorkResource().exist(metadataPath)){
return null;
}
InputStream metadataInput = WorkContext.getWorkResource().openStream(metadataPath);
XMLableReader reader = XMLableReader.createXMLableReader(
new InputStreamReader(metadataInput, EncodeConstants.ENCODING_UTF_8));
CptxMetadata metadata = (CptxMetadata) new DefaultXMLObjectUnmarshaler().unmarshal(
MarshalUtil.createMarshalableExtra(CptxMetadata.class), reader);
return metadata;
} catch (Exception e) {
FineLoggerFactory.getLogger().error(e.getMessage(), e);
}
return null;
}
/**
* 根据文件获取编译后的文件夹绝对路径比如原文件位于reportlets/test/merge.cptx转化后为evn://assets/engine/test/merge文件夹
* @param file
* @return
*/
public static String generateCompileDir(FILE file){
String filePath = file.getPath();
return CptxFileUtils.generateCompileDir(filePath);
}
}

6
designer-realize/src/main/java/com/fr/nx/app/designer/CptxApp.java

@ -5,7 +5,7 @@ import com.fr.design.mainframe.AbstractAppProvider;
import com.fr.design.mainframe.JTemplate;
import com.fr.file.FILE;
import com.fr.main.impl.WorkBook;
import com.fr.nx.app.designer.utils.DesignerCptxFileUtils;
import com.fr.nx.cptx.utils.CptxFileUtils;
/**
* 支持设计器打开cptx文件
@ -35,7 +35,7 @@ public class CptxApp extends AbstractAppProvider<WorkBook> {
*/
@Override
public JTemplate<WorkBook, ?> openTemplate(FILE tplFile) {
WorkBook workBook = DesignerCptxFileUtils.getWorkBook(tplFile);
WorkBook workBook = CptxFileUtils.getWorkBook(CptxFileUtils.getFormatPath(tplFile.getPath()));
if (workBook == null) {
workBook = new WorkBook();
}
@ -44,7 +44,7 @@ public class CptxApp extends AbstractAppProvider<WorkBook> {
@Override
public WorkBook asIOFile(FILE file) {
WorkBook workBook = DesignerCptxFileUtils.getWorkBook(file);
WorkBook workBook = CptxFileUtils.getWorkBook(CptxFileUtils.getFormatPath(file.getPath()));
if (workBook == null) {
workBook = new WorkBook();
}

4
designer-realize/src/main/java/com/fr/nx/app/designer/JStreamBook.java

@ -14,12 +14,12 @@ import com.fr.general.ComparatorUtils;
import com.fr.locale.InterProviderFactory;
import com.fr.log.FineLoggerFactory;
import com.fr.main.impl.WorkBook;
import com.fr.nx.app.designer.utils.DesignerCptxFileUtils;
import com.fr.nx.cptx.entry.metadata.CptxMetadata;
import com.fr.nx.app.designer.menu.CalculateAttrAction;
import com.fr.nx.app.designer.toolbar.TemplateTransformer;
import com.fr.nx.app.designer.toolbar.TransformResult;
import com.fr.nx.app.designer.toolbar.TransformResultInfo;
import com.fr.nx.cptx.utils.CptxFileUtils;
import com.fr.stable.StringUtils;
import com.fr.stable.project.ProjectConstants;
import com.fr.third.jodd.util.ArraysUtil;
@ -103,7 +103,7 @@ public class JStreamBook extends JWorkBook {
}
private String getSuffix() {
CptxMetadata metadata = DesignerCptxFileUtils.getMetadata(this.getEditingFILE());
CptxMetadata metadata = CptxFileUtils.getMetadata(this.getEditingFILE().getPath());
if (metadata != null && metadata.isForceCpt()) {
return InterProviderFactory.getProvider().getLocText("Fine-Plugin_Engine_Compatibility_Mode");
}

16
designer-realize/src/test/java/com/fr/nx/app/designer/CptxAppTest.java

@ -3,7 +3,7 @@ package com.fr.nx.app.designer;
import com.fr.file.AbstractFILE;
import com.fr.file.FILE;
import com.fr.main.impl.WorkBook;
import com.fr.nx.app.designer.utils.DesignerCptxFileUtils;
import com.fr.nx.cptx.utils.CptxFileUtils;
import org.easymock.EasyMock;
import org.junit.Assert;
import org.junit.FixMethodOrder;
@ -21,7 +21,7 @@ import org.powermock.modules.junit4.PowerMockRunnerDelegate;
@RunWith(PowerMockRunner.class)
@PowerMockRunnerDelegate(JUnit4.class)
@PrepareForTest({
DesignerCptxFileUtils.class
CptxFileUtils.class
})
public class CptxAppTest {
@ -34,20 +34,24 @@ public class CptxAppTest {
@Test
public void testAsIOFile() {
PowerMock.mockStatic(DesignerCptxFileUtils.class);
PowerMock.mockStatic(CptxFileUtils.class);
FILE file = new AbstractFILE() {
@Override
public String getPath() {
return "path/to/file.cpt";
}
};
WorkBook workBook = new WorkBook();
EasyMock.expect(DesignerCptxFileUtils.getWorkBook(file))
EasyMock.expect(CptxFileUtils.getWorkBook(file.getPath()))
.andReturn(workBook).once()
.andReturn(null).once();
PowerMock.replay(DesignerCptxFileUtils.class);
PowerMock.replay(CptxFileUtils.class);
Assert.assertSame(workBook, new CptxApp().asIOFile(file));
Assert.assertNotNull(new CptxApp().asIOFile(file));
PowerMock.verify(DesignerCptxFileUtils.class);
PowerMock.verify(CptxFileUtils.class);
}

Loading…
Cancel
Save