package eu.dnetlib.client.managers;

import java.util.HashMap;

/**
 * ActiveComponentManager Keeps a hash map with all components that are being
 * edited at the moment, ie are in use by other users, so that simultaneous
 * editing is not permitted.
 * 
 * Notification Service keeps track of the current Active (in use) components
 * and sends them periodically to the clients. Active Components Manager keeps
 * them updated on every received notification.
 * 
 * Every time someone tries to edit a component, a check is performed first by
 * looking up its ID in Active Components and see is it is currentry in use. In
 * that case, editing is disabled.
 * 
 * @author Eri
 * 
 */
public interface ActiveComponentsManager {

	/**
	 * 
	 * Sends a message to the Notification Server and Marks a component that is
	 * in use so that other users cannot edit it
	 * 
	 * @param itemdId
	 * @param userId
	 */
	public void MarkItem(String itemdId, String userId);

	/**
	 * Sends a message to the Notification Server and Unmarks a component that
	 * has been marked previously as 'in use', so that now that others user can
	 * edit it
	 * 
	 * @param itemdId
	 * @param userId
	 */
	public void unMarkItem(String itemdId, String userId);

	/**
	 * Updates the current Active Components map according to the updates
	 * received by the Notification Service
	 * 
	 * @param activeComponents
	 */

	public void updateActiveComponents(HashMap<String, String> activeComponents);

	/**
	 * Checks if the given component is in use by another user and therefore
	 * whether it should be locked ( editing didabled until it is marked as no
	 * longer Active )
	 * 
	 * @param componentId
	 * @param currentUserId
	 * @return
	 */
	public boolean isLocked(String componentId, String currentUserId);

	boolean isInUse(String componentId, String currentUserId);

	public void unlockAllComponents();

}