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.transfer.EntityLockTransfer; 020import com.echothree.model.control.core.server.control.CoreControl; 021import com.echothree.model.control.graphql.server.graphql.TimeObject; 022import com.echothree.util.server.persistence.Session; 023import graphql.annotations.annotationTypes.GraphQLDescription; 024import graphql.annotations.annotationTypes.GraphQLField; 025import graphql.annotations.annotationTypes.GraphQLName; 026import graphql.schema.DataFetchingEnvironment; 027 028@GraphQLDescription("entity lock object") 029@GraphQLName("EntityLock") 030public class EntityLockObject { 031 032 private final EntityLockTransfer entityLockTransfer; // Always Present 033 034 public EntityLockObject(EntityLockTransfer entityLockTransfer) { 035 this.entityLockTransfer = entityLockTransfer; 036 } 037 038 @GraphQLField 039 @GraphQLDescription("lock target entity instance") 040 public EntityInstanceObject getLockTargetEntityInstance(final DataFetchingEnvironment env) { 041 EntityInstanceObject result = null; 042 043 if(CoreSecurityUtils.getHasEntityInstanceAccess(env)) { 044 var coreControl = Session.getModelController(CoreControl.class); 045 var entityInstance = coreControl.getEntityInstanceByEntityRef(entityLockTransfer.getLockTargetEntityInstance().getEntityRef()); 046 047 result = new EntityInstanceObject(entityInstance); 048 } 049 050 return result; 051 } 052 053 @GraphQLField 054 @GraphQLDescription("locked by entity instance") 055 public EntityInstanceObject getLockedByEntityInstance(final DataFetchingEnvironment env) { 056 EntityInstanceObject result = null; 057 058 if(CoreSecurityUtils.getHasEntityInstanceAccess(env)) { 059 var coreControl = Session.getModelController(CoreControl.class); 060 var entityInstance = coreControl.getEntityInstanceByEntityRef(entityLockTransfer.getLockedByEntityInstance().getEntityRef()); 061 062 result = new EntityInstanceObject(entityInstance); 063 } 064 065 return result; 066 } 067 068 @GraphQLField 069 @GraphQLDescription("locked time") 070 public TimeObject getLockedTime() { 071 var lockedTime = entityLockTransfer.getUnformattedLockedTime(); 072 073 return lockedTime == null ? null : new TimeObject(lockedTime); 074 } 075 076 @GraphQLField 077 @GraphQLDescription("expiration time") 078 public TimeObject getExpirationTime() { 079 var expirationTime = entityLockTransfer.getUnformattedExpirationTime(); 080 081 return expirationTime == null ? null : new TimeObject(expirationTime); 082 } 083 084}