diff --git a/.gitignore b/.gitignore index f0a7210..2fc6ec6 100644 --- a/.gitignore +++ b/.gitignore @@ -84,3 +84,4 @@ lint/generated/ lint/outputs/ lint/tmp/ # lint/reports/ +Lambdas/Lists/src/main/resources/dbProperties.json diff --git a/Lambdas/Lists/pom.xml b/Lambdas/Lists/pom.xml index 2c6ea85..9442b49 100644 --- a/Lambdas/Lists/pom.xml +++ b/Lambdas/Lists/pom.xml @@ -24,5 +24,19 @@ aws-lambda-java-log4j2 1.2.0 + + org.json + json + 20200518 + + + org.apache.maven.plugins + maven-compiler-plugin + 3.8.1 + + + 1.11 + 1.11 + \ No newline at end of file diff --git a/Lambdas/Lists/src/main/java/DBConnector.java b/Lambdas/Lists/src/main/java/DBConnector.java new file mode 100644 index 0000000..c4f85b9 --- /dev/null +++ b/Lambdas/Lists/src/main/java/DBConnector.java @@ -0,0 +1,32 @@ +import org.json.JSONObject; + +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Path; +import java.sql.Connection; +import java.sql.DriverManager; +import java.sql.SQLException; +import java.util.Properties; + +public class DBConnector { + + Connection connection; + + DBConnector() throws IOException, SQLException { + this(loadProperties("dbProperties.json")); + } + + DBConnector(Properties dbProperties) throws SQLException { + System.out.println(dbProperties); + connection = DriverManager.getConnection(dbProperties.get("url").toString(), dbProperties); + + } + + public static Properties loadProperties(String path) throws IOException { + Properties toReturn = new Properties(); + String propertiesJSONString = Files.readString(Path.of(path)); + JSONObject propertiesJSON = new JSONObject(propertiesJSONString); + propertiesJSON.keys().forEachRemaining(key -> toReturn.setProperty(key, propertiesJSON.get(key).toString())); + return toReturn; + } +} diff --git a/Lambdas/Lists/src/main/java/ListAdd.java b/Lambdas/Lists/src/main/java/ListAdd.java index fe0354b..d5a698b 100644 --- a/Lambdas/Lists/src/main/java/ListAdd.java +++ b/Lambdas/Lists/src/main/java/ListAdd.java @@ -1,3 +1,5 @@ +import java.io.IOException; +import java.sql.SQLException; import java.util.Map; import com.amazonaws.services.lambda.runtime.Context; @@ -17,6 +19,13 @@ public class ListAdd implements RequestHandler, String>{ } System.out.println(inputMap.get("context")); System.out.println(contextMap.get("sub")); + try { + System.out.println(new DBConnector()); + } catch (IOException e) { + e.printStackTrace(); + } catch (SQLException e) { + e.printStackTrace(); + } return null; } } diff --git a/Lambdas/Lists/src/main/java/ListAdder.java b/Lambdas/Lists/src/main/java/ListAdder.java new file mode 100644 index 0000000..413b7db --- /dev/null +++ b/Lambdas/Lists/src/main/java/ListAdder.java @@ -0,0 +1,4 @@ +public class ListAdder { + + +} diff --git a/Lambdas/Lists/target/classes/dbProperties.json b/Lambdas/Lists/target/classes/dbProperties.json new file mode 100644 index 0000000..ba1352b --- /dev/null +++ b/Lambdas/Lists/target/classes/dbProperties.json @@ -0,0 +1,5 @@ +{ + "url": "http://aws.com/something", + "user": "aUser", + "password": "aPassword" +} \ No newline at end of file