Skip to content

Commit

Permalink
minor refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
UmenR committed May 25, 2021
1 parent a5542e7 commit 51ad84d
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 7 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ buildNumber.properties
.project
.settings
.tern-project
*.iml
*.iml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@

/**
* REST API for the Crowdsource application: https://github.com/elimu-ai/crowdsource
*
* <p>
* This controller is responsible for handling the creation words and fetching data required for the creation of
* a new word eg:(Allophones, existing words etc.).
*/
Expand Down Expand Up @@ -60,13 +60,14 @@ public class WordContributionRestController {

/**
* Handles the creation of a new word & the corresponding word contribution event.
*
* @param request
* @param response
* @param requestBody JSON String
* @return
*/
@RequestMapping(value = "/word", method = RequestMethod.POST)
public String handleWordContributionRequest (
public String handleWordContributionRequest(
HttpServletRequest request,
HttpServletResponse response,
@RequestBody String requestBody) {
Expand Down Expand Up @@ -117,14 +118,14 @@ public String handleWordContributionRequest (
return jsonResponse;
}

try{
try {
//Convert the JSON String to WordGson Object.
Word newWord = new Word();
newWord.setWordType(wordGson.getWordType());
newWord.setText(wordGson.getText());
List<LetterToAllophoneMappingGson> wordGsonLetterToAllophoneMappingsGson = wordGson.getLetterToAllophoneMappings();
List<LetterToAllophoneMapping> letterToAllophoneMappings = new ArrayList<>();
for(LetterToAllophoneMappingGson letterToAllophoneMappingGson : wordGsonLetterToAllophoneMappingsGson){
for (LetterToAllophoneMappingGson letterToAllophoneMappingGson : wordGsonLetterToAllophoneMappingsGson) {
LetterToAllophoneMapping letterToAllophoneMapping = letterToAllophoneMappingDao.read(letterToAllophoneMappingGson.getId());
letterToAllophoneMappings.add(letterToAllophoneMapping);
}
Expand All @@ -144,7 +145,7 @@ public String handleWordContributionRequest (
wordContributionEventDao.create(wordContributionEvent);

response.setStatus(HttpStatus.CREATED.value());
} catch (Exception ex){
} catch (Exception ex) {
logger.error(ex);

jsonObject.put("result", "error");
Expand All @@ -160,6 +161,7 @@ public String handleWordContributionRequest (
/**
* This method will return all the required data to create a word. eg: Allophones etc.
* TODO : fetch other information that are optional when creating a new word eg: existing words(for Root word) etc.
*
* @param request
* @param response
* @return
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,4 @@ public void testGetWordDataForCrowdSourcing() {
assertThat(allophoneJsonObject.getString("valueIpa"), not(nullValue()));
}

}
}

0 comments on commit 51ad84d

Please sign in to comment.