List renaming

Added list reanming through a ListPUT lambda. Potentially could be used to alter other List aspects in the future.

Also renamed itemID to listID for semantic unity
This commit is contained in:
NMerz 2020-11-15 17:55:25 -05:00
parent 06d834eb01
commit 616caa1e10
8 changed files with 80 additions and 30 deletions

View File

@ -3,7 +3,7 @@ import java.sql.SQLException;
import java.util.ArrayList; import java.util.ArrayList;
public class List { public class List {
Integer itemID; Integer listID;
String name; String name;
String owner; String owner;
long lastUpdated; long lastUpdated;
@ -11,7 +11,7 @@ public class List {
boolean shared; boolean shared;
public List(ResultSet listRow, boolean shared) throws SQLException { public List(ResultSet listRow, boolean shared) throws SQLException {
itemID = listRow.getInt("listID"); listID = listRow.getInt("listID");
name = listRow.getString("name"); name = listRow.getString("name");
owner = listRow.getString("owner"); owner = listRow.getString("owner");
lastUpdated = listRow.getTimestamp("lastUpdated").toInstant().toEpochMilli(); lastUpdated = listRow.getTimestamp("lastUpdated").toInstant().toEpochMilli();
@ -26,7 +26,7 @@ public class List {
@Override @Override
public String toString() { public String toString() {
return "List{" + return "List{" +
"itemID=" + itemID + "listID=" + listID +
", name='" + name + '\'' + ", name='" + name + '\'' +
", owner='" + owner + '\'' + ", owner='" + owner + '\'' +
", lastUpdated=" + lastUpdated + ", lastUpdated=" + lastUpdated +
@ -38,12 +38,12 @@ public class List {
return entries.toArray(new ItemEntry[entries.size()]); return entries.toArray(new ItemEntry[entries.size()]);
} }
public Integer getItemID() { public Integer getListID() {
return itemID; return listID;
} }
public void setItemID(Integer itemID) { public void setListID(Integer listID) {
this.itemID = itemID; this.listID = listID;
} }
public String getName() { public String getName() {

View 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 ListPUT implements RequestHandler<Map<String,Object>, Object> {
public Object handleRequest(Map<String, Object> inputMap, Context unfilled) {
return BasicHandler.handleRequest(inputMap, unfilled, ListPutter.class);
}
}

View File

@ -0,0 +1,44 @@
import java.security.AccessControlException;
import java.sql.*;
import java.time.Instant;
import java.util.HashMap;
import java.util.Map;
public class ListPutter implements CallHandler {
private final Connection connection;
private final String cognitoID;
private final String ACCESS_CHECK = "SELECT * from ListSharee WHERE userID = ? and listID = ?;";
private final String LIST_RENAME = "UPDATE List SET name = ?, lastUpdated = ? WHERE listID = ?;";
public ListPutter(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(bodyMap.get("listID").toString());
PreparedStatement accessCheck = connection.prepareStatement(ACCESS_CHECK);
accessCheck.setString(1, cognitoID);
accessCheck.setInt(2, listID);
System.out.println(accessCheck);
ResultSet userLists = accessCheck.executeQuery();
if (!userLists.next()) {
throw new AccessControlException("User does not have access to list");
} else {
if (!ListPermissions.hasPermission(userLists.getInt("permissionLevel"), "Delete")) {
throw new AccessControlException("User " + cognitoID + " does not have permission to edit list " + listID);
}
}
PreparedStatement renameList = connection.prepareStatement(LIST_RENAME);
renameList.setString(1, bodyMap.get("name").toString());
renameList.setTimestamp(2, Timestamp.from(Instant.now()));
renameList.setInt(3, listID);
System.out.println(renameList);
renameList.executeUpdate();
connection.commit();
return null;
}
}

View File

@ -1,11 +1,7 @@
package com.example.listify; package com.example.listify;
import android.app.Dialog;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.os.Bundle; import android.os.Bundle;
import com.amplifyframework.auth.AuthException;
import com.bumptech.glide.Glide; import com.bumptech.glide.Glide;
import com.example.listify.data.List; import com.example.listify.data.List;
import com.example.listify.data.ListEntry; import com.example.listify.data.ListEntry;
@ -14,8 +10,6 @@ import com.google.android.material.floatingactionbutton.FloatingActionButton;
import androidx.appcompat.app.AppCompatActivity; import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.Toolbar; import androidx.appcompat.widget.Toolbar;
import android.view.View; import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.ImageButton; import android.widget.ImageButton;
import android.widget.ImageView; import android.widget.ImageView;
import android.widget.LinearLayout; import android.widget.LinearLayout;
@ -215,7 +209,7 @@ public class ItemDetails extends AppCompatActivity implements ListPickerDialogFr
try { try {
ListEntry entry = new ListEntry(shoppingLists.get(selectedListIndex).getItemID(), curProduct.getItemId(), quantity, Instant.now().toEpochMilli(),false); ListEntry entry = new ListEntry(shoppingLists.get(selectedListIndex).getListID(), curProduct.getItemId(), quantity, Instant.now().toEpochMilli(),false);
requestor.postObject(entry); requestor.postObject(entry);
Toast.makeText(this, String.format("%d of Item added to %s", quantity, shoppingLists.get(selectedListIndex).getName()), Toast.LENGTH_LONG).show(); Toast.makeText(this, String.format("%d of Item added to %s", quantity, shoppingLists.get(selectedListIndex).getName()), Toast.LENGTH_LONG).show();
} catch (Exception e) { } catch (Exception e) {

View File

@ -107,6 +107,7 @@ public class MainActivity extends AppCompatActivity implements CreateListDialogF
SynchronousReceiver<SearchHistory> historyReceiver = new SynchronousReceiver<>(); SynchronousReceiver<SearchHistory> historyReceiver = new SynchronousReceiver<>();
requestor.getObject("N/A", SearchHistory.class, historyReceiver, historyReceiver); requestor.getObject("N/A", SearchHistory.class, historyReceiver, historyReceiver);
try { try {
requestor.putObject(new List(293, "Java.py", "me!", 1));
System.out.println(historyReceiver.await()); System.out.println(historyReceiver.await());
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();

View File

@ -90,7 +90,7 @@ public class ShoppingListsSwipeableAdapter extends BaseAdapter {
final List curList = lists.get(position); final List curList = lists.get(position);
// Bind the view to the unique list ID // Bind the view to the unique list ID
binderHelper.bind(holder.swipeLayout, Integer.toString(curList.getItemID())); binderHelper.bind(holder.swipeLayout, Integer.toString(curList.getListID()));
if(curList.isShared()) { if(curList.isShared()) {
holder.textView.setText(curList.getName() + " (shared)"); holder.textView.setText(curList.getName() + " (shared)");
@ -102,7 +102,7 @@ public class ShoppingListsSwipeableAdapter extends BaseAdapter {
@Override @Override
public void onClick(View v) { public void onClick(View v) {
try { try {
requestor.deleteObject(Integer.toString(curList.getItemID()), List.class); requestor.deleteObject(Integer.toString(curList.getListID()), List.class);
} }
catch(Exception e) { catch(Exception e) {
e.printStackTrace(); e.printStackTrace();
@ -129,7 +129,7 @@ public class ShoppingListsSwipeableAdapter extends BaseAdapter {
public void onClick(DialogInterface dialog, int which) { public void onClick(DialogInterface dialog, int which) {
EditText sharedEmailText = (EditText) codeView.findViewById(R.id.editTextTextSharedEmail); EditText sharedEmailText = (EditText) codeView.findViewById(R.id.editTextTextSharedEmail);
String sharedEmail = sharedEmailText.getText().toString(); String sharedEmail = sharedEmailText.getText().toString();
ListShare listShare = new ListShare(curList.getItemID(), sharedEmail, "Read, Write, Delete, Share"); ListShare listShare = new ListShare(curList.getListID(), sharedEmail, "Read, Write, Delete, Share");
try { try {
requestor.putObject(listShare); requestor.putObject(listShare);
} }
@ -148,7 +148,7 @@ public class ShoppingListsSwipeableAdapter extends BaseAdapter {
Toast.makeText(activity, String.format("Share %s", curList.getName()), Toast.LENGTH_SHORT).show(); Toast.makeText(activity, String.format("Share %s", curList.getName()), Toast.LENGTH_SHORT).show();
// Close the layout // Close the layout
binderHelper.closeLayout(Integer.toString(curList.getItemID())); binderHelper.closeLayout(Integer.toString(curList.getListID()));
} }
}); });
@ -158,7 +158,7 @@ public class ShoppingListsSwipeableAdapter extends BaseAdapter {
Intent listPage = new Intent(activity, ListPage.class); Intent listPage = new Intent(activity, ListPage.class);
// Send the list ID // Send the list ID
listPage.putExtra("listID", curList.getItemID()); listPage.putExtra("listID", curList.getListID());
activity.startActivity(listPage); activity.startActivity(listPage);
} }
}); });

View File

@ -3,15 +3,15 @@ package com.example.listify.data;
import java.util.Arrays; import java.util.Arrays;
public class List { public class List {
Integer itemID; Integer listID;
String name; String name;
String owner; String owner;
long lastUpdated; long lastUpdated;
final ListEntry[] entries; final ListEntry[] entries;
boolean shared; boolean shared;
public List(Integer itemID, String name, String owner, long lastUpdated, ListEntry[] entries, boolean shared) { public List(Integer listID, String name, String owner, long lastUpdated, ListEntry[] entries, boolean shared) {
this.itemID = itemID; this.listID = listID;
this.name = name; this.name = name;
this.owner = owner; this.owner = owner;
this.lastUpdated = lastUpdated; this.lastUpdated = lastUpdated;
@ -19,14 +19,14 @@ public class List {
this.shared = false; this.shared = false;
} }
public List(Integer itemID, String name, String owner, long lastUpdated) { public List(Integer listID, String name, String owner, long lastUpdated) {
this(itemID, name, owner, lastUpdated, null, false); this(listID, name, owner, lastUpdated, null, false);
} }
@Override @Override
public String toString() { public String toString() {
return "List{" + return "List{" +
"itemID=" + itemID + "listID=" + listID +
", name='" + name + '\'' + ", name='" + name + '\'' +
", owner='" + owner + '\'' + ", owner='" + owner + '\'' +
", lastUpdated=" + lastUpdated + ", lastUpdated=" + lastUpdated +
@ -35,12 +35,12 @@ public class List {
'}'; '}';
} }
public Integer getItemID() { public Integer getListID() {
return itemID; return listID;
} }
public void setItemID(Integer itemID) { public void setListID(Integer listID) {
this.itemID = itemID; this.listID = listID;
} }
public String getName() { public String getName() {

View File

@ -101,7 +101,7 @@ public class HomeFragment extends Fragment implements CreateListDialogFragment.O
@Override @Override
public void run() { public void run() {
try { try {
newList.setItemID(idReceiver.await()); newList.setListID(idReceiver.await());
} catch (Exception e) { } catch (Exception e) {
getActivity().runOnUiThread(new Runnable() { getActivity().runOnUiThread(new Runnable() {
@Override @Override