You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tika.apache.org by nd...@apache.org on 2024/03/29 07:29:37 UTC

(tika) branch TIKA-4181-grpc updated: code formatting

This is an automated email from the ASF dual-hosted git repository.

ndipiazza pushed a commit to branch TIKA-4181-grpc
in repository https://gitbox.apache.org/repos/asf/tika.git


The following commit(s) were added to refs/heads/TIKA-4181-grpc by this push:
     new 322452021 code formatting
322452021 is described below

commit 32245202142ee2e8d9021a98a5775b251bc392bf
Author: Nicholas DiPiazza <nd...@apache.org>
AuthorDate: Fri Mar 29 02:29:31 2024 -0500

    code formatting
---
 tika-pipes/tika-grpc/README.md                     |   8 +-
 tika-pipes/tika-grpc/pom.xml                       |   2 +-
 .../apache/tika/pipes/grpc/TikaGrpcServerImpl.java |  20 ++--
 tika-pipes/tika-grpc/src/main/proto/tika.proto     |  12 +--
 .../org/apache/tika/pipes/grpc/TikaClient.java     | 119 ++++++++++-----------
 5 files changed, 81 insertions(+), 80 deletions(-)

diff --git a/tika-pipes/tika-grpc/README.md b/tika-pipes/tika-grpc/README.md
index 7b0d4ccd6..f2269b22b 100644
--- a/tika-pipes/tika-grpc/README.md
+++ b/tika-pipes/tika-grpc/README.md
@@ -5,9 +5,9 @@ The following is the Tika Pipes GRPC Server.
 This server will manage a pool of Tika Pipes clients.
 
 * Tika Pipes Fetcher CRUD operations
-  * Create
-  * Read
-  * Update
-  * Delete
+    * Create
+    * Read
+    * Update
+    * Delete
 * Fetch + Parse a given Fetch Item
 
diff --git a/tika-pipes/tika-grpc/pom.xml b/tika-pipes/tika-grpc/pom.xml
index a4d7486f8..3daaf7a3e 100644
--- a/tika-pipes/tika-grpc/pom.xml
+++ b/tika-pipes/tika-grpc/pom.xml
@@ -1,5 +1,5 @@
 <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">
+         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
   <modelVersion>4.0.0</modelVersion>
   <artifactId>tika-grpc</artifactId>
   <packaging>jar</packaging>
diff --git a/tika-pipes/tika-grpc/src/main/java/org/apache/tika/pipes/grpc/TikaGrpcServerImpl.java b/tika-pipes/tika-grpc/src/main/java/org/apache/tika/pipes/grpc/TikaGrpcServerImpl.java
index 697ebcac5..3098354d8 100644
--- a/tika-pipes/tika-grpc/src/main/java/org/apache/tika/pipes/grpc/TikaGrpcServerImpl.java
+++ b/tika-pipes/tika-grpc/src/main/java/org/apache/tika/pipes/grpc/TikaGrpcServerImpl.java
@@ -80,7 +80,8 @@ class TikaGrpcServerImpl extends TikaGrpc.TikaImplBase {
         for (var fetcherEntry : fetchers.entrySet()) {
             AbstractFetcher fetcherObject = fetcherEntry.getValue();
             Map<String, Object> fetcherConfigParams =
-                    OBJECT_MAPPER.convertValue(fetcherConfigs.get(fetcherEntry.getKey()), new TypeReference<>() {
+                    OBJECT_MAPPER.convertValue(fetcherConfigs.get(fetcherEntry.getKey()),
+                            new TypeReference<>() {
                             });
             Element fetcher = tikaConfigDoc.createElement("fetcher");
             fetcher.setAttribute("class", fetcherEntry.getValue().getClass().getName());
@@ -230,7 +231,8 @@ class TikaGrpcServerImpl extends TikaGrpc.TikaImplBase {
         Map<String, Object> paramMap =
                 OBJECT_MAPPER.convertValue(abstractConfig, new TypeReference<>() {
                 });
-        paramMap.forEach((k, v) -> getFetcherReply.putParams(Objects.toString(k), Objects.toString(v)));
+        paramMap.forEach(
+                (k, v) -> getFetcherReply.putParams(Objects.toString(k), Objects.toString(v)));
         responseObserver.onNext(getFetcherReply.build());
         responseObserver.onCompleted();
     }
@@ -247,16 +249,18 @@ class TikaGrpcServerImpl extends TikaGrpc.TikaImplBase {
         responseObserver.onCompleted();
     }
 
-    private GetFetcherReply.Builder createFetcherReply(Map.Entry<String, AbstractConfig> fetcherConfig) {
+    private GetFetcherReply.Builder createFetcherReply(
+            Map.Entry<String, AbstractConfig> fetcherConfig) {
         AbstractFetcher abstractFetcher = fetchers.get(fetcherConfig.getKey());
         AbstractConfig abstractConfig = fetcherConfigs.get(fetcherConfig.getKey());
-        GetFetcherReply.Builder replyBuilder = GetFetcherReply.newBuilder()
-                .setFetcherClass(abstractFetcher.getClass().getName())
-                .setName(abstractFetcher.getName());
+        GetFetcherReply.Builder replyBuilder =
+                GetFetcherReply.newBuilder().setFetcherClass(abstractFetcher.getClass().getName())
+                        .setName(abstractFetcher.getName());
         Map<String, Object> paramMap =
                 OBJECT_MAPPER.convertValue(abstractConfig, new TypeReference<>() {
                 });
-        paramMap.forEach((k, v) -> replyBuilder.putParams(Objects.toString(k), Objects.toString(v)));
+        paramMap.forEach(
+                (k, v) -> replyBuilder.putParams(Objects.toString(k), Objects.toString(v)));
         return replyBuilder;
     }
 
@@ -275,4 +279,4 @@ class TikaGrpcServerImpl extends TikaGrpc.TikaImplBase {
         fetcherConfigs.remove(name);
         fetchers.remove(name);
     }
-}
\ No newline at end of file
+}
diff --git a/tika-pipes/tika-grpc/src/main/proto/tika.proto b/tika-pipes/tika-grpc/src/main/proto/tika.proto
index c23c678d4..3095a0779 100644
--- a/tika-pipes/tika-grpc/src/main/proto/tika.proto
+++ b/tika-pipes/tika-grpc/src/main/proto/tika.proto
@@ -32,7 +32,7 @@ service Tika {
 message CreateFetcherRequest {
   string name = 1;
   string fetcherClass = 2;
-  map<string,string> params = 3;
+  map<string, string> params = 3;
 }
 
 message CreateFetcherReply {
@@ -42,7 +42,7 @@ message CreateFetcherReply {
 message UpdateFetcherRequest {
   string name = 1;
   string fetcherClass = 2;
-  map<string,string> params = 3;
+  map<string, string> params = 3;
 }
 
 message UpdateFetcherReply {
@@ -52,12 +52,12 @@ message UpdateFetcherReply {
 message FetchAndParseRequest {
   string fetcherName = 1;
   string fetchKey = 2;
-  map<string,string> metadata = 3;
+  map<string, string> metadata = 3;
 }
 
 message FetchAndParseReply {
   string fetchKey = 1;
-  map<string,string> fields = 2;
+  map<string, string> fields = 2;
 }
 
 message DeleteFetcherRequest {
@@ -75,7 +75,7 @@ message GetFetcherRequest {
 message GetFetcherReply {
   string name = 1;
   string fetcherClass = 2;
-  map<string,string> params = 3;
+  map<string, string> params = 3;
 }
 
 message ListFetchersRequest {
@@ -85,4 +85,4 @@ message ListFetchersRequest {
 
 message ListFetchersReply {
   repeated GetFetcherReply getFetcherReply = 1;
-}
\ No newline at end of file
+}
diff --git a/tika-pipes/tika-grpc/src/test/java/org/apache/tika/pipes/grpc/TikaClient.java b/tika-pipes/tika-grpc/src/test/java/org/apache/tika/pipes/grpc/TikaClient.java
index 332654002..2cfc958bd 100644
--- a/tika-pipes/tika-grpc/src/test/java/org/apache/tika/pipes/grpc/TikaClient.java
+++ b/tika-pipes/tika-grpc/src/test/java/org/apache/tika/pipes/grpc/TikaClient.java
@@ -35,78 +35,75 @@ import org.apache.tika.TikaGrpc;
 import org.apache.tika.pipes.fetcher.fs.FileSystemFetcher;
 
 public class TikaClient {
-  private static final Logger logger = Logger.getLogger(TikaClient.class.getName());
+    private static final Logger logger = Logger.getLogger(TikaClient.class.getName());
 
-  private final TikaGrpc.TikaBlockingStub blockingStub;
+    private final TikaGrpc.TikaBlockingStub blockingStub;
 
-  public TikaClient(Channel channel) {
-    // 'channel' here is a Channel, not a ManagedChannel, so it is not this code's responsibility to
-    // shut it down.
+    public TikaClient(Channel channel) {
+        // 'channel' here is a Channel, not a ManagedChannel, so it is not this code's responsibility to
+        // shut it down.
 
-    // Passing Channels to code makes code easier to test and makes it easier to reuse Channels.
-    blockingStub = TikaGrpc.newBlockingStub(channel);
-  }
-
-  public void createFetcher(CreateFetcherRequest createFileSystemFetcherRequest) {
-    CreateFetcherReply response;
-    try {
-      response = blockingStub.createFetcher(createFileSystemFetcherRequest);
-    } catch (StatusRuntimeException e) {
-      logger.log(Level.WARNING, "RPC failed: {0}", e.getStatus());
-      return;
+        // Passing Channels to code makes code easier to test and makes it easier to reuse Channels.
+        blockingStub = TikaGrpc.newBlockingStub(channel);
     }
-    logger.info("Create fetcher: " + response.getMessage());
-  }
 
-  public void fetchAndParse(FetchAndParseRequest fetchAndParseRequest) {
-    FetchAndParseReply fetchReply;
-    try {
-      fetchReply = blockingStub.fetchAndParse(fetchAndParseRequest);
-    } catch (StatusRuntimeException e) {
-      logger.log(Level.WARNING, "RPC failed: {0}", e.getStatus());
-      return;
+    public void createFetcher(CreateFetcherRequest createFileSystemFetcherRequest) {
+        CreateFetcherReply response;
+        try {
+            response = blockingStub.createFetcher(createFileSystemFetcherRequest);
+        } catch (StatusRuntimeException e) {
+            logger.log(Level.WARNING, "RPC failed: {0}", e.getStatus());
+            return;
+        }
+        logger.info("Create fetcher: " + response.getMessage());
     }
-    logger.info("Fetch reply - tika parsed metadata: " + fetchReply.getFieldsMap());
-  }
 
-  public static void main(String[] args) throws Exception {
-    if (args.length != 1) {
-      System.err.println("Expects one command line argument for the base path to use for the crawl.");
-      System.exit(1);
-      return;
+    public void fetchAndParse(FetchAndParseRequest fetchAndParseRequest) {
+        FetchAndParseReply fetchReply;
+        try {
+            fetchReply = blockingStub.fetchAndParse(fetchAndParseRequest);
+        } catch (StatusRuntimeException e) {
+            logger.log(Level.WARNING, "RPC failed: {0}", e.getStatus());
+            return;
+        }
+        logger.info("Fetch reply - tika parsed metadata: " + fetchReply.getFieldsMap());
     }
-    String crawlPath = args[0];
-    String target = "localhost:50051";
-    // Create a communication channel to the server, known as a Channel. Channels are thread-safe
-    // and reusable. It is common to create channels at the beginning of your application and reuse
-    // them until the application shuts down.
-    //
-    // For the example we use plaintext insecure credentials to avoid needing TLS certificates. To
-    // use TLS, use TlsChannelCredentials instead.
-    ManagedChannel channel = Grpc.newChannelBuilder(target, InsecureChannelCredentials.create())
-        .build();
-    try {
-      TikaClient client = new TikaClient(channel);
-      String fetcherId = "file-system-fetcher-" + UUID.randomUUID();
 
-      client.createFetcher(CreateFetcherRequest.newBuilder()
-              .setName(fetcherId)
-              .setFetcherClass(FileSystemFetcher.class.getName())
-              .putParams("basePath", crawlPath)
-              .putParams("extractFileSystemMetadata", "true")
-              .build());
+    public static void main(String[] args) throws Exception {
+        if (args.length != 1) {
+            System.err.println(
+                    "Expects one command line argument for the base path to use for the crawl.");
+            System.exit(1);
+            return;
+        }
+        String crawlPath = args[0];
+        String target = "localhost:50051";
+        // Create a communication channel to the server, known as a Channel. Channels are thread-safe
+        // and reusable. It is common to create channels at the beginning of your application and reuse
+        // them until the application shuts down.
+        //
+        // For the example we use plaintext insecure credentials to avoid needing TLS certificates. To
+        // use TLS, use TlsChannelCredentials instead.
+        ManagedChannel channel =
+                Grpc.newChannelBuilder(target, InsecureChannelCredentials.create()).build();
+        try {
+            TikaClient client = new TikaClient(channel);
+            String fetcherId = "file-system-fetcher-" + UUID.randomUUID();
+
+            client.createFetcher(CreateFetcherRequest.newBuilder().setName(fetcherId)
+                    .setFetcherClass(FileSystemFetcher.class.getName())
+                    .putParams("basePath", crawlPath).putParams("extractFileSystemMetadata", "true")
+                    .build());
 
-      client.fetchAndParse(FetchAndParseRequest.newBuilder()
-                      .setFetcherName(fetcherId)
-                      .setFetchKey("000164.pdf")
-              .build());
+            client.fetchAndParse(FetchAndParseRequest.newBuilder().setFetcherName(fetcherId)
+                    .setFetchKey("000164.pdf").build());
 
 
-    } finally {
-      // ManagedChannels use resources like threads and TCP connections. To prevent leaking these
-      // resources the channel should be shut down when it will no longer be used. If it may be used
-      // again leave it running.
-      channel.shutdownNow().awaitTermination(5, TimeUnit.SECONDS);
+        } finally {
+            // ManagedChannels use resources like threads and TCP connections. To prevent leaking these
+            // resources the channel should be shut down when it will no longer be used. If it may be used
+            // again leave it running.
+            channel.shutdownNow().awaitTermination(5, TimeUnit.SECONDS);
+        }
     }
-  }
 }