<commit_before>package streama

import grails.converters.JSON

import static org.springframework.http.HttpStatus.*
import grails.transaction.Transactional

@Transactional(readOnly = true)
class MovieController {
  def videoService

  static responseFormats = ['json', 'xml']
  static allowedMethods = [save: "POST", update: "PUT", delete: "DELETE"]

  def index() {
    return videoService.listMovies(params, [includeEmpty: true])
  }

  @Transactional
  def save(Movie movieInstance) {
    if (movieInstance == null) {
      render status: NOT_FOUND
      return
    }

    if (!movieInstance.imdb_id && movieInstance.apiId) {
      movieInstance.imdb_id = movieInstance.fullMovieMeta?.imdb_id
    }

    movieInstance.validate()
    if (movieInstance.hasErrors()) {
      render status: NOT_ACCEPTABLE
      return
    }

    movieInstance.save flush: true
    respond movieInstance, [status: CREATED]
  }

  def show(Movie movie) {
    if(!movie){
      render status: NOT_FOUND
      return
    }
    respond movie, [status: OK]
  }

  @Transactional<commit_msg>fix nullpointer issue for tags during movieSave<commit_after>package streama

import grails.converters.JSON

import static org.springframework.http.HttpStatus.*
import grails.transaction.Transactional

@Transactional(readOnly = true)
class MovieController {
  def videoService

  static responseFormats = ['json', 'xml']
  static allowedMethods = [save: "POST", update: "PUT", delete: "DELETE"]

  def index() {
    return videoService.listMovies(params, [includeEmpty: true])
  }

  @Transactional
  def save() {
    def data = request.JSON
    Movie movieInstance = Movie.findOrCreateById(data.id)
    if (movieInstance == null) {
      render status: NOT_FOUND
      return
    }

    if (!movieInstance.imdb_id && movieInstance.apiId) {
      movieInstance.imdb_id = movieInstance.fullMovieMeta?.imdb_id
    }

    movieInstance.validate()
    if (movieInstance.hasErrors()) {
      render status: NOT_ACCEPTABLE
      return
    }

    List tags = []
    data.tags?.each{ tagData ->
      Tag tag = Tag.findByIdOrName(tagData.id, tagData.name)
      if(!tag){
        tag = new Tag(tagData)
        tag.save(flush: true, failOnError: true)
      }

      tags.add(tag)
    }

    data.tags = tags*.id
    movieInstance.properties = data

    movieInstance.save flush: true
    respond movieInstance, [status: CREATED]
  }

  def show(Movie movie) {
    if(!movie){
      render status: NOT_FOUND
      return
    }
    respond movie, [status: OK]
  }

  @Transactional
{'fraction_non_alphanumeric': 0.10358408822371012, 'fraction_numerical': 0.0, 'mean_word_length': 3.184514003294893, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 4, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 2}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1212264', 'n_tokens_mistral': 800, 'n_tokens_neox': 763, 'n_words': 183}