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.contactlist.server.transfer;
018
019import com.echothree.model.control.contactlist.common.transfer.ContactListFrequencyTransfer;
020import com.echothree.model.control.contactlist.common.transfer.ContactListGroupTransfer;
021import com.echothree.model.control.contactlist.common.transfer.ContactListTransfer;
022import com.echothree.model.control.contactlist.common.transfer.ContactListTypeTransfer;
023import com.echothree.model.control.contactlist.server.ContactListControl;
024import com.echothree.model.control.workflow.common.transfer.WorkflowEntranceTransfer;
025import com.echothree.model.control.workflow.server.control.WorkflowControl;
026import com.echothree.model.data.contactlist.server.entity.ContactList;
027import com.echothree.model.data.contactlist.server.entity.ContactListDetail;
028import com.echothree.model.data.contactlist.server.entity.ContactListFrequency;
029import com.echothree.model.data.user.server.entity.UserVisit;
030import com.echothree.util.server.persistence.Session;
031
032public class ContactListTransferCache
033        extends BaseContactListTransferCache<ContactList, ContactListTransfer> {
034    
035    WorkflowControl workflowControl = Session.getModelController(WorkflowControl.class);
036    
037    /** Creates a new instance of ContactListTransferCache */
038    public ContactListTransferCache(UserVisit userVisit, ContactListControl contactListControl) {
039        super(userVisit, contactListControl);
040        
041        setIncludeEntityInstance(true);
042    }
043    
044    public ContactListTransfer getContactListTransfer(ContactList contactList) {
045        ContactListTransfer contactListTransfer = get(contactList);
046        
047        if(contactListTransfer == null) {
048            ContactListDetail contactListDetail = contactList.getLastDetail();
049            String contactListName = contactListDetail.getContactListName();
050            ContactListGroupTransfer contactListGroupTransfer = contactListControl.getContactListGroupTransfer(userVisit, contactListDetail.getContactListGroup());
051            ContactListTypeTransfer contactListTypeTransfer = contactListControl.getContactListTypeTransfer(userVisit, contactListDetail.getContactListType());
052            ContactListFrequency contactListFrequency = contactListDetail.getContactListFrequency();
053            ContactListFrequencyTransfer contactListFrequencyTransfer = contactListFrequency == null ? null : contactListControl.getContactListFrequencyTransfer(userVisit, contactListFrequency);
054            WorkflowEntranceTransfer defaultPartyContactListStatus = workflowControl.getWorkflowEntranceTransfer(userVisit, contactListDetail.getDefaultPartyContactListStatus());
055            Boolean isDefault = contactListDetail.getIsDefault();
056            Integer sortOrder = contactListDetail.getSortOrder();
057            String description = contactListControl.getBestContactListDescription(contactList, getLanguage());
058            
059            contactListTransfer = new ContactListTransfer(contactListName, contactListGroupTransfer, contactListTypeTransfer, contactListFrequencyTransfer,
060                    defaultPartyContactListStatus, isDefault, sortOrder, description);
061            put(contactList, contactListTransfer);
062        }
063        
064        return contactListTransfer;
065    }
066    
067}