diff options
author | Fiete Ostkamp <Fiete.Ostkamp@telekom.de> | 2022-09-19 16:55:36 +0200 |
---|---|---|
committer | Fiete Ostkamp <Fiete.Ostkamp@telekom.de> | 2022-09-19 16:55:36 +0200 |
commit | 7343beeaf260747aef6a6b9c22acd91de67c5ca0 (patch) | |
tree | cc90d98dfb61d5066184b346612bb04caaae64b4 /aai-schema-service/src/main | |
parent | e0ad4f2890f9f933199bc6f1b3f0e988da471aa9 (diff) |
Add instructions to invoke the linter and code formatter plugins to the README and invoke the formatter
Issue-ID: AAI-3526
Signed-off-by: Fiete Ostkamp <Fiete.Ostkamp@telekom.de>
Change-Id: Ibd383994732cea6460153704a1153beb530dc6c3
Diffstat (limited to 'aai-schema-service/src/main')
52 files changed, 968 insertions, 885 deletions
diff --git a/aai-schema-service/src/main/java/org/onap/aai/schemaservice/Profiles.java b/aai-schema-service/src/main/java/org/onap/aai/schemaservice/Profiles.java index 863d6c8..a34db5f 100644 --- a/aai-schema-service/src/main/java/org/onap/aai/schemaservice/Profiles.java +++ b/aai-schema-service/src/main/java/org/onap/aai/schemaservice/Profiles.java @@ -8,7 +8,7 @@ * 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 + * 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, @@ -17,6 +17,7 @@ * limitations under the License. * ============LICENSE_END========================================================= */ + package org.onap.aai.schemaservice; public final class Profiles { diff --git a/aai-schema-service/src/main/java/org/onap/aai/schemaservice/SchemaServiceApp.java b/aai-schema-service/src/main/java/org/onap/aai/schemaservice/SchemaServiceApp.java index 66718dd..291e0a6 100644 --- a/aai-schema-service/src/main/java/org/onap/aai/schemaservice/SchemaServiceApp.java +++ b/aai-schema-service/src/main/java/org/onap/aai/schemaservice/SchemaServiceApp.java @@ -8,7 +8,7 @@ * 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 + * 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, @@ -17,12 +17,20 @@ * limitations under the License. * ============LICENSE_END========================================================= */ + package org.onap.aai.schemaservice; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; +import java.util.Map; +import java.util.UUID; + +import javax.annotation.PostConstruct; +import javax.annotation.PreDestroy; + +import org.onap.aai.aailog.logs.AaiDebugLog; import org.onap.aai.exceptions.AAIException; import org.onap.aai.schemaservice.config.PropertyPasswordConfiguration; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.slf4j.MDC; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.SpringApplication; @@ -33,12 +41,6 @@ import org.springframework.boot.autoconfigure.jdbc.DataSourceTransactionManagerA import org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration; import org.springframework.context.annotation.ComponentScan; import org.springframework.core.env.Environment; -import org.onap.aai.aailog.logs.AaiDebugLog; - -import javax.annotation.PostConstruct; -import javax.annotation.PreDestroy; -import java.util.Map; -import java.util.UUID; import org.springframework.web.context.request.RequestContextListener; @SpringBootApplication @@ -46,15 +48,10 @@ import org.springframework.web.context.request.RequestContextListener; // It only searches beans in the following packages // Any method annotated with @Bean annotation or any class // with @Component, @Configuration, @Service will be picked up -@EnableAutoConfiguration(exclude = { - DataSourceAutoConfiguration.class, - DataSourceTransactionManagerAutoConfiguration.class, - HibernateJpaAutoConfiguration.class -}) -@ComponentScan(basePackages = { - "org.onap.aai.schemaservice", - "org.onap.aai.aaf" -}) +@EnableAutoConfiguration( + exclude = {DataSourceAutoConfiguration.class, + DataSourceTransactionManagerAutoConfiguration.class, HibernateJpaAutoConfiguration.class}) +@ComponentScan(basePackages = {"org.onap.aai.schemaservice", "org.onap.aai.aaf"}) public class SchemaServiceApp { private static final Logger logger = LoggerFactory.getLogger(SchemaServiceApp.class.getName()); @@ -79,11 +76,8 @@ public class SchemaServiceApp { Environment env = app.run(args).getEnvironment(); - logger.debug( - "Application '{}' is running on {}!", - env.getProperty("spring.application.name"), - env.getProperty("server.port") - ); + logger.debug("Application '{}' is running on {}!", + env.getProperty("spring.application.name"), env.getProperty("server.port")); logger.debug("SchemaService MicroService Started"); @@ -125,8 +119,8 @@ public class SchemaServiceApp { // This is only needed for tomcat keeping this as temporary System.setProperty("org.apache.tomcat.util.buf.UDecoder.ALLOW_ENCODED_SLASH", "true"); - - if (env.acceptsProfiles(Profiles.TWO_WAY_SSL) && env.acceptsProfiles(Profiles.ONE_WAY_SSL)) { + if (env.acceptsProfiles(Profiles.TWO_WAY_SSL) + && env.acceptsProfiles(Profiles.ONE_WAY_SSL)) { logger.warn("You have seriously misconfigured your application"); } diff --git a/aai-schema-service/src/main/java/org/onap/aai/schemaservice/config/AAIConfigTranslator.java b/aai-schema-service/src/main/java/org/onap/aai/schemaservice/config/AAIConfigTranslator.java index 38645db..3d1e854 100644 --- a/aai-schema-service/src/main/java/org/onap/aai/schemaservice/config/AAIConfigTranslator.java +++ b/aai-schema-service/src/main/java/org/onap/aai/schemaservice/config/AAIConfigTranslator.java @@ -8,7 +8,7 @@ * 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 + * 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, @@ -17,10 +17,8 @@ * limitations under the License. * ============LICENSE_END========================================================= */ -package org.onap.aai.schemaservice.config; -import org.onap.aai.schemaservice.nodeschema.SchemaVersion; -import org.onap.aai.schemaservice.nodeschema.SchemaVersions; +package org.onap.aai.schemaservice.config; import java.io.File; import java.util.Arrays; @@ -31,6 +29,9 @@ import java.util.function.Supplier; import java.util.stream.Collectors; import java.util.stream.Stream; +import org.onap.aai.schemaservice.nodeschema.SchemaVersion; +import org.onap.aai.schemaservice.nodeschema.SchemaVersions; + /** * <b>AAIConfigTranslator</b> is responsible for looking at the * schema files and edge files based on the available versions @@ -38,81 +39,73 @@ import java.util.stream.Stream; */ public class AAIConfigTranslator extends ConfigTranslator { - private static final String FILESEP = (System.getProperty("file.separator") == null) ? "/" : System.getProperty("file.separator"); + private static final String FILESEP = + (System.getProperty("file.separator") == null) ? "/" : System.getProperty("file.separator"); public AAIConfigTranslator(SchemaLocationsBean bean, SchemaVersions schemaVersions) { - super(bean, schemaVersions); - } - - /* (non-Javadoc) - * @see org.onap.aai.setup.ConfigTranslator#getNodeFiles() - */ - @Override - public Map<SchemaVersion, List<String>> getNodeFiles() { - - Map<SchemaVersion, List<String>> files = new TreeMap<>(); - for (SchemaVersion v : schemaVersions.getVersions()) { - List<String> container = getVersionNodeFiles(v); - files.put(v, container); + super(bean, schemaVersions); } - return files; - } - + /* + * (non-Javadoc) + * + * @see org.onap.aai.setup.ConfigTranslator#getNodeFiles() + */ + @Override + public Map<SchemaVersion, List<String>> getNodeFiles() { + + Map<SchemaVersion, List<String>> files = new TreeMap<>(); + for (SchemaVersion v : schemaVersions.getVersions()) { + List<String> container = getVersionNodeFiles(v); + files.put(v, container); + } + + return files; + } - private List<String> getVersionNodeFiles(SchemaVersion v) { + private List<String> getVersionNodeFiles(SchemaVersion v) { - return getVersionFiles( - bean.getNodeDirectory(), - v, - () -> bean.getNodesInclusionPattern().stream(), - () -> bean.getNodesExclusionPattern().stream() - ); - } + return getVersionFiles(bean.getNodeDirectory(), v, + () -> bean.getNodesInclusionPattern().stream(), + () -> bean.getNodesExclusionPattern().stream()); + } + /* + * (non-Javadoc) + * + * @see org.onap.aai.setup.ConfigTranslator#getEdgeFiles() + */ + @Override + public Map<SchemaVersion, List<String>> getEdgeFiles() { + + Map<SchemaVersion, List<String>> files = new TreeMap<>(); + for (SchemaVersion v : schemaVersions.getVersions()) { + List<String> container = getVersionEdgeFiles(v); + files.put(v, container); + } + + return files; + } - /* (non-Javadoc) - * @see org.onap.aai.setup.ConfigTranslator#getEdgeFiles() - */ - @Override - public Map<SchemaVersion, List<String>> getEdgeFiles() { + private List<String> getVersionEdgeFiles(SchemaVersion v) { - Map<SchemaVersion, List<String>> files = new TreeMap<>(); - for (SchemaVersion v : schemaVersions.getVersions()) { - List<String> container = getVersionEdgeFiles(v); - files.put(v, container); + return getVersionFiles(bean.getEdgeDirectory(), v, + () -> bean.getEdgesInclusionPattern().stream(), + () -> bean.getEdgesExclusionPattern().stream()); } - return files; - } - - private List<String> getVersionEdgeFiles(SchemaVersion v) { - - return getVersionFiles( - bean.getEdgeDirectory(), - v, - () -> bean.getEdgesInclusionPattern().stream(), - () -> bean.getEdgesExclusionPattern().stream() - ); - } - - private List<String> getVersionFiles( - String startDirectory, - SchemaVersion schemaVersion, - Supplier<Stream<String>> inclusionPattern, - Supplier<Stream<String>> exclusionPattern - ){ - - List<String> container; - final String directoryName = startDirectory + FILESEP + schemaVersion.toString() + FILESEP; - - container = Arrays.stream(new File(directoryName).listFiles()) - .map(File::getName) - .filter(name -> inclusionPattern.get().anyMatch(name::matches)) - .map(name -> directoryName + name) - .filter(name -> exclusionPattern.get().noneMatch(name::matches)) - .collect(Collectors.toList()); - - return container; - } + private List<String> getVersionFiles(String startDirectory, SchemaVersion schemaVersion, + Supplier<Stream<String>> inclusionPattern, Supplier<Stream<String>> exclusionPattern) { + + List<String> container; + final String directoryName = startDirectory + FILESEP + schemaVersion.toString() + FILESEP; + + container = Arrays.stream(new File(directoryName).listFiles()).map(File::getName) + .filter(name -> inclusionPattern.get().anyMatch(name::matches)) + .map(name -> directoryName + name) + .filter(name -> exclusionPattern.get().noneMatch(name::matches)) + .collect(Collectors.toList()); + + return container; + } } diff --git a/aai-schema-service/src/main/java/org/onap/aai/schemaservice/config/AuthorizationConfiguration.java b/aai-schema-service/src/main/java/org/onap/aai/schemaservice/config/AuthorizationConfiguration.java index 8069520..971fb2b 100644 --- a/aai-schema-service/src/main/java/org/onap/aai/schemaservice/config/AuthorizationConfiguration.java +++ b/aai-schema-service/src/main/java/org/onap/aai/schemaservice/config/AuthorizationConfiguration.java @@ -8,7 +8,7 @@ * 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 + * 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, @@ -17,6 +17,7 @@ * limitations under the License. * ============LICENSE_END========================================================= */ + package org.onap.aai.schemaservice.config; import org.onap.aai.aaf.auth.AAIAuthCore; @@ -33,7 +34,7 @@ public class AuthorizationConfiguration { private String basePath; @Bean - public AAIAuthCore aaiAuthCore(){ + public AAIAuthCore aaiAuthCore() { return new AAIAuthCore(basePath); } } diff --git a/aai-schema-service/src/main/java/org/onap/aai/schemaservice/config/ConfigTranslator.java b/aai-schema-service/src/main/java/org/onap/aai/schemaservice/config/ConfigTranslator.java index e13367d..b86f9fa 100644 --- a/aai-schema-service/src/main/java/org/onap/aai/schemaservice/config/ConfigTranslator.java +++ b/aai-schema-service/src/main/java/org/onap/aai/schemaservice/config/ConfigTranslator.java @@ -8,7 +8,7 @@ * 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 + * 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, @@ -17,15 +17,16 @@ * limitations under the License. * ============LICENSE_END========================================================= */ + package org.onap.aai.schemaservice.config; +import java.util.List; +import java.util.Map; + import org.onap.aai.schemaservice.nodeschema.SchemaVersion; import org.onap.aai.schemaservice.nodeschema.SchemaVersions; import org.springframework.beans.factory.annotation.Autowired; -import java.util.List; -import java.util.Map; - /** * Converts the contents of the schema config file * (which lists which schema files to be loaded) to @@ -33,34 +34,34 @@ import java.util.Map; * */ public abstract class ConfigTranslator { - protected SchemaLocationsBean bean; - protected SchemaVersions schemaVersions; + protected SchemaLocationsBean bean; + protected SchemaVersions schemaVersions; - @Autowired - public ConfigTranslator(SchemaLocationsBean schemaLocationbean, SchemaVersions schemaVersions) { - this.bean = schemaLocationbean; - this.schemaVersions = schemaVersions; - } + @Autowired + public ConfigTranslator(SchemaLocationsBean schemaLocationbean, SchemaVersions schemaVersions) { + this.bean = schemaLocationbean; + this.schemaVersions = schemaVersions; + } - /** - * Translates the contents of the schema config file - * into the input for the NodeIngestor - * - * @return Map of Version to the list of (string) filenames to be - * ingested for that version - */ - public abstract Map<SchemaVersion, List<String>> getNodeFiles(); + /** + * Translates the contents of the schema config file + * into the input for the NodeIngestor + * + * @return Map of Version to the list of (string) filenames to be + * ingested for that version + */ + public abstract Map<SchemaVersion, List<String>> getNodeFiles(); - /** - * Translates the contents of the schema config file - * into the input for the EdgeIngestor - * - * @return Map of Version to the List of (String) filenames to be - * ingested for that version - */ - public abstract Map<SchemaVersion, List<String>> getEdgeFiles(); + /** + * Translates the contents of the schema config file + * into the input for the EdgeIngestor + * + * @return Map of Version to the List of (String) filenames to be + * ingested for that version + */ + public abstract Map<SchemaVersion, List<String>> getEdgeFiles(); - public SchemaVersions getSchemaVersions(){ - return schemaVersions; - } + public SchemaVersions getSchemaVersions() { + return schemaVersions; + } } diff --git a/aai-schema-service/src/main/java/org/onap/aai/schemaservice/config/ErrorHandler.java b/aai-schema-service/src/main/java/org/onap/aai/schemaservice/config/ErrorHandler.java index a565298..83a1805 100644 --- a/aai-schema-service/src/main/java/org/onap/aai/schemaservice/config/ErrorHandler.java +++ b/aai-schema-service/src/main/java/org/onap/aai/schemaservice/config/ErrorHandler.java @@ -23,11 +23,13 @@ package org.onap.aai.schemaservice.config; import java.io.IOException; import java.util.ArrayList; import java.util.List; + import javax.servlet.FilterChain; import javax.servlet.ServletException; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import javax.ws.rs.core.MediaType; + import org.onap.aai.exceptions.AAIException; import org.onap.aai.logging.ErrorLogHelper; import org.onap.aai.logging.ErrorObject; @@ -61,8 +63,8 @@ public class ErrorHandler extends OncePerRequestFilter { @Override protected void doFilterInternal(HttpServletRequest httpServletRequest, - HttpServletResponse httpServletResponse, - FilterChain filterChain) throws ServletException, IOException { + HttpServletResponse httpServletResponse, FilterChain filterChain) + throws ServletException, IOException { String uri = httpServletRequest.getRequestURI(); @@ -104,8 +106,8 @@ public class ErrorHandler extends OncePerRequestFilter { ArrayList<String> templateVars = new ArrayList<>(); AAIException aaiException = (AAIException) e; - String message = ErrorLogHelper - .getRESTAPIErrorResponse(mediaTypeList, aaiException, templateVars); + String message = ErrorLogHelper.getRESTAPIErrorResponse(mediaTypeList, aaiException, + templateVars); ErrorObject object = null; try { object = ErrorLogHelper.getErrorObject(aaiException.getCode()); @@ -128,8 +130,8 @@ public class ErrorHandler extends OncePerRequestFilter { ArrayList<String> templateVars = new ArrayList<>(); AAIException aaiException = new AAIException("AAI_4000", e); LOGGER.error("Encountered an internal exception {}", LogFormatTools.getStackTop(e)); - String message = ErrorLogHelper - .getRESTAPIErrorResponse(mediaTypeList, aaiException, templateVars); + String message = ErrorLogHelper.getRESTAPIErrorResponse(mediaTypeList, aaiException, + templateVars); ErrorObject object = null; try { object = ErrorLogHelper.getErrorObject(aaiException.getCode()); diff --git a/aai-schema-service/src/main/java/org/onap/aai/schemaservice/config/JettyPasswordDecoder.java b/aai-schema-service/src/main/java/org/onap/aai/schemaservice/config/JettyPasswordDecoder.java index 1b48753..f1576b0 100644 --- a/aai-schema-service/src/main/java/org/onap/aai/schemaservice/config/JettyPasswordDecoder.java +++ b/aai-schema-service/src/main/java/org/onap/aai/schemaservice/config/JettyPasswordDecoder.java @@ -8,7 +8,7 @@ * 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 + * 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, @@ -17,6 +17,7 @@ * limitations under the License. * ============LICENSE_END========================================================= */ + package org.onap.aai.schemaservice.config; import org.eclipse.jetty.util.security.Password; diff --git a/aai-schema-service/src/main/java/org/onap/aai/schemaservice/config/PasswordDecoder.java b/aai-schema-service/src/main/java/org/onap/aai/schemaservice/config/PasswordDecoder.java index f0ae940..9ebd684 100644 --- a/aai-schema-service/src/main/java/org/onap/aai/schemaservice/config/PasswordDecoder.java +++ b/aai-schema-service/src/main/java/org/onap/aai/schemaservice/config/PasswordDecoder.java @@ -8,7 +8,7 @@ * 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 + * 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, @@ -17,6 +17,7 @@ * limitations under the License. * ============LICENSE_END========================================================= */ + package org.onap.aai.schemaservice.config; public interface PasswordDecoder { diff --git a/aai-schema-service/src/main/java/org/onap/aai/schemaservice/config/PropertyPasswordConfiguration.java b/aai-schema-service/src/main/java/org/onap/aai/schemaservice/config/PropertyPasswordConfiguration.java index 2f42309..2292577 100644 --- a/aai-schema-service/src/main/java/org/onap/aai/schemaservice/config/PropertyPasswordConfiguration.java +++ b/aai-schema-service/src/main/java/org/onap/aai/schemaservice/config/PropertyPasswordConfiguration.java @@ -29,6 +29,7 @@ import java.util.Map; import java.util.Properties; import java.util.regex.Matcher; import java.util.regex.Pattern; + import org.apache.commons.io.IOUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -68,9 +69,8 @@ public class PropertyPasswordConfiguration logger.warn("Keystore password is null in AAF Certman password file"); } } catch (IOException e) { - logger.warn( - "Not using AAF Certman password file " + passwordFile.getName() + " e=" + - e.getMessage()); + logger.warn("Not using AAF Certman password file " + passwordFile.getName() + " e=" + + e.getMessage()); } File passphrasesFile = new File(certPath + ".passphrases"); @@ -86,9 +86,8 @@ public class PropertyPasswordConfiguration logger.warn("Truststore password is null in AAF Certman passphrases file"); } } catch (IOException e) { - logger.warn( - "Not using AAF Certman passphrases file " + passphrasesFile.getName() + " e=" + - e.getMessage()); + logger.warn("Not using AAF Certman passphrases file " + passphrasesFile.getName() + + " e=" + e.getMessage()); } } for (PropertySource<?> propertySource : environment.getPropertySources()) { @@ -97,8 +96,8 @@ public class PropertyPasswordConfiguration if (!propertyOverrides.isEmpty()) { PropertySource<?> decodedProperties = new MapPropertySource("decoded " + propertySource.getName(), propertyOverrides); - environment.getPropertySources() - .addBefore(propertySource.getName(), decodedProperties); + environment.getPropertySources().addBefore(propertySource.getName(), + decodedProperties); } } diff --git a/aai-schema-service/src/main/java/org/onap/aai/schemaservice/config/SchemaConfiguration.java b/aai-schema-service/src/main/java/org/onap/aai/schemaservice/config/SchemaConfiguration.java index 28f6bc1..69d214c 100644 --- a/aai-schema-service/src/main/java/org/onap/aai/schemaservice/config/SchemaConfiguration.java +++ b/aai-schema-service/src/main/java/org/onap/aai/schemaservice/config/SchemaConfiguration.java @@ -8,7 +8,7 @@ * 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 + * 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, @@ -17,6 +17,7 @@ * limitations under the License. * ============LICENSE_END========================================================= */ + package org.onap.aai.schemaservice.config; import org.onap.aai.schemaservice.nodeschema.NodeIngestor; @@ -38,7 +39,8 @@ public class SchemaConfiguration { } @Bean(name = "configTranslator") - public ConfigTranslator configTranslator(SchemaLocationsBean schemaLocationsBean, SchemaVersions schemaVersions) { + public ConfigTranslator configTranslator(SchemaLocationsBean schemaLocationsBean, + SchemaVersions schemaVersions) { return new AAIConfigTranslator(schemaLocationsBean, schemaVersions); } @@ -53,12 +55,11 @@ public class SchemaConfiguration { } @Bean - public NodeValidator nodeValidator( - ConfigTranslator configTranslator, + public NodeValidator nodeValidator(ConfigTranslator configTranslator, SchemaErrorStrategy schemaErrorStrategy, - DuplicateNodeDefinitionValidationModule duplicateNodeDefinitionValidationModule - ) { - return new NodeValidator(configTranslator, schemaErrorStrategy, duplicateNodeDefinitionValidationModule); + DuplicateNodeDefinitionValidationModule duplicateNodeDefinitionValidationModule) { + return new NodeValidator(configTranslator, schemaErrorStrategy, + duplicateNodeDefinitionValidationModule); } @Bean diff --git a/aai-schema-service/src/main/java/org/onap/aai/schemaservice/config/SchemaLocationsBean.java b/aai-schema-service/src/main/java/org/onap/aai/schemaservice/config/SchemaLocationsBean.java index 042889b..3582c5e 100644 --- a/aai-schema-service/src/main/java/org/onap/aai/schemaservice/config/SchemaLocationsBean.java +++ b/aai-schema-service/src/main/java/org/onap/aai/schemaservice/config/SchemaLocationsBean.java @@ -8,7 +8,7 @@ * 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 + * 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, @@ -17,122 +17,123 @@ * limitations under the License. * ============LICENSE_END========================================================= */ + package org.onap.aai.schemaservice.config; +import java.util.List; + import org.springframework.beans.factory.annotation.Value; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.PropertySource; import org.springframework.context.support.PropertySourcesPlaceholderConfigurer; -import java.util.List; - @Configuration -@PropertySource(value = "classpath:schema-ingest.properties", ignoreResourceNotFound=true) -@PropertySource(value = "file:${schema.ingest.file}", ignoreResourceNotFound=true) +@PropertySource(value = "classpath:schema-ingest.properties", ignoreResourceNotFound = true) +@PropertySource(value = "file:${schema.ingest.file}", ignoreResourceNotFound = true) public class SchemaLocationsBean { - /* - * Per Spring documentation, the last PropertySource that works will - * be applied. Here, schema.ingest.file will be an environment variable - * set on install that tells Spring where to look for the schema - * ingest properties file (and the actual filename), but the former - * PropertySource gives the default of looking on the classpath for - * schema-ingest.properties in case that second one doesn't work. - * - * The schema-ingest.properties file (or its equivalent if you choose - * to name it otherwise) must contain the entries the below @Value - * annotations are looking for. - */ - - @Value("${schema.configuration.location}") - private String schemaConfigLoc; - - @Value("${schema.nodes.location}") - private String nodeDirectory; - - @Value("${schema.edges.location}") - private String edgeDirectory; - - @Value("${schema.nodes.inclusion.list:}#{T(java.util.Arrays).asList(\".*oxm(.*).xml\")}") - private List<String> nodesInclusionPattern; - - @Value("${schema.nodes.exclusion.list:}#{T(java.util.Collections).emptyList()}") - private List<String> nodesExclusionPattern; - - @Value("${schema.edges.inclusion.list:}#{T(java.util.Arrays).asList(\"DbEdgeRules_.*.json\")}") - private List<String> edgesInclusionPattern; - - @Value("${schema.edges.exclusion.list:}#{T(java.util.Collections).emptyList()}") - private List<String> edgesExclusionPattern; - - /** - * @return the file name/location with the list of schema files to be ingested - */ - public String getSchemaConfigLocation() { - return schemaConfigLoc; - } - - /** - * Sets the name/location of the file with the list of schema files to ingest - * - * @param schemaConfigLoc - the file name/location - */ - public void setSchemaConfigLocation(String schemaConfigLoc) { - this.schemaConfigLoc = schemaConfigLoc; - } - - /** - * @return the location of the OXM files - */ - public String getNodeDirectory() { - return nodeDirectory; - } - - /** - * Sets the location of the OXM files - * - * @param nodeDirectory - the location of the OXM files - */ - public void setNodeDirectory(String nodeDirectory) { - this.nodeDirectory = nodeDirectory; - } - - /** - * @return the location of the edge rule json files - */ - public String getEdgeDirectory() { - return edgeDirectory; - } - - /** - * Sets the location of the edge rule json files - * - * @param edgeDirectory - the location of the edge rule files - */ - public void setEdgeDirectory(String edgeDirectory) { - this.edgeDirectory = edgeDirectory; - } - - public List<String> getNodesExclusionPattern(){ - return this.nodesExclusionPattern; - } - - public List<String> getNodesInclusionPattern(){ - return this.nodesInclusionPattern; - } - - public List<String> getEdgesExclusionPattern(){ - return this.edgesExclusionPattern; - } - - public List<String> getEdgesInclusionPattern(){ - return this.edgesInclusionPattern; - } - - //this allows the code to actually read the value from the config file - //without this those strings get set to literally "${edgeDir}" etc - @Bean - public static PropertySourcesPlaceholderConfigurer propertySourcesPlaceholderConfigurer() { - return new PropertySourcesPlaceholderConfigurer(); - } + /* + * Per Spring documentation, the last PropertySource that works will + * be applied. Here, schema.ingest.file will be an environment variable + * set on install that tells Spring where to look for the schema + * ingest properties file (and the actual filename), but the former + * PropertySource gives the default of looking on the classpath for + * schema-ingest.properties in case that second one doesn't work. + * + * The schema-ingest.properties file (or its equivalent if you choose + * to name it otherwise) must contain the entries the below @Value + * annotations are looking for. + */ + + @Value("${schema.configuration.location}") + private String schemaConfigLoc; + + @Value("${schema.nodes.location}") + private String nodeDirectory; + + @Value("${schema.edges.location}") + private String edgeDirectory; + + @Value("${schema.nodes.inclusion.list:}#{T(java.util.Arrays).asList(\".*oxm(.*).xml\")}") + private List<String> nodesInclusionPattern; + + @Value("${schema.nodes.exclusion.list:}#{T(java.util.Collections).emptyList()}") + private List<String> nodesExclusionPattern; + + @Value("${schema.edges.inclusion.list:}#{T(java.util.Arrays).asList(\"DbEdgeRules_.*.json\")}") + private List<String> edgesInclusionPattern; + + @Value("${schema.edges.exclusion.list:}#{T(java.util.Collections).emptyList()}") + private List<String> edgesExclusionPattern; + + /** + * @return the file name/location with the list of schema files to be ingested + */ + public String getSchemaConfigLocation() { + return schemaConfigLoc; + } + + /** + * Sets the name/location of the file with the list of schema files to ingest + * + * @param schemaConfigLoc - the file name/location + */ + public void setSchemaConfigLocation(String schemaConfigLoc) { + this.schemaConfigLoc = schemaConfigLoc; + } + + /** + * @return the location of the OXM files + */ + public String getNodeDirectory() { + return nodeDirectory; + } + + /** + * Sets the location of the OXM files + * + * @param nodeDirectory - the location of the OXM files + */ + public void setNodeDirectory(String nodeDirectory) { + this.nodeDirectory = nodeDirectory; + } + + /** + * @return the location of the edge rule json files + */ + public String getEdgeDirectory() { + return edgeDirectory; + } + + /** + * Sets the location of the edge rule json files + * + * @param edgeDirectory - the location of the edge rule files + */ + public void setEdgeDirectory(String edgeDirectory) { + this.edgeDirectory = edgeDirectory; + } + + public List<String> getNodesExclusionPattern() { + return this.nodesExclusionPattern; + } + + public List<String> getNodesInclusionPattern() { + return this.nodesInclusionPattern; + } + + public List<String> getEdgesExclusionPattern() { + return this.edgesExclusionPattern; + } + + public List<String> getEdgesInclusionPattern() { + return this.edgesInclusionPattern; + } + + // this allows the code to actually read the value from the config file + // without this those strings get set to literally "${edgeDir}" etc + @Bean + public static PropertySourcesPlaceholderConfigurer propertySourcesPlaceholderConfigurer() { + return new PropertySourcesPlaceholderConfigurer(); + } } diff --git a/aai-schema-service/src/main/java/org/onap/aai/schemaservice/edges/EdgeResource.java b/aai-schema-service/src/main/java/org/onap/aai/schemaservice/edges/EdgeResource.java index cb045ea..bae48c3 100644 --- a/aai-schema-service/src/main/java/org/onap/aai/schemaservice/edges/EdgeResource.java +++ b/aai-schema-service/src/main/java/org/onap/aai/schemaservice/edges/EdgeResource.java @@ -8,7 +8,7 @@ * 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 + * 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, @@ -17,18 +17,13 @@ * limitations under the License. * ============LICENSE_END========================================================= */ + package org.onap.aai.schemaservice.edges; import com.google.gson.Gson; import com.google.gson.GsonBuilder; -import org.onap.aai.exceptions.AAIException; -import org.onap.aai.restcore.HttpMethod; -import org.onap.aai.restcore.RESTAPI; -import org.onap.aai.schemaservice.nodeschema.SchemaVersion; -import org.onap.aai.schemaservice.nodeschema.SchemaVersions; -import org.onap.aai.schemaservice.nodeschema.validation.AAISchemaValidationException; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.util.StringUtils; + +import java.util.Optional; import javax.ws.rs.GET; import javax.ws.rs.Path; @@ -38,7 +33,15 @@ import javax.ws.rs.core.Context; import javax.ws.rs.core.HttpHeaders; import javax.ws.rs.core.Response; import javax.ws.rs.core.UriInfo; -import java.util.Optional; + +import org.onap.aai.exceptions.AAIException; +import org.onap.aai.restcore.HttpMethod; +import org.onap.aai.restcore.RESTAPI; +import org.onap.aai.schemaservice.nodeschema.SchemaVersion; +import org.onap.aai.schemaservice.nodeschema.SchemaVersions; +import org.onap.aai.schemaservice.nodeschema.validation.AAISchemaValidationException; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.util.StringUtils; @Path("/v1") public class EdgeResource extends RESTAPI { @@ -48,46 +51,46 @@ public class EdgeResource extends RESTAPI { private final Gson gson; @Autowired - public EdgeResource(EdgeService edgeService, SchemaVersions schemaVersions){ - this.edgeService = edgeService; + public EdgeResource(EdgeService edgeService, SchemaVersions schemaVersions) { + this.edgeService = edgeService; this.schemaVersions = schemaVersions; gson = new GsonBuilder().create(); } @GET @Path("/edgerules") - @Produces({ "application/json"}) + @Produces({"application/json"}) public Response retrieveSchema(@QueryParam("version") String version, - @Context HttpHeaders headers, - @Context UriInfo info) - { + @Context HttpHeaders headers, @Context UriInfo info) { Response response = null; try { - if(StringUtils.isEmpty(version)){ + if (StringUtils.isEmpty(version)) { throw new AAIException("AAI_3050"); } SchemaVersion schemaVersion = new SchemaVersion(version); - if(!schemaVersions.getVersions().contains(schemaVersion)){ + if (!schemaVersions.getVersions().contains(schemaVersion)) { throw new AAIException("AAI_3018", version); } Optional<EdgeRules> edgeRulesOptional = edgeService.findRules(version); - if(!edgeRulesOptional.isPresent()){ + if (!edgeRulesOptional.isPresent()) { throw new AAIException("AAI_3001"); } response = Response.ok(gson.toJson(edgeRulesOptional.get())).build(); - } catch(AAIException ex){ + } catch (AAIException ex) { response = consumerExceptionResponseGenerator(headers, info, HttpMethod.GET, ex); - } catch(AAISchemaValidationException ex){ - response = consumerExceptionResponseGenerator(headers, info, HttpMethod.GET, new AAIException("AAI_3051", version)); - } catch(Exception ex){ - response = consumerExceptionResponseGenerator(headers, info, HttpMethod.GET, new AAIException("AAI_4000")); + } catch (AAISchemaValidationException ex) { + response = consumerExceptionResponseGenerator(headers, info, HttpMethod.GET, + new AAIException("AAI_3051", version)); + } catch (Exception ex) { + response = consumerExceptionResponseGenerator(headers, info, HttpMethod.GET, + new AAIException("AAI_4000")); } return response; diff --git a/aai-schema-service/src/main/java/org/onap/aai/schemaservice/edges/EdgeRule.java b/aai-schema-service/src/main/java/org/onap/aai/schemaservice/edges/EdgeRule.java index ab0f311..e7eb15b 100644 --- a/aai-schema-service/src/main/java/org/onap/aai/schemaservice/edges/EdgeRule.java +++ b/aai-schema-service/src/main/java/org/onap/aai/schemaservice/edges/EdgeRule.java @@ -8,7 +8,7 @@ * 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 + * 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, @@ -17,6 +17,7 @@ * limitations under the License. * ============LICENSE_END========================================================= */ + package org.onap.aai.schemaservice.edges; import com.google.gson.annotations.SerializedName; @@ -36,19 +37,11 @@ public class EdgeRule { @Override public String toString() { - return "EdgeRule{" + - "from='" + from + '\'' + - ", to='" + to + '\'' + - ", label='" + label + '\'' + - ", direction='" + direction + '\'' + - ", multiplicity='" + multiplicity + '\'' + - ", description='" + description + '\'' + - ", containsOtherV='" + containsOtherV + '\'' + - ", deleteOtherV='" + deleteOtherV + '\'' + - ", preventDelete='" + preventDelete + '\'' + - ", privateEdge=" + privateEdge + - ", isDefaultEdge=" + defaultEdge + - '}'; + return "EdgeRule{" + "from='" + from + '\'' + ", to='" + to + '\'' + ", label='" + label + + '\'' + ", direction='" + direction + '\'' + ", multiplicity='" + multiplicity + '\'' + + ", description='" + description + '\'' + ", containsOtherV='" + containsOtherV + '\'' + + ", deleteOtherV='" + deleteOtherV + '\'' + ", preventDelete='" + preventDelete + '\'' + + ", privateEdge=" + privateEdge + ", isDefaultEdge=" + defaultEdge + '}'; } @SerializedName("delete-other-v") diff --git a/aai-schema-service/src/main/java/org/onap/aai/schemaservice/edges/EdgeRules.java b/aai-schema-service/src/main/java/org/onap/aai/schemaservice/edges/EdgeRules.java index ec68d30..bad43d3 100644 --- a/aai-schema-service/src/main/java/org/onap/aai/schemaservice/edges/EdgeRules.java +++ b/aai-schema-service/src/main/java/org/onap/aai/schemaservice/edges/EdgeRules.java @@ -8,7 +8,7 @@ * 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 + * 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, @@ -17,6 +17,7 @@ * limitations under the License. * ============LICENSE_END========================================================= */ + package org.onap.aai.schemaservice.edges; import com.google.gson.annotations.SerializedName; @@ -29,7 +30,7 @@ public class EdgeRules { @SerializedName("rules") private List<EdgeRule> rules; - public EdgeRules(List<EdgeRule> rules){ + public EdgeRules(List<EdgeRule> rules) { this.rules = rules; } @@ -64,9 +65,7 @@ public class EdgeRules { @Override public String toString() { - return "EdgeRules{" + - "rules=" + rules + - '}'; + return "EdgeRules{" + "rules=" + rules + '}'; } } diff --git a/aai-schema-service/src/main/java/org/onap/aai/schemaservice/edges/EdgeService.java b/aai-schema-service/src/main/java/org/onap/aai/schemaservice/edges/EdgeService.java index a4eba45..0b2cc75 100644 --- a/aai-schema-service/src/main/java/org/onap/aai/schemaservice/edges/EdgeService.java +++ b/aai-schema-service/src/main/java/org/onap/aai/schemaservice/edges/EdgeService.java @@ -8,7 +8,7 @@ * 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 + * 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, @@ -17,21 +17,14 @@ * limitations under the License. * ============LICENSE_END========================================================= */ + package org.onap.aai.schemaservice.edges; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import com.google.gson.FieldNamingPolicy; import com.google.gson.Gson; import com.google.gson.GsonBuilder; import com.google.gson.stream.JsonReader; -import org.onap.aai.schemaservice.nodeschema.SchemaVersion; -import org.onap.aai.schemaservice.nodeschema.SchemaVersions; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.beans.factory.annotation.Value; -import org.springframework.stereotype.Service; -import javax.annotation.PostConstruct; import java.io.File; import java.io.FileReader; import java.io.IOException; @@ -42,6 +35,16 @@ import java.util.*; import java.util.stream.Collectors; import java.util.stream.Stream; +import javax.annotation.PostConstruct; + +import org.onap.aai.schemaservice.nodeschema.SchemaVersion; +import org.onap.aai.schemaservice.nodeschema.SchemaVersions; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.stereotype.Service; + @Service public class EdgeService { @@ -56,39 +59,42 @@ public class EdgeService { @Autowired public EdgeService(SchemaVersions schemaVersions, - @Value("${schema.edges.location}") String edgesLocation){ + @Value("${schema.edges.location}") String edgesLocation) { this.schemaVersions = schemaVersions; - this.edgesLocation = edgesLocation; - this.rulesMap = new HashMap<>(); + this.edgesLocation = edgesLocation; + this.rulesMap = new HashMap<>(); } @PostConstruct public void initialize() throws IOException { - Gson gson = new GsonBuilder().setFieldNamingPolicy(FieldNamingPolicy.LOWER_CASE_WITH_DASHES).create(); + Gson gson = new GsonBuilder().setFieldNamingPolicy(FieldNamingPolicy.LOWER_CASE_WITH_DASHES) + .create(); for (SchemaVersion schemaVersion : schemaVersions.getVersions()) { String edgeRuleVersionPath = edgesLocation + FILESEP + schemaVersion.toString(); - LOGGER.debug("For the version {} looking for edge rules in folder {}", schemaVersion, edgeRuleVersionPath); + LOGGER.debug("For the version {} looking for edge rules in folder {}", schemaVersion, + edgeRuleVersionPath); - try (Stream<Path> pathStream = Files.walk(Paths.get(edgeRuleVersionPath))){ + try (Stream<Path> pathStream = Files.walk(Paths.get(edgeRuleVersionPath))) { - List<Path> jsonFiles = pathStream - .filter((path) -> path.toString().endsWith(".json")) - .collect(Collectors.toList()); + List<Path> jsonFiles = + pathStream.filter((path) -> path.toString().endsWith(".json")) + .collect(Collectors.toList()); - if(jsonFiles.isEmpty()){ - LOGGER.error("Unable to find any edge rules json files in folder {}", edgeRuleVersionPath); + if (jsonFiles.isEmpty()) { + LOGGER.error("Unable to find any edge rules json files in folder {}", + edgeRuleVersionPath); } else { LOGGER.trace("Found the following edge rules {}", jsonFiles); } List<EdgeRule> rules = new ArrayList<>(); - for(Path path : jsonFiles){ + for (Path path : jsonFiles) { File edgeRuleFile = path.toFile(); - try (JsonReader jsonReader = new JsonReader(new FileReader(edgeRuleFile))){ + try (JsonReader jsonReader = new JsonReader(new FileReader(edgeRuleFile))) { EdgeRules edgeRules = gson.fromJson(jsonReader, EdgeRules.class); rules.addAll(edgeRules.getRules()); } @@ -100,7 +106,7 @@ public class EdgeService { } - public Optional<EdgeRules> findRules(String version){ + public Optional<EdgeRules> findRules(String version) { return Optional.ofNullable(rulesMap.get(version)); } } diff --git a/aai-schema-service/src/main/java/org/onap/aai/schemaservice/healthcheck/EchoResource.java b/aai-schema-service/src/main/java/org/onap/aai/schemaservice/healthcheck/EchoResource.java index 2a98876..47552b1 100644 --- a/aai-schema-service/src/main/java/org/onap/aai/schemaservice/healthcheck/EchoResource.java +++ b/aai-schema-service/src/main/java/org/onap/aai/schemaservice/healthcheck/EchoResource.java @@ -8,7 +8,7 @@ * 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 + * 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, @@ -17,11 +17,11 @@ * limitations under the License. * ============LICENSE_END========================================================= */ + package org.onap.aai.schemaservice.healthcheck; -import org.onap.aai.exceptions.AAIException; -import org.onap.aai.logging.ErrorLogHelper; -import org.onap.aai.restcore.RESTAPI; +import java.util.ArrayList; +import java.util.HashMap; import javax.servlet.http.HttpServletRequest; import javax.ws.rs.GET; @@ -29,8 +29,10 @@ import javax.ws.rs.Path; import javax.ws.rs.Produces; import javax.ws.rs.core.*; import javax.ws.rs.core.Response.Status; -import java.util.ArrayList; -import java.util.HashMap; + +import org.onap.aai.exceptions.AAIException; +import org.onap.aai.logging.ErrorLogHelper; +import org.onap.aai.restcore.RESTAPI; /** * The Class EchoResponse. @@ -40,7 +42,8 @@ public class EchoResource extends RESTAPI { /** * Simple health-check API that echos back the X-FromAppId and X-TransactionId to clients. - * If there is a query string, a transaction gets logged into hbase, proving the application is connected to the data store. + * If there is a query string, a transaction gets logged into hbase, proving the application is + * connected to the data store. * If there is no query string, no transaction logging is done to hbase. * * @param headers the headers @@ -48,9 +51,10 @@ public class EchoResource extends RESTAPI { * @return the response */ @GET - @Produces( { MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON }) + @Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON}) @Path("/echo") - public Response echoResult(@Context HttpHeaders headers, @Context HttpServletRequest req, @Context UriInfo uriInfo) { + public Response echoResult(@Context HttpHeaders headers, @Context HttpServletRequest req, + @Context UriInfo uriInfo) { Response response = null; AAIException ex = null; @@ -58,20 +62,21 @@ public class EchoResource extends RESTAPI { String transId = null; try { - fromAppId = getFromAppId(headers ); + fromAppId = getFromAppId(headers); transId = getTransId(headers); } catch (AAIException e) { ArrayList<String> templateVars = new ArrayList<String>(); templateVars.add("Headers missing"); return Response - .status(e.getErrorObject().getHTTPResponseCode()) - .entity(ErrorLogHelper.getRESTAPIErrorResponse(headers.getAcceptableMediaTypes(), e, templateVars)) + .status(e.getErrorObject().getHTTPResponseCode()).entity(ErrorLogHelper + .getRESTAPIErrorResponse(headers.getAcceptableMediaTypes(), e, templateVars)) .build(); } try { - HashMap<AAIException, ArrayList<String>> exceptionList = new HashMap<AAIException, ArrayList<String>>(); + HashMap<AAIException, ArrayList<String>> exceptionList = + new HashMap<AAIException, ArrayList<String>>(); ArrayList<String> templateVars = new ArrayList<String>(); templateVars.add(fromAppId); @@ -79,22 +84,21 @@ public class EchoResource extends RESTAPI { exceptionList.put(new AAIException("AAI_0002", "OK"), templateVars); - response = Response.status(Status.OK) - .entity(ErrorLogHelper.getRESTAPIInfoResponse( - headers.getAcceptableMediaTypes(), exceptionList)) + response = Response + .status(Status.OK).entity(ErrorLogHelper + .getRESTAPIInfoResponse(headers.getAcceptableMediaTypes(), exceptionList)) .build(); } catch (Exception e) { ex = new AAIException("AAI_4000", e); ArrayList<String> templateVars = new ArrayList<String>(); templateVars.add(Action.GET.name()); - templateVars.add(fromAppId +" "+transId); + templateVars.add(fromAppId + " " + transId); response = Response - .status(Status.INTERNAL_SERVER_ERROR) - .entity(ErrorLogHelper.getRESTAPIErrorResponse( - headers.getAcceptableMediaTypes(), ex, - templateVars)).build(); + .status(Status.INTERNAL_SERVER_ERROR).entity(ErrorLogHelper + .getRESTAPIErrorResponse(headers.getAcceptableMediaTypes(), ex, templateVars)) + .build(); } finally { if (ex != null) { diff --git a/aai-schema-service/src/main/java/org/onap/aai/schemaservice/interceptors/AAIContainerFilter.java b/aai-schema-service/src/main/java/org/onap/aai/schemaservice/interceptors/AAIContainerFilter.java index e5588b6..cb04bc4 100644 --- a/aai-schema-service/src/main/java/org/onap/aai/schemaservice/interceptors/AAIContainerFilter.java +++ b/aai-schema-service/src/main/java/org/onap/aai/schemaservice/interceptors/AAIContainerFilter.java @@ -8,7 +8,7 @@ * 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 + * 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, @@ -17,12 +17,13 @@ * limitations under the License. * ============LICENSE_END========================================================= */ -package org.onap.aai.schemaservice.interceptors; -import org.onap.aai.util.FormatDate; +package org.onap.aai.schemaservice.interceptors; import java.util.UUID; +import org.onap.aai.util.FormatDate; + public abstract class AAIContainerFilter { protected String genDate() { diff --git a/aai-schema-service/src/main/java/org/onap/aai/schemaservice/interceptors/AAIHeaderProperties.java b/aai-schema-service/src/main/java/org/onap/aai/schemaservice/interceptors/AAIHeaderProperties.java index 8f08d3f..467475b 100644 --- a/aai-schema-service/src/main/java/org/onap/aai/schemaservice/interceptors/AAIHeaderProperties.java +++ b/aai-schema-service/src/main/java/org/onap/aai/schemaservice/interceptors/AAIHeaderProperties.java @@ -8,7 +8,7 @@ * 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 + * 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, @@ -17,6 +17,7 @@ * limitations under the License. * ============LICENSE_END========================================================= */ + package org.onap.aai.schemaservice.interceptors; public final class AAIHeaderProperties { diff --git a/aai-schema-service/src/main/java/org/onap/aai/schemaservice/interceptors/package-info.java b/aai-schema-service/src/main/java/org/onap/aai/schemaservice/interceptors/package-info.java index 6cf55f0..4929cc0 100644 --- a/aai-schema-service/src/main/java/org/onap/aai/schemaservice/interceptors/package-info.java +++ b/aai-schema-service/src/main/java/org/onap/aai/schemaservice/interceptors/package-info.java @@ -8,7 +8,7 @@ * 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 + * 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, @@ -26,11 +26,12 @@ * * <pre> * <code> - * @Priority(AAIRequestFilterPriority.YOUR_PRIORITY) + * @Priority(AAIRequestFilterPriority.YOUR_PRIORITY) * public class YourInterceptor extends AAIContainerFilter implements ContainerRequestFilter { * * } * </code> * </pre> */ + package org.onap.aai.schemaservice.interceptors; diff --git a/aai-schema-service/src/main/java/org/onap/aai/schemaservice/interceptors/post/AAIResponseFilterPriority.java b/aai-schema-service/src/main/java/org/onap/aai/schemaservice/interceptors/post/AAIResponseFilterPriority.java index fceadeb..b4144bb 100644 --- a/aai-schema-service/src/main/java/org/onap/aai/schemaservice/interceptors/post/AAIResponseFilterPriority.java +++ b/aai-schema-service/src/main/java/org/onap/aai/schemaservice/interceptors/post/AAIResponseFilterPriority.java @@ -8,7 +8,7 @@ * 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 + * 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, @@ -17,6 +17,7 @@ * limitations under the License. * ============LICENSE_END========================================================= */ + package org.onap.aai.schemaservice.interceptors.post; /** diff --git a/aai-schema-service/src/main/java/org/onap/aai/schemaservice/interceptors/post/InvalidResponseStatus.java b/aai-schema-service/src/main/java/org/onap/aai/schemaservice/interceptors/post/InvalidResponseStatus.java index d987171..5f80b2b 100644 --- a/aai-schema-service/src/main/java/org/onap/aai/schemaservice/interceptors/post/InvalidResponseStatus.java +++ b/aai-schema-service/src/main/java/org/onap/aai/schemaservice/interceptors/post/InvalidResponseStatus.java @@ -8,7 +8,7 @@ * 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 + * 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, @@ -17,11 +17,12 @@ * limitations under the License. * ============LICENSE_END========================================================= */ + package org.onap.aai.schemaservice.interceptors.post; -import org.onap.aai.exceptions.AAIException; -import org.onap.aai.logging.ErrorLogHelper; -import org.onap.aai.schemaservice.interceptors.AAIContainerFilter; +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; import javax.annotation.Priority; import javax.print.attribute.standard.Media; @@ -30,16 +31,17 @@ import javax.ws.rs.container.ContainerResponseContext; import javax.ws.rs.container.ContainerResponseFilter; import javax.ws.rs.core.MediaType; import javax.ws.rs.core.UriInfo; -import java.io.IOException; -import java.util.ArrayList; -import java.util.List; + +import org.onap.aai.exceptions.AAIException; +import org.onap.aai.logging.ErrorLogHelper; +import org.onap.aai.schemaservice.interceptors.AAIContainerFilter; @Priority(AAIResponseFilterPriority.INVALID_RESPONSE_STATUS) public class InvalidResponseStatus extends AAIContainerFilter implements ContainerResponseFilter { @Override - public void filter(ContainerRequestContext requestContext, ContainerResponseContext responseContext) - throws IOException { + public void filter(ContainerRequestContext requestContext, + ContainerResponseContext responseContext) throws IOException { String contentType = responseContext.getHeaderString("Content-Type"); ArrayList<String> templateVars = new ArrayList<>(); diff --git a/aai-schema-service/src/main/java/org/onap/aai/schemaservice/interceptors/post/ResponseHeaderManipulation.java b/aai-schema-service/src/main/java/org/onap/aai/schemaservice/interceptors/post/ResponseHeaderManipulation.java index 76d14b6..170ac40 100644 --- a/aai-schema-service/src/main/java/org/onap/aai/schemaservice/interceptors/post/ResponseHeaderManipulation.java +++ b/aai-schema-service/src/main/java/org/onap/aai/schemaservice/interceptors/post/ResponseHeaderManipulation.java @@ -21,11 +21,13 @@ package org.onap.aai.schemaservice.interceptors.post; import java.io.IOException; + import javax.annotation.Priority; import javax.ws.rs.container.ContainerRequestContext; import javax.ws.rs.container.ContainerResponseContext; import javax.ws.rs.container.ContainerResponseFilter; import javax.ws.rs.core.MediaType; + import org.onap.aai.schemaservice.interceptors.AAIContainerFilter; import org.onap.aai.schemaservice.interceptors.AAIHeaderProperties; @@ -38,15 +40,14 @@ public class ResponseHeaderManipulation extends AAIContainerFilter @Override public void filter(ContainerRequestContext requestContext, - ContainerResponseContext responseContext) - throws IOException { + ContainerResponseContext responseContext) throws IOException { updateResponseHeaders(requestContext, responseContext); } private void updateResponseHeaders(ContainerRequestContext requestContext, - ContainerResponseContext responseContext) { + ContainerResponseContext responseContext) { responseContext.getHeaders().add(AAIHeaderProperties.AAI_TX_ID, requestContext.getProperty(AAIHeaderProperties.AAI_TX_ID)); diff --git a/aai-schema-service/src/main/java/org/onap/aai/schemaservice/interceptors/post/ResponseTransactionLogging.java b/aai-schema-service/src/main/java/org/onap/aai/schemaservice/interceptors/post/ResponseTransactionLogging.java index 11f3737..f89440a 100644 --- a/aai-schema-service/src/main/java/org/onap/aai/schemaservice/interceptors/post/ResponseTransactionLogging.java +++ b/aai-schema-service/src/main/java/org/onap/aai/schemaservice/interceptors/post/ResponseTransactionLogging.java @@ -8,7 +8,7 @@ * 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 + * 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, @@ -17,18 +17,22 @@ * limitations under the License. * ============LICENSE_END========================================================= */ + package org.onap.aai.schemaservice.interceptors.post; import com.google.gson.JsonObject; + import java.io.IOException; import java.util.Objects; import java.util.Optional; + import javax.annotation.Priority; import javax.servlet.http.HttpServletResponse; import javax.ws.rs.HttpMethod; import javax.ws.rs.container.ContainerRequestContext; import javax.ws.rs.container.ContainerResponseContext; import javax.ws.rs.container.ContainerResponseFilter; + import org.onap.aai.logging.ErrorLogHelper; import org.onap.aai.schemaservice.interceptors.AAIContainerFilter; import org.onap.aai.schemaservice.interceptors.AAIHeaderProperties; @@ -40,39 +44,42 @@ import org.springframework.web.context.request.RequestContextHolder; import org.springframework.web.context.request.ServletRequestAttributes; @Priority(AAIResponseFilterPriority.RESPONSE_TRANS_LOGGING) -public class ResponseTransactionLogging extends AAIContainerFilter implements ContainerResponseFilter { +public class ResponseTransactionLogging extends AAIContainerFilter + implements ContainerResponseFilter { - private static final Logger TRANSACTION_LOGGER = LoggerFactory.getLogger(ResponseTransactionLogging.class); + private static final Logger TRANSACTION_LOGGER = + LoggerFactory.getLogger(ResponseTransactionLogging.class); @Override - public void filter(ContainerRequestContext requestContext, ContainerResponseContext responseContext) - throws IOException { + public void filter(ContainerRequestContext requestContext, + ContainerResponseContext responseContext) throws IOException { this.transLogging(requestContext, responseContext); } - private void transLogging(ContainerRequestContext requestContext, ContainerResponseContext responseContext) { + private void transLogging(ContainerRequestContext requestContext, + ContainerResponseContext responseContext) { String logValue = AAIConfig.get("aai.transaction.logging", "true"); - String isGetTransactionResponseLoggingEnabled = AAIConfig.get("aai.transaction.logging.get", "false"); + String isGetTransactionResponseLoggingEnabled = + AAIConfig.get("aai.transaction.logging.get", "false"); String httpMethod = requestContext.getMethod(); - if(Boolean.parseBoolean(logValue)){ + if (Boolean.parseBoolean(logValue)) { String transId = requestContext.getHeaderString(AAIHeaderProperties.TRANSACTION_ID); String fromAppId = requestContext.getHeaderString(AAIHeaderProperties.FROM_APP_ID); String fullUri = requestContext.getUriInfo().getRequestUri().toString(); - String requestTs = (String) requestContext.getProperty(AAIHeaderProperties.AAI_REQUEST_TS); - + String requestTs = + (String) requestContext.getProperty(AAIHeaderProperties.AAI_REQUEST_TS); String status = Integer.toString(responseContext.getStatus()); String request = (String) requestContext.getProperty(AAIHeaderProperties.AAI_REQUEST); String response = this.getResponseString(responseContext); - JsonObject logEntry = new JsonObject(); logEntry.addProperty("transactionId", transId); logEntry.addProperty("status", status); @@ -82,7 +89,8 @@ public class ResponseTransactionLogging extends AAIContainerFilter implements Co logEntry.addProperty("resourceId", fullUri); logEntry.addProperty("resourceType", httpMethod); logEntry.addProperty("rqstBuf", Objects.toString(request, "")); - if(Boolean.parseBoolean(isGetTransactionResponseLoggingEnabled) || (!HttpMethod.GET.equals(httpMethod))) { + if (Boolean.parseBoolean(isGetTransactionResponseLoggingEnabled) + || (!HttpMethod.GET.equals(httpMethod))) { logEntry.addProperty("respBuf", Objects.toString(response, "")); } @@ -97,7 +105,8 @@ public class ResponseTransactionLogging extends AAIContainerFilter implements Co private String getHttpServletResponseContentType() { final RequestAttributes requestAttributes = RequestContextHolder.getRequestAttributes(); if (requestAttributes != null) { - HttpServletResponse response = ((ServletRequestAttributes) requestAttributes).getResponse(); + HttpServletResponse response = + ((ServletRequestAttributes) requestAttributes).getResponse(); return response == null ? null : response.getContentType(); } return null; diff --git a/aai-schema-service/src/main/java/org/onap/aai/schemaservice/interceptors/pre/AAIRequestFilterPriority.java b/aai-schema-service/src/main/java/org/onap/aai/schemaservice/interceptors/pre/AAIRequestFilterPriority.java index 0ecc0cf..423ff61 100644 --- a/aai-schema-service/src/main/java/org/onap/aai/schemaservice/interceptors/pre/AAIRequestFilterPriority.java +++ b/aai-schema-service/src/main/java/org/onap/aai/schemaservice/interceptors/pre/AAIRequestFilterPriority.java @@ -8,7 +8,7 @@ * 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 + * 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, @@ -17,6 +17,7 @@ * limitations under the License. * ============LICENSE_END========================================================= */ + package org.onap.aai.schemaservice.interceptors.pre; public final class AAIRequestFilterPriority { diff --git a/aai-schema-service/src/main/java/org/onap/aai/schemaservice/interceptors/pre/HeaderValidation.java b/aai-schema-service/src/main/java/org/onap/aai/schemaservice/interceptors/pre/HeaderValidation.java index 66be48e..3b22ff0 100644 --- a/aai-schema-service/src/main/java/org/onap/aai/schemaservice/interceptors/pre/HeaderValidation.java +++ b/aai-schema-service/src/main/java/org/onap/aai/schemaservice/interceptors/pre/HeaderValidation.java @@ -8,7 +8,7 @@ * 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 + * 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, @@ -17,14 +17,13 @@ * limitations under the License. * ============LICENSE_END========================================================= */ + package org.onap.aai.schemaservice.interceptors.pre; -import org.onap.aai.exceptions.AAIException; -import org.onap.aai.logging.ErrorLogHelper; -import org.onap.aai.schemaservice.interceptors.AAIContainerFilter; -import org.onap.aai.schemaservice.interceptors.AAIHeaderProperties; -import org.onap.logging.filter.base.Constants; -import org.onap.logging.ref.slf4j.ONAPLogConstants; +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; +import java.util.Optional; import javax.annotation.Priority; import javax.ws.rs.container.ContainerRequestContext; @@ -32,10 +31,13 @@ import javax.ws.rs.container.ContainerRequestFilter; import javax.ws.rs.container.PreMatching; import javax.ws.rs.core.MediaType; import javax.ws.rs.core.Response; -import java.io.IOException; -import java.util.ArrayList; -import java.util.List; -import java.util.Optional; + +import org.onap.aai.exceptions.AAIException; +import org.onap.aai.logging.ErrorLogHelper; +import org.onap.aai.schemaservice.interceptors.AAIContainerFilter; +import org.onap.aai.schemaservice.interceptors.AAIHeaderProperties; +import org.onap.logging.filter.base.Constants; +import org.onap.logging.ref.slf4j.ONAPLogConstants; @PreMatching @Priority(AAIRequestFilterPriority.HEADER_VALIDATION) @@ -62,18 +64,21 @@ public class HeaderValidation extends AAIContainerFilter implements ContainerReq } private Optional<Response> validateHeaderValuePresence(String value, String errorCode, - List<MediaType> acceptHeaderValues) { + List<MediaType> acceptHeaderValues) { Response response = null; AAIException aaie; if (value == null || value.isEmpty()) { aaie = new AAIException(errorCode); - return Optional.of(Response.status(aaie.getErrorObject().getHTTPResponseCode()) - .entity(ErrorLogHelper.getRESTAPIErrorResponse(acceptHeaderValues, aaie, new ArrayList<>())) - .build()); + return Optional + .of(Response + .status(aaie.getErrorObject().getHTTPResponseCode()).entity(ErrorLogHelper + .getRESTAPIErrorResponse(acceptHeaderValues, aaie, new ArrayList<>())) + .build()); } return Optional.ofNullable(response); } + public String getRequestId(ContainerRequestContext requestContext) { String requestId = requestContext.getHeaderString(ONAPLogConstants.Headers.REQUEST_ID); if (requestId == null || requestId.isEmpty()) { @@ -81,7 +86,8 @@ public class HeaderValidation extends AAIContainerFilter implements ContainerReq if (requestId == null || requestId.isEmpty()) { requestId = requestContext.getHeaderString(Constants.HttpHeaders.TRANSACTION_ID); if (requestId == null || requestId.isEmpty()) { - requestId = requestContext.getHeaderString(Constants.HttpHeaders.ECOMP_REQUEST_ID); + requestId = + requestContext.getHeaderString(Constants.HttpHeaders.ECOMP_REQUEST_ID); if (requestId == null || requestId.isEmpty()) { return requestId; } diff --git a/aai-schema-service/src/main/java/org/onap/aai/schemaservice/interceptors/pre/HttpHeaderInterceptor.java b/aai-schema-service/src/main/java/org/onap/aai/schemaservice/interceptors/pre/HttpHeaderInterceptor.java index 26765e5..2830456 100644 --- a/aai-schema-service/src/main/java/org/onap/aai/schemaservice/interceptors/pre/HttpHeaderInterceptor.java +++ b/aai-schema-service/src/main/java/org/onap/aai/schemaservice/interceptors/pre/HttpHeaderInterceptor.java @@ -8,7 +8,7 @@ * 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 + * 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, @@ -17,17 +17,19 @@ * limitations under the License. * ============LICENSE_END========================================================= */ + package org.onap.aai.schemaservice.interceptors.pre; -import org.onap.aai.schemaservice.interceptors.AAIContainerFilter; -import org.onap.aai.schemaservice.interceptors.AAIHeaderProperties; +import java.io.IOException; import javax.annotation.Priority; import javax.ws.rs.HttpMethod; import javax.ws.rs.container.ContainerRequestContext; import javax.ws.rs.container.ContainerRequestFilter; import javax.ws.rs.container.PreMatching; -import java.io.IOException; + +import org.onap.aai.schemaservice.interceptors.AAIContainerFilter; +import org.onap.aai.schemaservice.interceptors.AAIHeaderProperties; /** * The Class HttpHeaderInterceptor @@ -39,10 +41,12 @@ public class HttpHeaderInterceptor extends AAIContainerFilter implements Contain @Override public void filter(ContainerRequestContext containerRequestContext) throws IOException { - String overrideMethod = containerRequestContext.getHeaderString(AAIHeaderProperties.HTTP_METHOD_OVERRIDE); + String overrideMethod = + containerRequestContext.getHeaderString(AAIHeaderProperties.HTTP_METHOD_OVERRIDE); String httpMethod = containerRequestContext.getMethod(); - if (HttpMethod.POST.equalsIgnoreCase(httpMethod) && patchMethod.equalsIgnoreCase(overrideMethod)) { + if (HttpMethod.POST.equalsIgnoreCase(httpMethod) + && patchMethod.equalsIgnoreCase(overrideMethod)) { containerRequestContext.setMethod(patchMethod); } } diff --git a/aai-schema-service/src/main/java/org/onap/aai/schemaservice/interceptors/pre/OneWaySslAuthorization.java b/aai-schema-service/src/main/java/org/onap/aai/schemaservice/interceptors/pre/OneWaySslAuthorization.java index 989e56a..32bf3d8 100644 --- a/aai-schema-service/src/main/java/org/onap/aai/schemaservice/interceptors/pre/OneWaySslAuthorization.java +++ b/aai-schema-service/src/main/java/org/onap/aai/schemaservice/interceptors/pre/OneWaySslAuthorization.java @@ -8,7 +8,7 @@ * 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 + * 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, @@ -17,15 +17,13 @@ * limitations under the License. * ============LICENSE_END========================================================= */ + package org.onap.aai.schemaservice.interceptors.pre; -import org.onap.aai.exceptions.AAIException; -import org.onap.aai.logging.ErrorLogHelper; -import org.onap.aai.schemaservice.Profiles; -import org.onap.aai.schemaservice.interceptors.AAIContainerFilter; -import org.onap.aai.schemaservice.service.AuthorizationService; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.context.annotation.Profile; +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; +import java.util.Optional; import javax.annotation.Priority; import javax.ws.rs.container.ContainerRequestContext; @@ -33,10 +31,14 @@ import javax.ws.rs.container.ContainerRequestFilter; import javax.ws.rs.container.PreMatching; import javax.ws.rs.core.MediaType; import javax.ws.rs.core.Response; -import java.io.IOException; -import java.util.ArrayList; -import java.util.List; -import java.util.Optional; + +import org.onap.aai.exceptions.AAIException; +import org.onap.aai.logging.ErrorLogHelper; +import org.onap.aai.schemaservice.Profiles; +import org.onap.aai.schemaservice.interceptors.AAIContainerFilter; +import org.onap.aai.schemaservice.service.AuthorizationService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.annotation.Profile; @Profile(Profiles.ONE_WAY_SSL) @PreMatching @@ -49,7 +51,8 @@ public class OneWaySslAuthorization extends AAIContainerFilter implements Contai @Override public void filter(ContainerRequestContext containerRequestContext) throws IOException { - if (containerRequestContext.getUriInfo().getRequestUri().getPath().matches("^.*/util/echo$")) { + if (containerRequestContext.getUriInfo().getRequestUri().getPath() + .matches("^.*/util/echo$")) { return; } @@ -75,7 +78,8 @@ public class OneWaySslAuthorization extends AAIContainerFilter implements Contai private Optional<Response> errorResponse(String errorCode, List<MediaType> acceptHeaderValues) { AAIException aaie = new AAIException(errorCode); return Optional.of(Response.status(aaie.getErrorObject().getHTTPResponseCode()) - .entity(ErrorLogHelper.getRESTAPIErrorResponse(acceptHeaderValues, aaie, new ArrayList<>())) + .entity( + ErrorLogHelper.getRESTAPIErrorResponse(acceptHeaderValues, aaie, new ArrayList<>())) .build()); } diff --git a/aai-schema-service/src/main/java/org/onap/aai/schemaservice/interceptors/pre/RequestHeaderManipulation.java b/aai-schema-service/src/main/java/org/onap/aai/schemaservice/interceptors/pre/RequestHeaderManipulation.java index 211350a..996ae68 100644 --- a/aai-schema-service/src/main/java/org/onap/aai/schemaservice/interceptors/pre/RequestHeaderManipulation.java +++ b/aai-schema-service/src/main/java/org/onap/aai/schemaservice/interceptors/pre/RequestHeaderManipulation.java @@ -8,7 +8,7 @@ * 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 + * 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, @@ -17,23 +17,26 @@ * limitations under the License. * ============LICENSE_END========================================================= */ + package org.onap.aai.schemaservice.interceptors.pre; -import org.onap.aai.schemaservice.interceptors.AAIContainerFilter; -import org.onap.aai.schemaservice.interceptors.AAIHeaderProperties; +import java.util.Collections; +import java.util.regex.Matcher; +import java.util.regex.Pattern; import javax.annotation.Priority; import javax.ws.rs.container.ContainerRequestContext; import javax.ws.rs.container.ContainerRequestFilter; import javax.ws.rs.container.PreMatching; import javax.ws.rs.core.MultivaluedMap; -import java.util.Collections; -import java.util.regex.Matcher; -import java.util.regex.Pattern; + +import org.onap.aai.schemaservice.interceptors.AAIContainerFilter; +import org.onap.aai.schemaservice.interceptors.AAIHeaderProperties; @PreMatching @Priority(AAIRequestFilterPriority.HEADER_MANIPULATION) -public class RequestHeaderManipulation extends AAIContainerFilter implements ContainerRequestFilter { +public class RequestHeaderManipulation extends AAIContainerFilter + implements ContainerRequestFilter { public static final Pattern EXTRACT_VERSION_PATTERN = Pattern.compile("^(v[1-9][0-9]*).*$"); diff --git a/aai-schema-service/src/main/java/org/onap/aai/schemaservice/interceptors/pre/RequestTransactionLogging.java b/aai-schema-service/src/main/java/org/onap/aai/schemaservice/interceptors/pre/RequestTransactionLogging.java index fbf9fbe..cfbd364 100644 --- a/aai-schema-service/src/main/java/org/onap/aai/schemaservice/interceptors/pre/RequestTransactionLogging.java +++ b/aai-schema-service/src/main/java/org/onap/aai/schemaservice/interceptors/pre/RequestTransactionLogging.java @@ -8,7 +8,7 @@ * 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 + * 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, @@ -17,20 +17,24 @@ * limitations under the License. * ============LICENSE_END========================================================= */ + package org.onap.aai.schemaservice.interceptors.pre; import com.google.gson.JsonObject; + import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.InputStream; import java.util.UUID; + import javax.annotation.Priority; import javax.servlet.http.HttpServletRequest; import javax.ws.rs.container.ContainerRequestContext; import javax.ws.rs.container.ContainerRequestFilter; import javax.ws.rs.container.PreMatching; import javax.ws.rs.core.MediaType; + import org.glassfish.jersey.message.internal.ReaderWriter; import org.glassfish.jersey.server.ContainerException; import org.onap.aai.schemaservice.interceptors.AAIContainerFilter; @@ -42,7 +46,8 @@ import org.springframework.web.context.request.ServletRequestAttributes; @PreMatching @Priority(AAIRequestFilterPriority.REQUEST_TRANS_LOGGING) -public class RequestTransactionLogging extends AAIContainerFilter implements ContainerRequestFilter { +public class RequestTransactionLogging extends AAIContainerFilter + implements ContainerRequestFilter { private static final String DEFAULT_CONTENT_TYPE = MediaType.APPLICATION_JSON; private static final String DEFAULT_RESPONSE_TYPE = MediaType.APPLICATION_XML; @@ -56,12 +61,15 @@ public class RequestTransactionLogging extends AAIContainerFilter implements Con String currentTimeStamp = genDate(); String fullId = this.getAAITxIdToHeader(); this.addToRequestContext(requestContext, AAIHeaderProperties.AAI_TX_ID, fullId); - this.addToRequestContext(requestContext, AAIHeaderProperties.AAI_REQUEST, this.getRequest(requestContext, fullId)); - this.addToRequestContext(requestContext, AAIHeaderProperties.AAI_REQUEST_TS, currentTimeStamp); + this.addToRequestContext(requestContext, AAIHeaderProperties.AAI_REQUEST, + this.getRequest(requestContext, fullId)); + this.addToRequestContext(requestContext, AAIHeaderProperties.AAI_REQUEST_TS, + currentTimeStamp); this.addDefaultContentType(requestContext); } - private void addToRequestContext(ContainerRequestContext requestContext, String name, String aaiTxIdToHeader) { + private void addToRequestContext(ContainerRequestContext requestContext, String name, + String aaiTxIdToHeader) { requestContext.setProperty(name, aaiTxIdToHeader); } @@ -87,7 +95,8 @@ public class RequestTransactionLogging extends AAIContainerFilter implements Con private String getHttpServletRequestContentType() { final RequestAttributes requestAttributes = RequestContextHolder.getRequestAttributes(); if (requestAttributes != null) { - HttpServletRequest request = ((ServletRequestAttributes) requestAttributes).getRequest(); + HttpServletRequest request = + ((ServletRequestAttributes) requestAttributes).getRequest(); return request.getContentType(); } return null; diff --git a/aai-schema-service/src/main/java/org/onap/aai/schemaservice/logging/LocalHostAccessLog.java b/aai-schema-service/src/main/java/org/onap/aai/schemaservice/logging/LocalHostAccessLog.java index 9ff3cb2..dc42bde 100644 --- a/aai-schema-service/src/main/java/org/onap/aai/schemaservice/logging/LocalHostAccessLog.java +++ b/aai-schema-service/src/main/java/org/onap/aai/schemaservice/logging/LocalHostAccessLog.java @@ -8,7 +8,7 @@ * 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 + * 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, @@ -17,9 +17,13 @@ * limitations under the License. * ============LICENSE_END========================================================= */ + package org.onap.aai.schemaservice.logging; import ch.qos.logback.access.jetty.RequestLogImpl; + +import java.util.Arrays; + import org.eclipse.jetty.server.handler.HandlerCollection; import org.eclipse.jetty.server.handler.RequestLogHandler; import org.eclipse.jetty.util.thread.QueuedThreadPool; @@ -30,16 +34,13 @@ import org.springframework.boot.web.servlet.server.AbstractServletWebServerFacto import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; -import java.util.Arrays; - @Configuration public class LocalHostAccessLog { @Bean public AbstractServletWebServerFactory jettyConfigBean( @Value("${jetty.threadPool.maxThreads:200}") final String maxThreads, - @Value("${jetty.threadPool.minThreads:8}") final String minThreads - ) { + @Value("${jetty.threadPool.minThreads:8}") final String minThreads) { JettyServletWebServerFactory jef = new JettyServletWebServerFactory(); jef.addServerCustomizers((JettyServerCustomizer) server -> { diff --git a/aai-schema-service/src/main/java/org/onap/aai/schemaservice/nodeschema/NodeIngestor.java b/aai-schema-service/src/main/java/org/onap/aai/schemaservice/nodeschema/NodeIngestor.java index 2459c54..713b078 100644 --- a/aai-schema-service/src/main/java/org/onap/aai/schemaservice/nodeschema/NodeIngestor.java +++ b/aai-schema-service/src/main/java/org/onap/aai/schemaservice/nodeschema/NodeIngestor.java @@ -8,7 +8,7 @@ * 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 + * 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, @@ -23,7 +23,9 @@ package org.onap.aai.schemaservice.nodeschema; import com.google.common.base.CaseFormat; import com.google.common.collect.ArrayListMultimap; import com.google.common.collect.Multimap; + import jakarta.xml.bind.JAXBException; + import java.io.ByteArrayInputStream; import java.io.File; import java.io.FileInputStream; @@ -42,10 +44,12 @@ import java.util.Set; import java.util.TreeMap; import java.util.regex.Matcher; import java.util.regex.Pattern; + import javax.xml.XMLConstants; import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; import javax.xml.parsers.ParserConfigurationException; + import org.eclipse.persistence.jaxb.JAXBContextProperties; import org.eclipse.persistence.jaxb.dynamic.DynamicJAXBContext; import org.eclipse.persistence.jaxb.dynamic.DynamicJAXBContextFactory; @@ -74,13 +78,12 @@ public class NodeIngestor { private Map<SchemaVersion, Document> schemaPerVersion = new TreeMap<>(); private ConfigTranslator translator; - @Autowired /** * Instantiates the NodeIngestor bean. * * @param translator - ConfigTranslator autowired in by Spring framework which - * contains the configuration information needed to ingest the desired files. + * contains the configuration information needed to ingest the desired files. */ public NodeIngestor(ConfigTranslator translator) { this.translator = translator; @@ -106,7 +109,7 @@ public class NodeIngestor { * @param files - List<String> of full filenames (ie including the path) to be ingested * @return DynamicJAXBContext including schema information from all given files * @throws FileNotFoundException if an OXM file can't be found - * @throws JAXBException if there's an error creating the DynamicJAXBContext + * @throws JAXBException if there's an error creating the DynamicJAXBContext */ private DynamicJAXBContext ingest(List<String> files) throws FileNotFoundException, JAXBException { @@ -118,11 +121,10 @@ public class NodeIngestor { Map<String, Object> properties = new HashMap<>(); properties.put(JAXBContextProperties.OXM_METADATA_SOURCE, streams); - return DynamicJAXBContextFactory - .createContextFromOXM(this.getClass().getClassLoader(), properties); + return DynamicJAXBContextFactory.createContextFromOXM(this.getClass().getClassLoader(), + properties); } - private Set<String> getAllNodeTypes(List<String> files) throws ParserConfigurationException, SAXException, IOException { Set<String> types = new HashSet<>(); @@ -142,7 +144,6 @@ public class NodeIngestor { final Document doc = docBuilder.parse(inputStream); final NodeList list = doc.getElementsByTagName("java-type"); - for (int i = 0; i < list.getLength(); i++) { String type = list.item(i).getAttributes().getNamedItem("name").getNodeValue(); javaTypes.add(list.item(i)); @@ -194,7 +195,7 @@ public class NodeIngestor { } private void createNode(Document combinedDoc, Node javaTypesContainer, - Map<String, Collection<Node>> map) { + Map<String, Collection<Node>> map) { for (Entry<String, Collection<Node>> entry : map.entrySet()) { @@ -212,9 +213,8 @@ public class NodeIngestor { Element element = (Element) copyOfFirstElement; NodeList javaAttributesList = element.getElementsByTagName("java-attributes"); - for (int javaAttributeIndex = 0; - javaAttributeIndex < javaAttributesList.getLength(); - javaAttributeIndex++) { + for (int javaAttributeIndex = 0; javaAttributeIndex < javaAttributesList + .getLength(); javaAttributeIndex++) { javaAttributeElement = javaAttributesList.item(javaAttributeIndex); } } @@ -225,14 +225,12 @@ public class NodeIngestor { Element element = (Element) copyOfCurrentElement; NodeList javaAttributesList = element.getElementsByTagName("java-attributes"); - for (int javaAttributeIndex = 0; - javaAttributeIndex < javaAttributesList.getLength(); - javaAttributeIndex++) { + for (int javaAttributeIndex = 0; javaAttributeIndex < javaAttributesList + .getLength(); javaAttributeIndex++) { Node jaElement = javaAttributesList.item(javaAttributeIndex); NodeList xmlElementList = jaElement.getChildNodes(); - for (int xmlElementIndex = 0; - xmlElementIndex < xmlElementList.getLength(); - xmlElementIndex++) { + for (int xmlElementIndex = 0; xmlElementIndex < xmlElementList + .getLength(); xmlElementIndex++) { if (javaAttributeElement != null) { Node curElem = xmlElementList.item(xmlElementIndex); if (curElem != null) { @@ -267,7 +265,7 @@ public class NodeIngestor { * Determines if the given version contains the given node type * * @param nodeType - node type to check, must be in lower hyphen form (ie "type-name") - * @param v - schema version to check against + * @param v - schema version to check against * @return */ public boolean hasNodeType(String nodeType, SchemaVersion v) { @@ -283,20 +281,16 @@ public class NodeIngestor { } private InputStream getShell(SchemaVersion v) { - String source = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + - "<xml-bindings xmlns=\"http://www.eclipse.org/eclipselink/xsds/persistence/oxm\" package-name=\"inventory.aai.onap.org." + - v.toString().toLowerCase() + "\" xml-mapping-metadata-complete=\"true\">\n" + - " <xml-schema element-form-default=\"QUALIFIED\">\n" + - " <xml-ns namespace-uri=\"http://org.onap.aai.inventory/" + - v.toString().toLowerCase() + "\" />\n" + - " </xml-schema>\n" + - " <java-types>\n" + - " </java-types>\n" + - "</xml-bindings>"; + String source = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + + "<xml-bindings xmlns=\"http://www.eclipse.org/eclipselink/xsds/persistence/oxm\" package-name=\"inventory.aai.onap.org." + + v.toString().toLowerCase() + "\" xml-mapping-metadata-complete=\"true\">\n" + + " <xml-schema element-form-default=\"QUALIFIED\">\n" + + " <xml-ns namespace-uri=\"http://org.onap.aai.inventory/" + + v.toString().toLowerCase() + "\" />\n" + " </xml-schema>\n" + " <java-types>\n" + + " </java-types>\n" + "</xml-bindings>"; return new ByteArrayInputStream(source.getBytes(StandardCharsets.UTF_8)); } - public SchemaVersion getVersionFromClassName(String classname) { Matcher m = classNamePattern.matcher(classname); String version = null; @@ -308,4 +302,3 @@ public class NodeIngestor { } } } - diff --git a/aai-schema-service/src/main/java/org/onap/aai/schemaservice/nodeschema/NodeSchemaResource.java b/aai-schema-service/src/main/java/org/onap/aai/schemaservice/nodeschema/NodeSchemaResource.java index 4eccd71..9c1f894 100644 --- a/aai-schema-service/src/main/java/org/onap/aai/schemaservice/nodeschema/NodeSchemaResource.java +++ b/aai-schema-service/src/main/java/org/onap/aai/schemaservice/nodeschema/NodeSchemaResource.java @@ -8,7 +8,7 @@ * 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 + * 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, @@ -17,14 +17,10 @@ * limitations under the License. * ============LICENSE_END========================================================= */ + package org.onap.aai.schemaservice.nodeschema; -import org.onap.aai.exceptions.AAIException; -import org.onap.aai.restcore.HttpMethod; -import org.onap.aai.restcore.RESTAPI; -import org.onap.aai.schemaservice.nodeschema.validation.AAISchemaValidationException; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.util.StringUtils; +import java.util.Optional; import javax.ws.rs.GET; import javax.ws.rs.Path; @@ -34,7 +30,13 @@ import javax.ws.rs.core.Context; import javax.ws.rs.core.HttpHeaders; import javax.ws.rs.core.Response; import javax.ws.rs.core.UriInfo; -import java.util.Optional; + +import org.onap.aai.exceptions.AAIException; +import org.onap.aai.restcore.HttpMethod; +import org.onap.aai.restcore.RESTAPI; +import org.onap.aai.schemaservice.nodeschema.validation.AAISchemaValidationException; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.util.StringUtils; @Path("/v1") public class NodeSchemaResource extends RESTAPI { @@ -46,27 +48,25 @@ public class NodeSchemaResource extends RESTAPI { @Autowired public NodeSchemaResource(NodeSchemaService nodeSchemaService, SchemaVersions schemaVersions) { this.nodeSchemaService = nodeSchemaService; - this.schemaVersions = schemaVersions; + this.schemaVersions = schemaVersions; } @GET @Path("/nodes") - @Produces({ "application/xml"}) + @Produces({"application/xml"}) public Response retrieveSchema(@QueryParam("version") String version, - @Context HttpHeaders headers, - @Context UriInfo info) - { + @Context HttpHeaders headers, @Context UriInfo info) { Response response; Optional<String> optionalSchema = nodeSchemaService.fetch(version); try { - if(StringUtils.isEmpty(version)){ + if (StringUtils.isEmpty(version)) { throw new AAIException("AAI_3050"); } SchemaVersion schemaVersion = new SchemaVersion(version); - if(!schemaVersions.getVersions().contains(schemaVersion)){ + if (!schemaVersions.getVersions().contains(schemaVersion)) { throw new AAIException("AAI_3018", version); } @@ -76,12 +76,14 @@ public class NodeSchemaResource extends RESTAPI { response = Response.ok(optionalSchema.get()).build(); - } catch(AAIException ex){ + } catch (AAIException ex) { response = consumerExceptionResponseGenerator(headers, info, HttpMethod.GET, ex); - } catch(AAISchemaValidationException ex){ - response = consumerExceptionResponseGenerator(headers, info, HttpMethod.GET, new AAIException("AAI_3051", version)); - } catch(Exception ex){ - response = consumerExceptionResponseGenerator(headers, info, HttpMethod.GET, new AAIException("AAI_4000")); + } catch (AAISchemaValidationException ex) { + response = consumerExceptionResponseGenerator(headers, info, HttpMethod.GET, + new AAIException("AAI_3051", version)); + } catch (Exception ex) { + response = consumerExceptionResponseGenerator(headers, info, HttpMethod.GET, + new AAIException("AAI_4000")); } return response; diff --git a/aai-schema-service/src/main/java/org/onap/aai/schemaservice/nodeschema/NodeSchemaService.java b/aai-schema-service/src/main/java/org/onap/aai/schemaservice/nodeschema/NodeSchemaService.java index 8c6399b..26214aa 100644 --- a/aai-schema-service/src/main/java/org/onap/aai/schemaservice/nodeschema/NodeSchemaService.java +++ b/aai-schema-service/src/main/java/org/onap/aai/schemaservice/nodeschema/NodeSchemaService.java @@ -8,7 +8,7 @@ * 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 + * 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, @@ -17,17 +17,9 @@ * limitations under the License. * ============LICENSE_END========================================================= */ -package org.onap.aai.schemaservice.nodeschema; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.onap.aai.logging.LogFormatTools; -import org.springframework.stereotype.Service; +package org.onap.aai.schemaservice.nodeschema; -import javax.annotation.PostConstruct; -import javax.xml.transform.*; -import javax.xml.transform.dom.DOMSource; -import javax.xml.transform.stream.StreamResult; import java.io.ByteArrayOutputStream; import java.io.OutputStreamWriter; import java.io.UnsupportedEncodingException; @@ -35,6 +27,16 @@ import java.util.HashMap; import java.util.Map; import java.util.Optional; +import javax.annotation.PostConstruct; +import javax.xml.transform.*; +import javax.xml.transform.dom.DOMSource; +import javax.xml.transform.stream.StreamResult; + +import org.onap.aai.logging.LogFormatTools; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.stereotype.Service; + @Service public class NodeSchemaService { @@ -62,8 +64,8 @@ public class NodeSchemaService { try { transformer = tf.newTransformer(); } catch (TransformerConfigurationException e) { - LOGGER.warn("Encountered an transformer configuration exception" + - "during node schema service startup ", LogFormatTools.getStackTop(e)); + LOGGER.warn("Encountered an transformer configuration exception" + + "during node schema service startup ", LogFormatTools.getStackTop(e)); } transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "no"); transformer.setOutputProperty(OutputKeys.METHOD, "xml"); @@ -74,12 +76,13 @@ public class NodeSchemaService { try { DOMSource domSource = new DOMSource(nodeIngestor.getSchema(schemaVersion)); - StreamResult streamResult = new StreamResult(new OutputStreamWriter(buffer, "UTF-8")); + StreamResult streamResult = + new StreamResult(new OutputStreamWriter(buffer, "UTF-8")); transformer.transform(domSource, streamResult); versionMap.put(schemaVersion.toString(), buffer.toString("UTF-8")); } catch (TransformerException | UnsupportedEncodingException e) { - LOGGER.warn("Encountered an transformer or unsupported encoding exception " + - "during node schema service startup ", LogFormatTools.getStackTop(e)); + LOGGER.warn("Encountered an transformer or unsupported encoding exception " + + "during node schema service startup ", LogFormatTools.getStackTop(e)); } })); diff --git a/aai-schema-service/src/main/java/org/onap/aai/schemaservice/nodeschema/SchemaVersion.java b/aai-schema-service/src/main/java/org/onap/aai/schemaservice/nodeschema/SchemaVersion.java index fc5b48c..380d15f 100644 --- a/aai-schema-service/src/main/java/org/onap/aai/schemaservice/nodeschema/SchemaVersion.java +++ b/aai-schema-service/src/main/java/org/onap/aai/schemaservice/nodeschema/SchemaVersion.java @@ -8,7 +8,7 @@ * 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 + * 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, @@ -17,59 +17,61 @@ * limitations under the License. * ============LICENSE_END========================================================= */ -package org.onap.aai.schemaservice.nodeschema; -import org.onap.aai.schemaservice.nodeschema.validation.AAISchemaValidationException; +package org.onap.aai.schemaservice.nodeschema; import java.util.regex.Pattern; +import org.onap.aai.schemaservice.nodeschema.validation.AAISchemaValidationException; + public class SchemaVersion implements Comparable<SchemaVersion> { public static final Pattern VERSION_PATTERN = Pattern.compile("v[1-9][0-9]*"); private final String value; - public SchemaVersion(String value){ + public SchemaVersion(String value) { - if(!VERSION_PATTERN.matcher(value).matches()){ - throw new AAISchemaValidationException("Invalid Schema Version " + value + ", value doesn't match the expected regex: " + VERSION_PATTERN); + if (!VERSION_PATTERN.matcher(value).matches()) { + throw new AAISchemaValidationException("Invalid Schema Version " + value + + ", value doesn't match the expected regex: " + VERSION_PATTERN); } this.value = value; } @Override - public int hashCode(){ + public int hashCode() { return value.hashCode(); } @Override - public boolean equals(Object other){ - if(this == other){ + public boolean equals(Object other) { + if (this == other) { return true; } - if(other == null){ + if (other == null) { return false; } - if(!(other instanceof SchemaVersion)){ + if (!(other instanceof SchemaVersion)) { return false; } - SchemaVersion obj = (SchemaVersion)other; + SchemaVersion obj = (SchemaVersion) other; return this.value.equals(obj.value); } @Override - public String toString(){ + public String toString() { return value; } @Override public int compareTo(SchemaVersion o) { - if(o == null){ + if (o == null) { return -1; } diff --git a/aai-schema-service/src/main/java/org/onap/aai/schemaservice/nodeschema/SchemaVersions.java b/aai-schema-service/src/main/java/org/onap/aai/schemaservice/nodeschema/SchemaVersions.java index 208d5d0..a8dc5dd 100644 --- a/aai-schema-service/src/main/java/org/onap/aai/schemaservice/nodeschema/SchemaVersions.java +++ b/aai-schema-service/src/main/java/org/onap/aai/schemaservice/nodeschema/SchemaVersions.java @@ -8,7 +8,7 @@ * 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 + * 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, @@ -17,17 +17,19 @@ * limitations under the License. * ============LICENSE_END========================================================= */ + package org.onap.aai.schemaservice.nodeschema; +import java.util.List; +import java.util.stream.Collectors; + +import javax.annotation.PostConstruct; + import org.onap.aai.schemaservice.nodeschema.validation.AAISchemaValidationException; import org.springframework.beans.factory.annotation.Value; import org.springframework.context.annotation.PropertySource; import org.springframework.stereotype.Component; -import javax.annotation.PostConstruct; -import java.util.List; -import java.util.stream.Collectors; - @Component @PropertySource(value = "classpath:schema-ingest.properties", ignoreResourceNotFound = true) @PropertySource(value = "file:${schema.ingest.file}", ignoreResourceNotFound = true) @@ -67,59 +69,53 @@ public class SchemaVersions { public void initialize() { versions = apiVersions.stream().map(SchemaVersion::new).collect(Collectors.toList()); - edgeLabelVersion = new SchemaVersion(edgeLabelStartVersion); - defaultVersion = new SchemaVersion(defaultApiVersion); - depthVersion = new SchemaVersion(depthStartVersion); - appRootVersion = new SchemaVersion(appRootStartVersion); - relatedLinkVersion = new SchemaVersion(relatedLinkStartVersion); + edgeLabelVersion = new SchemaVersion(edgeLabelStartVersion); + defaultVersion = new SchemaVersion(defaultApiVersion); + depthVersion = new SchemaVersion(depthStartVersion); + appRootVersion = new SchemaVersion(appRootStartVersion); + relatedLinkVersion = new SchemaVersion(relatedLinkStartVersion); namespaceChangeVersion = new SchemaVersion(namespaceChangeStartVersion); if (!versions.contains(edgeLabelVersion)) { throw new AAISchemaValidationException( - "Invalid, edge label version is not in the api versions list" + "Invalid, edge label version is not in the api versions list" + ", please check schema.version.list and ensure that the" - + " schema.version.edge.label.start is in that list" - ); + + " schema.version.edge.label.start is in that list"); } if (!versions.contains(defaultVersion)) { throw new AAISchemaValidationException( - "Invalid, default version is not in the api versions list" - + ", please check schema.version.list and ensure that the" - + " schema.version.api.default is in that list" - ); + "Invalid, default version is not in the api versions list" + + ", please check schema.version.list and ensure that the" + + " schema.version.api.default is in that list"); } if (!versions.contains(depthVersion)) { throw new AAISchemaValidationException( - "Invalid, depth version is not in the api versions list" - + ", please check schema.version.list and ensure that the" - + " schema.version.depth.start is in that list" - ); + "Invalid, depth version is not in the api versions list" + + ", please check schema.version.list and ensure that the" + + " schema.version.depth.start is in that list"); } - if(!versions.contains(appRootVersion)){ + if (!versions.contains(appRootVersion)) { throw new AAISchemaValidationException( - "Invalid, app root version is not in the api versions list" - + ", please check schema.version.list and ensure that the" - + " schema.version.app.root.start is in that list" - ); + "Invalid, app root version is not in the api versions list" + + ", please check schema.version.list and ensure that the" + + " schema.version.app.root.start is in that list"); } - if(!versions.contains(relatedLinkVersion)){ + if (!versions.contains(relatedLinkVersion)) { throw new AAISchemaValidationException( - "Invalid, related link version is not in the api versions list" - + ", please check schema.version.list and ensure that the" - + " schema.version.related.link.start is in that list" - ); + "Invalid, related link version is not in the api versions list" + + ", please check schema.version.list and ensure that the" + + " schema.version.related.link.start is in that list"); } - if(!versions.contains(namespaceChangeVersion)){ + if (!versions.contains(namespaceChangeVersion)) { throw new AAISchemaValidationException( - "Invalid, namespace change start version is not in the api versions list" - + ", please check schema.version.list and ensure that the" - + " schema.version.related.link.start is in that list" - ); + "Invalid, namespace change start version is not in the api versions list" + + ", please check schema.version.list and ensure that the" + + " schema.version.related.link.start is in that list"); } } @@ -139,11 +135,11 @@ public class SchemaVersions { return depthVersion; } - public SchemaVersion getAppRootVersion(){ + public SchemaVersion getAppRootVersion() { return appRootVersion; } - public SchemaVersion getRelatedLinkVersion(){ + public SchemaVersion getRelatedLinkVersion() { return relatedLinkVersion; } diff --git a/aai-schema-service/src/main/java/org/onap/aai/schemaservice/nodeschema/validation/AAISchemaValidationException.java b/aai-schema-service/src/main/java/org/onap/aai/schemaservice/nodeschema/validation/AAISchemaValidationException.java index fecc079..4d35e83 100644 --- a/aai-schema-service/src/main/java/org/onap/aai/schemaservice/nodeschema/validation/AAISchemaValidationException.java +++ b/aai-schema-service/src/main/java/org/onap/aai/schemaservice/nodeschema/validation/AAISchemaValidationException.java @@ -8,7 +8,7 @@ * 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 + * 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, @@ -17,13 +17,14 @@ * limitations under the License. * ============LICENSE_END========================================================= */ + package org.onap.aai.schemaservice.nodeschema.validation; /** * Indicates that a fatal error in the A&AI schema has been found. */ public class AAISchemaValidationException extends IllegalStateException { - public AAISchemaValidationException(String msg) { - super(msg); - } + public AAISchemaValidationException(String msg) { + super(msg); + } } diff --git a/aai-schema-service/src/main/java/org/onap/aai/schemaservice/nodeschema/validation/CheckEverythingStrategy.java b/aai-schema-service/src/main/java/org/onap/aai/schemaservice/nodeschema/validation/CheckEverythingStrategy.java index 047760f..40768b6 100644 --- a/aai-schema-service/src/main/java/org/onap/aai/schemaservice/nodeschema/validation/CheckEverythingStrategy.java +++ b/aai-schema-service/src/main/java/org/onap/aai/schemaservice/nodeschema/validation/CheckEverythingStrategy.java @@ -8,7 +8,7 @@ * 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 + * 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, @@ -17,13 +17,14 @@ * limitations under the License. * ============LICENSE_END========================================================= */ -package org.onap.aai.schemaservice.nodeschema.validation; -import org.apache.commons.lang.StringUtils; +package org.onap.aai.schemaservice.nodeschema.validation; import java.util.ArrayList; import java.util.List; +import org.apache.commons.lang.StringUtils; + /** * When an error is found, mark that it is NOT ok to * continue with installation/whatever other caller function, @@ -31,36 +32,42 @@ import java.util.List; * keep validating so all issues are found in one run. */ public class CheckEverythingStrategy implements SchemaErrorStrategy { - private boolean isOK = true; - private List<String> errorMsgs = new ArrayList<>(); + private boolean isOK = true; + private List<String> errorMsgs = new ArrayList<>(); - /* (non-Javadoc) - * @see org.onap.aai.edges.validation.SchemaErrorStrategy#isOK() - */ - @Override - public boolean isOK() { - return isOK; - } + /* + * (non-Javadoc) + * + * @see org.onap.aai.edges.validation.SchemaErrorStrategy#isOK() + */ + @Override + public boolean isOK() { + return isOK; + } - /* (non-Javadoc) - * @see org.onap.aai.edges.validation.SchemaErrorStrategy#getErrorMsg() - */ - @Override - public String getErrorMsg() { - if (errorMsgs.isEmpty()) { - return "No errors found."; - } else { - return StringUtils.join(errorMsgs, "\n"); + /* + * (non-Javadoc) + * + * @see org.onap.aai.edges.validation.SchemaErrorStrategy#getErrorMsg() + */ + @Override + public String getErrorMsg() { + if (errorMsgs.isEmpty()) { + return "No errors found."; + } else { + return StringUtils.join(errorMsgs, "\n"); + } } - } - /* (non-Javadoc) - * @see org.onap.aai.edges.validation.SchemaErrorStrategy#notifyOnError(java.lang.String) - */ - @Override - public void notifyOnError(String errorMsg) { - isOK = false; - errorMsgs.add(errorMsg); - } + /* + * (non-Javadoc) + * + * @see org.onap.aai.edges.validation.SchemaErrorStrategy#notifyOnError(java.lang.String) + */ + @Override + public void notifyOnError(String errorMsg) { + isOK = false; + errorMsgs.add(errorMsg); + } } diff --git a/aai-schema-service/src/main/java/org/onap/aai/schemaservice/nodeschema/validation/DefaultDuplicateNodeDefinitionValidationModule.java b/aai-schema-service/src/main/java/org/onap/aai/schemaservice/nodeschema/validation/DefaultDuplicateNodeDefinitionValidationModule.java index fa1c36b..b33fd8d 100644 --- a/aai-schema-service/src/main/java/org/onap/aai/schemaservice/nodeschema/validation/DefaultDuplicateNodeDefinitionValidationModule.java +++ b/aai-schema-service/src/main/java/org/onap/aai/schemaservice/nodeschema/validation/DefaultDuplicateNodeDefinitionValidationModule.java @@ -8,7 +8,7 @@ * 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 + * 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, @@ -17,25 +17,28 @@ * limitations under the License. * ============LICENSE_END========================================================= */ + package org.onap.aai.schemaservice.nodeschema.validation; import com.google.common.collect.ArrayListMultimap; import com.google.common.collect.Multimap; -import org.onap.aai.schemaservice.nodeschema.SchemaVersion; -import org.w3c.dom.Document; -import org.w3c.dom.NodeList; -import org.xml.sax.SAXException; -import javax.xml.XMLConstants; -import javax.xml.parsers.DocumentBuilder; -import javax.xml.parsers.DocumentBuilderFactory; -import javax.xml.parsers.ParserConfigurationException; import java.io.FileInputStream; import java.io.IOException; import java.io.InputStream; import java.util.Collection; import java.util.List; +import javax.xml.XMLConstants; +import javax.xml.parsers.DocumentBuilder; +import javax.xml.parsers.DocumentBuilderFactory; +import javax.xml.parsers.ParserConfigurationException; + +import org.onap.aai.schemaservice.nodeschema.SchemaVersion; +import org.w3c.dom.Document; +import org.w3c.dom.NodeList; +import org.xml.sax.SAXException; + /** * Default duplicate rules for A&AI - * node types may never have a duplicate definition @@ -44,63 +47,69 @@ import java.util.List; * Finds all duplicates and what files they're in. * */ -public class DefaultDuplicateNodeDefinitionValidationModule implements DuplicateNodeDefinitionValidationModule { +public class DefaultDuplicateNodeDefinitionValidationModule + implements DuplicateNodeDefinitionValidationModule { - /* (non-Javadoc) - * @see org.onap.aai.nodes.validation.DuplicateNodeDefinitionValidationModule#findDuplicates(java.util.List) - */ - @Override - public String findDuplicates(List<String> files, SchemaVersion v) { - try { - final DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance(); - docFactory.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, true); + /* + * (non-Javadoc) + * + * @see + * org.onap.aai.nodes.validation.DuplicateNodeDefinitionValidationModule#findDuplicates(java. + * util.List) + */ + @Override + public String findDuplicates(List<String> files, SchemaVersion v) { + try { + final DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance(); + docFactory.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, true); docFactory.setFeature("http://apache.org/xml/features/disallow-doctype-decl", true); docFactory.setFeature("http://xml.org/sax/features/external-general-entities", false); docFactory.setFeature("http://xml.org/sax/features/external-parameter-entities", false); docFactory.setAttribute(XMLConstants.ACCESS_EXTERNAL_DTD, ""); docFactory.setAttribute(XMLConstants.ACCESS_EXTERNAL_SCHEMA, ""); - final DocumentBuilder docBuilder = docFactory.newDocumentBuilder(); + final DocumentBuilder docBuilder = docFactory.newDocumentBuilder(); - Multimap<String, String> types = ArrayListMultimap.create(); - boolean foundDups = false; - for (String file : files) { - InputStream inputStream = new FileInputStream(file); - final Document doc = docBuilder.parse(inputStream); - final NodeList list = doc.getElementsByTagName("java-type"); + Multimap<String, String> types = ArrayListMultimap.create(); + boolean foundDups = false; + for (String file : files) { + InputStream inputStream = new FileInputStream(file); + final Document doc = docBuilder.parse(inputStream); + final NodeList list = doc.getElementsByTagName("java-type"); - for (int i = 0; i < list.getLength(); i++) { - String type = list.item(i).getAttributes().getNamedItem("name").getNodeValue(); - if (types.containsKey(type)) { - foundDups = true; - } - types.put(type, file); - } - } + for (int i = 0; i < list.getLength(); i++) { + String type = list.item(i).getAttributes().getNamedItem("name").getNodeValue(); + if (types.containsKey(type)) { + foundDups = true; + } + types.put(type, file); + } + } - if (foundDups) { - return buildErrorMsg(types, v); - } else { - return ""; - } - } catch (ParserConfigurationException | SAXException | IOException e) { - // TODO something useful with this information - return e.getMessage(); + if (foundDups) { + return buildErrorMsg(types, v); + } else { + return ""; + } + } catch (ParserConfigurationException | SAXException | IOException e) { + // TODO something useful with this information + return e.getMessage(); + } } - } - private String buildErrorMsg(Multimap<String, String> types, SchemaVersion v) { - StringBuilder errorMsg = new StringBuilder().append("Duplicates found in version ").append(v.toString()).append(". "); - for (String nodeType : types.keySet()) { - Collection<String> files = types.get(nodeType); - if (files.size() == 1) { - continue; //only record the duplicated ones - } - errorMsg.append(nodeType).append(" has definitions in "); - for (String file : files) { - errorMsg.append(file).append(" "); - } + private String buildErrorMsg(Multimap<String, String> types, SchemaVersion v) { + StringBuilder errorMsg = new StringBuilder().append("Duplicates found in version ") + .append(v.toString()).append(". "); + for (String nodeType : types.keySet()) { + Collection<String> files = types.get(nodeType); + if (files.size() == 1) { + continue; // only record the duplicated ones + } + errorMsg.append(nodeType).append(" has definitions in "); + for (String file : files) { + errorMsg.append(file).append(" "); + } + } + return errorMsg.toString(); } - return errorMsg.toString(); - } } diff --git a/aai-schema-service/src/main/java/org/onap/aai/schemaservice/nodeschema/validation/DefaultVersionValidationModule.java b/aai-schema-service/src/main/java/org/onap/aai/schemaservice/nodeschema/validation/DefaultVersionValidationModule.java index 8f674fc..ea7cdd7 100644 --- a/aai-schema-service/src/main/java/org/onap/aai/schemaservice/nodeschema/validation/DefaultVersionValidationModule.java +++ b/aai-schema-service/src/main/java/org/onap/aai/schemaservice/nodeschema/validation/DefaultVersionValidationModule.java @@ -8,7 +8,7 @@ * 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 + * 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, @@ -17,16 +17,17 @@ * limitations under the License. * ============LICENSE_END========================================================= */ + package org.onap.aai.schemaservice.nodeschema.validation; +import java.util.List; +import java.util.Map; + import org.onap.aai.schemaservice.config.ConfigTranslator; import org.onap.aai.schemaservice.nodeschema.SchemaVersion; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; -import java.util.List; -import java.util.Map; - /** * By default, A&AI must have schema files for all current * supported Versions in the Version enum @@ -34,39 +35,43 @@ import java.util.Map; */ @Component public class DefaultVersionValidationModule implements VersionValidationModule { - private ConfigTranslator config; + private ConfigTranslator config; - @Autowired - public DefaultVersionValidationModule(ConfigTranslator config) { - this.config = config; - } + @Autowired + public DefaultVersionValidationModule(ConfigTranslator config) { + this.config = config; + } - /* (non-Javadoc) - * @see org.onap.aai.validation.VersionValidationModule#validate(org.onap.aai.setup.ConfigTranslator) - */ - @Override - public String validate() { - Map<SchemaVersion, List<String>> nodeConfig = config.getNodeFiles(); - Map<SchemaVersion, List<String>> edgeConfig = config.getEdgeFiles(); + /* + * (non-Javadoc) + * + * @see + * org.onap.aai.validation.VersionValidationModule#validate(org.onap.aai.setup.ConfigTranslator) + */ + @Override + public String validate() { + Map<SchemaVersion, List<String>> nodeConfig = config.getNodeFiles(); + Map<SchemaVersion, List<String>> edgeConfig = config.getEdgeFiles(); - StringBuilder missingVers = new StringBuilder().append("Missing schema for the following versions: "); - boolean isMissing = false; - for (SchemaVersion v : config.getSchemaVersions().getVersions()) { - if (nodeConfig.get(v) == null) { - isMissing = true; - missingVers.append(v.toString()).append(" has no OXM configured. "); - } - if (edgeConfig.get(v) == null) { - isMissing = true; - missingVers.append(v.toString()).append(" has no edge rules configured. "); - } - } + StringBuilder missingVers = + new StringBuilder().append("Missing schema for the following versions: "); + boolean isMissing = false; + for (SchemaVersion v : config.getSchemaVersions().getVersions()) { + if (nodeConfig.get(v) == null) { + isMissing = true; + missingVers.append(v.toString()).append(" has no OXM configured. "); + } + if (edgeConfig.get(v) == null) { + isMissing = true; + missingVers.append(v.toString()).append(" has no edge rules configured. "); + } + } - if (isMissing) { - return missingVers.toString(); - } else { - return ""; + if (isMissing) { + return missingVers.toString(); + } else { + return ""; + } } - } } diff --git a/aai-schema-service/src/main/java/org/onap/aai/schemaservice/nodeschema/validation/DuplicateNodeDefinitionValidationModule.java b/aai-schema-service/src/main/java/org/onap/aai/schemaservice/nodeschema/validation/DuplicateNodeDefinitionValidationModule.java index 1cab48d..7b07ce8 100644 --- a/aai-schema-service/src/main/java/org/onap/aai/schemaservice/nodeschema/validation/DuplicateNodeDefinitionValidationModule.java +++ b/aai-schema-service/src/main/java/org/onap/aai/schemaservice/nodeschema/validation/DuplicateNodeDefinitionValidationModule.java @@ -8,7 +8,7 @@ * 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 + * 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, @@ -17,12 +17,13 @@ * limitations under the License. * ============LICENSE_END========================================================= */ -package org.onap.aai.schemaservice.nodeschema.validation; -import org.onap.aai.schemaservice.nodeschema.SchemaVersion; +package org.onap.aai.schemaservice.nodeschema.validation; import java.util.List; +import org.onap.aai.schemaservice.nodeschema.SchemaVersion; + /** * Defines rules for duplicate node definitions in a set of files * (where the intent is the set of files is all the OXM for one version). @@ -34,13 +35,13 @@ import java.util.List; * etc. */ public interface DuplicateNodeDefinitionValidationModule { - /** - * Finds any duplicates according to the defined rules - * - * @param files - the OXM files to use with full directory - * @return empty String if none found, else a String - * with appropriate information about what node types - * were found - */ - String findDuplicates(List<String> files, SchemaVersion v); + /** + * Finds any duplicates according to the defined rules + * + * @param files - the OXM files to use with full directory + * @return empty String if none found, else a String + * with appropriate information about what node types + * were found + */ + String findDuplicates(List<String> files, SchemaVersion v); } diff --git a/aai-schema-service/src/main/java/org/onap/aai/schemaservice/nodeschema/validation/FailFastStrategy.java b/aai-schema-service/src/main/java/org/onap/aai/schemaservice/nodeschema/validation/FailFastStrategy.java index 7c05007..5bbfb87 100644 --- a/aai-schema-service/src/main/java/org/onap/aai/schemaservice/nodeschema/validation/FailFastStrategy.java +++ b/aai-schema-service/src/main/java/org/onap/aai/schemaservice/nodeschema/validation/FailFastStrategy.java @@ -8,7 +8,7 @@ * 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 + * 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, @@ -17,6 +17,7 @@ * limitations under the License. * ============LICENSE_END========================================================= */ + package org.onap.aai.schemaservice.nodeschema.validation; /** @@ -25,33 +26,39 @@ package org.onap.aai.schemaservice.nodeschema.validation; * process to abort. */ public class FailFastStrategy implements SchemaErrorStrategy { - private boolean isOK = true; - private String errorMsg = "No errors found."; + private boolean isOK = true; + private String errorMsg = "No errors found."; - /* (non-Javadoc) - * @see org.onap.aai.edges.validation.SchemaErrorStrategy#isOK() - */ - @Override - public boolean isOK() { - return isOK; - } + /* + * (non-Javadoc) + * + * @see org.onap.aai.edges.validation.SchemaErrorStrategy#isOK() + */ + @Override + public boolean isOK() { + return isOK; + } - /* (non-Javadoc) - * @see org.onap.aai.edges.validation.SchemaErrorStrategy#getErrorMsg() - */ - @Override - public String getErrorMsg() { - return errorMsg; - } + /* + * (non-Javadoc) + * + * @see org.onap.aai.edges.validation.SchemaErrorStrategy#getErrorMsg() + */ + @Override + public String getErrorMsg() { + return errorMsg; + } - /* (non-Javadoc) - * @see org.onap.aai.edges.validation.SchemaErrorStrategy#notifyOnError(java.lang.String) - */ - @Override - public void notifyOnError(String errorMsg) { - isOK = false; - this.errorMsg = errorMsg; - throw new AAISchemaValidationException(errorMsg); - } + /* + * (non-Javadoc) + * + * @see org.onap.aai.edges.validation.SchemaErrorStrategy#notifyOnError(java.lang.String) + */ + @Override + public void notifyOnError(String errorMsg) { + isOK = false; + this.errorMsg = errorMsg; + throw new AAISchemaValidationException(errorMsg); + } } diff --git a/aai-schema-service/src/main/java/org/onap/aai/schemaservice/nodeschema/validation/NodeValidator.java b/aai-schema-service/src/main/java/org/onap/aai/schemaservice/nodeschema/validation/NodeValidator.java index bc46e16..faeadc5 100644 --- a/aai-schema-service/src/main/java/org/onap/aai/schemaservice/nodeschema/validation/NodeValidator.java +++ b/aai-schema-service/src/main/java/org/onap/aai/schemaservice/nodeschema/validation/NodeValidator.java @@ -8,7 +8,7 @@ * 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 + * 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, @@ -17,41 +17,43 @@ * limitations under the License. * ============LICENSE_END========================================================= */ + package org.onap.aai.schemaservice.nodeschema.validation; +import java.util.List; +import java.util.Map.Entry; + import org.onap.aai.schemaservice.config.ConfigTranslator; import org.onap.aai.schemaservice.nodeschema.SchemaVersion; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; -import java.util.List; -import java.util.Map.Entry; - @Component public class NodeValidator { - private ConfigTranslator translator; - private SchemaErrorStrategy strat; - private DuplicateNodeDefinitionValidationModule dupChecker; - - @Autowired - public NodeValidator(ConfigTranslator translator, SchemaErrorStrategy strategy, DuplicateNodeDefinitionValidationModule dupChecker) { - this.translator = translator; - this.strat = strategy; - this.dupChecker = dupChecker; - } - - public boolean validate() { - - for(Entry<SchemaVersion, List<String>> entry : translator.getNodeFiles().entrySet()) { - String result = dupChecker.findDuplicates(entry.getValue(), entry.getKey()); - if (!"".equals(result)) { - strat.notifyOnError(result); - } + private ConfigTranslator translator; + private SchemaErrorStrategy strat; + private DuplicateNodeDefinitionValidationModule dupChecker; + + @Autowired + public NodeValidator(ConfigTranslator translator, SchemaErrorStrategy strategy, + DuplicateNodeDefinitionValidationModule dupChecker) { + this.translator = translator; + this.strat = strategy; + this.dupChecker = dupChecker; + } + + public boolean validate() { + + for (Entry<SchemaVersion, List<String>> entry : translator.getNodeFiles().entrySet()) { + String result = dupChecker.findDuplicates(entry.getValue(), entry.getKey()); + if (!"".equals(result)) { + strat.notifyOnError(result); + } + } + return strat.isOK(); } - return strat.isOK(); - } - public String getErrorMsg() { - return strat.getErrorMsg(); - } + public String getErrorMsg() { + return strat.getErrorMsg(); + } } diff --git a/aai-schema-service/src/main/java/org/onap/aai/schemaservice/nodeschema/validation/SchemaErrorStrategy.java b/aai-schema-service/src/main/java/org/onap/aai/schemaservice/nodeschema/validation/SchemaErrorStrategy.java index a9cafa5..7d76533 100644 --- a/aai-schema-service/src/main/java/org/onap/aai/schemaservice/nodeschema/validation/SchemaErrorStrategy.java +++ b/aai-schema-service/src/main/java/org/onap/aai/schemaservice/nodeschema/validation/SchemaErrorStrategy.java @@ -8,7 +8,7 @@ * 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 + * 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, @@ -17,42 +17,43 @@ * limitations under the License. * ============LICENSE_END========================================================= */ + package org.onap.aai.schemaservice.nodeschema.validation; /** * Controls response to finding problems in the schema files. */ public interface SchemaErrorStrategy { - /** - * Gives if it is OK to proceed with whatever process - * invoked the validation (probably the installation of - * the A&AI instance). - * - * @return boolean - */ - public boolean isOK(); + /** + * Gives if it is OK to proceed with whatever process + * invoked the validation (probably the installation of + * the A&AI instance). + * + * @return boolean + */ + public boolean isOK(); - /** - * Gets the error message(s) gathered in the course - * of validation. - * - * @return String error message or messages concatenated together - */ - public String getErrorMsg(); + /** + * Gets the error message(s) gathered in the course + * of validation. + * + * @return String error message or messages concatenated together + */ + public String getErrorMsg(); - /** - * Invokes the ErrorStrategy to do whatever response to - * an issue in the schema having been found. - * - * Options: - * -Throw an exception if the whole process should be - * immediately aborted - * -Set OK status to false, store the message and allow the - * validation process to continue and find any other issues - * -Completely ignore that something is wrong - * etc. - * - * @param String errorMsg - the error message from the validator module - */ - public void notifyOnError(String errorMsg); + /** + * Invokes the ErrorStrategy to do whatever response to + * an issue in the schema having been found. + * + * Options: + * -Throw an exception if the whole process should be + * immediately aborted + * -Set OK status to false, store the message and allow the + * validation process to continue and find any other issues + * -Completely ignore that something is wrong + * etc. + * + * @param String errorMsg - the error message from the validator module + */ + public void notifyOnError(String errorMsg); } diff --git a/aai-schema-service/src/main/java/org/onap/aai/schemaservice/nodeschema/validation/VersionValidationModule.java b/aai-schema-service/src/main/java/org/onap/aai/schemaservice/nodeschema/validation/VersionValidationModule.java index 15ae19a..c7304d6 100644 --- a/aai-schema-service/src/main/java/org/onap/aai/schemaservice/nodeschema/validation/VersionValidationModule.java +++ b/aai-schema-service/src/main/java/org/onap/aai/schemaservice/nodeschema/validation/VersionValidationModule.java @@ -8,7 +8,7 @@ * 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 + * 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, @@ -17,8 +17,8 @@ * limitations under the License. * ============LICENSE_END========================================================= */ -package org.onap.aai.schemaservice.nodeschema.validation; +package org.onap.aai.schemaservice.nodeschema.validation; /** * Defines the behavior for what versions are required/optional. @@ -27,11 +27,11 @@ package org.onap.aai.schemaservice.nodeschema.validation; */ public interface VersionValidationModule { - /** - * Validates that all required versions have schema - * configured for them. - * - * @return empty string if none missing or else an appropriate error - */ - public String validate(); + /** + * Validates that all required versions have schema + * configured for them. + * + * @return empty string if none missing or else an appropriate error + */ + public String validate(); } diff --git a/aai-schema-service/src/main/java/org/onap/aai/schemaservice/nodeschema/validation/VersionValidator.java b/aai-schema-service/src/main/java/org/onap/aai/schemaservice/nodeschema/validation/VersionValidator.java index 0158bc3..135bdcc 100644 --- a/aai-schema-service/src/main/java/org/onap/aai/schemaservice/nodeschema/validation/VersionValidator.java +++ b/aai-schema-service/src/main/java/org/onap/aai/schemaservice/nodeschema/validation/VersionValidator.java @@ -8,7 +8,7 @@ * 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 + * 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, @@ -17,6 +17,7 @@ * limitations under the License. * ============LICENSE_END========================================================= */ + package org.onap.aai.schemaservice.nodeschema.validation; import org.springframework.beans.factory.annotation.Autowired; @@ -28,25 +29,25 @@ import org.springframework.stereotype.Component; */ @Component public class VersionValidator { - private SchemaErrorStrategy strat; - private VersionValidationModule verMod; - - @Autowired - public VersionValidator(SchemaErrorStrategy strategy, VersionValidationModule verMod) { - this.strat = strategy; - this.verMod = verMod; - } + private SchemaErrorStrategy strat; + private VersionValidationModule verMod; - public boolean validate() { - String result = verMod.validate(); - if (!"".equals(result)) { - strat.notifyOnError(result); + @Autowired + public VersionValidator(SchemaErrorStrategy strategy, VersionValidationModule verMod) { + this.strat = strategy; + this.verMod = verMod; } - return strat.isOK(); - } + public boolean validate() { + String result = verMod.validate(); + if (!"".equals(result)) { + strat.notifyOnError(result); + } - public String getErrorMsg() { - return strat.getErrorMsg(); - } + return strat.isOK(); + } + + public String getErrorMsg() { + return strat.getErrorMsg(); + } } diff --git a/aai-schema-service/src/main/java/org/onap/aai/schemaservice/query/QueryResource.java b/aai-schema-service/src/main/java/org/onap/aai/schemaservice/query/QueryResource.java index 0137d1d..69c9998 100644 --- a/aai-schema-service/src/main/java/org/onap/aai/schemaservice/query/QueryResource.java +++ b/aai-schema-service/src/main/java/org/onap/aai/schemaservice/query/QueryResource.java @@ -8,7 +8,7 @@ * 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 + * 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, @@ -17,27 +17,28 @@ * limitations under the License. * ============LICENSE_END========================================================= */ -package org.onap.aai.schemaservice.query; -import org.springframework.beans.factory.annotation.Autowired; +package org.onap.aai.schemaservice.query; import javax.ws.rs.GET; import javax.ws.rs.Path; import javax.ws.rs.core.Response; +import org.springframework.beans.factory.annotation.Autowired; + @Path("/v1") public class QueryResource { private QueryService queryService; @Autowired - public QueryResource(QueryService queryService){ + public QueryResource(QueryService queryService) { this.queryService = queryService; } @GET @Path("/stored-queries") - public Response retrieveStoredQueries(){ + public Response retrieveStoredQueries() { return Response.ok().entity(queryService.getStoredQueries()).build(); } diff --git a/aai-schema-service/src/main/java/org/onap/aai/schemaservice/query/QueryService.java b/aai-schema-service/src/main/java/org/onap/aai/schemaservice/query/QueryService.java index 1e67bd9..a3c8b5a 100644 --- a/aai-schema-service/src/main/java/org/onap/aai/schemaservice/query/QueryService.java +++ b/aai-schema-service/src/main/java/org/onap/aai/schemaservice/query/QueryService.java @@ -8,7 +8,7 @@ * 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 + * 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, @@ -17,14 +17,9 @@ * limitations under the License. * ============LICENSE_END========================================================= */ -package org.onap.aai.schemaservice.query; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.beans.factory.annotation.Value; -import org.springframework.stereotype.Service; +package org.onap.aai.schemaservice.query; -import javax.annotation.PostConstruct; import java.io.File; import java.io.IOException; import java.nio.charset.StandardCharsets; @@ -32,6 +27,13 @@ import java.nio.file.Files; import java.nio.file.Paths; import java.util.stream.Stream; +import javax.annotation.PostConstruct; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.stereotype.Service; + @Service public class QueryService { @@ -41,7 +43,7 @@ public class QueryService { private String storedQueriesContent; - public QueryService(@Value("${schema.query.location}") String queryLocation){ + public QueryService(@Value("${schema.query.location}") String queryLocation) { this.queryLocation = queryLocation; } @@ -53,7 +55,7 @@ public class QueryService { StringBuilder contentBuilder = new StringBuilder(); - try(Stream<String> stream = Files.lines(Paths.get(fileName), StandardCharsets.UTF_8)){ + try (Stream<String> stream = Files.lines(Paths.get(fileName), StandardCharsets.UTF_8)) { stream.forEach(s -> contentBuilder.append(s)); } @@ -62,7 +64,7 @@ public class QueryService { LOGGER.trace("Contents of the stored query file {}", storedQueriesContent); } - public String getStoredQueries(){ + public String getStoredQueries() { return storedQueriesContent; } } diff --git a/aai-schema-service/src/main/java/org/onap/aai/schemaservice/service/AuthorizationService.java b/aai-schema-service/src/main/java/org/onap/aai/schemaservice/service/AuthorizationService.java index 766e56c..808cde8 100644 --- a/aai-schema-service/src/main/java/org/onap/aai/schemaservice/service/AuthorizationService.java +++ b/aai-schema-service/src/main/java/org/onap/aai/schemaservice/service/AuthorizationService.java @@ -8,7 +8,7 @@ * 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 + * 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, @@ -17,17 +17,9 @@ * limitations under the License. * ============LICENSE_END========================================================= */ -package org.onap.aai.schemaservice.service; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.eclipse.jetty.util.security.Password; -import org.onap.aai.schemaservice.Profiles; -import org.onap.aai.util.AAIConstants; -import org.springframework.context.annotation.Profile; -import org.springframework.stereotype.Service; +package org.onap.aai.schemaservice.service; -import javax.annotation.PostConstruct; import java.io.IOException; import java.io.UnsupportedEncodingException; import java.nio.file.Files; @@ -37,6 +29,16 @@ import java.util.HashMap; import java.util.Map; import java.util.stream.Stream; +import javax.annotation.PostConstruct; + +import org.eclipse.jetty.util.security.Password; +import org.onap.aai.schemaservice.Profiles; +import org.onap.aai.util.AAIConstants; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.context.annotation.Profile; +import org.springframework.stereotype.Service; + @Profile(Profiles.ONE_WAY_SSL) @Service public class AuthorizationService { @@ -48,37 +50,39 @@ public class AuthorizationService { private static final Base64.Encoder ENCODER = Base64.getEncoder(); @PostConstruct - public void init(){ + public void init() { String basicAuthFile = getBasicAuthFilePath(); - try(Stream<String> stream = Files.lines(Paths.get(basicAuthFile))){ + try (Stream<String> stream = Files.lines(Paths.get(basicAuthFile))) { stream.filter(line -> !line.startsWith("#")).forEach(str -> { - byte [] bytes = null; + byte[] bytes = null; String usernamePassword = null; String accessType = null; try { - String [] userAccessType = str.split(","); + String[] userAccessType = str.split(","); - if(userAccessType == null || userAccessType.length != 2){ - throw new RuntimeException("Please check the realm.properties file as it is not conforming to the basic auth"); + if (userAccessType == null || userAccessType.length != 2) { + throw new RuntimeException( + "Please check the realm.properties file as it is not conforming to the basic auth"); } usernamePassword = userAccessType[0]; - accessType = userAccessType[1]; + accessType = userAccessType[1]; String[] usernamePasswordArray = usernamePassword.split(":"); - if(usernamePasswordArray == null || usernamePasswordArray.length != 3){ - throw new RuntimeException("This username / pwd is not a valid entry in realm.properties"); + if (usernamePasswordArray == null || usernamePasswordArray.length != 3) { + throw new RuntimeException( + "This username / pwd is not a valid entry in realm.properties"); } String username = usernamePasswordArray[0]; String password = null; - if(str.contains("OBF:")){ + if (str.contains("OBF:")) { password = usernamePasswordArray[1] + ":" + usernamePasswordArray[2]; password = Password.deobfuscate(password); } @@ -87,8 +91,7 @@ public class AuthorizationService { authorizedUsers.put(new String(bytes), accessType); - } catch (UnsupportedEncodingException e) - { + } catch (UnsupportedEncodingException e) { logger.error("Unable to support the encoding of the file" + basicAuthFile); } @@ -99,11 +102,12 @@ public class AuthorizationService { } } - public boolean checkIfUserAuthorized(String authorization){ - return authorizedUsers.containsKey(authorization) && "admin".equals(authorizedUsers.get(authorization)); + public boolean checkIfUserAuthorized(String authorization) { + return authorizedUsers.containsKey(authorization) + && "admin".equals(authorizedUsers.get(authorization)); } - public String getBasicAuthFilePath(){ + public String getBasicAuthFilePath() { return AAIConstants.AAI_HOME_ETC_AUTH + AAIConstants.AAI_FILESEP + "realm.properties"; } } diff --git a/aai-schema-service/src/main/java/org/onap/aai/schemaservice/versions/Version.java b/aai-schema-service/src/main/java/org/onap/aai/schemaservice/versions/Version.java index 47da48d..2bdf179 100644 --- a/aai-schema-service/src/main/java/org/onap/aai/schemaservice/versions/Version.java +++ b/aai-schema-service/src/main/java/org/onap/aai/schemaservice/versions/Version.java @@ -8,7 +8,7 @@ * 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 + * 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, @@ -17,6 +17,7 @@ * limitations under the License. * ============LICENSE_END========================================================= */ + package org.onap.aai.schemaservice.versions; import com.google.gson.annotations.SerializedName; @@ -99,35 +100,33 @@ public class Version { @Override public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; + if (this == o) + return true; + if (o == null || getClass() != o.getClass()) + return false; Version that = (Version) o; - return Objects.equals(versions, that.versions) && - Objects.equals(edgeVersion, that.edgeVersion) && - Objects.equals(defaultVersion, that.defaultVersion) && - Objects.equals(depthVersion, that.depthVersion) && - Objects.equals(appRootVersion, that.appRootVersion) && - Objects.equals(relatedLinkVersion, that.relatedLinkVersion) && - Objects.equals(namespaceChangeVersion, that.namespaceChangeVersion); + return Objects.equals(versions, that.versions) + && Objects.equals(edgeVersion, that.edgeVersion) + && Objects.equals(defaultVersion, that.defaultVersion) + && Objects.equals(depthVersion, that.depthVersion) + && Objects.equals(appRootVersion, that.appRootVersion) + && Objects.equals(relatedLinkVersion, that.relatedLinkVersion) + && Objects.equals(namespaceChangeVersion, that.namespaceChangeVersion); } @Override public int hashCode() { - return Objects.hash(versions, edgeVersion, defaultVersion, depthVersion, appRootVersion, relatedLinkVersion, namespaceChangeVersion); + return Objects.hash(versions, edgeVersion, defaultVersion, depthVersion, appRootVersion, + relatedLinkVersion, namespaceChangeVersion); } - @Override public String toString() { - return "Version{" + - "versions=" + versions + - ", edgeVersion='" + edgeVersion + '\'' + - ", defaultVersion='" + defaultVersion + '\'' + - ", depthVersion='" + depthVersion + '\'' + - ", appRootVersion='" + appRootVersion + '\'' + - ", relatedLinkVersion='" + relatedLinkVersion + '\'' + - ", namespaceChangeVersion='" + namespaceChangeVersion + '\'' + - '}'; + return "Version{" + "versions=" + versions + ", edgeVersion='" + edgeVersion + '\'' + + ", defaultVersion='" + defaultVersion + '\'' + ", depthVersion='" + depthVersion + + '\'' + ", appRootVersion='" + appRootVersion + '\'' + ", relatedLinkVersion='" + + relatedLinkVersion + '\'' + ", namespaceChangeVersion='" + namespaceChangeVersion + + '\'' + '}'; } } diff --git a/aai-schema-service/src/main/java/org/onap/aai/schemaservice/versions/VersionResource.java b/aai-schema-service/src/main/java/org/onap/aai/schemaservice/versions/VersionResource.java index 70e32bc..4093769 100644 --- a/aai-schema-service/src/main/java/org/onap/aai/schemaservice/versions/VersionResource.java +++ b/aai-schema-service/src/main/java/org/onap/aai/schemaservice/versions/VersionResource.java @@ -8,7 +8,7 @@ * 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 + * 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, @@ -17,10 +17,10 @@ * limitations under the License. * ============LICENSE_END========================================================= */ + package org.onap.aai.schemaservice.versions; import com.google.gson.Gson; -import org.springframework.beans.factory.annotation.Autowired; import javax.ws.rs.GET; import javax.ws.rs.Path; @@ -28,20 +28,22 @@ import javax.ws.rs.Produces; import javax.ws.rs.core.MediaType; import javax.ws.rs.core.Response; +import org.springframework.beans.factory.annotation.Autowired; + @Path("/v1") public class VersionResource { private VersionService versionService; @Autowired - public VersionResource(VersionService versionService){ + public VersionResource(VersionService versionService) { this.versionService = versionService; } @GET @Path("/versions") - @Produces({ MediaType.APPLICATION_JSON }) - public Response getVersions(){ + @Produces({MediaType.APPLICATION_JSON}) + public Response getVersions() { Gson gson = new Gson(); return Response.ok(gson.toJson(versionService.getVersionInfo())).build(); } diff --git a/aai-schema-service/src/main/java/org/onap/aai/schemaservice/versions/VersionService.java b/aai-schema-service/src/main/java/org/onap/aai/schemaservice/versions/VersionService.java index 2d80145..810e4eb 100644 --- a/aai-schema-service/src/main/java/org/onap/aai/schemaservice/versions/VersionService.java +++ b/aai-schema-service/src/main/java/org/onap/aai/schemaservice/versions/VersionService.java @@ -8,7 +8,7 @@ * 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 + * 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, @@ -17,13 +17,14 @@ * limitations under the License. * ============LICENSE_END========================================================= */ + package org.onap.aai.schemaservice.versions; +import java.util.List; + import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Service; -import java.util.List; - @Service public class VersionService { @@ -48,8 +49,7 @@ public class VersionService { @Value("${schema.version.api.default}") private String defaultApi; - - public Version getVersionInfo(){ + public Version getVersionInfo() { Version schemaVersion = new Version(); schemaVersion.setVersions(schemaVersionList); diff --git a/aai-schema-service/src/main/java/org/onap/aai/schemaservice/web/JerseyConfiguration.java b/aai-schema-service/src/main/java/org/onap/aai/schemaservice/web/JerseyConfiguration.java index 182203d..8b3a936 100644 --- a/aai-schema-service/src/main/java/org/onap/aai/schemaservice/web/JerseyConfiguration.java +++ b/aai-schema-service/src/main/java/org/onap/aai/schemaservice/web/JerseyConfiguration.java @@ -8,7 +8,7 @@ * 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 + * 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, @@ -17,15 +17,18 @@ * limitations under the License. * ============LICENSE_END========================================================= */ + package org.onap.aai.schemaservice.web; import java.util.List; import java.util.Set; import java.util.logging.Logger; import java.util.stream.Collectors; + import javax.annotation.Priority; import javax.ws.rs.container.ContainerRequestFilter; import javax.ws.rs.container.ContainerResponseFilter; + import org.glassfish.jersey.server.ResourceConfig; import org.onap.aai.schemaservice.edges.EdgeResource; import org.onap.aai.schemaservice.healthcheck.EchoResource; @@ -39,7 +42,6 @@ import org.springframework.context.annotation.Profile; import org.springframework.core.env.Environment; import org.springframework.stereotype.Component; - @Component public class JerseyConfiguration extends ResourceConfig { @@ -58,7 +60,7 @@ public class JerseyConfiguration extends ResourceConfig { register(QueryResource.class); register(EdgeResource.class); - //Request Filters + // Request Filters registerFilters(ContainerRequestFilter.class); registerFilters(ContainerResponseFilter.class); registerFilters(AuditLogContainerFilter.class); @@ -73,31 +75,30 @@ public class JerseyConfiguration extends ResourceConfig { Set<Class<? extends T>> filters = loggingReflections.getSubTypesOf(type); filters.addAll(reflections.getSubTypesOf(type)); - // Check to ensure that each of the filter has the @Priority annotation and if not throw exception + // Check to ensure that each of the filter has the @Priority annotation and if not throw + // exception for (Class filterClass : filters) { if (filterClass.getAnnotation(Priority.class) == null) { - throw new RuntimeException("Container filter " + filterClass.getName() + " does not have @Priority annotation"); + throw new RuntimeException("Container filter " + filterClass.getName() + + " does not have @Priority annotation"); } } // Turn the set back into a list - List<Class<? extends T>> filtersList = filters - .stream() - .filter(f -> { - if (f.isAnnotationPresent(Profile.class) - && !env.acceptsProfiles(f.getAnnotation(Profile.class).value())) { - return false; - } - return true; - }) - .collect(Collectors.toList()); + List<Class<? extends T>> filtersList = filters.stream().filter(f -> { + if (f.isAnnotationPresent(Profile.class) + && !env.acceptsProfiles(f.getAnnotation(Profile.class).value())) { + return false; + } + return true; + }).collect(Collectors.toList()); // Sort them by their priority levels value - filtersList.sort((c1, c2) -> Integer.valueOf(c1.getAnnotation(Priority.class).value()).compareTo(c2.getAnnotation(Priority.class).value())); + filtersList.sort((c1, c2) -> Integer.valueOf(c1.getAnnotation(Priority.class).value()) + .compareTo(c2.getAnnotation(Priority.class).value())); // Then register this to the jersey application filtersList.forEach(this::register); } - } |