From 556e4609732cabc11c8e383b67a5ab1385c5acc1 Mon Sep 17 00:00:00 2001 From: =?utf8?q?V=C3=A1s=C3=A1ry=20D=C3=A1niel?= Date: Wed, 15 Nov 2023 20:49:05 +0100 Subject: [PATCH] BC export, first look --- mc-vod-sync/QUESTIONS.md | 3 + .../java/hu/user/mcvodsync/VodSyncEntry.java | 14 +- .../src/main/resources/application-dev.yaml | 7 + .../java/hu/user/mcvodsync/AssetMapperIT.java | 58 ++++++ .../hu/user/mcvodsync/BrightCoveClientIT.java | 166 ++++++++++++++++-- .../user/mcvodsync/EmailSendServiceTest.java | 33 ++++ .../java/hu/user/mcvodsync/RepositoryIT.java | 50 +++++- .../hu/user/mcvodsync/VodSyncEntryTest.java | 21 --- .../hu/user/mcvodsync/VodXlsProcessorIT.java | 5 +- mc-vod-sync/mc-vod-sync-brightcove/pom.xml | 10 ++ .../brightcove/BrightCoveClient.java | 117 +++++++++++- .../brightcove/ExtendedApiClient.java | 46 +++++ .../mcvodsync/brightcove/PagedSearch.java | 30 ++++ .../RestTemplateResponseErrorHandler.java | 38 ++++ .../src/main/resources/openapi.yaml | 2 +- .../scripts/003_create_business_tables.sql | 1 + mc-vod-sync/mc-vod-sync-db/pom.xml | 2 +- .../main/java/hu/user/mcvodsync/db/Asset.java | 2 + .../java/hu/user/mcvodsync/db/AssetSync.java | 4 +- .../hu/user/mcvodsync/db/PlaylistSync.java | 4 +- .../java/hu/user/mcvodsync/db/SyncType.java | 2 +- .../db/repository/AssetSyncRepository.java | 8 + mc-vod-sync/mc-vod-sync-service/pom.xml | 10 ++ .../mcvodsync/service/ServiceProperties.java | 17 ++ .../service/export/AssetExportService.java | 124 +++++++++++++ .../export/CustomPropertiesTranslator.java | 9 + .../mcvodsync/service/export/VideoMapper.java | 57 ++++++ .../{xls => import}/AssetImportService.java | 6 +- .../service/{xls => import}/AssetMapper.java | 0 .../{xls => import}/ImportSummary.java | 0 .../{xls => import}/VodXlsProcessor.java | 0 .../service/mail/EmailSendService.java | 23 +++ mc-vod-sync/pom.xml | 4 +- 33 files changed, 793 insertions(+), 80 deletions(-) create mode 100644 mc-vod-sync/mc-vod-sync-app/src/test/java/hu/user/mcvodsync/AssetMapperIT.java create mode 100644 mc-vod-sync/mc-vod-sync-app/src/test/java/hu/user/mcvodsync/EmailSendServiceTest.java delete mode 100644 mc-vod-sync/mc-vod-sync-app/src/test/java/hu/user/mcvodsync/VodSyncEntryTest.java create mode 100644 mc-vod-sync/mc-vod-sync-brightcove/src/main/java/hu/user/mcvodsync/brightcove/ExtendedApiClient.java create mode 100644 mc-vod-sync/mc-vod-sync-brightcove/src/main/java/hu/user/mcvodsync/brightcove/PagedSearch.java create mode 100644 mc-vod-sync/mc-vod-sync-brightcove/src/main/java/hu/user/mcvodsync/brightcove/RestTemplateResponseErrorHandler.java create mode 100644 mc-vod-sync/mc-vod-sync-service/src/main/java/hu/user/mcvodsync/service/ServiceProperties.java create mode 100644 mc-vod-sync/mc-vod-sync-service/src/main/java/hu/user/mcvodsync/service/export/AssetExportService.java create mode 100644 mc-vod-sync/mc-vod-sync-service/src/main/java/hu/user/mcvodsync/service/export/CustomPropertiesTranslator.java create mode 100644 mc-vod-sync/mc-vod-sync-service/src/main/java/hu/user/mcvodsync/service/export/VideoMapper.java rename mc-vod-sync/mc-vod-sync-service/src/main/java/hu/user/mcvodsync/service/{xls => import}/AssetImportService.java (96%) rename mc-vod-sync/mc-vod-sync-service/src/main/java/hu/user/mcvodsync/service/{xls => import}/AssetMapper.java (100%) rename mc-vod-sync/mc-vod-sync-service/src/main/java/hu/user/mcvodsync/service/{xls => import}/ImportSummary.java (100%) rename mc-vod-sync/mc-vod-sync-service/src/main/java/hu/user/mcvodsync/service/{xls => import}/VodXlsProcessor.java (100%) create mode 100644 mc-vod-sync/mc-vod-sync-service/src/main/java/hu/user/mcvodsync/service/mail/EmailSendService.java diff --git a/mc-vod-sync/QUESTIONS.md b/mc-vod-sync/QUESTIONS.md index 2bff3a6c..196c36f8 100644 --- a/mc-vod-sync/QUESTIONS.md +++ b/mc-vod-sync/QUESTIONS.md @@ -1,3 +1,6 @@ +* A custom fields API kellhet? Ott be lehet állítani a custom filed-re pl. azt, hogy kötelező e, így amíg nincs értéke + addig a videó nem aktív. Ennek használata nélkül is létrehozható video? +* * A sunset kezelése is kell, tehát jöhet adat későbbi sunset-el? * A sunset és sunrise formátuma legyen egyforma (mindegy melyik) minden sorra! * Mik a kötelező mezők? Most: playlist, sunset, sunrise, title diff --git a/mc-vod-sync/mc-vod-sync-app/src/main/java/hu/user/mcvodsync/VodSyncEntry.java b/mc-vod-sync/mc-vod-sync-app/src/main/java/hu/user/mcvodsync/VodSyncEntry.java index cbabc15b..065235dd 100644 --- a/mc-vod-sync/mc-vod-sync-app/src/main/java/hu/user/mcvodsync/VodSyncEntry.java +++ b/mc-vod-sync/mc-vod-sync-app/src/main/java/hu/user/mcvodsync/VodSyncEntry.java @@ -8,9 +8,7 @@ package hu.user.mcvodsync; import lombok.extern.log4j.Log4j2; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; -import org.springframework.boot.builder.SpringApplicationBuilder; import org.springframework.boot.web.servlet.support.SpringBootServletInitializer; -import org.springframework.context.ApplicationContext; import org.springframework.core.SpringVersion; import org.springframework.data.jpa.repository.config.EnableJpaRepositories; import org.springframework.scheduling.annotation.EnableScheduling; @@ -23,19 +21,9 @@ import org.springframework.web.servlet.config.annotation.EnableWebMvc; @EnableScheduling public class VodSyncEntry extends SpringBootServletInitializer { - public static void main(String[] args) { -// AnsiConsole.systemInstall(); -// System.out.println( ansi().eraseScreen()); log.info("Spring version: {}", SpringVersion.getVersion()); - ApplicationContext applicationContext = SpringApplication.run(VodSyncEntry.class, args); -// AnsiConsole.systemUninstall(); - } - - @Override - protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) { - logger.info("Starting configure"); - return builder.sources(VodSyncEntry.class); + SpringApplication.run(VodSyncEntry.class, args); } } diff --git a/mc-vod-sync/mc-vod-sync-app/src/main/resources/application-dev.yaml b/mc-vod-sync/mc-vod-sync-app/src/main/resources/application-dev.yaml index e37ada87..167d87e6 100644 --- a/mc-vod-sync/mc-vod-sync-app/src/main/resources/application-dev.yaml +++ b/mc-vod-sync/mc-vod-sync-app/src/main/resources/application-dev.yaml @@ -24,6 +24,13 @@ spring: retrieveMessagesFromServerOnGetMessage: true username: db2admin password: password + mail: + host: mx.in.useribm.hu +# port: 587 +# spring.mail.username= +# spring.mail.password= +# spring.mail.properties.mail.smtp.auth=true +# spring.mail.properties.mail.smtp.starttls.enable=true camunda.bpm: generic-properties.properties: telemetry-reporter-activate: false diff --git a/mc-vod-sync/mc-vod-sync-app/src/test/java/hu/user/mcvodsync/AssetMapperIT.java b/mc-vod-sync/mc-vod-sync-app/src/test/java/hu/user/mcvodsync/AssetMapperIT.java new file mode 100644 index 00000000..44c4c855 --- /dev/null +++ b/mc-vod-sync/mc-vod-sync-app/src/test/java/hu/user/mcvodsync/AssetMapperIT.java @@ -0,0 +1,58 @@ +/* + * Copyright (c) $today.year-$today.month-24. + * By elGekko + */ + +package hu.user.mcvodsync; + +import com.brightcove.cms.client.model.Video; +import hu.user.mcvodsync.db.Asset; +import hu.user.mcvodsync.service.export.VideoMapper; +import lombok.extern.log4j.Log4j2; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.context.annotation.ComponentScan; +import org.springframework.test.context.ActiveProfiles; +import org.springframework.test.context.junit4.SpringRunner; + +import static org.junit.Assert.assertEquals; + + +@Log4j2 +@RunWith(SpringRunner.class) +@ComponentScan("hu.user.lis") +@SpringBootTest +@ActiveProfiles("dev") +public class AssetMapperIT { + @Autowired + private VideoMapper videoMapper; + + @Test + public void mapAssetToVideoTest() { + Asset asset = Asset.builder() + .progLocalTitle("progLocalTitle") + .catalogId("catalogId") + .hubInfo("hubInfo") + .build(); + Video video = videoMapper.toVideo(asset); + + assertEquals(asset.getCatalogId(), video.getReferenceId()); + assertEquals(asset.getProgLocalTitle(), video.getName()); + assertEquals(asset.getHubInfo(), video.getCustomFields().get(VideoMapper.NOTES)); + } + + @Test + public void mapVideoToAssetTest() { + Video video = new Video(); + video.setReferenceId("setReferenceId"); + video.setName("name"); + video.putCustomFieldsItem(VideoMapper.NOTES, "notes"); + Asset asset = videoMapper.toAsset(video); + + assertEquals(video.getReferenceId(), asset.getCatalogId()); + assertEquals(video.getName(), asset.getProgLocalTitle()); + assertEquals(video.getCustomFields().get(VideoMapper.NOTES), asset.getHubInfo()); + } +} diff --git a/mc-vod-sync/mc-vod-sync-app/src/test/java/hu/user/mcvodsync/BrightCoveClientIT.java b/mc-vod-sync/mc-vod-sync-app/src/test/java/hu/user/mcvodsync/BrightCoveClientIT.java index 4bc34606..54f58743 100644 --- a/mc-vod-sync/mc-vod-sync-app/src/test/java/hu/user/mcvodsync/BrightCoveClientIT.java +++ b/mc-vod-sync/mc-vod-sync-app/src/test/java/hu/user/mcvodsync/BrightCoveClientIT.java @@ -2,8 +2,11 @@ package hu.user.mcvodsync; import com.brightcove.cms.client.model.CreateVideoRequestBodyFields; import com.brightcove.cms.client.model.Playlist; +import com.brightcove.cms.client.model.PlaylistInputFields; import com.brightcove.cms.client.model.Video; +import com.google.common.collect.ImmutableMap; import hu.user.mcvodsync.brightcove.BrightCoveClient; +import hu.user.mcvodsync.brightcove.PagedSearch; import lombok.extern.log4j.Log4j2; import org.junit.Test; import org.junit.runner.RunWith; @@ -13,8 +16,13 @@ import org.springframework.context.annotation.ComponentScan; import org.springframework.test.context.ActiveProfiles; import org.springframework.test.context.TestPropertySource; import org.springframework.test.context.junit4.SpringRunner; +import org.springframework.web.client.HttpClientErrorException; +import org.springframework.web.client.HttpServerErrorException; +import java.util.ArrayList; +import java.util.Collections; import java.util.List; +import java.util.stream.Collectors; @Log4j2 @RunWith(SpringRunner.class) @@ -28,14 +36,61 @@ public class BrightCoveClientIT { private BrightCoveClient bcClient; + private List getVideos() { + List ids = new ArrayList<>(); + PagedSearch