X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=restconf%2Fsal-rest-connector%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Frestconf%2Frestful%2Fservices%2Fimpl%2FRestconfDataServiceImpl.java;h=b15a00aa8683d5a5b1c8a57dff0bef4377b45ff0;hb=ddc71443d58ac78f8a593be88e181310f1e4b9c8;hp=c27da7ab621e240beac41202bccc7c5bab5bd86e;hpb=61d053cd7e3fa0cfc4b7456aabbcacd2e65126fc;p=netconf.git diff --git a/restconf/sal-rest-connector/src/main/java/org/opendaylight/restconf/restful/services/impl/RestconfDataServiceImpl.java b/restconf/sal-rest-connector/src/main/java/org/opendaylight/restconf/restful/services/impl/RestconfDataServiceImpl.java index c27da7ab62..b15a00aa86 100644 --- a/restconf/sal-rest-connector/src/main/java/org/opendaylight/restconf/restful/services/impl/RestconfDataServiceImpl.java +++ b/restconf/sal-rest-connector/src/main/java/org/opendaylight/restconf/restful/services/impl/RestconfDataServiceImpl.java @@ -12,10 +12,10 @@ import com.google.common.base.Preconditions; import java.text.SimpleDateFormat; import java.util.Date; import java.util.TimeZone; +import javax.annotation.Nonnull; import javax.ws.rs.core.Response; import javax.ws.rs.core.UriInfo; import org.opendaylight.controller.md.sal.dom.api.DOMDataBroker; -import org.opendaylight.controller.md.sal.dom.api.DOMDataReadWriteTransaction; import org.opendaylight.controller.md.sal.dom.api.DOMMountPoint; import org.opendaylight.controller.md.sal.dom.api.DOMTransactionChain; import org.opendaylight.netconf.sal.restconf.impl.InstanceIdentifierContext; @@ -24,8 +24,10 @@ import org.opendaylight.netconf.sal.restconf.impl.PATCHContext; import org.opendaylight.netconf.sal.restconf.impl.PATCHStatusContext; import org.opendaylight.netconf.sal.restconf.impl.RestconfDocumentedException; import org.opendaylight.netconf.sal.restconf.impl.RestconfError; +import org.opendaylight.netconf.sal.restconf.impl.WriterParameters; import org.opendaylight.restconf.RestConnectorProvider; import org.opendaylight.restconf.common.references.SchemaContextRef; +import org.opendaylight.restconf.handlers.DOMMountPointServiceHandler; import org.opendaylight.restconf.handlers.SchemaContextHandler; import org.opendaylight.restconf.handlers.TransactionChainHandler; import org.opendaylight.restconf.restful.services.api.RestconfDataService; @@ -51,33 +53,41 @@ public class RestconfDataServiceImpl implements RestconfDataService { private final SchemaContextHandler schemaContextHandler; private final TransactionChainHandler transactionChainHandler; + private final DOMMountPointServiceHandler mountPointServiceHandler; public RestconfDataServiceImpl(final SchemaContextHandler schemaContextHandler, - final TransactionChainHandler transactionChainHandler) { + final TransactionChainHandler transactionChainHandler, + final DOMMountPointServiceHandler mountPointServiceHandler) { this.schemaContextHandler = schemaContextHandler; this.transactionChainHandler = transactionChainHandler; + this.mountPointServiceHandler = mountPointServiceHandler; + } + + @Override + public Response readData(final UriInfo uriInfo) { + return readData(null, uriInfo); } @Override public Response readData(final String identifier, final UriInfo uriInfo) { - Preconditions.checkNotNull(identifier); final SchemaContextRef schemaContextRef = new SchemaContextRef(this.schemaContextHandler.get()); + final InstanceIdentifierContext instanceIdentifier = ParserIdentifier.toInstanceIdentifier( + identifier, schemaContextRef.get(), Optional.of(this.mountPointServiceHandler.get())); - final InstanceIdentifierContext instanceIdentifier = ParserIdentifier.toInstanceIdentifier(identifier, - schemaContextRef.get()); - final DOMMountPoint mountPoint = instanceIdentifier.getMountPoint(); - final String value = uriInfo.getQueryParameters().getFirst(RestconfDataServiceConstant.CONTENT); + final WriterParameters parameters = ReadDataTransactionUtil.parseUriParameters( + instanceIdentifier, uriInfo); - final DOMTransactionChain transaction; + final DOMMountPoint mountPoint = instanceIdentifier.getMountPoint(); + final DOMTransactionChain transactionChain; if (mountPoint == null) { - transaction = this.transactionChainHandler.get(); + transactionChain = this.transactionChainHandler.get(); } else { - transaction = transactionOfMountPoint(mountPoint); + transactionChain = transactionChainOfMountPoint(mountPoint); } - final TransactionVarsWrapper transactionNode = new TransactionVarsWrapper(instanceIdentifier, mountPoint, - transaction); - final NormalizedNode node = ReadDataTransactionUtil.readData(value, transactionNode); + final TransactionVarsWrapper transactionNode = new TransactionVarsWrapper( + instanceIdentifier, mountPoint, transactionChain); + final NormalizedNode node = ReadDataTransactionUtil.readData(parameters.getContent(), transactionNode); if (node == null) { throw new RestconfDocumentedException( "Request could not be completed because the relevant data model content does not exist", @@ -90,12 +100,19 @@ public class RestconfDataServiceImpl implements RestconfDataService { + node.getNodeType().getLocalName() + '"'; final Response resp; - if ((value == null) || value.contains(RestconfDataServiceConstant.ReadData.CONFIG)) { - resp = Response.status(200).entity(new NormalizedNodeContext(instanceIdentifier, node)).header("ETag", etag) - .header("Last-Modified", dateFormatGmt.format(new Date())).build(); + if ((parameters.getContent().equals(RestconfDataServiceConstant.ReadData.ALL)) + || parameters.getContent().equals(RestconfDataServiceConstant.ReadData.CONFIG)) { + resp = Response.status(200) + .entity(new NormalizedNodeContext(instanceIdentifier, node, parameters)) + .header("ETag", etag) + .header("Last-Modified", dateFormatGmt.format(new Date())) + .build(); } else { - resp = Response.status(200).entity(new NormalizedNodeContext(instanceIdentifier, node)).build(); + resp = Response.status(200) + .entity(new NormalizedNodeContext(instanceIdentifier, node, parameters)) + .build(); } + return resp; } @@ -111,18 +128,18 @@ public class RestconfDataServiceImpl implements RestconfDataService { PutDataTransactionUtil.validateListKeysEqualityInPayloadAndUri(payload); final DOMMountPoint mountPoint = payload.getInstanceIdentifierContext().getMountPoint(); - final DOMTransactionChain transaction; + final DOMTransactionChain transactionChain; final SchemaContextRef ref; if (mountPoint == null) { - transaction = this.transactionChainHandler.get(); + transactionChain = this.transactionChainHandler.get(); ref = new SchemaContextRef(this.schemaContextHandler.get()); } else { - transaction = transactionOfMountPoint(mountPoint); + transactionChain = transactionChainOfMountPoint(mountPoint); ref = new SchemaContextRef(mountPoint.getSchemaContext()); } final TransactionVarsWrapper transactionNode = new TransactionVarsWrapper( - payload.getInstanceIdentifierContext(), mountPoint, transaction); + payload.getInstanceIdentifierContext(), mountPoint, transactionChain); return PutDataTransactionUtil.putData(payload, ref, transactionNode); } @@ -136,36 +153,36 @@ public class RestconfDataServiceImpl implements RestconfDataService { Preconditions.checkNotNull(payload); final DOMMountPoint mountPoint = payload.getInstanceIdentifierContext().getMountPoint(); - final DOMTransactionChain transaction; + final DOMTransactionChain transactionChain; final SchemaContextRef ref; if (mountPoint == null) { - transaction = this.transactionChainHandler.get(); + transactionChain = this.transactionChainHandler.get(); ref = new SchemaContextRef(this.schemaContextHandler.get()); } else { - transaction = transactionOfMountPoint(mountPoint); + transactionChain = transactionChainOfMountPoint(mountPoint); ref = new SchemaContextRef(mountPoint.getSchemaContext()); } final TransactionVarsWrapper transactionNode = new TransactionVarsWrapper( - payload.getInstanceIdentifierContext(), mountPoint, transaction); + payload.getInstanceIdentifierContext(), mountPoint, transactionChain); return PostDataTransactionUtil.postData(uriInfo, payload, transactionNode, ref); } @Override public Response deleteData(final String identifier) { final SchemaContextRef schemaContextRef = new SchemaContextRef(this.schemaContextHandler.get()); - final InstanceIdentifierContext instanceIdentifier = ParserIdentifier.toInstanceIdentifier(identifier, - schemaContextRef.get()); + final InstanceIdentifierContext instanceIdentifier = ParserIdentifier.toInstanceIdentifier( + identifier, schemaContextRef.get(), Optional.of(this.mountPointServiceHandler.get())); final DOMMountPoint mountPoint = instanceIdentifier.getMountPoint(); - final DOMTransactionChain transaction; + final DOMTransactionChain transactionChain; if (mountPoint == null) { - transaction = this.transactionChainHandler.get(); + transactionChain = this.transactionChainHandler.get(); } else { - transaction = transactionOfMountPoint(mountPoint); + transactionChain = transactionChainOfMountPoint(mountPoint); } final TransactionVarsWrapper transactionNode = new TransactionVarsWrapper(instanceIdentifier, mountPoint, - transaction); + transactionChain); return DeleteDataTransactionUtil.deleteData(transactionNode); } @@ -179,29 +196,29 @@ public class RestconfDataServiceImpl implements RestconfDataService { Preconditions.checkNotNull(context); final DOMMountPoint mountPoint = context.getInstanceIdentifierContext().getMountPoint(); - final DOMTransactionChain transaction; + final DOMTransactionChain transactionChain; final SchemaContextRef ref; if (mountPoint == null) { - transaction = this.transactionChainHandler.get(); + transactionChain = this.transactionChainHandler.get(); ref = new SchemaContextRef(this.schemaContextHandler.get()); } else { - transaction = transactionOfMountPoint(mountPoint); + transactionChain = transactionChainOfMountPoint(mountPoint); ref = new SchemaContextRef(mountPoint.getSchemaContext()); } final TransactionVarsWrapper transactionNode = new TransactionVarsWrapper( - context.getInstanceIdentifierContext(), mountPoint, transaction); + context.getInstanceIdentifierContext(), mountPoint, transactionChain); return PatchDataTransactionUtil.patchData(context, transactionNode, ref); } /** - * Prepare transaction to read data of mount point, if these data are - * present. + * Prepare transaction chain to access data of mount point * @param mountPoint - * @return {@link DOMDataReadWriteTransaction} + * - mount point reference + * @return {@link DOMTransactionChain} */ - private static DOMTransactionChain transactionOfMountPoint(final DOMMountPoint mountPoint) { + private static DOMTransactionChain transactionChainOfMountPoint(@Nonnull final DOMMountPoint mountPoint) { final Optional domDataBrokerService = mountPoint.getService(DOMDataBroker.class); if (domDataBrokerService.isPresent()) { return domDataBrokerService.get().createTransactionChain(RestConnectorProvider.transactionListener);