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.order.server.command.util; 018 019import com.echothree.control.user.order.common.spec.OrderTypeSpec; 020import com.echothree.model.control.order.common.OrderTypes; 021import com.echothree.model.control.security.common.SecurityRoleGroups; 022import java.util.HashMap; 023import java.util.Map; 024 025public class OrderAliasUtil { 026 027 private OrderAliasUtil() { 028 super(); 029 } 030 031 private static class OrderAliasUtilHolder { 032 static OrderAliasUtil instance = new OrderAliasUtil(); 033 } 034 035 public static OrderAliasUtil getInstance() { 036 return OrderAliasUtilHolder.instance; 037 } 038 039 private final static Map<String, String> securityRoleGroupNameByOrderTypeName; 040 041 static { 042 securityRoleGroupNameByOrderTypeName = new HashMap<>(); 043 securityRoleGroupNameByOrderTypeName.put(OrderTypes.SALES_ORDER.name(), SecurityRoleGroups.SalesOrderAlias.name()); 044 } 045 046 public String getSecurityRoleGroupNameByOrderTypeName(String orderTypeName) { 047 String securityRoleGroupName = null; 048 049 if(orderTypeName != null) { 050 securityRoleGroupName = securityRoleGroupNameByOrderTypeName.get(orderTypeName); 051 } 052 053 return securityRoleGroupName; 054 } 055 056 // Caution: no validation of the form has been done at this point. 057 public String getSecurityRoleGroupNameByOrderTypeSpec(OrderTypeSpec spec) { 058 String securityRoleGroupName = null; 059 060 if(spec != null) { 061 String orderTypeName = spec.getOrderTypeName(); 062 063 if(orderTypeName != null) { 064 securityRoleGroupName = getSecurityRoleGroupNameByOrderTypeName(orderTypeName); 065 } 066 } 067 068 return securityRoleGroupName; 069 } 070 071}