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.user.server.graphql; 018 019import com.echothree.model.control.accounting.server.graphql.AccountingSecurityUtils; 020import com.echothree.model.control.accounting.server.graphql.CurrencyObject; 021import com.echothree.model.control.graphql.server.graphql.TimeObject; 022import com.echothree.model.control.graphql.server.util.BaseGraphQl; 023import com.echothree.model.control.offer.server.graphql.OfferSecurityUtils; 024import com.echothree.model.control.offer.server.graphql.OfferUseObject; 025import com.echothree.model.control.party.server.graphql.DateTimeFormatObject; 026import com.echothree.model.control.party.server.graphql.LanguageObject; 027import com.echothree.model.control.party.server.graphql.PartySecurityUtils; 028import com.echothree.model.control.party.server.graphql.TimeZoneObject; 029import com.echothree.model.data.accounting.server.entity.Currency; 030import com.echothree.model.data.party.server.entity.DateTimeFormat; 031import com.echothree.model.data.party.server.entity.Language; 032import com.echothree.model.data.party.server.entity.TimeZone; 033import com.echothree.model.data.user.server.entity.UserVisit; 034import graphql.annotations.annotationTypes.GraphQLDescription; 035import graphql.annotations.annotationTypes.GraphQLField; 036import graphql.annotations.annotationTypes.GraphQLName; 037import graphql.annotations.annotationTypes.GraphQLNonNull; 038import graphql.schema.DataFetchingEnvironment; 039 040@GraphQLDescription("user visit object") 041@GraphQLName("UserVisit") 042public class UserVisitObject 043 implements BaseGraphQl { 044 045 private final UserVisit userVisit; // Always Present 046 047 public UserVisitObject(UserVisit userVisit) { 048 this.userVisit = userVisit; 049 } 050 051// @GraphQLField 052// @GraphQLDescription("user visit group") 053// public UserVisitGroupObject getUserVisitGroup() { 054// UserVisitGroup userVisitGroup = userVisit.getUserVisitGroup(); 055// 056// return userVisitGroup == null ? null : new UserVisitGroupObject(userVisitGroup); 057// } 058// 059// @GraphQLField 060// @GraphQLDescription("user key") 061// public UserKeyObject getUserKey() { 062// UserKey userKey = userVisit.getUserKey(); 063// 064// return userKey == null ? null : new UserKeyObject(userKey); 065// } 066 067 @GraphQLField 068 @GraphQLDescription("preferred language") 069 public LanguageObject getPreferredLanguage(final DataFetchingEnvironment env) { 070 Language preferredLanguage = userVisit.getPreferredLanguage(); 071 072 return preferredLanguage != null && PartySecurityUtils.getHasLanguageAccess(env) ? new LanguageObject(preferredLanguage) : null; 073 } 074 075 @GraphQLField 076 @GraphQLDescription("preferred language") 077 public CurrencyObject getPreferredCurrency(final DataFetchingEnvironment env) { 078 Currency preferredCurrency = userVisit.getPreferredCurrency(); 079 080 return preferredCurrency != null && AccountingSecurityUtils.getHasCurrencyAccess(env) ? new CurrencyObject(preferredCurrency) : null; 081 } 082 083 @GraphQLField 084 @GraphQLDescription("preferred time zone") 085 public TimeZoneObject getPreferredTimeZone(final DataFetchingEnvironment env) { 086 TimeZone preferredTimeZone = userVisit.getPreferredTimeZone(); 087 088 return preferredTimeZone != null && PartySecurityUtils.getHasTimeZoneAccess(env) ? new TimeZoneObject(preferredTimeZone) : null; 089 } 090 091 @GraphQLField 092 @GraphQLDescription("preferred date time format") 093 public DateTimeFormatObject getPreferredDateTimeFormat(final DataFetchingEnvironment env) { 094 DateTimeFormat preferredDateTimeFormat = userVisit.getPreferredDateTimeFormat(); 095 096 return preferredDateTimeFormat != null && PartySecurityUtils.getHasDateTimeFormatAccess(env) ? new DateTimeFormatObject(preferredDateTimeFormat) : null; 097 } 098 099 @GraphQLField 100 @GraphQLDescription("last command time") 101 @GraphQLNonNull 102 public TimeObject getLastCommandTime(final DataFetchingEnvironment env) { 103 return new TimeObject(userVisit.getLastCommandTime()); 104 } 105 106 @GraphQLField 107 @GraphQLDescription("offer use") 108 public OfferUseObject getOfferUse(final DataFetchingEnvironment env) { 109 var offeruse = userVisit.getOfferUse(); 110 111 return offeruse != null && OfferSecurityUtils.getHasOfferUseAccess(env) ? new OfferUseObject(userVisit.getOfferUse()) : null; 112 } 113 114// @GraphQLField 115// @GraphQLDescription("associate referral") 116// public AssociateReferralObject getAssociateReferral() { 117// var associateReferral = userVisit.getAssociateReferral(); 118// 119// return associateReferral != null && AssociateSecurityUtils.getHasAssociateReferralAccess(env) ? new AssociateReferralObject(associateReferral) : null; 120// } 121 122 @GraphQLField 123 @GraphQLDescription("retain until time") 124 public TimeObject getRetainUntilTime(final DataFetchingEnvironment env) { 125 var retainUntilTime = userVisit.getRetainUntilTime(); 126 127 return retainUntilTime == null ? null : new TimeObject(retainUntilTime); 128 } 129}