All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.geneweaver.io.connector.Connector Maven / Gradle / Ivy

There is a newer version: 2.7.12
Show newest version
/*-
 * 
 * Copyright 2018, 2020  The Jackson Laboratory Inc.
 *
 * 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.
 * 
 * @author Matthew Gerring
 */
package org.geneweaver.io.connector;

import java.io.PrintStream;
import java.util.function.Function;
import java.util.stream.Stream;

import org.geneweaver.domain.Entity;
import org.neo4j.ogm.session.Session;

/**
 * A function which runs to expand entities as they are being read.
 * Examples of doing this:
 * 1. Create a relationship between Transcript and Gene.
 * 2. Create a VariantEffect back to an existing transcript.
 * 3. 
 * 
 * @author gerrim
 * @param  Output of connection e.g. Produces or VariantEffect
 * @param  Input e.g. Transcript, Gene, Variant
 * 
 * Function>
 */
public interface Connector extends Function> {
	
	/**
	 * Simply calls 'stream(...)'
	 */
	default Stream apply(I entity) {
		return stream(entity);
	}

	/**
	 * Create a stream from the entity. Note that if threads and
	 * multiple sessions are used the session should not be cached
	 * between calls of this method, or anything.
	 * @param entity From which we will create a stream of connections
	 * @param session The current session, NOTE multiple sessions may be active.
	 * @return Stream of connections including the original entity.
	 */
	default Stream stream(I entity) {
		return stream(entity, null);
	}

	/**
	 * Create a stream from the entity. Note that if threads and
	 * multiple sessions are used the session should not be cached
	 * between calls of this method, or anything.
	 * @param entity From which we will create a stream of connections
	 * @param session The current session, NOTE multiple sessions may be active.
	 * @return Stream of connections including the original entity.
	 */
	default Stream stream(I ent, Session session) {
		return stream(ent, session, null);
	}
	
	/**
	 * Create a stream from the entity. Note that if threads and
	 * multiple sessions are used the session should not be cached
	 * between calls of this method, or anything.
	 * @param entity From which we will create a stream of connections
	 * @param session The current session, NOTE multiple sessions may be active.
	 * @param log for logging usually set in a -v command line to generate more verbose messages. Null for a normal run.
	 * @return Stream of connections including the original entity.
	 */
	abstract Stream stream(I ent, Session session, PrintStream log);
	
}