forked from fanruan/design
Browse Source
# Conflicts: # designer-realize/src/main/java/com/fr/design/mainframe/messagecollect/StartupMessageCollector.javapersist/11.0
vito
5 years ago
35 changed files with 2297 additions and 1891 deletions
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,70 @@
|
||||
package com.fr.design; |
||||
|
||||
import com.fr.config.dao.DaoContext; |
||||
import com.fr.config.dao.impl.LocalClassHelperDao; |
||||
import com.fr.config.dao.impl.LocalEntityDao; |
||||
import com.fr.config.dao.impl.LocalXmlEntityDao; |
||||
import com.fr.design.fun.ToolbarItemProvider; |
||||
import com.fr.design.gui.core.WidgetOption; |
||||
import com.fr.design.mainframe.JTemplate; |
||||
import com.fr.design.mainframe.JVirtualTemplate; |
||||
import com.fr.general.ModuleContext; |
||||
import com.fr.log.FineLoggerFactory; |
||||
import com.fr.report.restriction.CellCountRestriction; |
||||
import com.fr.report.restriction.ReportRestrictionScene; |
||||
import com.fr.restriction.Restrictions; |
||||
import com.fr.stable.Filter; |
||||
import com.fr.stable.module.Module; |
||||
import junit.framework.TestCase; |
||||
import org.easymock.EasyMock; |
||||
import org.junit.Assert; |
||||
|
||||
import java.util.HashSet; |
||||
import java.util.Set; |
||||
|
||||
/** |
||||
* @author zack |
||||
* @version 10.0 |
||||
* Created by zack on 2019/9/17 |
||||
*/ |
||||
public class ExtraDesignClassManagerTest extends TestCase { |
||||
@Override |
||||
protected void setUp() throws Exception { |
||||
DaoContext.setEntityDao(new LocalEntityDao()); |
||||
DaoContext.setClassHelperDao(new LocalClassHelperDao()); |
||||
DaoContext.setXmlEntityDao(new LocalXmlEntityDao()); |
||||
ModuleContext.startModule(Module.PAGE_MODULE); |
||||
Restrictions.register(ReportRestrictionScene.CELL_COUNT, new CellCountRestriction()); |
||||
} |
||||
|
||||
public void testGetWebOption() { |
||||
try { |
||||
final JTemplate jTemplate = new JVirtualTemplate(null); |
||||
ToolbarItemProvider item = EasyMock.mock(ToolbarItemProvider.class); |
||||
ToolbarItemProvider item1 = EasyMock.mock(ToolbarItemProvider.class); |
||||
EasyMock.expect(item.accept(jTemplate)).andReturn(false).anyTimes(); |
||||
EasyMock.expect(item.classForWidget()).andReturn(null).anyTimes(); |
||||
EasyMock.expect(item.iconPathForWidget()).andReturn("").anyTimes(); |
||||
EasyMock.expect(item.nameForWidget()).andReturn("1").anyTimes(); |
||||
EasyMock.expect(item1.accept(jTemplate)).andReturn(true).anyTimes(); |
||||
EasyMock.expect(item1.classForWidget()).andReturn(null).anyTimes(); |
||||
EasyMock.expect(item1.iconPathForWidget()).andReturn("").anyTimes(); |
||||
EasyMock.expect(item1.nameForWidget()).andReturn("2").anyTimes(); |
||||
EasyMock.replay(item); |
||||
EasyMock.replay(item1); |
||||
|
||||
Set<ToolbarItemProvider> set = new HashSet<>(); |
||||
set.add(item); |
||||
set.add(item1); |
||||
WidgetOption[] widgetOptions = ExtraDesignClassManager.getInstance().getWebWidgetOptions(set, new Filter<ToolbarItemProvider>() { |
||||
@Override |
||||
public boolean accept(ToolbarItemProvider toolbarItemProvider) { |
||||
return toolbarItemProvider.accept(jTemplate); |
||||
} |
||||
}); |
||||
Assert.assertEquals(1, widgetOptions.length); |
||||
} catch (Exception e) { |
||||
FineLoggerFactory.getLogger().error(e.getMessage(), e); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,18 @@
|
||||
package com.fr.design.mainframe.messagecollect.solid; |
||||
|
||||
/** |
||||
* Created by alex sung on 2019/9/5. |
||||
*/ |
||||
public class SolidCollectConstants { |
||||
private SolidCollectConstants(){} |
||||
|
||||
/** |
||||
* 客户端请求subject |
||||
*/ |
||||
public static final String REQUEST_SUBJECT = "solid"; |
||||
|
||||
/** |
||||
* 客户端请求超时鉴权时间,默认1h失效 |
||||
*/ |
||||
public static final long TIME_OUT = 60 * 60 * 1000; |
||||
} |
@ -0,0 +1,97 @@
|
||||
package com.fr.design.mainframe.messagecollect.solid; |
||||
|
||||
import com.fr.general.CloudCenter; |
||||
import com.fr.general.http.HttpToolbox; |
||||
import com.fr.json.JSON; |
||||
import com.fr.json.JSONFactory; |
||||
import com.fr.log.FineLoggerFactory; |
||||
import com.fr.security.JwtUtils; |
||||
import com.fr.stable.CommonUtils; |
||||
import com.fr.stable.StringUtils; |
||||
import com.fr.workspace.WorkContext; |
||||
|
||||
import java.io.IOException; |
||||
import java.util.HashMap; |
||||
import java.util.Map; |
||||
|
||||
import static com.fr.design.mainframe.messagecollect.solid.SolidCollectConstants.REQUEST_SUBJECT; |
||||
import static com.fr.design.mainframe.messagecollect.solid.SolidCollectConstants.TIME_OUT; |
||||
|
||||
/** |
||||
* 设计器固化信息回传类 |
||||
* Created by alex sung on 2019/8/22. |
||||
*/ |
||||
|
||||
|
||||
public class SolidCollector { |
||||
private static final String CONTENT_URL = "/v10/collect/solid"; |
||||
private static final String DELETE_URL = "/v10/collect/solid/delete"; |
||||
private static final String UNLOCK_URL = "/v10/collect/solid/unlock"; |
||||
private static final String ATTR_CIPHER_TEXT = "cipherText"; |
||||
private static final String ATTR_SIGNATURE = "signature"; |
||||
private static final String SOLID_UPLOAD_URL = CloudCenter.getInstance().acquireUrlByKind("design.solid"); |
||||
|
||||
private static volatile SolidCollector instance; |
||||
|
||||
public static SolidCollector getInstance() { |
||||
if (instance == null) { |
||||
synchronized (SolidCollector.class) { |
||||
if (instance == null) { |
||||
instance = new SolidCollector(); |
||||
} |
||||
} |
||||
} |
||||
return instance; |
||||
} |
||||
|
||||
/** |
||||
* 回传文件给云中心,并删除服务端本地文件 |
||||
*/ |
||||
public void sendToCloudCenterAndDeleteFile() { |
||||
if (WorkContext.getCurrent().isLocal()) { |
||||
return; |
||||
} |
||||
FineLoggerFactory.getLogger().info("start to get solid content from server..."); |
||||
try { |
||||
String content = requestContent(); |
||||
if (StringUtils.isNotEmpty(content)) { |
||||
String cipherText = JSONFactory.createJSON(JSON.OBJECT, content).optString("data"); |
||||
if(StringUtils.isNotEmpty(cipherText)){ |
||||
Map<String, Object> params = new HashMap<>(); |
||||
params.put(ATTR_CIPHER_TEXT, cipherText); |
||||
params.put(ATTR_SIGNATURE, String.valueOf(CommonUtils.signature())); |
||||
HttpToolbox.post(SOLID_UPLOAD_URL, params); |
||||
|
||||
String deleteUrl = WorkContext.getCurrent().getPath() + DELETE_URL; |
||||
HttpToolbox.post(deleteUrl, getParams()); |
||||
} |
||||
} |
||||
FineLoggerFactory.getLogger().info("send solid content to cloud center success."); |
||||
} catch (Exception e) { |
||||
FineLoggerFactory.getLogger().info(e.getMessage(), e); |
||||
} finally { |
||||
String unlockUrl = WorkContext.getCurrent().getPath() + UNLOCK_URL; |
||||
try { |
||||
HttpToolbox.post(unlockUrl, getParams()); |
||||
} catch (IOException e) { |
||||
FineLoggerFactory.getLogger().warn(e.getMessage(), e); |
||||
} |
||||
} |
||||
} |
||||
|
||||
/** |
||||
* 获取服务端固化文件内容 |
||||
* @return 回传内容 |
||||
*/ |
||||
public String requestContent() throws Exception { |
||||
Map<String, String> params = new HashMap<String, String>(); |
||||
params.put("token", JwtUtils.createDefaultJWT(REQUEST_SUBJECT, TIME_OUT)); |
||||
return HttpToolbox.get(WorkContext.getCurrent().getPath() + CONTENT_URL, params); |
||||
} |
||||
|
||||
private Map<String, Object> getParams() { |
||||
Map<String, Object> params = new HashMap<String, Object>(); |
||||
params.put("token", JwtUtils.createDefaultJWT(REQUEST_SUBJECT, TIME_OUT)); |
||||
return params; |
||||
} |
||||
} |
Loading…
Reference in new issue