/*-
 * ~~~~~~licensing~~~~~~
 * permission-component
 * ==========
 * Copyright (C) 2020 - 2021 EmDev LLC
 * ==========
 * 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.
 * ~~~~~~/licensing~~~~~~
 */
package ru.entaxy.esb.system.core.permission.component.operation;

import ru.entaxy.esb.system.core.permission.component.exception.UnknownOperationException;
import ru.entaxy.esb.system.core.permission.component.util.PermissionComponentConstants;

import java.util.HashMap;
import java.util.Map;

public class OperationFactory {

    private static final Map<String, Operation> operations;

    static {
        operations = new HashMap<>();
        operations.put(PermissionComponentConstants.OPERATION_CHECK, new Check());
        operations.put(PermissionComponentConstants.OPERATION_CHECK_EXCEPTION, new CheckWithException());
        operations.put(PermissionComponentConstants.OPERATION_CHECK_SYSTEM_ACCESS, new CheckSystemAccess());
        operations.put(PermissionComponentConstants.OPERATION_CHECK_SYSTEM_ACCESS_EXCEPTION, new CheckSystemAccessWithException());
        operations.put(PermissionComponentConstants.OPERATION_CREATE, new Create());
        operations.put(PermissionComponentConstants.OPERATION_DELETE, new Delete());
        operations.put(PermissionComponentConstants.OPERATION_GET, new Get());
        operations.put(PermissionComponentConstants.OPERATION_GET_BY_ALL_PARAM, new GetByAllParams());
        operations.put(PermissionComponentConstants.OPERATION_UPDATE, new Update());
    }

    public static final Operation getOperation(String name) throws UnknownOperationException {
        if (operations.containsKey(name)) {
            return operations.get(name);
        }
        throw new UnknownOperationException();
    }

}
