diff options
Diffstat (limited to 'aai-schema-service')
6 files changed, 160 insertions, 153 deletions
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 6e29d4a..a565298 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 @@ -7,9 +7,9 @@ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * + * <p> + * http://www.apache.org/licenses/LICENSE-2.0 + * <p> * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -17,29 +17,29 @@ * limitations under the License. * ============LICENSE_END========================================================= */ + package org.onap.aai.schemaservice.config; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; +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; import org.onap.aai.logging.ErrorObjectNotFoundException; import org.onap.aai.logging.LogFormatTools; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Value; import org.springframework.core.annotation.Order; import org.springframework.stereotype.Component; import org.springframework.web.filter.OncePerRequestFilter; -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 java.io.IOException; -import java.util.ArrayList; -import java.util.List; - /** * Responsible for dealing with uri that doesn't start with basePath * All of the other interceptors will handle any uri that starts with basePath @@ -60,7 +60,9 @@ public class ErrorHandler extends OncePerRequestFilter { } @Override - protected void doFilterInternal(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, FilterChain filterChain) throws ServletException, IOException { + protected void doFilterInternal(HttpServletRequest httpServletRequest, + HttpServletResponse httpServletResponse, + FilterChain filterChain) throws ServletException, IOException { String uri = httpServletRequest.getRequestURI(); @@ -102,14 +104,15 @@ 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()); + httpServletResponse.setStatus(object.getHTTPResponseCode().getStatusCode()); } catch (ErrorObjectNotFoundException e1) { - e1.printStackTrace(); + LOGGER.error("getErrorObject exception {}", LogFormatTools.getStackTop(e1)); } - httpServletResponse.setStatus(object.getHTTPResponseCode().getStatusCode()); httpServletResponse.setContentType(mediaTypeList.get(0).toString()); httpServletResponse.getWriter().write(message); httpServletResponse.getWriter().close(); @@ -125,14 +128,15 @@ 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()); + httpServletResponse.setStatus(object.getHTTPResponseCode().getStatusCode()); } catch (ErrorObjectNotFoundException e1) { - e1.printStackTrace(); + LOGGER.error("getErrorObject exception {}", LogFormatTools.getStackTop(e1)); } - httpServletResponse.setStatus(object.getHTTPResponseCode().getStatusCode()); httpServletResponse.setContentType(mediaTypeList.get(0).toString()); httpServletResponse.getWriter().write(message); httpServletResponse.getWriter().close(); 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 df1d91c..2f42309 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 @@ -7,9 +7,9 @@ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * + * <p> + * http://www.apache.org/licenses/LICENSE-2.0 + * <p> * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -17,6 +17,7 @@ * limitations under the License. * ============LICENSE_END========================================================= */ + package org.onap.aai.schemaservice.config; import java.io.File; @@ -38,95 +39,73 @@ import org.springframework.core.env.EnumerablePropertySource; import org.springframework.core.env.MapPropertySource; import org.springframework.core.env.PropertySource; -public class PropertyPasswordConfiguration implements ApplicationContextInitializer<ConfigurableApplicationContext> { +public class PropertyPasswordConfiguration + implements ApplicationContextInitializer<ConfigurableApplicationContext> { private static final Pattern decodePasswordPattern = Pattern.compile("password\\((.*?)\\)"); private PasswordDecoder passwordDecoder = new JettyPasswordDecoder(); - private static final Logger logger = LoggerFactory.getLogger(PropertyPasswordConfiguration.class.getName()); + private static final Logger logger = + LoggerFactory.getLogger(PropertyPasswordConfiguration.class.getName()); @Override public void initialize(ConfigurableApplicationContext applicationContext) { ConfigurableEnvironment environment = applicationContext.getEnvironment(); String certPath = environment.getProperty("server.certs.location"); - File passwordFile = null; - File passphrasesFile = null; - InputStream passwordStream = null; - InputStream passphrasesStream = null; Map<String, Object> sslProps = new LinkedHashMap<>(); // Override the passwords from application.properties if we find AAF certman files if (certPath != null) { - try { - passwordFile = new File(certPath + ".password"); - passwordStream = new FileInputStream(passwordFile); - - if (passwordStream != null) { - String keystorePassword = null; + File passwordFile = new File(certPath + ".password"); + try (InputStream passwordStream = new FileInputStream(passwordFile)) { + String keystorePassword = null; - keystorePassword = IOUtils.toString(passwordStream); - if (keystorePassword != null) { - keystorePassword = keystorePassword.trim(); - sslProps.put("server.ssl.key-store-password", keystorePassword); - } - else{ - logger.warn("Keystore password is null in AAF Certman password file"); - } + keystorePassword = IOUtils.toString(passwordStream); + if (keystorePassword != null) { + keystorePassword = keystorePassword.trim(); + sslProps.put("server.ssl.key-store-password", keystorePassword); } else { - logger.info("Not using AAF Certman password file"); + 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()); - } finally { - if (passwordStream != null) { - try { - passwordStream.close(); - } catch (Exception e) { - } - } + logger.warn( + "Not using AAF Certman password file " + passwordFile.getName() + " e=" + + e.getMessage()); } - try { - passphrasesFile = new File(certPath + ".passphrases"); - passphrasesStream = new FileInputStream(passphrasesFile); - if (passphrasesStream != null) { - String truststorePassword = null; - Properties passphrasesProps = new Properties(); - passphrasesProps.load(passphrasesStream); - truststorePassword = passphrasesProps.getProperty("cadi_truststore_password"); - if (truststorePassword != null) { - truststorePassword = truststorePassword.trim(); - sslProps.put("server.ssl.trust-store-password", truststorePassword); - } - else { - logger.warn("Truststore password is null in AAF Certman passphrases file"); - } + File passphrasesFile = new File(certPath + ".passphrases"); + try (InputStream passphrasesStream = new FileInputStream(passphrasesFile)) { + String truststorePassword = null; + Properties passphrasesProps = new Properties(); + passphrasesProps.load(passphrasesStream); + truststorePassword = passphrasesProps.getProperty("cadi_truststore_password"); + if (truststorePassword != null) { + truststorePassword = truststorePassword.trim(); + sslProps.put("server.ssl.trust-store-password", truststorePassword); } else { - logger.info("Not using AAF Certman passphrases file"); + 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()); - } finally { - if (passphrasesStream != null) { - try { - passphrasesStream.close(); - } catch (Exception e) { - } - } + logger.warn( + "Not using AAF Certman passphrases file " + passphrasesFile.getName() + " e=" + + e.getMessage()); } } for (PropertySource<?> propertySource : environment.getPropertySources()) { Map<String, Object> propertyOverrides = new LinkedHashMap<>(); decodePasswords(propertySource, propertyOverrides); if (!propertyOverrides.isEmpty()) { - PropertySource<?> decodedProperties = new MapPropertySource("decoded "+ propertySource.getName(), propertyOverrides); - environment.getPropertySources().addBefore(propertySource.getName(), decodedProperties); + PropertySource<?> decodedProperties = + new MapPropertySource("decoded " + propertySource.getName(), propertyOverrides); + environment.getPropertySources() + .addBefore(propertySource.getName(), decodedProperties); } } if (!sslProps.isEmpty()) { logger.info("Using AAF Certman files"); - PropertySource<?> additionalProperties = new MapPropertySource("additionalProperties", sslProps); + PropertySource<?> additionalProperties = + new MapPropertySource("additionalProperties", sslProps); environment.getPropertySources().addFirst(additionalProperties); } @@ -134,7 +113,8 @@ public class PropertyPasswordConfiguration implements ApplicationContextInitiali private void decodePasswords(PropertySource<?> source, Map<String, Object> propertyOverrides) { if (source instanceof EnumerablePropertySource) { - EnumerablePropertySource<?> enumerablePropertySource = (EnumerablePropertySource<?>) source; + EnumerablePropertySource<?> enumerablePropertySource = + (EnumerablePropertySource<?>) source; for (String key : enumerablePropertySource.getPropertyNames()) { Object rawValue = source.getProperty(key); if (rawValue instanceof String) { @@ -146,7 +126,9 @@ public class PropertyPasswordConfiguration implements ApplicationContextInitiali } private String decodePasswordsInString(String input) { - if (input == null) return null; + if (input == null) { + return null; + } StringBuffer output = new StringBuffer(); Matcher matcher = decodePasswordPattern.matcher(input); while (matcher.find()) { 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 8b03ac2..d987171 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 @@ -63,23 +63,19 @@ public class InvalidResponseStatus extends AAIContainerFilter implements Contain message = ErrorLogHelper.getRESTAPIErrorResponse(mediaTypeList, e, templateVars); responseContext.setEntity(message); - } - - else if (responseContext.getStatus() == 406) { + } else if (responseContext.getStatus() == 406) { responseContext.setStatus(406); mediaTypeList.add(MediaType.valueOf(contentType)); - if (contentType.equals(MediaType.APPLICATION_XML)) { + if (contentType == null) { + mediaTypeList.add(MediaType.APPLICATION_XML_TYPE); + e = new AAIException("AAI_3019", "null"); + } else if (contentType.equals(MediaType.APPLICATION_XML)) { e = new AAIException("AAI_3019", MediaType.APPLICATION_XML); } else if (contentType.equals(MediaType.APPLICATION_JSON)) { e = new AAIException("AAI_3019", MediaType.APPLICATION_JSON); } else { - if (contentType == null) { - mediaTypeList.add(MediaType.APPLICATION_XML_TYPE); - e = new AAIException("AAI_3019", "null"); - } else { - mediaTypeList.add(MediaType.valueOf(contentType)); - e = new AAIException("AAI_3019", contentType); - } + mediaTypeList.add(MediaType.valueOf(contentType)); + e = new AAIException("AAI_3019", contentType); } message = ErrorLogHelper.getRESTAPIErrorResponse(mediaTypeList, e, templateVars); responseContext.setEntity(message); 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 6e3848c..76d14b6 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 @@ -7,9 +7,9 @@ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * + * <p> + * http://www.apache.org/licenses/LICENSE-2.0 + * <p> * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -17,25 +17,28 @@ * limitations under the License. * ============LICENSE_END========================================================= */ -package org.onap.aai.schemaservice.interceptors.post; -import org.onap.aai.schemaservice.interceptors.AAIContainerFilter; -import org.onap.aai.schemaservice.interceptors.AAIHeaderProperties; +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 java.io.IOException; +import org.onap.aai.schemaservice.interceptors.AAIContainerFilter; +import org.onap.aai.schemaservice.interceptors.AAIHeaderProperties; @Priority(AAIResponseFilterPriority.HEADER_MANIPULATION) -public class ResponseHeaderManipulation extends AAIContainerFilter implements ContainerResponseFilter { +public class ResponseHeaderManipulation extends AAIContainerFilter + implements ContainerResponseFilter { private static final String DEFAULT_XML_TYPE = MediaType.APPLICATION_XML; + private static final String CONTENT_TYPE_HEADER = "Content-Type"; @Override - public void filter(ContainerRequestContext requestContext, ContainerResponseContext responseContext) + public void filter(ContainerRequestContext requestContext, + ContainerResponseContext responseContext) throws IOException { updateResponseHeaders(requestContext, responseContext); @@ -45,17 +48,17 @@ public class ResponseHeaderManipulation extends AAIContainerFilter implements Co private void updateResponseHeaders(ContainerRequestContext requestContext, ContainerResponseContext responseContext) { - responseContext.getHeaders().add(AAIHeaderProperties.AAI_TX_ID, requestContext.getProperty(AAIHeaderProperties.AAI_TX_ID)); + responseContext.getHeaders().add(AAIHeaderProperties.AAI_TX_ID, + requestContext.getProperty(AAIHeaderProperties.AAI_TX_ID)); - String responseContentType = responseContext.getHeaderString("Content-Type"); + String responseContentType = responseContext.getHeaderString(CONTENT_TYPE_HEADER); if (responseContentType == null) { String acceptType = requestContext.getHeaderString("Accept"); - if (acceptType == null || "*/*".equals(acceptType)) { - responseContext.getHeaders().putSingle("Content-Type", DEFAULT_XML_TYPE); + responseContext.getHeaders().putSingle(CONTENT_TYPE_HEADER, DEFAULT_XML_TYPE); } else { - responseContext.getHeaders().putSingle("Content-Type", acceptType); + responseContext.getHeaders().putSingle(CONTENT_TYPE_HEADER, acceptType); } } 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 10f0e61..11f3737 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 @@ -98,7 +98,7 @@ public class ResponseTransactionLogging extends AAIContainerFilter implements Co final RequestAttributes requestAttributes = RequestContextHolder.getRequestAttributes(); if (requestAttributes != null) { HttpServletResponse response = ((ServletRequestAttributes) requestAttributes).getResponse(); - return response.getContentType(); + return response == null ? null : response.getContentType(); } return null; } 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 2c32985..8beb537 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 @@ -17,17 +17,41 @@ * limitations under the License. * ============LICENSE_END========================================================= */ + package org.onap.aai.schemaservice.nodeschema; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; 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; +import java.io.FileNotFoundException; +import java.io.IOException; +import java.io.InputStream; +import java.nio.charset.StandardCharsets; +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashMap; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Map.Entry; +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; import org.onap.aai.schemaservice.config.ConfigTranslator; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; import org.w3c.dom.Document; @@ -36,18 +60,6 @@ import org.w3c.dom.Node; import org.w3c.dom.NodeList; import org.xml.sax.SAXException; -import javax.xml.XMLConstants; -import jakarta.xml.bind.JAXBException; -import javax.xml.parsers.DocumentBuilder; -import javax.xml.parsers.DocumentBuilderFactory; -import javax.xml.parsers.ParserConfigurationException; -import java.io.*; -import java.nio.charset.StandardCharsets; -import java.util.*; -import java.util.Map.Entry; -import java.util.regex.Matcher; -import java.util.regex.Pattern; - /** * NodeIngestor - ingests A&AI OXM files per given config, serves DynamicJAXBContext per version */ @@ -96,7 +108,8 @@ public class NodeIngestor { * @throws FileNotFoundException if an OXM file can't be found * @throws JAXBException if there's an error creating the DynamicJAXBContext */ - private DynamicJAXBContext ingest(List<String> files) throws FileNotFoundException, JAXBException { + private DynamicJAXBContext ingest(List<String> files) + throws FileNotFoundException, JAXBException { List<InputStream> streams = new ArrayList<>(); for (String name : files) { @@ -105,11 +118,13 @@ 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 { + private Set<String> getAllNodeTypes(List<String> files) + throws ParserConfigurationException, SAXException, IOException { Set<String> types = new HashSet<>(); final DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance(); docFactory.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, true); @@ -138,7 +153,8 @@ public class NodeIngestor { return types; } - private Document createCombinedSchema(List<String> files, SchemaVersion v) throws ParserConfigurationException, SAXException, IOException { + private Document createCombinedSchema(List<String> files, SchemaVersion v) + throws ParserConfigurationException, SAXException, IOException { final DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance(); docFactory.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, true); docFactory.setFeature("http://apache.org/xml/features/disallow-doctype-decl", true); @@ -150,7 +166,8 @@ public class NodeIngestor { DocumentBuilder masterDocBuilder = docFactory.newDocumentBuilder(); Document combinedDoc = masterDocBuilder.parse(getShell(v)); NodeList masterList = combinedDoc.getElementsByTagName("java-types"); - Node javaTypesContainer = masterList.getLength() == 0 ? combinedDoc.getDocumentElement() : masterList.item(0); + Node javaTypesContainer = + masterList.getLength() == 0 ? combinedDoc.getDocumentElement() : masterList.item(0); Multimap<String, Node> nodeMultimap = ArrayListMultimap.create(); LOGGER.debug("Started combining the schema from list of files {} for version {}", files, v); @@ -161,7 +178,7 @@ public class NodeIngestor { final Document doc = docBuilder.parse(inputStream); final NodeList list = doc.getElementsByTagName("java-type"); - for(int i = 0; i < list.getLength(); i++){ + for (int i = 0; i < list.getLength(); i++) { Node curNode = list.item(i); String name = curNode.getAttributes().getNamedItem("name").getNodeValue(); nodeMultimap.put(name, curNode); @@ -176,41 +193,51 @@ public class NodeIngestor { return combinedDoc; } - private void createNode(Document combinedDoc, Node javaTypesContainer, Map<String, Collection<Node>> map){ + private void createNode(Document combinedDoc, Node javaTypesContainer, + Map<String, Collection<Node>> map) { for (Entry<String, Collection<Node>> entry : map.entrySet()) { - List<Node> listOfNodes = (List<Node>)entry.getValue(); + List<Node> listOfNodes = (List<Node>) entry.getValue(); LOGGER.trace("NodeType {} Occurrences {}", entry.getKey(), listOfNodes.size()); Node copyOfFirstElement = null; Node javaAttributeElement = null; - if(listOfNodes.size() > 1){ - for(int index = 0; index < listOfNodes.size(); index++){ - if(index == 0){ + if (listOfNodes.size() > 1) { + for (int index = 0; index < listOfNodes.size(); index++) { + if (index == 0) { Node currentNode = listOfNodes.get(index); copyOfFirstElement = combinedDoc.importNode(currentNode, true); - if(copyOfFirstElement.getNodeType() == Node.ELEMENT_NODE){ + if (copyOfFirstElement.getNodeType() == Node.ELEMENT_NODE) { Element element = (Element) copyOfFirstElement; - NodeList javaAttributesList = element.getElementsByTagName("java-attributes"); - for(int javaAttributeIndex = 0; javaAttributeIndex < javaAttributesList.getLength(); javaAttributeIndex++){ + NodeList javaAttributesList = + element.getElementsByTagName("java-attributes"); + for (int javaAttributeIndex = 0; + javaAttributeIndex < javaAttributesList.getLength(); + javaAttributeIndex++) { javaAttributeElement = javaAttributesList.item(javaAttributeIndex); } } } else { Node currentNode = listOfNodes.get(index); Node copyOfCurrentElement = combinedDoc.importNode(currentNode, true); - if(copyOfCurrentElement.getNodeType() == Node.ELEMENT_NODE){ + if (copyOfCurrentElement.getNodeType() == Node.ELEMENT_NODE) { Element element = (Element) copyOfCurrentElement; - NodeList javaAttributesList = element.getElementsByTagName("java-attributes"); - for(int javaAttributeIndex = 0; javaAttributeIndex < javaAttributesList.getLength(); javaAttributeIndex++){ + NodeList javaAttributesList = + element.getElementsByTagName("java-attributes"); + 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++){ - if(javaAttributeElement != null){ + for (int xmlElementIndex = 0; + xmlElementIndex < xmlElementList.getLength(); + xmlElementIndex++) { + if (javaAttributeElement != null) { Node curElem = xmlElementList.item(xmlElementIndex); - if(curElem != null){ - javaAttributeElement.appendChild(curElem.cloneNode(true)); + if (curElem != null) { + javaAttributeElement + .appendChild(curElem.cloneNode(true)); } } } @@ -220,7 +247,7 @@ public class NodeIngestor { } } javaTypesContainer.appendChild(copyOfFirstElement); - } else if(listOfNodes.size() == 1){ + } else if (listOfNodes.size() == 1) { javaTypesContainer.appendChild(combinedDoc.importNode(listOfNodes.get(0), true)); } } @@ -251,22 +278,17 @@ public class NodeIngestor { return typesPerVersion.get(v); } - /** - * 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 - * @return - */ public Document getSchema(SchemaVersion v) { return schemaPerVersion.get(v); } 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-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-ns namespace-uri=\"http://org.onap.aai.inventory/" + + v.toString().toLowerCase() + "\" />\n" + " </xml-schema>\n" + " <java-types>\n" + " </java-types>\n" + |