Convert rcf8040 from web.xml to programmtic web API
[netconf.git] / restconf / restconf-nb-rfc8040 / src / main / java / org / opendaylight / restconf / nb / rfc8040 / services / wrapper / ServicesWrapper.java
1 /*
2  * Copyright (c) 2016 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.restconf.nb.rfc8040.services.wrapper;
9
10 import javax.ws.rs.Path;
11 import javax.ws.rs.core.Response;
12 import javax.ws.rs.core.UriInfo;
13 import org.opendaylight.mdsal.dom.api.DOMSchemaService;
14 import org.opendaylight.mdsal.dom.api.DOMYangTextSourceProvider;
15 import org.opendaylight.restconf.common.context.NormalizedNodeContext;
16 import org.opendaylight.restconf.common.patch.PatchContext;
17 import org.opendaylight.restconf.common.patch.PatchStatusContext;
18 import org.opendaylight.restconf.common.schema.SchemaExportContext;
19 import org.opendaylight.restconf.nb.rfc8040.handlers.DOMDataBrokerHandler;
20 import org.opendaylight.restconf.nb.rfc8040.handlers.DOMMountPointServiceHandler;
21 import org.opendaylight.restconf.nb.rfc8040.handlers.NotificationServiceHandler;
22 import org.opendaylight.restconf.nb.rfc8040.handlers.RpcServiceHandler;
23 import org.opendaylight.restconf.nb.rfc8040.handlers.SchemaContextHandler;
24 import org.opendaylight.restconf.nb.rfc8040.handlers.TransactionChainHandler;
25 import org.opendaylight.restconf.nb.rfc8040.rests.services.api.RestconfDataService;
26 import org.opendaylight.restconf.nb.rfc8040.rests.services.api.RestconfInvokeOperationsService;
27 import org.opendaylight.restconf.nb.rfc8040.rests.services.api.RestconfStreamsSubscriptionService;
28 import org.opendaylight.restconf.nb.rfc8040.rests.services.api.TransactionServicesWrapper;
29 import org.opendaylight.restconf.nb.rfc8040.rests.services.impl.RestconfDataServiceImpl;
30 import org.opendaylight.restconf.nb.rfc8040.rests.services.impl.RestconfInvokeOperationsServiceImpl;
31 import org.opendaylight.restconf.nb.rfc8040.rests.services.impl.RestconfStreamsSubscriptionServiceImpl;
32 import org.opendaylight.restconf.nb.rfc8040.services.simple.api.BaseServicesWrapper;
33 import org.opendaylight.restconf.nb.rfc8040.services.simple.api.RestconfOperationsService;
34 import org.opendaylight.restconf.nb.rfc8040.services.simple.api.RestconfSchemaService;
35 import org.opendaylight.restconf.nb.rfc8040.services.simple.api.RestconfService;
36 import org.opendaylight.restconf.nb.rfc8040.services.simple.impl.RestconfImpl;
37 import org.opendaylight.restconf.nb.rfc8040.services.simple.impl.RestconfOperationsServiceImpl;
38 import org.opendaylight.restconf.nb.rfc8040.services.simple.impl.RestconfSchemaServiceImpl;
39
40 /**
41  * Wrapper for services.
42  * <ul>
43  * <li>{@link BaseServicesWrapper}
44  * <li>{@link TransactionServicesWrapper}
45  * </ul>
46  *
47  */
48 @Path("/")
49 public final class ServicesWrapper implements BaseServicesWrapper, TransactionServicesWrapper {
50
51     private final RestconfDataService delegRestconfDataService;
52     private final RestconfInvokeOperationsService delegRestconfInvokeOpsService;
53     private final RestconfStreamsSubscriptionService delegRestconfSubscrService;
54     private final RestconfOperationsService delegRestOpsService;
55     private final RestconfSchemaService delegRestSchService;
56     private final RestconfService delegRestService;
57
58     private ServicesWrapper(RestconfDataService delegRestconfDataService,
59             RestconfInvokeOperationsService delegRestconfInvokeOpsService,
60             RestconfStreamsSubscriptionService delegRestconfSubscrService,
61             RestconfOperationsService delegRestOpsService, RestconfSchemaService delegRestSchService,
62             RestconfService delegRestService) {
63         this.delegRestconfDataService = delegRestconfDataService;
64         this.delegRestconfInvokeOpsService = delegRestconfInvokeOpsService;
65         this.delegRestconfSubscrService = delegRestconfSubscrService;
66         this.delegRestOpsService = delegRestOpsService;
67         this.delegRestSchService = delegRestSchService;
68         this.delegRestService = delegRestService;
69     }
70
71     public static ServicesWrapper newInstance(final SchemaContextHandler schemaCtxHandler,
72             final DOMMountPointServiceHandler domMountPointServiceHandler,
73             final TransactionChainHandler transactionChainHandler, final DOMDataBrokerHandler domDataBrokerHandler,
74             final RpcServiceHandler rpcServiceHandler, final NotificationServiceHandler notificationServiceHandler,
75             final DOMSchemaService domSchemaService) {
76         RestconfOperationsService restconfOpsService =
77                 new RestconfOperationsServiceImpl(schemaCtxHandler, domMountPointServiceHandler);
78         final DOMYangTextSourceProvider yangTextSourceProvider =
79                 (DOMYangTextSourceProvider) domSchemaService.getSupportedExtensions()
80                         .get(DOMYangTextSourceProvider.class);
81         RestconfSchemaService restconfSchemaService =
82                 new RestconfSchemaServiceImpl(schemaCtxHandler, domMountPointServiceHandler,
83                 yangTextSourceProvider);
84         RestconfStreamsSubscriptionService restconfSubscrService =
85                 new RestconfStreamsSubscriptionServiceImpl(domDataBrokerHandler,
86                 notificationServiceHandler, schemaCtxHandler, transactionChainHandler);
87         RestconfDataService restconfDataService =
88                 new RestconfDataServiceImpl(schemaCtxHandler, transactionChainHandler, domMountPointServiceHandler,
89                         restconfSubscrService);
90         RestconfInvokeOperationsService restconfInvokeOpsService =
91                 new RestconfInvokeOperationsServiceImpl(rpcServiceHandler, schemaCtxHandler);
92         RestconfService restconfService = new RestconfImpl(schemaCtxHandler);
93         return new ServicesWrapper(restconfDataService, restconfInvokeOpsService,
94                 restconfSubscrService, restconfOpsService, restconfSchemaService, restconfService);
95     }
96
97     @Override
98     public NormalizedNodeContext getOperations(final UriInfo uriInfo) {
99         return this.delegRestOpsService.getOperations(uriInfo);
100     }
101
102     @Override
103     public NormalizedNodeContext getOperations(final String identifier, final UriInfo uriInfo) {
104         return this.delegRestOpsService.getOperations(identifier, uriInfo);
105     }
106
107     @Override
108     public SchemaExportContext getSchema(final String mountAndModuleId) {
109         return this.delegRestSchService.getSchema(mountAndModuleId);
110     }
111
112     @Override
113     public Response readData(final UriInfo uriInfo) {
114         return this.delegRestconfDataService.readData(uriInfo);
115     }
116
117     @Override
118     public Response readData(final String identifier, final UriInfo uriInfo) {
119         return this.delegRestconfDataService.readData(identifier, uriInfo);
120     }
121
122     @Override
123     public Response putData(final String identifier, final NormalizedNodeContext payload, final UriInfo uriInfo) {
124         return this.delegRestconfDataService.putData(identifier, payload, uriInfo);
125     }
126
127     @Override
128     public Response postData(final String identifier, final NormalizedNodeContext payload, final UriInfo uriInfo) {
129         return this.delegRestconfDataService.postData(identifier, payload, uriInfo);
130     }
131
132     @Override
133     public Response postData(final NormalizedNodeContext payload, final UriInfo uriInfo) {
134         return this.delegRestconfDataService.postData(payload, uriInfo);
135     }
136
137     @Override
138     public Response deleteData(final String identifier) {
139         return this.delegRestconfDataService.deleteData(identifier);
140     }
141
142     @Override
143     public PatchStatusContext patchData(final String identifier, final PatchContext context, final UriInfo uriInfo) {
144         return this.delegRestconfDataService.patchData(identifier, context, uriInfo);
145     }
146
147     @Override
148     public PatchStatusContext patchData(final PatchContext context, final UriInfo uriInfo) {
149         return this.delegRestconfDataService.patchData(context, uriInfo);
150     }
151
152     @Override
153     public NormalizedNodeContext invokeRpc(final String identifier, final NormalizedNodeContext payload,
154             final UriInfo uriInfo) {
155         return this.delegRestconfInvokeOpsService.invokeRpc(identifier, payload, uriInfo);
156     }
157
158     @Override
159     public NormalizedNodeContext subscribeToStream(final String identifier, final UriInfo uriInfo) {
160         return this.delegRestconfSubscrService.subscribeToStream(identifier, uriInfo);
161     }
162
163     @Override
164     public NormalizedNodeContext getLibraryVersion() {
165         return this.delegRestService.getLibraryVersion();
166     }
167 }