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.EmailAddressStatusConstants;
020import com.echothree.model.control.contact.common.workflow.EmailAddressVerificationConstants;
021import com.echothree.model.control.contact.common.transfer.ContactEmailAddressTransfer;
022import com.echothree.model.control.contact.server.control.ContactControl;
023import com.echothree.model.control.core.server.control.CoreControl;
024import com.echothree.model.control.workflow.common.transfer.WorkflowEntityStatusTransfer;
025import com.echothree.model.control.workflow.server.control.WorkflowControl;
026import com.echothree.model.data.contact.server.entity.ContactEmailAddress;
027import com.echothree.model.data.core.server.entity.EntityInstance;
028import com.echothree.model.data.user.server.entity.UserVisit;
029import com.echothree.util.server.persistence.Session;
030
031public class ContactEmailAddressTransferCache
032        extends BaseContactTransferCache<ContactEmailAddress, ContactEmailAddressTransfer> {
033    
034    CoreControl coreControl = Session.getModelController(CoreControl.class);
035    WorkflowControl workflowControl = Session.getModelController(WorkflowControl.class);
036
037    /** Creates a new instance of ContactEmailAddressTransferCache */
038    public ContactEmailAddressTransferCache(UserVisit userVisit, ContactControl contactControl) {
039        super(userVisit, contactControl);
040    }
041    
042    public ContactEmailAddressTransfer getContactEmailAddressTransfer(ContactEmailAddress contactEmailAddress) {
043        ContactEmailAddressTransfer contactEmailAddressTransfer = get(contactEmailAddress);
044        
045        if(contactEmailAddressTransfer == null) {
046            String emailAddress = contactEmailAddress.getEmailAddress();
047            
048            EntityInstance entityInstance = coreControl.getEntityInstanceByBasePK(contactEmailAddress.getContactMechanismPK());
049            WorkflowEntityStatusTransfer emailAddressStatusTransfer = workflowControl.getWorkflowEntityStatusTransferByEntityInstanceUsingNames(userVisit,
050                    EmailAddressStatusConstants.Workflow_EMAIL_ADDRESS_STATUS, entityInstance);
051            WorkflowEntityStatusTransfer emailAddressVerificationTransfer = workflowControl.getWorkflowEntityStatusTransferByEntityInstanceUsingNames(userVisit,
052                    EmailAddressVerificationConstants.Workflow_EMAIL_ADDRESS_VERIFICATION, entityInstance);
053            
054            contactEmailAddressTransfer = new ContactEmailAddressTransfer(emailAddress, emailAddressStatusTransfer, emailAddressVerificationTransfer);
055            put(contactEmailAddress, contactEmailAddressTransfer);
056        }
057        
058        return contactEmailAddressTransfer;
059    }
060    
061}