
org.jnosql.artemis.graph.DefaultGraphWorkflow Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of graph-extension Show documentation
Show all versions of graph-extension Show documentation
Eclipse JNoSQL mapping layer, Artemis, to Graph API
The newest version!
/*
* Copyright (c) 2017 Otávio Santana and others
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* and Apache License v2.0 which accompanies this distribution.
* The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html
* and the Apache License v2.0 is available at http://www.opensource.org/licenses/apache2.0.php.
*
* You may elect to redistribute this code under either of these licenses.
*
* Contributors:
*
* Otavio Santana
*/
package org.jnosql.artemis.graph;
import org.apache.tinkerpop.gremlin.structure.Vertex;
import javax.inject.Inject;
import java.util.Objects;
import java.util.function.Function;
import java.util.function.UnaryOperator;
/**
* The default implementation of {@link GraphWorkflow}
*/
class DefaultGraphWorkflow implements GraphWorkflow {
private GraphEventPersistManager graphEventPersistManager;
private GraphConverter converter;
DefaultGraphWorkflow() {
}
@Inject
DefaultGraphWorkflow(GraphEventPersistManager graphEventPersistManager, GraphConverter converter) {
this.graphEventPersistManager = graphEventPersistManager;
this.converter = converter;
}
@Override
public T flow(T entity, UnaryOperator action) {
Function flow = getFlow(entity, action);
return flow.apply(entity);
}
private Function getFlow(T entity, UnaryOperator action) {
UnaryOperator validation = t -> Objects.requireNonNull(t, "entity is required");
UnaryOperator firePreEntity = t -> {
graphEventPersistManager.firePreEntity(t);
return t;
};
UnaryOperator firePreGraphEntity = t -> {
graphEventPersistManager.firePreGraphEntity(t);
return t;
};
Function converterGraph = t -> converter.toVertex(t);
UnaryOperator firePreGraph = t -> {
graphEventPersistManager.firePreGraph(t);
return t;
};
UnaryOperator firePostGraph = t -> {
graphEventPersistManager.firePostGraph(t);
return t;
};
Function converterEntity = t -> converter.toEntity(entity, t);
UnaryOperator firePostEntity = t -> {
graphEventPersistManager.firePostEntity(t);
return t;
};
UnaryOperator firePostGraphEntity = t -> {
graphEventPersistManager.firePostGraphEntity(t);
return t;
};
return validation
.andThen(firePreEntity)
.andThen(firePreGraphEntity)
.andThen(converterGraph)
.andThen(firePreGraph)
.andThen(action)
.andThen(firePostGraph)
.andThen(converterEntity)
.andThen(firePostEntity)
.andThen(firePostGraphEntity);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy