001// -------------------------------------------------------------------------------- 002// Copyright 2002-2024 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 com.echothree.model.control.security.common.SecurityRoles; 023import java.util.HashMap; 024import java.util.Map; 025 026public class BatchAliasUtil { 027 028 private BatchAliasUtil() { 029 super(); 030 } 031 032 private static class BatchAliasUtilHolder { 033 static BatchAliasUtil instance = new BatchAliasUtil(); 034 } 035 036 public static BatchAliasUtil getInstance() { 037 return BatchAliasUtilHolder.instance; 038 } 039 040 private final static Map<String, String> securityRoleGroupNameByBatchTypeName; 041 042 static { 043 securityRoleGroupNameByBatchTypeName = new HashMap<>(); 044 securityRoleGroupNameByBatchTypeName.put(BatchConstants.BatchType_SALES_ORDER, SecurityRoleGroups.SalesOrderBatchAlias.name()); 045 } 046 047 public String getSecurityRoleGroupNameByBatchTypeName(String batchTypeName) { 048 String securityRoleGroupName = null; 049 050 if(batchTypeName != null) { 051 securityRoleGroupName = securityRoleGroupNameByBatchTypeName.get(batchTypeName); 052 } 053 054 return securityRoleGroupName; 055 } 056 057 // Caution: no validation of the form has been done at this point. 058 public String getSecurityRoleGroupNameByBatchTypeSpec(BatchTypeSpec spec) { 059 String securityRoleGroupName = null; 060 061 if(spec != null) { 062 String batchTypeName = spec.getBatchTypeName(); 063 064 if(batchTypeName != null) { 065 securityRoleGroupName = getSecurityRoleGroupNameByBatchTypeName(batchTypeName); 066 } 067 } 068 069 return securityRoleGroupName; 070 } 071 072}