mirror of
https://github.com/ClaytonWWilson/Listify.git
synced 2025-12-16 02:38:47 +00:00
Merge pull request #144 from ClaytonWWilson/lambda-robustness
Update list sharing
This commit is contained in:
commit
98596389ee
@ -12,7 +12,7 @@ public class ListGetter implements CallHandler{
|
|||||||
private final String cognitoID;
|
private final String cognitoID;
|
||||||
|
|
||||||
private final String GET_LIST = "SELECT * FROM List WHERE listID = ?;";
|
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 SHARE_CHECK = "SELECT * FROM ListSharee WHERE listID = ?;";
|
||||||
private final String GET_ENTRIES = "SELECT * FROM ListProduct 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);
|
System.out.println(getListsResults);
|
||||||
ArrayList<Integer> listIds = new ArrayList<>();
|
ArrayList<Integer> listIds = new ArrayList<>();
|
||||||
while (getListsResults.next()) {
|
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;
|
return listIds;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -24,7 +24,7 @@ public class ListPermissions {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static boolean hasPermission(Integer level, String permission) {
|
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) {
|
public static Integer getKeyForPermission(String permissionRaw) {
|
||||||
|
|||||||
@ -9,9 +9,9 @@ public class ListShare {
|
|||||||
Integer uiPosition;
|
Integer uiPosition;
|
||||||
ArrayList<ListShare> other;
|
ArrayList<ListShare> other;
|
||||||
|
|
||||||
public ListShare(ResultSet listRow) throws SQLException {
|
public ListShare(ResultSet listRow, String shareWithEmail) throws SQLException {
|
||||||
this.listID = listRow.getInt("listID");
|
this.listID = listRow.getInt("listID");
|
||||||
this.shareWithEmail = listRow.getString("userID");
|
this.shareWithEmail = shareWithEmail;
|
||||||
this.permissionLevel = listRow.getInt("permissionLevel");
|
this.permissionLevel = listRow.getInt("permissionLevel");
|
||||||
this.uiPosition = listRow.getInt("uiPosition");
|
this.uiPosition = listRow.getInt("uiPosition");
|
||||||
other = new ArrayList<>();
|
other = new ArrayList<>();
|
||||||
|
|||||||
@ -1,8 +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.Connection;
|
||||||
import java.sql.PreparedStatement;
|
import java.sql.PreparedStatement;
|
||||||
import java.sql.ResultSet;
|
import java.sql.ResultSet;
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
import java.util.InputMismatchException;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
public class ListShareGetter implements CallHandler{
|
public class ListShareGetter implements CallHandler{
|
||||||
@ -24,14 +30,63 @@ public class ListShareGetter implements CallHandler{
|
|||||||
getList.setInt(1, listID);
|
getList.setInt(1, listID);
|
||||||
|
|
||||||
ResultSet getListResults = getList.executeQuery();
|
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
|
//Insert the ListShare objects to hold the data of the remaining rows into first's ListShare list
|
||||||
while (getListResults.next()) {
|
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;
|
return first;
|
||||||
|
|||||||
@ -51,7 +51,7 @@ public class UserGetter implements CallHandler {
|
|||||||
if (foundUsers.size() != 1) {
|
if (foundUsers.size() != 1) {
|
||||||
System.out.println(foundUsers);
|
System.out.println(foundUsers);
|
||||||
if (foundUsers.size() == 0) {
|
if (foundUsers.size() == 0) {
|
||||||
throw new InputMismatchException("Not user with given attribute (" + attributeToGet + ")");
|
throw new InputMismatchException("No user with given attribute when searching for (" + attributeToGet + ")");
|
||||||
}
|
}
|
||||||
throw new InputMismatchException("Found more than one user with supposedly unique attribute (" + attributeToGet + ")");
|
throw new InputMismatchException("Found more than one user with supposedly unique attribute (" + attributeToGet + ")");
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,42 +1,20 @@
|
|||||||
package com.example.listify;
|
package com.example.listify;
|
||||||
|
|
||||||
import android.app.AlertDialog;
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.DialogInterface;
|
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.util.Log;
|
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
import android.widget.ArrayAdapter;
|
import android.widget.*;
|
||||||
import android.widget.Button;
|
|
||||||
import android.widget.EditText;
|
|
||||||
import android.widget.ImageView;
|
|
||||||
import android.widget.ListView;
|
|
||||||
import android.widget.ProgressBar;
|
|
||||||
import android.widget.TextView;
|
|
||||||
|
|
||||||
import com.bumptech.glide.Glide;
|
|
||||||
import com.example.listify.adapter.ShareeSwipeableAdapter;
|
|
||||||
import com.example.listify.adapter.ShoppingListsSwipeableAdapter;
|
|
||||||
import com.example.listify.data.Chain;
|
|
||||||
import com.example.listify.data.Item;
|
|
||||||
import com.example.listify.data.List;
|
|
||||||
import com.example.listify.data.ListEntry;
|
|
||||||
import com.example.listify.data.ListShare;
|
|
||||||
|
|
||||||
import org.json.JSONException;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.text.DecimalFormat;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.Properties;
|
|
||||||
|
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
import androidx.annotation.Nullable;
|
import androidx.annotation.Nullable;
|
||||||
import androidx.appcompat.app.AppCompatActivity;
|
import androidx.appcompat.app.AppCompatActivity;
|
||||||
|
import com.example.listify.data.ListShare;
|
||||||
|
import org.json.JSONException;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Properties;
|
||||||
|
|
||||||
import static com.example.listify.MainActivity.am;
|
import static com.example.listify.MainActivity.am;
|
||||||
|
|
||||||
@ -48,6 +26,7 @@ public class ListSharees extends AppCompatActivity implements Requestor.Receiver
|
|||||||
Button shareList;
|
Button shareList;
|
||||||
Button removeSharee;
|
Button removeSharee;
|
||||||
|
|
||||||
|
ArrayList<ListShare> lShareeEntries = new ArrayList<>();
|
||||||
ArrayList<String> lShareeEmails = new ArrayList<>();
|
ArrayList<String> lShareeEmails = new ArrayList<>();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -97,6 +76,7 @@ public class ListSharees extends AppCompatActivity implements Requestor.Receiver
|
|||||||
|
|
||||||
if(sharee.getEntries() != null) {
|
if(sharee.getEntries() != null) {
|
||||||
for(ListShare ls : sharee.getEntries()) {
|
for(ListShare ls : sharee.getEntries()) {
|
||||||
|
lShareeEntries.add(ls);
|
||||||
lShareeEmails.add(ls.getShareWithEmail());
|
lShareeEmails.add(ls.getShareWithEmail());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -135,9 +115,17 @@ public class ListSharees extends AppCompatActivity implements Requestor.Receiver
|
|||||||
removeSharee.setOnClickListener(new View.OnClickListener() {
|
removeSharee.setOnClickListener(new View.OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View v) {
|
public void onClick(View v) {
|
||||||
lShareeEmails.remove(position);
|
try {
|
||||||
|
lShareeEntries.get(position).setPermissionLevel(0);
|
||||||
|
ListShare toRemove = lShareeEntries.remove(position);
|
||||||
|
System.out.println(toRemove);
|
||||||
|
requestor.putObject(toRemove);
|
||||||
myAdapter.notifyDataSetChanged();
|
myAdapter.notifyDataSetChanged();
|
||||||
}
|
}
|
||||||
|
catch(Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
//No need to show owner
|
//No need to show owner
|
||||||
|
|||||||
@ -61,6 +61,7 @@ public class ListShare {
|
|||||||
" [Permissions: ");
|
" [Permissions: ");
|
||||||
|
|
||||||
int permissionLevelCopy = permissionLevel;
|
int permissionLevelCopy = permissionLevel;
|
||||||
|
if (permissionLevel > 0) {
|
||||||
for (Integer permissionObject : keysToPerms.keySet()) {
|
for (Integer permissionObject : keysToPerms.keySet()) {
|
||||||
Integer permissionInteger = permissionObject;
|
Integer permissionInteger = permissionObject;
|
||||||
if (permissionLevelCopy % permissionInteger == 0) {
|
if (permissionLevelCopy % permissionInteger == 0) {
|
||||||
@ -68,7 +69,8 @@ public class ListShare {
|
|||||||
toReturn.append(keysToPerms.get(permissionInteger)).append(",");
|
toReturn.append(keysToPerms.get(permissionInteger)).append(",");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (BuildConfig.DEBUG && permissionLevelCopy != 1) {
|
}
|
||||||
|
if (BuildConfig.DEBUG && (permissionLevelCopy != 1 && permissionLevelCopy != 0)) {
|
||||||
throw new AssertionError("Assertion failed");
|
throw new AssertionError("Assertion failed");
|
||||||
}
|
}
|
||||||
toReturn.append("]}");
|
toReturn.append("]}");
|
||||||
|
|||||||
@ -6,24 +6,15 @@ import android.view.View;
|
|||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
import android.widget.ListView;
|
import android.widget.ListView;
|
||||||
import android.widget.ProgressBar;
|
import android.widget.ProgressBar;
|
||||||
import android.widget.RelativeLayout;
|
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
|
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
import androidx.fragment.app.Fragment;
|
import androidx.fragment.app.Fragment;
|
||||||
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout;
|
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout;
|
||||||
|
import com.example.listify.*;
|
||||||
import com.example.listify.AuthManager;
|
|
||||||
import com.example.listify.CreateListDialogFragment;
|
|
||||||
import com.example.listify.LoadingCircleDialog;
|
|
||||||
import com.example.listify.R;
|
|
||||||
import com.example.listify.Requestor;
|
|
||||||
import com.example.listify.SynchronousReceiver;
|
|
||||||
import com.example.listify.adapter.ShoppingListsSwipeableAdapter;
|
import com.example.listify.adapter.ShoppingListsSwipeableAdapter;
|
||||||
import com.example.listify.data.List;
|
import com.example.listify.data.List;
|
||||||
import com.google.android.material.floatingactionbutton.FloatingActionButton;
|
import com.google.android.material.floatingactionbutton.FloatingActionButton;
|
||||||
|
|
||||||
import org.json.JSONException;
|
import org.json.JSONException;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
@ -157,6 +148,9 @@ public class HomeFragment extends Fragment implements CreateListDialogFragment.O
|
|||||||
|
|
||||||
Integer[] listIds = (Integer[]) delivered;
|
Integer[] listIds = (Integer[]) delivered;
|
||||||
// Create threads and add them to a list
|
// Create threads and add them to a list
|
||||||
|
if (listIds == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
Thread[] threads = new Thread[listIds.length];
|
Thread[] threads = new Thread[listIds.length];
|
||||||
List[] results = new List[listIds.length];
|
List[] results = new List[listIds.length];
|
||||||
for (int i = 0; i < listIds.length; i++) {
|
for (int i = 0; i < listIds.length; i++) {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user