<commit_before>package com.lucidchart.open.nark.utils

import com.lucidchart.open.nark.models.records.Dashboard

import java.util.Date
import java.util.UUID

import scala.util.Random

import play.api.Play.configuration
import play.api.Play.current
import play.api.mvc.Cookie
import play.api.mvc.CookieBaker
import play.api.mvc.Cookies
import play.api.mvc.DiscardingCookie
import play.api.mvc.RequestHeader

case class DashboardHistoryItem(dashboardId: UUID, url: String, name: String) {
	def this(d: Dashboard) = this(d.id, d.url, d.name)
}

object DashboardHistory {
	protected val maxItems = configuration.getInt("dashboardhistory.count").get

	object DashboardHistoryCookieBaker extends CookieBaker[List[DashboardHistoryItem]] {
		val COOKIE_NAME = "dashboardhistory"
		val emptyCookie = Nil
		override val secure = false
		override val isSigned = true
		override val httpOnly = true
		override val path = configuration.getString("application.context").get
		override val domain = None
		override val maxAge = Some(315360000)
		
		def deserialize(data: Map[String, String]) = {
			val unserialized = for (i <- 0 until data.size) yield {
				val itemString = data(i.toString)
				val parts = itemString.split("\\|", 3)
				DashboardHistoryItem(
					UUID.fromString(parts(0)),
					parts(1),
					parts(2)<commit_msg>handle empty dashboard history cookie<commit_after>package com.lucidchart.open.nark.utils

import com.lucidchart.open.nark.models.records.Dashboard

import java.util.Date
import java.util.UUID

import scala.util.Random

import play.api.Play.configuration
import play.api.Play.current
import play.api.mvc.Cookie
import play.api.mvc.CookieBaker
import play.api.mvc.Cookies
import play.api.mvc.DiscardingCookie
import play.api.mvc.RequestHeader

case class DashboardHistoryItem(dashboardId: UUID, url: String, name: String) {
	def this(d: Dashboard) = this(d.id, d.url, d.name)
}

object DashboardHistory {
	protected val maxItems = configuration.getInt("dashboardhistory.count").get

	object DashboardHistoryCookieBaker extends CookieBaker[List[DashboardHistoryItem]] {
		val COOKIE_NAME = "dashboardhistory"
		val emptyCookie = Nil
		override val secure = false
		override val isSigned = true
		override val httpOnly = true
		override val path = configuration.getString("application.context").get
		override val domain = None
		override val maxAge = Some(315360000)
		
		def deserialize(data: Map[String, String]) = {
			val nonEmptyData = data.filter(!_._1.isEmpty)
			val unserialized = for (i <- 0 until nonEmptyData.size) yield {
				val itemString = nonEmptyData(i.toString)
				val parts = itemString.split("\\|", 3)
				DashboardHistoryItem(
					UUID.fromString(parts(0)),
					parts(1),
					parts(2)
{'fraction_non_alphanumeric': 0.10084341767510084, 'fraction_numerical': 0.010634396773010634, 'mean_word_length': 4.624742268041237, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, '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': '4261278', 'n_tokens_mistral': 949, 'n_tokens_neox': 858, 'n_words': 208}