Skip to content

Commit

Permalink
[#11878] Update SearchAccountRequests endpoint (#12950)
Browse files Browse the repository at this point in the history
* update search document and create-core script

* update it

* modify relevant classes to use id instead of (email, institute)

* remove duplicate method

* fix it tests

* fix failing tests

* remove unnecessary comment
  • Loading branch information
EuniceSim142 authored Apr 2, 2024
1 parent 7ec74c7 commit 0b07036
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 11 deletions.
2 changes: 2 additions & 0 deletions solr/solr.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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 instructor2");
verifySearchResults(results, ins2General);

______TS("success: search for account requests; account requests should be searchable by their status");

results = accountRequestsDb.searchAccountRequestsInWholeSystem("registered");
verifySearchResults(results, ins2General);

______TS("success: search for account requests; unregistered account requests should be searchable");

results = accountRequestsDb.searchAccountRequestsInWholeSystem("\"unregisteredinstructor1@gmail.tmt\"");
Expand Down
4 changes: 3 additions & 1 deletion src/it/resources/data/typicalDataBundle.json
Original file line number Diff line number Diff line change
Expand Up @@ -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 instructor2",
"status": "REGISTERED"
},
"instructor3": {
"name": "Instructor 3 of CourseNoRegister",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,10 +152,8 @@ 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("java.util.UUID:" + accountRequestId.toString()));
Collections.singletonList(accountRequestId.toString()));
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package teammates.storage.sqlsearch;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;

Expand All @@ -19,14 +20,29 @@ class AccountRequestSearchDocument extends SearchDocument<AccountRequest> {
Map<String, Object> getSearchableFields() {
Map<String, Object> fields = new HashMap<>();
AccountRequest accountRequest = entity;
String[] searchableTexts = {
accountRequest.getName(), accountRequest.getEmail(), accountRequest.getInstitute(),
};

fields.put("id", accountRequest.getId());
ArrayList<String> 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().toString());
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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 0b07036

Please sign in to comment.