From 34c9f252ce5c2121ebe64709bced6190291fe197 Mon Sep 17 00:00:00 2001
From: OZGCloud <ozgcloud@mgm-tp.com>
Date: Fri, 27 Nov 2020 10:41:09 +0100
Subject: [PATCH] OZG-94 add pluto-grpc api to goofy

---
 goofy-server/pom.xml                          | 59 +++++++++++++++----
 .../de/itvsh/goofy/vorgang/VorgangMapper.java | 13 ++++
 .../goofy/vorgang/VorgangRemoteService.java   | 28 +++++++++
 .../itvsh/goofy/vorgang/VorgangService.java   | 17 ++++++
 .../src/main/resources/application.yml        |  9 ++-
 pom.xml                                       | 31 +++++++---
 6 files changed, 138 insertions(+), 19 deletions(-)
 create mode 100644 goofy-server/src/main/java/de/itvsh/goofy/vorgang/VorgangMapper.java
 create mode 100644 goofy-server/src/main/java/de/itvsh/goofy/vorgang/VorgangRemoteService.java
 create mode 100644 goofy-server/src/main/java/de/itvsh/goofy/vorgang/VorgangService.java

diff --git a/goofy-server/pom.xml b/goofy-server/pom.xml
index 7ff1a14aae..cafb8aa351 100644
--- a/goofy-server/pom.xml
+++ b/goofy-server/pom.xml
@@ -39,6 +39,22 @@
 			<groupId>org.springframework.boot</groupId>
 			<artifactId>spring-boot-starter-hateoas</artifactId>
 		</dependency>
+		<dependency>
+			<groupId>net.devh</groupId>
+			<artifactId>grpc-client-spring-boot-starter</artifactId>
+		</dependency>
+
+		<!-- own projects -->
+		<dependency>
+			<groupId>de.itvsh.ozg.pluto</groupId>
+			<artifactId>pluto-interface</artifactId>
+		</dependency>
+
+		<!-- tools -->
+		<dependency>
+			<groupId>org.mapstruct</groupId>
+			<artifactId>mapstruct</artifactId>
+		</dependency>
 
 		<!-- Dev -->
 		<dependency>
@@ -77,7 +93,38 @@
 
 	<build>
 		<plugins>
+			<plugin>
+				<groupId>org.apache.maven.plugins</groupId>
+				<artifactId>maven-compiler-plugin</artifactId>
+				<version>3.8.1</version>
+				<configuration>
+					<source>${java.version}</source>
+					<target>${java.version}</target>
+					<annotationProcessorPaths>
+						<path>
+							<groupId>org.projectlombok</groupId>
+							<artifactId>lombok</artifactId>
+							<version>1.18.16</version>
+						</path>
+						<path>
+							<groupId>org.mapstruct</groupId>
+							<artifactId>mapstruct-processor</artifactId>
+							<version>${mapstruct.version}</version>
+						</path>
+						<!-- other annotation processors -->
+					</annotationProcessorPaths>
 
+					<showWarnings>true</showWarnings>
+					<compilerArgs>
+						<compilerArg>
+							-Amapstruct.defaultComponentModel=spring
+						</compilerArg>
+						<compilerArg>
+							-Amapstruct.unmappedTargetPolicy=ERROR
+						</compilerArg>
+					</compilerArgs>
+				</configuration>
+			</plugin>
 			<plugin>
 				<groupId>org.apache.maven.plugins</groupId>
 				<artifactId>maven-failsafe-plugin</artifactId>
@@ -91,7 +138,6 @@
 				<artifactId>spring-boot-maven-plugin</artifactId>
 			</plugin>
 
-
 			<plugin>
 				<groupId>org.apache.maven.plugins</groupId>
 				<artifactId>maven-resources-plugin</artifactId>
@@ -156,7 +202,6 @@
 				<groupId>pl.project13.maven</groupId>
 				<artifactId>git-commit-id-plugin</artifactId>
 				<configuration>
-					<verbose>true</verbose>
 					<offline>true</offline>
 				</configuration>
 				<executions>
@@ -169,14 +214,6 @@
 					</execution>
 				</executions>
 			</plugin>
-            <plugin>
-                <groupId>org.apache.maven.plugins</groupId>
-                <artifactId>maven-compiler-plugin</artifactId>
-                <configuration>
-                    <source>14</source>
-                    <target>14</target>
-                </configuration>
-            </plugin>
-        </plugins>
+		</plugins>
 	</build>
 </project>
diff --git a/goofy-server/src/main/java/de/itvsh/goofy/vorgang/VorgangMapper.java b/goofy-server/src/main/java/de/itvsh/goofy/vorgang/VorgangMapper.java
new file mode 100644
index 0000000000..39575853b0
--- /dev/null
+++ b/goofy-server/src/main/java/de/itvsh/goofy/vorgang/VorgangMapper.java
@@ -0,0 +1,13 @@
+package de.itvsh.goofy.vorgang;
+
+import org.mapstruct.Mapper;
+import org.mapstruct.Mapping;
+
+import de.itvsh.ozg.pluto.vorgang.PlutoVorgangHeader;
+
+@Mapper
+public interface VorgangMapper {
+
+	@Mapping(target = "initialDate", source = "createdAt")
+	Vorgang toVorgang(PlutoVorgangHeader vorgangHeader);
+}
diff --git a/goofy-server/src/main/java/de/itvsh/goofy/vorgang/VorgangRemoteService.java b/goofy-server/src/main/java/de/itvsh/goofy/vorgang/VorgangRemoteService.java
new file mode 100644
index 0000000000..32c037cd7e
--- /dev/null
+++ b/goofy-server/src/main/java/de/itvsh/goofy/vorgang/VorgangRemoteService.java
@@ -0,0 +1,28 @@
+package de.itvsh.goofy.vorgang;
+
+import java.util.stream.Stream;
+
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+import de.itvsh.ozg.pluto.vorgang.FindVorgangRequest;
+import de.itvsh.ozg.pluto.vorgang.VorgangServiceGrpc.VorgangServiceBlockingStub;
+import net.devh.boot.grpc.client.inject.GrpcClient;
+
+@Service
+ class VorgangRemoteService {
+
+	@GrpcClient("pluto")
+	private VorgangServiceBlockingStub vorgangServiceStub;
+	@Autowired
+	private VorgangMapper vorgangMapper;
+
+	public Stream<Vorgang> findVorgang(int limit, int offset) {
+		return vorgangServiceStub.findVorgang(buildFindVorgangRequest(limit, offset)).getVorgangList().stream()//
+		.map(vorgangMapper::toVorgang);
+	}
+
+	private FindVorgangRequest buildFindVorgangRequest(int limit ,int offset) {
+		return FindVorgangRequest.newBuilder().setLimit(limit).setOffset(offset).build();
+	}
+}
diff --git a/goofy-server/src/main/java/de/itvsh/goofy/vorgang/VorgangService.java b/goofy-server/src/main/java/de/itvsh/goofy/vorgang/VorgangService.java
new file mode 100644
index 0000000000..290ddc0c7e
--- /dev/null
+++ b/goofy-server/src/main/java/de/itvsh/goofy/vorgang/VorgangService.java
@@ -0,0 +1,17 @@
+package de.itvsh.goofy.vorgang;
+
+import java.util.stream.Stream;
+
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+@Service
+class VorgangService {
+
+	@Autowired
+	private VorgangRemoteService remoteService;
+
+	public Stream<Vorgang> findVorgang(int limit, int offset) {
+	return remoteService.findVorgang(limit, offset);
+	}
+}
diff --git a/goofy-server/src/main/resources/application.yml b/goofy-server/src/main/resources/application.yml
index aad089b513..c511da79f2 100644
--- a/goofy-server/src/main/resources/application.yml
+++ b/goofy-server/src/main/resources/application.yml
@@ -4,4 +4,11 @@ logging:
     de.itvsh: INFO
 
 goofy:
-  production: false
\ No newline at end of file
+  production: false
+  
+  
+grpc:
+  client:
+    pluto:
+      address: static://127.0.0.1:9090
+      negotiationType: PLAINTEXT
\ No newline at end of file
diff --git a/pom.xml b/pom.xml
index 09fa00e33b..a5a10caffb 100644
--- a/pom.xml
+++ b/pom.xml
@@ -20,6 +20,8 @@
 		<java.version>15</java.version>
 
 		<spring.boot.version>2.4.0</spring.boot.version>
+		<grpc.spring-boot-starter.version>2.10.1.RELEASE</grpc.spring-boot-starter.version>
+		<mapstruct.version>1.4.1.Final</mapstruct.version>
 
 		<!-- plugins -->
 		<maven-jar-plugin.version>3.2.0</maven-jar-plugin.version>
@@ -40,6 +42,23 @@
 				<scope>import</scope>
 			</dependency>
 
+			<!-- tools -->
+			<dependency>
+				<groupId>org.mapstruct</groupId>
+				<artifactId>mapstruct</artifactId>
+				<version>${mapstruct.version}</version>
+			</dependency>
+			<dependency>
+				<groupId>net.devh</groupId>
+				<artifactId>grpc-client-spring-boot-starter</artifactId>
+				<version>${grpc.spring-boot-starter.version}</version>
+			</dependency>
+
+			<dependency>
+				<groupId>de.itvsh.ozg.pluto</groupId>
+				<artifactId>pluto-interface</artifactId>
+				<version>${project.version}</version>
+			</dependency>
 		</dependencies>
 	</dependencyManagement>
 
@@ -51,29 +70,27 @@
 					<artifactId>maven-resources-plugin</artifactId>
 					<version>${resources.plugin.version}</version>
 				</plugin>
+				
 				<plugin>
 					<groupId>org.springframework.boot</groupId>
 					<artifactId>spring-boot-maven-plugin</artifactId>
 					<version>${spring.boot.version}</version>
 					<executions>
-					
+
 						<execution>
 							<id>repackage</id>
 							<goals>
 								<goal>repackage</goal>
 							</goals>
 						</execution>
-						
+
 						<execution>
 							<id>build info</id>
 							<goals>
 								<goal>build-info</goal>
 							</goals>
-						<!-- 	<configuration>
-								<additionalProperties>
-									<jenkins.build.number>${buildnumber}</jenkins.build.number>
-								</additionalProperties>
-							</configuration> -->
+							<!-- <configuration> <additionalProperties> <jenkins.build.number>${buildnumber}</jenkins.build.number> 
+								</additionalProperties> </configuration> -->
 						</execution>
 					</executions>
 				</plugin>
-- 
GitLab