Evacuate static methods tests to RestconfDataServiceImplTest
[netconf.git] / restconf / restconf-nb / src / main / java / org / opendaylight / restconf / nb / rfc8040 / rests / services / impl / RestconfOperationsServiceImpl.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.rests.services.impl;
9
10 import static java.util.Objects.requireNonNull;
11
12 import java.util.Optional;
13 import javax.ws.rs.Path;
14 import org.opendaylight.mdsal.dom.api.DOMMountPointService;
15 import org.opendaylight.restconf.nb.rfc8040.databind.DatabindProvider;
16 import org.opendaylight.restconf.nb.rfc8040.rests.services.api.RestconfOperationsService;
17 import org.opendaylight.restconf.nb.rfc8040.utils.parser.ParserIdentifier;
18 import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
19
20 /**
21  * Implementation of {@link RestconfOperationsService}.
22  */
23 @Path("/")
24 public class RestconfOperationsServiceImpl implements RestconfOperationsService {
25     private final DatabindProvider databindProvider;
26     private final DOMMountPointService mountPointService;
27
28     /**
29      * Set {@link DatabindProvider} for getting actual {@link EffectiveModelContext}.
30      *
31      * @param databindProvider a {@link DatabindProvider}
32      * @param mountPointService a {@link DOMMountPointService}
33      */
34     public RestconfOperationsServiceImpl(final DatabindProvider databindProvider,
35             final DOMMountPointService mountPointService) {
36         this.databindProvider = requireNonNull(databindProvider);
37         this.mountPointService = requireNonNull(mountPointService);
38     }
39
40     @Override
41     public String getOperationsJSON() {
42         return OperationsContent.JSON.bodyFor(databindProvider.currentContext().modelContext());
43     }
44
45     @Override
46     public String getOperationJSON(final String identifier) {
47         final var identifierContext = ParserIdentifier.toInstanceIdentifier(identifier,
48                 databindProvider.currentContext().modelContext(), Optional.of(mountPointService));
49         return OperationsContent.JSON.bodyFor(identifierContext);
50     }
51
52     @Override
53     public String getOperationsXML() {
54         return OperationsContent.XML.bodyFor(databindProvider.currentContext().modelContext());
55     }
56
57     @Override
58     public String getOperationXML(final String identifier) {
59         final var identifierContext = ParserIdentifier.toInstanceIdentifier(identifier,
60                 databindProvider.currentContext().modelContext(), Optional.of(mountPointService));
61         return OperationsContent.XML.bodyFor(identifierContext);
62     }
63 }