|
|
@ -7,17 +7,15 @@ import com.fr.design.extra.Process; |
|
|
|
import com.fr.design.i18n.Toolkit; |
|
|
|
import com.fr.design.i18n.Toolkit; |
|
|
|
import com.fr.design.login.DesignerLoginHelper; |
|
|
|
import com.fr.design.login.DesignerLoginHelper; |
|
|
|
import com.fr.design.login.DesignerLoginSource; |
|
|
|
import com.fr.design.login.DesignerLoginSource; |
|
|
|
import com.fr.design.mainframe.DesignerContext; |
|
|
|
|
|
|
|
import com.fr.design.mainframe.alphafine.AlphaFineHelper; |
|
|
|
import com.fr.design.mainframe.alphafine.AlphaFineHelper; |
|
|
|
import com.fr.design.mainframe.alphafine.model.TemplateResource; |
|
|
|
import com.fr.design.mainframe.alphafine.model.TemplateResource; |
|
|
|
import com.fr.design.mainframe.alphafine.search.helper.FineMarketClientHelper; |
|
|
|
import com.fr.design.mainframe.alphafine.search.helper.FineMarketClientHelper; |
|
|
|
import com.fr.design.mainframe.toast.SimpleToast; |
|
|
|
import com.fr.design.mainframe.toast.SimpleToast; |
|
|
|
import com.fr.file.FileFILE; |
|
|
|
|
|
|
|
import com.fr.log.FineLoggerFactory; |
|
|
|
import com.fr.log.FineLoggerFactory; |
|
|
|
import com.fr.third.jodd.io.ZipUtil; |
|
|
|
import com.fr.third.jodd.io.ZipUtil; |
|
|
|
import com.fr.workspace.WorkContext; |
|
|
|
import com.fr.workspace.WorkContext; |
|
|
|
|
|
|
|
|
|
|
|
import java.awt.Desktop; |
|
|
|
import javax.swing.SwingUtilities; |
|
|
|
import java.awt.Window; |
|
|
|
import java.awt.Window; |
|
|
|
import java.io.File; |
|
|
|
import java.io.File; |
|
|
|
import java.io.IOException; |
|
|
|
import java.io.IOException; |
|
|
@ -43,78 +41,50 @@ public class FineMarketDownloadManager { |
|
|
|
|
|
|
|
|
|
|
|
private static final String OPENING_PLEASE_WAIT = Toolkit.i18nText("Fine-Design_Report_AlphaFine_Template_Resource_Opening"); |
|
|
|
private static final String OPENING_PLEASE_WAIT = Toolkit.i18nText("Fine-Design_Report_AlphaFine_Template_Resource_Opening"); |
|
|
|
private static final String DOWNLOAD_FAILED = Toolkit.i18nText("Fine-Design_Report_AlphaFine_Template_Resource_Download_Failed_Check_Network"); |
|
|
|
private static final String DOWNLOAD_FAILED = Toolkit.i18nText("Fine-Design_Report_AlphaFine_Template_Resource_Download_Failed_Check_Network"); |
|
|
|
private static final String REPORTLETS = "/reportlets"; |
|
|
|
|
|
|
|
private static final String ZIP = ".zip"; |
|
|
|
|
|
|
|
private static final String RAR = ".rar"; |
|
|
|
|
|
|
|
private static final String CPT = ".cpt"; |
|
|
|
|
|
|
|
private static final String FRM = ".frm"; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* 下载资源并解压, |
|
|
|
* 下载资源并解压 |
|
|
|
* */ |
|
|
|
* */ |
|
|
|
public void downloadAndOpenTemplateResource(TemplateResource resource, Window parentWindow){ |
|
|
|
public String installResource(TemplateResource resource, Window parentWindow){ |
|
|
|
// 验证登录
|
|
|
|
// 验证登录
|
|
|
|
String token = DesignerEnvManager.getEnvManager().getDesignerLoginRefreshToken(); |
|
|
|
String token = DesignerEnvManager.getEnvManager().getDesignerLoginRefreshToken(); |
|
|
|
if (Strings.isEmpty(token)) { |
|
|
|
if (Strings.isEmpty(token)) { |
|
|
|
DesignerLoginHelper.showLoginDialog(DesignerLoginSource.NORMAL, new HashMap<>(), AlphaFineHelper.getAlphaFineDialog()); |
|
|
|
DesignerLoginHelper.showLoginDialog(DesignerLoginSource.NORMAL, new HashMap<>(), AlphaFineHelper.getAlphaFineDialog()); |
|
|
|
return; |
|
|
|
return null; |
|
|
|
} |
|
|
|
} |
|
|
|
downloadAndOpen(resource, parentWindow); |
|
|
|
return install(resource, parentWindow); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private void downloadAndOpen(TemplateResource resource, Window parentWindow) { |
|
|
|
private String install(TemplateResource resource, Window parentWindow) { |
|
|
|
// 获取报表录作为下载位置
|
|
|
|
// 获取报表录作为下载位置
|
|
|
|
String workDir = WorkContext.getCurrent().getPath() + REPORTLETS; |
|
|
|
String workDir = WorkContext.getCurrent().getPath() + FineMarketConstants.REPORTLETS; |
|
|
|
File destDir = new File(workDir); |
|
|
|
File destDir = new File(workDir); |
|
|
|
|
|
|
|
|
|
|
|
DownloadProcess downloadProcess = new DownloadProcess(parentWindow); |
|
|
|
DownloadProcess downloadProcess = new DownloadProcess(parentWindow); |
|
|
|
String fileName = null; |
|
|
|
String fileName = null; |
|
|
|
try { |
|
|
|
try { |
|
|
|
fileName = FineMarketClientHelper.getInstance().download(resource, destDir, downloadProcess); |
|
|
|
fileName = FineMarketClientHelper.getInstance().download(resource, destDir, downloadProcess); |
|
|
|
open(fileName, downloadProcess); |
|
|
|
unzip(fileName, downloadProcess); |
|
|
|
|
|
|
|
return fileName; |
|
|
|
} catch (Exception e) { |
|
|
|
} catch (Exception e) { |
|
|
|
downloadProcess.process(FineMarketDownloadManager.PROCESS_FAILED); |
|
|
|
downloadProcess.process(FineMarketDownloadManager.PROCESS_FAILED); |
|
|
|
FineLoggerFactory.getLogger().error(e, e.getMessage()); |
|
|
|
FineLoggerFactory.getLogger().error(e, e.getMessage()); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
return null; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void open(String fileName, DownloadProcess process) throws IOException { |
|
|
|
void unzip(String fileName, DownloadProcess process) throws IOException { |
|
|
|
process.process(OPENING_FILE); |
|
|
|
process.process(OPENING_FILE); |
|
|
|
if (Strings.isEmpty(fileName)) { |
|
|
|
|
|
|
|
return; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
File fileNeedOpen = new File(fileName); |
|
|
|
|
|
|
|
if (fileName.endsWith(ZIP)) { |
|
|
|
|
|
|
|
File[] files = unzip(fileName); |
|
|
|
|
|
|
|
fileNeedOpen = getFirstCptOrFrm(files); |
|
|
|
|
|
|
|
} else if (fileName.endsWith(RAR)) { |
|
|
|
|
|
|
|
// rar直接打开系统文件夹
|
|
|
|
|
|
|
|
File parentDir = new File(fileName).getParentFile(); |
|
|
|
|
|
|
|
Desktop.getDesktop().open(parentDir); |
|
|
|
|
|
|
|
return; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
openInDesigner(fileNeedOpen); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private File getFirstCptOrFrm(File[] files) { |
|
|
|
if (fileName.endsWith(FineMarketConstants.ZIP)) { |
|
|
|
for (File f : files) { |
|
|
|
File file = new File(fileName); |
|
|
|
if (f.getName().endsWith(CPT) || f.getName().endsWith(FRM)) { |
|
|
|
File parentDir = file.getParentFile(); |
|
|
|
return f; |
|
|
|
ZipUtil.unzip(file, parentDir); |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
return null; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
File[] unzip(String fileName) throws IOException { |
|
|
|
|
|
|
|
File file = new File(fileName); |
|
|
|
|
|
|
|
File parentDir = file.getParentFile(); |
|
|
|
|
|
|
|
ZipUtil.unzip(file, parentDir); |
|
|
|
|
|
|
|
return parentDir.listFiles(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void openInDesigner(File file) { |
|
|
|
|
|
|
|
DesignerContext.getDesignerFrame().openTemplate(new FileFILE(file)); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
@ -138,13 +108,15 @@ public class FineMarketDownloadManager { |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public void process(Double aDouble) { |
|
|
|
public void process(Double aDouble) { |
|
|
|
if (aDouble == PROCESS_FAILED) { |
|
|
|
SwingUtilities.invokeLater(()->{ |
|
|
|
downloadFailed(); |
|
|
|
if (aDouble == PROCESS_FAILED) { |
|
|
|
} else if (aDouble == PROCESS_SUCCESS) { |
|
|
|
downloadFailed(); |
|
|
|
downloadSuccess(); |
|
|
|
} else if (aDouble == PROCESS_SUCCESS) { |
|
|
|
} else if (aDouble == OPENING_FILE) { |
|
|
|
downloadSuccess(); |
|
|
|
openingFile(); |
|
|
|
} else if (aDouble == OPENING_FILE) { |
|
|
|
} |
|
|
|
openingFile(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public void downloadFailed() { |
|
|
|
public void downloadFailed() { |
|
|
|