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.contact.server.transfer;
018
019import com.echothree.model.control.contact.common.transfer.PostalAddressElementTypeTransfer;
020import com.echothree.model.control.contact.common.transfer.PostalAddressLineElementTransfer;
021import com.echothree.model.control.contact.common.transfer.PostalAddressLineTransfer;
022import com.echothree.model.control.contact.server.control.ContactControl;
023import com.echothree.model.data.contact.server.entity.PostalAddressLineElement;
024import com.echothree.model.data.user.server.entity.UserVisit;
025
026public class PostalAddressLineElementTransferCache
027        extends BaseContactTransferCache<PostalAddressLineElement, PostalAddressLineElementTransfer> {
028    
029    /** Creates a new instance of PostalAddressLineElementTransferCache */
030    public PostalAddressLineElementTransferCache(UserVisit userVisit, ContactControl contactControl) {
031        super(userVisit, contactControl);
032    }
033    
034    public PostalAddressLineElementTransfer getPostalAddressLineElementTransfer(PostalAddressLineElement postalAddressLineElement) {
035        PostalAddressLineElementTransfer postalAddressLineElementTransfer = get(postalAddressLineElement);
036        
037        if(postalAddressLineElementTransfer == null) {
038            PostalAddressLineTransfer postalAddressLine = contactControl.getPostalAddressLineTransfer(userVisit,
039                    postalAddressLineElement.getPostalAddressLine());
040            Integer postalAddressLineElementSortOrder = postalAddressLineElement.getPostalAddressLineElementSortOrder();
041            PostalAddressElementTypeTransfer postalAddressElementType = contactControl.getPostalAddressElementTypeTransfer(userVisit,
042                    postalAddressLineElement.getPostalAddressElementType());
043            String prefix = postalAddressLineElement.getPrefix();
044            Boolean alwaysIncludePrefix = postalAddressLineElement.getAlwaysIncludePrefix();
045            String suffix = postalAddressLineElement.getSuffix();
046            Boolean alwaysIncludeSuffix = postalAddressLineElement.getAlwaysIncludeSuffix();
047            
048            postalAddressLineElementTransfer = new PostalAddressLineElementTransfer(postalAddressLine,
049                    postalAddressLineElementSortOrder, postalAddressElementType, prefix, alwaysIncludePrefix, suffix,
050                    alwaysIncludeSuffix);
051            put(postalAddressLineElement, postalAddressLineElementTransfer);
052        }
053        
054        return postalAddressLineElementTransfer;
055    }
056    
057}