diff --git a/config/alfresco/templates/webscripts/org/alfresco/repository/rating/rating.post.json.ftl b/config/alfresco/templates/webscripts/org/alfresco/repository/rating/rating.post.json.ftl index 0e26e23ff6..45eed03611 100644 --- a/config/alfresco/templates/webscripts/org/alfresco/repository/rating/rating.post.json.ftl +++ b/config/alfresco/templates/webscripts/org/alfresco/repository/rating/rating.post.json.ftl @@ -2,7 +2,9 @@ { "data": { - "ratedNodeUrl": "${ratedNode!""}" + "ratedNodeUrl": "${ratedNode!""}", + "rating": ${rating?c}, + "ratingScheme": "${ratingScheme!""}" } } \ No newline at end of file diff --git a/source/java/org/alfresco/repo/web/scripts/rating/RatingPost.java b/source/java/org/alfresco/repo/web/scripts/rating/RatingPost.java index 8b90d6fb20..d180bdfe10 100644 --- a/source/java/org/alfresco/repo/web/scripts/rating/RatingPost.java +++ b/source/java/org/alfresco/repo/web/scripts/rating/RatingPost.java @@ -73,7 +73,7 @@ public class RatingPost extends AbstractRatingWebScript } // Check that the scheme name actually exists - String schemeName = json.getString(RATING_SCHEME); + final String schemeName = json.getString(RATING_SCHEME); RatingScheme scheme = ratingService.getRatingScheme(schemeName); if (scheme == null) { @@ -82,7 +82,7 @@ public class RatingPost extends AbstractRatingWebScript // Range checking of the rating score will be done within the RatingService. // So we can just apply the rating. - int rating = json.getInt(RATING); + final int rating = json.getInt(RATING); ratingService.applyRating(nodeRefToBeRated, rating, schemeName); // We'll return the URL to the ratings of the just-rated node. @@ -90,6 +90,8 @@ public class RatingPost extends AbstractRatingWebScript String ratedNodeUrl = MessageFormat.format(NODE_RATINGS_URL_FORMAT, ratedNodeUrlFragment); model.put(RATED_NODE, ratedNodeUrl); + model.put(RATING, rating); + model.put(RATING_SCHEME, schemeName); } catch (IOException iox) { diff --git a/source/java/org/alfresco/repo/web/scripts/rating/RatingRestApiTest.java b/source/java/org/alfresco/repo/web/scripts/rating/RatingRestApiTest.java index 80efb4cd3f..e09c09ff1d 100644 --- a/source/java/org/alfresco/repo/web/scripts/rating/RatingRestApiTest.java +++ b/source/java/org/alfresco/repo/web/scripts/rating/RatingRestApiTest.java @@ -39,6 +39,12 @@ import org.springframework.extensions.webscripts.TestWebScriptServer.GetRequest; import org.springframework.extensions.webscripts.TestWebScriptServer.PostRequest; import org.springframework.extensions.webscripts.TestWebScriptServer.Response; +/** + * This class tests the ReST API of the {@link RatingService}. + * + * @author Neil McErlean + * @since 3.4 + */ public class RatingRestApiTest extends BaseWebScriptTest { private static final String USER_ONE = "UserOne"; @@ -109,12 +115,8 @@ public class RatingRestApiTest extends BaseWebScriptTest }); } - //TODO test POST out-of-range. - //TODO test GET average - public void testGetRatingSchemeDefinitions() throws Exception { - // May as well return all of them in one call. final int expectedStatus = 200; Response rsp = sendRequest(new GetRequest(GET_RATING_DEFS_URL), expectedStatus); @@ -182,6 +184,8 @@ public class RatingRestApiTest extends BaseWebScriptTest assertNotNull("JSON 'data' object was null", dataObj); String returnedUrl = dataObj.getString("ratedNodeUrl"); assertEquals(ratingUrl, returnedUrl); + assertEquals("fiveStarRatingScheme", dataObj.getString("ratingScheme")); + assertEquals(ratingValue, dataObj.getInt("rating")); // Now GET the ratings via that returned URL rsp = sendRequest(new GetRequest(ratingUrl), 200);