Skip to content

Commit

Permalink
reformat chained functions by removing included line breaks
Browse files Browse the repository at this point in the history
  • Loading branch information
vraybaud committed Jun 9, 2020
1 parent 4801b5a commit 127a90c
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 46 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ interface EntityRepository : Neo4jRepository<Entity, String> {
"""
MATCH (entity:Entity { id: {id} })
RETURN entity
"""
"""
)
fun getEntityCoreById(id: String): List<Map<String, Any>>

Expand All @@ -23,7 +23,7 @@ interface EntityRepository : Neo4jRepository<Entity, String> {
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<Map<String, Any>>

Expand All @@ -34,7 +34,7 @@ interface EntityRepository : Neo4jRepository<Entity, String> {
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<Map<String, Any>>

Expand All @@ -45,7 +45,7 @@ interface EntityRepository : Neo4jRepository<Entity, String> {
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<Map<String, Any>>
}
Original file line number Diff line number Diff line change
Expand Up @@ -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<String, String>()).queryStatistics().relationshipsCreated
}
Expand All @@ -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<String, String>()).queryStatistics().propertiesSet
}

Expand All @@ -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<String, String>(), true).toList().isNotEmpty()
}
Expand All @@ -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<String, String>(), true).toList().isNotEmpty()
}
Expand All @@ -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<String, String>(), true).toList().isNotEmpty()
}
Expand All @@ -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<String, String>()).queryStatistics().nodesDeleted
Expand All @@ -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<String, String>()).queryStatistics().propertiesSet
}

Expand All @@ -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<String, Any>()).queryStatistics()
logger.debug("Deleted entity $entityId : deleted ${queryStatistics.nodesDeleted} nodes, ${queryStatistics.relationshipsDeleted} relations")
Expand Down Expand Up @@ -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<String, Any>()).queryStatistics()
logger.debug("Deleted entity $entityId attributes : deleted ${queryStatistics.nodesDeleted} nodes, ${queryStatistics.relationshipsDeleted} relations")
Expand All @@ -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<String, Any>()).queryStatistics()
logger.debug("Deleted property $propertyName : deleted ${queryStatistics.nodesDeleted} nodes, ${queryStatistics.relationshipsDeleted} relations")
Expand All @@ -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<String, Any>()).queryStatistics()
logger.debug("Deleted relationship $relationshipType : deleted ${queryStatistics.nodesDeleted} nodes, ${queryStatistics.relationshipsDeleted} relations")
Expand Down Expand Up @@ -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<String, Any>(), true)
Expand All @@ -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<String, Any>(), true).toMutableList()
Expand All @@ -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<String, Any>(), true).toMutableList()
Expand All @@ -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<String, Any>(), true).toMutableList()
Expand All @@ -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 }
}
Expand All @@ -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<String, Any>(), true).toMutableList()
.map { it["p"] as Property }
Expand All @@ -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<String, Any>(), true).toMutableList()
.map { it["r"] as Relationship }
Expand All @@ -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<String, Any>(), true).toMutableList()
.map { it["e"] as Entity }
.firstOrNull()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -190,31 +190,28 @@ class EntityService(
private fun createAttributeProperties(subject: Attribute, values: Map<String, List<Any>>) {
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<String, List<Any>>) {
Expand Down

0 comments on commit 127a90c

Please sign in to comment.