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 4, 2020
1 parent e4c31f5 commit 0d3b4f3
Show file tree
Hide file tree
Showing 153 changed files with 2,313 additions and 1,125 deletions.
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()
}
}
}
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 @@ -5,14 +5,14 @@ import com.egm.stellio.shared.util.NgsiLdParsingUtils.JSONLD_VALUE_KW
import com.egm.stellio.shared.util.NgsiLdParsingUtils.NGSILD_DATE_TIME_TYPE
import com.egm.stellio.shared.util.NgsiLdParsingUtils.NGSILD_ENTITY_TYPE
import com.fasterxml.jackson.annotation.JsonIgnore
import java.time.Instant
import java.time.ZoneOffset
import java.time.ZonedDateTime
import java.util.UUID
import org.neo4j.ogm.annotation.Id
import org.neo4j.ogm.annotation.NodeEntity
import org.neo4j.ogm.annotation.Relationship
import org.neo4j.ogm.annotation.Transient
import java.time.Instant
import java.time.ZoneOffset
import java.time.ZonedDateTime
import java.util.*

@NodeEntity
open class Attribute(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,17 @@ 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 java.time.Instant
import java.time.ZoneOffset
import java.time.ZonedDateTime
import org.neo4j.ogm.annotation.Id
import org.neo4j.ogm.annotation.Labels
import org.neo4j.ogm.annotation.NodeEntity
import org.neo4j.ogm.annotation.Relationship
import org.neo4j.ogm.types.spatial.GeographicPoint2d
import java.time.Instant
import java.time.ZoneOffset
import java.time.ZonedDateTime

@NodeEntity
@JsonIgnoreProperties(ignoreUnknown = true)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ import com.egm.stellio.shared.util.NgsiLdParsingUtils.NGSILD_PROPERTY_VALUE
import com.egm.stellio.shared.util.NgsiLdParsingUtils.NGSILD_TIME_TYPE
import com.egm.stellio.shared.util.NgsiLdParsingUtils.NGSILD_UNIT_CODE_PROPERTY
import com.fasterxml.jackson.annotation.JsonRawValue
import org.neo4j.ogm.annotation.NodeEntity
import java.time.LocalDate
import java.time.LocalTime
import java.time.ZonedDateTime
import org.neo4j.ogm.annotation.NodeEntity

@NodeEntity
class Property(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package com.egm.stellio.entity.model

import com.fasterxml.jackson.annotation.JsonProperty
import java.time.ZonedDateTime
import org.neo4j.ogm.annotation.Labels
import org.neo4j.ogm.annotation.NodeEntity
import java.time.ZonedDateTime

@NodeEntity
class Relationship(
Expand All @@ -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 @@ -3,17 +3,21 @@ package com.egm.stellio.entity.repository
import com.egm.stellio.entity.model.Entity
import com.egm.stellio.entity.model.Property
import com.egm.stellio.entity.model.Relationship
import com.egm.stellio.shared.util.*
import com.egm.stellio.shared.util.extractShortTypeFromExpanded
import com.egm.stellio.shared.util.isDate
import com.egm.stellio.shared.util.isDateTime
import com.egm.stellio.shared.util.isFloat
import com.egm.stellio.shared.util.isTime
import java.time.Instant
import java.time.ZoneOffset
import javax.annotation.PostConstruct
import org.neo4j.ogm.session.Session
import org.neo4j.ogm.session.SessionFactory
import org.neo4j.ogm.session.event.Event
import org.neo4j.ogm.session.event.EventListenerAdapter
import org.slf4j.LoggerFactory
import org.springframework.stereotype.Component
import org.springframework.transaction.annotation.Transactional
import java.time.Instant
import java.time.ZoneOffset
import javax.annotation.PostConstruct

@Component
class Neo4jRepository(
Expand Down Expand Up @@ -111,8 +115,10 @@ class Neo4jRepository(
MERGE (a)-[:$relationshipType]->(target)
""".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 Down Expand Up @@ -177,9 +183,9 @@ class Neo4jRepository(
}

/**
Given an entity E1 having a relationship R1 with an entity E2
When matching the relationships of R1 (to be deleted with R1), a check on :Relationship is necessary since R1 has a link also called HAS_OBJECT with the target entity E2
Otherwise, it will delete not only the relationships of R1 but also the entity E2
Given an entity E1 having a relationship R1 with an entity E2
When matching the relationships of R1 (to be deleted with R1), a check on :Relationship is necessary since R1 has a link also called HAS_OBJECT with the target entity E2
Otherwise, it will delete not only the relationships of R1 but also the entity E2
*/
@Transactional
fun deleteEntityRelationship(entityId: String, relationshipType: String): Int {
Expand All @@ -202,7 +208,10 @@ class Neo4jRepository(
return queryStatistics.nodesDeleted
}

fun getEntitiesByTypeAndQuery(type: String, query: Pair<List<Triple<String, String, String>>, List<Triple<String, String, String>>>): List<String> {
fun getEntitiesByTypeAndQuery(
type: String,
query: Pair<List<Triple<String, String, String>>, List<Triple<String, String, String>>>
): List<String> {
val propertiesFilter =
if (query.second.isNotEmpty())
query.second.joinToString(" AND ") {
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 @@ -10,12 +10,12 @@ import com.egm.stellio.shared.model.BadRequestDataException
import com.egm.stellio.shared.model.ExpandedEntity
import com.egm.stellio.shared.util.NgsiLdParsingUtils.NGSILD_ENTITY_ID
import com.egm.stellio.shared.util.NgsiLdParsingUtils.NGSILD_ENTITY_TYPE
import kotlin.streams.toList
import org.jgrapht.Graph
import org.jgrapht.Graphs
import org.jgrapht.graph.DefaultEdge
import org.jgrapht.graph.DirectedPseudograph
import org.springframework.stereotype.Component
import kotlin.streams.toList

/**
* Service to work on a list of entities.
Expand Down
Loading

0 comments on commit 0d3b4f3

Please sign in to comment.