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.associate.server.transfer;
018
019import com.echothree.model.control.associate.common.transfer.AssociateProgramTransfer;
020import com.echothree.model.control.associate.common.transfer.AssociateTransfer;
021import com.echothree.model.control.associate.server.control.AssociateControl;
022import com.echothree.model.control.core.common.transfer.MimeTypeTransfer;
023import com.echothree.model.control.core.server.control.CoreControl;
024import com.echothree.model.control.party.common.transfer.PartyTransfer;
025import com.echothree.model.control.party.server.control.PartyControl;
026import com.echothree.model.data.associate.server.entity.Associate;
027import com.echothree.model.data.associate.server.entity.AssociateDetail;
028import com.echothree.model.data.user.server.entity.UserVisit;
029import com.echothree.util.server.persistence.Session;
030
031public class AssociateTransferCache
032        extends BaseAssociateTransferCache<Associate, AssociateTransfer> {
033    
034    CoreControl coreControl = Session.getModelController(CoreControl.class);
035    PartyControl partyControl = Session.getModelController(PartyControl.class);
036    
037    /** Creates a new instance of AssociateTransferCache */
038    public AssociateTransferCache(UserVisit userVisit, AssociateControl associateControl) {
039        super(userVisit, associateControl);
040        
041        setIncludeEntityInstance(true);
042    }
043    
044    @Override
045    public AssociateTransfer getTransfer(Associate associate) {
046        AssociateTransfer associateTransfer = get(associate);
047        
048        if(associateTransfer == null) {
049            AssociateDetail associateDetail = associate.getLastDetail();
050            AssociateProgramTransfer associateProgram = associateControl.getAssociateProgramTransfer(userVisit, associateDetail.getAssociateProgram());
051            String associateName = associateDetail.getAssociateName();
052            PartyTransfer party = partyControl.getPartyTransfer(userVisit, associateDetail.getParty());
053            String description = associateDetail.getDescription();
054            MimeTypeTransfer summaryMimeType = coreControl.getMimeTypeTransfer(userVisit, associateDetail.getSummaryMimeType());
055            String summary = associateDetail.getSummary();
056            
057            associateTransfer = new AssociateTransfer(associateProgram, associateName, party, description, summaryMimeType, summary);
058            put(associate, associateTransfer);
059        }
060        return associateTransfer;
061    }
062    
063}