diff options
author | Jesse Morgan <jesse@jesterpm.net> | 2013-10-01 22:21:19 -0700 |
---|---|---|
committer | Jesse Morgan <jesse@jesterpm.net> | 2013-10-01 22:21:19 -0700 |
commit | eed876b36366196eb405b1fc840a939fb6fa054c (patch) | |
tree | 6386de4d0e75f90b660447f13b841f8494b7898f /src/com | |
parent | 13fe4388c758d6272327e1ca086df29ef78e32a1 (diff) |
Adding message banner20131001a
Diffstat (limited to 'src/com')
-rw-r--r-- | src/com/p4square/grow/backend/GrowBackend.java | 3 | ||||
-rw-r--r-- | src/com/p4square/grow/backend/resources/BannerResource.java | 66 |
2 files changed, 69 insertions, 0 deletions
diff --git a/src/com/p4square/grow/backend/GrowBackend.java b/src/com/p4square/grow/backend/GrowBackend.java index 7da6fff..533cf09 100644 --- a/src/com/p4square/grow/backend/GrowBackend.java +++ b/src/com/p4square/grow/backend/GrowBackend.java @@ -17,6 +17,7 @@ import com.p4square.grow.config.Config; import com.p4square.grow.backend.db.CassandraDatabase; import com.p4square.grow.backend.resources.AccountResource; +import com.p4square.grow.backend.resources.BannerResource; import com.p4square.grow.backend.resources.SurveyResource; import com.p4square.grow.backend.resources.SurveyResultsResource; import com.p4square.grow.backend.resources.TrainingRecordResource; @@ -64,6 +65,8 @@ public class GrowBackend extends Application { router.attach("/accounts/{userId}/training/videos/{videoId}", TrainingRecordResource.class); + // Misc. + router.attach("/banner", BannerResource.class); return router; } diff --git a/src/com/p4square/grow/backend/resources/BannerResource.java b/src/com/p4square/grow/backend/resources/BannerResource.java new file mode 100644 index 0000000..4551777 --- /dev/null +++ b/src/com/p4square/grow/backend/resources/BannerResource.java @@ -0,0 +1,66 @@ +/* + * Copyright 2013 Jesse Morgan + */ + +package com.p4square.grow.backend.resources; + +import java.io.IOException; + +import org.restlet.data.Status; +import org.restlet.resource.ServerResource; +import org.restlet.representation.Representation; +import org.restlet.representation.StringRepresentation; + +import org.apache.log4j.Logger; + +import com.p4square.grow.backend.GrowBackend; +import com.p4square.grow.backend.db.CassandraDatabase; + +/** + * Fetches or sets the banner string. + * + * @author Jesse Morgan <jesse@jesterpm.net> + */ +public class BannerResource extends ServerResource { + private static final Logger LOG = Logger.getLogger(BannerResource.class); + + private CassandraDatabase mDb; + + @Override + public void doInit() { + super.doInit(); + + final GrowBackend backend = (GrowBackend) getApplication(); + mDb = backend.getDatabase(); + } + + /** + * Handle GET Requests. + */ + @Override + protected Representation get() { + String result = mDb.getKey("strings", "banner"); + + if (result == null || result.length() == 0) { + result = "{}"; + } + + return new StringRepresentation(result); + } + + /** + * Handle PUT requests + */ + @Override + protected Representation put(Representation entity) { + try { + mDb.putKey("strings", "banner", entity.getText()); + setStatus(Status.SUCCESS_NO_CONTENT); + + } catch (IOException e) { + setStatus(Status.SERVER_ERROR_INTERNAL); + } + + return null; + } +} |