-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add find method to retrieve all distinct positions
- Loading branch information
1 parent
f04d7aa
commit e3528a3
Showing
12 changed files
with
1,554 additions
and
1,474 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 8 additions & 1 deletion
9
backend/src/main/kotlin/fr/gouv/cnsp/monitorfish/domain/use_cases/ParseAndSavePosition.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,23 @@ | ||
package fr.gouv.cnsp.monitorfish.domain.use_cases | ||
|
||
import fr.gouv.cnsp.monitorfish.config.UseCase | ||
import fr.gouv.cnsp.monitorfish.domain.entities.Position | ||
import fr.gouv.cnsp.monitorfish.domain.exceptions.NAFMessageParsingException | ||
import fr.gouv.cnsp.monitorfish.domain.mappers.NAFMessageMapper | ||
import fr.gouv.cnsp.monitorfish.domain.repositories.PositionsRepository | ||
import org.slf4j.Logger | ||
import org.slf4j.LoggerFactory | ||
|
||
@UseCase | ||
class ParseAndSavePosition(private val positionsRepository: PositionsRepository) { | ||
private val logger: Logger = LoggerFactory.getLogger(ParseAndSavePosition::class.java) | ||
|
||
@Throws(NAFMessageParsingException::class) | ||
fun execute(naf: String) { | ||
val position = NAFMessageMapper(naf).toPosition() | ||
if (position.internalReferenceNumber == null) { | ||
logger.warn("No internal reference number for position $position") | ||
} | ||
positionsRepository.save(position) | ||
logger.debug("Saved new position $position") | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 46 additions & 1 deletion
47
...lin/fr/gouv/cnsp/monitorfish/infrastructure/database/repositories/DBPositionRepository.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,51 @@ | ||
package fr.gouv.cnsp.monitorfish.infrastructure.database.repositories | ||
|
||
import fr.gouv.cnsp.monitorfish.infrastructure.database.entities.PositionEntity | ||
import org.springframework.data.jpa.repository.Query | ||
import org.springframework.data.repository.CrudRepository | ||
import javax.persistence.Tuple | ||
|
||
interface DBPositionRepository : CrudRepository<PositionEntity, Long> | ||
interface DBPositionRepository : CrudRepository<PositionEntity, Long> { | ||
fun findAllByMMSI(MMSI: String): List<PositionEntity> | ||
|
||
@Query(value = "select distinct " + | ||
"n.internal_reference_number, " + | ||
"n.external_reference_number, " + | ||
"n.mmsi, " + | ||
"n.ircs, " + | ||
"p.id, " + | ||
"p.date_time, " + | ||
"p.vessel_name, " + | ||
"p.flag_state, " + | ||
"p.from_country, " + | ||
"p.destination_country, " + | ||
"p.trip_number, " + | ||
"p.latitude, " + | ||
"p.longitude, " + | ||
"p.speed, " + | ||
"p.course, " + | ||
"p.position_type " + | ||
"from positions n " + | ||
"left join positions p on p.id = (select po.ID from positions po where " + | ||
"n.internal_reference_number = po.internal_reference_number " + | ||
"order by po.date_time desc limit 1) " + | ||
"group by " + | ||
"n.internal_reference_number, " + | ||
"n.external_reference_number, " + | ||
"n.mmsi, " + | ||
"n.ircs, " + | ||
"p.id, " + | ||
"p.date_time, " + | ||
"p.vessel_name, " + | ||
"p.flag_state, " + | ||
"p.from_country, " + | ||
"p.destination_country, " + | ||
"p.trip_number, " + | ||
"p.latitude, " + | ||
"p.longitude, " + | ||
"p.speed, " + | ||
"p.course, " + | ||
"p.position_type ", | ||
nativeQuery = true) | ||
fun findLastDistinctPositions(): List<PositionEntity> | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.