Skip to content

Commit

Permalink
Update dist/boda-bulkcmparser.jar
Browse files Browse the repository at this point in the history
  • Loading branch information
erssebaggala committed Jul 1, 2019
1 parent ae3fae6 commit b63ec5e
Show file tree
Hide file tree
Showing 4 changed files with 98 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);
}



}
}

0 comments on commit b63ec5e

Please sign in to comment.