001// -------------------------------------------------------------------------------- 002// Copyright 2002-2025 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.comment.common.CommentConstants; 020import com.echothree.model.control.contact.common.ContactMechanismTypes; 021import com.echothree.model.control.contact.common.ContactOptions; 022import com.echothree.model.control.contact.common.transfer.ContactMechanismTransfer; 023import com.echothree.model.control.contact.server.control.ContactControl; 024import com.echothree.model.data.contact.server.entity.ContactMechanism; 025import com.echothree.model.data.user.server.entity.UserVisit; 026import com.echothree.util.server.persistence.Session; 027import javax.enterprise.context.RequestScoped; 028 029@RequestScoped 030public class ContactMechanismTransferCache 031 extends BaseContactTransferCache<ContactMechanism, ContactMechanismTransfer> { 032 033 ContactControl contactControl = Session.getModelController(ContactControl.class); 034 035 boolean includeComments; 036 037 /** Creates a new instance of ContactMechanismTransferCache */ 038 protected ContactMechanismTransferCache() { 039 super(); 040 041 var options = session.getOptions(); 042 if(options != null) { 043 setIncludeUuid(options.contains(ContactOptions.ContactMechanismIncludeUuid)); 044 includeComments = options.contains(ContactOptions.ContactMechanismIncludeComments); 045 setIncludeEntityAttributeGroups(options.contains(ContactOptions.ContactMechanismIncludeEntityAttributeGroups)); 046 setIncludeTagScopes(options.contains(ContactOptions.ContactMechanismIncludeTagScopes)); 047 } 048 049 setIncludeEntityInstance(true); 050 } 051 052 public ContactMechanismTransfer getContactMechanismTransfer(UserVisit userVisit, ContactMechanism contactMechanism) { 053 var contactMechanismTransfer = get(contactMechanism); 054 055 if(contactMechanismTransfer == null) { 056 var contactMechanismDetail = contactMechanism.getLastDetail(); 057 var contactMechanismName = contactMechanismDetail.getContactMechanismName(); 058 var contactMechanismType = contactControl.getContactMechanismTypeTransfer(userVisit, 059 contactMechanismDetail.getContactMechanismType()); 060 var allowSolicitation = contactMechanismDetail.getAllowSolicitation(); 061 062 contactMechanismTransfer = new ContactMechanismTransfer(contactMechanismName, contactMechanismType, allowSolicitation); 063 put(userVisit, contactMechanism, contactMechanismTransfer); 064 065 var contactMechanismTypeName = contactMechanismType.getContactMechanismTypeName(); 066 067 if(contactMechanismTypeName.equals(ContactMechanismTypes.POSTAL_ADDRESS.name())) { 068 contactMechanismTransfer.setContactPostalAddress(contactControl.getContactPostalAddressTransfer(userVisit, contactControl.getContactPostalAddress(contactMechanism)) ); 069 } else if(contactMechanismTypeName.equals(ContactMechanismTypes.EMAIL_ADDRESS.name())) { 070 contactMechanismTransfer.setContactEmailAddress(contactControl.getContactEmailAddressTransfer(userVisit, contactControl.getContactEmailAddress(contactMechanism))); 071 } else if(contactMechanismTypeName.equals(ContactMechanismTypes.TELECOM_ADDRESS.name())) { 072 contactMechanismTransfer.setContactTelephone(contactControl.getContactTelephoneTransfer(userVisit, contactControl.getContactTelephone(contactMechanism))); 073 } else if(contactMechanismTypeName.equals(ContactMechanismTypes.WEB_ADDRESS.name())) { 074 contactMechanismTransfer.setContactWebAddress(contactControl.getContactWebAddressTransfer(userVisit, contactControl.getContactWebAddress(contactMechanism))); 075 } else if(contactMechanismTypeName.equals(ContactMechanismTypes.INET_4.name())) { 076 contactMechanismTransfer.setContactInet4Address(contactControl.getContactInet4AddressTransfer(userVisit, contactControl.getContactInet4Address(contactMechanism))); 077 } 078 079 if(includeComments) { 080 setupComments(userVisit, contactMechanism, null, contactMechanismTransfer, CommentConstants.CommentType_CONTACT_MECHANISM); 081 } 082 } 083 084 return contactMechanismTransfer; 085 } 086 087}