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.core.server.transfer;
018
019import com.echothree.model.control.core.common.transfer.EntityGeoPointDefaultTransfer;
020import com.echothree.model.control.core.server.control.CoreControl;
021import com.echothree.model.control.uom.common.UomConstants;
022import com.echothree.model.control.uom.server.control.UomControl;
023import com.echothree.model.data.core.server.entity.EntityGeoPointDefault;
024import com.echothree.model.data.uom.server.entity.UnitOfMeasureKind;
025import com.echothree.model.data.user.server.entity.UserVisit;
026import com.echothree.util.common.string.GeoPointUtils;
027import com.echothree.util.server.persistence.Session;
028import javax.enterprise.context.RequestScoped;
029
030@RequestScoped
031public class EntityGeoPointDefaultTransferCache
032        extends BaseCoreTransferCache<EntityGeoPointDefault, EntityGeoPointDefaultTransfer> {
033
034    CoreControl coreControl = Session.getModelController(CoreControl.class);
035    UomControl uomControl = Session.getModelController(UomControl.class);
036    UnitOfMeasureKind elevationUnitOfMeasureKind = uomControl.getUnitOfMeasureKindByUnitOfMeasureKindUseTypeUsingNames(UomConstants.UnitOfMeasureKindUseType_ELEVATION);
037    UnitOfMeasureKind altitudeUnitOfMeasureKind = uomControl.getUnitOfMeasureKindByUnitOfMeasureKindUseTypeUsingNames(UomConstants.UnitOfMeasureKindUseType_ALTITUDE);
038    GeoPointUtils geoPointUtils = GeoPointUtils.getInstance();
039    
040    /** Creates a new instance of EntityGeoPointDefaultTransferCache */
041    protected EntityGeoPointDefaultTransferCache() {
042        super();
043    }
044    
045    public EntityGeoPointDefaultTransfer getEntityGeoPointDefaultTransfer(final UserVisit userVisit, final EntityGeoPointDefault entityGeoPointDefault) {
046        var entityGeoPointDefaultTransfer = get(entityGeoPointDefault);
047        
048        if(entityGeoPointDefaultTransfer == null) {
049            var entityAttribute = coreControl.getEntityAttributeTransfer(userVisit, entityGeoPointDefault.getEntityAttribute(), null);
050            var unformattedLatitude = entityGeoPointDefault.getLatitude();
051            var latitude = geoPointUtils.formatDegrees(unformattedLatitude);
052            var unformattedLongitude = entityGeoPointDefault.getLongitude();
053            var longitude = geoPointUtils.formatDegrees(unformattedLongitude);
054            var elevation = formatUnitOfMeasure(userVisit, elevationUnitOfMeasureKind, entityGeoPointDefault.getElevation());
055            var altitude = formatUnitOfMeasure(userVisit, altitudeUnitOfMeasureKind, entityGeoPointDefault.getAltitude());
056            
057            entityGeoPointDefaultTransfer = new EntityGeoPointDefaultTransfer(entityAttribute, unformattedLatitude, latitude,
058                    unformattedLongitude, longitude, elevation, altitude);
059            put(userVisit, entityGeoPointDefault, entityGeoPointDefaultTransfer);
060        }
061        
062        return entityGeoPointDefaultTransfer;
063    }
064    
065}