Search in sources :

Example 1 with Revision

use of org.opendaylight.yangtools.yang.common.Revision in project controller by opendaylight.

the class ConfigSubsystemFacade method transformIdentities.

private static Map<String, Map<Optional<Revision>, IdentityMapping>> transformIdentities(final Set<Module> modules) {
    Map<String, Map<Optional<Revision>, IdentityMapping>> mappedIds = new HashMap<>();
    for (Module module : modules) {
        String namespace = module.getNamespace().toString();
        Map<Optional<Revision>, IdentityMapping> revisionsByNamespace = mappedIds.computeIfAbsent(namespace, k -> new HashMap<>());
        Optional<Revision> revision = Optional.fromJavaUtil(module.getRevision());
        IdentityMapping identityMapping = revisionsByNamespace.computeIfAbsent(revision, k -> new IdentityMapping());
        for (IdentitySchemaNode identitySchemaNode : module.getIdentities()) {
            identityMapping.addIdSchemaNode(identitySchemaNode);
        }
    }
    return mappedIds;
}
Also used : IdentityMapping(org.opendaylight.controller.config.facade.xml.mapping.IdentityMapping) Revision(org.opendaylight.yangtools.yang.common.Revision) Optional(com.google.common.base.Optional) HashMap(java.util.HashMap) Module(org.opendaylight.yangtools.yang.model.api.Module) HashMap(java.util.HashMap) Map(java.util.Map) IdentitySchemaNode(org.opendaylight.yangtools.yang.model.api.IdentitySchemaNode)

Example 2 with Revision

use of org.opendaylight.yangtools.yang.common.Revision in project controller by opendaylight.

the class ConfigSubsystemFacade method getConfigMapping.

public Config getConfigMapping() {
    final YangStoreContext snapshot = yangStoreService.getCurrentSnapshot();
    Map<String, Map<String, ModuleConfig>> factories = transformMbeToModuleConfigs(snapshot.getModuleMXBeanEntryMap());
    Map<String, Map<Optional<Revision>, IdentityMapping>> identitiesMap = transformIdentities(snapshot.getModules());
    return new Config(factories, identitiesMap, snapshot.getEnumResolver());
}
Also used : YangStoreContext(org.opendaylight.controller.config.facade.xml.osgi.YangStoreContext) Revision(org.opendaylight.yangtools.yang.common.Revision) ModuleConfig(org.opendaylight.controller.config.facade.xml.mapping.config.ModuleConfig) Config(org.opendaylight.controller.config.facade.xml.mapping.config.Config) InstanceConfig(org.opendaylight.controller.config.facade.xml.mapping.config.InstanceConfig) HashMap(java.util.HashMap) Map(java.util.Map)

Example 3 with Revision

use of org.opendaylight.yangtools.yang.common.Revision in project controller by opendaylight.

the class SimpleIdentityRefAttributeReadingStrategyTest method testReadIdRef.

@Test
public void testReadIdRef() throws Exception {
    final Map<String, Map<Optional<Revision>, IdentityMapping>> identityMapping = Maps.newHashMap();
    final IdentityMapping value = new IdentityMapping();
    final Optional<Revision> rev = Optional.of(Revision.of("2017-10-10"));
    identityMapping.put("namespace", Collections.singletonMap(rev, value));
    identityMapping.put("inner", Collections.singletonMap(rev, value));
    final SimpleIdentityRefAttributeReadingStrategy key = new SimpleIdentityRefAttributeReadingStrategy(null, "key", identityMapping);
    String read = key.readElementContent(XmlElement.fromString("<el xmlns=\"namespace\">local</el>"));
    assertEquals(QName.create(URI.create("namespace"), rev.toJavaUtil(), "local").toString(), read);
    read = key.readElementContent(XmlElement.fromString("<el xmlns:a=\"inner\" xmlns=\"namespace\">a:local</el>"));
    assertEquals(QName.create(URI.create("inner"), rev.toJavaUtil(), "local").toString(), read);
    read = key.readElementContent(XmlElement.fromString("<top xmlns=\"namespace\"><el>local</el></top>").getOnlyChildElement());
    assertEquals(QName.create(URI.create("namespace"), rev.toJavaUtil(), "local").toString(), read);
}
Also used : IdentityMapping(org.opendaylight.controller.config.facade.xml.mapping.IdentityMapping) Revision(org.opendaylight.yangtools.yang.common.Revision) Map(java.util.Map) Test(org.junit.Test)

Aggregations

Map (java.util.Map)3 Revision (org.opendaylight.yangtools.yang.common.Revision)3 HashMap (java.util.HashMap)2 IdentityMapping (org.opendaylight.controller.config.facade.xml.mapping.IdentityMapping)2 Optional (com.google.common.base.Optional)1 Test (org.junit.Test)1 Config (org.opendaylight.controller.config.facade.xml.mapping.config.Config)1 InstanceConfig (org.opendaylight.controller.config.facade.xml.mapping.config.InstanceConfig)1 ModuleConfig (org.opendaylight.controller.config.facade.xml.mapping.config.ModuleConfig)1 YangStoreContext (org.opendaylight.controller.config.facade.xml.osgi.YangStoreContext)1 IdentitySchemaNode (org.opendaylight.yangtools.yang.model.api.IdentitySchemaNode)1 Module (org.opendaylight.yangtools.yang.model.api.Module)1