Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[AB#45135][AB#45120][AB#45132] Channel Service bugfixes and improvements #333

Merged
merged 5 commits into from
Jul 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,7 @@ export class PlaylistPublishedEventHandler extends TransactionalInboxMessageHand
).run(txnClient);

const programMappings = programs.reduce((acc: Dict<number>, cur) => {
if (cur.sort_index) {
acc[cur.sort_index] = cur.id;
}
acc[cur.sort_index] = cur.id;
return acc;
}, {});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,15 +149,18 @@ describe('validateChannel', () => {
async (
_videoServiceBaseUrl,
_authToken,
videoIds,
assignedVideos,
): Promise<{ videos: DetailedVideo[]; validations: [] }> => {
if (videoIds.length === 0) {
if (assignedVideos.length === 0) {
return {
validations: [],
videos: [],
};
} else {
return { videos: createVideos(videoIds), validations: [] };
return {
videos: createVideos(assignedVideos.map((v) => v.videoId)),
validations: [],
};
}
},
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,9 @@ export async function validateChannel(
getValidationAndVideos(
config.videoServiceBaseUrl,
jwtToken,
publishDto.placeholder_video_id ? [publishDto.placeholder_video_id] : [],
publishDto.placeholder_video_id
? [{ videoId: publishDto.placeholder_video_id }]
: [],
publishDto.is_drm_protected,
true,
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,15 @@ class TestLocalizableProgramCreatedDbMessageHandler extends LocalizableProgramCr
}
}

class TestLocalizableProgramUpdatedDbMessageHandler extends LocalizableProgramUpdatedDbMessageHandler {
override additionalWork(): Promise<void> {
return Promise.resolve();
}
override getSourceTitle(): Promise<string> {
return Promise.resolve('unit test title');
}
}

const serviceAccountToken = 'SERVICE_ACCOUNT_TOKEN';
jest.mock('@axinom/mosaic-id-link-be', () => {
const originalModule = jest.requireActual('@axinom/mosaic-id-link-be');
Expand Down Expand Up @@ -137,10 +146,10 @@ describe('Localizable Program DB trigger events', () => {
});

describe('LocalizableProgramUpdatedDbMessageHandler', () => {
let handler: LocalizableProgramUpdatedDbMessageHandler;
let handler: TestLocalizableProgramUpdatedDbMessageHandler;

beforeAll(() => {
handler = new LocalizableProgramUpdatedDbMessageHandler(
handler = new TestLocalizableProgramUpdatedDbMessageHandler(
storeOutboxMessage,
config,
);
Expand All @@ -161,7 +170,7 @@ describe('Localizable Program DB trigger events', () => {
{
payload: {
entity_id: payload.id.toString(),
entity_title: payload.title,
entity_title: 'unit test title',
entity_type: LOCALIZATION_PROGRAM_TYPE,
fields: {
title: payload.title,
Expand Down Expand Up @@ -196,7 +205,7 @@ describe('Localizable Program DB trigger events', () => {
{
payload: {
entity_id: payload.id.toString(),
entity_title: payload.title,
entity_title: 'unit test title',
entity_type: LOCALIZATION_PROGRAM_TYPE,
fields: {
title: payload.title,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { MessagingSettings } from '@axinom/mosaic-message-bus-abstractions';
import {
LocalizationServiceMultiTenantMessagingSettings,
LocalizeEntityCommand,
Expand Down Expand Up @@ -60,7 +61,61 @@ const getLocalizationMappedError = mosaicErrorMappingFactory(
},
);

export class LocalizableProgramCreatedDbMessageHandler extends LocalizableTransactionalInboxMessageHandler<LocalizableProgramDbEvent> {
export abstract class ProgramLocalizableTransactionalInboxMessageHandler<
T,
> extends LocalizableTransactionalInboxMessageHandler<T> {
constructor(
messagingSettings: MessagingSettings,
storeOutboxMessage: StoreOutboxMessage,
config: Config,
) {
super(messagingSettings, storeOutboxMessage, config);
}

protected async getSourceTitle(
id: string,
ownerClient: ClientBase,
fields: { title?: string | undefined },
): Promise<string> {
const program = await selectOne(
'programs',
{ id },
{
lateral: {
playlist: selectExactlyOne(
'playlists',
{
id: parent('playlist_id'),
},
{
columns: ['start_date_time'],
lateral: {
channel: selectExactlyOne(
'channels',
{
id: parent('channel_id'),
},
{ columns: ['title'] },
),
},
},
),
},
},
).run(ownerClient);
if (!program) {
throw new MosaicError(
`Could not find the program "${fields.title}" with ID "${id}".`,
);
}
return `${fields.title} (${program.playlist.start_date_time.substring(
0,
10,
)} - ${program.playlist.channel.title})`;
}
}

export class LocalizableProgramCreatedDbMessageHandler extends ProgramLocalizableTransactionalInboxMessageHandler<LocalizableProgramDbEvent> {
constructor(storeOutboxMessage: StoreOutboxMessage, config: Config) {
super(
LocalizableProgramDbMessagingSettings.LocalizableProgramCreated,
Expand Down Expand Up @@ -166,51 +221,9 @@ export class LocalizableProgramCreatedDbMessageHandler extends LocalizableTransa
image_id,
);
}

protected async getSourceTitle(
id: string,
ownerClient: ClientBase,
fields: { title?: string | undefined },
): Promise<string> {
const program = await selectOne(
'programs',
{ id },
{
lateral: {
playlist: selectExactlyOne(
'playlists',
{
id: parent('playlist_id'),
},
{
columns: ['start_date_time'],
lateral: {
channel: selectExactlyOne(
'channels',
{
id: parent('channel_id'),
},
{ columns: ['title'] },
),
},
},
),
},
},
).run(ownerClient);
if (!program) {
throw new MosaicError(
`Could not find the program "${fields.title}" with ID "${id}".`,
);
}
return `${fields.title} (${program.playlist.start_date_time.substring(
0,
10,
)} - ${program.playlist.channel.title})`;
}
}

export class LocalizableProgramUpdatedDbMessageHandler extends LocalizableTransactionalInboxMessageHandler<LocalizableProgramDbEvent> {
export class LocalizableProgramUpdatedDbMessageHandler extends ProgramLocalizableTransactionalInboxMessageHandler<LocalizableProgramDbEvent> {
constructor(storeOutboxMessage: StoreOutboxMessage, config: Config) {
super(
LocalizableProgramDbMessagingSettings.LocalizableProgramUpdated,
Expand All @@ -219,17 +232,19 @@ export class LocalizableProgramUpdatedDbMessageHandler extends LocalizableTransa
);
}

override async getLocalizationCommandData({
payload: { id, image_id, ...fields },
}: TypedTransactionalMessage<LocalizableProgramDbEvent>): Promise<
LocalizationMessageData | undefined
> {
override async getLocalizationCommandData(
{
payload: { id, image_id, ...fields },
}: TypedTransactionalMessage<LocalizableProgramDbEvent>,
ownerClient: ClientBase,
): Promise<LocalizationMessageData | undefined> {
const sourceTitle = await this.getSourceTitle(id, ownerClient, fields);
return getLocalizationUpsertMessageData(
this.config.serviceId,
LOCALIZATION_PROGRAM_TYPE,
id,
fields,
fields.title,
sourceTitle,
image_id,
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -199,15 +199,18 @@ describe('validatePlaylist', () => {
async (
_videoServiceBaseUrl,
_authToken,
videoIds,
assignedVideos,
): Promise<{ videos: DetailedVideo[]; validations: [] }> => {
if (videoIds.length === 0) {
if (assignedVideos.length === 0) {
return {
validations: [],
videos: [],
};
} else {
return { videos: createVideos(videoIds), validations: [] };
return {
videos: createVideos(assignedVideos.map((v) => v.videoId)),
validations: [],
};
}
},
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ import {
import {
getValidationAndImages,
getValidationAndVideos,
} from '../../../publishing/common';
SelectedVideo,
} from '../../../publishing';
import { getProgramValidationAndLocalizations } from '../../../publishing/common/localization';
import {
calculateValidationStatus,
Expand Down Expand Up @@ -72,24 +73,35 @@ export async function validatePlaylist(
}

const imagesIds: string[] = [];
const videoIds: string[] = [];
const selectedVideos: SelectedVideo[] = [];

publishDto.programs.map((pr) => {
if (pr.image_id) {
imagesIds.push(pr.image_id);
}
videoIds.push(pr.video_id);
selectedVideos.push({
videoId: pr.video_id,
source: `The video is used for the program "${pr.title}".`,
});
pr.program_cue_points
.flatMap((cp) => cp.cue_point_schedules)
.map((s) => {
.map((s, index) => {
if (s.video_id) {
videoIds.push(s.video_id);
selectedVideos.push({
videoId: s.video_id,
source: `The video is assigned as the item number ${
index + 1
} of the program "${pr.title}".`,
});
}
});
});

if (config.playlistShouldBe24Hours && channel.placeholder_video_id) {
videoIds.push(channel.placeholder_video_id);
selectedVideos.push({
videoId: channel.placeholder_video_id,
source: 'The video is the channel placeholder video.',
});
}

const [
Expand All @@ -106,7 +118,7 @@ export async function validatePlaylist(
getValidationAndVideos(
config.videoServiceBaseUrl,
jwtToken,
videoIds,
selectedVideos,
channel.is_drm_protected,
false,
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ describe('getValidationAndVideos', () => {
const { videos, validations } = await getValidationAndVideos(
endpoint,
authToken,
[videoId1],
[{ videoId: videoId1 }],
true,
true,
);
Expand Down Expand Up @@ -139,7 +139,7 @@ describe('getValidationAndVideos', () => {
const { videos, validations } = await getValidationAndVideos(
endpoint,
authToken,
[videoId1],
[{ videoId: videoId1 }],
true,
true,
);
Expand All @@ -161,7 +161,7 @@ describe('getValidationAndVideos', () => {
const { videos, validations } = await getValidationAndVideos(
endpoint,
authToken,
[videoId1, videoId2],
[{ videoId: videoId1 }, { videoId: videoId2 }],
false,
false,
);
Expand All @@ -183,7 +183,13 @@ describe('getValidationAndVideos', () => {

// Act
const error = await rejectionOf(
getValidationAndVideos(endpoint, authToken, ['1'], false, true),
getValidationAndVideos(
endpoint,
authToken,
[{ videoId: '1' }],
false,
true,
),
);

// Assert
Expand Down Expand Up @@ -212,7 +218,13 @@ describe('getValidationAndVideos', () => {

// Act
const error = await rejectionOf(
getValidationAndVideos(endpoint, authToken, ['1'], false, true),
getValidationAndVideos(
endpoint,
authToken,
[{ videoId: '1' }],
false,
true,
),
);

// Assert
Expand Down Expand Up @@ -240,7 +252,13 @@ describe('getValidationAndVideos', () => {

// Act
const error = await rejectionOf(
getValidationAndVideos(endpoint, authToken, ['1'], false, true),
getValidationAndVideos(
endpoint,
authToken,
[{ videoId: '1' }],
false,
true,
),
);

// Assert
Expand Down
Loading