Merge "Bug 6746 - Restconf: Not working GET operation on mount points"
[netconf.git] / restconf / sal-rest-connector / src / main / java / org / opendaylight / restconf / jersey / providers / AbstractIdentifierAwareJaxRsProvider.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
9 package org.opendaylight.restconf.jersey.providers;
10
11 import com.google.common.base.Optional;
12 import javax.ws.rs.core.Context;
13 import javax.ws.rs.core.Request;
14 import javax.ws.rs.core.UriInfo;
15 import org.opendaylight.netconf.sal.rest.api.RestconfConstants;
16 import org.opendaylight.netconf.sal.restconf.impl.ControllerContext;
17 import org.opendaylight.netconf.sal.restconf.impl.InstanceIdentifierContext;
18 import org.opendaylight.restconf.utils.parser.ParserIdentifier;
19
20 public class AbstractIdentifierAwareJaxRsProvider {
21
22     private static final String POST = "POST";
23
24     @Context
25     private UriInfo uriInfo;
26
27     @Context
28     private Request request;
29
30     protected final String getIdentifier() {
31         return this.uriInfo.getPathParameters(false).getFirst(RestconfConstants.IDENTIFIER);
32     }
33
34     protected InstanceIdentifierContext<?> getInstanceIdentifierContext() {
35         return ParserIdentifier.toInstanceIdentifier(getIdentifier(),
36                 ControllerContext.getInstance().getGlobalSchema(), Optional.absent());
37     }
38
39     protected UriInfo getUriInfo() {
40         return this.uriInfo;
41     }
42
43     protected boolean isPost() {
44         return POST.equals(this.request.getMethod());
45     }
46
47     void setUriInfo(final UriInfo uriInfo) {
48         this.uriInfo = uriInfo;
49     }
50
51     void setRequest(final Request request) {
52         this.request = request;
53     }
54 }