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.model.control.warehouse.server.transfer;
018
019import com.echothree.model.control.warehouse.common.transfer.LocationNameElementTransfer;
020import com.echothree.model.control.warehouse.common.transfer.LocationTypeTransfer;
021import com.echothree.model.control.warehouse.server.control.WarehouseControl;
022import com.echothree.model.data.user.server.entity.UserVisit;
023import com.echothree.model.data.warehouse.server.entity.LocationNameElement;
024import com.echothree.model.data.warehouse.server.entity.LocationNameElementDetail;
025
026public class LocationNameElementTransferCache
027        extends BaseWarehouseTransferCache<LocationNameElement, LocationNameElementTransfer> {
028    
029    /** Creates a new instance of LocationNameElementTransferCache */
030    public LocationNameElementTransferCache(UserVisit userVisit, WarehouseControl warehouseControl) {
031        super(userVisit, warehouseControl);
032        
033        setIncludeEntityInstance(true);
034    }
035    
036    public LocationNameElementTransfer getLocationNameElementTransfer(LocationNameElement locationNameElement) {
037        LocationNameElementTransfer locationNameElementTransfer = get(locationNameElement);
038        
039        if(locationNameElementTransfer == null) {
040            LocationNameElementDetail locationNameElementDetail = locationNameElement.getLastDetail();
041            String locationNameElementName = locationNameElementDetail.getLocationNameElementName();
042            LocationTypeTransferCache locationTypeTransferCache = warehouseControl.getWarehouseTransferCaches(userVisit).getLocationTypeTransferCache();
043            LocationTypeTransfer locationType = locationTypeTransferCache.getLocationTypeTransfer(locationNameElementDetail.getLocationType());
044            Integer offset = locationNameElementDetail.getOffset();
045            Integer length = locationNameElementDetail.getLength();
046            String validationPattern = locationNameElementDetail.getValidationPattern();
047            String description = warehouseControl.getBestLocationNameElementDescription(locationNameElement, getLanguage());
048            
049            locationNameElementTransfer = new LocationNameElementTransfer(locationNameElementName, locationType, offset, length,
050                    validationPattern, description);
051            put(locationNameElement, locationNameElementTransfer);
052        }
053        
054        return locationNameElementTransfer;
055    }
056    
057}