Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import com.epam.brn.enums.WordType

data class ResourceResponse(
var id: Long? = null,
var audioFileUrl: String? = "",
val word: String? = "",
val wordPronounce: String? = "",
val wordType: WordType?,
Expand Down
12 changes: 3 additions & 9 deletions src/main/kotlin/com/epam/brn/model/Resource.kt
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,16 @@ import javax.persistence.UniqueConstraint

@Entity
@Table(
uniqueConstraints = [UniqueConstraint(columnNames = ["word", "audioFileUrl", "wordType"])],
uniqueConstraints = [UniqueConstraint(columnNames = ["word", "wordType"])],
indexes = [
Index(name = "word_audio_file_idx", columnList = "word, audioFileUrl, wordType"),
Index(name = "audio_file_idx", columnList = "audioFileUrl")
Index(name = "word_idx", columnList = "word, wordType")
]
)
data class Resource(
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
var id: Long? = null,
@Column(nullable = false)
var audioFileUrl: String? = "",
@Column(nullable = false)
var word: String = "",
var wordType: String = "",
var locale: String = "",
Expand All @@ -39,7 +36,6 @@ data class Resource(
) {
fun toResponse() = ResourceResponse(
id = id,
audioFileUrl = audioFileUrl,
word = word.replace("+", ""),
wordPronounce = word,
pictureFileUrl = pictureFileUrl,
Expand All @@ -48,7 +44,7 @@ data class Resource(
description = description
)

override fun toString() = "Resource(id=$id, audioFileUrl='$audioFileUrl', word='$word'," +
override fun toString() = "Resource(id=$id, word='$word'," +
" pictureFileUrl='$pictureFileUrl', soundsCount=$soundsCount), description='$description'"

override fun equals(other: Any?): Boolean {
Expand All @@ -58,7 +54,6 @@ data class Resource(
other as Resource

if (id != other.id) return false
if (audioFileUrl != other.audioFileUrl) return false
if (word != other.word) return false
if (wordType != other.wordType) return false
if (pictureFileUrl != other.pictureFileUrl) return false
Expand All @@ -70,7 +65,6 @@ data class Resource(

override fun hashCode(): Int {
var result = id?.hashCode() ?: 0
result = 31 * result + (audioFileUrl?.hashCode() ?: 0)
result = 31 * result + (word.hashCode())
result = 31 * result + wordType.hashCode()
result = 31 * result + (pictureFileUrl?.hashCode() ?: 0)
Expand Down
4 changes: 0 additions & 4 deletions src/main/kotlin/com/epam/brn/repo/ResourceRepository.kt
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,5 @@ interface ResourceRepository : CrudRepository<Resource, Long> {

fun findFirstByWordAndWordType(word: String, wordType: String): Optional<Resource>

fun findFirstByWordAndAudioFileUrlLike(word: String, audioFileUrl: String): Optional<Resource>

fun findFirstByWordAndWordTypeAndAudioFileUrlLike(word: String, wordType: String, audioFileUrl: String): Optional<Resource>

fun findFirstByWordAndLocaleAndWordType(word: String, locale: String, wordType: String): Optional<Resource>
}
6 changes: 0 additions & 6 deletions src/main/kotlin/com/epam/brn/service/ResourceService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,6 @@ class ResourceService(private val resourceRepository: ResourceRepository) {
return if (resources.isNotEmpty()) resources.first() else null
}

fun findFirstByWordAndAudioFileUrlLike(word: String, audioFileName: String): Resource? {
return resourceRepository
.findFirstByWordAndAudioFileUrlLike(word, audioFileName)
.orElse(null)
}

fun save(resource: Resource): Resource = resourceRepository.save(resource)

fun updateDescription(id: Long, description: String): ResourceResponse {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.epam.brn.upload.csv.audiometrySpeech

import com.epam.brn.dto.AudioFileMetaData
import com.epam.brn.enums.AudiometryType
import com.epam.brn.enums.BrnLocale
import com.epam.brn.model.AudiometryTask
Expand Down Expand Up @@ -62,20 +61,11 @@ class LopotkoRecordProcessor(
val hashWord = DigestUtils.md5Hex(word)
mapHashWord[word] = hashWord
val wordType = WordType.AUDIOMETRY_WORD.toString()
val audioFileUrl =
wordsService.getSubFilePathForWord(
AudioFileMetaData(
word,
locale.locale,
wordsService.getDefaultManVoiceForLocale(locale.locale)
)
)
val resource = resourceRepository.findFirstByWordAndWordTypeAndAudioFileUrlLike(word, wordType, audioFileUrl)
val resource = resourceRepository.findFirstByWordAndWordType(word, wordType)
.orElse(
Resource(
word = word,
audioFileUrl = audioFileUrl,
locale = locale.locale,
locale = locale.locale
)
)
resource.wordType = wordType
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,6 @@ class SeriesMatrixRecordProcessor(
locale = locale.locale
)
)
resource.audioFileUrl = audioPath
resource.wordType = wordType.name
return resource
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,6 @@ class SeriesPhrasesRecordProcessor(
pictureFileUrl = pictureDefaultPath
)
)
resource.audioFileUrl = audioPath
resource.wordType = wordType
return resource
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,6 @@ class SeriesWordsRecordProcessor(
locale = locale.locale,
)
)
resource.audioFileUrl = audioPath
resource.wordType = WordType.OBJECT.toString()
return resource
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@ class SeriesWordsKorolevaRecordProcessor(
locale = locale.locale,
)
)
resource.audioFileUrl = audioPath
resource.wordType = WordType.OBJECT.toString()
return resource
}
Expand Down
8 changes: 8 additions & 0 deletions src/main/resources/db/migration/V220221129_2385.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
DROP INDEX audio_file_idx;
DROP INDEX word_audio_file_idx;
CREATE INDEX word_idx on resource (word, word_type);

ALTER TABLE resource DROP CONSTRAINT resource_constrain;
ALTER TABLE resource ADD CONSTRAINT resource_constrain unique (word, word_type);

ALTER TABLE resource DROP COLUMN audio_file_url;
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class ResourceControllerIT : BaseIT() {
@Test
fun `should update resource description successfully`() {
// GIVEN
val resource = resourceRepository.save(Resource(description = "description", wordType = "OBJECT"))
val resource = resourceRepository.save(Resource(description = "description", wordType = "OBJECT", word = "word"))
val descriptionForUpdate = "new description"
val requestJson = objectMapper.writeValueAsString(UpdateResourceDescriptionRequest(descriptionForUpdate))

Expand Down
6 changes: 3 additions & 3 deletions src/test/kotlin/com/epam/brn/repo/BaseTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,11 @@ abstract class BaseTest {
subGroup1.exercises.addAll(listOf(exercise1, exercise2))

val firstResource =
Resource(audioFileUrl = "audio_f", word = listOfWords[0], pictureFileUrl = "picture_f", soundsCount = 0)
Resource(word = listOfWords[0], pictureFileUrl = "picture_f", soundsCount = 0)
val secondResource =
Resource(audioFileUrl = "audio_s", word = listOfWords[1], pictureFileUrl = "picture_s", soundsCount = 0)
Resource(word = listOfWords[1], pictureFileUrl = "picture_s", soundsCount = 0)
val thirdResource =
Resource(audioFileUrl = "audio_t", word = listOfWords[2], pictureFileUrl = "picture_t", soundsCount = 0)
Resource(word = listOfWords[2], pictureFileUrl = "picture_t", soundsCount = 0)

resourceRepository.saveAll(listOf(firstResource, secondResource, thirdResource))

Expand Down
31 changes: 0 additions & 31 deletions src/test/kotlin/com/epam/brn/service/ResourceServiceTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import org.junit.jupiter.api.Test
import org.junit.jupiter.api.assertThrows
import org.junit.jupiter.api.extension.ExtendWith
import org.springframework.data.repository.findByIdOrNull
import java.util.Optional

@ExtendWith(MockKExtension::class)
internal class ResourceServiceTest {
Expand Down Expand Up @@ -57,36 +56,6 @@ internal class ResourceServiceTest {
foundFirstResource shouldBe null
}

@Test
fun `should return resource by word and audio file url`() {
// GIVEN
val word = "word"
val audioFileName = "audioFileName"
every { resourceRepositoryMock.findFirstByWordAndAudioFileUrlLike(word, audioFileName) } returns Optional.of(
resourceMock
)

// WHEN
val foundResource = resourceService.findFirstByWordAndAudioFileUrlLike(word, audioFileName)

// THEN
foundResource shouldBe resourceMock
}

@Test
fun `should return null if word and audio file url is not found`() {
// GIVEN
val word = "word"
val audioFileName = "audioFileName"
every { resourceRepositoryMock.findFirstByWordAndAudioFileUrlLike(word, audioFileName) } returns Optional.empty()

// WHEN
val foundResource = resourceService.findFirstByWordAndAudioFileUrlLike(word, audioFileName)

// THEN
foundResource shouldBe null
}

@Test
fun `should save resource`() {
// GIVEN
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,7 @@ internal class LopotkoRecordProcessorTest {
)
} returns audiometry
every {
resourceRepositoryMock.findFirstByWordAndWordTypeAndAudioFileUrlLike(
ofType(String::class),
resourceRepositoryMock.findFirstByWordAndWordType(
ofType(String::class),
ofType(String::class)
)
Expand Down Expand Up @@ -144,7 +143,6 @@ internal class LopotkoRecordProcessorTest {
return Resource(
word = "бал",
wordType = WordType.OBJECT.toString(),
audioFileUrl = "/audio/filipp/518d3c4523afcd59e2feae1093870f5f.ogg",
pictureFileUrl = "pictures/бал.jpg"
)
}
Expand All @@ -153,7 +151,6 @@ internal class LopotkoRecordProcessorTest {
return Resource(
word = "бум",
wordType = WordType.OBJECT.toString(),
audioFileUrl = "/audio/filipp/8e3cba18a3a6a3aa51e160a3d1e1ebcc.ogg",
pictureFileUrl = "pictures/бум.jpg"
)
}
Expand All @@ -162,7 +159,6 @@ internal class LopotkoRecordProcessorTest {
return Resource(
word = "быль",
wordType = WordType.OBJECT.toString(),
audioFileUrl = "/audio/filipp/4df3cdbbe2abf27f91f673032c95141e.ogg",
pictureFileUrl = "pictures/быль.jpg"
)
}
Expand All @@ -171,7 +167,6 @@ internal class LopotkoRecordProcessorTest {
return Resource(
word = "вить",
wordType = WordType.OBJECT.toString(),
audioFileUrl = "/audio/filipp/77ebaea90791bb15d4f758191aae5930.ogg",
pictureFileUrl = "pictures/вить.jpg"
)
}
Expand All @@ -180,7 +175,6 @@ internal class LopotkoRecordProcessorTest {
return Resource(
word = "гад",
wordType = WordType.OBJECT.toString(),
audioFileUrl = "/audio/filipp/2e0b56e224fe469866e1aaa81caaafcc.ogg",
pictureFileUrl = "pictures/гад.jpg"
)
}
Expand All @@ -189,7 +183,6 @@ internal class LopotkoRecordProcessorTest {
return Resource(
word = "дуб",
wordType = WordType.OBJECT.toString(),
audioFileUrl = "/audio/filipp/494d676049e14da7fd3a9182955287ab.ogg",
pictureFileUrl = "pictures/дуб.jpg"
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,6 @@ internal class SeriesMatrixRecordProcessorTest {
return Resource(
word = "девочка",
wordType = WordType.OBJECT.toString(),
audioFileUrl = "audio/ogg/filipp/девочка.ogg",
pictureFileUrl = "pictures/withWord/девочка.jpg"
)
}
Expand All @@ -226,7 +225,6 @@ internal class SeriesMatrixRecordProcessorTest {
return Resource(
word = "бабушка",
wordType = WordType.OBJECT.toString(),
audioFileUrl = "audio/ogg/filipp/бабушка.ogg",
pictureFileUrl = "pictures/withWord/бабушка.jpg"
)
}
Expand All @@ -235,7 +233,6 @@ internal class SeriesMatrixRecordProcessorTest {
return Resource(
word = "дедушка",
wordType = WordType.OBJECT.toString(),
audioFileUrl = "audio/ogg/filipp/дедушка.ogg",
pictureFileUrl = "pictures/withWord/дедушка.jpg"
)
}
Expand All @@ -244,7 +241,6 @@ internal class SeriesMatrixRecordProcessorTest {
return Resource(
word = "сидит",
wordType = WordType.OBJECT_ACTION.toString(),
audioFileUrl = "audio/ogg/filipp/сидит.ogg",
pictureFileUrl = "pictures/withWord/сидит.jpg"
)
}
Expand All @@ -253,7 +249,6 @@ internal class SeriesMatrixRecordProcessorTest {
return Resource(
word = "лежит",
wordType = WordType.OBJECT_ACTION.toString(),
audioFileUrl = "audio/ogg/filipp/лежит.ogg",
pictureFileUrl = "pictures/withWord/лежит.jpg"
)
}
Expand All @@ -262,7 +257,6 @@ internal class SeriesMatrixRecordProcessorTest {
return Resource(
word = "идет",
wordType = WordType.OBJECT_ACTION.toString(),
audioFileUrl = "audio/ogg/filipp/идет.ogg",
pictureFileUrl = "pictures/withWord/идет.jpg"
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,6 @@ internal class SeriesWordsRecordProcessorTest {
return Resource(
word = "бал",
wordType = WordType.OBJECT.toString(),
audioFileUrl = "/test/бал.ogg",
pictureFileUrl = "pictures/бал.jpg"
)
}
Expand All @@ -294,7 +293,6 @@ internal class SeriesWordsRecordProcessorTest {
return Resource(
word = "бум",
wordType = WordType.OBJECT.toString(),
audioFileUrl = "/test/бум.ogg",
pictureFileUrl = "pictures/бум.jpg"
)
}
Expand All @@ -303,7 +301,6 @@ internal class SeriesWordsRecordProcessorTest {
return Resource(
word = "быль",
wordType = WordType.OBJECT.toString(),
audioFileUrl = "/test/быль.ogg",
pictureFileUrl = "pictures/быль.jpg"
)
}
Expand All @@ -312,7 +309,6 @@ internal class SeriesWordsRecordProcessorTest {
return Resource(
word = "вить",
wordType = WordType.OBJECT.toString(),
audioFileUrl = "/test/вить.ogg",
pictureFileUrl = "pictures/вить.jpg"
)
}
Expand All @@ -321,7 +317,6 @@ internal class SeriesWordsRecordProcessorTest {
return Resource(
word = "гад",
wordType = WordType.OBJECT.toString(),
audioFileUrl = "/test/гад.ogg",
pictureFileUrl = "pictures/гад.jpg"
)
}
Expand All @@ -330,7 +325,6 @@ internal class SeriesWordsRecordProcessorTest {
return Resource(
word = "дуб",
wordType = WordType.OBJECT.toString(),
audioFileUrl = "/test/дуб.ogg",
pictureFileUrl = "pictures/дуб.jpg"
)
}
Expand Down
Loading