Skip to content

Commit

Permalink
Merge pull request #22 from SRGSSR/develop
Browse files Browse the repository at this point in the history
Fix user id query parameter
  • Loading branch information
StaehliJ authored Apr 1, 2019
2 parents 68ee4ca + 99338b9 commit 5d7ba14
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 8 deletions.
4 changes: 2 additions & 2 deletions docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ A wide list of parameters are available.

#### Personnal recommendation for a user

* `/api/v2/playlist/recommendation/personalRecommendation` : get media list object.
* `user` (optional, string): `UserId` to use for a personal recommendation.
* `/api/v2/playlist/personalRecommendation` : get media list object.
* `userId` (optional, string): `UserId` to use for a personal recommendation.
* Returns a `recommendedList` object.

## Private APIs
Expand Down
16 changes: 12 additions & 4 deletions docs/RECOMMENDATION.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@ Since July 2018, Play Android (2.0.207 and more) and Play iOS (2.8.3-272 and mor

## Recommendation type

### Media ecommendation list for a media
### Media recommendation list for a media

The API doesn't not support paginations, so mobile applications didn't implement pagination. The media recommendation list must have at least 49 items, the 50th is the requested media.
The API doesn't not support paginations, therefore mobile applications didn't implement pagination. The media recommendation list must have at least 49 items, the 50th is the requested media.

#### RTS `urn.contains(":rts:")`

- For videos `urn.contains(":video:")`, ask Peach recommendation `continuous_playback_mobile` service.
- For audios `urn.contains(":audio:")`, Playfff recommendation. Based on IL requests, without personalization. Here is how it works:
- For videos `urn.contains(":video:")`, it asks Peach recommendation `continuous_playback_mobile` service.
- For audios `urn.contains(":audio:")`, it asks Playfff recommendation. Based on IL requests, without personalization. Here is how it works:
- Get `IL-Media`. It returns an empty list if it's a `LIVESTREAM` or a `SCHEDULED_LIVESTREAM`.
- Get `IL-EpisodeComposition` with last 100 episodes. Sort episodes with a date ascending order.
- Determine if the media is a full length or a clip.
Expand All @@ -33,6 +33,14 @@ The API doesn't not support paginations, so mobile applications didn't implement
#### Other BUs

- No recommendation provided. It returns an empty list.

### Media recommendation list for a user

The API doesn't not support paginations, therefore mobile applications didn't implement pagination. The media recommendation list must have at least 50 items.

#### RTS

- With and without an `userId`, it asks Peach recommendation `play_home_personal_rec` service.

## License

Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

<groupId>com.example</groupId>
<artifactId>pfff</artifactId>
<version>9</version>
<version>10</version>
<packaging>jar</packaging>

<name>pfff</name>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ private RecommendedList getRecommendationList(@PathVariable("purpose") String pu
@ResponseBody
RecommendedList personalRecommendation(
HttpServletRequest request,
@RequestParam(value = "user", required = false, defaultValue = "unknown") String userId) {
@RequestParam(value = "userId", required = false, defaultValue = "unknown") String userId) {
return service.rtsPlayHomePersonalRecommendation(userId);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package com.example.pfff.controller;

import com.example.pfff.model.RecommendedList;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
Expand All @@ -15,7 +17,9 @@
import org.springframework.web.client.RestTemplate;
import org.springframework.web.context.WebApplicationContext;

import java.io.IOException;
import java.util.List;
import java.util.concurrent.atomic.AtomicReference;

import static org.springframework.security.test.web.servlet.setup.SecurityMockMvcConfigurers.springSecurity;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
Expand Down Expand Up @@ -142,4 +146,26 @@ private void getRecommendationURNFormat(String mediaURN, boolean isAvailable) th
mvc.perform(get("/api/v2/playlist/recommendation/" + purpose + "/" + mediaURN).param("standalone", "true")).andExpect(isAvailable ? jsonPath("$.recommendationId").isNotEmpty() : jsonPath("$.recommendationId").doesNotExist());

}

@Test
public void getRTSPersonalRecommendation() throws Exception {
AtomicReference<RecommendedList> anonymousRecommendedListReference = new AtomicReference<>();
mvc.perform(get("/api/v2/playlist/personalRecommendation")).andExpect(status().isOk()).andExpect(jsonPath("$").isMap()).andExpect(jsonPath("$.recommendationId").isNotEmpty()).andExpect(jsonPath("$.recommendationId").isNotEmpty()).andDo(mvcResult -> {
String json = mvcResult.getResponse().getContentAsString();
RecommendedList anonymousRecommendedList = (RecommendedList) convertJSONStringToObject(json, RecommendedList.class);
anonymousRecommendedListReference.set(anonymousRecommendedList);
});;
mvc.perform(get("/api/v2/playlist/personalRecommendation").param("userId", "203656")).andExpect(status().isOk()).andExpect(jsonPath("$").isMap()).andExpect(jsonPath("$.recommendationId").isNotEmpty()).andExpect(jsonPath("$.title").isNotEmpty()).andDo(mvcResult -> {
String json = mvcResult.getResponse().getContentAsString();
RecommendedList userRecommendedList = (RecommendedList) convertJSONStringToObject(json, RecommendedList.class);

Assert.assertNotEquals(anonymousRecommendedListReference.get().getRecommendationId(), userRecommendedList.getRecommendationId());
Assert.assertNotEquals(anonymousRecommendedListReference.get().getTitle(), userRecommendedList.getTitle());
});
}

public static <T> Object convertJSONStringToObject(String json, Class<T> objectClass) throws IOException {
ObjectMapper mapper = new ObjectMapper();
return mapper.readValue(json, objectClass);
}
}

0 comments on commit 5d7ba14

Please sign in to comment.