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.Version;
30 import org.onap.aai.sparky.logging.AaiUiMsgs;
32 public class OxmModelLoader {
34 private static final Logger LOG = LoggerFactory.getInstance().getLogger(OxmModelLoader.class);
37 * The intent of this parameter is to be able to programmatically over-ride the latest AAI schema
38 * version discovered from the aai-schema jar file. This property is optional, but if set on the
39 * bean or by another class in the system, then it will override the spec version that is loaded.
41 * If the latestVersionOverride is greater than 0 then it will set the latest version to the
42 * specified version, and that stream will be returned if available.
45 protected Version oxmApiVersion;
46 protected Set<OxmModelProcessor> processors;
48 private NodeIngestor nodeIngestor;
50 public OxmModelLoader(Version apiVersionOverride, Set<OxmModelProcessor> oxmModelProcessors,
51 NodeIngestor nodeIngestor) {
52 this.oxmApiVersion = apiVersionOverride;
53 this.processors = oxmModelProcessors;
54 this.nodeIngestor = nodeIngestor;
57 public OxmModelLoader(Set<OxmModelProcessor> oxmModelProcessors, NodeIngestor nodeIngestor) {
58 this.oxmApiVersion = Version.getLatest();
59 this.processors = oxmModelProcessors;
60 this.nodeIngestor = nodeIngestor;
63 public Version getLatestVersionNum() {
72 * @param inputStream file handle for oxm
74 public void loadModel() {
76 final DynamicJAXBContext oxmContext = nodeIngestor.getContextForVersion(oxmApiVersion);
77 parseOxmContext(oxmContext);
78 // populateSearchableOxmModel();
79 LOG.info(AaiUiMsgs.OXM_LOAD_SUCCESS, String.valueOf(oxmApiVersion));
80 } catch (Exception exc) {
81 LOG.info(AaiUiMsgs.OXM_PARSE_ERROR_NONVERBOSE);
82 LOG.error(AaiUiMsgs.OXM_PARSE_ERROR_VERBOSE, "OXM v" + oxmApiVersion, exc.getMessage());
87 * Parses the oxm context.
89 * @param oxmContext the oxm context
91 private void parseOxmContext(DynamicJAXBContext oxmContext) {
93 if (processors != null && processors.size() > 0) {
95 for (OxmModelProcessor processor : processors) {
99 processor.processOxmModel(oxmContext);
101 } catch (Exception exc) {
103 LOG.warn(AaiUiMsgs.WARN_GENERIC,
104 "OxmModelProcessor experienced an error. Error: " + exc.getMessage());