2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved.
6 * Copyright © 2017-2018 Amdocs
7 * ================================================================================
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
19 * ============LICENSE_END=========================================================
21 package org.onap.aai.sparky.config.oxm;
25 import org.eclipse.persistence.jaxb.dynamic.DynamicJAXBContext;
26 import org.onap.aai.cl.api.Logger;
27 import org.onap.aai.cl.eelf.LoggerFactory;
28 import org.onap.aai.nodes.NodeIngestor;
29 import org.onap.aai.setup.SchemaVersion;
30 import org.onap.aai.setup.SchemaVersions;
31 import org.onap.aai.sparky.logging.AaiUiMsgs;
32 import org.springframework.beans.factory.annotation.Autowired;
33 import org.springframework.stereotype.Component;
35 @Component("oxmModelLoader")
36 public class OxmModelLoader {
38 private static final Logger LOG = LoggerFactory.getInstance().getLogger(OxmModelLoader.class);
41 * The intent of this parameter is to be able to programmatically over-ride the latest AAI schema
42 * version discovered from the aai-schema jar file. This property is optional, but if set on the
43 * bean or by another class in the system, then it will override the spec version that is loaded.
45 * If the latestVersionOverride is greater than 0 then it will set the latest version to the
46 * specified version, and that stream will be returned if available.
49 protected SchemaVersion oxmApiVersion;
50 protected Set<OxmModelProcessor> processors;
52 private NodeIngestor nodeIngestor;
54 public OxmModelLoader(String apiVersionOverride, Set<OxmModelProcessor> oxmModelProcessors) {
55 this.oxmApiVersion = new SchemaVersion(apiVersionOverride);
56 this.processors = oxmModelProcessors;
59 public OxmModelLoader(Set<OxmModelProcessor> oxmModelProcessors, SchemaVersions schemaVersions) {
60 this.oxmApiVersion = schemaVersions.getDefaultVersion();
61 this.processors = oxmModelProcessors;
64 public SchemaVersion getOxmApiVersion() {
70 public NodeIngestor getNodeIngestor() {
75 public void setNodeIngestor(NodeIngestor nodeIngestor) {
76 this.nodeIngestor = nodeIngestor;
82 * @param inputStream file handle for oxm
84 public void loadModel() {
86 final DynamicJAXBContext oxmContext = nodeIngestor.getContextForVersion(oxmApiVersion);
87 parseOxmContext(oxmContext);
88 // populateSearchableOxmModel();
89 LOG.info(AaiUiMsgs.OXM_LOAD_SUCCESS, String.valueOf(oxmApiVersion));
90 } catch (Exception exc) {
91 LOG.info(AaiUiMsgs.OXM_PARSE_ERROR_NONVERBOSE);
92 LOG.error(AaiUiMsgs.OXM_PARSE_ERROR_VERBOSE, "OXM v" + oxmApiVersion, exc.getMessage());
97 * Parses the oxm context.
99 * @param oxmContext the oxm context
101 private void parseOxmContext(DynamicJAXBContext oxmContext) {
103 if (processors != null && processors.size() > 0) {
105 for (OxmModelProcessor processor : processors) {
109 processor.processOxmModel(oxmContext);
111 } catch (Exception exc) {
113 LOG.warn(AaiUiMsgs.WARN_GENERIC,
114 "OxmModelProcessor experienced an error. Error: " + exc.getMessage());