package controllers;

import org.sagebionetworks.bridge.exceptions.BridgeServiceException;
import org.sagebionetworks.bridge.models.UserSession;
import org.sagebionetworks.bridge.services.BackfillService;

import play.mvc.Result;

import com.stormpath.sdk.account.Account;
import com.stormpath.sdk.client.Client;

public class BackfillController extends BaseController {

    private Client stormpathClient;

    private BackfillService backfillService;

    public void setStormpathClient(Client client) {
        this.stormpathClient = client;
    }

    public void setBackfillService(BackfillService backfillService) {
        this.backfillService = backfillService;
    }

    public Result stormpathUserConsent() throws Exception {
        checkUser();
        int total = backfillService.stormpathUserConsent();
        return okResult("Done. " + total + " accounts backfilled.");
    }

    public Result dynamoUserConsent() throws Exception {
        checkUser();
        int total = backfillService.dynamoUserConsent();
        return okResult("Done. " + total + " records backfilled.");
    }

    private void checkUser() throws Exception {
        UserSession session = getSession();
        Account account = stormpathClient.getResource(session.getUser().getStormpathHref(), Account.class);
        if (!account.isMemberOfGroup("backfill")) {
            throw new BridgeServiceException(account.getUsername() + " not allowed to perform backfill.", 403);
        }
    }
}

@@ -80,24 +80,71 @@
 eException;%0A
+import org.sagebionetworks.bridge.models.User;%0A
 import org.s
@@ -275,328 +275,110 @@
 t;%0A%0A
-import com.stormpath.sdk.account.Account;%0Aimport com.stormpath.sdk.client.Client;%0A%0Apublic class BackfillController extends BaseController %7B%0A%0A    private Client stormpathClient;%0A%0A    private BackfillService backfillService;%0A%0A    public void setStormpathClient(Client client) %7B%0A        this.stormpathClient = client;%0A    %7D
+public class BackfillController extends BaseController %7B%0A%0A    private BackfillService backfillService;
 %0A%0A  
@@ -1031,144 +1031,76 @@
     
-Account account = stormpathClient.getResource(session.getUser().getStormpathHref(), Account.class);%0A        if (!ac
+User user = session.getUser();%0A        if (!user.getRoles().
 co
-u
 nt
-.isMemberOfGroup
+ains
 (%22ba
@@ -1156,23 +1156,20 @@
 ception(
-account
+user
 .getUser

Remove Stormpath - nice!