<commit_before>package fi.mml.portti.service.db.permissions;

import fi.mml.portti.domain.permissions.Permissions;
import fi.mml.portti.domain.permissions.UniqueResourceName;
import fi.nls.oskari.domain.User;
import fi.nls.oskari.permission.domain.Resource;
import fi.nls.oskari.service.db.BaseService;

import java.util.List;
import java.util.Map;
import java.util.Set;

public interface PermissionsService extends BaseService<Permissions> {

	/**
	 * Returns a set of permission keys that are configured as additional permissions
	 * @return
     */
	Set<String> getAdditionalPermissions();

	/**
	 * Returns an UI name for the permission
	 * @param permissionId
	 * @param lang
     * @return
     */
	String getPermissionName(String permissionId, String lang);
	/**
	 * Insert permissions.
	 * @param uniqueResourceName
	 * @param externalId
	 * @param externalIdType USER or ROLE
	 * @param permissionsType permissions type such as VIEW or PUBLISH
	 */
	public void insertPermissions(
			UniqueResourceName uniqueResourceName, String externalId, String externalIdType, String permissionsType);
	
	/**
	 * Return resources for which permissions have been granted to the given user or role. 
	 * This method returns resources for which:
	 * <ul>
	 * <li>permissions have been granted to user</li>
	 * <li>permissions have been granted to roles where the user belongs</li>
	 * </ul>
	 * 
	 * @param resourceType resource type such as map layer
	 * @param user current user
	 * @param permissionsType permissions type such as VIEW or PUBLISH
	 * @return list of String objects of format namespace+resourceName
	 */
	public Set<String> getResourcesWithGrantedPermissions(
			String resourceType, 
			User user,
			String permissionsType);
	
	/**
	 * Return resources for which permissions have been granted to the given user or role.
	 * 
	 * <p>If externalType is USER, this method returns resources for which permissions 
	 * have been granted to user. NOTE! This method does not return resources for which permissions 
	 * have been granted to roles where the user belongs.</p>
	 * 
	 * <p>If externalType is ROLE, this method returns resources for which permissions 
	 * have been granted to role.<p>
	 * 
	 * @param resourceType resource type such as map layer
	 * @param externalId
	 * @param externalIdType
	 * @param permissionsType permissions type such as VIEW or PUBLISH
	 * @return list of String objects of format namespace+resourceName
	 */
	public Set<String> getResourcesWithGrantedPermissions(
			String resourceType, 
			String externalId,
			String externalIdType,
			String permissionsType);
	
	/**
	 * Return resource matching type and mapping.
	 * @param type
     * @param mapping
	 * @return resource with permissions
	 */
	public Resource getResource(final String type, final String mapping);

    /**
     * Deletes resource and any permissions bound to it
     * @param resource<commit_msg>Fix doc<commit_after>package fi.mml.portti.service.db.permissions;

import fi.mml.portti.domain.permissions.Permissions;
import fi.mml.portti.domain.permissions.UniqueResourceName;
import fi.nls.oskari.domain.User;
import fi.nls.oskari.permission.domain.Resource;
import fi.nls.oskari.service.db.BaseService;

import java.util.List;
import java.util.Map;
import java.util.Set;

public interface PermissionsService extends BaseService<Permissions> {

	/**
	 * Returns a set of permission keys that are configured as additional permissions
	 * @return
     */
	Set<String> getAdditionalPermissions();

	/**
	 * Returns an UI name for the permission
	 * @param permissionId
	 * @param lang
     * @return
     */
	String getPermissionName(String permissionId, String lang);
	/**
	 * Insert permissions.
	 * @param uniqueResourceName
	 * @param externalId
	 * @param externalIdType USER or ROLE
	 * @param permissionsType permissions type such as VIEW or PUBLISH
	 */
	public void insertPermissions(
			UniqueResourceName uniqueResourceName, String externalId, String externalIdType, String permissionsType);
	
	/**
	 * Return resources for which permissions have been granted to the given user or role. 
	 * This method returns resources for which:
	 * <ul>
	 * <li>permissions have been granted to user</li>
	 * <li>permissions have been granted to roles where the user belongs</li>
	 * </ul>
	 * 
	 * @param resourceType resource type such as map layer
	 * @param user current user
	 * @param permissionsType permissions type such as VIEW or PUBLISH
	 * @return Set of String objects of format namespace+resourceName
	 */
	public Set<String> getResourcesWithGrantedPermissions(
			String resourceType, 
			User user,
			String permissionsType);
	
	/**
	 * Return resources for which permissions have been granted to the given user or role.
	 * 
	 * <p>If externalType is USER, this method returns resources for which permissions 
	 * have been granted to user. NOTE! This method does not return resources for which permissions 
	 * have been granted to roles where the user belongs.</p>
	 * 
	 * <p>If externalType is ROLE, this method returns resources for which permissions 
	 * have been granted to role.<p>
	 * 
	 * @param resourceType resource type such as map layer
	 * @param externalId
	 * @param externalIdType
	 * @param permissionsType permissions type such as VIEW or PUBLISH
	 * @return Set of String objects of format namespace+resourceName
	 */
	public Set<String> getResourcesWithGrantedPermissions(
			String resourceType, 
			String externalId,
			String externalIdType,
			String permissionsType);
	
	/**
	 * Return resource matching type and mapping.
	 * @param type
     * @param mapping
	 * @return resource with permissions
	 */
	public Resource getResource(final String type, final String mapping);

    /**
     * Deletes resource and any permissions bound to it
     * @param resource
{'fraction_non_alphanumeric': 0.07449364915894267, 'fraction_numerical': 0.0, 'mean_word_length': 3.938135593220339, 'pattern_counts': {'":': 0, '<': 31, '<?xml version=': 0, '>': 31, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7665318', 'n_tokens_mistral': 1644, 'n_tokens_neox': 1485, 'n_words': 598}