Skip to content

Commit

Permalink
Merge pull request #11 from erssebaggala/fix_null_exception
Browse files Browse the repository at this point in the history
Fix null exception fixes #10
  • Loading branch information
erssebaggala authored Jul 1, 2019
2 parents aa55932 + b63ec5e commit 0537b81
Show file tree
Hide file tree
Showing 5 changed files with 144 additions and 23 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ java -jar boda-bulkcmparser.jar -i input_folder -o out_folder
java -jar boda-bulkcmparser.jar -i input_folder -p
java -jar boda-bulkcmparser.jar -i input_folder -p -m
Copyright (c) 2018 Bodastage Solutions(http://www.bodastage.com)
Copyright (c) 2019 Bodastage Solutions(http://www.bodastage.com)
```

# Download and installation
Expand Down
Binary file modified dist/boda-bulkcmparser.jar
Binary file not shown.
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.6";
final static String VERSION = "2.0.7";


private static final Logger LOGGER = LoggerFactory.getLogger(BodaBulkCMParser.class);
Expand Down Expand Up @@ -327,6 +327,22 @@ public class BodaBulkCMParser {
*/
private String parameterFile = null;


/**
* This is used to mark when processing is still inside the children of a
* a parameter - child scenario. It is useful when one of the children has
* the same name as the parent.
* <moname>
* <chid1>someValue</child1>
* ...
* <moname>someValue</moname>
* ...
* <child/>someValue<childN>
* </moName>
*
*/
private Boolean inParentChildTag = false;

public void setExtractParametersOnly(Boolean bool){
extractParametersOnly = bool;
}
Expand Down Expand Up @@ -606,7 +622,7 @@ public void parse() throws XMLStreamException, FileNotFoundException, Unsupporte

//Reset variables
resetVariables();

//Extracting values
if (parserState == ParserStates.EXTRACTING_VALUES) {
processFileOrDirectory();
Expand Down Expand Up @@ -797,7 +813,7 @@ public void startElementEvent(XMLEvent xmlEvent) {

startElementTag = qName;
startElementTagPrefix = prefix;

Iterator<Attribute> attributes = startElement.getAttributes();

if(qName.equals("fileFooter") && ParserStates.EXTRACTING_PARAMETERS == parserState){
Expand Down Expand Up @@ -962,12 +978,11 @@ public void endELementEvent(XMLEvent xmlEvent)
EndElement endElement = xmlEvent.asEndElement();
String prefix = endElement.getName().getPrefix();
String qName = endElement.getName().getLocalPart();

startElementTag = "";

//E3:1 </xn:VsDataContainer>
if (qName.equalsIgnoreCase("VsDataContainer")) {

String vsDCTag = "VsDataContainer_" + vsDCDepth;
xmlTagStack.pop();
xmlAttrStack.remove(depth);
Expand All @@ -977,7 +992,8 @@ public void endELementEvent(XMLEvent xmlEvent)
depth--;
return;
}



//3.2 </xn:attributes>
if (qName.equals("attributes")) {
attrMarker = false;
Expand Down Expand Up @@ -1010,7 +1026,8 @@ public void endELementEvent(XMLEvent xmlEvent)
String newValue = tagData;

//Handle attributes with children
if (parentChildParameters.containsKey(qName)) {//End of parent tag
//inParentChildTag== false, means we have completed processing the children
if (parentChildParameters.containsKey(qName) && inParentChildTag == false) {//End of parent tag

//Ware at the end of the parent tag so we remove the mapping
//as the child values have already been collected in
Expand All @@ -1034,10 +1051,13 @@ public void endELementEvent(XMLEvent xmlEvent)
int len = vsDataTypeRlStack.size();
String parentTag = vsDataTypeRlStack.get(len - 2).toString();
newTag = parentTag + parentChildAttrSeperator + qName;

inParentChildTag = true;

//Store the parent and it's child
parentChildParameters.put(parentTag, qName);

}else{
inParentChildTag = false;
}

//Handle multivalued paramenters
Expand Down Expand Up @@ -1645,7 +1665,7 @@ public void closeMOPWMap() {
* @version 1.0.0
*/
public void showHelp() {
System.out.println("boda-bulkcmparser "+ VERSION +" Copyright (c) 2018 Bodastage(http://www.bodastage.com)");
System.out.println("boda-bulkcmparser "+ VERSION +" Copyright (c) 2019 Bodastage(http://www.bodastage.com)");
System.out.println("Parses 3GPP Bulk CM XML to csv.");
System.out.println("Usage: java -jar boda-bulkcmparser.jar <fileToParse.xml|Directory> <outputDirectory> [parameter.conf]");
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,15 @@
package com.bodastage.boda_bulkcmparser;

import com.bodastage.boda_bulkcmparser.bulkcmxml.BulkCmConfigDataFile;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.net.URL;
import java.util.Arrays;
import java.util.logging.Level;
import java.util.logging.Logger;
import junit.framework.Test;
import junit.framework.TestCase;
import junit.framework.TestSuite;
Expand Down Expand Up @@ -94,21 +102,68 @@ public static Test suite()
/**
* Run test.
*/
public void testApp()
{
// public void testApp()
// {
// try {
// BodaBulkCMParser parser = new BodaBulkCMParser();
// String[] args = { sampleBulkCMFile, System.getProperty("java.io.tmpdir")};
// parser.main(args);
//
// for(int i=0; i<expectedFiles.length;i++){
// boolean fileExists
// = new File( expectedFiles[i]).exists();
// assertTrue(fileExists);
// }
//
// } catch (Exception ex) {
// assertTrue(false);
// }
// }

public void testParentChildAttrbutesWithSameName(){
ClassLoader classLoader = getClass().getClassLoader();
File inFile = new File(classLoader.getResource("bulkcm_parent_child_same_name.xml").getFile());

BodaBulkCMParser parser = new BodaBulkCMParser();
String inputFile = inFile.getAbsolutePath();

System.out.println(inputFile);
String outputFolder = System.getProperty("java.io.tmpdir");

Logger.getLogger(BodaBulkCMParserTest.class.getName()).log(Level.INFO, "outputFolder:" + outputFolder );

String[] args = { "-i", inputFile, "-o", outputFolder};

parser.main(args);

String expectedResult [] = {
"FILENAME,DATETIME,bulkCmConfigDataFile_schemaLocation,SubNetwork_id,SubNetwork_2_id,meContext_id,ManagedElement_id,vsDataSomeMO_id,SomeAttr,SomeAttr_SomeAttrChild1,SomeAttr_SomeAttr",
"bulkcm_parent_child_same_name.xml,2019-04-16T00:05:00+03:00,http://www.3gpp.org/ftp/specs/archive/32_series/32.615#configData configData.xsd,BS_NRM_ROOT,101,4698,4698,Q0001,,Val1,SomeAttrChildVal"};

try {
BodaBulkCMParser parser = new BodaBulkCMParser();
String[] args = { sampleBulkCMFile, System.getProperty("java.io.tmpdir")};
parser.main(args);

for(int i=0; i<expectedFiles.length;i++){
boolean fileExists
= new File( expectedFiles[i]).exists();
assertTrue(fileExists);
String csvFile = outputFolder + File.separator + "vsDataSomeMO.csv";

BufferedReader br = new BufferedReader(new FileReader(csvFile));
String csvResult [] = new String[2];

int i = 0;
String st;
while ((st = br.readLine()) != null) {
csvResult[i] = st;
i++;
}

} catch (Exception ex) {
assertTrue(false);

assertTrue(Arrays.equals(expectedResult, csvResult));

} catch (FileNotFoundException ex) {
Logger.getLogger(BodaBulkCMParserTest.class.getName()).log(Level.SEVERE, null, ex);
assert(false);
} catch (IOException ex) {
Logger.getLogger(BodaBulkCMParserTest.class.getName()).log(Level.SEVERE, null, ex);
assert(false);
}



}
}
46 changes: 46 additions & 0 deletions src/test/resources/bulkcm_parent_child_same_name.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<?xml version="1.0" encoding="UTF-8"?>
<bulkCmConfigDataFile xmlns="http://www.3gpp.org/ftp/specs/archive/32_series/32.615#configData" xmlns:en="http://www.3gpp.org/ftp/specs/archive/32_series/32.765#eutranNrm" xmlns:un="http://www.3gpp.org/ftp/specs/archive/32_series/32.765#utranNrm" xmlns:gn="http://www.3gpp.org/ftp/specs/archive/32_series/32.765#gsmNrm" xmlns:xn="http://www.3gpp.org/ftp/specs/archive/32_series/32.625#genericNrm" xmlns:zs="http://ZTESpecificAttributes#ZTESpecificAttributes" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.3gpp.org/ftp/specs/archive/32_series/32.615#configData configData.xsd" xmlns:bs="http://www.bodastage.com">
<fileHeader fileFormatVersion="0.1.0" vendorName="Bodastage Solutions"/>
<configData>
<xn:SubNetwork id="BS_NRM_ROOT">
<xn:SubNetwork id="101">
<xn:attributes>
<xn:setOfMcc>999</xn:setOfMcc>
<xn:userLabel>usrLabel</xn:userLabel>
<xn:userDefinedNetworkType></xn:userDefinedNetworkType>
<xn:dnPrefix>www.bodastage.com</xn:dnPrefix>
</xn:attributes>
<xn:meContext id="4698">
<xn:attributes>
<xn:meContextId>4698</xn:meContextId>
<xn:dnPrefix>DC=www.bodastage.com</xn:dnPrefix>
</xn:attributes>
<xn:ManagedElement id="4698">
<xn:attributes>
<xn:locationName></xn:locationName>
<xn:userDefinedState>2</xn:userDefinedState>
<xn:vendorName>Bodastage Solutions</xn:vendorName>
<xn:swVersion>0.0.0</xn:swVersion>
<xn:managedElementType>SDR</xn:managedElementType>
<xn:userLabel>Some Element Name</xn:userLabel>
</xn:attributes>
<xn:vsDataContainer id="Q0001">
<xn:attributes>
<xn:vsDataType>vsDataSomeMO</xn:vsDataType>
<xn:vsDataFormatVersion>BodastageSpecificAttributes.0.0.0</xn:vsDataFormatVersion>
<bs:vsDataSomeMO>
<!-- Test for parent and child with the same names. -->
<bs:SomeAttr>
<bs:SomeAttrChild1>Val1</bs:SomeAttrChild1>
<bs:SomeAttr>SomeAttrChildVal</bs:SomeAttr>
</bs:SomeAttr>
</bs:vsDataSomeMO>
</xn:attributes>
</xn:vsDataContainer>
</xn:ManagedElement>
</xn:meContext>
</xn:SubNetwork>
</xn:SubNetwork>
</configData>
<fileFooter dateTime="2019-04-16T00:05:00+03:00"/>
</bulkCmConfigDataFile>

0 comments on commit 0537b81

Please sign in to comment.