RatingService.

Added rating, ratingScheme to the POST response.


git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@21090 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Neil McErlean
2010-07-12 12:17:30 +00:00
parent 83bb722d2e
commit f156a4f4b5
3 changed files with 15 additions and 7 deletions

View File

@@ -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)
{

View File

@@ -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);