Skip to content

Commit

Permalink
Use Recording StartTs and EndTs to calculate duration and validation
Browse files Browse the repository at this point in the history
Added some tests to verify the data maps correctly with invalid data, also verify the validation errors gets populated correctly.

Changes #68
  • Loading branch information
dmfrey committed Jan 24, 2017
1 parent 718f71e commit 34f6427
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,23 +35,26 @@ private MediaItemDataMapper() { }

public static MediaItem transform( ProgramEntity programEntity ) throws UnsupportedEncodingException {

boolean dateValidationError = false;
MediaItem mediaItem = new MediaItem();
mediaItem.setId( programEntity.getRecording().getRecordedId() );

if( null == programEntity.getStartTime() ) {
mediaItem.getValidationErrors().add( new Error( "StartTime", "StartTime is not valid for " + programEntity.getTitle() + " - " + programEntity.getSubTitle(), -1 ) );
if( null == programEntity.getRecording().getStartTs() ) {
mediaItem.getValidationErrors().add( new Error( "StartTs", "StartTs is not valid for " + programEntity.getTitle() + " - " + programEntity.getSubTitle(), -1 ) );
dateValidationError = true;
}

if( null == programEntity.getEndTime() ) {
mediaItem.getValidationErrors().add( new Error( "EndTime", "EndTime is not valid for " + programEntity.getTitle() + " - " + programEntity.getSubTitle(), -1 ) );
if( null == programEntity.getRecording().getEndTs() ) {
mediaItem.getValidationErrors().add( new Error( "EndTs", "EndTs is not valid for " + programEntity.getTitle() + " - " + programEntity.getSubTitle(), -1 ) );
dateValidationError = true;
}

if( null != programEntity.getChannel() && programEntity.getChannel().getChanId() != -1 ) {
mediaItem.getValidationErrors().add( new Error( "ChanId", "Channel Id is not valid for " + programEntity.getTitle() + " - " + programEntity.getSubTitle(), -1 ) );
if( programEntity.getRecording().getRecordedId() == -1 ) {
mediaItem.getValidationErrors().add( new Error( "RecordedId", "Recorded Id is not valid for " + programEntity.getTitle() + " - " + programEntity.getSubTitle(), -1 ) );
}

if( null != programEntity.getRecording() && programEntity.getRecording().getRecordedId() != -1 ) {
mediaItem.getValidationErrors().add( new Error( "RecordedId", "Recorded Id is not valid for " + programEntity.getTitle() + " - " + programEntity.getSubTitle(), -1 ) );
if( programEntity.getChannel().getChanId() == -1 ) {
mediaItem.getValidationErrors().add( new Error( "ChanId", "Channel Id is not valid for " + programEntity.getTitle() + " - " + programEntity.getSubTitle(), -1 ) );
}

switch( programEntity.getRecording().getStatus() ) {
Expand Down Expand Up @@ -94,13 +97,15 @@ public static MediaItem transform( ProgramEntity programEntity ) throws Unsuppor
mediaItem.setSubTitle( programEntity.getSubTitle() );
mediaItem.setInetref( programEntity.getInetref() );
mediaItem.setDescription( programEntity.getDescription() );
mediaItem.setStartDate( programEntity.getStartTime() );
mediaItem.setStartDate(programEntity.getStartTime());
mediaItem.setProgramFlags( programEntity.getProgramFlags() );
mediaItem.setSeason( programEntity.getSeason() );
mediaItem.setEpisode( programEntity.getEpisode() );
mediaItem.setStudio( programEntity.getChannel().getCallSign() );

calculateDuration( mediaItem, programEntity.getRecording().getStartTs(), programEntity.getRecording().getEndTs() );
if( !dateValidationError ) {
calculateDuration( mediaItem, programEntity.getRecording().getStartTs(), programEntity.getRecording().getEndTs() );
}

if( null != programEntity.getArtwork() ) {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,10 @@
import java.io.StringReader;

import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.greaterThan;
import static org.hamcrest.Matchers.hasSize;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.lessThan;
import static org.hamcrest.Matchers.not;
import static org.hamcrest.Matchers.nullValue;
import static org.junit.Assert.assertThat;
Expand All @@ -25,6 +28,7 @@
public class MediaItemDataMapperTest extends ApplicationTestCase {

private static final String JSON_RESPONSE_DVR_GET_RECORDED = "{\"Program\": {\"StartTime\": \"2015-09-08T11:30:00Z\", \"EndTime\": \"2015-09-08T12:00:00Z\", \"Title\": \"Star Wars: Droid Tales\", \"SubTitle\": \"Mission to Mos Eisley\", \"Category\": \"Fantasy\", \"CatType\": \"series\", \"Repeat\": \"false\", \"VideoProps\": \"11\", \"AudioProps\": \"0\", \"SubProps\": \"1\", \"SeriesId\": \"EP02206828\", \"ProgramId\": \"EP022068280003\", \"Stars\": \"0\", \"LastModified\": \"2015-09-08T12:00:01Z\", \"ProgramFlags\": \"5\", \"Airdate\": \"2015-09-07\", \"Description\": \"C-3PO recounts his adventure with the ``Star Wars Rebels'' crew in an effort to find R2-D2, who has been kidnapped.\", \"Inetref\": \"ttvdb.py_298171\", \"Season\": \"0\", \"Episode\": \"0\", \"TotalEpisodes\": \"0\", \"FileSize\": \"2780544064\", \"FileName\": \"2289_20150908113000.ts\", \"HostName\": \"mythcenter\", \"Channel\": {\"ChanId\": \"2289\", \"ChanNum\": \"1289\", \"CallSign\": \"DXDHD\", \"IconURL\": \"\", \"ChannelName\": \"Disney XD HD\", \"MplexId\": \"32767\", \"ServiceId\": \"0\", \"ATSCMajorChan\": \"1289\", \"ATSCMinorChan\": \"0\", \"Format\": \"Default\", \"FrequencyId\": \"1289\", \"FineTune\": \"0\", \"ChanFilters\": \"\", \"SourceId\": \"1\", \"InputId\": \"0\", \"CommFree\": \"false\", \"UseEIT\": \"false\", \"Visible\": \"true\", \"XMLTVID\": \"60006\", \"DefaultAuth\": \"\", \"Programs\": []}, \"Recording\": {\"RecordedId\": \"3120\", \"Status\": \"-3\", \"Priority\": \"0\", \"StartTs\": \"2015-09-08T11:30:00Z\", \"EndTs\": \"2015-09-08T12:00:00Z\", \"FileSize\": \"2780544064\", \"FileName\": \"2289_20150908113000.ts\", \"HostName\": \"mythcenter\", \"LastModified\": \"2015-09-08T12:00:01Z\", \"RecordId\": \"112\", \"RecGroup\": \"Default\", \"PlayGroup\": \"Default\", \"StorageGroup\": \"Default\", \"RecType\": \"0\", \"DupInType\": \"15\", \"DupMethod\": \"6\", \"EncoderId\": \"0\", \"EncoderName\": \"\", \"Profile\": \"Default\"}, \"Artwork\": {\"ArtworkInfos\": []}, \"Cast\": {\"CastMembers\": []}}}";
private static final String JSON_RESPONSE_DVR_GET_RECORDED_NULL_STARTTS = "{\"Program\": {\"StartTime\": \"2015-09-08T11:30:00Z\", \"EndTime\": \"2015-09-08T12:00:00Z\", \"Title\": \"Star Wars: Droid Tales\", \"SubTitle\": \"Mission to Mos Eisley\", \"Category\": \"Fantasy\", \"CatType\": \"series\", \"Repeat\": \"false\", \"VideoProps\": \"11\", \"AudioProps\": \"0\", \"SubProps\": \"1\", \"SeriesId\": \"EP02206828\", \"ProgramId\": \"EP022068280003\", \"Stars\": \"0\", \"LastModified\": \"2015-09-08T12:00:01Z\", \"ProgramFlags\": \"5\", \"Airdate\": \"2015-09-07\", \"Description\": \"C-3PO recounts his adventure with the ``Star Wars Rebels'' crew in an effort to find R2-D2, who has been kidnapped.\", \"Inetref\": \"ttvdb.py_298171\", \"Season\": \"0\", \"Episode\": \"0\", \"TotalEpisodes\": \"0\", \"FileSize\": \"2780544064\", \"FileName\": \"2289_20150908113000.ts\", \"HostName\": \"mythcenter\", \"Channel\": {\"ChanId\": \"2289\", \"ChanNum\": \"1289\", \"CallSign\": \"DXDHD\", \"IconURL\": \"\", \"ChannelName\": \"Disney XD HD\", \"MplexId\": \"32767\", \"ServiceId\": \"0\", \"ATSCMajorChan\": \"1289\", \"ATSCMinorChan\": \"0\", \"Format\": \"Default\", \"FrequencyId\": \"1289\", \"FineTune\": \"0\", \"ChanFilters\": \"\", \"SourceId\": \"1\", \"InputId\": \"0\", \"CommFree\": \"false\", \"UseEIT\": \"false\", \"Visible\": \"true\", \"XMLTVID\": \"60006\", \"DefaultAuth\": \"\", \"Programs\": []}, \"Recording\": {\"RecordedId\": \"3120\", \"Status\": \"-3\", \"Priority\": \"0\", \"StartTs\": null, \"EndTs\": \"2015-09-08T12:00:00Z\", \"FileSize\": \"2780544064\", \"FileName\": \"2289_20150908113000.ts\", \"HostName\": \"mythcenter\", \"LastModified\": \"2015-09-08T12:00:01Z\", \"RecordId\": \"112\", \"RecGroup\": \"Default\", \"PlayGroup\": \"Default\", \"StorageGroup\": \"Default\", \"RecType\": \"0\", \"DupInType\": \"15\", \"DupMethod\": \"6\", \"EncoderId\": \"0\", \"EncoderName\": \"\", \"Profile\": \"Default\"}, \"Artwork\": {\"ArtworkInfos\": []}, \"Cast\": {\"CastMembers\": []}}}";
private static final String JSON_RESPONSE_VIDEO_GET_VIDEO = "{\"VideoMetadataInfo\":{\"Id\": \"1\", \"Title\": \"big buck bunny 1080p stereo\", \"SubTitle\": \"\", \"Tagline\": \"\", \"Director\": \"Unknown\", \"Studio\": \"\", \"Description\": \"None\", \"Certification\": \"NR\", \"Inetref\": \"00000000\", \"Collectionref\": \"-1\", \"HomePage\": \"\", \"ReleaseDate\": \"\", \"AddDate\": \"2015-01-05T05:00:00Z\", \"UserRating\": \"0\", \"Length\": \"0\", \"PlayCount\": \"0\", \"Season\": \"0\", \"Episode\": \"0\", \"ParentalLevel\": \"1\", \"Visible\": \"true\", \"Watched\": \"false\", \"Processed\": \"true\", \"ContentType\": \"MOVIE\", \"FileName\": \"library\\/Blender\\/big_buck_bunny_1080p_stereo.ogg\", \"Hash\": \"63ad35476c29214c\", \"HostName\": \"mythcenter\", \"Coverart\": \"\", \"Fanart\": \"\", \"Banner\": \"\", \"Screenshot\": \"\", \"Trailer\": \"\", \"Artwork\": {\"ArtworkInfos\": []}, \"Cast\": {\"CastMembers\": []}}}";

private ProgramEntityJsonMapper programEntityJsonMapper;
Expand Down Expand Up @@ -64,7 +68,39 @@ public void testTransformProgram() throws Exception {
assertThat( mediaItem.getBannerUrl(), is( nullValue() ) );
assertThat( mediaItem.getPreviewUrl(), is( "/Content/GetPreviewImage?RecordedId=3120" ) );

assertThat( mediaItem.getDuration(), greaterThan( 0l ) );
assertThat( mediaItem.getDuration(), is( equalTo( 30L ) ) );
assertThat( mediaItem.isValid(), is( true ) );
assertThat( mediaItem.getValidationErrors(), hasSize( 0 ) );

}

@Test
public void testTransformProgramNullStartTs() throws Exception {

ProgramEntity programEntity = programEntityJsonMapper.transformProgramEntity( new StringReader( JSON_RESPONSE_DVR_GET_RECORDED_NULL_STARTTS ) );
assertThat( programEntity, not( nullValue() ) );

MediaItem mediaItem = MediaItemDataMapper.transform( programEntity );
assertThat( mediaItem, not( nullValue() ) );
assertThat( mediaItem.getId(), is( equalTo( 3120 ) ) );
assertThat( mediaItem.getMedia(), is( equalTo( Media.PROGRAM ) ) );
assertThat( mediaItem.getTitle(), is( equalTo( "Star Wars: Droid Tales" ) ) );
assertThat( mediaItem.getSubTitle(), is( equalTo( "Mission to Mos Eisley" ) ) );
assertThat( mediaItem.getDescription(), is( equalTo( "C-3PO recounts his adventure with the ``Star Wars Rebels'' crew in an effort to find R2-D2, who has been kidnapped." ) ) );
assertThat( mediaItem.getStartDate(), not( nullValue() ) );
assertThat( mediaItem.getSeason(), is( equalTo( 0 ) ) );
assertThat( mediaItem.getEpisode(), is( equalTo( 0 ) ) );
assertThat( mediaItem.getStudio(), is( equalTo( "DXDHD" ) ) );
assertThat( mediaItem.getUrl(), is( equalTo( "/Content/GetFile?FileName=2289_20150908113000.ts" ) ) );
assertThat( mediaItem.getFanartUrl(), is( nullValue() ) );
assertThat( mediaItem.getCoverartUrl(), is( nullValue() ) );
assertThat( mediaItem.getBannerUrl(), is( nullValue() ) );
assertThat( mediaItem.getPreviewUrl(), is( "/Content/GetPreviewImage?RecordedId=3120" ) );

assertThat( mediaItem.getDuration(), lessThan( 0l ) );
assertThat( mediaItem.isValid(), is( false ) );
assertThat( mediaItem.getValidationErrors(), hasSize( 1 ) );

}

Expand Down Expand Up @@ -92,6 +128,7 @@ public void testTransformVideo() throws Exception {
assertThat( mediaItem.getPreviewUrl(), is( nullValue() ) );

assertThat( mediaItem.getDuration(), is( equalTo( 0L ) ) );
assertThat( mediaItem.getValidationErrors(), hasSize( 0 ) );

}

Expand Down

0 comments on commit 34f6427

Please sign in to comment.