From 1b6bdcd1880786eada918b19cf5f2aab42ebdb37 Mon Sep 17 00:00:00 2001 From: Scott Macdonald <57190223+scmacdon@users.noreply.github.com> Date: Fri, 28 Oct 2022 06:15:04 -0400 Subject: [PATCH 1/8] Update Readme.md --- javav2/usecases/Creating_Spring_RDS_ Rest/Readme.md | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/javav2/usecases/Creating_Spring_RDS_ Rest/Readme.md b/javav2/usecases/Creating_Spring_RDS_ Rest/Readme.md index 966c6352d41..180fd226cf4 100644 --- a/javav2/usecases/Creating_Spring_RDS_ Rest/Readme.md +++ b/javav2/usecases/Creating_Spring_RDS_ Rest/Readme.md @@ -555,7 +555,7 @@ public class WorkItemRepository implements CrudRepository { @Override public Optional findById(String s) { - String sqlStatement = "SELECT idwork, date, description, guide, status, username FROM work WHERE idwork = :id;"; + String sqlStatement = "SELECT idwork, date, description, guide, status, username, archive FROM work WHERE idwork = :id;"; List parameters = List.of(param("id", s)); var result = execute(sqlStatement, parameters) .records() @@ -586,7 +586,7 @@ public class WorkItemRepository implements CrudRepository { param("id", id), param("arch", archived) ); - execute(sqlStatement, parameters); + execute(sqlStatement, parameters); } catch (RdsDataException e) { e.printStackTrace(); } @@ -598,7 +598,7 @@ public class WorkItemRepository implements CrudRepository { String isArc; if (status.compareTo("true") == 0) { - sqlStatement = "SELECT idwork, date, description, guide, status, username " + + sqlStatement = "SELECT idwork, date, description, guide, status, username, archive " + "FROM work WHERE archive = :arch ;"; isArc = "1"; List parameters = List.of( @@ -611,7 +611,7 @@ public class WorkItemRepository implements CrudRepository { .collect(Collectors.toUnmodifiableList()); } else if (status.compareTo("false") == 0) { - sqlStatement = "SELECT idwork, date, description, guide, status, username " + + sqlStatement = "SELECT idwork, date, description, guide, status, username, archive " + "FROM work WHERE archive = :arch ;"; isArc = "0"; List parameters = List.of( @@ -624,7 +624,7 @@ public class WorkItemRepository implements CrudRepository { .collect(Collectors.toUnmodifiableList()); } else { - sqlStatement = "SELECT idwork, date, description, guide, status, username FROM work ;"; + sqlStatement = "SELECT idwork, date, description, guide, status, username, archive FROM work ;"; List parameters = List.of( ); @@ -685,7 +685,6 @@ public class WorkItemRepository implements CrudRepository { } } - ``` From 54b9ba98681019f663deb088c4b9bba30843c6e1 Mon Sep 17 00:00:00 2001 From: Scott Macdonald <57190223+scmacdon@users.noreply.github.com> Date: Fri, 28 Oct 2022 06:15:29 -0400 Subject: [PATCH 2/8] Update WorkItemRepository.java --- .../src/main/java/com/aws/rest/WorkItemRepository.java | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/javav2/usecases/Creating_Spring_RDS_ Rest/src/main/java/com/aws/rest/WorkItemRepository.java b/javav2/usecases/Creating_Spring_RDS_ Rest/src/main/java/com/aws/rest/WorkItemRepository.java index 8ca1b3cde40..b719e8be44d 100644 --- a/javav2/usecases/Creating_Spring_RDS_ Rest/src/main/java/com/aws/rest/WorkItemRepository.java +++ b/javav2/usecases/Creating_Spring_RDS_ Rest/src/main/java/com/aws/rest/WorkItemRepository.java @@ -98,7 +98,7 @@ public Iterable saveAll(Iterable entities) { @Override public Optional findById(String s) { - String sqlStatement = "SELECT idwork, date, description, guide, status, username FROM work WHERE idwork = :id;"; + String sqlStatement = "SELECT idwork, date, description, guide, status, username, archive FROM work WHERE idwork = :id;"; List parameters = List.of(param("id", s)); var result = execute(sqlStatement, parameters) .records() @@ -129,7 +129,7 @@ public void flipItemArchive(String id) { param("id", id), param("arch", archived) ); - execute(sqlStatement, parameters); + execute(sqlStatement, parameters); } catch (RdsDataException e) { e.printStackTrace(); } @@ -141,7 +141,7 @@ public Iterable findAllWithStatus(String status) { String isArc; if (status.compareTo("true") == 0) { - sqlStatement = "SELECT idwork, date, description, guide, status, username " + + sqlStatement = "SELECT idwork, date, description, guide, status, username, archive " + "FROM work WHERE archive = :arch ;"; isArc = "1"; List parameters = List.of( @@ -154,7 +154,7 @@ public Iterable findAllWithStatus(String status) { .collect(Collectors.toUnmodifiableList()); } else if (status.compareTo("false") == 0) { - sqlStatement = "SELECT idwork, date, description, guide, status, username " + + sqlStatement = "SELECT idwork, date, description, guide, status, username, archive " + "FROM work WHERE archive = :arch ;"; isArc = "0"; List parameters = List.of( @@ -167,7 +167,7 @@ public Iterable findAllWithStatus(String status) { .collect(Collectors.toUnmodifiableList()); } else { - sqlStatement = "SELECT idwork, date, description, guide, status, username FROM work ;"; + sqlStatement = "SELECT idwork, date, description, guide, status, username, archive FROM work ;"; List parameters = List.of( ); From 6f465e24983aac3ad8249fca046b76436a19d0d9 Mon Sep 17 00:00:00 2001 From: Scott Macdonald <57190223+scmacdon@users.noreply.github.com> Date: Fri, 28 Oct 2022 06:16:43 -0400 Subject: [PATCH 3/8] Update WorkItem.java --- .../src/main/java/com/aws/rest/WorkItem.java | 22 +++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/javav2/usecases/Creating_Spring_RDS_ Rest/src/main/java/com/aws/rest/WorkItem.java b/javav2/usecases/Creating_Spring_RDS_ Rest/src/main/java/com/aws/rest/WorkItem.java index 28b214fe8ae..af07a93a866 100644 --- a/javav2/usecases/Creating_Spring_RDS_ Rest/src/main/java/com/aws/rest/WorkItem.java +++ b/javav2/usecases/Creating_Spring_RDS_ Rest/src/main/java/com/aws/rest/WorkItem.java @@ -16,11 +16,17 @@ public class WorkItem { private String date; private String description; private String status; + private boolean archived; public static WorkItem from(List fields) { var item = new WorkItem(); - for (int i = 0; i <= 5; i++) { + boolean arcVal = false; + for (int i = 0; i <= 6; i++) { String value = fields.get(i).stringValue(); + + if (i == 6) + arcVal = fields.get(i).booleanValue(); + switch (i) { case 0: item.setId(value); @@ -40,11 +46,23 @@ public static WorkItem from(List fields) { case 5: item.setName(value); break; + + case 6: + item.setArchived(arcVal); + break; } } return item; } + public void setArchived(boolean archived) { + this.archived =archived; + } + + public boolean getArchived() { + return this.archived; + } + public void setId(String id) { this.id = id; } @@ -93,4 +111,4 @@ public void setGuide(String guide) { public String getGuide() { return this.guide; } -} \ No newline at end of file +} From 56c841713611e98829faa902dde62da63b7354b6 Mon Sep 17 00:00:00 2001 From: Scott Macdonald <57190223+scmacdon@users.noreply.github.com> Date: Fri, 28 Oct 2022 06:17:36 -0400 Subject: [PATCH 4/8] Update Readme.md --- .../Creating_Spring_RDS_ Rest/Readme.md | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/javav2/usecases/Creating_Spring_RDS_ Rest/Readme.md b/javav2/usecases/Creating_Spring_RDS_ Rest/Readme.md index 180fd226cf4..52fb3b5d7dc 100644 --- a/javav2/usecases/Creating_Spring_RDS_ Rest/Readme.md +++ b/javav2/usecases/Creating_Spring_RDS_ Rest/Readme.md @@ -706,11 +706,16 @@ public class WorkItem { private String date; private String description; private String status; + private boolean archived; public static WorkItem from(List fields) { var item = new WorkItem(); - for (int i = 0; i <= 5; i++) { + boolean arcVal = false; + for (int i = 0; i <= 6; i++) { String value = fields.get(i).stringValue(); + if (i == 6) + arcVal = fields.get(i).booleanValue(); + switch (i) { case 0: item.setId(value); @@ -730,11 +735,23 @@ public class WorkItem { case 5: item.setName(value); break; + + case 6: + item.setArchived(arcVal); + break; } } return item; } + public void setArchived(boolean archived) { + this.archived =archived; + } + + public boolean getArchived() { + return this.archived; + } + public void setId(String id) { this.id = id; } From c0d7baed137320536179be78fd81e80ef6a01e87 Mon Sep 17 00:00:00 2001 From: Scott Macdonald <57190223+scmacdon@users.noreply.github.com> Date: Fri, 28 Oct 2022 06:24:20 -0400 Subject: [PATCH 5/8] Update Readme.md --- javav2/usecases/CreatingSpringRedshiftRest/Readme.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/javav2/usecases/CreatingSpringRedshiftRest/Readme.md b/javav2/usecases/CreatingSpringRedshiftRest/Readme.md index 65c41bac600..e7d7ada7bde 100644 --- a/javav2/usecases/CreatingSpringRedshiftRest/Readme.md +++ b/javav2/usecases/CreatingSpringRedshiftRest/Readme.md @@ -436,6 +436,7 @@ The following Java code represents the **WorkItemRepository** class. Notice that In addition, notice the use of [Class SqlParameter](https://sdk.amazonaws.com/java/api/latest/software/amazon/awssdk/services/redshiftdata/model/SqlParameter.html) when using SQL statements. For example, in the **getData** method, you build a list of **SqlParameter** objects used to get records from the database. ```java + package com.aws.rest; import org.springframework.stereotype.Component; @@ -484,14 +485,14 @@ public class WorkItemRepository { // Get all records from the Amazon Redshift table. if (arch.compareTo("") == 0) { - sqlStatement = "SELECT idwork, date, description, guide, status, username FROM work"; + sqlStatement = "SELECT idwork, date, description, guide, status, username, archive FROM work"; ExecuteStatementResponse response = executeAll(sqlStatement); String id = response.id(); System.out.println("The identifier of the statement is "+id); checkStatement(id); return getResults(id); } else { - sqlStatement = "SELECT idwork, date, description, guide, status, username " + + sqlStatement = "SELECT idwork, date, description, guide, status, username, archive " + "FROM work WHERE username = :username and archive = :arch ;"; parameters = List.of( @@ -608,8 +609,6 @@ public class WorkItemRepository { flipItemArchive(sqlStatement,parameters); } - - public String injectNewSubmission(WorkItem item) { try { String name = item.getName(); @@ -648,6 +647,7 @@ public class WorkItemRepository { } } + ``` ### WorkItem class From d213cc33423bcc1d9e59a615b76ec70b80d7c4ec Mon Sep 17 00:00:00 2001 From: Scott Macdonald <57190223+scmacdon@users.noreply.github.com> Date: Fri, 28 Oct 2022 06:25:16 -0400 Subject: [PATCH 6/8] Update Readme.md --- .../CreatingSpringRedshiftRest/Readme.md | 21 +++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/javav2/usecases/CreatingSpringRedshiftRest/Readme.md b/javav2/usecases/CreatingSpringRedshiftRest/Readme.md index e7d7ada7bde..5b56c653f3e 100644 --- a/javav2/usecases/CreatingSpringRedshiftRest/Readme.md +++ b/javav2/usecases/CreatingSpringRedshiftRest/Readme.md @@ -668,11 +668,17 @@ public class WorkItem { private String date; private String description; private String status; + private boolean archived ; public static WorkItem from(List fields) { var item = new WorkItem(); - for (int i = 0; i <= 5; i++) { - String value = fields.get(i).stringValue(); + for (int i = 0; i <= 6; i++) { + String value=""; + boolean val = false; + value = fields.get(i).stringValue(); + if (i == 6) + val = fields.get(i).booleanValue(); + switch (i) { case 0: item.setId(value); @@ -692,11 +698,22 @@ public class WorkItem { case 5: item.setName(value); break; + case 6: + item.setArchived(val); + break; } } return item; } + public boolean getArchived() { + return this.archived; + } + + public void setArchived(boolean archived) { + this.archived = archived; + } + public void setId(String id) { this.id = id; } From d25fb51a8345de0bd16772d4c4d419c0f52577d5 Mon Sep 17 00:00:00 2001 From: Scott Macdonald <57190223+scmacdon@users.noreply.github.com> Date: Fri, 28 Oct 2022 06:25:47 -0400 Subject: [PATCH 7/8] Update WorkItem.java --- .../src/main/java/com/aws/rest/WorkItem.java | 23 ++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/javav2/usecases/CreatingSpringRedshiftRest/src/main/java/com/aws/rest/WorkItem.java b/javav2/usecases/CreatingSpringRedshiftRest/src/main/java/com/aws/rest/WorkItem.java index 36d245ddbd2..ef914ba9338 100644 --- a/javav2/usecases/CreatingSpringRedshiftRest/src/main/java/com/aws/rest/WorkItem.java +++ b/javav2/usecases/CreatingSpringRedshiftRest/src/main/java/com/aws/rest/WorkItem.java @@ -16,11 +16,17 @@ public class WorkItem { private String date; private String description; private String status; + private boolean archived ; public static WorkItem from(List fields) { var item = new WorkItem(); - for (int i = 0; i <= 5; i++) { - String value = fields.get(i).stringValue(); + for (int i = 0; i <= 6; i++) { + String value=""; + boolean val = false; + value = fields.get(i).stringValue(); + if (i == 6) + val = fields.get(i).booleanValue(); + switch (i) { case 0: item.setId(value); @@ -40,11 +46,22 @@ public static WorkItem from(List fields) { case 5: item.setName(value); break; + case 6: + item.setArchived(val); + break; } } return item; } + public boolean getArchived() { + return this.archived; + } + + public void setArchived(boolean archived) { + this.archived = archived; + } + public void setId(String id) { this.id = id; } @@ -93,4 +110,4 @@ public void setGuide(String guide) { public String getGuide() { return this.guide; } -} \ No newline at end of file +} From cb5101a068aaf2498a76ac7c258d728f48fa3c86 Mon Sep 17 00:00:00 2001 From: Scott Macdonald <57190223+scmacdon@users.noreply.github.com> Date: Fri, 28 Oct 2022 06:26:26 -0400 Subject: [PATCH 8/8] Update WorkItemRepository.java --- .../src/main/java/com/aws/rest/WorkItemRepository.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/javav2/usecases/CreatingSpringRedshiftRest/src/main/java/com/aws/rest/WorkItemRepository.java b/javav2/usecases/CreatingSpringRedshiftRest/src/main/java/com/aws/rest/WorkItemRepository.java index 21618950691..a1be8c746fc 100644 --- a/javav2/usecases/CreatingSpringRedshiftRest/src/main/java/com/aws/rest/WorkItemRepository.java +++ b/javav2/usecases/CreatingSpringRedshiftRest/src/main/java/com/aws/rest/WorkItemRepository.java @@ -51,14 +51,14 @@ public List getData(String arch) { // Get all records from the Amazon Redshift table. if (arch.compareTo("") == 0) { - sqlStatement = "SELECT idwork, date, description, guide, status, username FROM work"; + sqlStatement = "SELECT idwork, date, description, guide, status, username, archive FROM work"; ExecuteStatementResponse response = executeAll(sqlStatement); String id = response.id(); System.out.println("The identifier of the statement is "+id); checkStatement(id); return getResults(id); } else { - sqlStatement = "SELECT idwork, date, description, guide, status, username " + + sqlStatement = "SELECT idwork, date, description, guide, status, username, archive " + "FROM work WHERE username = :username and archive = :arch ;"; parameters = List.of(