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.core.server.graphql; 018 019import com.echothree.model.control.graphql.server.graphql.BaseObject; 020import com.echothree.model.control.graphql.server.graphql.TimeObject; 021import com.echothree.model.data.core.server.entity.Event; 022import graphql.annotations.annotationTypes.GraphQLDescription; 023import graphql.annotations.annotationTypes.GraphQLField; 024import graphql.annotations.annotationTypes.GraphQLName; 025import graphql.annotations.annotationTypes.GraphQLNonNull; 026import graphql.schema.DataFetchingEnvironment; 027 028@GraphQLDescription("event object") 029@GraphQLName("Event") 030public class EventObject 031 extends BaseObject { 032 033 private final Event event; // Always Present 034 035 public EventObject(Event event) { 036 this.event = event; 037 } 038 039 @GraphQLField 040 @GraphQLDescription("event group") 041 public EventGroupObject getEventGroup() { 042 var eventgroup = event.getEventGroup(); 043 044 return eventgroup == null ? null : new EventGroupObject(eventgroup); 045 } 046 047 @GraphQLField 048 @GraphQLDescription("event time") 049 @GraphQLNonNull 050 public TimeObject getEventTime(final DataFetchingEnvironment env) { 051 return new TimeObject(event.getEventTime()); 052 } 053 054 @GraphQLField 055 @GraphQLDescription("event time sequence") 056 @GraphQLNonNull 057 public int getSortOrder() { 058 return event.getEventTimeSequence(); 059 } 060 061 @GraphQLField 062 @GraphQLDescription("entity instance") 063 @GraphQLNonNull 064 public EntityInstanceObject getEntityInstance() { 065 return new EntityInstanceObject(event.getEntityInstance()); 066 } 067 068 @GraphQLField 069 @GraphQLDescription("event type") 070 @GraphQLNonNull 071 public EventTypeObject getEventType() { 072 return new EventTypeObject(event.getEventType()); 073 } 074 075 @GraphQLField 076 @GraphQLDescription("related entity instance") 077 public EntityInstanceObject getRelatedEntityInstance(final DataFetchingEnvironment env) { 078 var relatedEntityInstance = event.getRelatedEntityInstance(); 079 080 return relatedEntityInstance != null && CoreSecurityUtils.getHasEntityInstanceAccess(env) ? new EntityInstanceObject(relatedEntityInstance) : null; 081 } 082 083 @GraphQLField 084 @GraphQLDescription("related event type") 085 public EventTypeObject getRelatedEventType() { 086 var relatedEventType = event.getRelatedEventType(); 087 088 return relatedEventType == null ? null : new EventTypeObject(relatedEventType); 089 } 090 091 @GraphQLField 092 @GraphQLDescription("created by") 093 public EntityInstanceObject getCreatedBy(final DataFetchingEnvironment env) { 094 var createdBy = event.getCreatedBy(); 095 096 return createdBy != null && CoreSecurityUtils.getHasEntityInstanceAccess(env) ? new EntityInstanceObject(createdBy) : null; 097 } 098 099}