Teach RFC8040 restconf about actions
[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.ActionServiceHandler;
20 import org.opendaylight.restconf.nb.rfc8040.handlers.DOMDataBrokerHandler;
21 import org.opendaylight.restconf.nb.rfc8040.handlers.DOMMountPointServiceHandler;
22 import org.opendaylight.restconf.nb.rfc8040.handlers.NotificationServiceHandler;
23 import org.opendaylight.restconf.nb.rfc8040.handlers.RpcServiceHandler;
24 import org.opendaylight.restconf.nb.rfc8040.handlers.SchemaContextHandler;
25 import org.opendaylight.restconf.nb.rfc8040.handlers.TransactionChainHandler;
26 import org.opendaylight.restconf.nb.rfc8040.rests.services.api.RestconfDataService;
27 import org.opendaylight.restconf.nb.rfc8040.rests.services.api.RestconfInvokeOperationsService;
28 import org.opendaylight.restconf.nb.rfc8040.rests.services.api.RestconfStreamsSubscriptionService;
29 import org.opendaylight.restconf.nb.rfc8040.rests.services.api.TransactionServicesWrapper;
30 import org.opendaylight.restconf.nb.rfc8040.rests.services.impl.RestconfDataServiceImpl;
31 import org.opendaylight.restconf.nb.rfc8040.rests.services.impl.RestconfInvokeOperationsServiceImpl;
32 import org.opendaylight.restconf.nb.rfc8040.rests.services.impl.RestconfStreamsSubscriptionServiceImpl;
33 import org.opendaylight.restconf.nb.rfc8040.services.simple.api.BaseServicesWrapper;
34 import org.opendaylight.restconf.nb.rfc8040.services.simple.api.RestconfOperationsService;
35 import org.opendaylight.restconf.nb.rfc8040.services.simple.api.RestconfSchemaService;
36 import org.opendaylight.restconf.nb.rfc8040.services.simple.api.RestconfService;
37 import org.opendaylight.restconf.nb.rfc8040.services.simple.impl.RestconfImpl;
38 import org.opendaylight.restconf.nb.rfc8040.services.simple.impl.RestconfOperationsServiceImpl;
39 import org.opendaylight.restconf.nb.rfc8040.services.simple.impl.RestconfSchemaServiceImpl;
40
41 /**
42  * Wrapper for services.
43  * <ul>
44  * <li>{@link BaseServicesWrapper}
45  * <li>{@link TransactionServicesWrapper}
46  * </ul>
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(final RestconfDataService delegRestconfDataService,
59             final RestconfInvokeOperationsService delegRestconfInvokeOpsService,
60             final RestconfStreamsSubscriptionService delegRestconfSubscrService,
61             final RestconfOperationsService delegRestOpsService, final RestconfSchemaService delegRestSchService,
62             final 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 ActionServiceHandler actionServiceHandler,
75             final NotificationServiceHandler notificationServiceHandler, final DOMSchemaService domSchemaService) {
76         RestconfOperationsService restconfOpsService = new RestconfOperationsServiceImpl(schemaCtxHandler,
77             domMountPointServiceHandler);
78         final DOMYangTextSourceProvider yangTextSourceProvider = domSchemaService.getExtensions()
79             .getInstance(DOMYangTextSourceProvider.class);
80         RestconfSchemaService restconfSchemaService = new RestconfSchemaServiceImpl(schemaCtxHandler,
81             domMountPointServiceHandler, yangTextSourceProvider);
82         RestconfStreamsSubscriptionService restconfSubscrService = new RestconfStreamsSubscriptionServiceImpl(
83             domDataBrokerHandler, notificationServiceHandler, schemaCtxHandler, transactionChainHandler);
84         RestconfDataService restconfDataService = new RestconfDataServiceImpl(schemaCtxHandler, transactionChainHandler,
85             domMountPointServiceHandler, restconfSubscrService, actionServiceHandler);
86         RestconfInvokeOperationsService restconfInvokeOpsService = new RestconfInvokeOperationsServiceImpl(
87             rpcServiceHandler, schemaCtxHandler);
88         RestconfService restconfService = new RestconfImpl(schemaCtxHandler);
89         return new ServicesWrapper(restconfDataService, restconfInvokeOpsService, restconfSubscrService,
90             restconfOpsService, restconfSchemaService, restconfService);
91     }
92
93     @Override
94     public NormalizedNodeContext getOperations(final UriInfo uriInfo) {
95         return this.delegRestOpsService.getOperations(uriInfo);
96     }
97
98     @Override
99     public NormalizedNodeContext getOperations(final String identifier, final UriInfo uriInfo) {
100         return this.delegRestOpsService.getOperations(identifier, uriInfo);
101     }
102
103     @Override
104     public SchemaExportContext getSchema(final String mountAndModuleId) {
105         return this.delegRestSchService.getSchema(mountAndModuleId);
106     }
107
108     @Override
109     public Response readData(final UriInfo uriInfo) {
110         return this.delegRestconfDataService.readData(uriInfo);
111     }
112
113     @Override
114     public Response readData(final String identifier, final UriInfo uriInfo) {
115         return this.delegRestconfDataService.readData(identifier, uriInfo);
116     }
117
118     @Override
119     public Response putData(final String identifier, final NormalizedNodeContext payload, final UriInfo uriInfo) {
120         return this.delegRestconfDataService.putData(identifier, payload, uriInfo);
121     }
122
123     @Override
124     public Response postData(final String identifier, final NormalizedNodeContext payload, final UriInfo uriInfo) {
125         return this.delegRestconfDataService.postData(identifier, payload, uriInfo);
126     }
127
128     @Override
129     public Response postData(final NormalizedNodeContext payload, final UriInfo uriInfo) {
130         return this.delegRestconfDataService.postData(payload, uriInfo);
131     }
132
133     @Override
134     public Response deleteData(final String identifier) {
135         return this.delegRestconfDataService.deleteData(identifier);
136     }
137
138     @Override
139     public PatchStatusContext patchData(final String identifier, final PatchContext context, final UriInfo uriInfo) {
140         return this.delegRestconfDataService.patchData(identifier, context, uriInfo);
141     }
142
143     @Override
144     public PatchStatusContext patchData(final PatchContext context, final UriInfo uriInfo) {
145         return this.delegRestconfDataService.patchData(context, uriInfo);
146     }
147
148     @Override
149     public NormalizedNodeContext invokeRpc(final String identifier, final NormalizedNodeContext payload,
150             final UriInfo uriInfo) {
151         return this.delegRestconfInvokeOpsService.invokeRpc(identifier, payload, uriInfo);
152     }
153
154     @Override
155     public NormalizedNodeContext subscribeToStream(final String identifier, final UriInfo uriInfo) {
156         return this.delegRestconfSubscrService.subscribeToStream(identifier, uriInfo);
157     }
158
159     @Override
160     public NormalizedNodeContext getLibraryVersion() {
161         return this.delegRestService.getLibraryVersion();
162     }
163 }