use of org.opendaylight.restconf.common.errors.RestconfDocumentedException in project netconf by opendaylight.
the class PostDataTransactionUtil method submitData.
/**
* Post data by type.
*
* @param path path
* @param data data
* @param strategy object that perform the actual DS operations
* @param schemaContext schema context of data
* @param point query parameter
* @param insert query parameter
* @return {@link FluentFuture}
*/
private static FluentFuture<? extends CommitInfo> submitData(final YangInstanceIdentifier path, final NormalizedNode data, final RestconfStrategy strategy, final EffectiveModelContext schemaContext, final WriteDataParams params) {
final RestconfTransaction transaction = strategy.prepareWriteExecution();
final InsertParam insert = params.insert();
if (insert == null) {
makePost(path, data, schemaContext, transaction);
return transaction.commit();
}
PutDataTransactionUtil.checkListAndOrderedType(schemaContext, path);
final NormalizedNode readData;
switch(insert) {
case FIRST:
readData = PutDataTransactionUtil.readList(strategy, path.getParent().getParent());
if (readData == null || ((NormalizedNodeContainer<?>) readData).isEmpty()) {
transaction.replace(path, data, schemaContext);
return transaction.commit();
}
checkItemDoesNotExists(strategy.exists(LogicalDatastoreType.CONFIGURATION, path), path);
transaction.remove(path.getParent().getParent());
transaction.replace(path, data, schemaContext);
transaction.replace(path.getParent().getParent(), readData, schemaContext);
return transaction.commit();
case LAST:
makePost(path, data, schemaContext, transaction);
return transaction.commit();
case BEFORE:
readData = PutDataTransactionUtil.readList(strategy, path.getParent().getParent());
if (readData == null || ((NormalizedNodeContainer<?>) readData).isEmpty()) {
transaction.replace(path, data, schemaContext);
return transaction.commit();
}
checkItemDoesNotExists(strategy.exists(LogicalDatastoreType.CONFIGURATION, path), path);
insertWithPointPost(path, data, schemaContext, params.getPoint(), (NormalizedNodeContainer<?>) readData, true, transaction);
return transaction.commit();
case AFTER:
readData = PutDataTransactionUtil.readList(strategy, path.getParent().getParent());
if (readData == null || ((NormalizedNodeContainer<?>) readData).isEmpty()) {
transaction.replace(path, data, schemaContext);
return transaction.commit();
}
checkItemDoesNotExists(strategy.exists(LogicalDatastoreType.CONFIGURATION, path), path);
insertWithPointPost(path, data, schemaContext, params.getPoint(), (NormalizedNodeContainer<?>) readData, false, transaction);
return transaction.commit();
default:
throw new RestconfDocumentedException("Used bad value of insert parameter. Possible values are first, last, before or after, but was: " + insert, ErrorType.PROTOCOL, ErrorTag.BAD_ATTRIBUTE);
}
}
use of org.opendaylight.restconf.common.errors.RestconfDocumentedException in project netconf by opendaylight.
the class PutDataTransactionUtil method submitData.
/**
* Put data to DS.
*
* @param path path of data
* @param schemaContext {@link SchemaContext}
* @param strategy object that perform the actual DS operations
* @param data data
* @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 WriteDataParams params) {
final RestconfTransaction transaction = strategy.prepareWriteExecution();
final InsertParam insert = params.insert();
if (insert == null) {
return makePut(path, schemaContext, transaction, data);
}
checkListAndOrderedType(schemaContext, path);
final NormalizedNode readData;
switch(insert) {
case FIRST:
readData = readList(strategy, path.getParent());
if (readData == null || ((NormalizedNodeContainer<?>) readData).isEmpty()) {
return makePut(path, schemaContext, transaction, data);
}
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);
case BEFORE:
readData = readList(strategy, path.getParent());
if (readData == null || ((NormalizedNodeContainer<?>) readData).isEmpty()) {
return makePut(path, schemaContext, transaction, data);
}
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, 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, ErrorType.PROTOCOL, ErrorTag.BAD_ATTRIBUTE);
}
}
use of org.opendaylight.restconf.common.errors.RestconfDocumentedException in project netconf by opendaylight.
the class PutDataTransactionUtil method checkListAndOrderedType.
public static DataSchemaNode checkListAndOrderedType(final EffectiveModelContext ctx, final YangInstanceIdentifier path) {
final YangInstanceIdentifier parent = path.getParent();
final DataSchemaContextNode<?> node = DataSchemaContextTree.from(ctx).findChild(parent).orElseThrow();
final DataSchemaNode dataSchemaNode = node.getDataSchemaNode();
if (dataSchemaNode instanceof ListSchemaNode) {
if (!((ListSchemaNode) dataSchemaNode).isUserOrdered()) {
throw new RestconfDocumentedException("Insert parameter can be used only with ordered-by user list.", ErrorType.PROTOCOL, ErrorTag.BAD_ELEMENT);
}
return dataSchemaNode;
}
if (dataSchemaNode instanceof LeafListSchemaNode) {
if (!((LeafListSchemaNode) dataSchemaNode).isUserOrdered()) {
throw new RestconfDocumentedException("Insert parameter can be used only with ordered-by user leaf-list.", ErrorType.PROTOCOL, ErrorTag.BAD_ELEMENT);
}
return dataSchemaNode;
}
throw new RestconfDocumentedException("Insert parameter can be used only with list or leaf-list", ErrorType.PROTOCOL, ErrorTag.BAD_ELEMENT);
}
use of org.opendaylight.restconf.common.errors.RestconfDocumentedException in project netconf by opendaylight.
the class ReadDataTransactionUtil method validateNodeMerge.
/**
* Validates whether the two NormalizedNodes can be merged.
*
* @param stateDataNode data node of state data
* @param configDataNode data node of config data
*/
private static void validateNodeMerge(@NonNull final NormalizedNode stateDataNode, @NonNull final NormalizedNode configDataNode) {
final QNameModule moduleOfStateData = stateDataNode.getIdentifier().getNodeType().getModule();
final QNameModule moduleOfConfigData = configDataNode.getIdentifier().getNodeType().getModule();
if (!moduleOfStateData.equals(moduleOfConfigData)) {
throw new RestconfDocumentedException("Unable to merge data from different modules.");
}
}
use of org.opendaylight.restconf.common.errors.RestconfDocumentedException in project netconf by opendaylight.
the class ReadDataTransactionUtil method prepareDataByParamWithDef.
private static NormalizedNode prepareDataByParamWithDef(final NormalizedNode result, final YangInstanceIdentifier path, final WithDefaultsParam withDefa, final EffectiveModelContext ctx) {
boolean trim;
switch(withDefa) {
case TRIM:
trim = true;
break;
case EXPLICIT:
trim = false;
break;
default:
throw new RestconfDocumentedException("Unsupported with-defaults value " + withDefa.paramValue());
}
final DataSchemaContextTree baseSchemaCtxTree = DataSchemaContextTree.from(ctx);
final DataSchemaNode baseSchemaNode = baseSchemaCtxTree.findChild(path).orElseThrow().getDataSchemaNode();
if (result instanceof ContainerNode) {
final DataContainerNodeBuilder<NodeIdentifier, ContainerNode> builder = SchemaAwareBuilders.containerBuilder((ContainerSchemaNode) baseSchemaNode);
buildCont(builder, (ContainerNode) result, baseSchemaCtxTree, path, trim);
return builder.build();
} else {
final DataContainerNodeBuilder<NodeIdentifierWithPredicates, MapEntryNode> builder = SchemaAwareBuilders.mapEntryBuilder((ListSchemaNode) baseSchemaNode);
buildMapEntryBuilder(builder, (MapEntryNode) result, baseSchemaCtxTree, path, trim, ((ListSchemaNode) baseSchemaNode).getKeyDefinition());
return builder.build();
}
}
Aggregations