package eu.dnetlib.workflow;

import java.util.Collection;

import com.googlecode.sarasvati.GraphProcess;

/**
 * Memory Graph processes doesn't have an ID or a way to be retrieved by id. By accessing through this interface we can
 * hide the underlying implementation of the graph process (hibernate or memory).
 *
 * @author marko
 *
 */
public interface GraphProcessRegistry {

	/**
	 * Register a process (if not yet registered) and associate it with a given resource.
	 *
	 * @param process
	 *            process
	 * @param identifier resource identifier
	 * @return process identifier
	 */
	String associateProcessWithResource(GraphProcess process, String identifier);

	/**
	 * Register a process so that it can be retrieved later. Assigning an identifier automatically.
	 *
	 * @param process
	 *            process
	 * @return process identifier
	 */
	String registerProcess(GraphProcess process);

	/**
	 * Find a registered process given an ID.
	 *
	 * @param identifier
	 *            process id
	 * @return process
	 */
	GraphProcess findProcess(String identifier);

	/**
	 * Find all processes associated with a given resource.
	 *
	 * @param identifier resource identifier
	 * @return collection of processes
	 */
	Collection<GraphProcess> findProcessesByResource(String identifier);

	/**
	 * Lists all the registered processes, possibly ordered by time (recent first).
	 *
	 * @return collection of process identifiers.
	 */
	Collection<String> listIdentifiers();

	/**
	 * obtain the id of a given process.
	 *
	 * @param process process
	 * @return process identifier
	 */
	String getProcessIdentifier(GraphProcess process);

	/**
	 * Unregister a registered process.
	 *
	 * @param identifier process identifier
	 */
	void unregisterProcess(String identifier);
}
