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.workflow.WebAddressStatusConstants;
020import com.echothree.model.control.contact.common.transfer.ContactWebAddressTransfer;
021import com.echothree.model.control.contact.server.control.ContactControl;
022import com.echothree.model.control.core.server.control.CoreControl;
023import com.echothree.model.control.workflow.common.transfer.WorkflowEntityStatusTransfer;
024import com.echothree.model.control.workflow.server.control.WorkflowControl;
025import com.echothree.model.data.contact.server.entity.ContactWebAddress;
026import com.echothree.model.data.core.server.entity.EntityInstance;
027import com.echothree.model.data.user.server.entity.UserVisit;
028import com.echothree.util.server.persistence.Session;
029
030public class ContactWebAddressTransferCache
031        extends BaseContactTransferCache<ContactWebAddress, ContactWebAddressTransfer> {
032    
033    CoreControl coreControl = Session.getModelController(CoreControl.class);
034    WorkflowControl workflowControl = Session.getModelController(WorkflowControl.class);
035
036    /** Creates a new instance of ContactWebAddressTransferCache */
037    public ContactWebAddressTransferCache(UserVisit userVisit, ContactControl contactControl) {
038        super(userVisit, contactControl);
039    }
040    
041    public ContactWebAddressTransfer getContactWebAddressTransfer(ContactWebAddress contactWebAddress) {
042        ContactWebAddressTransfer contactWebAddressTransfer = get(contactWebAddress);
043        
044        if(contactWebAddressTransfer == null) {
045            String url = contactWebAddress.getUrl();
046            
047            EntityInstance entityInstance = coreControl.getEntityInstanceByBasePK(contactWebAddress.getContactMechanismPK());
048            WorkflowEntityStatusTransfer webAddressStatusTransfer = workflowControl.getWorkflowEntityStatusTransferByEntityInstanceUsingNames(userVisit,
049                    WebAddressStatusConstants.Workflow_WEB_ADDRESS_STATUS, entityInstance);
050            
051            contactWebAddressTransfer = new ContactWebAddressTransfer(url, webAddressStatusTransfer);
052            put(contactWebAddress, contactWebAddressTransfer);
053        }
054        
055        return contactWebAddressTransfer;
056    }
057    
058}