Skip to content

Commit 6e27595

Browse files
authored
docs: add missing javadoc for ImportSpecification and friends (#324)
* docs: add missing javadoc for `ImportSpecification` and friends * fix: remove deprecate provider APIs BREAKING CHANGE: `Targets#getAll` becomes `Targets#getAllActive` BREAKING CHANGE: `SourceProvider#provide` has been deleted BREAKING CHANGE: `ActionProvider#provide` has been deleted
1 parent 306d728 commit 6e27595

26 files changed

+579
-60
lines changed

core/src/main/java/org/neo4j/importer/v1/Configuration.java

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@
2424
import java.util.Optional;
2525
import java.util.stream.Stream;
2626

27+
/**
28+
* {@link Configuration} is a simple, type-safe wrapper class over arbitrary top-level {@link ImportSpecification}
29+
* settings.
30+
*/
2731
public class Configuration implements Serializable {
2832

2933
private final Map<String, Object> settings;
@@ -32,21 +36,25 @@ public Configuration(Map<String, Object> settings) {
3236
this.settings = settings != null ? settings : Collections.emptyMap();
3337
}
3438

39+
/**
40+
* Returns the setting matched by its primary name (or its alternate names), if it conforms to the provided type
41+
* @param type expected value type of the setting
42+
* @param name primary setting name
43+
* @param alternativeNames alternative setting names, if any
44+
* @return the setting value if it matches the provided parameters in an optional wrapper, or an empty optional
45+
* @param <T> expected type of the setting value
46+
*/
3547
public <T> Optional<T> get(Class<T> type, String name, String... alternativeNames) {
3648
if (settings.isEmpty()) {
3749
return Optional.empty();
3850
}
3951
return Stream.concat(Stream.of(name), Arrays.stream(alternativeNames))
40-
.map(key -> getElement(type, key))
52+
.map(key -> get(type, key))
4153
.dropWhile(Optional::isEmpty)
4254
.flatMap(Optional::stream)
4355
.findFirst();
4456
}
4557

46-
private <T> Optional<T> getElement(Class<T> type, String name) {
47-
return settings.containsKey(name) ? Optional.of(type.cast(settings.get(name))) : Optional.empty();
48-
}
49-
5058
@Override
5159
public boolean equals(Object o) {
5260
if (this == o) return true;
@@ -64,4 +72,17 @@ public int hashCode() {
6472
public String toString() {
6573
return "Configuration{" + "settings=" + settings + '}';
6674
}
75+
76+
private <T> Optional<T> get(Class<T> type, String name) {
77+
return settings.containsKey(name) ? Optional.ofNullable(safeCast(type, name)) : Optional.empty();
78+
}
79+
80+
private <T> T safeCast(Class<T> type, String name) {
81+
var rawValue = settings.get(name);
82+
try {
83+
return type.cast(rawValue);
84+
} catch (ClassCastException e) {
85+
return null;
86+
}
87+
}
6788
}

core/src/main/java/org/neo4j/importer/v1/ImportSpecification.java

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,35 @@
2727
import org.neo4j.importer.v1.sources.Source;
2828
import org.neo4j.importer.v1.targets.Targets;
2929

30+
/**
31+
* {@link ImportSpecification} is the direct representation of the import-spec configuration YAML/JSON files.<br>
32+
* {@link ImportSpecification} is made of 3 mandatory attributes:
33+
* <ul>
34+
* <li>version</li>
35+
* <li>a list of {@link Source}</li>
36+
* <li>targets, which is a mix of:
37+
* <ul>
38+
* <li>{@link org.neo4j.importer.v1.targets.NodeTarget}</li>
39+
* <li>{@link org.neo4j.importer.v1.targets.RelationshipTarget}</li>
40+
* <li>{@link org.neo4j.importer.v1.targets.CustomQueryTarget}</li>
41+
* </ul>
42+
* </li></ul>
43+
* {@link ImportSpecification} can also include:
44+
* <ul>
45+
* <li>top-level settings, wrapped into {@link Configuration}</li>
46+
* <li>one-off {@link Action} scripts</li>
47+
* </ul><br>
48+
* Note: It is <strong>strongly</strong> discouraged to instantiate this class directly.
49+
* Please call one of the deserialization APIs of {@link ImportSpecificationDeserializer} instead.
50+
* The deserializer automatically loads all built-in and external
51+
* {@link org.neo4j.importer.v1.validation.SpecificationValidator} implementation and runs them against this.<br>
52+
* The direct use of {@link ImportSpecification} is most suited when targeting import tools that fully manage import
53+
* task ordering such as neo4j-admin (neo4j-admin handles the order between schema initialization, node import and
54+
* relationship import itself).<br>
55+
* In other cases, {@link org.neo4j.importer.v1.pipeline.ImportPipeline} is a better choice.<br>
56+
* You can construct an {@link org.neo4j.importer.v1.pipeline.ImportPipeline} instance from an instance of
57+
* {@link ImportSpecification} with {@link org.neo4j.importer.v1.pipeline.ImportPipeline#of(ImportSpecification)}.
58+
*/
3059
public class ImportSpecification implements Serializable {
3160

3261
private final String version;
@@ -54,22 +83,42 @@ public ImportSpecification(
5483
this.actions = actions;
5584
}
5685

86+
/**
87+
* Returns the {@link ImportSpecification} version
88+
* @return the version
89+
*/
5790
public String getVersion() {
5891
return version;
5992
}
6093

94+
/**
95+
* Returns the {@link ImportSpecification} top-level settings
96+
* @return the top-level settings
97+
*/
6198
public Configuration getConfiguration() {
6299
return configuration;
63100
}
64101

102+
/**
103+
* Returns the {@link ImportSpecification} data sources
104+
* @return the data sources
105+
*/
65106
public List<Source> getSources() {
66107
return sources;
67108
}
68109

110+
/**
111+
* Returns the {@link ImportSpecification} node, relationship and custom query targets, wrapped into {@link Targets}
112+
* @return the targets
113+
*/
69114
public Targets getTargets() {
70115
return targets;
71116
}
72117

118+
/**
119+
* Returns the {@link ImportSpecification} actions, active or not
120+
* @return the actions
121+
*/
73122
public List<Action> getActions() {
74123
return actions != null ? actions : Collections.emptyList();
75124
}

core/src/main/java/org/neo4j/importer/v1/ImportSpecificationDeserializer.java

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -60,22 +60,26 @@ public class ImportSpecificationDeserializer {
6060
.getSchema(ImportSpecificationDeserializer.class.getResourceAsStream("/spec.v1.json"));
6161

6262
/**
63-
* Returns an instance of {@link ImportSpecification} based on the provided {@link Reader} content.
64-
* The result is guaranteed to be consistent with the specification JSON schema.
63+
* Returns an instance of {@link ImportSpecification} based on the provided {@link Reader} content.<br>
64+
* The result is guaranteed to be consistent with the specification JSON schema.<br>
6565
* <br>
66-
* If implementations of the {@link SpecificationValidator} SPI are provided, they will also run against the
67-
* {@link ImportSpecification} instance before the latter is returned.
68-
* <br>
69-
* If the parsing, deserialization or validation (standard or via SPI implementations) fail, a {@link SpecificationException}
70-
* is going to be thrown.
71-
*
66+
* If implementations of the {@link SpecificationValidator} Service Provider Interface are provided, they will also
67+
* run against the {@link ImportSpecification} instance before the latter is returned.<br>
68+
* If the parsing, deserialization or validation (standard or via SPI implementations) fail, a
69+
* {@link SpecificationException} is thrown.
7270
* @return an {@link ImportSpecification}
7371
* @throws SpecificationException if parsing, deserialization or validation fail
7472
*/
7573
public static ImportSpecification deserialize(Reader spec) throws SpecificationException {
7674
return deserialize(spec, Optional.empty());
7775
}
7876

77+
/**
78+
* Same as {@link ImportSpecificationDeserializer#deserialize(Reader)}, except it checks extra validation rules
79+
* against the provided {@link Neo4jDistribution} value.
80+
* @return an {@link ImportSpecification}
81+
* @throws SpecificationException if parsing, deserialization or validation fail
82+
*/
7983
public static ImportSpecification deserialize(Reader spec, Neo4jDistribution neo4jDistribution)
8084
throws SpecificationException {
8185

core/src/main/java/org/neo4j/importer/v1/actions/Action.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,26 @@
1818

1919
import java.io.Serializable;
2020

21+
/**
22+
* {@link Action} define one-off execution scripts.<br>
23+
* The {@link Action} name must be unique within an instance of {@link org.neo4j.importer.v1.ImportSpecification}.<br>
24+
* The {@link Action} stage (see {@link Action#getStage()} determines when an action must be executed.<br>
25+
* Only {@link org.neo4j.importer.v1.actions.plugin.CypherAction} is defined by default.<br>
26+
* Other {@link ActionProvider} implementation may be registered through Java's standard
27+
* Service Provider Interface mechanism.
28+
*/
2129
public interface Action extends Serializable {
2230

2331
boolean DEFAULT_ACTIVE = true;
2432

33+
/**
34+
* Type of the action (example: "jdbc", "http", ...)<br>
35+
* The type name must be unique in a case-insensitive (per {@link java.util.Locale#ROOT} casing rules).<br>
36+
* Having multiple actions loaded with the same type is invalid and will lead to an exception being raised, aborting
37+
* the import early.<br>
38+
* Note: it is recommended that the type returned here be the same as the one this source's {@link ActionProvider}
39+
* supports, or a subset thereof.
40+
*/
2541
String getType();
2642

2743
/**

core/src/main/java/org/neo4j/importer/v1/actions/ActionProvider.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,24 @@
1919
import com.fasterxml.jackson.databind.node.ObjectNode;
2020
import java.util.function.Function;
2121

22+
/**
23+
* {@link ActionProvider} is a Service Provider Interface, allowing users to define their own action.
24+
* @param <T> the concrete type of the {@link Action} subclass
25+
*/
2226
public interface ActionProvider<T extends Action> extends Function<ObjectNode, T> {
2327

28+
/**
29+
* User-facing type of the concrete supported action, it must match the result of {@link Action#getType()}
30+
* @return the action type
31+
*/
2432
String supportedType();
33+
34+
/**
35+
* Deserialization endpoint.<br>
36+
* Note: implement deserialization leniently, validate strictly (define
37+
* {@link org.neo4j.importer.v1.validation.SpecificationValidator} for your own sources)
38+
* @return the deserialized action
39+
*/
40+
@Override
41+
T apply(ObjectNode node);
2542
}

core/src/main/java/org/neo4j/importer/v1/actions/ActionStage.java

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,45 @@
1616
*/
1717
package org.neo4j.importer.v1.actions;
1818

19+
/**
20+
* {@link ActionStage} defines when the enclosing {@link Action} must run.<br>
21+
* {@link org.neo4j.importer.v1.pipeline.ImportPipeline} translate this into concrete dependencies.
22+
*/
1923
public enum ActionStage {
24+
/**
25+
* The enclosing {@link Action} must run before anything else (actively-used sources, active targets)
26+
*/
2027
START,
28+
/**
29+
* The enclosing {@link Action} must run after all actively-used {@link org.neo4j.importer.v1.sources.Source}s
30+
*/
2131
POST_SOURCES,
32+
/**
33+
* The enclosing {@link Action} must run before all active {@link org.neo4j.importer.v1.targets.NodeTarget}s
34+
*/
2235
PRE_NODES,
36+
/**
37+
* The enclosing {@link Action} must run after all active {@link org.neo4j.importer.v1.targets.NodeTarget}s
38+
*/
2339
POST_NODES,
40+
/**
41+
* The enclosing {@link Action} must run before all active {@link org.neo4j.importer.v1.targets.RelationshipTarget}s
42+
*/
2443
PRE_RELATIONSHIPS,
44+
/**
45+
* The enclosing {@link Action} must run after all active {@link org.neo4j.importer.v1.targets.RelationshipTarget}s
46+
*/
2547
POST_RELATIONSHIPS,
48+
/**
49+
* The enclosing {@link Action} must run before all active {@link org.neo4j.importer.v1.targets.CustomQueryTarget}s
50+
*/
2651
PRE_QUERIES,
52+
/**
53+
* The enclosing {@link Action} must run after all active {@link org.neo4j.importer.v1.targets.CustomQueryTarget}s
54+
*/
2755
POST_QUERIES,
56+
/**
57+
* The enclosing {@link Action} must run after everything else (actively-used sources, active targets)
58+
*/
2859
END
2960
}

core/src/main/java/org/neo4j/importer/v1/actions/plugin/CypherAction.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,11 @@
2020
import org.neo4j.importer.v1.actions.Action;
2121
import org.neo4j.importer.v1.actions.ActionStage;
2222

23+
/**
24+
* {@link CypherAction} defines a one-off Cypher script to execute.<br>
25+
* It defines a query (see {@link CypherAction#getQuery()} and an execution mode {@link CypherExecutionMode} (default:
26+
* {@link CypherExecutionMode#TRANSACTION}).
27+
*/
2328
public class CypherAction implements Action {
2429
static final CypherExecutionMode DEFAULT_CYPHER_EXECUTION_MODE = CypherExecutionMode.TRANSACTION;
2530

0 commit comments

Comments
 (0)