import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
import org.opendaylight.mdsal.dom.api.DOMTransactionChain;
import org.opendaylight.restconf.common.context.InstanceIdentifierContext;
-import org.opendaylight.restconf.common.context.NormalizedNodeContext;
import org.opendaylight.restconf.common.errors.RestconfDocumentedException;
-import org.opendaylight.restconf.common.errors.RestconfError;
-import org.opendaylight.restconf.common.errors.RestconfError.ErrorTag;
+import org.opendaylight.restconf.nb.rfc8040.InsertParam;
+import org.opendaylight.restconf.nb.rfc8040.PointParam;
+import org.opendaylight.restconf.nb.rfc8040.WriteDataParams;
+import org.opendaylight.restconf.nb.rfc8040.legacy.NormalizedNodePayload;
import org.opendaylight.restconf.nb.rfc8040.rests.transactions.RestconfStrategy;
import org.opendaylight.restconf.nb.rfc8040.rests.transactions.RestconfTransaction;
-import org.opendaylight.restconf.nb.rfc8040.rests.utils.RestconfDataServiceConstant.PostPutQueryParameters.Insert;
import org.opendaylight.restconf.nb.rfc8040.utils.parser.ParserIdentifier;
+import org.opendaylight.yangtools.yang.common.ErrorTag;
+import org.opendaylight.yangtools.yang.common.ErrorType;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNodeContainer;
* @param payload data to put
* @param schemaContext reference to {@link EffectiveModelContext}
* @param strategy object that perform the actual DS operations
- * @param point query parameter
- * @param insert query parameter
+ * @param params {@link WriteDataParams}
* @return {@link Response}
*/
- public static Response putData(final NormalizedNodeContext payload, final EffectiveModelContext schemaContext,
- final RestconfStrategy strategy, final Insert insert, final String point) {
+ public static Response putData(final NormalizedNodePayload payload, final EffectiveModelContext schemaContext,
+ final RestconfStrategy strategy, final WriteDataParams params) {
final YangInstanceIdentifier path = payload.getInstanceIdentifierContext().getInstanceIdentifier();
final FluentFuture<Boolean> existsFuture = strategy.exists(LogicalDatastoreType.CONFIGURATION, path);
final ResponseFactory responseFactory =
new ResponseFactory(existsResponse.result ? Status.NO_CONTENT : Status.CREATED);
final FluentFuture<? extends CommitInfo> submitData = submitData(path, schemaContext, strategy,
- payload.getData(), insert, point);
+ payload.getData(), params);
//This method will close transactionChain if any
- FutureCallbackTx.addCallback(submitData, PUT_TX_TYPE, responseFactory, strategy, path);
+ FutureCallbackTx.addCallback(submitData, PUT_TX_TYPE, responseFactory, path);
return responseFactory.build();
}
* @param schemaContext {@link SchemaContext}
* @param strategy object that perform the actual DS operations
* @param data data
- * @param point query parameter
- * @param insert query parameter
+ * @param params {@link WriteDataParams}
* @return {@link FluentFuture}
*/
private static FluentFuture<? extends CommitInfo> submitData(final YangInstanceIdentifier path,
final EffectiveModelContext schemaContext,
final RestconfStrategy strategy,
final NormalizedNode data,
- final Insert insert, final String point) {
+ final WriteDataParams params) {
final RestconfTransaction transaction = strategy.prepareWriteExecution();
+ final InsertParam insert = params.insert();
if (insert == null) {
return makePut(path, schemaContext, transaction, data);
}
if (readData == null || ((NormalizedNodeContainer<?>) readData).isEmpty()) {
return makePut(path, schemaContext, transaction, data);
}
- transaction.remove(LogicalDatastoreType.CONFIGURATION, path.getParent());
- transaction.replace(LogicalDatastoreType.CONFIGURATION, path, data, schemaContext);
- transaction.replace(LogicalDatastoreType.CONFIGURATION, path.getParent(), readData, schemaContext);
+ transaction.remove(path.getParent());
+ transaction.replace(path, data, schemaContext);
+ transaction.replace(path.getParent(), readData, schemaContext);
return transaction.commit();
case LAST:
return makePut(path, schemaContext, transaction, data);
if (readData == null || ((NormalizedNodeContainer<?>) readData).isEmpty()) {
return makePut(path, schemaContext, transaction, data);
}
- insertWithPointPut(transaction, path, data, schemaContext, point, (NormalizedNodeContainer<?>) readData,
- true);
+ insertWithPointPut(transaction, path, data, schemaContext, params.getPoint(),
+ (NormalizedNodeContainer<?>) readData, true);
return transaction.commit();
case AFTER:
readData = readList(strategy, path.getParent());
if (readData == null || ((NormalizedNodeContainer<?>) readData).isEmpty()) {
return makePut(path, schemaContext, transaction, data);
}
- insertWithPointPut(transaction, path, data, schemaContext, point, (NormalizedNodeContainer<?>) readData,
- false);
+ insertWithPointPut(transaction, path, data, schemaContext, params.getPoint(),
+ (NormalizedNodeContainer<?>) readData, false);
return transaction.commit();
default:
throw new RestconfDocumentedException(
"Used bad value of insert parameter. Possible values are first, last, before or after, "
- + "but was: " + insert, RestconfError.ErrorType.PROTOCOL, ErrorTag.BAD_ATTRIBUTE);
+ + "but was: " + insert, ErrorType.PROTOCOL, ErrorTag.BAD_ATTRIBUTE);
}
}
// FIXME: this method is only called from a context where we are modifying data. This should be part of strategy,
// requiring an already-open transaction. It also must return a future, so it can be properly composed.
static NormalizedNode readList(final RestconfStrategy strategy, final YangInstanceIdentifier path) {
- return ReadDataTransactionUtil.readDataViaTransaction(strategy, LogicalDatastoreType.CONFIGURATION, path,
- false);
+ return ReadDataTransactionUtil.readDataViaTransaction(strategy, LogicalDatastoreType.CONFIGURATION, path);
}
private static void insertWithPointPut(final RestconfTransaction transaction,
final YangInstanceIdentifier path,
final NormalizedNode data,
- final EffectiveModelContext schemaContext, final String point,
+ final EffectiveModelContext schemaContext, final PointParam point,
final NormalizedNodeContainer<?> readList, final boolean before) {
- transaction.remove(LogicalDatastoreType.CONFIGURATION, path.getParent());
- final InstanceIdentifierContext<?> instanceIdentifier =
- ParserIdentifier.toInstanceIdentifier(point, schemaContext, Optional.empty());
+ transaction.remove(path.getParent());
+ final InstanceIdentifierContext instanceIdentifier =
+ // FIXME: Point should be able to give us this method
+ ParserIdentifier.toInstanceIdentifier(point.value(), schemaContext, Optional.empty());
int lastItemPosition = 0;
for (final NormalizedNode nodeChild : readList.body()) {
if (nodeChild.getIdentifier().equals(instanceIdentifier.getInstanceIdentifier().getLastPathArgument())) {
}
int lastInsertedPosition = 0;
final NormalizedNode emptySubtree = ImmutableNodes.fromInstanceId(schemaContext, path.getParent());
- transaction.merge(LogicalDatastoreType.CONFIGURATION,
- YangInstanceIdentifier.create(emptySubtree.getIdentifier()),
- emptySubtree);
+ transaction.merge(YangInstanceIdentifier.create(emptySubtree.getIdentifier()), emptySubtree);
for (final NormalizedNode nodeChild : readList.body()) {
if (lastInsertedPosition == lastItemPosition) {
- transaction.replace(LogicalDatastoreType.CONFIGURATION, path, data, schemaContext);
+ transaction.replace(path, data, schemaContext);
}
final YangInstanceIdentifier childPath = path.getParent().node(nodeChild.getIdentifier());
- transaction.replace(LogicalDatastoreType.CONFIGURATION, childPath, nodeChild, schemaContext);
+ transaction.replace(childPath, nodeChild, schemaContext);
lastInsertedPosition++;
}
}
final SchemaContext schemaContext,
final RestconfTransaction transaction,
final NormalizedNode data) {
- transaction.replace(LogicalDatastoreType.CONFIGURATION, path, data, schemaContext);
+ transaction.replace(path, data, schemaContext);
return transaction.commit();
}
if (dataSchemaNode instanceof ListSchemaNode) {
if (!((ListSchemaNode) dataSchemaNode).isUserOrdered()) {
throw new RestconfDocumentedException("Insert parameter can be used only with ordered-by user list.",
- RestconfError.ErrorType.PROTOCOL, ErrorTag.BAD_ELEMENT);
+ ErrorType.PROTOCOL, ErrorTag.BAD_ELEMENT);
}
return dataSchemaNode;
}
if (!((LeafListSchemaNode) dataSchemaNode).isUserOrdered()) {
throw new RestconfDocumentedException(
"Insert parameter can be used only with ordered-by user leaf-list.",
- RestconfError.ErrorType.PROTOCOL, ErrorTag.BAD_ELEMENT);
+ ErrorType.PROTOCOL, ErrorTag.BAD_ELEMENT);
}
return dataSchemaNode;
}
throw new RestconfDocumentedException("Insert parameter can be used only with list or leaf-list",
- RestconfError.ErrorType.PROTOCOL, ErrorTag.BAD_ELEMENT);
+ ErrorType.PROTOCOL, ErrorTag.BAD_ELEMENT);
}
}