2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Copyright (C) 2017 Amdocs
8 * =============================================================================
9 * Licensed under the Apache License, Version 2.0 (the "License");
10 * you may not use this file except in compliance with the License.
11 * You may obtain a copy of the License at
13 * http://www.apache.org/licenses/LICENSE-2.0
15 * Unless required by applicable law or agreed to in writing, software
16 * distributed under the License is distributed on an "AS IS" BASIS,
17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * See the License for the specific language governing permissions and
19 * limitations under the License.
21 * ECOMP is a trademark and service mark of AT&T Intellectual Property.
22 * ============LICENSE_END=========================================================
25 package org.onap.sdnc.dg.loader;
28 import java.util.ArrayList;
29 import java.util.List;
30 import org.apache.commons.io.FileUtils;
31 import org.apache.commons.lang.StringUtils;
32 import org.slf4j.Logger;
33 import org.slf4j.LoggerFactory;
34 import org.onap.ccsdk.sli.core.sli.SvcLogicException;
35 import org.onap.ccsdk.sli.core.sli.SvcLogicParser;
36 import org.onap.ccsdk.sli.core.sli.SvcLogicStore;
37 import org.onap.ccsdk.sli.core.sli.SvcLogicStoreFactory;
39 public class DGXMLLoad {
40 private final static Logger logger = LoggerFactory.getLogger(DGXMLLoad.class);
41 private final SvcLogicStore store;
42 public static String STRING_ENCODING = "utf-8";
44 public DGXMLLoad(String propfile) throws Exception {
45 if (StringUtils.isBlank(propfile)) {
46 throw new Exception(propfile + " Profile file is not defined");
48 this.store = SvcLogicStoreFactory.getSvcLogicStore(propfile);
51 protected DGXMLLoad(SvcLogicStore store) throws Exception {
55 public void loadDGXMLFile(String dgXMLpath) throws SvcLogicException {
56 if (dgXMLpath != null) {
57 SvcLogicParser.load(dgXMLpath, this.store);
61 private void loadDGXMLDir(String xmlPath) throws Exception {
64 "******************** Loading DG into Database *****************************");
65 List<String> errors = new ArrayList<String>();
66 if (this.store != null) {
67 File xmlDir = new File(xmlPath);
68 if (xmlDir != null && xmlDir.isDirectory()) {
69 String[] extensions = new String[] {"xml", "XML"};
70 List<File> files = (List<File>) FileUtils.listFiles(xmlDir, extensions, true);
71 for (File file : files) {
72 logger.info("Loading DG XML file :" + file.getCanonicalPath());
74 SvcLogicParser.load(file.getCanonicalPath(), this.store);
75 } catch (Exception e) {
76 errors.add("Failed to load XML " + file.getCanonicalPath()
77 + ", Exception : " + e.getMessage());
81 throw new Exception(xmlPath + " is not a valid XML Directory");
84 throw new Exception("Failed to initialise SvcLogicStore");
87 if (errors.size() > 0) {
88 throw new Exception(errors.toString());
90 } catch (Exception e) {
91 logger.error(e.getMessage());
95 public static void main(String[] args) {
97 String xmlPath = null;
98 String propertyPath = null;
100 if (args != null && args.length >= 2) {
102 propertyPath = args[1];
105 "Sufficient inputs for DGXMLLoadNActivate are missing <xmlpath> <dbPropertyfile>");
107 DGXMLLoad dgXMLLoadDB = new DGXMLLoad(propertyPath);
108 dgXMLLoadDB.loadDGXMLDir(xmlPath);
109 } catch (Exception e) {