Skip to content

Commit

Permalink
Extra fix for RestComm#234 - Adding of CsvStatsPrinter - making a fie…
Browse files Browse the repository at this point in the history
…ld as Enum
  • Loading branch information
vetss committed May 10, 2017
1 parent 80eec49 commit 27b9324
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,13 @@ public interface CounterCampaign extends Serializable {
* statistics output format
* @return
*/
int getOutputFormat();
CounterOutputFormat getOutputFormat();

/**
* statistics output format
* @return
*/
int getOutputFormatInt();

/**
* Returns counters definitions
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@

import org.mobicents.protocols.ss7.oam.common.statistics.api.CounterCampaign;
import org.mobicents.protocols.ss7.oam.common.statistics.api.CounterDefSet;
import org.mobicents.protocols.ss7.oam.common.statistics.api.CounterOutputFormat;
import org.mobicents.protocols.ss7.oam.common.statistics.api.CounterValueSet;
import org.mobicents.protocols.ss7.oam.common.statistics.api.SourceValueSet;

Expand All @@ -51,7 +52,7 @@ public class CounterCampaignImpl implements CounterCampaign {
private CounterDefSet counterSet;
private String counterSetName;
private int duration;
private int outputFormat;
private CounterOutputFormat outputFormat = CounterOutputFormat.VERBOSE;
private boolean shortCampaign;

private Date startTime;
Expand All @@ -62,12 +63,15 @@ public class CounterCampaignImpl implements CounterCampaign {
public CounterCampaignImpl() {
}

public CounterCampaignImpl(String name, String counterSetName, CounterDefSet counterSet, int duration, boolean shortCampaign, int outputFormat) {
public CounterCampaignImpl(String name, String counterSetName, CounterDefSet counterSet, int duration, boolean shortCampaign, CounterOutputFormat outputFormat) {
this.name = name;
this.counterSetName = counterSetName;
this.counterSet = counterSet;
this.duration = duration;
this.outputFormat = outputFormat;
if (outputFormat != null)
this.outputFormat = outputFormat;
else
this.outputFormat = CounterOutputFormat.VERBOSE;
this.shortCampaign = shortCampaign;
}

Expand All @@ -87,10 +91,15 @@ public int getDuration() {
}

@Override
public int getOutputFormat() {
public CounterOutputFormat getOutputFormat() {
return outputFormat;
}

@Override
public int getOutputFormatInt() {
return outputFormat.getCode();
}

@Override
public boolean isShortCampaign() {
return shortCampaign;
Expand Down Expand Up @@ -148,15 +157,21 @@ public void read(javolution.xml.XMLFormat.InputElement xml, CounterCampaignImpl
counterCampaign.counterSetName = xml.getAttribute(COUNTER_SET_NAME, "");
counterCampaign.shortCampaign = xml.getAttribute(SHORT_CAMPAIGN, false);
counterCampaign.duration = xml.getAttribute(DURATION, 60);
counterCampaign.outputFormat = xml.getAttribute(OUTPUT_FORMAT, 1);

String val = xml.getAttribute(OUTPUT_FORMAT, "VERBOSE");
try {
counterCampaign.outputFormat = Enum.valueOf(CounterOutputFormat.class, val);
} catch (Exception e) {
counterCampaign.outputFormat = CounterOutputFormat.VERBOSE;
}
}

public void write(CounterCampaignImpl counterCampaign, javolution.xml.XMLFormat.OutputElement xml) throws XMLStreamException {
xml.setAttribute(NAME, counterCampaign.getName());
xml.setAttribute(COUNTER_SET_NAME, counterCampaign.getCounterSetName());
xml.setAttribute(SHORT_CAMPAIGN, counterCampaign.isShortCampaign());
xml.setAttribute(DURATION, counterCampaign.getDuration());
xml.setAttribute(OUTPUT_FORMAT, counterCampaign.getOutputFormat());
xml.setAttribute(OUTPUT_FORMAT, counterCampaign.getOutputFormat().toString());
}
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,7 @@ private void doCreateCampaign(String campaignName, String counterSetName, int du

if (outputFormat != 0 && outputFormat != 1 && outputFormat != 2)
throw new Exception("Output format may be only CSV, verbose or CSV and verbose");
CounterOutputFormat counterOutputFormat = CounterOutputFormat.getInstance(outputFormat);

CounterMediator cm = lstCounterDefSet.get(counterSetName);
if (cm == null) {
Expand All @@ -265,7 +266,7 @@ private void doCreateCampaign(String campaignName, String counterSetName, int du
synchronized (this) {
CounterDefSet counterSet = cm.getCounterDefSet(counterSetName);
CounterCampaignImpl camp = new CounterCampaignImpl(campaignName, counterSetName, counterSet, duration,
shortCampaign, outputFormat);
shortCampaign, counterOutputFormat);
lstCounterCampaign.put(campaignName, camp);
this.store();
}
Expand Down Expand Up @@ -333,7 +334,7 @@ protected void processCampaign(CounterCampaignImpl cc, Date endTime) {
}
if (cm != null) {
SourceValueSet svs1 = cc.getLastSourceValueSet();
CounterOutputFormat outputFormat = CounterOutputFormat.getInstance(cc.getOutputFormat());
CounterOutputFormat outputFormat = cc.getOutputFormat();
if (outputFormat != null) {
switch (outputFormat) {
case CSV:
Expand Down
2 changes: 1 addition & 1 deletion oam/new-ui/src/main/webapp/modules/managecampaigns.html
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ <h3><i class="icon-map-marker" style="color: #CC9522;"></i> Create Campaign</h3>
var name = response.name;
var counterSetName = response.counterSetName;
var duration = response.duration;
var outputFormat = response.outputFormat;
var outputFormat = response.outputFormatInt;
var counterSet = response.counterSet;
var counterDefs = counterSet.counterDefs;
var isShortCampaign = response.shortCampaign;
Expand Down

0 comments on commit 27b9324

Please sign in to comment.