diff options
Diffstat (limited to 'aai-core/src/main/java/org/onap/aai')
15 files changed, 102 insertions, 81 deletions
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 ab74d798..750bc24f 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 @@ -33,7 +33,7 @@ import java.util.concurrent.ConcurrentHashMap; import org.onap.aai.introspection.LoaderFactory; import org.onap.aai.introspection.MoxyLoader; import org.springframework.context.annotation.Import; -@Import({NodesConfiguration.class, EdgesConfiguration.class}) +@Import({ConfigConfiguration.class, SchemaServiceConfiguration.class, NodesConfiguration.class, EdgesConfiguration.class}) @Configuration public class IntrospectionConfig { 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 88de78e7..c11d7a56 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 @@ -24,10 +24,10 @@ package org.onap.aai.config; import org.onap.aai.edges.EdgeIngestor; import org.onap.aai.nodes.NodeIngestor; import org.onap.aai.setup.AAIConfigTranslator; -import org.onap.aai.serialization.db.EdgeSerializer; import org.onap.aai.setup.ConfigTranslator; import org.onap.aai.setup.SchemaLocationsBean; -import org.onap.aai.setup.SchemaVersions; +import org.onap.aai.setup.SchemaConfigVersions; +import org.onap.aai.serialization.db.EdgeSerializer; import org.onap.aai.validation.CheckEverythingStrategy; import org.onap.aai.validation.SchemaErrorStrategy; import org.onap.aai.validation.nodes.DefaultDuplicateNodeDefinitionValidationModule; @@ -42,6 +42,7 @@ import org.springframework.context.annotation.*; @PropertySource(value = "file:${schema.ingest.file}", ignoreResourceNotFound = true) public class SchemaConfiguration { + //TODO : Inject this directly into nodeIngestor @Autowired(required = false) NodesConfiguration nodesConfiguration; @@ -66,7 +67,7 @@ public class SchemaConfiguration { @Bean(name = "configTranslator") @ConditionalOnProperty(name = "schema.translator.list", havingValue = "config", matchIfMissing = true) - public ConfigTranslator configTranslator(SchemaLocationsBean schemaLocationsBean, SchemaVersions schemaVersions) { + public ConfigTranslator configTranslator(SchemaLocationsBean schemaLocationsBean, SchemaConfigVersions schemaVersions) { return new AAIConfigTranslator(schemaLocationsBean, schemaVersions); } diff --git a/aai-core/src/main/java/org/onap/aai/dbgen/SchemaGenerator.java b/aai-core/src/main/java/org/onap/aai/dbgen/SchemaGenerator.java index e6eb1bca..b9277cd5 100644 --- a/aai-core/src/main/java/org/onap/aai/dbgen/SchemaGenerator.java +++ b/aai-core/src/main/java/org/onap/aai/dbgen/SchemaGenerator.java @@ -30,10 +30,7 @@ import org.onap.aai.config.SpringContextAware; import org.onap.aai.db.props.AAIProperties; import org.onap.aai.edges.EdgeIngestor; import org.onap.aai.edges.exceptions.EdgeRuleNotFoundException; -import org.onap.aai.introspection.Introspector; -import org.onap.aai.introspection.Loader; -import org.onap.aai.introspection.LoaderFactory; -import org.onap.aai.introspection.ModelType; +import org.onap.aai.introspection.*; import org.onap.aai.logging.LogFormatTools; import org.onap.aai.schema.enums.PropertyMetadata; import org.onap.aai.edges.EdgeRule; @@ -111,16 +108,8 @@ public class SchemaGenerator { } } - // ApplicationContext ctx = SpringContextAware.getApplicationContext(); - // Loader loader = - // ctx.getBean(LoaderFactory.class).createLoaderForVersion(ModelType.MOXY, - // AAIProperties.LATEST); - LoaderFactory loaderFactory = SpringContextAware.getBean(LoaderFactory.class); - SchemaVersions schemaVersions = SpringContextAware.getBean(SchemaVersions.class); + Loader loader = LoaderUtil.getLatestVersion(); - Loader loader = loaderFactory.createLoaderForVersion(ModelType.MOXY, schemaVersions.getDefaultVersion()); - // Loader loader = LoaderFactory.createLoaderForVersion(ModelType.MOXY, - // AAIProperties.LATEST); Map<String, Introspector> objs = loader.getAllObjects(); Map<String, PropertyKey> seenProps = new HashMap<>(); diff --git a/aai-core/src/main/java/org/onap/aai/introspection/LoaderUtil.java b/aai-core/src/main/java/org/onap/aai/introspection/LoaderUtil.java new file mode 100644 index 00000000..16d87d96 --- /dev/null +++ b/aai-core/src/main/java/org/onap/aai/introspection/LoaderUtil.java @@ -0,0 +1,34 @@ +/** + * ============LICENSE_START======================================================= + * org.onap.aai + * ================================================================================ + * Copyright © 2019 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ +package org.onap.aai.introspection; + +import org.onap.aai.config.SpringContextAware; +import org.onap.aai.setup.SchemaVersions; + +public class LoaderUtil { + + public static Loader getLatestVersion(){ + + LoaderFactory loaderFactory = SpringContextAware.getBean(LoaderFactory.class); + SchemaVersions schemaVersions = (SchemaVersions) SpringContextAware.getBean("schemaVersions"); + + return loaderFactory.createLoaderForVersion(ModelType.MOXY, schemaVersions.getDefaultVersion()); + } +} diff --git a/aai-core/src/main/java/org/onap/aai/introspection/sideeffect/SideEffect.java b/aai-core/src/main/java/org/onap/aai/introspection/sideeffect/SideEffect.java index 6bf03c17..891876af 100644 --- a/aai-core/src/main/java/org/onap/aai/introspection/sideeffect/SideEffect.java +++ b/aai-core/src/main/java/org/onap/aai/introspection/sideeffect/SideEffect.java @@ -27,10 +27,7 @@ import org.onap.aai.db.props.AAIProperties; import org.onap.aai.edges.exceptions.AmbiguousRuleChoiceException; import org.onap.aai.edges.exceptions.EdgeRuleNotFoundException; import org.onap.aai.exceptions.AAIException; -import org.onap.aai.introspection.Introspector; -import org.onap.aai.introspection.Loader; -import org.onap.aai.introspection.LoaderFactory; -import org.onap.aai.introspection.ModelType; +import org.onap.aai.introspection.*; import org.onap.aai.introspection.sideeffect.exceptions.AAIMissingRequiredPropertyException; import org.onap.aai.schema.enums.PropertyMetadata; import org.onap.aai.serialization.db.DBSerializer; @@ -63,9 +60,7 @@ public abstract class SideEffect { this.dbEngine = dbEngine; this.serializer = serializer; this.self = self; - LoaderFactory loaderFactory = SpringContextAware.getBean(LoaderFactory.class); - SchemaVersions schemaVersions = SpringContextAware.getBean(SchemaVersions.class); - this.latestLoader = loaderFactory.createLoaderForVersion(ModelType.MOXY, schemaVersions.getDefaultVersion()) ; + this.latestLoader = LoaderUtil.getLatestVersion(); } protected void execute() throws UnsupportedEncodingException, URISyntaxException, AAIException { @@ -91,9 +86,9 @@ public abstract class SideEffect { } return result; } - + protected Map<String, String> findProperties(Introspector obj, String uriString) throws AAIMissingRequiredPropertyException { - + final Map<String, String> result = new HashMap<>(); final Set<String> missing = new LinkedHashSet<>(); Matcher m = template.matcher(uriString); @@ -111,13 +106,13 @@ public abstract class SideEffect { missing.add(propName); } } - + if (!missing.isEmpty() && (properties != missing.size())) { throw new AAIMissingRequiredPropertyException("Cannot complete " + this.getPropertyMetadata().toString() + " uri. Missing properties " + missing); } return result; } - + protected Optional<String> replaceTemplates(Introspector obj, String uriString) throws AAIMissingRequiredPropertyException { String result = uriString; final Map<String, String> propMap = this.findProperties(obj, uriString); @@ -132,7 +127,7 @@ public abstract class SideEffect { result = result.replaceFirst("/[^/]+?(?:/\\*)+", ""); return Optional.of(result); } - + private Optional<String> resolveRelativePath(Optional<String> populatedUri) throws UnsupportedEncodingException { if (!populatedUri.isPresent()) { return Optional.empty(); @@ -140,7 +135,7 @@ public abstract class SideEffect { return Optional.of(populatedUri.get().replaceFirst("\\./", this.serializer.getURIForVertex(self) + "/")); } } - + protected abstract boolean replaceWithWildcard(); protected abstract PropertyMetadata getPropertyMetadata(); protected abstract void processURI(Optional<String> completeUri, Entry<String, String> entry) throws URISyntaxException, UnsupportedEncodingException, AAIException, EdgeRuleNotFoundException, AmbiguousRuleChoiceException; diff --git a/aai-core/src/main/java/org/onap/aai/parsers/query/QueryParser.java b/aai-core/src/main/java/org/onap/aai/parsers/query/QueryParser.java index 9129911a..d7f1832c 100644 --- a/aai-core/src/main/java/org/onap/aai/parsers/query/QueryParser.java +++ b/aai-core/src/main/java/org/onap/aai/parsers/query/QueryParser.java @@ -21,13 +21,12 @@ package org.onap.aai.parsers.query; import org.apache.tinkerpop.gremlin.structure.Vertex; import org.onap.aai.config.SpringContextAware; -import org.onap.aai.db.props.AAIProperties; import org.onap.aai.introspection.Loader; import org.onap.aai.introspection.LoaderFactory; +import org.onap.aai.introspection.LoaderUtil; import org.onap.aai.query.builder.QueryBuilder; import org.onap.aai.setup.SchemaVersion; import org.onap.aai.setup.SchemaVersions; - import java.net.URI; /** @@ -38,17 +37,17 @@ public abstract class QueryParser { protected Loader loader = null; protected Loader latestLoader = null; protected QueryBuilder<Vertex> queryBuilder = null; - + protected QueryBuilder<Vertex> parentQueryBuilder = null; - + protected URI uri = null; - + protected String resultResource = ""; - + protected String parentResourceType = ""; - + protected String containerResource = ""; - + /** * Instantiates a new query parser. * @@ -61,10 +60,11 @@ public abstract class QueryParser { this.queryBuilder = queryBuilder; this.loader = loader; LoaderFactory loaderFactory = SpringContextAware.getBean(LoaderFactory.class); - SchemaVersion latest = SpringContextAware.getBean(SchemaVersions.class).getDefaultVersion(); + SchemaVersion latest = ((SchemaVersions) SpringContextAware.getBean("schemaVersions")).getDefaultVersion(); + this.latestLoader = loaderFactory.createLoaderForVersion(loader.getModelType(), latest); } - + /** * Instantiates a new query parser. * @@ -74,21 +74,19 @@ public abstract class QueryParser { protected QueryParser(Loader loader, QueryBuilder<Vertex> queryBuilder) { this.queryBuilder = queryBuilder; this.loader = loader; - LoaderFactory loaderFactory = SpringContextAware.getBean(LoaderFactory.class); - SchemaVersion latest = SpringContextAware.getBean(SchemaVersions.class).getDefaultVersion(); - this.latestLoader = loaderFactory.createLoaderForVersion(loader.getModelType(), latest); + this.latestLoader = LoaderUtil.getLatestVersion(); } - + /** * Gets the container type. * * @return the container type */ public String getContainerType() { - + return this.containerResource; } - + /** * Gets the parent result type. * @@ -97,7 +95,7 @@ public abstract class QueryParser { public String getParentResultType() { return this.parentResourceType; } - + /** * Gets the result type. * @@ -106,7 +104,7 @@ public abstract class QueryParser { public String getResultType() { return this.resultResource; } - + /** * Gets the query builder. * @@ -115,7 +113,7 @@ public abstract class QueryParser { public QueryBuilder<Vertex> getQueryBuilder() { return this.queryBuilder; } - + /** * Gets the uri. * @@ -124,7 +122,7 @@ public abstract class QueryParser { public URI getUri() { return this.uri; } - + /** * Gets the parent query builder. * @@ -137,7 +135,7 @@ public abstract class QueryParser { return this.queryBuilder; } } - + /** * Checks if is dependent. * diff --git a/aai-core/src/main/java/org/onap/aai/parsers/relationship/RelationshipToURI.java b/aai-core/src/main/java/org/onap/aai/parsers/relationship/RelationshipToURI.java index 5ab38544..8cbed6d6 100644 --- a/aai-core/src/main/java/org/onap/aai/parsers/relationship/RelationshipToURI.java +++ b/aai-core/src/main/java/org/onap/aai/parsers/relationship/RelationshipToURI.java @@ -90,7 +90,7 @@ public class RelationshipToURI { //TODO proper spring wiring, but that requires a lot of refactoring so for now we have this ApplicationContext ctx = SpringContextAware.getApplicationContext(); edgeRules = ctx.getBean(EdgeIngestor.class); - schemaVersions = ctx.getBean(SchemaVersions.class); + schemaVersions = (SchemaVersions) ctx.getBean("schemaVersions"); } /** diff --git a/aai-core/src/main/java/org/onap/aai/parsers/uri/URIToRelationshipObject.java b/aai-core/src/main/java/org/onap/aai/parsers/uri/URIToRelationshipObject.java index cbb6ccdb..08eca16d 100644 --- a/aai-core/src/main/java/org/onap/aai/parsers/uri/URIToRelationshipObject.java +++ b/aai-core/src/main/java/org/onap/aai/parsers/uri/URIToRelationshipObject.java @@ -131,7 +131,7 @@ public class URIToRelationshipObject implements Parsable { URI originalUri = parser.getOriginalURI(); URI relatedLink = new URI(this.baseURL + this.originalVersion + "/" + originalUri); - SchemaVersions schemaVersions = SpringContextAware.getBean(SchemaVersions.class); + SchemaVersions schemaVersions = (SchemaVersions)SpringContextAware.getBean("schemaVersions"); if (this.originalVersion.compareTo(schemaVersions.getRelatedLinkVersion()) >= 0) { //only return the path section of the URI past v10 relatedLink = new URI(relatedLink.getRawPath()); diff --git a/aai-core/src/main/java/org/onap/aai/query/builder/GraphTraversalBuilder.java b/aai-core/src/main/java/org/onap/aai/query/builder/GraphTraversalBuilder.java index 80122296..bf9dd17f 100644 --- a/aai-core/src/main/java/org/onap/aai/query/builder/GraphTraversalBuilder.java +++ b/aai-core/src/main/java/org/onap/aai/query/builder/GraphTraversalBuilder.java @@ -226,16 +226,18 @@ public abstract class GraphTraversalBuilder<E> extends QueryBuilder<E> { @Override public QueryBuilder<Vertex> getVerticesByBooleanProperty(String key, Object value) { - boolean bValue = false; - - if(value instanceof String){ - bValue = Boolean.valueOf(value.toString()); - } else if(value instanceof Boolean){ - bValue = (Boolean) value; + if(value!=null && !"".equals(value)) { + boolean bValue = false; + + if(value instanceof String){//"true" + bValue = Boolean.valueOf(value.toString()); + } else if(value instanceof Boolean){//true + bValue = (Boolean) value; + } + + traversal.has(key, bValue); + stepIndex++; } - - traversal.has(key, bValue); - stepIndex++; return (QueryBuilder<Vertex>) this; } diff --git a/aai-core/src/main/java/org/onap/aai/query/builder/GremlinQueryBuilder.java b/aai-core/src/main/java/org/onap/aai/query/builder/GremlinQueryBuilder.java index 43925f49..1dc2cfe8 100644 --- a/aai-core/src/main/java/org/onap/aai/query/builder/GremlinQueryBuilder.java +++ b/aai-core/src/main/java/org/onap/aai/query/builder/GremlinQueryBuilder.java @@ -115,16 +115,18 @@ public abstract class GremlinQueryBuilder<E> extends QueryBuilder<E> { @Override public QueryBuilder<Vertex> getVerticesByBooleanProperty(String key, Object value) { - boolean bValue = false; - - if(value instanceof String){ - bValue = Boolean.valueOf(value.toString()); - } else if(value instanceof Boolean){ - bValue = (Boolean) value; - } - - list.add(HAS + key + "', " + bValue + ")"); - stepIndex++; + + if(value!=null && !"".equals(value)) { + boolean bValue = false; + if(value instanceof String){ + bValue = Boolean.valueOf(value.toString()); + } else if(value instanceof Boolean){ + bValue = (Boolean) value; + } + + list.add(HAS + key + "', " + bValue + ")"); + stepIndex++; + } return (QueryBuilder<Vertex>) this; } diff --git a/aai-core/src/main/java/org/onap/aai/query/builder/QueryBuilder.java b/aai-core/src/main/java/org/onap/aai/query/builder/QueryBuilder.java index 777204f2..68cfd5fc 100644 --- a/aai-core/src/main/java/org/onap/aai/query/builder/QueryBuilder.java +++ b/aai-core/src/main/java/org/onap/aai/query/builder/QueryBuilder.java @@ -256,6 +256,10 @@ public abstract class QueryBuilder<E> implements Iterator<E> { public abstract QueryBuilder<Vertex> createEdgeTraversal(EdgeType type, Introspector parent, Introspector child) throws AAIException; public abstract QueryBuilder<Vertex> getVerticesByBooleanProperty(String key, Object value); + + public QueryBuilder<Vertex> getVerticesByBooleanProperty(String key, MissingOptionalParameter value) { + return (QueryBuilder<Vertex>) this; + } /** * Creates the private edge traversal. * diff --git a/aai-core/src/main/java/org/onap/aai/restcore/search/GroovyQueryBuilder.java b/aai-core/src/main/java/org/onap/aai/restcore/search/GroovyQueryBuilder.java index 48d4ba8c..f5ec19d5 100644 --- a/aai-core/src/main/java/org/onap/aai/restcore/search/GroovyQueryBuilder.java +++ b/aai-core/src/main/java/org/onap/aai/restcore/search/GroovyQueryBuilder.java @@ -51,7 +51,7 @@ public class GroovyQueryBuilder extends AAIAbstractGroovyShell { @Override public String executeTraversal (TransactionalGraphEngine engine, String traversal, Map<String, Object> params) { QueryBuilder<Vertex> builder = engine.getQueryBuilder(QueryStyle.GREMLIN_TRAVERSAL); - SchemaVersions schemaVersions = SpringContextAware.getBean(SchemaVersions.class); + SchemaVersions schemaVersions = (SchemaVersions) SpringContextAware.getBean("schemaVersions"); Loader loader = SpringContextAware.getBean(LoaderFactory.class).createLoaderForVersion(ModelType.MOXY, schemaVersions.getDefaultVersion()); builder.changeLoader(loader); diff --git a/aai-core/src/main/java/org/onap/aai/serialization/db/DBSerializer.java b/aai-core/src/main/java/org/onap/aai/serialization/db/DBSerializer.java index a23ff1f9..1194dee4 100644 --- a/aai-core/src/main/java/org/onap/aai/serialization/db/DBSerializer.java +++ b/aai-core/src/main/java/org/onap/aai/serialization/db/DBSerializer.java @@ -116,7 +116,7 @@ public class DBSerializer { this.engine = engine; this.sourceOfTruth = sourceOfTruth; this.introspectionType = introspectionType; - this.schemaVersions = SpringContextAware.getBean(SchemaVersions.class); + this.schemaVersions = (SchemaVersions) SpringContextAware.getBean("schemaVersions"); SchemaVersion LATEST = schemaVersions.getDefaultVersion(); this.latestLoader = SpringContextAware.getBean(LoaderFactory.class).createLoaderForVersion(introspectionType, LATEST); this.version = version; diff --git a/aai-core/src/main/java/org/onap/aai/util/GenerateXsd.java b/aai-core/src/main/java/org/onap/aai/util/GenerateXsd.java index 97803653..f44663e0 100644 --- a/aai-core/src/main/java/org/onap/aai/util/GenerateXsd.java +++ b/aai-core/src/main/java/org/onap/aai/util/GenerateXsd.java @@ -104,7 +104,7 @@ public class GenerateXsd { return true; } - SchemaVersions schemaVersions = SpringContextAware.getBean(SchemaVersions.class); + SchemaVersions schemaVersions = (SchemaVersions) SpringContextAware.getBean("schemaVersions"); for (SchemaVersion v : schemaVersions.getVersions()) { if (v.equals(versionToGen)) { return true; diff --git a/aai-core/src/main/java/org/onap/aai/util/genxsd/ConfigTranslatorForDocs.java b/aai-core/src/main/java/org/onap/aai/util/genxsd/ConfigTranslatorForDocs.java index 0ee9cc83..3a42e437 100644 --- a/aai-core/src/main/java/org/onap/aai/util/genxsd/ConfigTranslatorForDocs.java +++ b/aai-core/src/main/java/org/onap/aai/util/genxsd/ConfigTranslatorForDocs.java @@ -23,22 +23,18 @@ package org.onap.aai.util.genxsd; import java.io.File; import java.io.FilenameFilter; import java.util.ArrayList; -import java.util.Arrays; import java.util.Collections; -import java.util.EnumMap; import java.util.List; import java.util.Map; import java.util.TreeMap; - import org.onap.aai.setup.ConfigTranslator; import org.onap.aai.setup.SchemaLocationsBean; import org.onap.aai.setup.SchemaVersion; -import org.onap.aai.setup.SchemaVersions; -import org.springframework.context.annotation.Configuration; +import org.onap.aai.setup.SchemaConfigVersions; public class ConfigTranslatorForDocs extends ConfigTranslator { - public ConfigTranslatorForDocs(SchemaLocationsBean bean, SchemaVersions schemaVersions) { + public ConfigTranslatorForDocs(SchemaLocationsBean bean, SchemaConfigVersions schemaVersions) { super(bean, schemaVersions); } |