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.graphql.server.graphql.TimeObject; 020import com.echothree.model.control.graphql.server.util.BaseGraphQl; 021import com.echothree.model.control.party.server.graphql.PartyObject; 022import com.echothree.model.control.party.server.graphql.PartyRelationshipObject; 023import com.echothree.model.control.party.server.graphql.PartySecurityUtils; 024import com.echothree.model.data.user.server.entity.UserSession; 025import graphql.annotations.annotationTypes.GraphQLDescription; 026import graphql.annotations.annotationTypes.GraphQLField; 027import graphql.annotations.annotationTypes.GraphQLName; 028import graphql.annotations.annotationTypes.GraphQLNonNull; 029import graphql.schema.DataFetchingEnvironment; 030 031@GraphQLDescription("user session object") 032@GraphQLName("UserSession") 033public class UserSessionObject 034 implements BaseGraphQl { 035 036 private final UserSession userSession; // Always Present 037 038 public UserSessionObject(UserSession userSession) { 039 this.userSession = userSession; 040 } 041 042 @GraphQLField 043 @GraphQLDescription("user visit") 044 @GraphQLNonNull 045 public UserVisitObject getUserVisit() { 046 return new UserVisitObject(userSession.getUserVisit()); 047 } 048 049 @GraphQLField 050 @GraphQLDescription("party") 051 @GraphQLNonNull 052 public PartyObject getParty() { 053 return new PartyObject(userSession.getParty()); 054 } 055 056 @GraphQLField 057 @GraphQLDescription("party relationship") 058 public PartyRelationshipObject getPartyRelationship(final DataFetchingEnvironment env) { 059 return PartySecurityUtils.getHasPartyRelationshipAccess(env) ? new PartyRelationshipObject(userSession.getPartyRelationship()) : null; 060 } 061 062 @GraphQLField 063 @GraphQLDescription("password verified time") 064 public TimeObject getIdentityVerifiedTime(final DataFetchingEnvironment env) { 065 var identityVerifiedTime = userSession.getIdentityVerifiedTime(); 066 067 return identityVerifiedTime == null ? null : new TimeObject(identityVerifiedTime); 068 } 069 070}