Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fiche navire - Afficher le type de réseau dans la liste des positions VMS #3550

Merged
merged 4 commits into from
Aug 19, 2024
Merged
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
@@ -0,0 +1,17 @@
package fr.gouv.cnsp.monitorfish.domain.entities.position

enum class NetworkType(val code: String) {
CELLULAR("CEL"),
SATELLITE("SAT"),
;

companion object {
infix fun from(code: String): NetworkType {
return try {
NetworkType.entries.first { it.code == code }
} catch (e: NoSuchElementException) {
throw NoSuchElementException("NetworkType $code not found.", e)
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,5 @@ data class Position(
val from: CountryCode? = null,
val destination: CountryCode? = null,
val tripNumber: String? = null,
val networkType: NetworkType? = null,
)
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ enum class NAFCode(val code: String) {
TRIP_NUMBER("TN"),
LATITUDE("LA"),
LONGITUDE("LO"),
NETWORK_TYPE("MS"),

;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package fr.gouv.cnsp.monitorfish.domain.mappers

import com.neovisionaries.i18n.CountryCode
import fr.gouv.cnsp.monitorfish.domain.entities.position.NetworkType
import fr.gouv.cnsp.monitorfish.domain.entities.position.Position
import fr.gouv.cnsp.monitorfish.domain.entities.position.PositionType
import fr.gouv.cnsp.monitorfish.domain.exceptions.NAFMessageParsingException
Expand Down Expand Up @@ -33,6 +34,7 @@ class NAFMessageMapper(private val naf: String) {
private var speed: Double? = null
private var tripNumber: String? = null
private var isManual: Boolean = false
private var networkType: NetworkType? = null

private val noCountry = "X"
private val positionMessageType = "POS"
Expand Down Expand Up @@ -83,11 +85,17 @@ class NAFMessageMapper(private val naf: String) {
NAFCode.LONGITUDE_DECIMAL -> this.longitude = value.toDouble()
NAFCode.SPEED -> this.speed = value.toDouble().div(10)
NAFCode.COURSE -> this.course = value.toDouble()
NAFCode.NETWORK_TYPE -> {
when (value.isNotEmpty()) {
true -> this.networkType = NetworkType.from(value)
false -> this.networkType = null
}
}
else -> {
logger.debug("VMS parsing: NAF code \"$it\" of value \"$value\" not handled")
}
}
} catch (e: NumberFormatException) {
} catch (e: Exception) {
throw NAFMessageParsingException("Incorrect value at field $it", naf, e)
}
}.run {
Expand Down Expand Up @@ -152,6 +160,7 @@ class NAFMessageMapper(private val naf: String) {
from = from,
tripNumber = tripNumber,
positionType = PositionType.VMS,
networkType = networkType,
isManual = isManual,
)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package fr.gouv.cnsp.monitorfish.infrastructure.api.outputs

import com.neovisionaries.i18n.CountryCode
import fr.gouv.cnsp.monitorfish.domain.entities.position.NetworkType
import fr.gouv.cnsp.monitorfish.domain.entities.position.Position
import fr.gouv.cnsp.monitorfish.domain.entities.position.PositionType
import java.time.ZonedDateTime
Expand All @@ -24,6 +25,7 @@ data class PositionDataOutput(
val isManual: Boolean? = null,
val isFishing: Boolean? = null,
val isAtPort: Boolean? = null,
val networkType: NetworkType? = null,
) {
companion object {
fun fromPosition(position: Position): PositionDataOutput {
Expand All @@ -46,6 +48,7 @@ data class PositionDataOutput(
isManual = position.isManual,
isFishing = position.isFishing,
isAtPort = position.isAtPort,
networkType = position.networkType,
)
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package fr.gouv.cnsp.monitorfish.infrastructure.database.entities

import com.neovisionaries.i18n.CountryCode
import fr.gouv.cnsp.monitorfish.domain.entities.position.NetworkType
import fr.gouv.cnsp.monitorfish.domain.entities.position.Position
import fr.gouv.cnsp.monitorfish.domain.entities.position.PositionType
import fr.gouv.cnsp.monitorfish.infrastructure.database.entities.converters.CountryCodeConverter
Expand Down Expand Up @@ -44,6 +45,9 @@ data class PositionEntity(
val isFishing: Boolean? = false,
@Column(name = "is_at_port")
val isAtPort: Boolean? = null,
@Column(name = "network_type")
@Enumerated(EnumType.STRING)
val networkType: NetworkType? = null,

// Mandatory fields
@Enumerated(EnumType.STRING)
Expand Down Expand Up @@ -81,6 +85,7 @@ data class PositionEntity(
isManual = isManual,
isFishing = isFishing,
isAtPort = isAtPort,
networkType = networkType,
)

companion object {
Expand All @@ -103,6 +108,7 @@ data class PositionEntity(
positionType = position.positionType,
isManual = position.isManual,
isFishing = position.isFishing,
networkType = position.networkType,
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ interface DBPositionRepository : CrudRepository<PositionEntity, Long> {
"p.position_type, " +
"p.is_manual, " +
"p.is_fishing, " +
"p.is_at_port " +
"p.is_at_port, " +
"p.network_type " +
"from positions p " +
"where p.internal_reference_number = :internalReferenceNumber " +
"and p.date_time >= :from " +
Expand Down Expand Up @@ -63,7 +64,8 @@ interface DBPositionRepository : CrudRepository<PositionEntity, Long> {
"p.position_type, " +
"p.is_manual, " +
"p.is_fishing, " +
"p.is_at_port " +
"p.is_at_port, " +
"p.network_type " +
"from positions p " +
"where p.external_reference_number = :externalReferenceNumber " +
"and p.date_time >= :from " +
Expand Down Expand Up @@ -97,7 +99,8 @@ interface DBPositionRepository : CrudRepository<PositionEntity, Long> {
"p.position_type, " +
"p.is_manual, " +
"p.is_fishing, " +
"p.is_at_port " +
"p.is_at_port, " +
"p.network_type " +
"from positions p " +
"where p.ircs = :ircs " +
"and p.date_time >= :from " +
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
ALTER TABLE
public.positions
ADD COLUMN
network_type varchar(50);
Original file line number Diff line number Diff line change
Expand Up @@ -69281,3 +69281,11 @@ INSERT INTO POSITIONS (INTERNAL_REFERENCE_NUMBER, EXTERNAL_REFERENCE_NUMBER, MMS
update positions
set is_at_port = true
where INTERNAL_REFERENCE_NUMBER = 'FAK000999999' and date_time < (now() AT TIME ZONE 'UTC')::TIMESTAMP - interval '22 hours';

update positions
set network_type = 'CELLULAR'
where INTERNAL_REFERENCE_NUMBER = 'FAK000999999' and date_time < (now() AT TIME ZONE 'UTC')::TIMESTAMP - interval '22 hours';

update positions
set network_type = 'SATELLITE'
where INTERNAL_REFERENCE_NUMBER = 'FAK000999999' and date_time > (now() AT TIME ZONE 'UTC')::TIMESTAMP - interval '22 hours';
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package fr.gouv.cnsp.monitorfish.domain.mappers

import com.neovisionaries.i18n.CountryCode
import fr.gouv.cnsp.monitorfish.domain.entities.position.NetworkType
import org.assertj.core.api.Assertions.assertThat
import org.assertj.core.api.Assertions.catchThrowable
import org.junit.jupiter.api.Test
Expand Down Expand Up @@ -205,4 +206,16 @@ internal class NAFMessageMapperUTests {
assertThat(position.speed).isNull()
assertThat(position.course).isNull()
}

@Test
internal fun `init Should parse the network type When given`() {
// Given
val naf = "//SR//TM/POS//IR/FRA000123456//NA/MANUEL//RC/FT6951//FS/FRA//XR/TL326095//DA/20200814//TI/0911//LT/+43.0789//LG/+006.1549//SP/000//CO/0//FR/FRA//RD/20200814//RT/0912//MS/SAT//ER//"

// When
val position = NAFMessageMapper(naf).toPosition()

// Then
assertThat(position.networkType).isEqualTo(NetworkType.SATELLITE)
}
}
31 changes: 31 additions & 0 deletions frontend/cypress/e2e/vessel_sidebar/control_buttons.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,37 @@ context('Vessel sidebar controls buttons', () => {
cy.get('[data-id="0"] > td').eq(2).contains('8.7 nds')
cy.get('[data-id="0"] > td').eq(1).find('[title="Position au port"]').should('exist')
cy.get('[data-id="0"] > td').eq(1).find('[title="Position manuelle (4h-report)"]').should('exist')
cy.get('[data-id="0"] > td').eq(1).find('[title="Réseau CELLULAR"]').should('exist')
cy.get('[data-id="0"] > td').eq(1).contains('CEL')
})

it('Vessel track Should be downloaded', () => {
// Given
cy.get('*[data-cy^="vessel-search-input"]', { timeout: 10000 }).type('Pheno')
cy.get('*[data-cy^="vessel-search-item"]').eq(0).click()
cy.wait(200)
cy.get('*[data-cy^="vessel-sidebar"]').should('be.visible')
cy.get('*[data-cy^="vessel-track-depth-selection"]').click()
cy.fill('Afficher la piste VMS depuis', '3 jours')
cy.wait(500)

// When
cy.clickButton('Exporter la piste')

// Then
cy.wait(400)
cy.exec('cd cypress/downloads && ls').then(result => {
const downloadedCSVFilename = result.stdout

return cy
.readFile(`cypress/downloads/${downloadedCSVFilename}`)
.should(
'contains',
'Nom,Marq. Ext.,C/S,MMSI,CFR,Pavillon,GDH (UTC),Latitude,Longitude,Cap,Vitesse,Au port,Type de réseau'
)
.should('contains', '"PHENOMENE","DONTSINK","CALLME","","FAK000999999"')
.should('contains', '"45° 55′ 12″ N","008° 45′ 54″ W",13,8.7,"Oui","Cellulaire"')
})
})

it('Vessel track dates Should be changed When walking in fishing trips', () => {
Expand Down
Loading
Loading