-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7c513f2
commit 98e6c38
Showing
13 changed files
with
104 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
import org.gradle.jvm.tasks.Jar | ||
|
||
plugins { | ||
id("java-library") | ||
id("org.orkg.gradle.kotlin-library") | ||
} | ||
|
||
tasks { | ||
|
44 changes: 44 additions & 0 deletions
44
...-migrations/src/main/kotlin/org/orkg/migrations/neo4j/AbstractCustomProcedureMigration.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package org.orkg.migrations.neo4j | ||
|
||
import ac.simons.neo4j.migrations.core.JavaBasedMigration | ||
import ac.simons.neo4j.migrations.core.MigrationContext | ||
import java.lang.Thread.sleep | ||
import java.util.* | ||
|
||
abstract class AbstractCustomProcedureMigration( | ||
private val migrationQuery: String, | ||
private val validationQuery: String, | ||
private val version: Long, | ||
private val validationIntervalMs: Long = 100, | ||
) : JavaBasedMigration { | ||
override fun apply(context: MigrationContext) { | ||
val systemDBContext = context.getSessionConfig { it.withDatabase("system") } | ||
context.driver.session(systemDBContext).executeWriteWithoutResult { tx -> | ||
tx.run(migrationQuery) | ||
} | ||
val orkgDBContext = context.getSessionConfig { it.withDatabase("orkg") } | ||
val validate = { | ||
try { | ||
context.driver.session(orkgDBContext).executeRead { tx -> | ||
tx.run(validationQuery).list().size | ||
} | ||
} catch (e: Exception) { | ||
-1 | ||
} | ||
} | ||
var result = validate() | ||
while (result == -1) { | ||
sleep(validationIntervalMs) | ||
result = validate() | ||
} | ||
} | ||
|
||
override fun getOptionalDescription(): Optional<String> = Optional.ofNullable( | ||
this::class.simpleName | ||
?.replace(Regex("""^[RV]\d+__"""), "") | ||
?.replace(Regex("""([A-Z])""")) { " " + it.value.lowercase() } | ||
?.trim() | ||
) | ||
|
||
override fun getChecksum(): Optional<String> = Optional.of(version.toString()) | ||
} |
16 changes: 16 additions & 0 deletions
16
...rations/src/main/kotlin/org/orkg/migrations/neo4j/R0027__CreateCustomSubgraphProcedure.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package org.orkg.migrations.neo4j | ||
|
||
@Suppress("ClassName") | ||
class R0027__CreateCustomSubgraphProcedure : AbstractCustomProcedureMigration( | ||
""" | ||
CALL apoc.custom.installProcedure( | ||
'subgraph(start :: ANY?, config :: MAP) :: (relationships :: LIST? OF RELATIONSHIP?)', | ||
'CALL apoc.path.subgraphAll(${'$'}start, ${'$'}config) YIELD relationships WITH relationships UNWIND relationships AS rel WITH rel WHERE rel:RELATED RETURN COLLECT(rel) AS relationships', | ||
'orkg', | ||
'read', | ||
'custom.subgraph(startNode <id>|Node|list, {maxLevel,relationshipFilter,labelFilter,bfs:true, filterStartNode:false, limit:-1, endNodes:[], terminatorNodes:[], sequence, beginSequenceAtStart:true}) yield relationships - expand the subgraph reachable from start node following relationships to max-level adhering to the label filters, returning all RELATED relationships within the subgraph' | ||
); | ||
""".trimIndent(), | ||
validationQuery = "CALL custom.subgraph([], {})", | ||
version = 1 | ||
) |
22 changes: 22 additions & 0 deletions
22
.../src/main/kotlin/org/orkg/migrations/neo4j/R0031__CreateCustomTimestampParsingFunction.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package org.orkg.migrations.neo4j | ||
|
||
import org.springframework.stereotype.Component | ||
|
||
@Component | ||
@Suppress("ClassName") | ||
class R0031__CreateCustomTimestampParsingFunction : AbstractCustomProcedureMigration( | ||
""" | ||
CALL apoc.custom.installFunction( | ||
'parseIsoOffsetDateTime(time :: STRING, unit = ms :: STRING) :: (INTEGER?)', | ||
'WITH apoc.text.regreplace(${'$'}time, "(\.\d{1,3})\d*", "${'$'}1") AS time // limit fraction to 3 digits because parsing pattern only supports milliseconds (see java.text.SimpleDateFormat) | ||
WITH apoc.text.regreplace(time, "(T\d{2}:\d{2})([+-]\d{2}:\d{2}|Z)${'$'}", "${'$'}1:00${'$'}2") AS time // insert seconds block if missing because parsing pattern does not support optional sections (see java.text.SimpleDateFormat) | ||
WITH apoc.text.regreplace(time, "(T\d{2}:\d{2}:\d{2})([+-]\d{2}:\d{2}|Z)${'$'}", "${'$'}1.0${'$'}2") AS time // insert milliseconds block if missing because parsing pattern does not support optional sections (see java.text.SimpleDateFormat) | ||
RETURN apoc.date.parse(time, ${'$'}unit, "yyyy-MM-dd\'T\'HH:mm:ss.SSSXXX")', | ||
'orkg', | ||
false, | ||
'custom.parseIsoOffsetDateTime(\'2012-12-23T21:15:05.645313+02:00\', \'ms|s|m|h|d\') - parse date string as offset date time into the specified time unit' | ||
); | ||
""".trimIndent(), | ||
validationQuery = "RETURN custom.parseIsoOffsetDateTime('2012-12-23T21:15:05.645313+02:00', 'ms')", | ||
version = 1 | ||
) |
6 changes: 0 additions & 6 deletions
6
...ations/src/main/resources/neo4j/migrations/R0027__create_custom_subgraph_procedure.cypher
This file was deleted.
Oops, something went wrong.
9 changes: 0 additions & 9 deletions
9
...rc/main/resources/neo4j/migrations/R0031__create_custom_timestamp_parsing_function.cypher
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters