Skip to content

Commit

Permalink
chore: fix a bunch of inspections warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
bobeal committed Apr 1, 2023
1 parent 631b986 commit fee39c2
Show file tree
Hide file tree
Showing 20 changed files with 58 additions and 66 deletions.
4 changes: 2 additions & 2 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ contributions are done using a pull request (PR). The detailed "protocol" used i

* Direct commits to master or develop branches (even single-line modifications) are not allowed. Every modification has to come as a PR
* In case the PR is implementing/fixing a numbered issue, the issue number has to be referenced in the subject of the PR at creation time
* Anybody is welcome to provide comments to the PR (either direct comments or using the review feature offered by Github)
* Anybody is welcome to provide comments to the PR (either direct comments or using the review feature offered by GitHub)
* Use *code line comments* instead of *general comments*, for traceability reasons (see comments lifecycle below)
* Comments lifecycle
* Comment is created, initiating a *comment thread*
Expand Down Expand Up @@ -152,7 +152,7 @@ merged into develop, thanks to the [Release Drafter GitHub action](https://githu

## Releasing

The process of making a release simply consists in creating the release in Github and providing the new tag name.
The process of making a release simply consists in creating the release in GitHub and providing the new tag name.

## Version numbers

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ class EntityAccessRightsService(
LEFT JOIN entity_payload ep ON ear.entity_id = ep.entity_id
WHERE ${if (isStellioAdmin) "1 = 1" else "subject_id IN (:subject_uuids)" }
${if (accessRights.isNotEmpty()) " AND access_right in (:access_rights)" else ""}
${if (!type.isNullOrEmpty()) " AND ${buildTypeQuery(type!!)}" else ""}
${if (!type.isNullOrEmpty()) " AND ${buildTypeQuery(type)}" else ""}
ORDER BY entity_id
LIMIT :limit
OFFSET :offset;
Expand Down Expand Up @@ -227,7 +227,7 @@ class EntityAccessRightsService(
LEFT JOIN entity_payload ep ON ear.entity_id = ep.entity_id
WHERE ${if (isStellioAdmin) "1 = 1" else "subject_id IN (:subject_uuids)" }
${if (accessRights.isNotEmpty()) " AND access_right in (:access_rights)" else ""}
${if (!type.isNullOrEmpty()) " AND ${buildTypeQuery(type!!)}" else ""}
${if (!type.isNullOrEmpty()) " AND ${buildTypeQuery(type)}" else ""}
""".trimIndent()
)
.let {
Expand All @@ -248,7 +248,7 @@ class EntityAccessRightsService(
sub: Option<Sub>,
entities: List<URI>
): Either<APIException, Map<URI, Map<AccessRight, List<SubjectRightInfo>>>> = either {
if (entities.isNullOrEmpty())
if (entities.isEmpty())
return@either emptyMap()

val subjectUuids = subjectReferentialService.getSubjectAndGroupsUUID(sub).bind()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,7 @@ data class SubjectReferential(

other as SubjectReferential

if (subjectId != other.subjectId) return false

return true
return subjectId == other.subjectId
}

override fun hashCode(): Int = subjectId.hashCode()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class EntityEventService(
contexts: List<String>
): Job =
coroutineScope.launch {
logger.debug("Sending create event for entity $entityId")
logger.debug("Sending create event for entity {}", entityId)
getSerializedEntity(entityId)
.onRight {
publishEntityEvent(EntityCreateEvent(sub, entityId, entityTypes, it.second, contexts))
Expand All @@ -56,7 +56,7 @@ class EntityEventService(
contexts: List<String>
): Job =
coroutineScope.launch {
logger.debug("Sending replace event for entity $entityId")
logger.debug("Sending replace event for entity {}", entityId)
getSerializedEntity(entityId)
.onRight {
publishEntityEvent(EntityReplaceEvent(sub, entityId, entityTypes, it.second, contexts))
Expand All @@ -71,7 +71,7 @@ class EntityEventService(
contexts: List<String>
): Job =
coroutineScope.launch {
logger.debug("Sending delete event for entity $entityId")
logger.debug("Sending delete event for entity {}", entityId)
publishEntityEvent(EntityDeleteEvent(sub, entityId, entityTypes, contexts))
}

Expand Down Expand Up @@ -150,7 +150,7 @@ class EntityEventService(
contexts: List<String>
): Job =
coroutineScope.launch {
logger.debug("Sending delete event for attribute $attributeName of entity $entityId")
logger.debug("Sending delete event for attribute {} of entity {}", attributeName, entityId)
getSerializedEntity(entityId)
.onRight {
if (deleteAll)
Expand Down Expand Up @@ -205,5 +205,5 @@ private fun <A, B> Either<A, B>.logResults(eventsType: EventsType, entityId: URI
this.fold({
logger.error("Error while sending $eventsType event for entity $entityId: $it")
}, {
logger.debug("Successfully sent event $eventsType event for entity $entityId")
logger.debug("Successfully sent event {} event for entity {}", eventsType, entityId)
})
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ class EntityOperationService(
*
* @return a [BatchOperationResult] with list of replaced ids and list of errors.
*/
@Transactional
suspend fun replace(entities: List<Pair<NgsiLdEntity, JsonLdEntity>>, sub: Sub?): BatchOperationResult =
processEntities(entities, false, sub, ::replaceEntity)

Expand All @@ -133,6 +134,7 @@ class EntityOperationService(
*
* @return a [BatchOperationResult] with list of updated ids and list of errors.
*/
@Transactional
suspend fun update(
entities: List<Pair<NgsiLdEntity, JsonLdEntity>>,
disallowOverwrite: Boolean = false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ class EntityPayloadService(
): Either<APIException, Unit> = either {
val createdAt = ZonedDateTime.now(ZoneOffset.UTC)
val attributesMetadata = ngsiLdEntity.prepareTemporalAttributes().bind()
logger.debug("Creating entity ${ngsiLdEntity.id}")
logger.debug("Creating entity {}", ngsiLdEntity.id)

createEntityPayload(ngsiLdEntity, createdAt, jsonLdEntity).bind()
temporalEntityAttributeService.createEntityTemporalReferences(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ class TemporalEntityAttributeService(
createdAt: ZonedDateTime,
sub: String? = null
): Either<APIException, Unit> = either {
logger.debug("Creating ${attributesMetadata.size} attributes in entity: ${ngsiLdEntity.id}")
logger.debug("Creating {} attributes in entity: {}", attributesMetadata.size, ngsiLdEntity.id)

attributesMetadata
.filter {
Expand Down Expand Up @@ -193,6 +193,7 @@ class TemporalEntityAttributeService(
.bind("modified_at", modifiedAt)
.execute()

@Transactional
suspend fun addAttribute(
entityId: URI,
ngsiLdAttribute: NgsiLdAttribute,
Expand All @@ -202,7 +203,7 @@ class TemporalEntityAttributeService(
sub: Sub?
): Either<APIException, Unit> =
either {
logger.debug("Adding attribute ${ngsiLdAttribute.name} to entity $entityId")
logger.debug("Adding attribute {} to entity {}", ngsiLdAttribute.name, entityId)
val temporalEntityAttribute = TemporalEntityAttribute(
entityId = entityId,
attributeName = ngsiLdAttribute.name,
Expand Down Expand Up @@ -235,6 +236,7 @@ class TemporalEntityAttributeService(
}
}

@Transactional
suspend fun replaceAttribute(
temporalEntityAttribute: TemporalEntityAttribute,
ngsiLdAttribute: NgsiLdAttribute,
Expand Down Expand Up @@ -283,14 +285,15 @@ class TemporalEntityAttributeService(
.bind("entity_id", entityId)
.execute()

@Transactional
suspend fun deleteTemporalAttribute(
entityId: URI,
attributeName: String,
datasetId: URI?,
deleteAll: Boolean = false
): Either<APIException, Unit> =
either {
logger.debug("Deleting attribute $attributeName from entity $entityId (all: $deleteAll)")
logger.debug("Deleting attribute {} from entity {} (all: {})", attributeName, entityId, deleteAll)
if (deleteAll) {
attributeInstanceService.deleteAllInstancesOfAttribute(entityId, attributeName).bind()
deleteTemporalAttributeAllInstancesReferences(entityId, attributeName).bind()
Expand Down Expand Up @@ -510,7 +513,7 @@ class TemporalEntityAttributeService(
either {
val attributeInstances = ngsiLdAttributes.flatOnInstances()
attributeInstances.parTraverseEither { (ngsiLdAttribute, ngsiLdAttributeInstance) ->
logger.debug("Appending attribute ${ngsiLdAttribute.name} in entity $entityUri")
logger.debug("Appending attribute {} in entity {}", ngsiLdAttribute.name, entityUri)
val currentTea =
getForEntityAndAttribute(entityUri, ngsiLdAttribute.name, ngsiLdAttributeInstance.datasetId)
.fold({ null }, { it })
Expand Down Expand Up @@ -578,7 +581,7 @@ class TemporalEntityAttributeService(
either {
val attributeInstances = ngsiLdAttributes.flatOnInstances()
attributeInstances.parTraverseEither { (ngsiLdAttribute, ngsiLdAttributeInstance) ->
logger.debug("Updating attribute ${ngsiLdAttribute.name} in entity $entityUri")
logger.debug("Updating attribute {} in entity {}", ngsiLdAttribute.name, entityUri)
val currentTea =
getForEntityAndAttribute(entityUri, ngsiLdAttribute.name, ngsiLdAttributeInstance.datasetId)
.fold({ null }, { it })
Expand Down Expand Up @@ -633,7 +636,12 @@ class TemporalEntityAttributeService(
either {
val expandedAttributeName = expandedPayload.keys.first()
val attributeValues = expandedPayload.values.first()[0]
logger.debug("Updating attribute $expandedAttributeName of entity $entityId with values: $attributeValues")
logger.debug(
"Updating attribute {} of entity {} with values: {}",
expandedAttributeName,
entityId,
attributeValues
)

val datasetId = attributeValues.getDatasetId()
val exists = hasAttribute(entityId, expandedAttributeName, datasetId).bind()
Expand All @@ -652,9 +660,8 @@ class TemporalEntityAttributeService(
updateStatus(tea.id, modifiedAt, jsonTargetObject.toString()).bind()

// then update attribute instance
val isNewObservation = attributeValues.containsKey(NGSILD_OBSERVED_AT_PROPERTY)
val timeAndProperty =
if (isNewObservation)
if (attributeValues.containsKey(NGSILD_OBSERVED_AT_PROPERTY))
Pair(
getPropertyValueFromMapAsDateTime(attributeValues, NGSILD_OBSERVED_AT_PROPERTY)!!,
AttributeInstance.TemporalProperty.OBSERVED_AT
Expand Down Expand Up @@ -702,7 +709,7 @@ class TemporalEntityAttributeService(
sub: Sub?
): Either<APIException, Unit> = either {
val ngsiLdAttributeInstance = ngsiLdAttribute.getAttributeInstances()[0]
logger.debug("Upserting temporal attribute ${ngsiLdAttribute.name} in entity $entityUri")
logger.debug("Upserting temporal attribute {} in entity {}", ngsiLdAttribute.name, entityUri)
val currentTea =
getForEntityAndAttribute(entityUri, ngsiLdAttribute.name, ngsiLdAttributeInstance.datasetId)
.fold({ null }, { it })
Expand All @@ -714,7 +721,11 @@ class TemporalEntityAttributeService(
)!!

if (currentTea == null) {
logger.debug("Creating attribute and instance for attribute ${ngsiLdAttribute.name} in entity $entityUri")
logger.debug(
"Creating attribute and instance for attribute {} in entity {}",
ngsiLdAttribute.name,
entityUri
)
addAttribute(
entityUri,
ngsiLdAttribute,
Expand All @@ -724,7 +735,7 @@ class TemporalEntityAttributeService(
sub
).bind()
} else {
logger.debug("Adding instance to attribute ${currentTea.attributeName} to entity $entityUri")
logger.debug("Adding instance to attribute {} to entity {}", currentTea.attributeName, entityUri)
attributeInstanceService.addAttributeInstance(
currentTea.id,
currentTea.attributeName,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,6 @@ suspend fun ReactiveDeleteOperation.TerminatingDelete.execute(): Either<APIExcep
.map { Unit.right() }
.awaitFirst()

fun Set<String>.toSqlArray(): String =
"ARRAY[${this.joinToString(separator = "','", prefix = "'", postfix = "'")}]"

fun URI?.toDatasetIdFilter(): String =
if (this != null) "AND dataset_id = :dataset_id"
else "AND dataset_id IS NULL"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ class V0_29__JsonLd_migration : BaseJavaMigration() {
) { resultSet, _ ->
Pair(resultSet.getString("entity_id").toUri(), resultSet.getString("payload"))
}.forEach { (entityId, payload) ->
logger.debug("Migrating entity $entityId")
logger.debug("Migrating entity {}", entityId)
val deserializedPayload = payload.deserializeAsMap()
val contexts = extractContextFromInput(deserializedPayload)
.map {
Expand Down Expand Up @@ -154,7 +154,7 @@ class V0_29__JsonLd_migration : BaseJavaMigration() {
}

if (entityHasAttribute(entityId, attributeName, datasetId)) {
logger.debug("Attribute $attributeName ($datasetId) exists, adding metadata and payload")
logger.debug("Attribute {} ({}) exists, adding metadata and payload", attributeName, datasetId)
updateTeaPayloadAndDates(
entityId,
attributeName,
Expand All @@ -167,7 +167,7 @@ class V0_29__JsonLd_migration : BaseJavaMigration() {
// create attributes that do not exist
// - non observed attributes created before we kept track of their history
// - attributes of type GeoProperty
logger.debug("Attribute $attributeName ($datasetId) does not exist, bootstrapping entry")
logger.debug("Attribute {} ({}) does not exist, bootstrapping entry", attributeName, datasetId)
createTeaEntry(
entityId,
attributeName,
Expand Down
2 changes: 1 addition & 1 deletion search-service/src/main/resources/application.properties
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ spring.flyway.baseline-version=0
spring.kafka.bootstrap-servers = localhost:29092
# To ensure we get all past messages when dynamically joining a new topic based on our "cim.entities.*" pattern
spring.kafka.consumer.auto-offset-reset = earliest
# By default, new matching topics are checked every 5 minutes but it can be configured by overriding the following prop
# By default, new matching topics are checked every 5 minutes, but it can be configured by overriding the following prop
# spring.kafka.consumer.properties.metadata.max.age.ms = 1000

server.error.include-stacktrace = always
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,11 @@ class EntityModelTests {
fun `it should serialize entityPayload with SAP if present and compact term if specified`() {
val entityPayloadWithSAP =
entityPayload.copy(specificAccessPolicy = AuthContextModel.SpecificAccessPolicy.AUTH_WRITE)
val serializedEntity = entityPayloadWithSAP.serializeProperties(false, true, listOf(APIC_COMPOUND_CONTEXT))
val serializedEntity = entityPayloadWithSAP.serializeProperties(
withSysAttrs = false,
withCompactTerms = true,
contexts = listOf(APIC_COMPOUND_CONTEXT)
)
val specificAccessPolicy = mapOf(
JsonLdUtils.JSONLD_TYPE_TERM to "Property",
JsonLdUtils.JSONLD_VALUE to AuthContextModel.SpecificAccessPolicy.AUTH_WRITE
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1165,7 +1165,7 @@ class TemporalEntityHandlerTests {
fun `modify attribute instance should return a 404 if attributeInstanceId or attribute name is not found`() {
val instanceTemporalFragment =
loadSampleData("fragments/temporal_instance_fragment.jsonld")
val expandedAttr = JsonLdUtils.expandJsonLdTerm(temporalEntityAttributeName, JsonLdUtils.NGSILD_CORE_CONTEXT)
val expandedAttr = JsonLdUtils.expandJsonLdTerm(temporalEntityAttributeName, NGSILD_CORE_CONTEXT)

coEvery { entityPayloadService.checkEntityExistence(any()) } returns Unit.right()
coEvery { authorizationService.userCanUpdateEntity(any(), sub) } returns Unit.right()
Expand Down Expand Up @@ -1551,7 +1551,7 @@ class TemporalEntityHandlerTests {

@Test
fun `delete attribute instance temporal should return 204`() {
val expandedAttr = JsonLdUtils.expandJsonLdTerm(temporalEntityAttributeName, JsonLdUtils.NGSILD_CORE_CONTEXT)
val expandedAttr = JsonLdUtils.expandJsonLdTerm(temporalEntityAttributeName, NGSILD_CORE_CONTEXT)
coEvery {
entityPayloadService.checkEntityExistence(any())
} returns Unit.right()
Expand Down Expand Up @@ -1608,7 +1608,7 @@ class TemporalEntityHandlerTests {

@Test
fun `delete attribute instance temporal should return 404 if attributeInstanceId or attribute name is not found`() {
val expandedAttr = JsonLdUtils.expandJsonLdTerm(temporalEntityAttributeName, JsonLdUtils.NGSILD_CORE_CONTEXT)
val expandedAttr = JsonLdUtils.expandJsonLdTerm(temporalEntityAttributeName, NGSILD_CORE_CONTEXT)

coEvery {
entityPayloadService.checkEntityExistence(any())
Expand Down
14 changes: 0 additions & 14 deletions shared/src/main/kotlin/com/egm/stellio/shared/model/Observation.kt

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ val GEO_QUERY_ALL_GEORELS = listOf(
)
const val GEOREL_NEAR_DISTANCE_MODIFIER = "distance"
const val GEOREL_NEAR_MAXDISTANCE_MODIFIER = "maxDistance"
const val GEOREL_NEAR_MINDISTANCE_MODIFIER = "minDistance"

private val georelNearRegex = "^near;(?:minDistance|maxDistance)==\\d+$".toRegex()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,9 @@ object JsonLdUtils {

const val NGSILD_CREATED_AT_TERM = "createdAt"
const val NGSILD_MODIFIED_AT_TERM = "modifiedAt"
val NGSILD_SYSATTRS_TERMS = listOf(NGSILD_CREATED_AT_TERM, NGSILD_MODIFIED_AT_TERM)
val NGSILD_SYSATTRS_TERMS = setOf(NGSILD_CREATED_AT_TERM, NGSILD_MODIFIED_AT_TERM)
const val NGSILD_CREATED_AT_PROPERTY = "https://uri.etsi.org/ngsi-ld/$NGSILD_CREATED_AT_TERM"
const val NGSILD_MODIFIED_AT_PROPERTY = "https://uri.etsi.org/ngsi-ld/$NGSILD_MODIFIED_AT_TERM"
val NGSILD_SYSATTRS_PROPERTIES = listOf(NGSILD_CREATED_AT_PROPERTY, NGSILD_MODIFIED_AT_PROPERTY)
const val NGSILD_OBSERVED_AT_TERM = "observedAt"
const val NGSILD_OBSERVED_AT_PROPERTY = "https://uri.etsi.org/ngsi-ld/$NGSILD_OBSERVED_AT_TERM"
const val NGSILD_UNIT_CODE_PROPERTY = "https://uri.etsi.org/ngsi-ld/unitCode"
Expand All @@ -78,8 +77,6 @@ object JsonLdUtils {
const val NGSILD_SUBSCRIPTION_TERM = "Subscription"
const val NGSILD_SUBSCRIPTION_PROPERTY = "https://uri.etsi.org/ngsi-ld/Subscription"
const val NGSILD_NOTIFICATION_TERM = "Notification"
const val NGSILD_NOTIFICATION_PROPERTY = "https://uri.etsi.org/ngsi-ld/Notification"
const val NGSILD_NOTIFICATION_ATTR_TERM = "notification"
const val NGSILD_NOTIFICATION_ATTR_PROPERTY = "https://uri.etsi.org/ngsi-ld/notification"

const val NGSILD_DATE_TIME_TYPE = "https://uri.etsi.org/ngsi-ld/DateTime"
Expand Down
Loading

0 comments on commit fee39c2

Please sign in to comment.