Skip to content

Commit

Permalink
Fix column misalignment caused by uneven number of 3GPP attributes
Browse files Browse the repository at this point in the history
Cases where un:UtranCell was missing the creationTime attribute
resulted in wrong csv column alignment
  • Loading branch information
erssebaggala committed Jul 28, 2017
1 parent 56bc2e0 commit bdcb6c0
Show file tree
Hide file tree
Showing 4 changed files with 103 additions and 13 deletions.
Binary file modified dist/boda-bulkcmparser.jar
Binary file not shown.
7 changes: 7 additions & 0 deletions nbactions.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,11 @@
<goal>assembly:single</goal>
</goals>
</action>
<action>
<actionName>CUSTOM-test</actionName>
<displayName>test</displayName>
<goals>
<goal>test</goal>
</goals>
</action>
</actions>
107 changes: 95 additions & 12 deletions src/main/java/com/bodastage/boda_bulkcmparser/BodaBulkCMParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,14 @@

public class BodaBulkCMParser {


/**
* Current release version
*
* Since 1.3.0
*/
final String VERSION = "1.3.0";

/**
* Tracks XML elements.
*
Expand Down Expand Up @@ -248,6 +256,13 @@ public class BodaBulkCMParser {
*/
Map<String, Stack> moColumnsParentIds = new LinkedHashMap<String, Stack>();

/**
* A map of 3GPP attributes to the 3GPP MOs
*
* @since 1.3.0
*/
Map<String, Stack> moThreeGPPAttrMap = new LinkedHashMap<String, Stack>();

/**
* The file/directory to be parsed.
*
Expand Down Expand Up @@ -719,6 +734,10 @@ public void endELementEvent(XMLEvent xmlEvent)
//3.2 </xn:attributes>
if (qName.equals("attributes")) {
attrMarker = false;

if(parserState == ParserStates.EXTRACTING_PARAMETERS && vsDataType == null){
updateThreeGPPAttrMap();
}
return;
}

Expand Down Expand Up @@ -941,18 +960,33 @@ public void process3GPPAttributes()
paramValues = paramValues + "," + toCSVFormat(meMap.getValue());
}
}

//Some MOs dont have 3GPP attributes e.g. the fileHeader
//and the fileFooter
if( moThreeGPPAttrMap.get(mo) != null ){
//Get 3GPP attributes for MO at the current depth
Stack a3GPPAtrr = moThreeGPPAttrMap.get(mo);
Map<String,String> current3GPPAttrs = null;

if (!threeGPPAttrStack.isEmpty() && threeGPPAttrStack.get(depth) != null) {
current3GPPAttrs = threeGPPAttrStack.get(depth);
}

for(int i =0; i < a3GPPAtrr.size();i++){
String aAttr = (String)a3GPPAtrr.get(i);
String aValue= "";

if( current3GPPAttrs != null && current3GPPAttrs.containsKey(aAttr)){
aValue = toCSVFormat(current3GPPAttrs.get(aAttr));
}

paramNames = paramNames + "," + aAttr;
paramValues = paramValues + "," + aValue;
}
}


//Get 3GPP parameters for the MO at the current depth.
if (!threeGPPAttrStack.isEmpty() && threeGPPAttrStack.get(depth) != null) {
Iterator<Map.Entry<String, String>> iter
= threeGPPAttrStack.get(depth).entrySet().iterator();
while (iter.hasNext()) {
Map.Entry<String, String> meMap = iter.next();
paramNames = paramNames + "," + meMap.getKey();
paramValues = paramValues + "," + toCSVFormat(meMap.getValue());
}
}


//Write the 3GPP defined MOs to files.
PrintWriter pw = null;
if (!output3GPPMOPWMap.containsKey(mo)) {
Expand Down Expand Up @@ -1065,6 +1099,55 @@ public void processVendorAttributes() {

}


/**
* Update the map of 3GPP MOs to attributes.
*
* This is necessary to ensure the final output in the csv is aligned.
*
* @since 1.3.0
*/
private void updateThreeGPPAttrMap(){
if( xmlTagStack == null || xmlTagStack.isEmpty() ) return;

String mo = xmlTagStack.peek().toString();

//Hold the current 3GPP attributes
HashMap<String, String> tgppAttrs = null;

Stack attrs = new Stack();

//Initialize if the MO does not exist
if(!moThreeGPPAttrMap.containsKey(mo)){
moThreeGPPAttrMap.put(mo, new Stack());
}


//The attributes stack can be empty if the MO has no 3GPP attributes
if(threeGPPAttrStack.isEmpty() || threeGPPAttrStack.get(depth) == null){
return;
}
tgppAttrs = (LinkedHashMap<String, String>) threeGPPAttrStack.get(depth);


attrs = moThreeGPPAttrMap.get(mo);

if(tgppAttrs != null){
//Get vendor specific attributes
Iterator<Map.Entry<String, String>> iter
= tgppAttrs.entrySet().iterator();
while (iter.hasNext()) {
Map.Entry<String, String> me = iter.next();
String parameter = me.getKey();
if( !attrs.contains( parameter ) ){
attrs.push(parameter);
}
}
moThreeGPPAttrMap.replace(mo, attrs);

}
}

/**
* Collect parameters for vendor specific mo data
*/
Expand Down Expand Up @@ -1178,7 +1261,7 @@ public void closeMOPWMap() {
* @version 1.0.0
*/
public void showHelp() {
System.out.println("boda-bulkcmparser 1.2.0 Copyright (c) 2017 Bodastage(http://www.bodastage.com)");
System.out.println("boda-bulkcmparser "+ VERSION +" 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
Expand Up @@ -79,7 +79,7 @@ public void tearDown(){

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

Expand Down

0 comments on commit bdcb6c0

Please sign in to comment.