Skip to content

Commit 1ac219e

Browse files
authored
Merge pull request #6 from vikadata/dev
Merge branch 'dev' into 'master'
2 parents c39b9a5 + 728a4c9 commit 1ac219e

File tree

74 files changed

+3092
-1388
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

74 files changed

+3092
-1388
lines changed

.mvn/settings.xml

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<!--
2+
~ Copyright (C) 2021 vikadata
3+
~
4+
~ This program is free software; you can redistribute it and/or modify
5+
~ it under the terms of the GNU General Public License as published by
6+
~ the Free Software Foundation; either version 2 of the License, or
7+
~ (at your option) any later version.
8+
~
9+
~ This program is distributed in the hope that it will be useful,
10+
~ but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
~ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
~ GNU General Public License for more details.
13+
~
14+
~ You should have received a copy of the GNU General Public License along
15+
~ with this program; if not, write to the Free Software Foundation, Inc.,
16+
~ 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
17+
-->
18+
19+
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
20+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
21+
xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd">
22+
<servers>
23+
<server>
24+
<id>sonatype-snapshot</id>
25+
<username>${env.SONATYPE_USERNAME}</username>
26+
<password>${env.SONATYPE_PASSWORD}</password>
27+
</server>
28+
<server>
29+
<id>sonatype-release</id>
30+
<username>${env.SONATYPE_USERNAME}</username>
31+
<password>${env.SONATYPE_PASSWORD}</password>
32+
</server>
33+
</servers>
34+
</settings>

.travis.yml

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
language: java
2+
3+
notifications:
4+
email:
5+
recipients:
6+
7+
8+
on_success: change
9+
on_failure: always
10+
11+
jdk:
12+
- openjdk8
13+
14+
stages:
15+
- unit tests
16+
- name: snapshot deploy
17+
if: branch = master
18+
19+
before_install:
20+
- openssl aes-256-cbc -K $encrypted_171b1c559d7b_key -iv $encrypted_171b1c559d7b_iv -in signingkey.asc.enc -out signingkey.asc -d
21+
- echo 'MAVEN_OPTS="$MAVEN_OPTS -Xmx1024m -XX:MaxPermSize=512m -XX:+BytecodeVerificationLocal"' >> ~/.mavenrc
22+
- cat ~/.mavenrc
23+
24+
before_script:
25+
- mvn -v
26+
27+
jobs:
28+
include:
29+
- stage: unit tests
30+
script:
31+
- mvn test -B
32+
- stage: snapshot deploy
33+
script:
34+
- gpg2 --keyring=$TRAVIS_BUILD_DIR/pubring.gpg --no-default-keyring --import signingkey.asc
35+
- gpg2 --allow-secret-key-import --keyring=$TRAVIS_BUILD_DIR/secring.gpg --no-default-keyring --import signingkey.asc
36+
- mvn clean deploy sonatype-snapshot --settings .mvn/settings.xml -Dgpg.executable=gpg2 -Dgpg.keyname=AE63A47A134B9CB61F0121D6E5A7C0A9C50BC9F3
37+
-Dgpg.passphrase=$GPG_PASSPHRASE -Dgpg.publicKeyring=$TRAVIS_BUILD_DIR/pubring.gpg -Dgpg.secretKeyring=$TRAVIS_BUILD_DIR/secring.gpg
38+
39+
env:
40+
global:
41+
- secure: jr1qB3I+hhI8Mz6fsrLYHPSbWWMqtCBs5JqEAV3uLvHprOeX+6kwSrshzWragsvOA8Ufa4Vpq7iXzyHCvxg3df6phiFF9YKPmFfymmulE4gQS7su/+2qI0NXZwNP23xXnNIMwh9RzVjQ8vR9upL9Dw1UOO9oL7XA/pcRMXHMhjNz5OrPTVF2h/IY7bCfuEnyYkc4MYaKUzdYUBv/629ZdHQx6p/+zKFzwRvXIXGmULYen+uJhTJxG6BC4N303/5XaPgVC3tBx5Ij4vQPjf8HVsczVg/5b0c9GLjo9SYS7P45Thbe/0FbBKr82nB3j4XC5gGYhHv7nhKKrcLu0YZxfM2cxYZj1K+Zc+2a/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thaX/F9+F6dzqUt6kaDF4uN4g0H0fXUoLwoHTEAzyJjv+WU+5lkry5wY+fAfFao1uP3zdcpmEjwOVfAPnBjibzfLcP7D/KjDHGVyhukjvm+s+FCr4h82Viq20A8XOJnuW26X+bDRHEOi407mM9sK1ukoUykR0xrBngrC6agCWcTNyGIaX/qJMkRRJ3nNy0Zb1vTzWa9OJyp9N1MxUE9uCn3KMi6D6eILdqcWOu3zLei4CPd23EEGuSqVcA+YyLCouK7HM0NnoFzV5QTUsMEjl7by/F7AuYBH2QZpoA3PrMXiGw6C4NJu3NoLlbdNXuX4Ocw3XM25RHUDhQgt1y+9vbHLbf4iUooiHeLqdrJVCkDEYFmWmJcLRfK+eWJjS80/s/P6aFY5Lx6Skxq7bpcNmVDM5TF9hcTTBNjLstzbEF5SmcocDRcVEFr4AbzI04bU2B2MZmTHhY3U09nDfnGNdsFAiySu6Kf7AUkbwjsEVkpqUQIko/SZZCWAPHpEUFStOQoR2UZS3wkzGQ60Kjg/on/G9xxWisfcMDli8ms0KAMH0QWERamiQnXE4XhxWxRQTqh7p/Z1NOyXP78wAbuSMCLGUGi7Kmg5JAlRdAEHBTTxzKXZyzLF1Rdtfx8NoWnE8bF55/PfE=

README-en.md

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
# vika.java
2-
[![Mit License](https://img.shields.io/badge/License-MIT-blue.svg)](https://www.apache.org/licenses/LICENSE-2.0.txt)
3-
[![Maven Central](https://maven-badges.herokuapp.com/maven-central/vikadata/vika-sdk-java/badge.svg)](https://maven-badges.herokuapp.com/maven-central/cn.vika/vika-sdk-java/)
4-
5-
![](./image/logo.png)
2+
[![LGPL-2.1](https://img.shields.io/badge/License-LGPL--2.1-blue.svg)](https://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt)
3+
[![Maven Central](https://maven-badges.herokuapp.com/maven-central/vikadata/vika-sdk-java/badge.svg)](https://search.maven.org/artifact/cn.vika/vika-client)
4+
[![Build](https://www.travis-ci.com/vikadata/vika.java.svg?branch=master)](https://www.travis-ci.com/github/vikadata/vika.java)
65

76
[简体中文](./README.md) | English
87

9-
Vika is a No-Code database platform for users and developers,here is Java SDK for integration.
8+
[VikaData](https://vika.cn) official Java SDK
109

README.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
# vika.java
2-
[![Mit License](https://img.shields.io/badge/License-MIT-blue.svg)](https://www.apache.org/licenses/LICENSE-2.0.txt)
3-
[![Maven Central](https://maven-badges.herokuapp.com/maven-central/vikadata/vika-sdk-java/badge.svg)](https://maven-badges.herokuapp.com/maven-central/cn.vika/vika-sdk-java/)
2+
[![LGPL-2.1](https://img.shields.io/badge/License-LGPL--2.1-blue.svg)](https://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt)
3+
[![Maven Central](https://maven-badges.herokuapp.com/maven-central/vikadata/vika-sdk-java/badge.svg)](https://search.maven.org/artifact/cn.vika/vika-client)
4+
[![Build](https://www.travis-ci.com/vikadata/vika.java.svg?branch=master)](https://www.travis-ci.com/github/vikadata/vika.java)
45

56
![](./image/logo.png)
67

78
简体中文 | [English](./README-en.md)
89

9-
维格表(vika.cn)官方Java SDK, 让你轻松集成维格表的 No-Code API数据库能力
10+
[维格表](https://vika.cn) 官方Java SDK, 让你轻松集成维格表的API连接能力

api/pom.xml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,16 @@
1111
<artifactId>vika-api</artifactId>
1212
<name>Vika Sdk Api</name>
1313
<description>Vika Sdk Api</description>
14+
<dependencies>
15+
<dependency>
16+
<groupId>cn.vika</groupId>
17+
<artifactId>vika-core</artifactId>
18+
</dependency>
19+
<dependency>
20+
<groupId>net.sf.jmimemagic</groupId>
21+
<artifactId>jmimemagic</artifactId>
22+
<version>0.1.5</version>
23+
</dependency>
24+
</dependencies>
1425

1526
</project>
Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
1+
package cn.vika.api.datasheet;
2+
3+
import java.io.ByteArrayOutputStream;
4+
import java.nio.charset.StandardCharsets;
5+
import java.util.Arrays;
6+
import java.util.Map;
7+
import java.util.UUID;
8+
9+
import cn.vika.api.exception.VikaApiException;
10+
import cn.vika.api.http.AbstractApi;
11+
import cn.vika.api.http.ApiCredential;
12+
import cn.vika.api.http.ApiHttpClient;
13+
import cn.vika.api.model.AbstractModel;
14+
import cn.vika.api.model.HttpResult;
15+
import cn.vika.core.http.GenericTypeReference;
16+
import cn.vika.core.http.HttpHeader;
17+
import cn.vika.core.http.HttpMediaType;
18+
import net.sf.jmimemagic.Magic;
19+
import net.sf.jmimemagic.MagicMatch;
20+
21+
import static cn.vika.api.exception.VikaApiException.DEFAULT_CODE;
22+
23+
/**
24+
* test
25+
*
26+
* @author Zoe Zheng
27+
* @date 2020-12-17 16:25:42
28+
*/
29+
public class AttachmentApi extends AbstractApi implements IAttachmentApi {
30+
private static final String PATH = "/datasheets/%s/attachments";
31+
32+
/**
33+
* datasheetId
34+
*/
35+
private final String datasheetId;
36+
37+
public AttachmentApi(ApiCredential credential, String datasheetId) {
38+
super(credential);
39+
this.datasheetId = datasheetId;
40+
}
41+
42+
public AttachmentApi(ApiCredential credential, ApiHttpClient httpClient, String datasheetId) {
43+
super(credential, httpClient);
44+
this.datasheetId = datasheetId;
45+
}
46+
47+
/**
48+
* upload datasheet attachment
49+
*
50+
* @param params add attachment data
51+
* @param responseType response type
52+
* @return responseType
53+
*/
54+
@Override
55+
public <T> T uploadAttachment(AbstractModel params, GenericTypeReference<HttpResult<T>> responseType) {
56+
HttpHeader header = HttpHeader.EMPTY;
57+
String boundary = UUID.randomUUID().toString();
58+
header.setContentType("multipart/form-data; charset=utf-8" + "; boundary=" + boundary);
59+
HttpResult<T> result;
60+
try {
61+
byte[] binary = getMultipartPayload(params, boundary);
62+
result = getDefaultHttpClient().upload(basePath(), HttpHeader.EMPTY, binary, responseType);
63+
}
64+
catch (Exception e) {
65+
throw new VikaApiException(DEFAULT_CODE, e.getMessage());
66+
}
67+
if (result.isSuccess()) {
68+
return result.getData();
69+
}
70+
throw new VikaApiException(result.getCode(), result.getMessage());
71+
}
72+
73+
@Override
74+
protected String basePath() {
75+
return String.format(PATH, datasheetId);
76+
}
77+
78+
/**
79+
*
80+
* @param params attachment data
81+
* @param boundary unique key
82+
* @return byte[]
83+
* @throws Exception IO exception maybe
84+
*/
85+
private byte[] getMultipartPayload(AbstractModel params, String boundary) throws Exception {
86+
ByteArrayOutputStream baos = new ByteArrayOutputStream();
87+
String[] binaryParams = params.getBinaryParams();
88+
for (Map.Entry<String, byte[]> entry : params.getMultipartRequestParams().entrySet()) {
89+
baos.write("--".getBytes(StandardCharsets.UTF_8));
90+
baos.write(boundary.getBytes(StandardCharsets.UTF_8));
91+
baos.write("\r\n".getBytes(StandardCharsets.UTF_8));
92+
baos.write("Content-Disposition: form-data; name=\"".getBytes(StandardCharsets.UTF_8));
93+
// binary
94+
if (Arrays.asList(binaryParams).contains(entry.getKey())) {
95+
baos.write(entry.getKey().getBytes(StandardCharsets.UTF_8));
96+
baos.write("\"; filename=\"".getBytes(StandardCharsets.UTF_8));
97+
baos.write(params.getBinaryParamNames().get(entry.getKey()));
98+
baos.write("\"\r\n".getBytes(StandardCharsets.UTF_8));
99+
baos.write("Content-Type:".getBytes(StandardCharsets.UTF_8));
100+
MagicMatch match = Magic.getMagicMatch(entry.getValue(), false);
101+
if (match != null) {
102+
baos.write(match.getMimeType().getBytes(StandardCharsets.UTF_8));
103+
}
104+
else {
105+
baos.write(HttpMediaType.APPLICATION_OCTET_STREAM.getBytes(StandardCharsets.UTF_8));
106+
}
107+
baos.write(";charset=utf-8".getBytes(StandardCharsets.UTF_8));
108+
baos.write("\r\n".getBytes(StandardCharsets.UTF_8));
109+
}
110+
else {
111+
baos.write(entry.getKey().getBytes(StandardCharsets.UTF_8));
112+
baos.write("\"\r\n".getBytes(StandardCharsets.UTF_8));
113+
}
114+
baos.write("\r\n".getBytes(StandardCharsets.UTF_8));
115+
baos.write(entry.getValue());
116+
baos.write("\r\n".getBytes(StandardCharsets.UTF_8));
117+
}
118+
if (baos.size() != 0) {
119+
baos.write("--".getBytes(StandardCharsets.UTF_8));
120+
baos.write(boundary.getBytes(StandardCharsets.UTF_8));
121+
baos.write("--\r\n".getBytes(StandardCharsets.UTF_8));
122+
}
123+
byte[] bytes = baos.toByteArray();
124+
baos.close();
125+
return bytes;
126+
}
127+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package cn.vika.api.datasheet;
2+
3+
import cn.vika.api.model.AbstractModel;
4+
import cn.vika.api.model.HttpResult;
5+
import cn.vika.core.http.GenericTypeReference;
6+
7+
/**
8+
* attachment api
9+
*
10+
* @author Zoe Zheng
11+
* @date 2020-12-17 16:15:54
12+
*/
13+
public interface IAttachmentApi {
14+
15+
/**
16+
* upload datasheet attachment
17+
*
18+
* @param params add attachment data
19+
* @param responseType response type
20+
* @return responseType
21+
*/
22+
<T> T uploadAttachment(AbstractModel params, GenericTypeReference<HttpResult<T>> responseType) throws Exception;
23+
}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
package cn.vika.api.datasheet;
2+
3+
import cn.vika.api.model.AbstractModel;
4+
import cn.vika.api.model.HttpResult;
5+
import cn.vika.core.http.GenericTypeReference;
6+
7+
/**
8+
* test
9+
*
10+
* @author Zoe Zheng
11+
* @date 2020-12-15 17:19:41
12+
*/
13+
public interface IRecordApi {
14+
/**
15+
* record list
16+
*
17+
* @param params request query params
18+
* @param responseType response type
19+
* @return responseType
20+
*/
21+
<T> T getRecords(AbstractModel params, GenericTypeReference<HttpResult<T>> responseType);
22+
23+
/**
24+
* add records
25+
*
26+
* @param model body data for post
27+
* @param responseType response type
28+
* @return responseType
29+
*/
30+
<T> T addRecords(AbstractModel model, GenericTypeReference<HttpResult<T>> responseType);
31+
32+
/**
33+
* modify record
34+
*
35+
* @param model body data for post
36+
* @param responseType response type
37+
* @return responseType
38+
*/
39+
<T> T modifyRecords(AbstractModel model, GenericTypeReference<HttpResult<T>> responseType);
40+
41+
/**
42+
* delete records
43+
*
44+
* @param model body data for post
45+
* @return boolean
46+
*/
47+
boolean deleteRecords(AbstractModel model);
48+
}

0 commit comments

Comments
 (0)