You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@baremaps.apache.org by GitBox <gi...@apache.org> on 2022/12/09 10:41:43 UTC

[GitHub] [incubator-baremaps] bchapuis commented on a diff in pull request #529: Improve IP to location with a Workflow and a simple web application

bchapuis commented on code in PR #529:
URL: https://github.com/apache/incubator-baremaps/pull/529#discussion_r1044313065


##########
baremaps-core/src/main/java/org/apache/baremaps/workflow/tasks/CreateIplocIndex.java:
##########
@@ -0,0 +1,126 @@
+/*
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
+ * in compliance with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software distributed under the License
+ * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
+ * or implied. See the License for the specific language governing permissions and limitations under
+ * the License.
+ */
+
+package org.apache.baremaps.workflow.tasks;
+
+import org.apache.baremaps.geocoder.geonames.GeonamesGeocoder;
+import org.apache.baremaps.iploc.IpLoc;
+import org.apache.baremaps.iploc.data.IpLocStats;
+import org.apache.baremaps.iploc.database.SqliteUtils;
+import org.apache.baremaps.iploc.nic.NicObject;
+import org.apache.baremaps.iploc.nic.NicParser;
+import org.apache.baremaps.workflow.Task;
+import org.apache.baremaps.workflow.WorkflowContext;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.BufferedInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.UncheckedIOException;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.util.Arrays;
+import java.util.Objects;
+import java.util.stream.Stream;
+
+public record CreateIplocIndex(String geonamesIndexPath, String[] iplocNicPath, String targetIplocIndexPath) implements Task {
+
+  private static final Logger logger = LoggerFactory.getLogger(CreateIplocIndex.class);
+
+  @Override
+  public void execute(WorkflowContext context) throws Exception {
+    logger.info("Generating Iploc from {} {}", geonamesIndexPath, iplocNicPath);
+
+    logger.info("Creating the Geocoder");
+    GeonamesGeocoder geocoder;
+    try {
+      geocoder = new GeonamesGeocoder(Path.of(geonamesIndexPath), null);
+      if (!geocoder.indexExists()) {
+        logger.error("Geocoder index doesn't exist");
+        return;
+      }
+      geocoder.open();
+    } catch(Exception e) {
+      logger.error("Error while creating the geocoder index", e);
+      return;
+    }
+
+    logger.info("Generating NIC objects stream");
+    Stream<NicObject> fetchNicObjectStream = Arrays.stream(iplocNicPath).flatMap(iplocNicPath -> {
+      try {
+        InputStream inputStream = new BufferedInputStream(Files.newInputStream(Path.of(iplocNicPath)));
+        return NicParser.parse(inputStream).onClose(() -> {

Review Comment:
   I think you could replace this with a try with resource and handle the stream (lines 74 to 100) in the try block.
   
   ```java
   try (InputStream inputStream = new BufferedInputStream(Files.newInputStream(Path.of(iplocNicPath)))) {
     // ...
   }
   ```



##########
baremaps-core/src/main/java/org/apache/baremaps/iploc/dto/InetnumLocationDto.java:
##########
@@ -0,0 +1,88 @@
+/*
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
+ * in compliance with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software distributed under the License
+ * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
+ * or implied. See the License for the specific language governing permissions and limitations under
+ * the License.
+ */
+
+package org.apache.baremaps.iploc.dto;
+
+
+
+import org.apache.baremaps.iploc.data.InetnumLocation;
+import org.apache.baremaps.iploc.data.Ipv4;
+
+public class InetnumLocationDto {
+
+  private final String address;
+
+  private final String ipv4Start;
+
+  private final String ipv4End;
+
+  private final double latitude;
+
+  private final double longitude;
+
+  private final String network;
+
+  private final String country;
+
+  public InetnumLocationDto(InetnumLocation inetnumLocation) {
+

Review Comment:
   can we remove these line returns in the constructor?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@baremaps.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org