Skip to content

Commit 8179b24

Browse files
authored
Merge pull request #9 from vikadata/feat-record-api
refactor record api
2 parents 49f0193 + c6ee160 commit 8179b24

File tree

103 files changed

+4830
-1818
lines changed

Some content is hidden

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

103 files changed

+4830
-1818
lines changed

README.md

Lines changed: 200 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,206 @@
1-
# vika.java
1+
# Vikadata&trade; Java SDK (*vika.java*)<br />Java Client Library for the Vikadata OpenAPI
2+
23
[![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)
34
[![Maven Central](https://maven-badges.herokuapp.com/maven-central/vikadata/vika-sdk-java/badge.svg)](https://search.maven.org/artifact/cn.vika/vika-client)
45
[![Build](https://www.travis-ci.com/vikadata/vika.java.svg?branch=master)](https://www.travis-ci.com/github/vikadata/vika.java)
6+
[![JavaDoc](https://javadoc.io/badge2/cn.vika/vika.java/javadoc.io.svg)](https://javadoc.io/doc/cn.vika/vika.java)
7+
8+
[github_issues]:https://github.com/vikadata/vika.java/issues
9+
[github_issues_new]:https://github.com/vikadata/vika.java/issues/new
10+
11+
[简体中文](./README_zh.md) | English
12+
13+
[Vika](https://vika.cn) Official Java SDK
14+
15+
Vikadata&trade; Java API (*vika.js*) provides a full featured and easy to consume Java
16+
library for working with vikadata via the Vikadata OpenAPI.<br/>
17+
18+
---
19+
20+
## Usage
21+
22+
### Java Version Requirement
23+
24+
Java 8+ is required to use sdk. not support Java 8 below
25+
26+
## Getting Started
27+
28+
### Installation
29+
30+
* Maven
31+
32+
```xml
33+
34+
<dependency>
35+
<groupId>cn.vika</groupId>
36+
<artifactId>vika-client</artifactId>
37+
<version>0.1.0</version>
38+
</dependency>
39+
```
40+
41+
* Gradle
42+
43+
```groovy
44+
dependencies {
45+
... ...
46+
implementation('cn.vika:vika-client:0.1.0')
47+
}
48+
```
49+
50+
## **Usage Example**
51+
52+
vika java client is quite simple to use, you don't need to set api url, all you need is the
53+
``Personal Api Key`` from your vika account settings page. Once you have that info it is as
54+
simple as:
55+
56+
First, you need to set api credential which belong your personal api key.
57+
58+
```java
59+
ApiCredential credential=new ApiCredential("Your API Key");
60+
```
61+
62+
Then, Init client instance
63+
64+
```java
65+
VikaApiClient vikaApiClient = new VikaApiClient(credential);
66+
```
67+
68+
By default, the API client has been added for setting connect and read timeouts, you can also change:
69+
70+
```java
71+
// Set the connect timeout to 8 second and the read timeout to 9 seconds
72+
VikaApiClient vikaApiClient = new VikaApiClient(credential)
73+
.withRequestTimeout(80000)
74+
.withReadTimeout(90000);
75+
```
76+
77+
As private deployment user, you can also change host url
78+
79+
```java
80+
VikaApiClient vikaApiClient = new VikaApiClient("http://ip:port", credential);
81+
```
82+
83+
#### **Query Record**
84+
85+
Most simple usage for query record quickly
86+
87+
```java
88+
// Get 10 records on first page
89+
List<RecordResult> records = vikaApiClient.getRecordApi().getRecords("datasheetId", 1, 10);
90+
```
91+
92+
#### **Pager Resulting**
93+
94+
API client provides an easy way to use paging mechanism to page through lists of results from the Open API.
95+
Below code are a couple of examples on how to use the Pager:
96+
97+
```java
98+
// Get a Pager instance that will page through the records with 100 record per page
99+
Pager<RecordResult> pager = vikaApiClient.getRecordApi().getRecords("datasheet_id", 100);
100+
101+
// Iterate through the pages and print out the per record detail
102+
while (pager.hasNext())) {
103+
for (RecordResult record : pager.next()) {
104+
System.out.println(record.getRecordId() + " -: " + record.getFields());
105+
}
106+
}
107+
```
108+
109+
you can also fetch all the items as a single list using a Pager instance:
110+
```java
111+
// Get a Pager instance so we can load all the records into a single list, 100 record at a time:
112+
Pager<RecordResult> pager = vikaApiClient.getRecordApi().getRecords("datasheet_id", 100);
113+
List<RecordResult> records = pager.all();
114+
```
115+
116+
**Java 8 Stream Support**
117+
118+
also provide method that returns a Java 8 Stream.
119+
```java
120+
// Pager as stream,support forEach、Group、Filter operation
121+
Stream<RecordResult> records = vikaApiClient.getRecordApi().getRecordsAsStream("datasheet_id");
122+
123+
// ex: extract record id to a list
124+
records.map(RecordResult::getRecordId).collect(Collectors.toList());
125+
```
126+
127+
**Advance Query**
128+
129+
```java
130+
// build query condition
131+
ApiQueryParam queryParam = new ApiQueryParam(1, 50)
132+
.withView("viewId")
133+
.withFields(Arrays.asList("fieldName"))
134+
.withRecordIds(Arrays.asList("recordId"))
135+
.withSort("fieldName", Order.DESC).withSort("fieldName", Order.ASC)
136+
.withFilter("{fieldName}>1");
137+
// query return pager result
138+
Pager<RecordResult> pager = vikaApiClient.getRecordApi().getRecords("datasheet_id", queryParam);
139+
```
140+
141+
#### **Add Record**
142+
143+
Class ``RecordMap`` is a key-value structure like ``Map<String, Object>``, all thing you do is converting json to map, you can use convert util from sdk provide which is named ``JacksonConverter``, you also can use jackson api build json structure data, more detail please reference unit test.
144+
145+
```java
146+
// Build Record Map by jackson api
147+
ObjectNode fieldMap = JsonNodeFactory.instance.objectNode()
148+
// simple data
149+
.put("fieldName", "string")
150+
.put("number", 1234);
151+
// sub tree node
152+
.set("city", JsonNodeFactory.instance.arrayNode().add("NewYork").add("Bejing"));
153+
// put record map into fields key
154+
ObjectNode fields = JsonNodeFactory.instance.objectNode().set("fields", fieldMap);
155+
// only one record, warp record into array node
156+
ArrayNode arrayNode = JsonNodeFactory.instance.arrayNode().add(fields);
157+
// convert json to Map List
158+
List<RecordMap> recordMaps = JacksonConverter.unmarshalToList(RecordMap.class, arrayNode);
159+
// create record request
160+
CreateRecordRequest recordRequest = new CreateRecordRequest().withRecords(recordMaps);
161+
// ok
162+
List<RecordResult> newRecords = vikaApiClient.getRecordApi().addRecords("datasheet_id", recordRequest);
163+
```
164+
165+
#### **Update Record**
166+
167+
```java
168+
// Build update record model
169+
UpdateRecord record = new UpdateRecord()
170+
// row record id from query result or add record result
171+
.withRecordId("recXXXXX")
172+
// single-text type field cell
173+
.withField("SingleText", "ABC")
174+
// single-select type field cell,
175+
// it can be set null or empty array if you want to clear field value: withField("Options", null)
176+
.withField("Options", Arrays.asList("LL", "NN"));
177+
// new Request model
178+
UpdateRecordRequest updateRecordRequest = new UpdateRecordRequest()
179+
.withRecords(Collections.singletonList(record));
180+
// request send
181+
List<RecordResult> updateRecords = vikaApiClient.getRecordApi().updateRecords("datasheet_id", updateRecordRequest);
182+
```
183+
184+
#### **Delete Record**
185+
186+
```java
187+
// DELETE one record only
188+
vikaApiClient.getRecordApi().deleteRecord("datasheet_id", "recXXXXXX");
189+
190+
// DELETE many record
191+
vikaApiClient.getRecordApi().deleteRecords("datasheet_id", Arrays.asList("recXXXXXX", "recXXXXXX"));
192+
```
193+
194+
## Reporting Issues
195+
Vika java sdk project uses GitHub's integrated issue tracking system to record bugs and feature requests.
196+
If you want to raise an issue, please follow the recommendations below:
197+
198+
* Before you log a bug, please search the [issue tracker][github_issues] to see if someone has already reported the problem.
199+
* If the issue doesn't already exist, [create a new issue][github_issues_new].
200+
* Please provide as much information as possible with the issue report, we like to know the version of Spring Boot that you are using, as well as your Operating System and JVM version.
201+
* If you need to paste code, or include a stack trace use Markdown escapes before and after your text.
5202

6-
![](./image/logo.png)
203+
## License
204+
Open Source software released under the [LGPL-2.1](https://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt).
7205

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

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

README-en.md renamed to README_zh.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
[![Maven Central](https://maven-badges.herokuapp.com/maven-central/vikadata/vika-sdk-java/badge.svg)](https://search.maven.org/artifact/cn.vika/vika-client)
44
[![Build](https://www.travis-ci.com/vikadata/vika.java.svg?branch=master)](https://www.travis-ci.com/github/vikadata/vika.java)
55

6-
[简体中文](./README.md) | English
6+
![](./image/logo.png)
77

8-
[VikaData](https://vika.cn) official Java SDK
8+
简体中文 | [English](./README-en.md)
99

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

api/pom.xml

Lines changed: 0 additions & 26 deletions
This file was deleted.

api/src/main/java/cn/vika/api/datasheet/AttachmentApi.java

Lines changed: 0 additions & 127 deletions
This file was deleted.

0 commit comments

Comments
 (0)