Move services 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.DOMActionService;
14 import org.opendaylight.mdsal.dom.api.DOMDataBroker;
15 import org.opendaylight.mdsal.dom.api.DOMMountPointService;
16 import org.opendaylight.mdsal.dom.api.DOMNotificationService;
17 import org.opendaylight.mdsal.dom.api.DOMRpcService;
18 import org.opendaylight.mdsal.dom.api.DOMSchemaService;
19 import org.opendaylight.mdsal.dom.api.DOMYangTextSourceProvider;
20 import org.opendaylight.restconf.common.context.NormalizedNodeContext;
21 import org.opendaylight.restconf.common.patch.PatchContext;
22 import org.opendaylight.restconf.common.patch.PatchStatusContext;
23 import org.opendaylight.restconf.common.schema.SchemaExportContext;
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.RestconfOperationsService;
29 import org.opendaylight.restconf.nb.rfc8040.rests.services.api.RestconfSchemaService;
30 import org.opendaylight.restconf.nb.rfc8040.rests.services.api.RestconfService;
31 import org.opendaylight.restconf.nb.rfc8040.rests.services.api.RestconfStreamsSubscriptionService;
32 import org.opendaylight.restconf.nb.rfc8040.rests.services.api.TransactionServicesWrapper;
33 import org.opendaylight.restconf.nb.rfc8040.rests.services.impl.RestconfDataServiceImpl;
34 import org.opendaylight.restconf.nb.rfc8040.rests.services.impl.RestconfImpl;
35 import org.opendaylight.restconf.nb.rfc8040.rests.services.impl.RestconfInvokeOperationsServiceImpl;
36 import org.opendaylight.restconf.nb.rfc8040.rests.services.impl.RestconfOperationsServiceImpl;
37 import org.opendaylight.restconf.nb.rfc8040.rests.services.impl.RestconfSchemaServiceImpl;
38 import org.opendaylight.restconf.nb.rfc8040.rests.services.impl.RestconfStreamsSubscriptionServiceImpl;
39 import org.opendaylight.restconf.nb.rfc8040.services.simple.api.BaseServicesWrapper;
40 import org.opendaylight.restconf.nb.rfc8040.streams.Configuration;
41
42 /**
43  * Wrapper for services.
44  * <ul>
45  * <li>{@link BaseServicesWrapper}
46  * <li>{@link TransactionServicesWrapper}
47  * </ul>
48  */
49 @Path("/")
50 public final class ServicesWrapper implements BaseServicesWrapper, TransactionServicesWrapper {
51
52     private final RestconfDataService delegRestconfDataService;
53     private final RestconfInvokeOperationsService delegRestconfInvokeOpsService;
54     private final RestconfStreamsSubscriptionService delegRestconfSubscrService;
55     private final RestconfOperationsService delegRestOpsService;
56     private final RestconfSchemaService delegRestSchService;
57     private final RestconfService delegRestService;
58
59     private ServicesWrapper(final RestconfDataService delegRestconfDataService,
60             final RestconfInvokeOperationsService delegRestconfInvokeOpsService,
61             final RestconfStreamsSubscriptionService delegRestconfSubscrService,
62             final RestconfOperationsService delegRestOpsService, final RestconfSchemaService delegRestSchService,
63             final RestconfService delegRestService) {
64         this.delegRestconfDataService = delegRestconfDataService;
65         this.delegRestconfInvokeOpsService = delegRestconfInvokeOpsService;
66         this.delegRestconfSubscrService = delegRestconfSubscrService;
67         this.delegRestOpsService = delegRestOpsService;
68         this.delegRestSchService = delegRestSchService;
69         this.delegRestService = delegRestService;
70     }
71
72     public static ServicesWrapper newInstance(final SchemaContextHandler schemaCtxHandler,
73             final DOMMountPointService mountPointService,
74             final TransactionChainHandler transactionChainHandler, final DOMDataBroker dataBroker,
75             final DOMRpcService rpcService, final DOMActionService actionService,
76             final DOMNotificationService notificationService, final DOMSchemaService domSchemaService,
77             final Configuration configuration) {
78         RestconfOperationsService restconfOpsService = new RestconfOperationsServiceImpl(schemaCtxHandler,
79             mountPointService);
80         final DOMYangTextSourceProvider yangTextSourceProvider = domSchemaService.getExtensions()
81             .getInstance(DOMYangTextSourceProvider.class);
82         RestconfSchemaService restconfSchemaService = new RestconfSchemaServiceImpl(schemaCtxHandler, mountPointService,
83             yangTextSourceProvider);
84         RestconfStreamsSubscriptionService restconfSubscrService = new RestconfStreamsSubscriptionServiceImpl(
85             dataBroker, notificationService, schemaCtxHandler, transactionChainHandler, configuration);
86         RestconfDataService restconfDataService = new RestconfDataServiceImpl(schemaCtxHandler, dataBroker,
87             mountPointService, restconfSubscrService, actionService, configuration);
88         RestconfInvokeOperationsService restconfInvokeOpsService = new RestconfInvokeOperationsServiceImpl(rpcService,
89             schemaCtxHandler);
90         RestconfService restconfService = new RestconfImpl(schemaCtxHandler);
91         return new ServicesWrapper(restconfDataService, restconfInvokeOpsService, restconfSubscrService,
92             restconfOpsService, restconfSchemaService, restconfService);
93     }
94
95     @Override
96     public NormalizedNodeContext getOperations(final UriInfo uriInfo) {
97         return this.delegRestOpsService.getOperations(uriInfo);
98     }
99
100     @Override
101     public NormalizedNodeContext getOperations(final String identifier, final UriInfo uriInfo) {
102         return this.delegRestOpsService.getOperations(identifier, uriInfo);
103     }
104
105     @Override
106     public SchemaExportContext getSchema(final String mountAndModuleId) {
107         return this.delegRestSchService.getSchema(mountAndModuleId);
108     }
109
110     @Override
111     public Response readData(final UriInfo uriInfo) {
112         return this.delegRestconfDataService.readData(uriInfo);
113     }
114
115     @Override
116     public Response readData(final String identifier, final UriInfo uriInfo) {
117         return this.delegRestconfDataService.readData(identifier, uriInfo);
118     }
119
120     @Override
121     public Response putData(final String identifier, final NormalizedNodeContext payload, final UriInfo uriInfo) {
122         return this.delegRestconfDataService.putData(identifier, payload, uriInfo);
123     }
124
125     @Override
126     public Response postData(final String identifier, final NormalizedNodeContext payload, final UriInfo uriInfo) {
127         return this.delegRestconfDataService.postData(identifier, payload, uriInfo);
128     }
129
130     @Override
131     public Response postData(final NormalizedNodeContext payload, final UriInfo uriInfo) {
132         return this.delegRestconfDataService.postData(payload, uriInfo);
133     }
134
135     @Override
136     public Response deleteData(final String identifier) {
137         return this.delegRestconfDataService.deleteData(identifier);
138     }
139
140     @Override
141     public PatchStatusContext patchData(final String identifier, final PatchContext context, final UriInfo uriInfo) {
142         return this.delegRestconfDataService.patchData(identifier, context, uriInfo);
143     }
144
145     @Override
146     public PatchStatusContext patchData(final PatchContext context, final UriInfo uriInfo) {
147         return this.delegRestconfDataService.patchData(context, uriInfo);
148     }
149
150     @Override
151     public Response patchData(final String identifier, final NormalizedNodeContext payload, final UriInfo uriInfo) {
152         return this.delegRestconfDataService.patchData(identifier, payload, uriInfo);
153     }
154
155     @Override
156     public NormalizedNodeContext invokeRpc(final String identifier, final NormalizedNodeContext payload,
157             final UriInfo uriInfo) {
158         return this.delegRestconfInvokeOpsService.invokeRpc(identifier, payload, uriInfo);
159     }
160
161     @Override
162     public NormalizedNodeContext subscribeToStream(final String identifier, final UriInfo uriInfo) {
163         return this.delegRestconfSubscrService.subscribeToStream(identifier, uriInfo);
164     }
165
166     @Override
167     public NormalizedNodeContext getLibraryVersion() {
168         return this.delegRestService.getLibraryVersion();
169     }
170 }