All Downloads are FREE. Search and download functionalities are using the official Maven repository.

cccev.projection.api.entity.requirement.RequirementRepository.kt Maven / Gradle / Ivy

package cccev.projection.api.entity.requirement

import cccev.projection.api.entity.NodeLabel
import cccev.projection.api.entity.Relation
import cccev.projection.api.entity.SnapRepositoryBase
import cccev.s2.requirement.domain.RequirementId
import cccev.s2.requirement.domain.model.RequirementIdentifier
import org.springframework.data.neo4j.repository.ReactiveNeo4jRepository
import org.springframework.data.neo4j.repository.query.Query
import org.springframework.stereotype.Repository
import org.springframework.stereotype.Service
import reactor.core.publisher.Flux
import reactor.core.publisher.Mono

@Repository
interface RequirementRepository: ReactiveNeo4jRepository {

    fun findByIdentifier(identifier: RequirementIdentifier): Mono

    // TODO also fetch other relations (info concepts, evidence type lists, ...) or it won't be filled in the entities
    @Query("" +
            "MATCH (root:${NodeLabel.REQUIREMENT}) WHERE root.identifier IN \$ids\n" +
            "OPTIONAL MATCH (root)-[hr:${Relation.HAS_REQUIREMENT}*1..]->(child:${NodeLabel.REQUIREMENT} {type: \$type})" +
            "OPTIONAL MATCH (root)-[r]->(other)" +
            "RETURN root, collect(hr), collect(child), collect(r), collect(other)"
    )
    fun findByIdentifierWithChildrenOfType(ids: Collection, type: String): Flux
    @Query("" +
            "MATCH (root:${NodeLabel.REQUIREMENT}) WHERE root.id IN \$ids\n" +
            "OPTIONAL MATCH (root)-[hr:${Relation.HAS_REQUIREMENT}*1..]->(child:${NodeLabel.REQUIREMENT} {type: \$type})" +
            "OPTIONAL MATCH (root)-[r]->(other)" +
            "RETURN root, collect(hr), collect(child)"
    )
    fun findByIdWithChildrenOfType(ids: Collection, type: String): Flux

    // TODO also fetch other relations (info concepts, evidence type lists, ...) or it won't be filled in the entity
    @Query("" +
            "MATCH (root:${NodeLabel.REQUIREMENT} WHERE root.identifier IN \$ids)" +
            "-[hr:${Relation.HAS_REQUIREMENT}*1..]->" +
            "(child:${NodeLabel.REQUIREMENT} {type: \$type})\n" +
            "RETURN child, collect(hr)"
    )
    fun findAllChildrenOfType(ids: Collection, type: String): Flux
}

@Service
class RequirementSnapRepository(
    override val repository: RequirementRepository
): SnapRepositoryBase()




© 2015 - 2025 Weber Informatics LLC | Privacy Policy