Skip to main content
summaryrefslogtreecommitdiffstats
blob: 0536bd0221e6c84f1eee49e2d007797a74f38d03 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
/*******************************************************************************
 * Copyright (c) 2011 Boeing.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     Boeing - initial API and implementation
 *******************************************************************************/
package org.eclipse.osee.ats.core.validator;

import java.util.LinkedList;
import java.util.List;
import org.eclipse.osee.ats.api.IAtsServices;
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;

/**
 * @author Donald G. Dunne
 */
public class AtsXWidgetValidateManager {
   public static AtsXWidgetValidateManager instance = new AtsXWidgetValidateManager();
   private final List<AtsXWidgetValidatorProvider> providers = new LinkedList<>();

   protected AtsXWidgetValidateManager() {
   }

   public void validateTransition(List<WidgetResult> results, IValueProvider valueProvider, IAtsWidgetDefinition widgetDef, IAtsStateDefinition fromStateDef, IAtsStateDefinition toStateDef, IAtsServices atsServices) {
      for (AtsXWidgetValidatorProvider provider : providers) {
         for (IAtsXWidgetValidator validator : provider.getValidators()) {
            try {
               WidgetResult status =
                  validator.validateTransition(valueProvider, widgetDef, fromStateDef, toStateDef, atsServices);
               if (!status.isValid()) {
                  results.add(status);
               }
            } catch (Exception ex) {
               results.add(new WidgetResult(WidgetStatus.Exception, widgetDef, ex, String.format(
                  "Exception retriving validation for widget [%s] Exception [%s]",
                  validator.getClass().getSimpleName(), ex.getLocalizedMessage()), ex));
               return;
            }
         }
      }
   }

   public void add(AtsXWidgetValidatorProvider provider) {
      providers.add(provider);
   }

}

Back to the top