aboutsummaryrefslogtreecommitdiffstats
path: root/aai-core/src
diff options
context:
space:
mode:
Diffstat (limited to 'aai-core/src')
-rw-r--r--aai-core/src/main/java/org/onap/aai/config/DmaapConfig.java110
-rw-r--r--aai-core/src/main/java/org/onap/aai/config/SpringContextAware.java42
-rw-r--r--aai-core/src/main/java/org/onap/aai/dmaap/AAIDmaapEventJMSProducer.java14
-rw-r--r--aai-core/src/main/java/org/onap/aai/dmaap/JMSConsumer.java160
-rw-r--r--aai-core/src/main/java/org/onap/aai/dmaap/JMSProducer.java58
-rw-r--r--aai-core/src/main/java/org/onap/aai/dmaap/MessageProducer.java29
-rw-r--r--aai-core/src/main/java/org/onap/aai/introspection/ModelInjestor.java31
-rw-r--r--aai-core/src/main/java/org/onap/aai/introspection/MoxyLoader.java18
-rw-r--r--aai-core/src/main/java/org/onap/aai/util/AAIApiServerURLBase.java35
-rw-r--r--aai-core/src/main/java/org/onap/aai/util/AAICSVWriter.java168
-rw-r--r--aai-core/src/main/java/org/onap/aai/util/AAIConfig.java9
-rw-r--r--aai-core/src/main/java/org/onap/aai/util/StoreNotificationEvent.java47
-rw-r--r--aai-core/src/test/java/org/onap/aai/introspection/sideeffect/DataCopyTest.java2
-rw-r--r--aai-core/src/test/java/org/onap/aai/util/AAICSVWriterTest.java77
-rw-r--r--aai-core/src/test/java/org/onap/aai/util/StoreNotificationEventTest.java2
-rw-r--r--aai-core/src/test/resources/oxm/aai_oxm_v10.xml (renamed from aai-core/src/test/resources/bundleconfig-local/etc/oxm/aai_oxm_v10.xml)0
-rw-r--r--aai-core/src/test/resources/oxm/aai_oxm_v11.xml (renamed from aai-core/src/test/resources/bundleconfig-local/etc/oxm/aai_oxm_v11.xml)0
-rw-r--r--aai-core/src/test/resources/oxm/aai_oxm_v12.xml (renamed from aai-core/src/test/resources/bundleconfig-local/etc/oxm/aai_oxm_v12.xml)14
-rw-r--r--aai-core/src/test/resources/oxm/aai_oxm_v8.xml (renamed from aai-core/src/test/resources/bundleconfig-local/etc/oxm/aai_oxm_v8.xml)0
-rw-r--r--aai-core/src/test/resources/oxm/aai_oxm_v9.xml (renamed from aai-core/src/test/resources/bundleconfig-local/etc/oxm/aai_oxm_v9.xml)0
-rw-r--r--aai-core/src/test/resources/oxm/sideeffect/nested-case.json (renamed from aai-core/src/test/resources/bundleconfig-local/etc/oxm/sideeffect/nested-case.json)0
21 files changed, 515 insertions, 301 deletions
diff --git a/aai-core/src/main/java/org/onap/aai/config/DmaapConfig.java b/aai-core/src/main/java/org/onap/aai/config/DmaapConfig.java
new file mode 100644
index 00000000..313775d9
--- /dev/null
+++ b/aai-core/src/main/java/org/onap/aai/config/DmaapConfig.java
@@ -0,0 +1,110 @@
+/**
+ * ============LICENSE_START=======================================================
+ * org.onap.aai
+ * ================================================================================
+ * Copyright © 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ *
+ * ECOMP is a trademark and service mark of AT&T Intellectual Property.
+ */
+package org.onap.aai.config;
+
+import org.apache.activemq.ActiveMQConnectionFactory;
+import org.apache.activemq.broker.BrokerService;
+import org.apache.activemq.command.ActiveMQQueue;
+import org.onap.aai.dmaap.JMSConsumer;
+import org.onap.aai.dmaap.JMSProducer;
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.context.annotation.Profile;
+import org.springframework.jms.connection.CachingConnectionFactory;
+import org.springframework.jms.core.JmsTemplate;
+import org.springframework.jms.listener.DefaultMessageListenerContainer;
+
+import javax.annotation.PostConstruct;
+
+@Profile("dmaap")
+@Configuration
+public class DmaapConfig {
+
+ @Value("${jms.bind.address}")
+ private String bindAddress;
+
+ @PostConstruct
+ public void init(){
+ System.setProperty("activemq.tcp.url", bindAddress);
+ }
+
+ @Bean(destroyMethod = "stop")
+ public BrokerService brokerService() throws Exception {
+
+ BrokerService broker = new BrokerService();
+ broker.addConnector(bindAddress);
+ broker.setPersistent(false);
+ broker.setUseJmx(false);
+ broker.setSchedulerSupport(false);
+ broker.start();
+
+ return broker;
+ }
+
+ @Bean(name = "connectionFactory")
+ public ActiveMQConnectionFactory activeMQConnectionFactory(){
+ return new ActiveMQConnectionFactory(bindAddress);
+ }
+
+ @Bean
+ public CachingConnectionFactory cachingConnectionFactory(){
+ return new CachingConnectionFactory(activeMQConnectionFactory());
+ }
+
+ @Bean(name = "destinationQueue")
+ public ActiveMQQueue activeMQQueue(){
+ return new ActiveMQQueue("IN_QUEUE");
+ }
+
+ @Bean
+ public JmsTemplate jmsTemplate(){
+ JmsTemplate jmsTemplate = new JmsTemplate();
+
+ jmsTemplate.setConnectionFactory(activeMQConnectionFactory());
+ jmsTemplate.setDefaultDestination(activeMQQueue());
+
+ return jmsTemplate;
+ }
+
+ @Bean
+ public JMSProducer jmsProducer(){
+ return new JMSProducer();
+ }
+
+ @Bean
+ public JMSConsumer jmsConsumer() throws Exception {
+ return new JMSConsumer();
+ }
+
+ @Bean
+ public DefaultMessageListenerContainer defaultMessageListenerContainer() throws Exception {
+
+ DefaultMessageListenerContainer messageListenerContainer = new DefaultMessageListenerContainer();
+
+ messageListenerContainer.setConnectionFactory(cachingConnectionFactory());
+ messageListenerContainer.setDestinationName("IN_QUEUE");
+ messageListenerContainer.setMessageListener(jmsConsumer());
+
+ return messageListenerContainer;
+ }
+}
diff --git a/aai-core/src/main/java/org/onap/aai/config/SpringContextAware.java b/aai-core/src/main/java/org/onap/aai/config/SpringContextAware.java
new file mode 100644
index 00000000..4ab9373a
--- /dev/null
+++ b/aai-core/src/main/java/org/onap/aai/config/SpringContextAware.java
@@ -0,0 +1,42 @@
+/**
+ * ============LICENSE_START=======================================================
+ * org.onap.aai
+ * ================================================================================
+ * Copyright © 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ *
+ * ECOMP is a trademark and service mark of AT&T Intellectual Property.
+ */
+package org.onap.aai.config;
+
+import org.springframework.beans.BeansException;
+import org.springframework.context.ApplicationContext;
+import org.springframework.context.ApplicationContextAware;
+import org.springframework.stereotype.Component;
+
+@Component
+public class SpringContextAware implements ApplicationContextAware {
+
+ private static ApplicationContext context = null;
+
+ public static ApplicationContext getApplicationContext() {
+ return context;
+ }
+
+ @Override
+ public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
+ context = applicationContext;
+ }
+}
diff --git a/aai-core/src/main/java/org/onap/aai/dmaap/AAIDmaapEventJMSProducer.java b/aai-core/src/main/java/org/onap/aai/dmaap/AAIDmaapEventJMSProducer.java
index 914042d4..a034b9fb 100644
--- a/aai-core/src/main/java/org/onap/aai/dmaap/AAIDmaapEventJMSProducer.java
+++ b/aai-core/src/main/java/org/onap/aai/dmaap/AAIDmaapEventJMSProducer.java
@@ -24,20 +24,24 @@ package org.onap.aai.dmaap;
import org.apache.activemq.ActiveMQConnectionFactory;
import org.apache.activemq.command.ActiveMQQueue;
import org.json.JSONObject;
+import org.onap.aai.config.SpringContextAware;
import org.onap.aai.util.AAIConfig;
+import org.springframework.context.ApplicationContext;
import org.springframework.jms.connection.CachingConnectionFactory;
import org.springframework.jms.core.JmsTemplate;
-public class AAIDmaapEventJMSProducer {
+public class AAIDmaapEventJMSProducer implements MessageProducer {
private JmsTemplate jmsTemplate;
+ private ApplicationContext applicationContext;
+
public AAIDmaapEventJMSProducer() {
if(AAIConfig.get("aai.jms.enable", "true").equals("true")){
- this.jmsTemplate = new JmsTemplate();
- String activeMqTcpUrl = System.getProperty("activemq.tcp.url", "tcp://localhost:61447");
- this.jmsTemplate.setConnectionFactory(new CachingConnectionFactory(new ActiveMQConnectionFactory(activeMqTcpUrl)));
- this.jmsTemplate.setDefaultDestination(new ActiveMQQueue("IN_QUEUE"));
+ this.jmsTemplate = new JmsTemplate();
+ String activeMqTcpUrl = System.getProperty("activemq.tcp.url", "tcp://localhost:61547");
+ this.jmsTemplate.setConnectionFactory(new CachingConnectionFactory(new ActiveMQConnectionFactory(activeMqTcpUrl)));
+ this.jmsTemplate.setDefaultDestination(new ActiveMQQueue("IN_QUEUE"));
}
}
diff --git a/aai-core/src/main/java/org/onap/aai/dmaap/JMSConsumer.java b/aai-core/src/main/java/org/onap/aai/dmaap/JMSConsumer.java
new file mode 100644
index 00000000..b7638876
--- /dev/null
+++ b/aai-core/src/main/java/org/onap/aai/dmaap/JMSConsumer.java
@@ -0,0 +1,160 @@
+/**
+ * ============LICENSE_START=======================================================
+ * org.onap.aai
+ * ================================================================================
+ * Copyright © 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ *
+ * ECOMP is a trademark and service mark of AT&T Intellectual Property.
+ */
+package org.onap.aai.dmaap;
+
+import com.att.eelf.configuration.EELFLogger;
+import com.att.eelf.configuration.EELFManager;
+import org.apache.log4j.MDC;
+import org.json.JSONException;
+import org.json.JSONObject;
+import org.onap.aai.config.SpringContextAware;
+import org.onap.aai.logging.LoggingContext.LoggingField;
+import org.onap.aai.logging.LoggingContext.StatusCode;
+import org.springframework.cloud.client.ServiceInstance;
+import org.springframework.cloud.client.loadbalancer.LoadBalancerClient;
+import org.springframework.core.env.Environment;
+import org.springframework.http.HttpEntity;
+import org.springframework.http.HttpHeaders;
+import org.springframework.http.HttpMethod;
+import org.springframework.http.MediaType;
+import org.springframework.web.client.RestTemplate;
+
+import javax.jms.JMSException;
+import javax.jms.Message;
+import javax.jms.MessageListener;
+import javax.jms.TextMessage;
+import java.util.Base64;
+import java.util.Collections;
+
+public class JMSConsumer implements MessageListener {
+
+ private static final EELFLogger LOGGER = EELFManager.getInstance().getLogger(JMSConsumer.class);
+
+ private static final int HTTPS_PORT = 3905;
+ private static final Base64.Encoder base64Encoder = Base64.getEncoder();
+
+ private HttpHeaders httpHeaders;
+ private RestTemplate restTemplate;
+
+ private Environment environment;
+ private LoadBalancerClient loadBalancerClient;
+
+ public JMSConsumer() throws Exception {
+ this((LoadBalancerClient)SpringContextAware.getApplicationContext().getBean("loadBalancerClient"));
+ }
+
+ public JMSConsumer(LoadBalancerClient loadBalancerClient) throws Exception {
+ this.loadBalancerClient = loadBalancerClient;
+ this.httpHeaders = new HttpHeaders();
+ this.httpHeaders.setAccept(Collections.singletonList(MediaType.APPLICATION_JSON));
+ this.environment = SpringContextAware.getApplicationContext().getEnvironment();
+
+ String username = this.environment.getProperty("dmaap.ribbon.username");
+ String password = this.environment.getProperty("dmaap.ribbon.password");
+
+ if(username == null || password == null){
+ throw new Exception("Unable to retrive username/password from the application properties");
+ }
+
+ String auth = String.format("%s:%s", username, password);
+ String authString = "Basic " + base64Encoder.encodeToString(auth.getBytes());
+ httpHeaders.add("Authorization", authString);
+
+ restTemplate = new RestTemplate();
+ }
+
+ @Override
+ public void onMessage(Message message) {
+
+ String jsmMessageTxt = "";
+ String aaiEvent = "";
+ String eventName = "";
+
+ String environment = System.getProperty("lrmRO");
+ if (environment == null) {
+ environment = "";
+ }
+
+ if (message instanceof TextMessage) {
+ try {
+ jsmMessageTxt = ((TextMessage) message).getText();
+ JSONObject jo = new JSONObject(jsmMessageTxt);
+
+ if (jo.has("aaiEventPayload")) {
+ aaiEvent = jo.getJSONObject("aaiEventPayload").toString();
+ } else {
+ return;
+ }
+ if (jo.getString("transId") != null) {
+ MDC.put("requestId", jo.getString("transId"));
+ }
+ if (jo.getString("fromAppId") != null) {
+ MDC.put("partnerName", jo.getString("fromAppId"));
+ }
+ MDC.put("targetEntity", "DMAAP");
+ if (jo.getString("event-topic") != null) {
+ eventName = jo.getString("event-topic");
+ MDC.put("targetServiceName", eventName);
+ }
+ MDC.put("serviceName", "AAI");
+ MDC.put(LoggingField.STATUS_CODE.toString(), StatusCode.COMPLETE.toString());
+ MDC.put(LoggingField.RESPONSE_CODE.toString(), "0");
+ LOGGER.info(eventName + "|" + aaiEvent);
+
+ HttpEntity<String> httpEntity = new HttpEntity<>(aaiEvent, httpHeaders);
+ ServiceInstance serviceInstance = loadBalancerClient.choose("dmaap");
+ String url = serviceInstance.getHost() + ":" + serviceInstance.getPort();
+
+ if(serviceInstance.getPort() == HTTPS_PORT){
+ url = "https://" + url;
+ } else {
+ url = "http://" + url;
+ }
+
+ url += "/events/" + eventName;
+
+ if ("AAI-EVENT".equals(eventName)) {
+ restTemplate.exchange(url, HttpMethod.POST, httpEntity, String.class);
+ LOGGER.info(eventName + "|Event sent.");
+ } else if ("AAI-VCE-INTERFACE-DATA".equals(eventName)) {
+ restTemplate.exchange(url, HttpMethod.POST, httpEntity, String.class);
+ String msg = "";
+ LOGGER.info(eventName + "|Event sent. " + msg);
+ } else {
+ MDC.put(LoggingField.STATUS_CODE.toString(), StatusCode.ERROR.toString());
+ MDC.put(LoggingField.RESPONSE_CODE.toString(), "900");
+ LOGGER.error(eventName + "|Event Topic invalid.");
+ }
+ } catch (JMSException | JSONException e) {
+ MDC.put(LoggingField.STATUS_CODE.toString(), StatusCode.ERROR.toString());
+ MDC.put(LoggingField.RESPONSE_CODE.toString(), "200");
+ LOGGER.error("AAI_7350 Error parsing aaievent jms message for sending to dmaap. " + jsmMessageTxt, e);
+ } catch (Exception e) {
+ MDC.put(LoggingField.STATUS_CODE.toString(), StatusCode.ERROR.toString());
+ MDC.put(LoggingField.RESPONSE_CODE.toString(), "200");
+ LOGGER.error("AAI_7350 Error sending message to dmaap. " + jsmMessageTxt, e);
+ }
+ }
+
+ }
+
+} \ No newline at end of file
diff --git a/aai-core/src/main/java/org/onap/aai/dmaap/JMSProducer.java b/aai-core/src/main/java/org/onap/aai/dmaap/JMSProducer.java
new file mode 100644
index 00000000..6dbfbb77
--- /dev/null
+++ b/aai-core/src/main/java/org/onap/aai/dmaap/JMSProducer.java
@@ -0,0 +1,58 @@
+/**
+ * ============LICENSE_START=======================================================
+ * org.onap.aai
+ * ================================================================================
+ * Copyright © 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ *
+ * ECOMP is a trademark and service mark of AT&T Intellectual Property.
+ */
+package org.onap.aai.dmaap;
+
+import org.apache.activemq.ActiveMQConnectionFactory;
+import org.apache.activemq.command.ActiveMQQueue;
+import org.json.JSONObject;
+import org.onap.aai.config.SpringContextAware;
+import org.onap.aai.util.AAIConfig;
+import org.springframework.context.ApplicationContext;
+import org.springframework.jms.connection.CachingConnectionFactory;
+import org.springframework.jms.core.JmsTemplate;
+
+public class JMSProducer implements MessageProducer {
+
+ private JmsTemplate jmsTemplate;
+
+ private ApplicationContext applicationContext;
+
+ public JMSProducer() {
+ if(AAIConfig.get("aai.jms.enable", "true").equals("true")){
+ applicationContext = SpringContextAware.getApplicationContext();
+ if(applicationContext == null){
+ this.jmsTemplate = new JmsTemplate();
+ String activeMqTcpUrl = System.getProperty("activemq.tcp.url", "tcp://localhost:61547");
+ this.jmsTemplate.setConnectionFactory(new CachingConnectionFactory(new ActiveMQConnectionFactory(activeMqTcpUrl)));
+ this.jmsTemplate.setDefaultDestination(new ActiveMQQueue("IN_QUEUE"));
+ } else {
+ jmsTemplate = (JmsTemplate) applicationContext.getBean("jmsTemplate");
+ }
+ }
+ }
+
+ public void sendMessageToDefaultDestination(JSONObject finalJson) {
+ if(jmsTemplate != null){
+ jmsTemplate.convertAndSend(finalJson.toString());
+ }
+ }
+}
diff --git a/aai-core/src/main/java/org/onap/aai/dmaap/MessageProducer.java b/aai-core/src/main/java/org/onap/aai/dmaap/MessageProducer.java
new file mode 100644
index 00000000..229ba1a5
--- /dev/null
+++ b/aai-core/src/main/java/org/onap/aai/dmaap/MessageProducer.java
@@ -0,0 +1,29 @@
+/**
+ * ============LICENSE_START=======================================================
+ * org.onap.aai
+ * ================================================================================
+ * Copyright © 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ *
+ * ECOMP is a trademark and service mark of AT&T Intellectual Property.
+ */
+package org.onap.aai.dmaap;
+
+import org.json.JSONObject;
+
+public interface MessageProducer {
+
+ void sendMessageToDefaultDestination(JSONObject finalJson);
+}
diff --git a/aai-core/src/main/java/org/onap/aai/introspection/ModelInjestor.java b/aai-core/src/main/java/org/onap/aai/introspection/ModelInjestor.java
index c670e946..524dcbf0 100644
--- a/aai-core/src/main/java/org/onap/aai/introspection/ModelInjestor.java
+++ b/aai-core/src/main/java/org/onap/aai/introspection/ModelInjestor.java
@@ -21,6 +21,8 @@
*/
package org.onap.aai.introspection;
+import com.att.eelf.configuration.EELFLogger;
+import com.att.eelf.configuration.EELFManager;
import org.eclipse.persistence.dynamic.DynamicType;
import org.eclipse.persistence.jaxb.JAXBContextProperties;
import org.eclipse.persistence.jaxb.dynamic.DynamicJAXBContext;
@@ -42,6 +44,7 @@ public class ModelInjestor {
private Map<Version, DynamicJAXBContext> versionContextMap = new HashMap<>();
private static final Pattern classNamePattern = Pattern.compile("\\.(v\\d+)\\.");
private static final Pattern uriPattern = Pattern.compile("(v\\d+)\\/");
+ private static final EELFLogger LOGGER = EELFManager.getInstance().getLogger(ModelInjestor.class);
/**
@@ -90,8 +93,24 @@ public class ModelInjestor {
*/
private void injestModel (Version version) throws JAXBException, FileNotFoundException {
String fileName = this.getOXMFileName(version);
- InputStream iStream = new FileInputStream(new File(fileName));
- Map<String, Object> properties = new HashMap<String, Object>();
+
+ File oxmFile = new File(AAIConstants.AAI_HOME_ETC + fileName);
+
+ // Check if the file exists on the path and if it doesn't exist then
+ // Using classloader makes it easy to have a different oxm file
+ // for unit testing the oxm files otherwise, you will be
+ // stuck with using the main oxm for even the testing
+
+ InputStream iStream;
+ if(oxmFile.exists()){
+ LOGGER.info("Oxm file exists on the system {}", oxmFile);
+ iStream = new FileInputStream(oxmFile);
+ } else {
+ LOGGER.warn("Unable to find oxm file {} on the system so using classloader", oxmFile);
+ iStream = getClass().getClassLoader().getResourceAsStream(fileName);
+ }
+
+ Map<String, Object> properties = new HashMap<String, Object>();
properties.put(JAXBContextProperties.OXM_METADATA_SOURCE, iStream);
final DynamicJAXBContext jaxbContext = DynamicJAXBContextFactory.createContextFromOXM(this.getClass().getClassLoader(), properties);
versionContextMap.put(version, jaxbContext);
@@ -168,7 +187,13 @@ public class ModelInjestor {
}
public String getOXMFileName(Version v) {
- return AAIConstants.AAI_HOME_ETC_OXM + "aai_oxm_" + v.toString() + ".xml";
+ // Changed the /oxm/aai_oxm_*.xml to oxm/aai_oxm_*.xml
+ // Modified to load from input stream using getClass().getClassLoader()
+ // As this will be able to relatively get the oxm if the oxm file is there
+ // So if there is a src/main/resources/oxm/ and src/test/resources/oxm, the
+ // test oxm will end up being used for tests and src oxm for source files
+ // Don't change this unless you understand the details specified
+ return "oxm/aai_oxm_" + v.toString() + ".xml";
}
}
diff --git a/aai-core/src/main/java/org/onap/aai/introspection/MoxyLoader.java b/aai-core/src/main/java/org/onap/aai/introspection/MoxyLoader.java
index 56ad2dc2..a2a673ec 100644
--- a/aai-core/src/main/java/org/onap/aai/introspection/MoxyLoader.java
+++ b/aai-core/src/main/java/org/onap/aai/introspection/MoxyLoader.java
@@ -34,6 +34,7 @@ import org.onap.aai.introspection.exceptions.AAIUnmarshallingException;
import org.onap.aai.logging.ErrorLogHelper;
import org.onap.aai.logging.LogFormatTools;
import org.onap.aai.restcore.MediaType;
+import org.onap.aai.util.AAIConstants;
import org.onap.aai.workarounds.NamingExceptions;
import org.w3c.dom.Document;
import org.w3c.dom.NodeList;
@@ -46,8 +47,7 @@ import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.transform.stream.StreamSource;
-import java.io.IOException;
-import java.io.StringReader;
+import java.io.*;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
@@ -176,7 +176,19 @@ public class MoxyLoader extends Loader {
docFactory.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, true);
final DocumentBuilder docBuilder = docFactory.newDocumentBuilder();
- final Document doc = docBuilder.parse(fileName);
+
+ InputStream inputStream;
+ File oxmFile = new File(AAIConstants.AAI_HOME_ETC + fileName);
+
+ if(oxmFile.exists()){
+ LOGGER.info("Oxm file exists on the system {}", oxmFile);
+ inputStream = new FileInputStream(oxmFile);
+ } else {
+ LOGGER.warn("Unable to find oxm file {} on the system so using classloader", oxmFile);
+ inputStream = getClass().getClassLoader().getResourceAsStream(fileName);
+ }
+
+ final Document doc = docBuilder.parse(inputStream);
final NodeList list = doc.getElementsByTagName("java-type");
for (int i = 0; i < list.getLength(); i++) {
diff --git a/aai-core/src/main/java/org/onap/aai/util/AAIApiServerURLBase.java b/aai-core/src/main/java/org/onap/aai/util/AAIApiServerURLBase.java
index e458c4f9..68869909 100644
--- a/aai-core/src/main/java/org/onap/aai/util/AAIApiServerURLBase.java
+++ b/aai-core/src/main/java/org/onap/aai/util/AAIApiServerURLBase.java
@@ -21,13 +21,6 @@
*/
package org.onap.aai.util;
-import java.util.List;
-import java.util.Map;
-
-import org.apache.cxf.helpers.CastUtils;
-import org.apache.cxf.message.Message;
-import org.apache.cxf.phase.PhaseInterceptorChain;
-
import org.onap.aai.exceptions.AAIException;
import org.onap.aai.introspection.Version;
@@ -42,20 +35,20 @@ public class AAIApiServerURLBase {
public static String get() throws AAIException {
String hostName = null;
- try {
- Message message = PhaseInterceptorChain.getCurrentMessage();
- Map<String, List<String>> headers = CastUtils.cast((Map) message.get(Message.PROTOCOL_HEADERS));
- List sa = null;
- if (headers != null) {
- sa = headers.get("host");
- }
-
- if (sa != null && sa.size() == 1) {
- hostName = "https://"+ sa.get(0).toString() + "/aai/";
- }
- } catch (Exception e) {
- // TODO: we may want to log an error here
- }
+// try {
+// Message message = PhaseInterceptorChain.getCurrentMessage();
+// Map<String, List<String>> headers = CastUtils.cast((Map) message.get(Message.PROTOCOL_HEADERS));
+// List sa = null;
+// if (headers != null) {
+// sa = headers.get("host");
+// }
+//
+// if (sa != null && sa.size() == 1) {
+// hostName = "https://"+ sa.get(0).toString() + "/aai/";
+// }
+// } catch (Exception e) {
+// // TODO: we may want to log an error here
+// }
// TODO: should this check the value a little closer and look for a pattern?
if (hostName == null) {
hostName = AAIConfig.get(AAIConstants.AAI_SERVER_URL_BASE);
diff --git a/aai-core/src/main/java/org/onap/aai/util/AAICSVWriter.java b/aai-core/src/main/java/org/onap/aai/util/AAICSVWriter.java
deleted file mode 100644
index c091fc24..00000000
--- a/aai-core/src/main/java/org/onap/aai/util/AAICSVWriter.java
+++ /dev/null
@@ -1,168 +0,0 @@
-/**
- * ============LICENSE_START=======================================================
- * org.onap.aai
- * ================================================================================
- * Copyright © 2017 AT&T Intellectual Property. All rights reserved.
- * ================================================================================
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- * ============LICENSE_END=========================================================
- *
- * ECOMP is a trademark and service mark of AT&T Intellectual Property.
- */
-/**
- *
- */
-package org.onap.aai.util;
-
-import java.io.IOException;
-import java.io.PrintWriter;
-import java.io.Writer;
-
-import com.opencsv.CSVWriter;
-
-/**
- * had to overwrite the separate character to separate string
- * Based on the public - A very simple CSV writer released under a commercial-friendly license.
- *
-
- */
-public class AAICSVWriter extends CSVWriter {
-
- private String separatorStr;
- private char overridequotechar;
- private String overridelineEnd;
- private Writer rawWriter;
- private PrintWriter pw;
-
- /**
- * Instantiates a new AAICSV writer.
- *
- * @param writer the writer
- */
- public AAICSVWriter(Writer writer) {
- super(writer);
- // TODO Auto-generated constructor stub
- }
-
- /**
- * Constructs AAICSVWriter with supplied separator string and quote char.
- *
- * @param writer the writer to an underlying CSV source.
- * @param overrideseparator the overrideseparator
- * @param quotechar the character to use for quoted elements
- * @param lineEnd the line feed terminator to use
- */
- public AAICSVWriter(Writer writer, String overrideseparator, char quotechar, String lineEnd) {
- super(writer, CSVWriter.DEFAULT_SEPARATOR, quotechar, DEFAULT_ESCAPE_CHARACTER, lineEnd);
- separatorStr = overrideseparator;
- overridequotechar = quotechar;
- overridelineEnd = lineEnd;
- this.rawWriter = writer;
- this.pw = new PrintWriter(writer);
- }
-
- /**
- * String contains special characters.
- *
- * @param line the line
- * @return true, if successful
- */
- private boolean stringContainsSpecialCharacters(String line) {
- return line.indexOf(overridequotechar) != -1 || line.indexOf(DEFAULT_ESCAPE_CHARACTER) != -1 || line.indexOf(separatorStr) != -1 || line.contains("\n") || line.contains("\r");
- }
-
- /**
- * Close the underlying stream writer flushing any buffered content.
- *
- * @throws IOException if bad things happen
- */
- public void close() throws IOException {
- flush();
- pw.close();
- rawWriter.close();
- }
-
- /**
- * Writes the next line to the file.
- *
- * @param nextLine a string array with each comma-separated element as a separate
- * entry.
- * @param applyQuotesToAll true if all values are to be quoted. false applies quotes only
- * to values which contain the separator, escape, quote or new line characters.
- */
- public void writeNext(String[] nextLine, boolean applyQuotesToAll) {
-
- if (nextLine == null)
- return;
-
- StringBuilder sb = new StringBuilder(INITIAL_STRING_SIZE);
- for (int i = 0; i < nextLine.length; i++) {
-
- if (i != 0) {
- sb.append(separatorStr);
- }
-
- String nextElement = nextLine[i];
-
- if (nextElement == null)
- continue;
-
- Boolean stringContainsSpecialCharacters = stringContainsSpecialCharacters(nextElement);
-
- if ((applyQuotesToAll || stringContainsSpecialCharacters) && overridequotechar != NO_QUOTE_CHARACTER)
- sb.append(overridequotechar);
-
- if (stringContainsSpecialCharacters) {
- sb.append(processLine(nextElement));
- } else {
- sb.append(nextElement);
- }
-
- if ((applyQuotesToAll || stringContainsSpecialCharacters) && overridequotechar != NO_QUOTE_CHARACTER)
- sb.append(overridequotechar);
- }
-
- sb.append(overridelineEnd);
- pw.write(sb.toString());
- }
-
-
- /**
- * Writes the next line to the file ignoring all exceptions.
- *
- * @param nextLine a string array with each comma-separated element as a separate
- * entry.
- */
- public void writeColumn(String[] nextLine) {
-
- if (nextLine == null)
- return;
-
- StringBuilder sb = new StringBuilder(INITIAL_STRING_SIZE);
- for (int i = 0; i < nextLine.length; i++) {
-
-
- String nextElement = nextLine[i];
-
- if (nextElement == null)
- continue;
-
- sb.append(nextElement);
-
-
- }
-
- sb.append(overridelineEnd);
- pw.write(sb.toString());
- }
-}
diff --git a/aai-core/src/main/java/org/onap/aai/util/AAIConfig.java b/aai-core/src/main/java/org/onap/aai/util/AAIConfig.java
index 57bf2cc7..6f904970 100644
--- a/aai-core/src/main/java/org/onap/aai/util/AAIConfig.java
+++ b/aai-core/src/main/java/org/onap/aai/util/AAIConfig.java
@@ -52,8 +52,6 @@ public class AAIConfig {
// this (probably) won't change between releases, put it in the config if it gets annoying...
private static HashMap<String,ArrayList<String>> defaultBools = new HashMap<String,ArrayList<String>>();
- private static Timer timer = new Timer();
-
/**
* Instantiates a new AAI config.
*/
@@ -123,13 +121,6 @@ public class AAIConfig {
}
/**
- * Cleanup.
- */
- public static void cleanup() {
- timer.cancel();
- }
-
- /**
* Gets the config file.
*
* @return the config file
diff --git a/aai-core/src/main/java/org/onap/aai/util/StoreNotificationEvent.java b/aai-core/src/main/java/org/onap/aai/util/StoreNotificationEvent.java
index 0ad33cb9..2a64e996 100644
--- a/aai-core/src/main/java/org/onap/aai/util/StoreNotificationEvent.java
+++ b/aai-core/src/main/java/org/onap/aai/util/StoreNotificationEvent.java
@@ -27,35 +27,70 @@ import java.util.UUID;
import javax.xml.bind.Marshaller;
+import com.att.eelf.configuration.EELFLogger;
+import com.att.eelf.configuration.EELFManager;
import org.eclipse.persistence.dynamic.DynamicEntity;
import org.eclipse.persistence.jaxb.dynamic.DynamicJAXBContext;
import org.json.JSONException;
import org.json.JSONObject;
+import org.onap.aai.config.SpringContextAware;
import org.onap.aai.dmaap.AAIDmaapEventJMSProducer;
+import org.onap.aai.dmaap.JMSProducer;
+import org.onap.aai.dmaap.MessageProducer;
import org.onap.aai.domain.notificationEvent.NotificationEvent;
import org.onap.aai.exceptions.AAIException;
import org.onap.aai.introspection.Introspector;
import org.onap.aai.introspection.Loader;
import org.onap.aai.introspection.exceptions.AAIUnknownObjectException;
+import org.springframework.beans.factory.NoSuchBeanDefinitionException;
+import org.springframework.context.ApplicationContext;
+import org.springframework.core.env.Environment;
public class StoreNotificationEvent {
- private AAIDmaapEventJMSProducer messageProducer;
+ private static final EELFLogger logger = EELFManager.getInstance().getLogger(StoreNotificationEvent.class);
+ private MessageProducer messageProducer;
private String fromAppId = "";
private String transId = "";
private final String transactionId;
private final String sourceOfTruth;
+
+ private ApplicationContext context;
+ private Environment env;
+
/**
* Instantiates a new store notification event.
*/
public StoreNotificationEvent(String transactionId, String sourceOfTruth) {
- this(new AAIDmaapEventJMSProducer(), transactionId, sourceOfTruth);
+ this.context = SpringContextAware.getApplicationContext();
+ // If the context is null then this is being invoked from
+ // non spring context so creating the jms producer each time
+ // Otherwise, get the jms producer from the spring context so
+ // no need to create a instance of this each time
+ // Also check if the environment has the dmaap profile
+ // TODO - Add the constants for profile so do this when adding the https two-way ssl and one way with basic auth
+ if(this.context == null){
+ this.messageProducer = new AAIDmaapEventJMSProducer();
+ } else {
+ env = context.getEnvironment();
+ if(env.acceptsProfiles("dmaap")){
+ try {
+ this.messageProducer = (JMSProducer)context.getBean("jmsProducer");
+ } catch(NoSuchBeanDefinitionException ex){
+ logger.error("Currently using the dmaap profile but still not able to find bean so check DmaapConfig", ex);
+ }
+ } else {
+ this.messageProducer = new AAIDmaapEventJMSProducer();
+ }
+ }
+ this.transactionId = transactionId;
+ this.sourceOfTruth = sourceOfTruth;
}
-
+
public StoreNotificationEvent(AAIDmaapEventJMSProducer producer, String transactionId, String sourceOfTruth) {
- this.messageProducer = producer;
- this.transactionId = transactionId;
- this.sourceOfTruth = sourceOfTruth;
+ this.messageProducer = producer;
+ this.transactionId = transactionId;
+ this.sourceOfTruth = sourceOfTruth;
}
/**
diff --git a/aai-core/src/test/java/org/onap/aai/introspection/sideeffect/DataCopyTest.java b/aai-core/src/test/java/org/onap/aai/introspection/sideeffect/DataCopyTest.java
index 7d3cafac..65a241f0 100644
--- a/aai-core/src/test/java/org/onap/aai/introspection/sideeffect/DataCopyTest.java
+++ b/aai-core/src/test/java/org/onap/aai/introspection/sideeffect/DataCopyTest.java
@@ -261,7 +261,7 @@ public class DataCopyTest {
private String getJsonString(String filename) throws IOException {
- FileInputStream is = new FileInputStream("src/test/resources/bundleconfig-local/etc/oxm/sideeffect/" + filename);
+ FileInputStream is = new FileInputStream("src/test/resources/oxm/sideeffect/" + filename);
String s = IOUtils.toString(is, "UTF-8");
IOUtils.closeQuietly(is);
diff --git a/aai-core/src/test/java/org/onap/aai/util/AAICSVWriterTest.java b/aai-core/src/test/java/org/onap/aai/util/AAICSVWriterTest.java
deleted file mode 100644
index b149e95f..00000000
--- a/aai-core/src/test/java/org/onap/aai/util/AAICSVWriterTest.java
+++ /dev/null
@@ -1,77 +0,0 @@
-/**
- * ============LICENSE_START=======================================================
- * org.onap.aai
- * ================================================================================
- * Copyright © 2017 AT&T Intellectual Property. All rights reserved.
- * ================================================================================
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- * ============LICENSE_END=========================================================
- *
- * ECOMP is a trademark and service mark of AT&T Intellectual Property.
- */
-package org.onap.aai.util;
-
-import java.io.File;
-import java.io.FileWriter;
-import java.io.IOException;
-
-import org.junit.Assert;
-import org.junit.Test;
-
-public class AAICSVWriterTest {
-
- private final String TEMP_DIR=System.getProperty("java.io.tmpdir")+"/test.csv";
-
- @Test
- public void writeFile() throws IOException
- {
-
-
- FileWriter fileWriter = new FileWriter(TEMP_DIR);
- AAICSVWriter aaicsvWriter = new AAICSVWriter(fileWriter, ",", '\'', null);
- aaicsvWriter.writeColumn(new String[]{"id", "name", null});
- aaicsvWriter.writeColumn(null);
- aaicsvWriter.writeNext(new String[]{"1", "Test1"}, true);
- aaicsvWriter.writeNext(new String[]{"1", "Test1"});
- aaicsvWriter.writeNext(new String[]{"1", "Test1"});
- aaicsvWriter.writeNext(new String[]{"1", "Test@"}, false);
- aaicsvWriter.writeNext(new String[]{"1", "Test1"});
- aaicsvWriter.writeNext(new String[]{"1", "Test1"});
- aaicsvWriter.writeNext(new String[]{"1", "Test1"});
- aaicsvWriter.writeNext(new String[]{"1", "Test1"});
- aaicsvWriter.writeNext(new String[]{"1", "Test1"});
- aaicsvWriter.writeNext(new String[]{"1", null});
- aaicsvWriter.writeNext(null);
- aaicsvWriter.close();
- File file = new File(TEMP_DIR);
- Assert.assertTrue("File shoud be exists", file.exists());
- }
-
- @Test
- public void writeFile1() throws IOException
- {
- FileWriter fileWriter = new FileWriter(TEMP_DIR);
- AAICSVWriter aaicsvWriter = new AAICSVWriter(fileWriter, ",", '\u0000', null);
- aaicsvWriter.writeNext(new String[]{"1", "Test1"}, true);
- aaicsvWriter.writeNext(new String[]{"1", "Tes\"t@"}, false);
- aaicsvWriter.writeNext(new String[]{"1", "Tes\t@"}, false);
- aaicsvWriter.writeNext(new String[]{"1", "Test,@"}, false);
- aaicsvWriter.writeNext(new String[]{"1", "Tes\n"}, false);
- aaicsvWriter.writeNext(new String[]{"1", "Tes\r"}, false);
- aaicsvWriter.writeNext(new String[]{"1", "Tes\u0000"}, false);
- aaicsvWriter.close();
- File file = new File(TEMP_DIR);
- Assert.assertTrue("File shoud be exists", file.exists());
-
- }
-}
diff --git a/aai-core/src/test/java/org/onap/aai/util/StoreNotificationEventTest.java b/aai-core/src/test/java/org/onap/aai/util/StoreNotificationEventTest.java
index 5c87b29e..0050c101 100644
--- a/aai-core/src/test/java/org/onap/aai/util/StoreNotificationEventTest.java
+++ b/aai-core/src/test/java/org/onap/aai/util/StoreNotificationEventTest.java
@@ -151,7 +151,7 @@ public class StoreNotificationEventTest extends AAISetup {
DynamicEntity obj = Mockito.mock(DynamicEntity.class);
DynamicJAXBContext notificationJaxbContext = Mockito.mock(DynamicJAXBContext.class);
ClassLoader cl = getClass().getClassLoader();
- InputStream is = cl.getResourceAsStream("bundleconfig-local/etc/oxm/aai_oxm_v11.xml");
+ InputStream is = cl.getResourceAsStream("oxm/aai_oxm_v11.xml");
Map<String, Object> properties = new HashMap<String, Object>();
properties.put(JAXBContextProperties.OXM_METADATA_SOURCE, is);
DynamicJAXBContext notificationJaxbContextReal = DynamicJAXBContextFactory.createContextFromOXM(cl, properties);
diff --git a/aai-core/src/test/resources/bundleconfig-local/etc/oxm/aai_oxm_v10.xml b/aai-core/src/test/resources/oxm/aai_oxm_v10.xml
index 51eaa349..51eaa349 100644
--- a/aai-core/src/test/resources/bundleconfig-local/etc/oxm/aai_oxm_v10.xml
+++ b/aai-core/src/test/resources/oxm/aai_oxm_v10.xml
diff --git a/aai-core/src/test/resources/bundleconfig-local/etc/oxm/aai_oxm_v11.xml b/aai-core/src/test/resources/oxm/aai_oxm_v11.xml
index 90d023ce..90d023ce 100644
--- a/aai-core/src/test/resources/bundleconfig-local/etc/oxm/aai_oxm_v11.xml
+++ b/aai-core/src/test/resources/oxm/aai_oxm_v11.xml
diff --git a/aai-core/src/test/resources/bundleconfig-local/etc/oxm/aai_oxm_v12.xml b/aai-core/src/test/resources/oxm/aai_oxm_v12.xml
index 2364cf82..4eff665e 100644
--- a/aai-core/src/test/resources/bundleconfig-local/etc/oxm/aai_oxm_v12.xml
+++ b/aai-core/src/test/resources/oxm/aai_oxm_v12.xml
@@ -5139,13 +5139,13 @@
</xml-properties>
<xml-root-element name="reserved-prop-names" />
<java-attributes>
- <xml-element java-attribute="lastModSourceOfTruth" name="last-mod-source-of-truth" type="java.lang.String" />
- <xml-element java-attribute="aaiNodeType" name="aai-node-type" type="java.lang.String" />
- <xml-element java-attribute="aaiCreatedTs" name="aai-created-ts" type="java.lang.Long" />
- <xml-element java-attribute="aaiUniqueKey" name="aai-unique-key" type="java.lang.String" />
- <xml-element java-attribute="aaiLastModTs" name="aai-last-mod-ts" type="java.lang.Long" />
- <xml-element java-attribute="sourceOfTruth" name="source-of-truth" type="java.lang.String" />
- <xml-element java-attribute="aaiUri" name="aai-uri" type="java.lang.String" />
+ <xml-element java-attribute="edgeLabel" name="edgeLabel" type="java.lang.String" />
+ <xml-element java-attribute="direction" name="direction" type="java.lang.String" />
+ <xml-element java-attribute="multiplicityRule" name="multiplicityRule" type="java.lang.String" />
+ <xml-element java-attribute="containsOtherV" name="contains-other-v" type="java.lang.String" />
+ <xml-element java-attribute="deleteOtherV" name="delete-other-v" type="java.lang.String" />
+ <xml-element java-attribute="svcinfra" name="SVC-INFRA" type="java.lang.String" />
+ <xml-element java-attribute="preventDelete" name="prevent-delete" type="java.lang.String" />
</java-attributes>
</java-type>
<java-type name="EdgePropNames">
diff --git a/aai-core/src/test/resources/bundleconfig-local/etc/oxm/aai_oxm_v8.xml b/aai-core/src/test/resources/oxm/aai_oxm_v8.xml
index d666b738..d666b738 100644
--- a/aai-core/src/test/resources/bundleconfig-local/etc/oxm/aai_oxm_v8.xml
+++ b/aai-core/src/test/resources/oxm/aai_oxm_v8.xml
diff --git a/aai-core/src/test/resources/bundleconfig-local/etc/oxm/aai_oxm_v9.xml b/aai-core/src/test/resources/oxm/aai_oxm_v9.xml
index ecffb2fc..ecffb2fc 100644
--- a/aai-core/src/test/resources/bundleconfig-local/etc/oxm/aai_oxm_v9.xml
+++ b/aai-core/src/test/resources/oxm/aai_oxm_v9.xml
diff --git a/aai-core/src/test/resources/bundleconfig-local/etc/oxm/sideeffect/nested-case.json b/aai-core/src/test/resources/oxm/sideeffect/nested-case.json
index 40a0493a..40a0493a 100644
--- a/aai-core/src/test/resources/bundleconfig-local/etc/oxm/sideeffect/nested-case.json
+++ b/aai-core/src/test/resources/oxm/sideeffect/nested-case.json