Compare commits

...

20 Commits

Author SHA1 Message Date
richie 298d68108e Merge pull request '修改pom文件中仓库位置' (#12) from onlyxx/finekit:master into master 3 years ago
左良 8304ca3fca 修改pom文件中仓库位置 3 years ago
fanglei d478c5195c Pull request #48: REPORT-51953 【设计器埋点】userid应该记录论坛用户的id而不是用户名 4 years ago
方磊 6c6d508a4d REPORT-51953 【设计器埋点】userid应该记录论坛用户的id而不是用户名 4 years ago
fanglei e2e8e2ae9b Pull request #47: REPORT-50207 埋点插件需要用到的一些后台方法封装到Finekit中 4 years ago
方磊 d7b8d62996 REPORT-50207 埋点插件需要用到的一些后台方法封装到Finekit中 4 years ago
fanglei dfd16cb126 Pull request #46: REPORT-50744 在FineKit增加根据JTemplate对象获取templateId的方法 4 years ago
方磊 198f73b578 REPORT-50744 用JTemplateProvider替代JTemplate 4 years ago
方磊 7013e6461f REPORT-50744 补上注释 4 years ago
方磊 649edf31f9 REPORT-50744 在FineKit增加根据JTemplate对象获取templateId的方法 4 years ago
fanglei 2f51c2b3c0 Pull request #45: REPORT-50744 在FineKit增加获取当前模板ID的方法和获取设计器ID的方法 4 years ago
方磊 b6778538bc REPORT-50744 在FineKit增加获取当前模板ID的方法和获取设计器ID的方法 4 years ago
richie 6df075061c 增加数据集lock特性 4 years ago
richie 30b5970252 Merge pull request 'REPORT-47782 数据集-数据连接-数据集界面的数据连接按钮,鼠标悬浮时的提示不对' (#10) from yvan/finekit:master into master 4 years ago
Yvan 521dd29c3e REPORT-47782 数据集-数据连接-数据集界面的数据连接按钮,鼠标悬浮时的提示不对 4 years ago
richie 8280abdf3b Merge pull request 'WIP REPORT-39459 json数据集-传参方式从get改为post-raw,参数的值没有保留' (#9) from Lucian.Chen/finekit:master into master 4 years ago
lucian c8fb5454f3 REPORT-39459 json数据集-传参方式从get改为post-raw,参数的值没有保留 4 years ago
richie 22c28b7090 Merge pull request 'REPORT-43833 【10.0.14】远程设计数据连接/服务器数据集增加锁定' (#6) from yvan/finekit:master into master 4 years ago
Yvan a1900cf1ba REPORT-43833 【10.0.14】远程设计数据连接/服务器数据集增加锁定 4 years ago
richie eaf185c3ed Merge pull request '无 jira 任务 fix: 之前的commit无故丢失,重构内心补上' (#5) from Dylan.Liu/finekit:master into master 4 years ago
  1. 4
      pom.xml
  2. 32
      src/main/java/com/fanruan/api/cal/ParameterKit.java
  3. 23
      src/main/java/com/fanruan/api/conf/MarketConfigKit.java
  4. 50
      src/main/java/com/fanruan/api/design/DesignKit.java
  5. 55
      src/main/java/com/fanruan/api/design/ui/component/UILockButton.java
  6. 38
      src/main/java/com/fanruan/api/design/work/ConnectionComboBoxPanel.java
  7. 50
      src/main/java/com/fanruan/api/design/work/compat/ConnectionLockHelper.java
  8. 122
      src/main/java/com/fanruan/api/design/work/component/ItemEditableComboBoxPanel.java
  9. 9
      src/main/java/com/fanruan/api/macro/ProductConstants.java
  10. 60
      src/main/java/com/fanruan/api/net/http/HttpKit.java
  11. 9
      src/main/java/com/fanruan/api/runtime/EnvKit.java
  12. 49
      src/test/java/com/fanruan/api/cal/ParameterKitTest.java

4
pom.xml

@ -176,7 +176,7 @@
<repository> <repository>
<id>fanruan</id> <id>fanruan</id>
<name>fanruan</name> <name>fanruan</name>
<url>http://mvn.finedevelop.com/repository/maven-public/</url> <url>https://mvn.fanruan.com/repository/maven-public/</url>
<snapshots> <snapshots>
<enabled>true</enabled> <enabled>true</enabled>
<updatePolicy>always</updatePolicy> <updatePolicy>always</updatePolicy>
@ -188,7 +188,7 @@
<pluginRepository> <pluginRepository>
<id>fanruan</id> <id>fanruan</id>
<name>fanruan</name> <name>fanruan</name>
<url>http://mvn.finedevelop.com/repository/maven-public/</url> <url>https://mvn.fanruan.com/repository/maven-public/</url>
<snapshots> <snapshots>
<enabled>true</enabled> <enabled>true</enabled>
<updatePolicy>always</updatePolicy> <updatePolicy>always</updatePolicy>

32
src/main/java/com/fanruan/api/cal/ParameterKit.java

@ -21,6 +21,7 @@ import com.fr.stable.script.NameSpace;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import java.util.Date; import java.util.Date;
import java.util.List;
import java.util.Map; import java.util.Map;
/** /**
@ -147,6 +148,37 @@ public class ParameterKit {
return parameters; return parameters;
} }
/**
* 获得参数并集将新的参数拼接在后面
*
* @param paramTexts sql语句
* @param ps 旧的参数集合
* @return 新参数集合
*/
public static ParameterProvider[] analyzeAndMergeParameters(String[] paramTexts, ParameterProvider[] ps) {
ParameterProvider[] parameters = ParameterKit.analyze4Parameters(paramTexts, false);
if (ArrayKit.isEmpty(parameters) || ArrayKit.isEmpty(ps)) {
return ArrayUtils.addAll(ps, parameters);
}
List<ParameterProvider> psList = ArrayKit.toList(ps);
// 检查ps中是否有parameter,如果没有就加进去
for (ParameterProvider parameter : parameters) {
for (int i = 0; i < ps.length; i ++) {
if (AssistKit.equals(ps[i].getName(), parameter.getName())) {
break;
}
else if (i >= ps.length - 1) {
psList.add(parameter);
}
}
}
return psList.toArray(new ParameterProvider[0]);
}
/** /**
* 增加处理数据集间联系例如select * from t where time=${today()} * 增加处理数据集间联系例如select * from t where time=${today()}
* *

23
src/main/java/com/fanruan/api/conf/MarketConfigKit.java

@ -0,0 +1,23 @@
package com.fanruan.api.conf;
import com.fr.config.MarketConfig;
public class MarketConfigKit {
/**
* 获取服务器appId
*
* @return appId
*/
public static String getAppId() {
return MarketConfig.getInstance().getCloudOperationMaintenanceId();
}
/**
* 获取已登录帆软市场的用户名
*
* @return userId
*/
public static long getUserId() {
return MarketConfig.getInstance().getBbsUid();
}
}

50
src/main/java/com/fanruan/api/design/DesignKit.java

@ -1,5 +1,8 @@
package com.fanruan.api.design; package com.fanruan.api.design;
import com.fr.base.io.BaseBook;
import com.fr.design.DesignerEnvManager;
import com.fr.design.mainframe.JTemplateProvider;
import com.fr.design.mainframe.WidgetPropertyPane; import com.fr.design.mainframe.WidgetPropertyPane;
import com.fr.base.TableData; import com.fr.base.TableData;
import com.fr.design.DesignModelAdapter; import com.fr.design.DesignModelAdapter;
@ -12,6 +15,7 @@ import com.fr.design.mainframe.DesignerContext;
import com.fr.design.mainframe.DesignerFrame; import com.fr.design.mainframe.DesignerFrame;
import com.fr.design.mainframe.HyperlinkGroupPaneActionImpl; import com.fr.design.mainframe.HyperlinkGroupPaneActionImpl;
import com.fr.design.mainframe.JTemplate; import com.fr.design.mainframe.JTemplate;
import com.fr.module.ModuleContext;
import javax.swing.JComponent; import javax.swing.JComponent;
@ -64,6 +68,43 @@ public class DesignKit {
return HistoryTemplateListPane.getInstance().getCurrentEditingTemplate(); return HistoryTemplateListPane.getInstance().getCurrentEditingTemplate();
} }
/**
* 获取当前正在编辑的模板的ID
*
* @return 正在编辑的模板的ID
*/
public static String getCurrentEditingTemplateId() {
return getCurrentEditingTemplate().getTarget().getTemplateID();
}
/**
* 获取指定模板的ID
*
* @param template 指定模板
* @return 模板ID
*/
public static String getTemplateId(JTemplateProvider template) {
return ((BaseBook) template.getTarget()).getTemplateID();
}
/**
* 获取设计器ID
*
* @return 设计器ID
*/
public static String getDesignerId() {
return DesignerEnvManager.getEnvManager().getUUID();
}
/**
* 获取注册码
*
* @return 注册码
*/
public static String getActivationKey() {
return DesignerEnvManager.getEnvManager().getActivationKey();
}
/** /**
* 根据名字获取已经定义的bean对象 * 根据名字获取已经定义的bean对象
* *
@ -97,4 +138,13 @@ public class DesignKit {
public static JComponent getWidgetComponent() { public static JComponent getWidgetComponent() {
return (JComponent) (WidgetPropertyPane.getInstance().getEditingFormDesigner().getSelectionModel().getSelection().getSelectedCreator()).getComponent(0); return (JComponent) (WidgetPropertyPane.getInstance().getEditingFormDesigner().getSelectionModel().getSelection().getSelectedCreator()).getComponent(0);
} }
/**
* 设计器是否启动
*
* @return isStartup
*/
public static boolean isStartup() {
return ModuleContext.isDesignerStartup();
}
} }

55
src/main/java/com/fanruan/api/design/ui/component/UILockButton.java

@ -0,0 +1,55 @@
package com.fanruan.api.design.ui.component;
import com.fr.design.editlock.EditLockChangeEvent;
import com.fr.design.editlock.EditLockChangeListener;
import com.fr.design.editlock.EditLockUtils;
import com.fr.report.LockItem;
import javax.swing.*;
/**
* @author Yvan
* @version 10.0
* Created by Yvan on 2021/1/20
*/
public class UILockButton extends UIButton implements EditLockChangeListener {
/**
* 锁定状态图标
*/
private final Icon lockedIcon;
/**
* 正常状态图标
*/
private final Icon normalIcon;
/**
* 锁定状态的提示信息
*/
private final String lockedTooltips;
/**
* 正常状态的提示信息
*/
private final String normalTooltips;
public UILockButton(Icon lockedIcon, Icon normalIcon, String lockedTooltips, String normalTooltips) {
super();
this.lockedIcon = lockedIcon;
this.normalIcon = normalIcon;
this.lockedTooltips = lockedTooltips;
this.normalTooltips = normalTooltips;
init();
}
private void init() {
boolean locked = EditLockUtils.isLocked(LockItem.CONNECTION);
this.setIcon(locked ? lockedIcon : normalIcon);
this.setToolTipText(locked ? lockedTooltips : normalTooltips);
}
@Override
public void updateLockedState(EditLockChangeEvent event) {
this.setIcon(event.isLocked() ? lockedIcon : normalIcon);
this.setToolTipText(event.isLocked() ? lockedTooltips : normalTooltips);
this.repaint();
}
}

38
src/main/java/com/fanruan/api/design/work/ConnectionComboBoxPanel.java

@ -5,6 +5,9 @@ import com.fanruan.api.data.ConnectionKit;
import com.fanruan.api.data.open.BaseConnection; import com.fanruan.api.data.open.BaseConnection;
import com.fanruan.api.design.DesignKit; import com.fanruan.api.design.DesignKit;
import com.fanruan.api.design.macro.DataSourceConstants; import com.fanruan.api.design.macro.DataSourceConstants;
import com.fanruan.api.design.ui.component.UIButton;
import com.fanruan.api.design.work.compat.ConnectionLockHelper;
import com.fanruan.api.design.work.component.ItemEditableComboBoxPanel;
import com.fanruan.api.generic.Runner; import com.fanruan.api.generic.Runner;
import com.fanruan.api.util.AssistKit; import com.fanruan.api.util.AssistKit;
import com.fanruan.api.util.StringKit; import com.fanruan.api.util.StringKit;
@ -12,10 +15,10 @@ import com.fr.data.impl.Connection;
import com.fr.design.DesignerEnvManager; import com.fr.design.DesignerEnvManager;
import com.fr.design.data.datapane.connect.ConnectionListPane; import com.fr.design.data.datapane.connect.ConnectionListPane;
import com.fr.design.data.datapane.connect.ConnectionShowPane; import com.fr.design.data.datapane.connect.ConnectionShowPane;
import com.fr.design.data.datapane.connect.ItemEditableComboBoxPanel;
import com.fr.design.dialog.BasicDialog; import com.fr.design.dialog.BasicDialog;
import com.fr.design.dialog.DialogActionAdapter; import com.fr.design.dialog.DialogActionAdapter;
import com.fr.file.ConnectionConfig; import com.fr.file.ConnectionConfig;
import com.fr.general.GeneralUtils;
import com.fr.stable.NameReference; import com.fr.stable.NameReference;
import com.fr.transaction.WorkerCallBack; import com.fr.transaction.WorkerCallBack;
import com.fr.workspace.WorkContext; import com.fr.workspace.WorkContext;
@ -23,6 +26,7 @@ import com.fr.workspace.server.connection.DBConnectAuth;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
import javax.swing.*; import javax.swing.*;
import java.awt.*;
import java.awt.event.ItemEvent; import java.awt.event.ItemEvent;
import java.awt.event.ItemListener; import java.awt.event.ItemListener;
import java.util.ArrayList; import java.util.ArrayList;
@ -54,6 +58,19 @@ public class ConnectionComboBoxPanel extends ItemEditableComboBoxPanel {
refreshItems(); refreshItems();
} }
@Override
protected UIButton initEditButton(UIButton editButton, Dimension buttonSize) {
if (isChangedVersion()) {
return ConnectionLockHelper.generateLockButton(buttonSize, e -> editItems());
} else {
return super.initEditButton(editButton, buttonSize);
}
}
private boolean isChangedVersion() {
return GeneralUtils.readBuildNO().compareTo("2021.03.15") > 0;
}
protected Iterator<String> items() { protected Iterator<String> items() {
nameList = new ArrayList<>(); nameList = new ArrayList<>();
Iterator<String> nameIt = ConnectionKit.getConnections().keySet().iterator(); Iterator<String> nameIt = ConnectionKit.getConnections().keySet().iterator();
@ -92,6 +109,12 @@ public class ConnectionComboBoxPanel extends ItemEditableComboBoxPanel {
protected void editItems() { protected void editItems() {
if (isChangedVersion()) {
boolean lock = ConnectionLockHelper.doLock(this);
if (lock) {
return;
}
}
final ConnectionListPane connectionListPane = new ConnectionListPane(); final ConnectionListPane connectionListPane = new ConnectionListPane();
final ConnectionConfig connectionConfig = ConnectionConfig.getInstance(); final ConnectionConfig connectionConfig = ConnectionConfig.getInstance();
ConnectionConfig cloned = connectionConfig.mirror(); ConnectionConfig cloned = connectionConfig.mirror();
@ -119,6 +142,7 @@ public class ConnectionComboBoxPanel extends ItemEditableComboBoxPanel {
@Override @Override
public void afterCommit() { public void afterCommit() {
DesignKit.getDesignerBean("databasename").refreshBeanElement(); DesignKit.getDesignerBean("databasename").refreshBeanElement();
unlock();
} }
@Override @Override
@ -127,11 +151,23 @@ public class ConnectionComboBoxPanel extends ItemEditableComboBoxPanel {
} }
}); });
} }
@Override
public void doCancel() {
super.doCancel();
unlock();
}
}); });
connectionListDialog.setVisible(true); connectionListDialog.setVisible(true);
refreshItems(); refreshItems();
} }
private void unlock() {
if (isChangedVersion()) {
ConnectionLockHelper.unlock();
}
}
/** /**
* @param connection 数据库链接 * @param connection 数据库链接
*/ */

50
src/main/java/com/fanruan/api/design/work/compat/ConnectionLockHelper.java

@ -0,0 +1,50 @@
package com.fanruan.api.design.work.compat;
import com.fanruan.api.design.ui.component.UIButton;
import com.fanruan.api.design.ui.component.UILockButton;
import com.fr.base.svg.IconUtils;
import com.fr.design.editlock.ConnectionLockChangeChecker;
import com.fr.design.editlock.EditLockUtils;
import com.fr.report.LockItem;
import java.awt.*;
import java.awt.event.ActionListener;
/**
* @author richie
* @version 10.0
* Created by richie on 2021/3/18
* 用于兼容没有数据连接lock的版本
*/
public class ConnectionLockHelper {
public static UIButton generateLockButton(Dimension buttonSize, ActionListener listener) {
UILockButton editButton = new UILockButton(
EditLockUtils.CONNECTION_LOCKED_ICON,
IconUtils.readIcon("/com/fr/design/images/m_web/connection"),
EditLockUtils.CONNECTION_LOCKED_TOOLTIPS,
null
);
editButton.setPreferredSize(buttonSize);
editButton.addActionListener(listener);
ConnectionLockChangeChecker.getInstance().addEditLockChangeListener(editButton);
return editButton;
}
public static boolean doLock(Component component) {
// 尝试为数据连接加锁
boolean actionLock = EditLockUtils.lock(LockItem.CONNECTION);
if (!actionLock) {
// 锁定失败,代表已经被其他用户锁定,跳出弹窗提示
EditLockUtils.showLockMessage(component);
return true;
}
return false;
}
public static void unlock() {
// 关闭定义数据连接页面,为其解锁
EditLockUtils.unlock(LockItem.CONNECTION);
}
}

122
src/main/java/com/fanruan/api/design/work/component/ItemEditableComboBoxPanel.java

@ -0,0 +1,122 @@
package com.fanruan.api.design.work.component;
import com.fanruan.api.design.ui.component.UIButton;
import com.fanruan.api.design.ui.component.UIComboBox;
import com.fanruan.api.util.IOKit;
import com.fanruan.api.util.StringKit;
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
/**
* @author richie
* @version 10.0
* Created by richie on 2021/3/18
*/
public abstract class ItemEditableComboBoxPanel extends JPanel {
private static final long serialVersionUID = 1L;
protected static final Object EMPTY = new Object() {
public String toString() {
return StringKit.EMPTY;
}
};
protected UIComboBox<?> itemComboBox;
protected UIButton editButton;
protected UIButton refreshButton;
public ItemEditableComboBoxPanel() {
super();
initComponents();
}
protected void initComponents() {
this.setLayout(new BorderLayout(4, 4));
Dimension buttonSize = new Dimension(26, 20);
itemComboBox = new UIComboBox<>();
itemComboBox.setEnabled(true);
this.add(itemComboBox, BorderLayout.CENTER);
refreshButton = new UIButton(IOKit.readIcon("/com/fr/design/images/control/refresh.png"));
JPanel jPanel = new JPanel(new GridLayout(0, 2, 4, 4));
editButton = initEditButton(editButton, buttonSize);
jPanel.add(editButton);
jPanel.add(refreshButton);
this.add(jPanel, BorderLayout.EAST);
refreshButton.setPreferredSize(buttonSize);
refreshButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
refreshItems();
}
});
}
protected UIButton initEditButton(UIButton editButton, Dimension buttonSize) {
editButton = new UIButton(IOKit.readIcon("/com/fr/design/images/control/control-center2.png"));
editButton.setPreferredSize(buttonSize);
editButton.addActionListener(evt -> editItems());
return editButton;
}
/**
* 给itemComboBox添加ActionListener
*/
public void addComboBoxActionListener(ActionListener l) {
itemComboBox.addActionListener(l);
}
protected void refreshItems() {
// 记录原来选中的Item,重新加载后需要再次选中
Object lastSelectedItem = itemComboBox.getSelectedItem();
DefaultComboBoxModel<Object> model = ((DefaultComboBoxModel<Object>) itemComboBox.getModel());
model.removeAllElements();
// 先加EMPTY,再加items
model.addElement(EMPTY);
java.util.Iterator<String> itemIt = items();
while (itemIt.hasNext()) {
model.addElement(itemIt.next());
}
// 再次选中之前选中的Item
int idx = model.getIndexOf(lastSelectedItem);
if (idx < 0) {
idx = 0;
}
itemComboBox.setSelectedIndex(idx);
}
/*
* 得到其中的itemComboBox所选中的Item
*/
public String getSelectedItem() {
Object selected = itemComboBox.getSelectedItem();
return selected instanceof String ? (String) selected : null;
}
/*
* 选中name项
*/
public void setSelectedItem(String name) {
DefaultComboBoxModel model = ((DefaultComboBoxModel) itemComboBox.getModel());
model.setSelectedItem(name);
}
/*
* 刷新ComboBox.items
*/
protected abstract java.util.Iterator<String> items();
/*
* 弹出对话框编辑Items
*/
protected abstract void editItems();
}

9
src/main/java/com/fanruan/api/macro/ProductConstants.java

@ -16,4 +16,13 @@ public class ProductConstants {
* 大的版本号 * 大的版本号
*/ */
public static final String MAIN_VERSION = com.fr.stable.ProductConstants.MAIN_VERSION; public static final String MAIN_VERSION = com.fr.stable.ProductConstants.MAIN_VERSION;
/**
* 获取env路径
*
* @return env路径
*/
public static String getEnvHome() {
return com.fr.stable.ProductConstants.getEnvHome();
}
} }

60
src/main/java/com/fanruan/api/net/http/HttpKit.java

@ -1,20 +1,12 @@
package com.fanruan.api.net.http; package com.fanruan.api.net.http;
import com.fanruan.api.macro.EncodeConstants;
import com.fanruan.api.log.LogKit; import com.fanruan.api.log.LogKit;
import com.fanruan.api.net.http.rs.BaseHttpResponseHandle; import com.fanruan.api.macro.EncodeConstants;
import com.fanruan.api.net.http.rs.HttpRequest; import com.fanruan.api.net.http.rs.HttpRequest;
import com.fanruan.api.net.http.rs.HttpRequestType; import com.fanruan.api.net.http.rs.*;
import com.fanruan.api.net.http.rs.HttpResponseType; import com.fr.json.JSONObject;
import com.fanruan.api.net.http.rs.StreamResponseHandle;
import com.fanruan.api.net.http.rs.TextResponseHandle;
import com.fanruan.api.net.http.rs.UploadResponseHandle;
import com.fr.third.guava.collect.Maps; import com.fr.third.guava.collect.Maps;
import com.fr.third.org.apache.http.HttpEntity; import com.fr.third.org.apache.http.*;
import com.fr.third.org.apache.http.HttpEntityEnclosingRequest;
import com.fr.third.org.apache.http.HttpHost;
import com.fr.third.org.apache.http.NameValuePair;
import com.fr.third.org.apache.http.NoHttpResponseException;
import com.fr.third.org.apache.http.client.HttpRequestRetryHandler; import com.fr.third.org.apache.http.client.HttpRequestRetryHandler;
import com.fr.third.org.apache.http.client.config.RequestConfig; import com.fr.third.org.apache.http.client.config.RequestConfig;
import com.fr.third.org.apache.http.client.entity.UrlEncodedFormEntity; import com.fr.third.org.apache.http.client.entity.UrlEncodedFormEntity;
@ -31,6 +23,7 @@ import com.fr.third.org.apache.http.conn.socket.LayeredConnectionSocketFactory;
import com.fr.third.org.apache.http.conn.socket.PlainConnectionSocketFactory; import com.fr.third.org.apache.http.conn.socket.PlainConnectionSocketFactory;
import com.fr.third.org.apache.http.conn.ssl.SSLConnectionSocketFactory; import com.fr.third.org.apache.http.conn.ssl.SSLConnectionSocketFactory;
import com.fr.third.org.apache.http.entity.FileEntity; import com.fr.third.org.apache.http.entity.FileEntity;
import com.fr.third.org.apache.http.entity.StringEntity;
import com.fr.third.org.apache.http.entity.mime.HttpMultipartMode; import com.fr.third.org.apache.http.entity.mime.HttpMultipartMode;
import com.fr.third.org.apache.http.entity.mime.MultipartEntityBuilder; import com.fr.third.org.apache.http.entity.mime.MultipartEntityBuilder;
import com.fr.third.org.apache.http.impl.client.CloseableHttpClient; import com.fr.third.org.apache.http.impl.client.CloseableHttpClient;
@ -45,20 +38,13 @@ import org.jetbrains.annotations.Nullable;
import javax.net.ssl.SSLContext; import javax.net.ssl.SSLContext;
import javax.net.ssl.SSLException; import javax.net.ssl.SSLException;
import javax.net.ssl.SSLHandshakeException; import javax.net.ssl.SSLHandshakeException;
import java.io.ByteArrayInputStream; import java.io.*;
import java.io.File;
import java.io.IOException;
import java.io.InterruptedIOException;
import java.io.UnsupportedEncodingException;
import java.net.URI; import java.net.URI;
import java.net.URISyntaxException; import java.net.URISyntaxException;
import java.net.URLEncoder; import java.net.URLEncoder;
import java.net.UnknownHostException; import java.net.UnknownHostException;
import java.nio.charset.Charset; import java.nio.charset.Charset;
import java.util.ArrayList; import java.util.*;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import static com.fanruan.api.net.http.rs.HttpRequestType.POST; import static com.fanruan.api.net.http.rs.HttpRequestType.POST;
@ -205,6 +191,30 @@ public class HttpKit {
}); });
} }
/**
* 发起POST JSON请求并获取返回的文本
*
* @param url 响应请求的的服务器地址
* @param params POST请求的参数
* @return 服务器返回的文本内容
*/
public static String postJSON(String url, JSONObject params, Map<String, String> headers) throws IOException {
StringEntity jsonEntity = new StringEntity(params.toString(), "UTF-8");
jsonEntity.setContentEncoding("UTF-8");
if (headers != null) {
headers.put("Content-Type", "application/json");
} else {
headers = new HashMap<>();
headers.put("Content-Type", "application/json");
}
return executeAndParse(HttpRequest
.custom()
.headers(headers)
.url(url)
.post(jsonEntity)
.build());
}
/** /**
* 发起POST请求并获取返回的文本 * 发起POST请求并获取返回的文本
* *
@ -438,6 +448,7 @@ public class HttpKit {
/** /**
* 从指定的地址下载文件 * 从指定的地址下载文件
*
* @param url 文件下载地址 * @param url 文件下载地址
* @return 文件的字节流 * @return 文件的字节流
* @throws IOException 下载过程中出现错误则抛出此异常 * @throws IOException 下载过程中出现错误则抛出此异常
@ -448,10 +459,11 @@ public class HttpKit {
/** /**
* 从指定的地址下载文件 * 从指定的地址下载文件
* @param url 文件下载地址 *
* @param params 参数对 * @param url 文件下载地址
* @param params 参数对
* @param responseEncoding 响应的文件编码 * @param responseEncoding 响应的文件编码
* @param headers 请求头 * @param headers 请求头
* @return 文件的字节流 * @return 文件的字节流
* @throws IOException 下载过程中出现错误则抛出此异常 * @throws IOException 下载过程中出现错误则抛出此异常
*/ */

9
src/main/java/com/fanruan/api/runtime/EnvKit.java

@ -48,4 +48,13 @@ public class EnvKit {
public static void checkout() { public static void checkout() {
SimpleWork.checkOut(); SimpleWork.checkOut();
} }
/**
* 判断工作目录是否是本地
*
* @return isLocal
*/
public static boolean isLocal() {
return WorkContext.getCurrent().isLocal();
}
} }

49
src/test/java/com/fanruan/api/cal/ParameterKitTest.java

@ -150,4 +150,53 @@ public class ParameterKitTest extends Prepare {
"[{\"name\":\"p1\",\"value\":1,\"type\":\"Integer\"},{\"name\":\"p2\",\"value\":\"abc\",\"type\":\"String\"},{\"name\":\"p3\",\"value\":\"=sum(1, 2, 4)\",\"type\":\"String\"}]", "[{\"name\":\"p1\",\"value\":1,\"type\":\"Integer\"},{\"name\":\"p2\",\"value\":\"abc\",\"type\":\"String\"},{\"name\":\"p3\",\"value\":\"=sum(1, 2, 4)\",\"type\":\"String\"}]",
ParameterKit.parameters2Json(providers).toString()); ParameterKit.parameters2Json(providers).toString());
} }
@Test
public void testAnalyzeAndMergeParameters() {
ParameterProvider param1 = ParameterKit.newParameter("test1", "1");
ParameterProvider param2 = ParameterKit.newParameter("test2", "2");
String text1 = "${a}";
String text2 = "${test1}";
ParameterProvider[] parameters1 = ParameterKit.analyzeAndMergeParameters(
new String[]{text1, text2},
new ParameterProvider[] {param1, param2}
);
ParameterProvider[] parameters2 = ParameterKit.analyzeAndMergeParameters(null, null);
ParameterProvider[] parameters3 = ParameterKit.analyzeAndMergeParameters(
null,
new ParameterProvider[] {param1, param2}
);
ParameterProvider[] parameters4 = ParameterKit.analyzeAndMergeParameters(
new String[] {},
new ParameterProvider[] {param1, param2}
);
ParameterProvider[] parameters5 = ParameterKit.analyzeAndMergeParameters(
new String[]{text1, text2},
new ParameterProvider[] {}
);
Assert.assertEquals(parameters1.length, 3);
Assert.assertEquals(parameters1[0], param1);
Assert.assertEquals(parameters1[1], param2);
Assert.assertEquals(parameters1[2].getName(), "a");
Assert.assertEquals(parameters1[2].getValue(), "");
Assert.assertEquals(parameters2.length, 0);
Assert.assertEquals(parameters3.length, 2);
Assert.assertEquals(parameters3[0], param1);
Assert.assertEquals(parameters3[1], param2);
Assert.assertEquals(parameters4.length, 2);
Assert.assertEquals(parameters4[0], param1);
Assert.assertEquals(parameters4[1], param2);
Assert.assertEquals(parameters5.length, 2);
Assert.assertEquals(parameters5[0].getName(), "a");
Assert.assertEquals(parameters5[0].getValue(), "");
Assert.assertEquals(parameters5[1].getName(), "test1");
Assert.assertEquals(parameters5[1].getValue(), "");
}
} }
Loading…
Cancel
Save