-
Notifications
You must be signed in to change notification settings - Fork 4
feat: introduce config object, make service loading optional #274
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
fbiville
wants to merge
1
commit into
main
Choose a base branch
from
configuration
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
199 changes: 199 additions & 0 deletions
199
core/src/main/java/org/neo4j/importer/v1/ImportSpecificationSettings.java
This file contains hidden or 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,199 @@ | ||||||||||||
/* | ||||||||||||
* Copyright (c) "Neo4j" | ||||||||||||
* Neo4j Sweden AB [https://neo4j.com] | ||||||||||||
* | ||||||||||||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||||||||||||
* you may not use this file except in compliance with the License. | ||||||||||||
* You may obtain a copy of the License at | ||||||||||||
* | ||||||||||||
* http://www.apache.org/licenses/LICENSE-2.0 | ||||||||||||
* | ||||||||||||
* Unless required by applicable law or agreed to in writing, software | ||||||||||||
* distributed under the License is distributed on an "AS IS" BASIS, | ||||||||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||||||||||||
* See the License for the specific language governing permissions and | ||||||||||||
* limitations under the License. | ||||||||||||
*/ | ||||||||||||
package org.neo4j.importer.v1; | ||||||||||||
|
||||||||||||
import static java.util.Collections.unmodifiableSet; | ||||||||||||
|
||||||||||||
import java.util.Arrays; | ||||||||||||
import java.util.HashSet; | ||||||||||||
import java.util.LinkedHashSet; | ||||||||||||
import java.util.Optional; | ||||||||||||
import java.util.Set; | ||||||||||||
import org.neo4j.importer.v1.actions.Action; | ||||||||||||
import org.neo4j.importer.v1.actions.ActionProvider; | ||||||||||||
import org.neo4j.importer.v1.actions.plugin.CypherActionProvider; | ||||||||||||
import org.neo4j.importer.v1.distribution.Neo4jDistribution; | ||||||||||||
import org.neo4j.importer.v1.sources.Source; | ||||||||||||
import org.neo4j.importer.v1.sources.SourceProvider; | ||||||||||||
import org.neo4j.importer.v1.targets.EntityTargetExtension; | ||||||||||||
import org.neo4j.importer.v1.targets.EntityTargetExtensionProvider; | ||||||||||||
import org.neo4j.importer.v1.validation.SpecificationValidator; | ||||||||||||
|
||||||||||||
public class ImportSpecificationSettings { | ||||||||||||
|
||||||||||||
public static final ImportSpecificationSettings DEFAULT_SETTINGS = builder().build(); | ||||||||||||
|
||||||||||||
private final boolean automaticPluginDiscoveryEnabled; | ||||||||||||
private final Set<Class<? extends SpecificationValidator>> specificationValidators; | ||||||||||||
private final Set<Class<? extends SourceProvider<? extends Source>>> sourceProviders; | ||||||||||||
private final Set<Class<? extends ActionProvider<? extends Action>>> actionProviders; | ||||||||||||
private final Set<Class<? extends EntityTargetExtensionProvider<? extends EntityTargetExtension>>> | ||||||||||||
entityTargetExtensionProviders; | ||||||||||||
private final Neo4jDistribution neo4jDistribution; | ||||||||||||
|
||||||||||||
public ImportSpecificationSettings( | ||||||||||||
boolean automaticPluginDiscoveryEnabled, | ||||||||||||
Set<Class<? extends SpecificationValidator>> specificationValidators, | ||||||||||||
Set<Class<? extends SourceProvider<? extends Source>>> sourceProviders, | ||||||||||||
Set<Class<? extends ActionProvider<? extends Action>>> actionProviders, | ||||||||||||
Set<Class<? extends EntityTargetExtensionProvider<? extends EntityTargetExtension>>> | ||||||||||||
entityTargetExtensionProviders, | ||||||||||||
Neo4jDistribution neo4jDistribution) { | ||||||||||||
this.automaticPluginDiscoveryEnabled = automaticPluginDiscoveryEnabled; | ||||||||||||
this.specificationValidators = unmodifiableSet(specificationValidators); | ||||||||||||
this.sourceProviders = unmodifiableSet(sourceProviders); | ||||||||||||
this.actionProviders = unmodifiableSet(actionProviders); | ||||||||||||
this.entityTargetExtensionProviders = unmodifiableSet(entityTargetExtensionProviders); | ||||||||||||
this.neo4jDistribution = neo4jDistribution; | ||||||||||||
} | ||||||||||||
|
||||||||||||
public static Builder builder() { | ||||||||||||
return new Builder(); | ||||||||||||
} | ||||||||||||
|
||||||||||||
public boolean isAutomaticPluginDiscoveryEnabled() { | ||||||||||||
return automaticPluginDiscoveryEnabled; | ||||||||||||
} | ||||||||||||
|
||||||||||||
public Set<Class<? extends SpecificationValidator>> getSpecificationValidators() { | ||||||||||||
return specificationValidators; | ||||||||||||
} | ||||||||||||
|
||||||||||||
public Set<Class<? extends SourceProvider<? extends Source>>> getSourceProviders() { | ||||||||||||
return sourceProviders; | ||||||||||||
} | ||||||||||||
|
||||||||||||
public Set<Class<? extends ActionProvider<? extends Action>>> getActionProviders() { | ||||||||||||
return actionProviders; | ||||||||||||
} | ||||||||||||
|
||||||||||||
public Set<Class<? extends EntityTargetExtensionProvider<? extends EntityTargetExtension>>> | ||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. note: I need to add the companion method for this in import-spec/core/src/main/java/org/neo4j/importer/v1/targets/EntityTarget.java Lines 28 to 32 in ccfb1ff
not sure how to do the latter... |
||||||||||||
getEntityTargetExtensionProviders() { | ||||||||||||
return entityTargetExtensionProviders; | ||||||||||||
} | ||||||||||||
|
||||||||||||
public Optional<Neo4jDistribution> getNeo4jDistribution() { | ||||||||||||
return Optional.ofNullable(neo4jDistribution); | ||||||||||||
} | ||||||||||||
|
||||||||||||
@Override | ||||||||||||
public String toString() { | ||||||||||||
return "ImportSpecificationConfig{" + "enableAutomaticPluginDiscovery=" | ||||||||||||
+ automaticPluginDiscoveryEnabled + ", sourceProviders=" | ||||||||||||
+ sourceProviders + ", actionProviders=" | ||||||||||||
+ actionProviders + ", entityTargetExtensionProviders=" | ||||||||||||
+ entityTargetExtensionProviders + ", neo4jDistribution=" | ||||||||||||
+ neo4jDistribution + '}'; | ||||||||||||
} | ||||||||||||
|
||||||||||||
public static class Builder { | ||||||||||||
private boolean automaticPluginDiscoveryEnabled = true; | ||||||||||||
private final Set<Class<? extends SpecificationValidator>> specificationValidators = | ||||||||||||
Plugins.loadBuiltInSpecificationValidators(); | ||||||||||||
private final Set<Class<? extends SourceProvider<? extends Source>>> sourceProviders = new HashSet<>(); | ||||||||||||
private final Set<Class<? extends ActionProvider<? extends Action>>> actionProviders = | ||||||||||||
new HashSet<>(Set.of(CypherActionProvider.class)); | ||||||||||||
private final Set<Class<? extends EntityTargetExtensionProvider<? extends EntityTargetExtension>>> | ||||||||||||
entityTargetExtensionProviders = new HashSet<>(); | ||||||||||||
private Neo4jDistribution neo4jDistribution; | ||||||||||||
|
||||||||||||
private Builder() {} | ||||||||||||
|
||||||||||||
public Builder withAutomaticPluginDiscoveryDisabled() { | ||||||||||||
this.automaticPluginDiscoveryEnabled = false; | ||||||||||||
return this; | ||||||||||||
} | ||||||||||||
|
||||||||||||
public Builder withAutomaticPluginDiscoveryEnabled() { | ||||||||||||
this.automaticPluginDiscoveryEnabled = true; | ||||||||||||
return this; | ||||||||||||
} | ||||||||||||
|
||||||||||||
@SafeVarargs | ||||||||||||
public final Builder withSpecificationValidators( | ||||||||||||
Class<SpecificationValidator> specificationValidator, Class<SpecificationValidator>... otherProviders) { | ||||||||||||
return withSpecificationValidators(concat(specificationValidator, otherProviders)); | ||||||||||||
} | ||||||||||||
|
||||||||||||
public Builder withSpecificationValidators( | ||||||||||||
Set<Class<? extends SpecificationValidator>> specificationValidators) { | ||||||||||||
this.specificationValidators.addAll(specificationValidators); | ||||||||||||
return this; | ||||||||||||
} | ||||||||||||
|
||||||||||||
@SafeVarargs | ||||||||||||
public final Builder withSourceProviders( | ||||||||||||
Class<SourceProvider<? extends Source>> sourceProvider, | ||||||||||||
Class<SourceProvider<? extends Source>>... otherProviders) { | ||||||||||||
return withSourceProviders(concat(sourceProvider, otherProviders)); | ||||||||||||
} | ||||||||||||
|
||||||||||||
public Builder withSourceProviders(Set<Class<? extends SourceProvider<? extends Source>>> sourceProviders) { | ||||||||||||
this.sourceProviders.addAll(sourceProviders); | ||||||||||||
return this; | ||||||||||||
} | ||||||||||||
|
||||||||||||
@SafeVarargs | ||||||||||||
public final Builder withActionProviders( | ||||||||||||
Class<? extends ActionProvider<? extends Action>> actionProvider, | ||||||||||||
Class<? extends ActionProvider<? extends Action>>... otherProviders) { | ||||||||||||
return withActionProviders(concat(actionProvider, otherProviders)); | ||||||||||||
} | ||||||||||||
|
||||||||||||
public Builder withActionProviders(Set<Class<? extends ActionProvider<? extends Action>>> actionProviders) { | ||||||||||||
this.actionProviders.addAll(actionProviders); | ||||||||||||
return this; | ||||||||||||
} | ||||||||||||
|
||||||||||||
@SafeVarargs | ||||||||||||
public final Builder withEntityTargetExtensionProviders( | ||||||||||||
Class<? extends EntityTargetExtensionProvider<? extends EntityTargetExtension>> | ||||||||||||
entityTargetExtensionProvider, | ||||||||||||
Class<? extends EntityTargetExtensionProvider<? extends EntityTargetExtension>>... otherProviders) { | ||||||||||||
return withEntityTargetExtensionProviders(concat(entityTargetExtensionProvider, otherProviders)); | ||||||||||||
} | ||||||||||||
|
||||||||||||
public Builder withEntityTargetExtensionProviders( | ||||||||||||
Set<Class<? extends EntityTargetExtensionProvider<? extends EntityTargetExtension>>> | ||||||||||||
entityTargetExtensionProviders) { | ||||||||||||
this.entityTargetExtensionProviders.addAll(entityTargetExtensionProviders); | ||||||||||||
return this; | ||||||||||||
} | ||||||||||||
|
||||||||||||
public Builder withRuntimeValidationEnabledAgainst(Neo4jDistribution neo4jDistribution) { | ||||||||||||
this.neo4jDistribution = neo4jDistribution; | ||||||||||||
return this; | ||||||||||||
} | ||||||||||||
|
||||||||||||
public ImportSpecificationSettings build() { | ||||||||||||
return new ImportSpecificationSettings( | ||||||||||||
automaticPluginDiscoveryEnabled, | ||||||||||||
specificationValidators, | ||||||||||||
sourceProviders, | ||||||||||||
actionProviders, | ||||||||||||
entityTargetExtensionProviders, | ||||||||||||
neo4jDistribution); | ||||||||||||
} | ||||||||||||
|
||||||||||||
private static <T> Set<T> concat(T sourceProvider, T[] otherProviders) { | ||||||||||||
var providers = new LinkedHashSet<T>(1 + otherProviders.length); | ||||||||||||
providers.add(sourceProvider); | ||||||||||||
providers.addAll(Arrays.asList(otherProviders)); | ||||||||||||
return providers; | ||||||||||||
} | ||||||||||||
} | ||||||||||||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
todo: docs