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.core.common.workflow.EventGroupStatusConstants;
020import com.echothree.model.control.graphql.server.graphql.BaseEntityInstanceObject;
021import com.echothree.model.control.workflow.server.graphql.WorkflowEntityStatusObject;
022import com.echothree.model.data.core.server.entity.EventGroup;
023import com.echothree.model.data.core.server.entity.EventGroupDetail;
024import graphql.annotations.annotationTypes.GraphQLDescription;
025import graphql.annotations.annotationTypes.GraphQLField;
026import graphql.annotations.annotationTypes.GraphQLName;
027import graphql.annotations.annotationTypes.GraphQLNonNull;
028import graphql.schema.DataFetchingEnvironment;
029
030@GraphQLDescription("event group object")
031@GraphQLName("EventGroup")
032public class EventGroupObject
033        extends BaseEntityInstanceObject {
034    
035    private final EventGroup eventGroup; // Always Present
036    
037    public EventGroupObject(EventGroup eventGroup) {
038        super(eventGroup.getPrimaryKey());
039        
040        this.eventGroup = eventGroup;
041    }
042
043    private EventGroupDetail eventGroupDetail; // Optional, use getEventGroupDetail()
044    
045    private EventGroupDetail getEventGroupDetail() {
046        if(eventGroupDetail == null) {
047            eventGroupDetail = eventGroup.getLastDetail();
048        }
049        
050        return eventGroupDetail;
051    }
052    
053    @GraphQLField
054    @GraphQLDescription("event group name")
055    @GraphQLNonNull
056    public String getEventGroupName() {
057        return getEventGroupDetail().getEventGroupName();
058    }
059
060    @GraphQLField
061    @GraphQLDescription("event group status")
062    public WorkflowEntityStatusObject getEventGroupStatus(final DataFetchingEnvironment env) {
063        return getWorkflowEntityStatusObject(env, EventGroupStatusConstants.Workflow_EVENT_GROUP_STATUS);
064    }
065
066}