Skip to content

Commit 53b09c3

Browse files
committed
new sample
1 parent 8a5bd7f commit 53b09c3

5 files changed

Lines changed: 187 additions & 0 deletions

File tree

samples/CreateTenant/README.md

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
# Permify Java SDK
2+
3+
This repository contains a sample usage for the Java SDK for Permify.
4+
5+
## Getting Started
6+
7+
### Prerequisites
8+
9+
Ensure you have the following installed:
10+
- Java
11+
- Maven
12+
13+
### Building the Project
14+
15+
Navigate to the root directory of the project and run the following commands to build and install the SDK:
16+
17+
```sh
18+
mvn clean install
19+
```
20+
21+
### Running the Application
22+
23+
After successfully building the project, you can run the application using the following command:
24+
25+
```sh
26+
java -jar target/your-artifact-name-0.0.1.jar
27+
```
28+
29+
Replace your-artifact-name-0.0.1.jar with the actual name of the jar file generated after the build.
30+
31+
## For your own Projects
32+
33+
To use the Permify SDK in your project, add the following dependency to your pom.xml file:
34+
35+
```xml
36+
<dependency>
37+
<groupId>co.permify</groupId>
38+
<artifactId>permify</artifactId>
39+
<version>0.0.1</version>
40+
</dependency>
41+
```
42+
43+
Here is a simple permify client:
44+
45+
```java
46+
47+
public static void main(String[] args) {
48+
String baseUrl = "http://localhost:3476";
49+
ApiClient apiClient = new ApiClient();
50+
apiClient.setBasePath(baseUrl);
51+
}
52+
53+
```
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
3+
<modelVersion>4.0.0</modelVersion>
4+
<groupId>org.springframework</groupId>
5+
<artifactId>gs-maven</artifactId>
6+
<version>0.1.0</version>
7+
<build>
8+
<plugins>
9+
<plugin>
10+
<artifactId>maven-shade-plugin</artifactId>
11+
<version>3.2.4</version>
12+
<executions>
13+
<execution>
14+
<phase>package</phase>
15+
<goals>
16+
<goal>shade</goal>
17+
</goals>
18+
<configuration>
19+
<transformers>
20+
<transformer>
21+
<mainClass>hello.HelloWorld</mainClass>
22+
</transformer>
23+
</transformers>
24+
</configuration>
25+
</execution>
26+
</executions>
27+
</plugin>
28+
</plugins>
29+
</build>
30+
<properties>
31+
<maven.compiler.target>1.8</maven.compiler.target>
32+
<maven.compiler.source>1.8</maven.compiler.source>
33+
</properties>
34+
</project>

samples/CreateTenant/pom.xml

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
4+
<modelVersion>4.0.0</modelVersion>
5+
6+
<groupId>org.springframework</groupId>
7+
<artifactId>gs-maven</artifactId>
8+
<packaging>jar</packaging>
9+
<version>0.1.0</version>
10+
11+
<properties>
12+
<maven.compiler.source>1.8</maven.compiler.source>
13+
<maven.compiler.target>1.8</maven.compiler.target>
14+
</properties>
15+
16+
<dependencies>
17+
<dependency>
18+
<groupId>joda-time</groupId>
19+
<artifactId>joda-time</artifactId>
20+
<version>2.9.2</version>
21+
</dependency>
22+
23+
<dependency>
24+
<groupId>co.permify</groupId>
25+
<artifactId>permify</artifactId>
26+
<version>0.0.1</version>
27+
</dependency>
28+
</dependencies>
29+
30+
31+
<build>
32+
<plugins>
33+
<plugin>
34+
<groupId>org.apache.maven.plugins</groupId>
35+
<artifactId>maven-shade-plugin</artifactId>
36+
<version>3.2.4</version>
37+
<executions>
38+
<execution>
39+
<phase>package</phase>
40+
<goals>
41+
<goal>shade</goal>
42+
</goals>
43+
<configuration>
44+
<transformers>
45+
<transformer
46+
implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
47+
<mainClass>hello.HelloWorld</mainClass>
48+
</transformer>
49+
</transformers>
50+
</configuration>
51+
</execution>
52+
</executions>
53+
</plugin>
54+
</plugins>
55+
</build>
56+
</project>
57+
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package hello;
2+
3+
public class Greeter {
4+
public String sayHello() {
5+
return "Hello world!";
6+
}
7+
}
8+
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
package hello;
2+
3+
import org.joda.time.LocalTime;
4+
import org.permify.api.TenancyApi;
5+
import org.permify.model.TenantCreateRequest;
6+
import org.permify.model.TenantCreateResponse;
7+
import org.permify.ApiClient;
8+
import reactor.core.publisher.Mono;
9+
10+
public class HelloWorld {
11+
public static void main(String[] args) {
12+
String baseUrl = "http://localhost:3476"; // Ensure this is the correct port
13+
String bearerToken = "secret"; // Replace with your actual bearer token
14+
15+
ApiClient apiClient = new ApiClient();
16+
apiClient.setBasePath(baseUrl);
17+
System.out.println("Created Api Client Endpoint: " + apiClient.getBasePath());
18+
apiClient.addDefaultHeader("Authorization", "Bearer secret");
19+
20+
TenancyApi api = new TenancyApi(apiClient);
21+
22+
try {
23+
System.out.println("Sending request to " + baseUrl + " with Authorization header Bearer " + bearerToken);
24+
TenantCreateRequest req = new TenantCreateRequest();
25+
req.setId("template_tenant2");
26+
req.setName("Template");
27+
Mono<TenantCreateResponse> responseMono = api.tenantsCreate(req);
28+
TenantCreateResponse response = responseMono.block(); // Block to get the response synchronously
29+
System.out.println("Tenant create response: " + response);
30+
} catch (Exception e) {
31+
LocalTime time = new LocalTime();
32+
System.out.println("Error occurred at " + time.toString() + ": " + e.getMessage());
33+
}
34+
}
35+
}

0 commit comments

Comments
 (0)