mirror of
https://github.com/ClaytonWWilson/Listify.git
synced 2026-03-11 02:55:04 +00:00
Lamdba Integration
Test Lamdbas with full pipeline of client through database
This commit is contained in:
@@ -44,6 +44,13 @@ public class AuthManager {
|
||||
}
|
||||
|
||||
public String getUserToken() {
|
||||
if (authSession == null) {
|
||||
try {
|
||||
fetchAuthSession();
|
||||
} catch (AuthException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
return authSession.getUserPoolTokens().getValue().getIdToken();
|
||||
}
|
||||
|
||||
|
||||
@@ -1,44 +0,0 @@
|
||||
package com.example.listify;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
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;
|
||||
|
||||
public Item(Integer productID, Integer chainID, String upc, String description, BigDecimal price,
|
||||
String imageURL, String department, LocalDateTime retrievedDate, Integer fetchCounts) {
|
||||
this.productID = productID;
|
||||
this.chainID = chainID;
|
||||
this.upc = upc;
|
||||
this.description = description;
|
||||
this.price = price;
|
||||
this.imageURL = imageURL;
|
||||
this.department = department;
|
||||
this.retrievedDate = retrievedDate;
|
||||
this.fetchCounts = 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 +
|
||||
'}';
|
||||
}
|
||||
}
|
||||
@@ -1,8 +0,0 @@
|
||||
package com.example.listify;
|
||||
|
||||
public class List {
|
||||
String name;
|
||||
List(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
}
|
||||
@@ -13,11 +13,18 @@ import androidx.navigation.Navigation;
|
||||
import androidx.navigation.ui.AppBarConfiguration;
|
||||
import androidx.navigation.ui.NavigationUI;
|
||||
import com.amplifyframework.auth.AuthException;
|
||||
import com.example.listify.data.Item;
|
||||
import com.example.listify.data.ListEntry;
|
||||
import com.example.listify.data.List;
|
||||
import com.google.android.material.navigation.NavigationView;
|
||||
import org.json.JSONException;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.time.Instant;
|
||||
import java.time.ZoneOffset;
|
||||
import java.util.Arrays;
|
||||
import java.util.Properties;
|
||||
import java.util.Random;
|
||||
|
||||
public class MainActivity extends AppCompatActivity {
|
||||
private AppBarConfiguration mAppBarConfiguration;
|
||||
@@ -29,51 +36,73 @@ public class MainActivity extends AppCompatActivity {
|
||||
|
||||
//------------------------------Auth Testing---------------------------------------------//
|
||||
|
||||
AuthManager authManager = new AuthManager();
|
||||
try {
|
||||
authManager.signIn("merzn@purdue.edu", "Password123");
|
||||
Log.i("Authentication", authManager.getAuthSession().toString());
|
||||
Log.i("Token", authManager.getAuthSession().getUserPoolTokens().getValue().getIdToken());
|
||||
} catch (AuthException e) {
|
||||
Log.i("Authentication", "Login failed. User probably needs to register. Exact error: " + e.getMessage());
|
||||
boolean testAuth = false;
|
||||
|
||||
if (testAuth) {
|
||||
|
||||
AuthManager authManager = new AuthManager();
|
||||
try {
|
||||
authManager.startSignUp("merzn@purdue.edu", "Password123");
|
||||
authManager.confirmSignUp("######");
|
||||
} catch (AuthException signUpError) {
|
||||
Log.e("Authentication", "SignUp error: " + signUpError.getMessage());
|
||||
authManager.signIn("merzn@purdue.edu", "Password123");
|
||||
Log.i("Authentication", authManager.getAuthSession().toString());
|
||||
Log.i("Token", authManager.getAuthSession().getUserPoolTokens().getValue().getIdToken());
|
||||
} catch (AuthException e) {
|
||||
Log.i("Authentication", "Login failed. User probably needs to register. Exact error: " + e.getMessage());
|
||||
try {
|
||||
authManager.startSignUp("merzn@purdue.edu", "Password123");
|
||||
authManager.confirmSignUp("######");
|
||||
} catch (AuthException signUpError) {
|
||||
Log.e("Authentication", "SignUp error: " + signUpError.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
//------------------------------------------------------------------------------------------//
|
||||
|
||||
|
||||
boolean testAPI = true;
|
||||
//----------------------------------API Testing---------------------------------------------//
|
||||
Properties configs = new Properties();
|
||||
try {
|
||||
configs = AuthManager.loadProperties(this, "android.resource://" + getPackageName() + "/raw/auths.json");
|
||||
} catch (IOException|JSONException e) {
|
||||
e.printStackTrace();
|
||||
if (testAPI) {
|
||||
AuthManager authManager = new AuthManager();
|
||||
try {
|
||||
authManager.signIn("merzn@purdue.edu", "Password123");
|
||||
} catch (AuthException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
Properties configs = new Properties();
|
||||
try {
|
||||
configs = AuthManager.loadProperties(this, "android.resource://" + getPackageName() + "/raw/auths.json");
|
||||
} catch (IOException | JSONException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
Requestor requestor = new Requestor(authManager, configs.getProperty("apiKey"));
|
||||
//The name is the only part of this that is used, the rest is generated by the Lambda.
|
||||
List testList = new List(-1, "New List", "user filled by lambda", Instant.now().toEpochMilli());
|
||||
//Everything except addedDate is used for ItemEntry
|
||||
ListEntry entry = new ListEntry(1, 1, new Random().nextInt(), Instant.now().atZone(ZoneOffset.UTC).toLocalDateTime(),false);
|
||||
SynchronousReceiver<Integer> idReceiver = new SynchronousReceiver<>();
|
||||
try {
|
||||
requestor.postObject(testList, idReceiver, idReceiver);
|
||||
System.out.println(idReceiver.await());
|
||||
requestor.postObject(entry);
|
||||
} catch (JSONException | IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
SynchronousReceiver<Item> itemReceiver = new SynchronousReceiver<>();
|
||||
requestor.getObject("1", Item.class, itemReceiver, itemReceiver);
|
||||
SynchronousReceiver<List> listReceiver = new SynchronousReceiver<>();
|
||||
requestor.getObject("39", List.class, listReceiver, listReceiver);
|
||||
SynchronousReceiver<Integer[]> listIdsReceiver = new SynchronousReceiver<>();
|
||||
requestor.getListOfIds(List.class, listIdsReceiver, listIdsReceiver);
|
||||
try {
|
||||
System.out.println(itemReceiver.await());
|
||||
System.out.println(listReceiver.await());
|
||||
System.out.println(Arrays.toString(listIdsReceiver.await()));
|
||||
} catch (IOException receiverError) {
|
||||
receiverError.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
Requestor requestor = new Requestor(authManager,configs.getProperty("apiKey"));
|
||||
List testList = new List("IAmATestList");
|
||||
try {
|
||||
requestor.postObject(testList);
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
SynchronousReceiver<Item> receiver = new SynchronousReceiver<Item>();
|
||||
requestor.getObject("1", Item.class, receiver, receiver);
|
||||
try {
|
||||
System.out.println(receiver.await());
|
||||
} catch (IOException receiverError) {
|
||||
receiverError.printStackTrace();
|
||||
}
|
||||
|
||||
|
||||
//------------------------------------------------------------------------------------------//
|
||||
|
||||
|
||||
|
||||
@@ -29,7 +29,7 @@ public class Requestor {
|
||||
}
|
||||
|
||||
public <T> void getListOfIds(Class<T> ofType, Receiver<Integer[]> successHandler, RequestErrorHandler failureHandler) {
|
||||
String getURL = DEV_BASEURL + "/" + ofType.getSimpleName() + "?list=-1";
|
||||
String getURL = DEV_BASEURL + "/" + ofType.getSimpleName() + "?id=-1";
|
||||
Request postRequest = buildBaseRequest(getURL, "GET", null);
|
||||
launchCall(postRequest, successHandler, Integer[].class, failureHandler);
|
||||
}
|
||||
@@ -41,15 +41,22 @@ public class Requestor {
|
||||
}
|
||||
|
||||
public void postObject(Object toPost) throws JSONException {
|
||||
postObject(toPost, null);
|
||||
postObject(toPost, (RequestErrorHandler) null);
|
||||
}
|
||||
|
||||
public void postObject(Object toPost, RequestErrorHandler failureHandler) throws JSONException {
|
||||
String postURL = DEV_BASEURL + "/" + toPost.getClass().getSimpleName();
|
||||
Request postRequest = buildBaseRequest(postURL, "POST", new Gson().toJson(toPost));
|
||||
launchCall(postRequest, null, null, failureHandler);
|
||||
postObject(toPost, null, failureHandler);
|
||||
}
|
||||
|
||||
public void postObject(Object toPost, Receiver<Integer> idReceiver) throws JSONException {
|
||||
postObject(toPost, idReceiver, null);
|
||||
}
|
||||
|
||||
public void postObject(Object toPost, Receiver<Integer> idReceiver, RequestErrorHandler failureHandler) throws JSONException {
|
||||
String postURL = DEV_BASEURL + "/" + toPost.getClass().getSimpleName();
|
||||
Request postRequest = buildBaseRequest(postURL, "POST", new Gson().toJson(toPost));
|
||||
launchCall(postRequest, idReceiver, Integer.class, failureHandler);
|
||||
}
|
||||
|
||||
private void launchCall(Request toLaunch, Receiver receiver, Class classType, RequestErrorHandler failureHandler) {
|
||||
client.newCall(toLaunch).enqueue(new Callback() {
|
||||
|
||||
116
Listify/app/src/main/java/com/example/listify/data/Item.java
Normal file
116
Listify/app/src/main/java/com/example/listify/data/Item.java
Normal file
@@ -0,0 +1,116 @@
|
||||
package com.example.listify.data;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
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;
|
||||
|
||||
public Item(Integer productID, Integer chainID, String upc, String description, BigDecimal price,
|
||||
String imageURL, String department, LocalDateTime retrievedDate, Integer fetchCounts) {
|
||||
this.productID = productID;
|
||||
this.chainID = chainID;
|
||||
this.upc = upc;
|
||||
this.description = description;
|
||||
this.price = price;
|
||||
this.imageURL = imageURL;
|
||||
this.department = department;
|
||||
this.retrievedDate = retrievedDate;
|
||||
this.fetchCounts = fetchCounts;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Item{" +
|
||||
"productID=" + productID +
|
||||
", chainID=" + chainID +
|
||||
", upc='" + upc + '\'' +
|
||||
", description='" + description + '\'' +
|
||||
", price=" + price +
|
||||
", imageURL='" + imageURL + '\'' +
|
||||
", department='" + department + '\'' +
|
||||
", retrievedDate=" + (retrievedDate == null ? null : 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;
|
||||
}
|
||||
}
|
||||
70
Listify/app/src/main/java/com/example/listify/data/List.java
Normal file
70
Listify/app/src/main/java/com/example/listify/data/List.java
Normal file
@@ -0,0 +1,70 @@
|
||||
package com.example.listify.data;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
public class List {
|
||||
Integer itemID;
|
||||
String name;
|
||||
String owner;
|
||||
long lastUpdated;
|
||||
final ListEntry[] entries;
|
||||
|
||||
public List(Integer itemID, String name, String owner, long lastUpdated, ListEntry[] entries) {
|
||||
this.itemID = itemID;
|
||||
this.name = name;
|
||||
this.owner = owner;
|
||||
this.lastUpdated = lastUpdated;
|
||||
this.entries = entries;
|
||||
}
|
||||
|
||||
public List(Integer itemID, String name, String owner, long lastUpdated) {
|
||||
this(itemID, name, owner, lastUpdated, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "List{" +
|
||||
"itemID=" + itemID +
|
||||
", name='" + name + '\'' +
|
||||
", owner='" + owner + '\'' +
|
||||
", lastUpdated=" + lastUpdated +
|
||||
", entries=" + Arrays.toString(entries) +
|
||||
'}';
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
public ListEntry[] getEntries() {
|
||||
return entries;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,70 @@
|
||||
package com.example.listify.data;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
public class ListEntry {
|
||||
Integer listID;
|
||||
Integer productID;
|
||||
Integer quantity;
|
||||
LocalDateTime addedDate;
|
||||
Boolean purchased;
|
||||
|
||||
public ListEntry(Integer listID, Integer productID, Integer quantity, LocalDateTime addedDate, Boolean purchased) {
|
||||
this.listID = listID;
|
||||
this.productID = productID;
|
||||
this.quantity = quantity;
|
||||
this.addedDate = addedDate;
|
||||
this.purchased = purchased;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "ListEntry{" +
|
||||
"listID=" + listID +
|
||||
", productID=" + productID +
|
||||
", quantity=" + quantity +
|
||||
", addedDate=" + addedDate +
|
||||
", purchased=" + purchased +
|
||||
'}';
|
||||
}
|
||||
|
||||
public Integer getListID() {
|
||||
return listID;
|
||||
}
|
||||
|
||||
public void setListID(Integer listID) {
|
||||
this.listID = listID;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user