001// --------------------------------------------------------------------------------
002// Copyright 2002-2025 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.communication.server.transfer;
018
019import com.echothree.model.control.communication.common.transfer.CommunicationEmailSourceTransfer;
020import com.echothree.model.control.communication.server.control.CommunicationControl;
021import com.echothree.model.control.core.server.control.ServerControl;
022import com.echothree.model.control.selector.server.control.SelectorControl;
023import com.echothree.model.control.workeffort.server.control.WorkEffortControl;
024import com.echothree.model.data.communication.server.entity.CommunicationEmailSource;
025import com.echothree.model.data.user.server.entity.UserVisit;
026import com.echothree.util.server.persistence.Session;
027import javax.enterprise.context.RequestScoped;
028
029@RequestScoped
030public class CommunicationEmailSourceTransferCache
031        extends BaseCommunicationTransferCache<CommunicationEmailSource, CommunicationEmailSourceTransfer> {
032
033    CommunicationControl communicationControl = Session.getModelController(CommunicationControl.class);
034    ServerControl serverControl = Session.getModelController(ServerControl.class);
035    SelectorControl selectorControl = Session.getModelController(SelectorControl.class);
036    WorkEffortControl workEffortControl = Session.getModelController(WorkEffortControl.class);
037    
038    /** Creates a new instance of CommunicationEmailSourceTransferCache */
039    protected CommunicationEmailSourceTransferCache() {
040        super();
041    }
042    
043    public CommunicationEmailSourceTransfer getCommunicationEmailSourceTransfer(UserVisit userVisit, CommunicationEmailSource communicationEmailSource) {
044        var communicationEmailSourceTransfer = get(communicationEmailSource);
045        
046        if(communicationEmailSourceTransfer == null) {
047            var serverTransfer = serverControl.getServerTransfer(userVisit, communicationEmailSource.getServer());
048            var username = communicationEmailSource.getUsername();
049            var password = communicationControl.decodeCommunicationEmailSourcePassword(communicationEmailSource);
050            var receiveWorkEffortScopeTransfer = workEffortControl.getWorkEffortScopeTransfer(userVisit, communicationEmailSource.getReceiveWorkEffortScope());
051            var sendWorkEffortScopeTransfer = workEffortControl.getWorkEffortScopeTransfer(userVisit, communicationEmailSource.getSendWorkEffortScope());
052            var reviewEmployeeSelector = communicationEmailSource.getReviewEmployeeSelector();
053            var reviewEmployeeSelectorTransfer = reviewEmployeeSelector == null? null: selectorControl.getSelectorTransfer(userVisit, reviewEmployeeSelector);
054            
055            communicationEmailSourceTransfer = new CommunicationEmailSourceTransfer(serverTransfer, username, password,
056                    receiveWorkEffortScopeTransfer, sendWorkEffortScopeTransfer, reviewEmployeeSelectorTransfer);
057            put(userVisit, communicationEmailSource, communicationEmailSourceTransfer);
058        }
059        
060        return communicationEmailSourceTransfer;
061    }
062    
063}