Skip to content

Commit

Permalink
Resolved conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
sripooja committed Jul 13, 2016
2 parents 81c1242 + 2fb63a6 commit 5bcec90
Show file tree
Hide file tree
Showing 4 changed files with 85 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -198,5 +198,14 @@ public void deactivationRequest(@RequestParam(value = "msisdn") Long msisdn) {
}
subscriberService.deactivateAllSubscriptionsForSubscriber(msisdn);
}

@RequestMapping("/getScores")
@ResponseBody
public String getScoresForNumber(@RequestParam(required = true) Long callingNumber) {
LOGGER.info("/getScores Getting scores for user");
String scores = mobileAcademyService.getScoresForUser(callingNumber);
LOGGER.info("Scores: " + scores);
return scores;
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,11 @@ public interface MobileAcademyService {
*/
void triggerCompletionNotification(Long callingNumber);

/**
* Get scores for a user
* @param callingNumber
* @return
*/
String getScoresForUser(Long callingNumber);

}
Original file line number Diff line number Diff line change
Expand Up @@ -442,4 +442,19 @@ private MaCourse mapCourseDomainToDto(NmsCourse course) {
courseDto.setContent(course.getContent());
return courseDto;
}

public String getScoresForUser(Long callingNumber) {
LOGGER.debug("Fetching scores in service");
String scores = "{000000}";
Bookmark existingBookmark = bookmarkService.getLatestBookmarkByUserId(callingNumber.toString());
if (existingBookmark != null && existingBookmark.getProgress() != null) {
Map<String, Integer> scoreMap = (Map<String, Integer>) existingBookmark.getProgress().get(SCORES_KEY);
scores = scoreMap.toString();
LOGGER.debug("Returning real scores for user");
} else {
LOGGER.debug("No scores found for user");
}

return scores;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
import org.apache.commons.httpclient.URIException;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpDelete;
import org.apache.commons.io.IOUtils;
import org.apache.http.HttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.client.utils.URIBuilder;
Expand All @@ -15,6 +17,8 @@
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.motechproject.mtraining.domain.Bookmark;
import org.motechproject.mtraining.service.BookmarkService;
import org.motechproject.nms.api.web.contract.AddFlwRequest;
import org.motechproject.nms.flw.domain.FlwError;
import org.motechproject.nms.flw.domain.FlwErrorReason;
Expand Down Expand Up @@ -58,7 +62,10 @@
import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.*;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
Expand Down Expand Up @@ -135,6 +142,9 @@ public class OpsControllerBundleIT extends BasePaxIT {
private RegionHelper rh;
private SubscriptionHelper sh;

@Inject
BookmarkService bookmarkService;

@Before
public void setupTestData() {
testingService.clearDatabase();
Expand Down Expand Up @@ -327,6 +337,49 @@ public void testUpdateNoTaluka() throws IOException, InterruptedException {
assertNull("Taluka update rejected", flw.getTaluka());
}

@Test
public void testGetScoresForUser() throws IOException, InterruptedException {
Long callingNumber = 9876543210L;
String getScoresEndpoint = String.format("http://localhost:%d/api/ops/getScores?callingNumber=%d",
TestContext.getJettyPort(), callingNumber);
Map<String, Integer> scores = new HashMap<>();
scores.put("1", 4);
scores.put("2", 3);
Map<String, Object> progress = new HashMap<>();
progress.put("scoresByChapter", scores);
Bookmark newBookmark = new Bookmark(callingNumber.toString(), null, null, null, progress);
bookmarkService.createBookmark(newBookmark);

HttpGet httpGet = RequestBuilder.createGetRequest(getScoresEndpoint);
HttpResponse response = SimpleHttpClient.httpRequestAndResponse(httpGet, RequestBuilder.ADMIN_USERNAME, RequestBuilder.ADMIN_PASSWORD);
assertNotNull(response);
assertEquals(200, response.getStatusLine().getStatusCode());
String body = IOUtils.toString(response.getEntity().getContent());
assertTrue(body.contains("1=4"));
assertTrue(body.contains("2=3"));
}

@Test
public void testGetScoresForUserNoScores() throws IOException, InterruptedException {
Long callingNumber = 9876543210L;
String getScoresEndpoint = String.format("http://localhost:%d/api/ops/getScores?callingNumber=%d",
TestContext.getJettyPort(), 9976543210L);
Map<String, Integer> scores = new HashMap<>();
scores.put("1", 4);
scores.put("2", 3);
Map<String, Object> progress = new HashMap<>();
progress.put("scoresByChapter", scores);
Bookmark newBookmark = new Bookmark(callingNumber.toString(), null, null, null, progress);
bookmarkService.createBookmark(newBookmark);

HttpGet httpGet = RequestBuilder.createGetRequest(getScoresEndpoint);
HttpResponse response = SimpleHttpClient.httpRequestAndResponse(httpGet, RequestBuilder.ADMIN_USERNAME, RequestBuilder.ADMIN_PASSWORD);
assertNotNull(response);
assertEquals(200, response.getStatusLine().getStatusCode());
String body = IOUtils.toString(response.getEntity().getContent());
assertEquals("{000000}", body);
}

private void createFlwHelper(String name, Long phoneNumber, String mctsFlwId) {
TransactionStatus status = transactionManager.getTransaction(new DefaultTransactionDefinition());
stateDataService.create(state);
Expand Down

0 comments on commit 5bcec90

Please sign in to comment.