Bump MRI upstreams
[netconf.git] / restconf / sal-rest-docgen / src / main / java / org / opendaylight / netconf / sal / rest / doc / impl / BaseYangSwaggerGeneratorRFC8040.java
1 /*
2  * Copyright (c) 2018 Inocybe Technologies 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.netconf.sal.rest.doc.impl;
9
10 import java.util.Optional;
11 import org.opendaylight.mdsal.dom.api.DOMSchemaService;
12
13 /**
14  * Base class for an RFC 8040 implementation.
15  *
16  * @author Thomas Pantelis
17  */
18 public abstract class BaseYangSwaggerGeneratorRFC8040 extends BaseYangSwaggerGenerator {
19
20     private static final String DEFAULT_BASE_PATH = "rests";
21     private static final String PATH_VERSION = "rfc8040";
22     private final String basePath;
23
24     protected BaseYangSwaggerGeneratorRFC8040(final Optional<DOMSchemaService> schemaService) {
25         super(schemaService);
26         this.basePath = DEFAULT_BASE_PATH;
27     }
28
29     protected BaseYangSwaggerGeneratorRFC8040(final Optional<DOMSchemaService> schemaService, final String basePath) {
30         super(schemaService);
31         this.basePath = basePath;
32     }
33
34     @Override
35     protected String getPathVersion() {
36         return PATH_VERSION;
37     }
38
39     @Override
40     public String getResourcePath(final String resourceType, final String context) {
41         if (isData(resourceType)) {
42             return "/" + basePath + "/data" + context;
43         }
44         return "/" + basePath + "/operations" + context;
45     }
46
47     @Override
48     public String getResourcePathPart(final String resourceType) {
49         if (isData(resourceType)) {
50             return "data";
51         }
52         return "operations";
53     }
54
55     private static boolean isData(final String dataStore) {
56         return "config".contains(dataStore) || "operational".contains(dataStore);
57     }
58
59     @Override
60     protected ListPathBuilder newListPathBuilder() {
61         return new ListPathBuilder() {
62             private String prefix = "=";
63
64             @Override
65             public String nextParamIdentifier(final String key) {
66                 final String str = prefix + "{" + key + "}";
67                 prefix = ",";
68                 return str;
69             }
70         };
71     }
72
73     @Override
74     protected void appendPathKeyValue(final StringBuilder builder, final Object value) {
75         builder.deleteCharAt(builder.length() - 1).append("=").append(value).append('/');
76     }
77 }