From 55cba1e0f3373fa69d3b9a66f455ad36ab4b82cf Mon Sep 17 00:00:00 2001 From: Jesse Morgan Date: Sun, 20 Mar 2016 17:07:26 -0700 Subject: Adding support for Church Community Builder login. Beginning with this change all of the Church Management System integration logic is moving into implementations of the new IntegrationDriver interface. The desired IntegrationDriver can be selected by setting the integrationDriver config to the appropriate class name. This commit is only moving login support. Progress reporting will move in a later commit. --- src/com/p4square/grow/frontend/ChapterCompletePage.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'src/com/p4square/grow/frontend/ChapterCompletePage.java') diff --git a/src/com/p4square/grow/frontend/ChapterCompletePage.java b/src/com/p4square/grow/frontend/ChapterCompletePage.java index f07a870..2dd1ecf 100644 --- a/src/com/p4square/grow/frontend/ChapterCompletePage.java +++ b/src/com/p4square/grow/frontend/ChapterCompletePage.java @@ -7,6 +7,7 @@ package com.p4square.grow.frontend; import java.util.Date; import java.util.Map; +import com.p4square.f1oauth.FellowshipOneIntegrationDriver; import freemarker.template.Template; import org.restlet.data.MediaType; @@ -172,7 +173,8 @@ public class ChapterCompletePage extends FreeMarkerPageResource { Attribute attribute = new Attribute(attributeName); attribute.setStartDate(new Date()); - F1API f1 = mGrowFrontend.getF1Access().getAuthenticatedApi(user); + F1API f1 = ((FellowshipOneIntegrationDriver) mGrowFrontend.getThirdPartyIntegrationFactory()) + .getF1Access().getAuthenticatedApi(user); if (!f1.addAttribute(user.getIdentifier(), attribute)) { LOG.error("addAttribute failed for " + user.getIdentifier() + " with attribute " + attributeName); -- cgit v1.2.3 From 6698ffbb300ff8e48b5f3fe59144c699d39ab094 Mon Sep 17 00:00:00 2001 From: Jesse Morgan Date: Tue, 22 Mar 2016 21:42:03 -0700 Subject: Integrating the ProgressReporter Using the new ProgressReporter interface in AssessmentResultsPage and ChapterCompletePage. --- .../f1oauth/FellowshipOneIntegrationDriver.java | 10 +++++++ src/com/p4square/grow/ccb/CCBProgressReporter.java | 32 ++++++++++++++++++++++ .../ChurchCommunityBuilderIntegrationDriver.java | 10 +++++++ .../grow/frontend/AssessmentResultsPage.java | 32 ++++++++-------------- .../grow/frontend/ChapterCompletePage.java | 27 ++++-------------- .../p4square/grow/frontend/IntegrationDriver.java | 9 ++++++ .../p4square/grow/frontend/ProgressReporter.java | 5 ++-- 7 files changed, 80 insertions(+), 45 deletions(-) create mode 100644 src/com/p4square/grow/ccb/CCBProgressReporter.java (limited to 'src/com/p4square/grow/frontend/ChapterCompletePage.java') diff --git a/src/com/p4square/f1oauth/FellowshipOneIntegrationDriver.java b/src/com/p4square/f1oauth/FellowshipOneIntegrationDriver.java index e72df5e..865f5d6 100644 --- a/src/com/p4square/f1oauth/FellowshipOneIntegrationDriver.java +++ b/src/com/p4square/f1oauth/FellowshipOneIntegrationDriver.java @@ -3,6 +3,7 @@ package com.p4square.f1oauth; import com.codahale.metrics.MetricRegistry; import com.p4square.grow.config.Config; import com.p4square.grow.frontend.IntegrationDriver; +import com.p4square.grow.frontend.ProgressReporter; import org.restlet.Context; import org.restlet.security.Verifier; @@ -17,6 +18,8 @@ public class FellowshipOneIntegrationDriver implements IntegrationDriver { private final Config mConfig; private final F1Access mAPI; + private final ProgressReporter mProgressReporter; + public FellowshipOneIntegrationDriver(final Context context) { mContext = context; mConfig = (Config) context.getAttributes().get("com.p4square.grow.config"); @@ -29,6 +32,8 @@ public class FellowshipOneIntegrationDriver implements IntegrationDriver { mConfig.getString("f1ChurchCode", "pfseawa"), F1Access.UserType.WEBLINK); mAPI.setMetricRegistry(mMetricRegistry); + + mProgressReporter = new F1ProgressReporter(mAPI); } /** @@ -42,4 +47,9 @@ public class FellowshipOneIntegrationDriver implements IntegrationDriver { public Verifier newUserAuthenticationVerifier() { return new SecondPartyVerifier(mContext, mAPI); } + + @Override + public ProgressReporter getProgressReporter() { + return mProgressReporter; + } } diff --git a/src/com/p4square/grow/ccb/CCBProgressReporter.java b/src/com/p4square/grow/ccb/CCBProgressReporter.java new file mode 100644 index 0000000..e2304fe --- /dev/null +++ b/src/com/p4square/grow/ccb/CCBProgressReporter.java @@ -0,0 +1,32 @@ +package com.p4square.grow.ccb; + +import com.p4square.ccbapi.CCBAPI; +import com.p4square.grow.frontend.ProgressReporter; +import org.restlet.security.User; + +import java.util.Date; + +/** + * A ProgressReporter which records progress in CCB. + * + * Except not really, because it's not implemented yet. + * This is just a placeholder until ccb-api-client-java has support for updating an individual. + */ +public class CCBProgressReporter implements ProgressReporter { + + private final CCBAPI mAPI; + + public CCBProgressReporter(final CCBAPI api) { + mAPI = api; + } + + @Override + public void reportAssessmentComplete(User user, String level, Date date, String results) { + // TODO + } + + @Override + public void reportChapterComplete(User user, String chapter, Date date) { + // TODO + } +} diff --git a/src/com/p4square/grow/ccb/ChurchCommunityBuilderIntegrationDriver.java b/src/com/p4square/grow/ccb/ChurchCommunityBuilderIntegrationDriver.java index 3aeca2c..48d143c 100644 --- a/src/com/p4square/grow/ccb/ChurchCommunityBuilderIntegrationDriver.java +++ b/src/com/p4square/grow/ccb/ChurchCommunityBuilderIntegrationDriver.java @@ -5,6 +5,7 @@ import com.p4square.ccbapi.CCBAPI; import com.p4square.ccbapi.CCBAPIClient; import com.p4square.grow.config.Config; import com.p4square.grow.frontend.IntegrationDriver; +import com.p4square.grow.frontend.ProgressReporter; import org.restlet.Context; import org.restlet.security.Verifier; @@ -22,6 +23,8 @@ public class ChurchCommunityBuilderIntegrationDriver implements IntegrationDrive private final CCBAPI mAPI; + private final CCBProgressReporter mProgressReporter; + public ChurchCommunityBuilderIntegrationDriver(final Context context) { mContext = context; mConfig = (Config) context.getAttributes().get("com.p4square.grow.config"); @@ -38,6 +41,8 @@ public class ChurchCommunityBuilderIntegrationDriver implements IntegrationDrive mAPI = api; + mProgressReporter = new CCBProgressReporter(mAPI); + } catch (URISyntaxException e) { throw new RuntimeException(e); } @@ -47,4 +52,9 @@ public class ChurchCommunityBuilderIntegrationDriver implements IntegrationDrive public Verifier newUserAuthenticationVerifier() { return new CCBUserVerifier(mAPI); } + + @Override + public ProgressReporter getProgressReporter() { + return mProgressReporter; + } } diff --git a/src/com/p4square/grow/frontend/AssessmentResultsPage.java b/src/com/p4square/grow/frontend/AssessmentResultsPage.java index 9b66794..f1c924b 100644 --- a/src/com/p4square/grow/frontend/AssessmentResultsPage.java +++ b/src/com/p4square/grow/frontend/AssessmentResultsPage.java @@ -7,6 +7,7 @@ package com.p4square.grow.frontend; import java.util.Date; import java.util.Map; +import com.fasterxml.jackson.core.JsonProcessingException; import com.p4square.f1oauth.FellowshipOneIntegrationDriver; import freemarker.template.Template; @@ -30,6 +31,7 @@ import com.p4square.f1oauth.F1User; import com.p4square.grow.config.Config; import com.p4square.grow.provider.JsonEncodedProvider; +import org.restlet.security.User; /** * This page fetches the user's final score and displays the transitional page between @@ -103,30 +105,18 @@ public class AssessmentResultsPage extends FreeMarkerPageResource { } private void publishScoreInF1(Map results) { - if (!(getRequest().getClientInfo().getUser() instanceof F1User)) { - // Only useful if the user is from F1. - return; - } + final ProgressReporter reporter = mGrowFrontend.getThirdPartyIntegrationFactory().getProgressReporter(); - F1User user = (F1User) getRequest().getClientInfo().getUser(); + try { + final User user = getRequest().getClientInfo().getUser(); + final String level = results.get("result").toString(); + final Date completionDate = new Date(); + final String data = JsonEncodedProvider.MAPPER.writeValueAsString(results); - // Update the attribute. - String attributeName = "Assessment Complete - " + results.get("result"); + reporter.reportAssessmentComplete(user, level, completionDate, data); - try { - Attribute attribute = new Attribute(attributeName); - attribute.setStartDate(new Date()); - attribute.setComment(JsonEncodedProvider.MAPPER.writeValueAsString(results)); - - F1API f1 = ((FellowshipOneIntegrationDriver) mGrowFrontend.getThirdPartyIntegrationFactory()) - .getF1Access().getAuthenticatedApi(user); - if (!f1.addAttribute(user.getIdentifier(), attribute)) { - LOG.error("addAttribute failed for " + user.getIdentifier() - + " with attribute " + attributeName); - } - } catch (Exception e) { - LOG.error("addAttribute failed for " + user.getIdentifier() - + " with attribute " + attributeName, e); + } catch (JsonProcessingException e) { + LOG.error("Failed to generate json " + e.getMessage(), e); } } diff --git a/src/com/p4square/grow/frontend/ChapterCompletePage.java b/src/com/p4square/grow/frontend/ChapterCompletePage.java index 2dd1ecf..35abc43 100644 --- a/src/com/p4square/grow/frontend/ChapterCompletePage.java +++ b/src/com/p4square/grow/frontend/ChapterCompletePage.java @@ -32,6 +32,7 @@ import com.p4square.grow.config.Config; import com.p4square.grow.model.TrainingRecord; import com.p4square.grow.provider.Provider; import com.p4square.grow.provider.TrainingRecordProvider; +import org.restlet.security.User; /** * This resource displays the transitional page between chapters. @@ -159,30 +160,12 @@ public class ChapterCompletePage extends FreeMarkerPageResource { } private void assignAttribute() { - if (!(getRequest().getClientInfo().getUser() instanceof F1User)) { - // Only useful if the user is from F1. - return; - } - - F1User user = (F1User) getRequest().getClientInfo().getUser(); + final ProgressReporter reporter = mGrowFrontend.getThirdPartyIntegrationFactory().getProgressReporter(); - // Update the attribute. - String attributeName = "Training Complete - " + mChapter; + final User user = getRequest().getClientInfo().getUser(); + final Date completionDate = new Date(); - try { - Attribute attribute = new Attribute(attributeName); - attribute.setStartDate(new Date()); - - F1API f1 = ((FellowshipOneIntegrationDriver) mGrowFrontend.getThirdPartyIntegrationFactory()) - .getF1Access().getAuthenticatedApi(user); - if (!f1.addAttribute(user.getIdentifier(), attribute)) { - LOG.error("addAttribute failed for " + user.getIdentifier() - + " with attribute " + attributeName); - } - } catch (Exception e) { - LOG.error("addAttribute failed for " + user.getIdentifier() - + " with attribute " + attributeName, e); - } + reporter.reportChapterComplete(user, mChapter, completionDate); } /** diff --git a/src/com/p4square/grow/frontend/IntegrationDriver.java b/src/com/p4square/grow/frontend/IntegrationDriver.java index 3370116..b9c3508 100644 --- a/src/com/p4square/grow/frontend/IntegrationDriver.java +++ b/src/com/p4square/grow/frontend/IntegrationDriver.java @@ -14,4 +14,13 @@ public interface IntegrationDriver { * @return A Verifier. */ Verifier newUserAuthenticationVerifier(); + + /** + * Return a ProgressReporter for this Church Management System. + * + * The ProgressReporter should be thread-safe. + * + * @return The ProgressReporter. + */ + ProgressReporter getProgressReporter(); } diff --git a/src/com/p4square/grow/frontend/ProgressReporter.java b/src/com/p4square/grow/frontend/ProgressReporter.java index 9b57ff4..2f36832 100644 --- a/src/com/p4square/grow/frontend/ProgressReporter.java +++ b/src/com/p4square/grow/frontend/ProgressReporter.java @@ -20,10 +20,11 @@ public interface ProgressReporter { void reportAssessmentComplete(User user, String level, Date date, String results); /** + * Report that the User completed the chapter. * * @param user The user who completed the chapter. - * @param chapter The chatper completed. - * @param date Teh completion date. + * @param chapter The chapter completed. + * @param date The completion date. */ void reportChapterComplete(User user, String chapter, Date date); } -- cgit v1.2.3