Permalink
Browse files

initial commit

  • Loading branch information...
0 parents commit a1d6d69b656860e4b15e61790ec15135cfd58acf unknown committed Aug 13, 2012
@@ -0,0 +1,10 @@
+*.class
+.project
+.settings/
+.classpath
+target/
+
+# Package Files #
+*.jar
+*.war
+*.ear
@@ -0,0 +1,12 @@
+Rateable
+==========
+
+A simple library to enable Reviewers to rate Reviewables, leveraging best practice modern software engineering techniques
+
+CHANGELOG
+==========
+v 1.0 8/12/12 Initial release
+
+DEPENDENCIES
+==========
+com.visionarysoftwaresolutions:reviewable:1.1
57 pom.xml
@@ -0,0 +1,57 @@
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+ <groupId>com.visionarysoftwaresolutions</groupId>
+ <artifactId>ratable</artifactId>
+ <version>0.0.1-SNAPSHOT</version>
+ <packaging>jar</packaging>
+ <name>Ratable</name>
+ <url>http://www.github.com/leadVisionary/ratable</url>
+ <description>A simple library library for Ratable entities, defined as Objects that can be rated on a rating scale. </description>
+ <inceptionYear>April 2012</inceptionYear>
+ <organization>
+ <name>Visionary Software Solutions</name>
+ <url>http://www.visionarysoftwaresolutions.com</url>
+ </organization>
+ <scm>
+ <url>http://www.github.com/leadVisionary/ratable</url>
+ </scm>
+ <dependencies>
+ <dependency>
+ <groupId>com.visionarysoftwaresolutions</groupId>
+ <artifactId>reviewable</artifactId>
+ <version>1.1</version>
+ </dependency>
+ <dependency>
+ <groupId>org.spockframework</groupId>
+ <artifactId>spock-core</artifactId>
+ <version>0.6-groovy-1.8</version>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+ <distributionManagement>
+ <repository>
+ <id>repo</id>
+ <url>https://github.com/leadVisionary/mvn-repo/raw/master/releases</url>
+ </repository>
+ <snapshotRepository>
+ <id>snapshot-repo</id>
+ <url>https://github.com/leadVisionary/mvn-repo/raw/master/snapshots</url>
+ </snapshotRepository>
+ </distributionManagement>
+ <repositories>
+ <repository>
+ <id>snapshots</id>
+ <url>https://github.com/leadVisionary/mvn-repo/raw/master/snapshots</url>
+ </repository>
+ <repository>
+ <id>releases</id>
+ <url>https://github.com/leadVisionary/mvn-repo/raw/master/releases</url>
+ </repository>
+ </repositories>
+
+ <properties>
+ <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+ </properties>
+</project>
@@ -0,0 +1,32 @@
+package com.visionarysoftwaresolutions.ratable;
+
+import com.visionarysoftwaresolutions.reviewable.Review;
+import com.visionarysoftwaresolutions.reviewable.Reviewable;
+import com.visionarysoftwaresolutions.reviewable.Reviewer;
+
+class BasicReview implements Review{
+
+ private final Rater rater;
+ private final Reviewable reviewed;
+ private final String description;
+
+ BasicReview(Rater r, Reviewable re, String des){
+ rater = r;
+ reviewed= re;
+ description = des;
+ }
+ @Override
+ public String getDescription() {
+ return description;
+ }
+
+ @Override
+ public Reviewer getReviewer() {
+ return rater;
+ }
+
+ @Override
+ public Reviewable getReviewed() {
+ return reviewed;
+ }
+}
@@ -0,0 +1,5 @@
+package com.visionarysoftwaresolutions.ratable;
+
+public enum NoRatingScale {
+ NONE
+}
@@ -0,0 +1,28 @@
+package com.visionarysoftwaresolutions.ratable;
+
+import com.visionarysoftwaresolutions.reviewable.ReviewDecorator;
+import com.visionarysoftwaresolutions.reviewable.Reviewable;
+
+/**
+ *
+ * @author Nicholas Vaidyanathan, Lead Visionary of Visionary Software Solutions
+ * @description RatedReview is a simple interface for a review that an entity that
+ * reviews other entities on a scale.
+ * We try to make it as generalizable as possible so it can apply in multiple situations
+ * Scenario: A Reviewer creates a RatedReview for a Reviewable with a description, Rating it on a RatingScale
+ * Example: Nick creates a RatedReview of YourBody
+ * with a RatingScale of OneToTenRatingScale
+ * with a rating of 10 and a description "It's awesome!"
+ */
+public class RatedReview extends ReviewDecorator {
+ private Enum<?> rating;
+
+ public RatedReview(Rater rater, Reviewable toReview, String description, Enum<?> rating) {
+ super(new BasicReview(rater, toReview, description));
+ this.rating = rating;
+ }
+
+ public String getRating(){
+ return rating.name();
+ }
+}
@@ -0,0 +1,20 @@
+package com.visionarysoftwaresolutions.ratable;
+
+import com.visionarysoftwaresolutions.reviewable.Review;
+import com.visionarysoftwaresolutions.reviewable.Reviewable;
+import com.visionarysoftwaresolutions.reviewable.Reviewer;
+
+public abstract class Rater implements Reviewer {
+ @Override
+ public Review review(Reviewable toReview, String description){
+ return rate(toReview, description, null);
+ }
+
+ public RatedReview rate(Reviewable toRate, String description, Enum<?> rating){
+ return review(toRate, description,rating);
+ }
+
+ public RatedReview review(Reviewable toRate, String description, Enum<?> rating){
+ return new RatingFactory().create(this, toRate, description, rating);
+ }
+}
@@ -0,0 +1,18 @@
+package com.visionarysoftwaresolutions.ratable;
+
+import com.visionarysoftwaresolutions.reviewable.Review;
+import com.visionarysoftwaresolutions.reviewable.ReviewFactory;
+import com.visionarysoftwaresolutions.reviewable.Reviewable;
+import com.visionarysoftwaresolutions.reviewable.Reviewer;
+
+public class RatingFactory implements ReviewFactory {
+
+ @Override
+ public Review create(Reviewer reviewer, Reviewable toReview, String description) {
+ return create((Rater)reviewer, toReview, description,NoRatingScale.NONE);
+ }
+
+ public RatedReview create(Rater rat, Reviewable toReview, String description, Enum<?> rating){
+ return new RatedReview(rat, toReview, description, rating);
+ }
+}
@@ -0,0 +1,15 @@
+package com.visionarysoftwaresolutions.ratable
+
+import com.visionarysoftwaresolutions.ratable.Rater
+import com.visionarysoftwaresolutions.reviewable.Review;
+import com.visionarysoftwaresolutions.reviewable.Reviewable
+import com.visionarysoftwaresolutions.reviewable.Reviewer;
+
+class Beer implements Reviewable {
+ String name
+ Review rev
+ @Override
+ public Review getReview(Reviewer reviewer) {
+ rev
+ }
+}
@@ -0,0 +1,15 @@
+package com.visionarysoftwaresolutions.ratable;
+
+public enum FiveStarRatingScale {
+ ONE("1"),
+ TWO("2"),
+ THREE("3"),
+ FOUR("4"),
+ FIVE("5")
+
+ private final String value
+
+ FiveStarRatingScale(String val){
+ this.value = val
+ }
+}
@@ -0,0 +1,12 @@
+package com.visionarysoftwaresolutions.ratable;
+
+import com.visionarysoftwaresolutions.ratable.RatedReview;
+import com.visionarysoftwaresolutions.ratable.Rater;
+import com.visionarysoftwaresolutions.reviewable.Reviewable;
+import com.visionarysoftwaresolutions.reviewable.Reviewer;
+
+public class RatedFoodReview extends RatedReview {
+ private Rater rev
+ private Reviewable view
+ private String description
+ }
@@ -0,0 +1,52 @@
+package com.visionarysoftwaresolutions.ratable
+
+import com.visionarysoftwaresolutions.reviewable.Review
+import com.visionarysoftwaresolutions.reviewable.Reviewable;
+
+
+class RatingSpec extends spock.lang.Specification {
+ Rater nick
+ Reviewable food
+
+ public void setup(){
+ given: "we have a user named nick"
+ nick = new User("nick")
+ and: "some beer named Guinness"
+ food = new Beer(name:"Guinness")
+ }
+
+ def "when no rating is given, a review can still be made"(){
+ when: "I try to have a rater review a reviewable"
+ Review result = nick.review(food, "delicious")
+ then: "the review should be saved"
+ result.description == "delicious"
+ and: "the reviewer should be nick"
+ result.reviewer == nick
+ and: "the reviewed should be beer"
+ result.reviewed == food
+ }
+
+ def "default reviews from factories should not be rated"(){
+ when: "we create a review from the factory"
+ def result = new RatingFactory().create(nick, food, "no taste")
+ and: "we try to make a rating from it"
+ def rated = (RatedReview) result
+ then: "it should have no rating set"
+ rated.rating == NoRatingScale.NONE.toString()
+ }
+
+ def "can make a rated review"(){
+ when: "I have the Reviewer rate the Reviewable"
+ RatedReview result = nick.rate(food,
+ "It is so creamy and delicious!",
+ FiveStarRatingScale.FIVE);
+ then: "it has nick as the reviewer"
+ result.reviewer == nick
+ and: "guiness as the food"
+ result.reviewed == food
+ and:"creamy and delicious as the description"
+ result.description == "It is so creamy and delicious!"
+ and: "it is rated"
+ result.rating == FiveStarRatingScale.FIVE.toString()
+ }
+}
@@ -0,0 +1,11 @@
+package com.visionarysoftwaresolutions.ratable;
+
+import com.visionarysoftwaresolutions.ratable.Rater;
+
+class User extends Rater {
+ public final String name;
+
+ public User(String string) {
+ name = string;
+ }
+}

0 comments on commit a1d6d69

Please sign in to comment.