Skip to content

Commit

Permalink
refactor(connector): merge [WIP]
Browse files Browse the repository at this point in the history
  • Loading branch information
averni committed Mar 24, 2023
1 parent 6471623 commit 3fc4432
Show file tree
Hide file tree
Showing 13 changed files with 443 additions and 59 deletions.
4 changes: 2 additions & 2 deletions connector/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ WORKDIR /app

ARG DEPENDENCY=/app/target/dependency
COPY --from=build /app/target/*.jar /app/
COPY --from=build ${DEPENDENCY}/BOOT-INF/lib /app/lib
COPY --from=build ${DEPENDENCY}/META-INF /app/META-INF
# COPY --from=build ${DEPENDENCY}/BOOT-INF/lib /app/lib
# COPY --from=build ${DEPENDENCY}/META-INF /app/META-INF

COPY mvnw .

Expand Down
74 changes: 61 additions & 13 deletions connector/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,13 @@
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<license.maven.plugin.version>4.1</license.maven.plugin.version>
<!-- <spring-shell.version>3.0.0-M2</spring-shell.version> -->
<version.swagger.codegen>3.0.41</version.swagger.codegen>
<yaml.file>${project.basedir}/src/main/resources/ohpp-api.yaml</yaml.file>
<generated-sources-path>${project.build.directory}/generated-sources</generated-sources-path>
<generated-sources-java-path>main/java</generated-sources-java-path>
<springfox-swagger.version>2.6.1</springfox-swagger.version>
<joda.version>2.1</joda.version>
<start-class>org.isf.patientportal.connector.ConnectorApplication</start-class>
</properties>
<dependencies>
<!-- <dependency>
Expand All @@ -42,12 +49,12 @@
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-log4j2</artifactId>
<exclusions>
<!--exclusions>
<exclusion>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-slf4j-impl</artifactId>
</exclusion>
</exclusions>
</exclusions-->
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
Expand Down Expand Up @@ -76,16 +83,6 @@
<artifactId>spring-batch-test</artifactId>
<scope>test</scope>
</dependency-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-log4j2</artifactId>
<exclusions>
<exclusion>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-slf4j-impl</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
Expand All @@ -98,7 +95,43 @@
<version>3.0.0</version>
</dependency>

<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.14.2</version>
</dependency>

<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-boot-starter</artifactId>
<version>3.0.0</version>
</dependency>

<dependency>
<groupId>io.swagger.core.v3</groupId>
<artifactId>swagger-annotations</artifactId>
<version>2.2.8</version>
</dependency>


<dependency>
<groupId>javax.validation</groupId>
<artifactId>validation-api</artifactId>
<version>2.0.1.Final</version>
</dependency>

<dependency>
<groupId>org.openapitools</groupId>
<artifactId>jackson-databind-nullable</artifactId>
<version>0.2.1</version>
</dependency>

<dependency>
<groupId>joda-time</groupId>
<artifactId>joda-time</artifactId>
<version>${joda.version}</version>
</dependency>

<dependency>
<groupId>org.isf</groupId>
<artifactId>OH-core</artifactId>
Expand Down Expand Up @@ -130,6 +163,15 @@
</dependencyManagement> -->

<build>
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
<excludes>
<exclude>**/conf.properties</exclude>
</excludes>
</resource>
</resources>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
Expand All @@ -143,8 +185,11 @@
<artifactId>spring-boot-maven-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
<configuration>
<mainClass>org.isf.patientportal.connector.ConnectorApplication</mainClass>
<mainClass>${spring.boot.mainclass}</mainClass>
</configuration>
</execution>
</executions>
Expand All @@ -155,6 +200,9 @@
<profiles>
<profile>
<id>release</id>
<properties>
<spring.boot.mainclass>org.isf.patientportal.connector.ConnectorApplication</spring.boot.mainclass>
</properties>
<build>
<plugins>
<plugin>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,26 @@
package org.isf.patientportal.connector;


import org.isf.generaldata.GeneralData;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;

import org.isf.patientportal.connector.common.SyncReport;
import org.isf.patientportal.connector.config.ConnectorConfiguration;
import org.isf.patientportal.connector.sync.common.SyncResult;
import org.isf.patientportal.connector.sync.patient.PatientSource;
import org.isf.patientportal.connector.sync.patient.PatientSyncer;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ImportResource;

@ImportResource({"classpath*:**/applicationContext.xml"})
Expand All @@ -15,14 +29,45 @@ public class ConnectorApplication implements CommandLineRunner {

private static final Logger logger = LoggerFactory.getLogger(ConnectorApplication.class);

@Autowired
private PatientSource patientSource;


public static void main(String[] args) {
SpringApplication.run(ConnectorApplication.class, args);
}

@Bean
protected PatientSyncer patientSyncer() {
return new PatientSyncer();
}

@Override
public void run(String... args) throws Exception {
logger.debug("Starting oh connector using config file");
GeneralData.getGeneralData();
logger.info("Starting oh connector using config ");
logger.info("Api url " + ConnectorConfiguration.API_URL);
logger.info("Using " + ConnectorConfiguration.PARALLEL + " threads");

ExecutorService executor = Executors.newFixedThreadPool(ConnectorConfiguration.PARALLEL);
List<Integer> patientIds = patientSource.getPatientIds();
logger.info("Found " + patientIds.size() + " patients to sync");
List<Callable<SyncResult>> patientsToSync = new ArrayList<Callable<SyncResult>>();
for (Integer patientId : patientIds) {
PatientSyncer patientSyncer = new PatientSyncer(patientId);
patientSyncer.setPatientManager(patientSource.getPatientManager());
patientsToSync.add(patientSyncer);
}
List<Future<SyncResult>> results = executor.invokeAll(patientsToSync);
executor.shutdown();

SyncReport report = new SyncReport();
for (Future<SyncResult> future : results) {
SyncResult result = future.get();
report.addResult(result);
}

logger.info("Sync report: " + report);

}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package org.isf.patientportal.connector.common;

import java.util.ArrayList;

import org.isf.patientportal.connector.sync.common.SyncResult;

public class SyncReport {

protected ArrayList<SyncResult> results;

public SyncReport() {
results = new ArrayList<SyncResult>();
}


public void addResult(SyncResult result) {
results.add(result);
}

public ArrayList<SyncResult> getResults() {
return results;
}

public String toString() {
StringBuilder sb = new StringBuilder();
sb.append("Sync report:\n");
for (SyncResult result : results) {
sb.append("Synced " + result.getObjectId() + "[" + result.getObjectType() + "] OP " + result.getOp().name() + " with result " + result.isSuccess() + " and message " + result.getMessage() + "\n");
sb.append("\n");
}
return sb.toString();
}

}
Original file line number Diff line number Diff line change
@@ -1,14 +1,20 @@
package org.isf.patientportal.connector.config;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

public class Configuration {
@Configuration
public class ConnectorConfiguration {
@Value("${oh.api.key}")
public static String API_KEY = "1234567890";

@Value("${oh.api.token}")
public static String API_TOKEN = "1234567890";

@Value("${oh.api.url}")
public static String API_URL = "http://localhost:8080/patient-portal/api";

@Value("${oh.api.parallel}")
public static int PARALLEL = 2;

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
package org.isf.patientportal.connector.runner;


import org.isf.patientportal.connector.config.Configuration;
import org.isf.patientportal.connector.config.ConnectorConfiguration;

public class ImportRunner {
public void syncPatient(int patientId) {
System.out.println("Syncing patients");
}

public void run() {
int numThreads = Configuration.PARALLEL;
int numThreads = ConnectorConfiguration.PARALLEL;


}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
package org.isf.patientportal.connector.sync.common;


public class SyncResult {

public enum Op {
NOOP, UPDATE, CREATE, DELETE, ERROR
}

private int objectId;
private String objectType;
private boolean success;
private String message;
private Op resultType;

public SyncResult() {
}

public SyncResult(int objectId, String objectType, boolean success, String message, Op resultType) {
this.objectId = objectId;
this.objectType = objectType;
this.success = success;
this.message = message;
this.resultType = resultType;
}

public int getObjectId() {
return objectId;
}
public void setObjectId(int objectId) {
this.objectId = objectId;
}
public String getObjectType() {
return objectType;
}
public void setObjectType(String objectType) {
this.objectType = objectType;
}
public boolean isSuccess() {
return success;
}
public void setSuccess(boolean success) {
this.success = success;
}
public String getMessage() {
return message;
}
public void setMessage(String message) {
this.message = message;
}
public Op getOp() {
return resultType;
}
public void setOp(Op resultType) {
this.resultType = resultType;
}
}
Loading

0 comments on commit 3fc4432

Please sign in to comment.