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