Skip to content

Commit

Permalink
#184 WEBUI_KPI_Field.OffsetName
Browse files Browse the repository at this point in the history
  • Loading branch information
teosarca committed Mar 3, 2017
1 parent a8256dd commit 714b333
Show file tree
Hide file tree
Showing 4 changed files with 82 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ public static interface BucketValueExtractor
private final boolean groupBy;

private final ITranslatableString caption;
private final ITranslatableString offsetCaption;
private final ITranslatableString description;
private final String unit;
private final KPIFieldValueType valueType;
Expand All @@ -79,6 +80,7 @@ private KPIField(final Builder builder)
groupBy = builder.groupBy;

caption = builder.caption;
offsetCaption = builder.offsetCaption;
description = builder.description;
unit = builder.unit;
valueType = builder.valueType;
Expand Down Expand Up @@ -205,13 +207,12 @@ public String getFieldName()
{
return fieldName;
}

public String getOffsetFieldName()
{
return fieldName + "_offset";
}


public boolean isGroupBy()
{
return groupBy;
Expand All @@ -222,6 +223,11 @@ public String getCaption(final String adLanguage)
return caption.translate(adLanguage);
}

public String getOffsetCaption(final String adLanguage)
{
return offsetCaption.translate(adLanguage);
}

public String getDescription(final String adLanguage)
{
return description.translate(adLanguage);
Expand Down Expand Up @@ -260,8 +266,9 @@ public BucketValueExtractor getBucketValueExtractor()
public static final class Builder
{
private String fieldName;
private boolean groupBy;
private ITranslatableString caption;
private boolean groupBy = false;
private ITranslatableString caption = ImmutableTranslatableString.empty();
private ITranslatableString offsetCaption = ImmutableTranslatableString.empty();
private ITranslatableString description = ImmutableTranslatableString.empty();
private String unit;
private KPIFieldValueType valueType;
Expand All @@ -288,21 +295,30 @@ public Builder setFieldName(final String fieldName)
this.fieldName = fieldName;
return this;
}
public Builder setGroupBy(boolean groupBy)

public Builder setGroupBy(final boolean groupBy)
{
this.groupBy = groupBy;
return this;
}

public Builder setCaption(final ITranslatableString caption)
{
Check.assumeNotNull(caption, "Parameter caption is not null");
this.caption = caption;
return this;
}

public Builder setOffsetCaption(final ITranslatableString offsetCaption)
{
Check.assumeNotNull(offsetCaption, "Parameter offsetCaption is not null");
this.offsetCaption = offsetCaption;
return this;
}

public Builder setDescription(final ITranslatableString description)
{
Check.assumeNotNull(description, "Parameter description is not null");
this.description = description;
return this;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ private KPI getKPIOrNull(final int WEBUI_KPI_ID)
.setCaption(trls.getColumnTrl(I_WEBUI_KPI.COLUMNNAME_Name, kpiDef.getName()))
.setDescription(trls.getColumnTrl(I_WEBUI_KPI.COLUMNNAME_Description, kpiDef.getDescription()))
.setChartType(KPIChartType.forCode(kpiDef.getChartType()))
.setFields(retrieveKPIFields(WEBUI_KPI_ID))
.setFields(retrieveKPIFields(WEBUI_KPI_ID, kpiDef.isGenerateComparation()))
//
.setCompareOffset(compareOffset)
.setDefaultTimeRange(timeRange)
Expand All @@ -229,7 +229,7 @@ private KPI getKPIOrNull(final int WEBUI_KPI_ID)
});
}

private List<KPIField> retrieveKPIFields(final int WEBUI_KPI_ID)
private List<KPIField> retrieveKPIFields(final int WEBUI_KPI_ID, final boolean isComputeOffset)
{
return queryBL.createQueryBuilder(I_WEBUI_KPI_Field.class, Env.getCtx(), ITrx.TRXNAME_None)
.addEqualsFilter(I_WEBUI_KPI_Field.COLUMN_WEBUI_KPI_ID, WEBUI_KPI_ID)
Expand All @@ -242,17 +242,18 @@ private List<KPIField> retrieveKPIFields(final int WEBUI_KPI_ID)
//
.create()
.stream(I_WEBUI_KPI_Field.class)
.map(kpiField -> createKPIField(kpiField))
.map(kpiField -> createKPIField(kpiField, isComputeOffset))
.collect(GuavaCollectors.toImmutableList());
}

private static final KPIField createKPIField(final I_WEBUI_KPI_Field kpiFieldDef)
private static final KPIField createKPIField(final I_WEBUI_KPI_Field kpiFieldDef, final boolean isComputeOffset)
{
final I_AD_Element adElement = kpiFieldDef.getAD_Element();
final String fieldName = adElement.getColumnName();

//
// Extract field caption and description
final IModelTranslationMap kpiFieldDefTrl = InterfaceWrapperHelper.getModelTranslationMap(kpiFieldDef);
final ITranslatableString caption;
final ITranslatableString description;
if (Check.isEmpty(kpiFieldDef.getName(), true))
Expand All @@ -263,15 +264,32 @@ private static final KPIField createKPIField(final I_WEBUI_KPI_Field kpiFieldDef
}
else
{
caption = ImmutableTranslatableString.constant(kpiFieldDef.getName());
caption = kpiFieldDefTrl.getColumnTrl(I_WEBUI_KPI_Field.COLUMNNAME_Name, kpiFieldDef.getName());
description = ImmutableTranslatableString.empty();
}

//
// Extract offset field's caption and description
final ITranslatableString offsetCaption;
if (!isComputeOffset)
{
offsetCaption = ImmutableTranslatableString.empty();
}
else if (Check.isEmpty(kpiFieldDef.getOffsetName(), true))
{
offsetCaption = caption;
}
else
{
offsetCaption = kpiFieldDefTrl.getColumnTrl(I_WEBUI_KPI_Field.COLUMNNAME_OffsetName, kpiFieldDef.getOffsetName());
}

return KPIField.builder()
.setFieldName(fieldName)
.setGroupBy(kpiFieldDef.isGroupBy())
//
.setCaption(caption)
.setOffsetCaption(offsetCaption)
.setDescription(description)
.setUnit(kpiFieldDef.getUOMSymbol())
.setValueType(KPIFieldValueType.fromDisplayType(kpiFieldDef.getAD_Reference_ID()))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,16 @@
@JsonAutoDetect(fieldVisibility = Visibility.ANY, getterVisibility = Visibility.NONE, setterVisibility = Visibility.NONE)
public class JsonKPIFieldLayout
{
public static final JsonKPIFieldLayout of(final KPIField kpiField, final JSONOptions jsonOpts)
public static final JsonKPIFieldLayout field(final KPIField kpiField, final JSONOptions jsonOpts)
{
return new JsonKPIFieldLayout(kpiField, kpiField.getFieldName(), jsonOpts);
final boolean isOffsetField = false;
return new JsonKPIFieldLayout(kpiField, isOffsetField, jsonOpts);
}
public static final JsonKPIFieldLayout of(final KPIField kpiField, final String fieldName, final JSONOptions jsonOpts)

public static final JsonKPIFieldLayout offsetField(final KPIField kpiField, final JSONOptions jsonOpts)
{
return new JsonKPIFieldLayout(kpiField, fieldName, jsonOpts);
final boolean isOffsetField = true;
return new JsonKPIFieldLayout(kpiField, isOffsetField, jsonOpts);
}

@JsonProperty("caption")
Expand All @@ -49,13 +51,13 @@ public static final JsonKPIFieldLayout of(final KPIField kpiField, final String
@JsonProperty("description")
@JsonInclude(JsonInclude.Include.NON_EMPTY)
private final String description;

@JsonProperty("unit")
private final String unit;

@JsonProperty("fieldName")
private final String fieldName;

@JsonProperty("groupBy")
private final boolean groupBy;

Expand All @@ -65,19 +67,37 @@ public static final JsonKPIFieldLayout of(final KPIField kpiField, final String
@JsonProperty("color")
@JsonInclude(JsonInclude.Include.NON_EMPTY)
private final String color;
public JsonKPIFieldLayout(final KPIField kpiField, String fieldName, final JSONOptions jsonOpts)

public JsonKPIFieldLayout(final KPIField kpiField, final boolean isOffsetField, final JSONOptions jsonOpts)
{
final String adLanguage = jsonOpts.getAD_Language();

caption = kpiField.getCaption(adLanguage);
// Caption
if (isOffsetField)
{
caption = kpiField.getOffsetCaption(adLanguage);
}
else
{
caption = kpiField.getCaption(adLanguage);
}

// FieldName
if (isOffsetField)
{
fieldName = kpiField.getOffsetFieldName();
}
else
{
fieldName = kpiField.getFieldName();
}

description = kpiField.getDescription(adLanguage);
unit = kpiField.getUnit();

this.fieldName = fieldName;

groupBy = kpiField.isGroupBy();
dataType = kpiField.getValueType().toJson();

color = kpiField.getColor();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public static final JsonKPILayout of(final KPI kpi, final JSONOptions jsonOpts)

@JsonProperty("pollIntervalSec")
private final int pollIntervalSec;

@JsonProperty("fields")
private final List<JsonKPIFieldLayout> fields;

Expand All @@ -76,11 +76,11 @@ public JsonKPILayout(final KPI kpi, final JSONOptions jsonOpts)
final boolean hasCompareOffset = kpi.hasCompareOffset();
for (final KPIField kpiField : kpi.getFields())
{
jsonFields.add(JsonKPIFieldLayout.of(kpiField, jsonOpts));
jsonFields.add(JsonKPIFieldLayout.field(kpiField, jsonOpts));

if (hasCompareOffset && !kpiField.isGroupBy())
{
jsonFields.add(JsonKPIFieldLayout.of(kpiField, kpiField.getOffsetFieldName(), jsonOpts));
jsonFields.add(JsonKPIFieldLayout.offsetField(kpiField, jsonOpts));
}
}
fields = jsonFields.build();
Expand Down

0 comments on commit 714b333

Please sign in to comment.