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.communication.server.transfer;
018
019import com.echothree.model.control.communication.common.transfer.CommunicationEventPurposeTransfer;
020import com.echothree.model.control.communication.common.transfer.CommunicationEventTransfer;
021import com.echothree.model.control.communication.common.transfer.CommunicationEventTypeTransfer;
022import com.echothree.model.control.communication.common.transfer.CommunicationSourceTransfer;
023import com.echothree.model.control.communication.server.control.CommunicationControl;
024import com.echothree.model.control.contact.common.transfer.PartyContactMechanismTransfer;
025import com.echothree.model.control.contact.server.control.ContactControl;
026import com.echothree.model.control.document.common.transfer.DocumentTransfer;
027import com.echothree.model.control.document.server.control.DocumentControl;
028import com.echothree.model.data.communication.server.entity.CommunicationEvent;
029import com.echothree.model.data.communication.server.entity.CommunicationEventDetail;
030import com.echothree.model.data.user.server.entity.UserVisit;
031import com.echothree.util.server.persistence.Session;
032
033public class CommunicationEventTransferCache
034        extends BaseCommunicationTransferCache<CommunicationEvent, CommunicationEventTransfer> {
035    
036    ContactControl contactControl = Session.getModelController(ContactControl.class);
037    DocumentControl documentControl = Session.getModelController(DocumentControl.class);
038    
039    /** Creates a new instance of CommunicationEventTransferCache */
040    public CommunicationEventTransferCache(UserVisit userVisit, CommunicationControl communicationControl) {
041        super(userVisit, communicationControl);
042        
043        setIncludeEntityInstance(true);
044    }
045    
046    public CommunicationEventTransfer getCommunicationEventTransfer(CommunicationEvent communicationEvent) {
047        CommunicationEventTransfer communicationEventTransfer = get(communicationEvent);
048        
049        if(communicationEventTransfer == null) {
050            CommunicationEventDetail communicationEventDetail = communicationEvent.getLastDetail();
051            String communicationEventName = communicationEventDetail.getCommunicationEventName();
052            CommunicationEventTypeTransfer communicationEventTypeTransfer = communicationControl.getCommunicationEventTypeTransfer(userVisit, 
053                    communicationEventDetail.getCommunicationEventType());
054            CommunicationSourceTransfer communicationSourceTransfer = communicationControl.getCommunicationSourceTransfer(userVisit, 
055                    communicationEventDetail.getCommunicationSource());
056            CommunicationEventPurposeTransfer communicationEventPurposeTransfer = communicationControl.getCommunicationEventPurposeTransfer(userVisit, 
057                    communicationEventDetail.getCommunicationEventPurpose());
058            CommunicationEvent originalCommunicationEvent = communicationEventDetail.getOriginalCommunicationEvent();
059            CommunicationEventTransfer originalCommunicationEventTransfer = originalCommunicationEvent == null? null: communicationControl.getCommunicationEventTransfer(userVisit, originalCommunicationEvent);
060            CommunicationEvent parentCommunicationEvent = communicationEventDetail.getParentCommunicationEvent();
061            CommunicationEventTransfer parentCommunicationEventTransfer = parentCommunicationEvent == null? null: communicationControl.getCommunicationEventTransfer(userVisit, parentCommunicationEvent);
062            PartyContactMechanismTransfer partyContactMechanismTransfer = contactControl.getPartyContactMechanismTransfer(userVisit, communicationEventDetail.getPartyContactMechanism());
063            DocumentTransfer documentTransfer = documentControl.getDocumentTransfer(userVisit, communicationEventDetail.getDocument());
064            
065            communicationEventTransfer = new CommunicationEventTransfer(communicationEventName, communicationEventTypeTransfer,
066                    communicationSourceTransfer, communicationEventPurposeTransfer, originalCommunicationEventTransfer,
067                    parentCommunicationEventTransfer, partyContactMechanismTransfer, documentTransfer);
068            put(communicationEvent, communicationEventTransfer);
069            setupOwnedWorkEfforts(communicationEvent, null, communicationEventTransfer);
070        }
071        
072        return communicationEventTransfer;
073    }
074    
075}