001// -------------------------------------------------------------------------------- 002// Copyright 2002-2026 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.control.user.sales.server.command; 018 019import com.echothree.control.user.sales.common.form.GetSalesOrderTimesForm; 020import com.echothree.control.user.sales.common.result.SalesResultFactory; 021import com.echothree.model.control.order.server.control.OrderControl; 022import com.echothree.model.control.order.server.control.OrderTimeControl; 023import com.echothree.model.control.sales.server.logic.SalesOrderLogic; 024import com.echothree.model.data.order.server.entity.Order; 025import com.echothree.model.data.order.server.entity.OrderTime; 026import com.echothree.model.data.order.server.factory.OrderTimeFactory; 027import com.echothree.util.common.command.BaseResult; 028import com.echothree.util.common.validation.FieldDefinition; 029import com.echothree.util.common.validation.FieldType; 030import com.echothree.util.server.control.BasePaginatedMultipleEntitiesCommand; 031import java.util.Collection; 032import java.util.List; 033import javax.enterprise.context.Dependent; 034import javax.inject.Inject; 035 036@Dependent 037public class GetSalesOrderTimesCommand 038 extends BasePaginatedMultipleEntitiesCommand<OrderTime, GetSalesOrderTimesForm> { 039 040 private final static List<FieldDefinition> FORM_FIELD_DEFINITIONS; 041 042 static { 043 FORM_FIELD_DEFINITIONS = List.of( 044 new FieldDefinition("OrderName", FieldType.ENTITY_NAME, true, null, null) 045 ); 046 } 047 048 @Inject 049 OrderControl orderControl; 050 051 @Inject 052 OrderTimeControl orderTimeControl; 053 054 @Inject 055 SalesOrderLogic salesOrderLogic; 056 057 058 059 /** Creates a new instance of GetSalesOrderTimesCommand */ 060 public GetSalesOrderTimesCommand() { 061 super(null, FORM_FIELD_DEFINITIONS, true); 062 } 063 064 Order order; 065 066 @Override 067 protected void handleForm() { 068 order = salesOrderLogic.getOrderByName(this, form.getOrderName()); 069 } 070 071 @Override 072 protected Long getTotalEntities() { 073 return hasExecutionErrors() ? null : orderTimeControl.countOrderTimesByOrder(order); 074 } 075 076 @Override 077 protected Collection<OrderTime> getEntities() { 078 return hasExecutionErrors() ? null : orderTimeControl.getOrderTimesByOrder(order); 079 } 080 081 @Override 082 protected BaseResult getResult(Collection<OrderTime> entities) { 083 var result = SalesResultFactory.getGetSalesOrderTimesResult(); 084 085 if(entities != null) { 086 var userVisit = getUserVisit(); 087 088 result.setOrder(orderControl.getOrderTransfer(userVisit, order)); 089 090 if(session.hasLimit(OrderTimeFactory.class)) { 091 result.setOrderTimeCount(getTotalEntities()); 092 } 093 094 result.setOrderTimes(orderTimeControl.getOrderTimeTransfers(userVisit, entities)); 095 } 096 097 return result; 098 } 099 100}