diff options
author | 2017-12-18 19:39:40 -0600 | |
---|---|---|
committer | 2017-12-19 08:18:21 -0800 | |
commit | 49f9de63c3d04a2f6ccd3a81e88a01febe185fd9 (patch) | |
tree | a17c03255d96727062658158fa7e77c450c3a845 /appc-config/appc-config-generator/provider/src/main/java/org/onap/sdnc/config/generator/tool | |
parent | b1c754c49e15e7fad854ee8c678d53be8d40e30e (diff) |
Update appc-config-generator to use onap packaging
Change-Id: Ia89d9eb8f56c8ac0e46cbe1b473f7cfced32228a
Issue-ID: APPC-13
Signed-off-by: Takamune Cho <tc012c@att.com>
Diffstat (limited to 'appc-config/appc-config-generator/provider/src/main/java/org/onap/sdnc/config/generator/tool')
9 files changed, 206 insertions, 227 deletions
diff --git a/appc-config/appc-config-generator/provider/src/main/java/org/onap/sdnc/config/generator/tool/CheckDataTool.java b/appc-config/appc-config-generator/provider/src/main/java/org/onap/sdnc/config/generator/tool/CheckDataTool.java index 316e821df..4488e0be8 100644 --- a/appc-config/appc-config-generator/provider/src/main/java/org/onap/sdnc/config/generator/tool/CheckDataTool.java +++ b/appc-config/appc-config-generator/provider/src/main/java/org/onap/sdnc/config/generator/tool/CheckDataTool.java @@ -1,9 +1,11 @@ /*- * ============LICENSE_START======================================================= - * ONAP : APP-C + * ONAP : APPC * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. * ================================================================================ + * Copyright (C) 2017 Amdocs + * ============================================================================= * 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 @@ -15,33 +17,33 @@ * 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. + * + * ECOMP is a trademark and service mark of AT&T Intellectual Property. * ============LICENSE_END========================================================= */ -package org.openecomp.sdnc.config.generator.tool; +package org.onap.sdnc.config.generator.tool; import java.io.StringReader; - import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; - import org.codehaus.jettison.json.JSONArray; import org.codehaus.jettison.json.JSONException; import org.codehaus.jettison.json.JSONObject; -import org.openecomp.sdnc.config.generator.ConfigGeneratorConstant; +import org.onap.sdnc.config.generator.ConfigGeneratorConstant; import org.w3c.dom.Document; import org.xml.sax.InputSource; public class CheckDataTool { - public static String checkData(String data){ + public static String checkData(String data) { boolean isJSON = isJSON(data); - if(isJSON){ + if (isJSON) { return ConfigGeneratorConstant.DATA_TYPE_JSON; } boolean isXML = isXML(data); - if(isXML){ + if (isXML) { return ConfigGeneratorConstant.DATA_TYPE_XML; } @@ -60,13 +62,13 @@ public class CheckDataTool { } return true; - // try { - // final ObjectMapper mapper = new ObjectMapper(); - // mapper.readTree(data); - // return true; - // } catch (IOException e) { - // return false; - // } + // try { + // final ObjectMapper mapper = new ObjectMapper(); + // mapper.readTree(data); + // return true; + // } catch (IOException e) { + // return false; + // } } public static boolean isXML(String data) { diff --git a/appc-config/appc-config-generator/provider/src/main/java/org/onap/sdnc/config/generator/tool/Constants.java b/appc-config/appc-config-generator/provider/src/main/java/org/onap/sdnc/config/generator/tool/Constants.java index d8af571e8..c368eb605 100644 --- a/appc-config/appc-config-generator/provider/src/main/java/org/onap/sdnc/config/generator/tool/Constants.java +++ b/appc-config/appc-config-generator/provider/src/main/java/org/onap/sdnc/config/generator/tool/Constants.java @@ -1,9 +1,11 @@ /*- * ============LICENSE_START======================================================= - * ONAP : APP-C + * ONAP : APPC * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. * ================================================================================ + * Copyright (C) 2017 Amdocs + * ============================================================================= * 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 @@ -15,18 +17,20 @@ * 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. + * + * ECOMP is a trademark and service mark of AT&T Intellectual Property. * ============LICENSE_END========================================================= */ -package org.openecomp.sdnc.config.generator.tool; +package org.onap.sdnc.config.generator.tool; + +public class Constants { -public class Constants -{ + public static final String DBLIB_SERVICE = + "org.openecomp.sdnc.sli.resource.dblib.DBResourceManager"; + public static final String DEVICE_AUTHENTICATION = "DEVICE_AUTHENTICATION"; + public static final String SCHEMA_SDNCTL = "SDNCTL"; - public static final String DBLIB_SERVICE = "org.openecomp.sdnc.sli.resource.dblib.DBResourceManager"; - public static final String DEVICE_AUTHENTICATION="DEVICE_AUTHENTICATION"; - public static final String SCHEMA_SDNCTL="SDNCTL"; + public static final String APPC_CONFIG_DIR = "/opt/app/bvc/properties"; - public static final String APPC_CONFIG_DIR="/opt/app/bvc/properties"; - } diff --git a/appc-config/appc-config-generator/provider/src/main/java/org/onap/sdnc/config/generator/tool/CustomJsonNodeFactory.java b/appc-config/appc-config-generator/provider/src/main/java/org/onap/sdnc/config/generator/tool/CustomJsonNodeFactory.java index 5820cea7a..7a44b8b47 100644 --- a/appc-config/appc-config-generator/provider/src/main/java/org/onap/sdnc/config/generator/tool/CustomJsonNodeFactory.java +++ b/appc-config/appc-config-generator/provider/src/main/java/org/onap/sdnc/config/generator/tool/CustomJsonNodeFactory.java @@ -1,9 +1,11 @@ /*- * ============LICENSE_START======================================================= - * ONAP : APP-C + * ONAP : APPC * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. * ================================================================================ + * Copyright (C) 2017 Amdocs + * ============================================================================= * 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 @@ -15,18 +17,20 @@ * 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. + * + * ECOMP is a trademark and service mark of AT&T Intellectual Property. * ============LICENSE_END========================================================= */ -package org.openecomp.sdnc.config.generator.tool; +package org.onap.sdnc.config.generator.tool; import com.fasterxml.jackson.databind.node.JsonNodeFactory; import com.fasterxml.jackson.databind.node.TextNode; public class CustomJsonNodeFactory extends JsonNodeFactory { - public TextNode textNode(String text) { - return new CustomTextNode(text); + public TextNode textNode(String text) { + return new CustomTextNode(text); } } diff --git a/appc-config/appc-config-generator/provider/src/main/java/org/onap/sdnc/config/generator/tool/CustomTextNode.java b/appc-config/appc-config-generator/provider/src/main/java/org/onap/sdnc/config/generator/tool/CustomTextNode.java index 93e252a6d..2cfc643aa 100644 --- a/appc-config/appc-config-generator/provider/src/main/java/org/onap/sdnc/config/generator/tool/CustomTextNode.java +++ b/appc-config/appc-config-generator/provider/src/main/java/org/onap/sdnc/config/generator/tool/CustomTextNode.java @@ -1,9 +1,11 @@ /*- * ============LICENSE_START======================================================= - * ONAP : APP-C + * ONAP : APPC * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. * ================================================================================ + * Copyright (C) 2017 Amdocs + * ============================================================================= * 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 @@ -15,24 +17,25 @@ * 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. + * + * ECOMP is a trademark and service mark of AT&T Intellectual Property. * ============LICENSE_END========================================================= */ -package org.openecomp.sdnc.config.generator.tool; +package org.onap.sdnc.config.generator.tool; import com.fasterxml.jackson.core.io.CharTypes; import com.fasterxml.jackson.databind.node.TextNode; -public class CustomTextNode extends TextNode{ +public class CustomTextNode extends TextNode { public CustomTextNode(String v) { super(v); } - + @Override - public String toString() - { + public String toString() { int len = textValue().length(); len = len + 2 + (len >> 4); StringBuilder sb = new StringBuilder(len); @@ -40,11 +43,10 @@ public class CustomTextNode extends TextNode{ return sb.toString(); } - protected static void appendQuoted(StringBuilder sb, String content) - { - // sb.append('"'); + protected static void appendQuoted(StringBuilder sb, String content) { + // sb.append('"'); CharTypes.appendQuoted(sb, content); - // sb.append('"'); + // sb.append('"'); } - + } diff --git a/appc-config/appc-config-generator/provider/src/main/java/org/onap/sdnc/config/generator/tool/DbServiceUtil.java b/appc-config/appc-config-generator/provider/src/main/java/org/onap/sdnc/config/generator/tool/DbServiceUtil.java index c8340816e..94b346c1a 100644 --- a/appc-config/appc-config-generator/provider/src/main/java/org/onap/sdnc/config/generator/tool/DbServiceUtil.java +++ b/appc-config/appc-config-generator/provider/src/main/java/org/onap/sdnc/config/generator/tool/DbServiceUtil.java @@ -1,9 +1,11 @@ /*- * ============LICENSE_START======================================================= - * ONAP : APP-C + * ONAP : APPC * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. * ================================================================================ + * Copyright (C) 2017 Amdocs + * ============================================================================= * 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 @@ -15,59 +17,60 @@ * 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. + * + * ECOMP is a trademark and service mark of AT&T Intellectual Property. * ============LICENSE_END========================================================= */ -package org.openecomp.sdnc.config.generator.tool; +package org.onap.sdnc.config.generator.tool; import java.io.File; import java.net.URL; import java.sql.SQLException; import java.util.ArrayList; import java.util.Properties; - import javax.sql.rowset.CachedRowSet; - +import org.onap.ccsdk.sli.core.dblib.DBResourceManager; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import org.onap.ccsdk.sli.core.dblib.DBResourceManager; -import org.onap.ccsdk.sli.core.dblib.DbLibService; +public class DbServiceUtil { + private static final Logger log = LoggerFactory.getLogger(DbServiceUtil.class); -public class DbServiceUtil -{ - private static final Logger log = LoggerFactory - .getLogger(DbServiceUtil.class); - private static Properties props; private static DBResourceManager jdbcDataSource = null; - - public static boolean updateDB(String tableName, ArrayList inputArgs, String scema, String whereClause, String setCluase) throws SQLException - { - String updatePasswordString = "update " + tableName + " set " + setCluase + " where " + whereClause ; - boolean result = jdbcDataSource.writeData(updatePasswordString, inputArgs,Constants.SCHEMA_SDNCTL); - return result; + + public static boolean updateDB(String tableName, ArrayList inputArgs, String scema, + String whereClause, String setCluase) throws SQLException { + String updatePasswordString = + "update " + tableName + " set " + setCluase + " where " + whereClause; + boolean result = + jdbcDataSource.writeData(updatePasswordString, inputArgs, Constants.SCHEMA_SDNCTL); + return result; + } + + + public static CachedRowSet getData(String tableName, ArrayList argList, String schema, + String getselectData, String getDataClasue) throws SQLException { + String selectQuery = + "select " + getselectData + "from " + tableName + " where " + getDataClasue; + CachedRowSet data = jdbcDataSource.getData(selectQuery, argList, schema); + return data; } - - - public static CachedRowSet getData(String tableName, ArrayList argList, String schema, String getselectData, String getDataClasue ) throws SQLException - { - String selectQuery = "select " + getselectData + "from " + tableName + " where " + getDataClasue ; - CachedRowSet data = jdbcDataSource.getData(selectQuery, argList, schema); - return data; - } - - - public static DBResourceManager initDbLibService() throws Exception - { + + + public static DBResourceManager initDbLibService() throws Exception { props = new Properties(); - File file = new File("/opt/app/bvc/properties/dblib.properties"); - URL propURL = file.toURI().toURL(); - props.load(propURL.openStream()); + File file = new File("/opt/app/bvc/properties/dblib.properties"); + URL propURL = file.toURI().toURL(); + props.load(propURL.openStream()); + + // this is an expected difference in CCSDK jdbcDataSource = new DBResourceManager(props); + return jdbcDataSource; - + } diff --git a/appc-config/appc-config-generator/provider/src/main/java/org/onap/sdnc/config/generator/tool/EscapeUtils.java b/appc-config/appc-config-generator/provider/src/main/java/org/onap/sdnc/config/generator/tool/EscapeUtils.java index 36afe76ae..bd8b2f56b 100644 --- a/appc-config/appc-config-generator/provider/src/main/java/org/onap/sdnc/config/generator/tool/EscapeUtils.java +++ b/appc-config/appc-config-generator/provider/src/main/java/org/onap/sdnc/config/generator/tool/EscapeUtils.java @@ -1,9 +1,11 @@ /*- * ============LICENSE_START======================================================= - * ONAP : APP-C + * ONAP : APPC * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. * ================================================================================ + * Copyright (C) 2017 Amdocs + * ============================================================================= * 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 @@ -15,10 +17,12 @@ * 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. + * + * ECOMP is a trademark and service mark of AT&T Intellectual Property. * ============LICENSE_END========================================================= */ -package org.openecomp.sdnc.config.generator.tool; +package org.onap.sdnc.config.generator.tool; import org.apache.commons.lang3.StringUtils; @@ -32,16 +36,20 @@ public class EscapeUtils { if (str == null) { return null; } - String searchList[] = new String[]{"'","\\"}; - String replacementList[] = new String[]{ "''","\\\\"}; - return StringUtils.replaceEach(str,searchList, replacementList); + String searchList[] = new String[] {"'", "\\"}; + String replacementList[] = new String[] {"''", "\\\\"}; + return StringUtils.replaceEach(str, searchList, replacementList); } - + + // Added for E2E defect 266908 Quote issue public static String unescapeSql(String str) { if (str == null) { return null; } - + /* + * String searchList[] = new String[]{"''", "\\\\"}; String replacementList[] = new + * String[]{ "'", "\\"}; + */ String searchList[] = new String[] {"''"}; String replacementList[] = new String[] {"'"}; return StringUtils.replaceEach(str, searchList, replacementList); @@ -59,13 +67,13 @@ public class EscapeUtils { for (int i = 0; i < length; i++) { char c = s.charAt(i); switch (c) { - case '\\': - case '\"': - case '\'': - case '\0': { - newLength += 1; - } - break; + case '\\': + case '\"': + case '\'': + case '\0': { + newLength += 1; + } + break; } } if (length == newLength) { @@ -76,25 +84,25 @@ public class EscapeUtils { for (int i = 0; i < length; i++) { char c = s.charAt(i); switch (c) { - case '\\': { - sb.append("\\\\"); - } - break; - case '\"': { - sb.append("\\\""); - } - break; - case '\'': { - sb.append("\\\'"); - } - break; - case '\0': { - sb.append("\\0"); - } - break; - default: { - sb.append(c); - } + case '\\': { + sb.append("\\\\"); + } + break; + case '\"': { + sb.append("\\\""); + } + break; + case '\'': { + sb.append("\\\'"); + } + break; + case '\0': { + sb.append("\\0"); + } + break; + default: { + sb.append(c); + } } } return sb.toString(); diff --git a/appc-config/appc-config-generator/provider/src/main/java/org/onap/sdnc/config/generator/tool/JSONTool.java b/appc-config/appc-config-generator/provider/src/main/java/org/onap/sdnc/config/generator/tool/JSONTool.java index 63fd7006e..a4731099d 100644 --- a/appc-config/appc-config-generator/provider/src/main/java/org/onap/sdnc/config/generator/tool/JSONTool.java +++ b/appc-config/appc-config-generator/provider/src/main/java/org/onap/sdnc/config/generator/tool/JSONTool.java @@ -1,9 +1,11 @@ /*- * ============LICENSE_START======================================================= - * ONAP : APP-C + * ONAP : APPC * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. * ================================================================================ + * Copyright (C) 2017 Amdocs + * ============================================================================= * 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 @@ -15,37 +17,36 @@ * 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. + * + * ECOMP is a trademark and service mark of AT&T Intellectual Property. * ============LICENSE_END========================================================= */ -package org.openecomp.sdnc.config.generator.tool; +package org.onap.sdnc.config.generator.tool; import java.util.ArrayList; import java.util.HashMap; import java.util.Iterator; import java.util.List; import java.util.Map; - import org.codehaus.jettison.json.JSONArray; import org.codehaus.jettison.json.JSONException; import org.codehaus.jettison.json.JSONObject; - import com.att.eelf.configuration.EELFLogger; import com.att.eelf.configuration.EELFManager; -import com.fasterxml.jackson.databind.JsonNode; -import com.fasterxml.jackson.databind.ObjectMapper; public class JSONTool { - private static final EELFLogger log = EELFManager.getInstance().getLogger(JSONTool.class); + private static final EELFLogger log = EELFManager.getInstance().getLogger(JSONTool.class); public static Map<String, String> convertToProperties(String s) throws JSONException { return convertToProperties(s, null); } - public static Map<String, String> convertToProperties(String s,List<String> blockKeys) throws JSONException { + public static Map<String, String> convertToProperties(String s, List<String> blockKeys) + throws JSONException { JSONObject json = new JSONObject(s); Map<String, String> mm = new HashMap<String, String>(); @@ -64,70 +65,14 @@ public class JSONTool { wm.remove(key); - if(blockKeys != null && blockKeys.contains(key) && o != null){ - //log.info("Adding JSON Block Keys : " + key + "=" + o.toString()); - mm.put("block_" +key,o.toString()); - } - - if (o instanceof Boolean || o instanceof Number || o instanceof String) { - mm.put(key, o.toString()); - //log.info("Added property: " + key + ": " + o.toString()); - } - - else if (o instanceof JSONObject) { - JSONObject jo = (JSONObject) o; - Iterator<String> i = jo.keys(); - while (i.hasNext()) { - String key1 = i.next(); - wm.put(key + "." + key1, jo.get(key1)); - } - } - - else if (o instanceof JSONArray) { - JSONArray ja = (JSONArray) o; - mm.put("size_"+key, String.valueOf(ja.length())); - - //log.info("Added property: " + key + "_length" + ": " + String.valueOf(ja.length())); - - for (int i = 0; i < ja.length(); i++) - wm.put(key + '[' + i + ']', ja.get(i)); - } - } - - return mm; - } - - /* - public static Map<String, String> convertToProperties1(String s,List<String> blockKeys) throws Exception { - ObjectMapper objectMapper = new ObjectMapper(); - - JsonNode rootNode = objectMapper.readTree(s); - - Map<String, String> mm = new HashMap<String, String>(); - - Map<String, Object> wm = new HashMap<String, Object>(); - Iterator<String> ii = rootNode.fieldNames(); - while (ii.hasNext()) { - String key1 = ii.next(); - wm.put(key1, rootNode.get(key1)); - - - } - - while (!wm.isEmpty()) - for (String key : new ArrayList<>(wm.keySet())) { - Object o = wm.get(key); - wm.remove(key); - - - if(blockKeys != null && blockKeys.contains(key) && o != null){ - //log.info("Adding JSON Block Keys : " + key + "=" + o.toString()); - mm.put("block_" +key,o.toString()); + if (blockKeys != null && blockKeys.contains(key) && o != null) { + // log.info("Adding JSON Block Keys : " + key + "=" + o.toString()); + mm.put("block_" + key, o.toString()); } if (o instanceof Boolean || o instanceof Number || o instanceof String) { mm.put(key, o.toString()); - //log.info("Added property: " + key + ": " + o.toString()); + // log.info("Added property: " + key + ": " + o.toString()); } else if (o instanceof JSONObject) { @@ -141,9 +86,10 @@ public class JSONTool { else if (o instanceof JSONArray) { JSONArray ja = (JSONArray) o; - mm.put("size_"+key, String.valueOf(ja.length())); + mm.put("size_" + key, String.valueOf(ja.length())); - //log.info("Added property: " + key + "_length" + ": " + String.valueOf(ja.length())); + // log.info("Added property: " + key + "_length" + ": " + + // String.valueOf(ja.length())); for (int i = 0; i < ja.length(); i++) wm.put(key + '[' + i + ']', ja.get(i)); @@ -152,6 +98,5 @@ public class JSONTool { return mm; } -*/ } diff --git a/appc-config/appc-config-generator/provider/src/main/java/org/onap/sdnc/config/generator/tool/LogParserTool.java b/appc-config/appc-config-generator/provider/src/main/java/org/onap/sdnc/config/generator/tool/LogParserTool.java index 54823bc17..0c228b8eb 100644 --- a/appc-config/appc-config-generator/provider/src/main/java/org/onap/sdnc/config/generator/tool/LogParserTool.java +++ b/appc-config/appc-config-generator/provider/src/main/java/org/onap/sdnc/config/generator/tool/LogParserTool.java @@ -1,9 +1,11 @@ /*- * ============LICENSE_START======================================================= - * ONAP : APP-C + * ONAP : APPC * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. * ================================================================================ + * Copyright (C) 2017 Amdocs + * ============================================================================= * 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 @@ -15,25 +17,26 @@ * 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. + * + * ECOMP is a trademark and service mark of AT&T Intellectual Property. * ============LICENSE_END========================================================= */ -package org.openecomp.sdnc.config.generator.tool; +package org.onap.sdnc.config.generator.tool; import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Date; import java.util.List; - import com.att.eelf.configuration.EELFLogger; import com.att.eelf.configuration.EELFManager; -public class LogParserTool { - private static final EELFLogger log = EELFManager.getInstance().getLogger(JSONTool.class); +public class LogParserTool { + private static final EELFLogger log = EELFManager.getInstance().getLogger(JSONTool.class); private String[] singleLines; - private List<String> recentErrors = new ArrayList<String> ();; + private List<String> recentErrors = new ArrayList<String>();; private Date todaysDate = new Date(); private SimpleDateFormat dFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss"); private final int minMilli = 60000; @@ -41,7 +44,7 @@ public class LogParserTool { private final int NOT_IN_TIME = 1; private final int NO_DATE = 2; - public String parseErrorLog(String data){ + public String parseErrorLog(String data) { singleLines = data.split("\\r?\\n"); try { getNearestDates(); @@ -49,40 +52,42 @@ public class LogParserTool { } catch (Exception e) { e.printStackTrace(); } - if(recentErrors.size() == 0){ + if (recentErrors.size() == 0) { recentErrors.clear(); return "Did not find the string 'Starting orchestration of file backed up to /var/opt/MetaSwitch/orch/orch_conf.json' in the log file with timestamp within the last 5 minutes"; - }else if(recentErrors.size() == 1){ + } else if (recentErrors.size() == 1) { recentErrors.clear(); - return "Did not find the string ‘Error parsing orchestration file’ in the log file with timestamp within the last 5 minutes"; - }else{ + return "Did not find the string ?Error parsing orchestration file? in the log file with timestamp within the last 5 minutes"; + } else { String error = recentErrors.get(0); recentErrors.clear(); - return "Error: "+ error.substring(error.indexOf("Error parsing orchestration file:")+34); + return "Error: " + + error.substring(error.indexOf("Error parsing orchestration file:") + 34); } } - public void getNearestDates() throws ParseException{ + public void getNearestDates() throws ParseException { int result; - for( int i = singleLines.length-1; i >= 0 ; i--){ - if(singleLines[i].contains("Starting orchestration of file backed up to") || singleLines[i].contains("Error parsing orchestration file:")){ + for (int i = singleLines.length - 1; i >= 0; i--) { + if (singleLines[i].contains("Starting orchestration of file backed up to") + || singleLines[i].contains("Error parsing orchestration file:")) { result = checkDateTime(singleLines[i]); - if( result == IN_TIME) + if (result == IN_TIME) recentErrors.add(singleLines[i]); - else if(result == NOT_IN_TIME){ + else if (result == NOT_IN_TIME) { return; } } } } - private int checkDateTime(String line){ + private int checkDateTime(String line) { Date newDate; try { newDate = dFormat.parse(line.substring(0, 19)); - if((todaysDate.getTime() - newDate.getTime()) <= 5*minMilli){ + if ((todaysDate.getTime() - newDate.getTime()) <= 5 * minMilli) { return IN_TIME; - }else + } else return NOT_IN_TIME; } catch (ParseException e) { e.printStackTrace(); diff --git a/appc-config/appc-config-generator/provider/src/main/java/org/onap/sdnc/config/generator/tool/MergeTool.java b/appc-config/appc-config-generator/provider/src/main/java/org/onap/sdnc/config/generator/tool/MergeTool.java index 0958deebb..a7f0b9d32 100644 --- a/appc-config/appc-config-generator/provider/src/main/java/org/onap/sdnc/config/generator/tool/MergeTool.java +++ b/appc-config/appc-config-generator/provider/src/main/java/org/onap/sdnc/config/generator/tool/MergeTool.java @@ -1,9 +1,11 @@ /*- * ============LICENSE_START======================================================= - * ONAP : APP-C + * ONAP : APPC * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. * ================================================================================ + * Copyright (C) 2017 Amdocs + * ============================================================================= * 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 @@ -15,16 +17,17 @@ * 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. + * + * ECOMP is a trademark and service mark of AT&T Intellectual Property. * ============LICENSE_END========================================================= */ -package org.openecomp.sdnc.config.generator.tool; +package org.onap.sdnc.config.generator.tool; import java.io.IOException; import java.io.StringWriter; import java.util.Iterator; import java.util.Map; - import org.apache.commons.lang3.StringUtils; import org.apache.velocity.Template; import org.apache.velocity.VelocityContext; @@ -33,8 +36,7 @@ import org.apache.velocity.app.VelocityEngine; import org.apache.velocity.runtime.RuntimeConstants; import org.apache.velocity.runtime.resource.loader.StringResourceLoader; import org.apache.velocity.runtime.resource.util.StringResourceRepository; -import org.openecomp.sdnc.config.generator.ConfigGeneratorConstant; - +import org.onap.sdnc.config.generator.ConfigGeneratorConstant; import com.att.eelf.configuration.EELFLogger; import com.att.eelf.configuration.EELFManager; import com.fasterxml.jackson.core.JsonParseException; @@ -45,10 +47,10 @@ import com.fasterxml.jackson.databind.ObjectMapper; public class MergeTool { - private static final EELFLogger log = EELFManager.getInstance().getLogger(MergeTool.class); + private static final EELFLogger log = EELFManager.getInstance().getLogger(MergeTool.class); - public static String mergeMap2TemplateData(String template, Map< String, String> dataMap ){ - log.info("MergeMap2TemplateData Template :"+ template + " Maps :"+ dataMap); + public static String mergeMap2TemplateData(String template, Map<String, String> dataMap) { + log.info("MergeMap2TemplateData Template :" + template + " Maps :" + dataMap); StringWriter writer = new StringWriter(); VelocityEngine ve = new VelocityEngine(); ve.setProperty(RuntimeConstants.RESOURCE_LOADER, "string"); @@ -56,13 +58,14 @@ public class MergeTool { ve.addProperty("string.resource.loader.repository.static", "false"); ve.init(); - StringResourceRepository repo = (StringResourceRepository)ve.getApplicationAttribute(StringResourceLoader.REPOSITORY_NAME_DEFAULT); + StringResourceRepository repo = (StringResourceRepository) ve + .getApplicationAttribute(StringResourceLoader.REPOSITORY_NAME_DEFAULT); repo.putStringResource("TemplateResource", template); Template t = ve.getTemplate("TemplateResource"); VelocityContext context = new VelocityContext(); Iterator<Map.Entry<String, String>> entries = dataMap.entrySet().iterator(); - while (entries.hasNext()) { + while (entries.hasNext()) { Map.Entry<String, String> entry = entries.next(); context.put(entry.getKey(), entry.getValue()); } @@ -71,33 +74,36 @@ public class MergeTool { } - public static String mergeJson2TemplateData(String template, String jsonData, String templateType, String doPrettyOutput) throws JsonParseException, JsonMappingException, IOException{ + public static String mergeJson2TemplateData(String template, String jsonData, + String templateType, String doPrettyOutput) + throws JsonParseException, JsonMappingException, IOException { String mergedData = template; - if( StringUtils.isNotBlank(template) && StringUtils.isNotBlank(jsonData)){ + if (StringUtils.isNotBlank(template) && StringUtils.isNotBlank(jsonData)) { Velocity.init(); - ObjectMapper mapper = new ObjectMapper(); - CustomJsonNodeFactory f = new CustomJsonNodeFactory(); + ObjectMapper mapper = new ObjectMapper(); + CustomJsonNodeFactory f = new CustomJsonNodeFactory(); mapper.setNodeFactory(f); - JsonNode jsonObj = mapper.readValue(jsonData, JsonNode.class); + JsonNode jsonObj = mapper.readValue(jsonData, JsonNode.class); - VelocityContext context = new VelocityContext(); + VelocityContext context = new VelocityContext(); Iterator<String> ii = jsonObj.fieldNames(); while (ii.hasNext()) { String key = ii.next(); context.put(key, jsonObj.get(key)); - } + } - StringWriter writer = new StringWriter(); + StringWriter writer = new StringWriter(); Velocity.evaluate(context, writer, "TemplateData", template); writer.flush(); - mergedData = writer.toString(); + mergedData = writer.toString(); - if(StringUtils.isNotBlank(templateType) && StringUtils.isNotBlank(doPrettyOutput) + if (StringUtils.isNotBlank(templateType) && StringUtils.isNotBlank(doPrettyOutput) && ConfigGeneratorConstant.Y.equalsIgnoreCase(doPrettyOutput) - && ( ConfigGeneratorConstant.DATA_TYPE_JSON.equalsIgnoreCase(templateType) - || ConfigGeneratorConstant.DATA_TYPE_XML.equalsIgnoreCase(templateType)) ){ + && (ConfigGeneratorConstant.DATA_TYPE_JSON.equalsIgnoreCase(templateType) + || ConfigGeneratorConstant.DATA_TYPE_XML + .equalsIgnoreCase(templateType))) { // Perform Prettying } |