Skip to content

Commit

Permalink
Merge pull request devgateway#7 from devgateway/task/TOBACCO-800/tets…
Browse files Browse the repository at this point in the history
…im-industry-responses

TOBACCO-800: Add industry responses variables
  • Loading branch information
vchihai authored Jan 3, 2022
2 parents c803462 + 4d183f8 commit 067f757
Show file tree
Hide file tree
Showing 7 changed files with 200 additions and 67 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

<div wicket:id="baseLineNumbers"/>
<div wicket:id="priceAnalysisNumbers"/>
<div wicket:id="industryResponsesNumbers"/>

</div>
</wicket:extend>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,26 +1,23 @@
package org.devgateway.toolkit.forms.wicket.page.edit.dataset;

import org.apache.wicket.Component;
import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.markup.repeater.RepeatingView;
import org.apache.wicket.model.Model;
import org.apache.wicket.model.PropertyModel;
import org.apache.wicket.model.StringResourceModel;
import org.apache.wicket.markup.html.form.Form;
import org.apache.wicket.markup.html.form.FormComponent;
import org.apache.wicket.markup.html.form.validation.AbstractFormValidator;
import org.apache.wicket.request.mapper.parameter.PageParameters;
import org.apache.wicket.spring.injection.annot.SpringBean;
import org.devgateway.toolkit.forms.validators.PositiveBigDecimalValidator;
import org.devgateway.toolkit.forms.wicket.components.form.TextFieldBootstrapFormComponent;
import org.devgateway.toolkit.forms.wicket.page.edit.AbstractEditPage;
import org.devgateway.toolkit.forms.wicket.page.lists.dataset.ListTetsimDatasetPage;
import org.devgateway.toolkit.persistence.dao.categories.TobaccoProduct;
import org.devgateway.toolkit.persistence.dao.data.DatasetStatus;
import org.devgateway.toolkit.persistence.dao.data.TetsimDataset;
import org.devgateway.toolkit.persistence.dao.data.TetsimPriceVariable;
import org.devgateway.toolkit.persistence.service.category.TobaccoProductService;
import org.devgateway.toolkit.persistence.dao.data.TetsimTobaccoProductValue;
import org.devgateway.toolkit.persistence.service.data.TetsimDatasetService;
import org.wicketstuff.annotation.mount.MountPath;

import java.util.List;
import java.math.BigDecimal;

import static org.devgateway.toolkit.forms.WebConstants.MAXIMUM_PERCENTAGE;

/**
* @author vchihai
Expand Down Expand Up @@ -50,6 +47,9 @@ protected void onInitialize() {
editForm.add(getYear());
editForm.add(getBaseLineNumbers());
editForm.add(getPriceAnalysisNumbers());
editForm.add(getIndustryResponsesNumbers());

editForm.add(new TetsimMarketSharePercentageValidator());
}

private TextFieldBootstrapFormComponent<Integer> getYear() {
Expand All @@ -66,4 +66,28 @@ private TetsimBaselineNumbersPanel getBaseLineNumbers() {
private TetsimPriceAnalysisPanel getPriceAnalysisNumbers() {
return new TetsimPriceAnalysisPanel("priceAnalysisNumbers", editForm.getModel());
}

private TetsimIndustryResponsesPanel getIndustryResponsesNumbers() {
return new TetsimIndustryResponsesPanel("industryResponsesNumbers", editForm.getModel());
}

private class TetsimMarketSharePercentageValidator extends AbstractFormValidator {

@Override
public FormComponent<?>[] getDependentFormComponents() {
return new FormComponent[0];
}

@Override
public void validate(final Form<?> form) {
TetsimPriceVariable marketShare = editForm.getModelObject().getMarketShare();
BigDecimal sum = marketShare.getValues().stream()
.map(TetsimTobaccoProductValue::getValue)
.reduce(BigDecimal.ZERO, BigDecimal::add);

if (sum.intValue() > MAXIMUM_PERCENTAGE) {
editForm.error(getString("error.form.validation.marketShare.percentage"));
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
page.title.add=Add TETSIM Dataset
page.title.edit=Edit TETSIM Dataset
year.label=Year
year.label=Year

error.form.validation.marketShare.percentage=The total of all the market share values should add up to 100
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?xml version="1.0" encoding="UTF-8"?>
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:wicket="http://wicket.apache.org">
<body>
<wicket:panel>
<div class="col-md-12">
<h3>Industry responses to the change in taxation:</h3>
</div>

<div class="col-md-12">
<table class="table table-hover table-bordered" border="1">
<thead>
<tr class="headers">
<th wicket:id="industryResponsesHeaders"/>
</tr>
</thead>
<tbody>
<tr wicket:id="industryResponsesVariables"/>
</tbody>
</table>
</div>
</wicket:panel>
</body>
</html>
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
package org.devgateway.toolkit.forms.wicket.page.edit.dataset;

import org.apache.wicket.Component;
import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.markup.html.panel.Panel;
import org.apache.wicket.markup.repeater.RepeatingView;
import org.apache.wicket.model.IModel;
import org.apache.wicket.model.Model;
import org.apache.wicket.model.PropertyModel;
import org.apache.wicket.model.StringResourceModel;
import org.apache.wicket.spring.injection.annot.SpringBean;
import org.devgateway.toolkit.persistence.dao.categories.TobaccoProduct;
import org.devgateway.toolkit.persistence.dao.data.TetsimDataset;
import org.devgateway.toolkit.persistence.service.category.TobaccoProductService;

import java.util.List;

/**
* @author Viorel Chihai
*/
public class TetsimIndustryResponsesPanel extends Panel {

protected final IModel<TetsimDataset> tetsimDatasetIModel;

@SpringBean
protected TobaccoProductService tobaccoProductService;

public TetsimIndustryResponsesPanel(final String id, final IModel<TetsimDataset> tetsimDatasetIModel) {
super(id);
this.tetsimDatasetIModel = tetsimDatasetIModel;
}

@Override
protected void onInitialize() {
super.onInitialize();
add(getIndustryResponsesHeaders());
add(getIndustryResponsesVariables());
}

private Component getIndustryResponsesHeaders() {
RepeatingView analysisHeaders = new RepeatingView("industryResponsesHeaders");
analysisHeaders.add(new Label(analysisHeaders.newChildId(),
Model.of("Industry responses to the change in taxation")));
analysisHeaders.add(new Label(analysisHeaders.newChildId(), Model.of("Unit")));

List<TobaccoProduct> tobaccoProducts = tobaccoProductService.findAllSorted();
for (TobaccoProduct tobaccoProduct : tobaccoProducts) {
analysisHeaders.add(new Label(analysisHeaders.newChildId(),
new PropertyModel<>(tobaccoProduct, "label")));
}

return analysisHeaders;
}

private Component getIndustryResponsesVariables() {
RepeatingView variables = new RepeatingView("industryResponsesVariables");

variables.add(getOverShifting(variables.newChildId()));
variables.add(getUnderShifting(variables.newChildId()));

return variables;
}

/**
* Get overshifting variable panel with tobacco product inputs.
* Mandatory. Numerical fields with decimals.
*
* @param id
* @return TetsimTobaccoProductsVariable
*/
private TetsimTobaccoProductsVariable getOverShifting(final String id) {
return new TetsimTobaccoProductsVariable(id,
new StringResourceModel("overShifting.label"),
new StringResourceModel("overShifting.unit"),
new PropertyModel<>(tetsimDatasetIModel, "overShifting"), true) {
};
}

/**
* Get undershifting variable panel with tobacco product inputs.
* Mandatory. Numerical fields with decimals.
*
* @param id
* @return TetsimTobaccoProductsVariable
*/
private TetsimTobaccoProductsVariable getUnderShifting(final String id) {
return new TetsimTobaccoProductsVariable(id,
new StringResourceModel("underShifting.label"),
new StringResourceModel("underShifting.unit"),
new PropertyModel<>(tetsimDatasetIModel, "underShifting"), true) {
};
}

}


Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
overShifting.label=Overshifting (% change above excise tax increase)
overShifting.unit=Percentage change above excise tax increase

underShifting.label=Change in illicit NOT (proportion of change in discount price): sensitivity factor
underShifting.unit=Undershifting (% change below excise tax increase)

Loading

0 comments on commit 067f757

Please sign in to comment.