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.employee.server.graphql; 018 019import com.echothree.model.control.employee.common.workflow.EmployeeAvailabilityConstants; 020import com.echothree.model.control.employee.common.workflow.EmployeeStatusConstants; 021import com.echothree.model.control.employee.server.control.EmployeeControl; 022import com.echothree.model.control.party.server.graphql.BasePartyObject; 023import com.echothree.model.control.workflow.server.graphql.WorkflowEntityStatusObject; 024import com.echothree.model.data.employee.server.entity.PartyEmployee; 025import com.echothree.model.data.party.server.entity.Party; 026import com.echothree.util.server.persistence.Session; 027import graphql.annotations.annotationTypes.GraphQLDescription; 028import graphql.annotations.annotationTypes.GraphQLField; 029import graphql.annotations.annotationTypes.GraphQLName; 030import graphql.annotations.annotationTypes.GraphQLNonNull; 031import graphql.schema.DataFetchingEnvironment; 032 033@GraphQLDescription("employee object") 034@GraphQLName("Employee") 035public class EmployeeObject 036 extends BasePartyObject { 037 038 public EmployeeObject(Party party) { 039 super(party); 040 } 041 042 public EmployeeObject(PartyEmployee partyEmployee) { 043 super(partyEmployee.getParty()); 044 045 this.partyEmployee = partyEmployee; 046 } 047 048 private PartyEmployee partyEmployee; // Optional, use getEmployee() 049 050 protected PartyEmployee getPartyEmployee() { 051 if(partyEmployee == null) { 052 var employeeControl = Session.getModelController(EmployeeControl.class); 053 054 partyEmployee = employeeControl.getPartyEmployee(party); 055 } 056 057 return partyEmployee; 058 } 059 060 @GraphQLField 061 @GraphQLDescription("employee name") 062 @GraphQLNonNull 063 public String getEmployeeName() { 064 return getPartyEmployee().getPartyEmployeeName(); 065 } 066 067// @GraphQLField 068// @GraphQLDescription("employee type") 069// @GraphQLNonNull 070// public EmployeeTypeObject getEmployeeType(final DataFetchingEnvironment env) { 071// return EmployeeSecurityUtils.getHasEmployeeTypeAccess(env) ? 072// new EmployeeTypeObject(getEmployee().getEmployeeType()) : null; 073// } 074 075 076 @GraphQLField 077 @GraphQLDescription("employee status") 078 public WorkflowEntityStatusObject getEmployeeStatus(final DataFetchingEnvironment env) { 079 return getWorkflowEntityStatusObject(env, EmployeeStatusConstants.Workflow_EMPLOYEE_STATUS); 080 } 081 082 083 @GraphQLField 084 @GraphQLDescription("employee availability") 085 public WorkflowEntityStatusObject getEmployeeAvailability(final DataFetchingEnvironment env) { 086 return getWorkflowEntityStatusObject(env, EmployeeAvailabilityConstants.Workflow_EMPLOYEE_AVAILABILITY); 087 } 088 089}