DCAE-D be initial commit
[sdc/dcae-d/dt-be-main.git] / dcaedt_validator / checker / src / main / java / org / onap / sdc / dcae / checker / Workflows.java
1 package org.onap.sdc.dcae.checker;
2
3 import java.util.Map;
4
5 import org.onap.sdc.dcae.checker.annotations.Checks;
6
7 import java.util.List;
8 import java.util.Iterator;
9
10 @Checks
11 public class Workflows {
12
13         @Checks(path="/topology_template/workflows")
14         public void check_workflows(Map theDefinition, Checker.CheckContext theContext) {
15
16                 theContext.enter("workflows");
17                 
18                 try {
19                         if(!theContext.checker().checkDefinition("workflows", theDefinition, theContext))
20                                 return;
21
22           for (Iterator<Map.Entry<String,Map>> i = theDefinition.entrySet().iterator(); i.hasNext(); ) {
23           Map.Entry<String,Map> e = i.next();
24                                 check_workflow_definition(e.getKey(), e.getValue(), theContext);
25         }
26                 }
27                 finally {
28                         theContext.exit();
29                 }
30         }
31
32
33         public void check_workflow_definition(String theName, Map theDef, Checker.CheckContext theContext) {
34                 
35                 theContext.enter("workflow", Construct.Workflow);
36
37                 if (theDef.containsKey("inputs")) {
38         theContext
39                                 .checker()
40                                         .checkProperties((Map<String,Map>)theDef.get("inputs"), theContext);
41     }
42
43                 if (theDef.containsKey("preconditions")) {
44                         check_workflow_preconditions_definition((List<Map>)theDef.get("preconditions"), theContext);
45                 }
46
47                 if (theDef.containsKey("steps")) {
48                         check_workflow_steps_definition((Map<String, Map>)theDef.get("steps"), theContext);
49                 }
50
51                 theContext.exit();
52         }
53           
54
55         public void check_workflow_steps_definition(Map theSteps, Checker.CheckContext theContext) {
56                 
57                 theContext.enter("steps");
58
59                 try {
60                         for (Iterator<Map.Entry<String,Map>> i = theSteps.entrySet().iterator(); i.hasNext(); ) {
61                 Map.Entry<String,Map> e = i.next();
62                                 check_workflow_step_definition(e.getKey(), e.getValue(), theContext);
63         }
64                 }
65                 finally {
66                         theContext.exit();
67                 }
68
69         }
70
71         public void check_workflow_step_definition(String theName, Map theDef, Checker.CheckContext theContext) {
72
73                 theContext.enter(theName);
74                 try {
75                         //requireed entry, must be a node or group template
76                         String          target = (String)theDef.get("target");
77                         Construct targetConstruct = null;
78
79                         if (theContext.catalog().hasTemplate(theContext.target(), Construct.Group, target)) {
80                                 targetConstruct = Construct.Group;
81                         }
82                         else if (theContext.catalog().hasTemplate(theContext.target(), Construct.Node, target)) {
83                                 targetConstruct = Construct.Node;
84                         }
85                         else {
86                                 theContext.addError("The 'target' entry must contain a reference to a node template or group template, '" + target + "' is none of those", null);
87                         }
88
89                         String targetRelationship = (String)theDef.get("target_relationship");
90                         if (targetConstruct.equals(Construct.Node)) {
91                                 if (targetRelationship != null) {
92                                         //must be a requirement of the target Node
93                                 }
94                         }
95
96                         
97                 }
98                 finally {
99                         theContext.exit();
100                 }
101         }
102
103         public void check_workflow_preconditions_definition(List<Map> thePreconditions, Checker.CheckContext theContext) {
104                 
105                 theContext.enter("preconditions");
106
107                 try {
108                         for (Map precondition: thePreconditions) {
109                                 check_workflow_precondition_definition(precondition, theContext);
110         }
111                 }
112                 finally {
113                         theContext.exit();
114                 }
115         }
116
117         public void check_workflow_precondition_definition(Map theDef, Checker.CheckContext theContext) {
118         }
119
120 }