Skip to content

Commit

Permalink
MAIN-T-121 Default search for Documents
Browse files Browse the repository at this point in the history
Update logic for document retrieval and search pattern

Removed logic that retrieves all documents for a user in `DocumentService` and `DocumentFacade`. Simplified search pattern in `SearchSpec` and `DocumentSearchController`. Adjusted the corresponding API interfaces and modified various configuration files.


Merge-request: MAIN-MR-74
Merged-by: Hanna Kurhuzenkava <[email protected]>
  • Loading branch information
hanna-eismant authored and Space Cloud committed Apr 26, 2024
1 parent d5b20c9 commit cea834a
Show file tree
Hide file tree
Showing 16 changed files with 228 additions and 105 deletions.
23 changes: 23 additions & 0 deletions server/.run/DokyApplication DEV.run.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="DokyApplication DEV" type="SpringBootApplicationConfigurationType"
factoryName="Spring Boot">
<option name="ACTIVE_PROFILES" value="dev"/>
<option name="FRAME_DEACTIVATION_UPDATE_POLICY" value="UpdateClassesAndResources"/>
<module name="doky.server.main"/>
<option name="SPRING_BOOT_MAIN_CLASS" value="org.hkurh.doky.DokyApplication"/>
<extension name="net.ashald.envfile">
<option name="IS_ENABLED" value="true"/>
<option name="IS_SUBST" value="false"/>
<option name="IS_PATH_MACRO_SUPPORTED" value="false"/>
<option name="IS_IGNORE_MISSING_FILES" value="false"/>
<option name="IS_ENABLE_EXPERIMENTAL_INTEGRATIONS" value="false"/>
<ENTRIES>
<ENTRY IS_ENABLED="true" PARSER="runconfig" IS_EXECUTABLE="false"/>
<ENTRY IS_ENABLED="true" PARSER="env" IS_EXECUTABLE="false" PATH="doky-dev.env"/>
</ENTRIES>
</extension>
<method v="2">
<option name="Make" enabled="true"/>
</method>
</configuration>
</component>
23 changes: 23 additions & 0 deletions server/.run/DokyApplication.run.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="DokyApplication" type="SpringBootApplicationConfigurationType"
factoryName="Spring Boot" nameIsGenerated="true">
<option name="ACTIVE_PROFILES" value="local"/>
<option name="FRAME_DEACTIVATION_UPDATE_POLICY" value="UpdateClassesAndResources"/>
<module name="doky.server.main"/>
<option name="SPRING_BOOT_MAIN_CLASS" value="org.hkurh.doky.DokyApplication"/>
<extension name="net.ashald.envfile">
<option name="IS_ENABLED" value="true"/>
<option name="IS_SUBST" value="false"/>
<option name="IS_PATH_MACRO_SUPPORTED" value="false"/>
<option name="IS_IGNORE_MISSING_FILES" value="false"/>
<option name="IS_ENABLE_EXPERIMENTAL_INTEGRATIONS" value="false"/>
<ENTRIES>
<ENTRY IS_ENABLED="true" PARSER="runconfig" IS_EXECUTABLE="false"/>
<ENTRY IS_ENABLED="true" PARSER="env" IS_EXECUTABLE="false" PATH="doky-local.env"/>
</ENTRIES>
</extension>
<method v="2">
<option name="Make" enabled="true"/>
</method>
</configuration>
</component>
34 changes: 34 additions & 0 deletions server/.run/server [apiTest].run.xml
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,38 @@
<RunAsTest>false</RunAsTest>
<method v="2"/>
</configuration>
<configuration default="false" name="server [apiTest]" type="GradleRunConfiguration" factoryName="Gradle">
<ExternalSystemSettings>
<option name="executionName"/>
<option name="externalProjectPath" value="$PROJECT_DIR$/server"/>
<option name="externalSystemIdString" value="GRADLE"/>
<option name="scriptParameters" value="-PrunApiTests=true"/>
<option name="taskDescriptions">
<list/>
</option>
<option name="taskNames">
<list>
<option value="apiTest"/>
</list>
</option>
<option name="vmOptions"/>
</ExternalSystemSettings>
<ExternalSystemDebugServerProcess>true</ExternalSystemDebugServerProcess>
<ExternalSystemReattachDebugProcess>true</ExternalSystemReattachDebugProcess>
<EXTENSION ID="com.intellij.execution.ExternalSystemRunConfigurationJavaExtension">
<extension name="net.ashald.envfile">
<option name="IS_ENABLED" value="false"/>
<option name="IS_SUBST" value="false"/>
<option name="IS_PATH_MACRO_SUPPORTED" value="false"/>
<option name="IS_IGNORE_MISSING_FILES" value="false"/>
<option name="IS_ENABLE_EXPERIMENTAL_INTEGRATIONS" value="false"/>
<ENTRIES>
<ENTRY IS_ENABLED="true" PARSER="runconfig" IS_EXECUTABLE="false"/>
</ENTRIES>
</extension>
</EXTENSION>
<DebugAllEnabled>false</DebugAllEnabled>
<RunAsTest>false</RunAsTest>
<method v="2"/>
</configuration>
</component>
34 changes: 34 additions & 0 deletions server/.run/server [integrationTest].run.xml
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,38 @@
<RunAsTest>false</RunAsTest>
<method v="2"/>
</configuration>
<configuration default="false" name="server [integrationTest]" type="GradleRunConfiguration" factoryName="Gradle">
<ExternalSystemSettings>
<option name="executionName"/>
<option name="externalProjectPath" value="$PROJECT_DIR$/server"/>
<option name="externalSystemIdString" value="GRADLE"/>
<option name="scriptParameters" value="-PrunIntegrationTests=true"/>
<option name="taskDescriptions">
<list/>
</option>
<option name="taskNames">
<list>
<option value="integrationTest"/>
</list>
</option>
<option name="vmOptions"/>
</ExternalSystemSettings>
<ExternalSystemDebugServerProcess>true</ExternalSystemDebugServerProcess>
<ExternalSystemReattachDebugProcess>true</ExternalSystemReattachDebugProcess>
<EXTENSION ID="com.intellij.execution.ExternalSystemRunConfigurationJavaExtension">
<extension name="net.ashald.envfile">
<option name="IS_ENABLED" value="false"/>
<option name="IS_SUBST" value="false"/>
<option name="IS_PATH_MACRO_SUPPORTED" value="false"/>
<option name="IS_IGNORE_MISSING_FILES" value="false"/>
<option name="IS_ENABLE_EXPERIMENTAL_INTEGRATIONS" value="false"/>
<ENTRIES>
<ENTRY IS_ENABLED="true" PARSER="runconfig" IS_EXECUTABLE="false"/>
</ENTRIES>
</extension>
</EXTENSION>
<DebugAllEnabled>false</DebugAllEnabled>
<RunAsTest>false</RunAsTest>
<method v="2"/>
</configuration>
</component>
90 changes: 68 additions & 22 deletions server/.run/server [test].run.xml
Original file line number Diff line number Diff line change
@@ -1,24 +1,70 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="server [test]" type="GradleRunConfiguration" factoryName="Gradle">
<ExternalSystemSettings>
<option name="executionName"/>
<option name="externalProjectPath" value="$PROJECT_DIR$/server"/>
<option name="externalSystemIdString" value="GRADLE"/>
<option name="scriptParameters" value=""/>
<option name="taskDescriptions">
<list/>
</option>
<option name="taskNames">
<list>
<option value="test"/>
</list>
</option>
<option name="vmOptions"/>
</ExternalSystemSettings>
<ExternalSystemDebugServerProcess>true</ExternalSystemDebugServerProcess>
<ExternalSystemReattachDebugProcess>true</ExternalSystemReattachDebugProcess>
<DebugAllEnabled>false</DebugAllEnabled>
<RunAsTest>false</RunAsTest>
<method v="2"/>
</configuration>
<configuration default="false" name="server [test]" type="GradleRunConfiguration" factoryName="Gradle">
<ExternalSystemSettings>
<option name="executionName"/>
<option name="externalProjectPath" value="$PROJECT_DIR$/server"/>
<option name="externalSystemIdString" value="GRADLE"/>
<option name="scriptParameters" value=""/>
<option name="taskDescriptions">
<list/>
</option>
<option name="taskNames">
<list>
<option value="test"/>
</list>
</option>
<option name="vmOptions"/>
</ExternalSystemSettings>
<ExternalSystemDebugServerProcess>true</ExternalSystemDebugServerProcess>
<ExternalSystemReattachDebugProcess>true</ExternalSystemReattachDebugProcess>
<EXTENSION ID="com.intellij.execution.ExternalSystemRunConfigurationJavaExtension">
<extension name="net.ashald.envfile">
<option name="IS_ENABLED" value="false"/>
<option name="IS_SUBST" value="false"/>
<option name="IS_PATH_MACRO_SUPPORTED" value="false"/>
<option name="IS_IGNORE_MISSING_FILES" value="false"/>
<option name="IS_ENABLE_EXPERIMENTAL_INTEGRATIONS" value="false"/>
<ENTRIES>
<ENTRY IS_ENABLED="true" PARSER="runconfig" IS_EXECUTABLE="false"/>
</ENTRIES>
</extension>
</EXTENSION>
<DebugAllEnabled>false</DebugAllEnabled>
<RunAsTest>false</RunAsTest>
<method v="2"/>
</configuration>
<configuration default="false" name="server [test]" type="GradleRunConfiguration" factoryName="Gradle">
<ExternalSystemSettings>
<option name="executionName"/>
<option name="externalProjectPath" value="$PROJECT_DIR$/server"/>
<option name="externalSystemIdString" value="GRADLE"/>
<option name="scriptParameters" value=""/>
<option name="taskDescriptions">
<list/>
</option>
<option name="taskNames">
<list>
<option value="test"/>
</list>
</option>
<option name="vmOptions"/>
</ExternalSystemSettings>
<ExternalSystemDebugServerProcess>true</ExternalSystemDebugServerProcess>
<ExternalSystemReattachDebugProcess>true</ExternalSystemReattachDebugProcess>
<EXTENSION ID="com.intellij.execution.ExternalSystemRunConfigurationJavaExtension">
<extension name="net.ashald.envfile">
<option name="IS_ENABLED" value="false"/>
<option name="IS_SUBST" value="false"/>
<option name="IS_PATH_MACRO_SUPPORTED" value="false"/>
<option name="IS_IGNORE_MISSING_FILES" value="false"/>
<option name="IS_ENABLE_EXPERIMENTAL_INTEGRATIONS" value="false"/>
<ENTRIES>
<ENTRY IS_ENABLED="true" PARSER="runconfig" IS_EXECUTABLE="false"/>
</ENTRIES>
</extension>
</EXTENSION>
<DebugAllEnabled>false</DebugAllEnabled>
<RunAsTest>false</RunAsTest>
<method v="2"/>
</configuration>
</component>
37 changes: 2 additions & 35 deletions server/src/apiTest/kotlin/org/hkurh/doky/DocumentSpec.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,12 @@ package org.hkurh.doky
import io.restassured.RestAssured.given
import org.hamcrest.CoreMatchers.notNullValue
import org.hkurh.doky.documents.api.DocumentRequest
import org.hkurh.doky.documents.db.DocumentEntityRepository
import org.hkurh.doky.users.db.UserEntityRepository
import org.junit.Rule
import org.junit.jupiter.api.AfterEach
import org.junit.jupiter.api.Assertions.assertEquals
import org.junit.jupiter.api.Assertions.assertNotNull
import org.junit.jupiter.api.Assertions.assertNull
import org.junit.jupiter.api.DisplayName
import org.junit.jupiter.api.Test
import org.junit.rules.TemporaryFolder
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.beans.factory.annotation.Value
import org.springframework.http.HttpStatus
import org.springframework.test.context.jdbc.Sql
Expand All @@ -33,28 +28,20 @@ class DocumentSpec : RestSpec() {
val documentFileNameProperty = "fileName"
val existedDocumentNameFirst = "Test_1"
val existedDocumentFileNameFirst = "test.txt"
val existedDocumentNameSecond = "Test_2"
val existedDocumentNameThird = "Test_3"
val existedDocumentNameFour = "Test_4"
val newDocumentName = "Apples"
val newDocumentDescription = "Do you like apples?"
val uploadFileName = "test_1.txt"

@Value("\${doky.filestorage.path}")
val fileStoragePath: String? = null
lateinit var fileStoragePath: String

@Rule
var temporaryFolder = TemporaryFolder()

@Autowired
lateinit var documentEntityRepository: DocumentEntityRepository

@Autowired
lateinit var userEntityRepository: UserEntityRepository

@AfterEach
fun tearDown() {
fileStoragePath?.let {
fileStoragePath.let {
FileSystemUtils.deleteRecursively(Paths.get(it))
}
}
Expand Down Expand Up @@ -100,26 +87,6 @@ class DocumentSpec : RestSpec() {
assertEquals(existedDocumentFileNameFirst, fileName)
}

@Test
@DisplayName("Should get all existing documents for user")
@Sql(scripts = ["classpath:sql/DocumentSpec/setup.sql"], executionPhase = Sql.ExecutionPhase.BEFORE_TEST_METHOD)
fun shouldGetAllExistingDocumentsForUser() {
// given
val requestSpec = prepareRequestSpecWithLogin().build()

// when:
val response = given(requestSpec).get(endpoint)

// then
response.then().statusCode(HttpStatus.OK.value())
val documents: List<Map<String, String>> = response.path(".")

assertNotNull(documents.find { d -> (existedDocumentNameFirst == d[documentNameProperty]) })
assertNotNull(documents.find { d -> (existedDocumentNameSecond == d[documentNameProperty]) })
assertNull(documents.find { d -> (existedDocumentNameThird == d[documentNameProperty]) })
assertNull(documents.find { d -> (existedDocumentNameFour == d[documentNameProperty]) })
}

@Test
@DisplayName("Should return 404 when get existing document that belongs to another user")
@Sql(scripts = ["classpath:sql/DocumentSpec/setup.sql"], executionPhase = Sql.ExecutionPhase.BEFORE_TEST_METHOD)
Expand Down
33 changes: 28 additions & 5 deletions server/src/apiTest/kotlin/org/hkurh/doky/SearchSpec.kt
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,12 @@ import org.springframework.test.context.jdbc.Sql

@DisplayName("Document Search API test")
class SearchSpec : RestSpec() {
val endpoint = "/documents/search"
val endpoint = "/documents"
val documentNameProperty = "name"
val documentName1 = "Test note 1"
val documentName2 = "Test note 2"
val documentNameFirst = "Test note 1"
val documentNameSecond = "Lorem"
val documentNameThird = "Test note 2"
val documentNameFour = "Cras at nulla ex"

@Value("\${doky.search.solr.core.documents:documents-test}")
lateinit var coreName: String
Expand All @@ -35,6 +37,27 @@ class SearchSpec : RestSpec() {
documentIndexer.fullIndex()
}

@Test
@DisplayName("Should get all existing documents for user")
@Sql(scripts = ["classpath:sql/SearchSpec/setup.sql"], executionPhase = Sql.ExecutionPhase.BEFORE_TEST_METHOD)
@Sql(scripts = ["classpath:sql/SearchSpec/cleanup.sql"], executionPhase = Sql.ExecutionPhase.AFTER_TEST_METHOD)
fun shouldGetAllExistingDocumentsForUser() {
// given
val requestSpec = prepareRequestSpecWithLogin().build()

// when:
val response = given(requestSpec).get(endpoint)

// then
response.then().statusCode(HttpStatus.OK.value())
val documents: List<Map<String, String>> = response.path(".")

assertNotNull(documents.find { d -> (documentNameFirst == d[documentNameProperty]) })
assertNotNull(documents.find { d -> (documentNameSecond == d[documentNameProperty]) })
assertNull(documents.find { d -> (documentNameThird == d[documentNameProperty]) })
assertNull(documents.find { d -> (documentNameFour == d[documentNameProperty]) })
}

@Test
@DisplayName("Should return only documents that allowed to user")
@Sql(scripts = ["classpath:sql/SearchSpec/setup.sql"], executionPhase = Sql.ExecutionPhase.BEFORE_TEST_METHOD)
Expand All @@ -50,8 +73,8 @@ class SearchSpec : RestSpec() {
response.then().statusCode(HttpStatus.OK.value())
val documents: List<Map<String, String>> = response.path(".")

assertNotNull(documents.find { d -> (documentName1 == d[documentNameProperty]) })
assertNull(documents.find { d -> (documentName2 == d[documentNameProperty]) })
assertNotNull(documents.find { d -> (documentNameFirst == d[documentNameProperty]) })
assertNull(documents.find { d -> (documentNameThird == d[documentNameProperty]) })
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,6 @@ interface DocumentFacade {
*/
fun findDocument(id: String): DocumentResponse?

/**
* Retrieves a list of all documents.
*
* @return A list of [DocumentResponse] objects representing the retrieved documents. The list may contain null values if the document retrieval failed.
*/
fun findAllDocuments(): List<DocumentResponse?>

/**
* Saves a file and attach it to document with the given ID.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,6 @@ interface DocumentService {
*/
fun find(id: String): DocumentEntity?

/**
* Finds all documents.
*
* @return A list of [DocumentEntity] objects representing the found documents.
*/
fun find(): List<DocumentEntity>

/**
* Saves the given document.
*
Expand Down
Loading

0 comments on commit cea834a

Please sign in to comment.