package controllers;

import org.sagebionetworks.bridge.exceptions.UnauthorizedException;
import org.sagebionetworks.bridge.models.Study;
import org.sagebionetworks.bridge.models.User;
import org.sagebionetworks.bridge.services.BackfillService;

import play.mvc.Result;

public class BackfillController extends AdminController {

    private BackfillService backfillService;

    public void setBackfillService(BackfillService backfillService) {
        this.backfillService = backfillService;
    }
    
    public Result stormpathUserConsent() throws Exception {
        checkUser();
        Study study = studyService.getStudyByHostname(getHostname());
        int total = backfillService.stormpathUserConsent(study);
        return okResult("Done. " + total + " accounts backfilled.");
    }

    private void checkUser() throws Exception {
        User user = getAuthenticatedAdminSession().getUser();
        if (!user.getRoles().contains("backfill")) {
            throw new UnauthorizedException();
        }
    }
}

@@ -571,32 +571,115 @@
    checkUser();%0A
+        int total = 0;%0A        for (Study study : studyService.getStudies()) %7B%0A    
         Study st
@@ -740,26 +740,27 @@
         
-int
+   
  total 
++
 = backfi
@@ -798,16 +798,26 @@
 study);%0A
+        %7D%0A
         

Update BackfillController.java