Search in sources :

Example 81 with EffectiveModelContext

use of org.opendaylight.yangtools.yang.model.api.EffectiveModelContext in project netconf by opendaylight.

the class WadlGenTest method testListGeneration.

@Test
public void testListGeneration() {
    final WadlGenerator generator = new WadlGenerator();
    final EffectiveModelContext context = YangParserTestUtils.parseYangResourceDirectory("/wadl-gen");
    Table<GeneratedFileType, GeneratedFilePath, GeneratedFile> generatedWadlFiles = generator.generateFiles(context, Set.copyOf(context.getModules()), (module, representation) -> Optional.empty());
    assertEquals(3, generatedWadlFiles.size());
// TODO: more asserts
}
Also used : GeneratedFilePath(org.opendaylight.yangtools.plugin.generator.api.GeneratedFilePath) GeneratedFileType(org.opendaylight.yangtools.plugin.generator.api.GeneratedFileType) GeneratedFile(org.opendaylight.yangtools.plugin.generator.api.GeneratedFile) EffectiveModelContext(org.opendaylight.yangtools.yang.model.api.EffectiveModelContext) Test(org.junit.Test)

Example 82 with EffectiveModelContext

use of org.opendaylight.yangtools.yang.model.api.EffectiveModelContext in project netconf by opendaylight.

the class MountPointSwagger method getMountPointApi.

public CommonApiObject getMountPointApi(final UriInfo uriInfo, final Long id, final String module, final String revision, final URIType uriType, final OAversion oaversion) {
    final YangInstanceIdentifier iid = getInstanceId(id);
    final EffectiveModelContext context = getSchemaContext(iid);
    final String urlPrefix = getYangMountUrl(iid);
    final String deviceName = extractDeviceName(iid);
    if (context == null) {
        return null;
    }
    if (DATASTORES_LABEL.equals(module) && DATASTORES_REVISION.equals(revision)) {
        return generateDataStoreApiDoc(uriInfo, urlPrefix, deviceName);
    }
    final SwaggerObject swaggerObject = swaggerGenerator.getApiDeclaration(module, revision, uriInfo, context, urlPrefix, uriType, oaversion);
    return BaseYangSwaggerGenerator.getAppropriateDoc(swaggerObject, oaversion);
}
Also used : SwaggerObject(org.opendaylight.netconf.sal.rest.doc.swagger.SwaggerObject) YangInstanceIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier) EffectiveModelContext(org.opendaylight.yangtools.yang.model.api.EffectiveModelContext)

Example 83 with EffectiveModelContext

use of org.opendaylight.yangtools.yang.model.api.EffectiveModelContext in project netconf by opendaylight.

the class MountPointSwagger method getMountPointApi.

public CommonApiObject getMountPointApi(final UriInfo uriInfo, final Long id, final Optional<Integer> pageNum, final URIType uriType, final OAversion oaversion) {
    final YangInstanceIdentifier iid = getInstanceId(id);
    final EffectiveModelContext context = getSchemaContext(iid);
    final String urlPrefix = getYangMountUrl(iid);
    final String deviceName = extractDeviceName(iid);
    if (context == null) {
        return null;
    }
    final DefinitionNames definitionNames = new DefinitionNames();
    boolean includeDataStore = true;
    Optional<Range<Integer>> range = Optional.empty();
    if (pageNum.isPresent()) {
        final int pageNumValue = pageNum.get();
        final int end = DEFAULT_PAGESIZE * pageNumValue - 1;
        int start = end - DEFAULT_PAGESIZE;
        if (pageNumValue == 1) {
            start++;
        } else {
            includeDataStore = false;
        }
        range = Optional.of(Range.closed(start, end));
    }
    final SwaggerObject doc;
    final SwaggerObject swaggerObject = swaggerGenerator.getAllModulesDoc(uriInfo, range, context, Optional.of(deviceName), urlPrefix, definitionNames, uriType, oaversion);
    if (includeDataStore) {
        doc = generateDataStoreApiDoc(uriInfo, urlPrefix, deviceName);
        addFields(doc.getPaths(), swaggerObject.getPaths().fields());
        addFields(doc.getDefinitions(), swaggerObject.getDefinitions().fields());
        doc.getInfo().setTitle(swaggerObject.getInfo().getTitle());
    } else {
        doc = swaggerObject;
    }
    return BaseYangSwaggerGenerator.getAppropriateDoc(doc, oaversion);
}
Also used : SwaggerObject(org.opendaylight.netconf.sal.rest.doc.swagger.SwaggerObject) DefinitionNames(org.opendaylight.netconf.sal.rest.doc.impl.DefinitionNames) Range(com.google.common.collect.Range) YangInstanceIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier) EffectiveModelContext(org.opendaylight.yangtools.yang.model.api.EffectiveModelContext)

Example 84 with EffectiveModelContext

use of org.opendaylight.yangtools.yang.model.api.EffectiveModelContext in project netconf by opendaylight.

the class CreateStreamUtilTest method prepareDomPayload.

private NormalizedNodePayload prepareDomPayload(final String rpcName, final Function<RpcDefinition, ContainerLike> rpcToContainer, final String toasterValue, final String inputOutputName) {
    final EffectiveModelContext schema = refSchemaCtx;
    final Module rpcModule = schema.findModules("sal-remote").iterator().next();
    final QName rpcQName = QName.create(rpcModule.getQNameModule(), rpcName);
    ContainerLike rpcInputSchemaNode = null;
    for (final RpcDefinition rpc : rpcModule.getRpcs()) {
        if (rpcQName.isEqualWithoutRevision(rpc.getQName())) {
            rpcInputSchemaNode = rpcToContainer.apply(rpc);
            break;
        }
    }
    assertNotNull(rpcInputSchemaNode);
    final DataContainerNodeBuilder<YangInstanceIdentifier.NodeIdentifier, ContainerNode> container = SchemaAwareBuilders.containerBuilder(rpcInputSchemaNode);
    final QName lfQName = QName.create(rpcModule.getQNameModule(), inputOutputName);
    final DataSchemaNode lfSchemaNode = rpcInputSchemaNode.findDataChildByName(lfQName).orElseThrow();
    assertThat(lfSchemaNode, instanceOf(LeafSchemaNode.class));
    final Object o;
    if ("toaster".equals(toasterValue)) {
        final QName rpcQname = QName.create("http://netconfcentral.org/ns/toaster", "2009-11-20", toasterValue);
        o = YangInstanceIdentifier.builder().node(rpcQname).build();
    } else {
        o = toasterValue;
    }
    final LeafNode<Object> lfNode = SchemaAwareBuilders.leafBuilder((LeafSchemaNode) lfSchemaNode).withValue(o).build();
    container.withChild(lfNode);
    return NormalizedNodePayload.of(new InstanceIdentifierContext<>(null, rpcInputSchemaNode, null, schema), container.build());
}
Also used : ContainerLike(org.opendaylight.yangtools.yang.model.api.ContainerLike) RpcDefinition(org.opendaylight.yangtools.yang.model.api.RpcDefinition) DataSchemaNode(org.opendaylight.yangtools.yang.model.api.DataSchemaNode) QName(org.opendaylight.yangtools.yang.common.QName) LeafSchemaNode(org.opendaylight.yangtools.yang.model.api.LeafSchemaNode) ContainerNode(org.opendaylight.yangtools.yang.data.api.schema.ContainerNode) Module(org.opendaylight.yangtools.yang.model.api.Module) EffectiveModelContext(org.opendaylight.yangtools.yang.model.api.EffectiveModelContext)

Example 85 with EffectiveModelContext

use of org.opendaylight.yangtools.yang.model.api.EffectiveModelContext in project netconf by opendaylight.

the class ParserIdentifier method coerceModelContext.

private static EffectiveModelContext coerceModelContext(final DOMMountPoint mountPoint) {
    final EffectiveModelContext context = modelContext(mountPoint);
    checkState(context != null, "Mount point %s does not have a model context", mountPoint);
    return context;
}
Also used : EffectiveModelContext(org.opendaylight.yangtools.yang.model.api.EffectiveModelContext)

Aggregations

EffectiveModelContext (org.opendaylight.yangtools.yang.model.api.EffectiveModelContext)182 Test (org.junit.Test)99 Module (org.opendaylight.yangtools.yang.model.api.Module)37 QName (org.opendaylight.yangtools.yang.common.QName)29 ContainerNode (org.opendaylight.yangtools.yang.data.api.schema.ContainerNode)28 DataSchemaNode (org.opendaylight.yangtools.yang.model.api.DataSchemaNode)26 NormalizedNode (org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode)24 LeafSchemaNode (org.opendaylight.yangtools.yang.model.api.LeafSchemaNode)24 ContainerSchemaNode (org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode)21 YangInstanceIdentifier (org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier)18 QNameModule (org.opendaylight.yangtools.yang.common.QNameModule)16 NodeIdentifier (org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier)16 NormalizedNodeStreamWriter (org.opendaylight.yangtools.yang.data.api.schema.stream.NormalizedNodeStreamWriter)16 IRSchemaSource (org.opendaylight.yangtools.yang.parser.rfc7950.ir.IRSchemaSource)14 DOMMountPoint (org.opendaylight.mdsal.dom.api.DOMMountPoint)13 RestconfDocumentedException (org.opendaylight.restconf.common.errors.RestconfDocumentedException)13 RpcDefinition (org.opendaylight.yangtools.yang.model.api.RpcDefinition)13 MapEntryNode (org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode)11 IOException (java.io.IOException)9 Collection (java.util.Collection)9