mirror of
https://github.com/ClaytonWWilson/Listify.git
synced 2026-03-10 18:55:03 +00:00
Merge pull request #30 from ClaytonWWilson/ClientLambdas
Client lambdas
This commit is contained in:
124
Lambdas/Lists/Item/src/Item.java
Normal file
124
Lambdas/Lists/Item/src/Item.java
Normal file
@@ -0,0 +1,124 @@
|
||||
import java.math.BigDecimal;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
public class Item {
|
||||
Integer productID;
|
||||
Integer chainID;
|
||||
String upc;
|
||||
String description;
|
||||
BigDecimal price;
|
||||
String imageURL;
|
||||
String department;
|
||||
LocalDateTime retrievedDate;
|
||||
Integer fetchCounts;
|
||||
|
||||
Item(ResultSet itemRow) throws SQLException {
|
||||
this.productID = itemRow.getInt(1);
|
||||
System.out.println(this.productID);
|
||||
this.chainID = itemRow.getInt(2);
|
||||
System.out.println(this.chainID);
|
||||
this.upc = itemRow.getString(3);
|
||||
System.out.println(this.upc);
|
||||
this.description = itemRow.getString(4);
|
||||
System.out.println(this.description);
|
||||
this.price = itemRow.getBigDecimal(5);
|
||||
System.out.println(this.price);
|
||||
this.imageURL = itemRow.getString(6);
|
||||
System.out.println(imageURL);
|
||||
this.department = itemRow.getString(7);
|
||||
System.out.println(department);
|
||||
this.retrievedDate = itemRow.getObject(8, LocalDateTime.class);
|
||||
System.out.println(retrievedDate);
|
||||
this.fetchCounts = itemRow.getInt(9);
|
||||
System.out.println(fetchCounts);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Item{" +
|
||||
"productID=" + productID +
|
||||
", chainID=" + chainID +
|
||||
", upc='" + upc + '\'' +
|
||||
", description='" + description + '\'' +
|
||||
", price=" + price +
|
||||
", imageURL='" + imageURL + '\'' +
|
||||
", department='" + department + '\'' +
|
||||
", retrievedDate=" + retrievedDate +
|
||||
", fetchCounts=" + fetchCounts +
|
||||
'}';
|
||||
}
|
||||
|
||||
public Integer getProductID() {
|
||||
return productID;
|
||||
}
|
||||
|
||||
public void setProductID(Integer productID) {
|
||||
this.productID = productID;
|
||||
}
|
||||
|
||||
public Integer getChainID() {
|
||||
return chainID;
|
||||
}
|
||||
|
||||
public void setChainID(Integer chainID) {
|
||||
this.chainID = chainID;
|
||||
}
|
||||
|
||||
public String getUpc() {
|
||||
return upc;
|
||||
}
|
||||
|
||||
public void setUpc(String upc) {
|
||||
this.upc = upc;
|
||||
}
|
||||
|
||||
public String getDescription() {
|
||||
return description;
|
||||
}
|
||||
|
||||
public void setDescription(String description) {
|
||||
this.description = description;
|
||||
}
|
||||
|
||||
public BigDecimal getPrice() {
|
||||
return price;
|
||||
}
|
||||
|
||||
public void setPrice(BigDecimal price) {
|
||||
this.price = price;
|
||||
}
|
||||
|
||||
public String getImageURL() {
|
||||
return imageURL;
|
||||
}
|
||||
|
||||
public void setImageURL(String imageURL) {
|
||||
this.imageURL = imageURL;
|
||||
}
|
||||
|
||||
public String getDepartment() {
|
||||
return department;
|
||||
}
|
||||
|
||||
public void setDepartment(String department) {
|
||||
this.department = department;
|
||||
}
|
||||
|
||||
public LocalDateTime getRetrievedDate() {
|
||||
return retrievedDate;
|
||||
}
|
||||
|
||||
public void setRetrievedDate(LocalDateTime retrievedDate) {
|
||||
this.retrievedDate = retrievedDate;
|
||||
}
|
||||
|
||||
public Integer getFetchCounts() {
|
||||
return fetchCounts;
|
||||
}
|
||||
|
||||
public void setFetchCounts(Integer fetchCounts) {
|
||||
this.fetchCounts = fetchCounts;
|
||||
}
|
||||
}
|
||||
11
Lambdas/Lists/Item/src/ItemGET.java
Normal file
11
Lambdas/Lists/Item/src/ItemGET.java
Normal file
@@ -0,0 +1,11 @@
|
||||
import com.amazonaws.services.lambda.runtime.Context;
|
||||
import com.amazonaws.services.lambda.runtime.RequestHandler;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
public class ItemGET implements RequestHandler<Map<String,Object>, Object> {
|
||||
|
||||
public Object handleRequest(Map<String, Object> inputMap, Context unfilled) {
|
||||
return BasicHandler.handleRequest(inputMap, unfilled, ItemGetter.class);
|
||||
}
|
||||
}
|
||||
36
Lambdas/Lists/Item/src/ItemGetter.java
Normal file
36
Lambdas/Lists/Item/src/ItemGetter.java
Normal file
@@ -0,0 +1,36 @@
|
||||
import com.google.gson.Gson;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class ItemGetter implements CallHandler{
|
||||
private final DBConnector connector;
|
||||
|
||||
private final String GET_ITEM = "SELECT * FROM Product WHERE productID = ?;";
|
||||
|
||||
public ItemGetter(DBConnector connector, String cognitoID) {
|
||||
this.connector = connector;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object conductAction(Map<String, Object> bodyMap, HashMap<String, String> queryMap, String cognitoID) throws SQLException {
|
||||
Connection connection = connector.getConnection();
|
||||
try {
|
||||
PreparedStatement statement = connection.prepareStatement(GET_ITEM);
|
||||
statement.setInt(1, Integer.parseInt(queryMap.get("id")));
|
||||
System.out.println(statement);
|
||||
ResultSet queryResults = statement.executeQuery();
|
||||
queryResults.first();
|
||||
System.out.println(queryResults);
|
||||
Item retrievedItem = new Item(queryResults);
|
||||
System.out.println(retrievedItem);
|
||||
return retrievedItem;
|
||||
} finally {
|
||||
connection.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
50
Lambdas/Lists/List/src/ItemEntry.java
Normal file
50
Lambdas/Lists/List/src/ItemEntry.java
Normal file
@@ -0,0 +1,50 @@
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
public class ItemEntry {
|
||||
Integer listID;
|
||||
Integer productID;
|
||||
Integer quantity;
|
||||
LocalDateTime addedDate;
|
||||
Boolean purchased;
|
||||
public ItemEntry(Integer listID, ResultSet listRow) throws SQLException {
|
||||
this.listID = listID;
|
||||
productID = listRow.getInt(1);
|
||||
quantity = listRow.getInt(2);
|
||||
addedDate = listRow.getObject(3, LocalDateTime.class);
|
||||
purchased = listRow.getBoolean(4);
|
||||
}
|
||||
|
||||
public Integer getProductID() {
|
||||
return productID;
|
||||
}
|
||||
|
||||
public void setProductID(Integer productID) {
|
||||
this.productID = productID;
|
||||
}
|
||||
|
||||
public Integer getQuantity() {
|
||||
return quantity;
|
||||
}
|
||||
|
||||
public void setQuantity(Integer quantity) {
|
||||
this.quantity = quantity;
|
||||
}
|
||||
|
||||
public LocalDateTime getAddedDate() {
|
||||
return addedDate;
|
||||
}
|
||||
|
||||
public void setAddedDate(LocalDateTime addedDate) {
|
||||
this.addedDate = addedDate;
|
||||
}
|
||||
|
||||
public Boolean getPurchased() {
|
||||
return purchased;
|
||||
}
|
||||
|
||||
public void setPurchased(Boolean purchased) {
|
||||
this.purchased = purchased;
|
||||
}
|
||||
}
|
||||
72
Lambdas/Lists/List/src/List.java
Normal file
72
Lambdas/Lists/List/src/List.java
Normal file
@@ -0,0 +1,72 @@
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.time.Instant;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class List {
|
||||
Integer itemID;
|
||||
String name;
|
||||
String owner;
|
||||
long lastUpdated;
|
||||
ArrayList<ItemEntry> entries;
|
||||
|
||||
public List(ResultSet listRow) throws SQLException {
|
||||
itemID = listRow.getInt("listID");
|
||||
name = listRow.getString("name");
|
||||
owner = listRow.getString("owner");
|
||||
lastUpdated = listRow.getTimestamp("lastUpdated").toInstant().toEpochMilli();
|
||||
entries = new ArrayList<>();
|
||||
}
|
||||
|
||||
public void addItemEntry(ItemEntry entry) {
|
||||
entries.add(entry);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "List{" +
|
||||
"itemID=" + itemID +
|
||||
", name='" + name + '\'' +
|
||||
", owner='" + owner + '\'' +
|
||||
", lastUpdated=" + lastUpdated +
|
||||
", entries=" + entries +
|
||||
'}';
|
||||
}
|
||||
|
||||
public ItemEntry[] getEntries() {
|
||||
return entries.toArray(new ItemEntry[entries.size()]);
|
||||
}
|
||||
|
||||
public Integer getItemID() {
|
||||
return itemID;
|
||||
}
|
||||
|
||||
public void setItemID(Integer itemID) {
|
||||
this.itemID = itemID;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getOwner() {
|
||||
return owner;
|
||||
}
|
||||
|
||||
public void setOwner(String owner) {
|
||||
this.owner = owner;
|
||||
}
|
||||
|
||||
public long getLastUpdated() {
|
||||
return lastUpdated;
|
||||
}
|
||||
|
||||
public void setLastUpdated(long lastUpdated) {
|
||||
this.lastUpdated = lastUpdated;
|
||||
}
|
||||
}
|
||||
33
Lambdas/Lists/List/src/ListAdder.java
Normal file
33
Lambdas/Lists/List/src/ListAdder.java
Normal file
@@ -0,0 +1,33 @@
|
||||
import java.sql.*;
|
||||
import java.time.Instant;
|
||||
import java.time.ZoneOffset;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class ListAdder implements CallHandler {
|
||||
|
||||
private DBConnector connector;
|
||||
private String cognitoID;
|
||||
|
||||
private final String LIST_CREATE = "INSERT INTO List (name, owner, lastUpdated) VALUES (?, ?, ?)";
|
||||
|
||||
public ListAdder(DBConnector connector, String cognitoID) {
|
||||
this.connector = connector;
|
||||
this.cognitoID = cognitoID;
|
||||
}
|
||||
|
||||
public Object conductAction(Map<String, Object> bodyMap, HashMap<String, String> queryString, String cognitoID) throws SQLException {
|
||||
Connection connection = connector.getConnection();
|
||||
PreparedStatement statement = connection.prepareStatement(LIST_CREATE, Statement.RETURN_GENERATED_KEYS);
|
||||
statement.setString(1, bodyMap.get("name").toString());//Needs safe checking
|
||||
statement.setString(2, cognitoID);
|
||||
statement.setTimestamp(3, Timestamp.from(Instant.now()));
|
||||
System.out.println(statement);
|
||||
statement.executeUpdate();
|
||||
ResultSet newIDRS = statement.getGeneratedKeys();
|
||||
newIDRS.first();
|
||||
Integer newID = newIDRS.getInt(1);
|
||||
connection.commit();
|
||||
return newID;
|
||||
}
|
||||
}
|
||||
12
Lambdas/Lists/List/src/ListGET.java
Normal file
12
Lambdas/Lists/List/src/ListGET.java
Normal file
@@ -0,0 +1,12 @@
|
||||
import com.amazonaws.services.lambda.runtime.Context;
|
||||
import com.amazonaws.services.lambda.runtime.RequestHandler;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
public class ListGET implements RequestHandler<Map<String,Object>, Object> {
|
||||
|
||||
public Object handleRequest(Map<String, Object> inputMap, Context unfilled) {
|
||||
return BasicHandler.handleRequest(inputMap, unfilled, ListGetter.class);
|
||||
}
|
||||
|
||||
}
|
||||
58
Lambdas/Lists/List/src/ListGetter.java
Normal file
58
Lambdas/Lists/List/src/ListGetter.java
Normal file
@@ -0,0 +1,58 @@
|
||||
import com.google.gson.Gson;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class ListGetter implements CallHandler{
|
||||
private final DBConnector connector;
|
||||
private final String cognitoID;
|
||||
|
||||
private final String GET_LIST = "SELECT * FROM List WHERE listID = ?;";
|
||||
private final String GET_LISTS = "SELECT listID FROM List WHERE owner = ?;";
|
||||
private final String GET_ENTRIES = "SELECT * FROM ListProduct WHERE listID = ?;";
|
||||
|
||||
public ListGetter(DBConnector connector, String cognitoID) {
|
||||
this.connector = connector;
|
||||
this.cognitoID = cognitoID;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object conductAction(Map<String, Object> bodyMap, HashMap<String, String> queryMap, String cognitoID) throws SQLException {
|
||||
try (Connection connection = connector.getConnection()) {
|
||||
Integer id = Integer.parseInt(queryMap.get("id"));
|
||||
if (id == -1) {
|
||||
PreparedStatement getLists = connection.prepareStatement(GET_LISTS);
|
||||
getLists.setString(1, cognitoID);
|
||||
System.out.println(getLists);
|
||||
ResultSet getListsResults = getLists.executeQuery();
|
||||
System.out.println(getListsResults);
|
||||
ArrayList<Integer> listIds = new ArrayList<>();
|
||||
while (getListsResults.next()) {
|
||||
listIds.add(getListsResults.getInt(1));
|
||||
}
|
||||
return listIds;
|
||||
}
|
||||
PreparedStatement getList = connection.prepareStatement(GET_LIST);
|
||||
getList.setInt(1, id);
|
||||
System.out.println(getList);
|
||||
ResultSet getListResults = getList.executeQuery();
|
||||
getListResults.first();
|
||||
System.out.println(getListResults);
|
||||
List retrievedList = new List(getListResults);
|
||||
System.out.println(retrievedList);
|
||||
PreparedStatement getListEntries = connection.prepareStatement(GET_ENTRIES);
|
||||
getListEntries.setInt(1, id);
|
||||
ResultSet getEntryResults = getListEntries.executeQuery();
|
||||
while (getEntryResults.next()) {
|
||||
retrievedList.addItemEntry(new ItemEntry(id, getEntryResults));
|
||||
}
|
||||
System.out.println(retrievedList);
|
||||
return retrievedList;
|
||||
}
|
||||
}
|
||||
}
|
||||
11
Lambdas/Lists/List/src/ListPOST.java
Normal file
11
Lambdas/Lists/List/src/ListPOST.java
Normal file
@@ -0,0 +1,11 @@
|
||||
import java.util.Map;
|
||||
|
||||
import com.amazonaws.services.lambda.runtime.Context;
|
||||
import com.amazonaws.services.lambda.runtime.RequestHandler;
|
||||
|
||||
public class ListPOST implements RequestHandler<Map<String,Object>, Object>{
|
||||
|
||||
public Object handleRequest(Map<String, Object> inputMap, Context unfilled) {
|
||||
return BasicHandler.handleRequest(inputMap, unfilled, ListAdder.class);
|
||||
}
|
||||
}
|
||||
38
Lambdas/Lists/ListEntry/src/ListEntryAdder.java
Normal file
38
Lambdas/Lists/ListEntry/src/ListEntryAdder.java
Normal file
@@ -0,0 +1,38 @@
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.SQLException;
|
||||
import java.time.Instant;
|
||||
import java.time.ZoneOffset;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class ListEntryAdder implements CallHandler {
|
||||
|
||||
private DBConnector connector;
|
||||
private String cognitoID;
|
||||
|
||||
private final String ITEM_TO_LIST = "INSERT INTO ListProduct (productID, listID, quantity, addedDate, purchased) VALUES (?, ?, ?, ?, ?)";
|
||||
|
||||
public ListEntryAdder(DBConnector connector, String cognitoID) {
|
||||
this.connector = connector;
|
||||
this.cognitoID = cognitoID;
|
||||
}
|
||||
|
||||
public Object conductAction(Map<String, Object> bodyMap, HashMap<String, String> queryString, String cognitoID) throws SQLException {
|
||||
Connection connection = connector.getConnection();
|
||||
try {
|
||||
PreparedStatement statement = connection.prepareStatement(ITEM_TO_LIST);
|
||||
statement.setInt(1, (Integer) bodyMap.get("productID"));
|
||||
statement.setInt(2, (Integer) bodyMap.get("listID"));
|
||||
statement.setInt(3, (Integer) bodyMap.get("quantity"));
|
||||
statement.setObject(4, Instant.now().atZone(ZoneOffset.UTC).toLocalDateTime());
|
||||
statement.setBoolean(5, (Boolean) bodyMap.get("purchased"));
|
||||
System.out.println(statement);
|
||||
statement.executeUpdate();
|
||||
connection.commit();
|
||||
} finally {
|
||||
connection.close();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
11
Lambdas/Lists/ListEntry/src/ListEntryDELETE.java
Normal file
11
Lambdas/Lists/ListEntry/src/ListEntryDELETE.java
Normal file
@@ -0,0 +1,11 @@
|
||||
import com.amazonaws.services.lambda.runtime.Context;
|
||||
import com.amazonaws.services.lambda.runtime.RequestHandler;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
public class ListEntryDELETE implements RequestHandler<Map<String,Object>, Object> {
|
||||
|
||||
public Object handleRequest(Map<String, Object> inputMap, Context unfilled) {
|
||||
return BasicHandler.handleRequest(inputMap, unfilled, ListEntryDeleter.class);
|
||||
}
|
||||
}
|
||||
33
Lambdas/Lists/ListEntry/src/ListEntryDeleter.java
Normal file
33
Lambdas/Lists/ListEntry/src/ListEntryDeleter.java
Normal file
@@ -0,0 +1,33 @@
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.SQLException;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class ListEntryDeleter implements CallHandler {
|
||||
|
||||
private DBConnector connector;
|
||||
private String cognitoID;
|
||||
|
||||
private final String REMOVE_FROM_LIST = "DELETE FROM ListProduct WHERE (ProductID = ? AND ListID = ?);";
|
||||
|
||||
public ListEntryDeleter(DBConnector connector, String cognitoID) {
|
||||
this.connector = connector;
|
||||
this.cognitoID = cognitoID;
|
||||
}
|
||||
|
||||
public Object conductAction(Map<String, Object> bodyMap, HashMap<String, String> queryString, String cognitoID) throws SQLException {
|
||||
Connection connection = connector.getConnection();
|
||||
try {
|
||||
PreparedStatement statement = connection.prepareStatement(REMOVE_FROM_LIST);
|
||||
statement.setInt(1, (Integer) bodyMap.get("ProductID"));
|
||||
statement.setInt(2, (Integer) bodyMap.get("ListID"));
|
||||
System.out.println(statement);
|
||||
statement.executeUpdate();
|
||||
connection.commit();
|
||||
} finally {
|
||||
connection.close();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
11
Lambdas/Lists/ListEntry/src/ListEntryPOST.java
Normal file
11
Lambdas/Lists/ListEntry/src/ListEntryPOST.java
Normal file
@@ -0,0 +1,11 @@
|
||||
import com.amazonaws.services.lambda.runtime.Context;
|
||||
import com.amazonaws.services.lambda.runtime.RequestHandler;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
public class ListEntryPOST implements RequestHandler<Map<String,Object>, Object> {
|
||||
|
||||
public Object handleRequest(Map<String, Object> inputMap, Context unfilled) {
|
||||
return BasicHandler.handleRequest(inputMap, unfilled, ListEntryAdder.class);
|
||||
}
|
||||
}
|
||||
3
Lambdas/Lists/User/resources/cognitoProperties.json
Normal file
3
Lambdas/Lists/User/resources/cognitoProperties.json
Normal file
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"userPoolId": "us-east-2_MFgSVKQMd",
|
||||
}
|
||||
11
Lambdas/Lists/User/src/UserDELETE.java
Normal file
11
Lambdas/Lists/User/src/UserDELETE.java
Normal file
@@ -0,0 +1,11 @@
|
||||
import com.amazonaws.services.lambda.runtime.Context;
|
||||
import com.amazonaws.services.lambda.runtime.RequestHandler;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
public class UserDELETE implements RequestHandler<Map<String,Object>, Object> {
|
||||
|
||||
public Object handleRequest(Map<String, Object> inputMap, Context unfilled) {
|
||||
return BasicHandler.handleRequest(inputMap, unfilled, UserDeleter.class);
|
||||
}
|
||||
}
|
||||
58
Lambdas/Lists/User/src/UserDeleter.java
Normal file
58
Lambdas/Lists/User/src/UserDeleter.java
Normal file
@@ -0,0 +1,58 @@
|
||||
import com.amazonaws.services.cognitoidp.AWSCognitoIdentityProvider;
|
||||
import com.amazonaws.services.cognitoidp.AWSCognitoIdentityProviderClientBuilder;
|
||||
import com.amazonaws.services.cognitoidp.model.AdminDeleteUserRequest;
|
||||
import com.amazonaws.services.cognitoidp.model.AdminUserGlobalSignOutRequest;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.sql.SQLException;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Properties;
|
||||
|
||||
public class UserDeleter implements CallHandler {
|
||||
|
||||
private DBConnector connector;
|
||||
private String cognitoID;
|
||||
|
||||
//private final String REMOVE_FROM_LIST = "DELETE FROM ListProduct WHERE (ProductID = ? AND ListID = ?);";
|
||||
|
||||
public UserDeleter(DBConnector connector, String cognitoID) {
|
||||
this.connector = connector;
|
||||
this.cognitoID = cognitoID;
|
||||
}
|
||||
|
||||
public Object conductAction(Map<String, Object> bodyMap, HashMap<String, String> queryString, String cognitoID) throws SQLException {
|
||||
AWSCognitoIdentityProvider awsCognitoIdentityProvider = AWSCognitoIdentityProviderClientBuilder.defaultClient();
|
||||
Properties cognitoProperties;
|
||||
try {
|
||||
cognitoProperties = DBConnector.loadProperties("cognitoProperties.json");
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
String userPoolId = cognitoProperties.get("userPoolId").toString();
|
||||
System.out.println(userPoolId);
|
||||
AdminUserGlobalSignOutRequest adminUserGlobalSignOutRequest = new AdminUserGlobalSignOutRequest().withUserPoolId(userPoolId);
|
||||
adminUserGlobalSignOutRequest.setUsername(cognitoID);
|
||||
System.out.println(adminUserGlobalSignOutRequest);
|
||||
awsCognitoIdentityProvider.adminUserGlobalSignOut(adminUserGlobalSignOutRequest);
|
||||
AdminDeleteUserRequest adminDeleteUserRequest = new AdminDeleteUserRequest().withUserPoolId(userPoolId);
|
||||
adminDeleteUserRequest.setUsername(cognitoID);
|
||||
System.out.println(adminDeleteUserRequest);
|
||||
awsCognitoIdentityProvider.adminDeleteUser(adminDeleteUserRequest);
|
||||
return null;
|
||||
|
||||
// Connection connection = connector.getConnection();
|
||||
// try {
|
||||
// PreparedStatement statement = connection.prepareStatement(REMOVE_FROM_LIST);
|
||||
// statement.setInt(1, (Integer) bodyMap.get("ProductID"));
|
||||
// statement.setInt(2, (Integer) bodyMap.get("ListID"));
|
||||
// System.out.println(statement);
|
||||
// statement.executeUpdate();
|
||||
// connection.commit();
|
||||
// } finally {
|
||||
// connection.close();
|
||||
// }
|
||||
// return null;
|
||||
}
|
||||
}
|
||||
@@ -39,6 +39,56 @@
|
||||
<artifactId>mariadb-java-client</artifactId>
|
||||
<version>2.7.0</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.httpcomponents</groupId>
|
||||
<artifactId>httpclient</artifactId>
|
||||
<version>4.5.12</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.google.code.gson</groupId>
|
||||
<artifactId>gson</artifactId>
|
||||
<version>2.8.6</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.amazonaws</groupId>
|
||||
<artifactId>aws-java-sdk-cognitoidentity</artifactId>
|
||||
<version>1.11.875</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.amazonaws</groupId>
|
||||
<artifactId>aws-java-sdk-cognitoidp</artifactId>
|
||||
<version>1.11.875</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>software.amazon.ion</groupId>
|
||||
<artifactId>ion-java</artifactId>
|
||||
<version>1.5.1</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>joda-time</groupId>
|
||||
<artifactId>joda-time</artifactId>
|
||||
<version>2.10.6</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>commons-logging</groupId>
|
||||
<artifactId>commons-logging</artifactId>
|
||||
<version>1.2</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.fasterxml.jackson.dataformat</groupId>
|
||||
<artifactId>jackson-dataformat-cbor</artifactId>
|
||||
<version>2.11.3</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.fasterxml.jackson.dataformat</groupId>
|
||||
<artifactId>jackson-dataformat-xml</artifactId>
|
||||
<version>2.8.5</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.fasterxml.jackson.core</groupId>
|
||||
<artifactId>jackson-databind</artifactId>
|
||||
<version>2.11.3</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
<properties>
|
||||
<maven.compiler.source>1.11</maven.compiler.source>
|
||||
|
||||
31
Lambdas/Lists/src/main/java/BasicHandler.java
Normal file
31
Lambdas/Lists/src/main/java/BasicHandler.java
Normal file
@@ -0,0 +1,31 @@
|
||||
import com.amazonaws.services.lambda.runtime.Context;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.sql.SQLException;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class BasicHandler {
|
||||
public static <T extends CallHandler> Object handleRequest(Map<String, Object> inputMap, Context unfilled, Class<T> toCall) {
|
||||
String cognitoID = InputUtils.getCognitoIDFromBody(inputMap);
|
||||
HashMap<String, String> queryMap = InputUtils.getQueryParams(inputMap);
|
||||
try {
|
||||
DBConnector connector = new DBConnector();
|
||||
try {
|
||||
Constructor<T> constructor = toCall.getConstructor(DBConnector.class, String.class);
|
||||
CallHandler callHandler = constructor.newInstance(connector, cognitoID);
|
||||
return callHandler.conductAction(InputUtils.getBody(inputMap), queryMap, cognitoID);
|
||||
} catch (SQLException | NoSuchMethodException | InstantiationException | IllegalAccessException | InvocationTargetException e) {
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
connector.close();
|
||||
}
|
||||
} catch (IOException |SQLException|ClassNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
throw new RuntimeException(e.getLocalizedMessage());
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
7
Lambdas/Lists/src/main/java/CallHandler.java
Normal file
7
Lambdas/Lists/src/main/java/CallHandler.java
Normal file
@@ -0,0 +1,7 @@
|
||||
import java.sql.SQLException;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public interface CallHandler {
|
||||
Object conductAction(Map<String, Object> bodyMap, HashMap<String, String> queryString, String cognitoID) throws SQLException;
|
||||
}
|
||||
@@ -12,11 +12,11 @@ public class DBConnector {
|
||||
|
||||
Connection connection;
|
||||
|
||||
DBConnector() throws IOException, SQLException, ClassNotFoundException {
|
||||
public DBConnector() throws IOException, SQLException, ClassNotFoundException {
|
||||
this(loadProperties("dbProperties.json"));
|
||||
}
|
||||
|
||||
DBConnector(Properties dbProperties) throws SQLException, ClassNotFoundException {
|
||||
public DBConnector(Properties dbProperties) throws SQLException, ClassNotFoundException {
|
||||
Class.forName("org.mariadb.jdbc.Driver");
|
||||
System.out.println(dbProperties);
|
||||
System.out.println(DBConnector.buildURL(dbProperties));
|
||||
|
||||
@@ -1,3 +1,9 @@
|
||||
import org.apache.http.NameValuePair;
|
||||
import org.apache.http.client.utils.URLEncodedUtils;
|
||||
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class InputUtils {
|
||||
@@ -19,6 +25,24 @@ public class InputUtils {
|
||||
return getMap(inputMap, "body");
|
||||
}
|
||||
|
||||
private static String getQueryString(Map<String, Object> inputMap) {
|
||||
return (String) (getMap(inputMap, "params").get("querystring"));
|
||||
}
|
||||
|
||||
public static HashMap<String, String> getQueryParams(Map<String, Object> inputMap) {
|
||||
return (HashMap<String, String>) (getMap(inputMap, "params").get("querystring"));
|
||||
|
||||
// String queryString = getQueryString(inputMap);
|
||||
// List<NameValuePair> queryparams = URLEncodedUtils.parse(queryString, StandardCharsets.UTF_8);
|
||||
// HashMap<String, String> mappedParams = new HashMap<>();
|
||||
// for (NameValuePair param : queryparams) {
|
||||
// mappedParams.put(param.getName(), param.getValue());
|
||||
// }
|
||||
// return mappedParams;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public static Map<String, Object> getMap(Map<String, Object> parentMap, String childKey) {
|
||||
if ((parentMap.get(childKey) != null) && (parentMap.get(childKey) instanceof Map<?, ?>)) {
|
||||
return ((Map<String, Object>) parentMap.get(childKey));
|
||||
|
||||
@@ -1,27 +0,0 @@
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.SQLException;
|
||||
import java.util.Map;
|
||||
|
||||
public class ListAdder {
|
||||
|
||||
private DBConnector connector;
|
||||
private String cognitoID;
|
||||
|
||||
private final String LIST_CREATE = "INSERT INTO Lists (Name, Owner) VALUES (?, ?)";
|
||||
|
||||
ListAdder(DBConnector connector, String cognitoID) {
|
||||
this.connector = connector;
|
||||
this.cognitoID = cognitoID;
|
||||
}
|
||||
|
||||
public void add(Map<String, Object> bodyMap) throws SQLException {
|
||||
Connection connection = connector.getConnection();
|
||||
PreparedStatement statement = connection.prepareStatement(LIST_CREATE);
|
||||
statement.setString(1, bodyMap.get("name").toString());//Needs safe checking
|
||||
statement.setString(2, cognitoID);
|
||||
System.out.println(statement);
|
||||
statement.executeUpdate();
|
||||
connection.commit();
|
||||
}
|
||||
}
|
||||
@@ -1,28 +0,0 @@
|
||||
import java.io.IOException;
|
||||
import java.sql.SQLException;
|
||||
import java.util.Map;
|
||||
|
||||
import com.amazonaws.services.lambda.runtime.Context;
|
||||
import com.amazonaws.services.lambda.runtime.RequestHandler;
|
||||
|
||||
public class ListPOST implements RequestHandler<Map<String,Object>, String>{
|
||||
|
||||
|
||||
public String handleRequest(Map<String, Object> inputMap, Context unfilled) {
|
||||
String cognitoID = InputUtils.getCognitoIDFromBody(inputMap);
|
||||
try {
|
||||
DBConnector connector = new DBConnector();
|
||||
try {
|
||||
new ListAdder(connector, cognitoID).add(InputUtils.getBody(inputMap));
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
connector.close();
|
||||
}
|
||||
} catch (IOException|SQLException|ClassNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
throw new RuntimeException(e.getMessage());
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
BIN
Lambdas/Lists/target/Lists-1.0-SNAPSHOT.jar
Normal file
BIN
Lambdas/Lists/target/Lists-1.0-SNAPSHOT.jar
Normal file
Binary file not shown.
5
Lambdas/Lists/target/maven-archiver/pom.properties
Normal file
5
Lambdas/Lists/target/maven-archiver/pom.properties
Normal file
@@ -0,0 +1,5 @@
|
||||
#Generated by Maven
|
||||
#Mon Oct 05 10:19:24 EDT 2020
|
||||
groupId=groupId
|
||||
artifactId=Lists
|
||||
version=1.0-SNAPSHOT
|
||||
@@ -0,0 +1,4 @@
|
||||
/Users/MNM/Documents/GitHub/Listify/Lambdas/Lists/src/main/java/CallHandler.java
|
||||
/Users/MNM/Documents/GitHub/Listify/Lambdas/Lists/src/main/java/DBConnector.java
|
||||
/Users/MNM/Documents/GitHub/Listify/Lambdas/Lists/src/main/java/BasicHandler.java
|
||||
/Users/MNM/Documents/GitHub/Listify/Lambdas/Lists/src/main/java/InputUtils.java
|
||||
Reference in New Issue
Block a user