<commit_before>package jp.ijufumi.openreports.service.settings

import java.sql.SQLException

import jp.ijufumi.openreports.model.TReportGroup
import jp.ijufumi.openreports.service.enums.StatusCode
import jp.ijufumi.openreports.vo.ReportGroupInfo
import org.joda.time.DateTime
import skinny.logging.Logging

class ReportGroupSettingsService extends Logging {
  def getGroups: Seq[ReportGroupInfo] = {
    TReportGroup
      .findAll()
      .map(r => ReportGroupInfo(r.reportGroupId, r.reportGroupName, r.versions))
  }

  def getGroup(reportGroupId: Long): Option[ReportGroupInfo] = {
    TReportGroup
      .findById(reportGroupId)
      .map(r => ReportGroupInfo(r.reportGroupId, r.reportGroupName, r.versions))
  }

  def registerGroup(reportGroupName: String): StatusCode.Value = {
    try {
      TReportGroup.createWithAttributes('reportGroupName -> reportGroupName)
    } catch {
      case e: SQLException => return StatusCode.of(e)
      case _               => return StatusCode.OTHER_ERROR
    }

    StatusCode.OK
  }

  def updateGroup(
      reportGroupId: Long,
      reportGroupName: String,
      versions: Long
  ): StatusCode.Value = {
    try {
      val groupOpt = TReportGroup.findById(reportGroupId)
      if (groupOpt.isEmpty) {
        return StatusCode.DATA_NOT_FOUND
      }

      val group = groupOpt.get

      val count = TReportGroup
        .updateByIdAndVersion(reportGroupId, versions)
        .withAttributes('reportGroupName -> reportGroupName,
                        'updatedAt -> DateTime.now())

      if (count != 1) {
        return StatusCode.ALREADY_UPDATED
      }
    } catch {
      case e: SQLException => return StatusCode.of(e)
      case _               => return StatusCode.OTHER_ERROR
    }

    StatusCode.OK
  }
}<commit_msg>Add register report-group function(services class).<commit_after>package jp.ijufumi.openreports.service.settings

import java.sql.SQLException

import jp.ijufumi.openreports.model.TReportGroup
import jp.ijufumi.openreports.service.enums.StatusCode
import jp.ijufumi.openreports.vo.ReportGroupInfo
import org.joda.time.DateTime
import skinny.logging.Logging

class ReportGroupSettingsService extends Logging {
  def getGroups: Seq[ReportGroupInfo] = {
    TReportGroup
      .findAll()
      .map(r => ReportGroupInfo(r.reportGroupId, r.reportGroupName, r.versions))
  }

  def getGroup(reportGroupId: Long): Option[ReportGroupInfo] = {
    TReportGroup
      .findById(reportGroupId)
      .map(r => ReportGroupInfo(r.reportGroupId, r.reportGroupName, r.versions))
  }

  def registerGroup(reportGroupName: String): StatusCode.Value = {
    try {
      TReportGroup.createWithAttributes('reportGroupName -> reportGroupName)
    } catch {
      case e: SQLException => return StatusCode.of(e)
      case _               => return StatusCode.OTHER_ERROR
    }

    StatusCode.OK
  }

  def updateGroup(
      reportGroupId: Long,
      reportGroupName: String,
      versions: Long
  ): StatusCode.Value = {
    try {
      val groupOpt = TReportGroup.findById(reportGroupId)
      if (groupOpt.isEmpty) {
        return StatusCode.DATA_NOT_FOUND
      }

      val count = TReportGroup
        .updateByIdAndVersion(reportGroupId, versions)
        .withAttributes('reportGroupName -> reportGroupName,
                        'updatedAt -> DateTime.now())

      if (count != 1) {
        return StatusCode.ALREADY_UPDATED
      }
    } catch {
      case e: SQLException => return StatusCode.of(e)
      case _               => return StatusCode.OTHER_ERROR
    }

    StatusCode.OK
  }
}
{'fraction_non_alphanumeric': 0.09299719887955182, 'fraction_numerical': 0.0005602240896358543, 'mean_word_length': 2.9027322404371585, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 21, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, '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': '21758', 'n_tokens_mistral': 1078, 'n_tokens_neox': 1053, 'n_words': 197}