Skip to content

Commit

Permalink
Merge pull request #30 from input-output-hk/develop
Browse files Browse the repository at this point in the history
Merge changes from develop to master
  • Loading branch information
alexromanov committed Jan 19, 2022
2 parents b7c00d2 + 01f8378 commit ca997f5
Show file tree
Hide file tree
Showing 19 changed files with 791 additions and 2 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,5 @@ Professional Services Group Repository:

### PSG Services: gRPC API Examples

* Examples in Javascript can be found [here](https://github.com/input-output-hk/PSG/tree/master/examples/js)
* Examples in Javascript can be found [here](https://github.com/input-output-hk/PSG/tree/master/examples/js)
* Examples in Java can be found [here](https://github.com/input-output-hk/PSG/tree/master/examples/java)
8 changes: 7 additions & 1 deletion docs/source/guides/store_and_hash_service_guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -141,4 +141,10 @@ message AppError {
string code = 1;
string msg = 2;
}
```
```

There are two groups of errors, that can occur while using PSG services:
- permanent (E.g. `failed to authorise call, valid API credentials should be provided`)
- temporary (E.g. `The system is temporarily unavailable. Please try again later`)

In case of temporary errors - you need just try to make a call to service later.
43 changes: 43 additions & 0 deletions examples/java/psg-spring-boot-demo/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# PSG Services - JAVA example (Spring Boot)

## Prerequisites
Install the following tools:

- [Java](https://www.oracle.com/java/technologies/downloads/)
- [Protocol Buffer Compiler](https://grpc.io/docs/protoc-installation/)

**NOTE:** make sure, that **for development and testing purposes** you are using **[PSG Services - Testnet](https://psg-testnet.iog.services/)**

## How to run example service:

1. Make sure, that you have registered an account in [PSG Self Serve UI](https://psg.iog.services/), purchased a package and generated API Token

2. Replace CLIENT_ID and API_TOKEN with your PSG Self Serve UI account values in the src/resources/application.properties file:
```shell
clientId=CLIENT_ID
token=API_TOKEN
```

3. Replace AWS_ACCESS_KEY, AWS_SECRET_KEY, AWS_S3_BUCKET and BUCKET_REGION with your S3 account values and replace demo-file-path with your desired path in src/resources/application.properties:
```shell
s3.key=AWS_ACCCESS_KEY
s3.secret=AWS_SECRET_KEY
s3.bucket=AWS_S3_BUCKET
s3.region=BUCKET_REGION
```

3. Run Spring Boot application by executing the following command in terminal:
```shell
$ mvn spring-boot:run
```
### Metadata service
- ListMetadata: ```$ curl -X GET "http://localhost:8080/listmetadata"```

- SubmitMetadata:```$ curl -X POST "http://localhost:8080/submitmetadata?metadata=SOMEDATA"```

### StoreAndHash service
- StoreAndHash (save file at AWS S3): ```$ curl -X POST "http://localhost:8080/storeAws?path=test&content=test"```
- StoreAndHash (save file at IPFS): ```$ curl -X POST "http://localhost:8080/storeIpfs?host=IPFS_HOST&port=IPFS_PORT&content=testcontent"```
**NOTE**: Do not forget to use your own IPFS_HOST and IPFS_PORT values while using POST /storeIpfs endpoint
- StoreAndHash (get results): ```$ curl -X GET "http://localhost:8080/store/result"```

202 changes: 202 additions & 0 deletions examples/java/psg-spring-boot-demo/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,202 @@
<?xml version="1.0" encoding="UTF-8"?>
<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/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>org.example</groupId>
<artifactId>psg-spring-boot-demo</artifactId>
<version>1.0-SNAPSHOT</version>

<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.5.6</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>

<properties>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<spring-cloud.version>2020.0.4</spring-cloud.version>
</properties>

<dependencies>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.22</version>
<scope>provided</scope>
</dependency>

<!-- For both -->
<dependency>
<groupId>net.devh</groupId>
<artifactId>grpc-spring-boot-starter</artifactId>
<version>2.12.0.RELEASE</version>
<exclusions>
<exclusion>
<groupId>io.grpc</groupId>
<artifactId>grpc-netty-shaded</artifactId>
</exclusion>
</exclusions>
</dependency>
<!-- For the client (only) -->
<dependency>
<groupId>net.devh</groupId>
<artifactId>grpc-client-spring-boot-starter</artifactId>
<version>2.12.0.RELEASE</version>
<exclusions>
<exclusion>
<groupId>io.grpc</groupId>
<artifactId>grpc-netty-shaded</artifactId>
</exclusion>
</exclusions>
</dependency><dependency>
<groupId>net.devh</groupId>
<artifactId>grpc-client-spring-boot-autoconfigure</artifactId>
<version>2.12.0.RELEASE</version>
<type>pom</type>
</dependency>
</dependencies>

<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>${spring-cloud.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>

<build>
<extensions>
<extension>
<groupId>kr.motd.maven</groupId>
<artifactId>os-maven-plugin</artifactId>
<version>1.6.1</version>
</extension>
</extensions>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<failIfNoTests>true</failIfNoTests>
</configuration>
</plugin>
<plugin>
<groupId>org.xolstice.maven.plugins</groupId>
<artifactId>protobuf-maven-plugin</artifactId>
<version>0.6.1</version>
<configuration>
<protocArtifact>
com.google.protobuf:protoc:3.3.0:exe:${os.detected.classifier}
</protocArtifact>
<pluginId>grpc-java</pluginId>
<pluginArtifact>
io.grpc:protoc-gen-grpc-java:1.4.0:exe:${os.detected.classifier}
</pluginArtifact>
</configuration>
<executions>
<execution>
<goals>
<goal>compile</goal>
<goal>compile-custom</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>

<repositories>
<repository>
<id>spring-snapshots</id>
<name>Spring Snapshots</name>
<url>http://repo.spring.io/libs-snapshot-local</url>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
<repository>
<id>spring-milestones</id>
<name>Spring Milestones</name>
<url>http://repo.spring.io/libs-milestone-local</url>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
<repository>
<id>spring-releases</id>
<name>Spring Releases</name>
<url>http://repo.spring.io/release</url>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>spring-snapshots</id>
<name>Spring Snapshots</name>
<url>http://repo.spring.io/libs-snapshot-local</url>
<snapshots>
<enabled>true</enabled>
</snapshots>
</pluginRepository>
<pluginRepository>
<id>spring-milestones</id>
<name>Spring Milestones</name>
<url>http://repo.spring.io/libs-milestone-local</url>
<snapshots>
<enabled>false</enabled>
</snapshots>
</pluginRepository>
<pluginRepository>
<id>spring-plugin-snapshots</id>
<name>Spring Snapshots</name>
<url>http://repo.spring.io/plugins-snapshot-local</url>
<snapshots>
<enabled>true</enabled>
</snapshots>
</pluginRepository>
<pluginRepository>
<id>spring-plugin-milestones</id>
<name>Spring Milestones</name>
<url>http://repo.spring.io/plugins-release-local</url>
<snapshots>
<enabled>false</enabled>
</snapshots>
</pluginRepository>
</pluginRepositories>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package io.psg.demo;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
public class PsgBootApplication {
public static void main(String[] args) {
SpringApplication.run(PsgBootApplication.class, args);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package io.psg.demo.controller;

import io.psg.demo.model.TransactionStatus;
import io.psg.demo.service.DataService;
import lombok.extern.java.Log;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@Log
public class MetadataController {
@Autowired
DataService dataService;

@GetMapping("/listmetadata")
public List<TransactionStatus> list() {
return dataService.getMetadata();
}

@PostMapping("/submitmetadata")
public List<TransactionStatus> submit(@RequestParam("metadata") String metadata) {
return dataService.submitMetadata(metadata);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package io.psg.demo.controller;

import io.psg.demo.model.StoreResult;
import io.psg.demo.service.StoreService;
import lombok.extern.java.Log;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@Log
public class StoreController {
@Autowired
StoreService storeService;

@PostMapping("/storeAws")
public void storeFileAtAws(@RequestParam("path") String path, @RequestParam("content") String fileContent) {
storeService.storeAtAws(path, fileContent);
}

@PostMapping("/storeIpfs")
public void storeFileAtIpfs(@RequestParam("host") String host, @RequestParam("port") Integer port, @RequestParam("content") String fileContent) {
storeService.storeAtIpfs(host, port, fileContent);
}

@GetMapping("/store/result")
public List<StoreResult> result() {
return storeService.getResults();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package io.psg.demo.model;

import lombok.Builder;
import lombok.Data;

@Data
@Builder
public class StoreResult {
private String hash;
private String url;
private String errorCode;
private String errorMessage;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package io.psg.demo.model;

import lombok.Builder;
import lombok.Data;

@Data
@Builder
public class TransactionStatus {
private String id;
private String state;
private String metadata;
private String errorCode;
private String errorMessage;
}

0 comments on commit ca997f5

Please sign in to comment.