/*
 * Copyright 2010 James Pether Sörling
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *   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,
 * 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.
 *
 *	$Id$
 *  $HeadURL$
*/
// This file was generated by the JavaTM Architecture for XML Binding(JAXB) Reference Implementation, v2.2.11
// See http://java.sun.com/xml/jaxb
// Any modifications to this file will be lost upon recompilation of the source schema.
// Generated on: 2019.02.24 at 11:39:54 PM CET
//

package com.hack23.cia.model.external.val.kommunvalkrets.impl;

import javax.xml.bind.JAXBElement;
import javax.xml.bind.annotation.XmlElementDecl;
import javax.xml.bind.annotation.XmlRegistry;
import javax.xml.namespace.QName;

/**
 * A factory for creating Object objects.
 */
@XmlRegistry
public class ObjectFactory {

    /** The Constant _Root_QNAME. */
    private static final QName _Root_QNAME = new QName("http://kommunvalkrets.val.external.model.cia.hack23.com/impl", "root");

    /**
	 * Instantiates a new object factory.
	 */
    public ObjectFactory() {
    }

    /**
	 * Creates a new Object object.
	 *
	 * @return the sweden county data container
	 */
    public SwedenCountyDataContainer createSwedenCountyDataContainer() {
        return new SwedenCountyDataContainer();
    }

    /**
	 * Creates a new Object object.
	 *
	 * @return the sweden county data
	 */
    public SwedenCountyData createSwedenCountyData() {
        return new SwedenCountyData();
    }

    /**
	 * Creates a new Object object.
	 *
	 * @return the sweden municipality data
	 */
    public SwedenMunicipalityData createSwedenMunicipalityData() {
        return new SwedenMunicipalityData();
    }

    /**
	 * Creates a new Object object.
	 *
	 * @return the sweden municipality election region data
	 */
    public SwedenMunicipalityElectionRegionData createSwedenMunicipalityElectionRegionData() {
        return new SwedenMunicipalityElectionRegionData();
    }

    /**
	 * Creates a new Object object.
	 *
	 * @param value the value
	 * @return the JAXB element< sweden county data container>
	 */
    @XmlElementDecl(namespace = "http://kommunvalkrets.val.external.model.cia.hack23.com/impl", name = "root")
    public JAXBElement<SwedenCountyDataContainer> createRoot(final SwedenCountyDataContainer value) {
        return new JAXBElement<>(_Root_QNAME, SwedenCountyDataContainer.class, null, value);
    }

}


/*
 * Copyright 2010 James Pether Sörling
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *   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,
 * 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.
 *
 *	$Id$
 *  $HeadURL$
*/
// This file was generated by the JavaTM Architecture for XML Binding(JAXB) Reference Implementation, v2.2.11
// See http://java.sun.com/xml/jaxb
// Any modifications to this file will be lost upon recompilation of the source schema.
// Generated on: 2019.02.24 at 11:39:47 PM CET
//

package com.hack23.cia.model.external.val.partier.impl;

import javax.xml.bind.JAXBElement;
import javax.xml.bind.annotation.XmlElementDecl;
import javax.xml.bind.annotation.XmlRegistry;
import javax.xml.namespace.QName;

/**
 * A factory for creating Object objects.
 */
@XmlRegistry
public class ObjectFactory {

    /** The Constant _Root_QNAME. */
    private static final QName _Root_QNAME = new QName("http://partier.val.external.model.cia.hack23.com/impl", "root");

    /**
	 * Instantiates a new object factory.
	 */
    public ObjectFactory() {
    }

    /**
	 * Creates a new Object object.
	 *
	 * @return the sweden election type container element
	 */
    public SwedenElectionTypeContainerElement createSwedenElectionTypeContainerElement() {
        return new SwedenElectionTypeContainerElement();
    }

    /**
	 * Creates a new Object object.
	 *
	 * @return the sweden election type
	 */
    public SwedenElectionType createSwedenElectionType() {
        return new SwedenElectionType();
    }

    /**
	 * Creates a new Object object.
	 *
	 * @return the sweden election region
	 */
    public SwedenElectionRegion createSwedenElectionRegion() {
        return new SwedenElectionRegion();
    }

    /**
	 * Creates a new Object object.
	 *
	 * @return the sweden political party
	 */
    public SwedenPoliticalParty createSwedenPoliticalParty() {
        return new SwedenPoliticalParty();
    }

    /**
	 * Creates a new Object object.
	 *
	 * @param value the value
	 * @return the JAXB element< sweden election type container element>
	 */
    @XmlElementDecl(namespace = "http://partier.val.external.model.cia.hack23.com/impl", name = "root")
    public JAXBElement<SwedenElectionTypeContainerElement> createRoot(final SwedenElectionTypeContainerElement value) {
        return new JAXBElement<>(_Root_QNAME, SwedenElectionTypeContainerElement.class, null, value);
    }

}


/*
 * Copyright 2010-2019 James Pether Sörling
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *   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,
 * 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.
 *
 *	$Id$
 *  $HeadURL$
 */
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;
import java.util.Map;
import java.util.Map.Entry;
import java.util.stream.Collectors;

import org.apache.commons.lang3.StringUtils;
import org.dussan.vaadin.dcharts.DCharts;
import org.dussan.vaadin.dcharts.base.elements.XYseries;
import org.dussan.vaadin.dcharts.data.DataSeries;
import org.dussan.vaadin.dcharts.options.Series;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import com.hack23.cia.model.internal.application.data.document.impl.RiksdagenDocumentTypeSummaryEmbeddedId;
import com.hack23.cia.model.internal.application.data.document.impl.ViewRiksdagenDocumentTypeDailySummary;
import com.hack23.cia.service.api.DataContainer;
import com.hack23.cia.web.impl.ui.application.views.common.chartfactory.api.DocumentChartDataManager;
import com.vaadin.ui.AbstractOrderedLayout;

/**
 * The Class DocumentChartDataManagerImpl.
 */
@Service
public final class DocumentChartDataManagerImpl extends AbstractChartDataManagerImpl
		implements DocumentChartDataManager {

	private static final Logger LOGGER = LoggerFactory.getLogger(DocumentChartDataManagerImpl.class);

	/** The Constant MOT_PROP_BET. */
	private static final String MOT_PROP_BET = "mot:prop:bet";

	/** The Constant YEAR_PREFIX. */
	private static final String YEAR_PREFIX = "19";

	/** The Constant EMPTY_STRING. */
	private static final String EMPTY_STRING = "";

	private static final String DD_MMM_YYYY = "dd-MMM-yyyy";

	/**
	 * Instantiates a new document chart data manager impl.
	 */
	public DocumentChartDataManagerImpl() {
		super();
	}

	/**
	 * Gets the document type map.
	 *
	 * @return the document type map
	 */
	private Map<String, List<ViewRiksdagenDocumentTypeDailySummary>> getDocumentTypeMap() {
		final DataContainer<ViewRiksdagenDocumentTypeDailySummary, RiksdagenDocumentTypeSummaryEmbeddedId> documentTypeSummaryDailyDataContainer = getApplicationManager()
				.getDataContainer(ViewRiksdagenDocumentTypeDailySummary.class);

		return documentTypeSummaryDailyDataContainer.getAll().parallelStream()
				.filter(t -> t != null && !t.getEmbeddedId().getPublicDate().startsWith(YEAR_PREFIX)
						&& StringUtils.containsIgnoreCase(MOT_PROP_BET, t.getEmbeddedId().getDocumentType()))
				.collect(Collectors.groupingBy(t -> t.getEmbeddedId().getDocumentType()));
	}

	@Override
	public void createDocumentTypeChart(final AbstractOrderedLayout content) {
		final Map<String, List<ViewRiksdagenDocumentTypeDailySummary>> map = getDocumentTypeMap();
		final SimpleDateFormat simpleDateFormat = new SimpleDateFormat(DD_MMM_YYYY, Locale.ENGLISH);
		final SimpleDateFormat parseInputDateFormat = new SimpleDateFormat("yyyy-MM-dd",Locale.ENGLISH);

		final DataSeries dataSeries = new DataSeries();
		final Series series = new Series();

		for (final Entry<String, List<ViewRiksdagenDocumentTypeDailySummary>> entry : map.entrySet()) {
			if (entry.getKey() != null && !EMPTY_STRING.equals(entry.getKey())) {
				addDataSeries(simpleDateFormat, parseInputDateFormat, dataSeries, series, entry);
			}
		}

		addChart(content, "Document type",
				new DCharts().setDataSeries(dataSeries)
						.setOptions(getChartOptions().createOptionsXYDateFloatLegendInsideOneColumn(series)).show(),
				true);
	}

	/**
	 * 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,
			final Entry<String, List<ViewRiksdagenDocumentTypeDailySummary>> entry) {

		series.addSeries(new XYseries().setLabel(entry.getKey()));
		dataSeries.newSeries();

		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) {
					LOGGER.warn("Problem parsing date:{}", item.getEmbeddedId().getPublicDate());
				}

			}
		}
	}

}


/*
 * Copyright 2010 James Pether Sörling
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *   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,
 * 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.
 *
 *	$Id$
 *  $HeadURL$
*/
// This file was generated by the JavaTM Architecture for XML Binding(JAXB) Reference Implementation, v2.2.11
// See http://java.sun.com/xml/jaxb
// Any modifications to this file will be lost upon recompilation of the source schema.
// Generated on: 2019.02.24 at 11:39:47 PM CET
//

package com.hack23.cia.model.external.val.partier.impl;

import java.util.ArrayList;
import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Inheritance;
import javax.persistence.InheritanceType;
import javax.persistence.JoinColumn;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlType;

import org.apache.commons.lang3.builder.EqualsBuilder;
import org.apache.commons.lang3.builder.HashCodeBuilder;

import com.hack23.cia.model.common.api.ModelObject;

/**
 * The Class SwedenElectionTypeContainerElement.
 */
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "SwedenElectionTypeContainerElement", propOrder = {
    "electionTypes"
})
@Entity(name = "SwedenElectionTypeContainerElement")
@Table(name = "SWEDEN_ELECTION_TYPE_CONTAIN_0")
@Inheritance(strategy = InheritanceType.JOINED)
public class SwedenElectionTypeContainerElement
    implements ModelObject
{

    /**
	 *
	 */
	private static final long serialVersionUID = 1L;

	/** The election types. */
    @XmlElement(name = "valtyp", required = true)
    protected List<SwedenElectionType> electionTypes = new ArrayList<>();

    /** The hjid. */
    @XmlAttribute(name = "Hjid")
    protected Long hjid;

    /**
	 * Gets the election types.
	 *
	 * @return the election types
	 */
    @OneToMany(targetEntity = SwedenElectionType.class, cascade = {
        CascadeType.ALL
    })
    @JoinColumn(name = "ELECTION_TYPES_SWEDEN_ELECTI_0")
    public List<SwedenElectionType> getElectionTypes() {
        return this.electionTypes;
    }

    /**
	 * Sets the election types.
	 *
	 * @param electionTypes the new election types
	 */
    public void setElectionTypes(final List<SwedenElectionType> electionTypes) {
        this.electionTypes = electionTypes;
    }

    /**
	 * Gets the hjid.
	 *
	 * @return the hjid
	 */
    @Id
    @Column(name = "HJID")
    @GeneratedValue(strategy = GenerationType.AUTO)
    public Long getHjid() {
        return hjid;
    }

    /**
	 * Sets the hjid.
	 *
	 * @param value the new hjid
	 */
    public void setHjid(final Long value) {
        this.hjid = value;
    }

	public boolean equals(final Object obj) {
		if (obj == null) {
			return false;
		}
		if (obj == this) {
			return true;
		}
		if (obj.getClass() != getClass()) {
			return false;
		}
		return new EqualsBuilder().append(getElectionTypes().toArray(), ((SwedenElectionTypeContainerElement) obj).getElectionTypes().toArray()).isEquals();
	}

	/* (non-Javadoc)
	 * @see java.lang.Object#hashCode()
	 */
	@Override
	public final int hashCode() {
		return HashCodeBuilder.reflectionHashCode(this);
	}

}


/*
 * Copyright 2010-2019 James Pether Sörling
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *   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,
 * 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.
 *
 *	$Id$
 *  $HeadURL$
*/
package com.hack23.cia.web.widgets.charts;

import java.util.ArrayList;
import java.util.List;

import org.apache.commons.lang3.builder.EqualsBuilder;
import org.apache.commons.lang3.builder.HashCodeBuilder;

import com.vaadin.shared.ui.JavaScriptComponentState;

/**
 * The Class SankeyChartState.
 */
public final class SankeyChartState extends JavaScriptComponentState {

	/** The Constant serialVersionUID. */
	private static final long serialVersionUID = 1L;

	/** The values. */
	public List<List<Object>> values = new ArrayList<>();

	/** The my id. */
	public String myId;

	/**
	 * Instantiates a new sankey chart state.
	 */
	public SankeyChartState() {
		super();
	}

	/**
	 * Adds the data row.
	 *
	 * @param from the from
	 * @param to the to
	 * @param weight the weight
	 */
	public void addDataRow(final String from, final String to, int weight) {
		final ArrayList<Object> valueData = new ArrayList<>();
		valueData.add(from);
		valueData.add(to);
		valueData.add(weight);
		values.add(valueData);
	}

	@Override
	public int hashCode() {
		return HashCodeBuilder.reflectionHashCode(this, false);
	}

	@Override
	public boolean equals(Object obj) {
		return EqualsBuilder.reflectionEquals(this, obj);
	}

}


/*
 * Copyright 2010 James Pether Sörling
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *   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,
 * 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.
 *
 *	$Id$
 *  $HeadURL$
*/
// This file was generated by the JavaTM Architecture for XML Binding(JAXB) Reference Implementation, v2.2.11
// See http://java.sun.com/xml/jaxb
// Any modifications to this file will be lost upon recompilation of the source schema.
// Generated on: 2019.02.24 at 11:40:10 PM CET
//

package com.hack23.cia.model.external.riksdagen.utskottsforslag.impl;

import java.math.BigInteger;

import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Inheritance;
import javax.persistence.InheritanceType;
import javax.persistence.Lob;
import javax.persistence.Table;
import javax.persistence.Transient;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlAnyElement;
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlSchemaType;
import javax.xml.bind.annotation.XmlType;

import org.apache.commons.lang3.builder.EqualsBuilder;
import org.apache.commons.lang3.builder.HashCodeBuilder;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;
import org.jvnet.hyperjaxb3.xml.bind.annotation.adapters.ElementAsString;
import org.jvnet.hyperjaxb3.xml.bind.annotation.adapters.XmlAdapterUtils;
import org.w3c.dom.Element;

import com.hack23.cia.model.common.api.ModelObject;

/**
 * The Class CommitteeProposalData.
 */
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "CommitteeProposalData", propOrder = {
    "header",
    "issueNumber",
    "proposal",
    "decisionType",
    "againstProposalNumber",
    "againstProposalParties",
    "ballotId",
    "ballotSummary",
    "ballotUrlXml",
    "committeeReport",
    "winner",
    "rm"
})
@Entity(name = "CommitteeProposalData")
@Table(name = "COMMITTEE_PROPOSAL_DATA")
@Inheritance(strategy = InheritanceType.JOINED)
public class CommitteeProposalData
    implements ModelObject
{

    /**
	 *
	 */
	private static final long serialVersionUID = 1L;

	/** The header. */
    @XmlElement(name = "rubrik", required = true)
    protected String header;

    /** The issue number. */
    @XmlElement(name = "punkt", required = true)
    protected BigInteger issueNumber;

    /** The proposal. */
    @XmlElement(name = "forslag", required = true)
    protected String proposal;

    /** The decision type. */
    @XmlElement(name = "beslutstyp", required = true)
    protected String decisionType;

    /** The against proposal number. */
    @XmlElement(name = "motforslag_nummer", required = true)
    protected BigInteger againstProposalNumber;

    /** The against proposal parties. */
    @XmlElement(name = "motforslag_partier", required = true)
    protected String againstProposalParties;

    /** The ballot id. */
    @XmlElement(name = "votering_id", required = true)
    protected String ballotId;

    /** The ballot summary. */
    @XmlAnyElement
    protected Element ballotSummary;

    /** The ballot url xml. */
    @XmlElement(name = "votering_url_xml", required = true)
    @XmlSchemaType(name = "anyURI")
    protected String ballotUrlXml;

    /** The committee report. */
    @XmlElement(name = "bet", required = true)
    protected String committeeReport;

    /** The winner. */
    @XmlElement(name = "vinnare", required = true)
    protected String winner;

    /** The rm. */
    @XmlElement(required = true)
    protected String rm;

    /** The hjid. */
    @XmlAttribute(name = "Hjid")
    protected Long hjid;

    /**
	 * Gets the header.
	 *
	 * @return the header
	 */
    @Basic
    @Column(name = "HEADER")
    public String getHeader() {
        return header;
    }

    /**
	 * Sets the header.
	 *
	 * @param value the new header
	 */
    public void setHeader(final String value) {
        this.header = value;
    }

    /**
	 * Gets the issue number.
	 *
	 * @return the issue number
	 */
    @Basic
    @Column(name = "ISSUE_NUMBER", precision = 20)
    public BigInteger getIssueNumber() {
        return issueNumber;
    }

    /**
	 * Sets the issue number.
	 *
	 * @param value the new issue number
	 */
    public void setIssueNumber(final BigInteger value) {
        this.issueNumber = value;
    }

    /**
	 * Gets the proposal.
	 *
	 * @return the proposal
	 */
    @Basic
    @Column(name = "PROPOSAL", length = 10485760)
    public String getProposal() {
        return proposal;
    }

    /**
	 * Sets the proposal.
	 *
	 * @param value the new proposal
	 */
    public void setProposal(final String value) {
        this.proposal = value;
    }

    /**
	 * Gets the decision type.
	 *
	 * @return the decision type
	 */
    @Basic
    @Column(name = "DECISION_TYPE")
    public String getDecisionType() {
        return decisionType;
    }

    /**
	 * Sets the decision type.
	 *
	 * @param value the new decision type
	 */
    public void setDecisionType(final String value) {
        this.decisionType = value;
    }

    /**
	 * Gets the against proposal number.
	 *
	 * @return the against proposal number
	 */
    @Basic
    @Column(name = "AGAINST_PROPOSAL_NUMBER", precision = 20)
    public BigInteger getAgainstProposalNumber() {
        return againstProposalNumber;
    }

    /**
	 * Sets the against proposal number.
	 *
	 * @param value the new against proposal number
	 */
    public void setAgainstProposalNumber(final BigInteger value) {
        this.againstProposalNumber = value;
    }

    /**
	 * Gets the against proposal parties.
	 *
	 * @return the against proposal parties
	 */
    @Basic
    @Column(name = "AGAINST_PROPOSAL_PARTIES")
    public String getAgainstProposalParties() {
        return againstProposalParties;
    }

    /**
	 * Sets the against proposal parties.
	 *
	 * @param value the new against proposal parties
	 */
    public void setAgainstProposalParties(final String value) {
        this.againstProposalParties = value;
    }

    /**
	 * Gets the ballot id.
	 *
	 * @return the ballot id
	 */
    @Basic
    @Column(name = "BALLOT_ID")
    public String getBallotId() {
        return ballotId;
    }

    /**
	 * Sets the ballot id.
	 *
	 * @param value the new ballot id
	 */
    public void setBallotId(final String value) {
        this.ballotId = value;
    }

    /**
	 * Gets the ballot summary.
	 *
	 * @return the ballot summary
	 */
    @Transient
    public Element getBallotSummary() {
        return ballotSummary;
    }

    /**
	 * Sets the ballot summary.
	 *
	 * @param value the new ballot summary
	 */
    public void setBallotSummary(final Element value) {
        this.ballotSummary = value;
    }

    /**
	 * Gets the ballot url xml.
	 *
	 * @return the ballot url xml
	 */
    @Basic
    @Column(name = "BALLOT_URL_XML")
    public String getBallotUrlXml() {
        return ballotUrlXml;
    }

    /**
	 * Sets the ballot url xml.
	 *
	 * @param value the new ballot url xml
	 */
    public void setBallotUrlXml(final String value) {
        this.ballotUrlXml = value;
    }

    /**
	 * Gets the committee report.
	 *
	 * @return the committee report
	 */
    @Basic
    @Column(name = "COMMITTEE_REPORT")
    public String getCommitteeReport() {
        return committeeReport;
    }

    /**
	 * Sets the committee report.
	 *
	 * @param value the new committee report
	 */
    public void setCommitteeReport(final String value) {
        this.committeeReport = value;
    }

    /**
	 * Gets the winner.
	 *
	 * @return the winner
	 */
    @Basic
    @Column(name = "WINNER")
    public String getWinner() {
        return winner;
    }

    /**
	 * Sets the winner.
	 *
	 * @param value the new winner
	 */
    public void setWinner(final String value) {
        this.winner = value;
    }

    /**
	 * Gets the rm.
	 *
	 * @return the rm
	 */
    @Basic
    @Column(name = "RM")
    public String getRm() {
        return rm;
    }

    /**
	 * Sets the rm.
	 *
	 * @param value the new rm
	 */
    public void setRm(final String value) {
        this.rm = value;
    }

    /**
	 * With header.
	 *
	 * @param value the value
	 * @return the committee proposal data
	 */
    public CommitteeProposalData withHeader(final String value) {
        setHeader(value);
        return this;
    }

    /**
	 * With issue number.
	 *
	 * @param value the value
	 * @return the committee proposal data
	 */
    public CommitteeProposalData withIssueNumber(final BigInteger value) {
        setIssueNumber(value);
        return this;
    }

    /**
	 * With proposal.
	 *
	 * @param value the value
	 * @return the committee proposal data
	 */
    public CommitteeProposalData withProposal(final String value) {
        setProposal(value);
        return this;
    }

    /**
	 * With decision type.
	 *
	 * @param value the value
	 * @return the committee proposal data
	 */
    public CommitteeProposalData withDecisionType(final String value) {
        setDecisionType(value);
        return this;
    }

    /**
	 * With against proposal number.
	 *
	 * @param value the value
	 * @return the committee proposal data
	 */
    public CommitteeProposalData withAgainstProposalNumber(final BigInteger value) {
        setAgainstProposalNumber(value);
        return this;
    }

    /**
	 * With against proposal parties.
	 *
	 * @param value the value
	 * @return the committee proposal data
	 */
    public CommitteeProposalData withAgainstProposalParties(final String value) {
        setAgainstProposalParties(value);
        return this;
    }

    /**
	 * With ballot id.
	 *
	 * @param value the value
	 * @return the committee proposal data
	 */
    public CommitteeProposalData withBallotId(final String value) {
        setBallotId(value);
        return this;
    }

    /**
	 * With ballot summary.
	 *
	 * @param value the value
	 * @return the committee proposal data
	 */
    public CommitteeProposalData withBallotSummary(final Element value) {
        setBallotSummary(value);
        return this;
    }

    /**
	 * With ballot url xml.
	 *
	 * @param value the value
	 * @return the committee proposal data
	 */
    public CommitteeProposalData withBallotUrlXml(final String value) {
        setBallotUrlXml(value);
        return this;
    }

    /**
	 * With committee report.
	 *
	 * @param value the value
	 * @return the committee proposal data
	 */
    public CommitteeProposalData withCommitteeReport(final String value) {
        setCommitteeReport(value);
        return this;
    }

    /**
	 * With winner.
	 *
	 * @param value the value
	 * @return the committee proposal data
	 */
    public CommitteeProposalData withWinner(final String value) {
        setWinner(value);
        return this;
    }

    /**
	 * With rm.
	 *
	 * @param value the value
	 * @return the committee proposal data
	 */
    public CommitteeProposalData withRm(final String value) {
        setRm(value);
        return this;
    }

	/* (non-Javadoc)
	 * @see java.lang.Object#toString()
	 */
	@Override
	public final String toString() {
		return ToStringBuilder.reflectionToString(this, ToStringStyle.SHORT_PREFIX_STYLE);
	}

    /**
	 * Gets the hjid.
	 *
	 * @return the hjid
	 */
    @Id
    @Column(name = "HJID")
    @GeneratedValue(strategy = GenerationType.AUTO)
    public Long getHjid() {
        return hjid;
    }

    /**
	 * Sets the hjid.
	 *
	 * @param value the new hjid
	 */
    public void setHjid(final Long value) {
        this.hjid = value;
    }

    /**
	 * Gets the ballot summary item.
	 *
	 * @return the ballot summary item
	 */
    @Basic
    @Column(name = "BALLOT_SUMMARY_ITEM")
    @Lob
    public String getBallotSummaryItem() {
        return XmlAdapterUtils.unmarshall(ElementAsString.class, this.getBallotSummary());
    }

    /**
	 * Sets the ballot summary item.
	 *
	 * @param target the new ballot summary item
	 */
    public void setBallotSummaryItem(final String target) {
        setBallotSummary(XmlAdapterUtils.marshall(ElementAsString.class, target));
    }

    /* (non-Javadoc)
     * @see java.lang.Object#equals(java.lang.Object)
     */
    public boolean equals(final Object object) {
    	return EqualsBuilder.reflectionEquals(this,object,"hjid");
    }

	/* (non-Javadoc)
	 * @see java.lang.Object#hashCode()
	 */
	@Override
	public final int hashCode() {
		return HashCodeBuilder.reflectionHashCode(this);
	}

}


/*
 * Copyright 2010 James Pether Sörling
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *   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,
 * 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.
 *
 *	$Id$
 *  $HeadURL$
*/
// This file was generated by the JavaTM Architecture for XML Binding(JAXB) Reference Implementation, v2.2.11
// See http://java.sun.com/xml/jaxb
// Any modifications to this file will be lost upon recompilation of the source schema.
// Generated on: 2019.02.24 at 11:26:40 PM CET
//

package com.hack23.cia.model.external.worldbank.countries.impl;

import javax.persistence.AttributeOverride;
import javax.persistence.AttributeOverrides;
import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.Embedded;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Inheritance;
import javax.persistence.InheritanceType;
import javax.persistence.Table;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlType;

import org.apache.commons.lang3.builder.EqualsBuilder;
import org.apache.commons.lang3.builder.HashCodeBuilder;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;

import com.hack23.cia.model.common.api.ModelObject;

/**
 * The Class CountryElement.
 */
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "", propOrder = {
    "iso2Code",
    "countryName",
    "region",
    "adminregion",
    "incomeLevel",
    "lendingType",
    "capitalCity",
    "longitude",
    "latitude"
})
@XmlRootElement(name = "country")
@Entity(name = "CountryElement")
@Table(name = "COUNTRY_ELEMENT")
@Inheritance(strategy = InheritanceType.JOINED)
public class CountryElement
    implements ModelObject
{

    /**
	 *
	 */
	private static final long serialVersionUID = 1L;

	/** The iso 2 code. */
    @XmlElement(required = true)
    protected String iso2Code;

    /** The country name. */
    @XmlElement(name = "name", required = true)
    protected String countryName;

    /** The region. */
    @XmlElement(required = true)
    protected Region region;

    /** The adminregion. */
    @XmlElement(required = true)
    protected Adminregion adminregion;

    /** The income level. */
    @XmlElement(required = true)
    protected IncomeLevel incomeLevel;

    /** The lending type. */
    @XmlElement(required = true)
    protected LendingType lendingType;

    /** The capital city. */
    @XmlElement(required = true)
    protected String capitalCity;

    /** The longitude. */
    @XmlElement(required = true)
    protected String longitude;

    /** The latitude. */
    @XmlElement(required = true)
    protected String latitude;

    /** The id. */
    @XmlAttribute(name = "id")
    protected String id;

    /** The hjid. */
    @XmlAttribute(name = "Hjid")
    protected Long hjid;

    /**
	 * Gets the iso 2 code.
	 *
	 * @return the iso 2 code
	 */
    @Basic
    @Column(name = "ISO_2CODE")
    public String getIso2Code() {
        return iso2Code;
    }

    /**
	 * Sets the iso 2 code.
	 *
	 * @param value the new iso 2 code
	 */
    public void setIso2Code(final String value) {
        this.iso2Code = value;
    }

    /**
	 * Gets the country name.
	 *
	 * @return the country name
	 */
    @Basic
    @Column(name = "COUNTRY_NAME")
    public String getCountryName() {
        return countryName;
    }

    /**
	 * Sets the country name.
	 *
	 * @param value the new country name
	 */
    public void setCountryName(final String value) {
        this.countryName = value;
    }

    /**
	 * Gets the region.
	 *
	 * @return the region
	 */
    @Embedded
    @AttributeOverrides({
        @AttributeOverride(name = "value", column = @Column(name = "REGION_VALUE")),
        @AttributeOverride(name = "id", column = @Column(name = "REGION_ID"))
    })
    public Region getRegion() {
        return region;
    }

    /**
	 * Sets the region.
	 *
	 * @param value the new region
	 */
    public void setRegion(final Region value) {
        this.region = value;
    }

    /**
	 * Gets the adminregion.
	 *
	 * @return the adminregion
	 */
    @Embedded
    @AttributeOverrides({
        @AttributeOverride(name = "value", column = @Column(name = "ADMINREGION_VALUE")),
        @AttributeOverride(name = "id", column = @Column(name = "ADMINREGION_ID"))
    })
    public Adminregion getAdminregion() {
        return adminregion;
    }

    /**
	 * Sets the adminregion.
	 *
	 * @param value the new adminregion
	 */
    public void setAdminregion(final Adminregion value) {
        this.adminregion = value;
    }

    /**
	 * Gets the income level.
	 *
	 * @return the income level
	 */
    @Embedded
    @AttributeOverrides({
        @AttributeOverride(name = "value", column = @Column(name = "INCOME_LEVEL_VALUE")),
        @AttributeOverride(name = "id", column = @Column(name = "INCOME_LEVEL_ID"))
    })
    public IncomeLevel getIncomeLevel() {
        return incomeLevel;
    }

    /**
	 * Sets the income level.
	 *
	 * @param value the new income level
	 */
    public void setIncomeLevel(final IncomeLevel value) {
        this.incomeLevel = value;
    }

    /**
	 * Gets the lending type.
	 *
	 * @return the lending type
	 */
    @Embedded
    @AttributeOverrides({
        @AttributeOverride(name = "value", column = @Column(name = "LENDING_TYPE_VALUE")),
        @AttributeOverride(name = "id", column = @Column(name = "LENDING_TYPE_ID"))
    })
    public LendingType getLendingType() {
        return lendingType;
    }

    /**
	 * Sets the lending type.
	 *
	 * @param value the new lending type
	 */
    public void setLendingType(final LendingType value) {
        this.lendingType = value;
    }

    /**
	 * Gets the capital city.
	 *
	 * @return the capital city
	 */
    @Basic
    @Column(name = "CAPITAL_CITY")
    public String getCapitalCity() {
        return capitalCity;
    }

    /**
	 * Sets the capital city.
	 *
	 * @param value the new capital city
	 */
    public void setCapitalCity(final String value) {
        this.capitalCity = value;
    }

    /**
	 * Gets the longitude.
	 *
	 * @return the longitude
	 */
    @Basic
    @Column(name = "LONGITUDE")
    public String getLongitude() {
        return longitude;
    }

    /**
	 * Sets the longitude.
	 *
	 * @param value the new longitude
	 */
    public void setLongitude(final String value) {
        this.longitude = value;
    }

    /**
	 * Gets the latitude.
	 *
	 * @return the latitude
	 */
    @Basic
    @Column(name = "LATITUDE")
    public String getLatitude() {
        return latitude;
    }

    /**
	 * Sets the latitude.
	 *
	 * @param value the new latitude
	 */
    public void setLatitude(final String value) {
        this.latitude = value;
    }

    /**
	 * Gets the id.
	 *
	 * @return the id
	 */
    @Basic
    @Column(name = "ID")
    public String getId() {
        return id;
    }

    /**
	 * Sets the id.
	 *
	 * @param value the new id
	 */
    public void setId(final String value) {
        this.id = value;
    }

    /**
	 * With iso 2 code.
	 *
	 * @param value the value
	 * @return the country element
	 */
    public CountryElement withIso2Code(final String value) {
        setIso2Code(value);
        return this;
    }

    /**
	 * With country name.
	 *
	 * @param value the value
	 * @return the country element
	 */
    public CountryElement withCountryName(final String value) {
        setCountryName(value);
        return this;
    }

    /**
	 * With region.
	 *
	 * @param value the value
	 * @return the country element
	 */
    public CountryElement withRegion(final Region value) {
        setRegion(value);
        return this;
    }

    /**
	 * With adminregion.
	 *
	 * @param value the value
	 * @return the country element
	 */
    public CountryElement withAdminregion(final Adminregion value) {
        setAdminregion(value);
        return this;
    }

    /**
	 * With income level.
	 *
	 * @param value the value
	 * @return the country element
	 */
    public CountryElement withIncomeLevel(final IncomeLevel value) {
        setIncomeLevel(value);
        return this;
    }

    /**
	 * With lending type.
	 *
	 * @param value the value
	 * @return the country element
	 */
    public CountryElement withLendingType(final LendingType value) {
        setLendingType(value);
        return this;
    }

    /**
	 * With capital city.
	 *
	 * @param value the value
	 * @return the country element
	 */
    public CountryElement withCapitalCity(final String value) {
        setCapitalCity(value);
        return this;
    }

    /**
	 * With longitude.
	 *
	 * @param value the value
	 * @return the country element
	 */
    public CountryElement withLongitude(final String value) {
        setLongitude(value);
        return this;
    }

    /**
	 * With latitude.
	 *
	 * @param value the value
	 * @return the country element
	 */
    public CountryElement withLatitude(final String value) {
        setLatitude(value);
        return this;
    }

    /**
	 * With id.
	 *
	 * @param value the value
	 * @return the country element
	 */
    public CountryElement withId(final String value) {
        setId(value);
        return this;
    }

	/* (non-Javadoc)
	 * @see java.lang.Object#hashCode()
	 */
	@Override
	public final int hashCode() {
		return HashCodeBuilder.reflectionHashCode(this);
	}

	/* (non-Javadoc)
	 * @see java.lang.Object#toString()
	 */
	@Override
	public final String toString() {
		return ToStringBuilder.reflectionToString(this, ToStringStyle.SHORT_PREFIX_STYLE);
	}

    /**
	 * Gets the hjid.
	 *
	 * @return the hjid
	 */
    @Id
    @Column(name = "HJID")
    @GeneratedValue(strategy = GenerationType.AUTO)
    public Long getHjid() {
        return hjid;
    }

    /**
	 * Sets the hjid.
	 *
	 * @param value the new hjid
	 */
    public void setHjid(final Long value) {
        this.hjid = value;
    }

    /* (non-Javadoc)
     * @see java.lang.Object#equals(java.lang.Object)
     */
    public boolean equals(final Object object) {
    	return EqualsBuilder.reflectionEquals(this,object,"hjid");
    }

}


/*
 * Copyright 2010 James Pether Sörling
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *   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,
 * 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.
 *
 *	$Id$
 *  $HeadURL$
*/
// This file was generated by the JavaTM Architecture for XML Binding(JAXB) Reference Implementation, v2.2.11
// See http://java.sun.com/xml/jaxb
// Any modifications to this file will be lost upon recompilation of the source schema.
// Generated on: 2019.02.24 at 11:40:13 PM CET
//

package com.hack23.cia.model.external.riksdagen.votering.impl;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Inheritance;
import javax.persistence.InheritanceType;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlType;

import org.apache.commons.lang3.builder.EqualsBuilder;
import org.apache.commons.lang3.builder.HashCodeBuilder;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;

import com.hack23.cia.model.common.api.ModelObject;

/**
 * The Class BallotContainer.
 */
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "BallotContainer", propOrder = {
    "ballotDocumentData",
    "ballotDocumentElement"
})
@Entity(name = "BallotContainer")
@Table(name = "BALLOT_CONTAINER")
@Inheritance(strategy = InheritanceType.JOINED)
public class BallotContainer
    implements ModelObject
{

    /**
	 *
	 */
	private static final long serialVersionUID = 1L;

	/** The ballot document data. */
    @XmlElement(name = "dokvotering", required = true)
    protected BallotDocumentData ballotDocumentData;

    /** The ballot document element. */
    @XmlElement(name = "dokument", required = true)
    protected BallotDocumentElement ballotDocumentElement;

    /** The hjid. */
    @XmlAttribute(name = "Hjid")
    protected Long hjid;

    /**
	 * Gets the ballot document data.
	 *
	 * @return the ballot document data
	 */
    @ManyToOne(targetEntity = BallotDocumentData.class, cascade = {
        CascadeType.ALL
    })
    @JoinColumn(name = "BALLOT_DOCUMENT_DATA_BALLOT__0")
    public BallotDocumentData getBallotDocumentData() {
        return ballotDocumentData;
    }

    /**
	 * Sets the ballot document data.
	 *
	 * @param value the new ballot document data
	 */
    public void setBallotDocumentData(final BallotDocumentData value) {
        this.ballotDocumentData = value;
    }

    /**
	 * Gets the ballot document element.
	 *
	 * @return the ballot document element
	 */
    @ManyToOne(targetEntity = BallotDocumentElement.class, cascade = {
        CascadeType.ALL
    })
    @JoinColumn(name = "BALLOT_DOCUMENT_ELEMENT_BALL_0")
    public BallotDocumentElement getBallotDocumentElement() {
        return ballotDocumentElement;
    }

    /**
	 * Sets the ballot document element.
	 *
	 * @param value the new ballot document element
	 */
    public void setBallotDocumentElement(final BallotDocumentElement value) {
        this.ballotDocumentElement = value;
    }

    /**
	 * With ballot document data.
	 *
	 * @param value the value
	 * @return the ballot container
	 */
    public BallotContainer withBallotDocumentData(final BallotDocumentData value) {
        setBallotDocumentData(value);
        return this;
    }

    /**
	 * With ballot document element.
	 *
	 * @param value the value
	 * @return the ballot container
	 */
    public BallotContainer withBallotDocumentElement(final BallotDocumentElement value) {
        setBallotDocumentElement(value);
        return this;
    }

	/* (non-Javadoc)
	 * @see java.lang.Object#toString()
	 */
	@Override
	public final String toString() {
		return ToStringBuilder.reflectionToString(this, ToStringStyle.SHORT_PREFIX_STYLE);
	}

    /**
	 * Gets the hjid.
	 *
	 * @return the hjid
	 */
    @Id
    @Column(name = "HJID")
    @GeneratedValue(strategy = GenerationType.AUTO)
    public Long getHjid() {
        return hjid;
    }

    /**
	 * Sets the hjid.
	 *
	 * @param value the new hjid
	 */
    public void setHjid(final Long value) {
        this.hjid = value;
    }

    /* (non-Javadoc)
     * @see java.lang.Object#equals(java.lang.Object)
     */
    public boolean equals(final Object object) {
    	return EqualsBuilder.reflectionEquals(this,object,"hjid");
    }

	/* (non-Javadoc)
	 * @see java.lang.Object#hashCode()
	 */
	@Override
	public final int hashCode() {
		return HashCodeBuilder.reflectionHashCode(this);
	}

}


/*
 * Copyright 2010-2019 James Pether Sörling
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *   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,
 * 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.
 *
 *	$Id$
 *  $HeadURL$
*/
package com.hack23.cia.encryption.properties;

import java.security.Security;

import org.bouncycastle.jce.provider.BouncyCastleProvider;
import org.jasypt.encryption.pbe.StandardPBEStringEncryptor;

/**
 * The Class EncryptProperty.
 */
public final class EncryptProperty {

	/** The Constant EXPECTED_NUMBER_ARGS. */
	private static final int EXPECTED_NUMBER_ARGS = 2;

	/** The Constant PBEWITHSHA256AND128BITAES_CBC_BC. */
	private static final String PBEWITHSHA256AND128BITAES_CBC_BC = "PBEWITHSHA256AND128BITAES-CBC-BC";

	/** The Constant BC_PROVIDER_NAME. */
	private static final String BC_PROVIDER_NAME = "BC";

	/** The Constant ENC_CONTENT_SUFFIX. */
	private static final String ENC_CONTENT_SUFFIX = ")";

	/** The Constant ENC_CONTENT_PREFIX. */
	private static final String ENC_CONTENT_PREFIX = "ENC(";

	/** The Constant ENCRYPTED_PROPERTY_VALUE. */
	private static final String ENCRYPTED_PROPERTY_VALUE = "Encrypted property value:";

	/** The Constant ENCRYPTED_VALUE. */
	private static final String ENCRYPTED_VALUE = "Encrypted value:";

	/** The Constant HELP_MESSAGE. */
	private static final String HELP_MESSAGE = "Encrypt property value with PBEWITHSHA256AND128BITAES_CBC_BC, using symmetric key and value as arguments. ./encryptProperty [key] [value]";

	/**
	 * Instantiates a new encrypt property.
	 */
	public EncryptProperty() {
		super();
	}

	/**
	 * The main method.
	 *
	 * @param args the arguments
	 */
	public static void main(String[] args) {
		if (args.length == EXPECTED_NUMBER_ARGS) {
			final String encryptValue = new EncryptProperty().encryptValue(args[0], args[1]);
			System.out.println(ENCRYPTED_VALUE +encryptValue);
			System.out.println(ENCRYPTED_PROPERTY_VALUE + ENC_CONTENT_PREFIX +encryptValue +ENC_CONTENT_SUFFIX);
		} else {
			System.out.println(HELP_MESSAGE);
		}
	}

	/**
	 * Encrypt value.
	 *
	 * @param symmetricKey
	 *            the symmetric key
	 * @param value
	 *            the value
	 * @return the string
	 */
	public String encryptValue(final String symmetricKey,final String value) {
		return getEncryptor(symmetricKey).encrypt(value);

	}

	/**
	 * Gets the encryptor.
	 *
	 * @param symmetricKey
	 *            the symmetric key
	 * @return the encryptor
	 */
	private static StandardPBEStringEncryptor getEncryptor(final String symmetricKey) {
		Security.addProvider(new BouncyCastleProvider());
		final StandardPBEStringEncryptor mySecondEncryptor = new StandardPBEStringEncryptor();
		mySecondEncryptor.setProviderName(BC_PROVIDER_NAME);
		mySecondEncryptor.setAlgorithm(PBEWITHSHA256AND128BITAES_CBC_BC);
		mySecondEncryptor.setPassword(symmetricKey);
		return mySecondEncryptor;
	}

	/**
	 * Decrypt value.
	 *
	 * @param symmetricKey
	 *            the symmetric key
	 * @param value
	 *            the value
	 * @return the string
	 */
	public String decryptValue(final String symmetricKey,final String value) {
		return getEncryptor(symmetricKey).decrypt(value);

	}

}


/*
 * Copyright 2010-2019 James Pether Sörling
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *   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,
 * 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.
 *
 *	$Id$
 *  $HeadURL$
*/
package com.hack23.cia.service.external.riksdagen.impl;

import javax.xml.bind.JAXBElement;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.oxm.Unmarshaller;
import org.springframework.stereotype.Component;

import com.hack23.cia.model.external.riksdagen.person.impl.PersonData;
import com.hack23.cia.model.external.riksdagen.personlista.impl.PersonContainerElement;
import com.hack23.cia.service.external.common.api.XmlAgent;
import com.hack23.cia.service.external.common.api.XmlAgentException;
import com.hack23.cia.service.external.riksdagen.api.DataFailureException;
import com.hack23.cia.service.external.riksdagen.api.RiksdagenPersonApi;

/**
 * The Class RiksdagenPersonApiImpl.
 */
@Component
final class RiksdagenPersonApiImpl implements RiksdagenPersonApi {

	/** The Constant HTTP_PERSON_RIKSDAGEN_EXTERNAL_MODEL_CIA_HACK23_COM_IMPL. */
	private static final String HTTP_PERSON_RIKSDAGEN_EXTERNAL_MODEL_CIA_HACK23_COM_IMPL = "http://person.riksdagen.external.model.cia.hack23.com/impl";

	/**
	 * The Constant HTTP_PERSONLISTA_RIKSDAGEN_EXTERNAL_MODEL_CIA_HACK23_COM_IMPL.
	 */
	private static final String HTTP_PERSONLISTA_RIKSDAGEN_EXTERNAL_MODEL_CIA_HACK23_COM_IMPL = "http://personlista.riksdagen.external.model.cia.hack23.com/impl";

	/** The Constant ID_KEY. */
	private static final String ID_KEY = "${ID_KEY}";

	/** The Constant LOGGER. */
	private static final Logger LOGGER = LoggerFactory.getLogger(RiksdagenPersonApiImpl.class);

	/** The Constant PERSON. */
	private static final String PERSON = "https://data.riksdagen.se/person/${ID_KEY}";

	/** The Constant PERSON_LIST. */
	private static final String PERSON_LIST = "https://data.riksdagen.se/personlista/?iid=&fnamn=&enamn=&f_ar=&kn=&parti=&valkrets=&rdlstatus=samtliga&org=";

	/** The Constant PROBLEM_GETTING_PERSON_DATA_ID_S_FROM_DATA_RIKSDAGEN_SE. */
	private static final String PROBLEM_GETTING_PERSON_DATA_ID_S_FROM_DATA_RIKSDAGEN_SE = "Problem getting person data id:{}  from data.riksdagen.se";

	/** The Constant PROBLEM_GETTING_PERSON_LIST_FROM_DATA_RIKSDAGEN_SE. */
	private static final String PROBLEM_GETTING_PERSON_LIST_FROM_DATA_RIKSDAGEN_SE = "Problem getting person list from data.riksdagen.se";

	/** The person list unmarshaller. */
	@Autowired
	@Qualifier("riksdagenPersonListMarshaller")
	private Unmarshaller personListUnmarshaller;

	/** The person unmarshaller. */
	@Autowired
	@Qualifier("riksdagenPersonMarshaller")
	private Unmarshaller personUnmarshaller;

	/** The xml agent. */
	private final XmlAgent xmlAgent;

	/**
	 * Instantiates a new riksdagen person api impl.
	 *
	 * @param xmlAgent
	 *            the xml agent
	 */
	@Autowired
	public RiksdagenPersonApiImpl(final XmlAgent xmlAgent) {
		super();
		this.xmlAgent = xmlAgent;
	}

	/* (non-Javadoc)
	 * @see com.hack23.cia.service.external.riksdagen.api.RiksdagenPersonApi#getPerson(java.lang.String)
	 */
	@Override
	public PersonData getPerson(final String id) throws DataFailureException {
		try {
			final String url = PERSON.replace(ID_KEY, id);
			return ((JAXBElement<com.hack23.cia.model.external.riksdagen.person.impl.PersonContainerData>) xmlAgent
					.unmarshallXml(personUnmarshaller, url, HTTP_PERSON_RIKSDAGEN_EXTERNAL_MODEL_CIA_HACK23_COM_IMPL,
							null, null)).getValue().getPerson();
		} catch (final XmlAgentException e) {
			LOGGER.warn(PROBLEM_GETTING_PERSON_DATA_ID_S_FROM_DATA_RIKSDAGEN_SE, id);
			throw new DataFailureException(e);
		}
	}

	/* (non-Javadoc)
	 * @see com.hack23.cia.service.external.riksdagen.api.RiksdagenPersonApi#getPersonList()
	 */
	@Override
	public PersonContainerElement getPersonList() throws DataFailureException {
		try {
			return ((JAXBElement<PersonContainerElement>) xmlAgent.unmarshallXml(personListUnmarshaller, PERSON_LIST,
					HTTP_PERSONLISTA_RIKSDAGEN_EXTERNAL_MODEL_CIA_HACK23_COM_IMPL, null, null)).getValue();
		} catch (final XmlAgentException e) {
			LOGGER.warn(PROBLEM_GETTING_PERSON_LIST_FROM_DATA_RIKSDAGEN_SE);
			throw new DataFailureException(e);
		}
	}

}


/*
 * Copyright 2010 James Pether Sörling
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *   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,
 * 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.
 *
 *	$Id$
 *  $HeadURL$
*/
// This file was generated by the JavaTM Architecture for XML Binding(JAXB) Reference Implementation, v2.2.11
// See http://java.sun.com/xml/jaxb
// Any modifications to this file will be lost upon recompilation of the source schema.
// Generated on: 2019.02.24 at 11:39:52 PM CET
//

package com.hack23.cia.model.external.val.landstingvalkrets.impl;

import java.util.ArrayList;
import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Inheritance;
import javax.persistence.InheritanceType;
import javax.persistence.JoinColumn;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlType;

import org.apache.commons.lang3.builder.EqualsBuilder;
import org.apache.commons.lang3.builder.HashCodeBuilder;

import com.hack23.cia.model.common.api.ModelObject;

/**
 * The Class SwedenCountyElectoralRegionContainer.
 */
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "SwedenCountyElectoralRegionContainer", propOrder = {
    "countyElectoralRegions"
})
@Entity(name = "SwedenCountyElectoralRegionContainer")
@Table(name = "SWEDEN_COUNTY_ELECTORAL_REGI_0")
@Inheritance(strategy = InheritanceType.JOINED)
public class SwedenCountyElectoralRegionContainer
    implements ModelObject
{

    /**
	 *
	 */
	private static final long serialVersionUID = 1L;

	/** The county electoral regions. */
    @XmlElement(name = "landsting", required = true)
    protected List<SwedenCountyElectoralRegion> countyElectoralRegions = new ArrayList<>();

    /** The hjid. */
    @XmlAttribute(name = "Hjid")
    protected Long hjid;

    /**
	 * Gets the county electoral regions.
	 *
	 * @return the county electoral regions
	 */
    @OneToMany(targetEntity = SwedenCountyElectoralRegion.class, cascade = {
        CascadeType.ALL
    })
    @JoinColumn(name = "COUNTY_ELECTORAL_REGIONS_SWE_0")
    public List<SwedenCountyElectoralRegion> getCountyElectoralRegions() {
        return this.countyElectoralRegions;
    }

    /**
	 * Sets the county electoral regions.
	 *
	 * @param countyElectoralRegions the new county electoral regions
	 */
    public void setCountyElectoralRegions(final List<SwedenCountyElectoralRegion> countyElectoralRegions) {
        this.countyElectoralRegions = countyElectoralRegions;
    }

    /**
	 * Gets the hjid.
	 *
	 * @return the hjid
	 */
    @Id
    @Column(name = "HJID")
    @GeneratedValue(strategy = GenerationType.AUTO)
    public Long getHjid() {
        return hjid;
    }

    /**
	 * Sets the hjid.
	 *
	 * @param value the new hjid
	 */
    public void setHjid(final Long value) {
        this.hjid = value;
    }

	public boolean equals(final Object obj) {
		if (obj == null) {
			return false;
		}
		if (obj == this) {
			return true;
		}
		if (obj.getClass() != getClass()) {
			return false;
		}
		return new EqualsBuilder().append(getCountyElectoralRegions().toArray(), ((SwedenCountyElectoralRegionContainer) obj).getCountyElectoralRegions().toArray()).isEquals();
	}

	/* (non-Javadoc)
	 * @see java.lang.Object#hashCode()
	 */
	@Override
	public final int hashCode() {
		return HashCodeBuilder.reflectionHashCode(this);
	}

}


/*
 * Copyright 2010-2019 James Pether Sörling
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *   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,
 * 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.
 *
 *	$Id$
 *  $HeadURL$
*/
package com.hack23.cia.service.impl.task;

import java.io.Serializable;

import org.quartz.JobExecutionContext;
import org.quartz.Scheduler;
import org.quartz.SchedulerContext;
import org.quartz.SchedulerException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.ApplicationContext;
import org.springframework.scheduling.quartz.QuartzJobBean;

/**
 * The Class AbstractJob.
 */
public abstract class AbstractJob extends QuartzJobBean implements Serializable{

	/** The Constant LOGGER. */
	private static final Logger LOGGER = LoggerFactory.getLogger(AbstractJob.class);

	/** The Constant APPLICATION_CONTEXT. */
	private static final String APPLICATION_CONTEXT = "applicationContext";

	/** The Constant serialVersionUID. */
	private static final long serialVersionUID = 1L;

	/**
	 * Gets the job context holder.
	 *
	 * @param jobContext
	 *            the job context
	 * @return the job context holder
	 */
	protected final JobContextHolder getJobContextHolder(final JobExecutionContext jobContext) {
		final Scheduler scheduler = jobContext.getScheduler();
		    JobContextHolder bean = null;
		    try {
		    	final SchedulerContext schedulerContext = scheduler.getContext();
		        final ApplicationContext appContext = (ApplicationContext) schedulerContext.get(APPLICATION_CONTEXT);
		        bean = appContext.getBean(JobContextHolder.class);
		    } catch (final SchedulerException e) {
		       LOGGER.error("Failed to get JobContextHolder",e );
		    }

		return bean;
	}

}


//
// This file was generated by the JavaTM Architecture for XML Binding(JAXB) Reference Implementation, v2.2.11
// See http://java.sun.com/xml/jaxb
// Any modifications to this file will be lost upon recompilation of the source schema.
// Generated on: 2019.02.25 at 12:05:09 AM CET
//

package com.hack23.cia.model.internal.application.system.impl;

import java.util.ArrayList;
import java.util.List;

import javax.persistence.Basic;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Inheritance;
import javax.persistence.InheritanceType;
import javax.persistence.JoinColumn;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Version;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlType;

import org.apache.commons.lang3.builder.EqualsBuilder;
import org.apache.commons.lang3.builder.HashCodeBuilder;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;

import com.hack23.cia.model.common.api.ModelObject;

/**
 *
Java class for Agency complex type.
 *
 *
The following schema fragment specifies the expected content contained within this class.
 *
 *

 * <complexType name="Agency">
 *   <complexContent>
 *     <restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
 *       <sequence>
 *         <element name="modelObjectId" type="{http://www.w3.org/2001/XMLSchema}int" minOccurs="0"/>
 *         <element name="modelObjectVersion" type="{http://www.w3.org/2001/XMLSchema}int"/>
 *         <element name="agencyName" type="{http://www.w3.org/2001/XMLSchema}string" minOccurs="0"/>
 *         <element name="description" type="{http://www.w3.org/2001/XMLSchema}string" minOccurs="0"/>
 *         <element name="portals" type="{http://system.application.internal.model.cia.hack23.com/impl}Portal" maxOccurs="unbounded" minOccurs="0"/>
 *       </sequence>
 *     </restriction>
 *   </complexContent>
 * </complexType>
 *

 *
 *
 */
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "Agency", propOrder = {
    "modelObjectId",
    "modelObjectVersion",
    "agencyName",
    "description",
    "portals"
})
@Entity(name = "Agency")
@Table(name = "AGENCY")
@Inheritance(strategy = InheritanceType.JOINED)
public class Agency
    implements ModelObject
{

    /**
	 *
	 */
	private static final long serialVersionUID = 1L;
	protected Integer modelObjectId;
    protected int modelObjectVersion;
    protected String agencyName;
    protected String description;
    @XmlElement(nillable = true)
    protected List<Portal> portals;
    @XmlAttribute(name = "Hjid")
    protected Long hjid;

    /**
     * Gets the value of the modelObjectId property.
     *
     * @return
     *     possible object is
     *     {@link Integer }
     *
     */
    @Basic
    @Column(name = "MODEL_OBJECT_ID", precision = 10, scale = 0)
    public Integer getModelObjectId() {
        return modelObjectId;
    }

    /**
     * Sets the value of the modelObjectId property.
     *
     * @param value
     *     allowed object is
     *     {@link Integer }
     *
     */
    public void setModelObjectId(final Integer value) {
        this.modelObjectId = value;
    }

    /**
     * Gets the value of the modelObjectVersion property.
     *
     */
    @Version
    @Column(name = "MODEL_OBJECT_VERSION")
    public int getModelObjectVersion() {
        return modelObjectVersion;
    }

    /**
     * Sets the value of the modelObjectVersion property.
     *
     */
    public void setModelObjectVersion(final int value) {
        this.modelObjectVersion = value;
    }

    /**
     * Gets the value of the agencyName property.
     *
     * @return
     *     possible object is
     *     {@link String }
     *
     */
    @Basic
    @Column(name = "AGENCY_NAME")
    public String getAgencyName() {
        return agencyName;
    }

    /**
     * Sets the value of the agencyName property.
     *
     * @param value
     *     allowed object is
     *     {@link String }
     *
     */
    public void setAgencyName(final String value) {
        this.agencyName = value;
    }

    /**
     * Gets the value of the description property.
     *
     * @return
     *     possible object is
     *     {@link String }
     *
     */
    @Basic
    @Column(name = "DESCRIPTION")
    public String getDescription() {
        return description;
    }

    /**
     * Sets the value of the description property.
     *
     * @param value
     *     allowed object is
     *     {@link String }
     *
     */
    public void setDescription(final String value) {
        this.description = value;
    }

    /**
     * Gets the value of the portals property.
     *
     *

     * This accessor method returns a reference to the live list,
     * not a snapshot. Therefore any modification you make to the
     * returned list will be present inside the JAXB object.
     * This is why there is not a set method for the portals property.
     *
     *

     * For example, to add a new item, do as follows:
     *

     *    getPortals().add(newItem);
     *

     *
     *
     *

     * Objects of the following type(s) are allowed in the list
     * {@link Portal }
     *
     *
     */
    @OneToMany(targetEntity = Portal.class, cascade = {
        CascadeType.ALL
    })
    @JoinColumn(name = "PORTALS_AGENCY_HJID")
    public List<Portal> getPortals() {
        if (portals == null) {
            portals = new ArrayList<>();
        }
        return this.portals;
    }

    /**
     *
     *
     */
    public void setPortals(final List<Portal> portals) {
        this.portals = portals;
    }

    public Agency withModelObjectId(final Integer value) {
        setModelObjectId(value);
        return this;
    }

    public Agency withModelObjectVersion(final int value) {
        setModelObjectVersion(value);
        return this;
    }

    public Agency withAgencyName(final String value) {
        setAgencyName(value);
        return this;
    }

    public Agency withDescription(final String value) {
        setDescription(value);
        return this;
    }

    public Agency withPortals(final List<Portal> portals) {
        setPortals(portals);
        return this;
    }

	@Override
	public final String toString() {
		return ToStringBuilder.reflectionToString(this, ToStringStyle.SHORT_PREFIX_STYLE);
	}

    /**
     * Gets the value of the hjid property.
     *
     * @return
     *     possible object is
     *     {@link Long }
     *
     */
    @Id
    @Column(name = "HJID")
    @GeneratedValue(strategy = GenerationType.AUTO)
    public Long getHjid() {
        return hjid;
    }

    /**
     * Sets the value of the hjid property.
     *
     * @param value
     *     allowed object is
     *     {@link Long }
     *
     */
    public void setHjid(final Long value) {
        this.hjid = value;
    }

	@Override
	public final boolean equals(final Object obj) {
		return EqualsBuilder.reflectionEquals(this, obj);
	}

	@Override
	public final int hashCode() {
		return HashCodeBuilder.reflectionHashCode(this);
	}

}


/*
 * Copyright 2010-2019 James Pether Sörling
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *   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,
 * 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.
 *
 *	$Id$
 *  $HeadURL$
*/
package com.hack23.cia.web.impl.ui.application.views.user.home.pagemode;

import java.util.Optional;

import com.hack23.cia.model.internal.application.user.impl.UserAccount;
import com.hack23.cia.model.internal.application.user.impl.UserAccount_;
import com.hack23.cia.service.api.DataContainer;
import com.hack23.cia.web.impl.ui.application.util.UserContextUtil;
import com.hack23.cia.web.impl.ui.application.views.common.pagemode.AbstractBasicPageModContentFactoryImpl;
import com.hack23.cia.web.impl.ui.application.views.common.viewnames.UserViews;

/**
 * The Class AbstractPoliticianPageModContentFactoryImpl.
 */
abstract class AbstractUserHomePageModContentFactoryImpl extends AbstractBasicPageModContentFactoryImpl {

	/** The Constant NAME. */
	public static final String NAME = UserViews.USERHOME_VIEW_NAME;

	/**
	 * Instantiates a new abstract user home page mod content factory impl.
	 */
	AbstractUserHomePageModContentFactoryImpl() {
		super();
	}

	/**
	 * Gets the active user account.
	 *
	 * @return the active user account
	 */
	protected final Optional<UserAccount> getActiveUserAccount() {
		final DataContainer<UserAccount, Long> dataContainer = getApplicationManager()
				.getDataContainer(UserAccount.class);
		return dataContainer
				.getAllBy(UserAccount_.userId, UserContextUtil.getUserIdFromSecurityContext()).stream().findFirst();
	}

}


/*
 * Copyright 2010 James Pether Sörling
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *   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,
 * 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.
 *
 *	$Id$
 *  $HeadURL$
*/
// This file was generated by the JavaTM Architecture for XML Binding(JAXB) Reference Implementation, v2.2.11
// See http://java.sun.com/xml/jaxb
// Any modifications to this file will be lost upon recompilation of the source schema.
// Generated on: 2019.02.24 at 11:40:02 PM CET
//

package com.hack23.cia.model.external.riksdagen.dokumentlista.impl;

import java.math.BigInteger;
import java.util.ArrayList;
import java.util.List;

import javax.persistence.Basic;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Inheritance;
import javax.persistence.InheritanceType;
import javax.persistence.JoinColumn;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlSchemaType;
import javax.xml.bind.annotation.XmlType;

import org.apache.commons.lang3.builder.EqualsBuilder;
import org.apache.commons.lang3.builder.HashCodeBuilder;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;

import com.hack23.cia.model.common.api.ModelObject;

/**
 * The Class DocumentContainerElement.
 */
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "DocumentContainerElement", propOrder = {
    "dokument"
})
@Entity(name = "DocumentContainerElement")
@Table(name = "DOCUMENT_CONTAINER_ELEMENT")
@Inheritance(strategy = InheritanceType.JOINED)
public class DocumentContainerElement
    implements ModelObject
{

    /**
	 *
	 */
	private static final long serialVersionUID = 1L;

	/** The dokument. */
    @XmlElement(required = true)
    protected List<DocumentElement> dokument = new ArrayList<>();

    /** The datum. */
    @XmlAttribute(name = "datum", required = true)
    protected String datum;

    /** The debug. */
    @XmlAttribute(name = "debug", required = true)
    protected String debug;

    /** The next page. */
    @XmlAttribute(name = "nasta_sida", required = true)
    @XmlSchemaType(name = "anyURI")
    protected String nextPage;

    /** The page. */
    @XmlAttribute(name = "sida", required = true)
    protected BigInteger page;

    /** The total pages. */
    @XmlAttribute(name = "sidor", required = true)
    protected BigInteger totalPages;

    /** The created. */
    @XmlAttribute(name = "skapad", required = true)
    protected String created;

    /** The hits from. */
    @XmlAttribute(name = "traff_fran", required = true)
    protected BigInteger hitsFrom;

    /** The hits to. */
    @XmlAttribute(name = "traff_till", required = true)
    protected BigInteger hitsTo;

    /** The hits. */
    @XmlAttribute(name = "traffar", required = true)
    protected BigInteger hits;

    /** The document version. */
    @XmlAttribute(name = "version", required = true)
    protected String documentVersion;

    /** The warning. */
    @XmlAttribute(name = "warning", required = true)
    protected String warning;

    /** The hjid. */
    @XmlAttribute(name = "Hjid")
    protected Long hjid;

    /**
	 * Gets the dokument.
	 *
	 * @return the dokument
	 */
    @OneToMany(targetEntity = DocumentElement.class, cascade = {
        CascadeType.ALL
    })
    @JoinColumn(name = "DOKUMENT_DOCUMENT_CONTAINER__0")
    public List<DocumentElement> getDokument() {
        return this.dokument;
    }

    /**
	 * Sets the dokument.
	 *
	 * @param dokument the new dokument
	 */
    public void setDokument(final List<DocumentElement> dokument) {
        this.dokument = dokument;
    }

    /**
	 * Gets the datum.
	 *
	 * @return the datum
	 */
    @Basic
    @Column(name = "DATUM")
    public String getDatum() {
        return datum;
    }

    /**
	 * Sets the datum.
	 *
	 * @param value the new datum
	 */
    public void setDatum(final String value) {
        this.datum = value;
    }

    /**
	 * Gets the debug.
	 *
	 * @return the debug
	 */
    @Basic
    @Column(name = "DEBUG")
    public String getDebug() {
        return debug;
    }

    /**
	 * Sets the debug.
	 *
	 * @param value the new debug
	 */
    public void setDebug(final String value) {
        this.debug = value;
    }

    /**
	 * Gets the next page.
	 *
	 * @return the next page
	 */
    @Basic
    @Column(name = "NEXT_PAGE")
    public String getNextPage() {
        return nextPage;
    }

    /**
	 * Sets the next page.
	 *
	 * @param value the new next page
	 */
    public void setNextPage(final String value) {
        this.nextPage = value;
    }

    /**
	 * Gets the page.
	 *
	 * @return the page
	 */
    @Basic
    @Column(name = "PAGE", precision = 20)
    public BigInteger getPage() {
        return page;
    }

    /**
	 * Sets the page.
	 *
	 * @param value the new page
	 */
    public void setPage(final BigInteger value) {
        this.page = value;
    }

    /**
	 * Gets the total pages.
	 *
	 * @return the total pages
	 */
    @Basic
    @Column(name = "TOTAL_PAGES", precision = 20)
    public BigInteger getTotalPages() {
        return totalPages;
    }

    /**
	 * Sets the total pages.
	 *
	 * @param value the new total pages
	 */
    public void setTotalPages(final BigInteger value) {
        this.totalPages = value;
    }

    /**
	 * Gets the created.
	 *
	 * @return the created
	 */
    @Basic
    @Column(name = "CREATED")
    public String getCreated() {
        return created;
    }

    /**
	 * Sets the created.
	 *
	 * @param value the new created
	 */
    public void setCreated(final String value) {
        this.created = value;
    }

    /**
	 * Gets the hits from.
	 *
	 * @return the hits from
	 */
    @Basic
    @Column(name = "HITS_FROM", precision = 20)
    public BigInteger getHitsFrom() {
        return hitsFrom;
    }

    /**
	 * Sets the hits from.
	 *
	 * @param value the new hits from
	 */
    public void setHitsFrom(final BigInteger value) {
        this.hitsFrom = value;
    }

    /**
	 * Gets the hits to.
	 *
	 * @return the hits to
	 */
    @Basic
    @Column(name = "HITS_TO", precision = 20)
    public BigInteger getHitsTo() {
        return hitsTo;
    }

    /**
	 * Sets the hits to.
	 *
	 * @param value the new hits to
	 */
    public void setHitsTo(final BigInteger value) {
        this.hitsTo = value;
    }

    /**
	 * Gets the hits.
	 *
	 * @return the hits
	 */
    @Basic
    @Column(name = "HITS", precision = 20)
    public BigInteger getHits() {
        return hits;
    }

    /**
	 * Sets the hits.
	 *
	 * @param value the new hits
	 */
    public void setHits(final BigInteger value) {
        this.hits = value;
    }

    /**
	 * Gets the document version.
	 *
	 * @return the document version
	 */
    @Basic
    @Column(name = "DOCUMENT_VERSION")
    public String getDocumentVersion() {
        return documentVersion;
    }

    /**
	 * Sets the document version.
	 *
	 * @param value the new document version
	 */
    public void setDocumentVersion(final String value) {
        this.documentVersion = value;
    }

    /**
	 * Gets the warning.
	 *
	 * @return the warning
	 */
    @Basic
    @Column(name = "WARNING")
    public String getWarning() {
        return warning;
    }

    /**
	 * Sets the warning.
	 *
	 * @param value the new warning
	 */
    public void setWarning(final String value) {
        this.warning = value;
    }

    /**
	 * With dokument.
	 *
	 * @param dokument the dokument
	 * @return the document container element
	 */
    public DocumentContainerElement withDokument(final List<DocumentElement> dokument) {
        setDokument(dokument);
        return this;
    }

    /**
	 * With datum.
	 *
	 * @param value the value
	 * @return the document container element
	 */
    public DocumentContainerElement withDatum(final String value) {
        setDatum(value);
        return this;
    }

    /**
	 * With debug.
	 *
	 * @param value the value
	 * @return the document container element
	 */
    public DocumentContainerElement withDebug(final String value) {
        setDebug(value);
        return this;
    }

    /**
	 * With next page.
	 *
	 * @param value the value
	 * @return the document container element
	 */
    public DocumentContainerElement withNextPage(final String value) {
        setNextPage(value);
        return this;
    }

    /**
	 * With page.
	 *
	 * @param value the value
	 * @return the document container element
	 */
    public DocumentContainerElement withPage(final BigInteger value) {
        setPage(value);
        return this;
    }

    /**
	 * With total pages.
	 *
	 * @param value the value
	 * @return the document container element
	 */
    public DocumentContainerElement withTotalPages(final BigInteger value) {
        setTotalPages(value);
        return this;
    }

    /**
	 * With created.
	 *
	 * @param value the value
	 * @return the document container element
	 */
    public DocumentContainerElement withCreated(final String value) {
        setCreated(value);
        return this;
    }

    /**
	 * With hits from.
	 *
	 * @param value the value
	 * @return the document container element
	 */
    public DocumentContainerElement withHitsFrom(final BigInteger value) {
        setHitsFrom(value);
        return this;
    }

    /**
	 * With hits to.
	 *
	 * @param value the value
	 * @return the document container element
	 */
    public DocumentContainerElement withHitsTo(final BigInteger value) {
        setHitsTo(value);
        return this;
    }

    /**
	 * With hits.
	 *
	 * @param value the value
	 * @return the document container element
	 */
    public DocumentContainerElement withHits(final BigInteger value) {
        setHits(value);
        return this;
    }

    /**
	 * With document version.
	 *
	 * @param value the value
	 * @return the document container element
	 */
    public DocumentContainerElement withDocumentVersion(final String value) {
        setDocumentVersion(value);
        return this;
    }

    /**
	 * With warning.
	 *
	 * @param value the value
	 * @return the document container element
	 */
    public DocumentContainerElement withWarning(final String value) {
        setWarning(value);
        return this;
    }

	/* (non-Javadoc)
	 * @see java.lang.Object#toString()
	 */
	@Override
	public final String toString() {
		return ToStringBuilder.reflectionToString(this, ToStringStyle.SHORT_PREFIX_STYLE);
	}

    /**
	 * Gets the hjid.
	 *
	 * @return the hjid
	 */
    @Id
    @Column(name = "HJID")
    @GeneratedValue(strategy = GenerationType.AUTO)
    public Long getHjid() {
        return hjid;
    }

    /**
	 * Sets the hjid.
	 *
	 * @param value the new hjid
	 */
    public void setHjid(final Long value) {
        this.hjid = value;
    }

	public boolean equals(final Object obj) {
		if (obj == null) {
			return false;
		}
		if (obj == this) {
			return true;
		}
		if (obj.getClass() != getClass()) {
			return false;
		}
		return new EqualsBuilder().append(getDokument().toArray(), ((DocumentContainerElement) obj).getDokument().toArray()).isEquals();
	}

	/* (non-Javadoc)
	 * @see java.lang.Object#hashCode()
	 */
	@Override
	public final int hashCode() {
		return HashCodeBuilder.reflectionHashCode(this);
	}

}


/*
 * Copyright 2010-2019 James Pether Sörling
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *   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,
 * 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.
 *
 *	$Id$
 *  $HeadURL$
*/
package com.hack23.cia.web.impl.ui.application.views.common;

import java.util.Map;

import javax.annotation.PostConstruct;

import org.jsoup.Jsoup;
import org.jsoup.safety.Whitelist;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.AccessDeniedException;
import org.springframework.web.context.request.RequestContextHolder;

import com.hack23.cia.service.api.action.application.LogoutRequest;
import com.hack23.cia.web.impl.ui.application.action.PageActionEventHelper;
import com.hack23.cia.web.impl.ui.application.util.UserContextUtil;
import com.hack23.cia.web.impl.ui.application.views.common.labelfactory.LabelFactory;
import com.hack23.cia.web.impl.ui.application.views.common.menufactory.api.ApplicationMenuItemFactory;
import com.hack23.cia.web.impl.ui.application.views.common.pagelinks.api.PageLinkFactory;
import com.hack23.cia.web.impl.ui.application.views.common.pagemode.PageModeContentFactory;
import com.hack23.cia.web.impl.ui.application.views.common.sizing.ContentRatio;
import com.hack23.cia.web.impl.ui.application.views.pageclicklistener.LogoutClickListener;
import com.vaadin.icons.VaadinIcons;
import com.vaadin.navigator.View;
import com.vaadin.navigator.ViewChangeListener.ViewChangeEvent;
import com.vaadin.server.ThemeResource;
import com.vaadin.ui.Alignment;
import com.vaadin.ui.Button;
import com.vaadin.ui.HorizontalLayout;
import com.vaadin.ui.Image;
import com.vaadin.ui.Label;
import com.vaadin.ui.Link;
import com.vaadin.ui.MenuBar;
import com.vaadin.ui.Panel;
import com.vaadin.ui.VerticalLayout;

/**
 * The Class AbstractView.
 */
public abstract class AbstractView extends Panel implements View {

	/** The Constant serialVersionUID. */
	private static final long serialVersionUID = 1L;

	/** The Constant LOGGER. */
	private static final Logger LOGGER = LoggerFactory.getLogger(AbstractView.class);

	/** The Constant LOGOUT. */
	private static final String LOGOUT = "Logout";

	/** The Constant ROLE_USER. */
	private static final String ROLE_USER = "ROLE_USER";

	/** The Constant ROLE_ADMIN. */
	private static final String ROLE_ADMIN = "ROLE_ADMIN";

	/** The page mode content factory map. */
	private transient Map<String, PageModeContentFactory> pageModeContentFactoryMap;

	/** The page name. */
	private final String pageName;

	/** The barmenu. */
	private final MenuBar barmenu = new MenuBar();

	/** The top header right panel. */
	private final HorizontalLayout topHeaderRightPanel = new HorizontalLayout();

	/** The panel. */
	private Panel panel;

	/** The page link factory. */
	@Autowired
	protected transient PageLinkFactory pageLinkFactory;

	/** The page action event helper. */
	@Autowired
	protected transient PageActionEventHelper pageActionEventHelper;

	/** The menu item factory. */
	@Autowired
	private transient ApplicationMenuItemFactory menuItemFactory;

	/**
	 * Instantiates a new abstract view.
	 */
	protected AbstractView(final Map<String, PageModeContentFactory> pageModeContentFactoryMap, final String pageName) {
		super();
		this.pageModeContentFactoryMap = pageModeContentFactoryMap;
		this.pageName = pageName;
	}

	/**
	 * Post construct.
	 */
	@PostConstruct
	public final void postConstruct() {
		setSizeFull();
		createBasicLayoutWithPanelAndFooter(pageName);
	}

	@Override
	public final void enter(final ViewChangeEvent event) {
		try {

			final String parameters = Jsoup.clean(event.getParameters(), Whitelist.basic());

			for (final PageModeContentFactory pageModeContentFactory : pageModeContentFactoryMap.values()) {
				if (pageModeContentFactory.matches(pageName, parameters) && pageModeContentFactory.validReference(parameters)) {
					getPanel().setContent(pageModeContentFactory.createContent(parameters, getBarmenu(), getPanel()));
					return;
				}
			}

			LOGGER.warn("Invalid reference, content not found:{}/{}",pageName, parameters);
			final VerticalLayout panelContent = createFullSizeVerticalLayout();

			menuItemFactory.createMainPageMenuBar(getBarmenu());

			LabelFactory.createHeader2Label(panelContent,"Invalid reference, content not found:" +pageName+ "/"+ parameters);

			getPanel().setContent(panelContent);
			getPanel().setCaption("Invalid Reference");
		} catch (final AccessDeniedException e ) {
			LOGGER.warn("Authorization Failure:: {} : {}  exception : {}",e.getMessage(),pageName,e.getClass().getName());
			final VerticalLayout panelContent = createFullSizeVerticalLayout();
			LabelFactory.createHeader2Label(panelContent,"Access denied:" +pageName);
			getPanel().setContent(panelContent);
			getPanel().setCaption("Access denied");
		}
	}

	/**
	 * Creates the basic layout with panel and footer.
	 *
	 * @param panelName
	 *            the panel name
	 */
	protected final void createBasicLayoutWithPanelAndFooter(final String panelName) {
		final VerticalLayout layout = createFullSizeVerticalLayout();
		final VerticalLayout pageModeContent = createFullSizeVerticalLayout(false,false);
		layout.addComponent(pageModeContent);

		final HorizontalLayout topHeader = new HorizontalLayout();

		addLogoToHeader(topHeader);
		createTopTitleHeader(topHeader);

		topHeaderRightPanel.removeAllComponents();
		topHeader.addComponent(topHeaderRightPanel);
		topHeader.setComponentAlignment(topHeaderRightPanel, Alignment.MIDDLE_RIGHT);
		topHeader.setExpandRatio(topHeaderRightPanel, ContentRatio.LARGE);

		createTopHeaderActionsForUserContext();

		topHeaderRightPanel.setWidth("100%");
		topHeaderRightPanel.setHeight("50px");

		topHeader.setWidth("100%");
		topHeader.setHeight("50px");

		pageModeContent.addComponent(topHeader);
		pageModeContent.setComponentAlignment(topHeader, Alignment.TOP_CENTER);

		pageModeContent.addComponent(getBarmenu());
		pageModeContent.setComponentAlignment(getBarmenu(), Alignment.TOP_CENTER);

		panel = new Panel(panelName);
		panel.addStyleName("v-panel-page-panel");

		panel.setSizeFull();
		pageModeContent.addComponent(panel);
		pageModeContent.setExpandRatio(panel, ContentRatio.FULL_SIZE);

		pageModeContent.addComponent(pageLinkFactory.createMainViewPageLink());
		setContent(layout);

		setWidth(100, Unit.PERCENTAGE);
		setHeight(100, Unit.PERCENTAGE);
		setSizeFull();

	}

	/**
	 * Creates the top header actions for user context.
	 */
	private void createTopHeaderActionsForUserContext() {
		if (UserContextUtil.allowRoleInSecurityContext(ROLE_ADMIN) || UserContextUtil.allowRoleInSecurityContext(ROLE_USER)) {
			final Link userHomePageLink = pageLinkFactory.createUserHomeViewPageLink();
			topHeaderRightPanel.addComponent(userHomePageLink);
			topHeaderRightPanel.setComponentAlignment(userHomePageLink, Alignment.MIDDLE_RIGHT);

			final Button logoutButton = new Button(LOGOUT,VaadinIcons.SIGN_OUT);

			final LogoutRequest logoutRequest = new LogoutRequest();
			logoutRequest.setSessionId(RequestContextHolder.currentRequestAttributes().getSessionId());
			logoutButton.addClickListener(new LogoutClickListener(logoutRequest));

			topHeaderRightPanel.addComponent(logoutButton);
			topHeaderRightPanel.setComponentAlignment(logoutButton, Alignment.MIDDLE_RIGHT);

		} else {
			final Link createRegisterPageLink = pageLinkFactory.createRegisterPageLink();
			topHeaderRightPanel.addComponent(createRegisterPageLink);
			topHeaderRightPanel.setComponentAlignment(createRegisterPageLink, Alignment.MIDDLE_RIGHT);

			final Link createLoginPageLink = pageLinkFactory.createLoginPageLink();
			topHeaderRightPanel.addComponent(createLoginPageLink);
			topHeaderRightPanel.setComponentAlignment(createLoginPageLink, Alignment.MIDDLE_RIGHT);
		}
	}

	/**
	 * Creates the full size vertical layout.
	 *
	 * @param margin
	 *            the margin
	 * @param spacing
	 *            the spacing
	 * @return the vertical layout
	 */
	private static VerticalLayout createFullSizeVerticalLayout(final boolean margin, final boolean spacing) {
		final VerticalLayout layout = new VerticalLayout();
		layout.setMargin(margin);
		layout.setSpacing(spacing);
		layout.setWidth(100, Unit.PERCENTAGE);
		layout.setHeight(100, Unit.PERCENTAGE);
		return layout;
	}

	/**
	 * Creates the full size vertical layout.
	 *
	 * @return the vertical layout
	 */
	private static VerticalLayout createFullSizeVerticalLayout() {
		return createFullSizeVerticalLayout(true,true);
	}

	/**
	 * Adds the logo to header.
	 *
	 * @param topHeader
	 *            the top header
	 */
	private static void addLogoToHeader(final HorizontalLayout topHeader) {
		final ThemeResource ciaLogoResource = new ThemeResource("cia-logo.png");
		final Image ciaLogoImage = new Image(null,ciaLogoResource);
		topHeader.addComponent(ciaLogoImage);
		ciaLogoImage.setWidth("60px");
		ciaLogoImage.setHeight("60px");
		topHeader.setComponentAlignment(ciaLogoImage, Alignment.MIDDLE_LEFT);
		topHeader.setExpandRatio(ciaLogoImage, ContentRatio.SMALL);
	}

	/**
	 * Creates the top title header.
	 *
	 * @param topHeader
	 *            the top header
	 */
	private static void createTopTitleHeader(final HorizontalLayout topHeader) {
		final HorizontalLayout topTitleHeadertPanel = new HorizontalLayout();

		final Label titleLabel = new Label("Citizen Intelligence Agency");
		titleLabel.setStyleName("Header");
		topTitleHeadertPanel.addComponent(titleLabel);
		topTitleHeadertPanel.setComponentAlignment(titleLabel, Alignment.MIDDLE_LEFT);

		final Label sloganLabel = new Label("// Tracking politicians like bugs!");
		sloganLabel.setStyleName("HeaderSlogan");
		topTitleHeadertPanel.addComponent(sloganLabel);
		topTitleHeadertPanel.setComponentAlignment(sloganLabel, Alignment.MIDDLE_RIGHT);

		topHeader.addComponent(topTitleHeadertPanel);
		topHeader.setComponentAlignment(topTitleHeadertPanel, Alignment.MIDDLE_LEFT);
		topHeader.setExpandRatio(topTitleHeadertPanel, ContentRatio.GRID);
	}

	/**
	 * Gets the barmenu.
	 *
	 * @return the barmenu
	 */
	public final MenuBar getBarmenu() {
		return barmenu;
	}

	/**
	 * Gets the panel.
	 *
	 * @return the panel
	 */
	protected final Panel getPanel() {
		return panel;
	}

}


/*
 * Copyright 2010 James Pether Sörling
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *   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,
 * 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.
 *
 *	$Id$
 *  $HeadURL$
*/
// This file was generated by the JavaTM Architecture for XML Binding(JAXB) Reference Implementation, v2.2.11
// See http://java.sun.com/xml/jaxb
// Any modifications to this file will be lost upon recompilation of the source schema.
// Generated on: 2019.02.24 at 11:39:52 PM CET
//

package com.hack23.cia.model.external.val.landstingvalkrets.impl;

import javax.xml.bind.JAXBElement;
import javax.xml.bind.annotation.XmlElementDecl;
import javax.xml.bind.annotation.XmlRegistry;
import javax.xml.namespace.QName;

/**
 * A factory for creating Object objects.
 */
@XmlRegistry
public class ObjectFactory {

    /** The Constant _Root_QNAME. */
    private static final QName _Root_QNAME = new QName("http://landstingvalkrets.val.external.model.cia.hack23.com/impl", "root");

    /**
	 * Instantiates a new object factory.
	 */
    public ObjectFactory() {
    }

    /**
	 * Creates a new Object object.
	 *
	 * @return the sweden county electoral region container
	 */
    public SwedenCountyElectoralRegionContainer createSwedenCountyElectoralRegionContainer() {
        return new SwedenCountyElectoralRegionContainer();
    }

    /**
	 * Creates a new Object object.
	 *
	 * @return the sweden county electoral region
	 */
    public SwedenCountyElectoralRegion createSwedenCountyElectoralRegion() {
        return new SwedenCountyElectoralRegion();
    }

    /**
	 * Creates a new Object object.
	 *
	 * @return the sweden county electoral area
	 */
    public SwedenCountyElectoralArea createSwedenCountyElectoralArea() {
        return new SwedenCountyElectoralArea();
    }

    /**
	 * Creates a new Object object.
	 *
	 * @param value the value
	 * @return the JAXB element< sweden county electoral region container>
	 */
    @XmlElementDecl(namespace = "http://landstingvalkrets.val.external.model.cia.hack23.com/impl", name = "root")
    public JAXBElement<SwedenCountyElectoralRegionContainer> createRoot(final SwedenCountyElectoralRegionContainer value) {
        return new JAXBElement<>(_Root_QNAME, SwedenCountyElectoralRegionContainer.class, null, value);
    }

}