From e47092116ce15474412506a967f009a28ee396eb Mon Sep 17 00:00:00 2001 From: "Kajur, Harish (vk250x)" Date: Thu, 13 Dec 2018 09:02:53 -0500 Subject: Update aai-core use new schema ingest library Issue-ID: AAI-2003 Change-Id: I9234b6b594e559b58e445a97b78a4658190e6527 Signed-off-by: Kajur, Harish (vk250x) --- aai-core/pom.xml | 19 ++++++++- .../org/onap/aai/config/IntrospectionConfig.java | 12 +++--- .../org/onap/aai/config/SchemaConfiguration.java | 46 +++++++++++++++++---- aai-core/src/test/java/org/onap/aai/AAISetup.java | 47 ++++++++++++---------- .../query/builder/QueryBuilderTestAbstraction.java | 4 ++ .../query/builder/QueryTestsConfigTranslator.java | 3 +- .../db/DbSerializer_needsFakeRulesTest.java | 4 ++ 7 files changed, 97 insertions(+), 38 deletions(-) (limited to 'aai-core') diff --git a/aai-core/pom.xml b/aai-core/pom.xml index c3eb5f20..fbf6ff4c 100644 --- a/aai-core/pom.xml +++ b/aai-core/pom.xml @@ -66,6 +66,7 @@ v12 v15 v8,v9,v10,v11,v12,v13,v14,v15 + config @@ -169,6 +170,10 @@ schema.uri.base.path ${schema.uri.base.path} + + schema.translator.list + ${schema.translator.list} + aai.release ${aai.release} @@ -263,6 +268,10 @@ schema.uri.base.path ${schema.uri.base.path} + + schema.translator.list + ${schema.translator.list} + aai.release ${aai.release} @@ -348,6 +357,10 @@ schema.uri.base.path ${schema.uri.base.path} + + schema.translator.list + ${schema.translator.list} + aai.release ${aai.release} @@ -448,6 +461,10 @@ schema.uri.base.path ${schema.uri.base.path} + + schema.translator.list + ${schema.translator.list} + aai.release ${aai.release} @@ -699,7 +716,7 @@ org.onap.aai.aai-common aai-schema-ingest - 1.4.0 + ${project.version} org.onap.aai.aai-common diff --git a/aai-core/src/main/java/org/onap/aai/config/IntrospectionConfig.java b/aai-core/src/main/java/org/onap/aai/config/IntrospectionConfig.java index e737f08d..ab74d798 100644 --- a/aai-core/src/main/java/org/onap/aai/config/IntrospectionConfig.java +++ b/aai-core/src/main/java/org/onap/aai/config/IntrospectionConfig.java @@ -21,7 +21,6 @@ */ package org.onap.aai.config; -import org.onap.aai.schema.enums.ObjectMetadata; import org.onap.aai.setup.SchemaVersion; import org.onap.aai.setup.SchemaVersions; import org.springframework.beans.factory.annotation.Autowired; @@ -30,18 +29,19 @@ import org.springframework.context.annotation.Configuration; import java.util.*; import java.util.concurrent.ConcurrentHashMap; -import java.util.stream.Collectors; import org.onap.aai.introspection.LoaderFactory; import org.onap.aai.introspection.MoxyLoader; -import org.onap.aai.nodes.NodeIngestor; - +import org.springframework.context.annotation.Import; +@Import({NodesConfiguration.class, EdgesConfiguration.class}) @Configuration + public class IntrospectionConfig { private Map moxyInstanceMap = new ConcurrentHashMap<>(); + @Autowired - NodeIngestor nodeIngestor; + NodesConfiguration nodesConfiguration; @Bean public LoaderFactory loaderFactory(SchemaVersions schemaVersions) { @@ -52,7 +52,7 @@ public class IntrospectionConfig { public Map moxyLoaderInstance(SchemaVersions schemaVersions) { for(SchemaVersion version : schemaVersions.getVersions()){ if (!moxyInstanceMap.containsKey(version)) { - moxyInstanceMap.put(version, new MoxyLoader(version, nodeIngestor)); + moxyInstanceMap.put(version, new MoxyLoader(version, nodesConfiguration.nodeIngestor())); } } return moxyInstanceMap; diff --git a/aai-core/src/main/java/org/onap/aai/config/SchemaConfiguration.java b/aai-core/src/main/java/org/onap/aai/config/SchemaConfiguration.java index b00ecfb7..88de78e7 100644 --- a/aai-core/src/main/java/org/onap/aai/config/SchemaConfiguration.java +++ b/aai-core/src/main/java/org/onap/aai/config/SchemaConfiguration.java @@ -30,33 +30,65 @@ import org.onap.aai.setup.SchemaLocationsBean; import org.onap.aai.setup.SchemaVersions; import org.onap.aai.validation.CheckEverythingStrategy; import org.onap.aai.validation.SchemaErrorStrategy; +import org.onap.aai.validation.nodes.DefaultDuplicateNodeDefinitionValidationModule; +import org.onap.aai.validation.nodes.DuplicateNodeDefinitionValidationModule; +import org.onap.aai.validation.nodes.NodeValidator; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; import org.springframework.context.annotation.*; - +@Import({NodesConfiguration.class, EdgesConfiguration.class}) @Configuration +@PropertySource(value = "classpath:schema-ingest.properties", ignoreResourceNotFound = true) +@PropertySource(value = "file:${schema.ingest.file}", ignoreResourceNotFound = true) public class SchemaConfiguration { + @Autowired(required = false) + NodesConfiguration nodesConfiguration; + + @Autowired(required = false) + EdgesConfiguration edgesConfiguration; + @Bean - public EdgeIngestor edgeIngestor(SchemaLocationsBean schemaLocationsBean, SchemaVersions schemaVersions){ - return new EdgeIngestor(configTranslator(schemaLocationsBean, schemaVersions), schemaVersions); + public EdgeIngestor edgeIngestor(){ + return edgesConfiguration.edgeIngestor(); } @Bean public EdgeSerializer edgeSerializer(EdgeIngestor edgeIngestor){ return new EdgeSerializer(edgeIngestor); } - + @Bean(name = "nodeIngestor") - public NodeIngestor nodeIngestor(ConfigTranslator configTranslator) { - return new NodeIngestor(configTranslator); + public NodeIngestor nodeIngestor() { + return nodesConfiguration.nodeIngestor(); } + @Bean(name = "configTranslator") + @ConditionalOnProperty(name = "schema.translator.list", havingValue = "config", matchIfMissing = true) public ConfigTranslator configTranslator(SchemaLocationsBean schemaLocationsBean, SchemaVersions schemaVersions) { return new AAIConfigTranslator(schemaLocationsBean, schemaVersions); } @Bean + @ConditionalOnProperty(name = "schema.translator.list", havingValue = "config", matchIfMissing = true) public SchemaErrorStrategy schemaErrorStrategy(){ return new CheckEverythingStrategy(); - } + } + + @Bean + @ConditionalOnProperty(name = "schema.translator.list", havingValue = "config", matchIfMissing = true) + public DuplicateNodeDefinitionValidationModule duplicateNodeDefinitionValidationModule(){ + return new DefaultDuplicateNodeDefinitionValidationModule(); + } + + @Bean + @ConditionalOnProperty(name = "schema.translator.list", havingValue = "config", matchIfMissing = true) + public NodeValidator nodeValidator( + ConfigTranslator configTranslator, + SchemaErrorStrategy schemaErrorStrategy, + DuplicateNodeDefinitionValidationModule duplicateNodeDefinitionValidationModule + ){ + return new NodeValidator(configTranslator, schemaErrorStrategy, duplicateNodeDefinitionValidationModule); + } } diff --git a/aai-core/src/test/java/org/onap/aai/AAISetup.java b/aai-core/src/test/java/org/onap/aai/AAISetup.java index b7a4f740..ce8dfe20 100644 --- a/aai-core/src/test/java/org/onap/aai/AAISetup.java +++ b/aai-core/src/test/java/org/onap/aai/AAISetup.java @@ -59,7 +59,7 @@ import org.springframework.test.context.junit4.rules.SpringMethodRule; IntrospectionConfig.class, RestBeanConfig.class }) -@TestPropertySource(properties = { "schema.uri.base.path = /aai" }) +@TestPropertySource(properties = { "schema.uri.base.path = /aai", "schema.xsd.maxoccurs = 5000" , "schema.translator.list=config"}) public abstract class AAISetup { @ClassRule @@ -69,26 +69,29 @@ public abstract class AAISetup { public final SpringMethodRule springMethodRule = new SpringMethodRule(); @Autowired - protected Map moxyLoaderInstance; - - @Autowired - protected HttpEntry traversalHttpEntry; - - @Autowired - protected HttpEntry traversalUriHttpEntry; - - @Autowired - protected NodeIngestor nodeIngestor; - - @Autowired - protected LoaderFactory loaderFactory; + protected Map moxyLoaderInstance; + + @Autowired + protected HttpEntry traversalHttpEntry; + + @Autowired + protected HttpEntry traversalUriHttpEntry; + + @Autowired + protected NodeIngestor nodeIngestor; + + @Autowired + protected LoaderFactory loaderFactory; - @Autowired - protected SchemaVersions schemaVersions; + @Autowired + protected SchemaVersions schemaVersions; + + @Value("${schema.uri.base.path}") + protected String basePath; - @Value("${schema.uri.base.path}") - protected String basePath; - + @Value("${schema.xsd.maxoccurs}") + protected String maxOccurs; + protected static final String SERVICE_NAME = "JUNIT"; @BeforeClass @@ -98,7 +101,7 @@ public abstract class AAISetup { System.setProperty("aai.service.name", SERVICE_NAME); QueryFormatTestHelper.setFinalStatic(AAIConstants.class.getField("AAI_HOME_ETC_OXM"), "src/test/resources/bundleconfig-local/etc/oxm/"); } - - - + + + } diff --git a/aai-core/src/test/java/org/onap/aai/query/builder/QueryBuilderTestAbstraction.java b/aai-core/src/test/java/org/onap/aai/query/builder/QueryBuilderTestAbstraction.java index 95d0725e..ffb56057 100644 --- a/aai-core/src/test/java/org/onap/aai/query/builder/QueryBuilderTestAbstraction.java +++ b/aai-core/src/test/java/org/onap/aai/query/builder/QueryBuilderTestAbstraction.java @@ -47,6 +47,7 @@ import org.onap.aai.util.AAIConstants; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.test.annotation.DirtiesContext; import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.TestPropertySource; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import org.onap.aai.db.props.AAIProperties; @@ -72,6 +73,9 @@ import static org.junit.Assert.*; IntrospectionConfig.class }) @DirtiesContext(classMode = DirtiesContext.ClassMode.AFTER_CLASS) +@TestPropertySource(properties = { + "schema.translator.list = config" +}) public abstract class QueryBuilderTestAbstraction { protected Loader loader; diff --git a/aai-core/src/test/java/org/onap/aai/query/builder/QueryTestsConfigTranslator.java b/aai-core/src/test/java/org/onap/aai/query/builder/QueryTestsConfigTranslator.java index 90fb90ac..5cadb895 100644 --- a/aai-core/src/test/java/org/onap/aai/query/builder/QueryTestsConfigTranslator.java +++ b/aai-core/src/test/java/org/onap/aai/query/builder/QueryTestsConfigTranslator.java @@ -47,8 +47,7 @@ public class QueryTestsConfigTranslator extends AbstractConfigTranslator { Map> files = new TreeMap<>(); List container = new ArrayList<>(); container.add(file); - files.put(schemaVersions.getDefaultVersion(), container); - + files.put(schemaVersions.getDefaultVersion(), container); return files; } diff --git a/aai-core/src/test/java/org/onap/aai/serialization/db/DbSerializer_needsFakeRulesTest.java b/aai-core/src/test/java/org/onap/aai/serialization/db/DbSerializer_needsFakeRulesTest.java index b9d65c5f..1226eda1 100644 --- a/aai-core/src/test/java/org/onap/aai/serialization/db/DbSerializer_needsFakeRulesTest.java +++ b/aai-core/src/test/java/org/onap/aai/serialization/db/DbSerializer_needsFakeRulesTest.java @@ -44,6 +44,7 @@ import org.onap.aai.serialization.queryformats.QueryFormatTestHelper; import org.onap.aai.setup.SchemaLocationsBean; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.TestPropertySource; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import java.io.UnsupportedEncodingException; @@ -67,6 +68,9 @@ import static org.mockito.Mockito.when; SpringContextAware.class, IntrospectionConfig.class }) +@TestPropertySource(properties = { + "schema.translator.list = config" +}) public class DbSerializer_needsFakeRulesTest { //to use, set thrown.expect to whatever your test needs -- cgit 1.2.3-korg