Skip to content

Commit

Permalink
Fix bug: Reset parser variables when malformed file is skipped
Browse files Browse the repository at this point in the history
  • Loading branch information
erssebaggala committed Jan 8, 2019
1 parent a2c45e0 commit 925b75e
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 46 deletions.
Binary file modified dist/boda-bulkcmparser.jar
Binary file not shown.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<groupId>com.bodastate.boda_bulkcmparser</groupId>
<artifactId>boda-bulkcmparser</artifactId>
<packaging>jar</packaging>
<version>2.0.4</version>
<version>2.0.5</version>
<name>boda-bulkcmparser</name>
<url>http://maven.apache.org</url>
<dependencies>
Expand Down
101 changes: 56 additions & 45 deletions src/main/java/com/bodastage/boda_bulkcmparser/BodaBulkCMParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public class BodaBulkCMParser {
*
* Since 1.3.0
*/
final static String VERSION = "2.0.4";
final static String VERSION = "2.0.5";


private static final Logger LOGGER = LoggerFactory.getLogger(BodaBulkCMParser.class);
Expand Down Expand Up @@ -520,7 +520,7 @@ public static void main(String[] args) {

if(showVersion == true ){
System.out.println(VERSION);
System.out.println("Copyright (c) 2018 Bodastage Solutions(http://www.bodastage.com)");
System.out.println("Copyright (c) 2019 Bodastage Solutions(http://www.bodastage.com)");
System.exit(0);
}

Expand All @@ -536,7 +536,7 @@ public static void main(String[] args) {
footer += "java -jar boda-bulkcmparser.jar -i input_folder -o out_folder\n";
footer += "java -jar boda-bulkcmparser.jar -i input_folder -p\n";
footer += "java -jar boda-bulkcmparser.jar -i input_folder -p -m\n";
footer += "\nCopyright (c) 2018 Bodastage Solutions(http://www.bodastage.com)";
footer += "\nCopyright (c) 2019 Bodastage Solutions(http://www.bodastage.com)";
formatter.printHelp( "java -jar boda-bulkcmparser.jar", header, options, footer );
System.exit(0);
}
Expand Down Expand Up @@ -605,15 +605,7 @@ public void parse() throws XMLStreamException, FileNotFoundException, Unsupporte
}

//Reset variables
vsDataType = null;
vsDataTypeStack.clear();
vsDataTypeRlStack.clear();
xmlAttrStack.clear();
xmlTagStack.clear();
startElementTag = null;
startElementTagPrefix = "";
attrMarker = false;
depth = 0;
resetVariables();

//Extracting values
if (parserState == ParserStates.EXTRACTING_VALUES) {
Expand All @@ -626,6 +618,22 @@ public void parse() throws XMLStreamException, FileNotFoundException, Unsupporte
printExecutionTime();
}

/**
* Reset parser variables before next file
*/
public void resetVariables(){
//Reset variables
vsDataType = null;
vsDataTypeStack.clear();
vsDataTypeRlStack.clear();
xmlAttrStack.clear();
xmlTagStack.clear();
startElementTag = null;
startElementTagPrefix = "";
attrMarker = false;
depth = 0;
}

/**
* Determines if the source data file is a regular file or a directory and
* parses it accordingly
Expand Down Expand Up @@ -706,6 +714,9 @@ public void processFileOrDirectory()
} catch (Exception e) {
System.out.println(e.getMessage());
System.out.println("Skipping file: " + this.baseFileName + "\n");

//Reset variables if a file is skipped
resetVariables();
}
}
}
Expand Down Expand Up @@ -1506,7 +1517,7 @@ private void collectVendorMOColumns(){
//String pName = meMap.getKey();
String pName = parentMO + "_" + meMap.getKey();

if( parentIDStack.search(pName ) < 0 ){
if( parentIDStack.search(pName) < 0 ){
parentIDStack.push(pName);
}

Expand Down Expand Up @@ -1536,38 +1547,38 @@ private void collectVendorMOColumns(){

//
//Parent IDs
for (int i = 0; i < xmlTagStack.size(); i++) {
String parentMO = xmlTagStack.get(i).toString();

//If the parent tag is VsDataContainer, look for the
//vendor specific MO in the vsDataContainer-to-vsDataType map.
if (parentMO.startsWith("VsDataContainer")) {
parentMO = vsDataContainerTypeMap.get(parentMO);
}

//The depth at each xml tag index is index+1
int depthKey = i + 1;

//Iterate through the XML attribute tags for the element.
if (xmlAttrStack.get(depthKey) == null) {
continue; //Skip null values
}

Iterator<Map.Entry<String, String>> mIter
= xmlAttrStack.get(depthKey).entrySet().iterator();

while (mIter.hasNext()) {
Map.Entry<String, String> meMap = mIter.next();
//String pName = meMap.getKey();
String pName = parentMO + "_" + meMap.getKey();

if( parentIDStack.search(pName ) < 0 ){
parentIDStack.push(pName);
}
}
}

moColumnsParentIds.replace(vsDataType, parentIDStack);
// for (int i = 0; i < xmlTagStack.size(); i++) {
// String parentMO = xmlTagStack.get(i).toString();
//
// //If the parent tag is VsDataContainer, look for the
// //vendor specific MO in the vsDataContainer-to-vsDataType map.
// if (parentMO.startsWith("VsDataContainer")) {
// parentMO = vsDataContainerTypeMap.get(parentMO);
// }
//
// //The depth at each xml tag index is index+1
// int depthKey = i + 1;
//
// //Iterate through the XML attribute tags for the element.
// if (xmlAttrStack.get(depthKey) == null) {
// continue; //Skip null values
// }
//
// Iterator<Map.Entry<String, String>> mIter
// = xmlAttrStack.get(depthKey).entrySet().iterator();
//
// while (mIter.hasNext()) {
// Map.Entry<String, String> meMap = mIter.next();
// //String pName = meMap.getKey();
// String pName = parentMO + "_" + meMap.getKey();
//
// if( parentIDStack.search(pName ) < 0 ){
// parentIDStack.push(pName);
// }
// }
// }
//
// moColumnsParentIds.replace(vsDataType, parentIDStack);

}

Expand Down

0 comments on commit 925b75e

Please sign in to comment.