<commit_before>/*
 * This file is part of AMEE.
 *
 * Copyright (c) 2007, 2008, 2009 AMEE UK LIMITED (<EMAIL>).
 *
 * AMEE is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 3 of the License, or
 * (at your option) any later version.
 *
 * AMEE is free software and is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 * Created by http://www.dgen.net.
 * Website http://www.amee.cc
 */
package com.amee.service.auth;

import com.amee.domain.IAMEEEntity;
import com.amee.domain.IAMEEEntityReference;
import com.amee.domain.ObjectType;
import com.amee.domain.auth.AuthorizationContext;
import com.amee.domain.auth.Permission;
import com.amee.domain.auth.PermissionEntry;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.*;

@Service
public class PermissionService {

    /**
     * Defines which 'principals' (keys) can relate to which 'entities' (values).
     */
    public final static Map<ObjectType, Set<ObjectType>> PRINCIPAL_ENTITY = new HashMap<ObjectType, Set<ObjectType>>();

    /**
     * Define which principals can relate to which entities.
     */ {
        // Users <--> Entities
        addPrincipalAndEntity(ObjectType.USR, ObjectType.ENV);
        addPrincipalAndEntity(ObjectType.USR, ObjectType.PR);
        addPrincipalAndEntity(ObjectType.USR, ObjectType.DC);
        addPrincipalAndEntity(ObjectType.USR, ObjectType.NPI);
        addPrincipalAndEntity(ObjectType.USR, ObjectType.NDI);
        addPrincipalAndEntity(ObjectType.USR, ObjectType.PINV);
        addPrincipalAndEntity(ObjectType.USR, ObjectType.PITV);
        addPrincipalAndEntity(ObjectType.USR, ObjectType.DINV);
        addPrincipalAndEntity(ObjectType.USR, ObjectType.DITV);
        addPrincipalAndEntity(ObjectType.USR, ObjectType.DINVH);
        addPrincipalAndEntity(ObjectType.USR, ObjectType.DITVH);
        addPrincipalAndEntity(ObjectType.USR, ObjectType.AL);
        addPrincipalAndEntity(ObjectType.USR, ObjectType.ID);
        addPrincipalAndEntity(ObjectType.USR, ObjectType.IVD);
        addPrincipalAndEntity(ObjectType.USR, ObjectType.RVD);
        addPrincipalAndEntity(ObjectType.USR, ObjectType.ALC);
        addPrincipalAndEntity(ObjectType.USR, ObjectType.USR);
        addPrincipalAndEntity(ObjectType.USR, ObjectType.GRP);
        addPrincipalAndEntity(ObjectType.USR, ObjectType.VD);
        addPrincipalAndEntity(ObjectType.USR, ObjectType.TA);

        // Groups <--> Entities
        addPrincipalAndEntity(ObjectType.GRP, ObjectType.ENV);
        addPrincipalAndEntity(ObjectType.GRP, ObjectType.PR);
        addPrincipalAndEntity(ObjectType.GRP, ObjectType.DC);
        addPrincipalAndEntity(ObjectType.GRP, ObjectType.NPI);
        addPrincipalAndEntity(ObjectType.GRP, ObjectType.NDI);
        addPrincipalAndEntity(ObjectType.GRP, ObjectType.PINV);
        addPrincipalAndEntity(ObjectType.GRP, ObjectType.PITV);
        addPrincipalAndEntity(ObjectType.GRP, ObjectType.DINV);
        addPrincipalAndEntity(ObjectType.GRP, ObjectType.DITV);
        addPrincipalAndEntity(ObjectType.GRP, ObjectType.AL);
        addPrincipalAndEntity(ObjectType.GRP, ObjectType.ID);
        addPrincipalAndEntity(ObjectType.GRP, ObjectType.IVD);
        addPrincipalAndEntity(ObjectType.GRP, ObjectType.RVD);
        addPrincipalAndEntity(ObjectType.GRP, ObjectType.ALC);
        addPrincipalAndEntity(ObjectType.GRP, ObjectType.USR);
        addPrincipalAndEntity(ObjectType.GRP, ObjectType.GRP);
        addPrincipalAndEntity(ObjectType.GRP, ObjectType.VD);
        addPrincipalAndEntity(ObjectType.GRP, ObjectType.TA);
    }

    @Autowired
    private PermissionServiceDAO dao;

    public Permission getPermissionByUid(String uid) {
        return dao.getPermissionByUid(uid);
    }

    public void persist(Permission permission) {<commit_msg>PL-10446 - Added DIV resources.<commit_after>/*
 * This file is part of AMEE.
 *
 * Copyright (c) 2007, 2008, 2009 AMEE UK LIMITED (<EMAIL>).
 *
 * AMEE is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 3 of the License, or
 * (at your option) any later version.
 *
 * AMEE is free software and is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 * Created by http://www.dgen.net.
 * Website http://www.amee.cc
 */
package com.amee.service.auth;

import com.amee.domain.IAMEEEntity;
import com.amee.domain.IAMEEEntityReference;
import com.amee.domain.ObjectType;
import com.amee.domain.auth.AuthorizationContext;
import com.amee.domain.auth.Permission;
import com.amee.domain.auth.PermissionEntry;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.*;

@Service
public class PermissionService {

    /**
     * Defines which 'principals' (keys) can relate to which 'entities' (values).
     */
    public final static Map<ObjectType, Set<ObjectType>> PRINCIPAL_ENTITY = new HashMap<ObjectType, Set<ObjectType>>();

    /**
     * Define which principals can relate to which entities.
     */ {
        // Users <--> Entities
        addPrincipalAndEntity(ObjectType.USR, ObjectType.ENV);
        addPrincipalAndEntity(ObjectType.USR, ObjectType.PR);
        addPrincipalAndEntity(ObjectType.USR, ObjectType.DC);
        addPrincipalAndEntity(ObjectType.USR, ObjectType.NPI);
        addPrincipalAndEntity(ObjectType.USR, ObjectType.NDI);
        addPrincipalAndEntity(ObjectType.USR, ObjectType.PINV);
        addPrincipalAndEntity(ObjectType.USR, ObjectType.PITV);
        addPrincipalAndEntity(ObjectType.USR, ObjectType.DINV);
        addPrincipalAndEntity(ObjectType.USR, ObjectType.DINVH);
        addPrincipalAndEntity(ObjectType.USR, ObjectType.DITV);
        addPrincipalAndEntity(ObjectType.USR, ObjectType.DITVH);
        addPrincipalAndEntity(ObjectType.USR, ObjectType.AL);
        addPrincipalAndEntity(ObjectType.USR, ObjectType.ID);
        addPrincipalAndEntity(ObjectType.USR, ObjectType.IVD);
        addPrincipalAndEntity(ObjectType.USR, ObjectType.RVD);
        addPrincipalAndEntity(ObjectType.USR, ObjectType.ALC);
        addPrincipalAndEntity(ObjectType.USR, ObjectType.USR);
        addPrincipalAndEntity(ObjectType.USR, ObjectType.GRP);
        addPrincipalAndEntity(ObjectType.USR, ObjectType.VD);
        addPrincipalAndEntity(ObjectType.USR, ObjectType.TA);

        // Groups <--> Entities
        addPrincipalAndEntity(ObjectType.GRP, ObjectType.ENV);
        addPrincipalAndEntity(ObjectType.GRP, ObjectType.PR);
        addPrincipalAndEntity(ObjectType.GRP, ObjectType.DC);
        addPrincipalAndEntity(ObjectType.GRP, ObjectType.NPI);
        addPrincipalAndEntity(ObjectType.GRP, ObjectType.NDI);
        addPrincipalAndEntity(ObjectType.GRP, ObjectType.PINV);
        addPrincipalAndEntity(ObjectType.GRP, ObjectType.PITV);
        addPrincipalAndEntity(ObjectType.GRP, ObjectType.DINV);
        addPrincipalAndEntity(ObjectType.GRP, ObjectType.DINVH);
        addPrincipalAndEntity(ObjectType.GRP, ObjectType.DITV);
        addPrincipalAndEntity(ObjectType.GRP, ObjectType.DITVH);
        addPrincipalAndEntity(ObjectType.GRP, ObjectType.AL);
        addPrincipalAndEntity(ObjectType.GRP, ObjectType.ID);
        addPrincipalAndEntity(ObjectType.GRP, ObjectType.IVD);
        addPrincipalAndEntity(ObjectType.GRP, ObjectType.RVD);
        addPrincipalAndEntity(ObjectType.GRP, ObjectType.ALC);
        addPrincipalAndEntity(ObjectType.GRP, ObjectType.USR);
        addPrincipalAndEntity(ObjectType.GRP, ObjectType.GRP);
        addPrincipalAndEntity(ObjectType.GRP, ObjectType.VD);
        addPrincipalAndEntity(ObjectType.GRP, ObjectType.TA);
    }

    @Autowired
    private PermissionServiceDAO dao;

    public Permission getPermissionByUid(String uid) {
        return dao.getPermissionByUid(uid);
    }

    public void persist(Permission permission) {
{'fraction_non_alphanumeric': 0.0954514128187457, 'fraction_numerical': 0.003560762692396049, 'mean_word_length': 3.9247737556561084, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 6, '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': '4439088', 'n_tokens_mistral': 2671, 'n_tokens_neox': 2489, 'n_words': 541}