dfc6620287d0298e074b4bda357408ae1251d6c1
[netconf.git] / restconf / sal-rest-connector / src / main / java / org / opendaylight / restconf / common / wrapper / services / ServicesWrapperImpl.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.common.wrapper.services;
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.netconf.md.sal.rest.schema.SchemaExportContext;
14 import org.opendaylight.netconf.sal.restconf.impl.NormalizedNodeContext;
15 import org.opendaylight.netconf.sal.restconf.impl.PATCHContext;
16 import org.opendaylight.netconf.sal.restconf.impl.PATCHStatusContext;
17 import org.opendaylight.restconf.base.services.api.BaseServicesWrapper;
18 import org.opendaylight.restconf.base.services.api.RestconfOperationsService;
19 import org.opendaylight.restconf.base.services.api.RestconfSchemaService;
20 import org.opendaylight.restconf.base.services.impl.RestconfOperationsServiceImpl;
21 import org.opendaylight.restconf.base.services.impl.RestconfSchemaServiceImpl;
22 import org.opendaylight.restconf.handlers.DOMDataBrokerHandler;
23 import org.opendaylight.restconf.handlers.DOMMountPointServiceHandler;
24 import org.opendaylight.restconf.handlers.NotificationServiceHandler;
25 import org.opendaylight.restconf.handlers.RpcServiceHandler;
26 import org.opendaylight.restconf.handlers.SchemaContextHandler;
27 import org.opendaylight.restconf.handlers.TransactionChainHandler;
28 import org.opendaylight.restconf.restful.services.api.RestconfDataService;
29 import org.opendaylight.restconf.restful.services.api.RestconfInvokeOperationsService;
30 import org.opendaylight.restconf.restful.services.api.RestconfStreamsSubscriptionService;
31 import org.opendaylight.restconf.restful.services.api.TransactionServicesWrapper;
32 import org.opendaylight.restconf.restful.services.impl.RestconfDataServiceImpl;
33 import org.opendaylight.restconf.restful.services.impl.RestconfInvokeOperationsServiceImpl;
34 import org.opendaylight.restconf.restful.services.impl.RestconfStreamsSubscriptionServiceImpl;
35
36 /**
37  * Wrapper for services:
38  * <ul>
39  * <li>{@link BaseServicesWrapper}
40  * <li>{@link TransactionServicesWrapper}
41  * </ul>
42  *
43  */
44 @Path("/")
45 public class ServicesWrapperImpl implements BaseServicesWrapper, TransactionServicesWrapper {
46
47     private RestconfDataService delegRestconfDataService;
48     private RestconfInvokeOperationsService delegRestconfInvokeOpsService;
49     private RestconfStreamsSubscriptionService delegRestconfSubscrService;
50     private RestconfOperationsService delegRestOpsService;
51     private RestconfSchemaService delegRestSchService;
52
53     private ServicesWrapperImpl() {
54     }
55
56     private static class InstanceHolder {
57         public static final ServicesWrapperImpl INSTANCE = new ServicesWrapperImpl();
58     }
59
60     public static ServicesWrapperImpl getInstance() {
61         return InstanceHolder.INSTANCE;
62     }
63
64     @Override
65     public NormalizedNodeContext getOperations(final UriInfo uriInfo) {
66         return this.delegRestOpsService.getOperations(uriInfo);
67     }
68
69     @Override
70     public NormalizedNodeContext getOperations(final String identifier, final UriInfo uriInfo) {
71         return this.delegRestOpsService.getOperations(identifier, uriInfo);
72     }
73
74     @Override
75     public SchemaExportContext getSchema(final String mountAndModuleId) {
76         return this.delegRestSchService.getSchema(mountAndModuleId);
77     }
78
79     @Override
80     public Response readData(final UriInfo uriInfo) {
81         return this.delegRestconfDataService.readData(uriInfo);
82     }
83
84     @Override
85     public Response readData(final String identifier, final UriInfo uriInfo) {
86         return this.delegRestconfDataService.readData(identifier, uriInfo);
87     }
88
89     @Override
90     public Response putData(final String identifier, final NormalizedNodeContext payload, final UriInfo uriInfo) {
91         return this.delegRestconfDataService.putData(identifier, payload, uriInfo);
92     }
93
94     @Override
95     public Response postData(final String identifier, final NormalizedNodeContext payload, final UriInfo uriInfo) {
96         return this.delegRestconfDataService.postData(identifier, payload, uriInfo);
97     }
98
99     @Override
100     public Response postData(final NormalizedNodeContext payload, final UriInfo uriInfo) {
101         return this.delegRestconfDataService.postData(payload, uriInfo);
102     }
103
104     @Override
105     public Response deleteData(final String identifier) {
106         return this.delegRestconfDataService.deleteData(identifier);
107     }
108
109     @Override
110     public PATCHStatusContext patchData(final String identifier, final PATCHContext context, final UriInfo uriInfo) {
111         return this.delegRestconfDataService.patchData(identifier, context, uriInfo);
112     }
113
114     @Override
115     public PATCHStatusContext patchData(final PATCHContext context, final UriInfo uriInfo) {
116         return this.delegRestconfDataService.patchData(context, uriInfo);
117     }
118
119     @Override
120     public NormalizedNodeContext invokeRpc(final String identifier, final NormalizedNodeContext payload,
121                                            final UriInfo uriInfo) {
122         return this.delegRestconfInvokeOpsService.invokeRpc(identifier, payload, uriInfo);
123     }
124
125     @Override
126     public NormalizedNodeContext subscribeToStream(final String identifier, final UriInfo uriInfo) {
127         return this.delegRestconfSubscrService.subscribeToStream(identifier, uriInfo);
128     }
129
130     public void setHandlers(final SchemaContextHandler schemaCtxHandler,
131                             final DOMMountPointServiceHandler domMountPointServiceHandler,
132                             final TransactionChainHandler transactionChainHandler,
133                             final DOMDataBrokerHandler domDataBrokerHandler,
134             final RpcServiceHandler rpcServiceHandler, final NotificationServiceHandler notificationServiceHandler) {
135         this.delegRestOpsService = new RestconfOperationsServiceImpl(schemaCtxHandler, domMountPointServiceHandler);
136         this.delegRestSchService = new RestconfSchemaServiceImpl(schemaCtxHandler, domMountPointServiceHandler);
137         this.delegRestconfDataService = new RestconfDataServiceImpl(schemaCtxHandler, transactionChainHandler,
138                 domMountPointServiceHandler);
139         this.delegRestconfInvokeOpsService = new RestconfInvokeOperationsServiceImpl(rpcServiceHandler,
140                 schemaCtxHandler);
141         this.delegRestconfSubscrService =
142                 new RestconfStreamsSubscriptionServiceImpl(domDataBrokerHandler, notificationServiceHandler,
143                         schemaCtxHandler, transactionChainHandler);
144     }
145 }