import static org.opendaylight.restconf.nb.rfc8040.rests.utils.RestconfStreamsConstants.STREAM_LOCATION_PATH_PART;
import static org.opendaylight.restconf.nb.rfc8040.rests.utils.RestconfStreamsConstants.STREAM_PATH;
-import com.google.common.base.Optional;
import com.google.common.base.Preconditions;
import java.time.Clock;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.List;
import java.util.Map.Entry;
+import java.util.Objects;
+import java.util.Optional;
import javax.annotation.Nonnull;
+import javax.ws.rs.Path;
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.DOMMountPoint;
-import org.opendaylight.controller.md.sal.dom.api.DOMTransactionChain;
+import org.opendaylight.mdsal.dom.api.DOMDataBroker;
+import org.opendaylight.mdsal.dom.api.DOMMountPoint;
import org.opendaylight.restconf.common.context.InstanceIdentifierContext;
import org.opendaylight.restconf.common.context.NormalizedNodeContext;
import org.opendaylight.restconf.common.context.WriterParameters;
import org.opendaylight.restconf.common.errors.RestconfError;
import org.opendaylight.restconf.common.patch.PatchContext;
import org.opendaylight.restconf.common.patch.PatchStatusContext;
-import org.opendaylight.restconf.nb.rfc8040.RestConnectorProvider;
import org.opendaylight.restconf.nb.rfc8040.handlers.DOMMountPointServiceHandler;
import org.opendaylight.restconf.nb.rfc8040.handlers.SchemaContextHandler;
import org.opendaylight.restconf.nb.rfc8040.handlers.TransactionChainHandler;
/**
* Implementation of {@link RestconfDataService}.
*/
+@Path("/")
public class RestconfDataServiceImpl implements RestconfDataService {
private static final Logger LOG = LoggerFactory.getLogger(RestconfDataServiceImpl.class);
final TransactionChainHandler transactionChainHandler,
final DOMMountPointServiceHandler mountPointServiceHandler,
final RestconfStreamsSubscriptionService delegRestconfSubscrService) {
- this.schemaContextHandler = schemaContextHandler;
- this.transactionChainHandler = transactionChainHandler;
- this.mountPointServiceHandler = mountPointServiceHandler;
- this.delegRestconfSubscrService = delegRestconfSubscrService;
+ this.schemaContextHandler = Objects.requireNonNull(schemaContextHandler);
+ this.transactionChainHandler = Objects.requireNonNull(transactionChainHandler);
+ this.mountPointServiceHandler = Objects.requireNonNull(mountPointServiceHandler);
+ this.delegRestconfSubscrService = Objects.requireNonNull(delegRestconfSubscrService);
}
@Override
instanceIdentifier, uriInfo, tagged);
final DOMMountPoint mountPoint = instanceIdentifier.getMountPoint();
- final DOMTransactionChain transactionChain;
+ final TransactionChainHandler localTransactionChainHandler;
if (mountPoint == null) {
- transactionChain = this.transactionChainHandler.get();
+ localTransactionChainHandler = this.transactionChainHandler;
} else {
- transactionChain = transactionChainOfMountPoint(mountPoint);
+ localTransactionChainHandler = transactionChainOfMountPoint(mountPoint);
}
final TransactionVarsWrapper transactionNode = new TransactionVarsWrapper(
- instanceIdentifier, mountPoint, transactionChain);
+ instanceIdentifier, mountPoint, localTransactionChainHandler);
final NormalizedNode<?, ?> node =
ReadDataTransactionUtil.readData(identifier, parameters.getContent(), transactionNode, withDefa,
schemaContextRef, uriInfo);
insertUsed = true;
insert = entry.getValue().iterator().next();
} else {
- throw new RestconfDocumentedException("Insert parameter can be used only once.");
+ throw new RestconfDocumentedException("Insert parameter can be used only once.",
+ RestconfError.ErrorType.PROTOCOL, RestconfError.ErrorTag.BAD_ELEMENT);
}
break;
case "point":
pointUsed = true;
point = entry.getValue().iterator().next();
} else {
- throw new RestconfDocumentedException("Point parameter can be used only once.");
+ throw new RestconfDocumentedException("Point parameter can be used only once.",
+ RestconfError.ErrorType.PROTOCOL, RestconfError.ErrorTag.BAD_ELEMENT);
}
break;
default:
- throw new RestconfDocumentedException("Bad parameter for post: " + entry.getKey());
+ throw new RestconfDocumentedException("Bad parameter for post: " + entry.getKey(),
+ RestconfError.ErrorType.PROTOCOL, RestconfError.ErrorTag.BAD_ELEMENT);
}
}
PutDataTransactionUtil.validateListKeysEqualityInPayloadAndUri(payload);
final DOMMountPoint mountPoint = payload.getInstanceIdentifierContext().getMountPoint();
- final DOMTransactionChain transactionChain;
+ final TransactionChainHandler localTransactionChainHandler;
final SchemaContextRef ref;
if (mountPoint == null) {
- transactionChain = this.transactionChainHandler.get();
+ localTransactionChainHandler = this.transactionChainHandler;
ref = new SchemaContextRef(this.schemaContextHandler.get());
} else {
- transactionChain = transactionChainOfMountPoint(mountPoint);
+ localTransactionChainHandler = transactionChainOfMountPoint(mountPoint);
ref = new SchemaContextRef(mountPoint.getSchemaContext());
}
final TransactionVarsWrapper transactionNode = new TransactionVarsWrapper(
- payload.getInstanceIdentifierContext(), mountPoint, transactionChain);
+ payload.getInstanceIdentifierContext(), mountPoint, localTransactionChainHandler);
return PutDataTransactionUtil.putData(payload, ref, transactionNode, insert, point);
}
checkQueryParams(insertUsed, pointUsed, insert);
final DOMMountPoint mountPoint = payload.getInstanceIdentifierContext().getMountPoint();
- final DOMTransactionChain transactionChain;
+ final TransactionChainHandler localTransactionChainHandler;
final SchemaContextRef ref;
if (mountPoint == null) {
- transactionChain = this.transactionChainHandler.get();
+ localTransactionChainHandler = this.transactionChainHandler;
ref = new SchemaContextRef(this.schemaContextHandler.get());
} else {
- transactionChain = transactionChainOfMountPoint(mountPoint);
+ localTransactionChainHandler = transactionChainOfMountPoint(mountPoint);
ref = new SchemaContextRef(mountPoint.getSchemaContext());
}
final TransactionVarsWrapper transactionNode = new TransactionVarsWrapper(
- payload.getInstanceIdentifierContext(), mountPoint, transactionChain);
+ payload.getInstanceIdentifierContext(), mountPoint, localTransactionChainHandler);
return PostDataTransactionUtil.postData(uriInfo, payload, transactionNode, ref, insert, point);
}
identifier, schemaContextRef.get(), Optional.of(this.mountPointServiceHandler.get()));
final DOMMountPoint mountPoint = instanceIdentifier.getMountPoint();
- final DOMTransactionChain transactionChain;
+ final TransactionChainHandler localTransactionChainHandler;
if (mountPoint == null) {
- transactionChain = this.transactionChainHandler.get();
+ localTransactionChainHandler = this.transactionChainHandler;
} else {
- transactionChain = transactionChainOfMountPoint(mountPoint);
+ localTransactionChainHandler = transactionChainOfMountPoint(mountPoint);
}
final TransactionVarsWrapper transactionNode = new TransactionVarsWrapper(instanceIdentifier, mountPoint,
- transactionChain);
+ localTransactionChainHandler);
return DeleteDataTransactionUtil.deleteData(transactionNode);
}
Preconditions.checkNotNull(context);
final DOMMountPoint mountPoint = context.getInstanceIdentifierContext().getMountPoint();
- final DOMTransactionChain transactionChain;
+ final TransactionChainHandler localTransactionChainHandler;
final SchemaContextRef ref;
if (mountPoint == null) {
- transactionChain = this.transactionChainHandler.get();
+ localTransactionChainHandler = this.transactionChainHandler;
ref = new SchemaContextRef(this.schemaContextHandler.get());
} else {
- transactionChain = transactionChainOfMountPoint(mountPoint);
+ localTransactionChainHandler = transactionChainOfMountPoint(mountPoint);
ref = new SchemaContextRef(mountPoint.getSchemaContext());
}
final TransactionVarsWrapper transactionNode = new TransactionVarsWrapper(
- context.getInstanceIdentifierContext(), mountPoint, transactionChain);
+ context.getInstanceIdentifierContext(), mountPoint, localTransactionChainHandler);
return PatchDataTransactionUtil.patchData(context, transactionNode, ref);
}
* Prepare transaction chain to access data of mount point.
* @param mountPoint
* mount point reference
- * @return {@link DOMTransactionChain}
+ * @return {@link TransactionChainHandler}
*/
- private static DOMTransactionChain transactionChainOfMountPoint(@Nonnull final DOMMountPoint mountPoint) {
+ private static TransactionChainHandler transactionChainOfMountPoint(@Nonnull final DOMMountPoint mountPoint) {
final Optional<DOMDataBroker> domDataBrokerService = mountPoint.getService(DOMDataBroker.class);
if (domDataBrokerService.isPresent()) {
- return domDataBrokerService.get().createTransactionChain(RestConnectorProvider.TRANSACTION_CHAIN_LISTENER);
+ return new TransactionChainHandler(domDataBrokerService.get());
}
final String errMsg = "DOM data broker service isn't available for mount point " + mountPoint.getIdentifier();