Merge "Making it easier for cygwin users to run OpenDaylight using run.sh. With this...
[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 org.opendaylight.controller.sal.rest.doc.swagger.Operation;
11 import org.opendaylight.controller.sal.rest.doc.swagger.Parameter;
12 import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
13
14 import java.util.ArrayList;
15 import java.util.List;
16
17 /**
18  *
19  */
20 public final class OperationBuilder {
21
22   /**
23    *
24    */
25   public static class Get{
26
27     protected Operation spec;
28     protected DataSchemaNode schemaNode;
29     private final String METHOD_NAME = "GET";
30
31     public Get(DataSchemaNode node){
32       this.schemaNode = node;
33       spec = new Operation();
34       spec.setMethod(METHOD_NAME);
35       spec.setNickname(METHOD_NAME + "-" + node.getQName().getLocalName());
36       spec.setType(node.getQName().getLocalName());
37       spec.setNotes(node.getDescription());
38     }
39
40     public Get pathParams(List<Parameter> params){
41       List<Parameter> pathParameters = new ArrayList<>(params);
42       spec.setParameters(pathParameters);
43       return this;
44     }
45
46     public Operation build(){
47       return spec;
48     }
49   }
50
51   /**
52    *
53    */
54   public static class Put{
55     protected Operation spec;
56     protected DataSchemaNode schemaNode;
57     private final String METHOD_NAME = "PUT";
58
59     public Put(DataSchemaNode node){
60       this.schemaNode = node;
61       spec = new Operation();
62       spec.setType(node.getQName().getLocalName());
63       spec.setNotes(node.getDescription());
64     }
65
66     public Put pathParams(List<Parameter> params){
67       List<Parameter> parameters = new ArrayList<>(params);
68       Parameter payload = new Parameter();
69       payload.setParamType("body");
70       payload.setType(schemaNode.getQName().getLocalName());
71       parameters.add(payload);
72       spec.setParameters(parameters);
73       return this;
74     }
75
76     public Operation build(){
77       spec.setMethod(METHOD_NAME);
78       spec.setNickname(METHOD_NAME + "-" + schemaNode.getQName().getLocalName());
79       return spec;
80     }
81   }
82
83   /**
84    *
85    */
86   public static final class Post extends Put{
87
88     private final String METHOD_NAME = "POST";
89
90     public Post(DataSchemaNode node){
91       super(node);
92     }
93
94     public Operation build(){
95       spec.setMethod(METHOD_NAME);
96       spec.setNickname(METHOD_NAME + "-" + schemaNode.getQName().getLocalName());
97       return spec;
98     }
99   }
100
101   /**
102    *
103    */
104   public static final class Delete extends Get {
105     private final String METHOD_NAME = "DELETE";
106
107     public Delete(DataSchemaNode node){
108       super(node);
109     }
110
111     public Operation build(){
112       spec.setMethod(METHOD_NAME);
113       spec.setNickname(METHOD_NAME + "-" + schemaNode.getQName().getLocalName());
114       spec.setType(null);
115       return spec;
116     }
117   }
118 }