Skip to content

Commit

Permalink
Merge pull request #61 from SRGSSR/develop
Browse files Browse the repository at this point in the history
Release deeplink update (new topic list workflow and event list removal)
  • Loading branch information
pyby authored Feb 19, 2022
2 parents e45adb1 + 8fe8a56 commit 73aa5e4
Show file tree
Hide file tree
Showing 11 changed files with 172 additions and 250 deletions.
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>35</version>
<version>36</version>
<packaging>jar</packaging>

<name>pfff</name>
Expand Down
109 changes: 0 additions & 109 deletions src/main/java/ch/srgssr/playfff/model/playportal/PlayTopic.java

This file was deleted.

111 changes: 21 additions & 90 deletions src/main/java/ch/srgssr/playfff/service/DeepLinkService.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package ch.srgssr.playfff.service;

import ch.srg.il.domain.v2_0.ModuleConfig;
import ch.srg.il.domain.v2_0.ModuleConfigList;
import ch.srg.il.domain.v2_0.Topic;
import ch.srg.il.domain.v2_0.TopicList;
import ch.srgssr.playfff.helper.BaseResourceString;
import ch.srgssr.playfff.model.DeepLinkJSContent;
import ch.srgssr.playfff.model.Environment;
import ch.srgssr.playfff.model.playportal.PlayTopic;
import ch.srgssr.playfff.utils.Seo;
import ch.srgssr.playfff.utils.Sha1;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.slf4j.Logger;
Expand All @@ -17,14 +17,11 @@
import org.springframework.cache.annotation.Cacheable;
import org.springframework.cache.annotation.EnableCaching;
import org.springframework.context.ApplicationContext;
import org.springframework.http.HttpMethod;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;

import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.net.URI;
import java.security.NoSuchAlgorithmException;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
Expand Down Expand Up @@ -72,48 +69,22 @@ public synchronized DeepLinkJSContent refreshParsePlayUrlJSContent() {
String javascriptV1 = BaseResourceString.getString(applicationContext, "deeplink/v1/parsePlayUrl.js");
String javascriptV2 = BaseResourceString.getString(applicationContext, "deeplink/v2/parsePlayUrl.js");

Map<String, String> buProdMap = new HashMap<>();
buProdMap.put("srf", "srgplayer-srf.production.srf.ch");
buProdMap.put("rts", "srgplayer-rts.production.srf.ch");
buProdMap.put("rsi", "srgplayer-rsi.production.srf.ch");
buProdMap.put("rtr", "srgplayer-rtr.production.srf.ch");
buProdMap.put("swi", "srgplayer-swi.production.srf.ch");

Map<String, String> buStageMap = new HashMap<>();
buStageMap.put("srf", "srgplayer-srf.stage.srf.ch");
buStageMap.put("rts", "srgplayer-rts.stage.srf.ch");
buStageMap.put("rsi", "srgplayer-rsi.stage.srf.ch");
buStageMap.put("rtr", "srgplayer-rtr.stage.srf.ch");
buStageMap.put("swi", "srgplayer-swi.stage.srf.ch");

Map<String, String> buTestMap = new HashMap<>();
buTestMap.put("srf", "srgplayer-srf.test.srf.ch");
buTestMap.put("rts", "srgplayer-rts.test.srf.ch");
buTestMap.put("rsi", "srgplayer-rsi.test.srf.ch");
buTestMap.put("rtr", "srgplayer-rtr.test.srf.ch");
buTestMap.put("swi", "srgplayer-swi.test.srf.ch");

Map<Environment, Map<String, String>> environmentMap = new HashMap<>();
environmentMap.put(Environment.PROD, buProdMap);
environmentMap.put(Environment.STAGE, buStageMap);
environmentMap.put(Environment.TEST, buTestMap);
environmentMap.put(Environment.MMF, new HashMap<>());
List<String> srgBUs = Arrays.asList("rsi", "rtr", "rts", "srf", "swi");

Map<Environment, List<String>> busMap = new HashMap<>();
busMap.put(Environment.PROD, srgBUs);
busMap.put(Environment.STAGE, srgBUs);
busMap.put(Environment.TEST, srgBUs);
busMap.put(Environment.MMF, Arrays.asList());

Map<String, Map<String, Map<String, String>>> tvGlobalTopicMap = new HashMap<>();
Map<String, Map<String, Map<String, String>>> tvGlobalEventMap = new HashMap<>();

for (Environment environment : pullEnvironmentSet) {
Map<String, Map<String, String>> tvTopicMap = getTvTopicMap(environmentMap.get(environment));
Map<String, Map<String, String>> tvTopicMap = getTvTopicMap(busMap.get(environment), environment);

if (tvTopicMap.size() > 0) {
tvGlobalTopicMap.put(environment.getPrettyName(), tvTopicMap);
}

Map<String, Map<String, String>> tvEventMap = getTvEventMap(environmentMap.get(environment), environment);

if (tvEventMap.size() > 0) {
tvGlobalEventMap.put(environment.getPrettyName(), tvEventMap);
}
}

ObjectMapper mapperObj = new ObjectMapper();
Expand All @@ -130,18 +101,6 @@ public synchronized DeepLinkJSContent refreshParsePlayUrlJSContent() {
javascriptV2 = javascriptV2.replaceAll("\\/\\* INJECT TVTOPICS OBJECT \\*\\/", "var tvTopics = " + tvTopics + ";");
}

String tvEvents = null;
try {
tvEvents = mapperObj.writeValueAsString(tvGlobalEventMap);
} catch (IOException e) {
e.printStackTrace();
}

if (tvEvents != null) {
javascriptV1 = javascriptV1.replaceAll("\\/\\* INJECT TVEVENTS OBJECT \\*\\/", "var tvEvents = " + tvEvents + ";");
javascriptV2 = javascriptV2.replaceAll("\\/\\* INJECT TVEVENTS OBJECT \\*\\/", "var tvEvents = " + tvEvents + ";");
}

String buildHashV1 = "NO_SHA1";
try {
buildHashV1 = Sha1.sha1(javascriptV1);
Expand All @@ -165,50 +124,22 @@ public synchronized DeepLinkJSContent refreshParsePlayUrlJSContent() {
return new DeepLinkJSContent(javascriptV1, buildHashV1, javascriptV2, buildHashV2);
}

private Map<String, Map<String, String>> getTvTopicMap(Map<String, String> buMap) {
private Map<String, Map<String, String>> getTvTopicMap(List<String> buList, Environment environment) {
Map<String, Map<String, String>> tvTopicsMap = new HashMap<>();

for (Map.Entry<String, String> bu : buMap.entrySet()) {
URI tvTopicListUri = null;
try {
tvTopicListUri = new URI("https", null, bu.getValue(), 443, "/play/tv/topicList",
null, null);

ResponseEntity<PlayTopic[]> tvTopicListResponseEntity = restTemplate.exchange(tvTopicListUri, HttpMethod.GET, null, PlayTopic[].class);
for (String bu : buList) {
TopicList topicList = integrationLayerRequest.getTopics(bu, environment);
if (topicList != null) {
Map<String, String> tvTopicsSubMap = new HashMap<>();

if (tvTopicListResponseEntity.getBody() != null) {
PlayTopic[] tvTopicList = tvTopicListResponseEntity.getBody();
Map<String, String> tvTopicsSubMap = new HashMap<>();

for (PlayTopic playTopic : tvTopicList) {
tvTopicsSubMap.put(playTopic.getUrlEncodedTitle(), playTopic.getId());
}

tvTopicsMap.put(bu.getKey(), tvTopicsSubMap);
for (int i = 0; i < topicList.getList().size(); i++) {
Topic topic = topicList.getList().get(i);
tvTopicsSubMap.put(Seo.nameFromTitle(topic.getTitle()), topic.getId());
}
} catch (Exception e) {
e.printStackTrace();
}
}
return tvTopicsMap;
}

private Map<String, Map<String, String>> getTvEventMap(Map<String, String> buMap, Environment environment) {
Map<String, Map<String, String>> tvEventsMap = new HashMap<>();

for (Map.Entry<String, String> bu : buMap.entrySet()) {
ModuleConfigList moduleConfigList = integrationLayerRequest.getEvents(bu.getKey(), environment);
if (moduleConfigList != null) {
Map<String, String> tvEventsSubMap = new HashMap<>();

for (int i = 0; i < moduleConfigList.getModuleConfigList().size(); i++) {
ModuleConfig moduleConfig = moduleConfigList.getModuleConfigList().get(i);
tvEventsSubMap.put(moduleConfig.getSeoName(), moduleConfig.getId());
}

tvEventsMap.put(bu.getKey(), tvEventsSubMap);
tvTopicsMap.put(bu, tvTopicsSubMap);
}
}
return tvEventsMap;
return tvTopicsMap;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -101,13 +101,13 @@ public MediaComposition getMediaComposition(String mediaURN, Environment environ
}
}

public ModuleConfigList getEvents(String bu, Environment environment) {
String path = "/integrationlayer/2.0/" + bu + "/moduleConfigList/event.json";
public TopicList getTopics(String bu, Environment environment) {
String path = "/integrationlayer/2.0/" + bu + "/topicList/tv.json";
try {
URI uri = new URI("http", null, environment.getBaseUrl(), PORT, path, null, null);
ResponseEntity<String> responseEntity = restTemplate.getForEntity(uri, String.class);
SrgUnmarshaller unmarshaller = new SrgUnmarshaller();
return unmarshaller.unmarshal(responseEntity.getBody(), MediaType.APPLICATION_JSON, ModuleConfigList.class);
return unmarshaller.unmarshal(responseEntity.getBody(), MediaType.APPLICATION_JSON, TopicList.class);
} catch (Exception e) {
logger.warn("http://{}{} : {}", environment.getBaseUrl(), path, e.getMessage());
return null;
Expand Down
46 changes: 46 additions & 0 deletions src/main/java/ch/srgssr/playfff/utils/Seo.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package ch.srgssr.playfff.utils;

/**
* Copyright (c) SRG SSR. All rights reserved.
* <p>
* License information is available from the LICENSE file.
*/
public class Seo {
/*
Convert a string to a seo name
Based on Play SRG web application (from 'to-seo-string.ts')
*/
public static String nameFromTitle(String title) {
return title
.toLowerCase()
.replace(" - ", "-")
.replace("–", "-")
.replace(".", "-")

// utf-8 non breaking space
.replace("\\xa0", "-")

// whitespace characters
.replace("\\s", "-")
.replace(" ", "-")

// tabs and new line
.replace("\t", "-")
.replace("\n", "-")

// umlauts", accents and diacritics
.replace("ä", "ae")
.replace("ö", "oe")
.replace("ü", "ue")
.replaceAll("[éèê]", "e")
.replaceAll("[áàâ]", "a")
.replaceAll("[úùû]", "u")
.replaceAll("[óòô]", "o")
.replace("ç", "c")
.replace("æ", "ae")
.replace("œ", "oe")

// special characters (except "-"", "_")
.replaceAll("[^a-zA-Z0-9\\-_]*", "");
}
}
24 changes: 3 additions & 21 deletions src/main/resources/deeplink/v1/parsePlayUrl.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// parsePlayUrl

var parsePlayUrlVersion = 30;
var parsePlayUrlVersion = 31;
var parsePlayUrlBuild = "mmf";

if(! console) {
Expand Down Expand Up @@ -646,32 +646,14 @@ function parseForPlayApp(scheme, hostname, pathname, queryParams, anchor) {
}

/**
* Catch TV event urls
* Catch TV event urls (support removed - URLs switched to section page urls)
*
* Ex: https://www.srf.ch/play/tv/event/10-jahre-auf-und-davon
* Ex: https://www.rsi.ch/play/tv/event/event-playrsi-8858482
*/
if (pathname.endsWith("/tv/event")) {
if (pathname.endsWith("/tv/event") || pathname.includes("/tv/event")) {
return openPage(server, bu, "tv:home", null, null);
}
else if (pathname.includes("/tv/event")) {
var lastPathComponent = pathname.split("/").slice(-1)[0];

var eventId = null;

/* INJECT TVEVENTS OBJECT */

if (typeof tvEvents !== 'undefined' && lastPathComponent.length > 0) {
eventId = tvEvents[server][bu][lastPathComponent];
}

if (eventId) {
return openModule(server, bu, "event", eventId);
}
else {
return openPage(server, bu, "tv:home", null, null);
}
}

/**
* Catch TV section page urls
Expand Down
Loading

0 comments on commit 73aa5e4

Please sign in to comment.