Merge "Adding tunnel ipv4 src/dst flow-base model augmentations"
[controller.git] / opendaylight / md-sal / sal-rest-docgen / src / main / java / org / opendaylight / controller / sal / rest / doc / model / builder / OperationBuilder.java
1 /*
2  * Copyright (c) 2014 Cisco Systems, Inc. and others.  All rights reserved.
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6  * and is available at http://www.eclipse.org/legal/epl-v10.html
7  */
8 package org.opendaylight.controller.sal.rest.doc.model.builder;
9
10 import java.util.ArrayList;
11 import java.util.List;
12
13 import org.opendaylight.controller.sal.rest.doc.swagger.Operation;
14 import org.opendaylight.controller.sal.rest.doc.swagger.Parameter;
15 import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
16
17 /**
18  *
19  */
20 public final class OperationBuilder {
21
22     public static final String OPERATIONAL = "(operational)";
23     public static final String CONFIG = "(config)";
24
25     /**
26    *
27    */
28     public static class Get {
29
30         protected Operation spec;
31         protected DataSchemaNode schemaNode;
32         private final String METHOD_NAME = "GET";
33
34         public Get(DataSchemaNode node, boolean isConfig) {
35             this.schemaNode = node;
36             spec = new Operation();
37             spec.setMethod(METHOD_NAME);
38             spec.setNickname(METHOD_NAME + "-" + node.getQName().getLocalName());
39             spec.setType((isConfig ? CONFIG : OPERATIONAL) + node.getQName().getLocalName());
40             spec.setNotes(node.getDescription());
41         }
42
43         public Get pathParams(List<Parameter> params) {
44             List<Parameter> pathParameters = new ArrayList<>(params);
45             spec.setParameters(pathParameters);
46             return this;
47         }
48
49         public Operation build() {
50             return spec;
51         }
52     }
53
54     /**
55    *
56    */
57     public static class Put {
58         protected Operation spec;
59         protected DataSchemaNode schemaNode;
60         private final String METHOD_NAME = "PUT";
61
62         public Put(DataSchemaNode node) {
63             this.schemaNode = node;
64             spec = new Operation();
65             spec.setType(CONFIG + node.getQName().getLocalName());
66             spec.setNotes(node.getDescription());
67         }
68
69         public Put pathParams(List<Parameter> params) {
70             List<Parameter> parameters = new ArrayList<>(params);
71             Parameter payload = new Parameter();
72             payload.setParamType("body");
73             payload.setType(CONFIG + schemaNode.getQName().getLocalName());
74             parameters.add(payload);
75             spec.setParameters(parameters);
76             return this;
77         }
78
79         public Operation build() {
80             spec.setMethod(METHOD_NAME);
81             spec.setNickname(METHOD_NAME + "-" + schemaNode.getQName().getLocalName());
82             return spec;
83         }
84     }
85
86     /**
87    *
88    */
89     public static final class Post extends Put {
90
91         private final String METHOD_NAME = "POST";
92
93         public Post(DataSchemaNode node) {
94             super(node);
95         }
96
97         @Override
98         public Operation build() {
99             spec.setMethod(METHOD_NAME);
100             spec.setNickname(METHOD_NAME + "-" + schemaNode.getQName().getLocalName());
101             return spec;
102         }
103     }
104
105     /**
106    *
107    */
108     public static final class Delete extends Get {
109         private final String METHOD_NAME = "DELETE";
110
111         public Delete(DataSchemaNode node) {
112             super(node, false);
113         }
114
115         @Override
116         public Operation build() {
117             spec.setMethod(METHOD_NAME);
118             spec.setNickname(METHOD_NAME + "-" + schemaNode.getQName().getLocalName());
119             spec.setType(null);
120             return spec;
121         }
122     }
123 }