diff --git a/citizen-intelligence-agency/src/main/java/com/hack23/cia/web/impl/ui/application/views/common/chartfactory/impl/AbstractChartDataManagerImpl.java b/citizen-intelligence-agency/src/main/java/com/hack23/cia/web/impl/ui/application/views/common/chartfactory/impl/AbstractChartDataManagerImpl.java index 97f8fffff0..d1b3d380ef 100644 --- a/citizen-intelligence-agency/src/main/java/com/hack23/cia/web/impl/ui/application/views/common/chartfactory/impl/AbstractChartDataManagerImpl.java +++ b/citizen-intelligence-agency/src/main/java/com/hack23/cia/web/impl/ui/application/views/common/chartfactory/impl/AbstractChartDataManagerImpl.java @@ -27,47 +27,13 @@ import com.hack23.cia.service.api.ApplicationManager; import com.hack23.cia.service.api.DataContainer; import com.hack23.cia.web.impl.ui.application.views.common.chartfactory.api.ChartOptions; -import com.hack23.cia.web.impl.ui.application.views.common.sizing.ContentRatio; -import com.vaadin.server.Page; -import com.vaadin.server.Sizeable.Unit; import com.vaadin.ui.AbstractOrderedLayout; -import com.vaadin.ui.HorizontalLayout; -import com.vaadin.ui.Panel; /** * The Class AbstractChartDataManagerImpl. */ public abstract class AbstractChartDataManagerImpl { - /** The Constant CHART_MARGIN_SIZE. */ - private static final int CHART_BOTTOM_MARGIN_SIZE = 2; - - /** The Constant CHART_LEFT_MARGIN. */ - private static final int CHART_LEFT_MARGIN= 2; - - /** The Constant CHART_RIGHT_MARGIN. */ - private static final int CHART_RIGHT_MARGIN = 2; - - /** The Constant CHART_TOP_MARGIN_SIZE. */ - private static final int CHART_TOP_MARGIN_SIZE = 2; - - /** The Constant CHART_WIDTH_REDUCTION. */ - private static final int CHART_WIDTH_REDUCTION = 50; - - /** The Constant HEIGHT_PERCENTAGE_FULL_PAGE. */ - private static final double HEIGHT_PERCENTAGE_FULL_PAGE = 0.8; - /** The Constant HEIGHT_PERCETAGE_HALF_PAGE. */ - private static final double HEIGHT_PERCETAGE_HALF_PAGE = 0.5; - - /** The Constant MINIMUM_CHART_HEIGHT_FULL_PAGE. */ - private static final int MINIMUM_CHART_HEIGHT_FULL_PAGE = 400; - - /** The Constant MINIMUM_CHART_WIDTH. */ - private static final int MINIMUM_CHART_WIDTH = 600; - - /** The Constant NINIMUM_CHART_HEIGHT_HALF_PAGE. */ - private static final int NINIMUM_CHART_HEIGHT_HALF_PAGE = 200; - /** The application manager. */ @Autowired private ApplicationManager applicationManager; @@ -76,7 +42,6 @@ public abstract class AbstractChartDataManagerImpl { @Autowired private ChartOptions chartOptions; - /** * Instantiates a new abstract chart data manager impl. */ @@ -84,72 +49,20 @@ public AbstractChartDataManagerImpl() { super(); } - /** - * Gets the chart window height. - * - * @param fullPage the full page - * @return the chart window height - */ - private static int getChartWindowHeight(final boolean fullPage) { - if (fullPage) { - return Math.max((int) (Page.getCurrent().getBrowserWindowHeight() * HEIGHT_PERCENTAGE_FULL_PAGE) ,MINIMUM_CHART_HEIGHT_FULL_PAGE); - } else { - return Math.max((int) (Page.getCurrent().getBrowserWindowHeight() * HEIGHT_PERCETAGE_HALF_PAGE),NINIMUM_CHART_HEIGHT_HALF_PAGE); - } - } - - /** - * Gets the chart window width. - * - * @return the chart window width - */ - private static int getChartWindowWidth() { - return Math.max(Page.getCurrent().getBrowserWindowWidth() - CHART_WIDTH_REDUCTION,MINIMUM_CHART_WIDTH); - } - /** * Adds the chart. * - * @param content - * the content + * @param layout + * the layout * @param caption * the caption * @param chart * the chart - * @param fullPage - * the full page + * @param isFullPage + * the isFullPage */ - protected static final void addChart(final AbstractOrderedLayout content,final String caption, final DCharts chart, final boolean fullPage) { - final HorizontalLayout horizontalLayout = new HorizontalLayout(); - - final int browserWindowWidth = getChartWindowWidth(); - - final int browserWindowHeight = getChartWindowHeight(fullPage); - - horizontalLayout.setWidth(browserWindowWidth, Unit.PIXELS); - horizontalLayout.setHeight(browserWindowHeight, Unit.PIXELS); - horizontalLayout.setMargin(true); - horizontalLayout.setSpacing(false); - horizontalLayout.addStyleName("v-layout-content-overview-panel-level1"); - - final Panel formPanel = new Panel(); - formPanel.setSizeFull(); - formPanel.setContent(horizontalLayout); - formPanel.setCaption(caption); - - content.addComponent(formPanel); - content.setExpandRatio(formPanel, ContentRatio.LARGE); - - - chart.setWidth(100, Unit.PERCENTAGE); - chart.setHeight(100, Unit.PERCENTAGE); - chart.setMarginRight(CHART_RIGHT_MARGIN); - chart.setMarginLeft(CHART_LEFT_MARGIN); - chart.setMarginBottom(CHART_BOTTOM_MARGIN_SIZE); - chart.setMarginTop(CHART_TOP_MARGIN_SIZE); - - horizontalLayout.addComponent(chart); - chart.setCaption(caption); + protected static final void addChart(final AbstractOrderedLayout layout, final String caption, final DCharts chart, final boolean isFullPage) { + ChartUtils.addChart(layout, caption, chart, isFullPage); } /** @@ -173,25 +86,23 @@ protected final ChartOptions getChartOptions() { /** * Gets the party name. * - * @param party - * the party + * @param partySummary + * the partySummary * @return the party name */ - protected final String getPartyName(final String party) { + protected final String getPartyName(final String partySummary) { final DataContainer dataContainer = applicationManager .getDataContainer(ViewRiksdagenParty.class); final Optional matchingObjects =dataContainer.getAll().stream(). - filter((final ViewRiksdagenParty p) -> p.getPartyId().equalsIgnoreCase(party)). + filter((final ViewRiksdagenParty p) -> p.getPartyId().equalsIgnoreCase(partySummary)). findFirst(); if (matchingObjects.isPresent()) { return matchingObjects.get().getPartyName(); } else { - return party; + return partySummary; } } - - } diff --git a/citizen-intelligence-agency/src/main/java/com/hack23/cia/web/impl/ui/application/views/common/chartfactory/impl/AbstractGhantChartManagerImpl.java b/citizen-intelligence-agency/src/main/java/com/hack23/cia/web/impl/ui/application/views/common/chartfactory/impl/AbstractGhantChartManagerImpl.java index b898e29f11..58c4746539 100644 --- a/citizen-intelligence-agency/src/main/java/com/hack23/cia/web/impl/ui/application/views/common/chartfactory/impl/AbstractGhantChartManagerImpl.java +++ b/citizen-intelligence-agency/src/main/java/com/hack23/cia/web/impl/ui/application/views/common/chartfactory/impl/AbstractGhantChartManagerImpl.java @@ -93,47 +93,41 @@ private static final Gantt createGantt() { * @return the date */ private static final Date stripDatesAfterCurrentDate(final Date toDate) { - final DateTime currentTime = new DateTime(); - - if (currentTime.isBefore(toDate.getTime())) { - return currentTime.plusDays(1).toDate(); - } else { - return toDate; - } + return DateUtils.stripDatesAfterCurrentDate(toDate); } /** * Adds the view generic role member to step. * - * @param stepName - * the step name + * @param roleName + * the role name * @param step * the step - * @param assignments - * the assignments + * @param roleAssignments + * the role assignments * @param stepMapping * the step mapping */ - private void addViewGenericRoleMemberToStep(final String stepName, final Step step, final List assignments, + private void addViewGenericRoleMemberToStep(final String roleName, final Step step, final List roleAssignments, final StepMapping stepMapping) { - for (final T assignmentData : assignments) { + for (final T roleMember : roleAssignments) { String subStepName = ""; - if (stepMapping.getRoleCode(assignmentData) != null) { - subStepName = new StringBuilder().append(stepMapping.getFirstName(assignmentData)) - .append(CONTENT_SEPARATOR).append(stepMapping.getLastName(assignmentData)) - .append(PARTY_START_TAG).append(stepMapping.getParty(assignmentData)).append(PARTY_END_TAG) + if (stepMapping.getRoleCode(roleMember) != null) { + subStepName = new StringBuilder().append(stepMapping.getFirstName(roleMember)) + .append(CONTENT_SEPARATOR).append(stepMapping.getLastName(roleMember)) + .append(PARTY_START_TAG).append(stepMapping.getParty(roleMember)).append(PARTY_END_TAG) .toString(); } - final SubStep sameRoleSubStep = new SubStep(stepName + '.' + subStepName,CaptionMode.HTML); - sameRoleSubStep.setDescription(stepName + '.' + subStepName); - sameRoleSubStep.setBackgroundColor(stepMapping.getBackgroundColor(assignmentData)); + final SubStep sameRoleSubStep = new SubStep(roleName + '.' + subStepName,CaptionMode.HTML); + sameRoleSubStep.setDescription(roleName + '.' + subStepName); + sameRoleSubStep.setBackgroundColor(stepMapping.getBackgroundColor(roleMember)); - sameRoleSubStep.setStartDate(stepMapping.getFromDate(assignmentData).getTime()); - sameRoleSubStep.setEndDate(stripDatesAfterCurrentDate(stepMapping.getToDate(assignmentData)).getTime()); + sameRoleSubStep.setStartDate(stepMapping.getFromDate(roleMember).getTime()); + sameRoleSubStep.setEndDate(stripDatesAfterCurrentDate(stepMapping.getToDate(roleMember)).getTime()); step.addSubStep(sameRoleSubStep); } diff --git a/citizen-intelligence-agency/src/main/java/com/hack23/cia/web/impl/ui/application/views/common/chartfactory/impl/AdminChartDataManagerImpl.java b/citizen-intelligence-agency/src/main/java/com/hack23/cia/web/impl/ui/application/views/common/chartfactory/impl/AdminChartDataManagerImpl.java index 4a623f8b97..012064a060 100644 --- a/citizen-intelligence-agency/src/main/java/com/hack23/cia/web/impl/ui/application/views/common/chartfactory/impl/AdminChartDataManagerImpl.java +++ b/citizen-intelligence-agency/src/main/java/com/hack23/cia/web/impl/ui/application/views/common/chartfactory/impl/AdminChartDataManagerImpl.java @@ -8,7 +8,7 @@ * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, + * distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. @@ -19,9 +19,7 @@ package com.hack23.cia.web.impl.ui.application.views.common.chartfactory.impl; import java.io.Serializable; -import java.text.SimpleDateFormat; import java.util.List; -import java.util.Locale; import java.util.Map; import java.util.Map.Entry; import java.util.Objects; @@ -56,9 +54,6 @@ @Service public final class AdminChartDataManagerImpl extends AbstractChartDataManagerImpl implements AdminChartDataManager { - /** The Constant DD_MMM_YYYY. */ - private static final String DD_MMM_YYYY = "dd-MMM-yyyy"; - /** The Constant PAGE_HITS. */ private static final String PAGE_HITS = "Page Hits"; @@ -77,32 +72,34 @@ public AdminChartDataManagerImpl() { * * @param label the label * @param series the series - * @param list the list + * @param dailySummaries the dailySummaries * @param dataSeries the data series - * @param simpleDateFormat the simple date format * @param t the t */ private static void addViewApplicationActionEventPageElementDailySummaryValues(final String label, - final Series series, final List list, - final DataSeries dataSeries, final SimpleDateFormat simpleDateFormat, + final Series series, final List dailySummaries, + final DataSeries dataSeries, final ToLongFunction t) { series.addSeries(new XYseries().setLabel(label)); dataSeries.newSeries(); - for (final ViewApplicationActionEventPageElementDailySummary item : list) { - dataSeries.add(simpleDateFormat.format(item.getEmbeddedId().getCreatedDate()), t.applyAsLong(item)); + for (final ViewApplicationActionEventPageElementDailySummary summary : dailySummaries) { + dataSeries.add(DateUtils.formatDate(summary.getEmbeddedId().getCreatedDate()), t.applyAsLong(summary)); } } + /** + * Creates the application action event page daily summary chart. + * + * @param layout the layout + */ @Override - public void createApplicationActionEventPageDailySummaryChart(final AbstractOrderedLayout content) { + public void createApplicationActionEventPageDailySummaryChart(final AbstractOrderedLayout layout) { final Map> map = getApplicationActionEventPageDailySummaryMap(); final DataSeries dataSeries = new DataSeries(); - final SimpleDateFormat simpleDateFormat = new SimpleDateFormat(DD_MMM_YYYY, Locale.ENGLISH); - final Series series = new Series(); for (final Entry> entry : map.entrySet()) { @@ -114,7 +111,7 @@ public void createApplicationActionEventPageDailySummaryChart(final AbstractOrde final List list = entry.getValue(); for (final ViewApplicationActionEventPageDailySummary dataSummaryDaily : list) { dataSeries.add( - simpleDateFormat.format( + DateUtils.formatDate( dataSummaryDaily.getEmbeddedId().getCreatedDate()), dataSummaryDaily.getHits()); } @@ -122,35 +119,47 @@ public void createApplicationActionEventPageDailySummaryChart(final AbstractOrde } - addChart(content, "Application Action Events daily Summary", + addChart(layout, "Application Action Events daily Summary", new DCharts().setDataSeries(dataSeries) .setOptions(getChartOptions().createOptionsXYDateFloatLogYAxisLegendOutside(series)).show(), true); } + /** + * Creates the application action event page element daily summary chart. + * + * @param layout the layout + * @param page the page + * @param elementId the element id + */ @Override - public void createApplicationActionEventPageElementDailySummaryChart(final AbstractOrderedLayout content, + public void createApplicationActionEventPageElementDailySummaryChart(final AbstractOrderedLayout layout, final String page, final String elementId) { - final List list = getApplicationActionEventPageElementDailySummaryList( + final List dailySummaries = getApplicationActionEventPageElementDailySummaryList( page, elementId); - final SimpleDateFormat simpleDateFormat = new SimpleDateFormat(DD_MMM_YYYY, Locale.ENGLISH); final Series series = new Series(); final DataSeries dataSeries = new DataSeries(); - addViewApplicationActionEventPageElementDailySummaryValues(PAGE_HITS, series, list, dataSeries, - simpleDateFormat, ViewApplicationActionEventPageElementDailySummary::getHits); - addViewApplicationActionEventPageElementDailySummaryValues(PAGE_RANK, series, list, dataSeries, - simpleDateFormat, ViewApplicationActionEventPageElementDailySummary::getRank); + addViewApplicationActionEventPageElementDailySummaryValues(PAGE_HITS, series, dailySummaries, dataSeries, + ViewApplicationActionEventPageElementDailySummary::getHits); + addViewApplicationActionEventPageElementDailySummaryValues(PAGE_RANK, series, dailySummaries, dataSeries, + ViewApplicationActionEventPageElementDailySummary::getRank); - addChart(content, "Page element Action Events daily Summary", + addChart(layout, "Page element Action Events daily Summary", new DCharts().setDataSeries(dataSeries) .setOptions(getChartOptions().createOptionsXYDateFloatLogYAxisLegendOutside(series)).show(), true); } + /** + * Creates the application action event page mode daily summary chart. + * + * @param layout the layout + * @param page the page + */ @Override - public void createApplicationActionEventPageModeDailySummaryChart(final AbstractOrderedLayout content, + public void createApplicationActionEventPageModeDailySummaryChart(final AbstractOrderedLayout layout, final String page) { final Map> map = getApplicationActionEventPageModeDailySummaryMap( @@ -158,8 +167,6 @@ public void createApplicationActionEventPageModeDailySummaryChart(final Abstract final DataSeries dataSeries = new DataSeries(); - final SimpleDateFormat simpleDateFormat = new SimpleDateFormat(DD_MMM_YYYY, Locale.ENGLISH); - final Series series = new Series(); for (final Entry> entry : map.entrySet()) { @@ -170,13 +177,13 @@ public void createApplicationActionEventPageModeDailySummaryChart(final Abstract dataSeries.newSeries(); final List list = entry.getValue(); for (final ViewApplicationActionEventPageModeDailySummary item : list) { - dataSeries.add(simpleDateFormat.format(item.getEmbeddedId().getCreatedDate()), item.getHits()); + dataSeries.add(DateUtils.formatDate(item.getEmbeddedId().getCreatedDate()), item.getHits()); } } } - addChart(content, "Page Action Events daily Summary", + addChart(layout, "Page Action Events daily Summary", new DCharts().setDataSeries(dataSeries) .setOptions(getChartOptions().createOptionsXYDateFloatLogYAxisLegendOutside(series)).show(), true); @@ -240,13 +247,17 @@ private Map> getApp .collect(Collectors.groupingBy(t -> t.getEmbeddedId().getPageMode())); } + /** + * Creates the application session page daily summary chart. + * + * @param layout the layout + */ @Override - public void createApplicationSessionPageDailySummaryChart(final VerticalLayout content) { - final SimpleDateFormat simpleDateFormat = new SimpleDateFormat(DD_MMM_YYYY, Locale.ENGLISH); + public void createApplicationSessionPageDailySummaryChart(final VerticalLayout layout) { final DataContainer dataContainer = getApplicationManager().getDataContainer(ApplicationSession.class); final Map sessionByDayMap = dataContainer.getAll().stream() - .collect(Collectors.groupingBy(p -> simpleDateFormat.format(p.getCreatedDate()), Collectors.counting())); + .collect(Collectors.groupingBy(p -> DateUtils.formatDate(p.getCreatedDate()), Collectors.counting())); final DataSeries dataSeries = new DataSeries(); final Series series = new Series(); @@ -258,7 +269,7 @@ public void createApplicationSessionPageDailySummaryChart(final VerticalLayout c entry.getValue()); } - addChart(content, "Application Active Daily Users", + addChart(layout, "Application Active Daily Users", new DCharts().setDataSeries(dataSeries) .setOptions(getChartOptions().createOptionsXYDateFloatLogYAxisLegendOutside(series)).show(), true); diff --git a/citizen-intelligence-agency/src/main/java/com/hack23/cia/web/impl/ui/application/views/common/chartfactory/impl/BallotChartDataManagerImpl.java b/citizen-intelligence-agency/src/main/java/com/hack23/cia/web/impl/ui/application/views/common/chartfactory/impl/BallotChartDataManagerImpl.java index d94e738623..99dd2a772b 100644 --- a/citizen-intelligence-agency/src/main/java/com/hack23/cia/web/impl/ui/application/views/common/chartfactory/impl/BallotChartDataManagerImpl.java +++ b/citizen-intelligence-agency/src/main/java/com/hack23/cia/web/impl/ui/application/views/common/chartfactory/impl/BallotChartDataManagerImpl.java @@ -46,8 +46,15 @@ public BallotChartDataManagerImpl() { } + /** + * Creates the chart. + * + * @param tab the tab + * @param content the content + * @param partySummaries the party summaries + */ @Override - public void createChart(final Tab tab,final AbstractOrderedLayout content,final List partyList) { + public void createChart(final Tab tab,final AbstractOrderedLayout content,final List partySummaries) { final DataSeries dataSeries = new DataSeries(); final Series series = new Series(); @@ -58,18 +65,18 @@ public void createChart(final Tab tab,final AbstractOrderedLayout content,final series.addSeries(new XYseries().setLabel("Absent")); String caption=null; - for (final ViewRiksdagenVoteDataBallotPartySummary viewRiksdagenVoteDataBallotPartySummary : partyList) { + for (final ViewRiksdagenVoteDataBallotPartySummary partySummary : partySummaries) { if (caption == null) { - caption = "Party Summary : " + viewRiksdagenVoteDataBallotPartySummary.getEmbeddedId().getIssue() + " " + viewRiksdagenVoteDataBallotPartySummary.getEmbeddedId().getConcern(); + caption = "Party Summary : " + partySummary.getEmbeddedId().getIssue() + " " + partySummary.getEmbeddedId().getConcern(); content.setCaption(caption); tab.setCaption(caption); } dataSeries.newSeries() - .add(getPartyName(viewRiksdagenVoteDataBallotPartySummary.getEmbeddedId().getParty()), viewRiksdagenVoteDataBallotPartySummary.getPartyYesVotes()) - .add(getPartyName(viewRiksdagenVoteDataBallotPartySummary.getEmbeddedId().getParty()),viewRiksdagenVoteDataBallotPartySummary.getPartyNoVotes()) - .add(getPartyName(viewRiksdagenVoteDataBallotPartySummary.getEmbeddedId().getParty()),viewRiksdagenVoteDataBallotPartySummary.getPartyAbstainVotes()) - .add(getPartyName(viewRiksdagenVoteDataBallotPartySummary.getEmbeddedId().getParty()),viewRiksdagenVoteDataBallotPartySummary.getPartyAbsentVotes()); + .add(getPartyName(partySummary.getEmbeddedId().getParty()), partySummary.getPartyYesVotes()) + .add(getPartyName(partySummary.getEmbeddedId().getParty()),partySummary.getPartyNoVotes()) + .add(getPartyName(partySummary.getEmbeddedId().getParty()),partySummary.getPartyAbstainVotes()) + .add(getPartyName(partySummary.getEmbeddedId().getParty()),partySummary.getPartyAbsentVotes()); } @@ -78,16 +85,23 @@ public void createChart(final Tab tab,final AbstractOrderedLayout content,final + /** + * Creates the chart. + * + * @param tab the tab + * @param content the content + * @param ballotSummary the ballot summary + */ @Override - public void createChart(final Tab tab,final AbstractOrderedLayout content,final ViewRiksdagenVoteDataBallotSummary viewRiksdagenVoteDataBallotSummary) { + public void createChart(final Tab tab,final AbstractOrderedLayout content,final ViewRiksdagenVoteDataBallotSummary ballotSummary) { final DataSeries dataSeries = new DataSeries(); - dataSeries.newSeries().add("Yes", viewRiksdagenVoteDataBallotSummary.getYesVotes()); - dataSeries.newSeries().add("No", viewRiksdagenVoteDataBallotSummary.getNoVotes()); - dataSeries.newSeries().add("Abstain", viewRiksdagenVoteDataBallotSummary.getAbstainVotes()); - dataSeries.newSeries().add("Absent", viewRiksdagenVoteDataBallotSummary.getAbsentVotes()); + dataSeries.newSeries().add("Yes", ballotSummary.getYesVotes()); + dataSeries.newSeries().add("No", ballotSummary.getNoVotes()); + dataSeries.newSeries().add("Abstain", ballotSummary.getAbstainVotes()); + dataSeries.newSeries().add("Absent", ballotSummary.getAbsentVotes()); - final String caption = "Summary : " +viewRiksdagenVoteDataBallotSummary.getEmbeddedId().getIssue() + " " + viewRiksdagenVoteDataBallotSummary.getEmbeddedId().getConcern(); + final String caption = "Summary : " +ballotSummary.getEmbeddedId().getIssue() + " " + ballotSummary.getEmbeddedId().getConcern(); tab.setCaption(caption); addChart(content,caption, new DCharts().setDataSeries(dataSeries).setOptions(getChartOptions().createOptionsDonoutChart()).show(), true); diff --git a/citizen-intelligence-agency/src/main/java/com/hack23/cia/web/impl/ui/application/views/common/chartfactory/impl/ChartDataManagerImpl.java b/citizen-intelligence-agency/src/main/java/com/hack23/cia/web/impl/ui/application/views/common/chartfactory/impl/ChartDataManagerImpl.java index e65cb1f5f7..c0dcde8e7b 100644 --- a/citizen-intelligence-agency/src/main/java/com/hack23/cia/web/impl/ui/application/views/common/chartfactory/impl/ChartDataManagerImpl.java +++ b/citizen-intelligence-agency/src/main/java/com/hack23/cia/web/impl/ui/application/views/common/chartfactory/impl/ChartDataManagerImpl.java @@ -39,14 +39,21 @@ public ChartDataManagerImpl() { } + /** + * Creates the chart panel. + * + * @param layout the layout + * @param chartDataSeries the chart data series + * @param chartCaption the chart caption + */ @Override - public void createChartPanel(final AbstractOrderedLayout content,final DataSeries dataSeries, final String caption) { + public void createChartPanel(final AbstractOrderedLayout layout,final DataSeries chartDataSeries, final String chartCaption) { - final DCharts chart = new DCharts().setDataSeries(dataSeries).setOptions(getChartOptions().createOptionsPieChart()); + final DCharts chart = new DCharts().setDataSeries(chartDataSeries).setOptions(getChartOptions().createOptionsPieChart()); chart.show(); - addChart(content,caption, chart, true); + addChart(layout,chartCaption, chart, true); } diff --git a/citizen-intelligence-agency/src/main/java/com/hack23/cia/web/impl/ui/application/views/common/chartfactory/impl/ChartOptionsImpl.java b/citizen-intelligence-agency/src/main/java/com/hack23/cia/web/impl/ui/application/views/common/chartfactory/impl/ChartOptionsImpl.java index c19ee300ae..44f4961c5a 100644 --- a/citizen-intelligence-agency/src/main/java/com/hack23/cia/web/impl/ui/application/views/common/chartfactory/impl/ChartOptionsImpl.java +++ b/citizen-intelligence-agency/src/main/java/com/hack23/cia/web/impl/ui/application/views/common/chartfactory/impl/ChartOptionsImpl.java @@ -279,43 +279,77 @@ private static Legend setLegendStyling(final Legend legend) { return legend; } + /** + * Creates the options country line chart. + * + * @param chartSeries the chart series + * @return the options + */ @Override - public Options createOptionsCountryLineChart(final Series series) { - final Axes axes = new Axes().addAxis(new XYaxis().setRenderer(AxisRenderers.DATE) + public Options createOptionsCountryLineChart(final Series chartSeries) { + final Axes chartAxes = new Axes().addAxis(new XYaxis().setRenderer(AxisRenderers.DATE) .setTickOptions(new AxisTickRenderer().setFormatString(YEAR_MONTH_DAY_FORMAT).setFontFamily(FONT_FAMILY).setTextColor(TEXT_COLOR).setFontSize(FONT_SIZE)) .setNumberTicks(NUMBER_TICKS_DATE)).addAxis(new XYaxis(XYaxes.Y).setTickOptions(new AxisTickRenderer().setFontFamily(FONT_FAMILY).setTextColor(TEXT_COLOR).setFontSize(FONT_SIZE)).setNumberTicks(NUMBER_TICKS)); - return new Options().addOption(new SeriesDefaults()).addOption(axes) - .addOption(createHighLighterNorth()).addOption(series).addOption(createLegendInsideOneRow()) + return new Options().addOption(new SeriesDefaults()).addOption(chartAxes) + .addOption(createHighLighterNorth()).addOption(chartSeries).addOption(createLegendInsideOneRow()) .addOption(createDefaultGrid()).addOption(createCursor()); } + /** + * Creates the options donout chart. + * + * @return the options + */ @Override public Options createOptionsDonoutChart() { return new Options().setSeriesDefaults(createDonoutSeriesDefault()).setLegend(createdLegendEnhancedInsideNorthWest()) .setHighlighter(createHighLighter()).addOption(createDefaultGrid()).addOption(createCursor()); } + /** + * Creates the options donout chart with series. + * + * @param chartSeries the chart series + * @return the options + */ @Override - public Options createOptionsDonoutChartWithSeries(final Series series) { + public Options createOptionsDonoutChartWithSeries(final Series chartSeries) { return new Options().setSeriesDefaults(createDonoutSeriesDefault()).setLegend(createdLegendEnhancedInsideNorthWest()) - .setHighlighter(createHighLighter()).addOption(series).addOption(createDefaultGrid()).addOption(createCursor()); + .setHighlighter(createHighLighter()).addOption(chartSeries).addOption(createDefaultGrid()).addOption(createCursor()); } + /** + * Creates the options party line chart. + * + * @param chartSeries the chart series + * @return the options + */ @Override - public Options createOptionsPartyLineChart(final Series series) { + public Options createOptionsPartyLineChart(final Series chartSeries) { return new Options().addOption(new SeriesDefaults()).addOption(createAxesXYDateFloat()) - .addOption(createHighLighterNorth()).addOption(createCursor()).addOption(series) + .addOption(createHighLighterNorth()).addOption(createCursor()).addOption(chartSeries) .addOption(createLegendOutside()).addOption(createDefaultGrid()); } + /** + * Creates the options person line chart. + * + * @param chartSeries the chart series + * @return the options + */ @Override - public Options createOptionsPersonLineChart(final Series series) { + public Options createOptionsPersonLineChart(final Series chartSeries) { return new Options().addOption(new SeriesDefaults()).addOption(createAxesXYDateFloat()) - .addOption(createHighLighterNorth()).addOption(createCursor()).addOption(series) + .addOption(createHighLighterNorth()).addOption(createCursor()).addOption(chartSeries) .addOption(createLegendOutside()).addOption(createDefaultGrid()); } + /** + * Creates the options pie chart. + * + * @return the options + */ @Override public Options createOptionsPieChart() { return new Options().setSeriesDefaults(createSeriesDefaultPieChart()) @@ -323,16 +357,28 @@ public Options createOptionsPieChart() { .addOption(createDefaultGrid()).addOption(createCursor()); } + /** + * Creates the options XY date float legend inside one column. + * + * @param chartSeries the chart series + * @return the options + */ @Override - public Options createOptionsXYDateFloatLegendInsideOneColumn(final Series series) { + public Options createOptionsXYDateFloatLegendInsideOneColumn(final Series chartSeries) { return new Options().addOption(new SeriesDefaults()).addOption(createAxesXYDateFloat()) - .addOption(createHighLighterNorth()).addOption(series).addOption(createLegendOutsideOneColumn()) + .addOption(createHighLighterNorth()).addOption(chartSeries).addOption(createLegendOutsideOneColumn()) .addOption(createDefaultGrid()).addOption(createCursor()); } + /** + * Creates the options XY date float log Y axis legend outside. + * + * @param chartSeries the chart series + * @return the options + */ @Override - public Options createOptionsXYDateFloatLogYAxisLegendOutside(final Series series) { - return new Options().addOption(new SeriesDefaults()).addOption(series).addOption(createAxesXYDateFloatLog()) + public Options createOptionsXYDateFloatLogYAxisLegendOutside(final Series chartSeries) { + return new Options().addOption(new SeriesDefaults()).addOption(chartSeries).addOption(createAxesXYDateFloatLog()) .addOption(createHighLighterNorth()).addOption(createLegendOutside()) .addOption(createDefaultGrid()).addOption(createCursor()); } diff --git a/citizen-intelligence-agency/src/main/java/com/hack23/cia/web/impl/ui/application/views/common/chartfactory/impl/ChartUtils.java b/citizen-intelligence-agency/src/main/java/com/hack23/cia/web/impl/ui/application/views/common/chartfactory/impl/ChartUtils.java new file mode 100644 index 0000000000..b4e40bdf2e --- /dev/null +++ b/citizen-intelligence-agency/src/main/java/com/hack23/cia/web/impl/ui/application/views/common/chartfactory/impl/ChartUtils.java @@ -0,0 +1,115 @@ +package com.hack23.cia.web.impl.ui.application.views.common.chartfactory.impl; + +import org.dussan.vaadin.dcharts.DCharts; + +import com.hack23.cia.web.impl.ui.application.views.common.sizing.ContentRatio; +import com.vaadin.server.Page; +import com.vaadin.server.Sizeable.Unit; +import com.vaadin.ui.AbstractOrderedLayout; +import com.vaadin.ui.HorizontalLayout; +import com.vaadin.ui.Panel; + +/** + * The Class ChartUtils. + */ +public final class ChartUtils { + + /** The Constant CHART_BOTTOM_MARGIN_SIZE. */ + private static final int CHART_BOTTOM_MARGIN_SIZE = 2; + + /** The Constant CHART_LEFT_MARGIN. */ + private static final int CHART_LEFT_MARGIN = 2; + + /** The Constant CHART_RIGHT_MARGIN. */ + private static final int CHART_RIGHT_MARGIN = 2; + + /** The Constant CHART_TOP_MARGIN_SIZE. */ + private static final int CHART_TOP_MARGIN_SIZE = 2; + + /** The Constant CHART_WIDTH_REDUCTION. */ + private static final int CHART_WIDTH_REDUCTION = 50; + + /** The Constant HEIGHT_PERCENTAGE_FULL_PAGE. */ + private static final double HEIGHT_PERCENTAGE_FULL_PAGE = 0.8; + + /** The Constant HEIGHT_PERCETAGE_HALF_PAGE. */ + private static final double HEIGHT_PERCETAGE_HALF_PAGE = 0.5; + + /** The Constant MINIMUM_CHART_HEIGHT_FULL_PAGE. */ + private static final int MINIMUM_CHART_HEIGHT_FULL_PAGE = 400; + + /** The Constant MINIMUM_CHART_WIDTH. */ + private static final int MINIMUM_CHART_WIDTH = 600; + + /** The Constant NINIMUM_CHART_HEIGHT_HALF_PAGE. */ + private static final int NINIMUM_CHART_HEIGHT_HALF_PAGE = 200; + + /** + * Instantiates a new chart utils. + */ + private ChartUtils() { + // Utility class + } + + /** + * Gets the chart window height. + * + * @param isFullPage the is full page + * @return the chart window height + */ + public static int getChartWindowHeight(final boolean isFullPage) { + if (isFullPage) { + return Math.max((int) (Page.getCurrent().getBrowserWindowHeight() * HEIGHT_PERCENTAGE_FULL_PAGE), MINIMUM_CHART_HEIGHT_FULL_PAGE); + } else { + return Math.max((int) (Page.getCurrent().getBrowserWindowHeight() * HEIGHT_PERCETAGE_HALF_PAGE), NINIMUM_CHART_HEIGHT_HALF_PAGE); + } + } + + /** + * Gets the chart window width. + * + * @return the chart window width + */ + public static int getChartWindowWidth() { + return Math.max(Page.getCurrent().getBrowserWindowWidth() - CHART_WIDTH_REDUCTION, MINIMUM_CHART_WIDTH); + } + + /** + * Adds the chart. + * + * @param layout the layout + * @param caption the caption + * @param chart the chart + * @param isFullPage the is full page + */ + public static void addChart(final AbstractOrderedLayout layout, final String caption, final DCharts chart, final boolean isFullPage) { + final HorizontalLayout horizontalLayout = new HorizontalLayout(); + + final int browserWindowWidth = getChartWindowWidth(); + final int browserWindowHeight = getChartWindowHeight(isFullPage); + + horizontalLayout.setWidth(browserWindowWidth, Unit.PIXELS); + horizontalLayout.setHeight(browserWindowHeight, Unit.PIXELS); + horizontalLayout.setMargin(true); + horizontalLayout.setSpacing(false); + horizontalLayout.addStyleName("v-layout-content-overview-panel-level1"); + + final Panel formPanel = new Panel(); + formPanel.setSizeFull(); + formPanel.setContent(horizontalLayout); + formPanel.setCaption(caption); + + layout.addComponent(formPanel); + layout.setExpandRatio(formPanel, ContentRatio.LARGE); + + chart.setWidth(100, Unit.PERCENTAGE); + chart.setHeight(100, Unit.PERCENTAGE); + chart.setMarginRight(CHART_RIGHT_MARGIN); + chart.setMarginLeft(CHART_LEFT_MARGIN); + chart.setMarginBottom(CHART_BOTTOM_MARGIN_SIZE); + chart.setMarginTop(CHART_TOP_MARGIN_SIZE); + + horizontalLayout.addComponent(chart); + chart.setCaption(caption); + } +} diff --git a/citizen-intelligence-agency/src/main/java/com/hack23/cia/web/impl/ui/application/views/common/chartfactory/impl/CommitteeGhantChartManagerImpl.java b/citizen-intelligence-agency/src/main/java/com/hack23/cia/web/impl/ui/application/views/common/chartfactory/impl/CommitteeGhantChartManagerImpl.java index 460fe3aa8d..bc93994503 100644 --- a/citizen-intelligence-agency/src/main/java/com/hack23/cia/web/impl/ui/application/views/common/chartfactory/impl/CommitteeGhantChartManagerImpl.java +++ b/citizen-intelligence-agency/src/main/java/com/hack23/cia/web/impl/ui/application/views/common/chartfactory/impl/CommitteeGhantChartManagerImpl.java @@ -43,27 +43,42 @@ public CommitteeGhantChartManagerImpl() { super(); } + /** + * Gets the comparator. + * + * @return the comparator + */ @Override protected Comparator getComparator() { return (o1, o2) -> o1.getFromDate().compareTo(o2.getFromDate()); } + /** + * Gets the role mapping. + * + * @return the role mapping + */ @Override protected Function getRoleMapping() { return new RoleMapping(); } + /** + * Gets the step mapping. + * + * @return the step mapping + */ @Override protected StepMapping getStepMapping() { return new StepMapping<>() { @Override - public String getBackgroundColor(final ViewRiksdagenCommitteeRoleMember t) { + public String getBackgroundColor(final ViewRiksdagenCommitteeRoleMember roleMember) { String color; - if (t.getRoleCode().toLowerCase(Locale.ENGLISH).contains("suppleant")) { + if (roleMember.getRoleCode().toLowerCase(Locale.ENGLISH).contains("suppleant")) { color = "ded858"; - } else if (t.getRoleCode().toLowerCase(Locale.ENGLISH).contains("ordförande")) { + } else if (roleMember.getRoleCode().toLowerCase(Locale.ENGLISH).contains("ordförande")) { color = "3271c8"; } else { color = "0eab76"; @@ -73,38 +88,38 @@ public String getBackgroundColor(final ViewRiksdagenCommitteeRoleMember t) { } @Override - public Object getFirstName(final ViewRiksdagenCommitteeRoleMember t) { - return t.getFirstName(); + public Object getFirstName(final ViewRiksdagenCommitteeRoleMember roleMember) { + return roleMember.getFirstName(); } @Override - public Date getFromDate(final ViewRiksdagenCommitteeRoleMember t) { - return t.getFromDate(); + public Date getFromDate(final ViewRiksdagenCommitteeRoleMember roleMember) { + return roleMember.getFromDate(); } @Override - public Object getLastName(final ViewRiksdagenCommitteeRoleMember t) { - return t.getLastName(); + public Object getLastName(final ViewRiksdagenCommitteeRoleMember roleMember) { + return roleMember.getLastName(); } @Override - public String getOrg(final ViewRiksdagenCommitteeRoleMember t) { - return t.getDetail(); + public String getOrg(final ViewRiksdagenCommitteeRoleMember roleMember) { + return roleMember.getDetail(); } @Override - public String getParty(final ViewRiksdagenCommitteeRoleMember t) { - return t.getParty(); + public String getParty(final ViewRiksdagenCommitteeRoleMember roleMember) { + return roleMember.getParty(); } @Override - public String getRoleCode(final ViewRiksdagenCommitteeRoleMember t) { - return t.getRoleCode(); + public String getRoleCode(final ViewRiksdagenCommitteeRoleMember roleMember) { + return roleMember.getRoleCode(); } @Override - public Date getToDate(final ViewRiksdagenCommitteeRoleMember t) { - return Optional.ofNullable(t.getToDate()).orElseGet(Date::new); + public Date getToDate(final ViewRiksdagenCommitteeRoleMember roleMember) { + return Optional.ofNullable(roleMember.getToDate()).orElseGet(Date::new); } }; @@ -115,9 +130,15 @@ public Date getToDate(final ViewRiksdagenCommitteeRoleMember t) { */ private static final class RoleMapping implements Function { + /** + * Apply. + * + * @param roleMember the role member + * @return the string + */ @Override - public String apply(final ViewRiksdagenCommitteeRoleMember t) { - return t.getRoleCode() +".["+ t.getPersonId() +"]"; + public String apply(final ViewRiksdagenCommitteeRoleMember roleMember) { + return roleMember.getRoleCode() +".["+ roleMember.getPersonId() +"]"; } } diff --git a/citizen-intelligence-agency/src/main/java/com/hack23/cia/web/impl/ui/application/views/common/chartfactory/impl/DateUtils.java b/citizen-intelligence-agency/src/main/java/com/hack23/cia/web/impl/ui/application/views/common/chartfactory/impl/DateUtils.java new file mode 100644 index 0000000000..538a16ab85 --- /dev/null +++ b/citizen-intelligence-agency/src/main/java/com/hack23/cia/web/impl/ui/application/views/common/chartfactory/impl/DateUtils.java @@ -0,0 +1,63 @@ +package com.hack23.cia.web.impl.ui.application.views.common.chartfactory.impl; + +import java.text.ParseException; +import java.text.SimpleDateFormat; +import java.util.Date; +import java.util.Locale; + +import org.joda.time.DateTime; + +/** + * The Class DateUtils. + */ +public final class DateUtils { + + /** The Constant DATE_FORMAT. */ + private static final String DATE_FORMAT = "dd-MMM-yyyy"; + + /** + * Instantiates a new date utils. + */ + private DateUtils() { + // Utility class + } + + /** + * Format date. + * + * @param date the date + * @return the string + */ + public static String formatDate(final Date date) { + final SimpleDateFormat simpleDateFormat = new SimpleDateFormat(DATE_FORMAT, Locale.ENGLISH); + return simpleDateFormat.format(date); + } + + /** + * Parses the date. + * + * @param dateString the date string + * @return the date + * @throws ParseException the parse exception + */ + public static Date parseDate(final String dateString) throws ParseException { + final SimpleDateFormat simpleDateFormat = new SimpleDateFormat(DATE_FORMAT, Locale.ENGLISH); + return simpleDateFormat.parse(dateString); + } + + /** + * Strip dates after current date. + * + * @param toDate the to date + * @return the date + */ + public static Date stripDatesAfterCurrentDate(final Date toDate) { + final DateTime currentTime = new DateTime(); + + if (currentTime.isBefore(toDate.getTime())) { + return currentTime.plusDays(1).toDate(); + } else { + return toDate; + } + } +} diff --git a/citizen-intelligence-agency/src/main/java/com/hack23/cia/web/impl/ui/application/views/common/chartfactory/impl/DecisionChartDataManagerImpl.java b/citizen-intelligence-agency/src/main/java/com/hack23/cia/web/impl/ui/application/views/common/chartfactory/impl/DecisionChartDataManagerImpl.java index 75e41d6306..faeba71f92 100644 --- a/citizen-intelligence-agency/src/main/java/com/hack23/cia/web/impl/ui/application/views/common/chartfactory/impl/DecisionChartDataManagerImpl.java +++ b/citizen-intelligence-agency/src/main/java/com/hack23/cia/web/impl/ui/application/views/common/chartfactory/impl/DecisionChartDataManagerImpl.java @@ -18,7 +18,6 @@ */ package com.hack23.cia.web.impl.ui.application.views.common.chartfactory.impl; -import java.text.SimpleDateFormat; import java.util.Calendar; import java.util.Date; import java.util.GregorianCalendar; @@ -50,9 +49,6 @@ public final class DecisionChartDataManagerImpl extends AbstractChartDataManagerImpl implements DecisionChartDataManager { - /** The Constant DD_MMM_YYYY. */ - private static final String DD_MMM_YYYY = "dd-MMM-yyyy"; - /** The Constant EMPTY_STRING. */ private static final String EMPTY_STRING = ""; @@ -69,50 +65,52 @@ public DecisionChartDataManagerImpl() { /** * Adds the decision type by org data. * - * @param simpleDateFormat the simple date format * @param dataSeries the data series * @param series the series - * @param map the map + * @param decisionTypeMap the decision type map */ - private static void addDecisionTypeByOrgData(final SimpleDateFormat simpleDateFormat, final DataSeries dataSeries, - final Series series, final Map> map) { - for (final Entry> entry : map.entrySet()) { - if (!EMPTY_STRING.equals(entry.getKey())) { + private static void addDecisionTypeByOrgData(final DataSeries dataSeries, + final Series series, final Map> decisionTypeMap) { + for (final Entry> decisionTypeEntry : decisionTypeMap.entrySet()) { + if (!EMPTY_STRING.equals(decisionTypeEntry.getKey())) { final XYseries label = new XYseries(); - label.setLabel(entry.getKey()); + label.setLabel(decisionTypeEntry.getKey()); series.addSeries(label); dataSeries.newSeries(); - for (final ViewRiksdagenCommitteeDecisionTypeOrgDailySummary item : entry.getValue()) { - dataSeries.add(simpleDateFormat.format(item.getEmbeddedId().getDecisionDate()), + for (final ViewRiksdagenCommitteeDecisionTypeOrgDailySummary item : decisionTypeEntry.getValue()) { + dataSeries.add(DateUtils.formatDate(item.getEmbeddedId().getDecisionDate()), item.getTotal()); } } } } + /** + * Creates the decision type chart. + * + * @param content the content + */ @Override public void createDecisionTypeChart(final AbstractOrderedLayout content) { - final Map> map = getCommitteeDecisionTypeMap(); - - final SimpleDateFormat simpleDateFormat = new SimpleDateFormat(DD_MMM_YYYY, Locale.ENGLISH); + final Map> decisionTypeMap = getCommitteeDecisionTypeMap(); final DataSeries dataSeries = new DataSeries(); final Series series = new Series(); - for (final Entry> entry : map.entrySet()) { + for (final Entry> decisionTypeEntry : decisionTypeMap.entrySet()) { - if (entry.getKey() != null) { - series.addSeries(new XYseries().setLabel(entry.getKey())); + if (decisionTypeEntry.getKey() != null) { + series.addSeries(new XYseries().setLabel(decisionTypeEntry.getKey())); dataSeries.newSeries(); - final List list = entry.getValue(); + final List list = decisionTypeEntry.getValue(); for (final ViewRiksdagenCommitteeDecisionTypeDailySummary item : list) { - dataSeries.add(simpleDateFormat.format(item.getEmbeddedId().getDecisionDate()), item.getTotal()); + dataSeries.add(DateUtils.formatDate(item.getEmbeddedId().getDecisionDate()), item.getTotal()); } } @@ -124,11 +122,15 @@ public void createDecisionTypeChart(final AbstractOrderedLayout content) { true); } + /** + * Creates the decision type chart. + * + * @param content the content + * @param org the org + */ @Override public void createDecisionTypeChart(final AbstractOrderedLayout content, final String org) { - final SimpleDateFormat simpleDateFormat = new SimpleDateFormat(DD_MMM_YYYY, Locale.ENGLISH); - final DataSeries dataSeries = new DataSeries(); final Series series = new Series(); @@ -139,11 +141,11 @@ public void createDecisionTypeChart(final AbstractOrderedLayout content, final S if (itemList != null) { - final Map> map = itemList.parallelStream() + final Map> decisionTypeMap = itemList.parallelStream() .filter(t -> t != null && t.getEmbeddedId().getDecisionDate() != null) .collect(Collectors.groupingBy(t -> t.getEmbeddedId().getDecisionType())); - addDecisionTypeByOrgData(simpleDateFormat, dataSeries, series, map); + addDecisionTypeByOrgData(dataSeries, series, decisionTypeMap); } addChart(content, "Org Decision type daily summary", diff --git a/citizen-intelligence-agency/src/main/java/com/hack23/cia/web/impl/ui/application/views/common/chartfactory/impl/DecisionFlowChartManagerImpl.java b/citizen-intelligence-agency/src/main/java/com/hack23/cia/web/impl/ui/application/views/common/chartfactory/impl/DecisionFlowChartManagerImpl.java index bd10393ef6..2fa0a774b8 100644 --- a/citizen-intelligence-agency/src/main/java/com/hack23/cia/web/impl/ui/application/views/common/chartfactory/impl/DecisionFlowChartManagerImpl.java +++ b/citizen-intelligence-agency/src/main/java/com/hack23/cia/web/impl/ui/application/views/common/chartfactory/impl/DecisionFlowChartManagerImpl.java @@ -21,9 +21,10 @@ import java.util.List; import java.util.Locale; import java.util.Map; +import java.util.Map.Entry; +import java.util.Optional; import java.util.stream.Collectors; -import org.apache.commons.lang3.StringUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; @@ -54,375 +55,282 @@ public DecisionFlowChartManagerImpl() { /** * Creates the all decision flow. * - * @param committeeMap the committee map - * @param rm the rm + * @param committeeSummaryMap the committee summary map + * @param reportMonth the report month * @return the sankey chart */ @Override - public SankeyChart createAllDecisionFlow(final Map> committeeMap, - final String rm) { - validateInput(committeeMap, rm); - final List committeeSummaries = decisionDataFactory.createCommitteeSummary(rm); - return createAllDecisionFlowChart(committeeMap, committeeSummaries); + public SankeyChart createAllDecisionFlow(final Map> committeeSummaryMap, + final String reportMonth) { + // Retrieve all proposals for the given 'reportMonth' + final List committeeSummaries = decisionDataFactory.createCommitteeSummary(reportMonth); + + // Prepare the sankey chart + final SankeyChart sankeyChart = new SankeyChart(); + + // Group by organization + final Map> orgProposalMap = + committeeSummaries.stream() + .collect(Collectors.groupingBy(ProposalCommitteeeSummary::getOrg)); + + // For each org, if we have a matching committee in 'committeeSummaryMap', add data rows + for (final Entry> orgEntry : orgProposalMap.entrySet()) { + final String orgKey = orgEntry.getKey(); + final List orgSummaries = orgEntry.getValue(); + if (committeeSummaryMap.containsKey(orgKey)) { + final Optional committeeOpt = + committeeSummaryMap.get(orgKey).stream().findFirst(); + if (committeeOpt.isPresent()) { + final ViewRiksdagenCommittee committee = committeeOpt.get(); + addDocTypeDataRows(sankeyChart, orgSummaries, committee); + addDecisionDataRows(sankeyChart, orgSummaries, committee); + } + } + } + + sankeyChart.drawChart(); + return sankeyChart; } /** * Creates the committee decision flow. * * @param viewRiksdagenCommittee the view riksdagen committee - * @param committeeMap the committee map - * @param rm the rm + * @param committeeSummaryMap the committee summary map + * @param reportMonth the report month * @return the sankey chart */ @Override public SankeyChart createCommitteeDecisionFlow(final ViewRiksdagenCommittee viewRiksdagenCommittee, - final Map> committeeMap, - final String rm) { - validateCommitteeInput(viewRiksdagenCommittee, committeeMap, rm); - final List committeeSummaries = decisionDataFactory.createCommitteeSummary(rm); - return createCommitteeSpecificChart(viewRiksdagenCommittee, committeeSummaries); + final Map> committeeSummaryMap, + final String reportMonth) { + final List committeeSummaries = decisionDataFactory.createCommitteeSummary(reportMonth); + + final SankeyChart sankeyChart = new SankeyChart(); + // Group by organization + final Map> orgProposalMap = + committeeSummaries.stream() + .collect(Collectors.groupingBy(ProposalCommitteeeSummary::getOrg)); + + final String targetOrg = viewRiksdagenCommittee.getEmbeddedId().getOrgCode().toUpperCase(Locale.ENGLISH); + for (final Entry> orgEntry : orgProposalMap.entrySet()) { + final String orgKeyUpper = orgEntry.getKey().toUpperCase(Locale.ENGLISH); + if (committeeSummaryMap.containsKey(orgKeyUpper) && targetOrg.equals(orgKeyUpper)) { + addDocTypeDecisionDataRows(sankeyChart, orgEntry.getValue()); + } + } + + sankeyChart.drawChart(); + return sankeyChart; } /** * Creates the committeee decision summary. * - * @param committeeMap the committee map - * @param rm the rm + * @param committeeSummaryMap the committee summary map + * @param reportMonth the report month * @return the text area */ @Override - public TextArea createCommitteeeDecisionSummary(final Map> committeeMap, - final String rm) { - validateInput(committeeMap, rm); - final List committeeSummaries = decisionDataFactory.createCommitteeSummary(rm); - return createGeneralSummaryTextArea(committeeMap, committeeSummaries); + public TextArea createCommitteeeDecisionSummary(final Map> committeeSummaryMap, + final String reportMonth) { + final TextArea area = new TextArea("Summary"); + final StringBuilder builder = new StringBuilder(); + + final List committeeSummaries = decisionDataFactory.createCommitteeSummary(reportMonth); + + // Group by organization + final Map> orgProposalMap = + committeeSummaries.stream() + .collect(Collectors.groupingBy(ProposalCommitteeeSummary::getOrg)); + + for (final Entry> orgEntry : orgProposalMap.entrySet()) { + final String orgKeyUpper = orgEntry.getKey().toUpperCase(Locale.ENGLISH); + if (committeeSummaryMap.containsKey(orgKeyUpper)) { + // Grab the first committee from the list + final ViewRiksdagenCommittee committee = + committeeSummaryMap.get(orgKeyUpper).stream().findFirst().orElse(null); + addCommiteeSummary(builder, orgEntry.getValue(), committee); + } + } + area.setValue(builder.toString()); + return area; } /** * Creates the committeee decision summary. * * @param viewRiksdagenCommittee the view riksdagen committee - * @param rm the rm + * @param reportMonth the report month * @return the text area */ @Override public TextArea createCommitteeeDecisionSummary(final ViewRiksdagenCommittee viewRiksdagenCommittee, - final String rm) { - validateCommitteeInput(viewRiksdagenCommittee, null, rm); - final List committeeSummaries = decisionDataFactory.createCommitteeSummary(rm); - return createSpecificCommitteeSummary(viewRiksdagenCommittee, committeeSummaries); - } + final String reportMonth) { + final TextArea area = new TextArea("Summary"); + final StringBuilder builder = new StringBuilder(); - /** - * Validate input. - * - * @param committeeMap the committee map - * @param rm the rm - */ - private void validateInput(Map> committeeMap, String rm) { - if (committeeMap == null || committeeMap.isEmpty()) { - throw new IllegalArgumentException("Committee map cannot be null or empty"); - } - validateRm(rm); - } + final List committeeSummaries = decisionDataFactory.createCommitteeSummary(reportMonth); - /** - * Validate committee input. - * - * @param committee the committee - * @param committeeMap the committee map - * @param rm the rm - */ - private void validateCommitteeInput(ViewRiksdagenCommittee committee, - Map> committeeMap, - String rm) { - if (committee == null || committee.getEmbeddedId() == null) { - throw new IllegalArgumentException("Committee cannot be null"); - } - validateRm(rm); - } + // Group by organization + final Map> orgProposalMap = + committeeSummaries.stream() + .collect(Collectors.groupingBy(ProposalCommitteeeSummary::getOrg)); - /** - * Validate rm. - * - * @param rm the rm - */ - private void validateRm(String rm) { - if (StringUtils.isBlank(rm)) { - throw new IllegalArgumentException("RM parameter cannot be blank"); - } - } + final String targetOrg = viewRiksdagenCommittee.getEmbeddedId().getOrgCode().toUpperCase(Locale.ENGLISH); - /** - * Creates the all decision flow chart. - * - * @param committeeMap the committee map - * @param summaries the summaries - * @return the sankey chart - */ - private SankeyChart createAllDecisionFlowChart(Map> committeeMap, - List summaries) { - final SankeyChart chart = initializeChart("Parliamentary Decision Flow"); - - final Map> orgProposalMap = summaries.stream() - .collect(Collectors.groupingBy(ProposalCommitteeeSummary::getOrg)); - - orgProposalMap.forEach((org, orgSummaries) -> { - if (committeeMap.containsKey(org) && !committeeMap.get(org).isEmpty()) { - final ViewRiksdagenCommittee committee = committeeMap.get(org).get(0); - addDocTypeDataRows(chart, orgSummaries, committee); - addDecisionDataRows(chart, orgSummaries, committee); - } - }); - chart.drawChart(); - return chart; - } + // Retrieve the relevant summaries for the single committee + final List list = orgProposalMap.get(targetOrg); + addCommiteeSummary(builder, list, viewRiksdagenCommittee); - /** - * Creates the committee specific chart. - * - * @param committee the committee - * @param summaries the summaries - * @return the sankey chart - */ - private SankeyChart createCommitteeSpecificChart(ViewRiksdagenCommittee committee, - List summaries) { - final SankeyChart chart = initializeChart("Committee Decision Flow: " + committee.getEmbeddedId().getDetail()); - final String targetOrg = committee.getEmbeddedId().getOrgCode().toUpperCase(Locale.ENGLISH); - - final List committeeSummaries = summaries.stream() - .filter(summary -> targetOrg.equals(summary.getOrg().toUpperCase(Locale.ENGLISH))) - .collect(Collectors.toList()); - - addDocTypeDecisionFlowData(chart, committeeSummaries); - chart.drawChart(); - return chart; + area.setValue(builder.toString()); + return area; } /** - * Adds the doc type data rows. + * Helper to add doc type data rows to sankey. * - * @param chart the chart - * @param summaries the summaries + * @param sankeyChart the chart + * @param proposals the summary list for the org * @param committee the committee */ - private void addDocTypeDataRows(SankeyChart chart, - List summaries, - ViewRiksdagenCommittee committee) { - final Map docTypeCounts = summaries.stream() - .collect(Collectors.groupingBy( - ProposalCommitteeeSummary::getDocType, - Collectors.counting() - )); + private static void addDocTypeDataRows(final SankeyChart sankeyChart, + final List proposals, + final ViewRiksdagenCommittee committee) { + // Group by doc type + final Map> docTypeMap = + proposals.stream().collect(Collectors.groupingBy(ProposalCommitteeeSummary::getDocType)); final String committeeName = committee.getEmbeddedId().getDetail(); - docTypeCounts.forEach((docType, count) -> { - if (StringUtils.isNotEmpty(docType)) { - chart.addDataRow(docType, committeeName, count.intValue()); + for (final Entry> docEntry : docTypeMap.entrySet()) { + final String docType = docEntry.getKey(); + if (!docType.isEmpty()) { + sankeyChart.addDataRow(docType, committeeName, docEntry.getValue().size()); } - }); + } } /** - * Adds the decision data rows. + * Helper to add decision data rows to sankey. * - * @param chart the chart - * @param summaries the summaries + * @param sankeyChart the chart + * @param proposals the summary list for the org * @param committee the committee */ - private void addDecisionDataRows(SankeyChart chart, - List summaries, - ViewRiksdagenCommittee committee) { - final Map decisionCounts = summaries.stream() - .collect(Collectors.groupingBy( - ProposalCommitteeeSummary::getDecision, - Collectors.counting() - )); + private static void addDecisionDataRows(final SankeyChart sankeyChart, + final List proposals, + final ViewRiksdagenCommittee committee) { + // Group by decision + final Map> decisionMap = + proposals.stream().collect(Collectors.groupingBy(ProposalCommitteeeSummary::getDecision)); final String committeeName = committee.getEmbeddedId().getDetail(); - decisionCounts.forEach((decision, count) -> { - if (StringUtils.isNotEmpty(decision)) { - chart.addDataRow(committeeName, decision, count.intValue()); + for (final Entry> decisionEntry : decisionMap.entrySet()) { + final String decision = decisionEntry.getKey(); + if (!decision.isEmpty()) { + sankeyChart.addDataRow(committeeName, decision, decisionEntry.getValue().size()); } - }); - } - - /** - * Adds the doc type decision flow data. - * - * @param chart the chart - * @param summaries the summaries - */ - private void addDocTypeDecisionFlowData(SankeyChart chart, - List summaries) { - summaries.stream() - .filter(s -> StringUtils.isNotEmpty(s.getDocType()) && StringUtils.isNotEmpty(s.getDecision())) - .collect(Collectors.groupingBy( - ProposalCommitteeeSummary::getDocType, - Collectors.groupingBy( - ProposalCommitteeeSummary::getDecision, - Collectors.counting() - ) - )) - .forEach((docType, decisionMap) -> - decisionMap.forEach((decision, count) -> - chart.addDataRow(docType, decision, count.intValue()) - ) - ); + } } /** - * Creates the general summary text area. + * Helper to add doc type -> decision data rows to sankey. * - * @param committeeMap the committee map - * @param summaries the summaries - * @return the text area + * @param sankeyChart the chart + * @param proposals the summary list for the org */ - private TextArea createGeneralSummaryTextArea(Map> committeeMap, - List summaries) { - final StringBuilder builder = new StringBuilder(); - - committeeMap.forEach((org, committees) -> { - if (!committees.isEmpty()) { - final List orgSummaries = summaries.stream() - .filter(s -> org.equals(s.getOrg())) - .collect(Collectors.toList()); - - if (!orgSummaries.isEmpty()) { - addCommitteeSummarySection(builder, orgSummaries, committees.get(0)); + private static void addDocTypeDecisionDataRows(final SankeyChart sankeyChart, + final List proposals) { + // Group by doc type + final Map> docTypeMap = + proposals.stream().collect(Collectors.groupingBy(ProposalCommitteeeSummary::getDocType)); + + for (final Entry> docEntry : docTypeMap.entrySet()) { + final String docType = docEntry.getKey(); + if (!docType.isEmpty()) { + // Now group by decision + final Map> decisionMap = + docEntry.getValue().stream() + .collect(Collectors.groupingBy(ProposalCommitteeeSummary::getDecision)); + for (final Entry> decEntry : decisionMap.entrySet()) { + final String decision = decEntry.getKey(); + if (!decision.isEmpty()) { + sankeyChart.addDataRow(docType, decision, decEntry.getValue().size()); + } } } - }); - - return createFormattedTextArea("Summary", builder.toString()); - } - - /** - * Creates the specific committee summary. - * - * @param committee the committee - * @param summaries the summaries - * @return the text area - */ - private TextArea createSpecificCommitteeSummary(ViewRiksdagenCommittee committee, - List summaries) { - final StringBuilder builder = new StringBuilder(); - final String targetOrg = committee.getEmbeddedId().getOrgCode().toUpperCase(Locale.ENGLISH); - - final List committeeSummaries = summaries.stream() - .filter(s -> targetOrg.equals(s.getOrg().toUpperCase(Locale.ENGLISH))) - .collect(Collectors.toList()); - - addCommitteeSummarySection(builder, committeeSummaries, committee); - return createFormattedTextArea("Committee Summary", builder.toString()); + } } /** - * Adds the committee summary section. + * Helper to create a textual committee summary in a StringBuilder. * - * @param builder the builder - * @param summaries the summaries - * @param committee the committee + * @param builder the StringBuilder + * @param proposals the proposal summaries for this committee + * @param committee the committee */ - private void addCommitteeSummarySection(StringBuilder builder, - List summaries, - ViewRiksdagenCommittee committee) { - if (committee == null || summaries.isEmpty()) { + private static void addCommiteeSummary(final StringBuilder builder, + final List proposals, + final ViewRiksdagenCommittee committee) { + // If no committee or proposals, bail out + if (committee == null || proposals == null || proposals.isEmpty()) { return; } - builder.append('\n') - .append(committee.getEmbeddedId().getDetail()); + final String detail = committee.getEmbeddedId().getDetail(); + builder.append('\n').append(detail); - final Map> docTypeMap = summaries.stream() - .collect(Collectors.groupingBy(ProposalCommitteeeSummary::getDocType)); + // Group by doc type + final Map> docTypeMap = + proposals.stream().collect(Collectors.groupingBy(ProposalCommitteeeSummary::getDocType)); - docTypeMap.forEach((docType, docTypeSummaries) -> - addDocTypeSummary(builder, docType, docTypeSummaries)); + for (final Entry> docEntry : docTypeMap.entrySet()) { + addEntry(builder, docEntry); + } } /** - * Adds the doc type summary. + * Build a textual representation of doc type -> decision -> proposals. * * @param builder the builder - * @param docType the doc type - * @param summaries the summaries + * @param docEntry the doc entry */ - private void addDocTypeSummary(StringBuilder builder, - String docType, - List summaries) { - if (StringUtils.isEmpty(docType)) { - return; - } + private static void addEntry(final StringBuilder builder, + final Entry> docEntry) { + final String docType = docEntry.getKey(); + final List docTypeList = docEntry.getValue(); builder.append("\n ( ") - .append(summaries.size()) + .append(docTypeList.size()) .append(' ') .append(docType) .append(" -> "); - final Map> decisionMap = summaries.stream() - .collect(Collectors.groupingBy(ProposalCommitteeeSummary::getDecision)); - - decisionMap.forEach((decision, decisionSummaries) -> - addDecisionSummary(builder, decision, decisionSummaries)); - - builder.append(')'); - } - - /** - * Adds the decision summary. - * - * @param builder the builder - * @param decision the decision - * @param summaries the summaries - */ - private void addDecisionSummary(StringBuilder builder, - String decision, - List summaries) { - if (StringUtils.isEmpty(decision)) { - return; + // Group by decision + final Map> decisionMap = + docTypeList.stream() + .collect(Collectors.groupingBy(ProposalCommitteeeSummary::getDecision)); + + for (final Entry> decisionEntry : decisionMap.entrySet()) { + final String decision = decisionEntry.getKey(); + if (!decision.isEmpty()) { + builder.append("\n ") + .append(decisionEntry.getValue().size()) + .append(' ') + .append(decision) + .append(' '); + + for (final ProposalCommitteeeSummary summary : decisionEntry.getValue()) { + builder.append("\n ") + .append(summary.getDecision()) + .append(':') + .append(summary.getWording()) + .append(' ') + .append(summary.getWording2()) + .append(' '); + } + } } - - builder.append("\n ") - .append(summaries.size()) - .append(' ') - .append(decision); - - summaries.forEach(summary -> - builder.append("\n ") - .append(decision) - .append(':') - .append(summary.getWording()) - .append(' ') - .append(summary.getWording2())); - } - - /** - * Initialize chart. - * - * @param title the title - * @return the sankey chart - */ - private SankeyChart initializeChart(String title) { - final SankeyChart chart = new SankeyChart(); - chart.setCaption(title); - chart.setWidth("100%"); - return chart; - } - - /** - * Creates the formatted text area. - * - * @param caption the caption - * @param content the content - * @return the text area - */ - private TextArea createFormattedTextArea(String caption, String content) { - final TextArea area = new TextArea(caption); - area.setValue(content); - area.setWidth("100%"); - area.setReadOnly(true); - return area; + builder.append(')'); } -} \ No newline at end of file +} diff --git a/citizen-intelligence-agency/src/main/java/com/hack23/cia/web/impl/ui/application/views/common/chartfactory/impl/DocumentChartDataManagerImpl.java b/citizen-intelligence-agency/src/main/java/com/hack23/cia/web/impl/ui/application/views/common/chartfactory/impl/DocumentChartDataManagerImpl.java index a7172cc508..79a44f7396 100644 --- a/citizen-intelligence-agency/src/main/java/com/hack23/cia/web/impl/ui/application/views/common/chartfactory/impl/DocumentChartDataManagerImpl.java +++ b/citizen-intelligence-agency/src/main/java/com/hack23/cia/web/impl/ui/application/views/common/chartfactory/impl/DocumentChartDataManagerImpl.java @@ -18,7 +18,6 @@ */ package com.hack23.cia.web.impl.ui.application.views.common.chartfactory.impl; -import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.List; import java.util.Locale; @@ -48,11 +47,10 @@ public final class DocumentChartDataManagerImpl extends AbstractChartDataManagerImpl implements DocumentChartDataManager { - private static final String DD_MMM_YYYY = "dd-MMM-yyyy"; - /** The Constant EMPTY_STRING. */ private static final String EMPTY_STRING = ""; + /** The Constant LOGGER. */ private static final Logger LOGGER = LoggerFactory.getLogger(DocumentChartDataManagerImpl.class); /** The Constant MOT_PROP_BET. */ @@ -71,24 +69,22 @@ public DocumentChartDataManagerImpl() { /** * Adds the data series. * - * @param simpleDateFormat the simple date format - * @param parseInputDateFormat the parse input date format * @param dataSeries the data series * @param series the series * @param entry the entry */ - private static void addDataSeries(final SimpleDateFormat simpleDateFormat, - final SimpleDateFormat parseInputDateFormat, final DataSeries dataSeries, final Series series, + private static void addDataSeries(final DataSeries dataSeries, final Series series, final Entry> entry) { series.addSeries(new XYseries().setLabel(entry.getKey())); dataSeries.newSeries(); + final SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd",Locale.ENGLISH); for (final ViewRiksdagenDocumentTypeDailySummary item : entry.getValue()) { if (item != null && item.getEmbeddedId().getPublicDate().length() > 0) { try { - dataSeries.add(simpleDateFormat.format(parseInputDateFormat.parse(item.getEmbeddedId().getPublicDate())), item.getTotal()); - } catch (final ParseException e) { + dataSeries.add(DateUtils.formatDate(simpleDateFormat.parse(item.getEmbeddedId().getPublicDate())), item.getTotal()); + } catch (final Exception e) { LOGGER.warn("Problem parsing date:{}", item.getEmbeddedId().getPublicDate()); } @@ -96,22 +92,25 @@ private static void addDataSeries(final SimpleDateFormat simpleDateFormat, } } + /** + * Creates the document type chart. + * + * @param layout the layout + */ @Override - public void createDocumentTypeChart(final AbstractOrderedLayout content) { - final Map> map = getDocumentTypeMap(); - final SimpleDateFormat simpleDateFormat = new SimpleDateFormat(DD_MMM_YYYY, Locale.ENGLISH); - final SimpleDateFormat parseInputDateFormat = new SimpleDateFormat("yyyy-MM-dd",Locale.ENGLISH); + public void createDocumentTypeChart(final AbstractOrderedLayout layout) { + final Map> documentTypeMap = getDocumentTypeMap(); final DataSeries dataSeries = new DataSeries(); final Series series = new Series(); - for (final Entry> entry : map.entrySet()) { - if (entry.getKey() != null && !EMPTY_STRING.equals(entry.getKey())) { - addDataSeries(simpleDateFormat, parseInputDateFormat, dataSeries, series, entry); + for (final Entry> documentTypeEntry : documentTypeMap.entrySet()) { + if (documentTypeEntry.getKey() != null && !EMPTY_STRING.equals(documentTypeEntry.getKey())) { + addDataSeries(dataSeries, series, documentTypeEntry); } } - addChart(content, "Document type", + addChart(layout, "Document type", new DCharts().setDataSeries(dataSeries) .setOptions(getChartOptions().createOptionsXYDateFloatLegendInsideOneColumn(series)).show(), true); diff --git a/citizen-intelligence-agency/src/main/java/com/hack23/cia/web/impl/ui/application/views/common/chartfactory/impl/GovernmentBodyChartDataManagerImpl.java b/citizen-intelligence-agency/src/main/java/com/hack23/cia/web/impl/ui/application/views/common/chartfactory/impl/GovernmentBodyChartDataManagerImpl.java index 645b9f2e95..602c27b2f1 100644 --- a/citizen-intelligence-agency/src/main/java/com/hack23/cia/web/impl/ui/application/views/common/chartfactory/impl/GovernmentBodyChartDataManagerImpl.java +++ b/citizen-intelligence-agency/src/main/java/com/hack23/cia/web/impl/ui/application/views/common/chartfactory/impl/GovernmentBodyChartDataManagerImpl.java @@ -160,29 +160,29 @@ private static void addEntryData(final DataSeries dataSeries, final SimpleDateFo /** * Adds the annual data. * - * @param content - * the content - * @param name - * the name + * @param layout + * the layout + * @param governmentBodyName + * the government body name * @param label * the label - * @param collect - * the collect + * @param annualOutcomeSummaries + * the annual outcome summaries */ - private void addAnnualData(final VerticalLayout content, final String name, final String label, - final Map> collect) { + private void addAnnualData(final VerticalLayout layout, final String governmentBodyName, final String label, + final Map> annualOutcomeSummaries) { final DataSeries dataSeries = new DataSeries(); final Series series = new Series(); final SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd",Locale.ENGLISH); - for (final Entry> entry : collect.entrySet()) { + for (final Entry> entry : annualOutcomeSummaries.entrySet()) { series.addSeries(new XYseries().setLabel(entry.getKey())); dataSeries.newSeries(); addEntryData(dataSeries, simpleDateFormat, entry); - } + } - addChart(content, name + " " + label, + ChartUtils.addChart(layout, governmentBodyName + " " + label, new DCharts().setDataSeries(dataSeries) .setOptions(getChartOptions().createOptionsXYDateFloatLogYAxisLegendOutside(series)).show(), true); @@ -193,12 +193,12 @@ private void addAnnualData(final VerticalLayout content, final String name, fina * * @param report * the report - * @param content - * the content + * @param layout + * the layout * @param label * the label */ - private void addAnnualSummary(final Map> report, final VerticalLayout content, + private void addAnnualSummary(final Map> report, final VerticalLayout layout, final String label) { final DataSeries dataSeries = new DataSeries(); @@ -213,28 +213,44 @@ private void addAnnualSummary(final Map> collect = esvApi.getGovernmentBodyReport().get(name) + public void createGovernmentBodyExpenditureSummaryChart(final VerticalLayout layout, final String governmentBodyName) { + final Map> annualOutcomeSummaries = esvApi.getGovernmentBodyReport().get(governmentBodyName) .stream().filter(p -> p.getDescriptionFields().get(ANSLAGSPOSTSNAMN) != null) .collect(Collectors.groupingBy(t -> t.getDescriptionFields().get(ANSLAGSPOSTSNAMN))); - addAnnualData(content, name, ANNUAL_EXPENDITURE, collect); + addAnnualData(layout, governmentBodyName, ANNUAL_EXPENDITURE, annualOutcomeSummaries); } + /** + * Creates the government body headcount summary chart. + * + * @param layout the layout + */ @Override - public void createGovernmentBodyHeadcountSummaryChart(final VerticalLayout content) { + public void createGovernmentBodyHeadcountSummaryChart(final VerticalLayout layout) { final Map> map = esvApi.getData(); final DataSeries dataSeries = new DataSeries(); @@ -247,7 +263,7 @@ public void createGovernmentBodyHeadcountSummaryChart(final VerticalLayout conte addDataSerieValue(dataSeries, entry, entry.getValue().stream().mapToInt(GovernmentBodyAnnualSummary::getHeadCount).sum()); } - addChart(content, ANNUAL_HEADCOUNT_TOTAL_ALL_GOVERNMENT_BODIES, + ChartUtils.addChart(layout, ANNUAL_HEADCOUNT_TOTAL_ALL_GOVERNMENT_BODIES, new DCharts().setDataSeries(dataSeries) .setOptions(getChartOptions().createOptionsXYDateFloatLogYAxisLegendOutside(series)).show(), true); @@ -255,53 +271,86 @@ public void createGovernmentBodyHeadcountSummaryChart(final VerticalLayout conte } + /** + * Creates the government body headcount summary chart. + * + * @param layout the layout + * @param governmentBodyName the government body name + */ @Override - public void createGovernmentBodyHeadcountSummaryChart(final VerticalLayout content, final String name) { - final Map map = esvApi.getDataPerGovernmentBody(name); + public void createGovernmentBodyHeadcountSummaryChart(final VerticalLayout layout, final String governmentBodyName) { + final Map map = esvApi.getDataPerGovernmentBody(governmentBodyName); final DataSeries dataSeries = new DataSeries(); final Series series = new Series(); - series.addSeries(new XYseries().setLabel(name)); + series.addSeries(new XYseries().setLabel(governmentBodyName)); dataSeries.newSeries(); for (final Entry entry : map.entrySet()) { addDataSerieValue(dataSeries, entry, entry.getValue().getHeadCount()); } - addChart(content, name + " "+ ANNUAL_HEADCOUNT, + ChartUtils.addChart(layout, governmentBodyName + " "+ ANNUAL_HEADCOUNT, new DCharts().setDataSeries(dataSeries) .setOptions(getChartOptions().createOptionsXYDateFloatLogYAxisLegendOutside(series)).show(), true); } + /** + * Creates the government body income summary chart. + * + * @param layout the layout + */ @Override - public void createGovernmentBodyIncomeSummaryChart(final VerticalLayout content) { - addAnnualSummary(esvApi.getGovernmentBodyReportByField(INKOMSTTITELGRUPPSNAMN), content, ANNUAL_INCOME); + public void createGovernmentBodyIncomeSummaryChart(final VerticalLayout layout) { + addAnnualSummary(esvApi.getGovernmentBodyReportByField(INKOMSTTITELGRUPPSNAMN), layout, ANNUAL_INCOME); } + /** + * Creates the government body income summary chart. + * + * @param layout the layout + * @param governmentBodyName the government body name + */ @Override - public void createGovernmentBodyIncomeSummaryChart(final VerticalLayout content, final String name) { - final Map> collect = esvApi.getGovernmentBodyReport().get(name) + public void createGovernmentBodyIncomeSummaryChart(final VerticalLayout layout, final String governmentBodyName) { + final Map> annualOutcomeSummaries = esvApi.getGovernmentBodyReport().get(governmentBodyName) .stream().filter(p -> p.getDescriptionFields().get(INKOMSTTITELSNAMN) != null) .collect(Collectors.groupingBy(t -> t.getDescriptionFields().get(INKOMSTTITELSNAMN))); - addAnnualData(content, name, ANNUAL_INCOME, collect); + addAnnualData(layout, governmentBodyName, ANNUAL_INCOME, annualOutcomeSummaries); } + /** + * Creates the ministry government body expenditure summary chart. + * + * @param layout the layout + */ @Override - public void createMinistryGovernmentBodyExpenditureSummaryChart(final AbstractOrderedLayout content) { - createMinistrySummary(content,EXPENDITURE_GROUP_NAME,"MinistryGovernmentBodySpendingSummaryChart"); + public void createMinistryGovernmentBodyExpenditureSummaryChart(final AbstractOrderedLayout layout) { + createMinistrySummary(layout,EXPENDITURE_GROUP_NAME,"MinistryGovernmentBodySpendingSummaryChart"); } + /** + * Creates the ministry government body expenditure summary chart. + * + * @param layout the layout + * @param governmentBodyName the government body name + */ @Override - public void createMinistryGovernmentBodyExpenditureSummaryChart(final VerticalLayout content, final String name) { - addAnnualSummary(esvApi.getGovernmentBodyReportByFieldAndMinistry(EXPENDITURE_GROUP_NAME, name), content, ANNUAL_EXPENDITURE); + public void createMinistryGovernmentBodyExpenditureSummaryChart(final VerticalLayout layout, final String governmentBodyName) { + addAnnualSummary(esvApi.getGovernmentBodyReportByFieldAndMinistry(EXPENDITURE_GROUP_NAME, governmentBodyName), layout, ANNUAL_EXPENDITURE); } + /** + * Creates the ministry government body headcount summary chart. + * + * @param layout the layout + */ @Override - public void createMinistryGovernmentBodyHeadcountSummaryChart(final AbstractOrderedLayout content) { + public void createMinistryGovernmentBodyHeadcountSummaryChart(final AbstractOrderedLayout layout) { final Map> map = esvApi.getData(); final List ministryNames = esvApi.getMinistryNames(); @@ -320,7 +369,7 @@ public void createMinistryGovernmentBodyHeadcountSummaryChart(final AbstractOrde } } - addChart(content, ANNUAL_HEADCOUNT_ALL_MINISTRIES, + ChartUtils.addChart(layout, ANNUAL_HEADCOUNT_ALL_MINISTRIES, new DCharts().setDataSeries(dataSeries) .setOptions(getChartOptions().createOptionsXYDateFloatLogYAxisLegendOutside(series)).show(), true); @@ -328,11 +377,17 @@ public void createMinistryGovernmentBodyHeadcountSummaryChart(final AbstractOrde } + /** + * Creates the ministry government body headcount summary chart. + * + * @param layout the layout + * @param governmentBodyName the government body name + */ @Override - public void createMinistryGovernmentBodyHeadcountSummaryChart(final AbstractOrderedLayout content, - final String name) { - final Map> map = esvApi.getDataPerMinistry(name); - final List governmentBodyNames = esvApi.getGovernmentBodyNames(name); + public void createMinistryGovernmentBodyHeadcountSummaryChart(final AbstractOrderedLayout layout, + final String governmentBodyName) { + final Map> map = esvApi.getDataPerMinistry(governmentBodyName); + final List governmentBodyNames = esvApi.getGovernmentBodyNames(governmentBodyName); final DataSeries dataSeries = new DataSeries(); final Series series = new Series(); @@ -349,34 +404,45 @@ public void createMinistryGovernmentBodyHeadcountSummaryChart(final AbstractOrde } } - addChart(content, name + " "+ ANNUAL_HEADCOUNT_SUMMARY_ALL_GOVERNMENT_BODIES, + ChartUtils.addChart(layout, governmentBodyName + " "+ ANNUAL_HEADCOUNT_SUMMARY_ALL_GOVERNMENT_BODIES, new DCharts().setDataSeries(dataSeries) .setOptions(getChartOptions().createOptionsXYDateFloatLogYAxisLegendOutside(series)).show(), true); } + /** + * Creates the ministry government body income summary chart. + * + * @param layout the layout + */ @Override - public void createMinistryGovernmentBodyIncomeSummaryChart(final AbstractOrderedLayout content) { - createMinistrySummary(content,INKOMSTTITELGRUPPSNAMN,"MinistryGovernmentBodyIncomeSummaryChart"); + public void createMinistryGovernmentBodyIncomeSummaryChart(final AbstractOrderedLayout layout) { + createMinistrySummary(layout,INKOMSTTITELGRUPPSNAMN,"MinistryGovernmentBodyIncomeSummaryChart"); } + /** + * Creates the ministry government body income summary chart. + * + * @param layout the layout + * @param governmentBodyName the government body name + */ @Override - public void createMinistryGovernmentBodyIncomeSummaryChart(final VerticalLayout content, final String name) { - addAnnualSummary(esvApi.getGovernmentBodyReportByFieldAndMinistry(INKOMSTTITELGRUPPSNAMN,name), content, ANNUAL_INCOME); + public void createMinistryGovernmentBodyIncomeSummaryChart(final VerticalLayout layout, final String governmentBodyName) { + addAnnualSummary(esvApi.getGovernmentBodyReportByFieldAndMinistry(INKOMSTTITELGRUPPSNAMN,governmentBodyName), layout, ANNUAL_INCOME); } /** * Creates the ministry summary. * - * @param content the content + * @param layout the layout * @param field the field * @param label the label */ - private void createMinistrySummary(final AbstractOrderedLayout content, final String field, final String label) { + private void createMinistrySummary(final AbstractOrderedLayout layout, final String field, final String label) { final DataSeries dataSeries = new DataSeries(); final Series series = new Series(); @@ -394,10 +460,10 @@ private void createMinistrySummary(final AbstractOrderedLayout content, final St } } - addChart(content, label, + ChartUtils.addChart(layout, label, new DCharts().setDataSeries(dataSeries) .setOptions(getChartOptions().createOptionsXYDateFloatLogYAxisLegendOutside(series)).show(), true); } -} \ No newline at end of file +} diff --git a/citizen-intelligence-agency/src/main/java/com/hack23/cia/web/impl/ui/application/views/common/chartfactory/impl/GovernmentOutcomeChartDataManagerImpl.java b/citizen-intelligence-agency/src/main/java/com/hack23/cia/web/impl/ui/application/views/common/chartfactory/impl/GovernmentOutcomeChartDataManagerImpl.java index 093f16fc63..dfc56be663 100644 --- a/citizen-intelligence-agency/src/main/java/com/hack23/cia/web/impl/ui/application/views/common/chartfactory/impl/GovernmentOutcomeChartDataManagerImpl.java +++ b/citizen-intelligence-agency/src/main/java/com/hack23/cia/web/impl/ui/application/views/common/chartfactory/impl/GovernmentOutcomeChartDataManagerImpl.java @@ -52,31 +52,44 @@ public GovernmentOutcomeChartDataManagerImpl() { super(); } - private static void createPeriodData(final Map> map, final GovernmentOperationPeriodOutcome.Variables variables,final DataSeries dataSeries, - final Series series) { - series.addSeries(new XYseries().setLabel(variables.toString())); - dataSeries.newSeries(); + /** + * Creates the period data. + * + * @param outcomeMap the outcome map + * @param variables the variables + * @param chartDataSeries the chart data series + * @param chartSeries the chart series + */ + private static void createPeriodData(final Map> outcomeMap, final GovernmentOperationPeriodOutcome.Variables variables,final DataSeries chartDataSeries, + final Series chartSeries) { + chartSeries.addSeries(new XYseries().setLabel(variables.toString())); + chartDataSeries.newSeries(); - final List list = map.get(variables.toString()); + final List list = outcomeMap.get(variables.toString()); Collections.sort(list); for (final GovernmentOperationPeriodOutcome entry : list) { - dataSeries.add(entry.getPeriod() + "-01", entry.getValue()); + chartDataSeries.add(entry.getPeriod() + "-01", entry.getValue()); } } + /** + * Creates the government outcome chart. + * + * @param layout the layout + */ @Override - public void createGovernmentOutcomeChart(final AbstractOrderedLayout content) { - final Map> map = esvApi.getReport(); - final DataSeries dataSeries = new DataSeries(); - final Series series = new Series(); + public void createGovernmentOutcomeChart(final AbstractOrderedLayout layout) { + final Map> outcomeMap = esvApi.getReport(); + final DataSeries chartDataSeries = new DataSeries(); + final Series chartSeries = new Series(); - createPeriodData(map,GovernmentOperationPeriodOutcome.Variables.TOTAL_REVENUE, dataSeries, series); - createPeriodData(map,GovernmentOperationPeriodOutcome.Variables.TOTAL_EXPENDITURES, dataSeries, series); + createPeriodData(outcomeMap,GovernmentOperationPeriodOutcome.Variables.TOTAL_REVENUE, chartDataSeries, chartSeries); + createPeriodData(outcomeMap,GovernmentOperationPeriodOutcome.Variables.TOTAL_EXPENDITURES, chartDataSeries, chartSeries); - addChart(content, "GovernmentOperationPeriodOutcome", - new DCharts().setDataSeries(dataSeries) - .setOptions(getChartOptions().createOptionsXYDateFloatLogYAxisLegendOutside(series)).show(), + addChart(layout, "GovernmentOperationPeriodOutcome", + new DCharts().setDataSeries(chartDataSeries) + .setOptions(getChartOptions().createOptionsXYDateFloatLogYAxisLegendOutside(chartSeries)).show(), true); } diff --git a/citizen-intelligence-agency/src/main/java/com/hack23/cia/web/impl/ui/application/views/common/chartfactory/impl/MinistryGhantChartManagerImpl.java b/citizen-intelligence-agency/src/main/java/com/hack23/cia/web/impl/ui/application/views/common/chartfactory/impl/MinistryGhantChartManagerImpl.java index 4dae0e4a64..0286be8cd1 100644 --- a/citizen-intelligence-agency/src/main/java/com/hack23/cia/web/impl/ui/application/views/common/chartfactory/impl/MinistryGhantChartManagerImpl.java +++ b/citizen-intelligence-agency/src/main/java/com/hack23/cia/web/impl/ui/application/views/common/chartfactory/impl/MinistryGhantChartManagerImpl.java @@ -43,27 +43,42 @@ public MinistryGhantChartManagerImpl() { super(); } + /** + * Gets the comparator. + * + * @return the comparator + */ @Override protected Comparator getComparator() { return (o1, o2) -> o1.getFromDate().compareTo(o2.getFromDate()); } + /** + * Gets the role mapping. + * + * @return the role mapping + */ @Override protected Function getRoleMapping() { return new RoleMapping(); } + /** + * Gets the step mapping. + * + * @return the step mapping + */ @Override protected StepMapping getStepMapping() { return new StepMapping<>() { @Override - public String getBackgroundColor(final ViewRiksdagenGovermentRoleMember t) { + public String getBackgroundColor(final ViewRiksdagenGovermentRoleMember roleMember) { String color; - if (t.getRoleCode().toLowerCase(Locale.ENGLISH).contains("statsråd")) { + if (roleMember.getRoleCode().toLowerCase(Locale.ENGLISH).contains("statsråd")) { color = "ded858"; - } else if (t.getRoleCode().toLowerCase(Locale.ENGLISH).contains("statsminister")) { + } else if (roleMember.getRoleCode().toLowerCase(Locale.ENGLISH).contains("statsminister")) { color = "3271c8"; } else { color = "0eab76"; @@ -73,38 +88,38 @@ public String getBackgroundColor(final ViewRiksdagenGovermentRoleMember t) { } @Override - public Object getFirstName(final ViewRiksdagenGovermentRoleMember t) { - return t.getFirstName(); + public Object getFirstName(final ViewRiksdagenGovermentRoleMember roleMember) { + return roleMember.getFirstName(); } @Override - public Date getFromDate(final ViewRiksdagenGovermentRoleMember t) { - return t.getFromDate(); + public Date getFromDate(final ViewRiksdagenGovermentRoleMember roleMember) { + return roleMember.getFromDate(); } @Override - public Object getLastName(final ViewRiksdagenGovermentRoleMember t) { - return t.getLastName(); + public Object getLastName(final ViewRiksdagenGovermentRoleMember roleMember) { + return roleMember.getLastName(); } @Override - public String getOrg(final ViewRiksdagenGovermentRoleMember t) { - return t.getDetail(); + public String getOrg(final ViewRiksdagenGovermentRoleMember roleMember) { + return roleMember.getDetail(); } @Override - public String getParty(final ViewRiksdagenGovermentRoleMember t) { - return t.getParty(); + public String getParty(final ViewRiksdagenGovermentRoleMember roleMember) { + return roleMember.getParty(); } @Override - public String getRoleCode(final ViewRiksdagenGovermentRoleMember t) { - return t.getRoleCode(); + public String getRoleCode(final ViewRiksdagenGovermentRoleMember roleMember) { + return roleMember.getRoleCode(); } @Override - public Date getToDate(final ViewRiksdagenGovermentRoleMember t) { - return Optional.ofNullable(t.getToDate()).orElseGet(Date::new); + public Date getToDate(final ViewRiksdagenGovermentRoleMember roleMember) { + return Optional.ofNullable(roleMember.getToDate()).orElseGet(Date::new); } }; @@ -115,9 +130,15 @@ public Date getToDate(final ViewRiksdagenGovermentRoleMember t) { */ private static final class RoleMapping implements Function { + /** + * Apply. + * + * @param roleMember the role member + * @return the string + */ @Override - public String apply(final ViewRiksdagenGovermentRoleMember t) { - return t.getRoleCode()+ ".["+ t.getPersonId() +"]." + t.getDetail(); + public String apply(final ViewRiksdagenGovermentRoleMember roleMember) { + return roleMember.getRoleCode()+ ".["+ roleMember.getPersonId() +"]." + roleMember.getDetail(); } } diff --git a/citizen-intelligence-agency/src/main/java/com/hack23/cia/web/impl/ui/application/views/common/chartfactory/impl/OrgDocumentChartDataManagerImpl.java b/citizen-intelligence-agency/src/main/java/com/hack23/cia/web/impl/ui/application/views/common/chartfactory/impl/OrgDocumentChartDataManagerImpl.java index 499d5bf4ba..5d9346a612 100644 --- a/citizen-intelligence-agency/src/main/java/com/hack23/cia/web/impl/ui/application/views/common/chartfactory/impl/OrgDocumentChartDataManagerImpl.java +++ b/citizen-intelligence-agency/src/main/java/com/hack23/cia/web/impl/ui/application/views/common/chartfactory/impl/OrgDocumentChartDataManagerImpl.java @@ -50,8 +50,10 @@ public final class OrgDocumentChartDataManagerImpl extends AbstractChartDataManagerImpl implements OrgDocumentChartDataManager { + /** The Constant DD_MMM_YYYY. */ private static final String DD_MMM_YYYY = "dd-MMM-yyyy"; + /** The Constant DOCUMENT_HISTORY_BY_ORG. */ private static final String DOCUMENT_HISTORY_BY_ORG = "Document History by Org"; /** The Constant EMPTY_STRING. */ @@ -148,6 +150,12 @@ private static void addNewDataSerie(final DataSeries dataSeries, final Series se } } + /** + * Creates the document history chart by org. + * + * @param content the content + * @param org the org + */ @Override public void createDocumentHistoryChartByOrg(final AbstractOrderedLayout content, final String org) { final String searchOrg = org.toUpperCase(Locale.ENGLISH).replace(UNDER_SCORE, EMPTY_STRING) diff --git a/citizen-intelligence-agency/src/main/java/com/hack23/cia/web/impl/ui/application/views/common/chartfactory/impl/PartyChartDataManagerImpl.java b/citizen-intelligence-agency/src/main/java/com/hack23/cia/web/impl/ui/application/views/common/chartfactory/impl/PartyChartDataManagerImpl.java index fb3f9f8581..97fd866e55 100644 --- a/citizen-intelligence-agency/src/main/java/com/hack23/cia/web/impl/ui/application/views/common/chartfactory/impl/PartyChartDataManagerImpl.java +++ b/citizen-intelligence-agency/src/main/java/com/hack23/cia/web/impl/ui/application/views/common/chartfactory/impl/PartyChartDataManagerImpl.java @@ -18,11 +18,10 @@ */ package com.hack23.cia.web.impl.ui.application.views.common.chartfactory.impl; -import java.text.SimpleDateFormat; +import java.time.ZoneId; +import java.time.ZonedDateTime; import java.util.ArrayList; -import java.util.Calendar; import java.util.List; -import java.util.Locale; import java.util.Map; import java.util.Map.Entry; import java.util.Objects; @@ -30,7 +29,6 @@ import java.util.function.Function; import java.util.stream.Collectors; -import org.apache.commons.lang3.time.DateUtils; import org.dussan.vaadin.dcharts.DCharts; import org.dussan.vaadin.dcharts.base.elements.XYseries; import org.dussan.vaadin.dcharts.data.DataSeries; @@ -50,9 +48,6 @@ public final class PartyChartDataManagerImpl extends AbstractChartDataManagerImpl implements PartyChartDataManager { - /** The Constant DD_MMM_YYYY. */ - private static final String DD_MMM_YYYY = "dd-MMM-yyyy"; - /** The Constant NUMBER_BALLOTS. */ private static final String NUMBER_BALLOTS = "Number ballots"; @@ -77,19 +72,17 @@ public PartyChartDataManagerImpl() { * Adds the party data. * * @param dataSeries the data series - * @param simpleDateFormat the simple date format * @param list the list - * @param t the t + * @param dataValueFunction the data value function */ - private static void addPartyData(final DataSeries dataSeries, final SimpleDateFormat simpleDateFormat, - final List list, final Function t) { + private static void addPartyData(final DataSeries dataSeries, + final List list, final Function dataValueFunction) { dataSeries.newSeries(); for (final ViewRiksdagenVoteDataBallotPartySummaryDaily viewRiksdagenVoteDataBallotPartySummaryDaily : list) { if (viewRiksdagenVoteDataBallotPartySummaryDaily != null) { dataSeries.add( - simpleDateFormat - .format(viewRiksdagenVoteDataBallotPartySummaryDaily.getEmbeddedId().getVoteDate()), - t.apply(viewRiksdagenVoteDataBallotPartySummaryDaily)); + DateUtils.formatDate(viewRiksdagenVoteDataBallotPartySummaryDaily.getEmbeddedId().getVoteDate()), + dataValueFunction.apply(viewRiksdagenVoteDataBallotPartySummaryDaily)); } } } @@ -100,12 +93,11 @@ private static void addPartyData(final DataSeries dataSeries, final SimpleDateFo * * @param dataValueCalculator the data value calculator * @param dataSeries the data series - * @param simpleDateFormat the simple date format * @param series the series * @param entry the entry */ private void addBallotData(final DataValueCalculator dataValueCalculator, final DataSeries dataSeries, - final SimpleDateFormat simpleDateFormat, final Series series, + final Series series, final Entry> entry) { series.addSeries(new XYseries().setLabel(getPartyName(entry.getKey()))); @@ -114,8 +106,7 @@ private void addBallotData(final DataValueCalculator dataValueCalculator, final for (final ViewRiksdagenVoteDataBallotPartySummaryDaily viewRiksdagenVoteDataBallotPartySummaryDaily : list) { if (viewRiksdagenVoteDataBallotPartySummaryDaily != null) { dataSeries.add( - simpleDateFormat - .format(viewRiksdagenVoteDataBallotPartySummaryDaily.getEmbeddedId().getVoteDate()), + DateUtils.formatDate(viewRiksdagenVoteDataBallotPartySummaryDaily.getEmbeddedId().getVoteDate()), dataValueCalculator.getDataValue(viewRiksdagenVoteDataBallotPartySummaryDaily)); } } @@ -125,16 +116,21 @@ private void addBallotData(final DataValueCalculator dataValueCalculator, final + /** + * Creates the party age chart. + * + * @param content the content + */ @Override public void createPartyAgeChart(final AbstractOrderedLayout content) { - createPartyBallotChart(content,viewRiksdagenVoteDataBallotPartySummaryDaily -> DateUtils.toCalendar(viewRiksdagenVoteDataBallotPartySummaryDaily.getEmbeddedId().getVoteDate()).get(Calendar.YEAR) - viewRiksdagenVoteDataBallotPartySummaryDaily.getPartyAvgBornYear().intValue()); + createPartyBallotChart(content,viewRiksdagenVoteDataBallotPartySummaryDaily -> ZonedDateTime.now(ZoneId.of("Europe/Stockholm")).getYear() - viewRiksdagenVoteDataBallotPartySummaryDaily.getPartyAvgBornYear().intValue()); } /** * Creates the party ballot chart. * - * @param dataValueCalculator - * the data value calculator + * @param content the content + * @param dataValueCalculator the data value calculator * @return the d charts */ private void createPartyBallotChart(final AbstractOrderedLayout content,final DataValueCalculator dataValueCalculator) { @@ -142,21 +138,24 @@ private void createPartyBallotChart(final AbstractOrderedLayout content,final Da final DataSeries dataSeries = new DataSeries(); - final SimpleDateFormat simpleDateFormat = new SimpleDateFormat(DD_MMM_YYYY, Locale.ENGLISH); - final Series series = new Series(); for (final Entry> entry : map.entrySet()) { if (!"-".equals(entry.getKey())) { - addBallotData(dataValueCalculator, dataSeries, simpleDateFormat, series, entry); + addBallotData(dataValueCalculator, dataSeries, series, entry); } } - addChart(content,"Party ballot chart", new DCharts().setDataSeries(dataSeries).setOptions(getChartOptions().createOptionsXYDateFloatLegendInsideOneColumn(series)).show(), true); + ChartUtils.addChart(content,"Party ballot chart", new DCharts().setDataSeries(dataSeries).setOptions(getChartOptions().createOptionsXYDateFloatLegendInsideOneColumn(series)).show(), true); } + /** + * Creates the party gender chart. + * + * @param content the content + */ @Override public void createPartyGenderChart(final AbstractOrderedLayout content) { @@ -164,6 +163,12 @@ public void createPartyGenderChart(final AbstractOrderedLayout content) { } + /** + * Creates the party line chart. + * + * @param content the content + * @param partyId the party id + */ @Override public void createPartyLineChart(final AbstractOrderedLayout content,final String partyId) { @@ -176,16 +181,19 @@ public void createPartyLineChart(final AbstractOrderedLayout content,final Strin final DataSeries dataSeries = new DataSeries(); - final SimpleDateFormat simpleDateFormat = new SimpleDateFormat(DD_MMM_YYYY, Locale.ENGLISH); - - addPartyData(dataSeries, simpleDateFormat, list, ViewRiksdagenVoteDataBallotPartySummaryDaily::getPartyWonPercentage); - addPartyData(dataSeries, simpleDateFormat, list, ViewRiksdagenVoteDataBallotPartySummaryDaily::getPartyPercentageAbsent); + addPartyData(dataSeries, list, ViewRiksdagenVoteDataBallotPartySummaryDaily::getPartyWonPercentage); + addPartyData(dataSeries, list, ViewRiksdagenVoteDataBallotPartySummaryDaily::getPartyPercentageAbsent); - addChart(content,"Party result by", new DCharts().setDataSeries(dataSeries).setOptions(getChartOptions().createOptionsPartyLineChart(series)).show(), true); + ChartUtils.addChart(content,"Party result by", new DCharts().setDataSeries(dataSeries).setOptions(getChartOptions().createOptionsPartyLineChart(series)).show(), true); } } + /** + * Creates the party winner chart. + * + * @param content the content + */ @Override public void createPartyWinnerChart(final AbstractOrderedLayout content) { @@ -193,19 +201,17 @@ public void createPartyWinnerChart(final AbstractOrderedLayout content) { final DataSeries dataSeries = new DataSeries(); - final SimpleDateFormat simpleDateFormat = new SimpleDateFormat(DD_MMM_YYYY, Locale.ENGLISH); - final Series series = new Series(); for (final Entry> entry : map.entrySet()) { series.addSeries(new XYseries().setLabel(getPartyName(entry.getKey()))); - addPartyData(dataSeries, simpleDateFormat, entry.getValue(), ViewRiksdagenVoteDataBallotPartySummaryDaily::getPartyWonPercentage); + addPartyData(dataSeries, entry.getValue(), ViewRiksdagenVoteDataBallotPartySummaryDaily::getPartyWonPercentage); } series.addSeries(new XYseries().setLabel(NUMBER_BALLOTS)); - addPartyData(dataSeries, simpleDateFormat, getMaxSizeViewRiksdagenVoteDataBallotPartySummaryDaily(), ViewRiksdagenVoteDataBallotPartySummaryDaily::getNumberBallots); + addPartyData(dataSeries, getMaxSizeViewRiksdagenVoteDataBallotPartySummaryDaily(), ViewRiksdagenVoteDataBallotPartySummaryDaily::getNumberBallots); - addChart(content,"Party winner by daily ballot average", new DCharts().setDataSeries(dataSeries).setOptions(getChartOptions().createOptionsXYDateFloatLegendInsideOneColumn(series)).show(), true); + ChartUtils.addChart(content,"Party winner by daily ballot average", new DCharts().setDataSeries(dataSeries).setOptions(getChartOptions().createOptionsXYDateFloatLegendInsideOneColumn(series)).show(), true); } diff --git a/citizen-intelligence-agency/src/main/java/com/hack23/cia/web/impl/ui/application/views/common/chartfactory/impl/PartyCoalationChartDataManagerImpl.java b/citizen-intelligence-agency/src/main/java/com/hack23/cia/web/impl/ui/application/views/common/chartfactory/impl/PartyCoalationChartDataManagerImpl.java index f15bc40463..c7088d6463 100644 --- a/citizen-intelligence-agency/src/main/java/com/hack23/cia/web/impl/ui/application/views/common/chartfactory/impl/PartyCoalationChartDataManagerImpl.java +++ b/citizen-intelligence-agency/src/main/java/com/hack23/cia/web/impl/ui/application/views/common/chartfactory/impl/PartyCoalationChartDataManagerImpl.java @@ -76,23 +76,29 @@ private static void addData(final Map dataContainer = getApplicationManager() .getDataContainer(ViewRiksdagenPartyCoalationAgainstAnnualSummary.class); - final Map> map = dataContainer.getAll().parallelStream() - .filter(t -> t.getEmbeddedId().getGroupAgainst().contains(partyId) && t.getTotal() > FILTER_LOW_VALUES) - .collect(Collectors.groupingBy(t -> t.getEmbeddedId().getGroupAgainst())); + final Map> partySummaryMap = dataContainer.getAll().parallelStream() + .filter(summary -> summary.getEmbeddedId().getGroupAgainst().contains(partyId) && summary.getTotal() > FILTER_LOW_VALUES) + .collect(Collectors.groupingBy(summary -> summary.getEmbeddedId().getGroupAgainst())); - final Series series = new Series(); - final DataSeries dataSeries = new DataSeries(); + final Series chartSeries = new Series(); + final DataSeries chartDataSeries = new DataSeries(); - addData(map, series, dataSeries); + addData(partySummaryMap, chartSeries, chartDataSeries); - addChart(content, "Part of coalations against committee proposal in ballot more than twice", new DCharts() - .setDataSeries(dataSeries).setOptions(getChartOptions().createOptionsCountryLineChart(series)).show(), + ChartUtils.addChart(layout, "Part of coalations against committee proposal in ballot more than twice", new DCharts() + .setDataSeries(chartDataSeries).setOptions(getChartOptions().createOptionsCountryLineChart(chartSeries)).show(), true); } diff --git a/citizen-intelligence-agency/src/main/java/com/hack23/cia/web/impl/ui/application/views/common/chartfactory/impl/PartyDocumentChartDataManagerImpl.java b/citizen-intelligence-agency/src/main/java/com/hack23/cia/web/impl/ui/application/views/common/chartfactory/impl/PartyDocumentChartDataManagerImpl.java index 31cbb2e014..debceb7fe5 100644 --- a/citizen-intelligence-agency/src/main/java/com/hack23/cia/web/impl/ui/application/views/common/chartfactory/impl/PartyDocumentChartDataManagerImpl.java +++ b/citizen-intelligence-agency/src/main/java/com/hack23/cia/web/impl/ui/application/views/common/chartfactory/impl/PartyDocumentChartDataManagerImpl.java @@ -18,7 +18,6 @@ */ package com.hack23.cia.web.impl.ui.application.views.common.chartfactory.impl; -import java.text.SimpleDateFormat; import java.util.List; import java.util.Locale; import java.util.Map; @@ -48,9 +47,7 @@ public final class PartyDocumentChartDataManagerImpl extends AbstractChartDataManagerImpl implements PartyDocumentChartDataManager { - /** The Constant DD_MMM_YYYY. */ - private static final String DD_MMM_YYYY = "dd-MMM-yyyy"; - + /** The Constant DOCUMENT_HISTORY_PARTY. */ private static final String DOCUMENT_HISTORY_PARTY = "Document history party"; /** The Constant EMPTY_STRING. */ @@ -84,44 +81,49 @@ public PartyDocumentChartDataManagerImpl() { */ private static void addDocumentHistoryByPartyData(final DataSeries dataSeries, final Series series, final Map> map) { - final SimpleDateFormat simpleDateFormat = new SimpleDateFormat(DD_MMM_YYYY, Locale.ENGLISH); - for (final Entry> entry : map.entrySet()) { + for (final Entry> documentTypeEntry : map.entrySet()) { - series.addSeries(new XYseries().setLabel(entry.getKey())); + series.addSeries(new XYseries().setLabel(documentTypeEntry.getKey())); dataSeries.newSeries(); - if (entry.getValue() != null) { - for (final ViewRiksdagenPartyDocumentDailySummary item : entry.getValue()) { - dataSeries.add(simpleDateFormat.format(item.getEmbeddedId().getPublicDate()), item.getTotal()); + if (documentTypeEntry.getValue() != null) { + for (final ViewRiksdagenPartyDocumentDailySummary item : documentTypeEntry.getValue()) { + dataSeries.add(DateUtils.formatDate(item.getEmbeddedId().getPublicDate()), item.getTotal()); } } else { - LOGGER.info(LOG_MSG_MISSING_DATA_FOR_KEY, entry); + LOGGER.info(LOG_MSG_MISSING_DATA_FOR_KEY, documentTypeEntry); } } } + /** + * Creates the document history party chart. + * + * @param layout the layout + * @param partyShortCode the party short code + */ @Override - public void createDocumentHistoryPartyChart(final AbstractOrderedLayout content, final String org) { + public void createDocumentHistoryPartyChart(final AbstractOrderedLayout layout, final String partyShortCode) { final DataSeries dataSeries = new DataSeries(); final Series series = new Series(); final Map> allMap = getViewRiksdagenPartyDocumentDailySummaryMap(); final List itemList = allMap - .get(org.toUpperCase(Locale.ENGLISH).replace(UNDER_SCORE, EMPTY_STRING).trim()); + .get(partyShortCode.toUpperCase(Locale.ENGLISH).replace(UNDER_SCORE, EMPTY_STRING).trim()); if (itemList != null) { - final Map> map = itemList.parallelStream() + final Map> documentTypeMap = itemList.parallelStream() .filter(Objects::nonNull).collect(Collectors .groupingBy(t -> StringUtils.defaultIfBlank(t.getEmbeddedId().getDocumentType(), NO_INFO))); - addDocumentHistoryByPartyData(dataSeries, series, map); + addDocumentHistoryByPartyData(dataSeries, series, documentTypeMap); } - addChart(content, DOCUMENT_HISTORY_PARTY, + addChart(layout, DOCUMENT_HISTORY_PARTY, new DCharts().setDataSeries(dataSeries) .setOptions(getChartOptions().createOptionsXYDateFloatLegendInsideOneColumn(series)).show(), true); diff --git a/citizen-intelligence-agency/src/main/java/com/hack23/cia/web/impl/ui/application/views/common/chartfactory/impl/PartyGhantChartManagerImpl.java b/citizen-intelligence-agency/src/main/java/com/hack23/cia/web/impl/ui/application/views/common/chartfactory/impl/PartyGhantChartManagerImpl.java index d53dcce76d..853079600d 100644 --- a/citizen-intelligence-agency/src/main/java/com/hack23/cia/web/impl/ui/application/views/common/chartfactory/impl/PartyGhantChartManagerImpl.java +++ b/citizen-intelligence-agency/src/main/java/com/hack23/cia/web/impl/ui/application/views/common/chartfactory/impl/PartyGhantChartManagerImpl.java @@ -43,29 +43,44 @@ public PartyGhantChartManagerImpl() { super(); } + /** + * Gets the comparator. + * + * @return the comparator + */ @Override protected Comparator getComparator() { return (o1, o2) -> o1.getFromDate().compareTo(o2.getFromDate()); } + /** + * Gets the role mapping. + * + * @return the role mapping + */ @Override protected Function getRoleMapping() { return new RoleMapping(); } + /** + * Gets the step mapping. + * + * @return the step mapping + */ @Override protected StepMapping getStepMapping() { return new StepMapping<>() { @Override - public String getBackgroundColor(final ViewRiksdagenPartyRoleMember t) { + public String getBackgroundColor(final ViewRiksdagenPartyRoleMember roleMember) { String color; - if (t.getRoleCode().toLowerCase(Locale.ENGLISH).contains("vice")) { + if (roleMember.getRoleCode().toLowerCase(Locale.ENGLISH).contains("vice")) { color = "A8D999"; - } else if (t.getRoleCode().toLowerCase(Locale.ENGLISH).contains("partiledare") - || t.getRoleCode().toLowerCase(Locale.ENGLISH).contains("språkrör") - || t.getRoleCode().toLowerCase(Locale.ENGLISH).contains("partisekreterare")) { + } else if (roleMember.getRoleCode().toLowerCase(Locale.ENGLISH).contains("partiledare") + || roleMember.getRoleCode().toLowerCase(Locale.ENGLISH).contains("språkrör") + || roleMember.getRoleCode().toLowerCase(Locale.ENGLISH).contains("partisekreterare")) { color = "3271c8"; } else { color = "0eab76"; @@ -75,38 +90,38 @@ public String getBackgroundColor(final ViewRiksdagenPartyRoleMember t) { } @Override - public Object getFirstName(final ViewRiksdagenPartyRoleMember t) { - return t.getFirstName(); + public Object getFirstName(final ViewRiksdagenPartyRoleMember roleMember) { + return roleMember.getFirstName(); } @Override - public Date getFromDate(final ViewRiksdagenPartyRoleMember t) { - return t.getFromDate(); + public Date getFromDate(final ViewRiksdagenPartyRoleMember roleMember) { + return roleMember.getFromDate(); } @Override - public Object getLastName(final ViewRiksdagenPartyRoleMember t) { - return t.getLastName(); + public Object getLastName(final ViewRiksdagenPartyRoleMember roleMember) { + return roleMember.getLastName(); } @Override - public String getOrg(final ViewRiksdagenPartyRoleMember t) { - return t.getDetail(); + public String getOrg(final ViewRiksdagenPartyRoleMember roleMember) { + return roleMember.getDetail(); } @Override - public String getParty(final ViewRiksdagenPartyRoleMember t) { - return t.getParty(); + public String getParty(final ViewRiksdagenPartyRoleMember roleMember) { + return roleMember.getParty(); } @Override - public String getRoleCode(final ViewRiksdagenPartyRoleMember t) { - return t.getRoleCode(); + public String getRoleCode(final ViewRiksdagenPartyRoleMember roleMember) { + return roleMember.getRoleCode(); } @Override - public Date getToDate(final ViewRiksdagenPartyRoleMember t) { - return Optional.ofNullable(t.getToDate()).orElseGet(Date::new); + public Date getToDate(final ViewRiksdagenPartyRoleMember roleMember) { + return Optional.ofNullable(roleMember.getToDate()).orElseGet(Date::new); } }; @@ -117,9 +132,15 @@ public Date getToDate(final ViewRiksdagenPartyRoleMember t) { */ private static final class RoleMapping implements Function { + /** + * Apply. + * + * @param roleMember the role member + * @return the string + */ @Override - public String apply(final ViewRiksdagenPartyRoleMember t) { - return t.getRoleCode(); + public String apply(final ViewRiksdagenPartyRoleMember roleMember) { + return roleMember.getRoleCode(); } } diff --git a/citizen-intelligence-agency/src/main/java/com/hack23/cia/web/impl/ui/application/views/common/chartfactory/impl/PartySupportsChartDataManagerImpl.java b/citizen-intelligence-agency/src/main/java/com/hack23/cia/web/impl/ui/application/views/common/chartfactory/impl/PartySupportsChartDataManagerImpl.java index 77ce3f05ac..cbd1a2b28e 100644 --- a/citizen-intelligence-agency/src/main/java/com/hack23/cia/web/impl/ui/application/views/common/chartfactory/impl/PartySupportsChartDataManagerImpl.java +++ b/citizen-intelligence-agency/src/main/java/com/hack23/cia/web/impl/ui/application/views/common/chartfactory/impl/PartySupportsChartDataManagerImpl.java @@ -76,26 +76,32 @@ private static void addData(final Map dataContainer = getApplicationManager() .getDataContainer(ViewRiksdagenPartyBallotSupportAnnualSummary.class); - final List list = dataContainer.findListByEmbeddedProperty(ViewRiksdagenPartyBallotSupportAnnualSummary.class, + final List partySummaries = dataContainer.findListByEmbeddedProperty(ViewRiksdagenPartyBallotSupportAnnualSummary.class, ViewRiksdagenPartyBallotSupportAnnualSummary_.embeddedId, ViewRiksdagenPartyBallotSupportAnnualSummaryEmbeddedId.class, ViewRiksdagenPartyBallotSupportAnnualSummaryEmbeddedId_.party, partyId); - final Map> map = list.parallelStream().filter(Objects::nonNull) - .collect(Collectors.groupingBy(t -> t.getEmbeddedId().getOtherParty())); + final Map> partySummaryMap = partySummaries.parallelStream().filter(Objects::nonNull) + .collect(Collectors.groupingBy(summary -> summary.getEmbeddedId().getOtherParty())); final Series series = new Series(); final DataSeries dataSeries = new DataSeries(); - addData(map, series, dataSeries); + addData(partySummaryMap, series, dataSeries); - addChart(content,"Party support ballot", new DCharts().setDataSeries(dataSeries).setOptions(getChartOptions().createOptionsPartyLineChart(series)).show(), true); + ChartUtils.addChart(layout,"Party support ballot", new DCharts().setDataSeries(dataSeries).setOptions(getChartOptions().createOptionsPartyLineChart(series)).show(), true); } } diff --git a/citizen-intelligence-agency/src/main/java/com/hack23/cia/web/impl/ui/application/views/common/chartfactory/impl/PersonDocumentChartDataManagerImpl.java b/citizen-intelligence-agency/src/main/java/com/hack23/cia/web/impl/ui/application/views/common/chartfactory/impl/PersonDocumentChartDataManagerImpl.java index 0d735b22be..337122007b 100644 --- a/citizen-intelligence-agency/src/main/java/com/hack23/cia/web/impl/ui/application/views/common/chartfactory/impl/PersonDocumentChartDataManagerImpl.java +++ b/citizen-intelligence-agency/src/main/java/com/hack23/cia/web/impl/ui/application/views/common/chartfactory/impl/PersonDocumentChartDataManagerImpl.java @@ -18,7 +18,6 @@ */ package com.hack23.cia.web.impl.ui.application.views.common.chartfactory.impl; -import java.text.SimpleDateFormat; import java.util.List; import java.util.Locale; import java.util.Map; @@ -48,9 +47,7 @@ public final class PersonDocumentChartDataManagerImpl extends AbstractChartDataManagerImpl implements PersonDocumentChartDataManager { - /** The Constant DD_MMM_YYYY. */ - private static final String DD_MMM_YYYY = "dd-MMM-yyyy"; - + /** The Constant DOCUMENT_HISTORY. */ private static final String DOCUMENT_HISTORY = "Document history"; /** The Constant EMPTY_STRING. */ @@ -78,54 +75,56 @@ public PersonDocumentChartDataManagerImpl() { /** * Adds the document history by person data. * - * @param simpleDateFormat the simple date format * @param dataSeries the data series * @param series the series - * @param map the map + * @param documentSummaryMap the document summary map */ - private static void addDocumentHistoryByPersonData(final SimpleDateFormat simpleDateFormat, - final DataSeries dataSeries, final Series series, - final Map> map) { - for (final Entry> entry : map.entrySet()) { + private static void addDocumentHistoryByPersonData(final DataSeries dataSeries, final Series series, + final Map> documentSummaryMap) { + for (final Entry> documentSummaryEntry : documentSummaryMap.entrySet()) { - series.addSeries(new XYseries().setLabel(entry.getKey())); + series.addSeries(new XYseries().setLabel(documentSummaryEntry.getKey())); dataSeries.newSeries(); - if (entry.getValue() != null) { - for (final ViewRiksdagenPoliticianDocumentDailySummary item : entry.getValue()) { - dataSeries.add(simpleDateFormat.format(item.getEmbeddedId().getPublicDate()), item.getTotal()); + if (documentSummaryEntry.getValue() != null) { + for (final ViewRiksdagenPoliticianDocumentDailySummary documentSummary : documentSummaryEntry.getValue()) { + dataSeries.add(DateUtils.formatDate(documentSummary.getEmbeddedId().getPublicDate()), documentSummary.getTotal()); } } else { - LOGGER.info(LOG_MSG_MISSING_DATA_FOR_KEY, entry); + LOGGER.info(LOG_MSG_MISSING_DATA_FOR_KEY, documentSummaryEntry); } } } + /** + * Creates the person document history chart. + * + * @param layout the layout + * @param personId the person id + */ @Override - public void createPersonDocumentHistoryChart(final AbstractOrderedLayout content, final String personId) { - - final SimpleDateFormat simpleDateFormat = new SimpleDateFormat(DD_MMM_YYYY, Locale.ENGLISH); + public void createPersonDocumentHistoryChart(final AbstractOrderedLayout layout, final String personId) { final DataSeries dataSeries = new DataSeries(); final Series series = new Series(); - final Map> allMap = getViewRiksdagenPoliticianDocumentDailySummaryMap(); + final Map> allDocumentSummaryMap = getViewRiksdagenPoliticianDocumentDailySummaryMap(); - final List itemList = allMap + final List documentSummaryList = allDocumentSummaryMap .get(personId.toUpperCase(Locale.ENGLISH).replace(UNDER_SCORE, EMPTY_STRING).trim()); - if (itemList != null) { + if (documentSummaryList != null) { - final Map> map = itemList.parallelStream() + final Map> documentSummaryMap = documentSummaryList.parallelStream() .filter(Objects::nonNull).collect(Collectors - .groupingBy(t -> StringUtils.defaultIfBlank(t.getEmbeddedId().getDocumentType(), NO_INFO))); + .groupingBy(documentSummary -> StringUtils.defaultIfBlank(documentSummary.getEmbeddedId().getDocumentType(), NO_INFO))); - addDocumentHistoryByPersonData(simpleDateFormat, dataSeries, series, map); + addDocumentHistoryByPersonData(dataSeries, series, documentSummaryMap); } - addChart(content, DOCUMENT_HISTORY, + ChartUtils.addChart(layout, DOCUMENT_HISTORY, new DCharts().setDataSeries(dataSeries) .setOptions(getChartOptions().createOptionsXYDateFloatLegendInsideOneColumn(series)).show(), true); @@ -141,7 +140,7 @@ private Map> getViewRi .getDataContainer(ViewRiksdagenPoliticianDocumentDailySummary.class); return politicianBallotSummaryDailyDataContainer.getAll().parallelStream().filter(Objects::nonNull) - .collect(Collectors.groupingBy(t -> t.getEmbeddedId().getPersonId())); + .collect(Collectors.groupingBy(documentSummary -> documentSummary.getEmbeddedId().getPersonId())); } } diff --git a/citizen-intelligence-agency/src/main/java/com/hack23/cia/web/impl/ui/application/views/common/chartfactory/impl/PoliticianDataManagerImpl.java b/citizen-intelligence-agency/src/main/java/com/hack23/cia/web/impl/ui/application/views/common/chartfactory/impl/PoliticianDataManagerImpl.java index 44aa9ab29c..3257b3f465 100644 --- a/citizen-intelligence-agency/src/main/java/com/hack23/cia/web/impl/ui/application/views/common/chartfactory/impl/PoliticianDataManagerImpl.java +++ b/citizen-intelligence-agency/src/main/java/com/hack23/cia/web/impl/ui/application/views/common/chartfactory/impl/PoliticianDataManagerImpl.java @@ -18,9 +18,7 @@ */ package com.hack23.cia.web.impl.ui.application.views.common.chartfactory.impl; -import java.text.SimpleDateFormat; import java.util.List; -import java.util.Locale; import java.util.function.Function; import org.dussan.vaadin.dcharts.DCharts; @@ -44,9 +42,6 @@ public final class PoliticianDataManagerImpl extends AbstractChartDataManagerImp /** The Constant ABSENT. */ private static final String ABSENT = "Absent"; - /** The Constant DD_MMM_YYYY. */ - private static final String DD_MMM_YYYY = "dd-MMM-yyyy"; - /** The Constant NUMBER_BALLOTS. */ private static final String NUMBER_BALLOTS = "Number ballots"; @@ -74,19 +69,18 @@ public PoliticianDataManagerImpl() { * * @param list the list * @param dataSeries the data series - * @param simpleDateFormat the simple date format * @param t the t */ private static void addPoliticanData(final List list, - final DataSeries dataSeries, final SimpleDateFormat simpleDateFormat, final Function t) { + final DataSeries dataSeries, final Function t) { dataSeries.newSeries(); for (final ViewRiksdagenVoteDataBallotPoliticianSummaryDaily viewRiksdagenVoteDataBallotPoliticianSummaryDaily : list) { if (viewRiksdagenVoteDataBallotPoliticianSummaryDaily != null) { dataSeries.add( - simpleDateFormat.format( + DateUtils.formatDate( viewRiksdagenVoteDataBallotPoliticianSummaryDaily.getEmbeddedId().getVoteDate()), t.apply(viewRiksdagenVoteDataBallotPoliticianSummaryDaily)); - } + } } } @@ -99,22 +93,26 @@ private static void addPoliticanData(final List list, - final DataSeries dataSeries, final SimpleDateFormat simpleDateFormat) { - addPoliticanData(list, dataSeries, simpleDateFormat, ViewRiksdagenVoteDataBallotPoliticianSummaryDaily::getWonPercentage); - addPoliticanData(list, dataSeries, simpleDateFormat, ViewRiksdagenVoteDataBallotPoliticianSummaryDaily::getRebelPercentage); - addPoliticanData(list, dataSeries, simpleDateFormat, ViewRiksdagenVoteDataBallotPoliticianSummaryDaily::getPoliticianPercentageAbsent); - addPoliticanData(list, dataSeries, simpleDateFormat, ViewRiksdagenVoteDataBallotPoliticianSummaryDaily::getNumberBallots); + final DataSeries dataSeries) { + addPoliticanData(list, dataSeries, ViewRiksdagenVoteDataBallotPoliticianSummaryDaily::getWonPercentage); + addPoliticanData(list, dataSeries, ViewRiksdagenVoteDataBallotPoliticianSummaryDaily::getRebelPercentage); + addPoliticanData(list, dataSeries, ViewRiksdagenVoteDataBallotPoliticianSummaryDaily::getPoliticianPercentageAbsent); + addPoliticanData(list, dataSeries, ViewRiksdagenVoteDataBallotPoliticianSummaryDaily::getNumberBallots); } + /** + * Creates the person line chart. + * + * @param layout the layout + * @param personId the person id + */ @Override - public void createPersonLineChart(final AbstractOrderedLayout content,final String personId) { + public void createPersonLineChart(final AbstractOrderedLayout layout,final String personId) { final List list = dataChartManager.findByValue(personId); @@ -124,13 +122,11 @@ public void createPersonLineChart(final AbstractOrderedLayout content,final Stri final DataSeries dataSeries = new DataSeries(); - final SimpleDateFormat simpleDateFormat = new SimpleDateFormat(DD_MMM_YYYY, Locale.ENGLISH); - if (list != null) { - addPoliticianIndicatorData(list, dataSeries, simpleDateFormat); + addPoliticianIndicatorData(list, dataSeries); } - addChart(content,"Ballot indicators", new DCharts().setDataSeries(dataSeries).setOptions(getChartOptions().createOptionsPersonLineChart(series)).show(), true); + ChartUtils.addChart(layout,"Ballot indicators", new DCharts().setDataSeries(dataSeries).setOptions(getChartOptions().createOptionsPersonLineChart(series)).show(), true); } diff --git a/citizen-intelligence-agency/src/main/java/com/hack23/cia/web/impl/ui/application/views/common/chartfactory/impl/PoliticianGhantChartManagerImpl.java b/citizen-intelligence-agency/src/main/java/com/hack23/cia/web/impl/ui/application/views/common/chartfactory/impl/PoliticianGhantChartManagerImpl.java index 687c0e2384..5c6762a1e2 100644 --- a/citizen-intelligence-agency/src/main/java/com/hack23/cia/web/impl/ui/application/views/common/chartfactory/impl/PoliticianGhantChartManagerImpl.java +++ b/citizen-intelligence-agency/src/main/java/com/hack23/cia/web/impl/ui/application/views/common/chartfactory/impl/PoliticianGhantChartManagerImpl.java @@ -51,16 +51,31 @@ public PoliticianGhantChartManagerImpl() { super(); } + /** + * Gets the comparator. + * + * @return the comparator + */ @Override protected Comparator getComparator() { return (o1, o2) -> o1.getFromDate().compareTo(o2.getFromDate()); } + /** + * Gets the role mapping. + * + * @return the role mapping + */ @Override protected Function getRoleMapping() { return new RoleMapping(); } + /** + * Gets the step mapping. + * + * @return the step mapping + */ @Override protected StepMapping getStepMapping() { return new StepMapping<>() { @@ -131,6 +146,12 @@ private static final class RoleMapping implements Function findByValue(final String party) { final DataContainer partyBallotSummaryDailyDataContainer = applicationManager diff --git a/citizen-intelligence-agency/src/main/java/com/hack23/cia/web/impl/ui/application/views/common/chartfactory/impl/ViewRiksdagenVoteDataBallotPoliticianSummaryChartDataManagerImpl.java b/citizen-intelligence-agency/src/main/java/com/hack23/cia/web/impl/ui/application/views/common/chartfactory/impl/ViewRiksdagenVoteDataBallotPoliticianSummaryChartDataManagerImpl.java index c52257bb50..6433ef9cfa 100644 --- a/citizen-intelligence-agency/src/main/java/com/hack23/cia/web/impl/ui/application/views/common/chartfactory/impl/ViewRiksdagenVoteDataBallotPoliticianSummaryChartDataManagerImpl.java +++ b/citizen-intelligence-agency/src/main/java/com/hack23/cia/web/impl/ui/application/views/common/chartfactory/impl/ViewRiksdagenVoteDataBallotPoliticianSummaryChartDataManagerImpl.java @@ -50,6 +50,12 @@ public ViewRiksdagenVoteDataBallotPoliticianSummaryChartDataManagerImpl() { super(); } + /** + * Find by value. + * + * @param id the id + * @return the list + */ @Override public List findByValue(final String id) { final DataContainer politicianBallotSummaryDailyDataContainer = applicationManager diff --git a/citizen-intelligence-agency/src/main/java/com/hack23/cia/web/impl/ui/application/views/common/chartfactory/impl/ViewRiksdagenVoteDataBallotPoliticianSummaryDailyChartDataManagerImpl.java b/citizen-intelligence-agency/src/main/java/com/hack23/cia/web/impl/ui/application/views/common/chartfactory/impl/ViewRiksdagenVoteDataBallotPoliticianSummaryDailyChartDataManagerImpl.java index 5ad4eb17b6..49af0edb7d 100644 --- a/citizen-intelligence-agency/src/main/java/com/hack23/cia/web/impl/ui/application/views/common/chartfactory/impl/ViewRiksdagenVoteDataBallotPoliticianSummaryDailyChartDataManagerImpl.java +++ b/citizen-intelligence-agency/src/main/java/com/hack23/cia/web/impl/ui/application/views/common/chartfactory/impl/ViewRiksdagenVoteDataBallotPoliticianSummaryDailyChartDataManagerImpl.java @@ -50,6 +50,12 @@ public ViewRiksdagenVoteDataBallotPoliticianSummaryDailyChartDataManagerImpl() { super(); } + /** + * Find by value. + * + * @param value the value + * @return the list + */ @Override public List findByValue(final String value) { final DataContainer politicianBallotSummaryDailyDataContainer = applicationManager diff --git a/citizen-intelligence-agency/src/main/java/com/hack23/cia/web/impl/ui/application/views/common/chartfactory/impl/WorldIndicatorChartDataManagerImpl.java b/citizen-intelligence-agency/src/main/java/com/hack23/cia/web/impl/ui/application/views/common/chartfactory/impl/WorldIndicatorChartDataManagerImpl.java index f5c47cf979..afb8de7fc7 100644 --- a/citizen-intelligence-agency/src/main/java/com/hack23/cia/web/impl/ui/application/views/common/chartfactory/impl/WorldIndicatorChartDataManagerImpl.java +++ b/citizen-intelligence-agency/src/main/java/com/hack23/cia/web/impl/ui/application/views/common/chartfactory/impl/WorldIndicatorChartDataManagerImpl.java @@ -49,6 +49,13 @@ public WorldIndicatorChartDataManagerImpl() { } + /** + * Creates the indicator chart. + * + * @param content the content + * @param list the list + * @param summary the summary + */ @Override public void createIndicatorChart(final AbstractOrderedLayout content,final List list, final ViewWorldbankIndicatorDataCountrySummary summary) {