Skip to content

Commit

Permalink
refactoring: format all code #56
Browse files Browse the repository at this point in the history
  • Loading branch information
vraybaud committed Jun 9, 2020
1 parent 7f90196 commit 19f61c9
Show file tree
Hide file tree
Showing 151 changed files with 2,211 additions and 1,043 deletions.
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,14 @@ If you want to build only one of the services, you can launch:
./gradlew entity-service:build
```

### Formatting the code

To format the code, we use Intellij built-in formatter with settings that can be found in the `config/settings` directory.

Import settings with `File/Manage IDE Settings/Import Settings...`.

You can use plugins like [Save Actions](https://plugins.jetbrains.com/plugin/7642-save-actions) that applies changed code refactoring and optimized imports on a save.

### Working locally with Docker images

To work locally with a Docker image of a service without publishing it to Docker Hub, you can follow the below instructions:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ package com.egm.stellio.apigateway

import org.springframework.boot.autoconfigure.SpringBootApplication
import org.springframework.boot.runApplication
import org.springframework.cloud.gateway.route.builder.RouteLocatorBuilder
import org.springframework.cloud.gateway.route.RouteLocator
import org.springframework.cloud.gateway.route.builder.RouteLocatorBuilder
import org.springframework.cloud.security.oauth2.gateway.TokenRelayGatewayFilterFactory
import org.springframework.context.annotation.Bean

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@ class SecurityConfig {
fun springSecurityFilterChain(http: ServerHttpSecurity): SecurityWebFilterChain {
return http.csrf().disable().build()
}
}
}
Binary file added config/settings/stellio_format_settings.zip
Binary file not shown.
2 changes: 1 addition & 1 deletion docs/cla/cla.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"signedContributors": []
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ package com.egm.stellio.entity.config

import org.springframework.context.annotation.Bean
import org.springframework.context.annotation.Configuration
import org.springframework.core.task.SimpleAsyncTaskExecutor
import org.springframework.context.event.SimpleApplicationEventMulticaster
import org.springframework.context.event.ApplicationEventMulticaster
import org.springframework.context.event.SimpleApplicationEventMulticaster
import org.springframework.core.task.SimpleAsyncTaskExecutor

@Configuration
class AsynchronousEventsConfig {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package com.egm.stellio.entity.config

import org.neo4j.ogm.session.SessionFactory
import org.springframework.context.annotation.Bean
import org.springframework.context.annotation.Configuration
import org.springframework.data.neo4j.repository.config.EnableNeo4jRepositories
import org.springframework.transaction.annotation.EnableTransactionManagement
import org.springframework.data.neo4j.transaction.Neo4jTransactionManager
import org.neo4j.ogm.session.SessionFactory
import org.springframework.context.annotation.Bean
import org.springframework.transaction.annotation.EnableTransactionManagement

@Configuration
@EnableNeo4jRepositories(basePackages = ["com.egm.stellio.entity.repository"])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,4 @@ class WebSecurityConfig {

return http.build()
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import org.neo4j.ogm.annotation.Transient
import java.time.Instant
import java.time.ZoneOffset
import java.time.ZonedDateTime
import java.util.*
import java.util.UUID

@NodeEntity
open class Attribute(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ import com.egm.stellio.shared.util.NgsiLdParsingUtils.NGSILD_ENTITY_TYPE
import com.egm.stellio.shared.util.NgsiLdParsingUtils.NGSILD_GEOPROPERTY_VALUE
import com.egm.stellio.shared.util.NgsiLdParsingUtils.NGSILD_LOCATION_PROPERTY
import com.egm.stellio.shared.util.NgsiLdParsingUtils.NGSILD_MODIFIED_AT_PROPERTY
import com.fasterxml.jackson.annotation.*
import com.fasterxml.jackson.annotation.JsonIgnore
import com.fasterxml.jackson.annotation.JsonIgnoreProperties
import com.fasterxml.jackson.annotation.JsonProperty
import org.neo4j.ogm.annotation.Id
import org.neo4j.ogm.annotation.Labels
import org.neo4j.ogm.annotation.NodeEntity
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@ class Relationship(
val type: List<String>,

observedAt: ZonedDateTime? = null
) : Attribute(attributeType = "Relationship", observedAt = observedAt)
) : Attribute(attributeType = "Relationship", observedAt = observedAt)
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ import org.springframework.data.neo4j.repository.Neo4jRepository
import org.springframework.stereotype.Repository

@Repository
interface AttributeRepository : Neo4jRepository<Attribute, String>
interface AttributeRepository : Neo4jRepository<Attribute, String>
Original file line number Diff line number Diff line change
Expand Up @@ -8,36 +8,44 @@ import org.springframework.stereotype.Repository
@Repository
interface EntityRepository : Neo4jRepository<Entity, String> {

@Query("""
@Query(
"""
MATCH (entity:Entity { id: {id} })
RETURN entity
""")
"""
)
fun getEntityCoreById(id: String): List<Map<String, Any>>

@Query("""
@Query(
"""
MATCH (entity:Entity { id: {id} })-[:HAS_VALUE]->(property:Property)
OPTIONAL MATCH (property)-[:HAS_VALUE]->(propValue:Property)
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>>

@Query("""
@Query(
"""
MATCH (entity:Entity { id: {id} })-[:HAS_VALUE]->(property:Property {id: {propertyId} })
OPTIONAL MATCH (property)-[:HAS_VALUE]->(propValue:Property)
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>>

@Query("""
@Query(
"""
MATCH (entity:Entity { id: {id} })-[:HAS_OBJECT]->(rel:Relationship)-[r]->(relObject:Entity)
WHERE type(r) <> 'HAS_OBJECT'
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,17 +106,19 @@ 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
val relationshipTypeQueryStatistics = session.query(relationshipTypeQuery, emptyMap<String, String>()).queryStatistics().nodesDeleted
val objectQueryStatistics =
session.query(hasObjectQuery, emptyMap<String, String>()).queryStatistics().nodesDeleted
val relationshipTypeQueryStatistics =
session.query(relationshipTypeQuery, emptyMap<String, String>()).queryStatistics().nodesDeleted

return Pair(objectQueryStatistics, relationshipTypeQueryStatistics)
}
Expand All @@ -126,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 @@ -152,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 @@ -180,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 @@ -201,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 @@ -227,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 @@ -289,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 @@ -316,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 @@ -328,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 @@ -340,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 @@ -356,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 @@ -365,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 @@ -376,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 @@ -387,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 @@ -5,4 +5,4 @@ import org.springframework.data.neo4j.repository.Neo4jRepository
import org.springframework.stereotype.Repository

@Repository
interface PropertyRepository : Neo4jRepository<Property, String>
interface PropertyRepository : Neo4jRepository<Property, String>
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ import org.springframework.data.neo4j.repository.Neo4jRepository
import org.springframework.stereotype.Repository

@Repository
interface RelationshipRepository : Neo4jRepository<Relationship, String>
interface RelationshipRepository : Neo4jRepository<Relationship, String>
Original file line number Diff line number Diff line change
Expand Up @@ -92,11 +92,14 @@ class EntityOperationService(
}.collect(
{ BatchOperationResult() },
{ batchOperationResult, updateResult ->
updateResult.fold({
batchOperationResult.errors.add(it)
}, {
batchOperationResult.success.add(it)
})
updateResult.fold(
{
batchOperationResult.errors.add(it)
},
{
batchOperationResult.success.add(it)
}
)
},
BatchOperationResult::plusAssign
)
Expand Down
Loading

0 comments on commit 19f61c9

Please sign in to comment.