Skip to content

Commit

Permalink
Fix issue 4
Browse files Browse the repository at this point in the history
Some vsData* files have wrong column alignment
  • Loading branch information
erssebaggala committed Jul 8, 2017
1 parent 9bc9e0d commit 56bc2e0
Show file tree
Hide file tree
Showing 18 changed files with 91 additions and 34 deletions.
Binary file modified dist/boda-bulkcmparser.jar
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,13 @@ public class BodaBulkCMParser {
*/
Map<String, Stack> moColumns = new LinkedHashMap<String, Stack>();

/**
* Tracks the IDs of the parent elements
*
* @since 1.2.0
*/
Map<String, Stack> moColumnsParentIds = new LinkedHashMap<String, Stack>();

/**
* The file/directory to be parsed.
*
Expand Down Expand Up @@ -974,6 +981,8 @@ public void processVendorAttributes() {
String paramNames = "FileName,varDateTime";
String paramValues = bulkCMXMLFileBasename + "," + dateTime;

Map<String,String> parentIdValues = new LinkedHashMap<String, String>();

//Parent MO IDs
for (int i = 0; i < xmlTagStack.size(); i++) {

Expand All @@ -995,18 +1004,33 @@ public void processVendorAttributes() {
}
Iterator<Map.Entry<String, String>> aIter
= xmlAttrStack.get(depthKey).entrySet().iterator();

while (aIter.hasNext()) {
Map.Entry<String, String> meMap = aIter.next();

String pValue = toCSVFormat(meMap.getValue());
String pName = parentMO + "_" + meMap.getKey();

paramNames = paramNames + "," + pName;
paramValues = paramValues + "," + pValue;
parentIdValues.put(pName, pValue);

}
}


Stack parentIds = moColumnsParentIds.get(vsDataType);
for (int idx = 0; idx < parentIds.size(); idx++) {

String pName = (String)parentIds.get(idx);

String pValue= "";
if( parentIdValues.containsKey(pName)){
pValue = parentIdValues.get(pName);
}

paramNames = paramNames + "," + pName;
paramValues = paramValues + "," + pValue;
}

//Make copy of the columns first
Stack columns = new Stack();

Expand Down Expand Up @@ -1047,9 +1071,11 @@ public void processVendorAttributes() {
private void collectVendorMOColumns(){
if (!moColumns.containsKey(vsDataType)) {
moColumns.put(vsDataType, new Stack());
moColumnsParentIds.put(vsDataType, new Stack()); //Holds parent element IDs
}

Stack s = moColumns.get(vsDataType);
Stack parentIDStack = moColumnsParentIds.get(vsDataType);

//Get vendor specific attributes
Iterator<Map.Entry<String, String>> iter
Expand All @@ -1062,6 +1088,42 @@ private void collectVendorMOColumns(){
}
}
moColumns.replace(vsDataType, s);

//
//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);

}

/**
Expand Down Expand Up @@ -1116,7 +1178,7 @@ public void closeMOPWMap() {
* @version 1.0.0
*/
public void showHelp() {
System.out.println("boda-bulkcmparser 1.1.0 Copyright (c) 2017 Bodastage(http://www.bodastage.com)");
System.out.println("boda-bulkcmparser 1.2.0 Copyright (c) 2017 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>");
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,24 +1,18 @@
package com.bodastage.boda_bulkcmparser;

import com.bodastage.boda_bulkcmparser.bulkcmxml.BulkCmConfigDataFile;
import java.io.File;
import java.io.UnsupportedEncodingException;
import java.util.logging.Level;
import java.util.logging.Logger;
import junit.framework.Test;
import junit.framework.TestCase;
import junit.framework.TestSuite;
import com.bodastage.boda_bulkcmparser.BodaBulkCMParser;
import test.java.com.bodastage.boda_bulkcmparser.bulkcmxml.BulkCmConfigDataFile;
import test.java.com.bodastage.boda_bulkcmparser.bulkcmxml.FileHeader;
import test.java.com.bodastage.boda_bulkcmparser.bulkcmxml.FileFooter;

/**
* Unit test for boda-bulkcmparser.
*/
public class BodaBulkCMParserTest
extends TestCase
{
String sampleBulkCMFile = "/tmp/bulkcmdata.xml";
String sampleBulkCMFile;

String [] expectedFiles = {
"/tmp/bulkCmConfigDataFile.csv",
Expand Down Expand Up @@ -60,8 +54,10 @@ public void setUp() {
javax.xml.bind.Marshaller marshaller = jaxbCtx.createMarshaller();
marshaller.setProperty(javax.xml.bind.Marshaller.JAXB_ENCODING, "UTF-8"); //NOI18N
marshaller.setProperty(javax.xml.bind.Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);

File file = new File("/tmp/bulkcmdata.xml");

sampleBulkCMFile = System.getProperty("java.io.tmpdir") + File.separator + "bulkcmdata.xml";

File file = new File(sampleBulkCMFile);
marshaller.marshal(bulkCMConfigData, file);
}catch(Exception e){
System.err.println(e.getMessage());
Expand All @@ -83,7 +79,7 @@ public void tearDown(){

}catch(Exception e){
System.err.println(e.getMessage());
assertTrue(false);
//assertTrue(false);
}
}

Expand All @@ -102,7 +98,7 @@ public void testApp()
{
try {
BodaBulkCMParser parser = new BodaBulkCMParser();
String[] args = { sampleBulkCMFile, "/tmp"};
String[] args = { sampleBulkCMFile, System.getProperty("java.io.tmpdir")};
parser.main(args);

for(int i=0; i<expectedFiles.length;i++){
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
/*
*@author Bodastage<[email protected]>
*/
package test.java.com.bodastage.boda_bulkcmparser.bulkcmxml;
package com.bodastage.boda_bulkcmparser.bulkcmxml;

import javax.xml.bind.annotation.*;
import test.java.com.bodastage.boda_bulkcmparser.bulkcmxml.FileFooter;
import test.java.com.bodastage.boda_bulkcmparser.bulkcmxml.ConfigData;
import test.java.com.bodastage.boda_bulkcmparser.bulkcmxml.FileFooter;
import com.bodastage.boda_bulkcmparser.bulkcmxml.FileFooter;
import com.bodastage.boda_bulkcmparser.bulkcmxml.ConfigData;

@XmlRootElement(name = "bulkCmConfigDataFile", namespace = "")
public class BulkCmConfigDataFile {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* File footer.
*/
package test.java.com.bodastage.boda_bulkcmparser.bulkcmxml;
package com.bodastage.boda_bulkcmparser.bulkcmxml;

import javax.xml.bind.annotation.XmlElement;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* File footer.
*/
package test.java.com.bodastage.boda_bulkcmparser.bulkcmxml;
package com.bodastage.boda_bulkcmparser.bulkcmxml;

import javax.xml.bind.annotation.XmlAttribute;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* File header class.
*/
package test.java.com.bodastage.boda_bulkcmparser.bulkcmxml;
package com.bodastage.boda_bulkcmparser.bulkcmxml;

import javax.xml.bind.annotation.XmlAttribute;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package test.java.com.bodastage.boda_bulkcmparser.bulkcmxml;
package com.bodastage.boda_bulkcmparser.bulkcmxml;

import javax.xml.bind.annotation.XmlElement;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* Managed Element.
*/
package test.java.com.bodastage.boda_bulkcmparser.bulkcmxml;
package com.bodastage.boda_bulkcmparser.bulkcmxml;

/**
*
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* MeContext.
*/
package test.java.com.bodastage.boda_bulkcmparser.bulkcmxml;
package com.bodastage.boda_bulkcmparser.bulkcmxml;

import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlElement;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* Me Context
*/
package test.java.com.bodastage.boda_bulkcmparser.bulkcmxml;
package com.bodastage.boda_bulkcmparser.bulkcmxml;

import java.util.List;
import javax.xml.bind.annotation.XmlElement;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* SubNetwork.
*/
package test.java.com.bodastage.boda_bulkcmparser.bulkcmxml;
package com.bodastage.boda_bulkcmparser.bulkcmxml;

import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlElement;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* SubNetwork2.
*/
package test.java.com.bodastage.boda_bulkcmparser.bulkcmxml;
package com.bodastage.boda_bulkcmparser.bulkcmxml;

import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlElement;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* Subnetwork attributes.
*/
package test.java.com.bodastage.boda_bulkcmparser.bulkcmxml;
package com.bodastage.boda_bulkcmparser.bulkcmxml;

import javax.xml.bind.annotation.XmlElement;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package test.java.com.bodastage.boda_bulkcmparser.bulkcmxml;
package com.bodastage.boda_bulkcmparser.bulkcmxml;

import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlElement;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package test.java.com.bodastage.boda_bulkcmparser.bulkcmxml;
package com.bodastage.boda_bulkcmparser.bulkcmxml;

import javax.xml.bind.annotation.XmlElement;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package test.java.com.bodastage.boda_bulkcmparser.bulkcmxml;
package com.bodastage.boda_bulkcmparser.bulkcmxml;

import javax.xml.bind.annotation.XmlElement;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@
@XmlNs(prefix="xsi", namespaceURI="http://www.w3.org/2001/XMLSchema-instance")
}
)
package test.java.com.bodastage.boda_bulkcmparser.bulkcmxml;
package com.bodastage.boda_bulkcmparser.bulkcmxml;
import javax.xml.bind.annotation.*;

0 comments on commit 56bc2e0

Please sign in to comment.