From 623edc026685af0957ce49a2adb9900764b67e52 Mon Sep 17 00:00:00 2001 From: vraybaud Date: Tue, 9 Jun 2020 15:41:32 +0200 Subject: [PATCH] reformat chained functions by removing included line breaks --- .../entity/repository/EntityRepository.kt | 8 +- .../entity/repository/Neo4jRepository.kt | 40 +++---- .../stellio/entity/service/EntityService.kt | 41 +++---- .../service/TemporalEntityAttributeService.kt | 109 +++++++++--------- .../service/NotificationService.kt | 7 +- 5 files changed, 102 insertions(+), 103 deletions(-) diff --git a/entity-service/src/main/kotlin/com/egm/stellio/entity/repository/EntityRepository.kt b/entity-service/src/main/kotlin/com/egm/stellio/entity/repository/EntityRepository.kt index ba5db93718..6b55b63d0c 100644 --- a/entity-service/src/main/kotlin/com/egm/stellio/entity/repository/EntityRepository.kt +++ b/entity-service/src/main/kotlin/com/egm/stellio/entity/repository/EntityRepository.kt @@ -12,7 +12,7 @@ interface EntityRepository : Neo4jRepository { """ MATCH (entity:Entity { id: {id} }) RETURN entity - """ + """ ) fun getEntityCoreById(id: String): List> @@ -23,7 +23,7 @@ interface EntityRepository : Neo4jRepository { OPTIONAL MATCH (property)-[:HAS_OBJECT]->(relOfProp:Relationship)-[rel]->(relOfPropObject:Entity) WHERE type(rel) <> 'HAS_OBJECT' RETURN property, propValue, type(rel) as relType, relOfProp, relOfPropObject - """ + """ ) fun getEntitySpecificProperties(id: String): List> @@ -34,7 +34,7 @@ interface EntityRepository : Neo4jRepository { OPTIONAL MATCH (property)-[:HAS_OBJECT]->(relOfProp:Relationship)-[rel]->(relOfPropObject:Entity) WHERE type(rel) <> 'HAS_OBJECT' RETURN property, propValue, type(rel) as relType, relOfProp, relOfPropObject - """ + """ ) fun getEntitySpecificProperty(id: String, propertyId: String): List> @@ -45,7 +45,7 @@ interface EntityRepository : Neo4jRepository { OPTIONAL MATCH (rel)-[:HAS_OBJECT]->(relOfRel:Relationship)-[or]->(relOfRelObject:Entity) WHERE type(or) <> 'HAS_OBJECT' RETURN rel, type(r) as relType, relObject, relOfRel, type(or) as relOfRelType, relOfRelObject - """ + """ ) fun getEntityRelationships(id: String): List> } diff --git a/entity-service/src/main/kotlin/com/egm/stellio/entity/repository/Neo4jRepository.kt b/entity-service/src/main/kotlin/com/egm/stellio/entity/repository/Neo4jRepository.kt index 0f7fc84845..90119771a0 100644 --- a/entity-service/src/main/kotlin/com/egm/stellio/entity/repository/Neo4jRepository.kt +++ b/entity-service/src/main/kotlin/com/egm/stellio/entity/repository/Neo4jRepository.kt @@ -39,7 +39,7 @@ class Neo4jRepository( MATCH (subject:Attribute { id: "$relationshipId" }), (target:Entity { id: "$entityId" }) MERGE (subject)-[:$relationshipType]->(target) MERGE (subject)-[:HAS_OBJECT]->(target) - """ + """ return session.query(query, emptyMap()).queryStatistics().relationshipsCreated } @@ -52,7 +52,7 @@ class Neo4jRepository( val query = """ MERGE (subject:Entity { id: "$subjectId" }) ON MATCH SET subject.location = point({x: ${coordinates.first}, y: ${coordinates.second}, crs: 'wgs-84'}) - """ + """ return session.query(query, emptyMap()).queryStatistics().propertiesSet } @@ -71,7 +71,7 @@ class Neo4jRepository( val query = """ MATCH (a { id: '$attributeId' })-[:HAS_OBJECT]->(rel)-[:$relationshipType]->() RETURN a.id - """.trimIndent() + """.trimIndent() return session.query(query, emptyMap(), true).toList().isNotEmpty() } @@ -80,7 +80,7 @@ class Neo4jRepository( val query = """ MATCH (a { id: '$attributeId' })-[:HAS_VALUE]->(property:Property { name: "$propertyName" }) RETURN a.id - """.trimIndent() + """.trimIndent() return session.query(query, emptyMap(), true).toList().isNotEmpty() } @@ -89,7 +89,7 @@ class Neo4jRepository( val query = """ MATCH (a { id: '$attributeId' }) WHERE a.$geoPropertyName IS NOT NULL RETURN a.id - """.trimIndent() + """.trimIndent() return session.query(query, emptyMap(), true).toList().isNotEmpty() } @@ -106,14 +106,14 @@ class Neo4jRepository( (target:Entity { id: "$newRelationshipObjectId" }) DETACH DELETE v MERGE (a)-[:HAS_OBJECT]->(target) - """.trimIndent() + """.trimIndent() val relationshipTypeQuery = """ MATCH (a:Attribute { id: "$attributeId" })-[v:$relationshipType]->(e:Entity { id: '$oldRelationshipObjectId' }), (target:Entity { id: "$newRelationshipObjectId" }) DETACH DELETE v MERGE (a)-[:$relationshipType]->(target) - """.trimIndent() + """.trimIndent() val objectQueryStatistics = session.query(hasObjectQuery, emptyMap()).queryStatistics().nodesDeleted @@ -128,7 +128,7 @@ class Neo4jRepository( val query = """ MERGE (entity:Entity { id: "$entityId" }) ON MATCH SET entity.location = point({x: ${coordinates.first}, y: ${coordinates.second}, crs: 'wgs-84'}) - """ + """ return session.query(query, emptyMap()).queryStatistics().propertiesSet } @@ -154,7 +154,7 @@ class Neo4jRepository( OPTIONAL MATCH (rel)-[:HAS_VALUE]->(propOfRel) OPTIONAL MATCH (rel)-[:HAS_OBJECT]->(relOfRel:Relationship) DETACH DELETE n,prop,relOfProp,propOfProp,rel,propOfRel,relOfRel - """.trimIndent() + """.trimIndent() val queryStatistics = session.query(query, emptyMap()).queryStatistics() logger.debug("Deleted entity $entityId : deleted ${queryStatistics.nodesDeleted} nodes, ${queryStatistics.relationshipsDeleted} relations") @@ -182,7 +182,7 @@ class Neo4jRepository( OPTIONAL MATCH (rel)-[:HAS_VALUE]->(propOfRel) OPTIONAL MATCH (rel)-[:HAS_OBJECT]->(relOfRel:Relationship) DETACH DELETE prop,relOfProp,propOfProp,rel,propOfRel,relOfRel - """.trimIndent() + """.trimIndent() val queryStatistics = session.query(query, emptyMap()).queryStatistics() logger.debug("Deleted entity $entityId attributes : deleted ${queryStatistics.nodesDeleted} nodes, ${queryStatistics.relationshipsDeleted} relations") @@ -203,7 +203,7 @@ class Neo4jRepository( OPTIONAL MATCH (prop)-[:HAS_VALUE]->(propOfProp) OPTIONAL MATCH (prop)-[:HAS_OBJECT]->(relOfProp) DETACH DELETE prop,propOfProp,relOfProp - """.trimIndent() + """.trimIndent() val queryStatistics = session.query(query, emptyMap()).queryStatistics() logger.debug("Deleted property $propertyName : deleted ${queryStatistics.nodesDeleted} nodes, ${queryStatistics.relationshipsDeleted} relations") @@ -229,7 +229,7 @@ class Neo4jRepository( OPTIONAL MATCH (rel)-[:HAS_VALUE]->(propOfRel) OPTIONAL MATCH (rel)-[:HAS_OBJECT]->(relOfRel:Relationship) DETACH DELETE rel,propOfRel,relOfRel - """.trimIndent() + """.trimIndent() val queryStatistics = session.query(query, emptyMap()).queryStatistics() logger.debug("Deleted relationship $relationshipType : deleted ${queryStatistics.nodesDeleted} nodes, ${queryStatistics.relationshipsDeleted} relations") @@ -291,7 +291,7 @@ class Neo4jRepository( ${if (propertiesFilter.isNotEmpty() && relationshipsFilter.isNotEmpty()) " AND " else ""} $relationshipsFilter RETURN n.id as id - """ + """ logger.debug("Issuing search query $finalQuery") return session.query(finalQuery, emptyMap(), true) @@ -318,7 +318,7 @@ class Neo4jRepository( AND deviceProp.name = '$propertyName' AND toLower(deviceProp.value) = toLower('$observerId') RETURN e - """.trimIndent() + """.trimIndent() logger.debug("Issuing query $query") return session.query(query, emptyMap(), true).toMutableList() @@ -330,7 +330,7 @@ class Neo4jRepository( val query = """ MATCH (p:Property)-[:HAS_OBJECT]->(r:Relationship)-[:$relationshipType]->(e:Entity { id: '$observerId' }) RETURN p - """.trimIndent() + """.trimIndent() logger.debug("Issuing query $query") return session.query(query, emptyMap(), true).toMutableList() @@ -342,7 +342,7 @@ class Neo4jRepository( val query = """ MATCH (n:Entity)-[:HAS_VALUE]->(p:Property { id: '${property.id}' }) RETURN n - """.trimIndent() + """.trimIndent() logger.debug("Issuing query $query") return session.query(query, emptyMap(), true).toMutableList() @@ -358,7 +358,7 @@ class Neo4jRepository( MATCH (entity:Entity) WHERE entity.id IN {entitiesIds} RETURN entity.id as id - """ + """ return session.query(query, mapOf("entitiesIds" to entitiesIds), true).map { it["id"] as String } } @@ -367,7 +367,7 @@ class Neo4jRepository( val query = """ MATCH ({ id: '$subjectId' })-[:HAS_VALUE]->(p:Property { name: "$propertyName" }) RETURN p - """.trimIndent() + """.trimIndent() return session.query(query, emptyMap(), true).toMutableList() .map { it["p"] as Property } @@ -378,7 +378,7 @@ class Neo4jRepository( val query = """ MATCH ({ id: '$subjectId' })-[:HAS_OBJECT]->(r:Relationship)-[:$relationshipType]->() RETURN r - """.trimIndent() + """.trimIndent() return session.query(query, emptyMap(), true).toMutableList() .map { it["r"] as Relationship } @@ -389,7 +389,7 @@ class Neo4jRepository( val query = """ MATCH ({ id: '$subjectId' })-[:HAS_OBJECT]->(r:Relationship)-[:$relationshipType]->(e: Entity) RETURN e - """.trimIndent() + """.trimIndent() return session.query(query, emptyMap(), true).toMutableList() .map { it["e"] as Entity } .firstOrNull() diff --git a/entity-service/src/main/kotlin/com/egm/stellio/entity/service/EntityService.kt b/entity-service/src/main/kotlin/com/egm/stellio/entity/service/EntityService.kt index b7ab1db7a7..4fbc6bf605 100644 --- a/entity-service/src/main/kotlin/com/egm/stellio/entity/service/EntityService.kt +++ b/entity-service/src/main/kotlin/com/egm/stellio/entity/service/EntityService.kt @@ -190,31 +190,28 @@ class EntityService( private fun createAttributeProperties(subject: Attribute, values: Map>) { values.filterValues { it[0] is Map<*, *> - } - .mapValues { - expandValueAsMap(it.value) - } - .filter { - !(NGSILD_PROPERTIES_CORE_MEMBERS.plus(NGSILD_RELATIONSHIPS_CORE_MEMBERS)).contains(it.key) && - isAttributeOfType(it.value, NGSILD_PROPERTY_TYPE) - } - .forEach { entry -> - logger.debug("Creating property ${entry.key} with values ${entry.value}") + }.mapValues { + expandValueAsMap(it.value) + }.filter { + !(NGSILD_PROPERTIES_CORE_MEMBERS.plus(NGSILD_RELATIONSHIPS_CORE_MEMBERS)).contains(it.key) && + isAttributeOfType(it.value, NGSILD_PROPERTY_TYPE) + }.forEach { entry -> + logger.debug("Creating property ${entry.key} with values ${entry.value}") - // for short-handed properties, the value is directly accessible from the map under the @value key - val propertyValue = - getPropertyValueFromMap(entry.value, NGSILD_PROPERTY_VALUE) ?: entry.value["@value"]!! + // for short-handed properties, the value is directly accessible from the map under the @value key + val propertyValue = + getPropertyValueFromMap(entry.value, NGSILD_PROPERTY_VALUE) ?: entry.value["@value"]!! - val rawProperty = Property( - name = entry.key, value = propertyValue, - unitCode = getPropertyValueFromMapAsString(entry.value, NGSILD_UNIT_CODE_PROPERTY), - observedAt = getPropertyValueFromMapAsDateTime(entry.value, NGSILD_OBSERVED_AT_PROPERTY) - ) + val rawProperty = Property( + name = entry.key, value = propertyValue, + unitCode = getPropertyValueFromMapAsString(entry.value, NGSILD_UNIT_CODE_PROPERTY), + observedAt = getPropertyValueFromMapAsDateTime(entry.value, NGSILD_OBSERVED_AT_PROPERTY) + ) - val property = propertyRepository.save(rawProperty) - subject.properties.add(property) - attributeRepository.save(subject) - } + val property = propertyRepository.save(rawProperty) + subject.properties.add(property) + attributeRepository.save(subject) + } } private fun createAttributeRelationships(subject: Attribute, values: Map>) { diff --git a/search-service/src/main/kotlin/com/egm/stellio/search/service/TemporalEntityAttributeService.kt b/search-service/src/main/kotlin/com/egm/stellio/search/service/TemporalEntityAttributeService.kt index 80de70fcd6..cec6af08e5 100644 --- a/search-service/src/main/kotlin/com/egm/stellio/search/service/TemporalEntityAttributeService.kt +++ b/search-service/src/main/kotlin/com/egm/stellio/search/service/TemporalEntityAttributeService.kt @@ -125,7 +125,7 @@ class TemporalEntityAttributeService( SELECT id, entity_id, type, attribute_name, attribute_value_type, entity_payload::TEXT FROM temporal_entity_attribute WHERE entity_id = :entity_id - """.trimIndent() + """.trimIndent() val expandedAttrsList = attrs.map { @@ -151,7 +151,7 @@ class TemporalEntityAttributeService( SELECT id FROM temporal_entity_attribute WHERE entity_id = :entity_id - """.trimIndent() + """.trimIndent() return databaseClient .execute(selectQuery) @@ -166,7 +166,7 @@ class TemporalEntityAttributeService( FROM temporal_entity_attribute WHERE entity_id = :entity_id AND attribute_name = :attribute_name - """.trimIndent() + """.trimIndent() return databaseClient .execute(selectQuery) @@ -207,65 +207,64 @@ class TemporalEntityAttributeService( rawResults.filter { // filtering out empty lists or lists with an empty map of results it.isNotEmpty() && it[0].isNotEmpty() - } - .forEach { - // attribute_name is the name of the temporal property we want to update - val attributeName = it.first()["attribute_name"]!! as String + }.forEach { + // attribute_name is the name of the temporal property we want to update + val attributeName = it.first()["attribute_name"]!! as String - // extract the temporal property from the raw entity - // ... if it exists, which is not the case for notifications of a subscription (in this case, create an empty map) - val propertyToEnrich: MutableMap = - if (entity[attributeName] != null) { - expandValueAsMap(entity[attributeName]!!).toMutableMap() - } else { - mutableMapOf() - } + // extract the temporal property from the raw entity + // ... if it exists, which is not the case for notifications of a subscription (in this case, create an empty map) + val propertyToEnrich: MutableMap = + if (entity[attributeName] != null) { + expandValueAsMap(entity[attributeName]!!).toMutableMap() + } else { + mutableMapOf() + } - if (withTemporalValues) { - propertyToEnrich.putIfAbsent(NGSILD_ENTITY_TYPE, NGSILD_PROPERTY_TYPE.uri) - // remove the existing value as we will inject our list of results in the property - propertyToEnrich.remove(NGSILD_PROPERTY_VALUE) + if (withTemporalValues) { + propertyToEnrich.putIfAbsent(NGSILD_ENTITY_TYPE, NGSILD_PROPERTY_TYPE.uri) + // remove the existing value as we will inject our list of results in the property + propertyToEnrich.remove(NGSILD_PROPERTY_VALUE) - // Postgres stores the observedAt value in UTC. - // when retrieved, it's converted to the current timezone using the system variable timezone and with the +/- annotation. - // For this reason, a cast to Instant is needed (with UTC as ZoneOffset) to return the expected dateTime with Z format. - val valuesMap = - it.map { - if (it["value"] is Double) - TemporalValue( - it["value"] as Double, - (it["observed_at"] as ZonedDateTime).toInstant().atZone(ZoneOffset.UTC).toString() - ) - else - RawValue( - it["value"]!!, - (it["observed_at"] as ZonedDateTime).toInstant().atZone(ZoneOffset.UTC).toString() - ) - } - propertyToEnrich[NGSILD_PROPERTY_VALUES] = listOf(mapOf("@list" to valuesMap)) + // Postgres stores the observedAt value in UTC. + // when retrieved, it's converted to the current timezone using the system variable timezone and with the +/- annotation. + // For this reason, a cast to Instant is needed (with UTC as ZoneOffset) to return the expected dateTime with Z format. + val valuesMap = + it.map { + if (it["value"] is Double) + TemporalValue( + it["value"] as Double, + (it["observed_at"] as ZonedDateTime).toInstant().atZone(ZoneOffset.UTC).toString() + ) + else + RawValue( + it["value"]!!, + (it["observed_at"] as ZonedDateTime).toInstant().atZone(ZoneOffset.UTC).toString() + ) + } + propertyToEnrich[NGSILD_PROPERTY_VALUES] = listOf(mapOf("@list" to valuesMap)) - // and finally update the raw entity with the updated temporal property - entity[attributeName] = listOf(propertyToEnrich) - } else { - val valuesMap = - it.map { - mapOf( - NGSILD_ENTITY_TYPE to NGSILD_PROPERTY_TYPE.uri, - NGSILD_INSTANCE_ID_PROPERTY to mapOf( - NGSILD_ENTITY_ID to it["instance_id"] - ), - NGSILD_PROPERTY_VALUE to it["value"], - NGSILD_OBSERVED_AT_PROPERTY to mapOf( - NGSILD_ENTITY_TYPE to NGSILD_DATE_TIME_TYPE, - JSONLD_VALUE_KW to (it["observed_at"] as ZonedDateTime).toInstant() - .atZone(ZoneOffset.UTC).toString() - ) + // and finally update the raw entity with the updated temporal property + entity[attributeName] = listOf(propertyToEnrich) + } else { + val valuesMap = + it.map { + mapOf( + NGSILD_ENTITY_TYPE to NGSILD_PROPERTY_TYPE.uri, + NGSILD_INSTANCE_ID_PROPERTY to mapOf( + NGSILD_ENTITY_ID to it["instance_id"] + ), + NGSILD_PROPERTY_VALUE to it["value"], + NGSILD_OBSERVED_AT_PROPERTY to mapOf( + NGSILD_ENTITY_TYPE to NGSILD_DATE_TIME_TYPE, + JSONLD_VALUE_KW to (it["observed_at"] as ZonedDateTime).toInstant() + .atZone(ZoneOffset.UTC).toString() ) - } + ) + } - entity[attributeName] = listOf(valuesMap) - } + entity[attributeName] = listOf(valuesMap) } + } return ExpandedEntity(entity, expandedEntity.contexts) } diff --git a/subscription-service/src/main/kotlin/com/egm/stellio/subscription/service/NotificationService.kt b/subscription-service/src/main/kotlin/com/egm/stellio/subscription/service/NotificationService.kt index d458b0f39b..1989b6945e 100644 --- a/subscription-service/src/main/kotlin/com/egm/stellio/subscription/service/NotificationService.kt +++ b/subscription-service/src/main/kotlin/com/egm/stellio/subscription/service/NotificationService.kt @@ -25,8 +25,11 @@ class NotificationService( private val logger = LoggerFactory.getLogger(javaClass) - fun notifyMatchingSubscribers(rawEntity: String, expandedEntity: ExpandedEntity, updatedAttributes: Set): - Mono>> { + fun notifyMatchingSubscribers( + rawEntity: String, + expandedEntity: ExpandedEntity, + updatedAttributes: Set + ): Mono>> { val id = expandedEntity.id val type = expandedEntity.type return subscriptionService.getMatchingSubscriptions(id, type, updatedAttributes.joinToString(separator = ","))