mirror of
https://github.com/ClaytonWWilson/Listify.git
synced 2026-03-10 18:55:03 +00:00
Fixed merge conflict in List.java
This commit is contained in:
@@ -89,11 +89,9 @@ public class List {
|
||||
|
||||
public ItemEntry[] getEntries() {
|
||||
return entries.toArray(new ItemEntry[entries.size()]);
|
||||
//return;
|
||||
}
|
||||
|
||||
public void addItemEntry(ItemEntry entry) {
|
||||
entries.add(entry);
|
||||
//return;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,7 +12,7 @@ public class ListGetter implements CallHandler{
|
||||
private final String cognitoID;
|
||||
|
||||
private final String GET_LIST = "SELECT * FROM List WHERE listID = ?;";
|
||||
private final String GET_LISTS = "SELECT listID FROM ListSharee WHERE userID = ? ORDER BY uiPosition;";
|
||||
private final String GET_LISTS = "SELECT listID, permissionLevel FROM ListSharee WHERE userID = ? ORDER BY uiPosition;";
|
||||
private final String SHARE_CHECK = "SELECT * FROM ListSharee WHERE listID = ?;";
|
||||
private final String GET_ENTRIES = "SELECT * FROM ListProduct WHERE listID = ?;";
|
||||
|
||||
@@ -32,7 +32,10 @@ public class ListGetter implements CallHandler{
|
||||
System.out.println(getListsResults);
|
||||
ArrayList<Integer> listIds = new ArrayList<>();
|
||||
while (getListsResults.next()) {
|
||||
listIds.add(getListsResults.getInt(1));
|
||||
Integer permissionLevel = getListsResults.getInt("permissionLevel");
|
||||
if (ListPermissions.hasPermission(permissionLevel, "Read")) {
|
||||
listIds.add(getListsResults.getInt("listID"));
|
||||
}
|
||||
}
|
||||
return listIds;
|
||||
}
|
||||
@@ -43,7 +46,7 @@ public class ListGetter implements CallHandler{
|
||||
int sharees = 0;
|
||||
boolean verifiedAccess = false;
|
||||
int uiPosition = 1;
|
||||
while ((sharees < 2 && accessResults.next()) || !verifiedAccess) {
|
||||
while (accessResults.next() && (sharees < 2 || !verifiedAccess )) {
|
||||
int permissionLevel = accessResults.getInt("permissionLevel");
|
||||
if (accessResults.getString("userID").equals(cognitoID)) {
|
||||
verifiedAccess = true;
|
||||
@@ -56,6 +59,9 @@ public class ListGetter implements CallHandler{
|
||||
sharees++;
|
||||
}
|
||||
}
|
||||
if (!verifiedAccess) {
|
||||
throw new AccessControlException("User " + cognitoID + " does not have ant permission for list " + id);
|
||||
}
|
||||
boolean shared = false;
|
||||
if (sharees > 1) {
|
||||
shared = true;
|
||||
|
||||
@@ -24,7 +24,7 @@ public class ListPermissions {
|
||||
}
|
||||
|
||||
public static boolean hasPermission(Integer level, String permission) {
|
||||
return level % getKeyForPermission(permission) == 0;
|
||||
return (level % getKeyForPermission(permission) == 0 && level != 0);
|
||||
}
|
||||
|
||||
public static Integer getKeyForPermission(String permissionRaw) {
|
||||
|
||||
@@ -1,16 +1,57 @@
|
||||
package com.example.listify.data;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class ListShare {
|
||||
Integer listID;
|
||||
String shareWithEmail;
|
||||
Integer permissionLevel;
|
||||
Integer uiPosition;
|
||||
ArrayList<ListShare> other;
|
||||
|
||||
public ListShare(ResultSet listRow) throws SQLException {
|
||||
public ListShare(ResultSet listRow, String shareWithEmail) throws SQLException {
|
||||
this.listID = listRow.getInt("listID");
|
||||
this.shareWithEmail = listRow.getString("userID");
|
||||
this.shareWithEmail = shareWithEmail;
|
||||
this.permissionLevel = listRow.getInt("permissionLevel");
|
||||
this.uiPosition = listRow.getInt("uiPosition");
|
||||
other = new ArrayList<>();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "ListShare{" +
|
||||
"listID=" + listID +
|
||||
", shareWithEmail='" + shareWithEmail + '\'' +
|
||||
", permissionLevel=" + permissionLevel +
|
||||
", uiPosition=" + uiPosition +
|
||||
", other=" + other +
|
||||
'}';
|
||||
}
|
||||
|
||||
public Integer getPermissionLevel() {
|
||||
return permissionLevel;
|
||||
}
|
||||
|
||||
public void setPermissionLevel(Integer permissionLevel) {
|
||||
this.permissionLevel = permissionLevel;
|
||||
}
|
||||
|
||||
public Integer getUiPosition() {
|
||||
return uiPosition;
|
||||
}
|
||||
|
||||
public void setUiPosition(Integer uiPosition) {
|
||||
this.uiPosition = uiPosition;
|
||||
}
|
||||
|
||||
public ArrayList<ListShare> getOther() {
|
||||
return other;
|
||||
}
|
||||
|
||||
public void setOther(ArrayList<ListShare> other) {
|
||||
this.other = other;
|
||||
}
|
||||
|
||||
public Integer getListID() {
|
||||
return listID;
|
||||
}
|
||||
|
||||
@@ -1,65 +0,0 @@
|
||||
import java.security.AccessControlException;
|
||||
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 ListShareDeleter implements CallHandler {
|
||||
private final Connection connection;
|
||||
private final String cognitoID;
|
||||
|
||||
private final String GET_LIST_ACCESS = "SELECT * FROM List WHERE (owner = ? AND listID = ?);";
|
||||
private final String REMOVE_SHAREE = "DELETE FROM ListSharee WHERE listID = ? AND user = ?;";
|
||||
|
||||
public ListShareDeleter(Connection connection, String cognitoID) {
|
||||
this.connection = connection;
|
||||
this.cognitoID = cognitoID;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object conductAction(Map<String, Object> bodyMap, HashMap<String, String> queryMap, String cognitoID) throws SQLException {
|
||||
Integer listID = Integer.parseInt(queryMap.get("id"));
|
||||
|
||||
InvokeRequest invokeRequest = new InvokeRequest();
|
||||
invokeRequest.setFunctionName("UserGET");
|
||||
invokeRequest.setPayload("{" +
|
||||
" \"body\": {" +
|
||||
" \"emailToCheck\": \"" + bodyMap.get("shareWithEmail").toString() + "\"" +
|
||||
" }," +
|
||||
" \"params\": {" +
|
||||
" \"querystring\": {" +
|
||||
" }" +
|
||||
" }," +
|
||||
" \"context\": {" +
|
||||
" \"sub\": \"not used\"" +
|
||||
" }" +
|
||||
"}");
|
||||
InvokeResult invokeResult = AWSLambdaClientBuilder.defaultClient().invoke(invokeRequest);
|
||||
|
||||
String shareeID = new String(invokeResult.getPayload().array()).replace("\"", "");
|
||||
|
||||
//Ensure that the user who is unsharing a list is the owner of that list
|
||||
PreparedStatement accessCheck = connection.prepareStatement(GET_LIST_ACCESS);
|
||||
accessCheck.setString(1, cognitoID);
|
||||
accessCheck.setInt(2, listID);
|
||||
|
||||
ResultSet userLists = accessCheck.executeQuery();
|
||||
|
||||
//User does not own the list; unshare attempt fails
|
||||
if (!userLists.next()) {
|
||||
throw new AccessControlException("User does not have access to list");
|
||||
}
|
||||
|
||||
//Unshare the list with the specified sharee
|
||||
PreparedStatement unshareList = connection.prepareStatement(REMOVE_SHAREE);
|
||||
unshareList.setInt(1, listID);
|
||||
unshareList.setInt(2, shareeID);
|
||||
|
||||
cleanAccess.executeUpdate();
|
||||
connection.commit();
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -1,9 +1,14 @@
|
||||
import com.amazonaws.services.lambda.AWSLambdaClientBuilder;
|
||||
import com.amazonaws.services.lambda.model.InvokeRequest;
|
||||
import com.amazonaws.services.lambda.model.InvokeResult;
|
||||
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.InputMismatchException;
|
||||
import java.util.Map;
|
||||
|
||||
public class ListShareGetter implements CallHandler{
|
||||
@@ -21,18 +26,67 @@ public class ListShareGetter implements CallHandler{
|
||||
public Object conductAction(Map<String, Object> bodyMap, HashMap<String, String> queryMap, String cognitoID) throws SQLException {
|
||||
Integer listID = Integer.parseInt(queryMap.get("id"));
|
||||
|
||||
PreparedStatement getList = connection.prepareStatement(GET_LIST);
|
||||
PreparedStatement getList = connection.prepareStatement(GET_LISTS);
|
||||
getList.setInt(1, listID);
|
||||
|
||||
ResultSet getListResults = getList.executeQuery();
|
||||
getListResults.first();
|
||||
System.out.println(getListResults);
|
||||
|
||||
ListShare first = null;
|
||||
while (getListResults.next() && first == null) {
|
||||
InvokeRequest invokeRequest = new InvokeRequest();
|
||||
invokeRequest.setFunctionName("UserGET");
|
||||
invokeRequest.setPayload("{" +
|
||||
" \"body\": {" +
|
||||
" }," +
|
||||
" \"params\": {" +
|
||||
" \"querystring\": {" +
|
||||
" \"id\": \"" + getListResults.getString("userID") + "\"" +
|
||||
" }" +
|
||||
" }," +
|
||||
" \"context\": {" +
|
||||
" \"sub\": \"not used\"" +
|
||||
" }" +
|
||||
"}");
|
||||
InvokeResult invokeResult = AWSLambdaClientBuilder.defaultClient().invoke(invokeRequest);
|
||||
if (invokeResult.getStatusCode() != 200) {
|
||||
throw new InputMismatchException("Could not find specified user to share with");
|
||||
}
|
||||
String shareWithEmail = new Gson().fromJson(new String(invokeResult.getPayload().array()), User.class).email;
|
||||
first = new ListShare(getListResults, shareWithEmail);
|
||||
if (first.permissionLevel == 0 || first.permissionLevel == 1) {
|
||||
first = null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//ListShare object to hold the data values of the first row retrived
|
||||
ListShare first = new ListShare(getListResults);
|
||||
|
||||
//Insert the ListShare objects to hold the data of the remaining rows into first's ListShare list
|
||||
while (getListResults.next()) {
|
||||
first.addtoList(new ListShare(getListResults));
|
||||
InvokeRequest invokeRequest = new InvokeRequest();
|
||||
invokeRequest.setFunctionName("UserGET");
|
||||
invokeRequest.setPayload("{" +
|
||||
" \"body\": {" +
|
||||
" }," +
|
||||
" \"params\": {" +
|
||||
" \"querystring\": {" +
|
||||
" \"id\": \"" + getListResults.getString("userID") + "\"" +
|
||||
" }" +
|
||||
" }," +
|
||||
" \"context\": {" +
|
||||
" \"sub\": \"not used\"" +
|
||||
" }" +
|
||||
"}");
|
||||
InvokeResult invokeResult = AWSLambdaClientBuilder.defaultClient().invoke(invokeRequest);
|
||||
if (invokeResult.getStatusCode() != 200) {
|
||||
throw new InputMismatchException("Could not find specified user to share with");
|
||||
}
|
||||
String shareWithEmail = new Gson().fromJson(new String(invokeResult.getPayload().array()), User.class).email;
|
||||
ListShare newShare = new ListShare(getListResults, shareWithEmail);
|
||||
System.out.println(newShare);
|
||||
if (newShare.permissionLevel != 0 && newShare.permissionLevel != 1) {
|
||||
first.addtoList(newShare);
|
||||
}
|
||||
}
|
||||
|
||||
return first;
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import com.amazonaws.services.lambda.AWSLambdaClientBuilder;
|
||||
import com.amazonaws.services.lambda.model.InvokeRequest;
|
||||
import com.amazonaws.services.lambda.model.InvokeResult;
|
||||
import com.google.gson.Gson;
|
||||
|
||||
import java.security.AccessControlException;
|
||||
import java.sql.Connection;
|
||||
@@ -56,7 +57,7 @@ public class ListSharer implements CallHandler {
|
||||
if (invokeResult.getStatusCode() != 200) {
|
||||
throw new InputMismatchException("Could not find specified user to share with");
|
||||
}
|
||||
String shareWithSub = new String(invokeResult.getPayload().array()).replace("\"", "");
|
||||
String shareWithSub = new Gson().fromJson(new String(invokeResult.getPayload().array()), User.class).cognitoID;
|
||||
// checkAccess.setString(2, shareWithSub);
|
||||
// checkAccessRS = checkAccess.executeQuery();
|
||||
// if (checkAccessRS.next()) {
|
||||
|
||||
34
Lambdas/Lists/Picture/src/Picture.java
Normal file
34
Lambdas/Lists/Picture/src/Picture.java
Normal file
@@ -0,0 +1,34 @@
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
|
||||
public class Picture {
|
||||
String base64EncodedImage;
|
||||
|
||||
public Picture(ResultSet rs) {
|
||||
try {
|
||||
this.base64EncodedImage = rs.getString("base64image");
|
||||
} catch (SQLException throwables) {
|
||||
throwables.printStackTrace();
|
||||
this.base64EncodedImage = null;
|
||||
}
|
||||
}
|
||||
|
||||
public Picture(String base64EncodedImage) {
|
||||
this.base64EncodedImage = base64EncodedImage;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Picture{" +
|
||||
"base64EncodedImage='" + base64EncodedImage + '\'' +
|
||||
'}';
|
||||
}
|
||||
|
||||
public String getBase64EncodedImage() {
|
||||
return base64EncodedImage;
|
||||
}
|
||||
|
||||
public void setBase64EncodedImage(String base64EncodedImage) {
|
||||
this.base64EncodedImage = base64EncodedImage;
|
||||
}
|
||||
}
|
||||
12
Lambdas/Lists/Picture/src/PictureGET.java
Normal file
12
Lambdas/Lists/Picture/src/PictureGET.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 PictureGET implements RequestHandler<Map<String,Object>, Object> {
|
||||
|
||||
public Object handleRequest(Map<String, Object> inputMap, Context unfilled) {
|
||||
return BasicHandler.handleRequest(inputMap, unfilled, PictureGetter.class);
|
||||
}
|
||||
|
||||
}
|
||||
34
Lambdas/Lists/Picture/src/PictureGetter.java
Normal file
34
Lambdas/Lists/Picture/src/PictureGetter.java
Normal file
@@ -0,0 +1,34 @@
|
||||
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 PictureGetter implements CallHandler {
|
||||
private final Connection connection;
|
||||
private final String cognitoID;
|
||||
|
||||
private final String GET_ITEM = "SELECT * FROM Pictures WHERE cognitoID = ?;";
|
||||
|
||||
public PictureGetter(Connection connection, String cognitoID) {
|
||||
this.connection = connection;
|
||||
this.cognitoID = cognitoID;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object conductAction(Map<String, Object> bodyMap, HashMap<String, String> queryMap, String cognitoID) throws SQLException {
|
||||
PreparedStatement statement = connection.prepareStatement(GET_ITEM);
|
||||
if (!queryMap.get("id").toString().equals("profile")) {
|
||||
throw new IllegalArgumentException("Only profile pictures are currently supported.");
|
||||
}
|
||||
statement.setString(1, cognitoID);
|
||||
System.out.println(statement);
|
||||
ResultSet queryResults = statement.executeQuery();
|
||||
queryResults.first();
|
||||
System.out.println(queryResults);
|
||||
Picture retrievedPicture = new Picture(queryResults);
|
||||
// System.out.println(retrievedPicture);
|
||||
return retrievedPicture;
|
||||
}
|
||||
}
|
||||
@@ -3,10 +3,9 @@ import com.amazonaws.services.lambda.runtime.RequestHandler;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
public class ListShareDELETE implements RequestHandler<Map<String,Object>, Object> {
|
||||
public class PicturePUT implements RequestHandler<Map<String,Object>, Object> {
|
||||
|
||||
public Object handleRequest(Map<String, Object> inputMap, Context unfilled) {
|
||||
return BasicHandler.handleRequest(inputMap, unfilled, ListShareDeleter.class);
|
||||
return BasicHandler.handleRequest(inputMap, unfilled, PicturePutter.class);
|
||||
}
|
||||
|
||||
}
|
||||
28
Lambdas/Lists/Picture/src/PicturePutter.java
Normal file
28
Lambdas/Lists/Picture/src/PicturePutter.java
Normal file
@@ -0,0 +1,28 @@
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.SQLException;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class PicturePutter implements CallHandler {
|
||||
|
||||
private Connection connection;
|
||||
private String cognitoID;
|
||||
|
||||
public PicturePutter(Connection connection, String cognitoID) {
|
||||
this.connection = connection;
|
||||
this.cognitoID = cognitoID;
|
||||
}
|
||||
|
||||
final private String STORE_PICTURE_SQL = "REPLACE INTO Pictures(cognitoID, base64image) VALUES(?, ?);";
|
||||
|
||||
public Object conductAction(Map<String, Object> bodyMap, HashMap<String, String> queryString, String cognitoID) throws SQLException {
|
||||
PreparedStatement storePicture = connection.prepareStatement(STORE_PICTURE_SQL);
|
||||
storePicture.setString(1, cognitoID);
|
||||
storePicture.setString(2, bodyMap.get("base64EncodedImage").toString());
|
||||
System.out.println(storePicture);
|
||||
storePicture.executeUpdate();
|
||||
connection.commit();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
26
Lambdas/Lists/User/src/User.java
Normal file
26
Lambdas/Lists/User/src/User.java
Normal file
@@ -0,0 +1,26 @@
|
||||
|
||||
public class User {
|
||||
String cognitoID;
|
||||
String email;
|
||||
|
||||
public User(String cognitoID, String email) {
|
||||
this.cognitoID = cognitoID;
|
||||
this.email = email;
|
||||
}
|
||||
|
||||
public String getCognitoID() {
|
||||
return cognitoID;
|
||||
}
|
||||
|
||||
public void setCognitoID(String cognitoID) {
|
||||
this.cognitoID = cognitoID;
|
||||
}
|
||||
|
||||
public String getEmail() {
|
||||
return email;
|
||||
}
|
||||
|
||||
public void setEmail(String email) {
|
||||
this.email = email;
|
||||
}
|
||||
}
|
||||
@@ -34,15 +34,14 @@ public class UserGetter implements CallHandler {
|
||||
} else {
|
||||
try {
|
||||
String id = queryMap.get("id");
|
||||
attributeToGet = "email";
|
||||
checkRequest.setFilter("sub=\"" + cognitoID + "\"");
|
||||
if ((id != null) && (!id.equals(""))) {
|
||||
attributeToGet = "email";
|
||||
checkRequest.setFilter("sub=\"" + cognitoID + "\"");
|
||||
} else {
|
||||
return cognitoID;
|
||||
checkRequest.setFilter("sub=\"" + id + "\"");
|
||||
}
|
||||
} catch (Exception e) {
|
||||
System.out.println(e);
|
||||
return cognitoID;
|
||||
return new User(cognitoID, null);
|
||||
}
|
||||
}
|
||||
System.out.println(checkRequest);
|
||||
@@ -52,9 +51,9 @@ public class UserGetter implements CallHandler {
|
||||
if (foundUsers.size() != 1) {
|
||||
System.out.println(foundUsers);
|
||||
if (foundUsers.size() == 0) {
|
||||
throw new InputMismatchException("Not user with given email");
|
||||
throw new InputMismatchException("No user with given attribute when searching for (" + attributeToGet + ")");
|
||||
}
|
||||
throw new InputMismatchException("Found more than one user with supposedly unique email");
|
||||
throw new InputMismatchException("Found more than one user with supposedly unique attribute (" + attributeToGet + ")");
|
||||
}
|
||||
UserType foundUser = foundUsers.get(0);
|
||||
System.out.println(foundUser.getAttributes());
|
||||
@@ -66,6 +65,11 @@ public class UserGetter implements CallHandler {
|
||||
}
|
||||
System.out.println(attribute.getName() + ": " + attribute.getValue());
|
||||
}
|
||||
return attributeToReturn;
|
||||
if (attributeToGet.equals("email")) {
|
||||
return new User(cognitoID, attributeToReturn);
|
||||
} else if (attributeToGet.equals("sub")) {
|
||||
return new User(attributeToReturn, emailObject.toString());
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user