<commit_before>/**
 * Licensed to Jasig under one or more contributor license
 * agreements. See the NOTICE file distributed with this work
 * for additional information regarding copyright ownership.
 * Jasig licenses this file to you 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.
 */

package org.openregistry.core.domain.jpa.sor;

import org.hibernate.annotations.*;
import org.openregistry.core.domain.annotation.Gender;
import org.openregistry.core.domain.annotation.Required;
import org.openregistry.core.domain.annotation.RequiredSize;
import org.openregistry.core.domain.sor.SorName;
import org.openregistry.core.domain.sor.SorPerson;
import org.openregistry.core.domain.sor.SorRole;
import org.openregistry.core.domain.DisclosureSettings;
import org.openregistry.core.domain.Name;
import org.openregistry.core.domain.Type;
import org.openregistry.core.domain.jpa.JpaDisclosureSettingsImpl;
import org.openregistry.core.domain.jpa.JpaTypeImpl;
import org.openregistry.core.domain.internal.Entity;
import org.hibernate.envers.Audited;
import org.springframework.util.Assert;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.persistence.*;
import javax.persistence.CascadeType;
import javax.persistence.Table;
import javax.validation.Valid;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Past;
import javax.validation.constraints.Size;

import java.util.*;

/**
 * Implementation of the SoR Person.
 * Unique constraints assumes each person can have only one sorPerson from any given SOR
 *
 * @author <NAME>
 * @version $Revision$ $Date$
 * @since 1.0.0
 */
@javax.persistence.Entity(name = "sorPerson")
@Table(name = "prs_sor_persons")
//, uniqueConstraints = @UniqueConstraint(columnNames = {"source_sor_id", "person_id"}))
@Audited
@org.hibernate.annotations.Table(appliesTo = "prs_sor_persons", indexes = {@Index(name = "SOR_PERSON_SOURCE_AND_ID_INDEX", columnNames = {"source_sor_id", "id"})})
public class JpaSorPersonImpl extends Entity implements SorPerson {

    protected static final Logger logger = LoggerFactory.getLogger(JpaSorPersonImpl.class);

    @Id
    @Column(name = "record_id")
    @GeneratedValue(strategy = GenerationType.AUTO, generator = "prs_sor_persons_seq")
    @SequenceGenerator(name = "prs_sor_persons_seq", sequenceName = "prs_sor_persons_seq", initialValue = 1, allocationSize = 50)
    private Long recordId;

    @Column(name = "id")
    @Required(property = "person.sorId")
    private String sorId;

    @Column(name = "source_sor_id", nullable = false)
    @NotNull
    @Size(min = 1)
    private String sourceSor;

    @Column(name = "person_id")
    private Long personId;

    @Column(name = "date_of_birth", nullable = true)
    @Temporal(TemporalType.DATE)
    @Required(property = "person.dateOfBirth", message = "{dateOfBirthRequiredMsg}")
    @Past
    private Date dateOfBirth;

    @Column(name = "gender", length = 1, nullable = true)
    @Required(property = "person.gender", message = "{genderRequiredMsg}")
    @Size(min = 1, max = 1, message = "{genderRequiredMsg}")
//    @Gender
    private String gender;

    @OneToMany(cascade = CascadeType.ALL, mappedBy = "person", fetch = FetchType.LAZY, targetEntity = JpaSorNameImpl.class)
    @org.hibernate.annotations.Cascade(org.hibernate.annotations.CascadeType.DELETE_ORPHAN)
    @Fetch(value = FetchMode.SUBSELECT)
    @RequiredSize(property = "person.names")
    @Valid
    private List<SorName> names = new ArrayList<SorName>();

    @Column(name = "ssn", nullable = true, length = 9)
    @Required(property = "person.ssn")
    private String ssn;

    @OneToOne(cascade=CascadeType.ALL, mappedBy="person", fetch = FetchType.LAZY, targetEntity = JpaSorDisclosureSettingsImpl.class)
    private JpaSorDisclosureSettingsImpl disclosureSettings;

    @OneToMany(cascade = CascadeType.ALL, mappedBy = "person", fetch = FetchType.LAZY, targetEntity = JpaSorRoleImpl.class)
    @org.hibernate.annotations.Cascade(org.hibernate.annotations.CascadeType.DELETE_ORPHAN)
    @Fetch(value = FetchMode.SUBSELECT)
    @Valid
    private List<SorRole> roles = new ArrayList<SorRole>();

    @ElementCollection
    @CollectionTable(name = "prs_sor_persons_loc_attr", joinColumns = @JoinColumn(name = "sor_person_record_id"))
    @MapKeyColumn(name = "attribute_type")
    @Column(name = "attribute_value")
    private Map<String, String> sorLocalAttributes = new HashMap<String, String>();

    public List<SorRole> getRoles() {
        return this.roles;
    }

    public String getSsn() {
        return this.ssn;
    }

    public void setSsn(final String ssn) {
        this.ssn = ssn;
    }

    public Long getId() {
        return this.recordId;
    }

    public String getSorId() {
        return this.sorId;
    }

    public String getSourceSor() {
        return this.sourceSor;
    }

    public void setSourceSor(final String sorIdentifier) {
        this.sourceSor = sorIdentifier;
    }

    public List<SorName> getNames() {
        return this.names;
    }

    public void setSorId(final String id) {
        this.sorId = id;
    }

    public Date getDateOfBirth() {
        return this.dateOfBirth;
    }

    public void setDateOfBirth(final Date date) {
        this.dateOfBirth = date;
    }

    public String getGender() {
        return this.gender;
    }

    public void setGender(final String gender) {
        this.gender = gender;
    }

    /**
     * @see org.openregistry.core.domain.sor.SorPerson#getDisclosureSettings()
     */
    public DisclosureSettings getDisclosureSettings() {
		return this.disclosureSettings;
	}

	/**
	 * @see org.openregistry.core.domain.sor.SorPerson#setDisclosureSettings(org.openregistry.core.domain.DisclosureSettings)
	 */
	public void setDisclosureSettings(DisclosureSettings ds) {
		if (ds instanceof JpaSorDisclosureSettingsImpl) {
			this.disclosureSettings = new JpaSorDisclosureSettingsImpl
				(this, ds.getDisclosureCode(), ds.getLastUpdateDate(), ds.isWithinGracePeriod());
		} else {<commit_msg>Removed unused imports; updated implementation due to changes in the SorPErson interface<commit_after>/**
 * Licensed to Jasig under one or more contributor license
 * agreements. See the NOTICE file distributed with this work
 * for additional information regarding copyright ownership.
 * Jasig licenses this file to you 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.
 */

package org.openregistry.core.domain.jpa.sor;

import org.hibernate.annotations.*;
import org.openregistry.core.domain.annotation.Required;
import org.openregistry.core.domain.annotation.RequiredSize;
import org.openregistry.core.domain.sor.SorDisclosureSettings;
import org.openregistry.core.domain.sor.SorName;
import org.openregistry.core.domain.sor.SorPerson;
import org.openregistry.core.domain.sor.SorRole;
import org.openregistry.core.domain.Type;
import org.openregistry.core.domain.jpa.JpaTypeImpl;
import org.openregistry.core.domain.internal.Entity;
import org.hibernate.envers.Audited;
import org.springframework.util.Assert;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.persistence.*;
import javax.persistence.CascadeType;
import javax.persistence.Table;
import javax.validation.Valid;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Past;
import javax.validation.constraints.Size;

import java.util.*;

/**
 * Implementation of the SoR Person.
 * Unique constraints assumes each person can have only one sorPerson from any given SOR
 *
 * @author <NAME>
 * @version $Revision$ $Date$
 * @since 1.0.0
 */
@javax.persistence.Entity(name = "sorPerson")
@Table(name = "prs_sor_persons")
//, uniqueConstraints = @UniqueConstraint(columnNames = {"source_sor_id", "person_id"}))
@Audited
@org.hibernate.annotations.Table(appliesTo = "prs_sor_persons", indexes = {@Index(name = "SOR_PERSON_SOURCE_AND_ID_INDEX", columnNames = {"source_sor_id", "id"})})
public class JpaSorPersonImpl extends Entity implements SorPerson {

    protected static final Logger logger = LoggerFactory.getLogger(JpaSorPersonImpl.class);

    @Id
    @Column(name = "record_id")
    @GeneratedValue(strategy = GenerationType.AUTO, generator = "prs_sor_persons_seq")
    @SequenceGenerator(name = "prs_sor_persons_seq", sequenceName = "prs_sor_persons_seq", initialValue = 1, allocationSize = 50)
    private Long recordId;

    @Column(name = "id")
    @Required(property = "person.sorId")
    private String sorId;

    @Column(name = "source_sor_id", nullable = false)
    @NotNull
    @Size(min = 1)
    private String sourceSor;

    @Column(name = "person_id")
    private Long personId;

    @Column(name = "date_of_birth", nullable = true)
    @Temporal(TemporalType.DATE)
    @Required(property = "person.dateOfBirth", message = "{dateOfBirthRequiredMsg}")
    @Past
    private Date dateOfBirth;

    @Column(name = "gender", length = 1, nullable = true)
    @Required(property = "person.gender", message = "{genderRequiredMsg}")
    @Size(min = 1, max = 1, message = "{genderRequiredMsg}")
//    @Gender
    private String gender;

    @OneToMany(cascade = CascadeType.ALL, mappedBy = "person", fetch = FetchType.LAZY, targetEntity = JpaSorNameImpl.class)
    @org.hibernate.annotations.Cascade(org.hibernate.annotations.CascadeType.DELETE_ORPHAN)
    @Fetch(value = FetchMode.SUBSELECT)
    @RequiredSize(property = "person.names")
    @Valid
    private List<SorName> names = new ArrayList<SorName>();

    @Column(name = "ssn", nullable = true, length = 9)
    @Required(property = "person.ssn")
    private String ssn;

    @OneToOne(cascade=CascadeType.ALL, mappedBy="person", fetch = FetchType.LAZY, targetEntity = JpaSorDisclosureSettingsImpl.class)
    private JpaSorDisclosureSettingsImpl disclosureSettings;

    @OneToMany(cascade = CascadeType.ALL, mappedBy = "person", fetch = FetchType.LAZY, targetEntity = JpaSorRoleImpl.class)
    @org.hibernate.annotations.Cascade(org.hibernate.annotations.CascadeType.DELETE_ORPHAN)
    @Fetch(value = FetchMode.SUBSELECT)
    @Valid
    private List<SorRole> roles = new ArrayList<SorRole>();

    @ElementCollection
    @CollectionTable(name = "prs_sor_persons_loc_attr", joinColumns = @JoinColumn(name = "sor_person_record_id"))
    @MapKeyColumn(name = "attribute_type")
    @Column(name = "attribute_value")
    private Map<String, String> sorLocalAttributes = new HashMap<String, String>();

    public List<SorRole> getRoles() {
        return this.roles;
    }

    public String getSsn() {
        return this.ssn;
    }

    public void setSsn(final String ssn) {
        this.ssn = ssn;
    }

    public Long getId() {
        return this.recordId;
    }

    public String getSorId() {
        return this.sorId;
    }

    public String getSourceSor() {
        return this.sourceSor;
    }

    public void setSourceSor(final String sorIdentifier) {
        this.sourceSor = sorIdentifier;
    }

    public List<SorName> getNames() {
        return this.names;
    }

    public void setSorId(final String id) {
        this.sorId = id;
    }

    public Date getDateOfBirth() {
        return this.dateOfBirth;
    }

    public void setDateOfBirth(final Date date) {
        this.dateOfBirth = date;
    }

    public String getGender() {
        return this.gender;
    }

    public void setGender(final String gender) {
        this.gender = gender;
    }

    /**
     * @see org.openregistry.core.domain.sor.SorPerson#getDisclosureSettings()
     */
    public SorDisclosureSettings getDisclosureSettings() {
		return this.disclosureSettings;
	}

	/**
	 * @see org.openregistry.core.domain.sor.SorPerson#setDisclosureSettings(org.openregistry.core.domain.DisclosureSettings)
	 */
	public void setDisclosureSettings(SorDisclosureSettings ds) {
		if (ds instanceof JpaSorDisclosureSettingsImpl) {
			this.disclosureSettings = new JpaSorDisclosureSettingsImpl
				(this, ds.getDisclosureCode(), ds.getLastUpdateDate(), ds.isWithinGracePeriod());
		} else {
{'fraction_non_alphanumeric': 0.10714835926667694, 'fraction_numerical': 0.002619010938222154, 'mean_word_length': 4.121499013806706, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 21, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6083147', 'n_tokens_mistral': 4046, 'n_tokens_neox': 3910, 'n_words': 929}