From b44032d82a640482a5dd866bf39103eb0287cebe Mon Sep 17 00:00:00 2001 From: EuniceSim142 <77243938+EuniceSim142@users.noreply.github.com> Date: Thu, 28 Mar 2024 00:45:57 +0800 Subject: [PATCH 1/7] update search document and create-core script --- solr/solr.sh | 2 ++ .../AccountRequestSearchDocument.java | 22 ++++++++++++++++--- 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/solr/solr.sh b/solr/solr.sh index 401022a87d7..f29234bccd6 100755 --- a/solr/solr.sh +++ b/solr/solr.sh @@ -17,3 +17,5 @@ bin/solr create -c accountrequests -s 2 -rf 2 bin/solr config -c accountrequests -p 8983 -action set-user-property -property update.autoCreateFields -value false curl -X POST -H 'Content-type: application/json' --data-binary '{"add-field": {"name": "email", "type": "string"}}' localhost:8983/solr/accountrequests/schema curl -X POST -H 'Content-type: application/json' --data-binary '{"add-field": {"name": "institute", "type": "string"}}' localhost:8983/solr/accountrequests/schema +curl -X POST -H 'Content-type: application/json' --data-binary '{"add-field": {"name": "comments", "type": "string"}}' localhost:8983/solr/accountrequests/schema +curl -X POST -H 'Content-type: application/json' --data-binary '{"add-field": {"name": "status", "type": "string"}}' localhost:8983/solr/accountrequests/schema diff --git a/src/main/java/teammates/storage/sqlsearch/AccountRequestSearchDocument.java b/src/main/java/teammates/storage/sqlsearch/AccountRequestSearchDocument.java index 9fbaf38ef14..e1a6ec39420 100644 --- a/src/main/java/teammates/storage/sqlsearch/AccountRequestSearchDocument.java +++ b/src/main/java/teammates/storage/sqlsearch/AccountRequestSearchDocument.java @@ -1,5 +1,6 @@ package teammates.storage.sqlsearch; +import java.util.ArrayList; import java.util.HashMap; import java.util.Map; @@ -19,14 +20,29 @@ class AccountRequestSearchDocument extends SearchDocument { Map getSearchableFields() { Map fields = new HashMap<>(); AccountRequest accountRequest = entity; - String[] searchableTexts = { - accountRequest.getName(), accountRequest.getEmail(), accountRequest.getInstitute(), - }; + + ArrayList searchableTexts = new ArrayList<>(); + searchableTexts.add(accountRequest.getName()); + searchableTexts.add(accountRequest.getEmail()); + searchableTexts.add(accountRequest.getInstitute()); + + if (accountRequest.getComments() != null) { + searchableTexts.add(accountRequest.getComments()); + } + if (accountRequest.getStatus() != null) { + searchableTexts.add(accountRequest.getStatus().toString()); + } fields.put("id", accountRequest.getId()); fields.put("_text_", String.join(" ", searchableTexts)); fields.put("email", accountRequest.getEmail()); fields.put("institute", accountRequest.getInstitute()); + if (accountRequest.getComments() != null) { + fields.put("comments", accountRequest.getComments()); + } + if (accountRequest.getStatus() != null) { + fields.put("status", accountRequest.getStatus().toString()); + } return fields; } From 13a7cdaef85e22d6e074fd5b24d8bf4232a1a308 Mon Sep 17 00:00:00 2001 From: EuniceSim142 <77243938+EuniceSim142@users.noreply.github.com> Date: Thu, 28 Mar 2024 16:47:16 +0800 Subject: [PATCH 2/7] update it --- .../it/storage/sqlsearch/AccountRequestSearchIT.java | 10 ++++++++++ src/it/resources/data/typicalDataBundle.json | 4 +++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/src/it/java/teammates/it/storage/sqlsearch/AccountRequestSearchIT.java b/src/it/java/teammates/it/storage/sqlsearch/AccountRequestSearchIT.java index db64c17c2ab..e082eee4002 100644 --- a/src/it/java/teammates/it/storage/sqlsearch/AccountRequestSearchIT.java +++ b/src/it/java/teammates/it/storage/sqlsearch/AccountRequestSearchIT.java @@ -89,6 +89,16 @@ public void allTests() throws Exception { results = accountRequestsDb.searchAccountRequestsInWholeSystem("\"TEAMMATES Test Institute 2\""); verifySearchResults(results, unregisteredInstructor2); + ______TS("success: search for account requests; account requests should be searchable by their comments"); + + results = accountRequestsDb.searchAccountRequestsInWholeSystem("Comments for account request from instructor3"); + verifySearchResults(results, ins2InCourse2); + + ______TS("success: search for account requests; account requests should be searchable by their status"); + + results = accountRequestsDb.searchAccountRequestsInWholeSystem("registered"); + verifySearchResults(results, ins2InCourse2); + ______TS("success: search for account requests; unregistered account requests should be searchable"); results = accountRequestsDb.searchAccountRequestsInWholeSystem("\"unregisteredinstructor1@gmail.tmt\""); diff --git a/src/it/resources/data/typicalDataBundle.json b/src/it/resources/data/typicalDataBundle.json index 2372b2fa35f..e4e36ad930e 100644 --- a/src/it/resources/data/typicalDataBundle.json +++ b/src/it/resources/data/typicalDataBundle.json @@ -80,7 +80,9 @@ "name": "Instructor 2", "email": "instr2@teammates.tmt", "institute": "TEAMMATES Test Institute 1", - "registeredAt": "2015-02-14T00:00:00Z" + "registeredAt": "2015-02-14T00:00:00Z", + "comments": "Comments for account request from instructor3", + "status": "REGISTERED" }, "instructor3": { "name": "Instructor 3 of CourseNoRegister", From bc3786344bca78b3eb609c931af18314e5341cd5 Mon Sep 17 00:00:00 2001 From: EuniceSim142 <77243938+EuniceSim142@users.noreply.github.com> Date: Thu, 28 Mar 2024 17:28:17 +0800 Subject: [PATCH 3/7] modify relevant classes to use id instead of (email, institute) --- .../java/teammates/storage/sqlapi/AccountRequestsDb.java | 7 +++++++ .../storage/sqlsearch/AccountRequestSearchDocument.java | 2 +- .../storage/sqlsearch/AccountRequestSearchManager.java | 6 +++--- 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/src/main/java/teammates/storage/sqlapi/AccountRequestsDb.java b/src/main/java/teammates/storage/sqlapi/AccountRequestsDb.java index e3ced48d6af..d0fdb298cba 100644 --- a/src/main/java/teammates/storage/sqlapi/AccountRequestsDb.java +++ b/src/main/java/teammates/storage/sqlapi/AccountRequestsDb.java @@ -69,6 +69,13 @@ public AccountRequest getAccountRequest(String email, String institute) { return query.getResultStream().findFirst().orElse(null); } + /** + * Get AccountRequest by {@code id} from database. + */ + public AccountRequest getAccountRequest(UUID id) { + return HibernateUtil.get(AccountRequest.class, id); + } + /** * Get all Account Requests with {@code status} of 'pending'. */ diff --git a/src/main/java/teammates/storage/sqlsearch/AccountRequestSearchDocument.java b/src/main/java/teammates/storage/sqlsearch/AccountRequestSearchDocument.java index e1a6ec39420..15b6dd02e37 100644 --- a/src/main/java/teammates/storage/sqlsearch/AccountRequestSearchDocument.java +++ b/src/main/java/teammates/storage/sqlsearch/AccountRequestSearchDocument.java @@ -33,7 +33,7 @@ Map getSearchableFields() { searchableTexts.add(accountRequest.getStatus().toString()); } - fields.put("id", accountRequest.getId()); + fields.put("id", accountRequest.getId().toString()); fields.put("_text_", String.join(" ", searchableTexts)); fields.put("email", accountRequest.getEmail()); fields.put("institute", accountRequest.getInstitute()); diff --git a/src/main/java/teammates/storage/sqlsearch/AccountRequestSearchManager.java b/src/main/java/teammates/storage/sqlsearch/AccountRequestSearchManager.java index c5dc5d44428..5325836af32 100644 --- a/src/main/java/teammates/storage/sqlsearch/AccountRequestSearchManager.java +++ b/src/main/java/teammates/storage/sqlsearch/AccountRequestSearchManager.java @@ -2,6 +2,7 @@ import java.util.Comparator; import java.util.List; +import java.util.UUID; import org.apache.solr.client.solrj.SolrQuery; import org.apache.solr.client.solrj.response.QueryResponse; @@ -35,9 +36,8 @@ AccountRequestSearchDocument createDocument(AccountRequest accountRequest) { @Override AccountRequest getEntityFromDocument(SolrDocument document) { - String email = (String) document.getFirstValue("email"); - String institute = (String) document.getFirstValue("institute"); - return accountRequestsDb.getAccountRequest(email, institute); + UUID id = UUID.fromString((String) document.getFieldValue("id")); + return accountRequestsDb.getAccountRequest(id); } @Override From e82188b4c4996edba59c03eb9f7a239d57366f33 Mon Sep 17 00:00:00 2001 From: EuniceSim142 <77243938+EuniceSim142@users.noreply.github.com> Date: Fri, 29 Mar 2024 15:26:11 +0800 Subject: [PATCH 4/7] remove duplicate method --- .../java/teammates/storage/sqlapi/AccountRequestsDb.java | 7 ------- 1 file changed, 7 deletions(-) diff --git a/src/main/java/teammates/storage/sqlapi/AccountRequestsDb.java b/src/main/java/teammates/storage/sqlapi/AccountRequestsDb.java index 0899ce98452..f95f93bc7d9 100644 --- a/src/main/java/teammates/storage/sqlapi/AccountRequestsDb.java +++ b/src/main/java/teammates/storage/sqlapi/AccountRequestsDb.java @@ -77,13 +77,6 @@ public AccountRequest getAccountRequest(String email, String institute) { return query.getResultStream().findFirst().orElse(null); } - /** - * Get AccountRequest by {@code id} from database. - */ - public AccountRequest getAccountRequest(UUID id) { - return HibernateUtil.get(AccountRequest.class, id); - } - /** * Get all Account Requests with {@code status} of 'pending'. */ From 1ac96b08878a7748fb565fea3b33d8c9ca8f9b10 Mon Sep 17 00:00:00 2001 From: EuniceSim142 <77243938+EuniceSim142@users.noreply.github.com> Date: Fri, 29 Mar 2024 15:35:44 +0800 Subject: [PATCH 5/7] fix it tests --- .../it/storage/sqlsearch/AccountRequestSearchIT.java | 6 +++--- src/it/resources/data/typicalDataBundle.json | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/it/java/teammates/it/storage/sqlsearch/AccountRequestSearchIT.java b/src/it/java/teammates/it/storage/sqlsearch/AccountRequestSearchIT.java index e082eee4002..a9b196eafc8 100644 --- a/src/it/java/teammates/it/storage/sqlsearch/AccountRequestSearchIT.java +++ b/src/it/java/teammates/it/storage/sqlsearch/AccountRequestSearchIT.java @@ -91,13 +91,13 @@ public void allTests() throws Exception { ______TS("success: search for account requests; account requests should be searchable by their comments"); - results = accountRequestsDb.searchAccountRequestsInWholeSystem("Comments for account request from instructor3"); - verifySearchResults(results, ins2InCourse2); + results = accountRequestsDb.searchAccountRequestsInWholeSystem("Comments for account request from instructor2"); + verifySearchResults(results, ins2General); ______TS("success: search for account requests; account requests should be searchable by their status"); results = accountRequestsDb.searchAccountRequestsInWholeSystem("registered"); - verifySearchResults(results, ins2InCourse2); + verifySearchResults(results, ins2General); ______TS("success: search for account requests; unregistered account requests should be searchable"); diff --git a/src/it/resources/data/typicalDataBundle.json b/src/it/resources/data/typicalDataBundle.json index e4e36ad930e..887488e829d 100644 --- a/src/it/resources/data/typicalDataBundle.json +++ b/src/it/resources/data/typicalDataBundle.json @@ -81,7 +81,7 @@ "email": "instr2@teammates.tmt", "institute": "TEAMMATES Test Institute 1", "registeredAt": "2015-02-14T00:00:00Z", - "comments": "Comments for account request from instructor3", + "comments": "Comments for account request from instructor2", "status": "REGISTERED" }, "instructor3": { From 6e0c8a0e44da7a17eac81869ca1ebf78aabf36ef Mon Sep 17 00:00:00 2001 From: EuniceSim142 <77243938+EuniceSim142@users.noreply.github.com> Date: Tue, 2 Apr 2024 00:45:56 +0800 Subject: [PATCH 6/7] fix failing tests --- src/main/java/teammates/storage/sqlapi/AccountRequestsDb.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/teammates/storage/sqlapi/AccountRequestsDb.java b/src/main/java/teammates/storage/sqlapi/AccountRequestsDb.java index f95f93bc7d9..a2d27c8d6bf 100644 --- a/src/main/java/teammates/storage/sqlapi/AccountRequestsDb.java +++ b/src/main/java/teammates/storage/sqlapi/AccountRequestsDb.java @@ -155,7 +155,7 @@ public void deleteDocumentByAccountRequestId(UUID accountRequestId) { // Solr saves the id with the prefix "java.util.UUID:", so we need to add it here to // identify and delete the document from the index getSearchManager().deleteDocuments( - Collections.singletonList("java.util.UUID:" + accountRequestId.toString())); + Collections.singletonList(accountRequestId.toString())); } } From 49ff21ab821ace629d6be03225de2e370ee06829 Mon Sep 17 00:00:00 2001 From: EuniceSim142 <77243938+EuniceSim142@users.noreply.github.com> Date: Tue, 2 Apr 2024 19:22:16 +0800 Subject: [PATCH 7/7] remove unnecessary comment --- src/main/java/teammates/storage/sqlapi/AccountRequestsDb.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/main/java/teammates/storage/sqlapi/AccountRequestsDb.java b/src/main/java/teammates/storage/sqlapi/AccountRequestsDb.java index a2d27c8d6bf..b05b544d5b9 100644 --- a/src/main/java/teammates/storage/sqlapi/AccountRequestsDb.java +++ b/src/main/java/teammates/storage/sqlapi/AccountRequestsDb.java @@ -152,8 +152,6 @@ public void deleteAccountRequest(AccountRequest accountRequest) { */ public void deleteDocumentByAccountRequestId(UUID accountRequestId) { if (getSearchManager() != null) { - // Solr saves the id with the prefix "java.util.UUID:", so we need to add it here to - // identify and delete the document from the index getSearchManager().deleteDocuments( Collections.singletonList(accountRequestId.toString())); }