Skip to content
This repository was archived by the owner on Sep 18, 2024. It is now read-only.

Commit

Permalink
Merge pull request #28 from Senzing/issue17_sync-with-listener
Browse files Browse the repository at this point in the history
Issue17 sync with listener
  • Loading branch information
oskar700 authored May 13, 2022
2 parents 81c9e62 + 4c8cf5c commit 46d1d4c
Show file tree
Hide file tree
Showing 11 changed files with 65 additions and 134 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
[markdownlint](https://dlaa.me/markdownlint/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [1.0.2] - 2022-05-13

### Added to 1.0.2

- Updated project to match latest release of senzing-listener (v. 0.1.0) and G2 3.0.0.

## [Unreleased]

- Thing 5
Expand Down
85 changes: 1 addition & 84 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,62 +42,6 @@ as well as [OpenJDK](http://openjdk.java.net/) version 11.0.x (recommend version

This application interacts with Senzing API so it needs to be installed beforehand. Information on how to install it can be found here: [Senzing API quick start](https://docs.senzing.com/quickstart/)

You will also need the Senzing `g2.jar` file installed in your Maven repository. This file is included in the Senzing API installation above. In order to install `g2.jar` you must:

1. Locate your
[SENZING_G2_DIR](https://github.com/Senzing/knowledge-base/blob/main/lists/environment-variables.md#senzing_g2_dir)
directory.
The default locations are:
1. [Linux](https://github.com/Senzing/knowledge-base/blob/main/HOWTO/install-senzing-api.md#centos): `/opt/senzing/g2`
1. Windows MSI Installer: `C:\Program Files\Senzing\`

1. Determine your `SENZING_G2_JAR_VERSION` version number:
1. Locate your `g2BuildVersion.json` file:
1. Linux: `${SENZING_G2_DIR}/g2BuildVersion.json`
1. Windows: `${SENZING_G2_DIR}\data\g2BuildVersion.json`
1. Find the value for the `"VERSION"` property in the JSON contents.
Example:

```console
{
"PLATFORM": "Linux",
"VERSION": "1.14.20060",
"API_VERSION": "1.14.3",
"BUILD_NUMBER": "2020_02_29__02_00"
}
```

1. Install the `g2.jar` file in your local Maven repository, replacing the
`${SENZING_G2_DIR}` and `${SENZING_G2_JAR_VERSION}` variables as determined above:

1. Linux:

```console
export SENZING_G2_DIR=/opt/senzing/g2
export SENZING_G2_JAR_VERSION=1.14.3

mvn install:install-file \
-Dfile=${SENZING_G2_DIR}/lib/g2.jar \
-DgroupId=com.senzing \
-DartifactId=g2 \
-Dversion=${SENZING_G2_JAR_VERSION} \
-Dpackaging=jar
```

1. Windows:

```console
set SENZING_G2_DIR="C:\Program Files\Senzing\g2"
set SENZING_G2_JAR_VERSION=1.14.3

mvn install:install-file \
-Dfile="%SENZING_G2_DIR%\lib\g2.jar" \
-DgroupId=com.senzing \
-DartifactId=g2 \
-Dversion="%SENZING_G2_JAR_VERSION%" \
-Dpackaging=jar
```

1. Setup your environment. The Connector relies on native libraries and the
environment must be properly setup to find those libraries:

Expand All @@ -119,34 +63,7 @@ You will also need the Senzing `g2.jar` file installed in your Maven repository.

### Building

The Neo4j connector is built on [Senzing listener](https://github.com/Senzing/senzing-listener) framework pre-release version 0.0.1.
Download the [version 0.0.1 pre-release Senzing Listener](https://github.com/Senzing/senzing-listener/releases/tag/0.0.1) or clone
the [Senzing Listener](https://github.com/Senzing/senzing-listener) repository using the `--branch` to grab the `0.0.1` tag specifically.
The steps for building the listener are:


#### Option 1: Download the [ZIP file](https://github.com/Senzing/senzing-listener/archive/refs/tags/0.0.1.zip), extract and then build specific release.
```console
unzip [path-to-download]/senzing-listener-0.0.1.zip
cd senzing-listener-0.0.1
mvn clean install
```

#### Option 2: Download the [Gzip Tar file](https://github.com/Senzing/senzing-listener/archive/refs/tags/0.0.1.tar.gz), extract and then build specific release.
```console
tar -xf [path-to-download]/senzing-listener-0.0.1.tar.gz
cd senzing-listener-0.0.1
mvn clean install
```

#### Option 3: Clone repository to the specific `0.0.1` tag.
```console
git clone --branch 0.0.1 [email protected]:Senzing/senzing-listener.git
cd senzing-listener
mvn clean install
```

To build connector-neo4j simply execute:
To build connector-neo4j:

```console
git clone [email protected]:Senzing/connector-neo4j.git
Expand Down
22 changes: 15 additions & 7 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>com.senzing</groupId>
<artifactId>neo4j-connector</artifactId>
<version>0.1-SNAPSHOT</version>
<version>0.1.0</version>
<packaging>jar</packaging>
<name>G2 Neo4J Connector</name>
<description>G2 Neo4J connector app</description>
Expand All @@ -19,7 +19,7 @@
<dependency>
<groupId>com.senzing</groupId>
<artifactId>senzing-listener</artifactId>
<version>0.0.1</version>
<version>0.1.0</version>
</dependency>
<!-- tag::bolt-dependency[] -->
<dependency>
Expand Down Expand Up @@ -61,11 +61,6 @@
<artifactId>json</artifactId>
<version>20090211</version>
</dependency>
<dependency>
<groupId>com.senzing</groupId>
<artifactId>g2</artifactId>
<version>[1.14.0-SNAPSHOT,2.999.999)</version>
</dependency>
<dependency>
<groupId>com.rabbitmq</groupId>
<artifactId>amqp-client</artifactId>
Expand All @@ -79,6 +74,19 @@
</dependency>
</dependencies>

<repositories>
<repository>
<id>mvn-repo</id>
<url>http://github.com/Senzing/senzing-listener</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
</repositories>

<build>
<resources>
<resource>
Expand Down
14 changes: 7 additions & 7 deletions src/main/java/com/senzing/neo4j/connector/Neo4jConnector.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@
import javax.json.JsonObject;
import javax.json.JsonReader;

import com.senzing.listener.senzing.communication.ConsumerType;
import com.senzing.listener.senzing.communication.MessageConsumer;
import com.senzing.listener.senzing.communication.MessageConsumerFactory;
import com.senzing.listener.senzing.data.ConsumerCommandOptions;
import com.senzing.listener.senzing.service.exception.ServiceSetupException;
import com.senzing.listener.communication.ConsumerType;
import com.senzing.listener.communication.MessageConsumer;
import com.senzing.listener.communication.MessageConsumerFactory;
import com.senzing.listener.service.exception.ServiceSetupException;
import com.senzing.neo4j.connector.cmdline.CommandOptions;
import com.senzing.neo4j.connector.service.Neo4jConnectorService;

/**
Expand All @@ -33,7 +33,7 @@ public class Neo4jConnector {
* @throws MessageConsumerSetupException
*/
public void run(String config) throws ServiceSetupException, Exception {
String consumerType = getConfigValue(config, ConsumerCommandOptions.CONSUMER_TYPE);
String consumerType = getConfigValue(config, CommandOptions.CONSUMER_TYPE);
if (consumerType == null || consumerType.isEmpty()) {
consumerType = "rabbitmq";
}
Expand All @@ -58,7 +58,7 @@ public void run(String config) throws ServiceSetupException, Exception {
cnt = 0;
}
}
service.cleanUp();
service.destroy();
}

private String getConfigValue(String config, String key) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
import org.apache.commons.cli.ParseException;
import org.json.JSONException;

import com.senzing.listener.senzing.communication.ConsumerType;
import com.senzing.listener.senzing.data.ConsumerCommandOptions;
import com.senzing.listener.communication.ConsumerType;
import com.senzing.listener.communication.rabbitmq.RabbitMQConsumer;
import com.senzing.neo4j.connector.cmdline.CommandOptions;
import com.senzing.neo4j.connector.config.AppConfiguration;
import com.senzing.neo4j.connector.config.ConfigKeys;
Expand All @@ -28,13 +28,13 @@
*/
public class Neo4jConnectorApplication {

private static final String RABBITMQ_CONSUMER_TYPE = ConsumerType.rabbitmq.toString();
private static final String RABBITMQ_CONSUMER_TYPE = ConsumerType.RABBIT_MQ.toString();

private static Map<String, Object> configValues;

public static void main(String[] args) {
configValues = new HashMap<>();
configValues.put(ConsumerCommandOptions.CONSUMER_TYPE, RABBITMQ_CONSUMER_TYPE);
configValues.put(CommandOptions.CONSUMER_TYPE, RABBITMQ_CONSUMER_TYPE);
try {
processConfigFileConfiguration();
// Process the command line arguments after the config file since they override config file values.
Expand All @@ -53,15 +53,15 @@ public static void main(String[] args) {
private static void processConfigFileConfiguration() {
try {
AppConfiguration config = new AppConfiguration();
configValues.put(ConsumerCommandOptions.CONSUMER_TYPE, RABBITMQ_CONSUMER_TYPE);
configValues.put(CommandOptions.CONSUMER_TYPE, RABBITMQ_CONSUMER_TYPE);
configValues.put(CommandOptions.INI_FILE, config.getConfigValue(ConfigKeys.G2_INI_FILE));
configValues.put(CommandOptions.NEO4J_CONNECTION, config.getConfigValue(ConfigKeys.NEO4J_URI));
configValues.put(ConsumerCommandOptions.MQ_HOST, config.getConfigValue(ConfigKeys.RABBITMQ_HOST));
configValues.put(ConsumerCommandOptions.MQ_QUEUE, config.getConfigValue(ConfigKeys.RABBITMQ_NAME));
configValues.put(ConsumerCommandOptions.MQ_USER, config.getConfigValue(ConfigKeys.RABBITMQ_USER_NAME));
configValues.put(ConsumerCommandOptions.MQ_PASSWORD, config.getConfigValue(ConfigKeys.RABBITMQ_PASSWORD));
configValues.put(RabbitMQConsumer.MQ_HOST, config.getConfigValue(ConfigKeys.RABBITMQ_HOST));
configValues.put(RabbitMQConsumer.MQ_QUEUE, config.getConfigValue(ConfigKeys.RABBITMQ_NAME));
configValues.put(RabbitMQConsumer.MQ_USER, config.getConfigValue(ConfigKeys.RABBITMQ_USER_NAME));
configValues.put(RabbitMQConsumer.MQ_PASSWORD, config.getConfigValue(ConfigKeys.RABBITMQ_PASSWORD));
// This is a future enhancement and enabled when other consumers have been added.
//configValues.put(ConsumerCommandOptions.CONSUMER_TYPE, config.getConfigValue(ConfigKeys.CONSUMER_TYPE));
//configValues.put(CommandOptions.CONSUMER_TYPE, config.getConfigValue(ConfigKeys.CONSUMER_TYPE));
} catch (IOException e) {
System.out.println("Configuration file not found. Expecting command line arguments.");
}
Expand All @@ -82,11 +82,11 @@ private static void processArguments(String[] args) throws ParseException, JSONE
CommandLine commandLine = parser.parse(options, args);

addCommandLineValue(commandLine, CommandOptions.INI_FILE);
addCommandLineValue(commandLine, ConsumerCommandOptions.MQ_HOST);
addCommandLineValue(commandLine, ConsumerCommandOptions.MQ_USER);
addCommandLineValue(commandLine, ConsumerCommandOptions.MQ_PASSWORD);
addCommandLineValue(commandLine, ConsumerCommandOptions.MQ_QUEUE);
addCommandLineValue(commandLine, ConsumerCommandOptions.CONSUMER_TYPE);
addCommandLineValue(commandLine, RabbitMQConsumer.MQ_HOST);
addCommandLineValue(commandLine, RabbitMQConsumer.MQ_USER);
addCommandLineValue(commandLine, RabbitMQConsumer.MQ_PASSWORD);
addCommandLineValue(commandLine, RabbitMQConsumer.MQ_QUEUE);
addCommandLineValue(commandLine, CommandOptions.CONSUMER_TYPE);
addCommandLineValue(commandLine, CommandOptions.NEO4J_CONNECTION);
}

Expand All @@ -99,8 +99,8 @@ private static void addCommandLineValue(CommandLine commandLine, String key) {
private static void validateCommandLineParams() {
List<String> unsetParameters = new ArrayList<>();
checkParameter(unsetParameters, CommandOptions.INI_FILE);
checkParameter(unsetParameters, ConsumerCommandOptions.MQ_HOST);
checkParameter(unsetParameters, ConsumerCommandOptions.MQ_QUEUE);
checkParameter(unsetParameters, RabbitMQConsumer.MQ_HOST);
checkParameter(unsetParameters, RabbitMQConsumer.MQ_QUEUE);

if (!unsetParameters.isEmpty()) {
System.out.println("No configuration found for parameters: " + String.join(", ", unsetParameters));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,10 @@
import org.json.JSONException;
import org.json.JSONObject;

import com.senzing.listener.senzing.data.Definitions;
import com.senzing.listener.senzing.service.ListenerService;
import com.senzing.listener.senzing.service.exception.ServiceExecutionException;
import com.senzing.listener.senzing.service.exception.ServiceSetupException;
import com.senzing.listener.senzing.service.g2.G2Service;
import com.senzing.listener.service.ListenerService;
import com.senzing.listener.service.exception.ServiceExecutionException;
import com.senzing.listener.service.exception.ServiceSetupException;
import com.senzing.listener.service.g2.G2Service;
import com.senzing.neo4j.connector.cmdline.CommandOptions;
import com.senzing.neo4j.connector.config.AppConfiguration;
import com.senzing.neo4j.connector.config.ConfigKeys;
Expand Down Expand Up @@ -166,7 +165,8 @@ public void process(String message) throws ServiceExecutionException {
for (int i = 0; i < entities.size(); i++) {
JsonObject entity = entities.getJsonObject(i);
if (entity != null) {
Long entityID = entity.getJsonNumber(Definitions.ENTITY_ID_FIELD).longValue();
//Long entityID = entity.getJsonNumber(Definitions.ENTITY_ID_FIELD).longValue();
Long entityID = entity.getJsonNumber(G2Entity.ENTITY_ID_FIELD).longValue();
processEntity(entityID);
}
}
Expand Down Expand Up @@ -195,8 +195,8 @@ public String getStats() {
* Cleans up the service. Closes G2 and graph database connections and frees up resources.
*/
@Override
public void cleanUp() {
g2Service.cleanUp();
public void destroy() {
g2Service.destroy();
graphService.cleanUp();
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.senzing.neo4j.connector.service.graph;

import com.senzing.listener.senzing.service.exception.ServiceExecutionException;
import com.senzing.listener.service.exception.ServiceExecutionException;
import com.senzing.neo4j.connector.data.g2.G2Entity;

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.senzing.neo4j.connector.service.graph;

import com.senzing.listener.senzing.service.exception.ServiceSetupException;
import com.senzing.listener.service.exception.ServiceSetupException;
import com.senzing.neo4j.connector.service.graph.neo4j.Neo4jService;

public class GraphServiceFactory {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
import org.json.JSONException;
import org.json.JSONObject;

import com.senzing.listener.senzing.service.exception.ServiceExecutionException;
import com.senzing.listener.senzing.service.exception.ServiceSetupException;
import com.senzing.listener.service.exception.ServiceExecutionException;
import com.senzing.listener.service.exception.ServiceSetupException;
import com.senzing.neo4j.connector.cmdline.CommandOptions;
import com.senzing.neo4j.connector.config.AppConfiguration;
import com.senzing.neo4j.connector.config.ConfigKeys;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
import org.junit.Test;
import org.junit.runner.RunWith;

import com.senzing.listener.senzing.service.exception.ServiceExecutionException;
import com.senzing.listener.senzing.service.exception.ServiceSetupException;
import com.senzing.listener.senzing.service.g2.G2Service;
import com.senzing.listener.service.exception.ServiceExecutionException;
import com.senzing.listener.service.exception.ServiceSetupException;
import com.senzing.listener.service.g2.G2Service;
import com.senzing.neo4j.connector.config.AppConfiguration;
import com.senzing.neo4j.connector.config.ConfigKeys;
import com.senzing.neo4j.connector.graphdatabase.neo4j.CypherQuery;
Expand Down Expand Up @@ -184,7 +184,7 @@ public String getConfigValue(String configParameter) {
}

@Test
public void mainServiceWithWrongGraphType() throws com.senzing.listener.senzing.service.exception.ServiceSetupException {
public void mainServiceWithWrongGraphType() throws com.senzing.listener.service.exception.ServiceSetupException {
new MockUp<AppConfiguration>() {
@Mock
public String getConfigValue(String configParameter) {
Expand All @@ -202,7 +202,7 @@ public String getConfigValue(String configParameter) {
try {
new Neo4jConnectorService().init("{}");;
fail("Should have thrown an exception");
} catch (com.senzing.listener.senzing.service.exception.ServiceSetupException e) {
} catch (com.senzing.listener.service.exception.ServiceSetupException e) {
assertThat(e.getMessage(), is(equalTo("Invalid graph database type specified: titan")));
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
import org.junit.Test;
import org.junit.runner.RunWith;

import com.senzing.listener.senzing.service.exception.ServiceExecutionException;
import com.senzing.listener.senzing.service.exception.ServiceSetupException;
import com.senzing.listener.service.exception.ServiceExecutionException;
import com.senzing.listener.service.exception.ServiceSetupException;
import com.senzing.neo4j.connector.config.AppConfiguration;
import com.senzing.neo4j.connector.data.g2.G2Entity;
import com.senzing.neo4j.connector.graphdatabase.exception.GraphDatabaseConnectionException;
Expand Down

0 comments on commit 46d1d4c

Please sign in to comment.