<commit_before>/*
 * Copyright 2014 JBoss Inc
 *
 * 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.
 */
package io.apiman.manager.api.beans.apis;

import io.apiman.manager.api.beans.idm.DiscoverabilityLevel;

import java.io.Serializable;
import java.util.Date;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import javax.persistence.CascadeType;
import javax.persistence.CollectionTable;
import javax.persistence.Column;
import javax.persistence.ElementCollection;
import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinColumns;
import javax.persistence.Lob;
import javax.persistence.ManyToOne;
import javax.persistence.MapKeyColumn;
import javax.persistence.OneToMany;
import javax.persistence.OneToOne;
import javax.persistence.Table;
import javax.persistence.UniqueConstraint;

import com.fasterxml.jackson.annotation.JsonIdentityInfo;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonInclude.Include;
import com.fasterxml.jackson.annotation.ObjectIdGenerators;
import org.hibernate.annotations.ColumnDefault;
import org.hibernate.annotations.Nationalized;

/**
 * Models a single version of an API. Every API in APIMan has basic meta-data
 * stored in {@link ApiBean}. All other specifics of the API, such as
 * endpoint information and configured policies are associated with a particular
 * version of that API. This class represents that version.
 *
 * @author <EMAIL>
 */
@Entity
@Table(name = "api_versions",
       uniqueConstraints = { @UniqueConstraint(columnNames = { "api_id", "api_org_id", "version" }) })
@JsonInclude(Include.NON_NULL)
@JsonIdentityInfo(generator = ObjectIdGenerators.PropertyGenerator.class, property = "id")
public class ApiVersionBean implements Serializable, Cloneable {

    private static final long serialVersionUID = -2218697175049442690L;

    @Id @GeneratedValue
    private Long id;

    @ManyToOne
    @JoinColumns({
         @JoinColumn(name = "api_id", referencedColumnName = "id"),
         @JoinColumn(name = "api_org_id", referencedColumnName = "organization_id")
    })
    private ApiBean api;

    @Column(name = "status", nullable = false)
    @Enumerated(EnumType.STRING)
    private ApiStatus status;

    @Column(name = "endpoint")
    private String endpoint;

    @Column(name = "endpoint_type")
    @Enumerated(EnumType.STRING)
    private EndpointType endpointType;

    @Column(name = "endpoint_ct")
    @Enumerated(EnumType.STRING)
    private EndpointContentType endpointContentType;

    @ElementCollection(fetch = FetchType.EAGER)
    @MapKeyColumn(name = "name")
    @Column(name = "value")
    @CollectionTable(name = "endpoint_properties", joinColumns = @JoinColumn(name = "api_version_id"))
    private Map<String, String> endpointProperties = new HashMap<>();

    @ElementCollection(fetch = FetchType.EAGER)
    @CollectionTable(name = "api_gateways", joinColumns = @JoinColumn(name = "api_version_id"))
    private Set<ApiGatewayBean> gateways;

    @Column(name = "public_api", updatable = true, nullable = false)
    private boolean publicAPI;

    @Column(name = "discoverability")
    @Enumerated(EnumType.STRING)
    @ColumnDefault("'ORG_MEMBERS'")
    private DiscoverabilityLevel discoverability = DiscoverabilityLevel.ORG_MEMBERS;

    @OneToOne(mappedBy = "apiVersion", orphanRemoval = true, cascade = CascadeType.ALL, fetch = FetchType.LAZY)
    ApiDefinitionBean apiDefinition; // Deliberately no explicit getter/setter for this

    @OneToMany(fetch = FetchType.EAGER, mappedBy = "apiVersion", cascade = CascadeType.ALL, orphanRemoval = true)
    private Set<ApiPlanBean> plans = new HashSet<>();

    @Column(updatable = false)
    private String version;

    @Column(name = "created_by", updatable = false, nullable = false)
    private String createdBy;

    @Column(name = "created_on", updatable = false, nullable = false)
    private Date createdOn;

    @Column(name = "modified_by", updatable = true, nullable = false)
    private String modifiedBy;

    @Column(name = "modified_on", updatable = true, nullable = false)
    private Date modifiedOn;

    @Column(name = "published_on")
    private Date publishedOn;<commit_msg>fix(manager-api-beans): ignore `ApiDefinition` bean in `ApiVersionBean` for now<commit_after>/*
 * Copyright 2014 JBoss Inc
 *
 * 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.
 */
package io.apiman.manager.api.beans.apis;

import io.apiman.manager.api.beans.idm.DiscoverabilityLevel;

import java.io.Serializable;
import java.util.Date;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import javax.persistence.CascadeType;
import javax.persistence.CollectionTable;
import javax.persistence.Column;
import javax.persistence.ElementCollection;
import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinColumns;
import javax.persistence.Lob;
import javax.persistence.ManyToOne;
import javax.persistence.MapKeyColumn;
import javax.persistence.OneToMany;
import javax.persistence.OneToOne;
import javax.persistence.Table;
import javax.persistence.UniqueConstraint;

import com.fasterxml.jackson.annotation.JsonIdentityInfo;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonInclude.Include;
import com.fasterxml.jackson.annotation.ObjectIdGenerators;
import org.hibernate.annotations.ColumnDefault;
import org.hibernate.annotations.Nationalized;

/**
 * Models a single version of an API. Every API in APIMan has basic meta-data
 * stored in {@link ApiBean}. All other specifics of the API, such as
 * endpoint information and configured policies are associated with a particular
 * version of that API. This class represents that version.
 *
 * @author <EMAIL>
 */
@Entity
@Table(name = "api_versions",
       uniqueConstraints = { @UniqueConstraint(columnNames = { "api_id", "api_org_id", "version" }) })
@JsonInclude(Include.NON_NULL)
@JsonIdentityInfo(generator = ObjectIdGenerators.PropertyGenerator.class, property = "id")
public class ApiVersionBean implements Serializable, Cloneable {

    private static final long serialVersionUID = -2218697175049442690L;

    @Id @GeneratedValue
    private Long id;

    @ManyToOne
    @JoinColumns({
         @JoinColumn(name = "api_id", referencedColumnName = "id"),
         @JoinColumn(name = "api_org_id", referencedColumnName = "organization_id")
    })
    private ApiBean api;

    @Column(name = "status", nullable = false)
    @Enumerated(EnumType.STRING)
    private ApiStatus status;

    @Column(name = "endpoint")
    private String endpoint;

    @Column(name = "endpoint_type")
    @Enumerated(EnumType.STRING)
    private EndpointType endpointType;

    @Column(name = "endpoint_ct")
    @Enumerated(EnumType.STRING)
    private EndpointContentType endpointContentType;

    @ElementCollection(fetch = FetchType.EAGER)
    @MapKeyColumn(name = "name")
    @Column(name = "value")
    @CollectionTable(name = "endpoint_properties", joinColumns = @JoinColumn(name = "api_version_id"))
    private Map<String, String> endpointProperties = new HashMap<>();

    @ElementCollection(fetch = FetchType.EAGER)
    @CollectionTable(name = "api_gateways", joinColumns = @JoinColumn(name = "api_version_id"))
    private Set<ApiGatewayBean> gateways;

    @Column(name = "public_api", updatable = true, nullable = false)
    private boolean publicAPI;

    @Column(name = "discoverability")
    @Enumerated(EnumType.STRING)
    @ColumnDefault("'ORG_MEMBERS'")
    private DiscoverabilityLevel discoverability = DiscoverabilityLevel.ORG_MEMBERS;

    @OneToOne(mappedBy = "apiVersion", orphanRemoval = true, cascade = CascadeType.ALL, fetch = FetchType.LAZY)
    @JsonIgnore
    ApiDefinitionBean apiDefinition; // Deliberately no explicit getter/setter for this

    @OneToMany(fetch = FetchType.EAGER, mappedBy = "apiVersion", cascade = CascadeType.ALL, orphanRemoval = true)
    private Set<ApiPlanBean> plans = new HashSet<>();

    @Column(updatable = false)
    private String version;

    @Column(name = "created_by", updatable = false, nullable = false)
    private String createdBy;

    @Column(name = "created_on", updatable = false, nullable = false)
    private Date createdOn;

    @Column(name = "modified_by", updatable = true, nullable = false)
    private String modifiedBy;

    @Column(name = "modified_on", updatable = true, nullable = false)
    private Date modifiedOn;

    @Column(name = "published_on")
    private Date publishedOn;
{'fraction_non_alphanumeric': 0.09926177174780526, 'fraction_numerical': 0.00538707102952913, 'mean_word_length': 4.798149219201851, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 9}, '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': '5329327', 'n_tokens_mistral': 2917, 'n_tokens_neox': 2838, 'n_words': 775}