001// --------------------------------------------------------------------------------
002// Copyright 2002-2025 Echo Three, LLC
003//
004// Licensed under the Apache License, Version 2.0 (the "License");
005// you may not use this file except in compliance with the License.
006// You may obtain a copy of the License at
007//
008//     http://www.apache.org/licenses/LICENSE-2.0
009//
010// Unless required by applicable law or agreed to in writing, software
011// distributed under the License is distributed on an "AS IS" BASIS,
012// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013// See the License for the specific language governing permissions and
014// limitations under the License.
015// --------------------------------------------------------------------------------
016
017package com.echothree.control.user.batch.server.command.util;
018
019import com.echothree.control.user.batch.common.spec.BatchTypeSpec;
020import com.echothree.model.control.batch.common.BatchConstants;
021import com.echothree.model.control.security.common.SecurityRoleGroups;
022import java.util.HashMap;
023import java.util.Map;
024
025public class BatchAliasUtil {
026
027    private BatchAliasUtil() {
028        super();
029    }
030
031    private static class BatchAliasUtilHolder {
032        static BatchAliasUtil instance = new BatchAliasUtil();
033    }
034
035    public static BatchAliasUtil getInstance() {
036        return BatchAliasUtilHolder.instance;
037    }
038
039    private final static Map<String, String> securityRoleGroupNameByBatchTypeName;
040
041    static {
042        securityRoleGroupNameByBatchTypeName = new HashMap<>();
043        securityRoleGroupNameByBatchTypeName.put(BatchConstants.BatchType_SALES_ORDER, SecurityRoleGroups.SalesOrderBatchAlias.name());
044    }
045
046    public String getSecurityRoleGroupNameByBatchTypeName(String batchTypeName) {
047        String securityRoleGroupName = null;
048
049        if(batchTypeName != null) {
050            securityRoleGroupName = securityRoleGroupNameByBatchTypeName.get(batchTypeName);
051        }
052
053        return securityRoleGroupName;
054    }
055
056    // Caution: no validation of the form has been done at this point.
057    public String getSecurityRoleGroupNameByBatchTypeSpec(BatchTypeSpec spec) {
058        String securityRoleGroupName = null;
059
060        if(spec != null) {
061            var batchTypeName = spec.getBatchTypeName();
062            
063            if(batchTypeName != null) {
064                securityRoleGroupName = getSecurityRoleGroupNameByBatchTypeName(batchTypeName);
065            }
066        }
067
068        return securityRoleGroupName;
069    }
070
071}