Skip to content

Commit

Permalink
Merge pull request #54 from SRGSSR/develop
Browse files Browse the repository at this point in the history
Empty recommendation release
  • Loading branch information
pyby authored Feb 5, 2021
2 parents fa686ea + 20c585f commit 92b2e02
Show file tree
Hide file tree
Showing 10 changed files with 38 additions and 25 deletions.
6 changes: 0 additions & 6 deletions .travis.yml

This file was deleted.

7 changes: 4 additions & 3 deletions docs/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[![SRG Logger logo](README-images/logo.png)](https://github.com/SRGSSR/pfff)

[![Build Status](https://travis-ci.org/SRGSSR/pfff.svg?branch=master)](https://travis-ci.org/SRGSSR/pfff) [![GitHub release (latest by date)](https://img.shields.io/github/v/release/SRGSSR/pfff)](https://github.com/SRGSSR/pfff/releases) [![GitHub license](https://img.shields.io/github/license/SRGSSR/pfff)](https://github.com/SRGSSR/pfff/blob/master/LICENSE)
[![GitHub release (latest by date)](https://img.shields.io/github/v/release/SRGSSR/pfff)](https://github.com/SRGSSR/pfff/releases) [![GitHub license](https://img.shields.io/github/license/SRGSSR/pfff)](https://github.com/SRGSSR/pfff/blob/master/LICENSE)


## About
Expand All @@ -23,14 +23,15 @@ A wide list of parameters are available.
* `PFFF_USER` (optional, string): A user login to admin service.
* `PFFF_PASSWORD` (optional, string): A user password to admin service.
* `DEEP_LINK_REFRESH_DELAY_MS` (optional, integer): Scheduled fixed delay before refreshing the deep link script cache. If not set, defaults is `300000`.
* `DEEP_LINK_REFRESH_INITIAL_DELAY_MS` (optional, integer): Scheduled fixed initial delay before refreshing the deep link script cache. If not set, defaults is `0`.
* `MAX_DEEP_LINK_REPORTS` (optional, integer): Maximum number of deep link reports in the database. If not set, defaults is `2500`.
* `DEEP_LINK_ENVIRONMENTS` (optional, string, multiple): List of `Environment`s to pull deep link dynamic informations. If not set, defaults is `PROD`.
* `UPDATE_CHECK_DISABLED` (optional, boolean): Disable checking if a recommended or required update is available, if set to `true`. If not set, defaults is `false`.

## API
* `urn` (string): an unique identifier.
* `recommendedList` (object): a recommended result list with proterties:
* `recommendationId` (string): the recommendation identifer from the service.
* `recommendationId` (string, optional): the recommendation identifer from the service.
* `urns` (array): array of `urn`.
* `title` (string, optional): title of the playlist.
* `package` (string): Android package name or iOS bundle identifier.
Expand Down Expand Up @@ -74,7 +75,7 @@ A wide list of parameters are available.
* *Deprecated* `/api/v1/playlist/recommendation/continuousPlayback/{urn}` : get recommended medias for a continuous playback purpose. * `standalone` (optional, boolean): Recommendation for the playback mode. Default is `false`.
* `format` (optional, string): If set to `urn`, it returns an URN list. Default is `media` and redirects to an IL media list response.

More informations about the [recommendation engine](RECOMMENDATION.md) is available.
All those media recommendation APIs return the requested media at the first position in the list in order to create a playlist, unless the recommended list is empty. For more informations, see the [recommendation engine documentation](RECOMMENDATION.md).

#### Personnal recommendation for a user

Expand Down
2 changes: 1 addition & 1 deletion docs/RECOMMENDATION.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ Since July 2018, Play Android (2.0.207 and more) and Play iOS (2.8.3-272 and mor

## Media recommendation list for a 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.
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, put on the first position of the list. If there is no recommended media, the returned list is empty.

### Purposes

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>ch.srgssr</groupId>
<artifactId>playfff</artifactId>
<version>30</version>
<version>31</version>
<packaging>jar</packaging>

<name>pfff</name>
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/ch/srgssr/playfff/config/DeeplinkConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public class DeeplinkConfig {
@Autowired
private DeepLinkReportService deepLinkReportService;

@Scheduled(fixedDelayString = "${DEEP_LINK_REFRESH_DELAY_MS:300000}")
@Scheduled(fixedDelayString = "${DEEP_LINK_REFRESH_DELAY_MS:300000}", initialDelayString = "${DEEP_LINK_REFRESH_INITIAL_DELAY_MS:0}")
public void DeepLinkRefresh() {
deepLinkService.refreshParsePlayUrlJSContent();
deepLinkReportService.purgeOlderReports();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,9 @@ RecommendedList recommendationV2(

private RecommendedList getRecommendationList(@PathVariable("purpose") String purpose, @PathVariable("urn") String urn, @RequestParam(value = "standalone", required = false, defaultValue = "false") boolean standalone) {
RecommendedList recommendedList = service.getRecommendedUrns(purpose, urn, standalone);
recommendedList.addUrn(0, urn);
if (recommendedList.getUrns().size() > 0) {
recommendedList.addUrn(0, urn);
}
return recommendedList;
}

Expand Down
25 changes: 19 additions & 6 deletions src/main/java/ch/srgssr/playfff/service/RecommendationService.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
import ch.srgssr.playfff.model.RecommendedList;
import ch.srgssr.playfff.model.peach.PersonalRecommendationResult;
import ch.srgssr.playfff.model.peach.RecommendationResult;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpMethod;
import org.springframework.stereotype.Service;
Expand All @@ -23,6 +25,7 @@

@Service
public class RecommendationService {
private static final Logger logger = LoggerFactory.getLogger(RecommendationService.class);

@Autowired
private IntegrationLayerRequest integrationLayerRequest;
Expand Down Expand Up @@ -196,9 +199,14 @@ private RecommendedList rtsVideoRecommendedList(String purpose, String urn, bool

System.out.println(url.toUriString());

RecommendationResult recommendationResult = restTemplate
.exchange(url.toUriString(), HttpMethod.GET, null, RecommendationResult.class).getBody();
return new RecommendedList(url.getHost(), recommendationResult.getRecommendationId(), recommendationResult.getUrns());
try {
RecommendationResult recommendationResult = restTemplate
.exchange(url.toUriString(), HttpMethod.GET, null, RecommendationResult.class).getBody();
return new RecommendedList(url.getHost(), recommendationResult.getRecommendationId(), recommendationResult.getUrns());
} catch (Exception e) {
logger.warn("{} : {}", url.toUriString(), e.getMessage());
return new RecommendedList();
}
}

public RecommendedList rtsPlayHomePersonalRecommendation(String userId) {
Expand All @@ -209,10 +217,15 @@ public RecommendedList rtsPlayHomePersonalRecommendation(String userId) {

System.out.println(url.toUriString());

PersonalRecommendationResult result = restTemplate
.exchange(url.toUriString(), HttpMethod.GET, null, PersonalRecommendationResult.class).getBody();
try {
PersonalRecommendationResult result = restTemplate
.exchange(url.toUriString(), HttpMethod.GET, null, PersonalRecommendationResult.class).getBody();

return new RecommendedList(result.getTitle(), url.getHost(), result.getRecommendationId(), result.getUrns());
return new RecommendedList(result.getTitle(), url.getHost(), result.getRecommendationId(), result.getUrns());
} catch (Exception e) {
logger.warn("{} : {}", url.toUriString(), e.getMessage());
return new RecommendedList();
}
}

private RecommendedList srfRecommendedList(String purpose, String urn, boolean standalone) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,17 +159,17 @@ private void getRecommendationURNFormat(String mediaURN, boolean isAvailable) th
mvc.perform(get("/api/v1/playlist/recommendation/" + purpose + "/" + mediaURN).param("standalone", "false").param("format", format)).andExpect(status().isOk()).andExpect(jsonPath("$").isArray());
mvc.perform(get("/api/v1/playlist/recommendation/" + purpose + "/" + mediaURN).param("standalone", "true").param("format", format)).andExpect(status().isOk()).andExpect(jsonPath("$").isArray());

mvc.perform(get("/api/v1/playlist/recommendation/" + purpose + "/" + mediaURN).param("format", format)).andExpect(status().isOk()).andExpect(jsonPath("$[0]").value(mediaURN));
mvc.perform(get("/api/v1/playlist/recommendation/" + purpose + "/" + mediaURN).param("standalone", "false").param("format", format)).andExpect(jsonPath("$[0]").value(mediaURN));
mvc.perform(get("/api/v1/playlist/recommendation/" + purpose + "/" + mediaURN).param("standalone", "true").param("format", format)).andExpect(jsonPath("$[0]").value(mediaURN));
mvc.perform(get("/api/v1/playlist/recommendation/" + purpose + "/" + mediaURN).param("format", format)).andExpect(status().isOk()).andExpect(isAvailable ? jsonPath("$[0]").value(mediaURN) : jsonPath("$").isEmpty());
mvc.perform(get("/api/v1/playlist/recommendation/" + purpose + "/" + mediaURN).param("standalone", "false").param("format", format)).andExpect(isAvailable ? jsonPath("$[0]").value(mediaURN) : jsonPath("$").isEmpty());
mvc.perform(get("/api/v1/playlist/recommendation/" + purpose + "/" + mediaURN).param("standalone", "true").param("format", format)).andExpect(isAvailable ? jsonPath("$[0]").value(mediaURN) : jsonPath("$").isEmpty());

mvc.perform(get("/api/v2/playlist/recommendation/" + purpose + "/" + mediaURN)).andExpect(status().isOk()).andExpect(jsonPath("$").isMap());
mvc.perform(get("/api/v2/playlist/recommendation/" + purpose + "/" + mediaURN).param("standalone", "false")).andExpect(status().isOk()).andExpect(jsonPath("$").isMap());
mvc.perform(get("/api/v2/playlist/recommendation/" + purpose + "/" + mediaURN).param("standalone", "true")).andExpect(status().isOk()).andExpect(jsonPath("$").isMap());

mvc.perform(get("/api/v2/playlist/recommendation/" + purpose + "/" + mediaURN)).andExpect(status().isOk()).andExpect(jsonPath("$.urns[0]").value(mediaURN));
mvc.perform(get("/api/v2/playlist/recommendation/" + purpose + "/" + mediaURN).param("standalone", "false")).andExpect(jsonPath("$.urns[0]").value(mediaURN));
mvc.perform(get("/api/v2/playlist/recommendation/" + purpose + "/" + mediaURN).param("standalone", "true")).andExpect(jsonPath("$.urns[0]").value(mediaURN));
mvc.perform(get("/api/v2/playlist/recommendation/" + purpose + "/" + mediaURN)).andExpect(status().isOk()).andExpect(isAvailable ? jsonPath("$.urns[0]").value(mediaURN) : jsonPath("$.urns").isEmpty());
mvc.perform(get("/api/v2/playlist/recommendation/" + purpose + "/" + mediaURN).param("standalone", "false")).andExpect(isAvailable ? jsonPath("$.urns[0]").value(mediaURN) : jsonPath("$.urns").isEmpty());
mvc.perform(get("/api/v2/playlist/recommendation/" + purpose + "/" + mediaURN).param("standalone", "true")).andExpect(isAvailable ? jsonPath("$.urns[0]").value(mediaURN) : jsonPath("$.urns").isEmpty());

mvc.perform(get("/api/v2/playlist/recommendation/" + purpose + "/" + mediaURN)).andExpect(status().isOk()).andExpect(isAvailable ? jsonPath("$.recommendationId").isNotEmpty() : jsonPath("$.recommendationId").doesNotExist());
mvc.perform(get("/api/v2/playlist/recommendation/" + purpose + "/" + mediaURN).param("standalone", "false")).andExpect(isAvailable ? jsonPath("$.recommendationId").isNotEmpty() : jsonPath("$.recommendationId").doesNotExist());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import org.springframework.http.HttpMethod;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.test.context.TestPropertySource;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.test.web.client.ExpectedCount;
import org.springframework.test.web.client.MockRestServiceServer;
Expand All @@ -31,6 +32,7 @@

@RunWith(SpringRunner.class)
@SpringBootTest
@TestPropertySource(locations = "classpath:application-test.properties")
public class RecommendationServiceVideoResultTests {

@Autowired
Expand Down
1 change: 1 addition & 0 deletions src/test/resources/application-test.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
DEEP_LINK_REFRESH_INITIAL_DELAY_MS=2000

0 comments on commit 92b2e02

Please sign in to comment.