| /********************************************************************* |
| * Copyright (c) 2021 Boeing |
| * |
| * This program and the accompanying materials are made |
| * available under the terms of the Eclipse Public License 2.0 |
| * which is available at https://www.eclipse.org/legal/epl-2.0/ |
| * |
| * SPDX-License-Identifier: EPL-2.0 |
| * |
| * Contributors: |
| * Boeing - initial API and implementation |
| **********************************************************************/ |
| |
| package org.eclipse.osee.ats.core.validator; |
| |
| import java.util.Arrays; |
| import org.eclipse.osee.ats.api.AtsApi; |
| import org.eclipse.osee.ats.api.IAtsWorkItem; |
| import org.eclipse.osee.ats.api.data.AtsAttributeTypes; |
| import org.eclipse.osee.ats.api.util.IValueProvider; |
| import org.eclipse.osee.ats.api.workdef.IAtsStateDefinition; |
| import org.eclipse.osee.ats.api.workdef.IAtsWidgetDefinition; |
| import org.eclipse.osee.ats.api.workdef.WidgetResult; |
| import org.eclipse.osee.ats.api.workdef.WidgetStatus; |
| import org.eclipse.osee.framework.core.data.AttributeTypeToken; |
| |
| /** |
| * @author Donald G. Dunne |
| */ |
| public class AtsXPointsAttrValidator extends AtsXWidgetValidator { |
| |
| @Override |
| public WidgetResult validateTransition(IAtsWorkItem workItem, IValueProvider provider, IAtsWidgetDefinition widgetDef, IAtsStateDefinition fromStateDef, IAtsStateDefinition toStateDef, AtsApi atsApi) { |
| WidgetResult result = WidgetResult.Success; |
| if ("XEstimatedPointsWidget".equals(widgetDef.getXWidgetName())) { |
| boolean found = false; |
| for (AttributeTypeToken attrType : Arrays.asList(AtsAttributeTypes.Points, AtsAttributeTypes.PointsNumeric)) { |
| if (atsApi.getAttributeResolver().getAttributeCount(workItem, attrType) > 0) { |
| found = true; |
| break; |
| } |
| } |
| if (!found) { |
| result = new WidgetResult(WidgetStatus.Invalid_Incompleted, "[%s] is required for transition to [%s]", |
| widgetDef.getName(), toStateDef.getName()); |
| } |
| } |
| return result; |
| } |
| } |