Search in sources :

Example 6 with Episode

use of com.furyviewer.domain.Episode in project FuryViewer by TheDoctor-95.

the class EpisodeResourceIntTest method updateEpisode.

@Test
@Transactional
public void updateEpisode() throws Exception {
    // Initialize the database
    episodeRepository.saveAndFlush(episode);
    int databaseSizeBeforeUpdate = episodeRepository.findAll().size();
    // Update the episode
    Episode updatedEpisode = episodeRepository.findOne(episode.getId());
    updatedEpisode.number(UPDATED_NUMBER).name(UPDATED_NAME).duration(UPDATED_DURATION).releaseDate(UPDATED_RELEASE_DATE);
    restEpisodeMockMvc.perform(put("/api/episodes").contentType(TestUtil.APPLICATION_JSON_UTF8).content(TestUtil.convertObjectToJsonBytes(updatedEpisode))).andExpect(status().isOk());
    // Validate the Episode in the database
    List<Episode> episodeList = episodeRepository.findAll();
    assertThat(episodeList).hasSize(databaseSizeBeforeUpdate);
    Episode testEpisode = episodeList.get(episodeList.size() - 1);
    assertThat(testEpisode.getNumber()).isEqualTo(UPDATED_NUMBER);
    assertThat(testEpisode.getName()).isEqualTo(UPDATED_NAME);
    assertThat(testEpisode.getDuration()).isEqualTo(UPDATED_DURATION);
    assertThat(testEpisode.getReleaseDate()).isEqualTo(UPDATED_RELEASE_DATE);
}
Also used : Episode(com.furyviewer.domain.Episode) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) Transactional(org.springframework.transaction.annotation.Transactional)

Example 7 with Episode

use of com.furyviewer.domain.Episode in project FuryViewer by TheDoctor-95.

the class SeriesTmdbDTOService method importEpisode.

/**
 * Convierte la informacion de un episode de TMDB al formato de Furyviewer.
 * @param seriesName String | Titulo de la series a buscar.
 * @param episodeNum int | Numero del episode a buscar.
 * @param season Season | Season a la que pertenece el episode.
 * @throws IOException En caso de que no se pueda hacer la peticion a la api se lanza la execpcion.
 */
public void importEpisode(String seriesName, int episodeNum, com.furyviewer.domain.Season season) throws IOException {
    int seriesId = getIdTmdbSeries(seriesName);
    SeasonTmdbDTO se;
    Call<SeasonTmdbDTO> callSeason = apiTMDB.getSeason(seriesId, season.getNumber(), apikey);
    Response<SeasonTmdbDTO> response = callSeason.execute();
    if (response.isSuccessful()) {
        se = response.body();
        Episode ep = new Episode();
        ep.setNumber(episodeNum);
        episodeNum = episodeNum - 1;
        if (se.getEpisodes().get(episodeNum).getName() != null) {
            ep.setName(se.getEpisodes().get(episodeNum).getName());
        }
        double duration = getDurationEpisode(seriesId);
        if (duration != -1) {
            ep.setDuration(duration);
        }
        if (se.getEpisodes().get(episodeNum).getAirDate() != null) {
            ep.setReleaseDate(dateConversorService.releaseDateOMDBSeason(se.getEpisodes().get(episodeNum).getAirDate()));
        }
        String imdbId = getImdbId(seriesId, season.getNumber(), episodeNum);
        if (imdbId != null) {
            ep.setImdbId(imdbId);
        }
        ep.setSeason(season);
        if (se.getEpisodes().get(episodeNum).getOverview() != null) {
            ep.setDescription(stringApiCorrectorService.eraserEvilBytes(se.getEpisodes().get(episodeNum).getOverview()));
        }
        if (se.getEpisodes().get(episodeNum).getCrew() != null) {
            for (Crew crew : se.getEpisodes().get(episodeNum).getCrew()) {
                if (crew.getJob().equalsIgnoreCase("Director")) {
                    ep.setDirector(artistService.importDirector(crew.getName()));
                } else if (crew.getJob().equalsIgnoreCase("Writer")) {
                    ep.setScriptwriter(artistService.importScripwriter(crew.getName()));
                }
            }
        }
        ep = episodeRepository.save(ep);
        importActors(seriesId, ep);
        System.out.println("==================\nImportado..." + seriesName + " " + season.getNumber() + "x" + episodeNum + "\n==================");
    } else {
        throw new IOException(response.message());
    }
}
Also used : Episode(com.furyviewer.domain.Episode) Crew(com.furyviewer.service.dto.TheMovieDB.Season.Crew) SeasonTmdbDTO(com.furyviewer.service.dto.TheMovieDB.Season.SeasonTmdbDTO) IOException(java.io.IOException)

Example 8 with Episode

use of com.furyviewer.domain.Episode in project FuryViewer by TheDoctor-95.

the class EpisodeResource method createEpisode.

/**
 * POST  /episodes : Create a new episode.
 *
 * @param episode the episode to create
 * @return the ResponseEntity with status 201 (Created) and with body the new episode, or with status 400 (Bad Request) if the episode has already an ID
 * @throws URISyntaxException if the Location URI syntax is incorrect
 */
@PostMapping("/episodes")
@Timed
public ResponseEntity<Episode> createEpisode(@RequestBody Episode episode) throws URISyntaxException {
    log.debug("REST request to save Episode : {}", episode);
    if (episode.getId() != null) {
        throw new BadRequestAlertException("A new episode cannot already have an ID", ENTITY_NAME, "idexists");
    }
    Episode result = episodeRepository.save(episode);
    return ResponseEntity.created(new URI("/api/episodes/" + result.getId())).headers(HeaderUtil.createEntityCreationAlert(ENTITY_NAME, result.getId().toString())).body(result);
}
Also used : BadRequestAlertException(com.furyviewer.web.rest.errors.BadRequestAlertException) Episode(com.furyviewer.domain.Episode) URI(java.net.URI) Timed(com.codahale.metrics.annotation.Timed)

Aggregations

Episode (com.furyviewer.domain.Episode)8 Timed (com.codahale.metrics.annotation.Timed)3 Test (org.junit.Test)3 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)3 Transactional (org.springframework.transaction.annotation.Transactional)3 Season (com.furyviewer.domain.Season)1 ChapterSeenRepository (com.furyviewer.repository.ChapterSeenRepository)1 EpisodeRepository (com.furyviewer.repository.EpisodeRepository)1 SeriesStatsRepository (com.furyviewer.repository.SeriesStatsRepository)1 SecurityUtils (com.furyviewer.security.SecurityUtils)1 Crew (com.furyviewer.service.dto.TheMovieDB.Season.Crew)1 SeasonTmdbDTO (com.furyviewer.service.dto.TheMovieDB.Season.SeasonTmdbDTO)1 EpisodesHomeDTO (com.furyviewer.service.dto.util.EpisodesHomeDTO)1 BadRequestAlertException (com.furyviewer.web.rest.errors.BadRequestAlertException)1 IOException (java.io.IOException)1 URI (java.net.URI)1 LocalDate (java.time.LocalDate)1 ArrayList (java.util.ArrayList)1 Comparator (java.util.Comparator)1 List (java.util.List)1